dag

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: GPL-3.0, LGPL-3.0, LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchConflicts

func BatchConflicts(vertices []*EVMVertex) [][]bool

BatchConflicts returns the pairwise conflict adjacency matrix for a slice of vertices using native Go popcount. GPU bitmap intersection is provided by luxcpp kernels and reached through a cgo bridge, not implemented here.

func Conflicts

func Conflicts(a, b *EVMVertex) bool

Conflicts checks whether two EVM vertices have overlapping storage access that would create a data hazard if executed concurrently.

Conflict exists when:

  • a.WriteSet intersects b.ReadSet (write-read / RAW hazard)
  • a.ReadSet intersects b.WriteSet (read-write / WAR hazard)
  • a.WriteSet intersects b.WriteSet (write-write / WAW hazard)

Implementation lives in conflicts_cpu.go (Go popcount); GPU bitmap intersection lives in luxcpp kernels and is reached through the luxgpu cgo bridge from a higher-level dispatcher, not from Go.

func ConflictsSets

func ConflictsSets(aWrite, aRead, bWrite, bRead *StorageKeySet) bool

ConflictsSets checks conflicts using raw storage key sets. Useful when vertices have not been constructed yet (e.g., during builder speculative grouping).

Types

type Builder

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

Builder constructs EVM DAG vertices from mempool transactions.

The build process:

  1. Drain up to maxTxsPerVertex transactions from the mempool.
  2. Run Block-STM speculative parallel execution to compute per-tx r/w sets.
  3. Group transactions into a single vertex with union read/write sets.
  4. Select parents = frontier tips that cover the vertex's read dependencies.

func NewBuilder

func NewBuilder(cfg BuilderConfig) *Builder

NewBuilder creates a vertex builder.

func (*Builder) BuildVertex

func (b *Builder) BuildVertex(txs []*types.Transaction) *EVMVertex

BuildVertex creates a DAG vertex from a batch of transactions.

It runs speculative Block-STM execution to discover per-tx read/write sets, unions them into vertex-level sets, and selects parents from the DAG frontier that cover the union read set.

type BuilderConfig

type BuilderConfig struct {
	Workers         int
	MaxTxsPerVertex int
	FrontierFn      func() []ids.ID
	HeightFn        func() uint64
	EpochFn         func() uint32
}

BuilderConfig configures the vertex builder.

type DAGExecutor

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

DAGExecutor implements parallel.BlockExecutor but operates on DAG vertices instead of linear blocks. It receives finalized antichain cuts from the nebula DAG engine, topologically sorts the transactions across all vertices in the cut, and applies them using Block-STM parallel execution.

For backward compatibility during bootstrap, it also accepts linear blocks via ExecuteBlock and processes them sequentially.

func NewDAGExecutor

func NewDAGExecutor(cfg DAGExecutorConfig) *DAGExecutor

NewDAGExecutor creates a DAG executor.

func (*DAGExecutor) BuildVertex

func (e *DAGExecutor) BuildVertex(txs []*types.Transaction) *EVMVertex

BuildVertex creates a DAG vertex from pending transactions.

func (*DAGExecutor) ExecuteAntichain

func (e *DAGExecutor) ExecuteAntichain(
	config *ethparams.ChainConfig,
	header *types.Header,
	vertices []*EVMVertex,
	statedb *state.StateDB,
	vmCfg vm.Config,
) ([]*types.Receipt, error)

ExecuteAntichain processes a set of non-conflicting vertices (an antichain from the DAG) in parallel. Transactions from all vertices are merged into a single execution batch with conflict-aware ordering.

Precondition: all vertices in the antichain have been verified as non-conflicting by the nebula engine (no write-read, read-write, or write-write overlaps).

func (*DAGExecutor) ExecuteBlock

func (e *DAGExecutor) ExecuteBlock(
	config *ethparams.ChainConfig,
	header *types.Header,
	txs types.Transactions,
	statedb *state.StateDB,
	vmCfg vm.Config,
) ([]*types.Receipt, error)

ExecuteBlock implements parallel.BlockExecutor for backward compatibility. During bootstrap, the C-Chain still receives linear blocks. This method wraps them in a single-vertex DAG cut and executes normally.

func (*DAGExecutor) ExecuteTopologicalCut

func (e *DAGExecutor) ExecuteTopologicalCut(
	config *ethparams.ChainConfig,
	header *types.Header,
	vertices []*EVMVertex,
	statedb *state.StateDB,
	vmCfg vm.Config,
) ([]*types.Receipt, error)

ExecuteTopologicalCut processes vertices from a finalized DAG cut in topological order. Vertices that are independent (no parent-child relationship within the cut) are executed as an antichain. Dependent vertices are executed sequentially respecting causal order.

func (*DAGExecutor) Metrics

func (e *DAGExecutor) Metrics() map[string]int64

Metrics returns DAG executor statistics.

type DAGExecutorConfig

