@@ -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
178179func (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+
274286type 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+
276295type ParsedInitMessage struct {
277296 ChainId * big.Int
278297 InitialL1BaseFee * big.Int
0 commit comments