-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: consensus #68
Conversation
@@ -65,7 +65,7 @@ where | |||
|
There was a problem hiding this comment.
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
There was a problem hiding this 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?
bin/rollup/src/network.rs
Outdated
let chain = ctx.config().chain.clone(); | ||
let fcs = if let Some(named) = chain.chain.named() { |
There was a problem hiding this comment.
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.
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() { |
There was a problem hiding this comment.
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
.
crates/node/src/lib.rs
Outdated
@@ -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>, |
There was a problem hiding this comment.
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>;
}
consensus: Box<dyn Consensus + Send>, | |
consensus: Box<dyn Consensus>, |
crates/node/src/lib.rs
Outdated
@@ -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") |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this 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.
bin/rollup/src/args.rs
Outdated
/// Whether the rollup node should be run in dev mode. | ||
#[arg(long)] | ||
pub dev: bool, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
bin/rollup/src/network.rs
Outdated
}; | ||
|
||
// Create the consensus. | ||
let consensus: Box<dyn Consensus + Send> = if self.config.test { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oups indeed
This PR implements changes related to the consensus verifications:
Resolves #60