core

package
v1.22.45 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: BSD-3-Clause Imports: 5 Imported by: 30

Documentation

Overview

Package core provides core consensus interfaces and contracts. This package has zero dependencies on consensus modules.

Index

Examples

Constants

View Source
const (
	PendingTxs    = vm.PendingTxs
	StateSyncDone = vm.StateSyncDone
)

Constants re-exported from vm package

View Source
const (
	Unknown       = vm.Unknown
	Starting      = vm.Starting
	Syncing       = vm.Syncing
	Bootstrapping = vm.Bootstrapping
	Ready         = vm.Ready
	Degraded      = vm.Degraded
	Stopping      = vm.Stopping
	Stopped       = vm.Stopped

	// Legacy aliases for VMState constants (old naming convention)
	VMStateSyncing  = vm.Syncing
	VMBootstrapping = vm.Bootstrapping
	VMNormalOp      = vm.Ready
)

Re-export state constants from vm package

Variables

This section is empty.

Functions

This section is empty.

Types

type Acceptor

type Acceptor interface {
	// Accept processes an accepted item
	Accept(ctx context.Context, containerID ids.ID, container []byte) error
}

Acceptor interface for consensus acceptors

type AppError

type AppError struct {
	Code    int
	Message string
}

AppError represents an application-level error

func (AppError) Error

func (e AppError) Error() string

type BasicAcceptor added in v1.21.0

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

BasicAcceptor is a simple implementation of the Acceptor interface

func NewBasicAcceptor added in v1.21.0

func NewBasicAcceptor() *BasicAcceptor

NewBasicAcceptor creates a new basic acceptor

func (*BasicAcceptor) Accept added in v1.21.0

func (a *BasicAcceptor) Accept(ctx context.Context, containerID ids.ID, container []byte) error

Accept marks an item as accepted

type Block

type Block interface {
	ID() ids.ID
	ParentID() ids.ID
	Height() uint64
	Timestamp() int64
	Bytes() []byte
	Verify(context.Context) error
	Accept(context.Context) error
	Reject(context.Context) error
}

Block represents a block

type BlockState added in v1.22.32

type BlockState interface {
	// GetBlock gets a block
	GetBlock(ids.ID) (Block, error)

	// PutBlock puts a block
	PutBlock(Block) error

	// GetLastAccepted gets last accepted
	GetLastAccepted() (ids.ID, error)

	// SetLastAccepted sets last accepted
	SetLastAccepted(ids.ID) error
}

BlockState represents block storage for consensus

type BootstrapTracker

type BootstrapTracker interface {
	// OnBootstrapStarted is called when bootstrapping starts
	OnBootstrapStarted() error
	// OnBootstrapCompleted is called when bootstrapping completes
	OnBootstrapCompleted() error
	// IsBootstrapped returns whether the node has finished bootstrapping
	IsBootstrapped() bool
}

BootstrapTracker tracks the progress of bootstrapping

type ConsensusContext

type ConsensusContext interface {
	// Context returns the underlying Go context
	Context() context.Context

	// NodeID returns the node ID
	NodeID() ids.NodeID

	// ChainID returns the chain ID
	ChainID() ids.ID

	// Deadline returns the deadline for operations
	Deadline() time.Time
}

ConsensusContext provides context for consensus operations

type Decidable

type Decidable interface {
	// ID returns the ID of this decidable
	ID() ids.ID

	// Accept marks this as accepted
	Accept(context.Context) error

	// Reject marks this as rejected
	Reject(context.Context) error

	// Status returns the current status
	Status() Status
}

Decidable represents something that can be decided upon

type Fx

type Fx = vm.Fx

Type aliases to vm package

type FxLifecycle added in v1.22.32

type FxLifecycle = vm.FxLifecycle

Type aliases to vm package

type HealthCheckable

type HealthCheckable interface {
	// HealthCheck returns health information
	HealthCheck(context.Context) (interface{}, error)
}

HealthCheckable represents something that can report its health

