cbft

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: GPL-3.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorUnKnowBlock  = errors.New("unknown block")
	ErrorEngineBusy   = errors.New("cbft engine busy")
	ErrorNotRunning   = errors.New("cbft is not running")
	ErrorNotValidator = errors.New("current node not a validator")
	ErrorTimeout      = errors.New("timeout")
)

Functions

func CreateBackend

func CreateBackend(engine *Cbft, nodes []params.CbftNode) (*core.BlockChain, *core.BlockChainCache, *core.TxPool, consensus.Agency)

CreateBackend returns a new Backend for testing.

func CreateGenesis

func CreateGenesis(db ethdb.Database) (core.Genesis, *types.Block)

func CreateValidatorBackend

func CreateValidatorBackend(engine *Cbft, nodes []params.CbftNode) (*core.BlockChain, *core.BlockChainCache, *core.TxPool, consensus.Agency)

CreateValidatorBackend returns a new ValidatorBackend for testing.

func GenerateCbftNode

func GenerateCbftNode(num int) ([]*ecdsa.PrivateKey, []*bls.SecretKey, []params.CbftNode)

GenerateCbftNode returns a list of CbftNode for testing.

func GenerateKeys

func GenerateKeys(num int) ([]*ecdsa.PrivateKey, []*bls.SecretKey)

GenerateKeys returns the public and private key pair for testing.

func NewBlock

func NewBlock(parent common.Hash, number uint64) *types.Block

NewBlock returns a new block for testing.

func NewBlockWithSign

func NewBlockWithSign(parent common.Hash, number uint64, node *TestCBFT) *types.Block

NewBlock returns a new block for testing.

func NewEngineManager

func NewEngineManager(cbfts []*TestCBFT) ([]*network.EngineManager, []discover.NodeID)

NewEngineManager returns a list of EngineManager and NodeID.

Types

type API

type API interface {
	Status() []byte
	Evidences() string
	GetPrepareQC(number uint64) *types.QuorumCert
	GetSchnorrNIZKProve() (*bls.SchnorrProof, error)
}

API defines an exposed API function interface.

type Bridge

type Bridge interface {
	UpdateChainState(qcState, lockState, commitState *protocols.State)
	ConfirmViewChange(epoch, viewNumber uint64, block *types.Block, qc *ctypes.QuorumCert, viewChangeQC *ctypes.ViewChangeQC, preEpoch, preViewNumber uint64)
	SendViewChange(view *protocols.ViewChange)
	SendPrepareBlock(pb *protocols.PrepareBlock)
	SendPrepareVote(block *types.Block, vote *protocols.PrepareVote)
	GetViewChangeQC(epoch uint64, viewNumber uint64) (*ctypes.ViewChangeQC, error)

	Close()
}

Bridge encapsulates functions required to update consensus state and consensus msg. As a bridge layer for cbft and wal.

func NewBridge

func NewBridge(ctx *node.ServiceContext, cbft *Cbft) (Bridge, error)

NewBridge creates a new Bridge to update consensus state and consensus msg.

type Cbft

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

Cbft is the core structure of the consensus engine and is responsible for handling consensus logic.

func CreateCBFT

func CreateCBFT(pk *ecdsa.PrivateKey, sk *bls.SecretKey, period uint64, amount uint32) *Cbft

CreateCBFT returns a new CBFT for testing.

func New

func New(sysConfig *params.CbftConfig, optConfig *ctypes.OptionsConfig, eventMux *event.TypeMux, ctx *node.ServiceContext) *Cbft

New returns a new CBFT.

func (*Cbft) APIs

func (cbft *Cbft) APIs(chain consensus.ChainReader) []rpc.API

APIs returns a list of APIs provided by the consensus engine.

func (*Cbft) Author

func (cbft *Cbft) Author(header *types.Header) (common.Address, error)

Author returns the current node's Author.

func (*Cbft) AvgLatency

func (cbft *Cbft) AvgLatency() time.Duration

AvgLatency returns the average delay time of the specified node.

The average is the average delay between the current node and all consensus nodes. Return value unit: milliseconds.

func (*Cbft) BlockExists

func (cbft *Cbft) BlockExists(blockNumber uint64, blockHash common.Hash) error

BlockExists is used to query whether the specified block exists in this node.

