types

package
v6.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2019 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DuplicateVote = "DuplicateVote"
	MockGood      = "MockGood"
	MockBad       = "MockBad"
)

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

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

	EvidenceListID      = byte(0x01)
	NewRoundStepID      = byte(0x02)
	CommitStepID        = byte(0x03)
	ProposalID          = byte(0x04)
	ProposalPOLID       = byte(0x05)
	VoteID              = byte(0x06)
	HasVoteID           = byte(0x07)
	VoteSetMaj23ID      = byte(0X08)
	VoteSetBitsID       = byte(0x09)
	ProposalHeartbeatID = byte(0x0a)
	ProposalBlockID     = byte(0x0b)

	PacketTypePing = byte(0xff)
	PacketTypePong = byte(0xfe)
)

step and message id define

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

Types of votes TODO Make a new type "VoteType"

View Source
const (
	// RFC3339Millis ...
	RFC3339Millis = "2006-01-02T15:04:05.000Z" // forced microseconds

)

Variables

View Source
var (
	EvidenceType2Type map[string]reflect.Type
	EvidenceType2Obj  map[string]Evidence
)

EvidenceType map define

View Source
var (
	ErrVoteUnexpectedStep            = errors.New("Unexpected step")
	ErrVoteInvalidValidatorIndex     = errors.New("Invalid validator index")
	ErrVoteInvalidValidatorAddress   = errors.New("Invalid validator address")
	ErrVoteInvalidSignature          = errors.New("Invalid signature")
	ErrVoteInvalidBlockHash          = errors.New("Invalid block hash")
	ErrVoteNonDeterministicSignature = errors.New("Non-deterministic signature")
	ErrVoteNil                       = errors.New("Nil vote")
)

error defines

View Source
var (

	// ConsensusCrypto define
	ConsensusCrypto crypto.Crypto
)
View Source
var (

	// Fmt ...
	Fmt = fmt.Sprintf
)
View Source
var (
	// MsgMap define
	MsgMap map[byte]reflect.Type
)

Functions

func CanonicalTime

func CanonicalTime(t time.Time) string

CanonicalTime ...

func CreateCmd

func CreateCmd() *cobra.Command

CreateCmd ...

func Exit

func Exit(s string)

Exit ...

func Fingerprint

func Fingerprint(slice []byte) []byte

Fingerprint ...

func GenAddressByPubKey

func GenAddressByPubKey(pubkey crypto.PubKey) []byte

GenAddressByPubKey ...

func Init

func Init()

Init ...

func InitMessageMap

func InitMessageMap()

InitMessageMap ...

func IsVoteTypeValid

func IsVoteTypeValid(voteType byte) bool

IsVoteTypeValid ...

func KeyFileCmd

func KeyFileCmd() *cobra.Command

KeyFileCmd ...

func Kill

func Kill() error

Kill ...

func MaxInt

func MaxInt(a, b int) int

MaxInt ...

func MinInt

func MinInt(a, b int) int

MinInt ...

func PanicCrisis

func PanicCrisis(v interface{})

PanicCrisis ...

func PanicQ

func PanicQ(v interface{})

PanicQ ...

func PanicSanity

func PanicSanity(v interface{})

PanicSanity ...

func Parallel

func Parallel(tasks ...func())

Parallel ...

func PubKeyFromString

func PubKeyFromString(pubkeystring string) (crypto.PubKey, error)

PubKeyFromString ...

func RandInt63n

func RandInt63n(n int64) int64

RandInt63n ...

func RandIntn

func RandIntn(n int) int

RandIntn ...

func RandStr

func RandStr(length int) string

RandStr ...

func RandUint32

func RandUint32() uint32

RandUint32 ...

func SignBytes

func SignBytes(chainID string, o Signable) []byte

SignBytes is a convenience method for getting the bytes to sign of a Signable.

func SignatureFromString

func SignatureFromString(sigString string) (crypto.Signature, error)

SignatureFromString ...

func SimpleHashFromBinary

func SimpleHashFromBinary(item *DuplicateVoteEvidence) []byte

SimpleHashFromBinary ...

func Tempfile

func Tempfile(prefix string) (*os.File, string)

Tempfile ...

func WriteFile

func WriteFile(filePath string, contents []byte, mode os.FileMode) error

WriteFile ...

func WriteFileAtomic

func WriteFileAtomic(filePath string, newBytes []byte, mode os.FileMode) error

WriteFileAtomic ...

Types

type BitArray

type BitArray struct {
	*tmtypes.TendermintBitArray
	// contains filtered or unexported fields
}

BitArray ...

func NewBitArray

func NewBitArray(bits int) *BitArray

NewBitArray There is no BitArray whose Size is 0. Use nil instead.

func (*BitArray) And

func (bA *BitArray) And(o *BitArray) *BitArray

And Returns a BitArray of smaller bit size.

func (*BitArray) Bytes

func (bA *BitArray) Bytes() []byte

Bytes ...

func (*BitArray) Copy

func (bA *BitArray) Copy() *BitArray

