pbft

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 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("pbft engine busy")
	ErrorNotRunning   = errors.New("pbft is not running")
	ErrorNotValidator = errors.New("current node not a validator")
	ErrorTimeout      = errors.New("timeout")
)

Functions

func CreateBackend

func CreateBackend(engine *Pbft, nodes []configs.PbftNode) (*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 *Pbft, nodes []configs.PbftNode) (*core.BlockChain, *core.BlockChainCache, *core.TxPool, consensus.Agency)

CreateValidatorBackend returns a new ValidatorBackend for testing.

func GenerateKeys

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

GenerateKeys returns the public and private key pair for testing.

func GeneratePbftNode

func GeneratePbftNode(num int) ([]*ecdsa.PrivateKey, []*bls.SecretKey, []configs.PbftNode)

GeneratePbftNode returns a list of PbftNode 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 *TestPBFT) *types.Block

NewBlock returns a new block for testing.

func NewEngineManager

func NewEngineManager(pbfts []*TestPBFT) ([]*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)
	SendPreCommit(block *types.Block, vote *protocols.PreCommit)
	GetViewChangeQC(epoch uint64, blockNumber uint64, viewNumber uint64) (*ctypes.ViewChangeQC, error)

	Close()
}

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

func NewBridge

func NewBridge(ctx *node.ServiceContext, pbft *Pbft) (Bridge, error)

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

type HandleError

type HandleError interface {
	error
	AuthFailed() bool
}

type Pbft

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

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

func CreatePBFT

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

CreatePBFT returns a new PBFT for testing.

func New

func New(sysConfig *configs.PbftConfig, optConfig *ctypes.OptionsConfig, eventMux *event.TypeMux, ctx *node.ServiceContext) *Pbft

New returns a new PBFT.

func (*Pbft) APIs

func (pbft *Pbft) APIs(chain consensus.ChainReader) []rpc.API

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

func (*Pbft) Author

func (pbft *Pbft) Author(header *types.Header) (common.Address, error)

Author returns the current node's Author.

func (*Pbft) AvgLatency

func (pbft *Pbft) 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 (*Pbft) BlockExists

func (pbft *Pbft) BlockExists(blockNumber uint64, blockHash common.Hash) error

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

func (*Pbft) CalCurrentProposer

func (pbft *Pbft) CalCurrentProposer(numValidators int) uint64

func (*Pbft) CalCurrentProposerWithBlockNumber

func (pbft *Pbft) CalCurrentProposerWithBlockNumber(blockNumber uint64, numValidators int) uint64

func (*Pbft) CalcBlockDeadline

func (pbft *Pbft) CalcBlockDeadline(timePoint time.Time) time.Time

CalcBlockDeadline return the deadline of the block.

func (*Pbft) CalcNextBlockTime

func (pbft *Pbft) CalcNextBlockTime(blockTime time.Time) time.Time

CalcNextBlockTime returns the deadline of the next block.

func (*Pbft) Close

func (pbft *Pbft) Close() error

Close turns off the consensus engine.

func (*Pbft) Config

func (pbft *Pbft) Config() *ctypes.Config

Config returns the configuration information of the consensus engine.

func (*Pbft) ConsensusNodes

func (pbft *Pbft) ConsensusNodes() ([]discover.NodeID, error)

ConsensusNodes returns to the list of consensus nodes.

func (*Pbft) CurrentBlock

func (pbft *Pbft) CurrentBlock() *types.Block

CurrentBlock get the current lock block.

func (*Pbft) DealBlock

func (pbft *Pbft) DealBlock(block *types.Block) (b *types.Block, e error)

func (*Pbft) DecodeExtra

func (pbft *Pbft) DecodeExtra(extra []byte) (common.Hash, uint64, error)

func (*Pbft) DefaultAvgLatency

func (pbft *Pbft) DefaultAvgLatency() time.Duration

DefaultAvgLatency returns the avg latency of default.

func (*Pbft) Evidences

func (pbft *Pbft) Evidences() string

Evidences implements functions in API.

func (*Pbft) FastSyncCommitHead

func (pbft *Pbft) FastSyncCommitHead(block *types.Block) error

FastSyncCommitHead processes logic that performs fast synchronization.

func (*Pbft) Finalize

