types

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoneMode = iota // none consensus node
	PartMode        // partial node
	FullMode        // all node
)
View Source
const (
	ErrMsgTooLarge = iota
	ErrExtraStatusMsg
	ErrDecode
	ErrInvalidMsgCode
	ErrPbftProtocolVersionMismatch
	ErrNoStatusMsg
	ErrForkedBlock
)

Define error enumeration values related to messages.

View Source
const (
	RoundStepPrepareBlock = RoundStepType(0x01) // PrepareBlock Step
	RoundStepPrepareVote  = RoundStepType(0x02) // PrepareVote Step
	RoundStepPreCommit    = RoundStepType(0x03) // PreCommit Step

)

RoundStepType

View Source
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.

func ErrResp

func ErrResp(code ErrCode, format string, v ...interface{}) error

Build an error object based on the error code.

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

func (b *BlockTree) FindBlockAndQC(hash common.Hash, number uint64) (*types.Block, *QuorumCert)

FindBlockAndQC find the specified Block and its QC.

func (*BlockTree) FindBlockByHash

func (b *BlockTree) FindBlockByHash(hash common.Hash) *types.Block

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

func (b *BlockTree) InsertQCBlock(block *types.Block, qc *QuorumCert) (*types.Block, *types.Block)

Insert a Block that has reached the QC state, returns the LockQC, Commit Block based on the height of the inserted Block

func (*BlockTree) IsForked

func (b *BlockTree) IsForked(hash common.Hash, number uint64) (common.Hash, uint64, bool)

func (*BlockTree) MarshalJSON

func (b *BlockTree) MarshalJSON() ([]byte, error)

func (*BlockTree) NewRoot

func (b *BlockTree) NewRoot(block *types.Block)

func (*BlockTree) PruneBlock

func (b *BlockTree) PruneBlock(hash common.Hash, number uint64, clearFn func(*types.Block))

Delete invalid branch Block

func (*BlockTree) Reset

func (b *BlockTree) Reset(root *types.Block, qc *QuorumCert)

func (*BlockTree) UnmarshalJSON

func (b *BlockTree) UnmarshalJSON(input []byte) error

type CSMsgPool

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

func NewCSMsgPool

func NewCSMsgPool() *CSMsgPool

func (*CSMsgPool) AddPreCommit

func (cs *CSMsgPool) AddPreCommit(blockIndex uint32, validatorIndex uint32, msg *MsgInfo)

Add prepare votes to cache.

func (*CSMsgPool) AddPreCommitQC

func (cs *CSMsgPool) AddPreCommitQC(epoch, blockNumber uint64, blockIndex uint32, msg *MsgInfo)

Add prepare QC to cache.

func (*CSMsgPool) AddPrepareBlock

func (cs *CSMsgPool) AddPrepareBlock(blockIndex uint32, msg *MsgInfo)

Add prepare block to cache.

func (*CSMsgPool) AddPrepareQC

func (cs *CSMsgPool) AddPrepareQC(epoch, blockNumber uint64, blockIndex uint32, msg *MsgInfo)

Add prepare QC to cache.

func (*CSMsgPool) AddPrepareVote

func (cs *CSMsgPool) AddPrepareVote(blockIndex uint32, validatorIndex uint32, msg *MsgInfo)

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

func (cs *CSMsgPool) GetPreCommitQC(epoch, blockNumber uint64, index uint32) *MsgInfo

Get prepare QC and clear it from the cache

func (*CSMsgPool) GetPrepareBlock

func (cs *CSMsgPool) GetPrepareBlock(epoch, blockNumber uint64, index uint32) *MsgInfo

Get prepare block and clear it from the cache

func (*CSMsgPool) GetPrepareQC

func (cs *CSMsgPool) GetPrepareQC(epoch, blockNumber uint64, index uint32) *MsgInfo

Get prepare QC and clear it from the cache

func (*CSMsgPool) GetPrepareVote

func (cs *CSMsgPool) GetPrepareVote(epoch, blockNumber uint64, blockIndex uint32, validatorIndex uint32) *MsgInfo

Get prepare vote and clear it from the cache

func (*CSMsgPool) Purge

func (cs *CSMsgPool) Purge(epoch, blockNumber uint64)

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 ErrCode

type ErrCode int

func (ErrCode) String

func (e ErrCode) String() string

type Message

type Message interface {
	String() string
	MsgHash() common.Hash
	BHash() common.Hash
}

Message interface, all message structures must implement this interface.

type MsgInfo

type MsgInfo struct {
	Msg    Message
	PeerID string
	Inner  bool
}

func NewInnerMsgInfo

func NewInnerMsgInfo(message Message, id string) *MsgInfo

func NewMsgInfo

func NewMsgInfo(message Message, id string) *MsgInfo

Create a new MsgInfo object.

func (MsgInfo) String

func (m MsgInfo) String() string

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.

func (RoundStepType) String

func (rs RoundStepType) String() string

String returns a string

type Signature

type Signature [SignatureLength]byte

func BytesToSignature

func BytesToSignature(signSlice []byte) Signature

func (*Signature) Bytes

func (sig *Signature) Bytes() []byte

func (Signature) MarshalText

func (sig Signature) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*Signature) SetBytes

func (sig *Signature) SetBytes(signSlice []byte)

func (*Signature) String

func (sig *Signature) String() string

func (*Signature) UnmarshalJSON

func (sig *Signature) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Signature) UnmarshalText

func (sig *Signature) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type SyncCache

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

func NewSyncCache

func NewSyncCache(timeout time.Duration) *SyncCache

func (*SyncCache) Add

func (s *SyncCache) Add(v interface{})

func (*SyncCache) AddOrReplace

func (s *SyncCache) AddOrReplace(v interface{}) bool

func (*SyncCache) Len

func (s *SyncCache) Len() int

func (*SyncCache) Purge

func (s *SyncCache) Purge()

func (*SyncCache) Remove

func (s *SyncCache) Remove(v interface{})

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) MaxBlock

func (v ViewChangeQC) MaxBlock() (uint64, uint64, uint64, uint64, common.Hash, uint64)

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 (*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

Jump to

Keyboard shortcuts

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