Skip to content

Commit

Permalink
Use ObjectID over AccountAddress (#468)
Browse files Browse the repository at this point in the history
* Use ObjectID over AccountAddress
  • Loading branch information
oxade authored Feb 18, 2022
1 parent 3af4b1a commit ec02fe5
Show file tree
Hide file tree
Showing 15 changed files with 349 additions and 32 deletions.
2 changes: 1 addition & 1 deletion sui/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,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 @@ -262,7 +263,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 @@ -285,9 +286,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 @@ -300,7 +300,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 @@ -8,7 +8,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 @@ -454,7 +456,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 @@ -20,7 +20,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 @@ -381,7 +380,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 @@ -391,7 +390,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 @@ -150,7 +150,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

1 comment on commit ec02fe5

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bench results

�[0m�[0m�[1m�[32m Finished�[0m release [optimized + debuginfo] target(s) in 1.21s
�[0m�[0m�[1m�[32m Running�[0m target/release/bench
�[2m2022-02-18T19:11:06.630137Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Starting benchmark: OrdersAndCerts
�[2m2022-02-18T19:11:06.630157Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Preparing accounts.
�[2m2022-02-18T19:11:06.632861Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Open database on path: "/tmp/DB_8148C62074BA4FA5F5EC926B8DC60A6D1E2849FD"
�[2m2022-02-18T19:11:11.724193Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Preparing transactions.
�[2m2022-02-18T19:11:20.317847Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m Listening to TCP traffic on 127.0.0.1:9555
�[2m2022-02-18T19:11:21.319722Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Number of TCP connections: 2
�[2m2022-02-18T19:11:21.320211Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Set max_in_flight to 500
�[2m2022-02-18T19:11:21.320371Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Sending requests.
�[2m2022-02-18T19:11:21.326237Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Sending TCP requests to 127.0.0.1:9555
�[2m2022-02-18T19:11:21.335933Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Sending TCP requests to 127.0.0.1:9555
�[2m2022-02-18T19:11:22.680443Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 5000 packets
�[2m2022-02-18T19:11:23.577175Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 35000
�[2m2022-02-18T19:11:23.845772Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 35000
�[2m2022-02-18T19:11:23.862272Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 10000 packets
�[2m2022-02-18T19:11:25.339049Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 15000 packets
�[2m2022-02-18T19:11:26.605871Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 30000
�[2m2022-02-18T19:11:26.880283Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 20000 packets
�[2m2022-02-18T19:11:26.882695Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 30000
�[2m2022-02-18T19:11:28.355390Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 25000 packets
�[2m2022-02-18T19:11:29.516563Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 25000
�[2m2022-02-18T19:11:29.834004Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 30000 packets
�[2m2022-02-18T19:11:29.972421Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 25000
�[2m2022-02-18T19:11:31.242568Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 35000 packets
�[2m2022-02-18T19:11:32.217839Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 20000
�[2m2022-02-18T19:11:32.652400Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 40000 packets
�[2m2022-02-18T19:11:32.772595Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 20000
�[2m2022-02-18T19:11:34.112905Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 45000 packets
�[2m2022-02-18T19:11:35.293528Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 15000
�[2m2022-02-18T19:11:35.483194Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 15000
�[2m2022-02-18T19:11:35.498138Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 50000 packets
�[2m2022-02-18T19:11:36.718681Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 55000 packets
�[2m2022-02-18T19:11:37.419207Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 10000
�[2m2022-02-18T19:11:37.540518Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 10000
�[2m2022-02-18T19:11:37.571304Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 60000 packets
�[2m2022-02-18T19:11:38.426435Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 65000 packets
�[2m2022-02-18T19:11:39.178646Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 5000
�[2m2022-02-18T19:11:39.290356Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 5000
�[2m2022-02-18T19:11:39.307894Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 70000 packets
�[2m2022-02-18T19:11:40.162599Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 75000 packets
�[2m2022-02-18T19:11:41.038069Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 80000 packets
�[2m2022-02-18T19:11:41.048196Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Done sending TCP requests to 127.0.0.1:9555
�[2m2022-02-18T19:11:41.079789Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Done sending TCP requests to 127.0.0.1:9555
�[2m2022-02-18T19:11:41.080104Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Received 80000 responses.
�[2m2022-02-18T19:11:41.242440Z�[0m �[33m WARN�[0m �[2mbench�[0m�[2m:�[0m Completed benchmark for OrdersAndCerts
Total time: 19759391us, items: 40000, tx/sec: 2024.3538882347134

Please sign in to comment.