cbft

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: GPL-3.0 Imports: 52 Imported by: 0

Documentation

Overview

Package bft implements the BFT consensus engine.

Index

Constants

View Source
const (
	MixMode  = iota // all consensus node
	PartMode        // partial node
	FullMode        // all node
)
View Source
const (
	PrepareBlockMsg           = 0x00
	PrepareVoteMsg            = 0x01
	ViewChangeMsg             = 0x02
	ViewChangeVoteMsg         = 0x03
	ConfirmedPrepareBlockMsg  = 0x04
	GetPrepareVoteMsg         = 0x05
	PrepareVotesMsg           = 0x06
	GetPrepareBlockMsg        = 0x07
	GetHighestPrepareBlockMsg = 0x08
	HighestPrepareBlockMsg    = 0x09

	CBFTStatusMsg       = 0x0a
	PrepareBlockHashMsg = 0x0b
)
View Source
const (
	ErrMsgTooLarge = iota
	ErrDecode
	ErrInvalidMsgCode
	ErrProtocolVersionMismatch
	ErrNetworkIdMismatch
	ErrGenesisBlockMismatch
	ErrNoStatusMsg
	ErrExtraStatusMsg
	ErrSuspendedPeer
)
View Source
const (
	Accept = iota
	Discard
	Cache
)
View Source
const CbftProtocolMaxMsgSize = 10 * 1024 * 1024
View Source
const (
	DEFAULT_FANOUT_VALUE = 5
)
View Source
const (
	LOG_PREFIX = "OPENTRACE"
)
View Source
const (
	NONE = "NONE"
)

Variables

This section is empty.

Functions

func MaxInt64

func MaxInt64(a, b int64) int64

func MaxUInt

func MaxUInt(a, b uint32) uint32

func MessageType

func MessageType(msg interface{}) uint64

func MinInt

func MinInt(a, b int) int

func MinInt64

func MinInt64(a, b int64) int64

func MinUInt

func MinUInt(a, b uint32) uint32

func NewHandler

func NewHandler(cbft *Cbft) *baseHandler

func NewJournal

func NewJournal(path string) (*journal, error)

newTxJournal creates journal object

func NewPrepareVoteSet

func NewPrepareVoteSet(threshold uint32) *prepareVoteSet

func NewRouter

func NewRouter(cbft *Cbft, hd handler) *router

func Rand32Bytes

func Rand32Bytes(n uint32) []byte

func RandBytes

func RandBytes(n int) []byte

func RandInt31n

func RandInt31n(n int32) uint32

func RandIntn

func RandIntn(n int) int

Types

type AcceptStatus

type AcceptStatus int

type Agency

type Agency interface {
	Sign(msg interface{}) error
	VerifySign(msg interface{}) error
	GetLastNumber(blockNumber uint64) uint64
	GetValidator(blockNumber uint64) (*Validators, error)
	IsCandidateNode(nodeID discover.NodeID) bool
}

Agency

func NewInnerAgency

func NewInnerAgency(nodes []discover.Node, chain *core.BlockChain, blocksPerNode, offset int) Agency

func NewStaticAgency

func NewStaticAgency(nodes []discover.Node) Agency

type BitArray

type BitArray struct {
	Bits  uint32   `json:"bits"`  // NOTE: persisted via reflect, must be exported
	Elems []uint64 `json:"elems"` // NOTE: persisted via reflect, must be exported
}

BitArray is a thread-unsafe implementation of a bit array.

func NewBitArray

func NewBitArray(bits uint32) *BitArray

NewBitArray returns a new bit array. It returns nil if the number of bits is zero.

func (*BitArray) And

func (bA *BitArray) And(o *BitArray) *BitArray

And returns a bit array resulting from a bitwise AND of the two bit arrays. If the two bit-arrys have different lengths, this truncates the larger of the two bit-arrays from the right. Thus the size of the return value is the minimum of the two provided bit arrays.

func (*BitArray) Bytes

func (bA *BitArray) Bytes() []byte

Bytes returns the byte representation of the bits within the bitarray.

func (*BitArray) Copy

func (bA *BitArray) Copy() *BitArray

Copy returns a copy of the provided bit array.

func (*BitArray) GetIndex

func (bA *BitArray) GetIndex(i uint32) bool

GetIndex returns the bit at index i within the bit array. The behavior is undefined if i >= bA.Bits

func (*BitArray) IsEmpty

func (bA *BitArray) IsEmpty() bool

IsEmpty returns true iff all bits in the bit array are 0

func (*BitArray) IsFull

func (bA *BitArray) IsFull() bool

IsFull returns true iff all bits in the bit array are 1.

func (*BitArray) MarshalJSON

func (bA *BitArray) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface by marshaling bit array using a custom format: a string of '-' or 'x' where 'x' denotes the 1 bit.

func (*BitArray) Not

func (bA *BitArray) Not() *BitArray

Not returns a bit array resulting from a bitwise Not of the provided bit array.

func (*BitArray) Or

func (bA *BitArray) Or(o *BitArray) *BitArray

Or returns a bit array resulting from a bitwise OR of the two bit arrays. If the two bit-arrys have different lengths, Or right-pads the smaller of the two bit-arrays with zeroes. Thus the size of the return value is the maximum of the two provided bit arrays.

func (*BitArray) PickRandom

func (bA *BitArray) PickRandom() (uint32, bool)

PickRandom returns a random index for a set bit in the bit array. If there is no such value, it returns 0, false. It uses the global randomness in `random.go` to get this index.

func (*BitArray) SetIndex

func (bA *BitArray) SetIndex(i uint32, v bool) bool

SetIndex sets the bit at index i within the bit array. The behavior is undefined if i >= bA.Bits

func (*BitArray) Size

func (bA *BitArray) Size() uint32

Size returns the number of bits in the bitarray

func (*BitArray) String

func (bA *BitArray) String() string