Copy ...

func (*BitArray) GetIndex

func (bA *BitArray) GetIndex(i int) bool

GetIndex NOTE: behavior is undefined if i >= bA.Bits

func (*BitArray) IsEmpty

func (bA *BitArray) IsEmpty() bool

IsEmpty ...

func (*BitArray) IsFull

func (bA *BitArray) IsFull() bool

IsFull ...

func (*BitArray) Not

func (bA *BitArray) Not() *BitArray

Not ...

func (*BitArray) Or

func (bA *BitArray) Or(o *BitArray) *BitArray

Or Returns a BitArray of larger bits size.

func (*BitArray) PickRandom

func (bA *BitArray) PickRandom() (int, bool)

PickRandom ...

func (*BitArray) SetIndex

func (bA *BitArray) SetIndex(i int, v bool) bool

SetIndex NOTE: behavior is undefined if i >= bA.Bits

func (*BitArray) Size

func (bA *BitArray) Size() int

Size ...

func (*BitArray) String

func (bA *BitArray) String() string

func (*BitArray) StringIndented

func (bA *BitArray) StringIndented(indent string) string

StringIndented ...

func (*BitArray) Sub

func (bA *BitArray) Sub(o *BitArray) *BitArray

Sub ...

func (*BitArray) Update

func (bA *BitArray) Update(o *BitArray)

Update NOTE: other bitarray o is not locked when reading, so if necessary, caller must copy or lock o prior to calling Update. If bA is nil, does nothing.

type BlockGossip

type BlockGossip struct {
	BlockPartSizeBytes int `json:"block_part_size_bytes"` // NOTE: must not be 0
}

BlockGossip determine consensus critical elements of how blocks are gossiped

func DefaultBlockGossip

func DefaultBlockGossip() BlockGossip

DefaultBlockGossip returns a default BlockGossip.

type BlockID

type BlockID struct {
	tmtypes.BlockID
}

BlockID struct

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 BlockSize

type BlockSize struct {
	MaxBytes int   `json:"max_bytes"` // NOTE: must not be 0 nor greater than 100MB
	MaxTxs   int   `json:"max_txs"`
	MaxGas   int64 `json:"max_gas"`
}

BlockSize contain limits on the block size.

func DefaultBlockSize

func DefaultBlockSize() BlockSize

DefaultBlockSize returns a default BlockSize.

type CanonicalJSONBlockID

type CanonicalJSONBlockID struct {
	Hash        []byte                     `json:"hash,omitempty"`
	PartsHeader CanonicalJSONPartSetHeader `json:"parts,omitempty"`
}

CanonicalJSONBlockID ...

func CanonicalBlockID

func CanonicalBlockID(blockID BlockID) CanonicalJSONBlockID

CanonicalBlockID ...

type CanonicalJSONHeartbeat

type CanonicalJSONHeartbeat struct {
	Height           int64  `json:"height"`
	Round            int    `json:"round"`
	Sequence         int    `json:"sequence"`
	ValidatorAddress []byte `json:"validator_address"`
	ValidatorIndex   int    `json:"validator_index"`
}

CanonicalJSONHeartbeat ...

func CanonicalHeartbeat

func CanonicalHeartbeat(heartbeat *Heartbeat) CanonicalJSONHeartbeat

CanonicalHeartbeat ...

type CanonicalJSONOnceHeartbeat

type CanonicalJSONOnceHeartbeat struct {
	ChainID   string                 `json:"chain_id"`
	Heartbeat CanonicalJSONHeartbeat `json:"heartbeat"`
}

CanonicalJSONOnceHeartbeat ...

type CanonicalJSONOnceProposal

type CanonicalJSONOnceProposal struct {
	ChainID  string                `json:"chain_id"`
	Proposal CanonicalJSONProposal `json:"proposal"`
}

CanonicalJSONOnceProposal ...

type CanonicalJSONOnceVote

type CanonicalJSONOnceVote struct {
	ChainID string            `json:"chain_id"`
	Vote    CanonicalJSONVote `json:"vote"`
}

CanonicalJSONOnceVote ...

type CanonicalJSONPartSetHeader

type CanonicalJSONPartSetHeader struct {
	Hash  []byte `json:"hash"`
	Total int    `json:"total"`
}

CanonicalJSONPartSetHeader ...

type CanonicalJSONProposal

type CanonicalJSONProposal struct {
	BlockBytes []byte               `json:"block_parts_header"`
	Height     int64                `json:"height"`
	POLBlockID CanonicalJSONBlockID `json:"pol_block_id"`
	POLRound   int                  `json:"pol_round"`
	Round      int                  `json:"round"`
	Timestamp  string               `json:"timestamp"`
}

CanonicalJSONProposal ...

func CanonicalProposal

func CanonicalProposal(proposal *Proposal) CanonicalJSONProposal

CanonicalProposal ...

type CanonicalJSONVote

type CanonicalJSONVote struct {
	BlockID   CanonicalJSONBlockID `json:"block_id"`
	Height    int64                `json:"height"`
	Round     int                  `json:"round"`
	Timestamp string               `json:"timestamp"`
	Type      byte                 `json:"type"`
}

