driver

package
v1.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2024 License: MIT, MIT Imports: 25 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSequencerAlreadyStarted = sequencing.ErrSequencerAlreadyStarted
	ErrSequencerAlreadyStopped = sequencing.ErrSequencerAlreadyStopped
)

aliases to not disrupt op-conductor code

Functions

This section is empty.

Types

type AltDAIface added in v1.9.1

type AltDAIface interface {
	// Notify L1 finalized head so AltDA finality is always behind L1
	Finalize(ref eth.L1BlockRef)
	// Set the engine finalization signal callback
	OnFinalizedHeadSignal(f altda.HeadSignalFn)

	derive.AltDAInputFetcher
}

type AltSync

type AltSync interface {
	// RequestL2Range informs the sync source that the given range of L2 blocks is missing,
	// and should be retrieved from any available alternative syncing source.
	// The start and end of the range are exclusive:
	// the start is the head we already have, the end is the first thing we have queued up.
	// It's the task of the alt-sync mechanism to use this hint to fetch the right payloads.
	// Note that the end and start may not be consistent: in this case the sync method should fetch older history
	//
	// If the end value is zeroed, then the sync-method may determine the end free of choice,
	// e.g. sync till the chain head meets the wallclock time. This functionality is optional:
	// a fixed target to sync towards may be determined by picking up payloads through P2P gossip or other sources.
	//
	// The sync results should be returned back to the driver via the OnUnsafeL2Payload(ctx, payload) method.
	// The latest requested range should always take priority over previous requests.
	// There may be overlaps in requested ranges.
	// An error may be returned if the scheduling fails immediately, e.g. a context timeout.
	RequestL2Range(ctx context.Context, start, end eth.L2BlockRef) error
}

type AttributesHandler added in v1.8.0

type AttributesHandler interface {
	// HasAttributes returns if there are any block attributes to process.
	// HasAttributes is for EngineQueue testing only, and can be removed when attribute processing is fully independent.
	HasAttributes() bool
	// SetAttributes overwrites the set of attributes. This may be nil, to clear what may be processed next.
	SetAttributes(attributes *derive.AttributesWithParent)
	// Proceed runs one attempt of processing attributes, if any.
	// Proceed returns io.EOF if there are no attributes to process.
	Proceed(ctx context.Context) error
}

type CLSync added in v1.7.7

type CLSync interface {
	LowestQueuedUnsafeBlock() eth.L2BlockRef
}

type Config

type Config struct {
	// VerifierConfDepth is the distance to keep from the L1 head when reading L1 data for L2 derivation.
	VerifierConfDepth uint64 `json:"verifier_conf_depth"`

	// SequencerConfDepth is the distance to keep from the L1 head as origin when sequencing new L2 blocks.
	// If this distance is too large, the sequencer may:
	// - not adopt a L1 origin within the allowed time (rollup.Config.MaxSequencerDrift)
	// - not adopt a L1 origin that can be included on L1 within the allowed range (rollup.Config.SeqWindowSize)
	// and thus fail to produce a block with anything more than deposits.
	SequencerConfDepth uint64 `json:"sequencer_conf_depth"`

	// SequencerEnabled is true when the driver should sequence new blocks.
	SequencerEnabled bool `json:"sequencer_enabled"`

	// SequencerStopped is false when the driver should sequence new blocks.
	SequencerStopped bool `json:"sequencer_stopped"`

	// SequencerMaxSafeLag is the maximum number of L2 blocks for restricting the distance between L2 safe and unsafe.
	// Disabled if 0.
	SequencerMaxSafeLag uint64 `json:"sequencer_max_safe_lag"`
}

type DerivationPipeline

type DerivationPipeline interface {
	Reset()
	Step(ctx context.Context, pendingSafeHead eth.L2BlockRef) (*derive.AttributesWithParent, error)
	Origin() eth.L1BlockRef
	DerivationReady() bool
	ConfirmEngineReset()
}

type Drain added in v1.9.3

type Drain interface {
	Drain() error
}

type Driver

type Driver struct {
	*SyncDeriver
	// contains filtered or unexported fields
}

func NewDriver

func NewDriver(
	sys event.Registry,
	drain Drain,
	driverCfg *Config,
	cfg *rollup.Config,
	l2 L2Chain,
	l1 L1Chain,
	supervisor interop.InteropBackend,
	l1Blobs derive.L1BlobsFetcher,
	altSync AltSync,
	network Network,
	log log.Logger,
	metrics Metrics,
	sequencerStateListener sequencing.SequencerStateListener,
	safeHeadListener rollup.SafeHeadListener,
	syncCfg *sync.Config,
	sequencerConductor conductor.SequencerConductor,
	altDA AltDAIface,
) *Driver

NewDriver composes an events handler that tracks L1 state, triggers L2 Derivation, and optionally sequences new L2 blocks.

func (*Driver) BlockRefWithStatus

func (s *Driver) BlockRefWithStatus(ctx context.Context, num uint64) (eth.L2BlockRef, *eth.SyncStatus, error)

