Skip to content

Commit 267093a

Browse files
authored
Merge branch 'master' into master
2 parents 0a86b54 + 15e2283 commit 267093a

File tree

6 files changed

+69
-20
lines changed

6 files changed

+69
-20
lines changed

arbnode/delayed.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (m *DelayedInboxMessage) AfterInboxAcc() common.Hash {
155155
return crypto.Keccak256Hash(m.BeforeInboxAcc[:], hash)
156156
}
157157

158-
func (b *DelayedBridge) LookupMessagesInRange(ctx context.Context, from, to *big.Int, batchFetcher arbostypes.FallibleBatchFetcher) ([]*DelayedInboxMessage, error) {
158+
func (b *DelayedBridge) LookupMessagesInRange(ctx context.Context, from, to *big.Int, batchFetcher arbostypes.FallibleBatchFetcherWithParentBlock) ([]*DelayedInboxMessage, error) {
159159
query := ethereum.FilterQuery{
160160
BlockHash: nil,
161161
FromBlock: from,
@@ -184,7 +184,7 @@ func (l sortableMessageList) Less(i, j int) bool {
184184
return bytes.Compare(l[i].Message.Header.RequestId.Bytes(), l[j].Message.Header.RequestId.Bytes()) < 0
185185
}
186186

187-
func (b *DelayedBridge) logsToDeliveredMessages(ctx context.Context, logs []types.Log, batchFetcher arbostypes.FallibleBatchFetcher) ([]*DelayedInboxMessage, error) {
187+
func (b *DelayedBridge) logsToDeliveredMessages(ctx context.Context, logs []types.Log, batchFetcher arbostypes.FallibleBatchFetcherWithParentBlock) ([]*DelayedInboxMessage, error) {
188188
if len(logs) == 0 {
189189
return nil, nil
190190
}
@@ -258,7 +258,7 @@ func (b *DelayedBridge) logsToDeliveredMessages(ctx context.Context, logs []type
258258
},
259259
ParentChainBlockNumber: parsedLog.Raw.BlockNumber,
260260
}
261-
err := msg.Message.FillInBatchGasFields(batchFetcher)
261+
err := msg.Message.FillInBatchGasFieldsWithParentBlock(batchFetcher, msg.ParentChainBlockNumber)
262262
if err != nil {
263263
return nil, err
264264
}

arbnode/delayed_sequencer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (d *DelayedSequencer) sequenceWithoutLockout(ctx context.Context, lastBlock
175175
}
176176
lastDelayedAcc = acc
177177
err = msg.FillInBatchGasFields(func(batchNum uint64) ([]byte, error) {
178-
data, _, err := d.reader.GetSequencerMessageBytes(ctx, batchNum)
178+
data, _, err := d.reader.GetSequencerMessageBytesForParentBlock(ctx, batchNum, parentChainBlockNumber)
179179
return data, err
180180
})
181181
if err != nil {

arbnode/inbox_reader.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,16 @@ func (r *InboxReader) run(ctx context.Context, hadError bool) error {
473473
if err != nil {
474474
return err
475475
}
476-
delayedMessages, err := r.delayedBridge.LookupMessagesInRange(ctx, from, to, func(batchNum uint64) ([]byte, error) {
476+
delayedMessages, err := r.delayedBridge.LookupMessagesInRange(ctx, from, to, func(batchNum uint64, parentChainBlockNumber uint64) ([]byte, error) {
477477
if len(sequencerBatches) > 0 && batchNum >= sequencerBatches[0].SequenceNumber {
478478
idx := batchNum - sequencerBatches[0].SequenceNumber
479479
if idx < uint64(len(sequencerBatches)) {
480480
return sequencerBatches[idx].Serialize(ctx, r.l1Reader.Client())
481481
}
482482
log.Warn("missing mentioned batch in L1 message lookup", "batch", batchNum)
483483
}
484-
data, _, err := r.GetSequencerMessageBytes(ctx, batchNum)
484+
// Here we pass in the local parentChainBlockNumber as LookupMessagesInRange fetches parentChainBlockNumber from the logs
485+
data, _, err := r.GetSequencerMessageBytesForParentBlock(ctx, batchNum, parentChainBlockNumber)
485486
return data, err
486487
})
487488
if err != nil {
@@ -681,7 +682,11 @@ func (r *InboxReader) GetSequencerMessageBytes(ctx context.Context, seqNum uint6
681682
if err != nil {
682683
return nil, common.Hash{}, err
683684
}
684-
blockNum := arbmath.UintToBig(metadata.ParentChainBlock)
685+
return r.GetSequencerMessageBytesForParentBlock(ctx, seqNum, metadata.ParentChainBlock)
686+
}
687+
688+
func (r *InboxReader) GetSequencerMessageBytesForParentBlock(ctx context.Context, seqNum uint64, parentChainBlock uint64) ([]byte, common.Hash, error) {
689+
blockNum := arbmath.UintToBig(parentChainBlock)
685690
seqBatches, err := r.sequencerInbox.LookupBatchesInRange(ctx, blockNum, blockNum)
686691
if err != nil {
687692
return nil, common.Hash{}, err
@@ -694,7 +699,7 @@ func (r *InboxReader) GetSequencerMessageBytes(ctx context.Context, seqNum uint6
694699
}
695700
seenBatches = append(seenBatches, batch.SequenceNumber)
696701
}
697-
return nil, common.Hash{}, fmt.Errorf("sequencer batch %v not found in L1 block %v (found batches %v)", seqNum, metadata.ParentChainBlock, seenBatches)
702+
return nil, common.Hash{}, fmt.Errorf("sequencer batch %v not found in L1 block %v (found batches %v)", seqNum, parentChainBlock, seenBatches)
698703
}
699704

700705
func (r *InboxReader) GetLastReadBatchCount() uint64 {

arbnode/inbox_tracker.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,15 @@ func (t *InboxTracker) legacyGetDelayedMessageAndAccumulator(ctx context.Context
359359
}
360360

361361
func (t *InboxTracker) GetDelayedMessageAccumulatorAndParentChainBlockNumber(ctx context.Context, seqNum uint64) (*arbostypes.L1IncomingMessage, common.Hash, uint64, error) {
362-
msg, acc, blockNum, err := t.getRawDelayedMessageAccumulatorAndParentChainBlockNumber(ctx, seqNum)
362+
msg, acc, parentChainBlockNumber, err := t.getRawDelayedMessageAccumulatorAndParentChainBlockNumber(ctx, seqNum)
363363
if err != nil {
364-
return msg, acc, blockNum, err
364+
return msg, acc, parentChainBlockNumber, err
365365
}
366366
err = msg.FillInBatchGasFields(func(batchNum uint64) ([]byte, error) {
367-
data, _, err := t.txStreamer.inboxReader.GetSequencerMessageBytes(ctx, batchNum)
367+
data, _, err := t.txStreamer.inboxReader.GetSequencerMessageBytesForParentBlock(ctx, batchNum, parentChainBlockNumber)
368368
return data, err
369369
})
370-
return msg, acc, blockNum, err
370+
return msg, acc, parentChainBlockNumber, err
371371
}
372372

373373
// does not return message, so does not need to fill in batchGasFields

arbnode/transaction_streamer.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,37 @@ func (s *TransactionStreamer) GetMessage(msgIdx arbutil.MessageIndex) (*arbostyp
492492
return nil, err
493493
}
494494

495+
ctx, err := s.GetContextSafe()
496+
if err != nil {
497+
return nil, err
498+
}
499+
500+
var parentChainBlockNumber *uint64
501+
if message.DelayedMessagesRead != 0 && s.inboxReader != nil && s.inboxReader.tracker != nil {
502+
_, _, localParentChainBlockNumber, err := s.inboxReader.tracker.getRawDelayedMessageAccumulatorAndParentChainBlockNumber(ctx, message.DelayedMessagesRead-1)
503+
if err != nil {
504+
log.Warn("Failed to fetch parent chain block number for delayed message. Will fall back to BatchMetadata", "idx", message.DelayedMessagesRead-1)
505+
} else {
506+
parentChainBlockNumber = &localParentChainBlockNumber
507+
}
508+
}
509+
495510
err = message.Message.FillInBatchGasFields(func(batchNum uint64) ([]byte, error) {
496511
ctx, err := s.GetContextSafe()
497512
if err != nil {
498513
return nil, err
499514
}
500-
data, _, err := s.inboxReader.GetSequencerMessageBytes(ctx, batchNum)
515+
516+
var data []byte
517+
if parentChainBlockNumber != nil {
518+
data, _, err = s.inboxReader.GetSequencerMessageBytesForParentBlock(ctx, batchNum, *parentChainBlockNumber)
519+
} else {
520+
data, _, err = s.inboxReader.GetSequencerMessageBytes(ctx, batchNum)
521+
}
522+
if err != nil {
523+
return nil, err
524+
}
525+
501526
return data, err
502527
})
503528
if err != nil {

arbos/arbostypes/incomingmessage.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/ethereum/go-ethereum/common"
1515
"github.com/ethereum/go-ethereum/crypto"
16+
"github.com/ethereum/go-ethereum/log"
1617
"github.com/ethereum/go-ethereum/params"
1718

1819
"github.com/offchainlabs/nitro/arbos/util"
@@ -176,6 +177,10 @@ func LegacyCostForStats(stats *BatchDataStats) uint64 {
176177
}
177178

178179
func (msg *L1IncomingMessage) FillInBatchGasFields(batchFetcher FallibleBatchFetcher) error {
180+
return msg.FillInBatchGasFieldsWithParentBlock(FromFallibleBatchFetcher(batchFetcher), msg.Header.BlockNumber)
181+
}
182+
183+
func (msg *L1IncomingMessage) FillInBatchGasFieldsWithParentBlock(batchFetcher FallibleBatchFetcherWithParentBlock, parentChainBlockNumber uint64) error {
179184
if batchFetcher == nil || msg.Header.Kind != L1MessageType_BatchPostingReport {
180185
return nil
181186
}
@@ -187,16 +192,21 @@ func (msg *L1IncomingMessage) FillInBatchGasFields(batchFetcher FallibleBatchFet
187192
if err != nil {
188193
return fmt.Errorf("failed to parse batch posting report: %w", err)
189194
}
190-
batchData, err := batchFetcher(batchNum)
195+
batchData, err := batchFetcher(batchNum, parentChainBlockNumber)
191196
if err != nil {
192-
return fmt.Errorf("failed to fetch batch mentioned by batch posting report: %w", err)
193-
}
194-
gotHash := crypto.Keccak256Hash(batchData)
195-
if gotHash != batchHash {
196-
return fmt.Errorf("batch fetcher returned incorrect data hash %v (wanted %v for batch %v)", gotHash, batchHash, batchNum)
197+
if msg.LegacyBatchGasCost == nil {
198+
return fmt.Errorf("failed to fetch batch mentioned by batch posting report: %w", err)
199+
}
200+
log.Warn("Failed reading batch data for filling message - leaving BatchDataStats empty")
201+
} else {
202+
gotHash := crypto.Keccak256Hash(batchData)
203+
if gotHash != batchHash {
204+
return fmt.Errorf("batch fetcher returned incorrect data hash %v (wanted %v for batch %v)", gotHash, batchHash, batchNum)
205+
}
206+
msg.BatchDataStats = GetDataStats(batchData)
197207
}
198-
msg.BatchDataStats = GetDataStats(batchData)
199208
}
209+
200210
legacyCost := LegacyCostForStats(msg.BatchDataStats)
201211
msg.LegacyBatchGasCost = &legacyCost
202212
return nil
@@ -271,8 +281,17 @@ func ParseIncomingL1Message(rd io.Reader, batchFetcher FallibleBatchFetcher) (*L
271281
return msg, nil
272282
}
273283

284+
type FallibleBatchFetcherWithParentBlock func(batchNum uint64, parentChainBlock uint64) ([]byte, error)
285+
274286
type FallibleBatchFetcher func(batchNum uint64) ([]byte, error)
275287

288+
// Wraps FallibleBatchFetcher into FallibleBatchFetcherWithParentBlock to ignore parentChainBlock
289+
func FromFallibleBatchFetcher(f FallibleBatchFetcher) FallibleBatchFetcherWithParentBlock {
290+
return func(batchNum uint64, _ uint64) ([]byte, error) {
291+
return f(batchNum)
292+
}
293+
}
294+
276295
type ParsedInitMessage struct {
277296
ChainId *big.Int
278297
InitialL1BaseFee *big.Int

0 commit comments

Comments
 (0)