CanonicalJSONVote ...

func CanonicalVote

func CanonicalVote(vote *Vote) CanonicalJSONVote

CanonicalVote ...

type Commit

type Commit struct {
	*tmtypes.TendermintCommit
	// contains filtered or unexported fields
}

Commit struct

func (*Commit) BitArray

func (commit *Commit) BitArray() *BitArray

BitArray returns a BitArray of which validators voted in this commit

func (*Commit) FirstPrecommit

func (commit *Commit) FirstPrecommit() *tmtypes.Vote

FirstPrecommit returns the first non-nil precommit in the commit

func (*Commit) GetByIndex

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

GetByIndex returns the vote corresponding to a given validator index

func (*Commit) Hash

func (commit *Commit) Hash() []byte

Hash returns the hash of the commit

func (*Commit) Height

func (commit *Commit) Height() int64

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

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 Comparable

type Comparable interface {
	Less(o interface{}) bool
}

Comparable ...

type ConsensusParams

type ConsensusParams struct {
	BlockSize      `json:"block_size_params"`
	TxSize         `json:"tx_size_params"`
	BlockGossip    `json:"block_gossip_params"`
	EvidenceParams `json:"evidence_params"`
}

ConsensusParams contains consensus critical parameters that determine the validity of blocks.

func DefaultConsensusParams

func DefaultConsensusParams() *ConsensusParams

DefaultConsensusParams returns a default ConsensusParams.

func (*ConsensusParams) Hash

func (params *ConsensusParams) Hash() []byte

Hash returns a merkle hash of the parameters to store in the block header

func (*ConsensusParams) Validate

func (params *ConsensusParams) Validate() error

Validate validates the ConsensusParams to ensure all values are within their allowed limits, and returns an error if they are not.

type DefaultSigner

type DefaultSigner struct {
	PrivKey crypto.PrivKey `json:"priv_key"`
}

DefaultSigner implements Signer. It uses a standard, unencrypted crypto.PrivKey.

func NewDefaultSigner

func NewDefaultSigner(priv crypto.PrivKey) *DefaultSigner

NewDefaultSigner returns an instance of DefaultSigner.

func (*DefaultSigner) Sign

func (ds *DefaultSigner) Sign(msg []byte) (crypto.Signature, error)

Sign implements Signer. It signs the byte slice with a private key.

type DuplicateVoteEvidence

type DuplicateVoteEvidence struct {
	*tmtypes.DuplicateVoteEvidence
}

DuplicateVoteEvidence contains evidence a validator signed two conflicting votes.

func (*DuplicateVoteEvidence) Address

func (dve *DuplicateVoteEvidence) Address() []byte

Address returns the address of the validator.

func (*DuplicateVoteEvidence) Child

func (dve *DuplicateVoteEvidence) Child() proto.Message

Child ...

func (*DuplicateVoteEvidence) Copy

func (dve *DuplicateVoteEvidence) Copy() Evidence

Copy ...

func (*DuplicateVoteEvidence) Equal

func (dve *DuplicateVoteEvidence) Equal(ev Evidence) bool

Equal checks if two pieces of evidence are equal.

func (*DuplicateVoteEvidence) Hash

func (dve *DuplicateVoteEvidence) Hash() []byte

Hash returns the hash of the evidence.

func (*DuplicateVoteEvidence) Height

func (dve *DuplicateVoteEvidence) Height() int64

Height returns the height this evidence refers to.

func (*DuplicateVoteEvidence) Index

func (dve *DuplicateVoteEvidence) Index() int

Index returns the index of the validator.

func (*DuplicateVoteEvidence) SetChild

func (dve *DuplicateVoteEvidence) SetChild(child proto.Message)

SetChild ...

func (*DuplicateVoteEvidence) String

func (dve *DuplicateVoteEvidence) String() string

String returns a string representation of the evidence.

func (*DuplicateVoteEvidence) TypeName

func (dve *DuplicateVoteEvidence) TypeName() string

TypeName ...

func (*DuplicateVoteEvidence) Verify

func (dve *DuplicateVoteEvidence) Verify(chainID string) error

Verify returns an error if the two votes aren't conflicting. To be conflicting, they must be from the same validator, for the same H/R/S, but for different blocks.

type ErrEvidenceInvalid

type ErrEvidenceInvalid struct {
	Evidence   Evidence
	ErrorValue error
}

ErrEvidenceInvalid wraps a piece of evidence and the error denoting how or why it is invalid.

func NewEvidenceInvalidErr

func NewEvidenceInvalidErr(ev Evidence, err error) *ErrEvidenceInvalid

NewEvidenceInvalidErr ...

func (*ErrEvidenceInvalid) Error

func (err *ErrEvidenceInvalid) Error() string

Error returns a string representation of the error.

type ErrVoteConflictingVotes

type ErrVoteConflictingVotes struct {
	*DuplicateVoteEvidence
}

