types

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: Apache-2.0, Apache-2.0 Imports: 32 Imported by: 1

Documentation

Index

Constants

View Source
const (
	EventDataTypeNewBlock       = byte(0x01)
	EventDataTypeFork           = byte(0x02)
	EventDataTypeTx             = byte(0x03)
	EventDataTypeNewBlockHeader = byte(0x04)

	EventDataTypeSwitchToConsensus = byte(0x5)

	EventDataTypeRoundState = byte(0x11)
	EventDataTypeVote       = byte(0x12)

	EventDataTypeHookNewRound  = byte(0x21)
	EventDataTypeHookPropose   = byte(0x22)
	EventDataTypeHookPrevote   = byte(0x23)
	EventDataTypeHookPrecommit = byte(0x24)
	EventDataTypeHookCommit    = byte(0x25)
	EventDataTypeHookExecute   = byte(0x26)
)
View Source
const (
	// angine takes query id from 0x01 to 0x2F
	QueryTxExecution = 0x01
	QueryTx          = 0x02
)
View Source
const (
	// 0x0 bytes are for the blockchain
	ResultTypeGenesis        = byte(0x01)
	ResultTypeBlockchainInfo = byte(0x02)
	ResultTypeBlock          = byte(0x03)
	ResultTypeLastHeight     = byte(0x04)
	ResultTypeHealthInfo     = byte(0x05)

	// 0x2 bytes are for the network
	ResultTypeStatus    = byte(0x20)
	ResultTypeNetInfo   = byte(0x21)
	ResultTypeDialSeeds = byte(0x22)
	ResultTypeShards    = byte(0x23)

	// 0x1  bytes are for refuseList
	ResultTypeRefuseList = byte(0x10)

	// 0x4 bytes are for the consensus
	ResultTypeValidators         = byte(0x40)
	ResultTypeDumpConsensusState = byte(0x41)

	// 0x6 bytes are for txs / the application
	ResultTypeBroadcastTx       = byte(0x60)
	ResultTypeUnconfirmedTxs    = byte(0x61)
	ResultTypeBroadcastTxCommit = byte(0x62)
	ResultTypeRequestAdminOP    = byte(0x63)
	ResultTypeNumArchivedBlocks = byte(0x64)
	ResultTypeNumLimitTx        = byte(0x65)

	// 0x7 bytes are for querying the application
	ResultTypeQuery = byte(0x70)
	ResultTypeInfo  = byte(0x71)

	// 0x8 bytes are for events
	ResultTypeSubscribe   = byte(0x80)
	ResultTypeUnsubscribe = byte(0x81)
	ResultTypeEvent       = byte(0x82)

	// 0xa bytes for testing
	ResultTypeUnsafeSetConfig        = byte(0xa0)
	ResultTypeUnsafeStartCPUProfiler = byte(0xa1)
	ResultTypeUnsafeStopCPUProfiler  = byte(0xa2)
	ResultTypeUnsafeWriteHeapProfile = byte(0xa3)
	ResultTypeUnsafeFlushMempool     = byte(0xa4)
	ResultTypeCoreVersion            = byte(0xaf)

	// 0x9 bytes are for za_surveillance
	ResultTypeSurveillance = byte(0x90)
)
View Source
const (
	VoteTypePrevote   = byte(0x01)
	VoteTypePrecommit = byte(0x02)
)

Types of votes TODO Make a new type "VoteType"

View Source
const (
	AdminOpChangeValidator = "changeValidator"
)
View Source
const MaxBlockSize = 22020096 // 21MB TODO make it configurable
View Source
const (
	PRIV_FILE_NAME = "priv_validator.json"
)

Variables

View Source
var (
	PeerStateKey     = "ConsensusReactor.peerState"
	PeerMempoolChKey = "MempoolReactor.peerMempoolCh"
)
View Source
var (
	ErrPartSetUnexpectedIndex = errors.New("Error part set unexpected index")
	ErrPartSetInvalidProof    = errors.New("Error part set invalid proof")
)
View Source
var (
	ErrFileNotFound       = errors.New("priv_validator.json not found")
	ErrBranchIsUsed       = errors.New("priv_validator:branch name is used")
	ErrPVRevertFromBackup = errors.New("priv_validator:revert from backup, not find data")
)
View Source
var (
	ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
	ErrInvalidBlockPartHash      = errors.New("Error invalid block part hash")
)
View Source
var (
	ErrVoteUnexpectedStep          = errors.New("Unexpected step")
	ErrVoteInvalidValidatorIndex   = errors.New("Invalid round vote validator index")
	ErrVoteInvalidValidatorAddress = errors.New("Invalid round vote validator address")
	ErrVoteInvalidSignature        = errors.New("Invalid round vote signature")
	ErrVoteInvalidBlockHash        = errors.New("Invalid block hash")
)
View Source
var (
	AdminTag = []byte("zaop")
)
View Source
var CodeType_name = map[int32]string{
	0:   "OK",
	1:   "InternalError",
	2:   "EncodingError",
	3:   "BadNonce",
	4:   "Unauthorized",
	5:   "InsufficientFunds",
	6:   "UnknownRequest",
	101: "BaseDuplicateAddress",
	102: "BaseEncodingError",
	103: "BaseInsufficientFees",
	104: "BaseInsufficientFunds",
	105: "BaseInsufficientGasPrice",
	106: "BaseInvalidInput",
	107: "BaseInvalidOutput",
	108: "BaseInvalidPubKey",
	109: "BaseInvalidSequence",
	110: "BaseInvalidSignature",
	111: "BaseUnknownAddress",
	112: "BaseUnknownPubKey",
	113: "BaseUnknownPlugin",
	114: "WrongRLP",
	115: "SaveFailed",
	201: "GovUnknownEntity",
	202: "GovUnknownGroup",
	203: "GovUnknownProposal",
	204: "GovDuplicateGroup",
	205: "GovDuplicateMember",
	206: "GovDuplicateProposal",
	207: "GovDuplicateVote",
	208: "GovInvalidMember",
	209: "GovInvalidVote",
	210: "GovInvalidVotingPower",
}
View Source
var CodeType_value = map[string]int32{
	"OK":                       0,
	"InternalError":            1,
	"EncodingError":            2,
	"BadNonce":                 3,
	"Unauthorized":             4,
	"InsufficientFunds":        5,
	"UnknownRequest":           6,
	"BaseDuplicateAddress":     101,
	"BaseEncodingError":        102,
	"BaseInsufficientFees":     103,
	"BaseInsufficientFunds":    104,
	"BaseInsufficientGasPrice": 105,
	"BaseInvalidInput":         106,
	"BaseInvalidOutput":        107,
	"BaseInvalidPubKey":        108,
	"BaseInvalidSequence":      109,
	"BaseInvalidSignature":     110,
	"BaseUnknownAddress":       111,
	"BaseUnknownPubKey":        112,
	"BaseUnknownPlugin":        113,
	"WrongRLP":                 114,
	"SaveFailed":               115,
	"GovUnknownEntity":         201,
	"GovUnknownGroup":          202,
	"GovUnknownProposal":       203,
	"GovDuplicateGroup":        204,
	"GovDuplicateMember":       205,
	"GovDuplicateProposal":     206,
	"GovDuplicateVote":         207,
	"GovInvalidMember":         208,
	"GovInvalidVote":           209,
	"GovInvalidVotingPower":    210,
}
View Source
var GenDocKey = []byte("GenDocKey")
View Source
var ValidatorCodec = validatorCodec{}

