cross

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCycle                  = errors.New("cycle detected")
	ErrExecMsgHasInvalidIndex = errors.New("executing message has invalid log index")
	ErrExecMsgUnknownChain    = errors.New("executing message references unknown chain")
)

Functions

func CrossSafeHazards

func CrossSafeHazards(d SafeStartDeps, chainID types.ChainID, inL1DerivedFrom eth.BlockID,
	candidate types.BlockSeal, execMsgs []*types.ExecutingMessage) (hazards map[types.ChainIndex]types.BlockSeal, err error)

CrossSafeHazards checks if the given messages all exist and pass invariants. It returns a hazard-set: if any intra-block messaging happened, these hazard blocks have to be verified.

func CrossSafeUpdate

func CrossSafeUpdate(ctx context.Context, logger log.Logger, chainID types.ChainID, d CrossSafeDeps) error

func CrossUnsafeHazards

func CrossUnsafeHazards(d UnsafeStartDeps, chainID types.ChainID,
	candidate types.BlockSeal, execMsgs []*types.ExecutingMessage) (hazards map[types.ChainIndex]types.BlockSeal, err error)

CrossUnsafeHazards checks if the given messages all exist and pass invariants. It returns a hazard-set: if any intra-block messaging happened, these hazard blocks have to be verified.

func CrossUnsafeUpdate

func CrossUnsafeUpdate(ctx context.Context, logger log.Logger, chainID types.ChainID, d CrossUnsafeDeps) error

func GenerateMermaidDiagram

func GenerateMermaidDiagram(g *graph) string

GenerateMermaidDiagram creates a Mermaid flowchart diagram from the graph data for debugging.

func HazardCycleChecks

func HazardCycleChecks(d CycleCheckDeps, inTimestamp uint64, hazards map[types.ChainIndex]types.BlockSeal) error

HazardCycleChecks checks for cyclical dependencies between logs at the given timestamp. Here the timestamp invariant alone does not ensure ordering of messages.

We perform this check in 3 steps:

  • Gather all logs across all hazard blocks at the given timestamp.
  • Build the logs into a directed graph of dependencies between logs.
  • Check the graph for cycles.

The edges of the graph are determined by:

  • For all logs except the first in a block, there is an edge from the previous log.
  • For all executing messages, there is an edge from the initiating message.

The edges between sequential logs ensure the graph is well-connected and free of any disjoint subgraphs that would make cycle checking more difficult.

The cycle check is performed by executing Kahn's topological sort algorithm which succeeds if and only if a graph is acyclic.

Returns nil if no cycles are found or ErrCycle if a cycle is detected.

func HazardSafeFrontierChecks

func HazardSafeFrontierChecks(d SafeFrontierCheckDeps, inL1DerivedFrom eth.BlockID, hazards map[types.ChainIndex]types.BlockSeal) error

HazardSafeFrontierChecks verifies all the hazard blocks are either:

  • already cross-safe.
  • the first (if not first: local blocks to verify before proceeding) local-safe block, after the cross-safe block.

func HazardUnsafeFrontierChecks

func HazardUnsafeFrontierChecks(d UnsafeFrontierCheckDeps, hazards map[types.ChainIndex]types.BlockSeal) error

HazardUnsafeFrontierChecks verifies all the hazard blocks are either:

  • already cross-unsafe.
  • the first (if not first: local blocks to verify before proceeding) local-unsafe block, after the cross-unsafe block.

Types

type CrossSafeDeps

type CrossSafeDeps interface {
	CrossSafe(chainID types.ChainID) (derivedFrom types.BlockSeal, derived types.BlockSeal, err error)

	SafeFrontierCheckDeps
	SafeStartDeps

	CandidateCrossSafe(chain types.ChainID) (derivedFromScope, crossSafe eth.BlockRef, err error)
	NextDerivedFrom(chain types.ChainID, derivedFrom eth.BlockID) (after eth.BlockRef, err error)
	PreviousDerived(chain types.ChainID, derived eth.BlockID) (prevDerived types.BlockSeal, err error)

	OpenBlock(chainID types.ChainID, blockNum uint64) (ref eth.BlockRef, logCount uint32, execMsgs map[uint32]*types.ExecutingMessage, err error)

	UpdateCrossSafe(chain types.ChainID, l1View eth.BlockRef, lastCrossDerived eth.BlockRef) error
}

type CrossUnsafeDeps

type CrossUnsafeDeps interface {
	CrossUnsafe(chainID types.ChainID) (types.BlockSeal, error)

	UnsafeStartDeps
	UnsafeFrontierCheckDeps

	OpenBlock(chainID types.ChainID, blockNum uint64) (block eth.BlockRef, logCount uint32, execMsgs map[uint32]*types.ExecutingMessage, err error)

	UpdateCrossUnsafe(chain types.ChainID, crossUnsafe types.BlockSeal) error
}

type CycleCheckDeps

type CycleCheckDeps interface {
	// OpenBlock returns log data for the requested block, to be used for cycle checking.
	OpenBlock(chainID types.ChainID, blockNum uint64) (block eth.BlockRef, logCount uint32, execMsgs map[uint32]*types.ExecutingMessage, err error)
}

CycleCheckDeps is an interface for checking cyclical dependencies between logs.

type SafeFrontierCheckDeps

type SafeFrontierCheckDeps interface {
	CandidateCrossSafe(chain types.ChainID) (derivedFromScope, crossSafe eth.BlockRef, err error)

	CrossDerivedFrom(chainID types.ChainID, derived eth.BlockID) (derivedFrom types.BlockSeal, err error)

	DependencySet() depset.DependencySet
}

type SafeStartDeps

type SafeStartDeps interface {
	Check(chain types.ChainID, blockNum uint64, logIdx uint32, logHash common.Hash) (includedIn types.BlockSeal, err error)

	CrossDerivedFrom(chainID types.ChainID, derived eth.BlockID) (derivedFrom types.BlockSeal, err error)

	DependencySet() depset.DependencySet
}

type UnsafeFrontierCheckDeps

type UnsafeFrontierCheckDeps interface {
	ParentBlock(chainID types.ChainID, parentOf eth.BlockID) (parent eth.BlockID, err error)

	IsCrossUnsafe(chainID types.ChainID, block eth.BlockID) error
	IsLocalUnsafe(chainID types.ChainID, block eth.BlockID) error

	DependencySet() depset.DependencySet
}

type UnsafeStartDeps

type UnsafeStartDeps interface {
	Check(chain types.ChainID, blockNum uint64, logIdx uint32, logHash common.Hash) (includedIn types.BlockSeal, err error)

	IsCrossUnsafe(chainID types.ChainID, block eth.BlockID) error

	DependencySet() depset.DependencySet
}

type Worker

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

Worker iterates work

func NewCrossSafeWorker

func NewCrossSafeWorker(logger log.Logger, chainID types.ChainID, d CrossSafeDeps) *Worker

func NewCrossUnsafeWorker

func NewCrossUnsafeWorker(logger log.Logger, chainID types.ChainID, d CrossUnsafeDeps) *Worker

func NewWorker

func NewWorker(log log.Logger, workFn workFn) *Worker

NewWorker creates a new worker to process updates

func (*Worker) Close

func (s *Worker) Close()

func (*Worker) OnNewData

func (s *Worker) OnNewData()

func (*Worker) ProcessWork

func (s *Worker) ProcessWork() error

func (*Worker) StartBackground

func (s *Worker) StartBackground()

Jump to

Keyboard shortcuts

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