types

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2019 License: GPL-3.0 Imports: 28 Imported by: 4

Documentation

Index

Constants

View Source
const (
	MaxLimitBlockStore = 200
	MaxBlockBytes      = 1048510 // lMB
)

-------------------------------------------------------

View Source
const (
	EventCompleteProposal = "CompleteProposal"
	EventLock             = "Lock"
	//EventNewBlock          = "NewBlock"
	//EventNewBlockHeader    = "NewBlockHeader"
	EventNewRound       = "NewRound"
	EventNewRoundStep   = "NewRoundStep"
	EventPolka          = "Polka"
	EventRelock         = "Relock"
	EventTimeoutPropose = "TimeoutPropose"
	EventTimeoutWait    = "TimeoutWait"
	//EventTx                = "Tx"
	EventUnlock      = "Unlock"
	EventVote        = "Vote"
	EventMsgNotFound = "MessageUnsubscribe"
)

Reserved event types

View Source
const (
	//HealthOut peer time out
	HealthOut = 1200

	BlackDoorCount = 4

	SwitchPartWork = 0
	SwitchPartBack = 1
	SwitchPartSeed = 2
)
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
	// NOTE: RoundStepNewHeight acts as RoundStepCommitWait.
	RoundStepBlockSync = RoundStepType(0xee) // Entered commit state machine
)

RoundStepType

View Source
const (
	VoteTypePrevote   = byte(0x01)
	VoteTypePrecommit = byte(0x02)
)

Types of votes TODO Make a new type "VoteType"

View Source
const (

	//BlockPartSizeBytes is part's size
	BlockPartSizeBytes uint = 65536 // 64kB,
)
View Source
const TimeFormat = time.RFC3339Nano

TimeFormat is used for generating the sigs

Variables

View Source
var (
	//ErrPartSetUnexpectedIndex is Error part set unexpected index
	ErrPartSetUnexpectedIndex = errors.New("error part set unexpected index")
	//ErrPartSetInvalidProof is Error part set invalid proof
	ErrPartSetInvalidProof = errors.New("error part set invalid proof")
)
View Source
var (
	//ErrVoteUnexpectedStep is Error Unexpected step
	ErrVoteUnexpectedStep = errors.New("unexpected step")
	//ErrVoteInvalidValidatorIndex is Error Invalid validator index
	ErrVoteInvalidValidatorIndex = errors.New("invalid validator index")
	// ErrVoteInvalidValidatorAddress is Error Invalid validator address
	ErrVoteInvalidValidatorAddress = errors.New("invalid validator address")
	//ErrVoteInvalidSignature is Error Invalid signature
	ErrVoteInvalidSignature = errors.New("invalid signature")
	//ErrVoteInvalidBlockHash is Error Invalid block hash
	//ErrVoteInvalidBlockHash = errors.New("invalid block hash")
	//ErrVoteNonDeterministicSignature is Error Non-deterministic signature
	ErrVoteNonDeterministicSignature = errors.New("non-deterministic signature")
	//ErrVoteConflictingVotes  is Error Conflicting votes from validator
	ErrVoteConflictingVotes = errors.New("conflicting votes from validator")
	//ErrVoteNil is Error Nil vote
	ErrVoteNil = errors.New("nil vote")
)
View Source
var EnableHealthMgr = true
View Source
var (
	//ErrorGotVoteFromUnwantedRound is Peer has sent a vote that does not match our round for more than one round
	ErrorGotVoteFromUnwantedRound = errors.New("peer has sent a vote that does not match our round for more than one round")
)
View Source
var (
	//PeerStateKey is reactor key
	PeerStateKey = "ConsensusReactor.peerState"
)

Functions

func CanonicalTime

func CanonicalTime(t time.Time) string

func EqualCommitteeMemberArray

func EqualCommitteeMemberArray(a, b []*ctypes.CommitteeMember) bool

func IsVoteTypeValid

func IsVoteTypeValid(typeB byte) bool

IsVoteTypeValid return typeB is vote

func MakeBlockFromPartSet

func MakeBlockFromPartSet(reader *PartSet) (*ctypes.Block, error)

MakeBlockFromPartSet partSet to block

func RegisterBlockAmino

func RegisterBlockAmino(cdc *amino.Codec)

RegisterBlockAmino is register for block amino

Types

type BlockID

type BlockID struct {
	Hash        help.HexBytes `json:"hash"`
	PartsHeader PartSetHeader `json:"parts"`
}

BlockID defines the unique ID of a block as its Hash and its PartSetHeader

func (BlockID) Equals

func (blockID BlockID) Equals(other BlockID) bool

Equals returns true if the BlockID matches the given BlockID

func (BlockID) IsZero

func (blockID BlockID) IsZero() bool

IsZero returns true if this is the BlockID for a nil-block

func (BlockID) Key

func (blockID BlockID) Key() string

Key returns a machine-readable string representation of the BlockID

func (BlockID) String

func (blockID BlockID) String() string

String returns a human readable string representation of the BlockID

type BlockMeta

type BlockMeta struct {
	Block      *ctypes.Block
	BlockID    *BlockID
	BlockPacks *PartSet
	SeenCommit *Commit
	Proposal   *Proposal
}

BlockMeta struct

type BlockStore

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

BlockStore struct

func NewBlockStore

func NewBlockStore() *BlockStore

NewBlockStore warning all function not thread_safe

func (*BlockStore) LoadBlockCommit

func (b *BlockStore) LoadBlockCommit(height uint64) *Commit

LoadBlockCommit is load blocks commit vote

func (*BlockStore) LoadBlockMeta

func (b *BlockStore) LoadBlockMeta(height uint64) *BlockMeta

LoadBlockMeta load BlockMeta with height

func (*BlockStore) LoadBlockPart

func (b *BlockStore) LoadBlockPart(height uint64, index uint) *Part

LoadBlockPart load block part with height and index

func (*BlockStore) MaxBlockHeight

func (b *BlockStore) MaxBlockHeight() uint64

MaxBlockHeight get max fast block height

func (*BlockStore) MinBlockHeight

func (b *BlockStore) MinBlockHeight() uint64

MinBlockHeight get min fast block height

func (*BlockStore) SaveBlock