Functions

func AddListenerForEvent

func AddListenerForEvent(evsw EventSwitch, id, event string, cb func(data TMEventData))

func Byte64Tobyte

func Byte64Tobyte(bytes64 [64]byte) (bytes []byte)

func BytesToByte64

func BytesToByte64(bytes []byte) (b64 [64]byte)

func EventStringBond

func EventStringBond() string

Reserved

func EventStringCompleteProposal

func EventStringCompleteProposal() string

func EventStringDupeout

func EventStringDupeout() string

func EventStringFork

func EventStringFork() string

func EventStringHookCommit

func EventStringHookCommit() string

func EventStringHookExecute

func EventStringHookExecute() string

func EventStringHookNewRound

func EventStringHookNewRound() string

func EventStringHookPrecommit

func EventStringHookPrecommit() string

func EventStringHookPrevote

func EventStringHookPrevote() string

func EventStringHookPropose

func EventStringHookPropose() string

func EventStringLock

func EventStringLock() string

func EventStringNewBlock

func EventStringNewBlock() string

func EventStringNewBlockHeader

func EventStringNewBlockHeader() string

func EventStringNewRound

func EventStringNewRound() string

func EventStringNewRoundStep

func EventStringNewRoundStep() string

func EventStringPolka

func EventStringPolka() string

func EventStringRebond

func EventStringRebond() string

func EventStringRelock

func EventStringRelock() string

func EventStringSwitchToConsensus

func EventStringSwitchToConsensus() string

func EventStringTimeoutPropose

func EventStringTimeoutPropose() string

func EventStringTimeoutWait

func EventStringTimeoutWait() string

func EventStringTx

func EventStringTx(tx Tx) string

func EventStringUnbond

func EventStringUnbond() string

func EventStringUnlock

func EventStringUnlock() string

func EventStringVote

func EventStringVote() string

func FireEventCompleteProposal

func FireEventCompleteProposal(fireable events.Fireable, rs EventDataRoundState)

func FireEventHookCommit

func FireEventHookCommit(fireable events.Fireable, d EventDataHookCommit)

func FireEventHookExecute

func FireEventHookExecute(fireable events.Fireable, d EventDataHookExecute)

func FireEventHookNewRound

func FireEventHookNewRound(fireable events.Fireable, d EventDataHookNewRound)

func FireEventHookPrecommit

func FireEventHookPrecommit(fireable events.Fireable, d EventDataHookPrecommit)

func FireEventHookPrevote

func FireEventHookPrevote(fireable events.Fireable, d EventDataHookPrevote)

func FireEventHookPropose

func FireEventHookPropose(fireable events.Fireable, d EventDataHookPropose)

func FireEventLock

func FireEventLock(fireable events.Fireable, rs EventDataRoundState)

func FireEventNewBlock

func FireEventNewBlock(fireable events.Fireable, block EventDataNewBlock)

func FireEventNewBlockHeader

func FireEventNewBlockHeader(fireable events.Fireable, header EventDataNewBlockHeader)

func FireEventNewRound

func FireEventNewRound(fireable events.Fireable, rs EventDataRoundState)

func FireEventNewRoundStep

func FireEventNewRoundStep(fireable events.Fireable, rs EventDataRoundState)

func FireEventPolka

func FireEventPolka(fireable events.Fireable, rs EventDataRoundState)

func FireEventRelock

func FireEventRelock(fireable events.Fireable, rs EventDataRoundState)

func FireEventSwitchToConsensus

func FireEventSwitchToConsensus(fireable events.Fireable)

func FireEventTimeoutPropose

func FireEventTimeoutPropose(fireable events.Fireable, rs EventDataRoundState)

func FireEventTimeoutWait

func FireEventTimeoutWait(fireable events.Fireable, rs EventDataRoundState)

func FireEventTx

func FireEventTx(fireable events.Fireable, tx EventDataTx)

func FireEventUnlock

func FireEventUnlock(fireable events.Fireable, rs EventDataRoundState)

func FireEventVote

func FireEventVote(fireable events.Fireable, vote EventDataVote)

func GenTxsForTest

func GenTxsForTest(numtx, numExTx int) ([]Tx, []Tx)

func HashSignBytes

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

HashSignBytes is a convenience method for getting the hash of the bytes of a signable

func IsAdminOP

func IsAdminOP(tx []byte) bool

func IsVoteTypeValid

