evidence

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2022 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package evidence implements recording duplicate blocks and votes for cbft consensus.

Index

Constants

View Source
const (
	DuplicatePrepareBlockType consensus.EvidenceType = 1
	DuplicatePrepareVoteType  consensus.EvidenceType = 2
	DuplicateViewChangeType   consensus.EvidenceType = 3
)
View Source
const (
	// IdentityLength is the expected length of the identity
	IdentityLength = 20
)

Variables

This section is empty.

Functions

func NewBaseEvidencePool

func NewBaseEvidencePool(path string) (*baseEvidencePool, error)

func NewEvidence

func NewEvidence(dupType consensus.EvidenceType, data string) (consensus.Evidence, error)

NewEvidences retrieves the duplicate evidence by parsing string

func NewEvidences

func NewEvidences(data string) (consensus.Evidences, error)

NewEvidences retrieves the duplicate evidence by parsing string

Types

type DuplicatePrepareBlockEvidence

type DuplicatePrepareBlockEvidence struct {
	PrepareA *EvidencePrepare `json:"prepareA"`
	PrepareB *EvidencePrepare `json:"prepareB"`
}

DuplicatePrepareBlockEvidence recording duplicate blocks

func (DuplicatePrepareBlockEvidence) BlockNumber

func (d DuplicatePrepareBlockEvidence) BlockNumber() uint64

func (DuplicatePrepareBlockEvidence) BlsPubKey

func (DuplicatePrepareBlockEvidence) Epoch

func (DuplicatePrepareBlockEvidence) Equal

func (DuplicatePrepareBlockEvidence) Error

func (DuplicatePrepareBlockEvidence) Hash

func (DuplicatePrepareBlockEvidence) NodeID

func (DuplicatePrepareBlockEvidence) Type

func (DuplicatePrepareBlockEvidence) Validate

func (d DuplicatePrepareBlockEvidence) Validate() error

Validate verify the validity of the DuplicatePrepareBlockEvidence the same epoch,viewNumber,blockNumber,nodeId 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:"voteA"`
	VoteB *EvidenceVote `json:"voteB"`
}

DuplicatePrepareVoteEvidence recording duplicate vote

func (DuplicatePrepareVoteEvidence) BlockNumber

func (d DuplicatePrepareVoteEvidence) BlockNumber() uint64

func (DuplicatePrepareVoteEvidence) BlsPubKey

func (DuplicatePrepareVoteEvidence) Epoch

func (DuplicatePrepareVoteEvidence) Equal

func (DuplicatePrepareVoteEvidence) Error

func (DuplicatePrepareVoteEvidence) Hash

func (DuplicatePrepareVoteEvidence) NodeID

func (DuplicatePrepareVoteEvidence) Type

func (DuplicatePrepareVoteEvidence) Validate

func (d DuplicatePrepareVoteEvidence) Validate() error

Validate verify the validity of the duplicatePrepareVoteEvidence the same epoch,viewNumber,blockNumber,nodeId 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:"viewA"`
	ViewB *EvidenceView `json:"viewB"`
}

DuplicateViewChangeEvidence recording duplicate viewChange

func (DuplicateViewChangeEvidence) BlockNumber

func (d DuplicateViewChangeEvidence) BlockNumber() uint64

func (DuplicateViewChangeEvidence) BlsPubKey

func (d DuplicateViewChangeEvidence) BlsPubKey() *bls.PublicKey

func (DuplicateViewChangeEvidence) Epoch

func (DuplicateViewChangeEvidence) Equal

func (DuplicateViewChangeEvidence) Error

func (DuplicateViewChangeEvidence) Hash

func (d DuplicateViewChangeEvidence) Hash() []byte

func (DuplicateViewChangeEvidence) NodeID

func (DuplicateViewChangeEvidence) Type

func (DuplicateViewChangeEvidence) Validate

func (d DuplicateViewChangeEvidence) Validate() error

Validate verify the validity of the duplicateViewChangeEvidence the same epoch,viewNumber,nodeId and different block

func (DuplicateViewChangeEvidence) ValidateMsg

func (d DuplicateViewChangeEvidence) ValidateMsg() bool

func (DuplicateViewChangeEvidence) ViewNumber

func (d DuplicateViewChangeEvidence) ViewNumber() uint64

type EvidenceData

type EvidenceData struct {
	DP []*DuplicatePrepareBlockEvidence `json:"duplicatePrepare"`
	DV []*DuplicatePrepareVoteEvidence  `json:"duplicateVote"`
	DC []*DuplicateViewChangeEvidence   `json:"duplicateViewchange"`
}

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"`
	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(resolvePath func(string) string, 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:"viewNumber"`
	BlockHash    common.Hash      `json:"blockHash"`
	BlockNumber  uint64           `json:"blockNumber"`
	BlockIndex   uint32           `json:"blockIndex"` // The block number of the current ViewNumber proposal, 0....10
	BlockData    common.Hash      `json:"blockData"`
	ValidateNode *EvidenceNode    `json:"validateNode"`
	Signature    ctypes.Signature `json:"signature"`
}

Proposed block carrier.

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:"viewNumber"`
	BlockHash    common.Hash      `json:"blockHash"`
	BlockNumber  uint64           `json:"blockNumber"`
	ValidateNode *EvidenceNode    `json:"validateNode"`
	Signature    ctypes.Signature `json:"signature"`
	BlockEpoch   uint64           `json:"blockEpoch"`
	BlockView    uint64           `json:"blockView"`
}

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:"viewNumber"`
	BlockHash    common.Hash      `json:"blockHash"`
	BlockNumber  uint64           `json:"blockNumber"`
	BlockIndex   uint32           `json:"blockIndex"` // The block number of the current ViewNumber proposal, 0....10
	ValidateNode *EvidenceNode    `json:"validateNode"`
	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 Identity

type Identity string

func (Identity) Bytes

func (id Identity) Bytes() []byte

Bytes gets the string representation of the underlying identity.

type NumberOrderPrepareBlock

type NumberOrderPrepareBlock []*EvidencePrepare

func (*NumberOrderPrepareBlock) Add

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

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

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

Jump to

Keyboard shortcuts

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