func (b *BlockStore) SaveBlock(block *ctypes.Block, blockParts *PartSet, seenCommit *Commit, proposal *Proposal)

SaveBlock save block to blockStore

type CanonicalJSONBlockID

type CanonicalJSONBlockID struct {
	Hash        help.HexBytes              `json:"hash,omitempty"`
	PartsHeader CanonicalJSONPartSetHeader `json:"parts,omitempty"`
}

func CanonicalBlockID

func CanonicalBlockID(blockID BlockID) CanonicalJSONBlockID

type CanonicalJSONHeartbeat

type CanonicalJSONHeartbeat struct {
	ChainID          string       `json:"@chain_id"`
	Type             string       `json:"@type"`
	Height           uint64       `json:"height"`
	Round            uint         `json:"round"`
	Sequence         uint         `json:"sequence"`
	ValidatorAddress help.Address `json:"validator_address"`
	ValidatorIndex   uint         `json:"validator_index"`
}

type CanonicalJSONPartSetHeader

type CanonicalJSONPartSetHeader struct {
	Hash  help.HexBytes `json:"hash,omitempty"`
	Total uint          `json:"total,omitempty"`
}

func CanonicalPartSetHeader

func CanonicalPartSetHeader(psh PartSetHeader) CanonicalJSONPartSetHeader

type CanonicalJSONProposal

type CanonicalJSONProposal struct {
	ChainID          string                     `json:"@chain_id"`
	Type             string                     `json:"@type"`
	BlockPartsHeader CanonicalJSONPartSetHeader `json:"block_parts_header"`
	Height           uint64                     `json:"height"`
	POLBlockID       CanonicalJSONBlockID       `json:"pol_block_id"`
	POLRound         uint                       `json:"pol_round"`
	Round            uint                       `json:"round"`
	Timestamp        string                     `json:"timestamp"`
}

func CanonicalProposal

func CanonicalProposal(chainID string, proposal *Proposal) CanonicalJSONProposal

type CanonicalJSONVote

type CanonicalJSONVote struct {
	ChainID   string               `json:"@chain_id"`
	Type      string               `json:"@type"`
	BlockID   CanonicalJSONBlockID `json:"block_id"`
	Height    uint64               `json:"height"`
	Round     uint                 `json:"round"`
	Timestamp string               `json:"timestamp"`
	VoteType  byte                 `json:"type"`
}

func CanonicalVote

func CanonicalVote(chainID string, vote *Vote) CanonicalJSONVote

type Commit

type Commit struct {
	// NOTE: The Precommits are in order of address to preserve the bonded ValidatorSet order.
	// Any peer with a block can gossip precommits by index with a peer without recalculating the
	// active ValidatorSet.
	BlockID    BlockID `json:"block_id"`
	Precommits []*Vote `json:"precommits"`
	// contains filtered or unexported fields
}

Commit contains the evidence that a block was committed by a set of validators. NOTE: Commit is empty for height 1, but never nil.

func (*Commit) BitArray

func (commit *Commit) BitArray() *help.BitArray

BitArray returns a BitArray of which validators voted in this commit

func (*Commit) FirstPrecommit

func (commit *Commit) FirstPrecommit() *Vote

FirstPrecommit returns the first non-nil precommit in the commit. If all precommits are nil, it returns an empty precommit with height 0.

func (*Commit) GetByIndex

func (commit *Commit) GetByIndex(index uint) *Vote

GetByIndex returns the vote corresponding to a given validator index

func (*Commit) Hash

func (commit *Commit) Hash() help.HexBytes

Hash returns the hash of the commit

func (*Commit) Height

func (commit *Commit) Height() uint64

Height returns the height of the commit

func (*Commit) IsCommit

func (commit *Commit) IsCommit() bool

IsCommit returns true if there is at least one vote

func (*Commit) Round

func (commit *Commit) Round() int

Round returns the round of the commit

func (*Commit) Size

func (commit *Commit) Size() uint

Size returns the number of votes in the commit

func (*Commit) StringIndented

func (commit *Commit) StringIndented(indent string) string

StringIndented returns a string representation of the commit

func (*Commit) Type

func (commit *Commit) Type() byte

Type returns the vote type of the commit, which is always VoteTypePrecommit

func (*Commit) ValidateBasic

func (commit *Commit) ValidateBasic() error

ValidateBasic performs basic validation that doesn't involve state data.

type EventBus

type EventBus struct {
	help.BaseService
	// contains filtered or unexported fields
}

EventBus is a common bus for all events going through the system. All calls are proxied to underlying pubsub server. All events must be published using EventBus to ensure correct data types.

func NewEventBus

func NewEventBus() *EventBus

NewEventBus returns a new event bus.

func (*EventBus) OnStart

func (b *EventBus) OnStart() error

OnStart eventBus start

func (*EventBus) OnStop

func (b *EventBus) OnStop()

OnStop eventBus stop

func (*EventBus) PublishEventCompleteProposal

func (b *EventBus) PublishEventCompleteProposal(event EventDataRoundState) error

PublishEventCompleteProposal send event data common EventCompleteProposal

func (*EventBus) PublishEventLock

func (b *EventBus) PublishEventLock(event EventDataRoundState) error

PublishEventLock send event data common

func (*EventBus) PublishEventNewRound

func (b *EventBus) PublishEventNewRound(event EventDataRoundState) error

PublishEventNewRound send event data common EventNewRound

func (*EventBus) PublishEventNewRoundStep

func (b *EventBus) PublishEventNewRoundStep(event EventDataRoundState) error

PublishEventNewRoundStep send event data common EventNewRoundStep

func (*EventBus) PublishEventPolka

func (b *EventBus) PublishEventPolka(event EventDataRoundState) error

PublishEventPolka send event data common EventPolka

func (*EventBus) PublishEventRelock

func (b *EventBus) PublishEventRelock(event EventDataRoundState) error

PublishEventRelock send event data common relock

func (*EventBus) PublishEventTimeoutPropose

func (b *EventBus) PublishEventTimeoutPropose(event EventDataRoundState) error

PublishEventTimeoutPropose send event data common EventTimeoutPropose

func (*EventBus) PublishEventTimeoutWait

func (b *EventBus) PublishEventTimeoutWait(event EventDataRoundState) error

