Documentation ¶
Index ¶
- Constants
- Variables
- func CompareHRS(h1 int64, r1 int32, s1 cstypes.RoundStepType, h2 int64, r2 int32, ...) int
- func IsDataCorruptionError(err error) bool
- func MsgToWrappedProto(msg Message) (cmtcons.Message, error)
- func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int, config *cfg.Config) (err error)
- func WALToProto(msg WALMessage) (*cmtcons.WALMessage, error)
- func WALWithNBlocks(t *testing.T, numBlocks int, config *cfg.Config) (data []byte, err error)
- type BaseWAL
- func (wal *BaseWAL) FlushAndSync() error
- func (wal *BaseWAL) Group() *auto.Group
- func (wal *BaseWAL) OnStart() error
- func (wal *BaseWAL) OnStop()
- func (wal *BaseWAL) SearchForEndHeight(height int64, options *WALSearchOptions) (rd io.ReadCloser, found bool, err error)
- func (wal *BaseWAL) SetFlushInterval(i time.Duration)
- func (wal *BaseWAL) SetLogger(l log.Logger)
- func (wal *BaseWAL) Wait()
- func (wal *BaseWAL) Write(msg WALMessage) error
- func (wal *BaseWAL) WriteSync(msg WALMessage) error
- type BlockPartMessage
- type DataCorruptionError
- type EndHeightMessage
- type ErrConsensusMessageNotRecognized
- type ErrDenyMessageOverflow
- type Handshaker
- func (h *Handshaker) Handshake(ctx context.Context, proxyApp proxy.AppConns) error
- func (h *Handshaker) NBlocks() int
- func (h *Handshaker) ReplayBlocks(ctx context.Context, state sm.State, appHash []byte, appBlockHeight int64, ...) ([]byte, error)
- func (h *Handshaker) SetEventBus(eventBus types.BlockEventPublisher)
- func (h *Handshaker) SetLogger(l log.Logger)
- type HasProposalBlockPartMessage
- type HasVoteMessage
- type Message
- type Metrics
- func (m *Metrics) MarkLateVote(vt types.SignedMsgType)
- func (m *Metrics) MarkProposalProcessed(accepted bool)
- func (m *Metrics) MarkRound(r int32, st time.Time)
- func (m *Metrics) MarkStep(s cstypes.RoundStepType)
- func (m *Metrics) MarkVoteExtensionReceived(accepted bool)
- func (m *Metrics) MarkVoteReceived(vt types.SignedMsgType, power, totalPower int64)
- type NewRoundStepMessage
- type NewValidBlockMessage
- type PeerState
- func (ps *PeerState) ApplyHasProposalBlockPartMessage(msg *HasProposalBlockPartMessage)
- func (ps *PeerState) ApplyHasVoteMessage(msg *HasVoteMessage)
- func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage)
- func (ps *PeerState) ApplyNewValidBlockMessage(msg *NewValidBlockMessage)
- func (ps *PeerState) ApplyProposalPOLMessage(msg *ProposalPOLMessage)
- func (ps *PeerState) ApplyVoteSetBitsMessage(msg *VoteSetBitsMessage, ourVotes *bits.BitArray)
- func (ps *PeerState) BlockPartsSent() int
- func (ps *PeerState) EnsureVoteBitArrays(height int64, numValidators int)
- func (ps *PeerState) GetHeight() int64
- func (ps *PeerState) GetRoundState() *cstypes.PeerRoundState
- func (ps *PeerState) InitProposalBlockParts(partSetHeader types.PartSetHeader)
- func (ps *PeerState) MarshalJSON() ([]byte, error)
- func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader, rng *rand.Rand) *types.Vote
- func (ps *PeerState) RecordBlockPart() int
- func (ps *PeerState) RecordVote() int
- func (ps *PeerState) SendPartSetHasPart(part *types.Part, prs *cstypes.PeerRoundState) bool
- func (ps *PeerState) SendProposalSetHasProposal(logger log.Logger, rs *cstypes.RoundState, prs *cstypes.PeerRoundState)
- func (ps *PeerState) SetHasProposal(proposal *types.Proposal)
- func (ps *PeerState) SetHasProposalBlockPart(height int64, round int32, index int)
- func (ps *PeerState) SetHasVote(vote *types.Vote)
- func (ps *PeerState) SetLogger(logger log.Logger) *PeerState
- func (ps *PeerState) String() string
- func (ps *PeerState) StringIndented(indent string) string
- func (ps *PeerState) VotesSent() int
- type ProposalMessage
- type ProposalPOLMessage
- type Reactor
- func (conR *Reactor) AddPeer(peer p2p.Peer)
- func (*Reactor) GetChannels() []*p2p.ChannelDescriptor
- func (conR *Reactor) InitPeer(peer p2p.Peer) p2p.Peer
- func (conR *Reactor) OnStart() error
- func (conR *Reactor) OnStop()
- func (conR *Reactor) Receive(e p2p.Envelope)
- func (conR *Reactor) RemovePeer(p2p.Peer, any)
- func (conR *Reactor) SetEventBus(b *types.EventBus)
- func (*Reactor) String() string
- func (conR *Reactor) StringIndented(indent string) string
- func (conR *Reactor) SwitchToConsensus(state sm.State, skipWAL bool)
- func (conR *Reactor) WaitSync() bool
- type ReactorOption
- type State
- func (cs *State) AddProposalBlockPart(height int64, round int32, part *types.Part, peerID p2p.ID) error
- func (cs *State) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, err error)
- func (cs *State) GetLastHeight() int64
- func (cs *State) GetRoundState() *cstypes.RoundState
- func (cs *State) GetRoundStateJSON() ([]byte, error)
- func (cs *State) GetRoundStateSimpleJSON() ([]byte, error)
- func (cs *State) GetState() sm.State
- func (cs *State) GetValidators() (int64, []*types.Validator)
- func (cs *State) LoadCommit(height int64) *types.Commit
- func (cs *State) OnStart() error
- func (cs *State) OnStop()
- func (cs *State) OpenWAL(walFile string) (WAL, error)
- func (cs *State) SetEventBus(b *types.EventBus)
- func (cs *State) SetLogger(l log.Logger)
- func (cs *State) SetPrivValidator(priv types.PrivValidator)
- func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.ID) error
- func (cs *State) SetProposalAndBlock(proposal *types.Proposal, parts *types.PartSet, peerID p2p.ID) error
- func (cs *State) SetTimeoutTicker(timeoutTicker TimeoutTicker)
- func (*State) String() string
- func (cs *State) Wait()
- type StateOption
- type TimedWALMessage
- type TimeoutTicker
- type VoteMessage
- type VoteSetBitsMessage
- type VoteSetMaj23Message
- type WAL
- type WALDecoder
- type WALEncoder
- type WALMessage
- type WALSearchOptions
Constants ¶
const ( StateChannel = byte(0x20) DataChannel = byte(0x21) VoteChannel = byte(0x22) VoteSetBitsChannel = byte(0x23) )
const ( // MetricsSubsystem is a subsystem shared by all metrics exposed by this // package. MetricsSubsystem = "consensus" )
Variables ¶
var ( ErrNilMessage = errors.New("message is nil") ErrPeerStateHeightRegression = errors.New("error peer state height regression") ErrPeerStateInvalidStartTime = errors.New("error peer state invalid startTime") ErrCommitQuorumNotMet = errors.New("extended commit does not have +2/3 majority") ErrNilPrivValidator = errors.New("entered createProposalBlock with privValidator being nil") ErrProposalWithoutPreviousCommit = errors.New("propose step; cannot propose anything without commit for the previous block") )
var ( ErrInvalidProposalSignature = errors.New("error invalid proposal signature") ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round") ErrAddingVote = errors.New("error adding vote") ErrSignatureFoundInPastBlocks = errors.New("found signature from the same key") ErrPubKeyIsNotSet = errors.New("pubkey is not set. Look for \"Can't get private validator pubkey\" errors") ErrProposalTooManyParts = errors.New("proposal block has too many parts") )
Consensus sentinel errors.
Functions ¶
func CompareHRS ¶
func CompareHRS(h1 int64, r1 int32, s1 cstypes.RoundStepType, h2 int64, r2 int32, s2 cstypes.RoundStepType) int
func IsDataCorruptionError ¶
IsDataCorruptionError returns true if data has been corrupted inside WAL.
func MsgToWrappedProto ¶
TODO: This needs to be removed, but WALToProto depends on this. Takes a consensus message type and returns the proto defined consensus message, wrapped in the discriminating Message container.
func WALGenerateNBlocks ¶
WALGenerateNBlocks generates a consensus WAL. It does this by spinning up a stripped down version of node (proxy app, event bus, consensus state) with a persistent kvstore application and special consensus wal instance (byteBufferWAL) and waits until numBlocks are created. If the node fails to produce given numBlocks, it returns an error.
func WALToProto ¶
func WALToProto(msg WALMessage) (*cmtcons.WALMessage, error)
WALToProto takes a WAL message and return a proto walMessage and error.
Types ¶
type BaseWAL ¶
type BaseWAL struct { service.BaseService // contains filtered or unexported fields }
Write ahead logger writes msgs to disk before they are processed. Can be used for crash-recovery and deterministic replay. TODO: currently the wal is overwritten during replay catchup, give it a mode so it's either reading or appending - must read to end to start appending again.
func NewWAL ¶
NewWAL returns a new write-ahead logger based on `baseWAL`, which implements WAL. It's flushed and synced to disk every 2s and once when stopped.
func (*BaseWAL) FlushAndSync ¶
FlushAndSync flushes and fsync's the underlying group's data to disk. See auto#FlushAndSync.
func (*BaseWAL) OnStop ¶
func (wal *BaseWAL) OnStop()
Stop the underlying autofile group. Use Wait() to ensure it's finished shutting down before cleaning up files.
func (*BaseWAL) SearchForEndHeight ¶
func (wal *BaseWAL) SearchForEndHeight( height int64, options *WALSearchOptions, ) (rd io.ReadCloser, found bool, err error)
SearchForEndHeight searches for the EndHeightMessage with the given height and returns an auto.GroupReader, whenever it was found or not and an error. Group reader will be nil if found equals false.
CONTRACT: caller must close group reader.
func (*BaseWAL) SetFlushInterval ¶
SetFlushInterval allows us to override the periodic flush interval for the WAL.
func (*BaseWAL) Wait ¶
func (wal *BaseWAL) Wait()
Wait for the underlying autofile group to finish shutting down so it's safe to cleanup files.
func (*BaseWAL) Write ¶
func (wal *BaseWAL) Write(msg WALMessage) error
Write is called in newStep and for each receive on the peerMsgQueue and the timeoutTicker. NOTE: does not call fsync().
func (*BaseWAL) WriteSync ¶
func (wal *BaseWAL) WriteSync(msg WALMessage) error
WriteSync is called when we receive a msg from ourselves so that we write to disk before sending signed messages. NOTE: calls fsync().
type BlockPartMessage ¶
BlockPartMessage is sent when gossipping a piece of the proposed block.
func (*BlockPartMessage) String ¶
func (m *BlockPartMessage) String() string
String returns a string representation.
func (*BlockPartMessage) ValidateBasic ¶
func (m *BlockPartMessage) ValidateBasic() error
ValidateBasic performs basic validation.
type DataCorruptionError ¶
type DataCorruptionError struct {
// contains filtered or unexported fields
}
DataCorruptionError is an error that occurs if data on disk was corrupted.
func (DataCorruptionError) Cause ¶
func (e DataCorruptionError) Cause() error
func (DataCorruptionError) Error ¶
func (e DataCorruptionError) Error() string
type EndHeightMessage ¶
type EndHeightMessage struct {
Height int64 `json:"height"`
}
EndHeightMessage marks the end of the given height inside WAL. @internal used by scripts/wal2json util.
type ErrConsensusMessageNotRecognized ¶
type ErrConsensusMessageNotRecognized struct {
Message any
}
func (ErrConsensusMessageNotRecognized) Error ¶
func (e ErrConsensusMessageNotRecognized) Error() string
type ErrDenyMessageOverflow ¶
type ErrDenyMessageOverflow struct {
Err error
}
func (ErrDenyMessageOverflow) Error ¶
func (e ErrDenyMessageOverflow) Error() string
func (ErrDenyMessageOverflow) Unwrap ¶
func (e ErrDenyMessageOverflow) Unwrap() error
type Handshaker ¶
type Handshaker struct {
// contains filtered or unexported fields
}
func NewHandshaker ¶
func NewHandshaker(stateStore sm.Store, state sm.State, store sm.BlockStore, genDoc *types.GenesisDoc, ) *Handshaker
func (*Handshaker) NBlocks ¶
func (h *Handshaker) NBlocks() int
NBlocks returns the number of blocks applied to the state.
func (*Handshaker) ReplayBlocks ¶
func (h *Handshaker) ReplayBlocks( ctx context.Context, state sm.State, appHash []byte, appBlockHeight int64, proxyApp proxy.AppConns, ) ([]byte, error)
ReplayBlocks replays all blocks since appBlockHeight and ensures the result matches the current state. Returns the final AppHash or an error.
func (*Handshaker) SetEventBus ¶
func (h *Handshaker) SetEventBus(eventBus types.BlockEventPublisher)
SetEventBus - sets the event bus for publishing block related events. If not called, it defaults to types.NopEventBus.
func (*Handshaker) SetLogger ¶
func (h *Handshaker) SetLogger(l log.Logger)
type HasProposalBlockPartMessage ¶
HasProposalBlockPartMessage is sent to indicate that a particular block part has been received.
func (*HasProposalBlockPartMessage) String ¶
func (m *HasProposalBlockPartMessage) String() string
String returns a string representation.
func (*HasProposalBlockPartMessage) ValidateBasic ¶
func (m *HasProposalBlockPartMessage) ValidateBasic() error
ValidateBasic performs basic validation.
type HasVoteMessage ¶
type HasVoteMessage struct { Height int64 Round int32 Type types.SignedMsgType Index int32 }
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.
func (*HasVoteMessage) ValidateBasic ¶
func (m *HasVoteMessage) ValidateBasic() error
ValidateBasic performs basic validation.
type Message ¶
type Message interface {
ValidateBasic() error
}
Message is a message that can be sent and received on the Reactor.
type Metrics ¶
type Metrics struct { // Height of the chain. Height metrics.Gauge // Last height signed by this validator if the node is a validator. ValidatorLastSignedHeight metrics.Gauge `metrics_labels:"validator_address"` // Number of rounds. Rounds metrics.Gauge // Histogram of round duration. RoundDurationSeconds metrics.Histogram `metrics_bucketsizes:"0.1, 100, 8" metrics_buckettype:"exprange"` // Number of validators. Validators metrics.Gauge // Total power of all validators. ValidatorsPower metrics.Gauge // Power of a validator. ValidatorPower metrics.Gauge `metrics_labels:"validator_address"` // Amount of blocks missed per validator. ValidatorMissedBlocks metrics.Gauge `metrics_labels:"validator_address"` // Number of validators who did not sign. MissingValidators metrics.Gauge // Total power of the missing validators. MissingValidatorsPower metrics.Gauge // Number of validators who tried to double sign. ByzantineValidators metrics.Gauge // Total power of the byzantine validators. ByzantineValidatorsPower metrics.Gauge // Time between this and the last block. BlockIntervalSeconds metrics.Histogram // Number of transactions. NumTxs metrics.Gauge // Size of the block. BlockSizeBytes metrics.Gauge // Size of the chain in bytes. ChainSizeBytes metrics.Counter // Total number of transactions. TotalTxs metrics.Gauge // The latest block height. CommittedHeight metrics.Gauge `metrics_name:"latest_block_height"` // Number of block parts transmitted by each peer. BlockParts metrics.Counter `metrics_labels:"peer_id"` // Number of times we received a duplicate block part DuplicateBlockPart metrics.Counter // Number of times we received a duplicate vote DuplicateVote metrics.Counter // Histogram of durations for each step in the consensus protocol. StepDurationSeconds metrics.Histogram `metrics_bucketsizes:"0.1, 100, 8" metrics_buckettype:"exprange" metrics_labels:"step"` // Number of block parts received by the node, separated by whether the part // was relevant to the block the node is trying to gather or not. BlockGossipPartsReceived metrics.Counter `metrics_labels:"matches_current"` // QuroumPrevoteMessageDelay is the interval in seconds between the proposal // timestamp and the timestamp of the earliest prevote that achieved a quorum // during the prevote step. // // To compute it, sum the voting power over each prevote received, in increasing // order of timestamp. The timestamp of the first prevote to increase the sum to // be above 2/3 of the total voting power of the network defines the endpoint // the endpoint of the interval. Subtract the proposal timestamp from this endpoint // to obtain the quorum delay. // metrics:Interval in seconds between the proposal timestamp and the timestamp of the earliest prevote that achieved a quorum. QuorumPrevoteDelay metrics.Gauge `metrics_labels:"proposer_address"` // FullPrevoteDelay is the interval in seconds between the proposal // timestamp and the timestamp of the latest prevote in a round where 100% // of the voting power on the network issued prevotes. // metrics:Interval in seconds between the proposal timestamp and the timestamp of the latest prevote in a round where all validators voted. FullPrevoteDelay metrics.Gauge `metrics_labels:"proposer_address"` // VoteExtensionReceiveCount is the number of vote extensions received by this // node. The metric is annotated by the status of the vote extension from the // application, either 'accepted' or 'rejected'. VoteExtensionReceiveCount metrics.Counter `metrics_labels:"status"` // ProposalReceiveCount is the total number of proposals received by this node // since process start. // The metric is annotated by the status of the proposal from the application, // either 'accepted' or 'rejected'. ProposalReceiveCount metrics.Counter `metrics_labels:"status"` // ProposalCreationCount is the total number of proposals created by this node // since process start. // The metric is annotated by the status of the proposal from the application, // either 'accepted' or 'rejected'. ProposalCreateCount metrics.Counter // RoundVotingPowerPercent is the percentage of the total voting power received // with a round. The value begins at 0 for each round and approaches 1.0 as // additional voting power is observed. The metric is labeled by vote type. RoundVotingPowerPercent metrics.Gauge `metrics_labels:"vote_type"` // LateVotes stores the number of votes that were received by this node that // correspond to earlier heights and rounds than this node is currently // in. LateVotes metrics.Counter `metrics_labels:"vote_type"` // ProposalTimestampDifference is the difference between the local time // of the validator at the time it receives a proposal message, and the // timestamp of the received proposal message. // // The value of this metric is not expected to be negative, as it would // mean that the proposal's timestamp is in the future. This indicates // that the proposer's and this node's clocks are desynchronized. // // A positive value of this metric reflects the message delay from the // proposer to this node, for the delivery of a Proposal message. This // metric thus should drive the definition of values for the consensus // parameter SynchronyParams.MessageDelay, used by the PBTS algorithm. // metrics:Difference in seconds between the local time when a proposal message is received and the timestamp in the proposal message. ProposalTimestampDifference metrics.Histogram `metrics_bucketsizes:"-1.5, -1.0, -0.5, -0.2, 0, 0.2, 0.5, 1.0, 1.5, 2.0, 2.5, 4.0, 8.0" metrics_labels:"is_timely"` // contains filtered or unexported fields }
Metrics contains metrics exposed by this package.
func NopMetrics ¶
func NopMetrics() *Metrics
func PrometheusMetrics ¶
func (*Metrics) MarkLateVote ¶
func (m *Metrics) MarkLateVote(vt types.SignedMsgType)
func (*Metrics) MarkProposalProcessed ¶
func (*Metrics) MarkStep ¶
func (m *Metrics) MarkStep(s cstypes.RoundStepType)
func (*Metrics) MarkVoteExtensionReceived ¶
func (*Metrics) MarkVoteReceived ¶
func (m *Metrics) MarkVoteReceived(vt types.SignedMsgType, power, totalPower int64)
type NewRoundStepMessage ¶
type NewRoundStepMessage struct { Height int64 Round int32 Step cstypes.RoundStepType SecondsSinceStartTime int64 LastCommitRound int32 }
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.
func (*NewRoundStepMessage) ValidateBasic ¶
func (m *NewRoundStepMessage) ValidateBasic() error
ValidateBasic performs basic validation.
func (*NewRoundStepMessage) ValidateHeight ¶
func (m *NewRoundStepMessage) ValidateHeight(initialHeight int64) error
ValidateHeight validates the height given the chain's initial height.
type NewValidBlockMessage ¶
type NewValidBlockMessage struct { Height int64 Round int32 BlockPartSetHeader types.PartSetHeader BlockParts *bits.BitArray IsCommit bool }
NewValidBlockMessage is sent when a validator observes a valid block B in some round r, i.e., there is a Proposal for block B and 2/3+ prevotes for the block B in the round r. In case the block is also committed, then IsCommit flag is set to true.
func (*NewValidBlockMessage) String ¶
func (m *NewValidBlockMessage) String() string
String returns a string representation.
func (*NewValidBlockMessage) ValidateBasic ¶
func (m *NewValidBlockMessage) ValidateBasic() error
ValidateBasic performs basic validation.
type PeerState ¶
type PeerState struct { PRS cstypes.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 ¶
NewPeerState returns a new PeerState for the given Peer.
func (*PeerState) ApplyHasProposalBlockPartMessage ¶
func (ps *PeerState) ApplyHasProposalBlockPartMessage(msg *HasProposalBlockPartMessage)
ApplyHasProposalBlockPartMessage updates the peer state for the new block part.
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) ApplyNewValidBlockMessage ¶
func (ps *PeerState) ApplyNewValidBlockMessage(msg *NewValidBlockMessage)
ApplyNewValidBlockMessage updates the peer state for the new valid block.
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 *bits.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 ¶
BlockPartsSent returns the number of useful block parts the peer has sent us.
func (*PeerState) EnsureVoteBitArrays ¶
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 ¶
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() *cstypes.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(partSetHeader types.PartSetHeader)
InitProposalBlockParts initializes the peer's proposal block parts header and bit array.
func (*PeerState) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*PeerState) PickVoteToSend ¶
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 ¶
RecordBlockPart increments internal block part related statistics for this peer. It returns the total number of added block parts.
func (*PeerState) RecordVote ¶
RecordVote increments internal votes related statistics for this peer. It returns the total number of added votes.
func (*PeerState) SendPartSetHasPart ¶
SendPartSetHasPart sends the part to the peer. Returns true and marks the peer as having the part if the part was sent.
func (*PeerState) SendProposalSetHasProposal ¶
func (ps *PeerState) SendProposalSetHasProposal( logger log.Logger, rs *cstypes.RoundState, prs *cstypes.PeerRoundState, )
SendProposalSetHasProposal sends the Proposal (and ProposalPOL if there is one) to the peer. If successful, it marks the peer as having the proposal.
func (*PeerState) SetHasProposal ¶
SetHasProposal sets the given proposal as known for the peer.
func (*PeerState) SetHasProposalBlockPart ¶
SetHasProposalBlockPart sets the given block part index as known for the peer.
func (*PeerState) SetHasVote ¶
SetHasVote sets the given vote as known by the peer.
func (*PeerState) SetLogger ¶
SetLogger allows to set a logger on the peer state. Returns the peer state itself.
func (*PeerState) StringIndented ¶
StringIndented returns a string representation of the PeerState.
type ProposalMessage ¶
ProposalMessage is sent when a new block is proposed.
func (*ProposalMessage) String ¶
func (m *ProposalMessage) String() string
String returns a string representation.
func (*ProposalMessage) ValidateBasic ¶
func (m *ProposalMessage) ValidateBasic() error
ValidateBasic performs basic validation.
type ProposalPOLMessage ¶
ProposalPOLMessage is sent when a previous proposal is re-proposed.
func (*ProposalPOLMessage) String ¶
func (m *ProposalPOLMessage) String() string
String returns a string representation.
func (*ProposalPOLMessage) ValidateBasic ¶
func (m *ProposalPOLMessage) ValidateBasic() error
ValidateBasic performs basic validation.
type Reactor ¶
type Reactor struct { p2p.BaseReactor // BaseService + p2p.Switch Metrics *Metrics // contains filtered or unexported fields }
Reactor defines a reactor for the consensus service.
func NewReactor ¶
func NewReactor(consensusState *State, waitSync bool, options ...ReactorOption) *Reactor
NewReactor returns a new Reactor with the given consensusState.
func (*Reactor) AddPeer ¶
AddPeer implements Reactor by spawning multiple gossiping goroutines for the peer.
func (*Reactor) GetChannels ¶
func (*Reactor) GetChannels() []*p2p.ChannelDescriptor
GetChannels implements Reactor.
func (*Reactor) OnStart ¶
OnStart implements BaseService by subscribing to events, which later will be broadcasted to other peers and starting state if we're not in block sync.
func (*Reactor) OnStop ¶
func (conR *Reactor) OnStop()
OnStop implements BaseService by unsubscribing from events and stopping state.
func (*Reactor) Receive ¶
Receive implements Reactor NOTE: We process these messages even when we're block_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 (*Reactor) SetEventBus ¶
SetEventBus sets event bus.
func (*Reactor) String ¶
String returns a string representation of the Reactor. NOTE: For now, it is just a hard-coded string to avoid accessing unprotected shared variables. TODO: improve!
func (*Reactor) StringIndented ¶
StringIndented returns an indented string representation of the Reactor.
func (*Reactor) SwitchToConsensus ¶
SwitchToConsensus switches from block sync or state sync mode to consensus mode.
type ReactorOption ¶
type ReactorOption func(*Reactor)
func ReactorMetrics ¶
func ReactorMetrics(metrics *Metrics) ReactorOption
ReactorMetrics sets the metrics.
type State ¶
type State struct { service.BaseService cstypes.RoundState // contains filtered or unexported fields }
State 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 NewState ¶
func NewState( config *cfg.ConsensusConfig, state sm.State, blockExec *sm.BlockExecutor, blockStore sm.BlockStore, txNotifier txNotifier, evpool evidencePool, options ...StateOption, ) *State
NewState returns a new State.
func (*State) AddProposalBlockPart ¶
func (cs *State) AddProposalBlockPart(height int64, round int32, part *types.Part, peerID p2p.ID) error
AddProposalBlockPart inputs a part of the proposal block.
func (*State) GetLastHeight ¶
GetLastHeight returns the last height committed. If there were no blocks, returns 0.
func (*State) GetRoundState ¶
func (cs *State) GetRoundState() *cstypes.RoundState
GetRoundState returns a shallow copy of the internal consensus state.
func (*State) GetRoundStateJSON ¶
GetRoundStateJSON returns a json of RoundState.
func (*State) GetRoundStateSimpleJSON ¶
GetRoundStateSimpleJSON returns a json of RoundStateSimple.
func (*State) GetValidators ¶
GetValidators returns a copy of the current validators.
func (*State) LoadCommit ¶
LoadCommit loads the commit for a given height.
func (*State) OnStart ¶
OnStart loads the latest state via the WAL, and starts the timeout and receive routines.
func (*State) OpenWAL ¶
OpenWAL opens a file to log all consensus messages and timeouts for deterministic accountability.
func (*State) SetEventBus ¶
SetEventBus sets event bus.
func (*State) SetPrivValidator ¶
func (cs *State) SetPrivValidator(priv types.PrivValidator)
SetPrivValidator sets the private validator account for signing votes. It immediately requests pubkey and caches it.
func (*State) SetProposal ¶
SetProposal inputs a proposal.
func (*State) SetProposalAndBlock ¶
func (cs *State) SetProposalAndBlock( proposal *types.Proposal, parts *types.PartSet, peerID p2p.ID, ) error
SetProposalAndBlock inputs the proposal and all block parts.
func (*State) SetTimeoutTicker ¶
func (cs *State) SetTimeoutTicker(timeoutTicker TimeoutTicker)
SetTimeoutTicker sets the local timer. It may be useful to overwrite for testing.
type StateOption ¶
type StateOption func(*State)
StateOption sets an optional parameter on the State.
func OfflineStateSyncHeight ¶
func OfflineStateSyncHeight(height int64) StateOption
OfflineStateSyncHeight indicates the height at which the node statesync offline - before booting sets the metrics.
type TimedWALMessage ¶
type TimedWALMessage struct { Time time.Time `json:"time"` Msg WALMessage `json:"msg"` }
TimedWALMessage wraps WALMessage and adds Time for debugging purposes.
type TimeoutTicker ¶
type TimeoutTicker interface { Start() error Stop() error Chan() <-chan timeoutInfo // on which to receive a timeout ScheduleTimeout(ti timeoutInfo) // reset the timer SetLogger(l log.Logger) }
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() TimeoutTicker
NewTimeoutTicker returns a new TimeoutTicker.
type VoteMessage ¶
VoteMessage is sent when voting for a proposal (or lack thereof).
func (*VoteMessage) String ¶
func (m *VoteMessage) String() string
String returns a string representation.
func (*VoteMessage) ValidateBasic ¶
func (m *VoteMessage) ValidateBasic() error
ValidateBasic checks whether the vote within the message is well-formed.
type VoteSetBitsMessage ¶
type VoteSetBitsMessage struct { Height int64 Round int32 Type types.SignedMsgType BlockID types.BlockID Votes *bits.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.
func (*VoteSetBitsMessage) ValidateBasic ¶
func (m *VoteSetBitsMessage) ValidateBasic() error
ValidateBasic performs basic validation.
type VoteSetMaj23Message ¶
type VoteSetMaj23Message struct { Height int64 Round int32 Type types.SignedMsgType BlockID types.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.
func (*VoteSetMaj23Message) ValidateBasic ¶
func (m *VoteSetMaj23Message) ValidateBasic() error
ValidateBasic performs basic validation.
type WAL ¶
type WAL interface { Write(msg WALMessage) error WriteSync(msg WALMessage) error FlushAndSync() error SearchForEndHeight(height int64, options *WALSearchOptions) (rd io.ReadCloser, found bool, err error) // service methods Start() error Stop() error Wait() }
WAL is an interface for any write-ahead logger.
type WALDecoder ¶
type WALDecoder struct {
// contains filtered or unexported fields
}
A WALDecoder reads and decodes custom-encoded WAL messages from an input stream. See WALEncoder for the format used.
It will also compare the checksums and make sure data size is equal to the length from the header. If that is not the case, error will be returned.
func NewWALDecoder ¶
func NewWALDecoder(rd io.Reader) *WALDecoder
NewWALDecoder returns a new decoder that reads from rd.
func (*WALDecoder) Decode ¶
func (dec *WALDecoder) Decode() (*TimedWALMessage, error)
Decode reads the next custom-encoded value from its reader and returns it.
type WALEncoder ¶
type WALEncoder struct {
// contains filtered or unexported fields
}
A WALEncoder writes custom-encoded WAL messages to an output stream.
Format: 4 bytes CRC sum + 4 bytes length + arbitrary-length value.
func NewWALEncoder ¶
func NewWALEncoder(wr io.Writer) *WALEncoder
NewWALEncoder returns a new encoder that writes to wr.
func (*WALEncoder) Encode ¶
func (enc *WALEncoder) Encode(v *TimedWALMessage) error
Encode writes the custom encoding of v to the stream. It returns an error if the encoded size of v is greater than 1MB. Any error encountered during the write is also returned.
type WALMessage ¶
type WALMessage any
func WALFromProto ¶
func WALFromProto(msg *cmtcons.WALMessage) (WALMessage, error)
WALFromProto takes a proto wal message and return a consensus walMessage and error.
type WALSearchOptions ¶
type WALSearchOptions struct { // IgnoreDataCorruptionErrors set to true will result in skipping data corruption errors. IgnoreDataCorruptionErrors bool }
WALSearchOptions are optional arguments to SearchForEndHeight.