ErrVoteConflictingVotes ...

func NewConflictingVoteError

func NewConflictingVoteError(val *Validator, voteA, voteB *tmtypes.Vote) *ErrVoteConflictingVotes

NewConflictingVoteError ...

func (*ErrVoteConflictingVotes) Error

func (err *ErrVoteConflictingVotes) Error() string

type Evidence

type Evidence interface {
	Height() int64               // height of the equivocation
	Address() []byte             // address of the equivocating validator
	Index() int                  // index of the validator in the validator set
	Hash() []byte                // hash of the evidence
	Verify(chainID string) error // verify the evidence
	Equal(Evidence) bool         // check equality of evidence

	String() string
	Copy() Evidence
	TypeName() string
	SetChild(child proto.Message)
	Child() proto.Message
}

Evidence represents any provable malicious activity by a validator

func EvidenceEnvelope2Evidence

func EvidenceEnvelope2Evidence(envelope *tmtypes.EvidenceEnvelope) Evidence

EvidenceEnvelope2Evidence ...

type EvidenceData

type EvidenceData struct {
	*tmtypes.EvidenceData
	// contains filtered or unexported fields
}

EvidenceData ...

func (*EvidenceData) Hash

func (data *EvidenceData) Hash() []byte

Hash returns the hash of the data.

func (*EvidenceData) StringIndented

func (data *EvidenceData) StringIndented(indent string) string

StringIndented returns a string representation of the evidence.

type EvidenceEnvelope

type EvidenceEnvelope struct {
	*tmtypes.EvidenceEnvelope
}

EvidenceEnvelope ...

func (EvidenceEnvelope) Hash

func (env EvidenceEnvelope) Hash() []byte

Hash ...

func (EvidenceEnvelope) String

func (env EvidenceEnvelope) String() string

type EvidenceEnvelopeList

type EvidenceEnvelopeList []EvidenceEnvelope

EvidenceEnvelopeList contains any evidence of malicious wrong-doing by validators

func (EvidenceEnvelopeList) Has

func (evl EvidenceEnvelopeList) Has(evidence Evidence) bool

Has returns true if the evidence is in the EvidenceList.

func (EvidenceEnvelopeList) Hash

func (evl EvidenceEnvelopeList) Hash() []byte

Hash returns the simple merkle root hash of the EvidenceList.

func (EvidenceEnvelopeList) String

func (evl EvidenceEnvelopeList) String() string

type EvidenceList

type EvidenceList []Evidence

EvidenceList is a list of Evidence. Evidences is not a word.

func (EvidenceList) Has

func (evl EvidenceList) Has(evidence Evidence) bool

Has returns true if the evidence is in the EvidenceList.

func (EvidenceList) Hash

func (evl EvidenceList) Hash() []byte

Hash returns the simple merkle root hash of the EvidenceList.

func (EvidenceList) String

func (evl EvidenceList) String() string

type EvidenceParams

type EvidenceParams struct {
	MaxAge int64 `json:"max_age"` // only accept new evidence more recent than this
}

EvidenceParams determine how we handle evidence of malfeasance

func DefaultEvidenceParams

func DefaultEvidenceParams() EvidenceParams

DefaultEvidenceParams returns a default EvidenceParams.

type EvidencePool

type EvidencePool interface {
	PendingEvidence() []Evidence
	AddEvidence(Evidence) error
	Update(*TendermintBlock)
}

EvidencePool defines the EvidencePool interface used by the ConsensusState. UNSTABLE

type GenesisDoc

type GenesisDoc struct {
	GenesisTime     time.Time          `json:"genesis_time"`
	ChainID         string             `json:"chain_id"`
	ConsensusParams *ConsensusParams   `json:"consensus_params,omitempty"`
	Validators      []GenesisValidator `json:"validators"`
	AppHash         []byte             `json:"app_hash"`
	AppOptions      interface{}        `json:"app_options,omitempty"`
}

GenesisDoc defines the initial conditions for a tendermint blockchain, in particular its validator set.

func GenesisDocFromFile

func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error)

GenesisDocFromFile reads JSON data from a file and unmarshalls it into a GenesisDoc.

func GenesisDocFromJSON

func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error)

GenesisDocFromJSON unmarshalls JSON data into a GenesisDoc.

func (*GenesisDoc) SaveAs

func (genDoc *GenesisDoc) SaveAs(file string) error

SaveAs is a utility method for saving GenensisDoc as a JSON file.

func (*GenesisDoc) ValidateAndComplete

func (genDoc *GenesisDoc) ValidateAndComplete() error

ValidateAndComplete checks that all necessary fields are present and fills in defaults for optional fields left empty

func (*GenesisDoc) ValidatorHash

func (genDoc *GenesisDoc) ValidatorHash() []byte

ValidatorHash returns the hash of the validator set contained in the GenesisDoc

type GenesisValidator

type GenesisValidator struct {
	PubKey KeyText `json:"pub_key"`
	Power  int64   `json:"power"`
	Name   string  `json:"name"`
}