PublishEventTimeoutWait send event data common EventTimeoutWait

func (*EventBus) PublishEventUnlock

func (b *EventBus) PublishEventUnlock(event EventDataRoundState) error

PublishEventUnlock send event data common unlock

func (*EventBus) PublishEventVote

func (b *EventBus) PublishEventVote(event EventDataVote) error

PublishEventVote send event data common EventVote

func (*EventBus) Subscribe

func (b *EventBus) Subscribe(key string, out chan<- interface{}) event.Subscription

Subscribe chan<- interface{}

type EventCallback

type EventCallback func(data EventData)

EventCallback call back event

type EventData

type EventData interface {
}

EventData Generic event data can be typed and registered with go-amino via concrete implementation of this interface

type EventDataCommon

type EventDataCommon struct {
	Key  string              `json:"key"`
	Data EventDataRoundState `json:"data"`
}

EventDataCommon struct

type EventDataRoundState

type EventDataRoundState struct {
	Height uint64 `json:"height"`
	Round  uint   `json:"round"`
	Step   string `json:"step"`

	// private, not exposed to websockets
	RoundState interface{} `json:"-"`
}

EventDataRoundState NOTE: This goes into the replay WAL

type EventDataVote

type EventDataVote struct {
	Vote *Vote
}

EventDataVote event vote

type EventSwitch

type EventSwitch interface {
	help.Service
	Fireable

	AddListenerForEvent(listenerID, event string, cb EventCallback)
	RemoveListenerForEvent(event string, listenerID string)
	RemoveListener(listenerID string)
}

EventSwitch interface

func NewEventSwitch

func NewEventSwitch() EventSwitch

NewEventSwitch new

type Eventable

type Eventable interface {
	SetEventSwitch(evsw EventSwitch)
}

Eventable reactors and other modules should export this interface to become eventable

type Fireable

type Fireable interface {
	FireEvent(event string, data EventData)
}

Fireable an event switch or cache implements fireable

type Health

type Health struct {
	ID    tp2p.ID
	IP    string
	Port  uint32
	Tick  int32
	State uint32
	HType uint32
	Val   *Validator
	Self  bool
}

Health struct

func NewHealth

func NewHealth(id tp2p.ID, t, state uint32, val *Validator, Self bool) *Health

NewHealth new

func (*Health) Equal

func (h *Health) Equal(other *Health) bool

Equal return true they are same id or both nil otherwise return false

func (*Health) SimpleString

func (h *Health) SimpleString() string

SimpleString string

func (*Health) String

func (h *Health) String() string

type HealthMgr

type HealthMgr struct {
	help.BaseService
	Work map[tp2p.ID]*Health
	Back []*Health
	// contains filtered or unexported fields
}

HealthMgr struct

func NewHealthMgr

func NewHealthMgr(cid uint64) *HealthMgr

NewHealthMgr func

func (*HealthMgr) ChanFrom

func (h *HealthMgr) ChanFrom() chan *SwitchValidator

ChanFrom get switchChanTo for recv from state

func (*HealthMgr) ChanTo

func (h *HealthMgr) ChanTo() chan *SwitchValidator

ChanTo get switchChanTo for send to state

func (*HealthMgr) GetHealth

func (h *HealthMgr) GetHealth(adress []byte) *Health

func (*HealthMgr) OnStart

func (h *HealthMgr) OnStart() error

OnStart mgr start

func (*HealthMgr) OnStop

func (h *HealthMgr) OnStop()

OnStop mgr stop

func (*HealthMgr) PutBackHealth

func (h *HealthMgr) PutBackHealth(he *Health)

PutBackHealth add a *health to back

func (*HealthMgr) PutWorkHealth

func (h *HealthMgr) PutWorkHealth(he *Health)

PutWorkHealth add a *health to work

func (*HealthMgr) Sum

func (h *HealthMgr) Sum() int

Sum invoke in the testing, after mgr start

func (*HealthMgr) Switch

func (h *HealthMgr) Switch(s *SwitchValidator)

Switch send switch

func (*HealthMgr) UpdataHealthInfo

func (h *HealthMgr) UpdataHealthInfo(id tp2p.ID, ip string, port uint32, pk []byte)

UpdataHealthInfo update one health

func (*HealthMgr) Update

func (h *HealthMgr) Update(id tp2p.ID)

Update tick

func (*HealthMgr) UpdateFromCommittee

func (h *HealthMgr) UpdateFromCommittee(member, backMember ctypes.CommitteeMembers)

UpdateFromCommittee agent put member and back, update flag

func (*HealthMgr) VerifySwitch

func (h *HealthMgr) VerifySwitch(sv *SwitchValidator) error

VerifySwitch verify remove and add switchEnter

type HealthsByAddress

type HealthsByAddress []*Health

HealthsByAddress Sort Healths by address

func (HealthsByAddress) Len

func (hs HealthsByAddress) Len() int

func (HealthsByAddress) Less

func (hs HealthsByAddress) Less(i, j int) bool

func (HealthsByAddress) Swap

func (hs HealthsByAddress) Swap(i, j int)

type HeightVoteSet

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

HeightVoteSet comment

Keeps track of all VoteSets from round 0 to round 'round'.

Also keeps track of up to one RoundVoteSet greater than 'round' from each peer, to facilitate catchup syncing of commits.

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 uint64, valSet *ValidatorSet) *HeightVoteSet

NewHeightVoteSet get new HeightVoteSet

func (*HeightVoteSet) AddVote

func (hvs *HeightVoteSet) AddVote(vote *Vote, peerID string) (added bool, err error)

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

func (*HeightVoteSet) GetSignsFromVote

func (hvs *HeightVoteSet) GetSignsFromVote(round int, hash []byte, addr help.Address) *KeepBlockSign

GetSignsFromVote get sign from all round

func (*HeightVoteSet) Height

func (hvs *HeightVoteSet) Height() uint64

Height get now VoteSet Height

func (*HeightVoteSet) MarshalJSON

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

MarshalJSON get all votes json

func (*HeightVoteSet) POLInfo

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

POLInfo 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) *VoteSet

Precommits get preCommit vote

func (*HeightVoteSet) Prevotes

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