BlockRefWithStatus blocks the driver event loop and captures the syncing status, along with an L2 block reference by number consistent with that same status. If the event loop is too busy and the context expires, a context error is returned.

func (*Driver) Close

func (s *Driver) Close() error

func (*Driver) OnL1Finalized

func (s *Driver) OnL1Finalized(ctx context.Context, finalized eth.L1BlockRef) error

func (*Driver) OnL1Head

func (s *Driver) OnL1Head(ctx context.Context, unsafe eth.L1BlockRef) error

OnL1Head signals the driver that the L1 chain changed the "unsafe" block, also known as head of the chain, or "latest".

func (*Driver) OnL1Safe

func (s *Driver) OnL1Safe(ctx context.Context, safe eth.L1BlockRef) error

OnL1Safe signals the driver that the L1 chain changed the "safe", also known as the justified checkpoint (as seen on L1 beacon-chain).

func (*Driver) OnUnsafeL2Payload

func (s *Driver) OnUnsafeL2Payload(ctx context.Context, envelope *eth.ExecutionPayloadEnvelope) error

func (*Driver) OverrideLeader added in v1.8.0

func (s *Driver) OverrideLeader(ctx context.Context) error

func (*Driver) ResetDerivationPipeline

func (s *Driver) ResetDerivationPipeline(ctx context.Context) error

ResetDerivationPipeline forces a reset of the derivation pipeline. It waits for the reset to occur. It simply unblocks the caller rather than fully cancelling the reset request upon a context cancellation.

func (*Driver) SequencerActive added in v1.1.2

func (s *Driver) SequencerActive(ctx context.Context) (bool, error)

func (*Driver) Start

func (s *Driver) Start() error

Start starts up the state loop. The loop will have been started iff err is not nil.

func (*Driver) StartSequencer

func (s *Driver) StartSequencer(ctx context.Context, blockHash common.Hash) error

func (*Driver) StopSequencer

func (s *Driver) StopSequencer(ctx context.Context) (common.Hash, error)

func (*Driver) SyncStatus

func (s *Driver) SyncStatus(ctx context.Context) (*eth.SyncStatus, error)

SyncStatus blocks the driver event loop and captures the syncing status.

type EngineController added in v1.8.0

type EngineController interface {
	engine.LocalEngineControl
	IsEngineSyncing() bool
	InsertUnsafePayload(ctx context.Context, payload *eth.ExecutionPayloadEnvelope, ref eth.L2BlockRef) error
	TryUpdateEngine(ctx context.Context) error
	TryBackupUnsafeReorg(ctx context.Context) (bool, error)
}

type Finalizer added in v1.7.7

type Finalizer interface {
	FinalizedL1() eth.L1BlockRef
	event.Deriver
}

type L1Chain

type L1Chain interface {
	derive.L1Fetcher
	L1BlockRefByLabel(context.Context, eth.BlockLabel) (eth.L1BlockRef, error)
}

type L1FetcherMetrics added in v1.0.8

type L1FetcherMetrics interface {
	RecordL1RequestTime(method string, duration time.Duration)
}

type L2Chain

type L2Chain interface {
	engine.Engine
	L2BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L2BlockRef, error)
	L2BlockRefByHash(ctx context.Context, l2Hash common.Hash) (eth.L2BlockRef, error)
	L2BlockRefByNumber(ctx context.Context, num uint64) (eth.L2BlockRef, error)
}

type MeteredL1Fetcher added in v1.0.8

type MeteredL1Fetcher struct {
	// contains filtered or unexported fields
}

func NewMeteredL1Fetcher added in v1.0.8

func NewMeteredL1Fetcher(inner derive.L1Fetcher, metrics L1FetcherMetrics) *MeteredL1Fetcher

func (*MeteredL1Fetcher) FetchReceipts added in v1.0.8

func (m *MeteredL1Fetcher) FetchReceipts(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, types.Receipts, error)

func (*MeteredL1Fetcher) InfoAndTxsByHash added in v1.0.8

func (m *MeteredL1Fetcher) InfoAndTxsByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, types.Transactions, error)

func (*MeteredL1Fetcher) InfoByHash added in v1.0.8

func (m *MeteredL1Fetcher) InfoByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, error)

func (*MeteredL1Fetcher) L1BlockRefByHash added in v1.0.8

func (m *MeteredL1Fetcher) L1BlockRefByHash(ctx context.Context, hash common.Hash) (eth.L1BlockRef, error)

func (*MeteredL1Fetcher) L1BlockRefByLabel added in v1.0.8

func (m *MeteredL1Fetcher) L1BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L1BlockRef, error)

func (*MeteredL1Fetcher) L1BlockRefByNumber added in v1.0.8

func (m *MeteredL1Fetcher) L1BlockRefByNumber(ctx context.Context, num uint64) (eth.L1BlockRef, error)

type Metrics