func IsVoteTypeValid(type_ byte) bool

func MakeBlock

func MakeBlock(height int64, chainID string, txs []Tx, extxs []Tx, commit *Commit, proposer []byte,
	prevBlockID BlockID, valHash, appHash, receiptsHash []byte, partSize int) (*Block, *PartSet)

TODO: version

func PrivKeyByteToByte64

func PrivKeyByteToByte64(bytes []byte) (byte64 [64]byte)

func RandValidator

func RandValidator(randPower bool, minPower int64) (*Validator, *PrivValidator)

func RandValidatorSet

func RandValidatorSet(numValidators int, votingPower int64) (*ValidatorSet, []*PrivValidator)

NOTE: PrivValidator are in order.

func SignBytes

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

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

func SignCA

func SignCA(priv crypto.PrivKey, pubbytes []byte) string

func StrToSmallStr

func StrToSmallStr(str string) (smallstr string)

func StringTo32byte

func StringTo32byte(key string) ([32]byte, error)

func StringTo64byte

func StringTo64byte(key string) ([64]byte, error)

func StringToAnybyte

func StringToAnybyte(key string) ([]byte, error)

func Substr

func Substr(str string, start int, length int) string

func TagAdminOPTx

func TagAdminOPTx(tx []byte) []byte

func TxsLenForTest

func TxsLenForTest() int

func TxsNumForTest

func TxsNumForTest() int

func UnwrapTx

func UnwrapTx(tx []byte) []byte

func WrapTx

func WrapTx(prefix []byte, tx []byte) []byte

Types

type AdminOPCmd

type AdminOPCmd struct {
	CmdType  string    `json:"cmdtype"` //type for what kind of adminOp
	Msg      []byte    `json:"msg"`
	SelfSign []byte    `json:"sigs"`
	Time     time.Time `json:"time"`
	Nonce    uint64    `json:"nonce"`
	SInfos   []SigInfo `json:"siginfos"`
}

func (*AdminOPCmd) ExtractMsg

func (cmd *AdminOPCmd) ExtractMsg(o interface{}) (interface{}, error)

func (*AdminOPCmd) LoadMsg

func (cmd *AdminOPCmd) LoadMsg(o interface{}) error

type AdminVoteResult

type AdminVoteResult struct {
	Result    []byte
	PubKey    []byte
	Signature []byte
}

type Application

type Application interface {
	GetAngineHooks() Hooks
	CompatibleWithAngine()
	CheckTx(bs []byte) (from common.Address, nonce uint64, err error)
	Query([]byte) Result
	Info() ResultInfo
	Start() error
	Stop()
	SetCore(Core)
}

type BaseApplication

type BaseApplication struct {
	Database         db.DB
	InitializedState bool
}

func (*BaseApplication) InitBaseApplication

func (ba *BaseApplication) InitBaseApplication(name string, datadir string) (err error)

InitBaseApplication must be the first thing to be called when an application embeds BaseApplication

func (*BaseApplication) Initialized

func (ba *BaseApplication) Initialized() bool

Initialized returns if a BaseApplication based app has been fully initialized

func (*BaseApplication) LoadLastBlock

func (ba *BaseApplication) LoadLastBlock(t interface{}) (res interface{}, err error)

func (*BaseApplication) SaveLastBlock

func (ba *BaseApplication) SaveLastBlock(lastBlock interface{})

func (*BaseApplication) SaveLastBlockByKey

func (ba *BaseApplication) SaveLastBlockByKey(key []byte, lastBlock interface{})

func (*BaseApplication) Stop

func (ba *BaseApplication) Stop()

Stop handles freeing resources taken by BaseApplication

type Block

type Block struct {
	*Header    `json:"header"`
	*Data      `json:"data"`
	LastCommit *Commit `json:"last_commit"`
}

func GenBlockForTest

func GenBlockForTest(height int64, ntxs, nexTxs int) *Block

func GenBlocksForTest

func GenBlocksForTest(num int) []*Block

func (*Block) FillHeader

func (b *Block) FillHeader()

func (*Block) Hash

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

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

func (*Block) HashesTo

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

Convenience. A nil block never hashes to anything. Nothing hashes to a nil hash.

func (*Block) MakePartSet

func (b *Block) MakePartSet(partSize int) *PartSet

func (*Block) String

func (b *Block) String() string

func (*Block) StringIndented

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

func (*Block) StringShort

func (b *Block) StringShort() string

func (*Block) TxsIsNil

func (b *Block) TxsIsNil() bool

func (*Block) ValidateBasic

func (b *Block) ValidateBasic(chainID string, lastBlockHeight int64, lastBlockID BlockID,
	lastBlockTime time.Time, appHash, receiptsHash []byte) error

Basic validation that doesn't involve state data.

func (*Block) ValidateCommit added in v1.4.0

func (b *Block) ValidateCommit() error

type BlockID

type BlockID struct {
	Hash        []byte        `json:"hash"`
	PartsHeader PartSetHeader `json:"parts"`
}

func GenBlockID

func GenBlockID() BlockID

func (BlockID) Equals

func (blockID BlockID) Equals(other BlockID) bool

func (BlockID) IsZero

func (blockID BlockID) IsZero() bool

func (BlockID) Key

func (blockID BlockID) Key() string

func (BlockID) String

func (blockID BlockID) String() string

func (BlockID) WriteSignBytes

func (blockID BlockID) WriteSignBytes(w io.Writer, n *int, err *error)

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

func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta

type CanonicalJSONBlockID

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

func CanonicalBlockID

func CanonicalBlockID(blockID BlockID) CanonicalJSONBlockID

type CanonicalJSONOnceProposal

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

type CanonicalJSONOnceVote

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

type CanonicalJSONPartSetHeader

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

func CanonicalPartSetHeader

func CanonicalPartSetHeader(psh PartSetHeader) CanonicalJSONPartSetHeader

type CanonicalJSONProposal

