types

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: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoundStepNewHeight     = RoundStepType(0x01) // Wait til CommitTime + timeoutCommit
	RoundStepNewRound      = RoundStepType(0x02) // Setup new round and go to RoundStepPropose
	RoundStepPropose       = RoundStepType(0x03) // Did propose, gossip proposal
	RoundStepPrevote       = RoundStepType(0x04) // Did prevote, gossip prevotes
	RoundStepPrevoteWait   = RoundStepType(0x05) // Did receive any +2/3 prevotes, start timeout
	RoundStepPrecommit     = RoundStepType(0x06) // Did precommit, gossip precommits
	RoundStepPrecommitWait = RoundStepType(0x07) // Did receive any +2/3 precommits, start timeout
	RoundStepCommit        = RoundStepType(0x08) // Entered commit state machine

)

RoundStepType

Variables

View Source
var (
	ErrGotVoteFromUnwantedRound = errors.New(
		"peer has sent a vote that does not match our round for more than one round",
	)
)

Functions

This section is empty.

Types

type HeightVoteSet

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

跟踪从第0轮到第“r”轮的所有VoteSet。

还可以跟踪每个peer最多大于“回合”的一个RoundVoteSet,以促进提交的追赶同步。

A commit is +2/3 precommits for a block at a round, but which round is not known in advance, so when a peer provides a precommit for a round greater than mtx.round, we create a new entry in roundVoteSets but also remember the peer to prevent abuse. We let each peer provide us with up to 2 unexpected "catchup" rounds. One for their LastCommit round, and another for the official commit round.

func NewHeightVoteSet

func NewHeightVoteSet(chainID string, height int64, valSet *types.ValidatorSet) *HeightVoteSet

func (*HeightVoteSet) AddVote

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

Duplicate votes return added=false, err=nil. By convention, peerID is "" if origin is self.

func (*HeightVoteSet) Height

func (hvs *HeightVoteSet) Height() int64

func (*HeightVoteSet) MarshalJSON

func (hvs *HeightVoteSet) MarshalJSON() ([]byte, error)

func (*HeightVoteSet) POLInfo

func (hvs *HeightVoteSet) POLInfo() (polRound int, polBlockID types.BlockID)

Last round and blockID that has +2/3 prevotes for a particular block or nil. Returns -1 if no such round exists.

func (*HeightVoteSet) Precommits

func (hvs *HeightVoteSet) Precommits(round int) *types.VoteSet

func (*HeightVoteSet) Prevotes

func (hvs *HeightVoteSet) Prevotes(round int) *types.VoteSet

func (*HeightVoteSet) Reset

func (hvs *HeightVoteSet) Reset(height int64, valSet *types.ValidatorSet)

func (*HeightVoteSet) Round

func (hvs *HeightVoteSet) Round() int

func (*HeightVoteSet) SetPeerMaj23

func (hvs *HeightVoteSet) SetPeerMaj23(
	round int, voteType types.SignedMsgType, peerID p2p.ID, blockID types.BlockID) error

If a peer claims that it has 2/3 majority for given blockKey, call this. NOTE: if there are too many peers, or too much peer churn, this can cause memory issues. TODO: implement ability to remove peers too

func (*HeightVoteSet) SetRound

func (hvs *HeightVoteSet) SetRound(round int)

Create more RoundVoteSets up to round.

func (*HeightVoteSet) String

func (hvs *HeightVoteSet) String() string

func (*HeightVoteSet) StringIndented

func (hvs *HeightVoteSet) StringIndented(indent string) string

type PeerRoundState

type PeerRoundState struct {
	Height int64         `json:"height"` // Height peer is at
	Round  int           `json:"round"`  // Round peer is at, -1 if unknown.
	Step   RoundStepType `json:"step"`   // Step peer is at

	// Estimated start of round 0 at this height
	StartTime time.Time `json:"start_time"`

	// True if peer has proposal for this round
	Proposal                 bool                `json:"proposal"`
	ProposalBlockPartsHeader types.PartSetHeader `json:"proposal_block_parts_header"` //
	ProposalBlockParts       *bits.BitArray      `json:"proposal_block_parts"`        //
	ProposalPOLRound         int                 `json:"proposal_pol_round"`          // Proposal's POL round. -1 if none.

	// nil until ProposalPOLMessage received.
	ProposalPOL     *bits.BitArray `json:"proposal_pol"`
	Prevotes        *bits.BitArray `json:"prevotes"`          // All votes peer has for this round
	Precommits      *bits.BitArray `json:"precommits"`        // All precommits peer has for this round
	LastCommitRound int            `json:"last_commit_round"` // Round of commit for last height. -1 if none.
	LastCommit      *bits.BitArray `json:"last_commit"`       // All commit precommits of commit for last height.

	// Round that we have commit for. Not necessarily unique. -1 if none.
	CatchupCommitRound int `json:"catchup_commit_round"`

	// All commit precommits peer has for this height & CatchupCommitRound
	CatchupCommit *bits.BitArray `json:"catchup_commit"`
}

PeerRoundState 包含peer的已知状态. NOTE: Read-only when returned by PeerState.GetRoundState().

func (*PeerRoundState) Marshal

func (prs *PeerRoundState) Marshal() ([]byte, error)

Marshal returns the amino encoding.

