types

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: GPL-3.0 Imports: 19 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
	ErrCbftProtocolVersionMismatch
	ErrNoStatusMsg
	ErrForkedBlock
)

Define error enumeration values related to messages.

View Source
const (
	SignatureLength = 64
)

Variables

This section is empty.

Functions

func EncodeExtra

func EncodeExtra(cbftVersion byte, qc *QuorumCert) ([]byte, error)

EncodeExtra encode cbft 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 added in v1.0.0

func (b *BlockTree) FindBlocksAndQCs(number uint64) ([]*types.Block, []*QuorumCert)

FindBlocksAndQCs find the specified Block and its QC by blockNumber.

func (*BlockTree) FindForkedBlocksAndQCs added in v0.7.3

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

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 added in v1.0.0

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

type CSMsgPool added in v0.7.3

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

func NewCSMsgPool added in v0.7.3

func NewCSMsgPool() *CSMsgPool

func (*CSMsgPool) AddPrepareBlock added in v0.7.3

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

Add prepare block to cache.

func (*CSMsgPool) AddPrepareQC added in v0.7.3

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

Add prepare block to cache.

func (*CSMsgPool) AddPrepareVote added in v0.7.3

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

Add prepare votes to cache.

func (*CSMsgPool) GetPrepareBlock added in v0.7.3

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

Get prepare block and clear it from the cache

func (*CSMsgPool) GetPrepareQC added in v0.7.3

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

Get prepare QC and clear it from the cache

func (*CSMsgPool) GetPrepareVote added in v0.7.3

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

Get prepare vote and clear it from the cache

func (*CSMsgPool) Purge added in v0.7.3

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

type Config

type Config struct {
	Sys    *params.CbftConfig `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 added in v0.7.3

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     enode.IDv0        `json:"nodeID"`
	Node       *enode.Node       `json:"-"`
	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"`
	Signature    Signature       `json:"signature"`
	ValidatorSet *utils.BitArray `json:"validatorSet"`
}

func DecodeExtra

func DecodeExtra(extra []byte) (byte, *QuorumCert, error)

DecodeExtra decode extra data as cbft 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) Len

func (q QuorumCert) Len() int

func (*QuorumCert) String

func (q *QuorumCert) String() 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) NotEmpty added in v1.4.2

func (sig *Signature) NotEmpty() bool

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