driver

package
v0.10.14 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 16 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConfDepth

func NewConfDepth(depth uint64, l1Head func() eth.L1BlockRef, fetcher derive.L1Fetcher) *confDepth

Types

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"`
}

type DerivationPipeline

type DerivationPipeline interface {
	Reset()
	Step(ctx context.Context) error
	AddUnsafePayload(payload *eth.ExecutionPayload)
	Finalize(ref eth.L1BlockRef)
	FinalizedL1() eth.L1BlockRef
	Finalized() eth.L2BlockRef
	SafeL2Head() eth.L2BlockRef
	UnsafeL2Head() eth.L2BlockRef
	Origin() eth.L1BlockRef
}

type Downloader

type Downloader interface {
	InfoByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, error)
	FetchReceipts(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, types.Receipts, error)
}

type Driver

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

func NewDriver

func NewDriver(driverCfg *Config, cfg *rollup.Config, l2 L2Chain, l1 L1Chain, network Network, log log.Logger, snapshotLog log.Logger, metrics Metrics) *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, payload *eth.ExecutionPayload) 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) 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 added in v0.10.11

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

func (*Driver) StopSequencer added in v0.10.11

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. If the event loop is too busy and the context expires, a context error is returned.

type EngineMetrics added in v0.10.12

type EngineMetrics interface {
	RecordSequencingError()
	CountSequencedTxs(count int)

	RecordSequencerBuildingDiffTime(duration time.Duration)
	RecordSequencerSealingTime(duration time.Duration)
}

type L1Chain

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

type L1Metrics

type L1Metrics interface {
	RecordL1ReorgDepth(d uint64)
	RecordL1Ref(name string, ref eth.L1BlockRef)
}

type L1OriginSelector

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

func NewL1OriginSelector

func NewL1OriginSelector(log log.Logger, cfg *rollup.Config, l1 L1Blocks) *L1OriginSelector

func (*L1OriginSelector) FindL1Origin

func (los *L1OriginSelector) FindL1Origin(ctx context.Context, l2Head eth.L2BlockRef) (eth.L1BlockRef, error)

FindL1Origin determines what the next L1 Origin should be. The L1 Origin is either the L2 Head's Origin, or the following L1 block if the next L2 block's time is greater than or equal to the L2 Head's Origin.

type L1OriginSelectorIface

type L1OriginSelectorIface interface {
	FindL1Origin(ctx context.Context, l2Head eth.L2BlockRef) (eth.L1BlockRef, error)
}

type L1State

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

L1State tracks L1 head, safe and finalized blocks. It is not safe to write and read concurrently.

func NewL1State

func NewL1State(log log.Logger, metrics L1Metrics) *L1State

func (*L1State) HandleNewL1FinalizedBlock

func (s *L1State) HandleNewL1FinalizedBlock(finalized eth.L1BlockRef)

func (*L1State) HandleNewL1HeadBlock

func (s *L1State) HandleNewL1HeadBlock(head eth.L1BlockRef)

func (*L1State) HandleNewL1SafeBlock

func (s *L1State) HandleNewL1SafeBlock(safe eth.L1BlockRef)

func (*L1State) L1Finalized

func (s *L1State) L1Finalized() eth.L1BlockRef

L1Finalized returns either the stored L1 finalized block or an empty block reference if the L1 finalized block has not been initialized yet.

func (*L1State) L1Head

func (s *L1State) L1Head() eth.L1BlockRef

L1Head returns either the stored L1 head or an empty block reference if the L1 Head has not been initialized yet.

func (*L1State) L1Safe

func (s *L1State) L1Safe() eth.L1BlockRef

L1Safe returns either the stored L1 safe block or an empty block reference if the L1 safe block has not been initialized yet.

type L1StateIface

type L1StateIface interface {
	HandleNewL1HeadBlock(head eth.L1BlockRef)
	HandleNewL1SafeBlock(safe eth.L1BlockRef)
	HandleNewL1FinalizedBlock(finalized eth.L1BlockRef)

	L1Head() eth.L1BlockRef
	L1Safe() eth.L1BlockRef
	L1Finalized() eth.L1BlockRef
}

type L2Chain