String returns a string representation of BitArray: BA{<bit-string>}, where <bit-string> is a sequence of 'x' (1) and '_' (0). The <bit-string> includes spaces and newlines to help people. For a simple sequence of 'x' and '_' characters with no spaces or newlines, see the MarshalJSON() method. Example: "BA{_x_}" or "nil-BitArray" for nil.

func (*BitArray) StringIndented

func (bA *BitArray) StringIndented(indent string) string

StringIndented returns the same thing as String(), but applies the indent at every 10th bit, and twice at every 50th bit.

func (*BitArray) Sub

func (bA *BitArray) Sub(o *BitArray) *BitArray

Sub subtracts the two bit-arrays bitwise, without carrying the bits. Note that carryless subtraction of a - b is (a and not b). The output is the same as bA, regardless of o's size. If bA is longer than o, o is right padded with zeroes

func (*BitArray) UnmarshalJSON

func (bA *BitArray) UnmarshalJSON(bz []byte) error

UnmarshalJSON implements json.Unmarshaler interface by unmarshaling a custom JSON description.

func (*BitArray) Update

func (bA *BitArray) Update(o *BitArray)

Update sets the bA's bits to be that of the other bit array. The copying begins from the begin of both bit arrays.

type BlockExt

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

BlockExt is an extension from Block

func NewBlockExt

func NewBlockExt(block *types.Block, blockNum uint64, threshold int) *BlockExt

New creates a BlockExt object

func NewBlockExtByPeer

func NewBlockExtByPeer(block *types.Block, blockNum uint64, threshold int) *BlockExt

func NewBlockExtByPrepareBlock

func NewBlockExtByPrepareBlock(pb *prepareBlock, threshold int) *BlockExt

func NewBlockExtBySeal

func NewBlockExtBySeal(block *types.Block, blockNum uint64, threshold int) *BlockExt

func (BlockExt) BlockExtra

func (b BlockExt) BlockExtra() *BlockExtra

func (*BlockExt) IsParent

func (b *BlockExt) IsParent(hash common.Hash) bool

func (BlockExt) MarshalJSON

func (b BlockExt) MarshalJSON() ([]byte, error)

func (*BlockExt) Merge

func (b *BlockExt) Merge(ext *BlockExt)

func (*BlockExt) PrepareBlock

func (b *BlockExt) PrepareBlock() (*prepareBlock, error)

func (*BlockExt) SetSyncState

func (b *BlockExt) SetSyncState(err error)

func (BlockExt) Signs

func (b BlockExt) Signs() []common.BlockConfirmSign

func (BlockExt) String

func (b BlockExt) String() string

func (BlockExt) Votes

func (b BlockExt) Votes() []*prepareVote

type BlockExtMap

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

func NewBlockExtMap

func NewBlockExtMap(baseBlock *BlockExt, threshold int) *BlockExtMap

func (*BlockExtMap) Add

func (bm *BlockExtMap) Add(hash common.Hash, number uint64, blockExt *BlockExt)

func (*BlockExtMap) BaseBlock

func (bm *BlockExtMap) BaseBlock(hash common.Hash, number uint64) *BlockExt

func (*BlockExtMap) BlockString

func (bm *BlockExtMap) BlockString() string

func (*BlockExtMap) ClearChildren

func (bm *BlockExtMap) ClearChildren(hash common.Hash, number uint64, timestamp uint64)

func (*BlockExtMap) ClearParents

func (bm *BlockExtMap) ClearParents(hash common.Hash, number uint64)

func (*BlockExtMap) FindHighestConfirmed

func (bm *BlockExtMap) FindHighestConfirmed(hash common.Hash, number uint64) *BlockExt

func (*BlockExtMap) FindHighestConfirmedWithHeader

func (bm *BlockExtMap) FindHighestConfirmedWithHeader() *BlockExt

func (*BlockExtMap) FindHighestLogical

func (bm *BlockExtMap) FindHighestLogical(hash common.Hash, number uint64) *BlockExt

func (*BlockExtMap) GetHasVoteWithoutBlock

func (bm *BlockExtMap) GetHasVoteWithoutBlock(highest uint64) []*HashNumberBits

func (*BlockExtMap) GetSubChainUnExecuted

func (bm *BlockExtMap) GetSubChainUnExecuted() []*BlockExt

func (*BlockExtMap) GetSubChainWithTwoThirdVotes

func (bm *BlockExtMap) GetSubChainWithTwoThirdVotes(hash common.Hash, number uint64) []*BlockExt

func (*BlockExtMap) GetWithoutTwoThirdVotes

func (bm *BlockExtMap) GetWithoutTwoThirdVotes(highest uint64) []*HashNumberBits

func (*BlockExtMap) Len

func (bm *BlockExtMap) Len() int

func (*BlockExtMap) RemoveBlock

func (bm *BlockExtMap) RemoveBlock(block *BlockExt)

func (*BlockExtMap) Total

func (bm *BlockExtMap) Total() int

type BlockExtra

type BlockExtra struct {
	Prepare         []*prepareVote
	ViewChange      *viewChange
	ViewChangeVotes []*viewChangeVote
}

type Breakpoint

type Breakpoint interface {
	PrepareBP() PrepareBP
	ViewChangeBP() ViewChangeBP
	InternalBP() InternalBP
	SyncBlockBP() SyncBlockBP
}

Breakpoint is help resolve cbft consensus state Self implement breakpoint, watch all state about cbft

type Cbft

type Cbft struct {
	RoundState
	// contains filtered or unexported fields
}

func New

func New(config *params.CbftConfig, eventMux *event.TypeMux, ctx *node.ServiceContext) *Cbft

New creates a concurrent BFT consensus engine

func (*Cbft) APIs