func (*Cbft) CalcBlockDeadline

func (cbft *Cbft) CalcBlockDeadline(timePoint time.Time) time.Time

CalcBlockDeadline return the deadline of the block.

func (*Cbft) CalcNextBlockTime

func (cbft *Cbft) CalcNextBlockTime(blockTime time.Time) time.Time

CalcNextBlockTime returns the deadline of the next block.

func (*Cbft) Close

func (cbft *Cbft) Close() error

Close turns off the consensus engine.

func (*Cbft) Config

func (cbft *Cbft) Config() *ctypes.Config

Config returns the configuration information of the consensus engine.

func (*Cbft) ConsensusNodes

func (cbft *Cbft) ConsensusNodes() ([]discover.NodeID, error)

ConsensusNodes returns to the list of consensus nodes.

func (*Cbft) CurrentBlock

func (cbft *Cbft) CurrentBlock() *types.Block

CurrentBlock get the current lock block.

func (*Cbft) DecodeExtra

func (cbft *Cbft) DecodeExtra(extra []byte) (common.Hash, uint64, error)

func (*Cbft) DefaultAvgLatency

func (cbft *Cbft) DefaultAvgLatency() time.Duration

DefaultAvgLatency returns the avg latency of default.

func (*Cbft) Evidences

func (cbft *Cbft) Evidences() string

Evidences implements functions in API.

func (*Cbft) FastSyncCommitHead

func (cbft *Cbft) FastSyncCommitHead(block *types.Block) error

FastSyncCommitHead processes logic that performs fast synchronization.

func (*Cbft) Finalize

func (cbft *Cbft) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, receipts []*types.Receipt) (*types.Block, error)

Finalize implements consensus.Engine, no block rewards given, and returns the final block.

func (*Cbft) GetBlock

func (cbft *Cbft) GetBlock(hash common.Hash, number uint64) *types.Block

GetBlock returns the block corresponding to the specified number and hash.

func (*Cbft) GetBlockByHash

func (cbft *Cbft) GetBlockByHash(hash common.Hash) *types.Block

GetBlockByHash get the specified block by hash.

func (*Cbft) GetBlockByHashAndNum

func (cbft *Cbft) GetBlockByHashAndNum(hash common.Hash, number uint64) *types.Block

GetBlockByHash get the specified block by hash and number.

func (*Cbft) GetBlockWithoutLock

func (cbft *Cbft) GetBlockWithoutLock(hash common.Hash, number uint64) *types.Block

GetBlockWithoutLock returns the block corresponding to the specified number and hash.

func (*Cbft) GetPrepareQC

func (cbft *Cbft) GetPrepareQC(number uint64) *ctypes.QuorumCert

GetPrepareQC returns the QC data of the specified block height.

func (*Cbft) GetSchnorrNIZKProve

func (cbft *Cbft) GetSchnorrNIZKProve() (*bls.SchnorrProof, error)

func (*Cbft) HasBlock

func (cbft *Cbft) HasBlock(hash common.Hash, number uint64) bool

HasBlock check if the specified block exists in block tree.

func (*Cbft) HighestCommitBlockBn

func (cbft *Cbft) HighestCommitBlockBn() (uint64, common.Hash)

HighestCommitBlockBn returns the highest submitted block number of the current node.

func (*Cbft) HighestLockBlockBn

func (cbft *Cbft) HighestLockBlockBn() (uint64, common.Hash)

HighestLockBlockBn returns the highest locked block number of the current node.

func (*Cbft) HighestQCBlockBn

func (cbft *Cbft) HighestQCBlockBn() (uint64, common.Hash)

HighestQCBlockBn return the highest QC block number of the current node.

func (*Cbft) InsertChain

func (cbft *Cbft) InsertChain(block *types.Block) error

InsertChain is used to insert the block into the chain.

func (*Cbft) IsConsensusNode

func (cbft *Cbft) IsConsensusNode() bool

IsConsensusNode returns whether the current node is a consensus node.

func (*Cbft) IsSignedBySelf

func (cbft *Cbft) IsSignedBySelf(sealHash common.Hash, header *types.Header) bool

IsSignedBySelf returns the verification result , and the result is to determine whether the block information is the signature of the current node.

func (*Cbft) LatestStatus

