chain_container

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHistoryUnavailable = errors.New("safedb history unavailable on this node")

ErrHistoryUnavailable is the permanent counterpart of ethereum.NotFound: SafeDB on this node cannot and will not contain the requested history (e.g. snap/CL-sync bootstrap gap). Interop halts on this rather than retrying; recovery requires operator intervention.

Functions

This section is empty.

Types

type ChainContainer

type ChainContainer interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	Pause(ctx context.Context) error
	Resume(ctx context.Context) error

	ID() eth.ChainID
	LocalSafeBlockAtTimestamp(ctx context.Context, ts uint64) (eth.L2BlockRef, error)
	// TimestampToBlockNumber maps an L2 unix timestamp to the L2 block number (rollup derivation).
	TimestampToBlockNumber(ctx context.Context, ts uint64) (uint64, error)
	BlockNumberToTimestamp(ctx context.Context, blocknum uint64) (uint64, error)
	SyncStatus(ctx context.Context) (*eth.SyncStatus, error)
	OptimisticAt(ctx context.Context, ts uint64) (l2, l1 eth.BlockID, err error)
	// OutputRootAtL2BlockHash returns the L2 output root for the canonical
	// block at the given hash. Post-Isthmus the root is derived from the
	// header alone; pre-Isthmus it falls back to eth_getProof on state at
	// that block. Returns ethereum.NotFound if the EL no longer has the
	// block at that hash on its canonical chain.
	OutputRootAtL2BlockHash(ctx context.Context, blockHash common.Hash) (eth.Bytes32, error)
	OptimisticOutputAtTimestamp(ctx context.Context, ts uint64) (*eth.OutputV0, error)
	RegisterVerifier(v activity.VerificationActivity)
	// VerifierCurrentL1s returns the CurrentL1 from each registered verifier.
	// This allows callers to determine the minimum L1 block that all verifiers have processed.
	VerifierCurrentL1s() []eth.BlockID
	// FetchReceipts fetches the receipts for a given block by hash.
	// Returns block info and receipts, or an error if the block or receipts cannot be fetched.
	FetchReceipts(ctx context.Context, blockHash eth.BlockID) (eth.BlockInfo, types.Receipts, error)
	// BlockTime returns the block time in seconds for this chain.
	BlockTime() uint64
	// PruneDeniedAtOrAfterTimestamp removes deny-list entries with DecisionTimestamp >= timestamp.
	// Returns map of removed hashes by height.
	PruneDeniedAtOrAfterTimestamp(timestamp uint64) (map[uint64][]common.Hash, error)
	// PauseAndStopVN pauses the chain container restart loop and stops the virtual node.
	// This is used to freeze a chain's VN before a multi-chain rewind begins, preventing
	// the VN from issuing forkchoice updates that race with the rewind of a peer chain.
	PauseAndStopVN(ctx context.Context) error
	// IsDenied checks if a block hash is on the deny list at the given height.
	IsDenied(height uint64, payloadHash common.Hash) (bool, error)
	// GetDeniedOutput returns the reconstructed OutputV0 for a denied block.
	// Returns nil if the block is not denied at that height.
	GetDeniedOutput(height uint64, payloadHash common.Hash) (*eth.OutputV0, error)
	// OutputV0AtBlockNumber returns the full OutputV0 for the block at the given number.
	OutputV0AtBlockNumber(ctx context.Context, l2BlockNum uint64) (*eth.OutputV0, error)
	// SetResetCallback sets a callback that is invoked when the chain resets.
	// The supernode uses this to notify activities about chain resets.
	SetResetCallback(cb ResetCallback)
}

type DenyList

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

DenyList provides persistence for invalid block payload hashes using bbolt. Blocks are keyed by block height, with each height potentially having multiple denied hashes.

func OpenDenyList

func OpenDenyList(dataDir string) (*DenyList, error)

OpenDenyList opens or creates a DenyList at the given data directory.

func (*DenyList) Add

func (d *DenyList) Add(height uint64, payloadHash common.Hash, decisionTimestamp uint64, stateRoot, messagePasserStorageRoot eth.Bytes32) error

Add adds a payload hash to the deny list at the given block height. stateRoot and messagePasserStorageRoot are the output preimage fields for optimistic root computation. Multiple hashes can be denied at the same height.

func (*DenyList) Close

func (d *DenyList) Close() error

Close closes the database.

func (*DenyList) Contains