type CanonicalJSONProposal struct {
	BlockPartsHeader CanonicalJSONPartSetHeader `json:"block_parts_header"`
	Height           int64                      `json:"height"`
	POLBlockID       CanonicalJSONBlockID       `json:"pol_block_id"`
	POLRound         int64                      `json:"pol_round"`
	Round            int64                      `json:"round"`
}

func CanonicalProposal

func CanonicalProposal(proposal *Proposal) CanonicalJSONProposal

type CanonicalJSONVote

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

func CanonicalVote

func CanonicalVote(vote *Vote) CanonicalJSONVote

type CmdType

type CmdType string

type CodeType

type CodeType int32
const (
	CodeType_OK CodeType = 0
	// General response codes, 0 ~ 99
	CodeType_InternalError     CodeType = 1
	CodeType_EncodingError     CodeType = 2
	CodeType_BadNonce          CodeType = 3
	CodeType_Unauthorized      CodeType = 4
	CodeType_InsufficientFunds CodeType = 5
	CodeType_UnknownRequest    CodeType = 6
	CodeType_InvalidTx         CodeType = 7
	// Reserved for basecoin, 100 ~ 199
	CodeType_BaseDuplicateAddress     CodeType = 101
	CodeType_BaseEncodingError        CodeType = 102
	CodeType_BaseInsufficientFees     CodeType = 103
	CodeType_BaseInsufficientFunds    CodeType = 104
	CodeType_BaseInsufficientGasPrice CodeType = 105
	CodeType_BaseInvalidInput         CodeType = 106
	CodeType_BaseInvalidOutput        CodeType = 107
	CodeType_BaseInvalidPubKey        CodeType = 108
	CodeType_BaseInvalidSequence      CodeType = 109
	CodeType_BaseInvalidSignature     CodeType = 110
	CodeType_BaseUnknownAddress       CodeType = 111
	CodeType_BaseUnknownPubKey        CodeType = 112
	CodeType_BaseUnknownPlugin        CodeType = 113
	CodeType_WrongRLP                 CodeType = 114
	CodeType_SaveFailed               CodeType = 115
	// Reserved for governance, 200 ~ 299
	CodeType_GovUnknownEntity      CodeType = 201
	CodeType_GovUnknownGroup       CodeType = 202
	CodeType_GovUnknownProposal    CodeType = 203
	CodeType_GovDuplicateGroup     CodeType = 204
	CodeType_GovDuplicateMember    CodeType = 205
	CodeType_GovDuplicateProposal  CodeType = 206
	CodeType_GovDuplicateVote      CodeType = 207
	CodeType_GovInvalidMember      CodeType = 208
	CodeType_GovInvalidVote        CodeType = 209
	CodeType_GovInvalidVotingPower CodeType = 210
)

func (CodeType) String

func (x CodeType) String() string

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:"blockID"`
	Precommits []*Vote `json:"precommits"`
	// contains filtered or unexported fields
}

NOTE: Commit is empty for height 1, but never nil.

func GenCommitForTest

func GenCommitForTest(height int64, chainID string) *Commit

func (*Commit) BitArray

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

func (*Commit) FirstPrecommit

func (commit *Commit) FirstPrecommit() *Vote

func (*Commit) GetByIndex

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

func (*Commit) Hash

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

func (*Commit) Height

func (commit *Commit) Height() int64

func (*Commit) IsCommit

func (commit *Commit) IsCommit() bool

func (*Commit) Round

func (commit *Commit) Round() int64

func (*Commit) Size

func (commit *Commit) Size() int

func (*Commit) StringIndented

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

func (*Commit) Type

func (commit *Commit) Type() byte

func (*Commit) ValidateBasic

func (commit *Commit) ValidateBasic() error

type CommitResult

type CommitResult struct {
	AppHash      []byte
	ReceiptsHash []byte
}

type Core

type Core interface {
	Query(byte, []byte) (interface{}, error)
	GetBlockMeta(height int64) (*BlockMeta, error)
}

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"`
	ExTxs Txs `json:"extxs"` // this is for all other txs which won't be delivered to app
	// contains filtered or unexported fields
}

func (*Data) Hash

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

func (*Data) StringIndented

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

type DefaultSigner

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

Implements Signer

func NewDefaultSigner

func NewDefaultSigner(priv crypto.PrivKey) *DefaultSigner

func (*DefaultSigner) Sign

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

Implements Signer

type ErrVoteConflictingVotes

type ErrVoteConflictingVotes struct {
	VoteA *Vote
	VoteB *Vote
}

func (*ErrVoteConflictingVotes) Error

func (err *ErrVoteConflictingVotes) Error() string

type EventCache

type EventCache interface {
	Fireable
	Flush()
}

func NewEventCache

func NewEventCache(evsw EventSwitch) EventCache

type EventDataHookCommit

type EventDataHookCommit struct {
	Height int64
	Round  int64
	Block  *Block
	ResCh  chan CommitResult
}

func NewEventDataHookCommit

func NewEventDataHookCommit(height, round int64, block *Block) EventDataHookCommit

func (EventDataHookCommit) AssertIsTMEventData

func (_ EventDataHookCommit) AssertIsTMEventData()

type EventDataHookExecute

type EventDataHookExecute struct {
	Height int64
	Round  int64
	Block  *Block
	ResCh  chan ExecuteResult
}

func NewEventDataHookExecute

func NewEventDataHookExecute(height, round int64, block *Block) EventDataHookExecute

func (EventDataHookExecute) AssertIsTMEventData

func (_ EventDataHookExecute) AssertIsTMEventData()

type EventDataHookNewRound

type EventDataHookNewRound struct {
	Height int64
	Round  int64
	ResCh  chan NewRoundResult
}

func NewEventDataHookNewRound

func NewEventDataHookNewRound(height, round int64) EventDataHookNewRound

func (EventDataHookNewRound) AssertIsTMEventData

func (_ EventDataHookNewRound) AssertIsTMEventData()

