Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ObjectID over AccountAddress #468

Merged
merged 9 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sui/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl ClientServerBenchmark {
let order = if self.use_move {
// TODO: authority should not require seq# or digets for package in Move calls. Use dummy values
let framework_obj_ref = (
SUI_FRAMEWORK_ADDRESS,
ObjectID::from(SUI_FRAMEWORK_ADDRESS),
SequenceNumber::new(),
ObjectDigest::new([0; 32]),
);
Expand Down
1 change: 0 additions & 1 deletion sui_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use move_bytecode_utils::module_cache::ModuleCache;
use move_core_types::{
account_address::AccountAddress,
language_storage::{ModuleId, StructTag},
resolver::{ModuleResolver, ResourceResolver},
};
Expand Down
2 changes: 1 addition & 1 deletion sui_core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl ModuleResolver for AuthorityStore {
type Error = SuiError;

fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
match self.get_object(module_id.address())? {
match self.get_object(&ObjectID::from(*module_id.address()))? {
Some(o) => match &o.data {
Data::Package(c) => Ok(c
.get(module_id.name().as_str())
Expand Down
7 changes: 4 additions & 3 deletions sui_core/src/authority/temporary_store.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use move_core_types::account_address::AccountAddress;
use sui_types::event::Event;

use super::*;
Expand Down Expand Up @@ -263,7 +264,7 @@ impl Storage for AuthorityTemporaryStore {
impl ModuleResolver for AuthorityTemporaryStore {
type Error = SuiError;
fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
match self.read_object(module_id.address()) {
match self.read_object(&ObjectID::from(*module_id.address())) {
Some(o) => match &o.data {
Data::Package(c) => Ok(c
.get(module_id.name().as_str())
Expand All @@ -286,9 +287,9 @@ impl ResourceResolver for AuthorityTemporaryStore {
address: &AccountAddress,
struct_tag: &StructTag,
) -> Result<Option<Vec<u8>>, Self::Error> {
let object = match self.read_object(address) {
let object = match self.read_object(&ObjectID::from(*address)) {
Some(x) => x,
None => match self.read_object(address) {
None => match self.read_object(&ObjectID::from(*address)) {
None => return Ok(None),
Some(x) => {
if !x.is_read_only() {
Expand Down
4 changes: 3 additions & 1 deletion sui_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ where

#[cfg(test)]
pub async fn get_framework_object_ref(&mut self) -> Result<ObjectRef, anyhow::Error> {
let info = self.get_object_info(SUI_FRAMEWORK_ADDRESS).await?;
let info = self
.get_object_info(ObjectID::from(SUI_FRAMEWORK_ADDRESS))
.await?;
Ok(info.reference()?)
}

Expand Down
6 changes: 4 additions & 2 deletions sui_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use move_binary_format::{
file_format::{self, AddressIdentifierIndex, IdentifierIndex, ModuleHandle},
CompiledModule,
};
use move_core_types::{ident_str, identifier::Identifier, language_storage::TypeTag};
use move_core_types::{
account_address::AccountAddress, ident_str, identifier::Identifier, language_storage::TypeTag,
};
use move_package::BuildConfig;
use sui_adapter::genesis;
use sui_types::{
Expand Down Expand Up @@ -451,7 +453,7 @@ async fn test_publish_non_existing_dependent_module() {
// Add another dependent module that points to a random address, hence does not exist on-chain.
dependent_module
.address_identifiers
.push(AccountAddress::random());
.push(AccountAddress::from(ObjectID::random()));
dependent_module.module_handles.push(ModuleHandle {
address: AddressIdentifierIndex((dependent_module.address_identifiers.len() - 1) as u16),
name: IdentifierIndex(0),
Expand Down
5 changes: 2 additions & 3 deletions sui_core/src/unit_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use sui_types::object::{Data, Object, GAS_VALUE_FOR_TESTING, OBJECT_START_VERSIO
use tokio::runtime::Runtime;
use typed_store::Map;

use move_core_types::account_address::AccountAddress;
use std::env;
use std::fs;
use sui_types::error::SuiError::ObjectNotFound;
Expand Down Expand Up @@ -369,7 +368,7 @@ async fn fund_account_with_same_objects(
authorities: Vec<&LocalAuthorityClient>,
client: &mut ClientState<LocalAuthorityClient>,
object_ids: Vec<ObjectID>,
) -> HashMap<AccountAddress, Object> {
) -> HashMap<ObjectID, Object> {
let objs: Vec<_> = (0..authorities.len()).map(|_| object_ids.clone()).collect();
fund_account(authorities, client, objs).await
}
Expand All @@ -379,7 +378,7 @@ async fn fund_account(
authorities: Vec<&LocalAuthorityClient>,
client: &mut ClientState<LocalAuthorityClient>,
object_ids: Vec<Vec<ObjectID>>,
) -> HashMap<AccountAddress, Object> {
) -> HashMap<ObjectID, Object> {
let mut created_objects = HashMap::new();
for (authority, object_ids) in authorities.into_iter().zip(object_ids.into_iter()) {
for object_id in object_ids {
Expand Down
13 changes: 10 additions & 3 deletions sui_programmability/adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fn execute_internal<
type_args: Vec<TypeTag>,
args: Vec<Vec<u8>>,
mutable_ref_objects: Vec<Object>,
by_value_objects: BTreeMap<AccountAddress, Object>,
by_value_objects: BTreeMap<ObjectID, Object>,
object_owner_map: HashMap<SuiAddress, SuiAddress>,
gas_budget: u64, // gas budget for the current call operation
ctx: &mut TxContext,
Expand Down Expand Up @@ -400,7 +400,11 @@ pub fn verify_and_link<
})
.collect();
session
.publish_module_bundle(new_module_bytes, package_id, &mut gas_status)
.publish_module_bundle(
new_module_bytes,
AccountAddress::from(package_id),
&mut gas_status,
)
.map_err(|e| SuiError::ModulePublishFailure {
error: e.to_string(),
})?;
Expand Down Expand Up @@ -433,7 +437,10 @@ pub fn generate_package_id(
error: "Publishing modules with non-zero address is not allowed".to_string(),
});
}
let new_module_id = ModuleId::new(package_id, old_module_id.name().to_owned());
let new_module_id = ModuleId::new(
AccountAddress::from(package_id),
old_module_id.name().to_owned(),
);
if sub_map.insert(old_module_id, new_module_id).is_some() {
return Err(SuiError::ModulePublishFailure {
error: "Publishing two modules with the same ID".to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl ModuleResolver for InMemoryStorage {
type Error = ();
fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
Ok(self
.read_object(module_id.address())
.read_object(&ObjectID::from(*module_id.address()))
.map(|o| match &o.data {
Data::Package(m) => m[module_id.name().as_str()].clone().into_vec(),
Data::Move(_) => panic!("Type error"),
Expand Down
3 changes: 2 additions & 1 deletion sui_programmability/framework/src/natives/tx_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use move_binary_format::errors::PartialVMResult;
use move_core_types::account_address::AccountAddress;
use move_vm_runtime::native_functions::NativeContext;
use move_vm_types::{
gas_schedule::NativeCostIndex,
Expand All @@ -28,7 +29,7 @@ pub fn fresh_id(
// TODO(https://github.com/MystenLabs/fastnft/issues/58): finalize digest format
// unwrap safe because all digests in Move are serialized from the Rust `TransactionDigest`
let digest = TransactionDigest::try_from(inputs_hash.as_slice()).unwrap();
let id = Value::address(digest.derive_id(ids_created));
let id = Value::address(AccountAddress::from(digest.derive_id(ids_created)));

// TODO: choose cost
let cost = native_gas(context.cost_table(), NativeCostIndex::CREATE_SIGNER, 0);
Expand Down
Loading