@@ -19,6 +19,7 @@ package utils
19
19
20
20
import (
21
21
"crypto/ecdsa"
22
+ "errors"
22
23
"fmt"
23
24
"io"
24
25
"io/ioutil"
@@ -41,6 +42,7 @@ import (
41
42
"github.com/scroll-tech/go-ethereum/accounts/keystore"
42
43
"github.com/scroll-tech/go-ethereum/common"
43
44
"github.com/scroll-tech/go-ethereum/common/fdlimit"
45
+ "github.com/scroll-tech/go-ethereum/common/hexutil"
44
46
"github.com/scroll-tech/go-ethereum/consensus"
45
47
"github.com/scroll-tech/go-ethereum/consensus/clique"
46
48
"github.com/scroll-tech/go-ethereum/consensus/ethash"
@@ -53,6 +55,7 @@ import (
53
55
"github.com/scroll-tech/go-ethereum/eth/ethconfig"
54
56
"github.com/scroll-tech/go-ethereum/eth/gasprice"
55
57
"github.com/scroll-tech/go-ethereum/eth/tracers"
58
+ "github.com/scroll-tech/go-ethereum/ethclient"
56
59
"github.com/scroll-tech/go-ethereum/ethdb"
57
60
"github.com/scroll-tech/go-ethereum/ethstats"
58
61
"github.com/scroll-tech/go-ethereum/graphql"
@@ -70,6 +73,7 @@ import (
70
73
"github.com/scroll-tech/go-ethereum/p2p/nat"
71
74
"github.com/scroll-tech/go-ethereum/p2p/netutil"
72
75
"github.com/scroll-tech/go-ethereum/params"
76
+ "github.com/scroll-tech/go-ethereum/rpc"
73
77
)
74
78
75
79
func init () {
@@ -794,6 +798,20 @@ var (
794
798
Name : "catalyst" ,
795
799
Usage : "Catalyst mode (eth2 integration testing)" ,
796
800
}
801
+
802
+ // L1Settings
803
+ L1EndpointFlag = cli.StringFlag {
804
+ Name : "l1.endpoint" ,
805
+ Usage : "Endpoint of L1 HTTP-RPC server" ,
806
+ }
807
+ L1ConfirmationsFlag = cli.StringFlag {
808
+ Name : "l1.confirmations" ,
809
+ Usage : "Number of confirmations on L1 needed for finalization, or \" safe\" or \" finalized\" " ,
810
+ }
811
+ L1DeploymentBlockFlag = cli.Int64Flag {
812
+ Name : "l1.sync.startblock" ,
813
+ Usage : "L1 block height to start syncing from. Should be set to the L1 message queue deployment block number." ,
814
+ }
797
815
)
798
816
799
817
// MakeDataDir retrieves the currently requested data directory, terminating
@@ -1226,6 +1244,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
1226
1244
setNodeUserIdent (ctx , cfg )
1227
1245
setDataDir (ctx , cfg )
1228
1246
setSmartCard (ctx , cfg )
1247
+ setL1 (ctx , cfg )
1229
1248
1230
1249
if ctx .GlobalIsSet (ExternalSignerFlag .Name ) {
1231
1250
cfg .ExternalSigner = ctx .GlobalString (ExternalSignerFlag .Name )
@@ -1251,6 +1270,42 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
1251
1270
}
1252
1271
}
1253
1272
1273
+ func unmarshalBlockNumber (input string ) (rpc.BlockNumber , error ) {
1274
+ switch input {
1275
+ case "finalized" :
1276
+ return rpc .FinalizedBlockNumber , nil
1277
+ case "safe" :
1278
+ return rpc .SafeBlockNumber , nil
1279
+ }
1280
+ blockNum , err := hexutil .DecodeUint64 (input )
1281
+ if err == nil && blockNum <= math .MaxInt64 {
1282
+ return rpc .BlockNumber (blockNum ), nil
1283
+ }
1284
+ blockNum , err = strconv .ParseUint (input , 10 , 64 )
1285
+ if err == nil && blockNum <= math .MaxInt64 {
1286
+ return rpc .BlockNumber (blockNum ), nil
1287
+ }
1288
+ return 0 , errors .New ("incorrect value" )
1289
+ }
1290
+
1291
+ func setL1 (ctx * cli.Context , cfg * node.Config ) {
1292
+ var err error
1293
+ if ctx .GlobalIsSet (L1EndpointFlag .Name ) {
1294
+ cfg .L1Endpoint = ctx .GlobalString (L1EndpointFlag .Name )
1295
+ }
1296
+ if ctx .GlobalIsSet (L1ConfirmationsFlag .Name ) {
1297
+ cfg .L1Confirmations , err = unmarshalBlockNumber (ctx .GlobalString (L1ConfirmationsFlag .Name ))
1298
+ if err != nil {
1299
+ panic (fmt .Sprintf ("invalid value for flag %s: %s" , L1ConfirmationsFlag .Name , ctx .GlobalString (L1ConfirmationsFlag .Name )))
1300
+ }
1301
+ } else {
1302
+ cfg .L1Confirmations = rpc .FinalizedBlockNumber
1303
+ }
1304
+ if ctx .GlobalIsSet (L1DeploymentBlockFlag .Name ) {
1305
+ cfg .L1DeploymentBlock = ctx .GlobalUint64 (L1DeploymentBlockFlag .Name )
1306
+ }
1307
+ }
1308
+
1254
1309
func setSmartCard (ctx * cli.Context , cfg * node.Config ) {
1255
1310
// Skip enabling smartcards if no path is set
1256
1311
path := ctx .GlobalString (SmartCardDaemonPathFlag .Name )
@@ -1732,7 +1787,23 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend
1732
1787
stack .RegisterAPIs (tracers .APIs (backend .ApiBackend ))
1733
1788
return backend .ApiBackend , nil
1734
1789
}
1735
- backend , err := eth .New (stack , cfg )
1790
+
1791
+ // initialize L1 client for sync service
1792
+ // note: we need to do this here to avoid circular dependency
1793
+ l1EndpointUrl := stack .Config ().L1Endpoint
1794
+ var l1Client * ethclient.Client
1795
+
1796
+ if l1EndpointUrl != "" {
1797
+ var err error
1798
+ l1Client , err = ethclient .Dial (l1EndpointUrl )
1799
+ if err != nil {
1800
+ Fatalf ("Unable to connect to L1 endpoint at %v: %v" , l1EndpointUrl , err )
1801
+ }
1802
+
1803
+ log .Info ("Initialized L1 client" , "endpoint" , l1EndpointUrl )
1804
+ }
1805
+
1806
+ backend , err := eth .New (stack , cfg , l1Client )
1736
1807
if err != nil {
1737
1808
Fatalf ("Failed to register the Ethereum service: %v" , err )
1738
1809
}
0 commit comments