func (pbft *Pbft) 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 (*Pbft) GetBlock

func (pbft *Pbft) GetBlock(hash common.Hash, number uint64) *types.Block

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

func (*Pbft) GetBlockByHash

func (pbft *Pbft) GetBlockByHash(hash common.Hash) *types.Block

GetBlockByHash get the specified block by hash.

func (*Pbft) GetBlockByHashAndNum

func (pbft *Pbft) GetBlockByHashAndNum(hash common.Hash, number uint64) *types.Block

GetBlockByHash get the specified block by hash and number.

func (*Pbft) GetBlockWithoutLock

func (pbft *Pbft) GetBlockWithoutLock(hash common.Hash, number uint64) *types.Block

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

func (*Pbft) GetPrepareQC

func (pbft *Pbft) GetPrepareQC(number uint64) *ctypes.QuorumCert

GetPrepareQC returns the QC data of the specified block height.

func (*Pbft) GetSchnorrNIZKProve

func (pbft *Pbft) GetSchnorrNIZKProve() (*bls.SchnorrProof, error)

func (*Pbft) HasBlock

func (pbft *Pbft) HasBlock(hash common.Hash, number uint64) bool

HasBlock check if the specified block exists in block tree.

func (*Pbft) HighestCommitBlockBn

func (pbft *Pbft) HighestCommitBlockBn() (uint64, common.Hash)

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

func (*Pbft) HighestLockBlockBn

func (pbft *Pbft) HighestLockBlockBn() (uint64, common.Hash)

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

func (*Pbft) HighestPreCommitQCBlockBn

func (pbft *Pbft) HighestPreCommitQCBlockBn() (uint64, common.Hash)

HighestPreCommitQCBlockBn return the highest PreCommit QC block number of the current node.

func (*Pbft) HighestQCBlockBn

func (pbft *Pbft) HighestQCBlockBn() (uint64, common.Hash)

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

func (*Pbft) InsertChain

func (pbft *Pbft) InsertChain(block *types.Block) error

InsertChain is used to insert the block into the chain.

func (*Pbft) IsAddBlockTimeOver

func (pbft *Pbft) IsAddBlockTimeOver() bool

func (*Pbft) IsConsensusNode

func (pbft *Pbft) IsConsensusNode() bool

IsConsensusNode returns whether the current node is a consensus node.

func (*Pbft) IsSignedBySelf

func (pbft *Pbft) 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 (*Pbft) LatestStatus

func (pbft *Pbft) LatestStatus() (v *protocols.GetLatestStatus)

LatestStatus returns latest status.

func (*Pbft) LoadWal

func (pbft *Pbft) LoadWal() (err error)

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

func (*Pbft) MissingPreCommit

func (pbft *Pbft) MissingPreCommit() (v *protocols.GetPreCommit, err error)

MissingPreCommit returns missing preCommit.

func (*Pbft) MissingPrepareVote

func (pbft *Pbft) MissingPrepareVote() (v *protocols.GetPrepareVote, err error)

MissingPrepareVote returns missing vote.

func (*Pbft) MissingViewChangeNodes

func (pbft *Pbft) 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 (*Pbft) NextBaseBlock

func (pbft *Pbft) NextBaseBlock() *types.Block

NextBaseBlock is used to calculate the next block.

func (*Pbft) NodeID

func (pbft *Pbft) NodeID() discover.NodeID

NodeID returns the ID value of the current node

func (*Pbft) OnBlockPreCommitQuorumCert

func (pbft *Pbft) OnBlockPreCommitQuorumCert(id string, msg *protocols.BlockPreCommitQuorumCert) error

OnBlockQuorumCert handles the message type of BlockQuorumCertMsg.

func (*Pbft) OnBlockQuorumCert

func (pbft *Pbft) OnBlockQuorumCert(id string, msg *protocols.BlockQuorumCert) error

OnBlockQuorumCert handles the message type of BlockQuorumCertMsg.

func (*Pbft) OnCommitError

func (pbft *Pbft) OnCommitError(err error)

Asynchronous processing of errors generated by the submission block

func (*Pbft) OnGetBlockPreCommitQuorumCert

func (pbft *Pbft) OnGetBlockPreCommitQuorumCert(id string, msg *protocols.GetBlockPreCommitQuorumCert) error

