From 546ed7dfaccfae7a5ef0e01b03c55dd304526fdf Mon Sep 17 00:00:00 2001 From: welbon Date: Fri, 1 Sep 2023 23:26:09 +0800 Subject: [PATCH 01/23] [benchmark] merge calculate code from benchmark project --- Cargo.lock | 4 +- vm/e2e-tests/Cargo.toml | 2 +- vm/transaction-benchmarks/Cargo.toml | 2 +- vm/transaction-benchmarks/src/main.rs | 51 ++++++++++++++ vm/transaction-benchmarks/src/measurement.rs | 2 +- vm/transaction-benchmarks/src/transactions.rs | 70 ++++++++++++++++++- vm/vm-runtime/src/parallel_executor/mod.rs | 28 ++++++++ 7 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 vm/transaction-benchmarks/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 639e2a6016..471a5d7731 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9787,7 +9787,7 @@ version = "0.1.0" [[package]] name = "starcoin-language-e2e-tests" -version = "1.13.5" +version = "1.13.7" dependencies = [ "anyhow", "bcs", @@ -10782,7 +10782,7 @@ dependencies = [ [[package]] name = "starcoin-transaction-benchmarks" -version = "1.13.5" +version = "1.13.7" dependencies = [ "criterion", "criterion-cpu-time", diff --git a/vm/e2e-tests/Cargo.toml b/vm/e2e-tests/Cargo.toml index 5e9797088d..6d765b7d62 100644 --- a/vm/e2e-tests/Cargo.toml +++ b/vm/e2e-tests/Cargo.toml @@ -4,7 +4,7 @@ authors = { workspace = true } edition = { workspace = true } license = { workspace = true } publish = { workspace = true } -version = "1.13.5" +version = "1.13.7" homepage = { workspace = true } repository = { workspace = true } rust-version = { workspace = true } diff --git a/vm/transaction-benchmarks/Cargo.toml b/vm/transaction-benchmarks/Cargo.toml index 3ef153809f..91546f9e2b 100644 --- a/vm/transaction-benchmarks/Cargo.toml +++ b/vm/transaction-benchmarks/Cargo.toml @@ -4,7 +4,7 @@ authors = { workspace = true } edition = { workspace = true } license = { workspace = true } publish = { workspace = true } -version = "1.13.5" +version = "1.13.7" homepage = { workspace = true } repository = { workspace = true } rust-version = { workspace = true } diff --git a/vm/transaction-benchmarks/src/main.rs b/vm/transaction-benchmarks/src/main.rs new file mode 100644 index 0000000000..e06d8ce89a --- /dev/null +++ b/vm/transaction-benchmarks/src/main.rs @@ -0,0 +1,51 @@ +use num_cpus; +use proptest::prelude::*; +use starcoin_language_e2e_tests::account_universe::P2PTransferGen; +use starcoin_transaction_benchmarks::transactions::TransactionBencher; + +fn main() { + let default_num_accounts = 100; + let default_num_transactions = 1_000; + + let bencher = TransactionBencher::new( + any_with::((1_000, 1_000_000)), + default_num_accounts, + default_num_transactions, + ); + + let acts = [2, 10, 100, 1000, 10000]; + let txns = [1000, 10000]; + let num_warmups = 2; + let num_runs = 10; + + let mut measurements = Vec::new(); + + for block_size in txns { + for num_accounts in acts { + let mut times = + bencher.manual_parallel(num_accounts, block_size, num_warmups, num_runs); + times.sort(); + measurements.push(times); + } + } + + println!("CPUS = {}", num_cpus::get()); + + let mut i = 0; + for block_size in txns { + for num_accounts in acts { + println!( + "PARAMS: num_account = {}, block_size = {}", + num_accounts, block_size + ); + println!("TPS: {:?}", measurements[i]); + let mut sum = 0; + for m in &measurements[i] { + sum += m; + } + println!("AVG TPS = {:?}", sum / measurements[i].len()); + i = i + 1; + } + println!(); + } +} diff --git a/vm/transaction-benchmarks/src/measurement.rs b/vm/transaction-benchmarks/src/measurement.rs index c2fe8afbb7..71622e39d5 100644 --- a/vm/transaction-benchmarks/src/measurement.rs +++ b/vm/transaction-benchmarks/src/measurement.rs @@ -1,4 +1,4 @@ -// Copyright (c) Starcoin +// Copyright (c) The Diem Core Contributors // SPDX-License-Identifier: Apache-2.0 use criterion::Criterion; diff --git a/vm/transaction-benchmarks/src/transactions.rs b/vm/transaction-benchmarks/src/transactions.rs index 1eca72021d..90882dd730 100644 --- a/vm/transaction-benchmarks/src/transactions.rs +++ b/vm/transaction-benchmarks/src/transactions.rs @@ -84,17 +84,49 @@ where pub fn bench_parallel(&self, b: &mut Bencher) { b.iter_batched( || { - TransactionBenchState::with_size( + ParallelBenchState::with_size( &self.strategy, self.num_accounts, self.num_transactions, ) }, - |state| state.execute_parallel(), + |state| state.execute(), // The input here is the entire list of signed transactions, so it's pretty large. BatchSize::LargeInput, ) } + + pub fn manual_parallel( + &self, + num_accounts: usize, + num_txn: usize, + num_warmups: usize, + num_runs: usize, + ) -> Vec { + let mut ret = Vec::new(); + + let total_runs = num_warmups + num_runs; + for i in 0..total_runs { + let state = ParallelBenchState::with_size(&self.strategy, num_accounts, num_txn); + + if i < num_warmups { + println!("WARMUP - ignore results"); + state.execute(); + } else { + println!( + "RUN bencher for: num_threads = {}, \ + block_size = {}, \ + num_account = {}", + num_cpus::get(), + num_txn, + num_accounts, + ); + ret.push(state.execute()); + } + } + + ret + } } struct TransactionBenchState { @@ -233,3 +265,37 @@ fn universe_strategy( let balance_strategy = log_balance_strategy(max_balance); AccountUniverseGen::strategy(num_accounts, balance_strategy) } + +struct ParallelBenchState { + bench_state: TransactionBenchState, +} + +impl ParallelBenchState { + /// Creates a new benchmark state with the given number of accounts and transactions. + fn with_size(strategy: S, num_accounts: usize, num_transactions: usize) -> Self + where + S: Strategy, + S::Value: AUTransactionGen, + { + Self { + bench_state: TransactionBenchState::with_universe( + strategy, + universe_strategy(num_accounts, num_transactions), + num_transactions, + ), + } + } + + fn execute(self) -> usize { + // let txns = self + // .bench_state + // .transactions + // .into_iter() + // .map(Transaction::UserTransaction) + // .collect(); + + let state_view = self.bench_state.executor.get_state_view(); + // measured - microseconds. + ParallelStarcoinVM::execute_block_tps(self.bench_state.transactions.clone(), state_view) + } +} diff --git a/vm/vm-runtime/src/parallel_executor/mod.rs b/vm/vm-runtime/src/parallel_executor/mod.rs index d63740a717..6ac3e1d5e4 100644 --- a/vm/vm-runtime/src/parallel_executor/mod.rs +++ b/vm/vm-runtime/src/parallel_executor/mod.rs @@ -24,6 +24,7 @@ use starcoin_vm_types::{ write_set::{WriteOp, WriteSet}, }; use std::collections::BTreeMap; +use std::time::Instant; impl PTransaction for PreprocessedTransaction { type Key = StateKey; @@ -109,4 +110,31 @@ impl ParallelStarcoinVM { Err(Error::UserError(err)) => Err(err), } } + + pub fn execute_block_tps( + transactions: Vec, + state_view: &S, + ) -> usize { + // Verify the signatures of all the transactions in parallel. + // This is time consuming so don't wait and do the checking + // sequentially while executing the transactions. + + // let mut timer = Instant::now(); + let signature_verified_block: Vec = transactions + .par_iter() + .map(|txn| preprocess_transaction(txn.clone())) + .collect(); + // println!("CLONE & Prologue {:?}", timer.elapsed()); + + let executor = + ParallelTransactionExecutor::>::new(num_cpus::get()); + + let timer = Instant::now(); + let useless = executor.execute_transactions_parallel(state_view, signature_verified_block); + let exec_t = timer.elapsed(); + + drop(useless); + + (transactions.len() * 1000 / exec_t.as_millis() as usize) as usize + } } From 653b8ae52cfcfab7dd02bbca43910534c337895b Mon Sep 17 00:00:00 2001 From: welbon Date: Mon, 4 Sep 2023 17:04:44 +0800 Subject: [PATCH 02/23] [benchmark] Close the parallel execution --- node/src/node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/node.rs b/node/src/node.rs index 4f10c33f22..a68c0bfba0 100644 --- a/node/src/node.rs +++ b/node/src/node.rs @@ -235,7 +235,7 @@ impl NodeService { } // XXX FIXME YSG add execute_config - StarcoinVM::set_concurrency_level_once(num_cpus::get()); + // StarcoinVM::set_concurrency_level_once(num_cpus::get()); let (start_sender, start_receiver) = oneshot::channel(); let join_handle = timeout_join_handler::spawn(move || { let system = System::with_tokio_rt(|| { From e6153c6810974c97a41687ce9897f67dd7b2596d Mon Sep 17 00:00:00 2001 From: welbon Date: Tue, 5 Sep 2023 17:52:26 +0800 Subject: [PATCH 03/23] [benchmark] add the parameter for num_threads --- node/src/node.rs | 2 -- vm/transaction-benchmarks/src/transactions.rs | 23 ++++++++++++++++--- vm/vm-runtime/src/parallel_executor/mod.rs | 7 ++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/node/src/node.rs b/node/src/node.rs index a68c0bfba0..fd3e7fcf77 100644 --- a/node/src/node.rs +++ b/node/src/node.rs @@ -12,7 +12,6 @@ use futures::channel::oneshot; use futures::executor::block_on; use futures_timer::Delay; use network_api::{PeerProvider, PeerSelector, PeerStrategy}; -use num_cpus; use starcoin_account_service::{AccountEventService, AccountService, AccountStorage}; use starcoin_block_relayer::BlockRelayer; use starcoin_chain_notify::ChainNotifyHandlerService; @@ -55,7 +54,6 @@ use starcoin_sync::verified_rpc_client::VerifiedRpcClient; use starcoin_txpool::TxPoolActorService; use starcoin_types::system_events::{SystemShutdown, SystemStarted}; use starcoin_vm_runtime::metrics::VMMetrics; -use starcoin_vm_runtime::starcoin_vm::StarcoinVM; use std::sync::Arc; use std::time::{Duration, SystemTime}; diff --git a/vm/transaction-benchmarks/src/transactions.rs b/vm/transaction-benchmarks/src/transactions.rs index 90882dd730..10071863cd 100644 --- a/vm/transaction-benchmarks/src/transactions.rs +++ b/vm/transaction-benchmarks/src/transactions.rs @@ -88,6 +88,7 @@ where &self.strategy, self.num_accounts, self.num_transactions, + num_cpus::get(), ) }, |state| state.execute(), @@ -107,7 +108,12 @@ where let total_runs = num_warmups + num_runs; for i in 0..total_runs { - let state = ParallelBenchState::with_size(&self.strategy, num_accounts, num_txn); + let state = ParallelBenchState::with_size( + &self.strategy, + num_accounts, + num_txn, + num_cpus::get(), + ); if i < num_warmups { println!("WARMUP - ignore results"); @@ -268,11 +274,17 @@ fn universe_strategy( struct ParallelBenchState { bench_state: TransactionBenchState, + num_threads: usize, } impl ParallelBenchState { /// Creates a new benchmark state with the given number of accounts and transactions. - fn with_size(strategy: S, num_accounts: usize, num_transactions: usize) -> Self + fn with_size( + strategy: S, + num_accounts: usize, + num_transactions: usize, + num_threads: usize, + ) -> Self where S: Strategy, S::Value: AUTransactionGen, @@ -283,6 +295,7 @@ impl ParallelBenchState { universe_strategy(num_accounts, num_transactions), num_transactions, ), + num_threads, } } @@ -296,6 +309,10 @@ impl ParallelBenchState { let state_view = self.bench_state.executor.get_state_view(); // measured - microseconds. - ParallelStarcoinVM::execute_block_tps(self.bench_state.transactions.clone(), state_view) + ParallelStarcoinVM::execute_block_tps( + self.bench_state.transactions.clone(), + state_view, + self.num_threads, + ) } } diff --git a/vm/vm-runtime/src/parallel_executor/mod.rs b/vm/vm-runtime/src/parallel_executor/mod.rs index 6ac3e1d5e4..6cc30f7555 100644 --- a/vm/vm-runtime/src/parallel_executor/mod.rs +++ b/vm/vm-runtime/src/parallel_executor/mod.rs @@ -114,6 +114,7 @@ impl ParallelStarcoinVM { pub fn execute_block_tps( transactions: Vec, state_view: &S, + parallel_level: usize, ) -> usize { // Verify the signatures of all the transactions in parallel. // This is time consuming so don't wait and do the checking @@ -127,7 +128,9 @@ impl ParallelStarcoinVM { // println!("CLONE & Prologue {:?}", timer.elapsed()); let executor = - ParallelTransactionExecutor::>::new(num_cpus::get()); + ParallelTransactionExecutor::>::new( + parallel_level, + ); let timer = Instant::now(); let useless = executor.execute_transactions_parallel(state_view, signature_verified_block); @@ -135,6 +138,6 @@ impl ParallelStarcoinVM { drop(useless); - (transactions.len() * 1000 / exec_t.as_millis() as usize) as usize + transactions.len() * 1000 / exec_t.as_millis() as usize } } From a7a31e7aa827cd2000dccad70864d93593dc2499 Mon Sep 17 00:00:00 2001 From: welbon Date: Wed, 6 Sep 2023 10:00:25 +0800 Subject: [PATCH 04/23] [benchmark] Add manual_sequence for sequence execution --- vm/transaction-benchmarks/src/transactions.rs | 78 +++++++++++++++---- 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/vm/transaction-benchmarks/src/transactions.rs b/vm/transaction-benchmarks/src/transactions.rs index 10071863cd..1a7092c4d2 100644 --- a/vm/transaction-benchmarks/src/transactions.rs +++ b/vm/transaction-benchmarks/src/transactions.rs @@ -8,6 +8,7 @@ use proptest::{ test_runner::TestRunner, }; use starcoin_crypto::HashValue; +use std::time::Instant; use starcoin_language_e2e_tests::account::AccountData; use starcoin_language_e2e_tests::{ @@ -97,6 +98,41 @@ where ) } + pub fn manual_sequence( + &self, + num_accounts: usize, + num_txn: usize, + num_warmups: usize, + num_runs: usize, + ) -> Vec { + let mut ret = Vec::new(); + + let total_runs = num_warmups + num_runs; + for i in 0..total_runs { + let state = TransactionBenchState::with_size( + &self.strategy, + num_accounts, + num_txn, + ); + + if i < num_warmups { + println!("WARMUP - ignore results"); + state.execute(); + } else { + println!( + "RUN bencher for: num_threads = {}, \ + block_size = {}, \ + num_account = {}", + num_cpus::get(), + num_txn, + num_accounts, + ); + ret.push(state.execute()); + } + } + ret + } + pub fn manual_parallel( &self, num_accounts: usize, @@ -130,7 +166,6 @@ where ret.push(state.execute()); } } - ret } } @@ -234,31 +269,42 @@ impl TransactionBenchState { } /// Executes this state in a single block. - fn execute(self) { + fn execute(self) -> usize { // The output is ignored here since we're just testing transaction performance, not trying // to assert correctness. - StarcoinVM::execute_block( - self.transactions, - self.executor.get_state_view(), - None, - None, - ) - .expect("VM should not fail to start"); - } + StarcoinVM::set_concurrency_level_once(1); - /// Executes this state in a single block via parallel execution. - fn execute_parallel(self) { - // The output is ignored here since we're just testing transaction performance, not trying - // to assert correctness. - ParallelStarcoinVM::execute_block( + let transactions_len = self.transactions.len(); + + // this bench execution with TPS + let timer = Instant::now(); + let useless = StarcoinVM::execute_block( self.transactions, self.executor.get_state_view(), - num_cpus::get(), None, None, ) .expect("VM should not fail to start"); + + drop(useless); + + let exec_t = timer.elapsed(); + transactions_len * 1000 / exec_t.as_millis() as usize } + + // /// Executes this state in a single block via parallel execution. + // fn execute_parallel(self) { + // // The output is ignored here since we're just testing transaction performance, not trying + // // to assert correctness. + // ParallelStarcoinVM::execute_block( + // self.transactions, + // self.executor.get_state_view(), + // num_cpus::get(), + // None, + // None, + // ) + // .expect("VM should not fail to start"); + // } } /// Returns a strategy for the account universe customized for benchmarks. From 7e2b3dcf032621366ba2e5d0615f11ef2a5e9856 Mon Sep 17 00:00:00 2001 From: welbon Date: Thu, 7 Sep 2023 19:10:44 +0800 Subject: [PATCH 05/23] [benchmark] Add flamegraph config for transaction_benches --- Cargo.lock | 101 +++++++++++------- vm/transaction-benchmarks/Cargo.toml | 12 ++- .../benches/transaction_benches.rs | 15 ++- 3 files changed, 82 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 471a5d7731..2dcc277efa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,7 @@ checksum = "f728064aca1c318585bf4bb04ffcfac9e75e508ab4e8b1bd9ba5dfe04e2cbed5" dependencies = [ "actix-rt", "actix_derive", - "bitflags", + "bitflags 1.3.2", "bytes 1.4.0", "crossbeam-channel", "futures-core", @@ -738,7 +738,7 @@ version = "0.59.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "clap 2.34.0", @@ -761,7 +761,7 @@ version = "0.65.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "lazy_static 1.4.0", @@ -797,6 +797,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + [[package]] name = "bitmaps" version = "2.1.0" @@ -1196,7 +1202,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term 0.12.1", "atty", - "bitflags", + "bitflags 1.3.2", "strsim 0.8.0", "textwrap 0.11.0", "unicode-width", @@ -1210,7 +1216,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_derive", "clap_lex", "indexmap", @@ -1269,7 +1275,7 @@ version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1617,7 +1623,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "486d44227f71a1ef39554c0dc47e44b9f4139927c75043312690c3f476d1d788" dependencies = [ - "bitflags", + "bitflags 1.3.2", "crossterm_winapi 0.8.0", "libc", "mio 0.7.14", @@ -1633,7 +1639,7 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c85525306c4291d1b73ce93c8acf9c339f9b213aef6c1d85c3830cbf1c16325c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "crossterm_winapi 0.9.0", "libc", "mio 0.7.14", @@ -2722,7 +2728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ef1a30ae415c3a691a4f41afddc2dbcd6d70baf338368d85ebc1e8ed92cedb9" dependencies = [ "cfg-if 1.0.0", - "rustix", + "rustix 0.36.14", "windows-sys 0.45.0", ] @@ -2874,7 +2880,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" dependencies = [ - "bitflags", + "bitflags 1.3.2", "fuchsia-zircon-sys", ] @@ -3212,7 +3218,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" dependencies = [ - "bitflags", + "bitflags 1.3.2", "ignore", "walkdir", ] @@ -3850,14 +3856,13 @@ checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "is-terminal" -version = "0.4.3" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.1", - "io-lifetimes", - "rustix", - "windows-sys 0.45.0", + "rustix 0.38.11", + "windows-sys 0.48.0", ] [[package]] @@ -4141,7 +4146,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" dependencies = [ "arrayvec 0.5.2", - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "ryu", "static_assertions", @@ -4149,9 +4154,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.139" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libloading" @@ -4682,6 +4687,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" +[[package]] +name = "linux-raw-sys" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" + [[package]] name = "lock_api" version = "0.3.4" @@ -5939,7 +5950,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9ea4302b9759a7a88242299225ea3688e63c85ea136371bb6cf94fd674efaab" dependencies = [ "anyhow", - "bitflags", + "bitflags 1.3.2", "byteorder", "libc", "netlink-packet-core", @@ -6018,7 +6029,7 @@ dependencies = [ "async-trait", "asynchronous-codec 0.5.0", "bcs-ext", - "bitflags", + "bitflags 1.3.2", "bs58 0.3.1", "bytes 1.4.0", "derive_more", @@ -6088,7 +6099,7 @@ name = "network-p2p-types" version = "1.13.7" dependencies = [ "anyhow", - "bitflags", + "bitflags 1.3.2", "bytes 1.4.0", "derive_more", "libp2p", @@ -6128,7 +6139,7 @@ version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -6141,7 +6152,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "libc", "memoffset 0.6.5", @@ -6153,7 +6164,7 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "libc", "static_assertions", @@ -6450,7 +6461,7 @@ version = "0.10.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "foreign-types", "libc", @@ -7307,7 +7318,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29f1b898011ce9595050a68e60f90bad083ff2987a695a42357134c8381fba70" dependencies = [ "bit-set", - "bitflags", + "bitflags 1.3.2", "byteorder", "lazy_static 1.4.0", "num-traits 0.2.15", @@ -7750,7 +7761,7 @@ version = "10.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c307f7aacdbab3f0adee67d52739a1d71112cc068d6fab169ddeb18e48877fad" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -7848,7 +7859,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -8241,14 +8252,27 @@ version = "0.36.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14e4d67015953998ad0eb82887a0eb0129e18a7e2f3b7b0f6c422fddcd503d62" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", - "linux-raw-sys", + "linux-raw-sys 0.1.4", "windows-sys 0.45.0", ] +[[package]] +name = "rustix" +version = "0.38.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0c3dde1fc030af041adc40e79c0e7fbcf431dd24870053d187d7c66e4b87453" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys 0.4.5", + "windows-sys 0.48.0", +] + [[package]] name = "rustls" version = "0.19.1" @@ -8298,7 +8322,7 @@ version = "9.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db7826789c0e25614b03e5a54a0717a86f9ff6e6e5247f92b369472869320039" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "clipboard-win", "dirs-next", @@ -8486,7 +8510,7 @@ version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -10055,7 +10079,7 @@ dependencies = [ "async-std", "async-trait", "bcs-ext", - "bitflags", + "bitflags 1.3.2", "bytes 1.4.0", "derive_more", "fnv", @@ -10788,6 +10812,7 @@ dependencies = [ "criterion-cpu-time", "log 0.4.17", "num_cpus", + "pprof", "proptest", "proptest-derive", "starcoin-crypto", @@ -11365,7 +11390,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75182f12f490e953596550b65ee31bda7c8e043d9386174b353bda50838c3fd" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "system-configuration-sys", ] @@ -12119,7 +12144,7 @@ version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23ed0a32c88b039b73f1b6c5acbd0554bfa5b6be94467375fd947c4de3a02271" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cassowary", "crossterm 0.22.1", "unicode-segmentation", @@ -12874,7 +12899,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f1db1727772c05cf7a2cfece52c3aca8045ca1e176cd517d323489aa3c6d87" dependencies = [ "async-trait", - "bitflags", + "bitflags 1.3.2", "bytes 1.4.0", "cc", "ipnet", @@ -12916,7 +12941,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e3810f0d00c4dccb54c30a4eee815e703232819dec7b007db115791c42aa374" dependencies = [ "base64 0.10.1", - "bitflags", + "bitflags 1.3.2", "byteorder", "bytes 0.4.12", "futures 0.1.31", diff --git a/vm/transaction-benchmarks/Cargo.toml b/vm/transaction-benchmarks/Cargo.toml index 91546f9e2b..9563744909 100644 --- a/vm/transaction-benchmarks/Cargo.toml +++ b/vm/transaction-benchmarks/Cargo.toml @@ -15,18 +15,20 @@ starcoin-crypto = { package = "starcoin-crypto", workspace = true } starcoin-types = { workspace = true } starcoin-vm-runtime = { workspace = true } starcoin-vm-types = { workspace = true } -criterion = { workspace = true, optional = true } +criterion = { workspace = true, optional = true, features = ["html_reports"] } proptest = { workspace = true, optional = true } proptest-derive = { workspace = true, optional = true } +pprof = { version = "0.10", optional = true, features = ["flamegraph", "criterion"] } log = { workspace = true } criterion-cpu-time = "0.1.0" starcoin-language-e2e-tests = { path = "../e2e-tests" } # move-deps = { path = "../../aptos-move/move-deps" } [dev-dependencies] -criterion = { workspace = true } +criterion = { workspace = true, features = ["html_reports"] } proptest = { workspace = true } proptest-derive = { workspace = true } +pprof = { version = "0.10", features = ["flamegraph", "criterion"] } [[bench]] name = "transaction_benches" @@ -37,5 +39,9 @@ required-features = ["fuzzing"] fuzzing = [ "criterion", "proptest", - "proptest-derive" + "proptest-derive", + "pprof" ] +flamegraph = [] +html_reports = [] + diff --git a/vm/transaction-benchmarks/benches/transaction_benches.rs b/vm/transaction-benchmarks/benches/transaction_benches.rs index 9d4552ed5b..481bdd42f7 100644 --- a/vm/transaction-benchmarks/benches/transaction_benches.rs +++ b/vm/transaction-benchmarks/benches/transaction_benches.rs @@ -1,18 +1,21 @@ // Copyright (c) Starcoin // SPDX-License-Identifier: Apache-2.0 +use std::fs::File; use criterion::{criterion_group, criterion_main, measurement::Measurement, Criterion}; use proptest::prelude::*; use starcoin_language_e2e_tests::account_universe::P2PTransferGen; use starcoin_transaction_benchmarks::{ - measurement::wall_time_measurement, transactions::TransactionBencher, + transactions::TransactionBencher, }; +use pprof::criterion::{Output, PProfProfiler}; // // Transaction benchmarks // + fn peer_to_peer(c: &mut Criterion) { - let default_num_accounts = 10_000; + let default_num_accounts = 1_000; let default_num_transactions = 10_000; c.bench_function("peer_to_peer", |b| { let bencher = TransactionBencher::new( @@ -20,22 +23,24 @@ fn peer_to_peer(c: &mut Criterion) { default_num_accounts, default_num_transactions, ); - bencher.bench(b) + bencher.bench(b); }); c.bench_function("peer_to_peer_parallel", |b| { + let bencher = TransactionBencher::new( any_with::((10_000, 10_000_000)), default_num_accounts, default_num_transactions, ); - bencher.bench_parallel(b) + bencher.bench_parallel(b); }); } criterion_group!( name = txn_benches; - config = wall_time_measurement().sample_size(10); + // config = wall_time_measurement().sample_size(10); + config = Criterion::default().with_profiler(PProfProfiler::new(10, Output::Flamegraph(None))); targets = peer_to_peer ); From a75c93e15f4a8b5e61018693c7e798a502bb09ca Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Fri, 8 Sep 2023 10:29:07 +0800 Subject: [PATCH 06/23] build_test.yml use branch tps_benchmark --- .github/workflows/build_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 5a7ffd728f..9fb08cdd7d 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -3,7 +3,7 @@ on: workflow_dispatch: pull_request: branches: - - master + - tps_benchmark jobs: build-and-test: From 02790a47c41d5c98a8566a525b401a765e132316 Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Fri, 8 Sep 2023 11:31:28 +0800 Subject: [PATCH 07/23] add stm flamegraph.sh --- .github/workflows/build_test.yml | 38 +++++--------------------------- scripts/stm_flamegraph.sh | 13 +++++++++++ 2 files changed, 18 insertions(+), 33 deletions(-) create mode 100755 scripts/stm_flamegraph.sh diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 9fb08cdd7d..1b69245860 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -15,44 +15,16 @@ jobs: uses: actions/checkout@v1 with: submodules: recursive - - name: run fmt check - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check - name: setup environment run: bash ./scripts/dev_setup.sh -b -t -y -m - name: run cargo clean uses: actions-rs/cargo@v1 with: command: clean - - name: run cargo check - uses: actions-rs/cargo@v1 + - name: run flamegraph + run: bash ./scripts/stm_flamegraph.sh env: - RUSTFLAGS: -D warnings - with: - command: clippy - args: --all-targets - - name: build - uses: actions-rs/cargo@v1 - with: - command: build - args: --all - - name: test - run: ./scripts/nextest.sh -# - name: check changed files -# run: bash ./scripts/changed_files.sh - - name: Doc Tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --doc - - name: integration test dev environment - env: - RUST_LOG: info + RUST_LOG: error RUST_BACKTRACE: full - STARCOIN_WS: ${{ secrets.STARCOIN_WS }} - uses: actions-rs/cargo@v1 - with: - command: test - args: --test integration -- -e cmd + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/scripts/stm_flamegraph.sh b/scripts/stm_flamegraph.sh new file mode 100755 index 0000000000..17682dfdc8 --- /dev/null +++ b/scripts/stm_flamegraph.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +STARCOIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)" + +if [[ "$(uname)" != "Linux" ]]; then + echo "run flamegraph only in linux. exit" +fi + + +cmd="cargo bench -p starcoin-transaction-benchmarks --features fuzzing" +echo "run flamegraph with cmd: ${cmd}" +eval "$cmd" + From 64ee94fb6e9399ddb74824758919be8900bd21fe Mon Sep 17 00:00:00 2001 From: welbon Date: Fri, 8 Sep 2023 11:57:20 +0800 Subject: [PATCH 08/23] [benchmark] Add flamegraph config for script --- scripts/stm_flamegraph.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/stm_flamegraph.sh b/scripts/stm_flamegraph.sh index 17682dfdc8..73a344c2fc 100755 --- a/scripts/stm_flamegraph.sh +++ b/scripts/stm_flamegraph.sh @@ -7,7 +7,7 @@ if [[ "$(uname)" != "Linux" ]]; then fi -cmd="cargo bench -p starcoin-transaction-benchmarks --features fuzzing" +cmd="cargo bench -p starcoin-transaction-benchmarks --features fuzzing,flamegraph" echo "run flamegraph with cmd: ${cmd}" eval "$cmd" From f131e232f8eac1bca2045eccb0612e793705426d Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Fri, 8 Sep 2023 14:08:25 +0800 Subject: [PATCH 09/23] optimize mod StarcoinVM log --- .../benches/transaction_benches.rs | 9 ++---- vm/transaction-benchmarks/src/transactions.rs | 6 +--- vm/vm-runtime/src/starcoin_vm.rs | 29 ++++++++++++------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/vm/transaction-benchmarks/benches/transaction_benches.rs b/vm/transaction-benchmarks/benches/transaction_benches.rs index 481bdd42f7..24a4d702a4 100644 --- a/vm/transaction-benchmarks/benches/transaction_benches.rs +++ b/vm/transaction-benchmarks/benches/transaction_benches.rs @@ -1,14 +1,12 @@ // Copyright (c) Starcoin // SPDX-License-Identifier: Apache-2.0 -use std::fs::File; use criterion::{criterion_group, criterion_main, measurement::Measurement, Criterion}; +use pprof::criterion::{Output, PProfProfiler}; use proptest::prelude::*; use starcoin_language_e2e_tests::account_universe::P2PTransferGen; -use starcoin_transaction_benchmarks::{ - transactions::TransactionBencher, -}; -use pprof::criterion::{Output, PProfProfiler}; +use starcoin_transaction_benchmarks::transactions::TransactionBencher; +use std::fs::File; // // Transaction benchmarks @@ -27,7 +25,6 @@ fn peer_to_peer(c: &mut Criterion) { }); c.bench_function("peer_to_peer_parallel", |b| { - let bencher = TransactionBencher::new( any_with::((10_000, 10_000_000)), default_num_accounts, diff --git a/vm/transaction-benchmarks/src/transactions.rs b/vm/transaction-benchmarks/src/transactions.rs index 1a7092c4d2..872cae3f4b 100644 --- a/vm/transaction-benchmarks/src/transactions.rs +++ b/vm/transaction-benchmarks/src/transactions.rs @@ -109,11 +109,7 @@ where let total_runs = num_warmups + num_runs; for i in 0..total_runs { - let state = TransactionBenchState::with_size( - &self.strategy, - num_accounts, - num_txn, - ); + let state = TransactionBenchState::with_size(&self.strategy, num_accounts, num_txn); if i < num_warmups { println!("WARMUP - ignore results"); diff --git a/vm/vm-runtime/src/starcoin_vm.rs b/vm/vm-runtime/src/starcoin_vm.rs index 37a54ddf30..f5754122e6 100644 --- a/vm/vm-runtime/src/starcoin_vm.rs +++ b/vm/vm-runtime/src/starcoin_vm.rs @@ -932,6 +932,7 @@ impl StarcoinVM { &self, storage: &S, txn: SignedUserTransaction, + use_stm: bool, ) -> (VMStatus, TransactionOutput) { let txn_data = match TransactionMetadata::new(&txn) { Ok(txn_data) => txn_data, @@ -979,17 +980,21 @@ impl StarcoinVM { }; match result { Ok(status_and_output) => { - log_vm_status( - txn.id(), - &txn_data, - &status_and_output.0, - Some(&status_and_output.1), - ); + if !use_stm { + log_vm_status( + txn.id(), + &txn_data, + &status_and_output.0, + Some(&status_and_output.1), + ); + } status_and_output } Err(err) => { let txn_status = TransactionStatus::from(err.clone()); - log_vm_status(txn.id(), &txn_data, &err, None); + if !use_stm { + log_vm_status(txn.id(), &txn_data, &err, None); + } if txn_status.is_discarded() { discard_error_vm_status(err) } else { @@ -1103,8 +1108,11 @@ impl StarcoinVM { .start_timer() }); let gas_unit_price = transaction.gas_unit_price(); - let (status, output) = self - .execute_user_transaction(&data_cache.as_move_resolver(), transaction); + let (status, output) = self.execute_user_transaction( + &data_cache.as_move_resolver(), + transaction, + false, + ); // only need to check for user transactions. match gas_left.checked_sub(output.gas_used()) { Some(l) => gas_left = l, @@ -1593,7 +1601,8 @@ impl VMAdapter for StarcoinVM { Ok(match txn { PreprocessedTransaction::UserTransaction(txn) => { let sender = txn.sender().to_string(); - let (vm_status, output) = self.execute_user_transaction(data_cache, *txn.clone()); + let (vm_status, output) = + self.execute_user_transaction(data_cache, *txn.clone(), true); // XXX FIXME YSG // let gas_unit_price = transaction.gas_unit_price(); think about gas_used OutOfGas (vm_status, output, Some(sender)) From 72f63a50f6f208da9937499f59a38621bb1357ba Mon Sep 17 00:00:00 2001 From: welbon Date: Fri, 8 Sep 2023 15:45:28 +0800 Subject: [PATCH 10/23] [benchmark] Add flamegraph file to github CI artifact after action completed --- .github/workflows/build_test.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 1b69245860..dca3709217 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -28,3 +28,10 @@ jobs: RUST_BACKTRACE: full AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + - name: upload flamegraph to artifact + uses: actions/upload-artifact@v2 + with: + name: flamegraph-artifact + path: | + ./target/criterion/peer_to_peer_parallel/profile/p2p-p.1.flamegraph.svg + ./target/criterion/peer_to_peer_parallel/profile/p2p-p-flamegraph.svg From cf5d7a6ff8e30d7de16a9dc2d10d2df13dc667ce Mon Sep 17 00:00:00 2001 From: welbon Date: Fri, 8 Sep 2023 16:04:25 +0800 Subject: [PATCH 11/23] [benchmark] Split the peer_to_peer benchmark into two targets --- .../benches/transaction_benches.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/vm/transaction-benchmarks/benches/transaction_benches.rs b/vm/transaction-benchmarks/benches/transaction_benches.rs index 24a4d702a4..a664d325ce 100644 --- a/vm/transaction-benchmarks/benches/transaction_benches.rs +++ b/vm/transaction-benchmarks/benches/transaction_benches.rs @@ -12,23 +12,26 @@ use std::fs::File; // Transaction benchmarks // +const DEFAULT_NUM_ACCOUNTS: usize = 1_000; +const DEFAULT_NUM_TRANSACTIONS: usize = 10_000; + fn peer_to_peer(c: &mut Criterion) { - let default_num_accounts = 1_000; - let default_num_transactions = 10_000; c.bench_function("peer_to_peer", |b| { let bencher = TransactionBencher::new( any_with::((10_000, 10_000_000)), - default_num_accounts, - default_num_transactions, + DEFAULT_NUM_ACCOUNTS, + DEFAULT_NUM_TRANSACTIONS, ); bencher.bench(b); }); +} +fn peer_to_peer_parallel(c: &mut Criterion) { c.bench_function("peer_to_peer_parallel", |b| { let bencher = TransactionBencher::new( any_with::((10_000, 10_000_000)), - default_num_accounts, - default_num_transactions, + DEFAULT_NUM_ACCOUNTS, + DEFAULT_NUM_TRANSACTIONS, ); bencher.bench_parallel(b); }); @@ -38,7 +41,7 @@ criterion_group!( name = txn_benches; // config = wall_time_measurement().sample_size(10); config = Criterion::default().with_profiler(PProfProfiler::new(10, Output::Flamegraph(None))); - targets = peer_to_peer + targets = peer_to_peer, peer_to_peer_parallel ); criterion_main!(txn_benches); From 9930e84f8e069233644ba07ad473e0af525ba6dc Mon Sep 17 00:00:00 2001 From: welbon Date: Fri, 8 Sep 2023 16:54:08 +0800 Subject: [PATCH 12/23] [benchmark] Split the peer_to_peer benchmark into two targets --- .github/workflows/build_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index dca3709217..74df275de9 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -33,5 +33,5 @@ jobs: with: name: flamegraph-artifact path: | - ./target/criterion/peer_to_peer_parallel/profile/p2p-p.1.flamegraph.svg - ./target/criterion/peer_to_peer_parallel/profile/p2p-p-flamegraph.svg + ./target/criterion/peer_to_peer/profile/flamegraph.svg + ./target/criterion/peer_to_peer_parallel/profile/flamegraph.svg From e00d4de1451e04b4a2c399a10b18da1840958cbe Mon Sep 17 00:00:00 2001 From: welbon Date: Fri, 8 Sep 2023 17:22:14 +0800 Subject: [PATCH 13/23] [benchmark] Split the peer_to_peer benchmark into two targets --- .github/workflows/build_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 74df275de9..6728d1ed33 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -33,5 +33,5 @@ jobs: with: name: flamegraph-artifact path: | - ./target/criterion/peer_to_peer/profile/flamegraph.svg - ./target/criterion/peer_to_peer_parallel/profile/flamegraph.svg + ./peer_to_peer/profile/flamegraph.svg + ./peer_to_peer_parallel/profile/flamegraph.svg From d8c760b483324fb800418b901eade98d276b3600 Mon Sep 17 00:00:00 2001 From: welbon Date: Fri, 8 Sep 2023 19:37:10 +0800 Subject: [PATCH 14/23] [benchmark] fix flamegraph output command --- scripts/stm_flamegraph.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/stm_flamegraph.sh b/scripts/stm_flamegraph.sh index 73a344c2fc..30cd8dd04d 100755 --- a/scripts/stm_flamegraph.sh +++ b/scripts/stm_flamegraph.sh @@ -7,7 +7,7 @@ if [[ "$(uname)" != "Linux" ]]; then fi -cmd="cargo bench -p starcoin-transaction-benchmarks --features fuzzing,flamegraph" +cmd="cargo bench -p starcoin-transaction-benchmarks --bench transaction_benches --features fuzzing,flamegraph -- --profile-time=20" echo "run flamegraph with cmd: ${cmd}" eval "$cmd" From aa81c3712af7c5e1e09d76e4f2302dcd0cc52ef0 Mon Sep 17 00:00:00 2001 From: welbon Date: Fri, 8 Sep 2023 19:38:57 +0800 Subject: [PATCH 15/23] [benchmark] fix flamegraph output command --- .github/workflows/build_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 6728d1ed33..74df275de9 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -33,5 +33,5 @@ jobs: with: name: flamegraph-artifact path: | - ./peer_to_peer/profile/flamegraph.svg - ./peer_to_peer_parallel/profile/flamegraph.svg + ./target/criterion/peer_to_peer/profile/flamegraph.svg + ./target/criterion/peer_to_peer_parallel/profile/flamegraph.svg From c2d708750f5ae83d2996ce26d5731c280776cc3b Mon Sep 17 00:00:00 2001 From: welbon Date: Thu, 21 Sep 2023 09:57:25 +0800 Subject: [PATCH 16/23] [benchmark-log] some logs for benchmark --- .../src/account_universe/peer_to_peer.rs | 2 + vm/mvhashmap/src/lib.rs | 35 +++++++++++---- vm/parallel-executor/src/executor.rs | 25 ++++++++++- vm/parallel-executor/src/scheduler.rs | 44 +++++++++++++++---- vm/transaction-benchmarks/src/main.rs | 4 +- 5 files changed, 90 insertions(+), 20 deletions(-) diff --git a/vm/e2e-tests/src/account_universe/peer_to_peer.rs b/vm/e2e-tests/src/account_universe/peer_to_peer.rs index 61e58ea6ab..400bbc0780 100644 --- a/vm/e2e-tests/src/account_universe/peer_to_peer.rs +++ b/vm/e2e-tests/src/account_universe/peer_to_peer.rs @@ -14,6 +14,7 @@ use starcoin_vm_types::language_storage::ModuleId; use starcoin_vm_types::transaction::{SignedUserTransaction, TransactionStatus}; use starcoin_vm_types::vm_status::{AbortLocation, StatusCode}; use std::sync::Arc; +use starcoin_vm_types::values::debug::print_locals; /// Represents a peer-to-peer transaction performed in the account universe. /// @@ -111,6 +112,7 @@ impl AUTransactionGen for P2PTransferGen { ); } } + println!("AUTransactionGen::apply | Exited: {:?}", status); (txn, (status, gas_used)) } } diff --git a/vm/mvhashmap/src/lib.rs b/vm/mvhashmap/src/lib.rs index 52fc6ff013..0273b48ad0 100644 --- a/vm/mvhashmap/src/lib.rs +++ b/vm/mvhashmap/src/lib.rs @@ -2,14 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 use crossbeam::utils::CachePadded; use dashmap::DashMap; -use std::{ - collections::btree_map::BTreeMap, - hash::Hash, - sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, - }, -}; +use std::{collections::btree_map::BTreeMap, hash::Hash, sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, +}, thread}; #[cfg(test)] mod unit_tests; @@ -77,6 +73,8 @@ impl MVHashMap { pub fn write(&self, key: &K, version: Version, data: V) { let (txn_idx, incarnation) = version; + println!("{:?} - MVHashMap::mark_estimate | Entered, version: {:?}", thread::current().id(), version); + let mut map = self.data.entry(key.clone()).or_insert(BTreeMap::new()); let prev_cell = map.insert( txn_idx, @@ -87,28 +85,39 @@ impl MVHashMap { assert!(prev_cell .map(|cell| cell.incarnation < incarnation) .unwrap_or(true)); + + println!("{:?} - MVHashMap::mark_estimate | Exited, version: {:?}", thread::current().id(), version); } /// Mark an entry from transaction 'txn_idx' at access path 'key' as an estimated write /// (for future incarnation). Will panic if the entry is not in the data-structure. pub fn mark_estimate(&self, key: &K, txn_idx: TxnIndex) { + println!("{:?} - MVHashMap::mark_estimate | Entered, txn_id: {:?}", thread::current().id(), txn_idx); + let map = self.data.get(key).expect("Path must exist"); map.get(&txn_idx) .expect("Entry by txn must exist") .mark_estimate(); + + println!("{:?} - MVHashMap::mark_estimate | Exited", thread::current().id()); } /// Delete an entry from transaction 'txn_idx' at access path 'key'. Will panic /// if the access path has never been written before. pub fn delete(&self, key: &K, txn_idx: TxnIndex) { + println!("{:?} - MVHashMap::delete | Exit, txn_idx: {:?}", thread::current().id(), txn_idx); + // TODO: investigate logical deletion. let mut map = self.data.get_mut(key).expect("Path must exist"); map.remove(&txn_idx); + + println!("{:?} - MVHashMap::delete | Exited, txn_idx: {:?}", thread::current().id(), txn_idx); } /// read may return Ok((Arc, txn_idx, incarnation)), Err(dep_txn_idx) for /// a dependency of transaction dep_txn_idx or Err(None) when no prior entry is found. pub fn read(&self, key: &K, txn_idx: TxnIndex) -> Result<(Version, Arc), Option> { + println!("{:?} - MVHashMap::read | Entered, txn_id: {:?}", thread::current().id(), txn_idx); match self.data.get(key) { Some(tree) => { // Find the dependency @@ -116,20 +125,28 @@ impl MVHashMap { if let Some((idx, write_cell)) = iter.next_back() { let flag = write_cell.flag(); + println!("{:?} - MVHashMap::read | flag: {}", thread::current().id(), flag); + if flag == FLAG_ESTIMATE { // Found a dependency. + println!("{:?} - MVHashMap::read | Exit, FLAG_ESTIMATE {}", thread::current().id(), idx); Err(Some(*idx)) } else { debug_assert!(flag == FLAG_DONE); + println!("{:?} - MVHashMap::read | Exit, FLAG_DONE {}", thread::current().id(), idx); // The entry is populated, return its contents. let write_version = (*idx, write_cell.incarnation); Ok((write_version, write_cell.data.clone())) } } else { + println!("{:?} - MVHashMap::read | Exit, iter.next_back() -> Err(None)", thread::current().id()); Err(None) } } - None => Err(None), + None => { + println!("{:?} - MVHashMap::read | Exit, self.data.get(key) -> Err(None)", thread::current().id()); + Err(None) + } } } } diff --git a/vm/parallel-executor/src/executor.rs b/vm/parallel-executor/src/executor.rs index 17f69c91cd..1f52bd6a81 100644 --- a/vm/parallel-executor/src/executor.rs +++ b/vm/parallel-executor/src/executor.rs @@ -12,7 +12,8 @@ use num_cpus; use once_cell::sync::Lazy; use starcoin_infallible::Mutex; use starcoin_mvhashmap::MVHashMap; -use std::{collections::HashSet, hash::Hash, marker::PhantomData, sync::Arc, thread::spawn}; +use std::{collections::HashSet, hash::Hash, marker::PhantomData, sync::Arc, thread, thread::spawn}; +use std::any::Any; static RAYON_EXEC_POOL: Lazy = Lazy::new(|| { rayon::ThreadPoolBuilder::new() @@ -45,6 +46,7 @@ impl<'a, K: PartialOrd + Send + Clone + Hash + Eq, V: Send + Sync> MVHashMapView /// Captures a read from the VM execution. pub fn read(&self, key: &K) -> Option> { + println!("{:?} - MVHashMapView::read | Entered, {}", thread::current().id(), self.txn_idx); loop { match self.versioned_map.read(key, self.txn_idx) { Ok((version, v)) => { @@ -54,12 +56,15 @@ impl<'a, K: PartialOrd + Send + Clone + Hash + Eq, V: Send + Sync> MVHashMapView txn_idx, incarnation, )); + println!("{:?} - MVHashMapView::read | Exited, {} -> Some(v)", thread::current().id(), self.txn_idx); return Some(v); } Err(None) => { self.captured_reads .lock() .push(ReadDescriptor::from_storage(key.clone())); + + println!("{:?} - MVHashMapView::read | Exited, {}, -> None", thread::current().id(), self.txn_idx); return None; } Err(Some(dep_idx)) => { @@ -140,6 +145,9 @@ where executor: &E, ) -> SchedulerTask<'a> { let (idx_to_execute, incarnation) = version; + + println!("{:?} - MVHashMap::execute | Entered, idx_to_execute:{:?}, incarnation: {:?}", thread::current().id(), idx_to_execute, incarnation); + let txn = &signature_verified_block[idx_to_execute]; let state_view = MVHashMapView { @@ -153,6 +161,8 @@ where let execute_result = executor.execute_transaction(&state_view, txn); let mut prev_write_set: HashSet = last_input_output.write_set(idx_to_execute); + println!("{:?} - MVHashMap::execute | after executor.execute_transaction, execute_result: {:?}", thread::current().id(), execute_result.type_id()); + // For tracking whether the recent execution wrote outside of the previous write set. let mut writes_outside = false; let mut apply_writes = |output: &::Output| { @@ -192,6 +202,8 @@ where } last_input_output.record(idx_to_execute, state_view.take_reads(), result); + + println!("{:?} - ParallelTransactionExecutor::execute | Exited, idx_to_execute:{:?}, incarnation: {:?}", thread::current().id(), idx_to_execute, incarnation); scheduler.finish_execution(idx_to_execute, incarnation, writes_outside, guard) } @@ -207,6 +219,8 @@ where versioned_data_cache: &MVHashMap<::Key, ::Value>, scheduler: &'a Scheduler, ) -> SchedulerTask<'a> { + println!("{:?} - ParallelTransactionExecutor::validate | Entered {:?}", thread::current().id(), version_to_validate); + let (idx_to_validate, incarnation) = version_to_validate; let read_set = last_input_output .read_set(idx_to_validate) @@ -222,16 +236,21 @@ where let aborted = !valid && scheduler.try_abort(idx_to_validate, incarnation); + println!("{:?} - ParallelTransactionExecutor::validate | valid: {}, aborted: {}", thread::current().id(), valid, aborted); + if aborted { // Not valid and successfully aborted, mark the latest write-set as estimates. for k in &last_input_output.write_set(idx_to_validate) { versioned_data_cache.mark_estimate(k, idx_to_validate); } + println!("{:?} - ParallelTransactionExecutor::validate | Exited, aborted == true", thread::current().id()); scheduler.finish_abort(idx_to_validate, incarnation, guard) } else { + println!("{:?} - ParallelTransactionExecutor::validate | Exited, SchedulerTask::NoTask", thread::current().id()); SchedulerTask::NoTask } + } fn work_task_with_scope( @@ -249,6 +268,8 @@ where // Make executor for each task. TODO: fast concurrent executor. let executor = E::init(*executor_arguments); + println!("{:?} - ParallelTransactionExecutor::work_task_with_scope | Entered", thread::current().id()); + let mut scheduler_task = SchedulerTask::NoTask; loop { scheduler_task = match scheduler_task { @@ -283,6 +304,8 @@ where } } } + + println!("{:?} - ParallelTransactionExecutor::work_task_with_scope | Exited", thread::current().id()); } pub fn execute_transactions_parallel( diff --git a/vm/parallel-executor/src/scheduler.rs b/vm/parallel-executor/src/scheduler.rs index 1daa40c757..9d9f15a563 100644 --- a/vm/parallel-executor/src/scheduler.rs +++ b/vm/parallel-executor/src/scheduler.rs @@ -3,14 +3,10 @@ use crossbeam::utils::CachePadded; use starcoin_infallible::Mutex; -use std::{ - cmp::min, - hint, - sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, - Arc, Condvar, - }, -}; +use std::{cmp::min, hint, sync::{ + atomic::{AtomicBool, AtomicUsize, Ordering}, + Arc, Condvar, +}, thread}; // Type aliases. pub type TxnIndex = usize; @@ -167,35 +163,45 @@ impl Scheduler { /// returns false. Since incarnation numbers never decrease, this also ensures /// that the same version may not successfully abort more than once. pub fn try_abort(&self, txn_idx: TxnIndex, incarnation: Incarnation) -> bool { + println!("{:?} - Scheduler::try_abort | Entered, txn_idx: {:?}, incarnation: {:?}", thread::current().id(), txn_idx, incarnation); // lock the status. let mut status = self.txn_status[txn_idx].lock(); + println!("{:?} - Scheduler::try_abort | Status: {:?} ", thread::current().id(), status); if *status == TransactionStatus::Executed(incarnation) { *status = TransactionStatus::Aborting(incarnation); + println!("{:?} - Scheduler::try_abort | Exited, status == Executed", thread::current().id()); true } else { + println!("{:?} - Scheduler::try_abort | Exited, status != Executed", thread::current().id()); false } } /// Return the next task for the thread. pub fn next_task(&self) -> SchedulerTask { + println!("{:?} - Scheduler::next_task | Entered", thread::current().id()); loop { if self.done() { // No more tasks. + println!("{:?} - Scheduler::next_task | Exited, has SchedulerTask::Done", thread::current().id()); return SchedulerTask::Done; } let idx_to_validate = self.validation_idx.load(Ordering::SeqCst); let idx_to_execute = self.execution_idx.load(Ordering::SeqCst); + println!("{:?} - Scheduler::next_task | idx_to_validate: {}, idx_to_execute: {}", thread::current().id(), idx_to_validate, idx_to_execute); + if idx_to_validate < idx_to_execute { if let Some((version_to_validate, guard)) = self.try_validate_next_version() { + println!("{:?} - Scheduler::next_task | Exited: SchedulerTask::ValidationTask", thread::current().id()); return SchedulerTask::ValidationTask(version_to_validate, guard); } } else if let Some((version_to_execute, maybe_condvar, guard)) = self.try_execute_next_version() { + println!("{:?} - Scheduler::next_task | Exited: SchedulerTask::ExecutionTask", thread::current().id()); return SchedulerTask::ExecutionTask(version_to_execute, maybe_condvar, guard); } } @@ -215,6 +221,8 @@ impl Scheduler { // Note: Could pre-check that txn dep_txn_idx isn't in an executed state, but the caller // usually has just observed the read dependency. + println!("{:?} - Scheduler::wait_for_dependency | Entered, txn_idx: {:#?}, dep_txn_idx: {:#?}", thread::current().id(), txn_idx, dep_txn_idx); + // Create a condition variable associated with the dependency. let dep_condvar = Arc::new((Mutex::new(false), Condvar::new())); @@ -230,6 +238,7 @@ impl Scheduler { // Only place in scheduler where a thread may hold >1 mutexes, hence, such // acquisitions always happens in the same order (this function), may not deadlock. + println!("{:?} - Scheduler::wait_for_dependency | Exited, return None", thread::current().id(),); return None; } @@ -240,6 +249,7 @@ impl Scheduler { stored_deps.push(txn_idx); } + println!("{:?} - Scheduler::wait_for_dependency | Exited, return Some(dep_condvar), condvar index: {:?}", thread::current().id(), txn_idx); Some(dep_condvar) } @@ -254,6 +264,8 @@ impl Scheduler { revalidate_suffix: bool, guard: TaskGuard<'a>, ) -> SchedulerTask<'a> { + println!("{:?} - Scheduler::finish_execution | Entered, txn_id: {:?}, incarnation: {:?} ", thread::current().id(), txn_idx, incarnation); + self.set_executed_status(txn_idx, incarnation); let txn_deps: Vec = { @@ -273,6 +285,7 @@ impl Scheduler { dep }) .min(); + if let Some(execution_target_idx) = min_dep { // Decrease the execution index as necessary to ensure resolved dependencies // get a chance to be re-executed. @@ -290,10 +303,14 @@ impl Scheduler { } else { // Only transaction txn_idx requires validation. Return validation task // back to the caller. No need to change active tasks (-1 +1= 0) + println!("{:?} - Scheduler::finish_execution | Exited, ValidationTask", thread::current().id()); + return SchedulerTask::ValidationTask((txn_idx, incarnation), guard); } } + println!("{:?} - Scheduler::finish_execution | Exited, NoTask", thread::current().id()); + SchedulerTask::NoTask } @@ -320,6 +337,8 @@ impl Scheduler { // nothing to do, as another thread must have succeeded to incarnate and // obtain the task for re-execution. if let Some((new_incarnation, maybe_condvar)) = self.try_incarnate(txn_idx) { + println!("{:?} - Scheduler::finish_abort | Exited, ExecutionTask", thread::current().id()); + return SchedulerTask::ExecutionTask( (txn_idx, new_incarnation), maybe_condvar, @@ -328,6 +347,8 @@ impl Scheduler { } } + println!("{:?} - Scheduler::finish_abort | Exited, NoTask", thread::current().id()); + SchedulerTask::NoTask } } @@ -461,12 +482,15 @@ impl Scheduler { /// incremented incarnation number. /// The caller must ensure that the transaction is in the Suspended state. fn resume(&self, txn_idx: TxnIndex) { + println!("{:?} - Scheduler::resume | Entered, txn_id: {:?} ", thread::current().id(), txn_idx); + let mut status = self.txn_status[txn_idx].lock(); if let TransactionStatus::Suspended(incarnation, dep_condvar) = &*status { *status = TransactionStatus::ReadyToExecute(*incarnation, Some(dep_condvar.clone())); } else { unreachable!(); } + println!("{:?} - Scheduler::resume | Exited, txn_id: {:?} ", thread::current().id(), txn_idx); } /// Set status of the transaction to Executed(incarnation). @@ -482,12 +506,16 @@ impl Scheduler { /// After a successful abort, mark the transaction as ready for re-execution with /// an incremented incarnation number. fn set_aborted_status(&self, txn_idx: TxnIndex, incarnation: Incarnation) { + println!("{:?} - Scheduler::set_aborted_status | Entered, txn_id: {:?}, incarnation: {:?}", thread::current().id(), txn_idx, incarnation); + let mut status = self.txn_status[txn_idx].lock(); // Only makes sense when the current status is 'Aborting'. debug_assert!(*status == TransactionStatus::Aborting(incarnation)); *status = TransactionStatus::ReadyToExecute(incarnation + 1, None); + + println!("{:?} - Scheduler::set_aborted_status | Exited, txn_id: {:?}, incarnation: {:?}", thread::current().id(), txn_idx, incarnation); } /// A lazy, check of whether the scheduler execution is completed. diff --git a/vm/transaction-benchmarks/src/main.rs b/vm/transaction-benchmarks/src/main.rs index e06d8ce89a..dc26584945 100644 --- a/vm/transaction-benchmarks/src/main.rs +++ b/vm/transaction-benchmarks/src/main.rs @@ -13,8 +13,8 @@ fn main() { default_num_transactions, ); - let acts = [2, 10, 100, 1000, 10000]; - let txns = [1000, 10000]; + let acts = [2]; + let txns = [1000]; let num_warmups = 2; let num_runs = 10; From d9bcc7418cd2ac0620911fd6d4c75da4ccac5f34 Mon Sep 17 00:00:00 2001 From: welbon Date: Fri, 22 Sep 2023 22:57:36 +0800 Subject: [PATCH 17/23] [benchmark-log] fixed account layout for e2e-test --- vm/e2e-tests/Cargo.toml | 10 - vm/e2e-tests/src/account.rs | 417 ++++++++++++------ vm/e2e-tests/src/account_universe.rs | 2 +- .../src/account_universe/create_account.rs | 2 +- .../src/account_universe/peer_to_peer.rs | 1 - vm/e2e-tests/src/common_transactions.rs | 17 +- vm/e2e-tests/src/data_store.rs | 6 +- vm/e2e-tests/src/executor.rs | 10 +- vm/e2e-tests/src/gas_costs.rs | 10 +- vm/e2e-tests/src/proptest_types.rs | 2 +- vm/mvhashmap/src/lib.rs | 60 ++- vm/parallel-executor/src/executor.rs | 52 ++- vm/parallel-executor/src/scheduler.rs | 111 ++++- vm/transaction-benchmarks/Cargo.toml | 1 - vm/transaction-benchmarks/src/main.rs | 10 +- vm/transaction-benchmarks/src/transactions.rs | 4 +- vm/vm-runtime/src/errors.rs | 2 + .../src/parallel_executor/vm_wrapper.rs | 2 +- 18 files changed, 485 insertions(+), 234 deletions(-) diff --git a/vm/e2e-tests/Cargo.toml b/vm/e2e-tests/Cargo.toml index 6d765b7d62..a86789665f 100644 --- a/vm/e2e-tests/Cargo.toml +++ b/vm/e2e-tests/Cargo.toml @@ -39,13 +39,3 @@ move-table-extension = { workspace = true } starcoin-statedb = { workspace = true } starcoin-state-tree = { workspace = true } -#aptos-keygen = { path = "../../crates/aptos-keygen" } -#aptos-proptest-helpers = { path = "../../crates/aptos-proptest-helpers" } -#aptos-state-view = { path = "../../storage/state-view" } -#aptos-transaction-builder = { path = "../../sdk/transaction-builder" } -#aptos-types = { path = "../../types", features = ["fuzzing"] } -#aptos-vm = { path = "../aptos-vm" } -# aptos-writeset-generator = { path = "../writeset-transaction-generator" } -# cached-framework-packages = { path = "../framework/cached-packages" } -# move-deps = { path = "../move-deps", features = ["address32"] } -# vm-genesis = { path = "../vm-genesis" } diff --git a/vm/e2e-tests/src/account.rs b/vm/e2e-tests/src/account.rs index 4eeb3bfe77..e79a25d251 100644 --- a/vm/e2e-tests/src/account.rs +++ b/vm/e2e-tests/src/account.rs @@ -7,44 +7,56 @@ use crate::gas_costs; use anyhow::{Error, Result}; use starcoin_crypto::ed25519::{Ed25519PrivateKey, Ed25519PublicKey}; use starcoin_crypto::keygen::KeyGen; +use starcoin_crypto::ValidCryptoMaterial; +use starcoin_types::account::{Balance, EventHandleGenerator}; use starcoin_vm_types::access_path::AccessPath; use starcoin_vm_types::account_address::AccountAddress; +use starcoin_vm_types::account_config; use starcoin_vm_types::account_config::{genesis_address, AccountResource, BalanceResource}; use starcoin_vm_types::event::EventHandle; use starcoin_vm_types::genesis_config::ChainId; use starcoin_vm_types::language_storage::StructTag; use starcoin_vm_types::move_resource::MoveResource; use starcoin_vm_types::state_store::state_key::StateKey; -use starcoin_vm_types::transaction::authenticator::AuthenticationKey; +use starcoin_vm_types::token::token_code::TokenCode; +use starcoin_vm_types::transaction::authenticator::{ + AccountPrivateKey, AccountPublicKey +}; use starcoin_vm_types::transaction::{ RawUserTransaction, Script, ScriptFunction, SignedUserTransaction, TransactionPayload, }; use starcoin_vm_types::value::{MoveStructLayout, MoveTypeLayout}; use starcoin_vm_types::values::{Struct, Value}; use starcoin_vm_types::write_set::{WriteOp, WriteSet, WriteSetMut}; +use std::collections::BTreeMap; use std::str::FromStr; +use std::sync::Arc; // TTL is 86400s. Initial time was set to 0. pub const DEFAULT_EXPIRATION_TIME: u64 = 40_000; -/// Details about a Aptos account. +pub const STC_TOKEN_CODE_STR: &str = "0x1::STC::STC"; + +/// Details about a Starcoin account. /// /// Tests will typically create a set of `Account` instances to run transactions on. This type -/// encodes the logic to operate on and verify operations on any Aptos account. +/// encodes the logic to operate on and verify operations on any Starcoin account. #[derive(Debug, Clone, Eq, PartialEq)] pub struct Account { - addr: AccountAddress, - /// The current private key for this account. - pub privkey: Ed25519PrivateKey, - /// The current public key for this account. - pub pubkey: Ed25519PublicKey, + // addr: AccountAddress, + // /// The current private key for this account. + // pub privkey: Ed25519PrivateKey, + // /// The current public key for this account. + // pub pubkey: Ed25519PublicKey, + pub addr: AccountAddress, + private_key: Arc, } impl Account { /// Creates a new account in memory. /// /// The account returned by this constructor is a purely logical entity, meaning that it does - /// not automatically get added to the Aptos store. To add an account to the store, use + /// not automatically get added to the Starcoin store. To add an account to the store, use /// [`AccountData`] instances with /// [`FakeExecutor::add_account_data`][crate::executor::FakeExecutor::add_account_data]. /// This function returns distinct values upon every call. @@ -67,11 +79,22 @@ impl Account { let addr = starcoin_vm_types::account_address::from_public_key(&pubkey); Account { addr, - privkey, - pubkey, + private_key: Arc::new(AccountPrivateKey::Single(privkey)), + // pubkey, } } + /// Get the Key pair + pub fn ed25519_key_pair(&self) -> (Ed25519PublicKey, Ed25519PrivateKey) { + ( + self.private_key.public_key().as_single().unwrap(), + match self.private_key.as_ref() { + AccountPrivateKey::Single(pk) => pk.clone(), + AccountPrivateKey::Multi(pk) => pk.private_keys().get(0).unwrap().clone(), + }, + ) + } + /// Creates a new account with the given addr and key pair /// /// Like with [`Account::new`], the account returned by this constructor is a purely logical @@ -79,12 +102,12 @@ impl Account { pub fn new_validator( addr: AccountAddress, privkey: Ed25519PrivateKey, - pubkey: Ed25519PublicKey, + _pubkey: Ed25519PublicKey, ) -> Self { Account { addr, - privkey, - pubkey, + private_key: Arc::new(AccountPrivateKey::Single(privkey)), + // pubkey, } } @@ -98,11 +121,10 @@ impl Account { // pubkey: GENESIS_KEYPAIR.1.clone(), // privkey: GENESIS_KEYPAIR.0.clone(), // } - let (privkey, pubkey) = KeyGen::from_os_rng().generate_keypair(); + let (privkey, _pubkey) = KeyGen::from_os_rng().generate_keypair(); Account { addr: address, - pubkey, - privkey, + private_key: Arc::new(AccountPrivateKey::Single(privkey)), } } @@ -122,20 +144,17 @@ impl Account { &self.addr } - /// Returns the AccessPath that describes the Account resource instance. - /// - /// Use this to retrieve or publish the Account blob. - pub fn make_account_access_path(&self) -> AccessPath { - self.make_access_path(AccountResource::struct_tag()) - } - - /// Returns the AccessPath that describes the Account's CoinStore resource instance. + /// Returns the AccessPath that describes the Account balance resource instance. /// - /// Use this to retrieve or publish the Account CoinStore blob. - pub fn make_coin_store_access_path(&self) -> AccessPath { - // TODO(BobOng): - // self.make_access_path(CoinStoreResource::struct_tag()) - self.make_access_path(BalanceResource::struct_tag()) + /// Use this to retrieve or publish the Account balance blob. + pub fn make_balance_access_path(&self, token_code_str: &str) -> AccessPath { + let token_code = + TokenCode::from_str(token_code_str).expect("token code str should been valid."); + let token_type_tag = token_code + .try_into() + .expect("token code to type tag should be ok"); + // TODO/XXX: Convert this to BalanceResource::struct_tag once that takes type args + self.make_access_path(BalanceResource::struct_tag_for_token(token_type_tag)) } // TODO: plug in the account type @@ -145,22 +164,60 @@ impl Account { AccessPath::resource_access_path(self.addr, tag) } + pub fn make_account_access_path(&self) -> AccessPath { + self.make_access_path(AccountResource::struct_tag()) + } + + /// Returns the AccessPath that describes the EventHandleGenerator resource instance. + /// + /// Use this to retrieve or publish the EventHandleGenerator blob. + pub fn make_event_generator_access_path(&self) -> AccessPath { + self.make_access_path(account_config::event_handle_generator_struct_tag()) + } + /// Changes the keys for this account to the provided ones. - pub fn rotate_key(&mut self, privkey: Ed25519PrivateKey, pubkey: Ed25519PublicKey) { - self.privkey = privkey; - self.pubkey = pubkey; + pub fn rotate_key(&mut self, privkey: Ed25519PrivateKey, _pubkey: Ed25519PublicKey) { + // self.privkey = privkey; + // self.pubkey = pubkey; + self.private_key = Arc::new(AccountPrivateKey::Single(privkey)); } /// Computes the authentication key for this account, as stored on the chain. /// /// This is the same as the account's address if the keys have never been rotated. pub fn auth_key(&self) -> Vec { - AuthenticationKey::ed25519(&self.pubkey).to_vec() + self.private_key.public_key().authentication_key().to_vec() + } + + pub fn public_key(&self) -> Ed25519PublicKey { + match self.private_key.as_ref() { + AccountPrivateKey::Single(k) => Ed25519PublicKey::from(k), + AccountPrivateKey::Multi(k) => k.public_key().public_keys().get(0).unwrap().clone(), + } + } + + pub fn private_key(&self) -> &AccountPrivateKey { + &self.private_key } pub fn transaction(&self) -> TransactionBuilder { TransactionBuilder::new(self.clone()) } + + pub fn account_keypair(&self) -> (AccountPublicKey, AccountPrivateKey) { + let (pub_key, priv_key) = self.ed25519_key_pair(); + ( + AccountPublicKey::Single(pub_key), + AccountPrivateKey::Single(priv_key), + ) + } + + pub fn public_key_bytes(&self) -> Vec { + match self.private_key.as_ref() { + AccountPrivateKey::Single(public_key) => public_key.to_bytes().to_vec(), + AccountPrivateKey::Multi(public_key) => public_key.to_bytes().to_vec(), + } + } } impl Default for Account { @@ -263,6 +320,7 @@ impl TransactionBuilder { } pub fn sign(self) -> SignedUserTransaction { + let (public_key, private_key) = self.sender.ed25519_key_pair(); RawUserTransaction::new_with_default_gas_token( *self.sender.address(), self.sequence_number.expect("sequence number not set"), @@ -272,7 +330,7 @@ impl TransactionBuilder { self.ttl.unwrap_or(DEFAULT_EXPIRATION_TIME), self.chain_id.unwrap_or_else(ChainId::test), ) - .sign(&self.sender.privkey, self.sender.pubkey) + .sign(&private_key, public_key) .unwrap() .into_inner() } @@ -307,64 +365,64 @@ impl TransactionBuilder { // .into_inner() // } } - -//--------------------------------------------------------------------------- -// CoinStore resource represenation -//--------------------------------------------------------------------------- - -/// Struct that represents an account CoinStore resource for tests. -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct CoinStore { - coin: u64, - deposit_events: EventHandle, - withdraw_events: EventHandle, -} - -impl CoinStore { - /// Create a new CoinStore - pub fn new(coin: u64, deposit_events: EventHandle, withdraw_events: EventHandle) -> Self { - Self { - coin, - deposit_events, - withdraw_events, - } - } - - /// Retrieve the balance inside of this - pub fn coin(&self) -> u64 { - self.coin - } - - /// Returns the Move Value for the account's CoinStore - pub fn to_value(&self) -> Value { - Value::struct_(Struct::pack(vec![ - Value::u64(self.coin), - Value::struct_(Struct::pack(vec![ - Value::u64(self.withdraw_events.count()), - Value::vector_u8(self.withdraw_events.key().to_vec()), - ])), - Value::struct_(Struct::pack(vec![ - Value::u64(self.deposit_events.count()), - Value::vector_u8(self.deposit_events.key().to_vec()), - ])), - ])) - } - - /// Returns the value layout for the account's CoinStore - pub fn layout() -> MoveStructLayout { - MoveStructLayout::new(vec![ - MoveTypeLayout::U64, - MoveTypeLayout::Struct(MoveStructLayout::new(vec![ - MoveTypeLayout::U64, - MoveTypeLayout::Vector(Box::new(MoveTypeLayout::U8)), - ])), - MoveTypeLayout::Struct(MoveStructLayout::new(vec![ - MoveTypeLayout::U64, - MoveTypeLayout::Vector(Box::new(MoveTypeLayout::U8)), - ])), - ]) - } -} +// +// //--------------------------------------------------------------------------- +// // CoinStore resource represenation +// //--------------------------------------------------------------------------- +// +// /// Struct that represents an account CoinStore resource for tests. +// #[derive(Clone, Debug, Eq, PartialEq)] +// pub struct CoinStore { +// coin: u64, +// deposit_events: EventHandle, +// withdraw_events: EventHandle, +// } +// +// impl CoinStore { +// /// Create a new CoinStore +// pub fn new(coin: u64, deposit_events: EventHandle, withdraw_events: EventHandle) -> Self { +// Self { +// coin, +// deposit_events, +// withdraw_events, +// } +// } +// +// /// Retrieve the balance inside of this +// pub fn coin(&self) -> u64 { +// self.coin +// } +// +// /// Returns the Move Value for the account's CoinStore +// pub fn to_value(&self) -> Value { +// Value::struct_(Struct::pack(vec![ +// Value::u64(self.coin), +// Value::struct_(Struct::pack(vec![ +// Value::u64(self.withdraw_events.count()), +// Value::vector_u8(self.withdraw_events.key().to_vec()), +// ])), +// Value::struct_(Struct::pack(vec![ +// Value::u64(self.deposit_events.count()), +// Value::vector_u8(self.deposit_events.key().to_vec()), +// ])), +// ])) +// } +// +// /// Returns the value layout for the account's CoinStore +// pub fn layout() -> MoveStructLayout { +// MoveStructLayout::new(vec![ +// MoveTypeLayout::U64, +// MoveTypeLayout::Struct(MoveStructLayout::new(vec![ +// MoveTypeLayout::U64, +// MoveTypeLayout::Vector(Box::new(MoveTypeLayout::U8)), +// ])), +// MoveTypeLayout::Struct(MoveStructLayout::new(vec![ +// MoveTypeLayout::U64, +// MoveTypeLayout::Vector(Box::new(MoveTypeLayout::U8)), +// ])), +// ]) +// } +// } //--------------------------------------------------------------------------- // Account type represenation @@ -372,7 +430,7 @@ impl CoinStore { #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum AccountRoleSpecifier { - AptosRoot, + Root, TreasuryCompliance, DesignatedDealer, Validator, @@ -384,7 +442,7 @@ pub enum AccountRoleSpecifier { impl AccountRoleSpecifier { pub fn id(&self) -> u64 { match self { - Self::AptosRoot => 0, + Self::Root => 0, Self::TreasuryCompliance => 1, Self::DesignatedDealer => 2, Self::Validator => 3, @@ -455,13 +513,22 @@ impl AccountRole { /// `AccountData` captures the initial state needed to create accounts for tests. #[derive(Clone, Debug, Eq, PartialEq)] pub struct AccountData { + // account: Account, + // withdrawal_capability: Option, + // key_rotation_capability: Option, + // sequence_number: u64, + // + // coin_store: CoinStore, + // account_role: AccountRole, account: Account, - withdrawal_capability: Option, - key_rotation_capability: Option, sequence_number: u64, - - coin_store: CoinStore, - account_role: AccountRole, + key_rotation_capability: Option, + withdrawal_capability: Option, + withdraw_events: EventHandle, + deposit_events: EventHandle, + accept_token_events: EventHandle, + balances: BTreeMap, + event_generator: EventHandleGenerator, } fn new_event_handle(count: u64, address: AccountAddress) -> EventHandle { @@ -472,7 +539,7 @@ impl AccountData { /// Creates a new `AccountData` with a new account. /// /// This constructor is non-deterministic and should not be used against golden file. - pub fn new(balance: u64, sequence_number: u64) -> Self { + pub fn new(balance: u128, sequence_number: u64) -> Self { Self::with_account( Account::new(), balance, @@ -484,7 +551,7 @@ impl AccountData { /// Creates a new `AccountData` with a new account. /// /// Most tests will want to use this constructor. - pub fn new_from_seed(seed: &mut KeyGen, balance: u64, sequence_number: u64) -> Self { + pub fn new_from_seed(seed: &mut KeyGen, balance: u128, sequence_number: u64) -> Self { Self::with_account( Account::new_from_seed(seed), balance, @@ -496,7 +563,7 @@ impl AccountData { /// Creates a new `AccountData` with the provided account. pub fn with_account( account: Account, - balance: u64, + balance: u128, sequence_number: u64, account_specifier: AccountRoleSpecifier, ) -> Self { @@ -514,7 +581,7 @@ impl AccountData { pub fn with_keypair( privkey: Ed25519PrivateKey, pubkey: Ed25519PublicKey, - balance: u64, + balance: u128, sequence_number: u64, account_specifier: AccountRoleSpecifier, ) -> Self { @@ -525,24 +592,25 @@ impl AccountData { /// Creates a new `AccountData` with custom parameters. pub fn with_account_and_event_counts( account: Account, - balance: u64, + balance: u128, sequence_number: u64, sent_events_count: u64, received_events_count: u64, - account_specifier: AccountRoleSpecifier, + _account_specifier: AccountRoleSpecifier, ) -> Self { let addr = *account.address(); + let mut balances_map = BTreeMap::new(); + balances_map.insert(STC_TOKEN_CODE_STR.to_string(), Balance::new(balance)); Self { - account_role: AccountRole::new(*account.address(), account_specifier), - withdrawal_capability: Some(WithdrawCapability::new(addr)), - key_rotation_capability: Some(KeyRotationCapability::new(addr)), + event_generator: EventHandleGenerator::new_with_event_count(addr, 3), account, - coin_store: CoinStore::new( - balance, - new_event_handle(received_events_count, addr), - new_event_handle(sent_events_count, addr), - ), + balances: balances_map, sequence_number, + key_rotation_capability: None, + withdrawal_capability: Some(WithdrawCapability::new(addr)), + withdraw_events: EventHandle::new_from_address(&addr, sent_events_count), + deposit_events: EventHandle::new_from_address(&addr, received_events_count), + accept_token_events: EventHandle::new_from_address(&addr, 0), } } @@ -551,29 +619,87 @@ impl AccountData { self.account.rotate_key(privkey, pubkey) } + pub fn sent_payment_event_layout() -> MoveStructLayout { + MoveStructLayout::new(vec![ + MoveTypeLayout::U128, + MoveTypeLayout::Address, + MoveTypeLayout::Vector(Box::new(MoveTypeLayout::U8)), + ]) + } + + pub fn received_payment_event_type() -> MoveStructLayout { + MoveStructLayout::new(vec![ + MoveTypeLayout::U128, + MoveTypeLayout::Address, + MoveTypeLayout::Vector(Box::new(MoveTypeLayout::U8)), + ]) + } + + pub fn event_handle_layout() -> MoveStructLayout { + MoveStructLayout::new(vec![ + MoveTypeLayout::U64, + MoveTypeLayout::Vector(Box::new(MoveTypeLayout::U8)), + ]) + } + /// Returns the (Move value) layout of the Account::Account struct pub fn layout() -> MoveStructLayout { use MoveStructLayout as S; use MoveTypeLayout as T; - S::new(vec![T::Vector(Box::new(T::U8)), T::U64, T::Address]) + S::new(vec![ + T::Vector(Box::new(T::U8)), + T::Vector(Box::new(T::Struct(WithdrawCapability::layout()))), + T::Vector(Box::new(T::Struct(KeyRotationCapability::layout()))), + T::Struct(Self::event_handle_layout()), + T::Struct(Self::event_handle_layout()), + T::Struct(Self::event_handle_layout()), + T::U64, + ]) } /// Returns the account role specifier pub fn account_role(&self) -> AccountRoleSpecifier { - self.account_role.account_specifier() + //self.account_role.account_specifier() + AccountRoleSpecifier::ParentVASP } /// Creates and returns the top-level resources to be published under the account - pub fn to_value(&self) -> (Value, Value) { + pub fn to_value(&self) -> (Value, Vec<(String, Value)>, Value) { // TODO: publish some concept of Account + let balances: Vec<_> = self + .balances + .iter() + .map(|(code, balance)| (code.clone(), balance.to_value())) + .collect(); + let event_generator = self.event_generator.to_value(); let account = Value::struct_(Struct::pack(vec![ // TODO: this needs to compute the auth key instead - Value::vector_u8(AuthenticationKey::ed25519(&self.account.pubkey).to_vec()), + Value::vector_u8(self.account.auth_key().to_vec()), + self.withdrawal_capability + .as_ref() + .map(|v| v.value()) + .unwrap_or_else(|| Value::vector_for_testing_only(vec![])), + self.key_rotation_capability + .as_ref() + .map(|v| v.value()) + .unwrap_or_else(|| Value::vector_for_testing_only(vec![])), + + Value::struct_(Struct::pack(vec![ + Value::u64(self.withdraw_events.count()), + Value::vector_u8(self.withdraw_events.key().to_vec()), + ])), + Value::struct_(Struct::pack(vec![ + Value::u64(self.deposit_events.count()), + Value::vector_u8(self.deposit_events.key().to_vec()), + ])), + Value::struct_(Struct::pack(vec![ + Value::u64(self.accept_token_events.count()), + Value::vector_u8(self.accept_token_events.key().to_vec()), + ])), Value::u64(self.sequence_number), - Value::address(*self.address()), ])); - (account, self.coin_store.to_value()) + (account, balances, event_generator) } /// Returns the AccessPath that describes the Account resource instance. @@ -583,11 +709,15 @@ impl AccountData { self.account.make_account_access_path() } - /// Returns the AccessPath that describes the Account's CoinStore resource instance. + /// Returns the AccessPath that describes the Account's Balance resource instance. /// - /// Use this to retrieve or publish the Account's CoinStore blob. - pub fn make_coin_store_access_path(&self) -> AccessPath { - self.account.make_coin_store_access_path() + /// Use this to retrieve or publish the Account's Balance blob. + pub fn make_balance_access_path(&self, token_code: &str) -> AccessPath { + self.account.make_balance_access_path(token_code) + } + + pub fn make_event_generator_access_path(&self) -> AccessPath { + self.account.make_event_generator_access_path() } pub fn transfer_event_layout() -> MoveStructLayout { @@ -601,7 +731,7 @@ impl AccountData { /// Creates a writeset that contains the account data and can be patched to the storage /// directly. pub fn to_writeset(&self) -> WriteSet { - let (account_blob, coinstore_blob) = self.to_value(); + let (account_blob, balance_blobs, event_generator_blob) = self.to_value(); let mut write_set = Vec::new(); let account = account_blob .value_as::() @@ -612,17 +742,27 @@ impl AccountData { StateKey::AccessPath(self.make_account_access_path()), WriteOp::Value(account), )); + for (code, balance_blob) in balance_blobs.into_iter() { + let balance = balance_blob + .value_as::() + .unwrap() + .simple_serialize(&Balance::layout()) + .unwrap(); + write_set.push(( + StateKey::AccessPath(self.make_balance_access_path(code.as_str())), + WriteOp::Value(balance), + )); + } - let balance = coinstore_blob + let event_generator = event_generator_blob .value_as::() .unwrap() - .simple_serialize(&CoinStore::layout()) + .simple_serialize(&EventHandleGenerator::layout()) .unwrap(); write_set.push(( - StateKey::AccessPath(self.make_coin_store_access_path()), - WriteOp::Value(balance), + StateKey::AccessPath(self.make_event_generator_access_path()), + WriteOp::Value(event_generator), )); - WriteSetMut::new(write_set).freeze().unwrap() } @@ -645,8 +785,11 @@ impl AccountData { } /// Returns the initial balance. - pub fn balance(&self) -> u64 { - self.coin_store.coin() + pub fn balance(&self) -> u128 { + self.balances + .get(STC_TOKEN_CODE_STR) + .expect("get balance by currency_code fail") + .token() } /// Returns the initial sequence number. @@ -656,22 +799,22 @@ impl AccountData { /// Returns the unique key for this sent events stream. pub fn sent_events_key(&self) -> &[u8] { - self.coin_store.withdraw_events.key().as_bytes() + self.withdraw_events.key().as_bytes() } /// Returns the initial sent events count. pub fn sent_events_count(&self) -> u64 { - self.coin_store.withdraw_events.count() + self.withdraw_events.count() } /// Returns the unique key for this received events stream. pub fn received_events_key(&self) -> &[u8] { - self.coin_store.deposit_events.key().as_bytes() + self.deposit_events.key().as_bytes() } /// Returns the initial received events count. pub fn received_events_count(&self) -> u64 { - self.coin_store.deposit_events.count() + self.deposit_events.count() } } @@ -679,6 +822,7 @@ impl AccountData { pub struct WithdrawCapability { account_address: AccountAddress, } + impl WithdrawCapability { pub fn new(account_address: AccountAddress) -> Self { Self { account_address } @@ -699,6 +843,7 @@ impl WithdrawCapability { pub struct KeyRotationCapability { account_address: AccountAddress, } + impl KeyRotationCapability { pub fn new(account_address: AccountAddress) -> Self { Self { account_address } diff --git a/vm/e2e-tests/src/account_universe.rs b/vm/e2e-tests/src/account_universe.rs index 9cd85969b7..e3fec93e44 100644 --- a/vm/e2e-tests/src/account_universe.rs +++ b/vm/e2e-tests/src/account_universe.rs @@ -137,7 +137,7 @@ impl AccountCurrent { let received_events_count = initial_data.received_events_count(); Self { initial_data, - balance, + balance: balance as u64, sequence_number, sent_events_count, received_events_count, diff --git a/vm/e2e-tests/src/account_universe/create_account.rs b/vm/e2e-tests/src/account_universe/create_account.rs index e9b74de2e1..f85c1889a3 100644 --- a/vm/e2e-tests/src/account_universe/create_account.rs +++ b/vm/e2e-tests/src/account_universe/create_account.rs @@ -55,7 +55,7 @@ impl AUTransactionGen for CreateAccountGen { sender.event_counter_created = true; universe.add_account(AccountData::with_account( self.new_account.clone(), - self.amount, + self.amount as u128, 0, AccountRoleSpecifier::default(), )); diff --git a/vm/e2e-tests/src/account_universe/peer_to_peer.rs b/vm/e2e-tests/src/account_universe/peer_to_peer.rs index 400bbc0780..3bb47aa824 100644 --- a/vm/e2e-tests/src/account_universe/peer_to_peer.rs +++ b/vm/e2e-tests/src/account_universe/peer_to_peer.rs @@ -14,7 +14,6 @@ use starcoin_vm_types::language_storage::ModuleId; use starcoin_vm_types::transaction::{SignedUserTransaction, TransactionStatus}; use starcoin_vm_types::vm_status::{AbortLocation, StatusCode}; use std::sync::Arc; -use starcoin_vm_types::values::debug::print_locals; /// Represents a peer-to-peer transaction performed in the account universe. /// diff --git a/vm/e2e-tests/src/common_transactions.rs b/vm/e2e-tests/src/common_transactions.rs index 5f2379150d..7f8b0c57e9 100644 --- a/vm/e2e-tests/src/common_transactions.rs +++ b/vm/e2e-tests/src/common_transactions.rs @@ -40,7 +40,7 @@ pub fn empty_txn( ) -> SignedUserTransaction { build_signed_empty_txn( sender.address().clone(), - &sender.privkey.clone().into(), + &sender.private_key(), seq_num, now_time() + DEFAULT_EXPIRATION_TIME, ChainId::test(), @@ -60,11 +60,9 @@ pub fn create_account_txn( new_account: &Account, seq_num: u64, ) -> SignedUserTransaction { - let starcoin_acc = StarcoinAccount::with_keypair( - new_account.privkey.clone().into(), - new_account.pubkey.clone().into(), - Some(new_account.address().clone()), - ); + let (pub_k, priv_k) = new_account.account_keypair(); + let starcoin_acc = + StarcoinAccount::with_keypair(priv_k, pub_k, Some(new_account.address().clone())); create_account_txn_sent_as_association( &starcoin_acc, seq_num + 1, @@ -98,11 +96,8 @@ pub fn peer_to_peer_txn( // )) // .sequence_number(seq_num) // .sign() - let starcoin_acc = StarcoinAccount::with_keypair( - sender.privkey.clone().into(), - sender.pubkey.clone().into(), - Some(sender.address().clone()), - ); + let (pub_k, priv_k) = sender.account_keypair(); + let starcoin_acc = StarcoinAccount::with_keypair(priv_k, pub_k, Some(sender.address().clone())); peer_to_peer_v2( &starcoin_acc, receiver.address(), diff --git a/vm/e2e-tests/src/data_store.rs b/vm/e2e-tests/src/data_store.rs index bf9c595b7f..d2bf7d44bb 100644 --- a/vm/e2e-tests/src/data_store.rs +++ b/vm/e2e-tests/src/data_store.rs @@ -1,7 +1,7 @@ // Copyright (c) Starcoin // SPDX-License-Identifier: Apache-2.0 -//! Support for mocking the Aptos data store. +//! Support for mocking the Starcoin data store. use crate::account::AccountData; use anyhow::Result; use serde::{Deserialize, Serialize}; @@ -46,6 +46,8 @@ impl FakeDataStore { /// Adds a [`WriteSet`] to this data store. pub fn add_write_set(&self, write_set: &WriteSet) { + println!("FakeDataStore::add_write_set | {:#?}", write_set); + let mut write_handle = self.state_data.write().expect("Panic for lock"); for (state_key, write_op) in write_set { match write_op { @@ -99,6 +101,8 @@ impl FakeDataStore { // TODO: only the "sync" get is implemented impl StateView for FakeDataStore { fn get_state_value(&self, state_key: &StateKey) -> Result>> { + println!("StateView::get_state_value, state_key: {:#?}", state_key); + Ok(self.inner().get(state_key).cloned()) } diff --git a/vm/e2e-tests/src/executor.rs b/vm/e2e-tests/src/executor.rs index b0e53b869c..49681c0017 100644 --- a/vm/e2e-tests/src/executor.rs +++ b/vm/e2e-tests/src/executor.rs @@ -64,7 +64,7 @@ pub type TraceSeqMapping = (usize, Vec, Vec); /// Provides an environment to run a VM instance. /// -/// This struct is a mock in-memory implementation of the Aptos executor. +/// This struct is a mock in-memory implementation of the Starcoin executor. #[derive(Debug)] pub struct FakeExecutor { data_store: FakeDataStore, @@ -227,7 +227,7 @@ impl FakeExecutor { } /// Create one instance of [`AccountData`] without saving it to data store. - pub fn create_raw_account_data(&mut self, balance: u64, seq_num: u64) -> AccountData { + pub fn create_raw_account_data(&mut self, balance: u128, seq_num: u64) -> AccountData { AccountData::new_from_seed(&mut self.rng, balance, seq_num) } @@ -236,7 +236,7 @@ impl FakeExecutor { pub fn create_accounts(&mut self, size: usize, balance: u64, seq_num: u64) -> Vec { let mut accounts: Vec = Vec::with_capacity(size); for _i in 0..size { - let account_data = AccountData::new_from_seed(&mut self.rng, balance, seq_num); + let account_data = AccountData::new_from_seed(&mut self.rng, balance as u128, seq_num); self.add_account_data(&account_data); accounts.push(account_data.into_account()); } @@ -481,7 +481,9 @@ impl FakeExecutor { HashValue::zero(), self.block_time, minter_account.address().clone(), - Some(AuthenticationKey::ed25519(&minter_account.account().pubkey)), + Some(AuthenticationKey::ed25519( + &minter_account.account().public_key(), + )), 0, 0, ChainId::test(), diff --git a/vm/e2e-tests/src/gas_costs.rs b/vm/e2e-tests/src/gas_costs.rs index d505129b0f..c491ca2973 100644 --- a/vm/e2e-tests/src/gas_costs.rs +++ b/vm/e2e-tests/src/gas_costs.rs @@ -60,7 +60,7 @@ pub static CREATE_ACCOUNT_TOO_LOW_FIRST: Lazy = Lazy::new(|| { // The gas amount is the minimum that needs to be reserved, so use a value that's // clearly higher than that. let balance = TXN_RESERVED + 10_000; - let sender = AccountData::new(balance, 10); + let sender = AccountData::new(balance as u128, 10); executor.add_account_data(&sender); let receiver = Account::new(); @@ -77,7 +77,7 @@ pub static CREATE_ACCOUNT_TOO_LOW_NEXT: Lazy = Lazy::new(|| { // The gas amount is the minimum that needs to be reserved, so use a value that's // clearly higher than that. let balance = (2 * TXN_RESERVED) + 10_000; - let sender = AccountData::new(balance, 10); + let sender = AccountData::new(balance as u128, 10); executor.add_account_data(&sender); let txns = vec![ @@ -150,7 +150,7 @@ pub static PEER_TO_PEER_TOO_LOW: Lazy = Lazy::new(|| { // The gas amount is the minimum that needs to be reserved, so use a value that's clearly // higher than that. let balance = TXN_RESERVED + 10_000; - let sender = AccountData::new(balance, 10); + let sender = AccountData::new(balance as u128, 10); let receiver = AccountData::new(1_000_000, 10); executor.add_account_data(&sender); executor.add_account_data(&receiver); @@ -206,7 +206,7 @@ pub static PEER_TO_PEER_NEW_RECEIVER_TOO_LOW_FIRST: Lazy = Lazy::new(|| { // The gas amount is the minimum that needs to be reserved, so use a value that's // clearly higher than that. let balance = TXN_RESERVED + 10_000; - let sender = AccountData::new(balance, 10); + let sender = AccountData::new(balance as u128, 10); executor.add_account_data(&sender); let receiver = Account::new(); @@ -224,7 +224,7 @@ pub static PEER_TO_PEER_NEW_RECEIVER_TOO_LOW_NEXT: Lazy = Lazy::new(|| { // The gas amount is the minimum that needs to be reserved, so use a value that's // clearly higher than that. let balance = (2 * TXN_RESERVED) + 20_000; - let sender = AccountData::new(balance, 10); + let sender = AccountData::new(balance as u128, 10); executor.add_account_data(&sender); let txns = vec![ diff --git a/vm/e2e-tests/src/proptest_types.rs b/vm/e2e-tests/src/proptest_types.rs index e26d46946f..4a38faa1f5 100644 --- a/vm/e2e-tests/src/proptest_types.rs +++ b/vm/e2e-tests/src/proptest_types.rs @@ -35,7 +35,7 @@ impl AccountData { |(account, balance, sequence_number, sent_events_count, received_events_count)| { AccountData::with_account_and_event_counts( account, - balance, + balance as u128, sequence_number, sent_events_count, received_events_count, diff --git a/vm/mvhashmap/src/lib.rs b/vm/mvhashmap/src/lib.rs index 0273b48ad0..eaba938d94 100644 --- a/vm/mvhashmap/src/lib.rs +++ b/vm/mvhashmap/src/lib.rs @@ -2,10 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 use crossbeam::utils::CachePadded; use dashmap::DashMap; -use std::{collections::btree_map::BTreeMap, hash::Hash, sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, -}, thread}; +use std::{ + collections::btree_map::BTreeMap, + hash::Hash, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + thread, +}; #[cfg(test)] mod unit_tests; @@ -73,7 +78,11 @@ impl MVHashMap { pub fn write(&self, key: &K, version: Version, data: V) { let (txn_idx, incarnation) = version; - println!("{:?} - MVHashMap::mark_estimate | Entered, version: {:?}", thread::current().id(), version); + println!( + "{:?} - MVHashMap::write | Entered, version: {:?}", + thread::current().id(), + version + ); let mut map = self.data.entry(key.clone()).or_insert(BTreeMap::new()); let prev_cell = map.insert( @@ -86,38 +95,57 @@ impl MVHashMap { .map(|cell| cell.incarnation < incarnation) .unwrap_or(true)); - println!("{:?} - MVHashMap::mark_estimate | Exited, version: {:?}", thread::current().id(), version); + println!( + "{:?} - MVHashMap::write | Exited, version: {:?}", + thread::current().id(), + version + ); } /// Mark an entry from transaction 'txn_idx' at access path 'key' as an estimated write /// (for future incarnation). Will panic if the entry is not in the data-structure. pub fn mark_estimate(&self, key: &K, txn_idx: TxnIndex) { - println!("{:?} - MVHashMap::mark_estimate | Entered, txn_id: {:?}", thread::current().id(), txn_idx); + println!( + "{:?} - MVHashMap::mark_estimate | Entered, txn_id: {:?}", + thread::current().id(), + txn_idx + ); let map = self.data.get(key).expect("Path must exist"); map.get(&txn_idx) .expect("Entry by txn must exist") .mark_estimate(); - println!("{:?} - MVHashMap::mark_estimate | Exited", thread::current().id()); + println!( + "{:?} - MVHashMap::mark_estimate | Exited", + thread::current().id() + ); } /// Delete an entry from transaction 'txn_idx' at access path 'key'. Will panic /// if the access path has never been written before. pub fn delete(&self, key: &K, txn_idx: TxnIndex) { - println!("{:?} - MVHashMap::delete | Exit, txn_idx: {:?}", thread::current().id(), txn_idx); + println!( + "{:?} - MVHashMap::delete | Exit, txn_idx: {:?}", + thread::current().id(), + txn_idx + ); // TODO: investigate logical deletion. let mut map = self.data.get_mut(key).expect("Path must exist"); map.remove(&txn_idx); - println!("{:?} - MVHashMap::delete | Exited, txn_idx: {:?}", thread::current().id(), txn_idx); + println!( + "{:?} - MVHashMap::delete | Exited, txn_idx: {:?}", + thread::current().id(), + txn_idx + ); } /// read may return Ok((Arc, txn_idx, incarnation)), Err(dep_txn_idx) for /// a dependency of transaction dep_txn_idx or Err(None) when no prior entry is found. pub fn read(&self, key: &K, txn_idx: TxnIndex) -> Result<(Version, Arc), Option> { - println!("{:?} - MVHashMap::read | Entered, txn_id: {:?}", thread::current().id(), txn_idx); + // println!("{:?} - MVHashMap::read | Entered, txn_id: {:?}", thread::current().id(), txn_idx); match self.data.get(key) { Some(tree) => { // Find the dependency @@ -125,26 +153,26 @@ impl MVHashMap { if let Some((idx, write_cell)) = iter.next_back() { let flag = write_cell.flag(); - println!("{:?} - MVHashMap::read | flag: {}", thread::current().id(), flag); + // println!("{:?} - MVHashMap::read | flag: {}", thread::current().id(), flag); if flag == FLAG_ESTIMATE { // Found a dependency. - println!("{:?} - MVHashMap::read | Exit, FLAG_ESTIMATE {}", thread::current().id(), idx); + // println!("{:?} - MVHashMap::read | Exit, FLAG_ESTIMATE {}", thread::current().id(), idx); Err(Some(*idx)) } else { debug_assert!(flag == FLAG_DONE); - println!("{:?} - MVHashMap::read | Exit, FLAG_DONE {}", thread::current().id(), idx); + // println!("{:?} - MVHashMap::read | Exit, FLAG_DONE {}", thread::current().id(), idx); // The entry is populated, return its contents. let write_version = (*idx, write_cell.incarnation); Ok((write_version, write_cell.data.clone())) } } else { - println!("{:?} - MVHashMap::read | Exit, iter.next_back() -> Err(None)", thread::current().id()); + // println!("{:?} - MVHashMap::read | Exit, iter.next_back() -> Err(None)", thread::current().id()); Err(None) } } None => { - println!("{:?} - MVHashMap::read | Exit, self.data.get(key) -> Err(None)", thread::current().id()); + // println!("{:?} - MVHashMap::read | Exit, self.data.get(key) -> Err(None)", thread::current().id()); Err(None) } } diff --git a/vm/parallel-executor/src/executor.rs b/vm/parallel-executor/src/executor.rs index 1f52bd6a81..fef77828e5 100644 --- a/vm/parallel-executor/src/executor.rs +++ b/vm/parallel-executor/src/executor.rs @@ -12,8 +12,9 @@ use num_cpus; use once_cell::sync::Lazy; use starcoin_infallible::Mutex; use starcoin_mvhashmap::MVHashMap; -use std::{collections::HashSet, hash::Hash, marker::PhantomData, sync::Arc, thread, thread::spawn}; -use std::any::Any; +use std::{ + collections::HashSet, hash::Hash, marker::PhantomData, sync::Arc, thread, thread::spawn, +}; static RAYON_EXEC_POOL: Lazy = Lazy::new(|| { rayon::ThreadPoolBuilder::new() @@ -46,7 +47,7 @@ impl<'a, K: PartialOrd + Send + Clone + Hash + Eq, V: Send + Sync> MVHashMapView /// Captures a read from the VM execution. pub fn read(&self, key: &K) -> Option> { - println!("{:?} - MVHashMapView::read | Entered, {}", thread::current().id(), self.txn_idx); + // println!("{:?} - MVHashMapView::read | Entered, {}", thread::current().id(), self.txn_idx); loop { match self.versioned_map.read(key, self.txn_idx) { Ok((version, v)) => { @@ -56,7 +57,7 @@ impl<'a, K: PartialOrd + Send + Clone + Hash + Eq, V: Send + Sync> MVHashMapView txn_idx, incarnation, )); - println!("{:?} - MVHashMapView::read | Exited, {} -> Some(v)", thread::current().id(), self.txn_idx); + // println!("{:?} - MVHashMapView::read | Exited, {} -> Some(v)", thread::current().id(), self.txn_idx); return Some(v); } Err(None) => { @@ -64,7 +65,7 @@ impl<'a, K: PartialOrd + Send + Clone + Hash + Eq, V: Send + Sync> MVHashMapView .lock() .push(ReadDescriptor::from_storage(key.clone())); - println!("{:?} - MVHashMapView::read | Exited, {}, -> None", thread::current().id(), self.txn_idx); + // println!("{:?} - MVHashMapView::read | Exited, {}, -> None", thread::current().id(), self.txn_idx); return None; } Err(Some(dep_idx)) => { @@ -146,7 +147,7 @@ where ) -> SchedulerTask<'a> { let (idx_to_execute, incarnation) = version; - println!("{:?} - MVHashMap::execute | Entered, idx_to_execute:{:?}, incarnation: {:?}", thread::current().id(), idx_to_execute, incarnation); + println!("{:?} - ParallelTransactionExecutor::execute | Entered, idx_to_execute:{:?}, incarnation: {:?}", thread::current().id(), idx_to_execute, incarnation); let txn = &signature_verified_block[idx_to_execute]; @@ -161,8 +162,6 @@ where let execute_result = executor.execute_transaction(&state_view, txn); let mut prev_write_set: HashSet = last_input_output.write_set(idx_to_execute); - println!("{:?} - MVHashMap::execute | after executor.execute_transaction, execute_result: {:?}", thread::current().id(), execute_result.type_id()); - // For tracking whether the recent execution wrote outside of the previous write set. let mut writes_outside = false; let mut apply_writes = |output: &::Output| { @@ -183,14 +182,17 @@ where ExecutionStatus::Success(output) => { // Apply the writes to the versioned_data_cache. apply_writes(&output); + println!("{:?} - ParallelTransactionExecutor::execute | after executor.execute_transaction, ExecutionStatus::Success, output len: {:?}", thread::current().id(), output.get_writes().len()); ExecutionStatus::Success(output) } ExecutionStatus::SkipRest(output) => { // Apply the writes and record status indicating skip. apply_writes(&output); + println!("{:?} - ParallelTransactionExecutor::execute | after executor.execute_transaction, ExecutionStatus::SkipRest", thread::current().id()); ExecutionStatus::SkipRest(output) } ExecutionStatus::Abort(err) => { + println!("{:?} - MVHashMap::execute | after executor.execute_transaction, ExecutionStatus::Abort", thread::current().id()); // Record the status indicating abort. ExecutionStatus::Abort(Error::UserError(err)) } @@ -219,7 +221,11 @@ where versioned_data_cache: &MVHashMap<::Key, ::Value>, scheduler: &'a Scheduler, ) -> SchedulerTask<'a> { - println!("{:?} - ParallelTransactionExecutor::validate | Entered {:?}", thread::current().id(), version_to_validate); + println!( + "{:?} - ParallelTransactionExecutor::validate | Entered {:?}", + thread::current().id(), + version_to_validate + ); let (idx_to_validate, incarnation) = version_to_validate; let read_set = last_input_output @@ -236,7 +242,12 @@ where let aborted = !valid && scheduler.try_abort(idx_to_validate, incarnation); - println!("{:?} - ParallelTransactionExecutor::validate | valid: {}, aborted: {}", thread::current().id(), valid, aborted); + println!( + "{:?} - ParallelTransactionExecutor::validate | valid: {}, aborted: {}", + thread::current().id(), + valid, + aborted + ); if aborted { // Not valid and successfully aborted, mark the latest write-set as estimates. @@ -244,13 +255,18 @@ where versioned_data_cache.mark_estimate(k, idx_to_validate); } - println!("{:?} - ParallelTransactionExecutor::validate | Exited, aborted == true", thread::current().id()); + println!( + "{:?} - ParallelTransactionExecutor::validate | Exited, aborted == true", + thread::current().id() + ); scheduler.finish_abort(idx_to_validate, incarnation, guard) } else { - println!("{:?} - ParallelTransactionExecutor::validate | Exited, SchedulerTask::NoTask", thread::current().id()); + println!( + "{:?} - ParallelTransactionExecutor::validate | Exited, SchedulerTask::NoTask", + thread::current().id() + ); SchedulerTask::NoTask } - } fn work_task_with_scope( @@ -268,7 +284,10 @@ where // Make executor for each task. TODO: fast concurrent executor. let executor = E::init(*executor_arguments); - println!("{:?} - ParallelTransactionExecutor::work_task_with_scope | Entered", thread::current().id()); + println!( + "{:?} - ParallelTransactionExecutor::work_task_with_scope | Entered", + thread::current().id() + ); let mut scheduler_task = SchedulerTask::NoTask; loop { @@ -305,7 +324,10 @@ where } } - println!("{:?} - ParallelTransactionExecutor::work_task_with_scope | Exited", thread::current().id()); + println!( + "{:?} - ParallelTransactionExecutor::work_task_with_scope | Exited", + thread::current().id() + ); } pub fn execute_transactions_parallel( diff --git a/vm/parallel-executor/src/scheduler.rs b/vm/parallel-executor/src/scheduler.rs index 9d9f15a563..05cd056721 100644 --- a/vm/parallel-executor/src/scheduler.rs +++ b/vm/parallel-executor/src/scheduler.rs @@ -3,10 +3,15 @@ use crossbeam::utils::CachePadded; use starcoin_infallible::Mutex; -use std::{cmp::min, hint, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, - Arc, Condvar, -}, thread}; +use std::{ + cmp::min, + hint, + sync::{ + atomic::{AtomicBool, AtomicUsize, Ordering}, + Arc, Condvar, + }, + thread, +}; // Type aliases. pub type TxnIndex = usize; @@ -163,45 +168,60 @@ impl Scheduler { /// returns false. Since incarnation numbers never decrease, this also ensures /// that the same version may not successfully abort more than once. pub fn try_abort(&self, txn_idx: TxnIndex, incarnation: Incarnation) -> bool { - println!("{:?} - Scheduler::try_abort | Entered, txn_idx: {:?}, incarnation: {:?}", thread::current().id(), txn_idx, incarnation); + println!( + "{:?} - Scheduler::try_abort | Entered, txn_idx: {:?}, incarnation: {:?}", + thread::current().id(), + txn_idx, + incarnation + ); // lock the status. let mut status = self.txn_status[txn_idx].lock(); - println!("{:?} - Scheduler::try_abort | Status: {:?} ", thread::current().id(), status); + println!( + "{:?} - Scheduler::try_abort | Status: {:?} ", + thread::current().id(), + status + ); if *status == TransactionStatus::Executed(incarnation) { *status = TransactionStatus::Aborting(incarnation); - println!("{:?} - Scheduler::try_abort | Exited, status == Executed", thread::current().id()); + println!( + "{:?} - Scheduler::try_abort | Exited, status == Executed", + thread::current().id() + ); true } else { - println!("{:?} - Scheduler::try_abort | Exited, status != Executed", thread::current().id()); + println!( + "{:?} - Scheduler::try_abort | Exited, status != Executed", + thread::current().id() + ); false } } /// Return the next task for the thread. pub fn next_task(&self) -> SchedulerTask { - println!("{:?} - Scheduler::next_task | Entered", thread::current().id()); + // println!("{:?} - Scheduler::next_task | Entered", thread::current().id()); loop { if self.done() { // No more tasks. - println!("{:?} - Scheduler::next_task | Exited, has SchedulerTask::Done", thread::current().id()); + // println!("{:?} - Scheduler::next_task | Exited, has SchedulerTask::Done", thread::current().id()); return SchedulerTask::Done; } let idx_to_validate = self.validation_idx.load(Ordering::SeqCst); let idx_to_execute = self.execution_idx.load(Ordering::SeqCst); - println!("{:?} - Scheduler::next_task | idx_to_validate: {}, idx_to_execute: {}", thread::current().id(), idx_to_validate, idx_to_execute); + //println!("{:?} - Scheduler::next_task | idx_to_validate: {}, idx_to_execute: {}", thread::current().id(), idx_to_validate, idx_to_execute); if idx_to_validate < idx_to_execute { if let Some((version_to_validate, guard)) = self.try_validate_next_version() { - println!("{:?} - Scheduler::next_task | Exited: SchedulerTask::ValidationTask", thread::current().id()); + // println!("{:?} - Scheduler::next_task | Exited: SchedulerTask::ValidationTask", thread::current().id()); return SchedulerTask::ValidationTask(version_to_validate, guard); } } else if let Some((version_to_execute, maybe_condvar, guard)) = self.try_execute_next_version() { - println!("{:?} - Scheduler::next_task | Exited: SchedulerTask::ExecutionTask", thread::current().id()); + // println!("{:?} - Scheduler::next_task | Exited: SchedulerTask::ExecutionTask", thread::current().id()); return SchedulerTask::ExecutionTask(version_to_execute, maybe_condvar, guard); } } @@ -221,7 +241,12 @@ impl Scheduler { // Note: Could pre-check that txn dep_txn_idx isn't in an executed state, but the caller // usually has just observed the read dependency. - println!("{:?} - Scheduler::wait_for_dependency | Entered, txn_idx: {:#?}, dep_txn_idx: {:#?}", thread::current().id(), txn_idx, dep_txn_idx); + println!( + "{:?} - Scheduler::wait_for_dependency | Entered, txn_idx: {:#?}, dep_txn_idx: {:#?}", + thread::current().id(), + txn_idx, + dep_txn_idx + ); // Create a condition variable associated with the dependency. let dep_condvar = Arc::new((Mutex::new(false), Condvar::new())); @@ -238,7 +263,10 @@ impl Scheduler { // Only place in scheduler where a thread may hold >1 mutexes, hence, such // acquisitions always happens in the same order (this function), may not deadlock. - println!("{:?} - Scheduler::wait_for_dependency | Exited, return None", thread::current().id(),); + println!( + "{:?} - Scheduler::wait_for_dependency | Exited, return None", + thread::current().id(), + ); return None; } @@ -264,7 +292,12 @@ impl Scheduler { revalidate_suffix: bool, guard: TaskGuard<'a>, ) -> SchedulerTask<'a> { - println!("{:?} - Scheduler::finish_execution | Entered, txn_id: {:?}, incarnation: {:?} ", thread::current().id(), txn_idx, incarnation); + println!( + "{:?} - Scheduler::finish_execution | Entered, txn_id: {:?}, incarnation: {:?} ", + thread::current().id(), + txn_idx, + incarnation + ); self.set_executed_status(txn_idx, incarnation); @@ -303,13 +336,19 @@ impl Scheduler { } else { // Only transaction txn_idx requires validation. Return validation task // back to the caller. No need to change active tasks (-1 +1= 0) - println!("{:?} - Scheduler::finish_execution | Exited, ValidationTask", thread::current().id()); + println!( + "{:?} - Scheduler::finish_execution | Exited, ValidationTask", + thread::current().id() + ); return SchedulerTask::ValidationTask((txn_idx, incarnation), guard); } } - println!("{:?} - Scheduler::finish_execution | Exited, NoTask", thread::current().id()); + println!( + "{:?} - Scheduler::finish_execution | Exited, NoTask", + thread::current().id() + ); SchedulerTask::NoTask } @@ -337,7 +376,10 @@ impl Scheduler { // nothing to do, as another thread must have succeeded to incarnate and // obtain the task for re-execution. if let Some((new_incarnation, maybe_condvar)) = self.try_incarnate(txn_idx) { - println!("{:?} - Scheduler::finish_abort | Exited, ExecutionTask", thread::current().id()); + println!( + "{:?} - Scheduler::finish_abort | Exited, ExecutionTask", + thread::current().id() + ); return SchedulerTask::ExecutionTask( (txn_idx, new_incarnation), @@ -347,7 +389,10 @@ impl Scheduler { } } - println!("{:?} - Scheduler::finish_abort | Exited, NoTask", thread::current().id()); + println!( + "{:?} - Scheduler::finish_abort | Exited, NoTask", + thread::current().id() + ); SchedulerTask::NoTask } @@ -482,7 +527,11 @@ impl Scheduler { /// incremented incarnation number. /// The caller must ensure that the transaction is in the Suspended state. fn resume(&self, txn_idx: TxnIndex) { - println!("{:?} - Scheduler::resume | Entered, txn_id: {:?} ", thread::current().id(), txn_idx); + println!( + "{:?} - Scheduler::resume | Entered, txn_id: {:?} ", + thread::current().id(), + txn_idx + ); let mut status = self.txn_status[txn_idx].lock(); if let TransactionStatus::Suspended(incarnation, dep_condvar) = &*status { @@ -490,7 +539,11 @@ impl Scheduler { } else { unreachable!(); } - println!("{:?} - Scheduler::resume | Exited, txn_id: {:?} ", thread::current().id(), txn_idx); + println!( + "{:?} - Scheduler::resume | Exited, txn_id: {:?} ", + thread::current().id(), + txn_idx + ); } /// Set status of the transaction to Executed(incarnation). @@ -506,7 +559,12 @@ impl Scheduler { /// After a successful abort, mark the transaction as ready for re-execution with /// an incremented incarnation number. fn set_aborted_status(&self, txn_idx: TxnIndex, incarnation: Incarnation) { - println!("{:?} - Scheduler::set_aborted_status | Entered, txn_id: {:?}, incarnation: {:?}", thread::current().id(), txn_idx, incarnation); + println!( + "{:?} - Scheduler::set_aborted_status | Entered, txn_id: {:?}, incarnation: {:?}", + thread::current().id(), + txn_idx, + incarnation + ); let mut status = self.txn_status[txn_idx].lock(); @@ -515,7 +573,12 @@ impl Scheduler { *status = TransactionStatus::ReadyToExecute(incarnation + 1, None); - println!("{:?} - Scheduler::set_aborted_status | Exited, txn_id: {:?}, incarnation: {:?}", thread::current().id(), txn_idx, incarnation); + println!( + "{:?} - Scheduler::set_aborted_status | Exited, txn_id: {:?}, incarnation: {:?}", + thread::current().id(), + txn_idx, + incarnation + ); } /// A lazy, check of whether the scheduler execution is completed. diff --git a/vm/transaction-benchmarks/Cargo.toml b/vm/transaction-benchmarks/Cargo.toml index 9563744909..58ab314d1a 100644 --- a/vm/transaction-benchmarks/Cargo.toml +++ b/vm/transaction-benchmarks/Cargo.toml @@ -22,7 +22,6 @@ pprof = { version = "0.10", optional = true, features = ["flamegraph", "criterio log = { workspace = true } criterion-cpu-time = "0.1.0" starcoin-language-e2e-tests = { path = "../e2e-tests" } -# move-deps = { path = "../../aptos-move/move-deps" } [dev-dependencies] criterion = { workspace = true, features = ["html_reports"] } diff --git a/vm/transaction-benchmarks/src/main.rs b/vm/transaction-benchmarks/src/main.rs index dc26584945..92509695fd 100644 --- a/vm/transaction-benchmarks/src/main.rs +++ b/vm/transaction-benchmarks/src/main.rs @@ -8,22 +8,22 @@ fn main() { let default_num_transactions = 1_000; let bencher = TransactionBencher::new( - any_with::((1_000, 1_000_000)), + any_with::((1, 10)), default_num_accounts, default_num_transactions, ); let acts = [2]; - let txns = [1000]; - let num_warmups = 2; - let num_runs = 10; + let txns = [1]; + let num_warmups = 0; + let num_runs = 1; let mut measurements = Vec::new(); for block_size in txns { for num_accounts in acts { let mut times = - bencher.manual_parallel(num_accounts, block_size, num_warmups, num_runs); + bencher.manual_sequence(num_accounts, block_size, num_warmups, num_runs); times.sort(); measurements.push(times); } diff --git a/vm/transaction-benchmarks/src/transactions.rs b/vm/transaction-benchmarks/src/transactions.rs index 872cae3f4b..48f2b1188f 100644 --- a/vm/transaction-benchmarks/src/transactions.rs +++ b/vm/transaction-benchmarks/src/transactions.rs @@ -213,7 +213,9 @@ impl TransactionBenchState { HashValue::zero(), 0, minter_account.address().clone(), - Some(AuthenticationKey::ed25519(&minter_account.account().pubkey)), + Some(AuthenticationKey::ed25519( + &minter_account.account().public_key(), + )), 0, 0, ChainId::test(), diff --git a/vm/vm-runtime/src/errors.rs b/vm/vm-runtime/src/errors.rs index 71d6b2ea89..8f7d68ecf4 100644 --- a/vm/vm-runtime/src/errors.rs +++ b/vm/vm-runtime/src/errors.rs @@ -42,9 +42,11 @@ pub fn error_split(code: u64) -> (u8, u64) { pub fn convert_prologue_runtime_error(error: VMError) -> Result<(), VMStatus> { let status = error.into_vm_status(); + println!("convert_prologue_runtime_error: {:#?}", status.clone()); Err(match status { VMStatus::Executed => VMStatus::Executed, VMStatus::MoveAbort(location, code) => { + println!("convert_prologue_runtime_error, error: {:#?}", location); let (category, reason) = error_split(code); let new_major_status = match (category, reason) { (REQUIRES_ADDRESS, PROLOGUE_ACCOUNT_DOES_NOT_EXIST) => { diff --git a/vm/vm-runtime/src/parallel_executor/vm_wrapper.rs b/vm/vm-runtime/src/parallel_executor/vm_wrapper.rs index 0974cc5964..127f71359d 100644 --- a/vm/vm-runtime/src/parallel_executor/vm_wrapper.rs +++ b/vm/vm-runtime/src/parallel_executor/vm_wrapper.rs @@ -49,7 +49,7 @@ impl<'a, S: 'a + StateView> ExecutorTask for StarcoinVMWrapper<'a, S> { txn: &PreprocessedTransaction, ) -> ExecutionStatus { let versioned_view = VersionedView::new_view(self.base_view, view); - + println!("StarcoinVMWrapper::execute_transaction, txn: {:#?}", txn); match self.vm.execute_single_transaction(txn, &versioned_view) { Ok((vm_status, output, sender)) => { if output.status().is_discarded() { From 54048edbe2562b317198a98861ae86d60a3cfa90 Mon Sep 17 00:00:00 2001 From: welbon Date: Sat, 23 Sep 2023 19:22:09 +0800 Subject: [PATCH 18/23] [benchmark-log] closed some log --- vm/e2e-tests/src/account.rs | 3 +++ vm/e2e-tests/src/data_store.rs | 5 ++--- vm/mvhashmap/src/lib.rs | 20 ++++++++++---------- vm/parallel-executor/src/executor.rs | 16 ++++++++-------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/vm/e2e-tests/src/account.rs b/vm/e2e-tests/src/account.rs index e79a25d251..b168788c0c 100644 --- a/vm/e2e-tests/src/account.rs +++ b/vm/e2e-tests/src/account.rs @@ -672,6 +672,9 @@ impl AccountData { .iter() .map(|(code, balance)| (code.clone(), balance.to_value())) .collect(); + + // println!("AccountData::to_value | account:{:#?}, balances: {:#?}", self.account.addr, balances); + let event_generator = self.event_generator.to_value(); let account = Value::struct_(Struct::pack(vec![ // TODO: this needs to compute the auth key instead diff --git a/vm/e2e-tests/src/data_store.rs b/vm/e2e-tests/src/data_store.rs index d2bf7d44bb..1d12fbb9e7 100644 --- a/vm/e2e-tests/src/data_store.rs +++ b/vm/e2e-tests/src/data_store.rs @@ -46,7 +46,7 @@ impl FakeDataStore { /// Adds a [`WriteSet`] to this data store. pub fn add_write_set(&self, write_set: &WriteSet) { - println!("FakeDataStore::add_write_set | {:#?}", write_set); + // println!("FakeDataStore::add_write_set | {:#?}", write_set); let mut write_handle = self.state_data.write().expect("Panic for lock"); for (state_key, write_op) in write_set { @@ -101,8 +101,7 @@ impl FakeDataStore { // TODO: only the "sync" get is implemented impl StateView for FakeDataStore { fn get_state_value(&self, state_key: &StateKey) -> Result>> { - println!("StateView::get_state_value, state_key: {:#?}", state_key); - + // println!("StateView::get_state_value, state_key: {:#?}", state_key); Ok(self.inner().get(state_key).cloned()) } diff --git a/vm/mvhashmap/src/lib.rs b/vm/mvhashmap/src/lib.rs index eaba938d94..c3f098fca7 100644 --- a/vm/mvhashmap/src/lib.rs +++ b/vm/mvhashmap/src/lib.rs @@ -78,11 +78,11 @@ impl MVHashMap { pub fn write(&self, key: &K, version: Version, data: V) { let (txn_idx, incarnation) = version; - println!( - "{:?} - MVHashMap::write | Entered, version: {:?}", - thread::current().id(), - version - ); + // println!( + // "{:?} - MVHashMap::write | Entered, version: {:?}", + // thread::current().id(), + // version + // ); let mut map = self.data.entry(key.clone()).or_insert(BTreeMap::new()); let prev_cell = map.insert( @@ -95,11 +95,11 @@ impl MVHashMap { .map(|cell| cell.incarnation < incarnation) .unwrap_or(true)); - println!( - "{:?} - MVHashMap::write | Exited, version: {:?}", - thread::current().id(), - version - ); + // println!( + // "{:?} - MVHashMap::write | Exited, version: {:?}", + // thread::current().id(), + // version + // ); } /// Mark an entry from transaction 'txn_idx' at access path 'key' as an estimated write diff --git a/vm/parallel-executor/src/executor.rs b/vm/parallel-executor/src/executor.rs index fef77828e5..83b3ebc9f2 100644 --- a/vm/parallel-executor/src/executor.rs +++ b/vm/parallel-executor/src/executor.rs @@ -284,10 +284,10 @@ where // Make executor for each task. TODO: fast concurrent executor. let executor = E::init(*executor_arguments); - println!( - "{:?} - ParallelTransactionExecutor::work_task_with_scope | Entered", - thread::current().id() - ); + // println!( + // "{:?} - ParallelTransactionExecutor::work_task_with_scope | Entered", + // thread::current().id() + // ); let mut scheduler_task = SchedulerTask::NoTask; loop { @@ -324,10 +324,10 @@ where } } - println!( - "{:?} - ParallelTransactionExecutor::work_task_with_scope | Exited", - thread::current().id() - ); + // println!( + // "{:?} - ParallelTransactionExecutor::work_task_with_scope | Exited", + // thread::current().id() + // ); } pub fn execute_transactions_parallel( From 3db8a45035844687ffe58eb34af31ca662df2bce Mon Sep 17 00:00:00 2001 From: welbon Date: Sun, 24 Sep 2023 23:13:50 +0800 Subject: [PATCH 19/23] [benchmark-log] closed some log and fix some block meta creation error --- vm/e2e-tests/src/account.rs | 5 +- vm/e2e-tests/src/account_universe.rs | 2 +- .../src/account_universe/peer_to_peer.rs | 4 +- vm/e2e-tests/src/common_transactions.rs | 1 + vm/e2e-tests/src/executor.rs | 11 +- vm/mvhashmap/src/lib.rs | 20 +-- vm/parallel-executor/src/executor.rs | 40 ++--- vm/parallel-executor/src/scheduler.rs | 148 +++++++++--------- vm/transaction-benchmarks/src/transactions.rs | 34 ++-- vm/transaction-builder/src/lib.rs | 3 +- vm/vm-runtime/src/errors.rs | 4 +- 11 files changed, 139 insertions(+), 133 deletions(-) diff --git a/vm/e2e-tests/src/account.rs b/vm/e2e-tests/src/account.rs index b168788c0c..5022aeef32 100644 --- a/vm/e2e-tests/src/account.rs +++ b/vm/e2e-tests/src/account.rs @@ -19,9 +19,7 @@ use starcoin_vm_types::language_storage::StructTag; use starcoin_vm_types::move_resource::MoveResource; use starcoin_vm_types::state_store::state_key::StateKey; use starcoin_vm_types::token::token_code::TokenCode; -use starcoin_vm_types::transaction::authenticator::{ - AccountPrivateKey, AccountPublicKey -}; +use starcoin_vm_types::transaction::authenticator::{AccountPrivateKey, AccountPublicKey}; use starcoin_vm_types::transaction::{ RawUserTransaction, Script, ScriptFunction, SignedUserTransaction, TransactionPayload, }; @@ -687,7 +685,6 @@ impl AccountData { .as_ref() .map(|v| v.value()) .unwrap_or_else(|| Value::vector_for_testing_only(vec![])), - Value::struct_(Struct::pack(vec![ Value::u64(self.withdraw_events.count()), Value::vector_u8(self.withdraw_events.key().to_vec()), diff --git a/vm/e2e-tests/src/account_universe.rs b/vm/e2e-tests/src/account_universe.rs index e3fec93e44..a66aed1b64 100644 --- a/vm/e2e-tests/src/account_universe.rs +++ b/vm/e2e-tests/src/account_universe.rs @@ -410,7 +410,7 @@ pub fn assert_accounts_match( .read_account_resource(account.account()) .expect("account resource must exist"); let coin_store_resource = executor - .read_coin_store_resource(account.account()) + .read_balance_resource(account.account()) .expect("account balance resource must exist"); let auth_key = account.account().auth_key(); prop_assert_eq!( diff --git a/vm/e2e-tests/src/account_universe/peer_to_peer.rs b/vm/e2e-tests/src/account_universe/peer_to_peer.rs index 3bb47aa824..6bbee85201 100644 --- a/vm/e2e-tests/src/account_universe/peer_to_peer.rs +++ b/vm/e2e-tests/src/account_universe/peer_to_peer.rs @@ -37,6 +37,8 @@ impl AUTransactionGen for P2PTransferGen { .. } = self.sender_receiver.pick(universe); + // println!("sender balance : {:#?}, receiver: balance {:#?}", sender.balance, receiver.balance); + let txn = peer_to_peer_txn( sender.account(), receiver.account(), @@ -111,7 +113,7 @@ impl AUTransactionGen for P2PTransferGen { ); } } - println!("AUTransactionGen::apply | Exited: {:?}", status); + // println!("AUTransactionGen::apply | Exited: {:?}", status); (txn, (status, gas_used)) } } diff --git a/vm/e2e-tests/src/common_transactions.rs b/vm/e2e-tests/src/common_transactions.rs index 7f8b0c57e9..a47aaa7b77 100644 --- a/vm/e2e-tests/src/common_transactions.rs +++ b/vm/e2e-tests/src/common_transactions.rs @@ -102,6 +102,7 @@ pub fn peer_to_peer_txn( &starcoin_acc, receiver.address(), seq_num, + (SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() + 100) as u64, transfer_amount as u128, &ChainNetwork::new_test(), ) diff --git a/vm/e2e-tests/src/executor.rs b/vm/e2e-tests/src/executor.rs index 49681c0017..870b462918 100644 --- a/vm/e2e-tests/src/executor.rs +++ b/vm/e2e-tests/src/executor.rs @@ -9,7 +9,7 @@ use move_core_types::vm_status::KeptVMStatus; use move_table_extension::NativeTableContext; use num_cpus; use serde::{Deserialize, Serialize}; -use starcoin_config::ChainNetwork; +use starcoin_config::{ChainNetwork}; use starcoin_crypto::keygen::KeyGen; use starcoin_crypto::HashValue; use starcoin_gas::{StarcoinGasMeter, StarcoinGasParameters}; @@ -118,8 +118,9 @@ impl FakeExecutor { let fake_executor = Self::no_genesis(); let net = ChainNetwork::new_test(); let genesis_txn = Genesis::build_genesis_transaction(&net).unwrap(); - let _txn_info = + let useless = Genesis::execute_genesis_txn(fake_executor.get_state_view(), genesis_txn).unwrap(); + drop(useless); fake_executor } @@ -292,13 +293,13 @@ impl FakeExecutor { } /// Reads the CoinStore resource value for an account from this executor's data store. - pub fn read_coin_store_resource(&self, account: &Account) -> Option { - self.read_coin_store_resource_at_address(account.address()) + pub fn read_balance_resource(&self, account: &Account) -> Option { + self.read_balance_resource_at_address(account.address()) } /// Reads the CoinStore resource value for an account under the given address from this executor's /// data store. - pub fn read_coin_store_resource_at_address( + pub fn read_balance_resource_at_address( &self, addr: &AccountAddress, ) -> Option { diff --git a/vm/mvhashmap/src/lib.rs b/vm/mvhashmap/src/lib.rs index c3f098fca7..159b6ab6ed 100644 --- a/vm/mvhashmap/src/lib.rs +++ b/vm/mvhashmap/src/lib.rs @@ -125,21 +125,21 @@ impl MVHashMap { /// Delete an entry from transaction 'txn_idx' at access path 'key'. Will panic /// if the access path has never been written before. pub fn delete(&self, key: &K, txn_idx: TxnIndex) { - println!( - "{:?} - MVHashMap::delete | Exit, txn_idx: {:?}", - thread::current().id(), - txn_idx - ); + // println!( + // "{:?} - MVHashMap::delete | Exit, txn_idx: {:?}", + // thread::current().id(), + // txn_idx + // ); // TODO: investigate logical deletion. let mut map = self.data.get_mut(key).expect("Path must exist"); map.remove(&txn_idx); - println!( - "{:?} - MVHashMap::delete | Exited, txn_idx: {:?}", - thread::current().id(), - txn_idx - ); + // println!( + // "{:?} - MVHashMap::delete | Exited, txn_idx: {:?}", + // thread::current().id(), + // txn_idx + // ); } /// read may return Ok((Arc, txn_idx, incarnation)), Err(dep_txn_idx) for diff --git a/vm/parallel-executor/src/executor.rs b/vm/parallel-executor/src/executor.rs index 83b3ebc9f2..c25e4991ea 100644 --- a/vm/parallel-executor/src/executor.rs +++ b/vm/parallel-executor/src/executor.rs @@ -147,7 +147,7 @@ where ) -> SchedulerTask<'a> { let (idx_to_execute, incarnation) = version; - println!("{:?} - ParallelTransactionExecutor::execute | Entered, idx_to_execute:{:?}, incarnation: {:?}", thread::current().id(), idx_to_execute, incarnation); + // println!("{:?} - ParallelTransactionExecutor::execute | Entered, idx_to_execute:{:?}, incarnation: {:?}", thread::current().id(), idx_to_execute, incarnation); let txn = &signature_verified_block[idx_to_execute]; @@ -221,11 +221,11 @@ where versioned_data_cache: &MVHashMap<::Key, ::Value>, scheduler: &'a Scheduler, ) -> SchedulerTask<'a> { - println!( - "{:?} - ParallelTransactionExecutor::validate | Entered {:?}", - thread::current().id(), - version_to_validate - ); + // println!( + // "{:?} - ParallelTransactionExecutor::validate | Entered {:?}", + // thread::current().id(), + // version_to_validate + // ); let (idx_to_validate, incarnation) = version_to_validate; let read_set = last_input_output @@ -242,12 +242,12 @@ where let aborted = !valid && scheduler.try_abort(idx_to_validate, incarnation); - println!( - "{:?} - ParallelTransactionExecutor::validate | valid: {}, aborted: {}", - thread::current().id(), - valid, - aborted - ); + // println!( + // "{:?} - ParallelTransactionExecutor::validate | valid: {}, aborted: {}", + // thread::current().id(), + // valid, + // aborted + // ); if aborted { // Not valid and successfully aborted, mark the latest write-set as estimates. @@ -255,16 +255,16 @@ where versioned_data_cache.mark_estimate(k, idx_to_validate); } - println!( - "{:?} - ParallelTransactionExecutor::validate | Exited, aborted == true", - thread::current().id() - ); + // println!( + // "{:?} - ParallelTransactionExecutor::validate | Exited, aborted == true", + // thread::current().id() + // ); scheduler.finish_abort(idx_to_validate, incarnation, guard) } else { - println!( - "{:?} - ParallelTransactionExecutor::validate | Exited, SchedulerTask::NoTask", - thread::current().id() - ); + // println!( + // "{:?} - ParallelTransactionExecutor::validate | Exited, SchedulerTask::NoTask", + // thread::current().id() + // ); SchedulerTask::NoTask } } diff --git a/vm/parallel-executor/src/scheduler.rs b/vm/parallel-executor/src/scheduler.rs index 05cd056721..bfe0158723 100644 --- a/vm/parallel-executor/src/scheduler.rs +++ b/vm/parallel-executor/src/scheduler.rs @@ -168,32 +168,32 @@ impl Scheduler { /// returns false. Since incarnation numbers never decrease, this also ensures /// that the same version may not successfully abort more than once. pub fn try_abort(&self, txn_idx: TxnIndex, incarnation: Incarnation) -> bool { - println!( - "{:?} - Scheduler::try_abort | Entered, txn_idx: {:?}, incarnation: {:?}", - thread::current().id(), - txn_idx, - incarnation - ); + // println!( + // "{:?} - Scheduler::try_abort | Entered, txn_idx: {:?}, incarnation: {:?}", + // thread::current().id(), + // txn_idx, + // incarnation + // ); // lock the status. let mut status = self.txn_status[txn_idx].lock(); - println!( - "{:?} - Scheduler::try_abort | Status: {:?} ", - thread::current().id(), - status - ); + // println!( + // "{:?} - Scheduler::try_abort | Status: {:?} ", + // thread::current().id(), + // status + // ); if *status == TransactionStatus::Executed(incarnation) { *status = TransactionStatus::Aborting(incarnation); - println!( - "{:?} - Scheduler::try_abort | Exited, status == Executed", - thread::current().id() - ); + // println!( + // "{:?} - Scheduler::try_abort | Exited, status == Executed", + // thread::current().id() + // ); true } else { - println!( - "{:?} - Scheduler::try_abort | Exited, status != Executed", - thread::current().id() - ); + // println!( + // "{:?} - Scheduler::try_abort | Exited, status != Executed", + // thread::current().id() + // ); false } } @@ -241,12 +241,12 @@ impl Scheduler { // Note: Could pre-check that txn dep_txn_idx isn't in an executed state, but the caller // usually has just observed the read dependency. - println!( - "{:?} - Scheduler::wait_for_dependency | Entered, txn_idx: {:#?}, dep_txn_idx: {:#?}", - thread::current().id(), - txn_idx, - dep_txn_idx - ); + // println!( + // "{:?} - Scheduler::wait_for_dependency | Entered, txn_idx: {:#?}, dep_txn_idx: {:#?}", + // thread::current().id(), + // txn_idx, + // dep_txn_idx + // ); // Create a condition variable associated with the dependency. let dep_condvar = Arc::new((Mutex::new(false), Condvar::new())); @@ -263,10 +263,10 @@ impl Scheduler { // Only place in scheduler where a thread may hold >1 mutexes, hence, such // acquisitions always happens in the same order (this function), may not deadlock. - println!( - "{:?} - Scheduler::wait_for_dependency | Exited, return None", - thread::current().id(), - ); + // println!( + // "{:?} - Scheduler::wait_for_dependency | Exited, return None", + // thread::current().id(), + // ); return None; } @@ -277,7 +277,7 @@ impl Scheduler { stored_deps.push(txn_idx); } - println!("{:?} - Scheduler::wait_for_dependency | Exited, return Some(dep_condvar), condvar index: {:?}", thread::current().id(), txn_idx); + // println!("{:?} - Scheduler::wait_for_dependency | Exited, return Some(dep_condvar), condvar index: {:?}", thread::current().id(), txn_idx); Some(dep_condvar) } @@ -292,12 +292,12 @@ impl Scheduler { revalidate_suffix: bool, guard: TaskGuard<'a>, ) -> SchedulerTask<'a> { - println!( - "{:?} - Scheduler::finish_execution | Entered, txn_id: {:?}, incarnation: {:?} ", - thread::current().id(), - txn_idx, - incarnation - ); + // println!( + // "{:?} - Scheduler::finish_execution | Entered, txn_id: {:?}, incarnation: {:?} ", + // thread::current().id(), + // txn_idx, + // incarnation + // ); self.set_executed_status(txn_idx, incarnation); @@ -336,19 +336,19 @@ impl Scheduler { } else { // Only transaction txn_idx requires validation. Return validation task // back to the caller. No need to change active tasks (-1 +1= 0) - println!( - "{:?} - Scheduler::finish_execution | Exited, ValidationTask", - thread::current().id() - ); + // println!( + // "{:?} - Scheduler::finish_execution | Exited, ValidationTask", + // thread::current().id() + // ); return SchedulerTask::ValidationTask((txn_idx, incarnation), guard); } } - println!( - "{:?} - Scheduler::finish_execution | Exited, NoTask", - thread::current().id() - ); + // println!( + // "{:?} - Scheduler::finish_execution | Exited, NoTask", + // thread::current().id() + // ); SchedulerTask::NoTask } @@ -376,10 +376,10 @@ impl Scheduler { // nothing to do, as another thread must have succeeded to incarnate and // obtain the task for re-execution. if let Some((new_incarnation, maybe_condvar)) = self.try_incarnate(txn_idx) { - println!( - "{:?} - Scheduler::finish_abort | Exited, ExecutionTask", - thread::current().id() - ); + // println!( + // "{:?} - Scheduler::finish_abort | Exited, ExecutionTask", + // thread::current().id() + // ); return SchedulerTask::ExecutionTask( (txn_idx, new_incarnation), @@ -389,10 +389,10 @@ impl Scheduler { } } - println!( - "{:?} - Scheduler::finish_abort | Exited, NoTask", - thread::current().id() - ); + // println!( + // "{:?} - Scheduler::finish_abort | Exited, NoTask", + // thread::current().id() + // ); SchedulerTask::NoTask } @@ -527,11 +527,11 @@ impl Scheduler { /// incremented incarnation number. /// The caller must ensure that the transaction is in the Suspended state. fn resume(&self, txn_idx: TxnIndex) { - println!( - "{:?} - Scheduler::resume | Entered, txn_id: {:?} ", - thread::current().id(), - txn_idx - ); + // println!( + // "{:?} - Scheduler::resume | Entered, txn_id: {:?} ", + // thread::current().id(), + // txn_idx + // ); let mut status = self.txn_status[txn_idx].lock(); if let TransactionStatus::Suspended(incarnation, dep_condvar) = &*status { @@ -539,11 +539,11 @@ impl Scheduler { } else { unreachable!(); } - println!( - "{:?} - Scheduler::resume | Exited, txn_id: {:?} ", - thread::current().id(), - txn_idx - ); + // println!( + // "{:?} - Scheduler::resume | Exited, txn_id: {:?} ", + // thread::current().id(), + // txn_idx + // ); } /// Set status of the transaction to Executed(incarnation). @@ -559,12 +559,12 @@ impl Scheduler { /// After a successful abort, mark the transaction as ready for re-execution with /// an incremented incarnation number. fn set_aborted_status(&self, txn_idx: TxnIndex, incarnation: Incarnation) { - println!( - "{:?} - Scheduler::set_aborted_status | Entered, txn_id: {:?}, incarnation: {:?}", - thread::current().id(), - txn_idx, - incarnation - ); + // println!( + // "{:?} - Scheduler::set_aborted_status | Entered, txn_id: {:?}, incarnation: {:?}", + // thread::current().id(), + // txn_idx, + // incarnation + // ); let mut status = self.txn_status[txn_idx].lock(); @@ -573,12 +573,12 @@ impl Scheduler { *status = TransactionStatus::ReadyToExecute(incarnation + 1, None); - println!( - "{:?} - Scheduler::set_aborted_status | Exited, txn_id: {:?}, incarnation: {:?}", - thread::current().id(), - txn_idx, - incarnation - ); + // println!( + // "{:?} - Scheduler::set_aborted_status | Exited, txn_id: {:?}, incarnation: {:?}", + // thread::current().id(), + // txn_idx, + // incarnation + // ); } /// A lazy, check of whether the scheduler execution is completed. diff --git a/vm/transaction-benchmarks/src/transactions.rs b/vm/transaction-benchmarks/src/transactions.rs index 48f2b1188f..02807a9baf 100644 --- a/vm/transaction-benchmarks/src/transactions.rs +++ b/vm/transaction-benchmarks/src/transactions.rs @@ -8,7 +8,7 @@ use proptest::{ test_runner::TestRunner, }; use starcoin_crypto::HashValue; -use std::time::Instant; +use std::time::{Instant, SystemTime, UNIX_EPOCH}; use starcoin_language_e2e_tests::account::AccountData; use starcoin_language_e2e_tests::{ @@ -20,7 +20,7 @@ use starcoin_language_e2e_tests::{ use starcoin_types::{block_metadata::BlockMetadata, transaction::Transaction}; use starcoin_vm_runtime::{ - parallel_executor::ParallelStarcoinVM, starcoin_vm::StarcoinVM, VMExecutor, + parallel_executor::ParallelStarcoinVM, starcoin_vm::StarcoinVM, }; use starcoin_vm_types::genesis_config::ChainId; use starcoin_vm_types::transaction::authenticator::AuthenticationKey; @@ -106,11 +106,9 @@ where num_runs: usize, ) -> Vec { let mut ret = Vec::new(); - let total_runs = num_warmups + num_runs; for i in 0..total_runs { let state = TransactionBenchState::with_size(&self.strategy, num_accounts, num_txn); - if i < num_warmups { println!("WARMUP - ignore results"); state.execute(); @@ -208,23 +206,25 @@ impl TransactionBenchState { // vec![], // 1, // ); - let minter_account = AccountData::new(10000, 0); + + let minter_account = AccountData::new(10_000_000_000, 0); + state.executor.add_account_data(&minter_account); + let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64; let new_block = BlockMetadata::new( HashValue::zero(), - 0, + timestamp, minter_account.address().clone(), Some(AuthenticationKey::ed25519( &minter_account.account().public_key(), )), 0, - 0, + 1, ChainId::test(), 0, ); state .transactions .insert(0, Transaction::BlockMetadata(new_block)); - state } @@ -276,13 +276,17 @@ impl TransactionBenchState { // this bench execution with TPS let timer = Instant::now(); - let useless = StarcoinVM::execute_block( - self.transactions, - self.executor.get_state_view(), - None, - None, - ) - .expect("VM should not fail to start"); + let useless = self + .executor + .execute_transaction_block(self.transactions) + .expect("VM should not fail to start"); + // let useless = StarcoinVM::execute_block( + // self.transactions, + // self.executor.get_state_view(), + // None, + // None, + // ) + // .expect("VM should not fail to start"); drop(useless); diff --git a/vm/transaction-builder/src/lib.rs b/vm/transaction-builder/src/lib.rs index e911bf5204..c97b4771d3 100644 --- a/vm/transaction-builder/src/lib.rs +++ b/vm/transaction-builder/src/lib.rs @@ -299,6 +299,7 @@ pub fn peer_to_peer_v2( sender: &Account, recipient: &AccountAddress, seq_num: u64, + expiration_timestamp_secs: u64, amount: u128, net: &ChainNetwork, ) -> SignedUserTransaction { @@ -319,7 +320,7 @@ pub fn peer_to_peer_v2( )), 10000000, 1, - 1000 + 60 * 60, + expiration_timestamp_secs, net.chain_id(), )) } diff --git a/vm/vm-runtime/src/errors.rs b/vm/vm-runtime/src/errors.rs index 8f7d68ecf4..40e582bd11 100644 --- a/vm/vm-runtime/src/errors.rs +++ b/vm/vm-runtime/src/errors.rs @@ -41,12 +41,12 @@ pub fn error_split(code: u64) -> (u8, u64) { } pub fn convert_prologue_runtime_error(error: VMError) -> Result<(), VMStatus> { + println!("convert_prologue_runtime_error VMError: {:#?}", error); let status = error.into_vm_status(); - println!("convert_prologue_runtime_error: {:#?}", status.clone()); + Err(match status { VMStatus::Executed => VMStatus::Executed, VMStatus::MoveAbort(location, code) => { - println!("convert_prologue_runtime_error, error: {:#?}", location); let (category, reason) = error_split(code); let new_major_status = match (category, reason) { (REQUIRES_ADDRESS, PROLOGUE_ACCOUNT_DOES_NOT_EXIST) => { From 40af6d13a3c1a6e92655a5a98095d23902b822f4 Mon Sep 17 00:00:00 2001 From: welbon Date: Mon, 25 Sep 2023 09:29:32 +0800 Subject: [PATCH 20/23] [benchmark-log] add unittest for transaction --- executor/tests/error_code_test.rs | 87 +++++++++++++++++++ vm/e2e-tests/src/common_transactions.rs | 6 +- vm/e2e-tests/src/executor.rs | 2 +- vm/transaction-benchmarks/src/transactions.rs | 9 +- 4 files changed, 98 insertions(+), 6 deletions(-) diff --git a/executor/tests/error_code_test.rs b/executor/tests/error_code_test.rs index cef86b1cd3..a23fb73e9e 100644 --- a/executor/tests/error_code_test.rs +++ b/executor/tests/error_code_test.rs @@ -14,6 +14,7 @@ use starcoin_types::{ account::Account, block_metadata::BlockMetadata, transaction::Transaction, transaction::TransactionStatus, }; +use starcoin_vm_runtime::starcoin_vm::StarcoinVM; use starcoin_vm_types::account_address::AccountAddress; use starcoin_vm_types::account_config::core_code_address; use starcoin_vm_types::account_config::{genesis_address, stc_type_tag}; @@ -26,6 +27,7 @@ use starcoin_vm_types::transaction::TransactionPayload; use starcoin_vm_types::vm_status::KeptVMStatus; use starcoin_vm_types::vm_status::StatusCode; use std::str::FromStr; +use starcoin_state_api::ChainStateWriter; use test_helper::executor::*; use test_helper::executor::{association_execute, execute_and_apply, prepare_genesis}; use test_helper::txn::create_account_txn_sent_as_association; @@ -252,3 +254,88 @@ fn test_call_deprecated_function() -> Result<()> { // assert_eq!(Some(4875), move_abort_code(status)); Ok(()) } + +#[stest::test] +fn test_stm_dependency() -> Result<()> { + let (chain_state, net) = prepare_genesis(); + + let account1 = Account::new(); + let txn1 = Transaction::UserTransaction(create_account_txn_sent_as_association( + &account1, 0, 50_000_000, 1, &net, + )); + let output1 = execute_and_apply(&chain_state, txn1); + assert_eq!(KeptVMStatus::Executed, output1.status().status().unwrap()); + + let account2 = Account::new(); + + let txn2 = Transaction::UserTransaction(account1.sign_txn( + starcoin_transaction_builder::build_transfer_txn( + *account1.address(), + *account2.address(), + 0, + 1000, + 1, + DEFAULT_MAX_GAS_AMOUNT, + net.time_service().now_secs() + DEFAULT_EXPIRATION_TIME, + net.chain_id(), + ), + )); + + let output2 = execute_and_apply(&chain_state, txn2); + assert_eq!(KeptVMStatus::Executed, output2.status().status().unwrap()); + + let txn3 = Transaction::UserTransaction(account1.sign_txn( + starcoin_transaction_builder::build_transfer_txn( + *account1.address(), + *account2.address(), + 1, + 1000, + 1, + DEFAULT_MAX_GAS_AMOUNT, + net.time_service().now_secs() + DEFAULT_EXPIRATION_TIME, + net.chain_id(), + ), + )); + + let txn4 = Transaction::UserTransaction(account1.sign_txn( + starcoin_transaction_builder::build_transfer_txn( + *account1.address(), + *account2.address(), + 2, + 1000, + 1, + DEFAULT_MAX_GAS_AMOUNT, + net.time_service().now_secs() + DEFAULT_EXPIRATION_TIME, + net.chain_id(), + ), + )); + // + // let txn5 = Transaction::UserTransaction(account1.sign_txn( + // starcoin_transaction_builder::build_transfer_txn( + // *account1.address(), + // *account2.address(), + // 1, + // 1000, + // 1, + // DEFAULT_MAX_GAS_AMOUNT, + // net.time_service().now_secs() + DEFAULT_EXPIRATION_TIME, + // net.chain_id(), + // ), + // )); + + StarcoinVM::set_concurrency_level_once(4); + + let outputs = + starcoin_executor::execute_transactions(&chain_state, vec![txn3, txn4], None).unwrap(); + + outputs.into_iter().for_each(|output| { + if let TransactionStatus::Keep(_) = output.status() { + chain_state + .apply_write_set(output.write_set().clone()) + .expect("apply write_set should success."); + chain_state.commit().expect("commit should success."); + } + }); + + Ok(()) +} diff --git a/vm/e2e-tests/src/common_transactions.rs b/vm/e2e-tests/src/common_transactions.rs index a47aaa7b77..e79c8237b1 100644 --- a/vm/e2e-tests/src/common_transactions.rs +++ b/vm/e2e-tests/src/common_transactions.rs @@ -102,7 +102,11 @@ pub fn peer_to_peer_txn( &starcoin_acc, receiver.address(), seq_num, - (SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() + 100) as u64, + (SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs() + + 100) as u64, transfer_amount as u128, &ChainNetwork::new_test(), ) diff --git a/vm/e2e-tests/src/executor.rs b/vm/e2e-tests/src/executor.rs index 870b462918..94afa23ad3 100644 --- a/vm/e2e-tests/src/executor.rs +++ b/vm/e2e-tests/src/executor.rs @@ -9,7 +9,7 @@ use move_core_types::vm_status::KeptVMStatus; use move_table_extension::NativeTableContext; use num_cpus; use serde::{Deserialize, Serialize}; -use starcoin_config::{ChainNetwork}; +use starcoin_config::ChainNetwork; use starcoin_crypto::keygen::KeyGen; use starcoin_crypto::HashValue; use starcoin_gas::{StarcoinGasMeter, StarcoinGasParameters}; diff --git a/vm/transaction-benchmarks/src/transactions.rs b/vm/transaction-benchmarks/src/transactions.rs index 02807a9baf..855f16297b 100644 --- a/vm/transaction-benchmarks/src/transactions.rs +++ b/vm/transaction-benchmarks/src/transactions.rs @@ -19,9 +19,7 @@ use starcoin_language_e2e_tests::{ use starcoin_types::{block_metadata::BlockMetadata, transaction::Transaction}; -use starcoin_vm_runtime::{ - parallel_executor::ParallelStarcoinVM, starcoin_vm::StarcoinVM, -}; +use starcoin_vm_runtime::{parallel_executor::ParallelStarcoinVM, starcoin_vm::StarcoinVM}; use starcoin_vm_types::genesis_config::ChainId; use starcoin_vm_types::transaction::authenticator::AuthenticationKey; @@ -209,7 +207,10 @@ impl TransactionBenchState { let minter_account = AccountData::new(10_000_000_000, 0); state.executor.add_account_data(&minter_account); - let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64; + let timestamp = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() as u64; let new_block = BlockMetadata::new( HashValue::zero(), timestamp, From 68d22e3049a7e17f167b7bfaeaaa570a3d1f7e2b Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Mon, 25 Sep 2023 11:44:18 +0800 Subject: [PATCH 21/23] add balance --- executor/tests/error_code_test.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/executor/tests/error_code_test.rs b/executor/tests/error_code_test.rs index a23fb73e9e..801cbac9f3 100644 --- a/executor/tests/error_code_test.rs +++ b/executor/tests/error_code_test.rs @@ -336,6 +336,8 @@ fn test_stm_dependency() -> Result<()> { chain_state.commit().expect("commit should success."); } }); + let balance = get_balance(*account2.address(), &chain_state); + assert_eq!(balance, 3000); Ok(()) } From ea84a911662c32117687b6ae5a14bb36d9bed480 Mon Sep 17 00:00:00 2001 From: welbon Date: Mon, 25 Sep 2023 18:55:13 +0800 Subject: [PATCH 22/23] [e2e-test] fix error EPROLOGUE_CANT_PAY_GAS_DEPOSIT --- executor/tests/error_code_test.rs | 2 +- .../src/account_universe/peer_to_peer.rs | 5 +++ vm/e2e-tests/src/gas_costs.rs | 8 ++-- vm/transaction-benchmarks/src/lib.rs | 3 ++ vm/transaction-benchmarks/src/main.rs | 4 +- .../src/test_peer_to_peer.rs | 45 +++++++++++++++++++ vm/transaction-benchmarks/src/transactions.rs | 3 +- 7 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 vm/transaction-benchmarks/src/test_peer_to_peer.rs diff --git a/executor/tests/error_code_test.rs b/executor/tests/error_code_test.rs index 801cbac9f3..299fc6c438 100644 --- a/executor/tests/error_code_test.rs +++ b/executor/tests/error_code_test.rs @@ -4,6 +4,7 @@ use anyhow::Result; use once_cell::sync::Lazy; use starcoin_crypto::hash::PlainCryptoHash; +use starcoin_state_api::ChainStateWriter; use starcoin_transaction_builder::{ encode_transfer_script_by_token_code, DEFAULT_EXPIRATION_TIME, DEFAULT_MAX_GAS_AMOUNT, }; @@ -27,7 +28,6 @@ use starcoin_vm_types::transaction::TransactionPayload; use starcoin_vm_types::vm_status::KeptVMStatus; use starcoin_vm_types::vm_status::StatusCode; use std::str::FromStr; -use starcoin_state_api::ChainStateWriter; use test_helper::executor::*; use test_helper::executor::{association_execute, execute_and_apply, prepare_genesis}; use test_helper::txn::create_account_txn_sent_as_association; diff --git a/vm/e2e-tests/src/account_universe/peer_to_peer.rs b/vm/e2e-tests/src/account_universe/peer_to_peer.rs index 6bbee85201..37490095b9 100644 --- a/vm/e2e-tests/src/account_universe/peer_to_peer.rs +++ b/vm/e2e-tests/src/account_universe/peer_to_peer.rs @@ -46,6 +46,11 @@ impl AUTransactionGen for P2PTransferGen { self.amount, ); + println!( + "AUTransactionGen::apply | sender balance: {:#?}", + sender.balance + ); + // Now figure out whether the transaction will actually work. // This means that we'll get through the main part of the transaction. let enough_to_transfer = sender.balance >= self.amount; diff --git a/vm/e2e-tests/src/gas_costs.rs b/vm/e2e-tests/src/gas_costs.rs index c491ca2973..992fbbb945 100644 --- a/vm/e2e-tests/src/gas_costs.rs +++ b/vm/e2e-tests/src/gas_costs.rs @@ -13,7 +13,7 @@ use starcoin_crypto::{ed25519::Ed25519PrivateKey, PrivateKey, Uniform}; use starcoin_vm_types::transaction::{authenticator::AuthenticationKey, SignedUserTransaction}; /// The gas each transaction is configured to reserve. If the gas available in the account, -/// converted to microaptos, falls below this threshold, transactions are expected to fail with +/// converted to micro starcoin, falls below this threshold, transactions are expected to fail with /// an insufficient balance. pub const TXN_RESERVED: u64 = 500_000; @@ -133,12 +133,12 @@ pub static CREATE_EXISTING_ACCOUNT_NEXT: Lazy = Lazy::new(|| { pub static PEER_TO_PEER: Lazy = Lazy::new(|| { // Compute gas used by running a placeholder transaction. let mut executor = FakeExecutor::from_genesis_file(); - let sender = AccountData::new(1_000_000, 10); - let receiver = AccountData::new(1_000_000, 10); + let sender = AccountData::new(1_000_000_000, 10); + let receiver = AccountData::new(1_000_000_000, 10); executor.add_account_data(&sender); executor.add_account_data(&receiver); - let txn = peer_to_peer_txn(sender.account(), receiver.account(), 10, 20_000); + let txn = peer_to_peer_txn(sender.account(), receiver.account(), 10, 10); compute_gas_used(txn, &mut executor) }); diff --git a/vm/transaction-benchmarks/src/lib.rs b/vm/transaction-benchmarks/src/lib.rs index 723e0620bf..1191e8b4c8 100644 --- a/vm/transaction-benchmarks/src/lib.rs +++ b/vm/transaction-benchmarks/src/lib.rs @@ -8,3 +8,6 @@ pub mod measurement; #[cfg(any(test, feature = "fuzzing"))] pub mod transactions; + +#[cfg(test)] +mod test_peer_to_peer; diff --git a/vm/transaction-benchmarks/src/main.rs b/vm/transaction-benchmarks/src/main.rs index 92509695fd..3267c58393 100644 --- a/vm/transaction-benchmarks/src/main.rs +++ b/vm/transaction-benchmarks/src/main.rs @@ -14,7 +14,7 @@ fn main() { ); let acts = [2]; - let txns = [1]; + let txns = [1000]; let num_warmups = 0; let num_runs = 1; @@ -23,7 +23,7 @@ fn main() { for block_size in txns { for num_accounts in acts { let mut times = - bencher.manual_sequence(num_accounts, block_size, num_warmups, num_runs); + bencher.manual_parallel(num_accounts, block_size, num_warmups, num_runs); times.sort(); measurements.push(times); } diff --git a/vm/transaction-benchmarks/src/test_peer_to_peer.rs b/vm/transaction-benchmarks/src/test_peer_to_peer.rs new file mode 100644 index 0000000000..d73b09172c --- /dev/null +++ b/vm/transaction-benchmarks/src/test_peer_to_peer.rs @@ -0,0 +1,45 @@ +// Copyright (c) The Starcoin Core Contributors +// SPDX-License-Identifier: Apache-2.0 + +use crate::transactions::TransactionBencher; +use proptest::arbitrary::any_with; +use starcoin_language_e2e_tests::account::AccountData; +use starcoin_language_e2e_tests::account_universe::P2PTransferGen; +use starcoin_language_e2e_tests::common_transactions::peer_to_peer_txn; +use starcoin_language_e2e_tests::executor::FakeExecutor; + +#[test] +pub fn bencher_sequence() { + let default_num_account = 2; + let default_num_transactions = 1; + let maxium_transfer_balance = 100; + let minium_transfer_balance = 10; + + let bencher = TransactionBencher::new( + any_with::((minium_transfer_balance, maxium_transfer_balance)), + default_num_account, + default_num_transactions, + ); + bencher.manual_sequence(default_num_account, default_num_transactions, 1, 1); +} + +#[test] +pub fn fake_execute_with_account_data() { + // Compute gas used by running a placeholder transaction. + let mut executor = FakeExecutor::from_genesis_file(); + let sender = AccountData::new(1_000_000_000, 10); + let receiver = AccountData::new(1_000_000_000, 10); + executor.add_account_data(&sender); + executor.add_account_data(&receiver); + + let txn = peer_to_peer_txn(sender.account(), receiver.account(), 10, 10); + let result = executor.execute_block(vec![txn]); + match result { + Ok(outputs) => { + println!("Outputs: {:#?}", outputs); + } + Err(err) => { + println!("Error: {:#?}", err); + } + } +} diff --git a/vm/transaction-benchmarks/src/transactions.rs b/vm/transaction-benchmarks/src/transactions.rs index 855f16297b..b6cb7e2294 100644 --- a/vm/transaction-benchmarks/src/transactions.rs +++ b/vm/transaction-benchmarks/src/transactions.rs @@ -207,6 +207,7 @@ impl TransactionBenchState { let minter_account = AccountData::new(10_000_000_000, 0); state.executor.add_account_data(&minter_account); + let timestamp = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() @@ -316,7 +317,7 @@ fn universe_strategy( num_transactions: usize, ) -> impl Strategy { // Multiply by 5 past the number of to provide - let max_balance = TXN_RESERVED * num_transactions as u64 * 5; + let max_balance = 5_000_000_000;//TXN_RESERVED * num_transactions as u64 * 10_000; let balance_strategy = log_balance_strategy(max_balance); AccountUniverseGen::strategy(num_accounts, balance_strategy) } From f9575e6ac79055673b6bd4578fbb0d67b1c1ccf4 Mon Sep 17 00:00:00 2001 From: welbon Date: Mon, 25 Sep 2023 19:15:03 +0800 Subject: [PATCH 23/23] [e2e-test] disable all print --- .../src/account_universe/peer_to_peer.rs | 8 ++++---- vm/mvhashmap/src/lib.rs | 18 +++++++++--------- vm/parallel-executor/src/executor.rs | 8 ++++---- vm/transaction-benchmarks/src/main.rs | 8 ++++---- vm/vm-runtime/src/errors.rs | 2 +- .../src/parallel_executor/vm_wrapper.rs | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/vm/e2e-tests/src/account_universe/peer_to_peer.rs b/vm/e2e-tests/src/account_universe/peer_to_peer.rs index 37490095b9..012c5aa59e 100644 --- a/vm/e2e-tests/src/account_universe/peer_to_peer.rs +++ b/vm/e2e-tests/src/account_universe/peer_to_peer.rs @@ -46,10 +46,10 @@ impl AUTransactionGen for P2PTransferGen { self.amount, ); - println!( - "AUTransactionGen::apply | sender balance: {:#?}", - sender.balance - ); + // println!( + // "AUTransactionGen::apply | sender balance: {:#?}", + // sender.balance + // ); // Now figure out whether the transaction will actually work. // This means that we'll get through the main part of the transaction. diff --git a/vm/mvhashmap/src/lib.rs b/vm/mvhashmap/src/lib.rs index 159b6ab6ed..dc8306c9e8 100644 --- a/vm/mvhashmap/src/lib.rs +++ b/vm/mvhashmap/src/lib.rs @@ -105,21 +105,21 @@ impl MVHashMap { /// Mark an entry from transaction 'txn_idx' at access path 'key' as an estimated write /// (for future incarnation). Will panic if the entry is not in the data-structure. pub fn mark_estimate(&self, key: &K, txn_idx: TxnIndex) { - println!( - "{:?} - MVHashMap::mark_estimate | Entered, txn_id: {:?}", - thread::current().id(), - txn_idx - ); + // println!( + // "{:?} - MVHashMap::mark_estimate | Entered, txn_id: {:?}", + // thread::current().id(), + // txn_idx + // ); let map = self.data.get(key).expect("Path must exist"); map.get(&txn_idx) .expect("Entry by txn must exist") .mark_estimate(); - println!( - "{:?} - MVHashMap::mark_estimate | Exited", - thread::current().id() - ); + // println!( + // "{:?} - MVHashMap::mark_estimate | Exited", + // thread::current().id() + // ); } /// Delete an entry from transaction 'txn_idx' at access path 'key'. Will panic diff --git a/vm/parallel-executor/src/executor.rs b/vm/parallel-executor/src/executor.rs index c25e4991ea..397684380b 100644 --- a/vm/parallel-executor/src/executor.rs +++ b/vm/parallel-executor/src/executor.rs @@ -182,17 +182,17 @@ where ExecutionStatus::Success(output) => { // Apply the writes to the versioned_data_cache. apply_writes(&output); - println!("{:?} - ParallelTransactionExecutor::execute | after executor.execute_transaction, ExecutionStatus::Success, output len: {:?}", thread::current().id(), output.get_writes().len()); + // println!("{:?} - ParallelTransactionExecutor::execute | after executor.execute_transaction, ExecutionStatus::Success, output len: {:?}", thread::current().id(), output.get_writes().len()); ExecutionStatus::Success(output) } ExecutionStatus::SkipRest(output) => { // Apply the writes and record status indicating skip. apply_writes(&output); - println!("{:?} - ParallelTransactionExecutor::execute | after executor.execute_transaction, ExecutionStatus::SkipRest", thread::current().id()); + // println!("{:?} - ParallelTransactionExecutor::execute | after executor.execute_transaction, ExecutionStatus::SkipRest", thread::current().id()); ExecutionStatus::SkipRest(output) } ExecutionStatus::Abort(err) => { - println!("{:?} - MVHashMap::execute | after executor.execute_transaction, ExecutionStatus::Abort", thread::current().id()); + // println!("{:?} - MVHashMap::execute | after executor.execute_transaction, ExecutionStatus::Abort", thread::current().id()); // Record the status indicating abort. ExecutionStatus::Abort(Error::UserError(err)) } @@ -205,7 +205,7 @@ where last_input_output.record(idx_to_execute, state_view.take_reads(), result); - println!("{:?} - ParallelTransactionExecutor::execute | Exited, idx_to_execute:{:?}, incarnation: {:?}", thread::current().id(), idx_to_execute, incarnation); + // println!("{:?} - ParallelTransactionExecutor::execute | Exited, idx_to_execute:{:?}, incarnation: {:?}", thread::current().id(), idx_to_execute, incarnation); scheduler.finish_execution(idx_to_execute, incarnation, writes_outside, guard) } diff --git a/vm/transaction-benchmarks/src/main.rs b/vm/transaction-benchmarks/src/main.rs index 3267c58393..04af0c7e35 100644 --- a/vm/transaction-benchmarks/src/main.rs +++ b/vm/transaction-benchmarks/src/main.rs @@ -13,10 +13,10 @@ fn main() { default_num_transactions, ); - let acts = [2]; - let txns = [1000]; - let num_warmups = 0; - let num_runs = 1; + let acts = [10000,]; + let txns = [500000]; + let num_warmups = 2; + let num_runs = 10; let mut measurements = Vec::new(); diff --git a/vm/vm-runtime/src/errors.rs b/vm/vm-runtime/src/errors.rs index 40e582bd11..c10c461960 100644 --- a/vm/vm-runtime/src/errors.rs +++ b/vm/vm-runtime/src/errors.rs @@ -41,7 +41,7 @@ pub fn error_split(code: u64) -> (u8, u64) { } pub fn convert_prologue_runtime_error(error: VMError) -> Result<(), VMStatus> { - println!("convert_prologue_runtime_error VMError: {:#?}", error); + // println!("convert_prologue_runtime_error VMError: {:#?}", error); let status = error.into_vm_status(); Err(match status { diff --git a/vm/vm-runtime/src/parallel_executor/vm_wrapper.rs b/vm/vm-runtime/src/parallel_executor/vm_wrapper.rs index 127f71359d..4a568084de 100644 --- a/vm/vm-runtime/src/parallel_executor/vm_wrapper.rs +++ b/vm/vm-runtime/src/parallel_executor/vm_wrapper.rs @@ -49,7 +49,7 @@ impl<'a, S: 'a + StateView> ExecutorTask for StarcoinVMWrapper<'a, S> { txn: &PreprocessedTransaction, ) -> ExecutionStatus { let versioned_view = VersionedView::new_view(self.base_view, view); - println!("StarcoinVMWrapper::execute_transaction, txn: {:#?}", txn); + // println!("StarcoinVMWrapper::execute_transaction, txn: {:#?}", txn); match self.vm.execute_single_transaction(txn, &versioned_view) { Ok((vm_status, output, sender)) => { if output.status().is_discarded() {