consensus

package
v0.0.0-...-886a677 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package consensus contains Neo consensus node implementation.

It uses external dBFT library for the core algorithm and basically joins this library with Neo node internals implemented in NeoGo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockQueuer

type BlockQueuer interface {
	PutBlock(block *coreb.Block) error
}

BlockQueuer is an interface to the block queue manager sufficient for Service.

type Config

type Config struct {
	// Logger is a logger instance.
	Logger *zap.Logger
	// Broadcast is a callback which is called to notify the server
	// about a new consensus payload to be sent.
	Broadcast func(p *npayload.Extensible)
	// Chain is a Ledger instance.
	Chain Ledger
	// BlockQueue is a BlockQueuer instance.
	BlockQueue BlockQueuer
	// ProtocolConfiguration contains protocol settings.
	ProtocolConfiguration config.ProtocolConfiguration
	// RequestTx is a callback to which will be called
	// when a node lacks transactions present in the block.
	RequestTx func(h ...util.Uint256)
	// StopTxFlow is a callback that is called after the consensus
	// process stops accepting incoming transactions.
	StopTxFlow func()
	// TimePerBlock is minimal time that should pass before the next block is accepted.
	TimePerBlock time.Duration
	// Wallet is a local-node wallet configuration. If the path is empty, then
	// no wallet will be initialized and the service will be in watch-only mode.
	Wallet config.Wallet
}

Config is a configuration for consensus services.

type Ledger

type Ledger interface {
	ApplyPolicyToTxSet([]*transaction.Transaction) []*transaction.Transaction
	GetConfig() config.Blockchain
	GetMemPool() *mempool.Pool
	GetNextBlockValidators() ([]*keys.PublicKey, error)
	GetStateRoot(height uint32) (*state.MPTRoot, error)
	GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
	ComputeNextBlockValidators() []*keys.PublicKey
	PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error
	SubscribeForBlocks(ch chan *coreb.Block)
	UnsubscribeFromBlocks(ch chan *coreb.Block)
	GetBaseExecFee() int64
	CalculateAttributesFee(tx *transaction.Transaction) int64
	interop.Ledger
	mempool.Feer
}

Ledger is the interface to Blockchain sufficient for Service.

type Payload

type Payload struct {
	npayload.Extensible
	// contains filtered or unexported fields
}

Payload is a type for consensus-related messages.

func NewPayload

func NewPayload(m netmode.Magic, stateRootEnabled bool) *Payload

NewPayload creates a new consensus payload for the provided network.

func (*Payload) DecodeBinary

func (p *Payload) DecodeBinary(r *io.BinReader)

DecodeBinary implements the io.Serializable interface.

func (*Payload) EncodeBinary

func (p *Payload) EncodeBinary(w *io.BinWriter)

EncodeBinary implements the io.Serializable interface.

func (Payload) GetChangeView

func (p Payload) GetChangeView() dbft.ChangeView

GetChangeView implements the payload.ConsensusPayload interface.

func (Payload) GetCommit

func (p Payload) GetCommit() dbft.Commit

GetCommit implements the payload.ConsensusPayload interface.

func (Payload) GetPrepareRequest

func (p Payload) GetPrepareRequest() dbft.PrepareRequest[util.Uint256]

GetPrepareRequest implements the payload.ConsensusPayload interface.

func (Payload) GetPrepareResponse

func (p Payload) GetPrepareResponse() dbft.PrepareResponse[util.Uint256]

GetPrepareResponse implements the payload.ConsensusPayload interface.

func (Payload) GetRecoveryMessage

func (p Payload) GetRecoveryMessage() dbft.RecoveryMessage[util.Uint256]

GetRecoveryMessage implements the payload.ConsensusPayload interface.

func (Payload) GetRecoveryRequest

func (p Payload) GetRecoveryRequest() dbft.RecoveryRequest

GetRecoveryRequest implements the payload.ConsensusPayload interface.

func (*Payload) Hash

func (p *Payload) Hash() util.Uint256

Hash implements the payload.ConsensusPayload interface.

func (Payload) Height

func (p Payload) Height() uint32

Height implements the payload.ConsensusPayload interface.

func (Payload) Payload

func (p Payload) Payload() any

Payload implements the payload.ConsensusPayload interface.

func (*Payload) SetValidatorIndex

func (p *Payload) SetValidatorIndex(i uint16)

SetValidatorIndex implements the payload.ConsensusPayload interface.

func (*Payload) SetViewNumber

func (p *Payload) SetViewNumber(view byte)

SetViewNumber implements the payload.ConsensusPayload interface.

func (*Payload) Sign

func (p *Payload) Sign(key *privateKey) error

Sign signs payload using the private key. It also sets corresponding verification and invocation scripts.

func (Payload) Type

func (p Payload) Type() dbft.MessageType

Type implements the payload.ConsensusPayload interface.

func (Payload) ValidatorIndex

func (p Payload) ValidatorIndex() uint16

ValidatorIndex implements the payload.ConsensusPayload interface.

func (Payload) ViewNumber

func (p Payload) ViewNumber() byte

ViewNumber implements the payload.ConsensusPayload interface.

type Service

type Service interface {
	// Name returns service name.
	Name() string
	// Start initializes dBFT and starts event loop for consensus service.
	// It must be called only when the sufficient amount of peers are connected.
	// The service only starts once, subsequent calls to Start are no-op.
	Start()
	// Shutdown stops dBFT event loop. It can only be called once, subsequent calls
	// to Shutdown on the same instance are no-op. The instance that was stopped can
	// not be started again by calling Start (use a new instance if needed).
	Shutdown()

	// OnPayload is a callback to notify the Service about a newly received payload.
	OnPayload(p *npayload.Extensible) error
	// OnTransaction is a callback to notify the Service about a newly received transaction.
	OnTransaction(tx *transaction.Transaction)
}

Service represents a consensus instance.

func NewService

func NewService(cfg Config) (Service, error)

NewService returns a new consensus.Service instance.

Jump to

Keyboard shortcuts

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