consensus

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateChannel       = byte(0x20)
	DataChannel        = byte(0x21)
	VoteChannel        = byte(0x22)
	VoteSetBitsChannel = byte(0x23)
)

Variables

View Source
var (
	ErrPeerStateHeightRegression = errors.New("Error peer state height regression")
	ErrPeerStateInvalidStartTime = errors.New("Error peer state invalid startTime")
)
View Source
var (
	ErrInvalidProposalSignature = errors.New("Error invalid proposal signature")
	ErrInvalidProposalPOLRound  = errors.New("Error invalid proposal POL round")
	ErrAddingVote               = errors.New("Error adding vote")
	ErrVoteHeightMismatch       = errors.New("Error vote height mismatch")
)
View Source
var Major = "0" //
View Source
var Minor = "2" // replay refactor
View Source
var Revision = "2" // validation -> commit
View Source
var Spec = "1" // async

kind of arbitrary

View Source
var Version = cmn.Fmt("v%s/%s.%s.%s", Spec, Major, Minor, Revision)

Functions

func CompareHRS

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

func IsDataCorruptionError

func IsDataCorruptionError(err error) bool

IsDataCorruptionError returns true if data has been corrupted inside WAL.

func LoadConsensusParams

func LoadConsensusParams(db dbm.DB, height uint64) (types.ConsensusParams, error)

LoadConsensusParams loads the ConsensusParams for a given height.

func LoadValidators

func LoadValidators(db dbm.DB, height uint64) (*types.ValidatorSet, uint64, error)

LoadValidators loads the ValidatorSet for a given height. Returns ErrNoValSetForHeight if the validator set can't be found for this height.

func NewWAL

func NewWAL(walFile string) (*baseWAL, error)

func RegisterConsensusMessages

func RegisterConsensusMessages()

func RegisterWALMessages

func RegisterWALMessages()

func RunReplayFile

func RunReplayFile(config *cfg.Config, console bool)

replay the wal file

func SaveStatus

func SaveStatus(db dbm.DB, status NewStatus)

SaveStatus persists the NewStatus, the ValidatorsInfo, and the ConsensusParamsInfo to the database.

func VerifyEvidence

func VerifyEvidence(statusDB dbm.DB, status NewStatus, evidence types.Evidence) error

VerifyEvidence verifies the evidence fully by checking: - it is sufficiently recent (MaxAge) - it is from a key who was a validator at the given height - it is internally consistent - it was properly signed by the alleged equivocator

func VerifyFaultValEvidence

func VerifyFaultValEvidence(status NewStatus, lastCommit *types.Commit, fvi *types.FaultValidatorsEvidence) error

VerifyFaultValEvidence check the FaultValidatorsEvidence Just compare lastblock produce rounds and fault proposer which should produce block but not

func WALWithNBlocks

func WALWithNBlocks(numBlocks uint64) (data []byte, err error)

WALWithNBlocks generates a consensus WAL. It does this by spining up a stripped down version of node (event bus, consensus state) with a persistent kvstore application and special consensus wal instance (byteBufferWAL) and waits until numBlocks are created. Then it returns a WAL content.

Types

type BlockChainApp

type BlockChainApp interface {
	Height() uint64

	LoadBlockMeta(height uint64) *types.BlockMeta
	LoadBlock(height uint64) *types.Block
	LoadBlockPart(height uint64, index int) *types.Part

	LoadBlockCommit(height uint64) *types.Commit
	LoadSeenCommit(height uint64) *types.Commit
	GetValidators(height uint64) []*types.Validator
	GetRecoverValidators(height uint64) []*types.Validator

	CreateBlock(height uint64, maxTxs int, gasLimit uint64, timeUinx uint64) *types.Block
	PreRunBlock(block *types.Block)
	CheckBlock(block *types.Block) bool
	// CheckProcessResult(blockHash common.Hash, txsResult *types.TxsResult) bool
	CommitBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit, fastsync bool) ([]*types.Validator, error)

	SetLastChangedVals(height uint64, vals []*types.Validator)
}

