Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[BlockSTM] Per-block Gas Limit #7488

Merged
merged 65 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
a2fdc21
Halt PE when module r/w intersects
danielxiangzl Dec 10, 2022
fde12ef
Refactoring
danielxiangzl Dec 11, 2022
eeac7ae
adding ExecutionHalted
danielxiangzl Dec 12, 2022
a7fd742
fix
danielxiangzl Dec 12, 2022
25db9d5
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Dec 12, 2022
e14d371
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Dec 17, 2022
b801351
rebase
danielxiangzl Dec 20, 2022
36c661d
address comments
danielxiangzl Dec 20, 2022
13b386c
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Dec 20, 2022
2591610
address comments
danielxiangzl Dec 21, 2022
588dd4d
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Dec 21, 2022
a223680
address comments
danielxiangzl Dec 22, 2022
f8c4f85
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Dec 22, 2022
90ab072
nit
danielxiangzl Dec 22, 2022
84d8090
rebase
danielxiangzl Feb 2, 2023
ce8e383
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Feb 2, 2023
4b56d43
update comments
danielxiangzl Feb 2, 2023
66f5a93
lint
danielxiangzl Feb 2, 2023
cea3c06
Merge branch 'daniel-PE-module-fallback' of github.com:aptos-labs/apt…
danielxiangzl Feb 2, 2023
517f818
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Feb 3, 2023
8e2fee7
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Mar 6, 2023
985d829
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Mar 8, 2023
752bd1a
Merge branch 'main' into daniel-PE-module-fallback
danielxiangzl Mar 12, 2023
1fdf0a7
Merge branch 'main' into daniel-module-fallback
danielxiangzl Mar 29, 2023
13b9426
lint and tests
danielxiangzl Mar 29, 2023
84e7fdc
adding early halt for Abort and SkipRest
danielxiangzl Mar 30, 2023
585eb60
add per block gas
danielxiangzl Mar 30, 2023
3938ca1
sequential gas limit
danielxiangzl Mar 30, 2023
92c4b8b
resolving comments and adding metric counters
danielxiangzl Apr 3, 2023
9c27d1a
adding back StateCheckpoint
danielxiangzl Apr 4, 2023
f4f4d91
passing per-block gas limit to execution, but not state sync
danielxiangzl Apr 5, 2023
5e30733
gas limit on benchmarks
danielxiangzl Apr 5, 2023
fa5b942
refactor statecheckpoint, fix part of executor tests
danielxiangzl Apr 5, 2023
54a4425
append statecheckpoint when commit, fix more tests
danielxiangzl Apr 6, 2023
f604e90
nit
danielxiangzl Apr 6, 2023
c74d2df
resolve comments
danielxiangzl Apr 7, 2023
911cadf
adding tests for block gas limit
danielxiangzl Apr 10, 2023
57e9fb6
adding on chain config and fix tests
danielxiangzl Apr 11, 2023
9af8e45
test compatibility
danielxiangzl Apr 11, 2023
596c21b
Merge branch 'main' into daniel-per-block-gas
danielxiangzl Apr 11, 2023
439ce6a
fix tests, test block gas limit on forge
danielxiangzl Apr 12, 2023
c389a67
Merge branch 'daniel-per-block-gas' of github.com:aptos-labs/aptos-co…
danielxiangzl Apr 12, 2023
0361873
more counters
danielxiangzl Apr 12, 2023
b50b6ca
rebase
danielxiangzl Apr 18, 2023
413b4e3
Merge branch 'main' into daniel-per-block-gas
danielxiangzl Apr 18, 2023
adc0ae6
nit
danielxiangzl Apr 18, 2023
217356b
only flush logs of committed txns
danielxiangzl Apr 18, 2023
e3d39e7
Merge branch 'main' into daniel-per-block-gas
danielxiangzl Apr 21, 2023
88465a9
rebase
danielxiangzl Apr 24, 2023
84b6fff
fix commit race
danielxiangzl May 11, 2023
a09e522
resolve comments
danielxiangzl May 11, 2023
d092021
rebase
danielxiangzl May 11, 2023
eddab15
Merge branch 'main' into daniel-per-block-gas
danielxiangzl May 11, 2023
240ed5b
nit
danielxiangzl May 11, 2023
4c7b2df
Merge branch 'daniel-per-block-gas' of github.com:aptos-labs/aptos-co…
danielxiangzl May 11, 2023
5e5acf3
rebase
danielxiangzl May 15, 2023
d7ea33b
on-chain config default
danielxiangzl May 15, 2023
575c04f
Merge branch 'main' into daniel-per-block-gas
danielxiangzl May 15, 2023
bc4a4cd
nit
danielxiangzl May 16, 2023
3dbad83
Merge branch 'daniel-per-block-gas' of github.com:aptos-labs/aptos-co…
danielxiangzl May 16, 2023
0e34687
Merge branch 'main' into daniel-per-block-gas
danielxiangzl May 16, 2023
18b903a
rebase
danielxiangzl May 17, 2023
2451a1c
Merge branch 'main' into daniel-per-block-gas
danielxiangzl May 17, 2023
110cb60
rebase
danielxiangzl May 17, 2023
dfd15ce
Merge branch 'daniel-per-block-gas' of github.com:aptos-labs/aptos-co…
danielxiangzl May 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aptos-move/aptos-transaction-benchmarks/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn main() {

let mut measurements: Vec<Vec<(usize, usize)>> = Vec::new();
let concurrency_level = num_cpus::get();
let maybe_gas_limit = None;

for block_size in txns {
for num_accounts in acts {
Expand All @@ -25,6 +26,7 @@ fn main() {
num_warmups,
num_runs,
concurrency_level,
maybe_gas_limit,
);
times.sort();
measurements.push(times);
Expand Down
15 changes: 11 additions & 4 deletions aptos-move/aptos-transaction-benchmarks/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ where
num_warmups: usize,
num_runs: usize,
concurrency_level: usize,
maybe_gas_limit: Option<u64>,
) -> Vec<(usize, usize)> {
let mut ret = Vec::new();

Expand All @@ -110,7 +111,7 @@ where

if i < num_warmups {
println!("WARMUP - ignore results");
state.execute_blockstm_benchmark(concurrency_level);
state.execute_blockstm_benchmark(concurrency_level, maybe_gas_limit);
} else {
println!(
"RUN BlockSTM-only benchmark for: num_threads = {}, \
Expand All @@ -120,7 +121,7 @@ where
num_accounts,
num_txn,
);
ret.push(state.execute_blockstm_benchmark(concurrency_level));
ret.push(state.execute_blockstm_benchmark(concurrency_level, maybe_gas_limit));
}
}

Expand Down Expand Up @@ -220,7 +221,7 @@ impl TransactionBenchState {
fn execute(self) {
// The output is ignored here since we're just testing transaction performance, not trying
// to assert correctness.
BlockAptosVM::execute_block(self.transactions, self.executor.get_state_view(), 1)
BlockAptosVM::execute_block(self.transactions, self.executor.get_state_view(), 1, None)
.expect("VM should not fail to start");
}

Expand All @@ -232,15 +233,21 @@ impl TransactionBenchState {
self.transactions,
self.executor.get_state_view(),
num_cpus::get(),
None,
)
.expect("VM should not fail to start");
}

fn execute_blockstm_benchmark(self, concurrency_level: usize) -> (usize, usize) {
fn execute_blockstm_benchmark(
self,
concurrency_level: usize,
maybe_gas_limit: Option<u64>,
) -> (usize, usize) {
BlockAptosVM::execute_block_benchmark(
self.transactions,
self.executor.get_state_view(),
concurrency_level,
maybe_gas_limit,
)
}
}
Expand Down
41 changes: 39 additions & 2 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,8 +1483,45 @@ impl VMExecutor for AptosVM {
);

let count = transactions.len();
let ret =
BlockAptosVM::execute_block(transactions, state_view, Self::get_concurrency_level());
let ret = BlockAptosVM::execute_block(
transactions,
state_view,
Self::get_concurrency_level(),
None,
);
if ret.is_ok() {
// Record the histogram count for transactions per block.
BLOCK_TRANSACTION_COUNT.observe(count as f64);
}
ret
}

fn execute_block_with_gas_limit(
transactions: Vec<Transaction>,
state_view: &(impl StateView + Sync),
maybe_gas_limit: Option<u64>,
) -> std::result::Result<Vec<TransactionOutput>, VMStatus> {
fail_point!("move_adapter::execute_block", |_| {
Err(VMStatus::Error(
StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR,
None,
))
});

let log_context = AdapterLogSchema::new(state_view.id(), 0);
info!(
log_context,
"Executing block, transaction count: {}",
transactions.len()
);

let count = transactions.len();
let ret = BlockAptosVM::execute_block(
transactions,
state_view,
Self::get_concurrency_level(),
maybe_gas_limit,
);
if ret.is_ok() {
// Record the histogram count for transactions per block.
BLOCK_TRANSACTION_COUNT.observe(count as f64);
Expand Down
15 changes: 13 additions & 2 deletions aptos-move/aptos-vm/src/block_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ impl BlockExecutorTransactionOutput for AptosTransactionOutput {
TransactionStatus::Retry,
)))
}