type DAGExecutorConfig struct {
	Builder *Builder
	ApplyFn TxApplyFunc
	Workers int
}

DAGExecutorConfig configures the DAG executor.

type EVMVertex

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

EVMVertex is a DAG vertex that carries EVM transactions along with their speculative read/write sets. It implements the consensus vertex.Vertex interface so the nebula DAG engine can order and finalize it.

The read/write sets are computed during BuildVertex via Block-STM speculative execution. Conflict detection between vertices uses bitmap intersection on these sets (see conflicts.go).

func NewEVMVertex

func NewEVMVertex(
	height uint64,
	epoch uint32,
	parents []ids.ID,
	txs []*types.Transaction,
	readSet *StorageKeySet,
	writeSet *StorageKeySet,
) *EVMVertex

NewEVMVertex creates a vertex from transactions and their speculative r/w sets. The vertex ID is derived deterministically from parent IDs, tx hashes, and height.

func (*EVMVertex) Accept

func (v *EVMVertex) Accept(_ context.Context) error

func (*EVMVertex) Bytes

func (v *EVMVertex) Bytes() []byte

func (*EVMVertex) Epoch

func (v *EVMVertex) Epoch() uint32

func (*EVMVertex) Height

func (v *EVMVertex) Height() uint64

func (*EVMVertex) ID

func (v *EVMVertex) ID() ids.ID

func (*EVMVertex) Parents

func (v *EVMVertex) Parents() []ids.ID

func (*EVMVertex) ReadSet

func (v *EVMVertex) ReadSet() *StorageKeySet

ReadSet returns the speculative read set bitmap.

func (*EVMVertex) Reject

func (v *EVMVertex) Reject(_ context.Context) error

func (*EVMVertex) Status

func (v *EVMVertex) Status() choices.Status

func (*EVMVertex) Transactions

func (v *EVMVertex) Transactions() []*types.Transaction

Transactions returns the EVM transactions in this vertex.

func (*EVMVertex) Txs

func (v *EVMVertex) Txs() []ids.ID

func (*EVMVertex) Verify

func (v *EVMVertex) Verify(_ context.Context) error

func (*EVMVertex) WriteSet

func (v *EVMVertex) WriteSet() *StorageKeySet

WriteSet returns the speculative write set bitmap.

type StorageKeySet

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

StorageKeySet is a fixed-size bitmap representing a set of EVM storage keys.

func (*StorageKeySet) Add

func (s *StorageKeySet) Add(key common.Hash)

Add inserts a storage key into the set.

func (*StorageKeySet) Contains

func (s *StorageKeySet) Contains(key common.Hash) bool

Contains checks if a storage key might be in the set.

func (*StorageKeySet) IntersectionPopcount

func (s *StorageKeySet) IntersectionPopcount(other *StorageKeySet) int

IntersectionPopcount returns the number of shared bits.

func (*StorageKeySet) Intersects

func (s *StorageKeySet) Intersects(other *StorageKeySet) bool

Intersects returns true if two sets share any bits. This is the CPU path; the GPU path uses conflicts_gpu.go.

func (*StorageKeySet) IsEmpty

func (s *StorageKeySet) IsEmpty() bool

IsEmpty returns true if no keys have been inserted.

func (*StorageKeySet) Len

func (s *StorageKeySet) Len() int

Len returns the number of keys inserted.

func (*StorageKeySet) Union

func (s *StorageKeySet) Union(other *StorageKeySet)

Union merges another set into this one.

func (*StorageKeySet) Words

func (s *StorageKeySet) Words() *[bitmapWords]uint64

Words returns the raw bitmap for GPU kernel consumption.

type TxApplyFunc

type TxApplyFunc func(
	config *ethparams.ChainConfig,
	header *types.Header,
	tx *types.Transaction,
	statedb *state.StateDB,
	vmCfg vm.Config,
	txIndex int,
) (*types.Receipt, error)

TxApplyFunc executes a single transaction against the given state and returns the receipt. Injection point that lets callers plug in the EVM backend (Go-EVM / revm / cevm / GPU-EVM) without circular imports.

type VertexStore

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

VertexStore is an in-memory store of accepted vertices for the DAG.

func NewVertexStore

func NewVertexStore() *VertexStore

NewVertexStore creates a new vertex store.

func (*VertexStore) Add

func (s *VertexStore) Add(v *EVMVertex)

Add inserts a vertex into the store.

func (*VertexStore) Frontier

func (s *VertexStore) Frontier() []ids.ID

Frontier returns the current DAG tips (vertices with no children).

func (*VertexStore) Get

func (s *VertexStore) Get(id ids.ID) (*EVMVertex, bool)

Get retrieves a vertex by ID.

func (*VertexStore) Height

func (s *VertexStore) Height() uint64

Height returns max height + 1 across all vertices.

func (*VertexStore) Len

func (s *VertexStore) Len() int

Len returns total number of vertices.

Jump to

Keyboard shortcuts

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