func (cbft *Cbft) APIs(chain consensus.ChainReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.

func (*Cbft) AcceptPrepareBlock

func (cbft *Cbft) AcceptPrepareBlock(request *prepareBlock) AcceptStatus

func (*Cbft) AcceptPrepareVote

func (cbft *Cbft) AcceptPrepareVote(vote *prepareVote) AcceptStatus

func (*Cbft) AddJournal

func (cbft *Cbft) AddJournal(msg *MsgInfo)

func (*Cbft) AddPrepareBlock

func (cbft *Cbft) AddPrepareBlock(block *types.Block)

func (*Cbft) AddProcessingVote

func (cbft *Cbft) AddProcessingVote(nodeId discover.NodeID, vote *prepareVote)

func (*Cbft) AgreeViewChange

func (cbft *Cbft) AgreeViewChange() bool

func (*Cbft) Author

func (cbft *Cbft) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.

func (*Cbft) CalcBlockDeadline

func (cbft *Cbft) CalcBlockDeadline(timePoint int64) (time.Time, error)

func (*Cbft) CalcNextBlockTime

func (cbft *Cbft) CalcNextBlockTime(timePoint int64) (time.Time, error)

func (*Cbft) CheckConsensusNode

func (cbft *Cbft) CheckConsensusNode(address common.Address) bool

CheckConsensusNode check if the nodeID is a consensus node.

func (*Cbft) Clear

func (cbft *Cbft) Clear()

func (*Cbft) ClearChildren

func (cbft *Cbft) ClearChildren(baseBlockHash common.Hash, baseBlockNum uint64, Timestamp uint64)

func (*Cbft) ClearPending

func (cbft *Cbft) ClearPending()

func (*Cbft) ClearViewChange

func (cbft *Cbft) ClearViewChange()

func (*Cbft) Close

func (cbft *Cbft) Close() error

Close implements consensus.Engine. It's a noop for cbft as there is are no background threads.

func (*Cbft) CommitBlockBP

func (cbft *Cbft) CommitBlockBP(block *types.Block, txs int, gasUsed uint64, elapse time.Duration)

func (*Cbft) ConsensusNodes

func (cbft *Cbft) ConsensusNodes() ([]discover.NodeID, error)

ConsensusNodes returns all consensus nodes.

func (*Cbft) CurrentBlock

func (cbft *Cbft) CurrentBlock() *types.Block

func (*Cbft) Evidences

func (cbft *Cbft) Evidences() string

func (*Cbft) FastSyncCommitHead

func (cbft *Cbft) FastSyncCommitHead() <-chan error

func (*Cbft) Finalize

func (cbft *Cbft) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, receipts []*types.Receipt) (*types.Block, error)

Finalize implements consensus.Engine, no block rewards given, and returns the final block.

func (*Cbft) GetBlock

func (cbft *Cbft) GetBlock(hash common.Hash, number uint64) *types.Block

func (*Cbft) GetBlockByHash

func (cbft *Cbft) GetBlockByHash(hash common.Hash) *types.Block

func (*Cbft) GetBlockWithoutLock

func (cbft *Cbft) GetBlockWithoutLock(hash common.Hash, number uint64) *types.Block

func (*Cbft) HadSendViewChange

func (cbft *Cbft) HadSendViewChange() bool

func (*Cbft) HasBlock

func (cbft *Cbft) HasBlock(hash common.Hash, number uint64) bool

func (*Cbft) HasTwoThirdsMajorityViewChangeVotes

func (cbft *Cbft) HasTwoThirdsMajorityViewChangeVotes() bool

func (*Cbft) HighestConfirmedBlock

func (cbft *Cbft) HighestConfirmedBlock() *types.Block

HighestConfirmedBlock returns the cbft.highestConfirmed.block.

func (*Cbft) HighestLogicalBlock

func (cbft *Cbft) HighestLogicalBlock() *types.Block

HighestLogicalBlock returns the cbft.highestLogical.block.

func (*Cbft) InsertChain

func (cbft *Cbft) InsertChain(block *types.Block, syncState chan error)

func (*Cbft) IsConsensusNode

func (cbft *Cbft) IsConsensusNode() bool

IsConsensusNode check if local is a consensus node.

func (*Cbft) IsSignedBySelf

func (cbft *Cbft) IsSignedBySelf(sealHash common.Hash, signature []byte) bool

func (*Cbft) NextBaseBlock

func (cbft *Cbft) NextBaseBlock() *types.Block

func (*Cbft) OnBaseBlock

func (cbft *Cbft) OnBaseBlock(ch chan *types.Block)

func (*Cbft) OnConfirmedPrepareBlock

func (cbft *Cbft) OnConfirmedPrepareBlock(peerID discover.NodeID, pb *confirmedPrepareBlock) error

Sync confirmed prepare prepareVotes, not sync when local node has enough prepare prepareVotes

func (*Cbft) OnExecutedBlock

func (cbft *Cbft) OnExecutedBlock(bs *ExecuteBlockStatus)

