Skip to content

Commit

Permalink
feat(taiko-client): make p2p-sync required (#18571)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 authored Dec 17, 2024
1 parent e846f62 commit de92b28
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 34 deletions.
10 changes: 1 addition & 9 deletions packages/taiko-client/cmd/flags/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ import (

// Optional flags used by driver.
var (
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",
Value: false,
Category: driverCategory,
EnvVars: []string{"P2P_SYNC"},
}
P2PSyncTimeout = &cli.DurationFlag{
Name: "p2p.syncTimeout",
Usage: "P2P syncing timeout, if no sync progress is made within this time span, " +
Expand All @@ -27,6 +19,7 @@ var (
CheckPointSyncURL = &cli.StringFlag{
Name: "p2p.checkPointSyncUrl",
Usage: "HTTP RPC endpoint of another synced L2 execution engine node",
Required: true,
Category: driverCategory,
EnvVars: []string{"P2P_CHECK_POINT_SYNC_URL"},
}
Expand Down Expand Up @@ -60,7 +53,6 @@ var DriverFlags = MergeFlags(CommonFlags, []cli.Flag{
L2WSEndpoint,
L2AuthEndpoint,
JWTSecret,
P2PSync,
P2PSyncTimeout,
CheckPointSyncURL,
MaxExponent,
Expand Down
16 changes: 4 additions & 12 deletions packages/taiko-client/driver/chain_syncer/chain_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,13 @@ type L2ChainSyncer struct {

// Sync mode
syncMode string

// If this flag is activated, will try P2P beacon sync if current node is behind of the protocol's
// the latest verified block head
p2pSync bool
}

// New creates a new chain syncer instance.
func New(
ctx context.Context,
rpc *rpc.Client,
state *state.State,
p2pSync bool,
p2pSyncTimeout time.Duration,
maxRetrieveExponent uint64,
blobServerEndpoint *url.URL,
Expand Down Expand Up @@ -78,7 +73,6 @@ func New(
blobSyncer: blobSyncer,
progressTracker: tracker,
syncMode: syncMode,
p2pSync: p2pSync,
}, nil
}

Expand All @@ -104,7 +98,6 @@ func (s *L2ChainSyncer) Sync() error {
if s.progressTracker.Triggered() {
log.Info(
"Switch to insert pending blocks one by one",
"p2pEnabled", s.p2pSync,
"p2pOutOfSync", s.progressTracker.OutOfSync(),
)

Expand Down Expand Up @@ -170,13 +163,12 @@ func (s *L2ChainSyncer) AheadOfHeadToSync(heightToSync uint64) bool {

// needNewBeaconSyncTriggered checks whether the current L2 execution engine needs to trigger
// another new beacon sync, the following conditions should be met:
// 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 has met a sync timeout issue.
// 1. The protocol's latest verified block head is not zero.
// 2. The L2 execution engine's chain is behind of the protocol's latest verified block head.
// 3. The L2 execution engine's chain has 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.p2pSync || s.progressTracker.Finished() {
if s.progressTracker.Finished() {
return 0, false, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (s *ChainSyncerTestSuite) SetupTest() {
context.Background(),
s.RPCClient,
state,
false,
1*time.Hour,
0,
nil,
Expand Down
9 changes: 3 additions & 6 deletions packages/taiko-client/driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
// Config contains the configurations to initialize a Taiko driver.
type Config struct {
*rpc.ClientConfig
P2PSync bool
P2PSyncTimeout time.Duration
RetryInterval time.Duration
MaxExponent uint64
Expand All @@ -34,11 +33,10 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
}

var (
p2pSync = c.Bool(flags.P2PSync.Name)
l2CheckPoint = c.String(flags.CheckPointSyncURL.Name)
)

if p2pSync && len(l2CheckPoint) == 0 {
if len(l2CheckPoint) == 0 {
return nil, errors.New("empty L2 check point URL")
}

Expand All @@ -65,8 +63,8 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
}
}

if beaconEndpoint == "" && blobServerEndpoint == nil && socialScanEndpoint == nil {
return nil, errors.New("empty L1 beacon endpoint, blob server and Social Scan endpoint")
if beaconEndpoint == "" {
return nil, errors.New("empty L1 beacon endpoint")
}

var timeout = c.Duration(flags.RPCTimeout.Name)
Expand All @@ -83,7 +81,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
Timeout: timeout,
},
RetryInterval: c.Duration(flags.BackOffRetryInterval.Name),
P2PSync: p2pSync,
P2PSyncTimeout: c.Duration(flags.P2PSyncTimeout.Name),
MaxExponent: c.Uint64(flags.MaxExponent.Name),
BlobServerEndpoint: blobServerEndpoint,
Expand Down
4 changes: 0 additions & 4 deletions packages/taiko-client/driver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() {
s.Equal(taikoL2, c.TaikoL2Address.String())
s.Equal(120*time.Second, c.P2PSyncTimeout)
s.NotEmpty(c.JwtSecret)
s.True(c.P2PSync)
s.Equal(l2CheckPoint, c.L2CheckPoint)
s.Nil(new(Driver).InitFromCli(context.Background(), ctx))

Expand All @@ -52,7 +51,6 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() {
"--" + flags.JWTSecret.Name, os.Getenv("JWT_SECRET"),
"--" + flags.P2PSyncTimeout.Name, "120s",
"--" + flags.RPCTimeout.Name, "5s",
"--" + flags.P2PSync.Name,
"--" + flags.CheckPointSyncURL.Name, l2CheckPoint,
}))
}
Expand All @@ -70,7 +68,6 @@ func (s *DriverTestSuite) TestNewConfigFromCliContextEmptyL2CheckPoint() {
s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"--" + flags.JWTSecret.Name, os.Getenv("JWT_SECRET"),
"--" + flags.P2PSync.Name,
"--" + flags.L2WSEndpoint.Name, "",
}), "empty L2 check point URL")
}
Expand All @@ -85,7 +82,6 @@ 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.P2PSync.Name},
&cli.DurationFlag{Name: flags.P2PSyncTimeout.Name},
&cli.DurationFlag{Name: flags.RPCTimeout.Name},
&cli.StringFlag{Name: flags.CheckPointSyncURL.Name},
Expand Down
3 changes: 1 addition & 2 deletions packages/taiko-client/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,14 @@ func (d *Driver) InitFromConfig(ctx context.Context, cfg *Config) (err error) {
return err
}

if cfg.P2PSync && peers == 0 {
if 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.P2PSync,
cfg.P2PSyncTimeout,
cfg.MaxExponent,
cfg.BlobServerEndpoint,
Expand Down

0 comments on commit de92b28

Please sign in to comment.