GenesisValidator is an initial validator.

type Header struct {
	*tmtypes.TendermintBlockHeader
}

Header defines the structure of a Tendermint block header TODO: limit header size NOTE: changes to the Header should be duplicated in the abci Header

func (*Header) Hash

func (h *Header) Hash() []byte

Hash returns the hash of the header. Returns nil if ValidatorHash is missing.

func (*Header) StringIndented

func (h *Header) StringIndented(indent string) string

StringIndented returns a string representation of the header

type Heap

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

Heap ...

func NewHeap

func NewHeap() *Heap

NewHeap ...

func (*Heap) Len

func (h *Heap) Len() int64

Len ...

func (*Heap) Peek

func (h *Heap) Peek() interface{}

Peek ...

func (*Heap) Pop

func (h *Heap) Pop() interface{}

Pop ...

func (*Heap) Push

func (h *Heap) Push(value interface{}, priority Comparable)

Push ...

func (*Heap) Update

func (h *Heap) Update(value interface{}, priority Comparable)

Update ...

type Heartbeat

type Heartbeat struct {
	*tmtypes.Heartbeat
}

Heartbeat ...

func (*Heartbeat) WriteSignBytes

func (heartbeat *Heartbeat) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

WriteSignBytes writes the Heartbeat for signing. It panics if the Heartbeat is nil.

type HeightVoteSet

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

HeightVoteSet ...

func NewHeightVoteSet

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

NewHeightVoteSet ...

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, peerKey is "" if origin is self.

func (*HeightVoteSet) Height

func (hvs *HeightVoteSet) Height() int64

Height ...

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 ...

func (*HeightVoteSet) Prevotes

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

Prevotes ...

func (*HeightVoteSet) Reset

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

Reset ...

func (*HeightVoteSet) Round

func (hvs *HeightVoteSet) Round() int

Round ...

func (*HeightVoteSet) SetPeerMaj23

func (hvs *HeightVoteSet) SetPeerMaj23(round int, voteType byte, peerID string, blockID *tmtypes.BlockID)

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

func (*HeightVoteSet) StringIndented

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

StringIndented ...

type KeyText

type KeyText struct {
	Kind string `json:"type"`
	Data string `json:"data"`
}

KeyText ...

type MockBadEvidence

type MockBadEvidence struct {
	MockGoodEvidence
}

MockBadEvidence UNSTABLE

func (MockBadEvidence) Child

func (e MockBadEvidence) Child() proto.Message

Child ...

func (MockBadEvidence) Copy

func (e MockBadEvidence) Copy() Evidence

Copy ...

func (MockBadEvidence) Equal

func (e MockBadEvidence) Equal(ev Evidence) bool

Equal ...

func (MockBadEvidence) SetChild

func (e MockBadEvidence) SetChild(proto.Message)

SetChild ...

func (MockBadEvidence) String

func (e MockBadEvidence) String() string

func (MockBadEvidence) TypeName

func (e MockBadEvidence) TypeName() string

TypeName ...

func (MockBadEvidence) Verify

func (e MockBadEvidence) Verify(chainID string) error

Verify ...

type MockEvidencePool

type MockEvidencePool struct {
}

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

func (MockEvidencePool) AddEvidence

func (m MockEvidencePool) AddEvidence(Evidence) error

AddEvidence ...

func (MockEvidencePool) PendingEvidence

func (m MockEvidencePool) PendingEvidence() []Evidence

PendingEvidence ...

func (MockEvidencePool) Update

func (m MockEvidencePool) Update(*TendermintBlock)

Update ...

type MockGoodEvidence

type MockGoodEvidence struct {
	MGHeight  int64
	MGAddress []byte
	MGIndex   int
}

MockGoodEvidence UNSTABLE

func NewMockGoodEvidence

func NewMockGoodEvidence(height int64, index int, address []byte) MockGoodEvidence

NewMockGoodEvidence UNSTABLE

func (MockGoodEvidence) Address

func (e MockGoodEvidence) Address() []byte

Address ...

func (MockGoodEvidence) Child

func (e MockGoodEvidence) Child() proto.Message

Child ...

func (MockGoodEvidence) Copy

func (e MockGoodEvidence) Copy() Evidence

Copy ...

func (MockGoodEvidence) Equal

func (e MockGoodEvidence) Equal(ev Evidence) bool

Equal ...

func (MockGoodEvidence) Hash

func (e MockGoodEvidence) Hash() []byte

Hash ...

func (MockGoodEvidence) Height

func (e MockGoodEvidence) Height() int64

Height ...

func (MockGoodEvidence) Index

func (e MockGoodEvidence) Index() int

Index ...

func (MockGoodEvidence) SetChild

func (e MockGoodEvidence) SetChild(proto.Message)

SetChild ...

func (MockGoodEvidence) String

func (e MockGoodEvidence) String() string

func (MockGoodEvidence) TypeName

func (e MockGoodEvidence) TypeName() string

TypeName ...

func (MockGoodEvidence) Verify

func (e MockGoodEvidence) Verify(chainID string) error

Verify ...

type PeerRoundState

type PeerRoundState struct {
	Height             int64         // Height peer is at
	Round              int           // Round peer is at, -1 if unknown.
	Step               RoundStepType // Step peer is at
	StartTime          time.Time     // Estimated start of round 0 at this height
	Proposal           bool          // True if peer has proposal for this round
	ProposalBlock      bool          // True if peer has proposal block for this round
	ProposalPOLRound   int           // Proposal's POL round. -1 if none.
	ProposalPOL        *BitArray     // nil until ProposalPOLMessage received.
	Prevotes           *BitArray     // All votes peer has for this round
	Precommits         *BitArray     // All precommits peer has for this round
	LastCommitRound    int           // Round of commit for last height. -1 if none.
	LastCommit         *BitArray     // All commit precommits of commit for last height.
	CatchupCommitRound int           // Round that we have commit for. Not necessarily unique. -1 if none.
	CatchupCommit      *BitArray     // All commit precommits peer has for this height & CatchupCommitRound
}

PeerRoundState ...

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 Percent

type Percent uint32

Percent represents a percentage in increments of 1/1000th of a percent.

func (Percent) Float

func (p Percent) Float() float64

Float ...

func (Percent) String

func (p Percent) String() string

type PrivValidator

type PrivValidator interface {
	GetAddress() []byte // redundant since .PubKey().Address()
	GetPubKey() crypto.PubKey

	SignVote(chainID string, vote *Vote) error
	SignProposal(chainID string, proposal *Proposal) error
	SignHeartbeat(chainID string, heartbeat *Heartbeat) error

	GetLastHeight() int64
	GetLastRound() int
	GetLastStep() int8

	//reset height,round,step used by start to catch up
	ResetLastHeight(height int64)
}

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

type PrivValidatorFS

type PrivValidatorFS struct {
	Address       string   `json:"address"`
	PubKey        KeyText  `json:"pub_key"`
	LastHeight    int64    `json:"last_height"`
	LastRound     int      `json:"last_round"`
	LastStep      int8     `json:"last_step"`
	LastSignature *KeyText `json:"last_signature,omitempty"` // so we dont lose signatures
	LastSignBytes string   `json:"last_signbytes,omitempty"` // so we dont lose signatures

	// PrivKey should be empty if a Signer other than the default is being used.
	PrivKey KeyText `json:"priv_key"`
}

PrivValidatorFS implements PrivValidator using data persisted to disk to prevent double signing. The Signer itself can be mutated to use something besides the default, for instance a hardware signer.

type PrivValidatorImp

type PrivValidatorImp struct {
	Address       []byte
	PubKey        crypto.PubKey
	LastHeight    int64
	LastRound     int
	LastStep      int8
	LastSignature crypto.Signature
	LastSignBytes []byte

	// PrivKey should be empty if a Signer other than the default is being used.
	PrivKey crypto.PrivKey
	Signer  `json:"-"`
	// contains filtered or unexported fields
}

PrivValidatorImp ...

func GenPrivValidatorImp

func GenPrivValidatorImp(filePath string) *PrivValidatorImp

GenPrivValidatorImp generates a new validator with randomly generated private key and sets the filePath, but does not call Save().

func LoadOrGenPrivValidatorFS

func LoadOrGenPrivValidatorFS(filePath string) *PrivValidatorImp

LoadOrGenPrivValidatorFS loads a PrivValidatorFS from the given filePath or else generates a new one and saves it to the filePath.

func LoadPrivValidatorFS

func LoadPrivValidatorFS(filePath string) *PrivValidatorImp

LoadPrivValidatorFS loads a PrivValidatorImp from the filePath.

func LoadPrivValidatorFSWithSigner

func LoadPrivValidatorFSWithSigner(filePath string, signerFunc func(PrivValidator) Signer) *PrivValidatorImp

LoadPrivValidatorFSWithSigner loads a PrivValidatorFS with a custom signer object. The PrivValidatorFS handles double signing prevention by persisting data to the filePath, while the Signer handles the signing. If the filePath does not exist, the PrivValidatorFS must be created manually and saved.

func (*PrivValidatorImp) GetAddress

func (pv *PrivValidatorImp) GetAddress() []byte

GetAddress returns the address of the validator. Implements PrivValidator.

func (*PrivValidatorImp) GetLastHeight

func (pv *PrivValidatorImp) GetLastHeight() int64

GetLastHeight ...

func (*PrivValidatorImp) GetLastRound

func (pv *PrivValidatorImp) GetLastRound() int

GetLastRound ...

func (*PrivValidatorImp) GetLastStep

func (pv *PrivValidatorImp) GetLastStep() int8

GetLastStep ...

func (*PrivValidatorImp) GetPubKey

func (pv *PrivValidatorImp) GetPubKey() crypto.PubKey

GetPubKey returns the public key of the validator. Implements PrivValidator.

func (*PrivValidatorImp) Reset

func (pv *PrivValidatorImp) Reset()