Receive executed block status, remove block if status is error If status is nil, broadcast itself PrepareVote about this block Reset highest logical (because receive block is order) Reset highest confirmed if this block had 2f+1 prepareVotes Flush Block (2f+1 ViewChangeVote and 2f+1 BaseBlock's PrepareVote

func (*Cbft) OnFastSyncCommitHead

func (cbft *Cbft) OnFastSyncCommitHead(errCh chan error)

func (*Cbft) OnGetBlock

func (cbft *Cbft) OnGetBlock(hash common.Hash, number uint64, ch chan *types.Block)

func (*Cbft) OnGetBlockByHash

func (cbft *Cbft) OnGetBlockByHash(hash common.Hash, ch chan *types.Block)

func (*Cbft) OnGetHighestPrepareBlock

func (cbft *Cbft) OnGetHighestPrepareBlock(peerID discover.NodeID, msg *getHighestPrepareBlock) error

func (*Cbft) OnGetPrepareBlock

func (cbft *Cbft) OnGetPrepareBlock(peerID discover.NodeID, g *getPrepareBlock) error

func (*Cbft) OnGetPrepareVote

func (cbft *Cbft) OnGetPrepareVote(peerID discover.NodeID, pv *getPrepareVote) error

func (*Cbft) OnHasBlock

func (cbft *Cbft) OnHasBlock(block *HasBlock)

func (*Cbft) OnHighestPrepareBlock

func (cbft *Cbft) OnHighestPrepareBlock(peerID discover.NodeID, msg *highestPrepareBlock) error

func (*Cbft) OnNewBlock

func (cbft *Cbft) OnNewBlock(ext *BlockExt) error

OnNewBlock is called by protocol handler when it received a new block by P2P.

func (*Cbft) OnNewPrepareBlock

func (cbft *Cbft) OnNewPrepareBlock(nodeId discover.NodeID, request *prepareBlock, propagation bool) error

Receive prepare block from the other consensus node. Need check something ,such as validator index, address, view is equal local view , and last verify signature

func (*Cbft) OnPong

func (cbft *Cbft) OnPong(nodeID discover.NodeID, netLatency int64) error

OnPong is called by protocol handler when it received a new Pong message by P2P.

func (*Cbft) OnPrepareBlockHash

func (cbft *Cbft) OnPrepareBlockHash(peerID discover.NodeID, msg *prepareBlockHash) error

func (*Cbft) OnPrepareVote

func (cbft *Cbft) OnPrepareVote(peerID discover.NodeID, vote *prepareVote, propagation bool) error

OnBlockSignature is called by by protocol handler when it received a new block signature by P2P.

func (*Cbft) OnPrepareVotes

func (cbft *Cbft) OnPrepareVotes(peerID discover.NodeID, view *prepareVotes) error

func (*Cbft) OnSeal

func (cbft *Cbft) OnSeal(sealedBlock *types.Block, sealResultCh chan<- *types.Block, stopCh <-chan struct{})

func (*Cbft) OnSendViewChange

func (cbft *Cbft) OnSendViewChange()

func (*Cbft) OnShouldSeal

func (cbft *Cbft) OnShouldSeal(shouldSeal chan error)

func (*Cbft) OnStatus

func (cbft *Cbft) OnStatus(status chan string)

func (*Cbft) OnSyncBlock

func (cbft *Cbft) OnSyncBlock(ext *BlockExt)

Sync block from p2p BlockNum is must higher current highest confirmed block If verify block success, cbft will change sync mode It don't process new PrepareBlock, PrepareVote, Viewchange, ViewchangeVote It stop sync mode when new view's parent block is in memory. Now it had catch up other peer

func (*Cbft) OnViewChange

func (cbft *Cbft) OnViewChange(peerID discover.NodeID, view *viewChange) error

Receive view from other nodes Need verify timestamp , signature, promise highest confirmed block

func (*Cbft) OnViewChangeTimeout

func (cbft *Cbft) OnViewChangeTimeout(view *viewChange)

func (*Cbft) OnViewChangeVote

func (cbft *Cbft) OnViewChangeVote(peerID discover.NodeID, vote *viewChangeVote) error

func (*Cbft) OnViewChangeVoteTimeout

func (cbft *Cbft) OnViewChangeVoteTimeout(view *viewChangeVote)

Current view change timeout Need reset view

func (*Cbft) Prepare

func (cbft *Cbft) Prepare(chain consensus.ChainReader, header *types.Header) error

Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.

func (*Cbft) Protocols

func (cbft *Cbft) Protocols() []p2p.Protocol

func (*Cbft) ReceivePeerMsg

func (cbft *Cbft) ReceivePeerMsg(msg *MsgInfo)

func (*Cbft) Seal

func (cbft *Cbft) Seal(chain consensus.ChainReader, block *types.Block, sealResultCh chan<- *types.Block, stopCh <-chan struct{}) error

to sign the block, and store the sign to header.Extra[32:], send the sign to chanel to broadcast to other consensus nodes

func (*Cbft) SealHash

func (cbft *Cbft) SealHash(header *types.Header) common.Hash

SealHash returns the hash of a block prior to it being sealed.

func (*Cbft) SetBlockChainCache

func (cbft *Cbft) SetBlockChainCache(blockChainCache *core.BlockChainCache)

func (*Cbft) SetBreakpoint

func (cbft *Cbft) SetBreakpoint(t string)

func (*Cbft) SetLocalHighestPrepareNum

func (cbft *Cbft) SetLocalHighestPrepareNum(num uint64)

func (*Cbft) SetPrivateKey

func (cbft *Cbft) SetPrivateKey(privateKey *ecdsa.PrivateKey)

SetPrivateKey sets local's private key by the backend.go

func (*Cbft) ShouldSeal

func (cbft *Cbft) ShouldSeal(curTime int64) (bool, error)

ShouldSeal checks if it's local's turn to package new block at current time.

func (*Cbft) Start

func (cbft *Cbft) Start(blockChain *core.BlockChain, txPool *core.TxPool, agency Agency) error

Start sets blockChain and txPool into cbft

func (*Cbft) Status

func (cbft *Cbft) Status() string

func (*Cbft) VerifyAndViewChange

func (cbft *Cbft) VerifyAndViewChange(view *viewChange) error

func (*Cbft) VerifyHeader

func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*Cbft) VerifyHeaders

func (cbft *Cbft) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications (the order is that of the input slice).

func (*Cbft) VerifySeal

func (cbft *Cbft) VerifySeal(chain consensus.ChainReader, header *types.Header) error

VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.

type ConsensusMsg

type ConsensusMsg interface {
	CannibalizeBytes() ([]byte, error)
	Sign() []byte
}

type Context

type Context struct {
	//TraceID represents globally unique ID of the trace, such view's timestamp
	TraceID uint64 `json:"trace_id"`

	// SpanID represents span ID that must be unique within its trace, such as peerID, blockNum, baseBlock
	// but does not have to be globally unique.
	SpanID string `json:"span_id"`

	// ParentID refers to the ID of the parent span.
	// Should be "" if the current span is a root span.
	ParentID string `json:"parent_id"`

	// Log type such as "state", "stat"
	Flags byte `json:"flags"`

	//message signer
	Creator string `json:"creator"`

	//local node
	Processor string `json:"processor"`
}

type DuplicatePrepareVoteEvidence

type DuplicatePrepareVoteEvidence struct {
	VoteA *prepareVote
	VoteB *prepareVote
}

Evidence A.Number == B.Number but A.Hash != B.Hash

func (DuplicatePrepareVoteEvidence) Address

func (DuplicatePrepareVoteEvidence) BlockNumber

func (d DuplicatePrepareVoteEvidence) BlockNumber() uint64

func (DuplicatePrepareVoteEvidence) Equal

func (DuplicatePrepareVoteEvidence) Error

func (DuplicatePrepareVoteEvidence) Hash

func (DuplicatePrepareVoteEvidence) Validate

func (d DuplicatePrepareVoteEvidence) Validate() error

func (DuplicatePrepareVoteEvidence) Verify

type DuplicateViewChangeVoteEvidence

type DuplicateViewChangeVoteEvidence struct {
	VoteA *viewChangeVote
	VoteB *viewChangeVote
}

Evidence A.BlockNum == B.BlockNum but A.BlockHash != B.BlockHash

func (DuplicateViewChangeVoteEvidence) Address

func (DuplicateViewChangeVoteEvidence) BlockNumber

func (d DuplicateViewChangeVoteEvidence) BlockNumber() uint64

func (DuplicateViewChangeVoteEvidence) Equal

func (DuplicateViewChangeVoteEvidence) Error

func (DuplicateViewChangeVoteEvidence) Hash

func (DuplicateViewChangeVoteEvidence) Validate

func (DuplicateViewChangeVoteEvidence) Verify

type Evidence

type Evidence interface {
	Verify(ecdsa.PublicKey) error
	Equal(Evidence) bool
	//return lowest number
	BlockNumber() uint64
	Hash() []byte
	Address() common.Address
	Validate() error
}

type EvidenceData

type EvidenceData struct {
	DP []*DuplicatePrepareVoteEvidence    `json:"duplicate_prepare"`
	DV []*DuplicateViewChangeVoteEvidence `json:"duplicate_viewchange"`
	TV []*TimestampViewChangeVoteEvidence `json:"timestamp_viewchange"`
}

func ClassifyEvidence

func ClassifyEvidence(evds []Evidence) *EvidenceData

func NewEvidenceData

func NewEvidenceData() *EvidenceData

type EvidencePool

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

func NewEvidencePool

func NewEvidencePool(path string) (*EvidencePool, error)

func (*EvidencePool) AddPrepareVote

func (ev *EvidencePool) AddPrepareVote(p *prepareVote) error

func (*EvidencePool) AddViewChangeVote

func (ev *EvidencePool) AddViewChangeVote(v *viewChangeVote) error

func (*EvidencePool) Clear

func (ev *EvidencePool) Clear(timestamp, blockNum uint64)

func (*EvidencePool) Close

func (ev *EvidencePool) Close()

func (*EvidencePool) Evidences

func (ev *EvidencePool) Evidences() []Evidence

type ExecuteBlockStatus

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

type GetBlock

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

type HasBlock

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

type HashNumberBits

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

type IWALDatabase

type IWALDatabase interface {
	Put(key []byte, value []byte, wo *opt.WriteOptions) error
	Delete(key []byte) error
	Get(key []byte) ([]byte, error)
	Has(key []byte) (bool, error)
	Close()
}

type InnerAgency

type InnerAgency struct {
	Agency
	// contains filtered or unexported fields
}

func (*InnerAgency) GetLastNumber

func (ia *InnerAgency) GetLastNumber(blockNumber uint64) uint64

func (*InnerAgency) GetValidator

func (ia *InnerAgency) GetValidator(blockNumber uint64) (v *Validators, err error)

func (*InnerAgency) IsCandidateNode

func (ia *InnerAgency) IsCandidateNode(nodeID discover.NodeID) bool

func (*InnerAgency) Sign

func (ia *InnerAgency) Sign(interface{}) error

func (*InnerAgency) VerifySign

func (ia *InnerAgency) VerifySign(interface{}) error

type InternalBP

type InternalBP interface {
	ExecuteBlock(ctx context.Context, hash common.Hash, number uint64, timestamp uint64, elapse time.Duration)
	InvalidBlock(ctx context.Context, hash common.Hash, number uint64, timestamp uint64, err error)
	ForkedResetTxPool(ctx context.Context, newHeader *types.Header, injectBlock types.Blocks, elapse time.Duration, cbft *Cbft)
	ResetTxPool(ctx context.Context, ext *BlockExt, elapse time.Duration, cbft *Cbft)
	NewConfirmedBlock(ctx context.Context, ext *BlockExt, cbft *Cbft)
	NewLogicalBlock(ctx context.Context, ext *BlockExt, cbft *Cbft)
	NewRootBlock(ctx context.Context, ext *BlockExt, cbft *Cbft)
	NewHighestConfirmedBlock(ctx context.Context, ext *BlockExt, cbft *Cbft)
	NewHighestLogicalBlock(ctx context.Context, ext *BlockExt, cbft *Cbft)
	NewHighestRootBlock(ctx context.Context, ext *BlockExt, cbft *Cbft)

	SwitchView(ctx context.Context, view *viewChange, cbft *Cbft)
	Seal(ctx context.Context, ext *BlockExt, cbft *Cbft)
	StoreBlock(ctx context.Context, ext *BlockExt, cbft *Cbft)
}

type JournalMessage

type JournalMessage struct {
	Timestamp uint64
	Data      *MsgInfo
}

type JournalMessageCbftStatusData

type JournalMessageCbftStatusData struct {
	Timestamp uint64
	Data      *MsgInfoCbftStatusData
}

type JournalMessageConfirmedPrepareBlock

type JournalMessageConfirmedPrepareBlock struct {
	Timestamp uint64
	Data      *MsgInfoConfirmedPrepareBlock
}

type JournalMessageGetHighestPrepareBlock

type JournalMessageGetHighestPrepareBlock struct {
	Timestamp uint64
	Data      *MsgInfoGetHighestPrepareBlock
}

type JournalMessageGetPrepareBlock

type JournalMessageGetPrepareBlock struct {
	Timestamp uint64
	Data      *MsgInfoGetPrepareBlock
}

type JournalMessageGetPrepareVote

type JournalMessageGetPrepareVote struct {
	Timestamp uint64
	Data      *MsgInfoGetPrepareVote
}

type JournalMessageHighestPrepareBlock

type JournalMessageHighestPrepareBlock struct {
	Timestamp uint64
	Data      *MsgInfoHighestPrepareBlock
}

type JournalMessagePrepareBlock

type JournalMessagePrepareBlock struct {
	Timestamp uint64
	Data      *MsgInfoPrepareBlock
}

type JournalMessagePrepareBlockHash

type JournalMessagePrepareBlockHash struct {
	Timestamp uint64
	Data      *MsgInfoPrepareBlockHash
}

type JournalMessagePrepareVote

type JournalMessagePrepareVote struct {
	Timestamp uint64
	Data      *MsgInfoPrepareVote
}

type JournalMessagePrepareVotes

type JournalMessagePrepareVotes struct {
	Timestamp uint64
	Data      *MsgInfoPrepareVotes
}

type JournalMessageViewChange

type JournalMessageViewChange struct {
	Timestamp uint64
	Data      *MsgInfoViewChange
}

type JournalMessageViewChangeVote

type JournalMessageViewChangeVote struct {
	Timestamp uint64
	Data      *MsgInfoViewChangeVote
}

type LogRecord

type LogRecord struct {
	Timestamp int64       `json:"timestamp"`
	Log       interface{} `json:"log"`
}

type Message

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

type MsgInfo

type MsgInfo struct {
	Msg    Message
	PeerID discover.NodeID
}

func WALDecode

func WALDecode(pack []byte, msgType uint16) (*MsgInfo, error)

type MsgInfoCbftStatusData

type MsgInfoCbftStatusData struct {
	Msg    *cbftStatusData
	PeerID discover.NodeID
}

type MsgInfoConfirmedPrepareBlock

type MsgInfoConfirmedPrepareBlock struct {
	Msg    *confirmedPrepareBlock
	PeerID discover.NodeID
}

type MsgInfoGetHighestPrepareBlock

type MsgInfoGetHighestPrepareBlock struct {
	Msg    *getHighestPrepareBlock
	PeerID discover.NodeID
}

type MsgInfoGetPrepareBlock

type MsgInfoGetPrepareBlock struct {
	Msg    *getPrepareBlock
	PeerID discover.NodeID
}

type MsgInfoGetPrepareVote

type MsgInfoGetPrepareVote struct {
	Msg    *getPrepareVote
	PeerID discover.NodeID
}

type MsgInfoHighestPrepareBlock

type MsgInfoHighestPrepareBlock struct {
	Msg    *highestPrepareBlock
	PeerID discover.NodeID
}

type MsgInfoPrepareBlock

type MsgInfoPrepareBlock struct {
	Msg    *prepareBlock
	PeerID discover.NodeID
}

type MsgInfoPrepareBlockHash

type MsgInfoPrepareBlockHash struct {
	Msg    *prepareBlockHash
	PeerID discover.NodeID
}

type MsgInfoPrepareVote

type MsgInfoPrepareVote struct {
	Msg    *prepareVote
	PeerID discover.NodeID
}

type MsgInfoPrepareVotes

type MsgInfoPrepareVotes struct {
	Msg    *prepareVotes
	PeerID discover.NodeID
}

type MsgInfoViewChange

type MsgInfoViewChange struct {
	Msg    *viewChange
	PeerID discover.NodeID
}

type MsgInfoViewChangeVote

type MsgInfoViewChangeVote struct {
	Msg    *viewChangeVote
	PeerID discover.NodeID
}

type MsgPackage

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

type NumberOrderPrepare

type NumberOrderPrepare []*prepareVote

func (*NumberOrderPrepare) Add

func (vt *NumberOrderPrepare) Add(v *prepareVote) error

func (NumberOrderPrepare) Len

func (vt NumberOrderPrepare) Len() int

func (NumberOrderPrepare) Less

func (vt NumberOrderPrepare) Less(i, j int) bool

func (*NumberOrderPrepare) Remove

func (vt *NumberOrderPrepare) Remove(blockNum uint64)

func (NumberOrderPrepare) Swap

func (vt NumberOrderPrepare) Swap(i, j int)

type NumberOrderViewChange

type NumberOrderViewChange []*viewChangeVote

func (*NumberOrderViewChange) Add

func (vt *NumberOrderViewChange) Add(v *viewChangeVote) error

func (NumberOrderViewChange) Len

func (vt NumberOrderViewChange) Len() int

func (NumberOrderViewChange) Less

func (vt NumberOrderViewChange) Less(i, j int) bool

func (*NumberOrderViewChange) Remove

func (vt *NumberOrderViewChange) Remove(blockNum uint64)

func (NumberOrderViewChange) Swap

func (vt NumberOrderViewChange) Swap(i, j int)

type PendingBlock

type PendingBlock map[common.Hash]*prepareBlock

func (PendingBlock) Add

func (pb PendingBlock) Add(hash common.Hash, ext *prepareBlock)

func (*PendingBlock) Clear

func (pb *PendingBlock) Clear()

func (PendingBlock) String

func (pb PendingBlock) String() string

type PendingVote

type PendingVote map[common.Hash]*prepareVote

func (PendingVote) Add

func (pv PendingVote) Add(hash common.Hash, vote *prepareVote)

func (*PendingVote) Clear

func (pv *PendingVote) Clear()

func (PendingVote) String

func (pv PendingVote) String() string

type PrepareBP

type PrepareBP interface {
	CommitBlock(ctx context.Context, block *types.Block, txs int, gasUsed uint64, elapse time.Duration, cbft *Cbft)
	SendBlock(ctx context.Context, block *prepareBlock, cbft *Cbft)
	ReceiveBlock(ctx context.Context, block *prepareBlock, cbft *Cbft)
	ReceiveVote(ctx context.Context, block *prepareVote, cbft *Cbft)

	//accept block
	AcceptBlock(ctx context.Context, block *prepareBlock, cbft *Cbft)
	CacheBlock(ctx context.Context, block *prepareBlock, cbft *Cbft)
	DiscardBlock(ctx context.Context, block *prepareBlock, cbft *Cbft)

	//accept block
	AcceptVote(ctx context.Context, block *prepareVote, cbft *Cbft)
	CacheVote(ctx context.Context, block *prepareVote, cbft *Cbft)
	DiscardVote(ctx context.Context, block *prepareVote, cbft *Cbft)

	SendPrepareVote(ctx context.Context, ext *prepareVote, cbft *Cbft)
	InvalidBlock(ctx context.Context, block *prepareBlock, err error, cbft *Cbft)
	InvalidVote(ctx context.Context, block *prepareVote, err error, cbft *Cbft)
	InvalidViewChangeVote(ctx context.Context, block *prepareBlock, err error, cbft *Cbft)
	TwoThirdVotes(ctx context.Context, ext *prepareVote, cbft *Cbft)
}

type PrepareEvidence

type PrepareEvidence map[common.Address]NumberOrderPrepare

func (PrepareEvidence) Add

func (vt PrepareEvidence) Add(v *prepareVote) error

func (PrepareEvidence) Clear

func (vt PrepareEvidence) Clear(number uint64)

type ProcessingVote

type ProcessingVote map[common.Hash]map[discover.NodeID]*prepareVote

func (ProcessingVote) Add

func (pv ProcessingVote) Add(hash common.Hash, nodeId discover.NodeID, vote *prepareVote)

func (*ProcessingVote) Clear

func (pv *ProcessingVote) Clear()

func (ProcessingVote) String

func (pv ProcessingVote) String() string

type ProducerBlocks

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

func NewProducerBlocks

func NewProducerBlocks(author discover.NodeID, blockNum uint64) *ProducerBlocks

func (*ProducerBlocks) AddBlock

func (pb *ProducerBlocks) AddBlock(block *types.Block)

func (*ProducerBlocks) Author

func (pb *ProducerBlocks) Author() discover.NodeID

func (*ProducerBlocks) ExistBlock

func (pb *ProducerBlocks) ExistBlock(block *types.Block) bool

func (*ProducerBlocks) Len

func (pb *ProducerBlocks) Len() int

func (*ProducerBlocks) MaxSequenceBlock

func (pb *ProducerBlocks) MaxSequenceBlock() *types.Block

func (*ProducerBlocks) MaxSequenceBlockNum

func (pb *ProducerBlocks) MaxSequenceBlockNum() uint64

func (*ProducerBlocks) SetAuthor

func (pb *ProducerBlocks) SetAuthor(author discover.NodeID)

func (ProducerBlocks) String

func (pb ProducerBlocks) String() string

type RoundState

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

func (RoundState) String

func (rs RoundState) String() string

type SealBlock

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

func NewSealBlock

func NewSealBlock(block *types.Block, sealResultCh chan<- *types.Block, stopCh <-chan struct{}) *SealBlock

type Span

type Span struct {
	Context      Context       `json:"context"`
	StartTime    time.Time     `json:"start_time"`
	DurationTime time.Duration `json:"duration_time"`
	Tags         []Tag         `json:"tags"`
	LogRecords   []LogRecord   `json:"log_records"`
	//operation name, such as message type
	OperationName string `json:"operation_name"`
}

type StaticAgency

type StaticAgency struct {
	Agency
	// contains filtered or unexported fields
}

func (*StaticAgency) GetLastNumber

func (d *StaticAgency) GetLastNumber(blockNumber uint64) uint64

func (*StaticAgency) GetValidator

func (d *StaticAgency) GetValidator(uint64) (*Validators, error)

func (*StaticAgency) IsCandidateNode

func (d *StaticAgency) IsCandidateNode(nodeID discover.NodeID) bool

func (*StaticAgency) Sign

func (d *StaticAgency) Sign(interface{}) error

func (*StaticAgency) VerifySign

func (d *StaticAgency) VerifySign(interface{}) error

type SyncBlockBP

type SyncBlockBP interface {
	SyncBlock(ctx context.Context, ext *BlockExt, cbft *Cbft)
	InvalidBlock(ctx context.Context, ext *BlockExt, err error, cbft *Cbft)
}

type Tag

type Tag struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
}

type TimeOrderViewChange

type TimeOrderViewChange []*viewChangeVote

func (*TimeOrderViewChange) Add

func (vt *TimeOrderViewChange) Add(v *viewChangeVote) error

func (TimeOrderViewChange) Len

func (vt TimeOrderViewChange) Len() int

func (TimeOrderViewChange) Less

func (vt TimeOrderViewChange) Less(i, j int) bool

func (*TimeOrderViewChange) Remove

func (vt *TimeOrderViewChange) Remove(timestamp uint64)

func (TimeOrderViewChange) Swap

func (vt TimeOrderViewChange) Swap(i, j int)

type TimestampViewChangeVoteEvidence

type TimestampViewChangeVoteEvidence struct {
	VoteA *viewChangeVote
	VoteB *viewChangeVote
}

Evidence A.Timestamp < B.Timestamp but A.BlockNum > B.BlockNum

