Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(driver): rename some variables (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed May 1, 2024
1 parent 683e976 commit 3fac9ad
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cmd/flags/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -54,7 +54,7 @@ var DriverFlags = MergeFlags(CommonFlags, []cli.Flag{
L2WSEndpoint,
L2AuthEndpoint,
JWTSecret,
P2PSyncVerifiedBlocks,
P2PSync,
P2PSyncTimeout,
CheckPointSyncURL,
MaxExponent,
Expand Down
28 changes: 14 additions & 14 deletions driver/chain_syncer/chain_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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.
func New(
ctx context.Context,
rpc *rpc.Client,
state *state.State,
p2pSyncVerifiedBlocks bool,
p2pSync bool,
p2pSyncTimeout time.Duration,
maxRetrieveExponent uint64,
blobServerEndpoint *url.URL,
Expand All @@ -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
}

Expand All @@ -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 {
Expand All @@ -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(),
)

Expand Down Expand Up @@ -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
}

Expand Down
26 changes: 13 additions & 13 deletions driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}

Expand Down Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions driver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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,
}))
}
Expand All @@ -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")
}
Expand All @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ 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")
}

if d.l2ChainSyncer, err = chainSyncer.New(
d.ctx,
d.rpc,
d.state,
cfg.P2PSyncVerifiedBlocks,
cfg.P2PSync,
cfg.P2PSyncTimeout,
cfg.MaxExponent,
cfg.BlobServerEndpoint,
Expand Down

0 comments on commit 3fac9ad

Please sign in to comment.