BlockChainApp is the block manage interface.

type BlockExecutor

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

BlockExecutor provides the context and accessories for properly executing a block.

func NewBlockExecutor

func NewBlockExecutor(db dbm.DB, logger log.Logger, evpool EvidencePool) *BlockExecutor

NewBlockExecutor returns a new BlockExecutor with a NopEventBus. Call SetEventBus to provide one.

func (*BlockExecutor) ApplyBlock

func (blockExec *BlockExecutor) ApplyBlock(status NewStatus, blockID types.BlockID, block *types.Block, validators []*types.Validator) (NewStatus, error)

ApplyBlock validates the block against the NewStatus, executes it against the app, fires the relevant events, commits the app, and saves the new NewStatus and responses. It's the only function that needs to be called from outside this package to process and commit an entire block. It takes a blockID to avoid recomputing the parts hash.

func (*BlockExecutor) SetEventBus

func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher)

SetEventBus - sets the event bus for publishing block related events. If not called, it defaults to types.NopEventBus.

func (*BlockExecutor) ValidateBlock

func (blockExec *BlockExecutor) ValidateBlock(status NewStatus, block *types.Block) error

ValidateBlock validates the given block against the given NewStatus. If the block is invalid, it returns an error. Validation does not mutate state, but does require historical information from the stateDB, ie. to verify evidence from a validator at an old height.

type BlockPartMessage

type BlockPartMessage struct {
	Height uint64
	Round  int
	Part   *types.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.

func WithMetrics

func WithMetrics(metrics *Metrics) CSOption

WithMetrics sets the metrics.

type CommitStepMessage

type CommitStepMessage struct {
	Height           uint64
	BlockPartsHeader types.PartSetHeader
	BlockParts       *cmn.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 ConsensusParamsInfo

type ConsensusParamsInfo struct {
	ConsensusParams   types.ConsensusParams
	LastHeightChanged uint64
}

ConsensusParamsInfo represents the latest consensus params, or the last height it changed

func (ConsensusParamsInfo) Bytes

func (params ConsensusParamsInfo) Bytes() []byte

Bytes serializes the ConsensusParamsInfo using go-amino.

type ConsensusReactor

type ConsensusReactor struct {
	p2p.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, p2pmanager p2p.P2PManager) *ConsensusReactor

NewConsensusReactor returns a new ConsensusReactor with the given consensusState.

func (*ConsensusReactor) AddPeer

func (conR *ConsensusReactor) AddPeer(peer p2p.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() []*p2p.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 p2p.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 p2p.Peer, reason interface{})

RemovePeer implements Reactor

func (*ConsensusReactor) SetReceiveP2pTx

func (conR *ConsensusReactor) SetReceiveP2pTx(on bool)

func (*ConsensusReactor) StartTheWorld

func (conR *ConsensusReactor) StartTheWorld() bool

func (*ConsensusReactor) StopTheWorld

func (conR *ConsensusReactor) StopTheWorld() bool

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

func (*ConsensusReactor) SwitchToConsensus

func (conR *ConsensusReactor) SwitchToConsensus(status NewStatus, blocksSynced int)

SwitchToConsensus switches from fast_sync mode to consensus mode. It resets the state, turns off fast_sync, and starts the consensus state-machine

func (*ConsensusReactor) SwitchToFastSync

func (conR *ConsensusReactor) SwitchToFastSync()

SwitchToFastSync switches from consensus mode to fast_sync mode. It turns off consensus state-machine, and starts the fast_sync

type ConsensusState

type ConsensusState struct {
	cmn.BaseService

	cstypes.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,
	status NewStatus,
	blockExec *BlockExecutor,
	app BlockChainApp,
	mempool Mempool,
	evpool EvidencePool,
	options ...CSOption,
) *ConsensusState

NewConsensusState returns a new ConsensusState.

func (*ConsensusState) AddProposalBlockPart

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

AddProposalBlockPart inputs a part of the proposal block.

func (*ConsensusState) AddVote

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

AddVote inputs a vote.

func (*ConsensusState) DeleteHistoricalData

func (cs *ConsensusState) DeleteHistoricalData(keepLatestBlocks uint64)

func (*ConsensusState) GetChainId

func (cs *ConsensusState) GetChainId() string

GetChainId returns consensus chainID.

func (*ConsensusState) GetRoundState

func (cs *ConsensusState) GetRoundState() *cstypes.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) GetState

func (cs *ConsensusState) GetState() NewStatus

GetState returns a copy of the chain status.

func (*ConsensusState) GetValidators

func (cs *ConsensusState) GetValidators() (uint64, []*types.Validator)

GetValidators returns a copy of the current validators.

func (*ConsensusState) LoadCommit

func (cs *ConsensusState) LoadCommit(height uint64) *types.Commit

LoadCommit loads the commit for a given height.

func (*ConsensusState) OnReset

func (cs *ConsensusState) OnReset() error

OnReset implements cmn.Service.

func (*ConsensusState) OnStart

func (cs *ConsensusState) OnStart() error

OnStart implements cmn.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 cmn.Service. It stops all routines and waits for the WAL to finish.

func (*ConsensusState) OpenWAL

func (cs *ConsensusState) OpenWAL(walFile string) (WAL, error)

OpenWAL opens a file to log all consensus messages and timeouts for deterministic accountability

func (*ConsensusState) ReplayFile

func (cs *ConsensusState) ReplayFile(file string, console bool) error

Replay msgs in file or start the console

func (*ConsensusState) SetEventBus

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

SetEventBus sets event bus.

func (*ConsensusState) SetLogger

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

SetLogger implements Service.

func (*ConsensusState) SetPrivValidator

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

SetPrivValidator sets the private validator account for signing votes.

func (*ConsensusState) SetProposal

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

SetProposal inputs a proposal.

func (*ConsensusState) SetProposalAndBlock

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

SetProposalAndBlock inputs the proposal and all block parts.

func (*ConsensusState) SetReceiveP2pTx

func (cs *ConsensusState) SetReceiveP2pTx(on bool)

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) 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 DataCorruptionError

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

