@@ -3,13 +3,16 @@ package app
33import (
44 "context"
55 "fmt"
6+ "math/big"
67 "os"
78 "os/signal"
89 "time"
910
1011 "github.com/prometheus/client_golang/prometheus"
1112 "github.com/scroll-tech/da-codec/encoding"
1213 "github.com/scroll-tech/go-ethereum/common"
14+ gethTypes "github.com/scroll-tech/go-ethereum/core/types"
15+ "github.com/scroll-tech/go-ethereum/ethclient"
1316 "github.com/scroll-tech/go-ethereum/log"
1417 "github.com/urfave/cli/v2"
1518
@@ -74,12 +77,33 @@ func action(ctx *cli.Context) error {
7477 }
7578 }()
7679
77- blocks , err := orm .NewL2Block (dbForReplay ).GetL2BlocksInRange (subCtx , cfg .L2Config .ReplayStartHeight , cfg .L2Config .ReplayStartHeight )
80+ // Init l2geth connection
81+ l2Client , err := ethclient .Dial (cfg .L2Config .Endpoint )
7882 if err != nil {
79- log .Crit ("failed to get l2 blocks " , "start block " , cfg . L2Config . ReplayStartHeight , "end block" , cfg . L2Config . ReplayStartHeight , "error" , err )
83+ log .Crit ("failed to connect l2 geth " , "config file " , cfgFile , "error" , err )
8084 }
8185
82- chunk := & encoding.Chunk {Blocks : blocks }
86+ genesisHeader , err := l2Client .HeaderByNumber (subCtx , big .NewInt (0 ))
87+ if err != nil {
88+ return fmt .Errorf ("failed to retrieve L2 genesis header: %v" , err )
89+ }
90+
91+ genesisTime := genesisHeader .Time
92+ currentTime := uint64 (time .Now ().Unix ())
93+ timeDrift := currentTime - genesisTime
94+
95+ cfg .L2Config .ChunkProposerConfig .ChunkTimeoutSec += timeDrift
96+ cfg .L2Config .BatchProposerConfig .BatchTimeoutSec += timeDrift
97+ cfg .L2Config .BundleProposerConfig .BundleTimeoutSec += timeDrift
98+
99+ chunk := & encoding.Chunk {
100+ Blocks : []* encoding.Block {{
101+ Header : genesisHeader ,
102+ Transactions : nil ,
103+ WithdrawRoot : common.Hash {},
104+ RowConsumption : & gethTypes.RowConsumption {},
105+ }},
106+ }
83107
84108 var dbChunk * orm.Chunk
85109 dbChunk , err = orm .NewChunk (db ).InsertChunk (subCtx , chunk , encoding .CodecV0 , rutils.ChunkMetrics {})
0 commit comments