func (d *DenyList) Contains(height uint64, payloadHash common.Hash) (bool, error)

Contains checks if a payload hash is denied at the given block height.

func (*DenyList) GetDeniedHashes

func (d *DenyList) GetDeniedHashes(height uint64) ([]common.Hash, error)

GetDeniedHashes returns all denied payload hashes at the given block height.

func (*DenyList) GetDeniedRecords

func (d *DenyList) GetDeniedRecords(height uint64) ([]DenyRecord, error)

GetDeniedRecords returns all denied records at the given block height.

func (*DenyList) GetOutputV0

func (d *DenyList) GetOutputV0(height uint64, payloadHash common.Hash) (*eth.OutputV0, error)

GetOutputV0 reconstructs and returns the full OutputV0 for a denied block. Returns nil if the hash is not denied at that height.

func (*DenyList) HasDeniedAtOrAfterTimestamp added in v1.18.0

func (d *DenyList) HasDeniedAtOrAfterTimestamp(timestamp uint64) (bool, error)

HasDeniedAtOrAfterTimestamp returns true if any denied payload has DecisionTimestamp >= timestamp.

func (*DenyList) LastDeniedOutputV0

func (d *DenyList) LastDeniedOutputV0(height uint64) (*eth.OutputV0, error)

LastDeniedOutputV0 returns the OutputV0 for the most recently denied block at the given height. Returns nil if no blocks are denied at that height. Note: supernode does not currently behave in well defined ways when there are multiple denied blocks at the same height.

func (*DenyList) PruneAtOrAfterTimestamp

func (d *DenyList) PruneAtOrAfterTimestamp(timestamp uint64) (map[uint64][]common.Hash, error)

PruneAtOrAfterTimestamp iterates all keys in the bucket, decodes records, removes any where DecisionTimestamp >= timestamp, re-encodes remaining. Returns map of removed hashes by height.

type DenyRecord

type DenyRecord struct {
	PayloadHash              common.Hash `json:"payloadHash"`
	DecisionTimestamp        uint64      `json:"decisionTimestamp"`
	StateRoot                eth.Bytes32 `json:"stateRoot"`
	MessagePasserStorageRoot eth.Bytes32 `json:"messagePasserStorageRoot"`
}

DenyRecord stores a denied payload hash along with decision provenance and the output preimage fields for optimistic root computation.

type InteropChain

type InteropChain interface {
	ChainContainer
	// HasDeniedAtOrAfterTimestamp returns true if any deny-list entry has
	// DecisionTimestamp >= timestamp, without mutating the deny list.
	HasDeniedAtOrAfterTimestamp(timestamp uint64) (bool, error)
	// RewindEngine rewinds the engine to the highest block with timestamp less than
	// or equal to the given timestamp. invalidatedBlock is the block that triggered
	// the rewind and is passed to reset callbacks.
	RewindEngine(ctx context.Context, timestamp uint64, invalidatedBlock eth.BlockRef) error
	// InvalidateBlock adds a block to the deny list and triggers a rewind if the
	// chain currently uses that block at the specified height. Returns true if a
	// rewind was triggered, false otherwise.
	InvalidateBlock(ctx context.Context, height uint64, payloadHash common.Hash, decisionTimestamp uint64, stateRoot, messagePasserStorageRoot eth.Bytes32) (bool, error)
}

WARNING: InteropChain exposes the reorg-triggering operations (RewindEngine, InvalidateBlock) that bypass the interop WAL model when invoked outside of interop transition application. ONLY the interop activity should accept or hold a value of this interface. Every other caller must take the narrower ChainContainer above so the misuse is caught at compile time.

func NewChainContainer

func NewChainContainer(
	chainID eth.ChainID,
	vncfg *opnodecfg.Config,
	log gethlog.Logger,
	cfg config.CLIConfig,
	initOverload *rollupNode.InitializationOverrides,
	rpcHandler *oprpc.Handler,
	setHandler func(chainID string, h http.Handler),
	addMetricsRegistry func(key string, g prometheus.Gatherer),
	metrics *resources.SupernodeMetrics,
) InteropChain

type ResetCallback

type ResetCallback func(chainID eth.ChainID, timestamp uint64, invalidatedBlock eth.BlockRef)

ResetCallback is called when the chain container resets due to an invalidated block. The supernode uses this to notify activities about the reset. invalidatedBlock is the block that was invalidated and triggered the reset.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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