type EventDataHookPrecommit

type EventDataHookPrecommit struct {
	Height int64
	Round  int64
	Block  *Block
}

func (EventDataHookPrecommit) AssertIsTMEventData

func (_ EventDataHookPrecommit) AssertIsTMEventData()

type EventDataHookPrevote

type EventDataHookPrevote struct {
	Height int64
	Round  int64
	Block  *Block
}

func (EventDataHookPrevote) AssertIsTMEventData

func (_ EventDataHookPrevote) AssertIsTMEventData()

type EventDataHookPropose

type EventDataHookPropose struct {
	Height int64
	Round  int64
	Block  *Block
}

func (EventDataHookPropose) AssertIsTMEventData

func (_ EventDataHookPropose) AssertIsTMEventData()

type EventDataNewBlock

type EventDataNewBlock struct {
	Block *Block `json:"block"`
}

func (EventDataNewBlock) AssertIsTMEventData

func (_ EventDataNewBlock) AssertIsTMEventData()

type EventDataNewBlockHeader

type EventDataNewBlockHeader struct {
	Header *Header `json:"header"`
}

light weight event for benchmarking

func (EventDataNewBlockHeader) AssertIsTMEventData

func (_ EventDataNewBlockHeader) AssertIsTMEventData()

type EventDataRoundState

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

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

NOTE: This goes into the replay WAL

func (EventDataRoundState) AssertIsTMEventData

func (_ EventDataRoundState) AssertIsTMEventData()

type EventDataSwitchToConsensus

type EventDataSwitchToConsensus struct {
	State interface{}
}

func (EventDataSwitchToConsensus) AssertIsTMEventData

func (_ EventDataSwitchToConsensus) AssertIsTMEventData()

type EventDataTx

type EventDataTx struct {
	Tx    Tx       `json:"tx"`
	Data  []byte   `json:"data"`
	Log   string   `json:"log"`
	Code  CodeType `json:"code"`
	Error string   `json:"error"` // this is redundant information for now
}

All txs fire EventDataTx

func (EventDataTx) AssertIsTMEventData

func (_ EventDataTx) AssertIsTMEventData()

type EventDataVote

type EventDataVote struct {
	Vote *Vote
}

func (EventDataVote) AssertIsTMEventData

func (_ EventDataVote) AssertIsTMEventData()

type EventSwitch

type EventSwitch interface {
	events.EventSwitch
}

func NewEventSwitch

func NewEventSwitch() EventSwitch

type Eventable

type Eventable interface {
	SetEventSwitch(EventSwitch)
}

type ExecuteInvalidTx

type ExecuteInvalidTx struct {
	Bytes []byte
	Error error
}

type ExecuteResult

type ExecuteResult struct {
	ValidTxs   Txs
	InvalidTxs []ExecuteInvalidTx
	Error      error
}

type Fireable

type Fireable interface {
	events.Fireable
}

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"`
	Plugins     string             `json:"plugins"`
}

func GenesisDocFromJSON

func GenesisDocFromJSON(jsonBlob []byte) *GenesisDoc

func GenesisDocFromJSONRet

func GenesisDocFromJSONRet(jsonBlob []byte) (genState *GenesisDoc, err error)

func (*GenesisDoc) JSONBytes

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

func (*GenesisDoc) SaveAs

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

Utility method for saving GenensisDoc as JSON file.

type GenesisValidator

type GenesisValidator struct {
	PubKey     crypto.PubKey `json:"pub_key"`
	Amount     int64         `json:"amount"`
	Name       string        `json:"name"`
	IsCA       bool          `json:"is_ca"`
	RPCAddress string        `json:"rpc"`
}

func (*GenesisValidator) UnmarshalJSON

func (gv *GenesisValidator) UnmarshalJSON(b []byte) error

type GenesisValidatorJson

type GenesisValidatorJson struct {
	PubKey     []byte `json:"pub_key"`
	Amount     int64  `json:"amount"`
	Name       string `json:"name"`
	IsCA       bool   `json:"is_ca"`
	RPCAddress string `json:"rpc"`
}
type Header struct {
	ChainID         string    `json:"chain_id"`
	Height          int64     `json:"height"`
	Time            time.Time `json:"time"`
	NumTxs          int64     `json:"num_txs"` // XXX: Can we get rid of this?
	LastBlockID     BlockID   `json:"last_block_id"`
	LastCommitHash  []byte    `json:"last_commit_hash"` // commit from validators from the last block
	DataHash        []byte    `json:"data_hash"`        // transactions
	ValidatorsHash  []byte    `json:"validators_hash"`  // validators for the current block
	AppHash         []byte    `json:"app_hash"`         // state after txs from the previous block
	ReceiptsHash    []byte    `json:"recepits_hash"`    // recepits_hash from previous block
	ProposerAddress []byte    `json:"proposer_address"`
	Extra           []byte    `json:"extra"` // doesn't included in header hash
}

func (*Header) Hash

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

NOTE: hash is nil if required fields are missing.

func (*Header) StringIndented

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

type Hook

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

func NewHook

func NewHook(cb func(int64, int64, *Block) (interface{}, error)) *Hook

func (*Hook) Async

func (h *Hook) Async(height, round int64, block *Block, cb func(interface{}), onError func(error))

func (*Hook) Error

func (h *Hook) Error() error

func (*Hook) Result

func (h *Hook) Result() interface{}

func (*Hook) Sync

func (h *Hook) Sync(height, round int64, block *Block) (interface{}, error)

type Hooker

type Hooker interface {
	Sync(int, int, *Block) (interface{}, error)
	Async(int, int, *Block)
	Result() interface{}
}

type Hooks

type Hooks struct {
	OnNewRound  *Hook
	OnPropose   *Hook
	OnPrevote   *Hook
	OnPrecommit *Hook
	OnCommit    *Hook
	OnExecute   *Hook
}

type IFilter

type IFilter interface {
	CheckTx(Tx) (bool, error)
}

anyone impplements IFilter can be register as a tx filter

type IMempool

type IMempool interface {
	Lock()
	Unlock()
	Update(height int64, txs []Tx)
}

type KeyValueHistories added in v1.5.0

type KeyValueHistories []*KeyValueHistory

func (KeyValueHistories) String added in v1.5.0

func (k KeyValueHistories) String() string

type KeyValueHistory added in v1.5.0

type KeyValueHistory struct {
	Key                []byte
	ValueUpdateHistory *ValueUpdateHistory
}

func (*KeyValueHistory) String added in v1.5.0

func (k *KeyValueHistory) String() string

type NewRoundResult

type NewRoundResult struct {
}

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

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

func (*Part) String

func (part *Part) String() string

func (*Part) StringIndented

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

type PartSet

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

func NewPartSetFromData

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

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

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

func (*PartSet) BitArray

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

func (*PartSet) Count

func (ps *PartSet) Count() int

func (*PartSet) GetPart

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

func (*PartSet) GetReader

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

func (*PartSet) HasHeader

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

func (*PartSet) Hash

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

func (*PartSet) HashesTo

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

func (*PartSet) Header

func (ps *PartSet) Header() PartSetHeader

func (*PartSet) IsComplete

func (ps *PartSet) IsComplete() bool

func (*PartSet) StringShort

func (ps *PartSet) StringShort() string

func (*PartSet) Total

func (ps *PartSet) Total() int

type PartSetHeader

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

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

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

func (*PartSetReader) Read

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

type Peer

type Peer struct {
	p2p.NodeInfo     `json:"node_info"`
	IsOutbound       bool                 `json:"is_outbound"`
	ConnectionStatus p2p.ConnectionStatus `json:"connection_status"`
}

type PrivValidator

type PrivValidator struct {
	Address       []byte           `json:"address"`
	PubKey        crypto.PubKey    `json:"pub_key"`
	LastHeight    int64            `json:"last_height"`
	LastRound     int64            `json:"last_round"`
	LastStep      int8             `json:"last_step"`
	LastSignature crypto.Signature `json:"last_signature"` // so we dont lose signatures
	LastSignBytes []byte           `json:"last_signbytes"` // so we dont lose signatures

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

func GenPrivValidator(cryptoType string, privkey crypto.PrivKey) (*PrivValidator, error)

Generates a new validator with private key.

func LoadOrGenPrivValidator

func LoadOrGenPrivValidator(filePath string) *PrivValidator

func LoadPrivValidator

func LoadPrivValidator(filePath string) (*PrivValidator, error)

func (*PrivValidator) CopyReset

func (pv *PrivValidator) CopyReset() (cp PrivValidator)

func (*PrivValidator) GetAddress

func (privVal *PrivValidator) GetAddress() []byte

func (*PrivValidator) GetLastSignature

func (pv *PrivValidator) GetLastSignature() crypto.Signature

func (*PrivValidator) GetPrivKey

func (pv *PrivValidator) GetPrivKey() crypto.PrivKey

func (*PrivValidator) GetPrivateKey

func (privVal *PrivValidator) GetPrivateKey() crypto.PrivKey

func (*PrivValidator) GetPubKey

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

func (*PrivValidator) Reset

func (privVal *PrivValidator) Reset()

NOTE: Unsafe!

func (*PrivValidator) Save

func (privVal *PrivValidator) Save() error

func (*PrivValidator) SetFile

func (privVal *PrivValidator) SetFile(filePath string)

func (*PrivValidator) SetSigner

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

func (privVal *PrivValidator) String() string

func (*PrivValidator) UnmarshalJSON

func (pv *PrivValidator) UnmarshalJSON(data []byte) error

type PrivValidatorTool

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

func (*PrivValidatorTool) BackupData

func (pt *PrivValidatorTool) BackupData(branchName string) error

func (*PrivValidatorTool) DelBackup

func (pt *PrivValidatorTool) DelBackup(branchName string)

func (*PrivValidatorTool) Init

func (pt *PrivValidatorTool) Init(dir string) error

func (*PrivValidatorTool) RevertFromBackup

func (pt *PrivValidatorTool) RevertFromBackup(branchName string) error

func (*PrivValidatorTool) SaveNewPrivV

func (pt *PrivValidatorTool) SaveNewPrivV(toHeight int64) error

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           int64            `json:"height"`
	Round            int64            `json:"round"`
	BlockPartsHeader PartSetHeader    `json:"block_parts_header"`
	POLRound         int64            `json:"pol_round"`    // -1 if null.
	POLBlockID       BlockID          `json:"pol_block_id"` // zero if null.
	Signature        crypto.Signature `json:"signature"`
}

func NewProposal

func NewProposal(height int64, round int64, blockPartsHeader PartSetHeader, polRound int64, polBlockID BlockID) *Proposal

polRound: -1 if no polRound.

func (*Proposal) String

func (p *Proposal) String() string

func (*Proposal) WriteSignBytes

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

type RPCResult

type RPCResult interface {
	rpctypes.Result
}

type Result

type Result struct {
	Code CodeType
	Data []byte
	Log  string // Can be non-deterministic
}

CONTRACT: a zero Result is OK.

func NewError

func NewError(code CodeType, log string) Result

func NewResult

func NewResult(code CodeType, data []byte, log string) Result

func NewResultOK

func NewResultOK(data []byte, log string) Result

NOTE: if data == nil and log == "", same as zero Result.

func (Result) AppendLog

func (res Result) AppendLog(log string) Result

func (Result) Error

func (res Result) Error() string

func (Result) IsErr

func (res Result) IsErr() bool

func (Result) IsOK

func (res Result) IsOK() bool

func (Result) PrependLog

func (res Result) PrependLog(log string) Result

func (Result) SetData

func (res Result) SetData(data []byte) Result

func (Result) SetLog

func (res Result) SetLog(log string) Result

func (Result) String

func (res Result) String() string

type ResultBlock

