Documentation ¶
Index ¶
- Constants
- Variables
- func EventStringBond() string
- func EventStringCompleteProposal() string
- func EventStringDupeout() string
- func EventStringFork() string
- func EventStringLock() string
- func EventStringNewBlock() string
- func EventStringNewBlockHeader() string
- func EventStringNewRound() string
- func EventStringNewRoundStep() string
- func EventStringPolka() string
- func EventStringRebond() string
- func EventStringRelock() string
- func EventStringTimeoutPropose() string
- func EventStringTimeoutWait() string
- func EventStringTx(tx Tx) string
- func EventStringUnbond() string
- func EventStringUnlock() string
- func EventStringVote() string
- func HashSignBytes(chainID string, o Signable) []byte
- func RandValidator(randPower bool, minPower int64) (*Validator, *PrivValidator)
- func RandValidatorSet(numValidators int, votingPower int64) (*ValidatorSet, []*PrivValidator)
- func SignBytes(chainID string, o Signable) []byte
- type Block
- func (b *Block) FillHeader()
- func (b *Block) Hash() []byte
- func (b *Block) HashesTo(hash []byte) bool
- func (b *Block) MakePartSet() *PartSet
- func (b *Block) String() string
- func (b *Block) StringIndented(indent string) string
- func (b *Block) StringShort() string
- func (b *Block) ValidateBasic(chainID string, lastBlockHeight int, lastBlockHash []byte, ...) error
- type BlockMeta
- type Commit
- func (commit *Commit) BitArray() *BitArray
- func (commit *Commit) FirstPrecommit() *Vote
- func (commit *Commit) GetByIndex(index int) *Vote
- func (commit *Commit) Hash() []byte
- func (commit *Commit) Height() int
- func (commit *Commit) IsCommit() bool
- func (commit *Commit) Round() int
- func (commit *Commit) Size() int
- func (commit *Commit) StringIndented(indent string) string
- func (commit *Commit) Type() byte
- func (commit *Commit) ValidateBasic() error
- type Data
- type DefaultSigner
- type ErrVoteConflictingSignature
- type EventDataNewBlock
- type EventDataNewBlockHeader
- type EventDataRoundState
- type EventDataTx
- type EventDataVote
- type GenesisDoc
- type GenesisValidator
- type Header
- type Part
- type PartSet
- func (ps *PartSet) AddPart(part *Part, verify bool) (bool, error)
- func (ps *PartSet) BitArray() *BitArray
- func (ps *PartSet) Count() int
- func (ps *PartSet) GetPart(index int) *Part
- func (ps *PartSet) GetReader() io.Reader
- func (ps *PartSet) HasHeader(header PartSetHeader) bool
- func (ps *PartSet) Hash() []byte
- func (ps *PartSet) HashesTo(hash []byte) bool
- func (ps *PartSet) Header() PartSetHeader
- func (ps *PartSet) IsComplete() bool
- func (ps *PartSet) StringShort() string
- func (ps *PartSet) Total() int
- type PartSetHeader
- type PartSetReader
- type PrivValidator
- func (privVal *PrivValidator) Save()
- func (privVal *PrivValidator) SetFile(filePath string)
- func (privVal *PrivValidator) SetSigner(s Signer)
- func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) error
- func (privVal *PrivValidator) SignVote(chainID string, vote *Vote) error
- func (privVal *PrivValidator) String() string
- type PrivValidatorsByAddress
- type Proposal
- type Signable
- type Signer
- type TMEventData
- type Tx
- type Txs
- type Validator
- type ValidatorSet
- func (valSet *ValidatorSet) Add(val *Validator) (added bool)
- func (valSet *ValidatorSet) Copy() *ValidatorSet
- func (valSet *ValidatorSet) GetByAddress(address []byte) (index int, val *Validator)
- func (valSet *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator)
- func (valSet *ValidatorSet) HasAddress(address []byte) bool
- func (valSet *ValidatorSet) Hash() []byte
- func (valSet *ValidatorSet) IncrementAccum(times int)
- func (valSet *ValidatorSet) Iterate(fn func(index int, val *Validator) bool)
- func (valSet *ValidatorSet) Proposer() (proposer *Validator)
- func (valSet *ValidatorSet) Remove(address []byte) (val *Validator, removed bool)
- func (valSet *ValidatorSet) Size() int
- func (valSet *ValidatorSet) String() string
- func (valSet *ValidatorSet) StringIndented(indent string) string
- func (valSet *ValidatorSet) TotalVotingPower() int64
- func (valSet *ValidatorSet) Update(val *Validator) (updated bool)
- func (valSet *ValidatorSet) VerifyCommit(chainID string, hash []byte, parts PartSetHeader, height int, commit *Commit) error
- type ValidatorsByAddress
- type Vote
- type VoteSet
- func (voteSet *VoteSet) AddByAddress(address []byte, vote *Vote) (added bool, index int, err error)
- func (voteSet *VoteSet) AddByIndex(valIndex int, vote *Vote) (added bool, address []byte, err error)
- func (voteSet *VoteSet) BitArray() *BitArray
- func (voteSet *VoteSet) ChainID() string
- func (voteSet *VoteSet) GetByAddress(address []byte) *Vote
- func (voteSet *VoteSet) GetByIndex(valIndex int) *Vote
- func (voteSet *VoteSet) HasTwoThirdsAny() bool
- func (voteSet *VoteSet) HasTwoThirdsMajority() bool
- func (voteSet *VoteSet) Height() int
- func (voteSet *VoteSet) IsCommit() bool
- func (voteSet *VoteSet) MakeCommit() *Commit
- func (voteSet *VoteSet) Round() int
- func (voteSet *VoteSet) Size() int
- func (voteSet *VoteSet) String() string
- func (voteSet *VoteSet) StringIndented(indent string) string
- func (voteSet *VoteSet) StringShort() string
- func (voteSet *VoteSet) TwoThirdsMajority() (hash []byte, parts PartSetHeader, ok bool)
- func (voteSet *VoteSet) Type() byte
- type VoteSetReader
Constants ¶
const ( EventDataTypeNewBlock = byte(0x01) EventDataTypeFork = byte(0x02) EventDataTypeTx = byte(0x03) EventDataTypeNewBlockHeader = byte(0x04) EventDataTypeRoundState = byte(0x11) EventDataTypeVote = byte(0x12) )
const ( VoteTypePrevote = byte(0x01) VoteTypePrecommit = byte(0x02) )
Types of votes
const MaxBlockSize = 22020096 // 21MB TODO make it configurable
Variables ¶
var ( PeerStateKey = "ConsensusReactor.peerState" PeerMempoolChKey = "MempoolReactor.peerMempoolCh" )
var ( ErrPartSetUnexpectedIndex = errors.New("Error part set unexpected index") ErrPartSetInvalidProof = errors.New("Error part set invalid proof") )
var ( ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature") ErrInvalidBlockPartHash = errors.New("Error invalid block part hash") )
var ( ErrVoteUnexpectedStep = errors.New("Unexpected step") ErrVoteInvalidAccount = errors.New("Invalid round vote account") ErrVoteInvalidSignature = errors.New("Invalid round vote signature") ErrVoteInvalidBlockHash = errors.New("Invalid block hash") )
var GenDocKey = []byte("GenDocKey")
var ValidatorCodec = validatorCodec{}
Functions ¶
func EventStringCompleteProposal ¶ added in v0.7.0
func EventStringCompleteProposal() string
func EventStringDupeout ¶ added in v0.7.0
func EventStringDupeout() string
func EventStringFork ¶ added in v0.7.0
func EventStringFork() string
func EventStringLock ¶ added in v0.7.0
func EventStringLock() string
func EventStringNewBlock ¶ added in v0.7.0
func EventStringNewBlock() string
func EventStringNewBlockHeader ¶ added in v0.7.0
func EventStringNewBlockHeader() string
func EventStringNewRound ¶ added in v0.7.0
func EventStringNewRound() string
func EventStringNewRoundStep ¶ added in v0.7.0
func EventStringNewRoundStep() string
func EventStringPolka ¶ added in v0.7.0
func EventStringPolka() string
func EventStringRebond ¶ added in v0.7.0
func EventStringRebond() string
func EventStringRelock ¶ added in v0.7.0
func EventStringRelock() string
func EventStringTimeoutPropose ¶ added in v0.7.0
func EventStringTimeoutPropose() string
func EventStringTimeoutWait ¶ added in v0.7.0
func EventStringTimeoutWait() string
func EventStringTx ¶ added in v0.7.0
func EventStringUnbond ¶ added in v0.7.0
func EventStringUnbond() string
func EventStringUnlock ¶ added in v0.7.0
func EventStringUnlock() string
func EventStringVote ¶ added in v0.7.0
func EventStringVote() string
func HashSignBytes ¶ added in v0.7.0
HashSignBytes is a convenience method for getting the hash of the bytes of a signable
func RandValidator ¶
func RandValidator(randPower bool, minPower int64) (*Validator, *PrivValidator)
func RandValidatorSet ¶
func RandValidatorSet(numValidators int, votingPower int64) (*ValidatorSet, []*PrivValidator)
Types ¶
type Block ¶
type Block struct { *Header `json:"header"` *Data `json:"data"` LastCommit *Commit `json:"last_commit"` }
func (*Block) FillHeader ¶ added in v0.7.0
func (b *Block) FillHeader()
func (*Block) Hash ¶
Computes and returns the block hash. If the block is incomplete, block hash is nil for safety.
func (*Block) HashesTo ¶
Convenience. A nil block never hashes to anything. Nothing hashes to a nil hash.
func (*Block) MakePartSet ¶
func (*Block) StringIndented ¶
func (*Block) StringShort ¶
type BlockMeta ¶
type BlockMeta struct { Hash []byte `json:"hash"` // The block hash Header *Header `json:"header"` // The block's Header PartsHeader PartSetHeader `json:"parts_header"` // The PartSetHeader, for transfer }
func NewBlockMeta ¶
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. Precommits []*Vote `json:"precommits"` // contains filtered or unexported fields }
NOTE: Commit is empty for height 1, but never nil.
func (*Commit) FirstPrecommit ¶ added in v0.7.0
func (*Commit) GetByIndex ¶
func (*Commit) StringIndented ¶
func (*Commit) ValidateBasic ¶
type Data ¶
type Data struct { // Txs that will be applied by state @ block.Height+1. // NOTE: not all txs here are valid. We're just agreeing on the order first. // This means that block.AppHash does not include these txs. Txs Txs `json:"txs"` // contains filtered or unexported fields }
func (*Data) StringIndented ¶
type DefaultSigner ¶ added in v0.7.0
type DefaultSigner struct {
// contains filtered or unexported fields
}
Implements Signer
func NewDefaultSigner ¶ added in v0.7.0
func NewDefaultSigner(priv crypto.PrivKey) *DefaultSigner
func (*DefaultSigner) Sign ¶ added in v0.7.0
func (ds *DefaultSigner) Sign(msg []byte) crypto.Signature
Implements Signer
type ErrVoteConflictingSignature ¶ added in v0.7.0
func (*ErrVoteConflictingSignature) Error ¶ added in v0.7.0
func (err *ErrVoteConflictingSignature) Error() string
type EventDataNewBlock ¶
type EventDataNewBlock struct {
Block *Block `json:"block"`
}
func (EventDataNewBlock) AssertIsTMEventData ¶ added in v0.7.0
func (_ EventDataNewBlock) AssertIsTMEventData()
type EventDataNewBlockHeader ¶
type EventDataNewBlockHeader struct {
Header *Header `json:"header"`
}
light weight event for benchmarking
func (EventDataNewBlockHeader) AssertIsTMEventData ¶ added in v0.7.0
func (_ EventDataNewBlockHeader) AssertIsTMEventData()
type EventDataRoundState ¶
type EventDataRoundState struct { Height int `json:"height"` Round int `json:"round"` Step string `json:"step"` // private, not exposed to websockets RoundState interface{} `json:"-"` }
NOTE: This goes into the replay WAL
func (EventDataRoundState) AssertIsTMEventData ¶ added in v0.7.0
func (_ EventDataRoundState) AssertIsTMEventData()
type EventDataTx ¶
type EventDataTx struct { Tx Tx `json:"tx"` Result []byte `json:"result"` Log string `json:"log"` Error string `json:"error"` }
All txs fire EventDataTx
func (EventDataTx) AssertIsTMEventData ¶ added in v0.7.0
func (_ EventDataTx) AssertIsTMEventData()
type EventDataVote ¶
func (EventDataVote) AssertIsTMEventData ¶ added in v0.7.0
func (_ EventDataVote) AssertIsTMEventData()
type GenesisDoc ¶
type GenesisDoc struct { GenesisTime time.Time `json:"genesis_time"` ChainID string `json:"chain_id"` Validators []GenesisValidator `json:"validators"` AppHash []byte `json:"app_hash"` }
func GenesisDocFromJSON ¶
func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc)
func (*GenesisDoc) SaveAs ¶
func (genDoc *GenesisDoc) SaveAs(file string) error
Utility method for saving GenensisDoc as JSON file.
type GenesisValidator ¶
type Header ¶
type Header struct { ChainID string `json:"chain_id"` Height int `json:"height"` Time time.Time `json:"time"` NumTxs int `json:"num_txs"` LastBlockHash []byte `json:"last_block_hash"` LastBlockParts PartSetHeader `json:"last_block_parts"` LastCommitHash []byte `json:"last_commit_hash"` DataHash []byte `json:"data_hash"` ValidatorsHash []byte `json:"validators_hash"` AppHash []byte `json:"app_hash"` // state merkle root of txs from the previous block }
func (*Header) StringIndented ¶
type Part ¶
type Part struct { Index int `json:"index"` Bytes []byte `json:"bytes"` Proof merkle.SimpleProof `json:"proof"` // contains filtered or unexported fields }
func (*Part) StringIndented ¶
type PartSet ¶
type PartSet struct {
// contains filtered or unexported fields
}
func 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
Returns an empty PartSet ready to be populated.
func (*PartSet) HasHeader ¶
func (ps *PartSet) HasHeader(header PartSetHeader) bool
func (*PartSet) Header ¶
func (ps *PartSet) Header() PartSetHeader
func (*PartSet) IsComplete ¶
func (*PartSet) StringShort ¶
type PartSetHeader ¶
func (PartSetHeader) Equals ¶
func (psh PartSetHeader) Equals(other PartSetHeader) bool
func (PartSetHeader) IsZero ¶
func (psh PartSetHeader) IsZero() bool
func (PartSetHeader) String ¶
func (psh PartSetHeader) String() string
func (PartSetHeader) WriteSignBytes ¶ added in v0.7.0
func (psh PartSetHeader) WriteSignBytes(w io.Writer, n *int, err *error)
type PartSetReader ¶
type PartSetReader struct {
// contains filtered or unexported fields
}
func NewPartSetReader ¶
func NewPartSetReader(parts []*Part) *PartSetReader
type PrivValidator ¶
type PrivValidator struct { Address []byte `json:"address"` PubKey crypto.PubKey `json:"pub_key"` LastHeight int `json:"last_height"` LastRound int `json:"last_round"` LastStep int8 `json:"last_step"` // PrivKey should be empty if a Signer other than the default is being used. PrivKey crypto.PrivKey `json:"priv_key"` Signer `json:"-"` // contains filtered or unexported fields }
func GenPrivValidator ¶ added in v0.7.0
func GenPrivValidator() *PrivValidator
Generates a new validator with private key.
func LoadOrGenPrivValidator ¶ added in v0.7.0
func LoadOrGenPrivValidator(filePath string) *PrivValidator
func LoadPrivValidator ¶ added in v0.7.0
func LoadPrivValidator(filePath string) *PrivValidator
func (*PrivValidator) Save ¶ added in v0.7.0
func (privVal *PrivValidator) Save()
func (*PrivValidator) SetFile ¶ added in v0.7.0
func (privVal *PrivValidator) SetFile(filePath string)
func (*PrivValidator) SetSigner ¶ added in v0.7.0
func (privVal *PrivValidator) SetSigner(s Signer)
func (*PrivValidator) SignProposal ¶
func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) error
func (*PrivValidator) SignVote ¶
func (privVal *PrivValidator) SignVote(chainID string, vote *Vote) error
func (*PrivValidator) String ¶ added in v0.7.0
func (privVal *PrivValidator) String() string
type PrivValidatorsByAddress ¶
type PrivValidatorsByAddress []*PrivValidator
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 int `json:"height"` Round int `json:"round"` BlockPartsHeader PartSetHeader `json:"block_parts_header"` POLRound int `json:"pol_round"` // -1 if null. Signature crypto.SignatureEd25519 `json:"signature"` }
func NewProposal ¶
func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int) *Proposal
polRound: -1 if no polRound.
type Signable ¶
Signable is an interface for all signable things. It typically removes signatures before serializing.
type Signer ¶ added in v0.7.0
type Signer interface {
Sign(msg []byte) crypto.Signature
}
This is used to sign votes. It is the caller's duty to verify the msg before calling Sign, eg. to avoid double signing. Currently, the only callers are SignVote and SignProposal
type Validator ¶
type Validator struct { Address []byte `json:"address"` PubKey crypto.PubKey `json:"pub_key"` LastCommitHeight int `json:"last_commit_height"` VotingPower int64 `json:"voting_power"` Accum int64 `json:"accum"` }
Volatile state for each Validator Also persisted with the state, but fields change every height|round so they don't go in merkle.Tree
func (*Validator) CompareAccum ¶ added in v0.7.0
Returns the one with higher Accum.
type ValidatorSet ¶
type ValidatorSet struct { Validators []*Validator // NOTE: persisted via reflect, must be exported. // 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 .Proposer() 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 TODO: replace validators []*Validator with github.com/jaekwon/go-ibbs?
func NewValidatorSet ¶
func NewValidatorSet(vals []*Validator) *ValidatorSet
func (*ValidatorSet) Add ¶ added in v0.7.0
func (valSet *ValidatorSet) Add(val *Validator) (added bool)
func (*ValidatorSet) Copy ¶
func (valSet *ValidatorSet) Copy() *ValidatorSet
func (*ValidatorSet) GetByAddress ¶
func (valSet *ValidatorSet) GetByAddress(address []byte) (index int, val *Validator)
func (*ValidatorSet) GetByIndex ¶
func (valSet *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator)
func (*ValidatorSet) HasAddress ¶
func (valSet *ValidatorSet) HasAddress(address []byte) bool
func (*ValidatorSet) Hash ¶
func (valSet *ValidatorSet) Hash() []byte
func (*ValidatorSet) IncrementAccum ¶ added in v0.7.0
func (valSet *ValidatorSet) IncrementAccum(times int)
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)
func (*ValidatorSet) Proposer ¶
func (valSet *ValidatorSet) Proposer() (proposer *Validator)
func (*ValidatorSet) Remove ¶
func (valSet *ValidatorSet) Remove(address []byte) (val *Validator, removed bool)
func (*ValidatorSet) Size ¶
func (valSet *ValidatorSet) Size() int
func (*ValidatorSet) String ¶
func (valSet *ValidatorSet) String() string
func (*ValidatorSet) StringIndented ¶
func (valSet *ValidatorSet) StringIndented(indent string) string
func (*ValidatorSet) TotalVotingPower ¶
func (valSet *ValidatorSet) TotalVotingPower() int64
func (*ValidatorSet) Update ¶ added in v0.7.0
func (valSet *ValidatorSet) Update(val *Validator) (updated bool)
func (*ValidatorSet) VerifyCommit ¶
func (valSet *ValidatorSet) VerifyCommit(chainID string, hash []byte, parts PartSetHeader, height int, commit *Commit) error
Verify that +2/3 of the set had signed the given signBytes
type ValidatorsByAddress ¶
type ValidatorsByAddress []*Validator
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 { Height int `json:"height"` Round int `json:"round"` Type byte `json:"type"` BlockHash []byte `json:"block_hash"` // empty if vote is nil. BlockPartsHeader PartSetHeader `json:"block_parts_header"` // zero if vote is nil. Signature crypto.SignatureEd25519 `json:"signature"` }
Represents a prevote, precommit, or commit vote from validators for consensus.
type VoteSet ¶
type VoteSet struct {
// contains filtered or unexported fields
}
VoteSet helps collect signatures from validators at each height+round for a predefined vote type. Note that there three kinds of votes: prevotes, precommits, and commits. A commit of prior rounds can be added added in lieu of votes/precommits. NOTE: Assumes that the sum total of voting power does not exceed MaxUInt64.
func NewVoteSet ¶
Constructs a new VoteSet struct used to accumulate votes for given height/round.
func (*VoteSet) AddByAddress ¶ added in v0.7.0
Returns added=true, index if vote was added Otherwise returns err=ErrVote[UnexpectedStep|InvalidAccount|InvalidSignature|InvalidBlockHash|ConflictingSignature] Duplicate votes return added=false, err=nil. NOTE: vote should not be mutated after adding.
func (*VoteSet) AddByIndex ¶ added in v0.7.0
func (voteSet *VoteSet) AddByIndex(valIndex int, vote *Vote) (added bool, address []byte, err error)
Returns added=true, index if vote was added Otherwise returns err=ErrVote[UnexpectedStep|InvalidAccount|InvalidSignature|InvalidBlockHash|ConflictingSignature] Duplicate votes return added=false, err=nil. NOTE: vote should not be mutated after adding.
func (*VoteSet) GetByAddress ¶
func (*VoteSet) GetByIndex ¶
func (*VoteSet) HasTwoThirdsAny ¶
func (*VoteSet) HasTwoThirdsMajority ¶
func (*VoteSet) MakeCommit ¶
func (*VoteSet) StringIndented ¶
func (*VoteSet) StringShort ¶
func (*VoteSet) TwoThirdsMajority ¶
func (voteSet *VoteSet) TwoThirdsMajority() (hash []byte, parts PartSetHeader, ok bool)
Returns either a blockhash (or nil) that received +2/3 majority. If there exists no such majority, returns (nil, false).