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

Commit

Permalink
fix(rpc): fix an issue in checkSyncedL1SnippetFromAnchor && add mor…
Browse files Browse the repository at this point in the history
…e logs (#511)
  • Loading branch information
davidtaikocha authored Jan 18, 2024
1 parent d375ee0 commit b2f2f0b
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,14 @@ func (c *Client) CheckL1ReorgFromL2EE(
continue
}

isSyncedL1SnippetValid, err := c.checkSyncedL1SnippetFromAnchor(
isSyncedL1SnippetInvalid, err := c.checkSyncedL1SnippetFromAnchor(
ctx, blockID, l1Origin.L1BlockHeight.Uint64(), l1SignalService,
)
if err != nil {
return false, nil, nil, fmt.Errorf("failed to check L1 reorg from anchor transaction: %w", err)
}

if !isSyncedL1SnippetValid {
if isSyncedL1SnippetInvalid {
log.Info("Reorg detected due to invalid L1 snippet", "blockID", blockID)
reorged = true
blockID = new(big.Int).Sub(blockID, common.Big1)
Expand Down Expand Up @@ -527,28 +527,53 @@ func (c *Client) checkSyncedL1SnippetFromAnchor(
return false, err
}

if l1HeightInAnchor != l1Height {
log.Info("Reorg detected due to L1 height mismatch", "blockID", blockID)
if l1HeightInAnchor+1 != l1Height {
log.Info(
"Reorg detected due to L1 height mismatch",
"blockID", blockID,
"l1HeightInAnchor", l1HeightInAnchor,
"l1Height", l1Height,
)
return true, nil
}

if parentGasUsed != uint32(parent.GasUsed()) {
log.Info("Reorg detected due to parent gas used mismatch", "blockID", blockID)
log.Info(
"Reorg detected due to parent gas used mismatch",
"blockID", blockID,
"parentGasUsedInAnchor", parentGasUsed,
"parentGasUsed", parent.GasUsed(),
)
return true, nil
}

l1Header, err := c.L1.HeaderByHash(ctx, l1BlockHash)
l1Header, err := c.L1.HeaderByNumber(ctx, new(big.Int).SetUint64(l1HeightInAnchor))
if err != nil {
return false, err
}

if l1Header.Hash() != l1BlockHash {
log.Info(
"Reorg detected due to L1 block hash mismatch",
"blockID", blockID,
"l1BlockHashInAnchor", l1BlockHash,
"l1BlockHash", l1Header.Hash(),
)
return true, nil
}

currentRoot, err := c.GetStorageRoot(ctx, c.L1GethClient, l1SignalService, l1Header.Number)
if err != nil {
return false, err
}

if currentRoot != l1SignalRoot {
log.Info("Reorg detected due to L1 signal root mismatch", "blockID", blockID)
log.Info(
"Reorg detected due to L1 signal root mismatch",
"blockID", blockID,
"l1SignalRootInAnchor", l1SignalRoot,
"l1SignalRoot", currentRoot,
)
return true, nil
}

Expand Down

0 comments on commit b2f2f0b

Please sign in to comment.