Skip to content

Commit be3f189

Browse files
author
colinlyguo
committed
address comments
1 parent c0138d2 commit be3f189

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

rollup/cmd/proposer_tool/app/app.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ func action(ctx *cli.Context) error {
9393
}
9494

9595
startL2BlockHeight := ctx.Uint64(utils.StartL2BlockFlag.Name)
96-
startL2Block, err := l2Client.BlockByNumber(context.Background(), big.NewInt(int64(startL2BlockHeight)))
97-
if err != nil {
98-
log.Crit("failed to get start l2 block", "startL2BlockHeight", startL2BlockHeight, "error", err)
99-
}
100-
101-
chunk := &encoding.Chunk{Blocks: []*encoding.Block{{Header: startL2Block.Header()}}}
10296

10397
prevChunk, err := orm.NewChunk(dbForReplay).GetParentChunkByBlockNumber(subCtx, startL2BlockHeight)
10498
if err != nil {
@@ -110,12 +104,32 @@ func action(ctx *cli.Context) error {
110104
startQueueIndex = prevChunk.TotalL1MessagesPoppedBefore + prevChunk.TotalL1MessagesPoppedInChunk
111105
}
112106

113-
for _, tx := range startL2Block.Transactions() {
114-
if tx.Type() == gethTypes.L1MessageTxType {
115-
startQueueIndex++
107+
startBlock := uint64(0)
108+
if prevChunk != nil {
109+
startBlock = prevChunk.EndBlockNumber + 1
110+
}
111+
112+
var chunk *encoding.Chunk
113+
for blockNum := startBlock; blockNum <= startL2BlockHeight; blockNum++ {
114+
block, err := l2Client.BlockByNumber(context.Background(), big.NewInt(int64(blockNum)))
115+
if err != nil {
116+
log.Crit("failed to get block", "block number", blockNum, "error", err)
117+
}
118+
119+
for _, tx := range block.Transactions() {
120+
if tx.Type() == gethTypes.L1MessageTxType {
121+
startQueueIndex++
122+
}
123+
}
124+
125+
if blockNum == startL2BlockHeight {
126+
chunk = &encoding.Chunk{Blocks: []*encoding.Block{{Header: block.Header()}}}
116127
}
117128
}
118129

130+
// Setting empty hash as the post_l1_message_queue_hash of the first chunk,
131+
// i.e., treating the first L1 message after this chunk as the first L1 message in message queue v2.
132+
// Though this setting is different from mainnet, it's simple yet sufficient for data analysis usage.
119133
_, err = orm.NewChunk(db).InsertTestChunkForProposerTool(subCtx, chunk, encoding.CodecV0, startQueueIndex)
120134
if err != nil {
121135
log.Crit("failed to insert chunk", "error", err)

rollup/internal/orm/chunk.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,21 @@ func (o *Chunk) InsertTestChunkForProposerTool(ctx context.Context, chunk *encod
291291
}
292292

293293
numBlocks := len(chunk.Blocks)
294+
firstBlock := chunk.Blocks[0]
295+
lastBlock := chunk.Blocks[numBlocks-1]
294296
newChunk := Chunk{
295297
Index: 0,
296298
Hash: chunkHash.Hex(),
297-
StartBlockNumber: chunk.Blocks[0].Header.Number.Uint64(),
298-
StartBlockHash: chunk.Blocks[0].Header.Hash().Hex(),
299-
EndBlockNumber: chunk.Blocks[numBlocks-1].Header.Number.Uint64(),
300-
EndBlockHash: chunk.Blocks[numBlocks-1].Header.Hash().Hex(),
299+
StartBlockNumber: firstBlock.Header.Number.Uint64(),
300+
StartBlockHash: firstBlock.Header.Hash().Hex(),
301+
EndBlockNumber: lastBlock.Header.Number.Uint64(),
302+
EndBlockHash: lastBlock.Header.Hash().Hex(),
301303
TotalL2TxGas: chunk.TotalGasUsed(),
302304
TotalL2TxNum: chunk.NumL2Transactions(),
303-
StartBlockTime: chunk.Blocks[0].Header.Time,
305+
StartBlockTime: firstBlock.Header.Time,
304306
TotalL1MessagesPoppedBefore: totalL1MessagePoppedBefore,
305-
StateRoot: chunk.Blocks[numBlocks-1].Header.Root.Hex(),
306-
WithdrawRoot: chunk.Blocks[numBlocks-1].WithdrawRoot.Hex(),
307+
StateRoot: lastBlock.Header.Root.Hex(),
308+
WithdrawRoot: lastBlock.WithdrawRoot.Hex(),
307309
CodecVersion: int16(codecVersion),
308310
}
309311

0 commit comments

Comments
 (0)