work

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists = errors.New("entry with same ID already exists")

Functions

This section is empty.

Types

type Block

type Block interface {
	ID() eth.BlockID
	String() string
}

type BuildJob

type BuildJob interface {
	ID() seqtypes.BuildJobID
	Cancel(ctx context.Context) error
	Seal(ctx context.Context) (Block, error)
	String() string
	Close() // cleans up and unregisters the job
}

BuildJob provides access to the building work of a single protocol block. This may include extra access, such as inclusion of individual txs or block-building steps.

type Builder

type Builder interface {
	NewJob(ctx context.Context, opts *seqtypes.BuildOpts) (BuildJob, error)
	String() string
	ID() seqtypes.BuilderID
	io.Closer
}

Builder provides access to block-building work. Different implementations are available, e.g. for local or remote block-building.

type Collection

type Collection interface {
	Builder(id seqtypes.BuilderID) Builder
	Signer(id seqtypes.SignerID) Signer
	Committer(id seqtypes.CommitterID) Committer
	Publisher(id seqtypes.PublisherID) Publisher
	Sequencer(id seqtypes.SequencerID) Sequencer
}

type Committer

type Committer interface {
	String() string
	ID() seqtypes.CommitterID
	io.Closer
	Commit(ctx context.Context, block SignedBlock) error
}

Committer commits to a (signed) block to become canonical. This work is critical: if a block cannot be committed, the block is not safe to continue to work with, as it can be replaced by another block. E.g.: - commit a block to be persisted in the local node. - commit a block to an op-conductor service.

type Ensemble

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

Ensemble is a group of active services to sequence blocks with. Services can only be added to an ensemble, the ensemble is meant to run for the full lifetime of the Go service.

func (*Ensemble) AddBuilder

func (bs *Ensemble) AddBuilder(v Builder) error

AddBuilder adds a builder. Errors if the builder already exists.

func (*Ensemble) AddCommitter

func (bs *Ensemble) AddCommitter(v Committer) error

AddCommitter adds a committer. Errors if the committer already exists.

func (*Ensemble) AddPublisher

func (bs *Ensemble) AddPublisher(v Publisher) error

AddPublisher adds a publisher. Errors if the publisher already exists.

func (*Ensemble) AddSequencer

func (bs *Ensemble) AddSequencer(v Sequencer) error

AddSequencer adds a sequencer. Errors if the sequencer already exists.

func (*Ensemble) AddSigner

func (bs *Ensemble) AddSigner(v Signer) error

AddSigner adds a signer. Errors if the signer already exists.

func (*Ensemble) Builder

func (bs *Ensemble) Builder(id seqtypes.BuilderID) Builder

Builder gets a builder. Nil is returned if the ID is unknown.

func (*Ensemble) Builders

func (bs *Ensemble) Builders() []seqtypes.BuilderID

func (*Ensemble) Close

func (bs *Ensemble) Close() error

func (*Ensemble) Committer

func (bs *Ensemble) Committer(id seqtypes.CommitterID) Committer

Committer gets a committer. Nil is returned if the ID is unknown.

func (*Ensemble) Committers

func (bs *Ensemble) Committers() []seqtypes.CommitterID

func (*Ensemble) Load

func (bs *Ensemble) Load(ctx context.Context) (Starter, error)

Load is a short-cut to skip the config phase, and use an existing group of builders.

func (*Ensemble) Publisher

func (bs *Ensemble) Publisher(id seqtypes.PublisherID) Publisher

Publisher gets a publisher. Nil is returned if the ID is unknown.

func (*Ensemble) Publishers

func (bs *Ensemble) Publishers() []seqtypes.PublisherID

func (*Ensemble) Sequencer

func (bs *Ensemble) Sequencer(id seqtypes.SequencerID) Sequencer

Sequencer gets a sequencer. Nil is returned if the ID is unknown.

func (*Ensemble) Sequencers

func (bs *Ensemble) Sequencers() []seqtypes.SequencerID

func (*Ensemble) Signer

func (bs *Ensemble) Signer(id seqtypes.SignerID) Signer

Signer gets a signer. Nil is returned if the ID is unknown.

func (*Ensemble) Signers

func (bs *Ensemble) Signers() []seqtypes.SignerID

func (*Ensemble) Start

func (bs *Ensemble) Start(ctx context.Context, opts *StartOpts) (*Ensemble, error)

Start is a short-cut to skip the start phase, and use an existing group of builders.

type JobRegistry

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

func NewJobRegistry

func NewJobRegistry() *JobRegistry

func (*JobRegistry) Clear

func (ba *JobRegistry) Clear()

func (*JobRegistry) GetJob

func (ba *JobRegistry) GetJob(id seqtypes.BuildJobID) BuildJob