Reset resets all fields in the PrivValidatorFS. NOTE: Unsafe!

func (*PrivValidatorImp) ResetLastHeight

func (pv *PrivValidatorImp) ResetLastHeight(height int64)

ResetLastHeight ...

func (*PrivValidatorImp) Save

func (pv *PrivValidatorImp) Save()

Save persists the PrivValidatorFS to disk.

func (*PrivValidatorImp) SignHeartbeat

func (pv *PrivValidatorImp) SignHeartbeat(chainID string, heartbeat *Heartbeat) error

SignHeartbeat signs a canonical representation of the heartbeat, along with the chainID. Implements PrivValidator.

func (*PrivValidatorImp) SignProposal

func (pv *PrivValidatorImp) SignProposal(chainID string, proposal *Proposal) error

SignProposal signs a canonical representation of the proposal, along with the chainID. Implements PrivValidator.

func (*PrivValidatorImp) SignVote

func (pv *PrivValidatorImp) SignVote(chainID string, vote *Vote) error

SignVote signs a canonical representation of the vote, along with the chainID. Implements PrivValidator.

func (*PrivValidatorImp) String

func (pv *PrivValidatorImp) String() string

String returns a string representation of the PrivValidatorImp.

type PrivValidatorsByAddress

type PrivValidatorsByAddress []*PrivValidatorImp

PrivValidatorsByAddress ...

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 {
	tmtypes.Proposal
}

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 int64, round int, blockhash []byte, polRound int, polBlockID tmtypes.BlockID) *Proposal

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

func (*Proposal) String

func (p *Proposal) String() string

String returns a string representation of the Proposal.

func (*Proposal) WriteSignBytes

func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

WriteSignBytes writes the Proposal bytes for signing

type RoundState

type RoundState struct {
	Height         int64 // Height we are working on
	Round          int
	Step           RoundStepType
	StartTime      time.Time
	CommitTime     time.Time // Subjective time when +2/3 precommits for Block at Round were found
	Validators     *ValidatorSet
	Proposal       *tmtypes.Proposal
	ProposalBlock  *TendermintBlock
	LockedRound    int
	LockedBlock    *TendermintBlock
	Votes          *HeightVoteSet
	CommitRound    int
	LastCommit     *VoteSet // Last precommits at Height-1
	LastValidators *ValidatorSet
}

RoundState defines the internal consensus state. It is Immutable when returned from ConsensusState.GetRoundState() TODO: Actually, only the top pointer is copied, so access to field pointers is still racey NOTE: Not thread safe. Should only be manipulated by functions downstream of the cs.receiveRoutine

func (*RoundState) RoundStateMessage

func (rs *RoundState) RoundStateMessage() *tmtypes.NewRoundStepMsg

RoundStateMessage ...

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 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 ...

type Signable

type Signable interface {
	WriteSignBytes(chainID string, w io.Writer, n *int, err *error)
}

Signable is an interface for all signable things. It typically removes signatures before serializing.

type SignedHeader

type SignedHeader struct {
	Header *Header `json:"header"`
	Commit *Commit `json:"commit"`
}

SignedHeader is a header along with the commits that prove it

type Signer

type Signer interface {
	Sign(msg []byte) (crypto.Signature, error)
}

Signer is an interface that defines how to sign messages. It is the caller's duty to verify the msg before calling Sign, eg. to avoid double signing. Currently, the only callers are SignVote, SignProposal, and SignHeartbeat.

type TendermintBlock

type TendermintBlock struct {
	*tmtypes.TendermintBlock
}

TendermintBlock struct

func MakeBlock

func MakeBlock(height int64, round int64, Txs []*types.Transaction, commit *tmtypes.TendermintCommit) *TendermintBlock

MakeBlock returns a new block with an empty header, except what can be computed from itself. It populates the same set of fields validated by ValidateBasic

func (*TendermintBlock) AddEvidence

func (b *TendermintBlock) AddEvidence(evidence []Evidence)

AddEvidence appends the given evidence to the block

func (*TendermintBlock) FillHeader

func (b *TendermintBlock) FillHeader()

FillHeader fills in any remaining header fields that are a function of the block data

func (*TendermintBlock) Hash

func (b *TendermintBlock) Hash() []byte

Hash computes and returns the block hash. If the block is incomplete, block hash is nil for safety.

func (*TendermintBlock) HashesTo

func (b *TendermintBlock) HashesTo(hash []byte) bool

HashesTo is a convenience function that checks if a block hashes to the given argument. A nil block never hashes to anything, and nothing hashes to a nil hash.

func (*TendermintBlock) String

func (b *TendermintBlock) String() string

String returns a string representation of the block

func (*TendermintBlock) StringIndented

func (b *TendermintBlock) StringIndented(indent string) string

StringIndented returns a string representation of the block

func (*TendermintBlock) StringShort

func (b *TendermintBlock) StringShort() string

StringShort returns a shortened string representation of the block

func (*TendermintBlock) ValidateBasic

func (b *TendermintBlock) ValidateBasic() (int64, error)