OnGetBlockQuorumCert handles the message type of GetBlockQuorumCertMsg.

func (*Pbft) OnGetBlockQuorumCert

func (pbft *Pbft) OnGetBlockQuorumCert(id string, msg *protocols.GetBlockQuorumCert) error

OnGetBlockQuorumCert handles the message type of GetBlockQuorumCertMsg.

func (*Pbft) OnGetLatestStatus

func (pbft *Pbft) 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 (*Pbft) OnGetPreCommit

func (pbft *Pbft) OnGetPreCommit(id string, msg *protocols.GetPreCommit) error

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

func (*Pbft) OnGetPrepareBlock

func (pbft *Pbft) OnGetPrepareBlock(id string, msg *protocols.GetPrepareBlock) error

OnGetPrepareBlock handles the message type of GetPrepareBlockMsg.

func (*Pbft) OnGetPrepareVote

func (pbft *Pbft) 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 (*Pbft) OnGetQCBlockList

func (pbft *Pbft) OnGetQCBlockList(id string, msg *protocols.GetQCBlockList) error

OnGetQCBlockList handles the message type of GetQCBlockListMsg.

func (*Pbft) OnGetViewChange

func (pbft *Pbft) 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 (*Pbft) OnInsertQCBlock

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

OnInsertQCBlock performs security rule verification, view switching.

func (*Pbft) OnLatestStatus

func (pbft *Pbft) OnLatestStatus(id string, msg *protocols.LatestStatus) error

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

func (*Pbft) OnPong

func (pbft *Pbft) OnPong(nodeID string, netLatency int64) error

OnPong is used to receive the average delay time.

func (*Pbft) OnPreCommit

func (pbft *Pbft) OnPreCommit(id string, msg *protocols.PreCommit) error

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

func (*Pbft) OnPreCommits

func (pbft *Pbft) OnPreCommits(id string, msg *protocols.PreCommits) error

OnPrepareVotes handling response from GetPrepareVote response.

func (*Pbft) OnPrepareBlock

func (pbft *Pbft) OnPrepareBlock(id string, msg *protocols.PrepareBlock) error

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

func (*Pbft) OnPrepareBlockHash

func (pbft *Pbft) 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 (*Pbft) OnPrepareVote

func (pbft *Pbft) OnPrepareVote(id string, msg *protocols.PrepareVote) error

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

func (*Pbft) OnPrepareVotes

func (pbft *Pbft) OnPrepareVotes(id string, msg *protocols.PrepareVotes) error

OnPrepareVotes handling response from GetPrepareVote response.

func (*Pbft) OnSeal

func (pbft *Pbft) 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 (*Pbft) OnShouldSeal

func (pbft *Pbft) OnShouldSeal(result chan error)

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

func (*Pbft) OnViewChange

func (pbft *Pbft) OnViewChange(id string, msg *protocols.ViewChange) error

OnViewChange performs security rule verification, view switching.

func (*Pbft) OnViewChangeQuorumCert

func (pbft *Pbft) OnViewChangeQuorumCert(id string, msg *protocols.ViewChangeQuorumCert) error

OnViewChangeQuorumCert handles the message type of ViewChangeQuorumCertMsg.

func (*Pbft) OnViewChanges

func (pbft *Pbft) OnViewChanges(id string, msg *protocols.ViewChanges) error

OnViewChanges handles the message type of ViewChangesMsg.

func (*Pbft) OnViewTimeout

func (pbft *Pbft) OnViewTimeout()

OnViewTimeout performs timeout logic for view.

func (*Pbft) Pause

func (pbft *Pbft) Pause()

func (*Pbft) Prepare

func (pbft *Pbft) 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 (*Pbft) Protocols

func (pbft *Pbft) Protocols() []p2p.Protocol

Protocols return consensus engine to provide protocol information.

func (*Pbft) ReceiveMessage

func (pbft *Pbft) 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 PBFT message queue and there is a loop that will distribute the incoming message.

func (*Pbft) ReceiveSyncMsg

func (pbft *Pbft) 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 (*Pbft) Resume

func (pbft *Pbft) Resume()

func (*Pbft) Seal

func (pbft *Pbft) 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 (*Pbft) SealHash