DataCorruptionError is an error that occures 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 uint64 `json:"height"`
}

EndHeightMessage marks the end of the given height inside WAL. @internal used by scripts/wal2json util.

type ErrAppBlockHeightTooHigh

type ErrAppBlockHeightTooHigh struct {
	CoreHeight uint64
	AppHeight  uint64
}

func (ErrAppBlockHeightTooHigh) Error

func (e ErrAppBlockHeightTooHigh) Error() string

type ErrBlockHashMismatch

type ErrBlockHashMismatch struct {
	CoreHash []byte
	AppHash  []byte
	Height   uint64
}

func (ErrBlockHashMismatch) Error

func (e ErrBlockHashMismatch) Error() string

type ErrInvalidBlock

type ErrInvalidBlock error

type ErrLastStateMismatch

type ErrLastStateMismatch struct {
	Height uint64
	Core   []byte
	App    []byte
}

func (ErrLastStateMismatch) Error

func (e ErrLastStateMismatch) Error() string

type ErrNoABCIResponsesForHeight

type ErrNoABCIResponsesForHeight struct {
	Height uint64
}

func (ErrNoABCIResponsesForHeight) Error

type ErrNoConsensusParamsForHeight

type ErrNoConsensusParamsForHeight struct {
	Height uint64
}

func (ErrNoConsensusParamsForHeight) Error

type ErrNoValSetForHeight

type ErrNoValSetForHeight struct {
	Height uint64
}

func (ErrNoValSetForHeight) Error

func (e ErrNoValSetForHeight) Error() string

type ErrProxyAppConn

type ErrProxyAppConn error

type ErrStateMismatch

type ErrStateMismatch struct {
	Got      *NewStatus
	Expected *NewStatus
}

func (ErrStateMismatch) Error

func (e ErrStateMismatch) Error() string

type ErrUnknownBlock

type ErrUnknownBlock struct {
	Height uint64
}

func (ErrUnknownBlock) Error

func (e ErrUnknownBlock) Error() string

type EvidencePool

type EvidencePool interface {
	PendingEvidence() []types.Evidence
	AddEvidence(types.Evidence) error
	Update(*types.Block, NewStatus)
}

EvidencePool defines the EvidencePool interface used by the ConsensusState.

type HasVoteMessage

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

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 Mempool

type Mempool interface {
	Lock()
	Unlock()

	GoodTxsSize() int
	Reap(int) types.Txs
	Update(height uint64, txs types.Txs) error

	SetReceiveP2pTx(on bool)

	TxsAvailable() <-chan struct{}
	EnableTxsAvailable()
}

Mempool defines the mempool interface as used by the ConsensusState. Updates to the mempool need to be synchronized with committing a block so apps can reset their transient state on Commit

type Metrics

type Metrics struct {
	// Height of the chain.
	Height metrics.Gauge

	// Number of rounds.
	Rounds metrics.Gauge

	// Number of validators.
	Validators metrics.Gauge
	// Total power of all validators.
	ValidatorsPower metrics.Gauge
	// 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
	// Total number of transactions.
	TotalTxs metrics.Gauge
}

Metrics contains metrics exposed by this package.

func NopMetrics

func NopMetrics() *Metrics

NopMetrics returns no-op Metrics.

func PrometheusMetrics

func PrometheusMetrics() *Metrics

PrometheusMetrics returns Metrics build using Prometheus client library.

type MockBlockChainApp

type MockBlockChainApp struct {
	mock.Mock
}

MockBlockChainApp is an autogenerated mock type for the BlockChainApp type

func (*MockBlockChainApp) CheckBlock

func (_m *MockBlockChainApp) CheckBlock(block *types.Block) bool

CheckBlock provides a mock function with given fields: block

func (*MockBlockChainApp) CommitBlock

func (_m *MockBlockChainApp) CommitBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit, fastsync bool) ([]*types.Validator, error)

CommitBlock provides a mock function with given fields: block, blockParts, seenCommit, fastsync

func (*MockBlockChainApp) CreateBlock

func (_m *MockBlockChainApp) CreateBlock(height uint64, maxTxs int, gasLimit uint64, timeUinx uint64) *types.Block

CreateBlock provides a mock function with given fields: height, maxTxs, gasLimit, timeUinx

func (*MockBlockChainApp) GetRecoverValidators

func (_m *MockBlockChainApp) GetRecoverValidators(height uint64) []*types.Validator

GetRecoverValidators provides a mock function with given fields: height

func (*MockBlockChainApp) GetValidators

func (_m *MockBlockChainApp) GetValidators(height uint64) []*types.Validator

GetValidators provides a mock function with given fields: height

func (*MockBlockChainApp) Height

func (_m *MockBlockChainApp) Height() uint64

Height provides a mock function with given fields:

func (*MockBlockChainApp) LoadBlock

func (_m *MockBlockChainApp) LoadBlock(height uint64) *types.Block

LoadBlock provides a mock function with given fields: height

func (*MockBlockChainApp) LoadBlockCommit

func (_m *MockBlockChainApp) LoadBlockCommit(height uint64) *types.Commit

LoadBlockCommit provides a mock function with given fields: height

func (*MockBlockChainApp) LoadBlockMeta

func (_m *MockBlockChainApp) LoadBlockMeta(height uint64) *types.BlockMeta

LoadBlockMeta provides a mock function with given fields: height

func (*MockBlockChainApp) LoadBlockPart

func (_m *MockBlockChainApp) LoadBlockPart(height uint64, index int) *types.Part

LoadBlockPart provides a mock function with given fields: height, index

func (*MockBlockChainApp) LoadSeenCommit

func (_m *MockBlockChainApp) LoadSeenCommit(height uint64) *types.Commit

LoadSeenCommit provides a mock function with given fields: height

func (*MockBlockChainApp) PreRunBlock

func (_m *MockBlockChainApp) PreRunBlock(block *types.Block)

PreRunBlock provides a mock function with given fields: block

func (*MockBlockChainApp) SetLastChangedVals

func (_m *MockBlockChainApp) SetLastChangedVals(height uint64, vals []*types.Validator)

SetLastChangedVals provides a mock function with given fields: height, vals

type MockEvidencePool

type MockEvidencePool struct {
}

MockMempool is an empty implementation of a Mempool, useful for testing.

func (MockEvidencePool) AddEvidence

func (m MockEvidencePool) AddEvidence(types.Evidence) error

func (MockEvidencePool) PendingEvidence

func (m MockEvidencePool) PendingEvidence() []types.Evidence

func (MockEvidencePool) Update

func (m MockEvidencePool) Update(*types.Block, NewStatus)

type MockMempool

type MockMempool struct {
}

MockMempool is an empty implementation of a Mempool, useful for testing.

func (MockMempool) EnableTxsAvailable

func (m MockMempool) EnableTxsAvailable()

func (MockMempool) Flush

func (m MockMempool) Flush()

func (MockMempool) FlushAppConn

func (m MockMempool) FlushAppConn() error

func (MockMempool) GetTxFromCache added in v0.1.1

func (m MockMempool) GetTxFromCache(hash common.Hash) types.Tx

func (MockMempool) GoodTxsSize

func (m MockMempool) GoodTxsSize() int

func (MockMempool) Lock

func (m MockMempool) Lock()

func (MockMempool) Reap

func (m MockMempool) Reap(n int) types.Txs

func (MockMempool) SetReceiveP2pTx

func (m MockMempool) SetReceiveP2pTx(on bool)

func (MockMempool) TxsAvailable

func (m MockMempool) TxsAvailable() <-chan struct{}

func (MockMempool) Unlock

func (m MockMempool) Unlock()

func (MockMempool) Update

func (m MockMempool) Update(height uint64, txs types.Txs) error

type NewRoundStepMessage

type NewRoundStepMessage struct {
	Height                uint64
	Round                 int
	Step                  cstypes.RoundStepType
	SecondsSinceStartTime int
	LastCommitRound       int
}

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 NewStatus

type NewStatus struct {
	// Immutable
	ChainID string

	// LastBlockHeight=0 at genesis (ie. block(H=0) does not exist)
	LastBlockHeight  uint64
	LastBlockTotalTx uint64
	LastBlockID      types.BlockID
	LastBlockTime    uint64

	// LastValidators is used to validate block.LastCommit.
	// Validators are persisted to the database separately every time they change,
	// so we can query for historical validator sets.
	// Note that if s.LastBlockHeight causes a valset change,
	// we set s.LastHeightValidatorsChanged = s.LastBlockHeight + 1
	Validators                  *types.ValidatorSet
	LastValidators              *types.ValidatorSet
	LastHeightValidatorsChanged uint64

	//Indicate lastBlock is recoverBlock
	LastRecover bool

	// Consensus parameters used for validating blocks.
	// Changes returned by EndBlock and updated after Commit.
	ConsensusParams                  types.ConsensusParams
	LastHeightConsensusParamsChanged uint64
}

NewStatus is a short description of the latest committed block of the consensus. It keeps all information necessary to validate new blocks, including the last validator set and the consensus params. All fields are exposed so the struct can be easily serialized, but none of them should be mutated directly. NOTE: not goroutine-safe.

func CreateStatusFromGenesisDoc

func CreateStatusFromGenesisDoc(statusDB dbm.DB, genesisDoc *types.GenesisDoc) (NewStatus, error)

CreateStatusFromGenesisFile creates a new one from the given genesisDoc and persists the result to the database.

func CreateStatusFromGenesisFile

func CreateStatusFromGenesisFile(statusDB dbm.DB, genesisFilePath string) (NewStatus, error)

CreateStatusFromGenesisFile creates a new one from the given genesisFilePath and persists the result to the database.

func LoadStatus

func LoadStatus(db dbm.DB) (NewStatus, error)

LoadStatus loads the NewStatus from the database.

func LoadStatusByHeight

func LoadStatusByHeight(db dbm.DB, height uint64) (NewStatus, error)

LoadStatusByHeight from the database

func MakeGenesisStatus

func MakeGenesisStatus(genDoc *types.GenesisDoc) (NewStatus, error)

MakeGenesisStatus creates NewStatus from types.GenesisDoc.

func MakeGenesisStatusFromFile

func MakeGenesisStatusFromFile(genDocFile string) (NewStatus, error)

MakeGenesisStatusFromFile reads and unmarshals NewStatus from the given file.

Used during replay and in tests.

func (NewStatus) Bytes

func (status NewStatus) Bytes() []byte

Bytes serializes the NewStatus using go-amino.

func (NewStatus) Copy

func (status NewStatus) Copy() NewStatus

Copy makes a copy of the NewStatus for mutating.

func (NewStatus) Equals

func (status NewStatus) Equals(status2 NewStatus) bool

Equals returns true if the NewStatus are identical.

func (NewStatus) GetValidators

func (status NewStatus) GetValidators() (last *types.ValidatorSet, current *types.ValidatorSet)

GetValidators returns the last and current validator sets.

func (NewStatus) IsEmpty

func (status NewStatus) IsEmpty() bool

IsEmpty returns true if the NewStatus is equal to the empty status.

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

func NewPeerState(peer p2p.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 *cmn.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() int

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 int)

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() *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(partsHeader types.PartSetHeader)

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

func (*PeerState) PickSendVote

func (ps *PeerState) PickSendVote(votes types.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 types.VoteSetReader) (vote *types.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) int

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 *types.Vote) int

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 *types.Proposal)

SetHasProposal sets the given proposal as known for the peer.

func (*PeerState) SetHasProposalBlockPart

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

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

func (*PeerState) SetHasVote

func (ps *PeerState) SetHasVote(vote *types.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() int

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

type ProposalHeartbeatMessage

type ProposalHeartbeatMessage struct {
	Heartbeat *types.Heartbeat
}

ProposalHeartbeatMessage is sent to signal that a node is alive and waiting for transactions for a proposal.

func (*ProposalHeartbeatMessage) String

func (m *ProposalHeartbeatMessage) String() string

String returns a string representation.

type ProposalMessage

type ProposalMessage struct {
	Proposal *types.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 int
	ProposalPOL      *cmn.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 TimedWALMessage

type TimedWALMessage struct {
	Time time.Time  `json:"time"` // for debugging purposes
	Msg  WALMessage `json:"msg"`
}

type TimeoutTicker

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

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

type ValidatorsInfo struct {
	ValidatorSet      *types.ValidatorSet
	LastHeightChanged uint64
}

ValidatorsInfo represents the latest validator set, or the last height it changed

func (*ValidatorsInfo) Bytes

func (valInfo *ValidatorsInfo) Bytes() []byte

Bytes serializes the ValidatorsInfo using go-amino.

type VoteMessage

type VoteMessage struct {
	Vote *types.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   int
	Type    byte
	BlockID types.BlockID
	Votes   *cmn.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   int
	Type    byte
	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.

type WAL

type WAL interface {
	Write(WALMessage)
	WriteSync(WALMessage)
	Group() *auto.Group
	SearchForEndHeight(height uint64, options *WALSearchOptions) (gr *auto.GroupReader, found bool, err error)

	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 (go-amino encoded)

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.

type WALMessage

type WALMessage interface{}

type WALSearchOptions

type WALSearchOptions struct {
	// IgnoreDataCorruptionErrors set to true will result in skipping data corruption errors.
	IgnoreDataCorruptionErrors bool
}

WALSearchOptions are optional arguments to SearchForEndHeight.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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