cbft

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: GPL-3.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 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, []discover.NodeID)

NewEngineManager returns a list of EngineManager and NodeID.

Types

type API added in v0.7.1

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 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)
	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.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 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.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 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() ([]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 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) 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) NodeID added in v0.7.1

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

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{})

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{}) 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() *Status

Status returns the status data of the consensus engine.

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

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

func NewPublicConsensusAPI(engine API) *PublicConsensusAPI

NewPublicConsensusAPI creates a new PlatON blockchain API.

func (*PublicConsensusAPI) ConsensusStatus added in v0.7.1

func (s *PublicConsensusAPI) ConsensusStatus() *Status

ConsensusStatus returns the status data of the consensus engine.

func (*PublicConsensusAPI) Evidences added in v0.7.1

func (s *PublicConsensusAPI) Evidences() string

Evidences returns the relevant data of the verification.

func (*PublicConsensusAPI) GetPrepareQC added in v0.7.1

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

GetPrepareQC returns the QC certificate corresponding to the blockNumber.

func (*PublicConsensusAPI) GetSchnorrNIZKProve added in v0.7.3

func (s *PublicConsensusAPI) GetSchnorrNIZKProve() string

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