block

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: Apache-2.0 Imports: 38 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DAModeRetry   = "retry"
	DAModeSuccess = "success"
	DAModeFail    = "fail"
)

DA metric modes

View Source
const DefaultInterval = 1 * time.Second
View Source
const LastSubmittedDataHeightKey = "last-submitted-data-height"

LastSubmittedDataHeightKey is the key used for persisting the last submitted data height in store.

View Source
const (
	// MetricsSubsystem is a subsystem shared by all metrics exposed by this
	// package.
	MetricsSubsystem = "sequencer"
)

Variables

View Source
var (
	// ErrNoValidatorsInState is used when no validators/proposers are found in state
	ErrNoValidatorsInState = errors.New("no validators found in state")

	// ErrNotProposer is used when the manager is not a proposer
	ErrNotProposer = errors.New("not a proposer")

	// ErrNoBatch indicate no batch is available for creating block
	ErrNoBatch = errors.New("no batch to process")

	// ErrHeightFromFutureStr is the error message for height from future returned by da
	ErrHeightFromFutureStr = errors.New("given height is from the future")
)

These errors are used by Manager.

Functions

func GenerateHeaderHash

func GenerateHeaderHash(t *testing.T, height uint64, proposer []byte) []byte

GenerateHeaderHash creates a deterministic hash for a test header based on height and proposer. This is useful for predicting expected hashes in tests without needing full header construction.

Types

type BatchData

type BatchData struct {
	*coresequencer.Batch
	time.Time
	Data [][]byte
}

BatchData is used to pass batch, time and data (da.IDs) to BatchQueue

type Manager

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

Manager is responsible for aggregating transactions into blocks.

func NewManager

func NewManager(
	ctx context.Context,
	signer signer.Signer,
	config config.Config,
	genesis genesis.Genesis,
	store storepkg.Store,
	exec coreexecutor.Executor,
	sequencer coresequencer.Sequencer,
	da coreda.DA,
	logger logging.EventLogger,
	headerStore goheader.Store[*types.SignedHeader],
	dataStore goheader.Store[*types.Data],
	headerBroadcaster broadcaster[*types.SignedHeader],
	dataBroadcaster broadcaster[*types.Data],
	seqMetrics *Metrics,
	gasPrice float64,
	gasMultiplier float64,
	managerOpts ManagerOptions,
) (*Manager, error)

NewManager creates new block Manager.

func (*Manager) AggregationLoop

func (m *Manager) AggregationLoop(ctx context.Context, errCh chan<- error)

AggregationLoop is responsible for aggregating transactions into blocks.

func (*Manager) DAIncluderLoop

func (m *Manager) DAIncluderLoop(ctx context.Context, errCh chan<- error)

DAIncluderLoop is responsible for advancing the DAIncludedHeight by checking if blocks after the current height have both their header and data marked as DA-included in the caches. If so, it calls setDAIncludedHeight.

func (*Manager) DataCache

func (m *Manager) DataCache() *cache.Cache[types.Data]

DataCache returns the dataCache used by the manager.

func (*Manager) DataStoreRetrieveLoop added in v0.14.0

func (m *Manager) DataStoreRetrieveLoop(ctx context.Context)

DataStoreRetrieveLoop is responsible for retrieving data from the Data Store.

func (*Manager) DataSubmissionLoop

func (m *Manager) DataSubmissionLoop(ctx context.Context)

DataSubmissionLoop is responsible for submitting data to the DA layer.

func (*Manager) GetDAIncludedHeight added in v0.13.7

func (m *Manager) GetDAIncludedHeight() uint64

GetDAIncludedHeight returns the height at which all blocks have been included in the DA

func (*Manager) GetExecutor

func (m *Manager) GetExecutor() coreexecutor.Executor

GetExecutor returns the executor used by the manager.

Note: this is a temporary method to allow testing the manager. It will be removed once the manager is fully integrated with the execution client. TODO(tac0turtle): remove

func (*Manager) GetLastState

func (m *Manager) GetLastState() types.State

GetLastState returns the last recorded state.

func (*Manager) GetStoreHeight added in v0.10.2

func (m *Manager) GetStoreHeight(ctx context.Context) (uint64, error)

GetStoreHeight returns the manager's store height

func (*Manager) HeaderCache

func (m *Manager) HeaderCache() *cache.Cache[types.SignedHeader]

HeaderCache returns the headerCache used by the manager.

func (*Manager) HeaderStoreRetrieveLoop added in v0.14.0

func (m *Manager) HeaderStoreRetrieveLoop(ctx context.Context)

HeaderStoreRetrieveLoop is responsible for retrieving headers from the Header Store.

func (*Manager) HeaderSubmissionLoop added in v0.14.0

func (m *Manager) HeaderSubmissionLoop(ctx context.Context)

HeaderSubmissionLoop is responsible for submitting headers to the DA layer.

func (*Manager) IsBlockHashSeen added in v0.11.8

func (m *Manager) IsBlockHashSeen(blockHash string) bool

IsBlockHashSeen returns true if the block with the given hash has been seen.

