diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1b1491c56..9b76e11c4 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main] + branches: [main,ProcessL1Blocks-l1End] tags: - "v*" diff --git a/driver/chain_syncer/calldata/syncer.go b/driver/chain_syncer/calldata/syncer.go index 7d634d972..d621170a2 100644 --- a/driver/chain_syncer/calldata/syncer.go +++ b/driver/chain_syncer/calldata/syncer.go @@ -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 { diff --git a/pkg/rpc/methods.go b/pkg/rpc/methods.go index 9f66407a4..16451d5c0 100644 --- a/pkg/rpc/methods.go +++ b/pkg/rpc/methods.go @@ -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 } @@ -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 +}