type ResultBlock struct {
	BlockMeta *BlockMeta `json:"block_meta"`
	Block     *Block     `json:"block"`
}

type ResultBlockchainInfo

type ResultBlockchainInfo struct {
	LastHeight int64        `json:"last_height"`
	BlockMetas []*BlockMeta `json:"block_metas"`
}

type ResultBroadcastTx

type ResultBroadcastTx struct {
	Code   CodeType `json:"code"`
	Data   []byte   `json:"data"`
	TxHash string   `json:"tx_hash"`
	Log    string   `json:"log"`
}

type ResultBroadcastTxCommit

type ResultBroadcastTxCommit struct {
	Code   CodeType `json:"code"`
	Data   []byte   `json:"data"`
	TxHash string   `json:"tx_hash"`
	Log    string   `json:"log"`
}

type ResultCoreVersion

type ResultCoreVersion struct {
	Version    string `json:"version"`
	AppName    string `json:"appname"`
	AppVersion string `json:"appversion"`
	Hash       string `json:"hash"`
}

type ResultDialSeeds

type ResultDialSeeds struct {
}

type ResultDumpConsensusState

type ResultDumpConsensusState struct {
	RoundState      string   `json:"round_state"`
	PeerRoundStates []string `json:"peer_round_states"`
}

type ResultEvent

type ResultEvent struct {
	Name string      `json:"name"`
	Data TMEventData `json:"data"`
}

type ResultGenesis

type ResultGenesis struct {
	Genesis *GenesisDoc `json:"genesis"`
}

type ResultHealthInfo

type ResultHealthInfo struct {
	Status int `json:"status"`
}

type ResultInfo

type ResultInfo struct {
	Data             string `json:"data"`
	Version          string `json:"version"`
	LastBlockHeight  int64  `json:"last_block_height"`
	LastBlockAppHash []byte `json:"last_block_app_hash"`
}

type ResultLastHeight

type ResultLastHeight struct {
	LastHeight int64 `json:"last_height"`
}

type ResultNetInfo

type ResultNetInfo struct {
	Listening bool     `json:"listening"`
	Listeners []string `json:"listeners"`
	Peers     []*Peer  `json:"peers"`
}

type ResultNumArchivedBlocks

type ResultNumArchivedBlocks struct {
	Num int64 `json:"num"`
}

type ResultNumLimitTx

type ResultNumLimitTx struct {
	Num uint64 `json:"num"`
}

type ResultQuery

type ResultQuery struct {
	Result Result `json:"result"`
}

type ResultRefuseList

type ResultRefuseList struct {
	Result []string `json:"result"`
}

type ResultRequestAdminOP

type ResultRequestAdminOP struct {
	Code CodeType `json:"code"`
	Data []byte   `json:"data"`
	Log  string   `json:"log"`
}

type ResultShards

type ResultShards struct {
	Names []string `json:"names"`
}

type ResultStatus

type ResultStatus struct {
	NodeInfo          *p2p.NodeInfo `json:"node_info"`
	PubKey            crypto.PubKey `json:"pub_key"`
	LatestBlockHash   []byte        `json:"latest_block_hash"`
	LatestAppHash     []byte        `json:"latest_app_hash"`
	LatestBlockHeight int64         `json:"latest_block_height"`
	LatestBlockTime   int64         `json:"latest_block_time"` // nano
}

type ResultSubscribe

type ResultSubscribe struct {
}

type ResultSurveillance

type ResultSurveillance struct {
	NanoSecsPerTx time.Duration
	Height        int64
	Addr          string
	IsValidator   bool
	NumValidators int
	NumPeers      int
	RunningTime   time.Duration
	PubKey        string
}

type ResultTransaction

type ResultTransaction struct {
	BlockHash        []byte `json:"block_hash"`
	BlockHeight      uint64 `json:"block_height"`
	TransactionIndex uint64 `json:"transaction_index"`
	RawTransaction   []byte `json:"raw_transaction"`
	Timestamp        uint64 `json:"timestamp"`
}

type ResultUnconfirmedTxs

type ResultUnconfirmedTxs struct {
	N   int  `json:"n_txs"`
	Txs []Tx `json:"txs"`
}

type ResultUnsafeFlushMempool

type ResultUnsafeFlushMempool struct{}

type ResultUnsafeProfile

type ResultUnsafeProfile struct{}

type ResultUnsafeSetConfig

type ResultUnsafeSetConfig struct{}

type ResultUnsubscribe

type ResultUnsubscribe struct {
}

type ResultValidator

type ResultValidator struct {
	Address     []byte `json:"address"`
	PubKey      string `json:"pub_key"`
	VotingPower int64  `json:"voting_power"`
	Accum       int64  `json:"accum"`
	IsCA        bool   `json:"is_ca"`
}

func MakeResultValidators

func MakeResultValidators(vs []*Validator) []*ResultValidator

type ResultValidators

type ResultValidators struct {
	BlockHeight int64              `json:"block_height"`
	Validators  []*ResultValidator `json:"validators"`
}

type SigInfo

type SigInfo struct {
	PubKey    []byte `json:"pubkey"`
	Signature []byte `json:"signature"`
}

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 Signer

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 TMEventData

type TMEventData interface {
	events.EventData
	AssertIsTMEventData()
}

implements events.EventData

type Tx

type Tx []byte

func (Tx) Hash

func (tx Tx) Hash() []byte

ethereum transaction hash

func (Tx) Size

func (tx Tx) Size() int

type TxExecutionResult

type TxExecutionResult struct {
	Height    uint64 `json:"height"`
	BlockHash []byte `json:"blockhash"`
	Index     uint64 `json:"index"`
}

func (*TxExecutionResult) FromBytes

func (i *TxExecutionResult) FromBytes(data []byte) error

func (*TxExecutionResult) ToBytes

func (i *TxExecutionResult) ToBytes() ([]byte, error)

type TxInPool