func (*PeerRoundState) MarshalTo

func (prs *PeerRoundState) MarshalTo(data []byte) (int, error)

MarshalTo calls Marshal and copies to the given buffer.

func (*PeerRoundState) Size

func (prs *PeerRoundState) Size() int

Size returns the size of the amino encoding, in bytes.

func (PeerRoundState) String

func (prs PeerRoundState) String() string

String 字符串化PeerRoundState

func (PeerRoundState) StringIndented

func (prs PeerRoundState) StringIndented(indent string) string

StringIndented returns a string representation of the PeerRoundState

func (*PeerRoundState) Unmarshal

func (prs *PeerRoundState) Unmarshal(bs []byte) error

Unmarshal deserializes from amino encoded form.

type RoundState

type RoundState struct {
	Height    int64         `json:"height"`     // 高度
	Round     int           `json:"round"`      // 第几轮
	Step      RoundStepType `json:"step"`       // 哪个步骤
	StartTime time.Time     `json:"start_time"` // 开始时间

	// Subjective time when +2/3 precommits for Block at Round were found
	CommitTime         time.Time           `json:"commit_time"`
	Validators         *types.ValidatorSet `json:"validators"`
	Proposal           *types.Proposal     `json:"proposal"`
	ProposalBlock      *types.Block        `json:"proposal_block"`
	ProposalBlockParts *types.PartSet      `json:"proposal_block_parts"`
	LockedRound        int                 `json:"locked_round"`
	LockedBlock        *types.Block        `json:"locked_block"`
	LockedBlockParts   *types.PartSet      `json:"locked_block_parts"`

	// Last known round with POL for non-nil valid block.
	ValidRound int          `json:"valid_round"`
	ValidBlock *types.Block `json:"valid_block"` // Last known block of POL mentioned above.

	// Last known block parts of POL metnioned above.
	ValidBlockParts           *types.PartSet      `json:"valid_block_parts"`
	Votes                     *HeightVoteSet      `json:"votes"`
	CommitRound               int                 `json:"commit_round"` //
	LastCommit                *types.VoteSet      `json:"last_commit"`  // Last precommits at Height-1
	LastValidators            *types.ValidatorSet `json:"last_validators"`
	TriggeredTimeoutPrecommit bool                `json:"triggered_timeout_precommit"`
}

RoundState 定义了内部共识状态 NOTE: Not thread safe. Should only be manipulated by functions downstream of the cs.receiveRoutine

func (*RoundState) CompleteProposalEvent

func (rs *RoundState) CompleteProposalEvent() types.EventDataCompleteProposal

CompleteProposalEvent 事件,返回区块的信息

func (*RoundState) NewRoundEvent

func (rs *RoundState) NewRoundEvent() types.EventDataNewRound

NewRoundEvent 事件,返回携带出块人信息的RoundState

func (*RoundState) RoundStateEvent

func (rs *RoundState) RoundStateEvent() types.EventDataRoundState

RoundStateEvent 事件,返回高度,轮次和步骤

func (*RoundState) RoundStateSimple

func (rs *RoundState) RoundStateSimple() RoundStateSimple

将RoundState压缩为RoundStateSimple

func (*RoundState) String

func (rs *RoundState) String() string

String 仅调用StringIndented

func (*RoundState) StringIndented

func (rs *RoundState) StringIndented(indent string) string

StringIndented 返回RoundState字符串

func (*RoundState) StringShort

func (rs *RoundState) StringShort() string

StringShort returns a string

type RoundStateSimple

type RoundStateSimple struct {
	HeightRoundStep   string              `json:"height/round/step"`
	StartTime         time.Time           `json:"start_time"`
	ProposalBlockHash bytes.HexBytes      `json:"proposal_block_hash"`
	LockedBlockHash   bytes.HexBytes      `json:"locked_block_hash"`
	ValidBlockHash    bytes.HexBytes      `json:"valid_block_hash"`
	Votes             json.RawMessage     `json:"height_vote_set"`
	Proposer          types.ValidatorInfo `json:"proposer"`
}

用于RPC的压缩版 RoundState

func (*RoundStateSimple) Marshal

func (rs *RoundStateSimple) Marshal() ([]byte, error)

Marshal returns the amino encoding.

func (*RoundStateSimple) MarshalTo

func (rs *RoundStateSimple) MarshalTo(data []byte) (int, error)

MarshalTo calls Marshal and copies to the given buffer.

func (*RoundStateSimple) Size

func (rs *RoundStateSimple) Size() int

Size returns the size of the amino encoding, in bytes.

func (*RoundStateSimple) Unmarshal

func (rs *RoundStateSimple) Unmarshal(bs []byte) error

Unmarshal deserializes from amino encoded form.

type RoundStepType

type RoundStepType uint8 // 必须时数字化的,有序的

RoundStepType 枚举共识状态机的状态

func (RoundStepType) IsValid

func (rs RoundStepType) IsValid() bool

IsValid 存在这个类型,返回true

func (RoundStepType) String

func (rs RoundStepType) String() string

String 字符串化

type RoundVoteSet

type RoundVoteSet struct {
	Prevotes   *types.VoteSet
	Precommits *types.VoteSet
}

包含收到的投票集合

Jump to

Keyboard shortcuts

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