Skip to content

Commit 5b57c32

Browse files
authored
feat(consensus): Add consensus check for block sequencing (#231)
* update tests * remove println statement * update consensus algorithm to noop in integration tests * address comments
1 parent 3feb460 commit 5b57c32

File tree

15 files changed

+301
-62
lines changed

15 files changed

+301
-62
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ lint: fmt lint-toml clippy udeps codespell zepter
6464

6565
.PHONY: test
6666
test:
67-
cargo test \
67+
cargo nextest run \
6868
--workspace \
6969
--locked \
7070
--all-features \
71-
--no-fail-fast
71+
--no-fail-fast \
72+
-E 'not test(docker)'
7273

7374
# Used to update the mainnet-sample.sql data. Provide the path to the sqlite database that should be read from
7475
# using `DB_PATH`.

crates/manager/src/consensus.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub trait Consensus: Send + Debug {
1515
block: &ScrollBlock,
1616
signature: &Signature,
1717
) -> Result<(), ConsensusError>;
18+
/// Returns a boolean indicating whether the sequencer should sequence a block.
19+
fn should_sequence_block(&self, sequencer: &Address) -> bool;
1820
}
1921

2022
/// A no-op consensus instance.
@@ -32,6 +34,10 @@ impl Consensus for NoopConsensus {
3234
) -> Result<(), ConsensusError> {
3335
Ok(())
3436
}
37+
38+
fn should_sequence_block(&self, _sequencer: &Address) -> bool {
39+
true
40+
}
3541
}
3642

3743
/// The system contract consensus.
@@ -71,6 +77,10 @@ impl Consensus for SystemContractConsensus {
7177
}
7278
Ok(())
7379
}
80+
81+
fn should_sequence_block(&self, sequencer: &Address) -> bool {
82+
sequencer == &self.authorized_signer
83+
}
7484
}
7585

7686
#[cfg(test)]

crates/manager/src/manager/mod.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -510,21 +510,22 @@ where
510510
proceed_if!(
511511
en_synced,
512512
// Check if we need to trigger the build of a new payload.
513-
match (
514-
this.block_building_trigger.as_mut().map(|x| x.poll_tick(cx)),
515-
this.engine.is_payload_building_in_progress(),
513+
if let (Some(Poll::Ready(_)), Some(sequencer)) = (
514+
this.block_building_trigger.as_mut().map(|se| se.poll_tick(cx)),
515+
this.sequencer.as_mut()
516516
) {
517-
(Some(Poll::Ready(_)), false) => {
518-
if let Some(sequencer) = this.sequencer.as_mut() {
519-
sequencer.build_payload_attributes();
520-
}
521-
}
522-
(Some(Poll::Ready(_)), true) => {
523-
// If the sequencer is already building a payload, we don't need to trigger it
524-
// again.
517+
if !this.consensus.should_sequence_block(
518+
this.signer
519+
.as_ref()
520+
.map(|s| &s.address)
521+
.expect("signer must be set if sequencer is present"),
522+
) {
523+
trace!(target: "scroll::node::manager", "Signer is not authorized to sequence block for this slot");
524+
} else if this.engine.is_payload_building_in_progress() {
525525
warn!(target: "scroll::node::manager", "Payload building is already in progress skipping slot");
526+
} else {
527+
sequencer.build_payload_attributes();
526528
}
527-
_ => {}
528529
}
529530
);
530531

crates/node/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ futures.workspace = true
9595
reth-e2e-test-utils.workspace = true
9696
reth-node-core.workspace = true
9797
reth-provider.workspace = true
98+
reth-primitives-traits.workspace = true
9899
reth-rpc-server-types.workspace = true
99100
reth-scroll-node = { workspace = true, features = ["test-utils"] }
100101
reth-tasks.workspace = true
@@ -140,4 +141,6 @@ test-utils = [
140141
"scroll-alloy-rpc-types-engine",
141142
"alloy-rpc-types-engine",
142143
"scroll-derivation-pipeline",
144+
"reth-primitives-traits/test-utils",
145+
"reth-primitives-traits/test-utils",
143146
]

0 commit comments

Comments
 (0)