GetJob returns nil if the job isn't known.

func (*JobRegistry) Len

func (ba *JobRegistry) Len() int

func (*JobRegistry) RegisterJob

func (ba *JobRegistry) RegisterJob(job BuildJob) error

func (*JobRegistry) UnregisterJob

func (ba *JobRegistry) UnregisterJob(id seqtypes.BuildJobID)

type Jobs

type Jobs interface {
	// RegisterJob registers the given block-building job.
	// It may return an error if there already exists a job with the same ID.
	RegisterJob(job BuildJob) error
	// GetJob returns nil if the job isn't known.
	GetJob(id seqtypes.BuildJobID) BuildJob
	// UnregisterJob removes the block-building job from the tracker.
	UnregisterJob(id seqtypes.BuildJobID)
	// Clear unregisters all jobs
	Clear()
	// Len returns the number of registered jobs
	Len() int
}

Jobs tracks block-building jobs by ID, so the jobs can be inspected and updated.

type Loader

type Loader interface {
	Load(ctx context.Context) (Starter, error)
}

Loader loads a configuration, ready to start builders with.

type Publisher

type Publisher interface {
	String() string
	ID() seqtypes.PublisherID
	io.Closer
	Publish(ctx context.Context, block SignedBlock) error
}

Publisher publishes a (signed) block to external actors. Publishing may fail. E.g. publish the block to node(s) for propagation via P2P.

type Sequencer

type Sequencer interface {
	String() string
	ID() seqtypes.SequencerID

	// Close the sequencer. After closing successfully the sequencer is no longer usable.
	Close() error

	// Open starts a next sequencing slot
	Open(ctx context.Context) error

	// BuildJob identifies the current block-building work.
	// This work may be interacted with through the block-building API.
	// This may returns nil if there is no active job.
	BuildJob() BuildJob

	// Seal seals the current ongoing block-building job.
	// Returns an error if there was no block-building job open.
	Seal(ctx context.Context) error

	// Prebuilt inserts a pre-built block, skipping block-building.
	Prebuilt(ctx context.Context, block Block) error

	// Sign the previously built block.
	// Returns seqtypes.ErrAlreadySigned if already signed.
	// Returns an error if the block could not be signed.
	Sign(ctx context.Context) error

	// Commit the previously signed block, this ensures we can persist it before relying on it as canonical block.
	// Returns seqtypes.ErrAlreadyCommitted if already committed.
	// Returns an error if the block failed to commit.
	Commit(ctx context.Context) error

	// Publish the previously committed block.
	// Publishing is not respected by next steps.
	// For harder guarantees, use Commit to ensure the payload is successfully shared before the next phase.
	// Re-publishing is allowed.
	// Returns an error if none was previously successfully committed.
	// Returns an error if publishing fails.
	Publish(ctx context.Context) error

	// Next continues to the next sequencing slot.
	// If the current slot is unfinished, then it will finish the current slot.
	// If the current slot is fresh, it will be built.
	// An error is returned if any step fails. It is safe to re-attempt with Next if so.
	Next(ctx context.Context) error

	// Start starts automatic sequencing, on top of the given chain head.
	// An error is returned if the head of the chain does not match the provided head,
	// as safety measure to prevent reorgs during sequencer rotations.
	// An seqtypes.ErrSequencerAlreadyActive error is returned if the sequencer has already been started.
	Start(ctx context.Context, head common.Hash) error

	// Stop stops automatic sequencing, and returns the block-hash of the last sequenced block.
	// An seqtypes.ErrSequencerInactive error is returned if the sequencer has already been stopped.
	Stop(ctx context.Context) (last common.Hash, err error)

	// Active returns true if the automatic sequencing (see Start and Stop) is actively running.
	Active() bool
}

Sequencer utilizes Builder, Committer, Signer, Publisher to perform all the responsibilities to extend the chain. A Sequencer may internally pipeline work, but does not expose parallel work like a builder does.

type ServiceOpts

type ServiceOpts struct {
	*StartOpts
	Services Collection
}

type SignedBlock

type SignedBlock interface {
	Block
	opsigner.SignedObject
}

type Signer

type Signer interface {
	String() string
	ID() seqtypes.SignerID
	io.Closer
	Sign(ctx context.Context, block Block) (SignedBlock, error)
}

Signer signs a block to be published

type StartOpts

type StartOpts struct {
	Log     log.Logger
	Metrics metrics.Metricer
	Jobs    Jobs
}

type Starter

type Starter interface {
	Start(ctx context.Context, opts *StartOpts) (*Ensemble, error)
}

Starter starts an ensemble from some form of setup.

Directories

Path Synopsis
builders
committers
publishers
sequencers
signers

Jump to

Keyboard shortcuts

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