@@ -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
2327var 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 )
0 commit comments