func (cbft *Cbft) LatestStatus() (v *protocols.GetLatestStatus)

LatestStatus returns latest status.

func (*Cbft) LoadWal

func (cbft *Cbft) LoadWal() (err error)

LoadWal tries to recover consensus state and view msg from the wal.

func (*Cbft) MissingPrepareVote

func (cbft *Cbft) MissingPrepareVote() (v *protocols.GetPrepareVote, err error)

MissingPrepareVote returns missing vote.

func (*Cbft) MissingViewChangeNodes

func (cbft *Cbft) MissingViewChangeNodes() (v *protocols.GetViewChange, err error)

MissingViewChangeNodes returns the node ID of the missing vote.

Notes: Use the channel to complete serial execution to prevent concurrency.

func (*Cbft) NextBaseBlock

func (cbft *Cbft) NextBaseBlock() *types.Block

NextBaseBlock is used to calculate the next block.

func (*Cbft) NodeID

func (cbft *Cbft) NodeID() discover.NodeID

NodeID returns the ID value of the current node

func (*Cbft) OnBlockQuorumCert

func (cbft *Cbft) OnBlockQuorumCert(id string, msg *protocols.BlockQuorumCert) error

OnBlockQuorumCert handles the message type of BlockQuorumCertMsg.

func (*Cbft) OnCommitError

func (cbft *Cbft) OnCommitError(err error)

Asynchronous processing of errors generated by the submission block

func (*Cbft) OnGetBlockQuorumCert

func (cbft *Cbft) OnGetBlockQuorumCert(id string, msg *protocols.GetBlockQuorumCert) error

OnGetBlockQuorumCert handles the message type of GetBlockQuorumCertMsg.

func (*Cbft) OnGetLatestStatus

func (cbft *Cbft) OnGetLatestStatus(id string, msg *protocols.GetLatestStatus) error

OnGetLatestStatus hands GetLatestStatus messages.

main logic: 1.Compare the blockNumber of the sending node with the local node, and if the blockNumber of local node is larger then reply LatestStatus message, the message contains the status information of the local node.

func (*Cbft) OnGetPrepareBlock

func (cbft *Cbft) OnGetPrepareBlock(id string, msg *protocols.GetPrepareBlock) error

OnGetPrepareBlock handles the message type of GetPrepareBlockMsg.

func (*Cbft) OnGetPrepareVote

func (cbft *Cbft) OnGetPrepareVote(id string, msg *protocols.GetPrepareVote) error

OnGetPrepareVote is responsible for processing the business logic of the GetPrepareVote message. It will synchronously return a PrepareVotes message to the sender.

func (*Cbft) OnGetQCBlockList

func (cbft *Cbft) OnGetQCBlockList(id string, msg *protocols.GetQCBlockList) error

OnGetQCBlockList handles the message type of GetQCBlockListMsg.

func (*Cbft) OnGetViewChange

func (cbft *Cbft) OnGetViewChange(id string, msg *protocols.GetViewChange) error

OnGetViewChange responds to nodes that require viewChange.

The Epoch and viewNumber of viewChange must be consistent with the state of the current node.

func (*Cbft) OnInsertQCBlock

func (cbft *Cbft) OnInsertQCBlock(blocks []*types.Block, qcs []*ctypes.QuorumCert) error

OnInsertQCBlock performs security rule verification, view switching.

func (*Cbft) OnLatestStatus

func (cbft *Cbft) OnLatestStatus(id string, msg *protocols.LatestStatus) error

OnLatestStatus is used to process LatestStatus messages that received from peer.

func (*Cbft) OnPong

func (cbft *Cbft) OnPong(nodeID string, netLatency int64) error

OnPong is used to receive the average delay time.

func (*Cbft) OnPrepareBlock

func (cbft *Cbft) OnPrepareBlock(id string, msg *protocols.PrepareBlock) error

OnPrepareBlock performs security rule verification,store in blockTree, Whether to start synchronization

func (*Cbft) OnPrepareBlockHash

func (cbft *Cbft) OnPrepareBlockHash(id string, msg *protocols.PrepareBlockHash) error

OnPrepareBlockHash responsible for handling PrepareBlockHash message.

Note: After receiving the PrepareBlockHash message, it is determined whether the block information exists locally. If not, send a network request to get the block data.

