Skip to content

Commit 670964e

Browse files
author
colinlyguo
committed
fix
1 parent 4346772 commit 670964e

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

rollup/cmd/proposer_tool/app/app.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ import (
99

1010
"github.com/prometheus/client_golang/prometheus"
1111
"github.com/scroll-tech/da-codec/encoding"
12+
"github.com/scroll-tech/go-ethereum/common"
1213
"github.com/scroll-tech/go-ethereum/log"
1314
"github.com/urfave/cli/v2"
1415

1516
"scroll-tech/common/database"
17+
"scroll-tech/common/types"
1618
"scroll-tech/common/utils"
1719
"scroll-tech/common/version"
1820

1921
"scroll-tech/rollup/internal/config"
2022
"scroll-tech/rollup/internal/controller/watcher"
23+
"scroll-tech/rollup/internal/orm"
24+
rutils "scroll-tech/rollup/internal/utils"
2125
)
2226

2327
var app *cli.App
@@ -59,17 +63,51 @@ func action(ctx *cli.Context) error {
5963
}()
6064

6165
// Init l2BlockOrm connection
62-
l2BlockDB, err := database.InitDB(cfg.L2BlockDBConfigForProposerTool)
66+
dbForReplay, err := database.InitDB(cfg.DBConfigForReplay)
6367
if err != nil {
6468
log.Crit("failed to init l2BlockOrm connection", "err", err)
6569
}
6670
defer func() {
6771
cancel()
68-
if err = database.CloseDB(l2BlockDB); err != nil {
72+
if err = database.CloseDB(dbForReplay); err != nil {
6973
log.Crit("failed to close l2BlockOrm connection", "error", err)
7074
}
7175
}()
7276

77+
blocks, err := orm.NewL2Block(dbForReplay).GetL2BlocksInRange(subCtx, cfg.L2Config.ReplayStartHeight, cfg.L2Config.ReplayStartHeight)
78+
if err != nil {
79+
log.Crit("failed to get l2 blocks", "start block", cfg.L2Config.ReplayStartHeight, "end block", cfg.L2Config.ReplayStartHeight, "error", err)
80+
}
81+
82+
chunk := &encoding.Chunk{Blocks: blocks}
83+
84+
var dbChunk *orm.Chunk
85+
dbChunk, err = orm.NewChunk(db).InsertChunk(subCtx, chunk, encoding.CodecV0, rutils.ChunkMetrics{})
86+
if err != nil {
87+
log.Crit("failed to insert chunk", "error", err)
88+
}
89+
90+
if err = orm.NewChunk(db).UpdateProvingStatus(subCtx, dbChunk.Hash, types.ProvingTaskVerified); err != nil {
91+
log.Crit("failed to update genesis chunk proving status", "error", err)
92+
}
93+
94+
batch := &encoding.Batch{
95+
Index: 0,
96+
TotalL1MessagePoppedBefore: 0,
97+
ParentBatchHash: common.Hash{},
98+
Chunks: []*encoding.Chunk{chunk},
99+
}
100+
101+
var dbBatch *orm.Batch
102+
dbBatch, err = orm.NewBatch(db).InsertBatch(subCtx, batch, encoding.CodecV0, rutils.BatchMetrics{})
103+
if err != nil {
104+
log.Crit("failed to insert batch", "error", err)
105+
}
106+
107+
if err = orm.NewChunk(db).UpdateBatchHashInRange(subCtx, 0, 0, dbBatch.Hash); err != nil {
108+
log.Crit("failed to update batch hash for chunks", "error", err)
109+
}
110+
73111
registry := prometheus.DefaultRegisterer
74112

75113
genesisPath := ctx.String(utils.Genesis.Name)
@@ -87,8 +125,8 @@ func action(ctx *cli.Context) error {
87125
}
88126

89127
minCodecVersion := encoding.CodecVersion(ctx.Uint(utils.MinCodecVersionFlag.Name))
90-
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, l2BlockDB, db, registry, true /* used by tool */)
91-
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, l2BlockDB, db, registry)
128+
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, dbForReplay, db, registry, true /* used by tool */)
129+
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, dbForReplay, db, registry)
92130
bundleProposer := watcher.NewBundleProposer(subCtx, cfg.L2Config.BundleProposerConfig, minCodecVersion, genesis.Config, db, registry)
93131

94132
go utils.Loop(subCtx, 100*time.Millisecond, chunkProposer.TryProposeChunk)

rollup/conf/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
}
3333
},
3434
"l2_config": {
35+
"replay_start_height": 1000000,
3536
"confirmations": "0x1",
3637
"endpoint": "https://rpc.scroll.io",
3738
"l2_message_queue_address": "0x0000000000000000000000000000000000000000",

rollup/internal/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515

1616
// Config load configuration items.
1717
type Config struct {
18-
L1Config *L1Config `json:"l1_config"`
19-
L2Config *L2Config `json:"l2_config"`
20-
DBConfig *database.Config `json:"db_config"`
21-
L2BlockDBConfigForProposerTool *database.Config `json:"l2_block_db_config_for_proposer_tool"`
18+
L1Config *L1Config `json:"l1_config"`
19+
L2Config *L2Config `json:"l2_config"`
20+
DBConfig *database.Config `json:"db_config"`
21+
DBConfigForReplay *database.Config `json:"db_config_for_replay"`
2222
}
2323

2424
// NewConfig returns a new instance of Config.

rollup/internal/config/l2.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type L2Config struct {
2424
BatchProposerConfig *BatchProposerConfig `json:"batch_proposer_config"`
2525
// The bundle_proposer config
2626
BundleProposerConfig *BundleProposerConfig `json:"bundle_proposer_config"`
27+
28+
ReplayStartHeight uint64 `json:"replay_start_height"`
2729
}
2830

2931
// ChunkProposerConfig loads chunk_proposer configuration items.

0 commit comments

Comments
 (0)