consensus

package
v0.0.0-...-f47aca1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: Apache-2.0 Imports: 44 Imported by: 0

README

See the consensus spec and the reactor consensus spec for more information.

Documentation

Index

Constants

View Source
const (
	StateChannel       = byte(0x20)
	DataChannel        = byte(0x21)
	VoteChannel        = byte(0x22)
	VoteSetBitsChannel = byte(0x23)
)
View Source
const (
	// MetricsSubsystem is a subsystem shared by all metrics exposed by this
	// package.
	MetricsSubsystem = "consensus"
)

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

Functions

func CompareHRS

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

func IsDataCorruptionError

func IsDataCorruptionError(err error) bool

IsDataCorruptionError returns true if data has been corrupted inside WAL.

func RegisterMessages

func RegisterMessages(cdc *amino.Codec)

func RegisterWALMessages

func RegisterWALMessages(cdc *amino.Codec)

func RunReplayFile

func RunReplayFile(config cfg.BaseConfig, csConfig *cfg.ConsensusConfig, console bool)

replay the wal file

func WALGenerateNBlocks

func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error)

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 WALWithNBlocks

func WALWithNBlocks(t *testing.T, numBlocks int) (data []byte, err error)

WALWithNBlocks returns a WAL content with numBlocks.

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

func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*BaseWAL, error)

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

func (wal *BaseWAL) FlushAndSync() error

FlushAndSync flushes and fsync's the underlying group's data to disk. See auto#FlushAndSync

func (*BaseWAL) Group

func (wal *BaseWAL) Group() *auto.Group

func (*BaseWAL) OnStart

func (wal *BaseWAL) OnStart() error

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

func (wal *BaseWAL) SetFlushInterval(i time.Duration)

SetFlushInterval allows us to override the periodic flush interval for the WAL.

func (*BaseWAL) SetLogger

func (wal *BaseWAL) SetLogger(l log.Logger)

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

type BlockPartMessage struct {
	Height int64
	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.

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 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 int64 `json:"height"`
}

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

type Handshaker

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

func NewHandshaker

func NewHandshaker(stateDB dbm.DB, state sm.State,
	store sm.BlockStore, genDoc *types.GenesisDoc) *Handshaker

func (*Handshaker) Handshake

func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error

TODO: retry the handshake/replay if it fails ?

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

type HasVoteMessage struct {
	Height int64
	Round  int
	Type   types.SignedMsgType
	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.

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

	// ValidatorLastSignedHeight of a validator.
	ValidatorLastSignedHeight metrics.Gauge

	// Number of rounds.
	Rounds metrics.Gauge

	// Number of validators.
	Validators metrics.Gauge
	// Total power of all validators.
	ValidatorsPower metrics.Gauge
	// Power of a validator.
	ValidatorPower metrics.Gauge
	// Amount of blocks missed by a validator.
	ValidatorMissedBlocks 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.Gauge

	// Number of transactions.
	NumTxs metrics.Gauge
	// Size of the block.
	BlockSizeBytes metrics.Gauge
	// Total number of transactions.
	TotalTxs metrics.Gauge
	// The latest block height.
	CommittedHeight metrics.Gauge
	// Whether or not a node is fast syncing. 1 if yes, 0 if no.
	FastSyncing metrics.Gauge

	// Number of blockparts transmitted by peer.
	BlockParts metrics.Counter
}

Metrics contains metrics exposed by this package.

func NopMetrics

func NopMetrics() *Metrics

NopMetrics returns no-op Metrics.

func PrometheusMetrics

func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics

PrometheusMetrics returns Metrics build using Prometheus client library. Optionally, labels can be provided along with their values ("foo", "fooValue").

type NewRoundStepMessage

type NewRoundStepMessage struct {
	Height                int64
	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.

func (*NewRoundStepMessage) ValidateBasic

func (m *NewRoundStepMessage) ValidateBasic() error

ValidateBasic performs basic validation.

type NewValidBlockMessage

type NewValidBlockMessage struct {
	Height           int64
	Round            int
	BlockPartsHeader 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 包含了peer的已知状态。包括它的连接线程安全访问其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) 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 更新peer状态到最新的一轮

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

func (ps *PeerState) BlockPartsSent() int

BlockPartsSent returns the number of useful block parts the peer has sent us.

func (*PeerState) EnsureVoteBitArrays

func (ps *PeerState) EnsureVoteBitArrays(height int64, numValidators int)

EnsureVoteBitArrays 确保已分配bit-arrays以跟踪此peer收到的投票。 注意:确保numValidators与node在某高度上看到的验证者数量相符是很重要的。

func (*PeerState) GetHeight

func (ps *PeerState) GetHeight() int64

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 返回PeerRoundState的浅拷贝。 对其进行更改没有任何意义,因为它不会更改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 获取一个投票并发送到peer。如果投票被发送,返回true。

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

RecordBlockPart increments internal block part related statistics for this peer. It returns the total number of added block parts.

func (*PeerState) RecordVote

func (ps *PeerState) RecordVote() int

RecordVote 增加此对等方的内部投票相关统计信息。并返回总数

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 int64, round int, index int)

SetHasProposalBlockPart 设置peer对给定的部分区块索引已知。

func (*PeerState) SetHasVote

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

SetHasVote 设置peer对给定对vote已知

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 返回json PeerState。

func (*PeerState) VotesSent

func (ps *PeerState) VotesSent() int

VotesSent 返回peer已向我们发送投票的区块数。

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.

func (*ProposalMessage) ValidateBasic

func (m *ProposalMessage) ValidateBasic() error

ValidateBasic performs basic validation.

type ProposalPOLMessage

type ProposalPOLMessage struct {
	Height           int64
	ProposalPOLRound int
	ProposalPOL      *bits.BitArray
}

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
	// contains filtered or unexported fields
}

Reactor 共识模块的reactor

func NewReactor

func NewReactor(consensusState *State, fastSync bool, options ...ReactorOption) *Reactor

NewReactor returns a new Reactor with the given consensusState.

func (*Reactor) AddPeer

func (conR *Reactor) AddPeer(peer p2p.Peer)

AddPeer implements Reactor by spawning multiple gossiping goroutines for the peer.

func (*Reactor) FastSync

func (conR *Reactor) FastSync() bool

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

func (*Reactor) GetChannels

func (conR *Reactor) GetChannels() []*p2p.ChannelDescriptor

GetChannels implements Reactor

func (*Reactor) InitPeer

func (conR *Reactor) InitPeer(peer p2p.Peer) p2p.Peer

InitPeer implements Reactor by creating a state for the peer.

func (*Reactor) OnStart

func (conR *Reactor) 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 (*Reactor) OnStop

func (conR *Reactor) OnStop()

OnStop implements BaseService by unsubscribing from events and stopping state.

func (*Reactor) Receive

func (conR *Reactor) 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 (*Reactor) RemovePeer

func (conR *Reactor) RemovePeer(peer p2p.Peer, reason interface{})

RemovePeer is a noop.

func (*Reactor) SetEventBus

func (conR *Reactor) SetEventBus(b *types.EventBus)

SetEventBus sets event bus.

func (*Reactor) String

func (conR *Reactor) String() 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

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

StringIndented returns an indented string representation of the Reactor

func (*Reactor) SwitchToConsensus

func (conR *Reactor) SwitchToConsensus(state sm.State, blocksSynced uint64)

SwitchToConsensus 从快速同步模式转为共识模式。 它重置了状态,关闭了快速同步,并开启共识状态机

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 int, part *types.Part, peerID p2p.ID) error

AddProposalBlockPart 输入proposal的一部分

func (*State) AddVote

func (cs *State) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, err error)

AddVote 输入投票

func (*State) GetLastHeight

func (cs *State) GetLastHeight() int64

GetLastHeight 返回最后提交的高度,如果没有区块,返回0

func (*State) GetRoundState

func (cs *State) GetRoundState() *cstypes.RoundState

GetRoundState 返回内部roundState的浅拷贝

func (*State) GetRoundStateJSON

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

GetRoundStateJSON 使用go-amino,JSON序列化共识roundState

func (*State) GetRoundStateSimpleJSON

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

GetRoundStateSimpleJSON 使用go-amino,JSON序列化共识压缩版roundState

func (*State) GetState

func (cs *State) GetState() sm.State

GetState 返回链状态的拷贝

func (*State) GetValidators

func (cs *State) GetValidators() (int64, []*types.Validator)

GetValidators 返回当前的验证者

func (*State) LoadCommit

func (cs *State) LoadCommit(height int64) *types.Commit

LoadCommit 加载指定高度的commit

func (*State) OnStart

func (cs *State) OnStart() error

OnStart implements service.Service. 它通过WAL加载最新状态,并启动超时和接收routine。

func (*State) OnStop

func (cs *State) OnStop()

OnStop implements service.Service.

func (*State) OpenWAL

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

OpenWAL 打开一个文件来记录所有共识消息和超时,以确定确定性的责任

func (*State) ReplayFile

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

Replay msgs in file or start the console

func (*State) SetEventBus

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

SetEventBus 设置事件总线.

func (*State) SetLogger

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

SetLogger implements Service.

func (*State) SetPrivValidator

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

SetPrivValidator 设置私有验证器,用于签名投票

func (*State) SetProposal

func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.ID) error

SetProposal 输入proposal

func (*State) SetProposalAndBlock

func (cs *State) SetProposalAndBlock(
	proposal *types.Proposal,
	block *types.Block,
	parts *types.PartSet,
	peerID p2p.ID,
) error

SetProposalAndBlock 设置proposal和所有的区块part

func (*State) SetTimeoutTicker

func (cs *State) SetTimeoutTicker(timeoutTicker TimeoutTicker)

SetTimeoutTicker 设置超时器

func (*State) String

func (cs *State) String() string

String returns a string.

func (*State) Wait

func (cs *State) 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 StateOption

type StateOption func(*State)

StateOption sets an optional parameter on the State.

func StateMetrics

func StateMetrics(metrics *Metrics) StateOption

StateMetrics 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(log.Logger)
}

TimeoutTicker是一个计时器,用于根据timeoutInfo中的高度/回合/步长计划超时。 timeoutInfo.Duration可能是非正数.

func NewTimeoutTicker

func NewTimeoutTicker() TimeoutTicker

NewTimeoutTicker returns a new TimeoutTicker.

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.

func (*VoteMessage) ValidateBasic

func (m *VoteMessage) ValidateBasic() error

ValidateBasic performs basic validation.

type VoteSetBitsMessage

type VoteSetBitsMessage struct {
	Height  int64
	Round   int
	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   int
	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(WALMessage) error
	WriteSync(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 (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. It returns an error if the amino-encoded size of v is greater than 1MB. Any error encountered during the write is also returned.

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