Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fastnode support by trigger el-sync when needed #201

Merged
merged 8 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion op-e2e/actions/l2_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type safeDB interface {

func NewL2Verifier(t Testing, log log.Logger, l1 derive.L1Fetcher, blobsSrc derive.L1BlobsFetcher, plasmaSrc derive.PlasmaInputFetcher, eng L2API, cfg *rollup.Config, syncCfg *sync.Config, safeHeadListener safeDB) *L2Verifier {
metrics := &testutils.TestDerivationMetrics{}
engine := derive.NewEngineController(eng, log, metrics, cfg, syncCfg.SyncMode)
engine := derive.NewEngineController(eng, log, metrics, cfg, syncCfg)
pipeline := derive.NewDerivationPipeline(log, cfg, l1, blobsSrc, plasmaSrc, eng, engine, metrics, syncCfg, safeHeadListener)
pipeline.Reset()

Expand Down
16 changes: 16 additions & 0 deletions op-node/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,20 @@ var (
EnvVars: prefixEnvVars("SAFEDB_PATH"),
Category: OperationsCategory,
}

FastnodeMode = &cli.BoolFlag{
Name: "fastnode",
Usage: "Fastnode has a strong dependency on a specific synchronization mode during synchronization, so please set this flag when running fastnode.",
EnvVars: prefixEnvVars("FASTNODE"),
Value: false,
}

ELTriggerGap = &cli.IntFlag{
Name: "el-trigger.gap",
Usage: "gap to trigger el-sync",
Value: 86400,
EnvVars: prefixEnvVars("EL_TRIGGER_GAP"),
}
/* Deprecated Flags */
L2EngineSyncEnabled = &cli.BoolFlag{
Name: "l2.engine-sync",
Expand Down Expand Up @@ -374,6 +388,8 @@ var optionalFlags = []cli.Flag{
BeaconCheckIgnore,
BeaconFetchAllSidecars,
SyncModeFlag,
FastnodeMode,
ELTriggerGap,
RPCListenAddr,
RPCListenPort,
L1TrustRPC,
Expand Down
41 changes: 23 additions & 18 deletions op-node/rollup/derive/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (
syncStatusFinishedEL // EL sync is done & we should be performing consolidation
)

const DefaultElTriggerGap = 3600
owen-reorg marked this conversation as resolved.
Show resolved Hide resolved

var errNoFCUNeeded = errors.New("no FCU call was needed")

var _ EngineControl = (*EngineController)(nil)
Expand All @@ -45,14 +47,15 @@ type ExecEngine interface {
}

type EngineController struct {
engine ExecEngine // Underlying execution engine RPC
log log.Logger
metrics Metrics
syncMode sync.Mode
syncStatus syncStatusEnum
rollupCfg *rollup.Config
elStart time.Time
clock clock.Clock
engine ExecEngine // Underlying execution engine RPC
log log.Logger
metrics Metrics
syncMode sync.Mode
elTriggerGap int
syncStatus syncStatusEnum
rollupCfg *rollup.Config
elStart time.Time
clock clock.Clock

// Block Head State
unsafeHead eth.L2BlockRef
Expand All @@ -75,20 +78,21 @@ type EngineController struct {
safeAttrs *AttributesWithParent
}

func NewEngineController(engine ExecEngine, log log.Logger, metrics Metrics, rollupCfg *rollup.Config, syncMode sync.Mode) *EngineController {
func NewEngineController(engine ExecEngine, log log.Logger, metrics Metrics, rollupCfg *rollup.Config, syncConfig *sync.Config) *EngineController {
syncStatus := syncStatusCL
if syncMode == sync.ELSync {
if syncConfig.SyncMode == sync.ELSync {
syncStatus = syncStatusWillStartEL
}

return &EngineController{
engine: engine,
log: log,
metrics: metrics,
rollupCfg: rollupCfg,
syncMode: syncMode,
syncStatus: syncStatus,
clock: clock.SystemClock,
engine: engine,
log: log,
metrics: metrics,
rollupCfg: rollupCfg,
syncMode: syncConfig.SyncMode,
elTriggerGap: syncConfig.ELTriggerGap,
syncStatus: syncStatus,
clock: clock.SystemClock,
}
}

Expand Down Expand Up @@ -328,7 +332,8 @@ func (e *EngineController) InsertUnsafePayload(ctx context.Context, envelope *et
if e.syncStatus == syncStatusWillStartEL {
b, err := e.engine.L2BlockRefByLabel(ctx, eth.Finalized)
isTransitionBlock := e.rollupCfg.Genesis.L2.Number != 0 && b.Hash == e.rollupCfg.Genesis.L2.Hash
if errors.Is(err, ethereum.NotFound) || isTransitionBlock {
isGapSyncNeeded := ref.Number-e.UnsafeL2Head().Number > uint64(e.elTriggerGap)
if errors.Is(err, ethereum.NotFound) || isTransitionBlock || isGapSyncNeeded {
e.syncStatus = syncStatusStartedEL
e.log.Info("Starting EL sync")
e.elStart = e.clock.Now()
Expand Down
2 changes: 1 addition & 1 deletion op-node/rollup/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func NewDriver(
sequencerConfDepth := NewConfDepth(driverCfg.SequencerConfDepth, l1State.L1Head, l1)
findL1Origin := NewL1OriginSelector(log, cfg, sequencerConfDepth)
verifConfDepth := NewConfDepth(driverCfg.VerifierConfDepth, l1State.L1Head, l1)
engine := derive.NewEngineController(l2, log, metrics, cfg, syncCfg.SyncMode)
engine := derive.NewEngineController(l2, log, metrics, cfg, syncCfg)
derivationPipeline := derive.NewDerivationPipeline(log, cfg, verifConfDepth, l1Blobs, plasma, l2, engine, metrics, syncCfg, safeHeadListener)
attrBuilder := derive.NewFetchingAttributesBuilder(cfg, l1, l2)
meteredEngine := NewMeteredEngine(cfg, engine, metrics, log) // Only use the metered engine in the sequencer b/c it records sequencing metrics.
Expand Down
2 changes: 2 additions & 0 deletions op-node/rollup/sync/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ type Config struct {
// Note: We probably need to detect the condition that snap sync has not complete when we do a restart prior to running sync-start if we are doing
// snap sync with a genesis finalization data.
SkipSyncStartCheck bool `json:"skip_sync_start_check"`
// gap for trigger el-sync
ELTriggerGap int `json:"el_trigger_gap"`
}
10 changes: 10 additions & 0 deletions op-node/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,19 @@ func NewSyncConfig(ctx *cli.Context, log log.Logger) (*sync.Config, error) {
if err != nil {
return nil, err
}

//fastnode config
elTriggerGap := ctx.Int(flags.ELTriggerGap.Name)
if ctx.Bool(flags.FastnodeMode.Name) {
owen-reorg marked this conversation as resolved.
Show resolved Hide resolved
mode = sync.ELSync
// fastnode needs a smaller gap
elTriggerGap = 120
owen-reorg marked this conversation as resolved.
Show resolved Hide resolved
}

cfg := &sync.Config{
SyncMode: mode,
SkipSyncStartCheck: ctx.Bool(flags.SkipSyncStartCheck.Name),
ELTriggerGap: elTriggerGap,
}
if ctx.Bool(flags.L2EngineSyncEnabled.Name) {
cfg.SyncMode = sync.ELSync
Expand Down
7 changes: 6 additions & 1 deletion op-program/client/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ type Driver struct {
}

func NewDriver(logger log.Logger, cfg *rollup.Config, l1Source derive.L1Fetcher, l1BlobsSource derive.L1BlobsFetcher, l2Source L2Source, targetBlockNum uint64) *Driver {
engine := derive.NewEngineController(l2Source, logger, metrics.NoopMetrics, cfg, sync.CLSync)
engine := derive.NewEngineController(l2Source, logger, metrics.NoopMetrics, cfg,
&sync.Config{
SyncMode: sync.CLSync,
SkipSyncStartCheck: false,
ELTriggerGap: 0,
})
pipeline := derive.NewDerivationPipeline(logger, cfg, l1Source, l1BlobsSource, plasma.Disabled, l2Source, engine, metrics.NoopMetrics, &sync.Config{}, safedb.Disabled)
pipeline.Reset()
return &Driver{
Expand Down
Loading