Skip to content

Commit

Permalink
Clean up some logic (#532)
Browse files Browse the repository at this point in the history
* Clean up some logic
  • Loading branch information
oxade authored Feb 23, 2022
1 parent ae20572 commit fb02b41
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
6 changes: 3 additions & 3 deletions sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async fn genesis(
);
let sui_lib = sui_framework::get_sui_framework_modules(&genesis_conf.sui_framework_lib_path)?;
let lib_object =
Object::new_package(sui_lib, SuiAddress::default(), TransactionDigest::genesis())?;
Object::new_package(sui_lib, SuiAddress::default(), TransactionDigest::genesis());
preload_modules.push(lib_object);

info!(
Expand All @@ -174,7 +174,7 @@ async fn genesis(
move_lib,
SuiAddress::default(),
TransactionDigest::genesis(),
)?;
);
preload_modules.push(lib_object);

// Build custom move packages
Expand All @@ -194,7 +194,7 @@ async fn genesis(
)?;

let object =
Object::new_package(modules, SuiAddress::default(), TransactionDigest::genesis())?;
Object::new_package(modules, SuiAddress::default(), TransactionDigest::genesis());
info!("Loaded package [{}] from {:?}.", object.id(), path);
// Writing package id to network.conf for user to retrieve later.
config.loaded_move_packages.push((path, object.id()));
Expand Down
1 change: 0 additions & 1 deletion sui_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,6 @@ async fn test_hero() {
)
.await
.unwrap();
println!("ERRRR {:?}", effects.status);
assert!(matches!(effects.status, ExecutionStatus::Success { .. }));

// 7. Give them a boar!
Expand Down
2 changes: 1 addition & 1 deletion sui_programmability/adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub fn publish<E: Debug, S: ResourceResolver<Error = E> + ModuleResolver<Error =
}

// wrap the modules in an object, write it to the store
let package_object = Object::new_package(modules, sender, ctx.digest())?;
let package_object = Object::new_package(modules, sender, ctx.digest());
state_view.write_object(package_object);

