Skip to content

Commit

Permalink
Merge pull request #1977 from OffchainLabs/duplicate-getblocknumber
Browse files Browse the repository at this point in the history
don't re-request parent block if same block as previous block
  • Loading branch information
joshuacolvin0 authored Nov 21, 2023
2 parents 1c3f4ad + ff8746d commit 391900c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions arbnode/delayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ func (b *DelayedBridge) logsToDeliveredMessages(ctx context.Context, logs []type
}

messages := make([]*DelayedInboxMessage, 0, len(logs))
var lastParentChainBlockNumber uint64
var lastL1BlockNumber uint64
for _, parsedLog := range parsedLogs {
msgKey := common.BigToHash(parsedLog.MessageIndex)
data, ok := messageData[msgKey]
Expand All @@ -196,9 +198,17 @@ func (b *DelayedBridge) logsToDeliveredMessages(ctx context.Context, logs []type

requestId := common.BigToHash(parsedLog.MessageIndex)
parentChainBlockNumber := parsedLog.Raw.BlockNumber
l1BlockNumber, err := arbutil.CorrespondingL1BlockNumber(ctx, b.client, parentChainBlockNumber)
if err != nil {
return nil, err
var l1BlockNumber uint64
if lastParentChainBlockNumber == parentChainBlockNumber && lastParentChainBlockNumber > 0 {
l1BlockNumber = lastL1BlockNumber
} else {
var err error
l1BlockNumber, err = arbutil.CorrespondingL1BlockNumber(ctx, b.client, parentChainBlockNumber)
if err != nil {
return nil, err
}
lastParentChainBlockNumber = parentChainBlockNumber
lastL1BlockNumber = l1BlockNumber
}
msg := &DelayedInboxMessage{
BlockHash: parsedLog.Raw.BlockHash,
Expand All @@ -216,7 +226,7 @@ func (b *DelayedBridge) logsToDeliveredMessages(ctx context.Context, logs []type
},
ParentChainBlockNumber: parsedLog.Raw.BlockNumber,
}
err = msg.Message.FillInBatchGasCost(batchFetcher)
err := msg.Message.FillInBatchGasCost(batchFetcher)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 391900c

Please sign in to comment.