consensus

package
v0.0.0-...-f94ef0f Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const Category = "dBFT"

Category is message category for extensible payloads.

Variables

This section is empty.

Functions

func GetDefaultHonestNodeCount

func GetDefaultHonestNodeCount(n int) int

Types

type Config

type Config struct {
	// Logger is a logger instance.
	Logger *zap.Logger
	// Broadcast is a callback which is called to notify server
	// about new consensus payload to sent.
	Broadcast func(p *npayload.Extensible)
	// Chain is a Ledger instance.
	Chain Ledger
	// ProtocolConfiguration contains protocol settings.
	ProtocolConfiguration config.ProtocolConfiguration
	// RequestTx is a callback to which will be called
	// when a node lacks transactions present in a block.
	RequestTx func(h ...common.Hash)
	// TimePerBlock minimal time that should pass before next block is accepted.
	TimePerBlock time.Duration
	// Wallet is a local-node wallet configuration.
	Wallet *config.Wallet
}

Config is a configuration for consensus services.

type Ledger

type Ledger interface {
	AddBlock(block *coreb.Block) error
	ApplyPolicyToTxSet([]*transaction.Transaction) []*transaction.Transaction
	GetConfig() config.ProtocolConfiguration
	GetMemPool() *mempool.Pool
	GetStateModule() blockchainer.StateRoot
	GetTransaction(common.Hash) (*transaction.Transaction, *types.Receipt, error)
	GetValidators(uint32) ([]*keys.PublicKey, error)
	PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error
	SubscribeForBlocks(ch chan<- *coreb.Block)
	UnsubscribeFromBlocks(ch chan<- *coreb.Block)
	BlockHeight() uint32
	CurrentBlockHash() common.Hash
	GetBlock(hash common.Hash, full bool) (*coreb.Block, *types.Receipt, error)
	GetHeaderHash(int) common.Hash
	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 uint64) *Payload

NewPayload creates new consensus payload for the provided network.

func (*Payload) DecodeBinary

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

DecodeBinary implements io.Serializable interface.

func (*Payload) EncodeBinary

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

EncodeBinary implements io.Serializable interface.

func (Payload) GetChangeView

func (p Payload) GetChangeView() payload.ChangeView

GetChangeView implements payload.ConsensusPayload interface.

func (Payload) GetCommit

func (p Payload) GetCommit() payload.Commit

GetCommit implements payload.ConsensusPayload interface.

func (Payload) GetPrepareRequest

func (p Payload) GetPrepareRequest() payload.PrepareRequest

GetPrepareRequest implements payload.ConsensusPayload interface.

func (Payload) GetPrepareResponse

func (p Payload) GetPrepareResponse() payload.PrepareResponse

GetPrepareResponse implements payload.ConsensusPayload interface.

func (Payload) GetRecoveryMessage

func (p Payload) GetRecoveryMessage() payload.RecoveryMessage

GetRecoveryMessage implements payload.ConsensusPayload interface.

func (Payload) GetRecoveryRequest

func (p Payload) GetRecoveryRequest() payload.RecoveryRequest

GetRecoveryRequest implements payload.ConsensusPayload interface.

func (*Payload) Hash

func (p *Payload) Hash() common.Hash

Hash implements payload.ConsensusPayload interface.

func (Payload) Height

func (p Payload) Height() uint32

Height implements payload.ConsensusPayload interface.

func (Payload) Payload

func (p Payload) Payload() interface{}

Payload implements payload.ConsensusPayload interface.

func (*Payload) SetHeight

func (p *Payload) SetHeight(h uint32)

SetHeight implements payload.ConsensusPayload interface.

func (*Payload) SetPayload

func (p *Payload) SetPayload(pl interface{})

SetPayload implements payload.ConsensusPayload interface.

func (*Payload) SetType

func (p *Payload) SetType(t payload.MessageType)

SetType implements payload.ConsensusPayload interface.

func (*Payload) SetValidatorIndex

func (p *Payload) SetValidatorIndex(i uint16)

SetValidatorIndex implements payload.ConsensusPayload interface.

func (*Payload) SetViewNumber

func (p *Payload) SetViewNumber(view byte)

SetViewNumber implements payload.ConsensusPayload interface.

func (*Payload) Sign

func (p *Payload) Sign(key *keys.PrivateKey) error

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

func (Payload) Type

func (p Payload) Type() payload.MessageType

Type implements payload.ConsensusPayload interface.

func (Payload) ValidatorIndex

func (p Payload) ValidatorIndex() uint16

ValidatorIndex implements payload.ConsensusPayload interface.

func (Payload) ViewNumber

func (p Payload) ViewNumber() byte

ViewNumber implements payload.ConsensusPayload interface.

type Service

type Service interface {
	// Start initializes dBFT and starts event loop for consensus service.
	// It must be called only when sufficient amount of peers are connected.
	Start()
	// Shutdown stops dBFT event loop.
	Shutdown()

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

Service represents consensus instance.

func NewService

func NewService(cfg Config) (Service, error)

NewService returns new consensus.Service instance.

Jump to

Keyboard shortcuts

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