let mut total_gas_used = gas_cost;
Expand Down
4 changes: 2 additions & 2 deletions sui_programmability/adapter/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fn create_genesis_module_objects(lib_dir: &Path) -> SuiResult<Genesis> {
sui_framework::get_move_stdlib_modules(&lib_dir.join("deps").join("move-stdlib"))?;
let owner = SuiAddress::default();
let objects = vec![
Object::new_package(sui_modules, owner, TransactionDigest::genesis())?,
Object::new_package(std_modules, owner, TransactionDigest::genesis())?,
Object::new_package(sui_modules, owner, TransactionDigest::genesis()),
Object::new_package(std_modules, owner, TransactionDigest::genesis()),
];
Ok(Genesis { objects })
}
38 changes: 17 additions & 21 deletions sui_types/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ impl MoveObject {
// serde_bytes::ByteBuf is an analog of Vec<u8> with built-in fast serialization.
#[derive(Eq, PartialEq, Debug, Clone, Deserialize, Serialize, Hash)]
pub struct MovePackage {
id: ObjectID,
module_map: BTreeMap<String, ByteBuf>,
}

Expand All @@ -184,22 +183,21 @@ impl MovePackage {
}

pub fn from_map(module_map: &BTreeMap<String, ByteBuf>) -> Self {
// All modules in the same package must have the same address. Pick any
let id = ObjectID::from(
*CompiledModule::deserialize(module_map.values().next().unwrap())
.unwrap()
.self_id()
.address(),
);

Self {
id,
module_map: module_map.clone(),
}
}

pub fn id(&self) -> ObjectID {
self.id
// TODO: simplify this
// https://github.com/MystenLabs/fastnft/issues/249
// All modules in the same package must have the same address. Pick any
ObjectID::from(
*CompiledModule::deserialize(self.module_map.values().next().unwrap())
.unwrap()
.self_id()
.address(),
)
}

pub fn module_id(&self, module: &Identifier) -> Result<ModuleId, SuiError> {
Expand Down Expand Up @@ -236,10 +234,9 @@ impl MovePackage {
})
}
}
impl TryFrom<&Vec<CompiledModule>> for MovePackage {
type Error = SuiError;
fn try_from(compiled_modules: &Vec<CompiledModule>) -> Result<Self, SuiError> {
let package = MovePackage::from_map(
impl From<&Vec<CompiledModule>> for MovePackage {
fn from(compiled_modules: &Vec<CompiledModule>) -> Self {
MovePackage::from_map(
&compiled_modules
.iter()
.map(|module| {
Expand All @@ -248,8 +245,7 @@ impl TryFrom<&Vec<CompiledModule>> for MovePackage {
(module.self_id().name().to_string(), ByteBuf::from(bytes))
})
.collect(),
);
Ok(package)
)
}
}

Expand Down Expand Up @@ -370,12 +366,12 @@ impl Object {
modules: Vec<CompiledModule>,
owner: SuiAddress,
previous_transaction: TransactionDigest,
) -> Result<Self, SuiError> {
Ok(Object {
data: Data::Package(MovePackage::try_from(&modules)?),
) -> Self {
Object {
data: Data::Package(MovePackage::from(&modules)),
owner,
previous_transaction,
})
}
}

pub fn is_read_only(&self) -> bool {
Expand Down

1 comment on commit fb02b41

@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 2.88s
�[0m�[0m�[1m�[32m Running�[0m target/release/bench
�[2m2022-02-23T03:18:08.833232Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Starting benchmark: TransactionsAndCerts
�[2m2022-02-23T03:18:08.833265Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Preparing accounts.
�[2m2022-02-23T03:18:08.833723Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Open database on path: "/tmp/DB_B6125500421EDB16B389B0882E1CE329CAD9AC47"
�[2m2022-02-23T03:18:13.953688Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Preparing transactions.
�[2m2022-02-23T03:18:22.612669Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m Listening to TCP traffic on 127.0.0.1:9555
�[2m2022-02-23T03:18:23.614728Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Number of TCP connections: 2
�[2m2022-02-23T03:18:23.614764Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Set max_in_flight to 500
�[2m2022-02-23T03:18:23.614769Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Sending requests.
�[2m2022-02-23T03:18:23.621275Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Sending TCP requests to 127.0.0.1:9555
�[2m2022-02-23T03:18:23.627972Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Sending TCP requests to 127.0.0.1:9555
�[2m2022-02-23T03:18:24.485124Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 5000 packets
�[2m2022-02-23T03:18:25.247036Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 35000
�[2m2022-02-23T03:18:25.270580Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 35000
�[2m2022-02-23T03:18:25.347081Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 10000 packets
�[2m2022-02-23T03:18:26.213772Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 15000 packets
�[2m2022-02-23T03:18:27.001624Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 30000
�[2m2022-02-23T03:18:27.027318Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 30000
�[2m2022-02-23T03:18:27.084959Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 20000 packets
�[2m2022-02-23T03:18:27.951419Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 25000 packets
�[2m2022-02-23T03:18:28.713328Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 25000
�[2m2022-02-23T03:18:28.778473Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 25000
�[2m2022-02-23T03:18:28.819907Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 30000 packets
�[2m2022-02-23T03:18:29.687164Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 35000 packets
�[2m2022-02-23T03:18:30.465703Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 20000
�[2m2022-02-23T03:18:30.493724Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 20000
�[2m2022-02-23T03:18:30.559316Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 40000 packets
�[2m2022-02-23T03:18:31.430868Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 45000 packets
�[2m2022-02-23T03:18:32.234211Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 15000
�[2m2022-02-23T03:18:32.259795Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 15000
�[2m2022-02-23T03:18:32.308579Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 50000 packets
�[2m2022-02-23T03:18:33.188049Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 55000 packets
�[2m2022-02-23T03:18:33.962455Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 10000
�[2m2022-02-23T03:18:33.981524Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 10000
�[2m2022-02-23T03:18:34.062882Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 60000 packets
�[2m2022-02-23T03:18:34.937664Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 65000 packets
�[2m2022-02-23T03:18:35.737305Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 5000
�[2m2022-02-23T03:18:35.750709Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 5000
�[2m2022-02-23T03:18:35.819335Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 70000 packets
�[2m2022-02-23T03:18:36.699117Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 75000 packets
�[2m2022-02-23T03:18:37.594390Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Done sending TCP requests to 127.0.0.1:9555
�[2m2022-02-23T03:18:37.602986Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 80000 packets
�[2m2022-02-23T03:18:37.651139Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Done sending TCP requests to 127.0.0.1:9555
�[2m2022-02-23T03:18:37.652623Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Received 80000 responses.
�[2m2022-02-23T03:18:37.820306Z�[0m �[33m WARN�[0m �[2mbench�[0m�[2m:�[0m Completed benchmark for TransactionsAndCerts
Total time: 14037837us, items: 40000, tx/sec: 2849.441833524638

Please sign in to comment.