Skip to content
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(exex): OP Proposer ExEx #8206

Open
wants to merge 58 commits into
base: main
Choose a base branch
from

Conversation

0xKitsune
Copy link
Contributor

@0xKitsune 0xKitsune commented May 12, 2024

This PR implements the OP Proposer inside an ExEx, addressing #8174 . We are opening this draft for initial feedback.

Within the core logic, upon each ExecutionNotification the nextBlockNumber is fetched from the L2OutputOracle and compared against the current L2 block. If the target_block is equal to the current block, the L2Output is constructed and submitted to L1. Since Reth does not currently deliver historical storage proofs, we store the L2Output in persistent storage.

If the current L2 block is within the safe head, then we submit the latest L2Output transaction, otherwise we wait to submit until the latest L2 block is safe.

impl<T, N, P> OpProposer<T, N, P>
where
   T: Transport + Clone,
   N: Network,
   P: Provider<T, N>,
{
// --snip--

 pub fn run<Node: FullNodeComponents>(
       &self,
       mut ctx: ExExContext<Node>,
       mut l2_output_db: L2OutputDb,
       l2_output_oracle: Arc<L2OutputOracleInstance<T, Arc<P>, N>>,
       mut transaction_manager: TxManager<T, N, P>,
   ) -> impl Future<Output = eyre::Result<()>> {
      
      // --snip--

       async move {
           while let Some(notification) = ctx.notifications.recv().await {
             // --snip--
             
               // Get the target block number from the L2OutputOracle and the latest L2 block
               let target_block = l2_output_oracle.nextBlockNumber().call().await?._0.to::<u64>();
               let current_l2_block = l2_provider.last_block_number()?;
               
               // Skip to the next block if the target block is not reached
               if target_block > current_block{
                  continue;
               }
               
               let l2_output = get_l2_output(l2_output_db, l2_output_oracle.clone()).await?;

               // Check the L2 Safe Head. If the target block is within the safe head, submit the proposal
               let safe_head = get_l2_safe_head(rollup_provider.clone()).await?;
               if target_block <= safe_head {
                   transaction_manager.propose_l2_output(&l2_output_oracle, l2_output).await?;
               }
           }

           Ok(())
       }
   }

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

this is great, only have a few suggestions and nits

examples/exex/op-proposer/Cargo.toml Outdated Show resolved Hide resolved
examples/exex/op-proposer/src/main.rs Outdated Show resolved Hide resolved
examples/exex/op-proposer/src/op_proposer.rs Outdated Show resolved Hide resolved
examples/exex/op-proposer/src/tx_manager.rs Show resolved Hide resolved
examples/exex/op-proposer/src/tx_manager.rs Show resolved Hide resolved
examples/exex/op-proposer/src/tx_manager.rs Outdated Show resolved Hide resolved
@emhane emhane added C-enhancement New feature or request A-exex Execution Extensions labels May 16, 2024
* update async logic

* comments
@0xKitsune 0xKitsune marked this pull request as ready for review May 17, 2024 17:37
@0xKitsune 0xKitsune requested a review from gakonst as a code owner May 17, 2024 17:37
@0xKitsune 0xKitsune requested a review from mattsse May 18, 2024 18:00
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

I've pushed a few dep changes

I'd like to see a few more docs and debug impls for the structs like OpProposer and txManager

Comment on lines +50 to +52
// Spawn the OpProposer and TxManager, proposing L2 outputs to L1
let op_proposer_fut = async move {
tokio::select! {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this does not spawn but runs the jobs concurrently

maybe those should be actually spawned?

) -> eyre::Result<()> {
let l2_provider = ctx.provider().clone();
let rollup_provider = Arc::new(ProviderBuilder::new().with_recommended_fillers().on_http(
self.rollup_provider.parse().expect("Could not parse rollup provider endpoint"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should return an error

@0xKitsune
Copy link
Contributor Author

No problem I can update this later today! I am also planning to update the PR to be compatible with the upcoming fault proof updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exex Execution Extensions C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants