tbft

package
v0.0.0-...-15e8d78 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	//Start is status for notify
	Start int = iota
	//Stop is status for notify
	Stop
	//Switch is status for notify
	Switch
)
View Source
const (
	//StateChannel is channel state
	StateChannel = byte(0x20)
	//DataChannel is channel state
	DataChannel = byte(0x21)
	//VoteChannel is channel state
	VoteChannel = byte(0x22)
	//VoteSetBitsChannel is channel state
	VoteSetBitsChannel = byte(0x23)
)

Variables

View Source
var (
	//ErrInvalidProposalSignature is Error invalid proposal signature
	ErrInvalidProposalSignature = errors.New("error invalid proposal signature")
	//ErrInvalidProposalPOLRound is Error invalid proposal POL round
	ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round")
	//ErrAddingVote is Error adding vote
	ErrAddingVote = errors.New("error adding vote")
	//ErrVoteHeightMismatch is Error vote height mismatch
	ErrVoteHeightMismatch = errors.New("error vote height mismatch")
)

Functions

func CompareHRS

func CompareHRS(h1 uint64, r1 uint, s1 ttypes.RoundStepType, h2 uint64, r2 uint, s2 ttypes.RoundStepType) int

CompareHRS is compare msg'and peerSet's height round Step

func MakeValidators

func MakeValidators(cmm *types.CommitteeInfo) *ttypes.ValidatorSet

MakeValidators is make CommitteeInfo to ValidatorSet

func RegisterConsensusMessages

func RegisterConsensusMessages(cdc *amino.Codec)

RegisterConsensusMessages is register all consensus message

Types

type BlockPartMessage

type BlockPartMessage struct {
	Height uint64
	Round  uint
	Part   *ttypes.Part
}

BlockPartMessage is sent when gossipping a piece of the proposed block.

func (*BlockPartMessage) String

func (m *BlockPartMessage) String() string

String returns a string representation.

type CSOption

type CSOption func(*ConsensusState)

CSOption sets an optional parameter on the ConsensusState.

type CommitStepMessage

type CommitStepMessage struct {
	Height           uint64
	BlockPartsHeader ttypes.PartSetHeader
	BlockParts       *help.BitArray
}

CommitStepMessage is sent when a block is committed.

func (*CommitStepMessage) String

func (m *CommitStepMessage) String() string

String returns a string representation.

type ConsensusMessage

type ConsensusMessage interface{}

ConsensusMessage is a message that can be sent and received on the ConsensusReactor

type ConsensusReactor

type ConsensusReactor struct {
	tp2p.BaseReactor // BaseService + p2p.Switch
	// contains filtered or unexported fields
}

ConsensusReactor defines a reactor for the consensus service.

func NewConsensusReactor

func NewConsensusReactor(consensusState *ConsensusState, fastSync bool) *ConsensusReactor

NewConsensusReactor returns a new ConsensusReactor with the given consensusState.

func (*ConsensusReactor) AddPeer

func (conR *ConsensusReactor) AddPeer(peer tp2p.Peer)

AddPeer implements Reactor

func (*ConsensusReactor) FastSync

func (conR *ConsensusReactor) FastSync() bool

FastSync returns whether the consensus reactor is in fast-sync mode.

func (*ConsensusReactor) GetChannels

func (conR *ConsensusReactor) GetChannels() []*tp2p.ChannelDescriptor

GetChannels implements Reactor

func (*ConsensusReactor) OnStart

func (conR *ConsensusReactor) OnStart() error

OnStart implements BaseService by subscribing to events, which later will be broadcasted to other peers and starting state if we're not in fast sync.

func (*ConsensusReactor) OnStop

func (conR *ConsensusReactor) OnStop()

OnStop implements BaseService by unsubscribing from events and stopping state.

func (*ConsensusReactor) Receive

func (conR *ConsensusReactor) Receive(chID byte, src tp2p.Peer, msgBytes []byte)

Receive implements Reactor NOTE: We process these messages even when we're fast_syncing. Messages affect either a peer state or the consensus state. Peer state updates can happen in parallel, but processing of proposals, block parts, and votes are ordered by the receiveRoutine NOTE: blocks on consensus state for proposals, block parts, and votes

func (*ConsensusReactor) RemovePeer

func (conR *ConsensusReactor) RemovePeer(peer tp2p.Peer, reason interface{})

RemovePeer implements Reactor

func (*ConsensusReactor) SetEventBus

func (conR *ConsensusReactor) SetEventBus(b *ttypes.EventBus)

SetEventBus sets event bus.

func (*ConsensusReactor) SetHealthMgr

func (conR *ConsensusReactor) SetHealthMgr(h *ttypes.HealthMgr)

SetHealthMgr sets peer healthMgr

func (*ConsensusReactor) String

func (conR *ConsensusReactor) String() string

String returns a string representation of the ConsensusReactor. NOTE: For now, it is just a hard-coded string to avoid accessing unprotected shared variables. TODO: improve!

func (*ConsensusReactor) StringIndented

func (conR *ConsensusReactor) StringIndented(indent string) string

StringIndented returns an indented string representation of the ConsensusReactor

type ConsensusState

type ConsensusState struct {
	help.BaseService

	ttypes.RoundState
	// contains filtered or unexported fields
}

ConsensusState handles execution of the consensus algorithm. It processes votes and proposals, and upon reaching agreement, commits blocks to the chain and executes them against the application. The internal state machine receives input from peers, the internal validator, and from a timer.

func NewConsensusState

func NewConsensusState(
	config *cfg.ConsensusConfig,
	state ttypes.StateAgent,
	store *ttypes.BlockStore,
	options ...CSOption,
) *ConsensusState

NewConsensusState returns a new ConsensusState.

func (*ConsensusState) AddProposalBlockPart

func (cs *ConsensusState) AddProposalBlockPart(height uint64, round uint, part *ttypes.Part, peerID string) error

AddProposalBlockPart inputs a part of the proposal block. not used

func (*ConsensusState) AddVote

func (cs *ConsensusState) AddVote(vote *ttypes.Vote, peerID string) (added bool, err error)

AddVote inputs a vote. not used

func (*ConsensusState) GetRoundState

func (cs *ConsensusState) GetRoundState() *ttypes.RoundState

GetRoundState returns a shallow copy of the internal consensus state.

func (*ConsensusState) GetRoundStateJSON

func (cs *ConsensusState) GetRoundStateJSON() ([]byte, error)

GetRoundStateJSON returns a json of RoundState, marshalled using go-amino.

func (*ConsensusState) GetRoundStateSimpleJSON

func (cs *ConsensusState) GetRoundStateSimpleJSON() ([]byte, error)

GetRoundStateSimpleJSON returns a json of RoundStateSimple, marshalled using go-amino.

func (*ConsensusState) OnStart

func (cs *ConsensusState) OnStart() error

OnStart implements help.Service. It loads the latest state via the WAL, and starts the timeout and receive routines.

func (*ConsensusState) OnStop

func (cs *ConsensusState) OnStop()

OnStop implements help.Service. It stops all routines and waits for the WAL to finish.

func (*ConsensusState) SetCommitteeInfo

func (cs *ConsensusState) SetCommitteeInfo(c *types.CommitteeInfo)

func (*ConsensusState) SetEventBus

func (cs *ConsensusState) SetEventBus(b *ttypes.EventBus)

SetEventBus sets event bus.

func (*ConsensusState) SetHealthMgr

func (cs *ConsensusState) SetHealthMgr(h *ttypes.HealthMgr)

SetHealthMgr sets peer health

func (*ConsensusState) SetLogger

func (cs *ConsensusState) SetLogger(l log.Logger)

SetLogger implements Service.

func (*ConsensusState) SetPrivValidator

func (cs *ConsensusState) SetPrivValidator(priv ttypes.PrivValidator)

SetPrivValidator sets the private validator account for signing votes.

func (*ConsensusState) SetProposal

func (cs *ConsensusState) SetProposal(proposal *ttypes.Proposal, peerID string) error

SetProposal inputs a proposal. not used

func (*ConsensusState) SetProposalAndBlock

func (cs *ConsensusState) SetProposalAndBlock(proposal *ttypes.Proposal, block *types.Block, parts *ttypes.PartSet, peerID string) error

SetProposalAndBlock inputs the proposal and all block parts. not used

func (*ConsensusState) SetTimeoutTicker

func (cs *ConsensusState) SetTimeoutTicker(timeoutTicker TimeoutTicker)

SetTimeoutTicker sets the local timer. It may be useful to overwrite for testing.

func (*ConsensusState) String

func (cs *ConsensusState) String() string

String returns a string.

func (*ConsensusState) UpdateValidatorsSet

func (cs *ConsensusState) UpdateValidatorsSet(vset *ttypes.ValidatorSet, uHeight, eHeight uint64)

UpdateValidatorsSet is Set when the committee member is chaneged

func (*ConsensusState) Wait

func (cs *ConsensusState) Wait()

Wait waits for the the main routine to return. NOTE: be sure to Stop() the event switch and drain any event channels or this may deadlock

type HasVoteMessage

type HasVoteMessage struct {
	Height uint64
	Round  uint
	Type   byte
	Index  uint
}

HasVoteMessage is sent to indicate that a particular vote has been received.

func (*HasVoteMessage) String

func (m *HasVoteMessage) String() string

String returns a string representation.

type NewRoundStepMessage

type NewRoundStepMessage struct {
	Height                uint64
	Round                 uint
	Step                  ttypes.RoundStepType
	SecondsSinceStartTime uint
	LastCommitRound       uint
}

NewRoundStepMessage is sent for every step taken in the ConsensusState. For every height/round/step transition

func (*NewRoundStepMessage) String

func (m *NewRoundStepMessage) String() string

String returns a string representation.

type Node

type Node struct {
	help.BaseService

	Agent types.PbftAgentProxy
	// contains filtered or unexported fields
}

Node is the highest level interface to a full abeychain node. It includes all configuration information and running services.

func NewNode

func NewNode(config *cfg.TbftConfig, chainID string, priv *ecdsa.PrivateKey,
	agent types.PbftAgentProxy) (*Node, error)

NewNode returns a new, ready to go, abeychain Node.

func (*Node) AddHealthForCommittee

func (n *Node) AddHealthForCommittee(h *ttypes.HealthMgr, c *types.CommitteeInfo)

func (*Node) GetCommitteeStatus

func (n *Node) GetCommitteeStatus(committeeID *big.Int) map[string]interface{}

GetCommitteeStatus is show committee info in api

func (*Node) IsLeader

func (n *Node) IsLeader(committeeID *big.Int) bool

func (*Node) Notify

func (n *Node) Notify(id *big.Int, action int) error

Notify is agent change server order

func (*Node) OnStart

func (n *Node) OnStart() error

OnStart starts the Node. It implements help.Service.

func (*Node) OnStop

func (n *Node) OnStop()

OnStop stops the Node. It implements help.Service.

func (*Node) PutCommittee

func (n *Node) PutCommittee(committeeInfo *types.CommitteeInfo) error

PutCommittee is agent put all committee to server

func (*Node) PutNodes

func (n *Node) PutNodes(id *big.Int, nodes []*types.CommitteeNode) error

PutNodes is agent put peer's ip port

func (*Node) RunForever

func (n *Node) RunForever()

RunForever waits for an interrupt signal and stops the node.

func (*Node) SetCommitteeStop

func (n *Node) SetCommitteeStop(committeeID *big.Int, stop uint64) error

SetCommitteeStop is stop committeeID server

func (*Node) UpdateCommittee

func (n *Node) UpdateCommittee(info *types.CommitteeInfo) error

UpdateCommittee update the committee info from agent when the members was changed

type PeerState

type PeerState struct {
	PRS   ttypes.PeerRoundState `json:"round_state"` // Exposed.
	Stats *peerStateStats       `json:"stats"`       // Exposed.
	// contains filtered or unexported fields
}

PeerState contains the known state of a peer, including its connection and threadsafe access to its PeerRoundState. NOTE: THIS GETS DUMPED WITH rpc/core/consensus.go. Be mindful of what you Expose.

func NewPeerState

func NewPeerState(peer tp2p.Peer) *PeerState

NewPeerState returns a new PeerState for the given Peer

func (*PeerState) ApplyCommitStepMessage

func (ps *PeerState) ApplyCommitStepMessage(msg *CommitStepMessage)

ApplyCommitStepMessage updates the peer state for the new commit.

func (*PeerState) ApplyHasVoteMessage

func (ps *PeerState) ApplyHasVoteMessage(msg *HasVoteMessage)

ApplyHasVoteMessage updates the peer state for the new vote.

func (*PeerState) ApplyNewRoundStepMessage

func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage)

ApplyNewRoundStepMessage updates the peer state for the new round.

func (*PeerState) ApplyProposalPOLMessage

func (ps *PeerState) ApplyProposalPOLMessage(msg *ProposalPOLMessage)

ApplyProposalPOLMessage updates the peer state for the new proposal POL.

func (*PeerState) ApplyVoteSetBitsMessage

func (ps *PeerState) ApplyVoteSetBitsMessage(msg *VoteSetBitsMessage, ourVotes *help.BitArray)

ApplyVoteSetBitsMessage updates the peer state for the bit-array of votes it claims to have for the corresponding BlockID. `ourVotes` is a BitArray of votes we have for msg.BlockID NOTE: if ourVotes is nil (e.g. msg.Height < rs.Height), we conservatively overwrite ps's votes w/ msg.Votes.

func (*PeerState) BlockPartsSent

func (ps *PeerState) BlockPartsSent() uint

BlockPartsSent returns the number of blocks for which peer has been sending us block parts.

func (*PeerState) EnsureVoteBitArrays

func (ps *PeerState) EnsureVoteBitArrays(height uint64, numValidators uint)

EnsureVoteBitArrays ensures the bit-arrays have been allocated for tracking what votes this peer has received. NOTE: It's important to make sure that numValidators actually matches what the node sees as the number of validators for height.

func (*PeerState) GetHeight

func (ps *PeerState) GetHeight() uint64

GetHeight returns an atomic snapshot of the PeerRoundState's height used by the mempool to ensure peers are caught up before broadcasting new txs

func (*PeerState) GetRoundState

func (ps *PeerState) GetRoundState() *ttypes.PeerRoundState

GetRoundState returns an shallow copy of the PeerRoundState. There's no point in mutating it since it won't change PeerState.

func (*PeerState) InitProposalBlockParts

func (ps *PeerState) InitProposalBlockParts(partsHeader ttypes.PartSetHeader)

InitProposalBlockParts initializes the peer's proposal block parts header and bit array.

func (*PeerState) PickSendVote

func (ps *PeerState) PickSendVote(votes ttypes.VoteSetReader) bool

PickSendVote picks a vote and sends it to the peer. Returns true if vote was sent.

func (*PeerState) PickVoteToSend

func (ps *PeerState) PickVoteToSend(votes ttypes.VoteSetReader) (vote *ttypes.Vote, ok bool)

PickVoteToSend picks a vote to send to the peer. Returns true if a vote was picked. NOTE: `votes` must be the correct Size() for the Height().

func (*PeerState) RecordBlockPart

func (ps *PeerState) RecordBlockPart(bp *BlockPartMessage) uint

RecordBlockPart updates internal statistics for this peer by recording the block part. It returns the total number of block parts (1 per block). This essentially means the number of blocks for which peer has been sending us block parts.

func (*PeerState) RecordVote

func (ps *PeerState) RecordVote(vote *ttypes.Vote) uint

RecordVote updates internal statistics for this peer by recording the vote. It returns the total number of votes (1 per block). This essentially means the number of blocks for which peer has been sending us votes.

func (*PeerState) SetHasProposal

func (ps *PeerState) SetHasProposal(proposal *ttypes.Proposal)

SetHasProposal sets the given proposal as known for the peer.

func (*PeerState) SetHasProposalBlockPart

func (ps *PeerState) SetHasProposalBlockPart(height uint64, round uint, index uint)

SetHasProposalBlockPart sets the given block part index as known for the peer.

func (*PeerState) SetHasVote

func (ps *PeerState) SetHasVote(vote *ttypes.Vote)

SetHasVote sets the given vote as known by the peer

func (*PeerState) SetLogger

func (ps *PeerState) SetLogger(logger log.Logger) *PeerState

SetLogger allows to set a logger on the peer state. Returns the peer state itself.

func (*PeerState) String

func (ps *PeerState) String() string

String returns a string representation of the PeerState

func (*PeerState) StringIndented

func (ps *PeerState) StringIndented(indent string) string

StringIndented returns a string representation of the PeerState

func (*PeerState) ToJSON

func (ps *PeerState) ToJSON() ([]byte, error)

ToJSON returns a json of PeerState, marshalled using go-amino.

func (*PeerState) VotesSent

func (ps *PeerState) VotesSent() uint

VotesSent returns the number of blocks for which peer has been sending us votes.

type ProposalMessage

type ProposalMessage struct {
	Proposal *ttypes.Proposal
}

ProposalMessage is sent when a new block is proposed.

func (*ProposalMessage) String

func (m *ProposalMessage) String() string

String returns a string representation.

type ProposalPOLMessage

type ProposalPOLMessage struct {
	Height           uint64
	ProposalPOLRound uint
	ProposalPOL      *help.BitArray
}

ProposalPOLMessage is sent when a previous proposal is re-proposed.

func (*ProposalPOLMessage) String

func (m *ProposalPOLMessage) String() string

String returns a string representation.

type TimeoutTicker

type TimeoutTicker interface {
	Start() error
	Stop() error
	Chan() <-chan timeoutInfo       // on which to receive a timeout
	ScheduleTimeout(ti timeoutInfo) // reset the timer

}

TimeoutTicker is a timer that schedules timeouts conditional on the height/round/step in the timeoutInfo. The timeoutInfo.Duration may be non-positive.

func NewTimeoutTicker

func NewTimeoutTicker(name string) TimeoutTicker

NewTimeoutTicker returns a new TimeoutTicker.

type ValidatorUpdateMessage

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

ValidatorUpdateMessage is send when a new committee is elected

func (*ValidatorUpdateMessage) String

func (v *ValidatorUpdateMessage) String() string

String returns a string representation.

type VoteMessage

type VoteMessage struct {
	Vote *ttypes.Vote
}

VoteMessage is sent when voting for a proposal (or lack thereof).

func (*VoteMessage) String

func (m *VoteMessage) String() string

String returns a string representation.

type VoteSetBitsMessage

type VoteSetBitsMessage struct {
	Height  uint64
	Round   uint
	Type    byte
	BlockID ttypes.BlockID
	Votes   *help.BitArray
}

VoteSetBitsMessage is sent to communicate the bit-array of votes seen for the BlockID.

func (*VoteSetBitsMessage) String

func (m *VoteSetBitsMessage) String() string

String returns a string representation.

type VoteSetMaj23Message

type VoteSetMaj23Message struct {
	Height  uint64
	Round   uint
	Type    byte
	BlockID ttypes.BlockID
}

VoteSetMaj23Message is sent to indicate that a given BlockID has seen +2/3 votes.

func (*VoteSetMaj23Message) String

func (m *VoteSetMaj23Message) String() string

String returns a string representation.

Directories

Path Synopsis
flowrate
Package flowrate provides the tools for monitoring and limiting the flow rate of an arbitrary data stream.
Package flowrate provides the tools for monitoring and limiting the flow rate of an arbitrary data stream.
pex
upnp
Taken from taipei-torrent.
Taken from taipei-torrent.

Jump to

Keyboard shortcuts

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