func (*Cbft) OnPrepareVote

func (cbft *Cbft) OnPrepareVote(id string, msg *protocols.PrepareVote) error

OnPrepareVote perform security rule verification,store in blockTree, Whether to start synchronization

func (*Cbft) OnPrepareVotes

func (cbft *Cbft) OnPrepareVotes(id string, msg *protocols.PrepareVotes) error

OnPrepareVotes handling response from GetPrepareVote response.

func (*Cbft) OnSeal

func (cbft *Cbft) OnSeal(block *types.Block, results chan<- *types.Block, stop <-chan struct{}, complete chan<- struct{})

OnSeal is used to process the blocks that have already been generated.

func (*Cbft) OnShouldSeal

func (cbft *Cbft) OnShouldSeal(result chan error)

OnShouldSeal determines whether the current condition of the block is satisfied.

func (*Cbft) OnViewChange

func (cbft *Cbft) OnViewChange(id string, msg *protocols.ViewChange) error

OnViewChange performs security rule verification, view switching.

func (*Cbft) OnViewChangeQuorumCert

func (cbft *Cbft) OnViewChangeQuorumCert(id string, msg *protocols.ViewChangeQuorumCert) error

OnViewChangeQuorumCert handles the message type of ViewChangeQuorumCertMsg.

func (*Cbft) OnViewChanges

func (cbft *Cbft) OnViewChanges(id string, msg *protocols.ViewChanges) error

OnViewChanges handles the message type of ViewChangesMsg.

func (*Cbft) OnViewTimeout

func (cbft *Cbft) OnViewTimeout()

OnViewTimeout performs timeout logic for view.

func (*Cbft) Pause

func (cbft *Cbft) Pause()

func (*Cbft) Prepare

func (cbft *Cbft) Prepare(chain consensus.ChainReader, header *types.Header) error

Prepare implements consensus.Engine, preparing all the consensus fields of the header of running the transactions on top.

func (*Cbft) Protocols

func (cbft *Cbft) Protocols() []p2p.Protocol

Protocols return consensus engine to provide protocol information.

func (*Cbft) ReceiveMessage

func (cbft *Cbft) ReceiveMessage(msg *ctypes.MsgInfo) error

ReceiveMessage Entrance: The messages related to the consensus are entered from here. The message sent from the peer node is sent to the CBFT message queue and there is a loop that will distribute the incoming message.

func (*Cbft) ReceiveSyncMsg

func (cbft *Cbft) ReceiveSyncMsg(msg *ctypes.MsgInfo) error

ReceiveSyncMsg is used to receive messages that are synchronized from other nodes.

Possible message types are:

PrepareBlockVotesMsg/GetLatestStatusMsg/LatestStatusMsg/

func (*Cbft) Resume

func (cbft *Cbft) Resume()

func (*Cbft) Seal

func (cbft *Cbft) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}, complete chan<- struct{}) error

Seal is used to generate a block, and block data is passed to the execution channel.

func (*Cbft) SealHash

func (cbft *Cbft) SealHash(header *types.Header) common.Hash

SealHash returns the hash of a block prior to it being sealed.

func (*Cbft) ShouldSeal

func (cbft *Cbft) ShouldSeal(curTime time.Time) (bool, error)

ShouldSeal check if we can seal block.

func (*Cbft) Start

func (cbft *Cbft) Start(chain consensus.ChainReader, blockCacheWriter consensus.BlockCacheWriter, txPool consensus.TxPoolReset, agency consensus.Agency) error

Start starts consensus engine.

func (*Cbft) Status

func (cbft *Cbft) Status() []byte

Status returns the status data of the consensus engine.

func (*Cbft) SyncBlockQuorumCert

func (cbft *Cbft) SyncBlockQuorumCert(id string, blockNumber uint64, blockHash common.Hash, blockIndex uint32)

func (*Cbft) SyncPrepareBlock

func (cbft *Cbft) SyncPrepareBlock(id string, epoch uint64, viewNumber uint64, blockIndex uint32)

func (*Cbft) Syncing

func (cbft *Cbft) Syncing() bool

func (*Cbft) TracingSwitch

func (cbft *Cbft) TracingSwitch(flag int8)

TracingSwitch will be abandoned in the future.

