Documentation
¶
Overview ¶
Package core provides core consensus interfaces and contracts. This package has zero dependencies on consensus modules.
Index ¶
- Constants
- type Acceptor
- type AppError
- type BasicAcceptor
- type Block
- type BlockState
- type BootstrapTracker
- type ConsensusContext
- type Decidable
- type Fx
- type FxLifecycle
- type HealthCheckable
- type HealthStatus
- type ID
- type Message
- type MessageType
- type Protocol
- type State
- type Status
- type TestDecidable
- type Tx
- type UTXO
- type VM
- type VMState
Examples ¶
Constants ¶
const ( PendingTxs = vm.PendingTxs StateSyncDone = vm.StateSyncDone )
Constants re-exported from vm package
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 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
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 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 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 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 )
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) 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 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
Source Files
¶
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 |