Documentation ¶
Overview ¶
Package evidence implements recording duplicate blocks and votes for cbft consensus.
Index ¶
- Constants
- func NewBaseEvidencePool(path string) (*baseEvidencePool, error)
- func NewEvidence(dupType consensus.EvidenceType, data string) (consensus.Evidence, error)
- func NewEvidences(data string) (consensus.Evidences, error)
- type DuplicatePrepareBlockEvidence
- func (d DuplicatePrepareBlockEvidence) Address() common.Address
- func (d DuplicatePrepareBlockEvidence) BlockNumber() uint64
- func (d DuplicatePrepareBlockEvidence) Epoch() uint64
- func (d DuplicatePrepareBlockEvidence) Equal(ev consensus.Evidence) bool
- func (d DuplicatePrepareBlockEvidence) Error() string
- func (d DuplicatePrepareBlockEvidence) Hash() []byte
- func (d DuplicatePrepareBlockEvidence) Type() consensus.EvidenceType
- func (d DuplicatePrepareBlockEvidence) Validate() error
- func (d DuplicatePrepareBlockEvidence) ValidateMsg() bool
- func (d DuplicatePrepareBlockEvidence) ViewNumber() uint64
- type DuplicatePrepareVoteEvidence
- func (d DuplicatePrepareVoteEvidence) Address() common.Address
- func (d DuplicatePrepareVoteEvidence) BlockNumber() uint64
- func (d DuplicatePrepareVoteEvidence) Epoch() uint64
- func (d DuplicatePrepareVoteEvidence) Equal(ev consensus.Evidence) bool
- func (d DuplicatePrepareVoteEvidence) Error() string
- func (d DuplicatePrepareVoteEvidence) Hash() []byte
- func (d DuplicatePrepareVoteEvidence) Type() consensus.EvidenceType
- func (d DuplicatePrepareVoteEvidence) Validate() error
- func (d DuplicatePrepareVoteEvidence) ValidateMsg() bool
- func (d DuplicatePrepareVoteEvidence) ViewNumber() uint64
- type DuplicateViewChangeEvidence
- func (d DuplicateViewChangeEvidence) Address() common.Address
- func (d DuplicateViewChangeEvidence) BlockNumber() uint64
- func (d DuplicateViewChangeEvidence) Epoch() uint64
- func (d DuplicateViewChangeEvidence) Equal(ev consensus.Evidence) bool
- func (d DuplicateViewChangeEvidence) Error() string
- func (d DuplicateViewChangeEvidence) Hash() []byte
- func (d DuplicateViewChangeEvidence) Type() consensus.EvidenceType
- func (d DuplicateViewChangeEvidence) Validate() error
- func (d DuplicateViewChangeEvidence) ValidateMsg() bool
- func (d DuplicateViewChangeEvidence) ViewNumber() uint64
- type EvidenceData
- type EvidenceNode
- type EvidencePool
- type EvidencePrepare
- type EvidenceView
- type EvidenceVote
- type Identity
- type NumberOrderPrepareBlock
- type NumberOrderPrepareVote
- type NumberOrderViewChange
- type PrepareBlockEvidence
- type PrepareVoteEvidence
- type ViewChangeEvidence
Constants ¶
const ( DuplicatePrepareBlockType consensus.EvidenceType = 1 DuplicatePrepareVoteType consensus.EvidenceType = 2 DuplicateViewChangeType consensus.EvidenceType = 3 )
const (
// IdentityLength is the expected length of the identity
IdentityLength = 20
)
Variables ¶
This section is empty.
Functions ¶
func NewBaseEvidencePool ¶
func NewEvidence ¶
NewEvidences retrieves the duplicate evidence by parsing string
Types ¶
type DuplicatePrepareBlockEvidence ¶
type DuplicatePrepareBlockEvidence struct { PrepareA *EvidencePrepare `json:"prepare_a"` PrepareB *EvidencePrepare `json:"prepare_b"` }
DuplicatePrepareBlockEvidence recording duplicate blocks
func (DuplicatePrepareBlockEvidence) Address ¶
func (d DuplicatePrepareBlockEvidence) Address() common.Address
func (DuplicatePrepareBlockEvidence) BlockNumber ¶
func (d DuplicatePrepareBlockEvidence) BlockNumber() uint64
func (DuplicatePrepareBlockEvidence) Epoch ¶
func (d DuplicatePrepareBlockEvidence) Epoch() uint64
func (DuplicatePrepareBlockEvidence) Equal ¶
func (d DuplicatePrepareBlockEvidence) Equal(ev consensus.Evidence) bool
func (DuplicatePrepareBlockEvidence) Error ¶
func (d DuplicatePrepareBlockEvidence) Error() string
func (DuplicatePrepareBlockEvidence) Hash ¶
func (d DuplicatePrepareBlockEvidence) Hash() []byte
func (DuplicatePrepareBlockEvidence) Type ¶
func (d DuplicatePrepareBlockEvidence) Type() consensus.EvidenceType
func (DuplicatePrepareBlockEvidence) Validate ¶
func (d DuplicatePrepareBlockEvidence) Validate() error
Validate verify the validity of the DuplicatePrepareBlockEvidence the same epoch,viewNumber,blockNumber,node address and different blockHash
func (DuplicatePrepareBlockEvidence) ValidateMsg ¶
func (d DuplicatePrepareBlockEvidence) ValidateMsg() bool
func (DuplicatePrepareBlockEvidence) ViewNumber ¶
func (d DuplicatePrepareBlockEvidence) ViewNumber() uint64
type DuplicatePrepareVoteEvidence ¶
type DuplicatePrepareVoteEvidence struct { VoteA *EvidenceVote `json:"vote_a"` VoteB *EvidenceVote `json:"vote_b"` }
DuplicatePrepareVoteEvidence recording duplicate vote
func (DuplicatePrepareVoteEvidence) Address ¶
func (d DuplicatePrepareVoteEvidence) Address() common.Address
func (DuplicatePrepareVoteEvidence) BlockNumber ¶
func (d DuplicatePrepareVoteEvidence) BlockNumber() uint64
func (DuplicatePrepareVoteEvidence) Epoch ¶
func (d DuplicatePrepareVoteEvidence) Epoch() uint64
func (DuplicatePrepareVoteEvidence) Equal ¶
func (d DuplicatePrepareVoteEvidence) Equal(ev consensus.Evidence) bool
func (DuplicatePrepareVoteEvidence) Error ¶
func (d DuplicatePrepareVoteEvidence) Error() string
func (DuplicatePrepareVoteEvidence) Hash ¶
func (d DuplicatePrepareVoteEvidence) Hash() []byte
func (DuplicatePrepareVoteEvidence) Type ¶
func (d DuplicatePrepareVoteEvidence) Type() consensus.EvidenceType
func (DuplicatePrepareVoteEvidence) Validate ¶
func (d DuplicatePrepareVoteEvidence) Validate() error
Validate verify the validity of the duplicatePrepareVoteEvidence the same epoch,viewNumber,blockNumber,node address and different blockHash
func (DuplicatePrepareVoteEvidence) ValidateMsg ¶
func (d DuplicatePrepareVoteEvidence) ValidateMsg() bool
func (DuplicatePrepareVoteEvidence) ViewNumber ¶
func (d DuplicatePrepareVoteEvidence) ViewNumber() uint64
type DuplicateViewChangeEvidence ¶
type DuplicateViewChangeEvidence struct { ViewA *EvidenceView `json:"view_a"` ViewB *EvidenceView `json:"view_b"` }
DuplicateViewChangeEvidence recording duplicate viewChange
func (DuplicateViewChangeEvidence) Address ¶
func (d DuplicateViewChangeEvidence) Address() common.Address
func (DuplicateViewChangeEvidence) BlockNumber ¶
func (d DuplicateViewChangeEvidence) BlockNumber() uint64
func (DuplicateViewChangeEvidence) Epoch ¶
func (d DuplicateViewChangeEvidence) Epoch() uint64
func (DuplicateViewChangeEvidence) Equal ¶
func (d DuplicateViewChangeEvidence) Equal(ev consensus.Evidence) bool
func (DuplicateViewChangeEvidence) Error ¶
func (d DuplicateViewChangeEvidence) Error() string
func (DuplicateViewChangeEvidence) Hash ¶
func (d DuplicateViewChangeEvidence) Hash() []byte
func (DuplicateViewChangeEvidence) Type ¶
func (d DuplicateViewChangeEvidence) Type() consensus.EvidenceType
func (DuplicateViewChangeEvidence) Validate ¶
func (d DuplicateViewChangeEvidence) Validate() error
Validate verify the validity of the duplicateViewChangeEvidence the same epoch,viewNumber,blockNumber,node address and different blockHash
func (DuplicateViewChangeEvidence) ValidateMsg ¶
func (d DuplicateViewChangeEvidence) ValidateMsg() bool
func (DuplicateViewChangeEvidence) ViewNumber ¶
func (d DuplicateViewChangeEvidence) ViewNumber() uint64
type EvidenceData ¶
type EvidenceData struct { DP []*DuplicatePrepareBlockEvidence `json:"duplicate_prepare"` DV []*DuplicatePrepareVoteEvidence `json:"duplicate_vote"` DC []*DuplicateViewChangeEvidence `json:"duplicate_viewchange"` }
EvidenceData encapsulate externally visible duplicate data
func ClassifyEvidence ¶
func ClassifyEvidence(evds consensus.Evidences) *EvidenceData
ClassifyEvidence tries to convert evidence list to evidenceData
func NewEvidenceData ¶
func NewEvidenceData() *EvidenceData
type EvidenceNode ¶
type EvidenceNode struct { Index uint32 `json:"index"` Address common.Address `json:"address"` NodeID discover.NodeID `json:"NodeID"` BlsPubKey *bls.PublicKey `json:"blsPubKey"` }
EvidenceNode mainly used to save node BlsPubKey
func NewEvidenceNode ¶
func NewEvidenceNode(node *cbfttypes.ValidateNode) *EvidenceNode
func (*EvidenceNode) Verify ¶
func (vn *EvidenceNode) Verify(data, sign []byte) error
bls verifies signature
type EvidencePool ¶
type EvidencePool interface { consensus.EvidencePool AddPrepareBlock(pb *protocols.PrepareBlock, node *cbfttypes.ValidateNode) error AddPrepareVote(pv *protocols.PrepareVote, node *cbfttypes.ValidateNode) error AddViewChange(vc *protocols.ViewChange, node *cbfttypes.ValidateNode) error }
EvidencePool encapsulates functions required to record duplicate blocks and votes.
func NewEvidencePool ¶
func NewEvidencePool(ctx *node.ServiceContext, evidenceDir string) (EvidencePool, error)
NewEvidencePool creates a new baseEvidencePool to record duplicate blocks and votes.
type EvidencePrepare ¶
type EvidencePrepare struct { Epoch uint64 `json:"epoch"` ViewNumber uint64 `json:"view_number"` BlockHash common.Hash `json:"block_hash"` BlockNumber uint64 `json:"block_number"` BlockIndex uint32 `json:"block_index"` // The block number of the current ViewNumber proposal, 0....10 ValidateNode *EvidenceNode `json:"validate_node"` Signature ctypes.Signature `json:"signature"` }
Proposed block carrier.
func NewEvidencePrepare ¶
func NewEvidencePrepare(pb *protocols.PrepareBlock, node *cbfttypes.ValidateNode) (*EvidencePrepare, error)
func (*EvidencePrepare) CannibalizeBytes ¶
func (ep *EvidencePrepare) CannibalizeBytes() ([]byte, error)
func (*EvidencePrepare) Verify ¶
func (ep *EvidencePrepare) Verify() error
type EvidenceView ¶
type EvidenceView struct { Epoch uint64 `json:"epoch"` ViewNumber uint64 `json:"view_number"` BlockHash common.Hash `json:"block_hash"` BlockNumber uint64 `json:"block_number"` ValidateNode *EvidenceNode `json:"validate_node"` Signature ctypes.Signature `json:"signature"` BlockEpoch uint64 `json:"block_epoch"` BlockView uint64 `json:"block_view"` }
func NewEvidenceView ¶
func NewEvidenceView(vc *protocols.ViewChange, node *cbfttypes.ValidateNode) (*EvidenceView, error)
func (*EvidenceView) CannibalizeBytes ¶
func (ev *EvidenceView) CannibalizeBytes() ([]byte, error)
func (*EvidenceView) Verify ¶
func (ev *EvidenceView) Verify() error
type EvidenceVote ¶
type EvidenceVote struct { Epoch uint64 `json:"epoch"` ViewNumber uint64 `json:"view_number"` BlockHash common.Hash `json:"block_hash"` BlockNumber uint64 `json:"block_number"` BlockIndex uint32 `json:"block_index"` // The block number of the current ViewNumber proposal, 0....10 ValidateNode *EvidenceNode `json:"validate_node"` Signature ctypes.Signature `json:"signature"` }
func NewEvidenceVote ¶
func NewEvidenceVote(pv *protocols.PrepareVote, node *cbfttypes.ValidateNode) (*EvidenceVote, error)
func (*EvidenceVote) CannibalizeBytes ¶
func (ev *EvidenceVote) CannibalizeBytes() ([]byte, error)
func (*EvidenceVote) Verify ¶
func (ev *EvidenceVote) Verify() error
type NumberOrderPrepareBlock ¶
type NumberOrderPrepareBlock []*EvidencePrepare
func (*NumberOrderPrepareBlock) Add ¶
func (opb *NumberOrderPrepareBlock) Add(pb *EvidencePrepare) error
func (NumberOrderPrepareBlock) Len ¶
func (opb NumberOrderPrepareBlock) Len() int
func (NumberOrderPrepareBlock) Less ¶
func (opb NumberOrderPrepareBlock) Less(i, j int) bool
func (NumberOrderPrepareBlock) Swap ¶
func (opb NumberOrderPrepareBlock) Swap(i, j int)
type NumberOrderPrepareVote ¶
type NumberOrderPrepareVote []*EvidenceVote
func (*NumberOrderPrepareVote) Add ¶
func (opv *NumberOrderPrepareVote) Add(pv *EvidenceVote) error
func (NumberOrderPrepareVote) Len ¶
func (opv NumberOrderPrepareVote) Len() int
func (NumberOrderPrepareVote) Less ¶
func (opv NumberOrderPrepareVote) Less(i, j int) bool
func (NumberOrderPrepareVote) Swap ¶
func (opv NumberOrderPrepareVote) Swap(i, j int)
type NumberOrderViewChange ¶
type NumberOrderViewChange []*EvidenceView
func (*NumberOrderViewChange) Add ¶
func (ovc *NumberOrderViewChange) Add(vc *EvidenceView) error
func (NumberOrderViewChange) Len ¶
func (ovc NumberOrderViewChange) Len() int
func (NumberOrderViewChange) Less ¶
func (ovc NumberOrderViewChange) Less(i, j int) bool
func (NumberOrderViewChange) Swap ¶
func (ovc NumberOrderViewChange) Swap(i, j int)
type PrepareBlockEvidence ¶
type PrepareBlockEvidence map[Identity]NumberOrderPrepareBlock
func (PrepareBlockEvidence) Add ¶
func (pbe PrepareBlockEvidence) Add(pb *EvidencePrepare, id Identity) error
Add tries to add prepare block to PrepareBlockEvidence. if the return error is DuplicatePrepareBlockEvidence instructions the prepare is duplicated
func (PrepareBlockEvidence) Clear ¶
func (pbe PrepareBlockEvidence) Clear(epoch uint64, viewNumber uint64)
Clear tries to clear stale intermediate prepare
func (PrepareBlockEvidence) Size ¶
func (pbe PrepareBlockEvidence) Size() int
type PrepareVoteEvidence ¶
type PrepareVoteEvidence map[Identity]NumberOrderPrepareVote
func (PrepareVoteEvidence) Add ¶
func (pve PrepareVoteEvidence) Add(pv *EvidenceVote, id Identity) error
Add tries to add prepare vote to PrepareVoteEvidence. if the return error is DuplicatePrepareVoteEvidence instructions the vote is duplicated
func (PrepareVoteEvidence) Clear ¶
func (pve PrepareVoteEvidence) Clear(epoch uint64, viewNumber uint64)
Clear tries to clear stale intermediate vote
func (PrepareVoteEvidence) Size ¶
func (pve PrepareVoteEvidence) Size() int
type ViewChangeEvidence ¶
type ViewChangeEvidence map[Identity]NumberOrderViewChange
func (ViewChangeEvidence) Add ¶
func (vce ViewChangeEvidence) Add(vc *EvidenceView, id Identity) error
Add tries to add view to ViewChangeEvidence. if the return error is DuplicateViewChangeEvidence instructions the view is duplicated
func (ViewChangeEvidence) Clear ¶
func (vce ViewChangeEvidence) Clear(epoch uint64, viewNumber uint64)
Clear tries to clear stale intermediate view
func (ViewChangeEvidence) Size ¶
func (vce ViewChangeEvidence) Size() int