func (*Manager) IsDAIncluded added in v0.10.7

func (m *Manager) IsDAIncluded(ctx context.Context, height uint64) (bool, error)

IsDAIncluded returns true if the block with the given hash has been seen on DA. TODO(tac0turtle): should we use this for pending header system to verify how far ahead a chain is?

func (*Manager) LoadCache

func (m *Manager) LoadCache() error

LoadCache loads the header and data caches from disk.

func (*Manager) NotifyNewTransactions

func (m *Manager) NotifyNewTransactions()

NotifyNewTransactions signals that new transactions are available for processing This method will be called by the Reaper when it receives new transactions

func (*Manager) PendingHeaders

func (m *Manager) PendingHeaders() *PendingHeaders

PendingHeaders returns the pending headers.

func (*Manager) RetrieveLoop

func (m *Manager) RetrieveLoop(ctx context.Context)

RetrieveLoop is responsible for interacting with DA layer.

func (*Manager) SaveCache

func (m *Manager) SaveCache() error

SaveCache saves the header and data caches to disk.

func (*Manager) SeqClient

func (m *Manager) SeqClient() coresequencer.Sequencer

SeqClient returns the grpc sequencing client.

func (*Manager) SetLastState added in v0.11.8

func (m *Manager) SetLastState(state types.State)

SetLastState is used to set lastState used by Manager.

func (*Manager) SetRollkitHeightToDAHeight

func (m *Manager) SetRollkitHeightToDAHeight(ctx context.Context, height uint64) error

SetRollkitHeightToDAHeight stores the mapping from a Rollkit block height to the corresponding DA (Data Availability) layer heights where the block's header and data were included. This mapping is persisted in the store metadata and is used to track which DA heights contain the block components for a given Rollkit height.

For blocks with empty transactions, both header and data use the same DA height since empty transaction data is not actually published to the DA layer.

func (*Manager) SyncLoop

func (m *Manager) SyncLoop(ctx context.Context, errCh chan<- error)

SyncLoop is responsible for syncing blocks.

SyncLoop processes headers gossiped in P2P network to know what's the latest block height, block data is retrieved from DA layer.

func (*Manager) Validate

func (m *Manager) Validate(ctx context.Context, header *types.SignedHeader, data *types.Data) error

type ManagerOptions

type ManagerOptions struct {
	SignaturePayloadProvider types.SignaturePayloadProvider
	ValidatorHasherProvider  types.ValidatorHasherProvider
}

ManagerOptions defines the options for creating a new block Manager.

func DefaultManagerOptions

func DefaultManagerOptions() ManagerOptions

DefaultManagerOptions returns the default options for creating a new block Manager.

func (*ManagerOptions) Validate

func (opts *ManagerOptions) Validate() error

type Metrics added in v0.11.19

type Metrics struct {
	// Original metrics
	Height          metrics.Gauge // Height of the chain
	NumTxs          metrics.Gauge // Number of transactions in the latest block
	BlockSizeBytes  metrics.Gauge // Size of the latest block
	TotalTxs        metrics.Gauge // Total number of transactions
	CommittedHeight metrics.Gauge `metrics_name:"latest_block_height"` // The latest block height

	// Channel metrics
	ChannelBufferUsage map[string]metrics.Gauge
	DroppedSignals     metrics.Counter

	// Error metrics
	ErrorsByType         map[string]metrics.Counter
	RecoverableErrors    metrics.Counter
	NonRecoverableErrors metrics.Counter

	// Performance metrics
	OperationDuration map[string]metrics.Histogram
	GoroutineCount    metrics.Gauge

	// DA metrics
	DASubmissionAttempts  metrics.Counter
	DASubmissionSuccesses metrics.Counter
	DASubmissionFailures  metrics.Counter
	DARetrievalAttempts   metrics.Counter
	DARetrievalSuccesses  metrics.Counter
	DARetrievalFailures   metrics.Counter
	DAInclusionHeight     metrics.Gauge
	PendingHeadersCount   metrics.Gauge
	PendingDataCount      metrics.Gauge

	// Sync metrics
	SyncLag             metrics.Gauge
	HeadersSynced       metrics.Counter
	DataSynced          metrics.Counter
	BlocksApplied       metrics.Counter
	InvalidHeadersCount metrics.Counter

	// Block production metrics
	BlockProductionTime  metrics.Histogram
	EmptyBlocksProduced  metrics.Counter
	LazyBlocksProduced   metrics.Counter
	NormalBlocksProduced metrics.Counter
	TxsPerBlock          metrics.Histogram

	// State transition metrics
	StateTransitions   map[string]metrics.Counter
	InvalidTransitions metrics.Counter
}

Metrics contains all metrics exposed by this package.

func NopMetrics added in v0.11.19

func NopMetrics() *Metrics

NopMetrics returns no-op Metrics

func PrometheusMetrics added in v0.11.19

func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics

PrometheusMetrics returns Metrics built using Prometheus client library

type MetricsRecorder

