Documentation ¶
Index ¶
- func CreateBackend(engine *Cbft, nodes []params.CbftNode) (*core.BlockChain, *core.BlockChainCache, *core.TxPool, consensus.Agency)
- func CreateValidatorBackend(engine *Cbft, nodes []params.CbftNode) (*core.BlockChain, *core.BlockChainCache, *core.TxPool, consensus.Agency)
- func GenerateCbftNode(num int) ([]*ecdsa.PrivateKey, []*bls.SecretKey, []params.CbftNode)
- func GenerateKeys(num int) ([]*ecdsa.PrivateKey, []*bls.SecretKey)
- func NewBlock(parent common.Hash, number uint64) *types.Block
- func NewBlockWithSign(parent common.Hash, number uint64, node *TestCBFT) *types.Block
- func NewEngineManager(cbfts []*TestCBFT) ([]*network.EngineManager, []discover.NodeID)
- type API
- type Bridge
- type Cbft
- func (cbft *Cbft) APIs(chain consensus.ChainReader) []rpc.API
- func (cbft *Cbft) Author(header *types.Header) (common.Address, error)
- func (cbft *Cbft) AvgLatency() time.Duration
- func (cbft *Cbft) BlockExists(blockNumber uint64, blockHash common.Hash) error
- func (cbft *Cbft) CalcBlockDeadline(timePoint time.Time) time.Time
- func (cbft *Cbft) CalcNextBlockTime(blockTime time.Time) time.Time
- func (cbft *Cbft) Close() error
- func (cbft *Cbft) Config() *ctypes.Config
- func (cbft *Cbft) ConsensusNodes() ([]discover.NodeID, error)
- func (cbft *Cbft) CurrentBlock() *types.Block
- func (cbft *Cbft) DecodeExtra(extra []byte) (common.Hash, uint64, error)
- func (cbft *Cbft) DefaultAvgLatency() time.Duration
- func (cbft *Cbft) Evidences() string
- func (cbft *Cbft) FastSyncCommitHead(block *types.Block) error
- func (cbft *Cbft) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (cbft *Cbft) GetBlock(hash common.Hash, number uint64) *types.Block
- func (cbft *Cbft) GetBlockByHash(hash common.Hash) *types.Block
- func (cbft *Cbft) GetBlockWithoutLock(hash common.Hash, number uint64) *types.Block
- func (cbft *Cbft) GetPrepareQC(number uint64) *ctypes.QuorumCert
- func (cbft *Cbft) GetSchnorrNIZKProve() (*bls.SchnorrProof, error)
- func (cbft *Cbft) HasBlock(hash common.Hash, number uint64) bool
- func (cbft *Cbft) HighestCommitBlockBn() (uint64, common.Hash)
- func (cbft *Cbft) HighestLockBlockBn() (uint64, common.Hash)
- func (cbft *Cbft) HighestQCBlockBn() (uint64, common.Hash)
- func (cbft *Cbft) InsertChain(block *types.Block) error
- func (cbft *Cbft) IsConsensusNode() bool
- func (cbft *Cbft) IsSignedBySelf(sealHash common.Hash, header *types.Header) bool
- func (cbft *Cbft) LatestStatus() (v *protocols.GetLatestStatus)
- func (cbft *Cbft) LoadWal() (err error)
- func (cbft *Cbft) MissingPrepareVote() (v *protocols.GetPrepareVote, err error)
- func (cbft *Cbft) MissingViewChangeNodes() (v *protocols.GetViewChange, err error)
- func (cbft *Cbft) NextBaseBlock() *types.Block
- func (cbft *Cbft) NodeID() discover.NodeID
- func (cbft *Cbft) OnBlockQuorumCert(id string, msg *protocols.BlockQuorumCert) error
- func (cbft *Cbft) OnCommitError(err error)
- func (cbft *Cbft) OnGetBlockQuorumCert(id string, msg *protocols.GetBlockQuorumCert) error
- func (cbft *Cbft) OnGetLatestStatus(id string, msg *protocols.GetLatestStatus) error
- func (cbft *Cbft) OnGetPrepareBlock(id string, msg *protocols.GetPrepareBlock) error
- func (cbft *Cbft) OnGetPrepareVote(id string, msg *protocols.GetPrepareVote) error
- func (cbft *Cbft) OnGetQCBlockList(id string, msg *protocols.GetQCBlockList) error
- func (cbft *Cbft) OnGetViewChange(id string, msg *protocols.GetViewChange) error
- func (cbft *Cbft) OnInsertQCBlock(blocks []*types.Block, qcs []*ctypes.QuorumCert) error
- func (cbft *Cbft) OnLatestStatus(id string, msg *protocols.LatestStatus) error
- func (cbft *Cbft) OnPong(nodeID string, netLatency int64) error
- func (cbft *Cbft) OnPrepareBlock(id string, msg *protocols.PrepareBlock) error
- func (cbft *Cbft) OnPrepareBlockHash(id string, msg *protocols.PrepareBlockHash) error
- func (cbft *Cbft) OnPrepareVote(id string, msg *protocols.PrepareVote) error
- func (cbft *Cbft) OnPrepareVotes(id string, msg *protocols.PrepareVotes) error
- func (cbft *Cbft) OnSeal(block *types.Block, results chan<- *types.Block, stop <-chan struct{})
- func (cbft *Cbft) OnShouldSeal(result chan error)
- func (cbft *Cbft) OnViewChange(id string, msg *protocols.ViewChange) error
- func (cbft *Cbft) OnViewChangeQuorumCert(id string, msg *protocols.ViewChangeQuorumCert) error
- func (cbft *Cbft) OnViewChanges(id string, msg *protocols.ViewChanges) error
- func (cbft *Cbft) OnViewTimeout()
- func (cbft *Cbft) Pause()
- func (cbft *Cbft) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (cbft *Cbft) Protocols() []p2p.Protocol
- func (cbft *Cbft) ReceiveMessage(msg *ctypes.MsgInfo) error
- func (cbft *Cbft) ReceiveSyncMsg(msg *ctypes.MsgInfo) error
- func (cbft *Cbft) Resume()
- func (cbft *Cbft) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, ...) error
- func (cbft *Cbft) SealHash(header *types.Header) common.Hash
- func (cbft *Cbft) ShouldSeal(curTime time.Time) (bool, error)
- func (cbft *Cbft) Start(chain consensus.ChainReader, blockCacheWriter consensus.BlockCacheWriter, ...) error
- func (cbft *Cbft) Status() *Status
- func (cbft *Cbft) SyncBlockQuorumCert(id string, blockNumber uint64, blockHash common.Hash, blockIndex uint32)
- func (cbft *Cbft) SyncPrepareBlock(id string, epoch uint64, viewNumber uint64, blockIndex uint32)
- func (cbft *Cbft) TracingSwitch(flag int8)
- func (cbft *Cbft) TrySetHighestQCBlock(block *types.Block)
- func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
- func (cbft *Cbft) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (cbft *Cbft) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- type HandleError
- type PublicConsensusAPI
- type Status
- type TestCBFT
- func Mock4NodePipe(start bool) []*TestCBFT
- func Mock4NodePipe2(start bool) ([]*TestCBFT, []params.CbftNode)
- func MockNode(pk *ecdsa.PrivateKey, sk *bls.SecretKey, nodes []params.CbftNode, ...) *TestCBFT
- func MockValidator(pk *ecdsa.PrivateKey, sk *bls.SecretKey, nodes []params.CbftNode, ...) *TestCBFT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 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 ¶
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 NewBlockWithSign ¶
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() *Status 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) 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.
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 ¶
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) AvgLatency ¶
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 ¶
BlockExists is used to query whether the specified block exists in this node.
func (*Cbft) CalcBlockDeadline ¶
CalcBlockDeadline return the deadline of the block.
func (*Cbft) CalcNextBlockTime ¶
CalcNextBlockTime returns the deadline of the next block.
func (*Cbft) ConsensusNodes ¶
ConsensusNodes returns to the list of consensus nodes.
func (*Cbft) CurrentBlock ¶
CurrentBlock get the current lock block.
func (*Cbft) DefaultAvgLatency ¶
DefaultAvgLatency returns the avg latency of default.
func (*Cbft) FastSyncCommitHead ¶
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) GetBlockByHash ¶
GetBlockByHash get the specified block by hash.
func (*Cbft) GetBlockWithoutLock ¶
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) HighestCommitBlockBn ¶
HighestCommitBlockBn returns the highest submitted block number of the current node.
func (*Cbft) HighestLockBlockBn ¶
HighestLockBlockBn returns the highest locked block number of the current node.
func (*Cbft) HighestQCBlockBn ¶
HighestQCBlockBn return the highest QC block number of the current node.
func (*Cbft) InsertChain ¶
InsertChain is used to insert the block into the chain.
func (*Cbft) IsConsensusNode ¶
IsConsensusNode returns whether the current node is a consensus node.
func (*Cbft) IsSignedBySelf ¶
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) 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 ¶
NextBaseBlock is used to calculate the next block.
func (*Cbft) OnBlockQuorumCert ¶
func (cbft *Cbft) OnBlockQuorumCert(id string, msg *protocols.BlockQuorumCert) error
OnBlockQuorumCert handles the message type of BlockQuorumCertMsg.
func (*Cbft) OnCommitError ¶
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 ¶
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) 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) OnShouldSeal ¶
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) Prepare ¶
Prepare implements consensus.Engine, preparing all the consensus fields of the header of running the transactions on top.
func (*Cbft) ReceiveMessage ¶
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 ¶
ReceiveSyncMsg is used to receive messages that are synchronized from other nodes.
Possible message types are:
PrepareBlockVotesMsg/GetLatestStatusMsg/LatestStatusMsg/
func (*Cbft) Seal ¶
func (cbft *Cbft) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error
Seal is used to generate a block, and block data is passed to the execution channel.
func (*Cbft) ShouldSeal ¶
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) SyncBlockQuorumCert ¶
func (*Cbft) SyncPrepareBlock ¶
func (*Cbft) TracingSwitch ¶
TracingSwitch will be abandoned in the future.
func (*Cbft) TrySetHighestQCBlock ¶
func (*Cbft) VerifyHeader ¶
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 ¶
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.
type HandleError ¶
type PublicConsensusAPI ¶
type PublicConsensusAPI struct {
// contains filtered or unexported fields
}
PublicConsensusAPI provides an API to access the PlatON blockchain. It offers only methods that operate on public data that is freely available to anyone.
func NewPublicConsensusAPI ¶
func NewPublicConsensusAPI(engine API) *PublicConsensusAPI
NewPublicConsensusAPI creates a new PlatON blockchain API.
func (*PublicConsensusAPI) ConsensusStatus ¶
func (s *PublicConsensusAPI) ConsensusStatus() *Status
ConsensusStatus returns the status data of the consensus engine.
func (*PublicConsensusAPI) Evidences ¶
func (s *PublicConsensusAPI) Evidences() string
Evidences returns the relevant data of the verification.
func (*PublicConsensusAPI) GetPrepareQC ¶
func (s *PublicConsensusAPI) GetPrepareQC(number uint64) *types.QuorumCert
GetPrepareQC returns the QC certificate corresponding to the blockNumber.
func (*PublicConsensusAPI) GetSchnorrNIZKProve ¶
func (s *PublicConsensusAPI) GetSchnorrNIZKProve() string
type TestCBFT ¶
type TestCBFT struct {
// contains filtered or unexported fields
}
TestCBFT for testing.
func Mock4NodePipe ¶
Mock4NodePipe returns a list of TestCBFT for testing.
func Mock4NodePipe2 ¶
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.
Source Files ¶
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. |