Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(prover): improve onBlockProposed listener
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jun 7, 2023
1 parent d3fdd94 commit 165f4c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 8 additions & 2 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (c *Client) ensureGenesisMatched(ctx context.Context) error {
return nil
}

// WaitTillL2Synced keeps waiting until the L2 execution engine is fully synced.
func (c *Client) WaitTillL2Synced(ctx context.Context) error {
// WaitTillL2ExecutionEngineSynced keeps waiting until the L2 execution engine is fully synced.
func (c *Client) WaitTillL2ExecutionEngineSynced(ctx context.Context) error {
return backoff.Retry(
func() error {
if ctx.Err() != nil {
Expand Down Expand Up @@ -345,6 +345,12 @@ func (c *Client) CheckL1Reorg(ctx context.Context, blockID *big.Int) (bool, *typ

l1Origin, err := c.L2.L1OriginByID(ctx, blockID)
if err != nil {
// If the L2 EE is just synced through P2P, there is a chance that the EE do not have
// the chain head L1Origin information recorded.
if errors.Is(err, ethereum.NotFound) {
log.Info("L1Origin not found", "blockID", blockID)
return false, nil, nil, nil
}
return false, nil, nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {
}

// Wait until L2 execution engine is synced at first.
if err := p.rpc.WaitTillL2Synced(ctx); err != nil {
if err := p.rpc.WaitTillL2ExecutionEngineSynced(ctx); err != nil {
return fmt.Errorf("failed to wait until L2 execution engine synced: %w", err)
}

Expand Down
8 changes: 6 additions & 2 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,17 @@ func (p *Prover) onBlockProposed(
return nil
}

if err := p.rpc.WaitTillL2ExecutionEngineSynced(p.ctx); err != nil {
return err
}

// Check whteher the L1 chain has been reorged.
reorged, l1CurrentToReset, lastHandledBlockIDToReset, err := p.rpc.CheckL1Reorg(
ctx,
new(big.Int).Sub(event.Id, common.Big1),
)
if err != nil {
return fmt.Errorf("failed to check whether L1 chain was reorged: %w", err)
return fmt.Errorf("failed to check whether L1 chain was reorged (eventID %d): %w", event.Id, err)
}

if reorged {
Expand Down Expand Up @@ -489,7 +493,7 @@ func (p *Prover) Name() string {

// initL1Current initializes prover's L1Current cursor.
func (p *Prover) initL1Current(startingBlockID *big.Int) error {
if err := p.rpc.WaitTillL2Synced(p.ctx); err != nil {
if err := p.rpc.WaitTillL2ExecutionEngineSynced(p.ctx); err != nil {
return err
}

Expand Down

0 comments on commit 165f4c9

Please sign in to comment.