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

Commit

Permalink
feat: update ProcessL1Blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jul 21, 2023
1 parent 8c5f7a7 commit dba88c2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Push docker image to GCR"

on:
push:
branches: [main]
branches: [main,ProcessL1Blocks-l1End]
tags:
- "v*"

Expand Down
2 changes: 1 addition & 1 deletion driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *Syncer) ProcessL1Blocks(ctx context.Context, l1End *types.Header) error

startHeight := s.state.GetL1Current().Number
// If there is a L1 reorg, sometimes this will happen.
if startHeight.Uint64() > l1End.Number.Uint64() {
if startHeight.Uint64() >= l1End.Number.Uint64() {
startHeight = new(big.Int).Sub(l1End.Number, common.Big1)
newL1Current, err := s.rpc.L1.HeaderByNumber(ctx, startHeight)
if err != nil {
Expand Down
41 changes: 35 additions & 6 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,26 @@ 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 err.Error() == ethereum.NotFound.Error() {
stateVars, err := c.TaikoL1.GetStateVariables(nil)
log.Info("L1Origin not found", "blockID", blockID)

// 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.
justSyncedByP2P, err := c.IsJustSyncedByP2P(ctx)
if err != nil {
return false, nil, nil, err
return false,
nil,
nil,
fmt.Errorf("failed to check whether the L2 execution engine has just finished a P2P sync: %w", err)
}
log.Info("L1Origin not found", "blockID", blockID)

if blockID.Uint64() <= stateVars.LastVerifiedBlockId {
log.Info(
"Check whether the L2 execution engine has just finished a P2P sync",
"justSyncedByP2P",
justSyncedByP2P,
)

if justSyncedByP2P {
return false, nil, nil, nil
}

Expand Down Expand Up @@ -413,3 +423,22 @@ func (c *Client) CheckL1Reorg(ctx context.Context, blockID *big.Int) (bool, *typ

return reorged, l1CurrentToReset, blockIDToReset, nil
}

// IsJustSyncedByP2P checks whether the given L2 execution engine has just finished a P2P
// sync.
func (c *Client) IsJustSyncedByP2P(ctx context.Context) (bool, error) {
l2Head, err := c.L2.HeaderByNumber(ctx, nil)
if err != nil {
return false, err
}

if _, err = c.L2.L1OriginByID(ctx, l2Head.Number); err != nil {
if err.Error() == ethereum.NotFound.Error() {
return true, nil
}

return false, err
}

return false, nil
}

0 comments on commit dba88c2

Please sign in to comment.