Skip to content

Commit

Permalink
also constrain windowed blocks to max_block_txns
Browse files Browse the repository at this point in the history
  • Loading branch information
bchocho committed Nov 5, 2024
1 parent 1f25ce0 commit ddaf489
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 2 additions & 6 deletions consensus/src/block_preparer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,8 @@ impl BlockPreparer {
let txn_deduper = self.txn_deduper.clone();
let block_id = block.id();
let block_timestamp_usecs = block.timestamp_usecs();
let max_prepared_block_txns =
if let Some(max_txns_from_block_to_execute) = max_txns_from_block_to_execute {
max_txns_from_block_to_execute
} else {
self.max_block_txns * 2
};
// Always use max_block_txns * 2 regardless of max_txns_from_block_to_execute for better shuffling
let max_prepared_block_txns = self.max_block_txns * 2;
// Transaction filtering, deduplication and shuffling are CPU intensive tasks, so we run them in a blocking task.
let result = tokio::task::spawn_blocking(move || {
// stable sort to ensure batches with same gas are in the same order
Expand Down
18 changes: 12 additions & 6 deletions consensus/src/execution_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl ExecutionPipeline {
&self,
block: PipelinedBlock,
block_window: OrderedBlockWindow,
max_block_txns: u64,
metadata: BlockMetadataExt,
parent_block_id: HashValue,
txn_generator: BlockPreparer,
Expand All @@ -118,6 +119,7 @@ impl ExecutionPipeline {
.send(PrepareBlockCommand {
block,
block_window,
max_block_txns,
metadata,
block_executor_onchain_config,
parent_block_id,
Expand Down Expand Up @@ -153,6 +155,7 @@ impl ExecutionPipeline {
let PrepareBlockCommand {
block,
block_window,
max_block_txns,
metadata,
block_executor_onchain_config,
parent_block_id,
Expand Down Expand Up @@ -194,6 +197,7 @@ impl ExecutionPipeline {
execute_block_tx
.send(ExecuteBlockCommand {
input_txns,
max_block_txns,
max_txns_to_execute,
pipelined_block: block,
block: (block_id, sig_verified_txns).into(),
Expand Down Expand Up @@ -231,6 +235,7 @@ impl ExecutionPipeline {
) {
'outer: while let Some(ExecuteBlockCommand {
input_txns: _,
max_block_txns,
max_txns_to_execute,
pipelined_block,
block,
Expand Down Expand Up @@ -331,12 +336,11 @@ impl ExecutionPipeline {
} else {
txns.len()
};
let num_txns_to_execute = if let Some(max_user_txns_to_execute) = max_txns_to_execute {
txns.len()
.min(num_validator_txns.saturating_add(max_user_txns_to_execute as usize))
} else {
txns.len()
};
let mut num_txns_to_execute = txns.len().min(max_block_txns as usize);
if let Some(max_user_txns_to_execute) = max_txns_to_execute {
num_txns_to_execute = num_txns_to_execute
.min(num_validator_txns.saturating_add(max_user_txns_to_execute as usize));
}
let blocking_txns_provider = Arc::new(BlockingTxnsProvider::new(num_txns_to_execute));
let blocking_txns_writer = blocking_txns_provider.clone();
let join_shuffle = tokio::task::spawn_blocking(move || {
Expand Down Expand Up @@ -583,6 +587,7 @@ impl ExecutionPipeline {
struct PrepareBlockCommand {
block: PipelinedBlock,
block_window: OrderedBlockWindow,
max_block_txns: u64,
metadata: BlockMetadataExt,
block_executor_onchain_config: BlockExecutorConfigFromOnchain,
// The parent block id.
Expand All @@ -596,6 +601,7 @@ struct PrepareBlockCommand {

struct ExecuteBlockCommand {
input_txns: Vec<SignedTransaction>,
max_block_txns: u64,
max_txns_to_execute: Option<u64>,
pipelined_block: PipelinedBlock,
block: ExecutableBlock,
Expand Down
1 change: 1 addition & 0 deletions consensus/src/state_computer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ impl StateComputer for ExecutionProxy {
.queue(
block.clone(),
block_window.clone(),
self.max_block_txns,
metadata.clone(),
parent_block_id,
transaction_generator,
Expand Down

0 comments on commit ddaf489

Please sign in to comment.