func (pbft *Pbft) SealHash(header *types.Header) common.Hash

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

func (*Pbft) ShouldSeal

func (pbft *Pbft) ShouldSeal(curTime time.Time) (bool, error)

ShouldSeal check if we can seal block.

func (*Pbft) Start

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

Start starts consensus engine.

func (*Pbft) Status

func (pbft *Pbft) Status() []byte

Status returns the status data of the consensus engine.

func (*Pbft) SyncBlockPreCommitQuorumCert

func (pbft *Pbft) SyncBlockPreCommitQuorumCert(id string, blockNumber uint64, blockHash common.Hash, blockIndex uint32)

func (*Pbft) SyncBlockQuorumCert

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

func (*Pbft) SyncPrepareBlock

func (pbft *Pbft) SyncPrepareBlock(id string, epoch uint64, blockNumber uint64, blockIndex uint32, viewNumber uint64)

func (*Pbft) Syncing

func (pbft *Pbft) Syncing() bool

func (*Pbft) TracingSwitch

func (pbft *Pbft) TracingSwitch(flag int8)

TracingSwitch will be abandoned in the future.

func (*Pbft) TrySetHighestLockBlock

func (pbft *Pbft) TrySetHighestLockBlock(block *types.Block)

func (*Pbft) TrySetHighestPreCommitQCBlock

func (pbft *Pbft) TrySetHighestPreCommitQCBlock(block *types.Block)

func (*Pbft) TrySetHighestQCBlock

func (pbft *Pbft) TrySetHighestQCBlock(block *types.Block)

func (*Pbft) VerifyHeader

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

VerifyHeader verify the validity of the block header.

func (*Pbft) VerifyHeaders

func (pbft *Pbft) 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 (*Pbft) VerifySeal

func (pbft *Pbft) 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 PublicAdminConsensusAPI

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

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

func NewPublicAdminConsensusAPI

func NewPublicAdminConsensusAPI(engine API) *PublicAdminConsensusAPI

NewPublicAdminConsensusAPI creates a new PhoenixChain blockchain API.

func (*PublicAdminConsensusAPI) GetSchnorrNIZKProve

func (s *PublicAdminConsensusAPI) GetSchnorrNIZKProve() string

type PublicDebugConsensusAPI

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

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

func NewDebugConsensusAPI

func NewDebugConsensusAPI(engine API) *PublicDebugConsensusAPI

NewDebugConsensusAPI creates a new PhoenixChain blockchain API.

func (*PublicDebugConsensusAPI) ConsensusStatus

func (s *PublicDebugConsensusAPI) ConsensusStatus() *Status

ConsensusStatus returns the status data of the consensus engine.

func (*PublicDebugConsensusAPI) GetPrepareQC

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

GetPrepareQC returns the QC certificate corresponding to the blockNumber.

type PublicPhoenixchainConsensusAPI

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

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

func NewPublicPhoenixchainConsensusAPI

func NewPublicPhoenixchainConsensusAPI(engine API) *PublicPhoenixchainConsensusAPI

NewPublicPhoenixchainConsensusAPI creates a new PhoenixChain blockchain API.

func (*PublicPhoenixchainConsensusAPI) Evidences

func (s *PublicPhoenixchainConsensusAPI) 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 TestPBFT

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

TestPBFT for testing.

func Mock4NodePipe

func Mock4NodePipe(start bool) []*TestPBFT

Mock4NodePipe returns a list of TestPBFT for testing.

func Mock4NodePipe2

func Mock4NodePipe2(start bool) ([]*TestPBFT, []configs.PbftNode)

Mock4NodePipe returns a list of TestPBFT for testing.

func MockNode

func MockNode(pk *ecdsa.PrivateKey, sk *bls.SecretKey, nodes []configs.PbftNode, period uint64, amount uint32) *TestPBFT

MockNode returns a new TestPBFT for testing.

func MockValidator

func MockValidator(pk *ecdsa.PrivateKey, sk *bls.SecretKey, nodes []configs.PbftNode, period uint64, amount uint32) *TestPBFT

MockValidator returns a new TestPBFT for testing.

func (*TestPBFT) Start

func (t *TestPBFT) Start() error

Start turns on the pbft for testing.

Directories

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

Jump to

Keyboard shortcuts

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