Prevotes get preVote vote

func (*HeightVoteSet) Reset

func (hvs *HeightVoteSet) Reset(height uint64, valSet *ValidatorSet)

Reset is reset ValidatorSet

func (*HeightVoteSet) Round

func (hvs *HeightVoteSet) Round() int

Round get now VoteSet round

func (*HeightVoteSet) SetPeerMaj23

func (hvs *HeightVoteSet) SetPeerMaj23(round int, typeB byte, peerID string, blockID BlockID) error

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

SetRound Create more RoundVoteSets up to round.

func (*HeightVoteSet) String

func (hvs *HeightVoteSet) String() string

--------------------------------------------------------- string and json

func (*HeightVoteSet) StringIndented

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

StringIndented get Indented voteSet string

type KeepBlockSign

type KeepBlockSign struct {
	Result uint
	Sign   []byte
	Hash   common.Hash
}

KeepBlockSign is block's sign

type P2PID

type P2PID string

P2PID UNSTABLE XXX: duplicate of p2p.ID to avoid dependence between packages. Perhaps we can have a minimal types package containing this (and other things?) that both `types` and `p2p` import ?

type Part

type Part struct {
	Index uint             `json:"index"`
	Bytes help.HexBytes    `json:"bytes"`
	Proof help.SimpleProof `json:"proof"`
	// contains filtered or unexported fields
}

Part struct

func (*Part) Hash

func (part *Part) Hash() []byte

Hash is part's hash

func (*Part) String

func (part *Part) String() string

func (*Part) StringIndented

func (part *Part) StringIndented(indent string) string

StringIndented indent's string

type PartSet

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

PartSet struct

func MakePartSet

func MakePartSet(partSize uint, block *ctypes.Block) (*PartSet, error)

MakePartSet block to partset

func NewPartSetFromData

func NewPartSetFromData(data []byte, partSize uint) *PartSet

NewPartSetFromData Returns an immutable, full PartSet from the data bytes. The data bytes are split into "partSize" chunks, and merkle tree computed.

func NewPartSetFromHeader

func NewPartSetFromHeader(header PartSetHeader) *PartSet

NewPartSetFromHeader Returns an empty PartSet ready to be populated.

func (*PartSet) AddPart

func (ps *PartSet) AddPart(part *Part) (bool, error)

AddPart add a part to parts array

func (*PartSet) BitArray

func (ps *PartSet) BitArray() *help.BitArray

BitArray return BitArray's Copy

func (*PartSet) Count

func (ps *PartSet) Count() uint

Count Count of parts

func (*PartSet) GetPart

func (ps *PartSet) GetPart(index uint) *Part

GetPart get a part for index

func (*PartSet) GetReader

func (ps *PartSet) GetReader() io.Reader

GetReader get a new reader if not complete

func (*PartSet) HasHeader

func (ps *PartSet) HasHeader(header PartSetHeader) bool

HasHeader Compare header

func (*PartSet) Hash

func (ps *PartSet) Hash() []byte

Hash return ps'hash

func (*PartSet) HashesTo

func (ps *PartSet) HashesTo(hash []byte) bool

HashesTo Compare two hashes

func (*PartSet) Header

func (ps *PartSet) Header() PartSetHeader

Header get partSet's header

func (*PartSet) IsComplete

func (ps *PartSet) IsComplete() bool

IsComplete if get all part

func (*PartSet) MarshalJSON

func (ps *PartSet) MarshalJSON() ([]byte, error)

MarshalJSON is marshal partsBitArray to json

func (*PartSet) StringShort

func (ps *PartSet) StringShort() string

StringShort print partSet count and total

func (*PartSet) Total

func (ps *PartSet) Total() uint

Total sum of parts

type PartSetHeader

type PartSetHeader struct {
	Total uint          `json:"total"`
	Hash  help.HexBytes `json:"hash"`
}

PartSetHeader struct

func (PartSetHeader) Equals

func (psh PartSetHeader) Equals(other PartSetHeader) bool

Equals compare other partSet header's hash

func (PartSetHeader) IsZero

func (psh PartSetHeader) IsZero() bool

IsZero is have part

func (PartSetHeader) String

func (psh PartSetHeader) String() string

type PartSetReader

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

PartSetReader struct

func NewPartSetReader

func NewPartSetReader(parts []*Part) *PartSetReader

NewPartSetReader return new reader

func (*PartSetReader) Read

func (psr *PartSetReader) Read(p []byte) (n int, err error)

Read read a partSet bytes

type PeerRoundState

type PeerRoundState struct {
	Height                   uint64         `json:"height"`                      // Height peer is at
	Round                    uint           `json:"round"`                       // Round peer is at, -1 if unknown.
	Step                     RoundStepType  `json:"step"`                        // Step peer is at
	StartTime                time.Time      `json:"start_time"`                  // Estimated start of round 0 at this height
	Proposal                 bool           `json:"proposal"`                    // True if peer has proposal for this round
	ProposalBlockPartsHeader PartSetHeader  `json:"proposal_block_parts_header"` //
	ProposalBlockParts       *help.BitArray `json:"proposal_block_parts"`        //
	ProposalPOLRound         uint           `json:"proposal_pol_round"`          // Proposal's POL round. -1 if none.
	ProposalPOL              *help.BitArray `json:"proposal_pol"`                // nil until ProposalPOLMessage received.
	Prevotes                 *help.BitArray `json:"prevotes"`                    // All votes peer has for this round
	Precommits               *help.BitArray `json:"precommits"`                  // All precommits peer has for this round
	LastCommitRound          uint           `json:"last_commit_round"`           // Round of commit for last height. -1 if none.
	LastCommit               *help.BitArray `json:"last_commit"`                 // All commit precommits of commit for last height.
	CatchupCommitRound       int            `json:"catchup_commit_round"`        // Round that we have commit for. Not necessarily unique. -1 if none.
	CatchupCommit            *help.BitArray `json:"catchup_commit"`              // All commit precommits peer has for this height & CatchupCommitRound
}

PeerRoundState contains the known state of a peer. NOTE: Read-only when returned by PeerState.GetRoundState().

func (PeerRoundState) String

func (prs PeerRoundState) String() string

String returns a string representation of the PeerRoundState

