-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[framework] unify Rust and Move object ID derivation
Previously, there were two incompatible implementations of ObjectID derivation. This PR: - Eliminates the `ObjectID` derivation inside Move and replaces it with a native function that invokes the Rust `ObjectID` derivation. This ensures that Rust and Move agree on how ID's are generated, and should also be more efficient than the previous approach. - Introduces a harness for invoking Move unit tests and a unit tests for `TxContext` that shows the ID generation working as expected.
- Loading branch information
1 parent
e802402
commit 1af0d37
Showing
12 changed files
with
181 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Mysten Labs | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use fastx_types::base_types::TransactionDigest; | ||
use move_binary_format::errors::PartialVMResult; | ||
use move_vm_runtime::native_functions::NativeContext; | ||
use move_vm_types::{ | ||
gas_schedule::NativeCostIndex, | ||
loaded_data::runtime_types::Type, | ||
natives::function::{native_gas, NativeResult}, | ||
pop_arg, | ||
values::Value, | ||
}; | ||
use smallvec::smallvec; | ||
use std::{collections::VecDeque, convert::TryFrom}; | ||
|
||
pub fn fresh_id( | ||
context: &mut NativeContext, | ||
ty_args: Vec<Type>, | ||
mut args: VecDeque<Value>, | ||
) -> PartialVMResult<NativeResult> { | ||
debug_assert!(ty_args.is_empty()); | ||
debug_assert!(args.len() == 2); | ||
|
||
let ids_created = pop_arg!(args, u64); | ||
let inputs_hash = pop_arg!(args, Vec<u8>); | ||
|
||
// 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)); | ||
|
||
// TODO: choose cost | ||
let cost = native_gas(context.cost_table(), NativeCostIndex::CREATE_SIGNER, 0); | ||
|
||
Ok(NativeResult::ok(cost, smallvec![id])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#[test_only] | ||
module FastX::TxContextTests { | ||
use FastX::TxContext; | ||
|
||
#[test] | ||
fun test_id_generation() { | ||
let ctx = TxContext::dummy(); | ||
assert!(TxContext::get_ids_created(&ctx) == 0, 0); | ||
|
||
let id1 = TxContext::new_id(&mut ctx); | ||
let id2 = TxContext::new_id(&mut ctx); | ||
|
||
// new_id should always produce fresh ID's | ||
assert!(id1 != id2, 1); | ||
assert!(TxContext::get_ids_created(&ctx) == 2, 2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1af0d37
There was a problem hiding this comment.
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.12s
�[0m�[0m�[1m�[32m Running�[0m
target/release/bench
[2022-01-10T16:13:33Z INFO bench] Starting benchmark: OrdersAndCerts
[2022-01-10T16:13:33Z INFO bench] Preparing accounts.
[2022-01-10T16:13:37Z INFO bench] Preparing transactions.
[2022-01-10T16:13:45Z INFO fastpay::network] Listening to Tcp traffic on 127.0.0.1:9555
[2022-01-10T16:13:46Z INFO bench] Set max_in_flight to 500
[2022-01-10T16:13:46Z INFO bench] Sending requests.
[2022-01-10T16:13:46Z INFO fastpay::network] Sending Tcp requests to 127.0.0.1:9555
[2022-01-10T16:13:46Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:47Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:47Z INFO fastpay::network] 127.0.0.1:9555 has processed 5000 packets
[2022-01-10T16:13:48Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:48Z INFO fastpay::network] In flight 500 Remaining 35000
[2022-01-10T16:13:48Z INFO fastpay::network] 127.0.0.1:9555 has processed 10000 packets
[2022-01-10T16:13:49Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:49Z INFO fastpay::network] 127.0.0.1:9555 has processed 15000 packets
[2022-01-10T16:13:50Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:50Z INFO fastpay::network] In flight 500 Remaining 30000
[2022-01-10T16:13:50Z INFO fastpay::network] 127.0.0.1:9555 has processed 20000 packets
[2022-01-10T16:13:51Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:51Z INFO fastpay::network] 127.0.0.1:9555 has processed 25000 packets
[2022-01-10T16:13:51Z INFO fastpay::network] In flight 500 Remaining 25000
[2022-01-10T16:13:52Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:52Z INFO fastpay::network] 127.0.0.1:9555 has processed 30000 packets
[2022-01-10T16:13:52Z INFO fastpay::network] In flight 500 Remaining 25000
[2022-01-10T16:13:52Z INFO fastpay::network] 127.0.0.1:9555 has processed 35000 packets
[2022-01-10T16:13:53Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:53Z INFO fastpay::network] In flight 500 Remaining 20000
[2022-01-10T16:13:53Z INFO fastpay::network] 127.0.0.1:9555 has processed 40000 packets
[2022-01-10T16:13:54Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:54Z INFO fastpay::network] 127.0.0.1:9555 has processed 45000 packets
[2022-01-10T16:13:55Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:55Z INFO fastpay::network] In flight 500 Remaining 15000
[2022-01-10T16:13:55Z INFO fastpay::network] 127.0.0.1:9555 has processed 50000 packets
[2022-01-10T16:13:55Z INFO fastpay::network] 127.0.0.1:9555 has processed 55000 packets
[2022-01-10T16:13:56Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:56Z INFO fastpay::network] In flight 500 Remaining 10000
[2022-01-10T16:13:56Z INFO fastpay::network] 127.0.0.1:9555 has processed 60000 packets
[2022-01-10T16:13:56Z INFO fastpay::network] 127.0.0.1:9555 has processed 65000 packets
[2022-01-10T16:13:57Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:57Z INFO fastpay::network] In flight 500 Remaining 5000
[2022-01-10T16:13:57Z INFO fastpay::network] 127.0.0.1:9555 has processed 70000 packets
[2022-01-10T16:13:57Z INFO fastpay::network] 127.0.0.1:9555 has processed 75000 packets
[2022-01-10T16:13:58Z WARN fastpay::network] User query failed: The given sequence (SequenceNumber(0)) number must match the next expected sequence (SequenceNumber(1)) number of the account
[2022-01-10T16:13:58Z INFO fastpay::network] 127.0.0.1:9555 has processed 80000 packets
[2022-01-10T16:13:58Z INFO fastpay::network] Done sending Tcp requests to 127.0.0.1:9555
[2022-01-10T16:13:58Z INFO bench] Received 80000 responses.
[2022-01-10T16:13:58Z WARN bench] Completed benchmark for OrdersAndCerts
Total time: 11980903us, items: 40000, tx/sec: 3338.6465110351032