Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
22 changes: 20 additions & 2 deletions crates/engine/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct EngineDriver<EC, CS, P> {
metrics: EngineDriverMetrics,
/// The waker to notify when the engine driver should be polled.
waker: AtomicWaker,
/// Whether to allow empty blocks.
allow_empty_blocks: bool,
}

impl<EC, CS, P> EngineDriver<EC, CS, P>
Expand All @@ -69,6 +71,7 @@ where
fcs: ForkchoiceState,
sync_at_start_up: bool,
block_building_duration: Duration,
allow_empty_blocks: bool,
) -> Self {
Self {
client,
Expand All @@ -85,6 +88,7 @@ where
engine_future: None,
metrics: EngineDriverMetrics::default(),
waker: AtomicWaker::new(),
allow_empty_blocks,
}
}

Expand Down Expand Up @@ -312,6 +316,12 @@ where

match result {
Ok(block) => {
// Skip block if no transactions are present in block.
if !self.allow_empty_blocks && block.body.transactions.is_empty() {
tracing::trace!(target: "scroll::engine", "no transactions in block");
return None;
}

// Update the unsafe block info and return the block
let block_info = BlockInfo::new(block.number, block.hash_slow());
tracing::trace!(target: "scroll::engine", ?block_info, "updating unsafe block info from new payload");
Expand Down Expand Up @@ -531,8 +541,15 @@ mod tests {
ForkchoiceState::from_block_info(BlockInfo { number: 0, hash: Default::default() });
let duration = Duration::from_secs(2);

let mut driver =
EngineDriver::new(client, chain_spec, None::<ScrollRootProvider>, fcs, false, duration);
let mut driver = EngineDriver::new(
client,
chain_spec,
None::<ScrollRootProvider>,
fcs,
false,
duration,
true,
);

// Initially, it should be false
assert!(!driver.is_payload_building_in_progress());
Expand All @@ -559,6 +576,7 @@ mod tests {
fcs,
false,
duration,
true,
);

// Initially, it should be false
Expand Down
9 changes: 9 additions & 0 deletions crates/node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub struct ScrollRollupNodeConfig {
/// The gas price oracle args
#[command(flatten)]
pub gas_price_oracle_args: GasPriceOracleArgs,
/// Enable empty blocks
#[arg(long)]
pub allow_empty_blocks: bool,
Comment thread
frisitano marked this conversation as resolved.
Outdated
}

impl ScrollRollupNodeConfig {
Expand Down Expand Up @@ -261,6 +264,7 @@ impl ScrollRollupNodeConfig {
fcs,
self.engine_driver_args.sync_at_startup && !self.test && !chain_spec.is_dev_chain(),
Duration::from_millis(self.sequencer_args.payload_building_duration),
self.allow_empty_blocks,
);

// Create the consensus.
Expand Down Expand Up @@ -711,6 +715,7 @@ mod tests {
algorithm: ConsensusAlgorithm::SystemContract,
authorized_signer: None,
},
allow_empty_blocks: true,
};

let result = config.validate();
Expand Down Expand Up @@ -741,6 +746,7 @@ mod tests {
algorithm: ConsensusAlgorithm::SystemContract,
authorized_signer: None,
},
allow_empty_blocks: true,
};

let result = config.validate();
Expand All @@ -766,6 +772,7 @@ mod tests {
network_args: NetworkArgs::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

assert!(config.validate().is_ok());
Expand All @@ -789,6 +796,7 @@ mod tests {
network_args: NetworkArgs::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

assert!(config.validate().is_ok());
Expand All @@ -808,6 +816,7 @@ mod tests {
network_args: NetworkArgs::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

assert!(config.validate().is_ok());
Expand Down
2 changes: 2 additions & 0 deletions crates/node/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub fn default_test_scroll_rollup_node_config() -> ScrollRollupNodeConfig {
signer_args: Default::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
}
}

Expand Down Expand Up @@ -193,5 +194,6 @@ pub fn default_sequencer_test_scroll_rollup_node_config() -> ScrollRollupNodeCon
signer_args: Default::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
}
}
3 changes: 3 additions & 0 deletions crates/node/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async fn can_bridge_l1_messages() -> eyre::Result<()> {
signer_args: Default::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};
let (mut nodes, _tasks, _wallet) = setup_engine(node_args, 1, chain_spec, false, false).await?;
let node = nodes.pop().unwrap();
Expand Down Expand Up @@ -168,6 +169,7 @@ async fn can_sequence_and_gossip_blocks() {
signer_args: Default::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

let (nodes, _tasks, wallet) =
Expand Down Expand Up @@ -266,6 +268,7 @@ async fn can_penalize_peer_for_invalid_block() {
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
chain_orchestrator_args: ChainOrchestratorArgs::default(),
allow_empty_blocks: true,
};

let (nodes, _tasks, _) =
Expand Down
4 changes: 4 additions & 0 deletions crates/node/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async fn test_should_consolidate_to_block_15k() -> eyre::Result<()> {
signer_args: Default::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

let chain_spec = (*SCROLL_SEPOLIA).clone();
Expand Down Expand Up @@ -204,6 +205,7 @@ async fn test_should_consolidate_after_optimistic_sync() -> eyre::Result<()> {
signer_args: Default::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

// Create the chain spec for scroll dev with Feynman activated and a test genesis.
Expand Down Expand Up @@ -451,6 +453,7 @@ async fn test_consolidation() -> eyre::Result<()> {
signer_args: Default::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

// Create the chain spec for scroll dev with Feynman activated and a test genesis.
Expand Down Expand Up @@ -623,6 +626,7 @@ async fn test_chain_orchestrator_shallow_reorg_with_gap() -> eyre::Result<()> {
signer_args: Default::default(),
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

// Create the chain spec for scroll dev with Feynman activated and a test genesis.
Expand Down
63 changes: 63 additions & 0 deletions crates/sequencer/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,61 @@ use tokio::{
time::{Duration, Instant},
};

#[tokio::test]
async fn skip_block_with_no_transactions() {
reth_tracing::init_test_tracing();

const BLOCK_BUILDING_DURATION: Duration = Duration::from_millis(0);

// setup a test node
let (mut nodes, _tasks, _wallet) = setup(1, false).await.unwrap();
let node = nodes.pop().unwrap();

// create a forkchoice state
let genesis_hash = node.inner.chain_spec().genesis_hash();
let fcs = ForkchoiceState::new(
BlockInfo { hash: genesis_hash, number: 0 },
Default::default(),
Default::default(),
);

// create the engine driver connected to the node
let auth_client = node.inner.engine_http_client();
let engine_client = ScrollAuthApiEngineClient::new(auth_client);
let mut engine_driver = EngineDriver::new(
Arc::new(engine_client),
(*SCROLL_DEV).clone(),
None::<ScrollRootProvider>,
fcs,
false,
BLOCK_BUILDING_DURATION,
false,
);

// create a test database
let database = Arc::new(setup_test_db().await);
let provider = Arc::new(DatabaseL1MessageProvider::new(database.clone(), 0));

// create a sequencer
let mut sequencer = Sequencer::new(
provider,
Default::default(),
SCROLL_GAS_LIMIT,
4,
1,
L1MessageInclusionMode::BlockDepth(0),
);

// send a new payload attributes request.
sequencer.build_payload_attributes();
let payload_attributes = sequencer.next().await.unwrap();
engine_driver.handle_build_new_payload(payload_attributes);

// assert that no new payload event is emitted
let res = tokio::time::timeout(Duration::from_secs(1), engine_driver.next()).await;
assert!(res.is_err(), "expected no new payload, but a block was built: {:?}", res.ok());
}

#[tokio::test]
async fn can_build_blocks() {
reth_tracing::init_test_tracing();
Expand Down Expand Up @@ -66,6 +121,7 @@ async fn can_build_blocks() {
fcs,
false,
BLOCK_BUILDING_DURATION,
true,
);

// create a test database
Expand Down Expand Up @@ -192,6 +248,7 @@ async fn can_build_blocks_with_delayed_l1_messages() {
fcs,
false,
BLOCK_BUILDING_DURATION,
true,
);

// create a test database
Expand Down Expand Up @@ -317,6 +374,7 @@ async fn can_build_blocks_with_finalized_l1_messages() {
fcs,
false,
BLOCK_BUILDING_DURATION,
true,
);

// create a test database
Expand Down Expand Up @@ -460,6 +518,7 @@ async fn can_sequence_blocks_with_private_key_file() -> eyre::Result<()> {
},
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

let (nodes, _tasks, wallet) =
Expand Down Expand Up @@ -551,6 +610,7 @@ async fn can_sequence_blocks_with_hex_key_file_without_prefix() -> eyre::Result<
},
gas_price_oracle_args: GasPriceOracleArgs::default(),
consensus_args: ConsensusArgs::noop(),
allow_empty_blocks: true,
};

let (nodes, _tasks, wallet) =
Expand Down Expand Up @@ -658,6 +718,7 @@ async fn can_build_blocks_and_exit_at_gas_limit() {
fcs,
false,
BLOCK_BUILDING_DURATION,
true,
);

// issue a new payload to the execution layer.
Expand Down Expand Up @@ -743,6 +804,7 @@ async fn can_build_blocks_and_exit_at_time_limit() {
fcs,
false,
BLOCK_BUILDING_DURATION,
true,
);

// start timer.
Expand Down Expand Up @@ -809,6 +871,7 @@ async fn should_limit_l1_message_cumulative_gas() {
fcs,
false,
BLOCK_BUILDING_DURATION,
true,
);

// create a test database
Expand Down
Loading