func (TimestampViewChangeVoteEvidence) Address

func (TimestampViewChangeVoteEvidence) BlockNumber

func (d TimestampViewChangeVoteEvidence) BlockNumber() uint64

func (TimestampViewChangeVoteEvidence) Equal

func (TimestampViewChangeVoteEvidence) Error

func (TimestampViewChangeVoteEvidence) Hash

func (TimestampViewChangeVoteEvidence) Validate

func (TimestampViewChangeVoteEvidence) Verify

type ValidateNode

type ValidateNode struct {
	Index   int            `json:"index"`
	Address common.Address `json:"-"`
	PubKey  *ecdsa.PublicKey
}

func (*ValidateNode) String

func (vn *ValidateNode) String() string

func (*ValidateNode) Verify

func (vn *ValidateNode) Verify(data, sign []byte) bool

type ValidateNodeMap

type ValidateNodeMap map[discover.NodeID]*ValidateNode

func (ValidateNodeMap) String

func (vnm ValidateNodeMap) String() string

type Validators

type Validators struct {
	Nodes            ValidateNodeMap `json:"validateNodes"`
	ValidBlockNumber uint64          `json:"-"`
}

func (*Validators) AddressIndex

func (vs *Validators) AddressIndex(addr common.Address) (*ValidateNode, error)

func (*Validators) Equal

func (vs *Validators) Equal(rsh *Validators) bool

func (*Validators) Len

func (vs *Validators) Len() int

func (*Validators) NodeID

func (vs *Validators) NodeID(idx int) discover.NodeID

func (*Validators) NodeIndex

func (vs *Validators) NodeIndex(id discover.NodeID) (*ValidateNode, error)

func (*Validators) NodeIndexAddress

func (vs *Validators) NodeIndexAddress(id discover.NodeID) (*ValidateNode, error)

func (*Validators) NodeList

func (vs *Validators) NodeList() []discover.NodeID

func (*Validators) String

func (vs *Validators) String() string

type ViewChangeBP

type ViewChangeBP interface {
	SendViewChange(ctx context.Context, view *viewChange, cbft *Cbft)
	ReceiveViewChange(ctx context.Context, view *viewChange, cbft *Cbft)
	ReceiveViewChangeVote(ctx context.Context, view *viewChangeVote, cbft *Cbft)
	InvalidViewChange(ctx context.Context, view *viewChange, err error, cbft *Cbft)
	InvalidViewChangeVote(ctx context.Context, view *viewChangeVote, err error, cbft *Cbft)
	InvalidViewChangeBlock(ctx context.Context, view *viewChange, cbft *Cbft)
	TwoThirdViewChangeVotes(ctx context.Context, view *viewChange, votes ViewChangeVotes, cbft *Cbft)
	SendViewChangeVote(ctx context.Context, view *viewChangeVote, cbft *Cbft)
	ViewChangeTimeout(ctx context.Context, view *viewChange, cbft *Cbft)
}

type ViewChangeMessage

type ViewChangeMessage struct {
	Hash   common.Hash
	Number uint64
}

type ViewChangeMeta

type ViewChangeMeta struct {
	Number uint64
	Hash   common.Hash
	FileID uint32
	Seq    uint64
}

type ViewChangeVotes

type ViewChangeVotes map[common.Address]*viewChangeVote

func (ViewChangeVotes) Bits

func (vv ViewChangeVotes) Bits(cnt int) string

func (ViewChangeVotes) MarshalJSON

func (vv ViewChangeVotes) MarshalJSON() ([]byte, error)

func (ViewChangeVotes) String

func (vv ViewChangeVotes) String() string

func (ViewChangeVotes) UnmarshalJSON

func (vv ViewChangeVotes) UnmarshalJSON(b []byte) error

type ViewNumberEvidence

type ViewNumberEvidence map[common.Address]NumberOrderViewChange

func (ViewNumberEvidence) Add

func (vt ViewNumberEvidence) Add(v *viewChangeVote) error

func (ViewNumberEvidence) Clear

func (vt ViewNumberEvidence) Clear(number uint64)

type ViewTimeEvidence

type ViewTimeEvidence map[common.Address]TimeOrderViewChange

func (ViewTimeEvidence) Add

func (vt ViewTimeEvidence) Add(v *viewChangeVote) error

func (ViewTimeEvidence) Clear

func (vt ViewTimeEvidence) Clear(timestamp uint64)

type WALDatabase

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

func (*WALDatabase) Close

func (db *WALDatabase) Close()

func (*WALDatabase) Delete

func (db *WALDatabase) Delete(key []byte) error

Delete deletes the key from the queue and database

func (*WALDatabase) Get

func (db *WALDatabase) Get(key []byte) ([]byte, error)

Get returns the given key if it's present.

func (*WALDatabase) Has

func (db *WALDatabase) Has(key []byte) (bool, error)

func (*WALDatabase) Path

func (db *WALDatabase) Path() string

Path returns the path to the database directory.

func (*WALDatabase) Put

func (db *WALDatabase) Put(key []byte, value []byte, wo *opt.WriteOptions) error

Put puts the given key / value to the queue

type Wal

type Wal interface {
	Write(info *MsgInfo) error
	UpdateViewChange(info *ViewChangeMessage) error
	Load(add func(info *MsgInfo)) error
	Close()
}

func NewWal

func NewWal(ctx *node.ServiceContext, specifiedPath string) (Wal, error)

type WriterWrapper

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

func NewWriterWrapper

func NewWriterWrapper(file *os.File, bufferLimitSize int) *WriterWrapper

func (*WriterWrapper) Close

func (w *WriterWrapper) Close() (err error)

func (*WriterWrapper) Flush

func (w *WriterWrapper) Flush() (err error)

func (*WriterWrapper) FlushAndClose

func (w *WriterWrapper) FlushAndClose() (err error)

func (*WriterWrapper) Write

func (w *WriterWrapper) Write(p []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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