Example
ctx := context.Background()
checker := &mockHealthCheckable{
	health: map[string]string{"status": "operational"},
}

health, err := checker.HealthCheck(ctx)
if err != nil {
	fmt.Printf("Health check failed: %v\n", err)
} else {
	fmt.Printf("Health: %v\n", health)
}
Output:

Health: map[status:operational]

type HealthStatus

type HealthStatus int

HealthStatus represents health status

const (
	HealthUnknown HealthStatus = iota
	HealthHealthy
	HealthUnhealthy
)

func (HealthStatus) String

func (h HealthStatus) String() string

String returns the string representation

Example

Examples

status := HealthHealthy
fmt.Println(status.String())
Output:

healthy

type ID

type ID interface{ ~[32]byte }

ID interface for block/vertex IDs

type Message

type Message = vm.Message

Type aliases to vm package

type MessageType

type MessageType = vm.MessageType

Type aliases to vm package

type Protocol

type Protocol[I comparable] interface {
	// Initialize initializes the protocol
	Initialize(ctx context.Context) error

	// Step runs one poll/round of the protocol
	Step(ctx context.Context) error

	// Status returns the status of an item (e.g., {unknown, preferred, decided})
	Status(id I) (string, error)
}

Protocol represents a consensus protocol that can be plugged into engines

type State

type State = vm.State

State is the VM lifecycle state, re-exported from vm.State

type Status

type Status int

Status represents the consensus status of an item

const (
	// StatusUnknown means the status is unknown
	StatusUnknown Status = iota

	// StatusPending means the item is pending decision
	StatusPending

	// StatusProcessing means the item is being processed
	StatusProcessing

	// StatusAccepted means the item has been accepted
	StatusAccepted

	// StatusRejected means the item has been rejected
	StatusRejected
)

func (Status) Decided

func (s Status) Decided() bool

Decided returns true if the status represents a final decision

Example
fmt.Println(StatusPending.Decided())
fmt.Println(StatusAccepted.Decided())
fmt.Println(StatusRejected.Decided())
Output:

false
true
true

func (Status) String

func (s Status) String() string

String returns the string representation of the status

Example

Examples

fmt.Println(StatusPending.String())
fmt.Println(StatusAccepted.String())
Output:

pending
accepted

type TestDecidable

type TestDecidable struct {
	TestID     ids.ID
	TestStatus Status
	AcceptFunc func(context.Context) error
	RejectFunc func(context.Context) error
}

TestDecidable is a test implementation of Decidable

func NewTestDecidable

func NewTestDecidable(id ids.ID) *TestDecidable

NewTestDecidable creates a new test decidable

func (*TestDecidable) Accept

func (t *TestDecidable) Accept(ctx context.Context) error

Accept marks as accepted

func (*TestDecidable) ID

func (t *TestDecidable) ID() ids.ID

ID returns the ID

func (*TestDecidable) Reject

func (t *TestDecidable) Reject(ctx context.Context) error

Reject marks as rejected

func (*TestDecidable) Status

func (t *TestDecidable) Status() Status

Status returns current status

type Tx

type Tx interface {
	ID() ids.ID
	Bytes() []byte
	Verify(context.Context) error
	Accept(context.Context) error
}

Tx represents a transaction

type UTXO

type UTXO interface {
	ID() ids.ID
	TxID() ids.ID
	OutputIndex() uint32
	Amount() uint64
}

UTXO represents an unspent transaction output

type VM

type VM = interfaces.VM

VM is an alias to engine/interfaces.VM for backwards compatibility Import from github.com/luxfi/consensus/engine/interfaces for the full VM interface

type VMState

type VMState = vm.State

VMState is an alias for State (for compatibility with older code)

Directories

Path Synopsis
Package block provides block interfaces for consensus
Package block provides block interfaces for consensus
Package coremock provides mock implementations for testing
Package coremock provides mock implementations for testing
Package interfaces defines core consensus interfaces
Package interfaces defines core consensus interfaces

Jump to

Keyboard shortcuts

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