cbft

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: GPL-3.0 Imports: 54 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 added in v0.7.1

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

CreateBackend returns a new Backend for testing.

func CreateGenesis added in v1.0.0

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

func CreateValidatorBackend added in v0.7.1

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

CreateValidatorBackend returns a new ValidatorBackend for testing.

func GenerateCbftNode added in v0.7.1

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

GenerateCbftNode returns a list of CbftNode for testing.

func GenerateKeys added in v0.7.1

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

GenerateKeys returns the public and private key pair for testing.

func NewBlock added in v0.7.1

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

NewBlock returns a new block for testing.

func NewBlockWithSign added in v0.7.3

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

NewBlock returns a new block for testing.

func NewEngineManager added in v0.7.1

func NewEngineManager(cbfts []*TestCBFT) ([]*network.EngineManager, []enode.ID)

NewEngineManager returns a list of EngineManager and NodeID.

Types

type API added in v0.7.1

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 added in v0.7.1

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 added in v0.7.1

func NewBridge(ctx *node.Node, 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 added in v0.7.1

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.Node) *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 added in v0.7.1

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 added in v0.7.1

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 added in v0.7.1

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

Config returns the configuration information of the consensus engine.

func (*Cbft) ConsensusNodes

func (cbft *Cbft) ConsensusNodes() ([]enode.ID, 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 added in v0.7.3

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

func (*Cbft) DefaultAvgLatency added in v0.7.1

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

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 added in v0.7.1

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

GetPrepareQC returns the QC data of the specified block height.

func (*Cbft) GetSchnorrNIZKProve added in v0.7.3

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 added in v0.7.1

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

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

func (*Cbft) HighestLockBlockBn added in v0.7.1

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

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

func (*Cbft) HighestQCBlockBn added in v0.7.1

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 added in v0.7.3

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

LatestStatus returns latest status.

func (*Cbft) LoadWal added in v0.7.1

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

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

func (*Cbft) MissingPrepareVote added in v0.7.1

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

MissingPrepareVote returns missing vote.

func (*Cbft) MissingViewChangeNodes added in v0.7.1

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) Node added in v1.4.1

func (cbft *Cbft) Node() *enode.Node

NodeID returns the ID value of the current node

func (*Cbft) OnBlockQuorumCert added in v0.7.1

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

OnBlockQuorumCert handles the message type of BlockQuorumCertMsg.

func (*Cbft) OnCommitError added in v0.7.1

func (cbft *Cbft) OnCommitError(err error)

Asynchronous processing of errors generated by the submission block

func (*Cbft) OnGetBlockQuorumCert added in v0.7.1

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

OnGetBlockQuorumCert handles the message type of GetBlockQuorumCertMsg.

func (*Cbft) OnGetLatestStatus added in v0.7.1

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 added in v0.7.1

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

OnGetQCBlockList handles the message type of GetQCBlockListMsg.

func (*Cbft) OnGetViewChange added in v0.7.1

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 added in v0.7.1

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

OnInsertQCBlock performs security rule verification, view switching.

func (*Cbft) OnLatestStatus added in v0.7.1

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 added in v0.7.1

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 added in v0.7.1

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

OnViewChangeQuorumCert handles the message type of ViewChangeQuorumCertMsg.

func (*Cbft) OnViewChanges added in v0.7.1

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

OnViewChanges handles the message type of ViewChangesMsg.

func (*Cbft) OnViewTimeout added in v0.7.1

func (cbft *Cbft) OnViewTimeout()

OnViewTimeout performs timeout logic for view.

func (*Cbft) Pause added in v0.7.1

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 added in v0.7.1

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 added in v0.7.1

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 added in v0.7.1

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) Stop added in v1.3.1

func (cbft *Cbft) Stop() error

Stop turns off the consensus asyncExecutor and fetcher.

func (*Cbft) SyncBlockQuorumCert added in v0.7.1

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

func (*Cbft) SyncPrepareBlock added in v0.7.1

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

func (*Cbft) Syncing added in v1.0.0

func (cbft *Cbft) Syncing() bool

func (*Cbft) TracingSwitch added in v0.7.1

func (cbft *Cbft) TracingSwitch(flag int8)

TracingSwitch will be abandoned in the future.

func (*Cbft) TrySetHighestQCBlock added in v0.7.1

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 added in v0.7.1

type HandleError interface {
	error
	AuthFailed() bool
}

type PublicAdminConsensusAPI added in v1.1.1

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

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

func NewPublicAdminConsensusAPI added in v1.1.1

func NewPublicAdminConsensusAPI(engine API) *PublicAdminConsensusAPI

NewPublicAdminConsensusAPI creates a new PlatON blockchain API.

func (*PublicAdminConsensusAPI) GetSchnorrNIZKProve added in v1.1.1

func (s *PublicAdminConsensusAPI) GetSchnorrNIZKProve() string

type PublicDebugConsensusAPI added in v1.1.1

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

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

func NewDebugConsensusAPI added in v1.1.1

func NewDebugConsensusAPI(engine API) *PublicDebugConsensusAPI

NewDebugConsensusAPI creates a new PlatON blockchain API.

func (*PublicDebugConsensusAPI) ConsensusStatus added in v1.1.1

func (s *PublicDebugConsensusAPI) ConsensusStatus() *Status

ConsensusStatus returns the status data of the consensus engine.

func (*PublicDebugConsensusAPI) GetPrepareQC added in v1.1.1

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

GetPrepareQC returns the QC certificate corresponding to the blockNumber.

type PublicPlatonConsensusAPI added in v1.1.1

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

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

func NewPublicPlatonConsensusAPI added in v1.1.1

func NewPublicPlatonConsensusAPI(engine API) *PublicPlatonConsensusAPI

NewPublicPlatonConsensusAPI creates a new PlatON blockchain API.

func (*PublicPlatonConsensusAPI) Evidences added in v1.1.1

func (s *PublicPlatonConsensusAPI) Evidences() string

Evidences returns the relevant data of the verification.

type Status added in v0.7.3

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

type TestCBFT added in v0.7.1

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

TestCBFT for testing.

func Mock4NodePipe added in v0.7.1

func Mock4NodePipe(start bool) []*TestCBFT

Mock4NodePipe returns a list of TestCBFT for testing.

func Mock4NodePipe2 added in v0.7.3

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

Mock4NodePipe returns a list of TestCBFT for testing.

func MockNode added in v0.7.1

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 added in v0.7.1

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 added in v0.7.1

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