func (*Cbft) TrySetHighestQCBlock

func (cbft *Cbft) TrySetHighestQCBlock(block *types.Block)

func (*Cbft) VerifyHeader

func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error

VerifyHeader verify the validity of the block header.

func (*Cbft) VerifyHeaders

func (cbft *Cbft) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is used to verify the validity of block headers in batch.

func (*Cbft) VerifySeal

func (cbft *Cbft) VerifySeal(chain consensus.ChainReader, header *types.Header) error

VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.

type HandleError

type HandleError interface {
	error
	AuthFailed() bool
}

type PublicAdminConsensusAPI added in v0.16.1

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

PublicAdminConsensusAPI provides an API to access the Alaya blockchain. It offers only methods that operate on public data that is freely available to anyone.

func NewPublicAdminConsensusAPI added in v0.16.1

func NewPublicAdminConsensusAPI(engine API) *PublicAdminConsensusAPI

NewPublicAdminConsensusAPI creates a new Alaya blockchain API.

func (*PublicAdminConsensusAPI) GetSchnorrNIZKProve added in v0.16.1

func (s *PublicAdminConsensusAPI) GetSchnorrNIZKProve() string

type PublicDebugConsensusAPI added in v0.16.1

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

PublicDebugConsensusAPI provides an API to access the Alaya blockchain. It offers only methods that operate on public data that is freely available to anyone.

func NewDebugConsensusAPI added in v0.16.1

func NewDebugConsensusAPI(engine API) *PublicDebugConsensusAPI

NewDebugConsensusAPI creates a new Alaya blockchain API.

func (*PublicDebugConsensusAPI) ConsensusStatus added in v0.16.1

func (s *PublicDebugConsensusAPI) ConsensusStatus() *Status

ConsensusStatus returns the status data of the consensus engine.

func (*PublicDebugConsensusAPI) GetPrepareQC added in v0.16.1

func (s *PublicDebugConsensusAPI) GetPrepareQC(number uint64) *types.QuorumCert

GetPrepareQC returns the QC certificate corresponding to the blockNumber.

type PublicPlatonConsensusAPI added in v0.16.1

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

PublicPlatonConsensusAPI provides an API to access the Alaya blockchain. It offers only methods that operate on public data that is freely available to anyone.

func NewPublicPlatonConsensusAPI added in v0.16.1

func NewPublicPlatonConsensusAPI(engine API) *PublicPlatonConsensusAPI

NewPublicPlatonConsensusAPI creates a new Alaya blockchain API.

func (*PublicPlatonConsensusAPI) Evidences added in v0.16.1

func (s *PublicPlatonConsensusAPI) Evidences() string

Evidences returns the relevant data of the verification.

type Status

type Status struct {
	Tree      *types.BlockTree `json:"blockTree"`
	State     *state.ViewState `json:"state"`
	Validator bool             `json:"validator"`
}

type TestCBFT

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

TestCBFT for testing.

func Mock4NodePipe

func Mock4NodePipe(start bool) []*TestCBFT

Mock4NodePipe returns a list of TestCBFT for testing.

func Mock4NodePipe2

func Mock4NodePipe2(start bool) ([]*TestCBFT, []params.CbftNode)

Mock4NodePipe returns a list of TestCBFT for testing.

func MockNode

func MockNode(pk *ecdsa.PrivateKey, sk *bls.SecretKey, nodes []params.CbftNode, period uint64, amount uint32) *TestCBFT

MockNode returns a new TestCBFT for testing.

func MockValidator

func MockValidator(pk *ecdsa.PrivateKey, sk *bls.SecretKey, nodes []params.CbftNode, period uint64, amount uint32) *TestCBFT

MockValidator returns a new TestCBFT for testing.

func (*TestCBFT) Start

func (t *TestCBFT) Start() error

Start turns on the cbft for testing.

Directories

Path Synopsis
Package evidence implements recording duplicate blocks and votes for cbft consensus.
Package evidence implements recording duplicate blocks and votes for cbft consensus.
Package network implements a concrete consensus engines.
Package network implements a concrete consensus engines.
Package wal implements the similar write-ahead logging for cbft consensus.
Package wal implements the similar write-ahead logging for cbft consensus.

Jump to

Keyboard shortcuts

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