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

fix(op-node): pre-fetching handle L1 reOrg round 2 #117

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions op-node/sources/l1_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (s *L1Client) GoOrUpdatePreFetchReceipts(ctx context.Context, l1Start uint6
s.log.Info("pre-fetching receipts start", "startBlock", l1Start)
go func() {
var currentL1Block uint64
var parentHash *common.Hash
var parentHash common.Hash
bnoieh marked this conversation as resolved.
Show resolved Hide resolved
for {
select {
case <-s.done:
Expand All @@ -150,7 +150,7 @@ func (s *L1Client) GoOrUpdatePreFetchReceipts(ctx context.Context, l1Start uint6
case currentL1Block = <-s.preFetchReceiptsStartBlockChan:
s.log.Debug("pre-fetching receipts currentL1Block changed", "block", currentL1Block)
s.receiptsCache.RemoveAll()
parentHash = nil
parentHash = common.Hash{}
default:
blockRef, err := s.L1BlockRefByLabel(ctx, eth.Unsafe)
if err != nil {
Expand Down Expand Up @@ -194,13 +194,15 @@ func (s *L1Client) GoOrUpdatePreFetchReceipts(ctx context.Context, l1Start uint6
continue
}
if ok && pair.blockHash == blockInfo.Hash {
blockInfoChan <- blockInfo
return
}

isSuccess, err := s.PreFetchReceipts(ctx, blockInfo.Hash)
if err != nil {
s.log.Warn("failed to pre-fetch receipts", "err", err)
return
time.Sleep(1 * time.Second)
continue
}
if !isSuccess {
s.log.Debug("pre fetch receipts fail without error,need retry", "blockHash", blockInfo.Hash, "blockNumber", blockNumber)
Expand Down Expand Up @@ -233,13 +235,13 @@ func (s *L1Client) GoOrUpdatePreFetchReceipts(ctx context.Context, l1Start uint6
}

s.log.Debug("pre-fetching receipts hash", "latestBlockHash", latestBlockHash, "latestBlockNumber", latestBlockNumber, "oldestBlockNumber", oldestFetchBlockNumber, "oldestBlockParentHash", oldestBlockParentHash)
if parentHash != nil && oldestBlockParentHash != (common.Hash{}) && oldestBlockParentHash != *parentHash && currentL1Block >= sequencerConfDepth+uint64(taskCount) {
if parentHash != (common.Hash{}) && oldestBlockParentHash != (common.Hash{}) && oldestBlockParentHash != parentHash && currentL1Block >= sequencerConfDepth+uint64(taskCount) {
currentL1Block = currentL1Block - sequencerConfDepth - uint64(taskCount)
s.log.Warn("pre-fetching receipts found l1 reOrg, return to an earlier block height for re-prefetching", "recordParentHash", *parentHash, "unsafeParentHash", oldestBlockParentHash, "number", oldestFetchBlockNumber, "backToNumber", currentL1Block)
parentHash = nil
s.log.Warn("pre-fetching receipts found l1 reOrg, return to an earlier block height for re-prefetching", "recordParentHash", parentHash, "unsafeParentHash", oldestBlockParentHash, "number", oldestFetchBlockNumber, "backToNumber", currentL1Block)
parentHash = common.Hash{}
continue
}
parentHash = &latestBlockHash
parentHash = latestBlockHash
}
}
}()
Expand Down
Loading