type Metrics interface {
	RecordPipelineReset()
	RecordPublishingError()
	RecordDerivationError()

	RecordReceivedUnsafePayload(payload *eth.ExecutionPayloadEnvelope)

	RecordL1Ref(name string, ref eth.L1BlockRef)
	RecordL2Ref(name string, ref eth.L2BlockRef)
	RecordChannelInputBytes(inputCompressedBytes int)
	RecordHeadChannelOpened()
	RecordChannelTimedOut()
	RecordFrame()

	RecordDerivedBatches(batchType string)

	RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID)

	SetDerivationIdle(idle bool)

	RecordL1ReorgDepth(d uint64)

	engine.Metrics
	L1FetcherMetrics
	event.Metrics
	sequencing.Metrics
}

type Network

type Network interface {
	// PublishL2Payload is called by the driver whenever there is a new payload to publish, synchronously with the driver main loop.
	PublishL2Payload(ctx context.Context, payload *eth.ExecutionPayloadEnvelope) error
}

type ResetStepBackoffEvent added in v1.8.0

type ResetStepBackoffEvent struct {
}

func (ResetStepBackoffEvent) String added in v1.8.0

func (ev ResetStepBackoffEvent) String() string

type SequencerStateListener added in v1.1.2

type SequencerStateListener interface {
	SequencerStarted() error
	SequencerStopped() error
}

type StepAttemptEvent added in v1.8.0

type StepAttemptEvent struct{}

func (StepAttemptEvent) String added in v1.8.0

func (ev StepAttemptEvent) String() string

type StepDelayedReqEvent added in v1.8.0

type StepDelayedReqEvent struct {
	Delay time.Duration
}

func (StepDelayedReqEvent) String added in v1.8.0

func (ev StepDelayedReqEvent) String() string

type StepEvent added in v1.8.0

type StepEvent struct{}

func (StepEvent) String added in v1.8.0

func (ev StepEvent) String() string

type StepReqEvent added in v1.8.0

type StepReqEvent struct {
	ResetBackoff bool
}

func (StepReqEvent) String added in v1.8.0

func (ev StepReqEvent) String() string

type StepSchedulingDeriver added in v1.8.0

type StepSchedulingDeriver struct {
	// contains filtered or unexported fields
}

StepSchedulingDeriver is a deriver that emits StepEvent events. The deriver can be requested to schedule a step with a StepReqEvent.

It is then up to the caller to translate scheduling into StepAttemptEvent emissions, by waiting for NextStep or NextDelayedStep channels (nil if there is nothing to wait for, for channel-merging purposes).

Upon StepAttemptEvent the scheduler will then emit a StepEvent, while maintaining backoff state, to not spam steps.

Backoff can be reset by sending a request with StepReqEvent.ResetBackoff set to true, or by sending a ResetStepBackoffEvent.

func NewStepSchedulingDeriver added in v1.8.0

func NewStepSchedulingDeriver(log log.Logger) *StepSchedulingDeriver

func (*StepSchedulingDeriver) AttachEmitter added in v1.8.0

func (s *StepSchedulingDeriver) AttachEmitter(em event.Emitter)

func (*StepSchedulingDeriver) NextDelayedStep added in v1.8.0

func (s *StepSchedulingDeriver) NextDelayedStep() <-chan time.Time

NextDelayedStep is a temporary channel to await, and if triggered, the caller should emit a StepAttemptEvent to queue up a step while maintaining backoff. The returned channel may be nil, if there is no requested step with delay scheduled.

func (*StepSchedulingDeriver) NextStep added in v1.8.0

func (s *StepSchedulingDeriver) NextStep() <-chan struct{}

NextStep is a channel to await, and if triggered, the caller should emit a StepAttemptEvent to queue up a step while maintaining backoff.

func (*StepSchedulingDeriver) OnEvent added in v1.8.0

func (s *StepSchedulingDeriver) OnEvent(ev event.Event) bool

type SyncDeriver added in v1.8.0

type SyncDeriver struct {
	// The derivation pipeline is reset whenever we reorg.
	// The derivation pipeline determines the new l2Safe.
	Derivation DerivationPipeline

	SafeHeadNotifs rollup.SafeHeadListener // notified when safe head is updated

	CLSync CLSync

	// The engine controller is used by the sequencer & Derivation components.
	// We will also use it for EL sync in a future PR.
	Engine EngineController

	// Sync Mod Config
	SyncCfg *sync.Config

	Config *rollup.Config

	L1 L1Chain
	L2 L2Chain

	Emitter event.Emitter

	Log log.Logger

	Ctx context.Context

	Drain func() error
}

func (*SyncDeriver) AttachEmitter added in v1.8.0

func (s *SyncDeriver) AttachEmitter(em event.Emitter)

func (*SyncDeriver) OnEvent added in v1.8.0

func (s *SyncDeriver) OnEvent(ev event.Event) bool

func (*SyncDeriver) SyncStep added in v1.8.0

func (s *SyncDeriver) SyncStep()

SyncStep performs the sequence of encapsulated syncing steps. Warning: this sequence will be broken apart as outlined in op-node derivers design doc.

type SyncStatus deprecated

type SyncStatus = eth.SyncStatus

Deprecated: use eth.SyncStatus instead.

type SyncStatusTracker added in v1.8.0

type SyncStatusTracker interface {
	event.Deriver
	SyncStatus() *eth.SyncStatus
	L1Head() eth.L1BlockRef
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL