Documentation ¶
Index ¶
- Constants
- func EncodeExtra(pbftVersion byte, qc *QuorumCert) ([]byte, error)
- func ErrResp(code ErrCode, format string, v ...interface{}) error
- type BlockTree
- func (b *BlockTree) FindBlockAndQC(hash common.Hash, number uint64) (*types.Block, *QuorumCert)
- func (b *BlockTree) FindBlockByHash(hash common.Hash) *types.Block
- func (b *BlockTree) FindBlocksAndQCs(number uint64) ([]*types.Block, []*QuorumCert)
- func (b *BlockTree) FindForkedBlocksAndQCs(hash common.Hash, number uint64) ([]*types.Block, []*QuorumCert)
- func (b *BlockTree) InsertQCBlock(block *types.Block, qc *QuorumCert) (*types.Block, *types.Block)
- func (b *BlockTree) IsForked(hash common.Hash, number uint64) (common.Hash, uint64, bool)
- func (b *BlockTree) MarshalJSON() ([]byte, error)
- func (b *BlockTree) NewRoot(block *types.Block)
- func (b *BlockTree) PruneBlock(hash common.Hash, number uint64, clearFn func(*types.Block))
- func (b *BlockTree) Reset(root *types.Block, qc *QuorumCert)
- func (b *BlockTree) UnmarshalJSON(input []byte) error
- type CSMsgPool
- func (cs *CSMsgPool) AddPreCommit(blockIndex uint32, validatorIndex uint32, msg *MsgInfo)
- func (cs *CSMsgPool) AddPreCommitQC(epoch, blockNumber uint64, blockIndex uint32, msg *MsgInfo)
- func (cs *CSMsgPool) AddPrepareBlock(blockIndex uint32, msg *MsgInfo)
- func (cs *CSMsgPool) AddPrepareQC(epoch, blockNumber uint64, blockIndex uint32, msg *MsgInfo)
- func (cs *CSMsgPool) AddPrepareVote(blockIndex uint32, validatorIndex uint32, msg *MsgInfo)
- func (cs *CSMsgPool) GetPreCommit(epoch, blockNumber uint64, blockIndex uint32, validatorIndex uint32) *MsgInfo
- func (cs *CSMsgPool) GetPreCommitQC(epoch, blockNumber uint64, index uint32) *MsgInfo
- func (cs *CSMsgPool) GetPrepareBlock(epoch, blockNumber uint64, index uint32) *MsgInfo
- func (cs *CSMsgPool) GetPrepareQC(epoch, blockNumber uint64, index uint32) *MsgInfo
- func (cs *CSMsgPool) GetPrepareVote(epoch, blockNumber uint64, blockIndex uint32, validatorIndex uint32) *MsgInfo
- func (cs *CSMsgPool) Purge(epoch, blockNumber uint64)
- type Config
- type ConsensusMsg
- type ErrCode
- type Message
- type MsgInfo
- type MsgPackage
- type OptionsConfig
- type QuorumCert
- func (q QuorumCert) CannibalizeBytes() ([]byte, error)
- func (q *QuorumCert) HigherBlockView(blockEpoch, blockView uint64) bool
- func (q *QuorumCert) HigherQuorumCert(blockNumber uint64, blockEpoch, blockView uint64) bool
- func (q *QuorumCert) HigherStep(step RoundStepType) bool
- func (q QuorumCert) Len() int
- func (q *QuorumCert) String() string
- type RoundStepType
- type Signature
- type SyncCache
- type ViewChangeQC
- func (v *ViewChangeQC) AppendQuorumCert(viewChangeQC *ViewChangeQuorumCert)
- func (v ViewChangeQC) EqualAll(epoch uint64, viewNumber uint64, blockNumber uint64) error
- func (v ViewChangeQC) ExistViewChange(epoch, viewNumber uint64, blockHash common.Hash) bool
- func (v ViewChangeQC) Len() int
- func (v ViewChangeQC) MaxBlock() (uint64, uint64, uint64, uint64, common.Hash, uint64)
- func (v ViewChangeQC) String() string
- type ViewChangeQuorumCert
- func (q ViewChangeQuorumCert) CannibalizeBytes() ([]byte, error)
- func (q *ViewChangeQuorumCert) Copy() *ViewChangeQuorumCert
- func (q *ViewChangeQuorumCert) HigherBlockView(blockEpoch, blockView uint64) bool
- func (q *ViewChangeQuorumCert) HigherQuorumCert(c *ViewChangeQuorumCert) bool
- func (q ViewChangeQuorumCert) Len() int
- func (q ViewChangeQuorumCert) String() string
Constants ¶
const ( NoneMode = iota // none consensus node PartMode // partial node FullMode // all node )
const ( ErrMsgTooLarge = iota ErrExtraStatusMsg ErrDecode ErrInvalidMsgCode ErrPbftProtocolVersionMismatch ErrNoStatusMsg ErrForkedBlock )
Define error enumeration values related to messages.
const ( RoundStepPrepareBlock = RoundStepType(0x01) // PrepareBlock Step RoundStepPrepareVote = RoundStepType(0x02) // PrepareVote Step RoundStepPreCommit = RoundStepType(0x03) // PreCommit Step )
RoundStepType
const (
SignatureLength = 64
)
Variables ¶
This section is empty.
Functions ¶
func EncodeExtra ¶
func EncodeExtra(pbftVersion byte, qc *QuorumCert) ([]byte, error)
EncodeExtra encode pbft version and `QuorumCert` as extra data.
Types ¶
type BlockTree ¶
type BlockTree struct {
// contains filtered or unexported fields
}
BlockTree used to store blocks that are not currently written to disk, Block of QC, LockQC. Every time you submit to blockTree, it is possible to start QC changes.
func NewBlockTree ¶
func NewBlockTree(root *types.Block, qc *QuorumCert) *BlockTree
func (*BlockTree) FindBlockAndQC ¶
FindBlockAndQC find the specified Block and its QC.
func (*BlockTree) FindBlockByHash ¶
FindBlockByHash find the specified Block by hash.
func (*BlockTree) FindBlocksAndQCs ¶
func (b *BlockTree) FindBlocksAndQCs(number uint64) ([]*types.Block, []*QuorumCert)
FindBlocksAndQCs find the specified Block and its QC by blockNumber.
func (*BlockTree) FindForkedBlocksAndQCs ¶
func (b *BlockTree) FindForkedBlocksAndQCs(hash common.Hash, number uint64) ([]*types.Block, []*QuorumCert)
FindForkedBlockAndQC find the specified Block and its QC.
func (*BlockTree) InsertQCBlock ¶
Insert a Block that has reached the QC state, returns the LockQC, Commit Block based on the height of the inserted Block
func (*BlockTree) MarshalJSON ¶
func (*BlockTree) PruneBlock ¶
Delete invalid branch Block
func (*BlockTree) UnmarshalJSON ¶
type CSMsgPool ¶
type CSMsgPool struct {
// contains filtered or unexported fields
}
func NewCSMsgPool ¶
func NewCSMsgPool() *CSMsgPool
func (*CSMsgPool) AddPreCommit ¶
Add prepare votes to cache.
func (*CSMsgPool) AddPreCommitQC ¶
Add prepare QC to cache.
func (*CSMsgPool) AddPrepareBlock ¶
Add prepare block to cache.
func (*CSMsgPool) AddPrepareQC ¶
Add prepare QC to cache.
func (*CSMsgPool) AddPrepareVote ¶
Add prepare votes to cache.
func (*CSMsgPool) GetPreCommit ¶
func (cs *CSMsgPool) GetPreCommit(epoch, blockNumber uint64, blockIndex uint32, validatorIndex uint32) *MsgInfo
Get prepare vote and clear it from the cache
func (*CSMsgPool) GetPreCommitQC ¶
Get prepare QC and clear it from the cache
func (*CSMsgPool) GetPrepareBlock ¶
Get prepare block and clear it from the cache
func (*CSMsgPool) GetPrepareQC ¶
Get prepare QC and clear it from the cache
type Config ¶
type Config struct { Sys *configs.PbftConfig `json:"sys"` Option *OptionsConfig `json:"option"` }
type ConsensusMsg ¶
type ConsensusMsg interface { EpochNum() uint64 ViewNum() uint64 BlockNum() uint64 NodeIndex() uint32 CannibalizeBytes() ([]byte, error) Sign() []byte SetSign([]byte) }
Consensus message interface, all consensus message types must implement this interface.
type MsgInfo ¶
func NewInnerMsgInfo ¶
type MsgPackage ¶
type MsgPackage struct {
// contains filtered or unexported fields
}
MsgPackage represents a specific message package. It contains the node ID, the message body, and the forwarding mode from the sender.
func NewMsgPackage ¶
func NewMsgPackage(pid string, msg Message, mode uint64) *MsgPackage
Create a new MsgPackage based on params.
func (*MsgPackage) Message ¶
func (m *MsgPackage) Message() Message
func (*MsgPackage) Mode ¶
func (m *MsgPackage) Mode() uint64
func (*MsgPackage) PeerID ¶
func (m *MsgPackage) PeerID() string
type OptionsConfig ¶
type OptionsConfig struct { NodePriKey *ecdsa.PrivateKey `json:"-"` NodeID discover.NodeID `json:"nodeID"` BlsPriKey *bls.SecretKey `json:"-"` WalMode bool `json:"walMode"` PeerMsgQueueSize uint64 `json:"peerMsgQueueSize"` EvidenceDir string `json:"evidenceDir"` MaxPingLatency int64 `json:"maxPingLatency"` // maxPingLatency is the time in milliseconds between Ping and Pong MaxQueuesLimit int64 `json:"maxQueuesLimit"` // The maximum value that a single node can send a message. BlacklistDeadline int64 `json:"blacklistDeadline"` // Blacklist expiration time. unit: minute. Period uint64 `json:"period"` Amount uint32 `json:"amount"` }
type QuorumCert ¶
type QuorumCert struct { Epoch uint64 `json:"epoch"` ViewNumber uint64 `json:"viewNumber"` BlockHash common.Hash `json:"blockHash"` BlockNumber uint64 `json:"blockNumber"` BlockIndex uint32 `json:"blockIndex"` Step RoundStepType `json:"step"` Signature Signature `json:"signature"` ValidatorSet *utils.BitArray `json:"validatorSet"` }
func DecodeExtra ¶
func DecodeExtra(extra []byte) (byte, *QuorumCert, error)
DecodeExtra decode extra data as pbft version and `QuorumCert`.
func (QuorumCert) CannibalizeBytes ¶
func (q QuorumCert) CannibalizeBytes() ([]byte, error)
func (*QuorumCert) HigherBlockView ¶
func (q *QuorumCert) HigherBlockView(blockEpoch, blockView uint64) bool
if the two quorumCert have the same blockNumber
func (*QuorumCert) HigherQuorumCert ¶
func (q *QuorumCert) HigherQuorumCert(blockNumber uint64, blockEpoch, blockView uint64) bool
func (*QuorumCert) HigherStep ¶
func (q *QuorumCert) HigherStep(step RoundStepType) bool
func (QuorumCert) Len ¶
func (q QuorumCert) Len() int
func (*QuorumCert) String ¶
func (q *QuorumCert) String() string
type RoundStepType ¶
type RoundStepType uint32 // These must be numeric, ordered.
RoundStepType enumerates the state of the consensus state machine
func (RoundStepType) IsValid ¶
func (rs RoundStepType) IsValid() bool
IsValid returns true if the step is valid, false if unknown/undefined.
type Signature ¶
type Signature [SignatureLength]byte
func BytesToSignature ¶
func (Signature) MarshalText ¶
MarshalText returns the hex representation of a.
func (*Signature) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Signature) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type SyncCache ¶
type SyncCache struct {
// contains filtered or unexported fields
}
func NewSyncCache ¶
func (*SyncCache) AddOrReplace ¶
type ViewChangeQC ¶
type ViewChangeQC struct {
QCs []*ViewChangeQuorumCert `json:"qcs"`
}
func (*ViewChangeQC) AppendQuorumCert ¶
func (v *ViewChangeQC) AppendQuorumCert(viewChangeQC *ViewChangeQuorumCert)
func (ViewChangeQC) EqualAll ¶
func (v ViewChangeQC) EqualAll(epoch uint64, viewNumber uint64, blockNumber uint64) error
func (ViewChangeQC) ExistViewChange ¶
func (v ViewChangeQC) ExistViewChange(epoch, viewNumber uint64, blockHash common.Hash) bool
func (ViewChangeQC) Len ¶
func (v ViewChangeQC) Len() int
func (ViewChangeQC) String ¶
func (v ViewChangeQC) String() string
type ViewChangeQuorumCert ¶
type ViewChangeQuorumCert struct { Epoch uint64 `json:"epoch"` ViewNumber uint64 `json:"viewNumber"` BlockHash common.Hash `json:"blockHash"` BlockNumber uint64 `json:"blockNumber"` BlockEpoch uint64 `json:"blockEpoch"` BlockViewNumber uint64 `json:"blockViewNumber"` Signature Signature `json:"signature"` ValidatorSet *utils.BitArray `json:"validatorSet"` }
func (ViewChangeQuorumCert) CannibalizeBytes ¶
func (q ViewChangeQuorumCert) CannibalizeBytes() ([]byte, error)
func (*ViewChangeQuorumCert) Copy ¶
func (q *ViewChangeQuorumCert) Copy() *ViewChangeQuorumCert
func (*ViewChangeQuorumCert) HigherBlockView ¶
func (q *ViewChangeQuorumCert) HigherBlockView(blockEpoch, blockView uint64) bool
if the two quorumCert have the same blockNumber
func (*ViewChangeQuorumCert) HigherQuorumCert ¶
func (q *ViewChangeQuorumCert) HigherQuorumCert(c *ViewChangeQuorumCert) bool
func (ViewChangeQuorumCert) Len ¶
func (q ViewChangeQuorumCert) Len() int
func (ViewChangeQuorumCert) String ¶
func (q ViewChangeQuorumCert) String() string