func (PeerRoundState) StringIndented

func (prs PeerRoundState) StringIndented(indent string) string

StringIndented returns a string representation of the PeerRoundState

type PrivValidator

type PrivValidator interface {
	GetAddress() help.Address // redundant since .PubKey().Address()
	GetPubKey() tcrypto.PubKey

	SignVote(chainID string, vote *Vote) error
	SignProposal(chainID string, proposal *Proposal) error
}

PrivValidator defines the functionality of a local TrueChain validator that signs votes, proposals, and heartbeats, and never double signs.

func NewPrivValidator

func NewPrivValidator(priv ecdsa.PrivateKey) PrivValidator

NewPrivValidator return new private Validator

type PrivValidatorsByAddress

type PrivValidatorsByAddress []PrivValidator

PrivValidatorsByAddress is private validators for address

func (PrivValidatorsByAddress) Len

func (pvs PrivValidatorsByAddress) Len() int

func (PrivValidatorsByAddress) Less

func (pvs PrivValidatorsByAddress) Less(i, j int) bool

func (PrivValidatorsByAddress) Swap

func (pvs PrivValidatorsByAddress) Swap(i, j int)

type Proposal

type Proposal struct {
	Height           uint64        `json:"height"`
	Round            uint          `json:"round"`
	Timestamp        time.Time     `json:"timestamp"`
	BlockPartsHeader PartSetHeader `json:"block_parts_header"`
	POLRound         uint          `json:"pol_round"`    // -1 if null.
	POLBlockID       BlockID       `json:"pol_block_id"` // zero if null.
	Signature        []byte        `json:"signature"`
}

Proposal defines a block proposal for the consensus. It refers to the block only by its PartSetHeader. It must be signed by the correct proposer for the given Height/Round to be considered valid. It may depend on votes from a previous round, a so-called Proof-of-Lock (POL) round, as noted in the POLRound and POLBlockID.

func NewProposal

func NewProposal(height uint64, round int, blockPartsHeader PartSetHeader, polRound uint, polBlockID BlockID) *Proposal

NewProposal returns a new Proposal. If there is no POLRound, polRound should be -1.

func (*Proposal) SignBytes

func (p *Proposal) SignBytes(chainID string) []byte

SignBytes returns the Proposal bytes for signing

func (*Proposal) String

func (p *Proposal) String() string

String returns a string representation of the Proposal.

type RoundState

type RoundState struct {
	Height             uint64         `json:"height"` // Height we are working on
	Round              uint           `json:"round"`
	Step               RoundStepType  `json:"step"`
	StartTime          time.Time      `json:"start_time"`
	CommitTime         time.Time      `json:"commit_time"` // Subjective time when +2/3 precommits for Block at Round were found
	Validators         *ValidatorSet  `json:"validators"`
	Proposal           *Proposal      `json:"proposal"`
	ProposalBlock      *types.Block   `json:"proposal_block"`
	ProposalBlockParts *PartSet       `json:"proposal_block_parts"`
	LockedRound        uint           `json:"locked_round"`
	LockedBlock        *types.Block   `json:"locked_block"`
	LockedBlockParts   *PartSet       `json:"locked_block_parts"`
	ValidRound         uint           `json:"valid_round"`       // Last known round with POL for non-nil valid block.
	ValidBlock         *types.Block   `json:"valid_block"`       // Last known block of POL mentioned above.
	ValidBlockParts    *PartSet       `json:"valid_block_parts"` // Last known block parts of POL metnioned above.
	Votes              *HeightVoteSet `json:"votes"`
	CommitRound        uint           `json:"commit_round"` //
	LastCommit         *VoteSet       `json:"last_commit"`  // Last precommits at Height-1
}

RoundState defines the internal consensus state. NOTE: Not thread safe. Should only be manipulated by functions downstream of the cs.receiveRoutine

func (*RoundState) RoundStateEvent

func (rs *RoundState) RoundStateEvent() EventDataRoundState

RoundStateEvent returns the H/R/S of the RoundState as an event.

func (*RoundState) RoundStateSimple

func (rs *RoundState) RoundStateSimple() RoundStateSimple

RoundStateSimple Compress the RoundState to RoundStateSimple

func (*RoundState) String

func (rs *RoundState) String() string

String returns a string

func (*RoundState) StringIndented

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

StringIndented returns a string

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 help.HexBytes   `json:"proposal_block_hash"`
	LockedBlockHash   help.HexBytes   `json:"locked_block_hash"`
	ValidBlockHash    help.HexBytes   `json:"valid_block_hash"`
	Votes             json.RawMessage `json:"height_vote_set"`
}

RoundStateSimple Compressed version of the RoundState for use in RPC

type RoundStepType

type RoundStepType uint8 // These must be numeric, ordered.

RoundStepType enumerates the state of the consensus state machine

func (RoundStepType) String

func (rs RoundStepType) String() string

String returns a string

type RoundVoteSet

type RoundVoteSet struct {
	Prevotes   *VoteSet
	Precommits *VoteSet
}

RoundVoteSet struct

type StateAgent

type StateAgent interface {
	GetValidator() *ValidatorSet
	UpdateValidator(vset *ValidatorSet, makeids bool) error
	GetLastValidator() *ValidatorSet
	GetLastValidatorAddress() common.Address

	GetLastBlockHeight() uint64
	SetEndHeight(h uint64)
	SetBeginHeight(h uint64)
	GetChainID() string
	MakeBlock(v *SwitchValidator) (*ctypes.Block, error)
	MakePartSet(partSize uint, block *ctypes.Block) (*PartSet, error)
	ValidateBlock(block *ctypes.Block, result bool) (*KeepBlockSign, error)
	ConsensusCommit(block *ctypes.Block) error

	GetAddress() help.Address
	GetPubKey() tcrypto.PubKey
	SignVote(chainID string, vote *Vote) error
	SignProposal(chainID string, proposal *Proposal) error
	PrivReset()
}

StateAgent implements PrivValidator

type StateAgentImpl

type StateAgentImpl struct {
	Priv       *privValidator
	Agent      ctypes.PbftAgentProxy
	Validators *ValidatorSet

	ChainID     string
	LastHeight  uint64
	BeginHeight uint64
	EndHeight   uint64
	CID         uint64
	// contains filtered or unexported fields
}

StateAgentImpl agent state struct

func NewStateAgent

func NewStateAgent(agent ctypes.PbftAgentProxy, chainID string,
	vals *ValidatorSet, height, cid uint64) *StateAgentImpl

NewStateAgent return new agent state

func (*StateAgentImpl) Broadcast

func (state *StateAgentImpl) Broadcast(height *big.Int)

Broadcast is agent Broadcast block

func (*StateAgentImpl) ConsensusCommit

func (state *StateAgentImpl) ConsensusCommit(block *ctypes.Block) error

ConsensusCommit is BroadcastConsensus block to agent

func (*StateAgentImpl) GetAddress

func (state *StateAgentImpl) GetAddress() help.Address

GetAddress get priv_validator's address

func (*StateAgentImpl) GetChainID

func (state *StateAgentImpl) GetChainID() string

GetChainID is get state'chainID

func (*StateAgentImpl) GetLastBlockHeight

func (state *StateAgentImpl) GetLastBlockHeight() uint64

GetLastBlockHeight is get fast block height for agent

func (*StateAgentImpl) GetLastValidator

func (state *StateAgentImpl) GetLastValidator() *ValidatorSet

GetLastValidator is get state's Validators

func (*StateAgentImpl) GetLastValidatorAddress

func (state *StateAgentImpl) GetLastValidatorAddress() common.Address

func (*StateAgentImpl) GetPubKey

func (state *StateAgentImpl) GetPubKey() tcrypto.PubKey

GetPubKey get priv_validator's public key

func (*StateAgentImpl) GetValidator

func (state *StateAgentImpl) GetValidator() *ValidatorSet

GetValidator is get state's Validators

func (*StateAgentImpl) HasPeerID

func (state *StateAgentImpl) HasPeerID(id string) error

HasPeerID judge the peerid whether in validators

func (*StateAgentImpl) MakeBlock

func (state *StateAgentImpl) MakeBlock(v *SwitchValidator) (*ctypes.Block, error)

MakeBlock from agent FetchFastBlock

func (*StateAgentImpl) MakePartSet

func (state *StateAgentImpl) MakePartSet(partSize uint, block *ctypes.Block) (*PartSet, error)

MakePartSet make block to part for partSiae

func (*StateAgentImpl) PrivReset

func (state *StateAgentImpl) PrivReset()

PrivReset reset PrivValidator

func (*StateAgentImpl) SetBeginHeight

func (state *StateAgentImpl) SetBeginHeight(h uint64)

SetBeginHeight set height of block for the committee to begin. (begin,end]

func (*StateAgentImpl) SetEndHeight

func (state *StateAgentImpl) SetEndHeight(h uint64)

SetEndHeight set now committee fast block height for end. (begin,end]

func (*StateAgentImpl) SetPrivValidator

func (state *StateAgentImpl) SetPrivValidator(priv PrivValidator)

SetPrivValidator set state a new PrivValidator

func (*StateAgentImpl) SignProposal

func (state *StateAgentImpl) SignProposal(chainID string, proposal *Proposal) error

SignProposal sign of proposal msg

func (*StateAgentImpl) SignVote

func (state *StateAgentImpl) SignVote(chainID string, vote *Vote) error

SignVote sign of vote

func (*StateAgentImpl) UpdateValidator

func (state *StateAgentImpl) UpdateValidator(vset *ValidatorSet, makeids bool) error

UpdateValidator set new Validators when committee member was changed

func (*StateAgentImpl) ValidateBlock

func (state *StateAgentImpl) ValidateBlock(block *ctypes.Block, result bool) (*KeepBlockSign, error)

ValidateBlock get a verify block if nil return new

type SwitchValidator

type SwitchValidator struct {
	Remove    *Health
	Add       *Health
	Infos     []*ctypes.CommitteeMember
	Resion    string
	From      int // 0-- add ,1-- resore
	DoorCount int
	Round     int // -1 not exc,no lock
	ID        uint64
}

SwitchValidator struct

func (*SwitchValidator) Equal

func (s *SwitchValidator) Equal(other *SwitchValidator) bool

Equal return true they are same id or both nil otherwise return false

func (*SwitchValidator) EqualWithRemove

func (s *SwitchValidator) EqualWithRemove(other *SwitchValidator) bool

EqualWithRemove return true they are same id or both nil otherwise return false

func (*SwitchValidator) EqualWithoutID

func (s *SwitchValidator) EqualWithoutID(other *SwitchValidator) bool

EqualWithoutID return true they are same id or both nil otherwise return false

func (*SwitchValidator) String

func (s *SwitchValidator) String() string

type Validator

type Validator struct {
	Address     help.Address  `json:"address"`
	PubKey      crypto.PubKey `json:"pub_key"`
	VotingPower int64         `json:"voting_power"`
	Accum       int64         `json:"accum"`
}

Validator state for each Validator NOTE: The Accum is not included in Validator.Hash(); make sure to update that method if changes are made here

func NewValidator

func NewValidator(pubKey crypto.PubKey, votingPower int64) *Validator

NewValidator is return a new Validator

func (*Validator) CompareAccum

func (v *Validator) CompareAccum(other *Validator) *Validator

CompareAccum Returns the one with higher Accum.

func (*Validator) Copy

func (v *Validator) Copy() *Validator

Copy Creates a new copy of the validator so we can mutate accum. Panics if the validator is nil.

func (*Validator) Hash

func (v *Validator) Hash() []byte

Hash computes the unique ID of a validator with a given voting power. It excludes the Accum value, which changes with every round.

func (*Validator) String

func (v *Validator) String() string

type ValidatorSet

type ValidatorSet struct {
	// NOTE: persisted via reflect, must be exported.
	Validators []*Validator `json:"validators"`
	Proposer   *Validator   `json:"proposer"`
	// contains filtered or unexported fields
}

ValidatorSet represent a set of *Validator at a given height. The validators can be fetched by address or index. The index is in order of .Address, so the indices are fixed for all rounds of a given blockchain height. On the other hand, the .AccumPower of each validator and the designated .GetProposer() of a set changes every round, upon calling .IncrementAccum(). NOTE: Not goroutine-safe. NOTE: All get/set to validators should copy the value for safety.

func NewValidatorSet

func NewValidatorSet(vals []*Validator) *ValidatorSet

NewValidatorSet is make a Validator to ValidatorSet

func (*ValidatorSet) Add

func (valSet *ValidatorSet) Add(val *Validator) (added bool)

Add adds val to the validator set and returns true. It returns false if val is already in the set.

func (*ValidatorSet) Copy

func (valSet *ValidatorSet) Copy() *ValidatorSet

Copy each validator into a new ValidatorSet

func (*ValidatorSet) FindValidatorSetProposer

func (valSet *ValidatorSet) FindValidatorSetProposer(address common.Address)

func (*ValidatorSet) GetByAddress

func (valSet *ValidatorSet) GetByAddress(address []byte) (index int, val *Validator)

GetByAddress returns an index of the validator with address and validator itself if found. Otherwise, -1 and nil are returned.

func (*ValidatorSet) GetByIndex

func (valSet *ValidatorSet) GetByIndex(index uint) (address []byte, val *Validator)

GetByIndex returns the validator's address and validator itself by index. It returns nil values if index is less than 0 or greater or equal to len(ValidatorSet.Validators).

func (*ValidatorSet) GetProposer

func (valSet *ValidatorSet) GetProposer() (proposer *Validator)

GetProposer returns the current proposer. If the validator set is empty, nil is returned.

func (*ValidatorSet) HasAddress

func (valSet *ValidatorSet) HasAddress(address []byte) bool

HasAddress returns true if address given is in the validator set, false - otherwise.

func (*ValidatorSet) Hash

func (valSet *ValidatorSet) Hash() []byte

Hash returns the Merkle root hash build using validators (as leaves) in the set.

func (*ValidatorSet) IncrementAccum

func (valSet *ValidatorSet) IncrementAccum(times uint)

IncrementAccum increments accum of each validator and updates the proposer. Panics if validator set is empty.

func (*ValidatorSet) Iterate

func (valSet *ValidatorSet) Iterate(fn func(index int, val *Validator) bool)

Iterate will run the given function over the set.

func (*ValidatorSet) MakeIDs

func (valSet *ValidatorSet) MakeIDs() map[string]interface{}

func (*ValidatorSet) Remove

func (valSet *ValidatorSet) Remove(address []byte) (val *Validator, removed bool)

Remove deletes the validator with address. It returns the validator removed and true. If returns nil and false if validator is not present in the set.

func (*ValidatorSet) RemoveForPK

func (valSet *ValidatorSet) RemoveForPK(pk ecdsa.PublicKey) (val *Validator, removed bool)

RemoveForPK deletes the validator with address. It returns the validator removed and true. If returns nil and false if validator is not present in the set.

func (*ValidatorSet) Size

func (valSet *ValidatorSet) Size() uint

Size returns the length of the validator set.

func (*ValidatorSet) String

func (valSet *ValidatorSet) String() string

func (*ValidatorSet) StringIndented

func (valSet *ValidatorSet) StringIndented(indent string) string

StringIndented is VoteSet Indented format String

func (*ValidatorSet) TotalVotingPower

func (valSet *ValidatorSet) TotalVotingPower() int64

TotalVotingPower returns the sum of the voting powers of all validators.

func (*ValidatorSet) Update

func (valSet *ValidatorSet) Update(val *Validator) (updated bool)

Update updates val and returns true. It returns false if val is not present in the set.

func (*ValidatorSet) VerifyCommit

func (valSet *ValidatorSet) VerifyCommit(chainID string, blockID BlockID, height uint64, commit *Commit) error

VerifyCommit Verify that +2/3 of the set had signed the given signBytes

func (*ValidatorSet) VerifyCommitAny

func (valSet *ValidatorSet) VerifyCommitAny(newSet *ValidatorSet, chainID string,
	blockID BlockID, height uint64, commit *Commit) error

VerifyCommitAny will check to see if the set would be valid with a different validator set.

valSet is the validator set that we know * over 2/3 of the power in old signed this block

newSet is the validator set that signed this block

  • only votes from old are sufficient for 2/3 majority in the new set as well

That means that: * 10% of the valset can't just declare themselves kings * If the validator set is 3x old size, we need more proof to trust

type ValidatorsByAddress

type ValidatorsByAddress []*Validator

ValidatorsByAddress is Sort validators by address

func (ValidatorsByAddress) Len

func (vs ValidatorsByAddress) Len() int

func (ValidatorsByAddress) Less

func (vs ValidatorsByAddress) Less(i, j int) bool

func (ValidatorsByAddress) Swap

func (vs ValidatorsByAddress) Swap(i, j int)

type Vote

type Vote struct {
	ValidatorAddress help.Address `json:"validator_address"`
	ValidatorIndex   uint         `json:"validator_index"`
	Height           uint64       `json:"height"`
	Round            uint         `json:"round"`
	Result           uint         `json:"result"`
	Timestamp        time.Time    `json:"timestamp"`
	Type             byte         `json:"type"`
	BlockID          BlockID      `json:"block_id"` // zero if vote is nil.
	Signature        []byte       `json:"signature"`
	ResultSign       []byte       `json:"reuslt_signature"`
}

Vote Represents a prevote, precommit, or commit vote from validators for consensus.

func (*Vote) Copy

func (vote *Vote) Copy() *Vote

Copy return a vote Copy

func (*Vote) SignBytes

func (vote *Vote) SignBytes(chainID string) []byte

SignBytes is sign CanonicalVote and return rlpHash

func (*Vote) String

func (vote *Vote) String() string

func (*Vote) Verify

func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error

Verify is Verify Signature and ValidatorAddress

type VoteSet

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

VoteSet comment

VoteSet helps collect signatures from validators at each height+round for a
predefined vote type.

We need VoteSet to be able to keep track of conflicting votes when validators
double-sign.  Yet, we can't keep track of *all* the votes seen, as that could
be a DoS attack vector.

There are two storage areas for votes.
1. voteSet.votes
2. voteSet.votesByBlock

`.votes` is the "canonical" list of votes.  It always has at least one vote,
if a vote from a validator had been seen at all.  Usually it keeps track of
the first vote seen, but when a 2/3 majority is found, votes for that get
priority and are copied over from `.votesByBlock`.

`.votesByBlock` keeps track of a list of votes for a particular block.  There
are two ways a &blockVotes{} gets created in `.votesByBlock`.
1. the first vote seen by a validator was for the particular block.
2. a peer claims to have seen 2/3 majority for the particular block.

Since the first vote from a validator will always get added in `.votesByBlock`
, all votes in `.votes` will have a corresponding entry in `.votesByBlock`.

When a &blockVotes{} in `.votesByBlock` reaches a 2/3 majority quorum, its
votes are copied into `.votes`.

All this is memory bounded because conflicting votes only get added if a peer
told us to track that block, each peer only gets to tell us 1 such block, and,
there's only a limited number of peers.

NOTE: Assumes that the sum total of voting power does not exceed MaxUInt64.

func NewVoteSet

func NewVoteSet(chainID string, height uint64, round int, typeB byte, valSet *ValidatorSet) *VoteSet

NewVoteSet Constructs a new VoteSet struct used to accumulate votes for given height/round.

func (*VoteSet) AddVote

func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error)

AddVote Returns added=true if vote is valid and new. Otherwise returns err=ErrVote[

UnexpectedStep | InvalidIndex | InvalidAddress |
InvalidSignature | InvalidBlockHash | ConflictingVotes ]

Duplicate votes return added=false, err=nil. Conflicting votes return added=*, err=ErrVoteConflictingVotes. NOTE: vote should not be mutated after adding. NOTE: VoteSet must not be nil NOTE: Vote must not be nil

func (*VoteSet) BitArray

func (voteSet *VoteSet) BitArray() *help.BitArray

BitArray get voteSet's bitArray

func (*VoteSet) BitArrayByBlockID

func (voteSet *VoteSet) BitArrayByBlockID(blockID BlockID) *help.BitArray

BitArrayByBlockID get a BitArray for blockID

func (*VoteSet) BitArrayString

func (voteSet *VoteSet) BitArrayString() string

BitArrayString Return the bit-array of votes including the fraction of power that has voted like: "BA{29:xx__x__x_x___x__x_______xxx__} 856/1304 = 0.66"

func (*VoteSet) ChainID

func (voteSet *VoteSet) ChainID() string

ChainID is return VoteSet's ChainID

func (*VoteSet) GetByAddress

func (voteSet *VoteSet) GetByAddress(address []byte) *Vote

GetByAddress is get a vote for address

func (*VoteSet) GetByIndex

func (voteSet *VoteSet) GetByIndex(valIndex uint) *Vote

GetByIndex if validator has conflicting votes, returns "canonical" vote

func (*VoteSet) GetSignByAddress

func (voteSet *VoteSet) GetSignByAddress(addr help.Address) *KeepBlockSign

GetSignByAddress is address to KeepBlockSign

func (*VoteSet) HasAll

func (voteSet *VoteSet) HasAll() bool

HasAll is if have all vote

func (*VoteSet) HasTwoThirdsAny

func (voteSet *VoteSet) HasTwoThirdsAny() bool

HasTwoThirdsAny return is have up 2/3

func (*VoteSet) HasTwoThirdsMajority

func (voteSet *VoteSet) HasTwoThirdsMajority() bool

HasTwoThirdsMajority check is have first block id

func (*VoteSet) Height

func (voteSet *VoteSet) Height() uint64

Height is return VoteSet's height

func (*VoteSet) IsCommit

func (voteSet *VoteSet) IsCommit() bool

IsCommit check if is commit

func (*VoteSet) MakeCommit

func (voteSet *VoteSet) MakeCommit() *Commit

MakeCommit is make Commit

func (*VoteSet) MakePbftSigns

func (voteSet *VoteSet) MakePbftSigns(thash []byte) ([]*ttypes.PbftSign, error)

MakePbftSigns is make a signs for hash

func (*VoteSet) MarshalJSON

func (voteSet *VoteSet) MarshalJSON() ([]byte, error)

MarshalJSON Marshal the VoteSet to JSON. Same as String(), just in JSON, and without the height/round/typeB (since its already included in the votes).

func (*VoteSet) Round

func (voteSet *VoteSet) Round() int

Round is return VoteSet's round

func (*VoteSet) SetPeerMaj23

func (voteSet *VoteSet) SetPeerMaj23(peerID P2PID, blockID BlockID) error

SetPeerMaj23 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 NOTE: VoteSet must not be nil

func (*VoteSet) Size

func (voteSet *VoteSet) Size() uint

Size is return VoteSet's size

func (*VoteSet) String

func (voteSet *VoteSet) String() string

Strings and JSON

func (*VoteSet) StringIndented

func (voteSet *VoteSet) StringIndented(indent string) string

StringIndented is format print VoteSet indented

func (*VoteSet) StringShort

func (voteSet *VoteSet) StringShort() string

StringShort is format VteSet to short format

func (*VoteSet) TwoThirdsMajority

func (voteSet *VoteSet) TwoThirdsMajority() (blockID BlockID, ok bool)

TwoThirdsMajority If there was a +2/3 majority for blockID, return blockID and true. Else, return the empty BlockID{} and false.

func (*VoteSet) Type

func (voteSet *VoteSet) Type() byte

Type is return VoteSet's type

func (*VoteSet) VoteStrings

func (voteSet *VoteSet) VoteStrings() []string

VoteStrings Returns a list of votes compressed to more readable strings.

type VoteSetJSON

type VoteSetJSON struct {
	Votes         []string          `json:"votes"`
	VotesBitArray string            `json:"votes_bit_array"`
	PeerMaj23s    map[P2PID]BlockID `json:"peer_maj_23s"`
}

VoteSetJSON More human readable JSON of the vote set NOTE: insufficient for unmarshalling from (compressed votes) TODO: make the peerMaj23s nicer to read (eg just the block hash)

type VoteSetReader

type VoteSetReader interface {
	Height() uint64
	Round() int
	Type() byte
	Size() uint
	BitArray() *help.BitArray
	GetByIndex(uint) *Vote
	IsCommit() bool
}

VoteSetReader Common interface between *consensus.VoteSet and types.Commit

Jump to

Keyboard shortcuts

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