core

package
v1.22.25 Latest Latest
Warning

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

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

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

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    int32
	Message string
}

AppError represents an application-level error for peer messaging

func (*AppError) Error

func (e *AppError) Error() string

Error implements the error interface

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 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 Error added in v1.22.7

type Error = warp.Error

Error is an alias for warp.Error for backwards compatibility

type Fx

type Fx struct {
	ID ids.ID
	Fx interface{}
}

Fx defines a feature extension

type Handler added in v1.22.7

type Handler = warp.Handler

Handler is an alias for warp.Handler for backwards compatibility

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 struct {
	Type    MessageType
	NodeID  ids.NodeID
	Content []byte
}

Message defines a message that can be sent to the consensus engine

type MessageType

type MessageType uint32

MessageType defines the type of a message

const (
	// PendingTxs indicates pending transactions
	PendingTxs MessageType = iota
	// PutBlock indicates a block to be added
	PutBlock
	// GetBlock indicates a request for a block
	GetBlock
	// GetAccepted indicates a request for accepted blocks
	GetAccepted
	// Accepted indicates an accepted block
	Accepted
	// GetAncestors indicates a request for ancestors
	GetAncestors
	// MultiPut indicates multiple blocks
	MultiPut
	// GetFailed indicates a failed get request
	GetFailed
	// QueryFailed indicates a failed query
	QueryFailed
	// Chits indicates chits
	Chits
	// ChitsV2 indicates chits v2
	ChitsV2
	// GetAcceptedFrontier indicates a request for the accepted frontier
	GetAcceptedFrontier
	// AcceptedFrontier indicates the accepted frontier
	AcceptedFrontier
	// GetAcceptedFrontierFailed indicates a failed frontier request
	GetAcceptedFrontierFailed
	// WarpRequest indicates a warp request
	WarpRequest
	// WarpResponse indicates a warp response
	WarpResponse
	// WarpGossip indicates warp gossip
	WarpGossip
	// StateSyncDone indicates state sync completed
	StateSyncDone
)

func (MessageType) String

func (m MessageType) String() string

String returns the string representation of the message type

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 SendConfig

type SendConfig = warp.SendConfig

SendConfig is an alias for warp.SendConfig for backwards compatibility

type Sender added in v1.22.7

type Sender = warp.Sender

Sender is an alias for warp.Sender for backwards compatibility

type State

type State 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
}

State represents consensus 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

func (Status) String

func (s Status) String() string

String returns the string representation of the status

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 interface {
	// Initialize initializes the VM
	Initialize(
		ctx context.Context,
		chainCtx *consensuscontext.Context,
		dbManager manager.Manager,
		genesisBytes []byte,
		upgradeBytes []byte,
		configBytes []byte,
		toEngine chan<- Message,
		fxs []*Fx,
		warpSender interface{},
	) error

	// SetState sets the state of the VM
	SetState(ctx context.Context, state VMState) error

	// Shutdown shuts down the VM
	Shutdown(ctx context.Context) error

	// Version returns the version of the VM
	Version(ctx context.Context) (string, error)

	// HealthCheck returns nil if the VM is healthy
	HealthCheck(ctx context.Context) (interface{}, error)

	// CreateHandlers returns the HTTP handlers for the VM
	CreateHandlers(ctx context.Context) (map[string]http.Handler, error)

	// CreateStaticHandlers returns the static HTTP handlers for the VM
	CreateStaticHandlers(ctx context.Context) (map[string]http.Handler, error)

	// NewHTTPHandler returns a new HTTP handler for the VM
	NewHTTPHandler(ctx context.Context) (http.Handler, error)
}

VM defines the interface that all VMs must implement

type VMState

type VMState uint8

VMState represents the state of a VM

const (
	// VMInitializing is the state of a VM that is initializing
	VMInitializing VMState = iota
	// VMStateSyncing is the state of a VM that is syncing state
	VMStateSyncing
	// VMBootstrapping is the state of a VM that is bootstrapping
	VMBootstrapping
	// VMNormalOp is the state of a VM that is in normal operation
	VMNormalOp
)

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
Package tracker provides consensus tracking utilities
Package tracker provides consensus tracking utilities
Package verify provides verification utilities
Package verify provides verification utilities

Jump to

Keyboard shortcuts

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