diff --git a/cmd/flags/driver.go b/cmd/flags/driver.go index b29aa7174..eab6e4808 100644 --- a/cmd/flags/driver.go +++ b/cmd/flags/driver.go @@ -8,7 +8,7 @@ import ( // Optional flags used by driver. var ( - P2PSyncVerifiedBlocks = &cli.BoolFlag{ + P2PSync = &cli.BoolFlag{ Name: "p2p.sync", Usage: "Try P2P syncing blocks between L2 execution engines, " + "will be helpful to bring a new node online quickly", @@ -54,7 +54,7 @@ var DriverFlags = MergeFlags(CommonFlags, []cli.Flag{ L2WSEndpoint, L2AuthEndpoint, JWTSecret, - P2PSyncVerifiedBlocks, + P2PSync, P2PSyncTimeout, CheckPointSyncURL, MaxExponent, diff --git a/driver/chain_syncer/chain_syncer.go b/driver/chain_syncer/chain_syncer.go index 875d13492..5a97e4362 100644 --- a/driver/chain_syncer/chain_syncer.go +++ b/driver/chain_syncer/chain_syncer.go @@ -35,7 +35,7 @@ type L2ChainSyncer struct { // If this flag is activated, will try P2P beacon sync if current node is behind of the protocol's // the latest verified block head - p2pSyncVerifiedBlocks bool + p2pSync bool } // New creates a new chain syncer instance. @@ -43,7 +43,7 @@ func New( ctx context.Context, rpc *rpc.Client, state *state.State, - p2pSyncVerifiedBlocks bool, + p2pSync bool, p2pSyncTimeout time.Duration, maxRetrieveExponent uint64, blobServerEndpoint *url.URL, @@ -63,14 +63,14 @@ func New( } return &L2ChainSyncer{ - ctx: ctx, - rpc: rpc, - state: state, - beaconSyncer: beaconSyncer, - blobSyncer: blobSyncer, - progressTracker: tracker, - syncMode: syncMode, - p2pSyncVerifiedBlocks: p2pSyncVerifiedBlocks, + ctx: ctx, + rpc: rpc, + state: state, + beaconSyncer: beaconSyncer, + blobSyncer: blobSyncer, + progressTracker: tracker, + syncMode: syncMode, + p2pSync: p2pSync, }, nil } @@ -81,7 +81,7 @@ func (s *L2ChainSyncer) Sync() error { return err } // If current L2 execution engine's chain is behind of the protocol's latest verified block head, and the - // `P2PSyncVerifiedBlocks` flag is set, try triggering a beacon sync in L2 execution engine to catch up the + // `P2PSync` flag is set, try triggering a beacon sync in L2 execution engine to catch up the // latest verified block head. if needNewBeaconSyncTriggered { if err := s.beaconSyncer.TriggerBeaconSync(blockID); err != nil { @@ -96,7 +96,7 @@ func (s *L2ChainSyncer) Sync() error { if s.progressTracker.Triggered() { log.Info( "Switch to insert pending blocks one by one", - "p2pEnabled", s.p2pSyncVerifiedBlocks, + "p2pEnabled", s.p2pSync, "p2pOutOfSync", s.progressTracker.OutOfSync(), ) @@ -160,13 +160,13 @@ func (s *L2ChainSyncer) AheadOfProtocolVerifiedHead(verifiedHeightToCompare uint // needNewBeaconSyncTriggered checks whether the current L2 execution engine needs to trigger // another new beacon sync, the following conditions should be met: -// 1. The `P2PSyncVerifiedBlocks` flag is set. +// 1. The `P2PSync` flag is set. // 2. The protocol's latest verified block head is not zero. // 3. The L2 execution engine's chain is behind of the protocol's latest verified block head. // 4. The L2 execution engine's chain have met a sync timeout issue. func (s *L2ChainSyncer) needNewBeaconSyncTriggered() (uint64, bool, error) { // If the flag is not set or there was a finished beacon sync, we simply return false. - if !s.p2pSyncVerifiedBlocks || s.progressTracker.Finished() { + if !s.p2pSync || s.progressTracker.Finished() { return 0, false, nil } diff --git a/driver/config.go b/driver/config.go index 21d1382db..e385d758d 100644 --- a/driver/config.go +++ b/driver/config.go @@ -17,11 +17,11 @@ import ( // Config contains the configurations to initialize a Taiko driver. type Config struct { *rpc.ClientConfig - P2PSyncVerifiedBlocks bool - P2PSyncTimeout time.Duration - RetryInterval time.Duration - MaxExponent uint64 - BlobServerEndpoint *url.URL + P2PSync bool + P2PSyncTimeout time.Duration + RetryInterval time.Duration + MaxExponent uint64 + BlobServerEndpoint *url.URL } // NewConfigFromCliContext creates a new config instance from @@ -33,11 +33,11 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { } var ( - p2pSyncVerifiedBlocks = c.Bool(flags.P2PSyncVerifiedBlocks.Name) - l2CheckPoint = c.String(flags.CheckPointSyncURL.Name) + p2pSync = c.Bool(flags.P2PSync.Name) + l2CheckPoint = c.String(flags.CheckPointSyncURL.Name) ) - if p2pSyncVerifiedBlocks && len(l2CheckPoint) == 0 { + if p2pSync && len(l2CheckPoint) == 0 { return nil, errors.New("empty L2 check point URL") } @@ -67,10 +67,10 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { JwtSecret: string(jwtSecret), Timeout: timeout, }, - RetryInterval: c.Duration(flags.BackOffRetryInterval.Name), - P2PSyncVerifiedBlocks: p2pSyncVerifiedBlocks, - P2PSyncTimeout: c.Duration(flags.P2PSyncTimeout.Name), - MaxExponent: c.Uint64(flags.MaxExponent.Name), - BlobServerEndpoint: blobServerEndpoint, + RetryInterval: c.Duration(flags.BackOffRetryInterval.Name), + P2PSync: p2pSync, + P2PSyncTimeout: c.Duration(flags.P2PSyncTimeout.Name), + MaxExponent: c.Uint64(flags.MaxExponent.Name), + BlobServerEndpoint: blobServerEndpoint, }, nil } diff --git a/driver/config_test.go b/driver/config_test.go index 79bfd9b17..45cff6805 100644 --- a/driver/config_test.go +++ b/driver/config_test.go @@ -34,7 +34,7 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() { s.Equal(taikoL2, c.TaikoL2Address.String()) s.Equal(120*time.Second, c.P2PSyncTimeout) s.NotEmpty(c.JwtSecret) - s.True(c.P2PSyncVerifiedBlocks) + s.True(c.P2PSync) s.Equal(l2CheckPoint, c.L2CheckPoint) s.Nil(new(Driver).InitFromCli(context.Background(), ctx)) @@ -52,7 +52,7 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() { "--" + flags.JWTSecret.Name, os.Getenv("JWT_SECRET"), "--" + flags.P2PSyncTimeout.Name, "120s", "--" + flags.RPCTimeout.Name, "5s", - "--" + flags.P2PSyncVerifiedBlocks.Name, + "--" + flags.P2PSync.Name, "--" + flags.CheckPointSyncURL.Name, l2CheckPoint, })) } @@ -70,7 +70,7 @@ func (s *DriverTestSuite) TestNewConfigFromCliContextEmptyL2CheckPoint() { s.ErrorContains(app.Run([]string{ "TestNewConfigFromCliContext", "--" + flags.JWTSecret.Name, os.Getenv("JWT_SECRET"), - "--" + flags.P2PSyncVerifiedBlocks.Name, + "--" + flags.P2PSync.Name, "--" + flags.L2WSEndpoint.Name, "", }), "empty L2 check point URL") } @@ -85,7 +85,7 @@ func (s *DriverTestSuite) SetupApp() *cli.App { &cli.StringFlag{Name: flags.TaikoL1Address.Name}, &cli.StringFlag{Name: flags.TaikoL2Address.Name}, &cli.StringFlag{Name: flags.JWTSecret.Name}, - &cli.BoolFlag{Name: flags.P2PSyncVerifiedBlocks.Name}, + &cli.BoolFlag{Name: flags.P2PSync.Name}, &cli.DurationFlag{Name: flags.P2PSyncTimeout.Name}, &cli.DurationFlag{Name: flags.RPCTimeout.Name}, &cli.StringFlag{Name: flags.CheckPointSyncURL.Name}, diff --git a/driver/driver.go b/driver/driver.go index 91bf9e1fa..049b8c252 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -69,7 +69,7 @@ func (d *Driver) InitFromConfig(ctx context.Context, cfg *Config) (err error) { return err } - if cfg.P2PSyncVerifiedBlocks && peers == 0 { + if cfg.P2PSync && peers == 0 { log.Warn("P2P syncing verified blocks enabled, but no connected peer found in L2 execution engine") } @@ -77,7 +77,7 @@ func (d *Driver) InitFromConfig(ctx context.Context, cfg *Config) (err error) { d.ctx, d.rpc, d.state, - cfg.P2PSyncVerifiedBlocks, + cfg.P2PSync, cfg.P2PSyncTimeout, cfg.MaxExponent, cfg.BlobServerEndpoint,