type TxInPool struct {
	Counter int64 // a simple incrementing counter
	Height  int64 // height that this tx had been validated in
	Tx      Tx
}

A transaction that successfully ran

func (*TxInPool) GetHeight

func (memTx *TxInPool) GetHeight() int64

type TxPool

type TxPool interface {
	Lock()
	Unlock()
	Reap(count int) []Tx
	ReceiveTx(tx Tx) error
	Update(height int64, txs []Tx)
	Size() int
	TxsFrontWait() *clist.CElement
	Flush()
	RegisterFilter(filter IFilter)
	GetPendingMaxNonce([]byte) (uint64, error)
}

type TxPoolApplication

type TxPoolApplication interface {
	Application
	GetTxPool() TxPool
}

type TxpoolFilter

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

func NewTxpoolFilter

func NewTxpoolFilter(f func([]byte) (bool, error)) TxpoolFilter

func (TxpoolFilter) CheckTx

func (m TxpoolFilter) CheckTx(tx Tx) (bool, error)

type Txs

type Txs []Tx

func (Txs) Hash

func (txs Txs) Hash() []byte

func (Txs) ToBytes

func (txs Txs) ToBytes() [][]byte

type Validator

type Validator struct {
	Address     []byte        `json:"address"`
	PubKey      crypto.PubKey `json:"pub_key"`
	VotingPower int64         `json:"voting_power"`
	Accum       int64         `json:"accum"`
	IsCA        bool          `json:"is_ca"`
}

Volatile state for each Validator TODO: make non-volatile identity

  • Remove Accum - it can be computed, and now valset becomes identifying

func NewValidator

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

func (*Validator) CompareAccum

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

Returns the one with higher Accum.

func (*Validator) Copy

func (v *Validator) Copy() *Validator

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

func (*Validator) String

func (v *Validator) String() string

type ValidatorAttr

type ValidatorAttr struct {
	PubKey []byte       `json:"pubKey,omitempty"` //hex of pubkey;
	Power  int64        `json:"power,omitempty"`
	Cmd    ValidatorCmd `json:"cmd"`
	Addr   []byte       `json:"addr"`
	Nonce  uint64       `json:"nonce"`
}

func (*ValidatorAttr) GetIsCA

func (m *ValidatorAttr) GetIsCA() bool

func (*ValidatorAttr) GetPower

func (m *ValidatorAttr) GetPower() int64

func (*ValidatorAttr) GetPubKey

func (m *ValidatorAttr) GetPubKey() []byte

func (*ValidatorAttr) Reset

func (m *ValidatorAttr) Reset()

func (*ValidatorAttr) String

func (m *ValidatorAttr) String() string

type ValidatorCmd

type ValidatorCmd string
const (
	ValidatorCmdAddPeer    ValidatorCmd = "add_peer"
	ValidatorCmdUpdateNode ValidatorCmd = "update_node"
	ValidatorCmdRemoveNode ValidatorCmd = "remove_node"
)

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: move valset into an iavl tree where key is 'blockbonded|pubkey'

func NewValidatorSet

func NewValidatorSet(vals []*Validator) *ValidatorSet

func (*ValidatorSet) Add

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

func (valSet *ValidatorSet) IncrementAccum(times int64)

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

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

func (*ValidatorSet) VerifyCommit

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

type ValueHistoryResult struct {
	Key                  []byte                `json:"key"`
	ValueUpdateHistories []*ValueUpdateHistory `json:"value_update_histories"`
	Total                uint32                `json:"total"`
}

type ValueUpdateHistory added in v1.5.0

type ValueUpdateHistory struct {
	TxHash      []byte `json:"tx_hash"`
	BlockHeight uint64 `json:"block_height"`
	TimeStamp   uint64 `json:"time_stamp"`
	Value       []byte `json:"value"`
	TxIndex     uint32 `json:"tx_index"`
}

func (*ValueUpdateHistory) String added in v1.5.0

func (v *ValueUpdateHistory) String() string

type Vote

type Vote struct {
	ValidatorAddress []byte           `json:"validator_address"`
	ValidatorIndex   int              `json:"validator_index"`
	Height           int64            `json:"height"`
	Round            int64            `json:"round"`
	Type             byte             `json:"type"`
	BlockID          BlockID          `json:"block_id"` // zero if vote is nil.
	Signature        crypto.Signature `json:"signature"`
}

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

func (*Vote) Copy

func (vote *Vote) Copy() *Vote

func (*Vote) String

func (vote *Vote) String() string

func (*Vote) WriteSignBytes

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

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.

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 int64, round int64, type_ byte, valSet *ValidatorSet) *VoteSet

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)

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

func (*VoteSet) BitArray

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

func (*VoteSet) BitArrayByBlockID

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

func (*VoteSet) ChainID

func (voteSet *VoteSet) ChainID() string

func (*VoteSet) GetByAddress

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

func (*VoteSet) GetByIndex

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

NOTE: if validator has conflicting votes, returns "canonical" vote

func (*VoteSet) HasAll

func (voteSet *VoteSet) HasAll() bool

func (*VoteSet) HasTwoThirdsAny

func (voteSet *VoteSet) HasTwoThirdsAny() bool

func (*VoteSet) HasTwoThirdsMajority

func (voteSet *VoteSet) HasTwoThirdsMajority() bool

func (*VoteSet) Height

func (voteSet *VoteSet) Height() int64

func (*VoteSet) IsCommit

func (voteSet *VoteSet) IsCommit() bool

func (*VoteSet) MakeCommit

func (voteSet *VoteSet) MakeCommit() *Commit

func (*VoteSet) Round

func (voteSet *VoteSet) Round() int64

func (*VoteSet) SetPeerMaj23

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

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

func (*VoteSet) String

func (voteSet *VoteSet) String() string

func (*VoteSet) StringIndented

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

func (*VoteSet) StringShort

func (voteSet *VoteSet) StringShort() string

func (*VoteSet) TwoThirdsMajority

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

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 VoteSetReader

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

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