-
Notifications
You must be signed in to change notification settings - Fork 92
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
(WIP) feat: sequencer #179
base: master
Are you sure you want to change the base?
Conversation
5800e79
to
aa5d896
Compare
Hi I think see also see Engine API spec:
|
Hey @LEAFERx, Thank you for your catch. I will look into it shortly. However, block generations, along with transactions, have worked and continue to work. Still, I agree that we should implement |
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 awesome! I just gave it a first pass and left some comments, and will probably make another pass through it to make sure I didn't miss anything since this PR is so large.
I'll also work on getting this synced to some of the op stack chains to make sure there are no regressions.
bin/magi.rs
Outdated
#[clap(long = "sequencer-enabled")] | ||
sequencer_enabled: bool, | ||
#[clap(long = "sequencer-max-safe-lag", default_value = "0")] | ||
sequencer_max_safe_lag: String, |
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.
Why is this a string? Could we use an unsigned integer here instead?
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
bin/network.rs
Outdated
@@ -1,28 +1,91 @@ | |||
use std::str::FromStr; | |||
#![allow(unused_imports)] |
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.
Can we remove this and delete any unused imports or is there another reason this is 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.
Well, as I understood, the idea behind bin/network.rs is just for testing purposes, so we've added code to generate its own Enr and commented it out, and kept imports, will fix that part.
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
bin/network.rs
Outdated
// let bootnodes = vec![enr]; | ||
|
||
let bootnodes: Vec<discv5::enr::Enr<CombinedKey>> = | ||
vec![Enr::from_str("enr:-Je4QKqISnjZwcUSRQqLTbOoqFvmQX8sVlPIud5sWPrUp_8hPJXnzSyY-fqXhzqWGKDHjNSLJRbBGjC9VILm_HGuhHkBgmlkgnY0gmlwhH8AAAGHb3BzdGFja4OFBwCJc2VjcDI1NmsxoQMqv564GlblO4zWKiGSn0-lcr70dYrzwiieFETLNEy8xoN0Y3CCJvyDdWRwgib8").map_err(|e| eyre::eyre!("err: {}", e))?]; |
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.
Where is this node coming from? Can we make sure that this uses the optimism mainnet ones like as we specify in discovery::bootnodes?
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
bin/network.rs
Outdated
let (_, recv) = watch::channel(Address::from_str( | ||
"0x715b7219d986641df9efd9c7ef01218d528e19ec", | ||
"0xF64c29538cAE4E69eac62c50CDfebAC22b378044", |
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.
Can we also keep this as the op mainnet value?
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
src/derive/stages/attributes.rs
Outdated
prev_randao, | ||
suggested_fee_recipient, | ||
transactions, | ||
no_tx_pool: false, |
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.
Same concern as earlier with this not matching the spec, or is it supposed to add new transactions to the block since it is only run during the sequencer step?
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.
Well, i think i need to rework that part as i already told.
Yet would need some time.
src/driver/info.rs
Outdated
|
||
pub async fn get_finalized<P: InnerProvider>(p: &P, chain: &ChainConfig) -> HeadInfo { | ||
let block_number = BlockNumber::Finalized; | ||
Self::get_head_info(p, block_number) |
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.
nit: can we refactor these three to use an internal function to dedupe the unwrap_or_else handling? Maybe we can call it get_head_info_or_genesis
or something similar?
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.
That's a good idea. Also, we noticed that if we relaunch the L2 node and, at the same time, launch Magi, it can roll back heads to the genesis ones. So, I think maybe we should add additional checks there.
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
src/driver/mod.rs
Outdated
/// Produces a block if the conditions are met. | ||
/// If successful the block would be signed by sequencer and shared by P2P. | ||
async fn run_sequencer_step(&mut self) -> Result<()> { | ||
if let Some(seq_config) = self.sequencer_config.clone() { |
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 we can avoid cloning the entire config here by doing an as_ref
or something.,
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.
Although I guess since its just a uint in there it doesn't really matter. But if more stuff ends up being added to that config it could become a big clone.
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
src/driver/mod.rs
Outdated
async fn run_sequencer_step(&mut self) -> Result<()> { | ||
if let Some(seq_config) = self.sequencer_config.clone() { | ||
// Get unsafe head to build a new block on top of it. | ||
let head = self.engine_driver.unsafe_info.head; |
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.
Rename to unsafe_head
to match with the next line and avoid any confusion.
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
src/driver/mod.rs
Outdated
let head = self.engine_driver.unsafe_info.head; | ||
let unsafe_epoch = self.engine_driver.unsafe_info.epoch; | ||
|
||
if seq_config.max_safe_lag() > 0 { |
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'm not sure if this extra check here really matters in terms of efficiency. Might be better to just remove it for readability reasons.
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.
Do you want to remove the parameter at all?
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 don't think that we need to remove the parameter, but doesn't the check on L294 cover this case, making it redundant, or am I misunderstanding something?
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 we remove the zero check, the code will always return max safe lag reached...
when max_safe_lag == 0
, because safe block + 0
<= unsafe will always be true. As a result, no new blocks would be generated, among other issues.
We could use an Option
for max_safe_lag, but I still think there would be issues if someone passes 0
as the value.
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.
Oh I see that makes sense!
* Removed unused imports * Configurated to optimism mainnet * Improved comments
# Conflicts: # bin/magi.rs # src/config/mod.rs # src/derive/stages/attributes.rs # src/network/handlers/block_handler.rs
# Conflicts: # src/config/mod.rs # src/derive/mod.rs # src/derive/stages/attributes.rs # src/derive/stages/batches.rs # src/derive/state.rs # src/driver/mod.rs
what is the progress of this PR? |
I'd like @borispovod to look into it before review of a16z team. |
I think most of issues fixed by me and @dk-pontem , we are going to do review, unit tests, manual tests |
Hello everyone,
This PR includes changes we've made for running the sequencer on top of Magi. It also impacts types, configurations (additional parameters and refactoring), networking (broadcast and configuration), and RPC (implementation of missing endpoints).
I would appreciate a review, particularly if you notice something functioning incorrectly, and I'd like to hear your opinions on the changes, etc. In the future, I believe the sequencer should be moved into its own module, launched by a timer, etc. This is planned as part of future updates.
Additionally, I have primarily tested it on our devnet, so the tests should probably also be run on top of existing networks.
Thank you.
P.S. Sorry for the single commit. We have a monorepo, and it would be difficult to separate all the changes into individual commits. I hope we can improve this process in the future.