Skip to content

feat: consensus #68

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

Merged
merged 13 commits into from
Apr 24, 2025
Merged

feat: consensus #68

merged 13 commits into from
Apr 24, 2025

Conversation

greged93
Copy link
Collaborator

@greged93 greged93 commented Apr 23, 2025

This PR implements changes related to the consensus verifications:

  • Add a valid implementation of the PoA consensus.
  • Add a dev CLI argument that for now allows to run the node without any consensus checks.
  • Fixes an issue with the update of the FCS.

Resolves #60

@@ -65,7 +65,7 @@ where

Copy link
Collaborator Author

@greged93 greged93 Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we talked about reintroducing these lines of code:

        if self.forkchoice_state.is_genesis() {
            let block_num_hash = block.parent_num_hash();
            self.forkchoice_state = ForkchoiceState::from_block_info(BlockInfo {
                number: block_num_hash.number,
                hash: block_num_hash.hash,
            });
        }

and I tried running the node with them, but I didn't see any trigger of the pipeline sync. I think what happened is that it hits this path in the match, meaning it doesn't trigger a sync. My opinion is to keep the code as is, and implement a EL sync and CL sync similar to what optimism are doing.

EDIT: forgot to link the code in Reth.
https://github.com/scroll-tech/reth/blob/1b8ff78f46d5e95dd10876fd8145c27db598a0b0/crates/engine/tree/src/tree/mod.rs#L2075

@greged93 greged93 requested a review from frisitano April 24, 2025 07:11
Copy link
Collaborator

@frisitano frisitano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Left some minor nits inline. Can you open an issue so that we can update the logic to track signer rotation on L1 system contract please?

Comment on lines 103 to 104
let chain = ctx.config().chain.clone();
let fcs = if let Some(named) = chain.chain.named() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NamedChain is Copy so I don't think we need the clone here.

Suggested change
let chain = ctx.config().chain.clone();
let fcs = if let Some(named) = chain.chain.named() {
let fcs = if let Some(named) = ctx.config().chain.chain.named() {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, didn't notice if was Copy.

@@ -64,7 +63,7 @@ pub struct RollupNodeManager<C, EC, P, L1P, L1MP, CS> {
/// An indexer used to index data for the rollup node.
indexer: Indexer<CS>,
/// The consensus algorithm used by the rollup node.
consensus: C,
consensus: Box<dyn Consensus + Send>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we constrain the Consensus trait to be Send + Debug instead?

pub trait Consensus: std::fmt::Debug + Send {
    /// Validates a new block with the given signature.
    fn validate_new_block(
        &self,
        block: &ScrollBlock,
        signature: &Signature,
    ) -> Result<(), ConsensusError>;
}
Suggested change
consensus: Box<dyn Consensus + Send>,
consensus: Box<dyn Consensus>,

@@ -85,7 +84,7 @@ impl<C: Debug, EC: Debug, P: Debug, L1P: Debug, L1MP: Debug, CS: Debug> Debug
.field("derivation_pipeline", &self.derivation_pipeline)
.field("l1_notification_rx", &self.l1_notification_rx)
.field("indexer", &self.indexer)
.field("consensus", &self.consensus)
.field("consensus", &"Consensus")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Consensus is Debug then we can revert this.

@@ -30,7 +32,7 @@ pub struct NewBlock {
impl NewBlock {
/// Returns a [`NewBlock`] instance with the provided signature and block.
pub fn new(signature: Signature, block: reth_scroll_primitives::ScrollBlock) -> Self {
Self { signature: Bytes::from(signature.serialize_compact().to_vec()), block }
Self { signature: Bytes::from(Into::<Vec<u8>>::into(signature)), block }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now but in the future I would like to have a solution that ensures correct typing such that we have:

/// A message that is used to announce a new block to the network.
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable)]
pub struct NewBlock {
    /// The signature from the block author.
    pub signature: Signature,
    /// The block that is being announced.
    pub block: reth_scroll_primitives::ScrollBlock,
}

The reason we currently don't have this is because Signature does not implement Encodable. We may be able to address this by implementing Encodable ourselves on this type instead of leveraging the macro but I'm not sure. I will open an issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#71

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like the implementation of Encodable and Decodable was removed in this PR. Maybe we can ask for it to be reintroduced?
alloy-rs/core@37e08b2#diff-79b82cfeeba5106f10ab06fb251c628206b2d8f648bcd94e6fe01c6091763d1c

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's a good idea. Would you be able to open an issue upstream for this please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Collaborator

@frisitano frisitano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update README to reflect new CLI args before merge.

Comment on lines 9 to 11
/// Whether the rollup node should be run in dev mode.
#[arg(long)]
pub dev: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this conflict with reth's dev CLI arg?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sorry, I changed it to test but it reverted for some reason.

};

// Create the consensus.
let consensus: Box<dyn Consensus + Send> = if self.config.test {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Send can be removed here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups indeed

@greged93 greged93 merged commit 80b108b into main Apr 24, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Consensus] Implement Consensus
2 participants