type L2Chain interface {
	derive.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 MeteredEngine added in v0.10.12

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

MeteredEngine wraps an EngineControl and adds metrics such as block building time diff and sealing time

func NewMeteredEngine added in v0.10.12

func NewMeteredEngine(cfg *rollup.Config, inner derive.EngineControl, metrics EngineMetrics, log log.Logger) *MeteredEngine

func (*MeteredEngine) BuildingPayload added in v0.10.12

func (m *MeteredEngine) BuildingPayload() (onto eth.L2BlockRef, id eth.PayloadID, safe bool)

func (*MeteredEngine) CancelPayload added in v0.10.12

func (m *MeteredEngine) CancelPayload(ctx context.Context, force bool) error

func (*MeteredEngine) ConfirmPayload added in v0.10.12

func (m *MeteredEngine) ConfirmPayload(ctx context.Context) (out *eth.ExecutionPayload, errTyp derive.BlockInsertionErrType, err error)

func (*MeteredEngine) Finalized added in v0.10.12

func (m *MeteredEngine) Finalized() eth.L2BlockRef

func (*MeteredEngine) SafeL2Head added in v0.10.12

func (m *MeteredEngine) SafeL2Head() eth.L2BlockRef

func (*MeteredEngine) StartPayload added in v0.10.12

func (m *MeteredEngine) StartPayload(ctx context.Context, parent eth.L2BlockRef, attrs *eth.PayloadAttributes, updateSafe bool) (errType derive.BlockInsertionErrType, err error)

func (*MeteredEngine) UnsafeL2Head added in v0.10.12

func (m *MeteredEngine) UnsafeL2Head() eth.L2BlockRef

type Metrics

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

	RecordReceivedUnsafePayload(payload *eth.ExecutionPayload)

	RecordL1Ref(name string, ref eth.L1BlockRef)
	RecordL2Ref(name string, ref eth.L2BlockRef)

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

	SetDerivationIdle(idle bool)

	RecordL1ReorgDepth(d uint64)

	EngineMetrics
}

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.ExecutionPayload) error
}

type Sequencer

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

Sequencer implements the sequencing interface of the driver: it starts and completes block building jobs.

func NewSequencer

func NewSequencer(log log.Logger, cfg *rollup.Config, engine derive.EngineControl, attributesBuilder derive.AttributesBuilder, l1OriginSelector L1OriginSelectorIface) *Sequencer

func (*Sequencer) BuildingOnto added in v0.10.12

func (d *Sequencer) BuildingOnto() eth.L2BlockRef

BuildingOnto returns the L2 head reference that the latest block is or was being built on top of.

func (*Sequencer) CancelBuildingBlock added in v0.10.12

func (d *Sequencer) CancelBuildingBlock(ctx context.Context)

CancelBuildingBlock cancels the current open block building job. This sequencer only maintains one block building job at a time.

func (*Sequencer) CompleteBuildingBlock

func (d *Sequencer) CompleteBuildingBlock(ctx context.Context) (*eth.ExecutionPayload, error)

CompleteBuildingBlock takes the current block that is being built, and asks the engine to complete the building, seal the block, and persist it as canonical. Warning: the safe and finalized L2 blocks as viewed during the initiation of the block building are reused for completion of the block building. The Execution engine should not change the safe and finalized blocks between start and completion of block building.

func (*Sequencer) PlanNextSequencerAction added in v0.10.4

func (d *Sequencer) PlanNextSequencerAction() time.Duration

PlanNextSequencerAction returns a desired delay till the RunNextSequencerAction call.

func (*Sequencer) RunNextSequencerAction added in v0.10.12

func (d *Sequencer) RunNextSequencerAction(ctx context.Context) *eth.ExecutionPayload

RunNextSequencerAction starts new block building work, or seals existing work, and is best timed by first awaiting the delay returned by PlanNextSequencerAction. If a new block is successfully sealed, it will be returned for publishing, nil otherwise.

func (*Sequencer) StartBuildingBlock

func (d *Sequencer) StartBuildingBlock(ctx context.Context) error

StartBuildingBlock initiates a block building job on top of the given L2 head, safe and finalized blocks, and using the provided l1Origin.

type SequencerIface

type SequencerIface interface {
	StartBuildingBlock(ctx context.Context) error
	CompleteBuildingBlock(ctx context.Context) (*eth.ExecutionPayload, error)
	PlanNextSequencerAction() time.Duration
	RunNextSequencerAction(ctx context.Context) *eth.ExecutionPayload
	BuildingOnto() eth.L2BlockRef
}

type SyncStatus deprecated

type SyncStatus = eth.SyncStatus

Deprecated: use eth.SyncStatus instead.

Jump to

Keyboard shortcuts

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