/// Return the amount of gas consumed by the transaction.
fn gas_used(&self) -> u64 {
gelash marked this conversation as resolved.
Show resolved Hide resolved
self.0.txn_output().gas_used()
}
}

pub struct BlockAptosVM();
Expand All @@ -90,6 +95,7 @@ impl BlockAptosVM {
transactions: Vec<Transaction>,
state_view: &S,
concurrency_level: usize,
maybe_gas_limit: Option<u64>,
) -> Result<Vec<TransactionOutput>, VMStatus> {
let _timer = BLOCK_EXECUTOR_EXECUTE_BLOCK_SECONDS.start_timer();
// Verify the signatures of all the transactions in parallel.
Expand All @@ -112,6 +118,7 @@ impl BlockAptosVM {
BLOCK_EXECUTOR_CONCURRENCY.set(concurrency_level as i64);
let executor = BlockExecutor::<PreprocessedTransaction, AptosExecutorTask<S>, S>::new(
concurrency_level,
maybe_gas_limit,
);

let ret = executor
Expand Down Expand Up @@ -145,6 +152,7 @@ impl BlockAptosVM {
transactions: Vec<Transaction>,
state_view: &S,
concurrency_level: usize,
maybe_gas_limit: Option<u64>,
) -> (usize, usize) {
// Verify the signatures of all the transactions in parallel.
// This is time consuming so don't wait and do the checking
Expand Down Expand Up @@ -173,6 +181,7 @@ impl BlockAptosVM {
BLOCK_EXECUTOR_CONCURRENCY.set(concurrency_level as i64);
let executor = BlockExecutor::<PreprocessedTransaction, AptosExecutorTask<S>, S>::new(
concurrency_level,
maybe_gas_limit,
);
println!("Parallel execution starts...");
let timer = Instant::now();
Expand All @@ -186,8 +195,10 @@ impl BlockAptosVM {
flush_speculative_logs();

// sequentially execute the block and check if the results match
let seq_executor =
BlockExecutor::<PreprocessedTransaction, AptosExecutorTask<S>, S>::new(1);
let seq_executor = BlockExecutor::<PreprocessedTransaction, AptosExecutorTask<S>, S>::new(
1,
maybe_gas_limit,
);
println!("Sequential execution starts...");
let seq_timer = Instant::now();
let seq_ret =
Expand Down
8 changes: 8 additions & 0 deletions aptos-move/aptos-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ pub trait VMExecutor: Send + Sync {
transactions: Vec<Transaction>,
state_view: &(impl StateView + Sync),
) -> Result<Vec<TransactionOutput>, VMStatus>;

/// Executes a block of transactions with per_block_gas_limit
/// and returns output for each one of them.
fn execute_block_with_gas_limit(
transactions: Vec<Transaction>,
state_view: &(impl StateView + Sync),
maybe_gas_limit: Option<u64>,
) -> Result<Vec<TransactionOutput>, VMStatus>;
}

/*
Expand Down
36 changes: 36 additions & 0 deletions aptos-move/block-executor/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ pub static SPECULATIVE_ABORT_COUNT: Lazy<IntCounter> = Lazy::new(|| {
.unwrap()
});

/// Count of times the BlockSTM is early halted due to exceeding the per-block gas limit.
pub static PARALLEL_EXCEED_PER_BLOCK_GAS_LIMIT_COUNT: Lazy<IntCounter> = Lazy::new(|| {
register_int_counter!(
"aptos_execution_par_gas_limit_count",
"Count of times the BlockSTM is early halted due to exceeding the per-block gas limit"
)
.unwrap()
});

/// Count of times the sequential execution is early halted due to exceeding the per-block gas limit.
pub static SEQUENTIAL_EXCEED_PER_BLOCK_GAS_LIMIT_COUNT: Lazy<IntCounter> = Lazy::new(|| {
register_int_counter!(
"aptos_execution_seq_gas_limit_count",
"Count of times the sequential execution is early halted due to exceeding the per-block gas limit"
)
.unwrap()
});

pub static PARALLEL_EXECUTION_SECONDS: Lazy<Histogram> = Lazy::new(|| {
register_histogram!(
// metric name
Expand Down Expand Up @@ -109,3 +127,21 @@ pub static DEPENDENCY_WAIT_SECONDS: Lazy<Histogram> = Lazy::new(|| {
)
.unwrap()
});

pub static PARALLEL_PER_BLOCK_GAS: Lazy<Histogram> = Lazy::new(|| {
register_histogram!(
"aptos_execution_par_per_block_gas",
"The per-block consumed gas in parallel execution (Block STM)",
exponential_buckets(/*start=*/ 1.0, /*factor=*/ 2.0, /*count=*/ 30).unwrap(),
)
.unwrap()
});

pub static SEQUENTIAL_PER_BLOCK_GAS: Lazy<Histogram> = Lazy::new(|| {
register_histogram!(
"aptos_execution_seq_per_block_gas",
"The per-block consumed gas in sequential execution",
exponential_buckets(/*start=*/ 1.0, /*factor=*/ 2.0, /*count=*/ 30).unwrap(),
)
.unwrap()
});
Loading