type MetricsRecorder interface {
	RecordMetrics(gasPrice float64, blobSize uint64, statusCode coreda.StatusCode, numPendingBlocks uint64, includedBlockHeight uint64)
}

MetricsRecorder defines the interface for sequencers that support recording metrics. This interface is used to avoid duplication of the anonymous interface definition across multiple files in the block package.

type MetricsTimer

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

MetricsTimer helps track operation duration

func NewMetricsTimer

func NewMetricsTimer(operation string, metrics *Metrics) *MetricsTimer

NewMetricsTimer creates a new timer for tracking operation duration

func (*MetricsTimer) Stop

func (t *MetricsTimer) Stop()

Stop stops the timer and records the duration

type MockLogger

type MockLogger struct {
	mock.Mock
}

func (*MockLogger) Debug

func (m *MockLogger) Debug(args ...interface{})

For non-f methods, the first arg is typically the message string, others are keyvals.

func (*MockLogger) Debugf

func (m *MockLogger) Debugf(format string, args ...interface{})

func (*MockLogger) Error

func (m *MockLogger) Error(args ...interface{})

func (*MockLogger) Errorf

func (m *MockLogger) Errorf(format string, args ...interface{})

func (*MockLogger) Fatal

func (m *MockLogger) Fatal(args ...interface{})

func (*MockLogger) Fatalf

func (m *MockLogger) Fatalf(format string, args ...interface{})

func (*MockLogger) Info

func (m *MockLogger) Info(args ...interface{})

func (*MockLogger) Infof

func (m *MockLogger) Infof(format string, args ...interface{})

func (*MockLogger) Panic

func (m *MockLogger) Panic(args ...interface{})

func (*MockLogger) Panicf

func (m *MockLogger) Panicf(format string, args ...interface{})

func (*MockLogger) Warn

func (m *MockLogger) Warn(args ...interface{})

func (*MockLogger) Warnf

func (m *MockLogger) Warnf(format string, args ...interface{})

func (*MockLogger) With

func (m *MockLogger) With(keyvals ...interface{}) *zap.SugaredLogger

type NewDataEvent added in v0.14.0

type NewDataEvent struct {
	Data     *types.Data
	DAHeight uint64
}

NewDataEvent is used to pass header and DA height to headerInCh

type NewHeaderEvent added in v0.14.0

type NewHeaderEvent struct {
	Header   *types.SignedHeader
	DAHeight uint64
}

NewHeaderEvent is used to pass header and DA height to headerInCh

type PendingData

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

PendingData maintains Data that need to be published to DA layer

Important assertions: - data is safely stored in database before submission to DA - data is always pushed to DA in order (by height) - DA submission of multiple data is atomic - it's impossible to submit only part of a batch

lastSubmittedDataHeight is updated only after receiving confirmation from DA. Worst case scenario is when data was successfully submitted to DA, but confirmation was not received (e.g. node was restarted, networking issue occurred). In this case data is re-submitted to DA (it's extra cost). rollkit is able to skip duplicate data so this shouldn't affect full nodes. Note: Submission of pending data to DA should account for the DA max blob size.

func NewPendingData

func NewPendingData(store store.Store, logger logging.EventLogger) (*PendingData, error)

NewPendingData returns a new PendingData struct

type PendingHeaders added in v0.14.0

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

PendingHeaders maintains headers that need to be published to DA layer

Important assertions: - headers are safely stored in database before submission to DA - headers are always pushed to DA in order (by height) - DA submission of multiple headers is atomic - it's impossible to submit only part of a batch

lastSubmittedHeaderHeight is updated only after receiving confirmation from DA. Worst case scenario is when headers was successfully submitted to DA, but confirmation was not received (e.g. node was restarted, networking issue occurred). In this case headers are re-submitted to DA (it's extra cost). rollkit is able to skip duplicate headers so this shouldn't affect full nodes. TODO(tzdybal): we shouldn't try to push all pending headers at once; this should depend on max blob size

func NewPendingHeaders added in v0.14.0

func NewPendingHeaders(store storepkg.Store, logger logging.EventLogger) (*PendingHeaders, error)

NewPendingHeaders returns a new PendingHeaders struct

type Reaper

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

Reaper is responsible for periodically retrieving transactions from the executor, filtering out already seen transactions, and submitting new transactions to the sequencer.

func NewReaper

func NewReaper(ctx context.Context, exec coreexecutor.Executor, sequencer coresequencer.Sequencer, chainID string, interval time.Duration, logger logging.EventLogger, store ds.Batching) *Reaper

NewReaper creates a new Reaper instance with persistent seenTx storage.

func (*Reaper) SetManager

func (r *Reaper) SetManager(manager *Manager)

SetManager sets the Manager reference for transaction notifications

func (*Reaper) Start

func (r *Reaper) Start(ctx context.Context)

Start begins the reaping process at the specified interval.

func (*Reaper) SubmitTxs

func (r *Reaper) SubmitTxs()

SubmitTxs retrieves transactions from the executor and submits them to the sequencer.

Jump to

Keyboard shortcuts

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