ValidateBasic performs basic validation that doesn't involve state data. It checks the internal consistency of the block.

type TxSize

type TxSize struct {
	MaxBytes int   `json:"max_bytes"`
	MaxGas   int64 `json:"max_gas"`
}

TxSize contain limits on the tx size.

func DefaultTxSize

func DefaultTxSize() TxSize

DefaultTxSize returns a default TxSize.

type Validator

type Validator struct {
	Address     []byte `json:"address"`
	PubKey      []byte `json:"pub_key"`
	VotingPower int64  `json:"voting_power"`

	Accum int64 `json:"accum"`
}

Validator ...

func NewValidator

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

NewValidator ...

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. TODO: consider validator Accum overflow

func NewValidatorSet

func NewValidatorSet(vals []*Validator) *ValidatorSet

NewValidatorSet ...

func (*ValidatorSet) Add

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

Add ...

func (*ValidatorSet) Copy

func (valSet *ValidatorSet) Copy() *ValidatorSet

Copy ...

func (*ValidatorSet) GetByAddress

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

GetByAddress ...

func (*ValidatorSet) GetByIndex

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

GetByIndex returns the validator by index. It returns nil values if index < 0 or index >= len(ValidatorSet.Validators)

func (*ValidatorSet) GetProposer

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

GetProposer ...

func (*ValidatorSet) HasAddress

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

HasAddress ...

func (*ValidatorSet) Hash

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

Hash ...

func (*ValidatorSet) IncrementAccum

func (valSet *ValidatorSet) IncrementAccum(times int)

IncrementAccum incrementAccum and update the proposer TODO: mind the overflow when times and votingPower shares too large.

func (*ValidatorSet) Iterate

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

Iterate ...

func (*ValidatorSet) Remove

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

Remove ...

func (*ValidatorSet) Size

func (valSet *ValidatorSet) Size() int

Size ...

func (*ValidatorSet) String

func (valSet *ValidatorSet) String() string

func (*ValidatorSet) StringIndented

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

StringIndented ...

func (*ValidatorSet) TotalVotingPower

func (valSet *ValidatorSet) TotalVotingPower() int64

TotalVotingPower ...

func (*ValidatorSet) Update

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

Update ...

func (*ValidatorSet) VerifyCommit

func (valSet *ValidatorSet) VerifyCommit(chainID string, blockID BlockID, height int64, 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 int64, 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 ...

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 {
	*tmtypes.Vote
}

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

func (*Vote) Copy

func (vote *Vote) Copy() *Vote

Copy ...

func (*Vote) Hash

func (vote *Vote) Hash() []byte

Hash ...

func (*Vote) String

func (vote *Vote) String() string

func (*Vote) Verify

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

Verify ...

func (*Vote) WriteSignBytes

func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int, err *error)

WriteSignBytes ...

type VoteSet

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

VoteSet ...

func NewVoteSet

func NewVoteSet(chainID string, height int64, round int, voteType 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() *BitArray

BitArray ...

func (*VoteSet) BitArrayByBlockID

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

BitArrayByBlockID ...

func (*VoteSet) ChainID

func (voteSet *VoteSet) ChainID() string

ChainID ...

func (*VoteSet) GetByAddress

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

GetByAddress ...

func (*VoteSet) GetByIndex

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

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

func (*VoteSet) HasAll

func (voteSet *VoteSet) HasAll() bool

HasAll ...

func (*VoteSet) HasTwoThirdsAny

func (voteSet *VoteSet) HasTwoThirdsAny() bool

HasTwoThirdsAny ...

func (*VoteSet) HasTwoThirdsMajority

func (voteSet *VoteSet) HasTwoThirdsMajority() bool

HasTwoThirdsMajority ...

func (*VoteSet) Height

func (voteSet *VoteSet) Height() int64

Height ...

func (*VoteSet) IsCommit

func (voteSet *VoteSet) IsCommit() bool

IsCommit ...

func (*VoteSet) MakeCommit

func (voteSet *VoteSet) MakeCommit() *tmtypes.TendermintCommit

MakeCommit ...

func (*VoteSet) Round

func (voteSet *VoteSet) Round() int

Round ...

func (*VoteSet) SetPeerMaj23

func (voteSet *VoteSet) SetPeerMaj23(peerID string, blockID *tmtypes.BlockID)

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

Size ...

func (*VoteSet) String

func (voteSet *VoteSet) String() string

func (*VoteSet) StringIndented

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

StringIndented ...

func (*VoteSet) StringShort

func (voteSet *VoteSet) StringShort() string

StringShort ...

func (*VoteSet) TwoThirdsMajority

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

TwoThirdsMajority Returns either a blockhash (or nil) that received +2/3 majority. If there exists no such majority, returns (nil, PartSetHeader{}, false).

func (*VoteSet) Type

func (voteSet *VoteSet) Type() byte

Type ...

type VoteSetReader

type VoteSetReader interface {
	Height() int64
	Round() int
	Type() byte
	Size() int
	BitArray() *BitArray
	GetByIndex(int) *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