Skip to content

Commit 8db5339

Browse files
committed
fix issues with chunks when handling CodecV7
1 parent 99c0a9f commit 8db5339

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

rollup/internal/controller/watcher/batch_proposer.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,15 @@ func (p *BatchProposer) proposeBatch() error {
291291
var batch encoding.Batch
292292
batch.Index = dbParentBatch.Index + 1
293293
batch.ParentBatchHash = common.HexToHash(dbParentBatch.Hash)
294-
batch.TotalL1MessagePoppedBefore = firstUnbatchedChunk.TotalL1MessagesPoppedBefore
294+
batch.InitialL1MessageIndex = firstUnbatchedChunk.TotalL1MessagesPoppedBefore
295+
batch.TotalL1MessagePoppedBefore = firstUnbatchedChunk.TotalL1MessagesPoppedBefore // set for compatibility within relayer
295296
batch.InitialL1MessageQueueHash = common.HexToHash(firstUnbatchedChunk.InitialL1MessageQueueHash)
296297

297298
for i, chunk := range daChunks {
298299
batch.Chunks = append(batch.Chunks, chunk)
300+
if codec.Version() >= encoding.CodecV7 {
301+
batch.Blocks = append(batch.Blocks, chunk.Blocks...)
302+
}
299303
batch.LastL1MessageQueueHash = common.HexToHash(dbChunks[i].LastL1MessageQueueHash)
300304

301305
metrics, calcErr := utils.CalculateBatchMetrics(&batch, codec.Version())
@@ -370,7 +374,10 @@ func (p *BatchProposer) getDAChunks(dbChunks []*orm.Chunk) ([]*encoding.Chunk, e
370374
return nil, err
371375
}
372376
chunks[i] = &encoding.Chunk{
373-
Blocks: blocks,
377+
Blocks: blocks,
378+
InitialL1MessageIndex: c.TotalL1MessagesPoppedBefore,
379+
InitialL1MessageQueueHash: common.HexToHash(c.InitialL1MessageQueueHash),
380+
LastL1MessageQueueHash: common.HexToHash(c.LastL1MessageQueueHash),
374381
}
375382
}
376383
return chunks, nil

rollup/internal/controller/watcher/chunk_proposer.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,11 @@ func (p *ChunkProposer) proposeChunk() error {
312312

313313
// previous chunk is not CodecV7, this means this is the first chunk of the fork.
314314
if encoding.CodecVersion(parentChunk.CodecVersion) < codecVersion {
315-
// double check with the previous block
316-
prevBlocks, err := p.l2BlockOrm.GetL2BlocksGEHeight(p.ctx, blocks[0].Header.Number.Uint64()-1, 1)
317-
if err != nil || len(prevBlocks) == 0 || prevBlocks[0].Header.Hash() != blocks[0].Header.ParentHash {
318-
return fmt.Errorf("failed to get parent block: %w", err)
319-
}
320-
// We expect the previous block to be not EuclidV2. If it is something went wrong.
321-
if p.chainCfg.IsEuclidV2(prevBlocks[0].Header.Time) {
322-
return fmt.Errorf("unexpected EuclidV2 block: %v, current block: %d, chunk version: %d, parent chunk version: %d, parent chunk index: %d", prevBlocks[0].Header.Number, blocks[0].Header.Number, codecVersion, parentChunk.CodecVersion, parentChunk.Index)
323-
}
324-
325315
chunk.InitialL1MessageQueueHash = common.Hash{}
326316
}
327317

328318
chunk.LastL1MessageQueueHash = chunk.InitialL1MessageQueueHash
319+
chunk.InitialL1MessageIndex = parentChunk.TotalL1MessagesPoppedBefore + parentChunk.TotalL1MessagesPoppedInChunk
329320
}
330321

331322
var previousLastL1MessageQueueHash common.Hash

0 commit comments

Comments
 (0)