types

package
v0.0.0-...-7c12c5a Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2015 License: GPL-2.0, GPL-3.0 Imports: 23 Imported by: 0

README

tendermint/block

Block

TODO: document

Header
Validation
Data

PartSet

PartSet is used to split a byteslice of data into parts (pieces) for transmission. By splitting data into smaller parts and computing a Merkle root hash on the list, you can verify that a part is legitimately part of the complete data, and the part can be forwarded to other peers before all the parts are known. In short, it's a fast way to propagate a large file over a gossip network.

PartSet was inspired by the LibSwift project.

Usage:

data := RandBytes(2 << 20) // Something large

partSet := NewPartSetFromData(data)
partSet.Total()     // Total number of 4KB parts
partSet.Count()     // Equal to the Total, since we already have all the parts
partSet.Hash()      // The Merkle root hash
partSet.BitArray()  // A BitArray of partSet.Total() 1's

header := partSet.Header() // Send this to the peer
header.Total        // Total number of parts
header.Hash         // The merkle root hash

// Now we'll reconstruct the data from the parts
partSet2 := NewPartSetFromHeader(header)
partSet2.Total()    // Same total as partSet.Total()
partSet2.Count()    // Zero, since this PartSet doesn't have any parts yet.
partSet2.Hash()     // Same hash as in partSet.Hash()
partSet2.BitArray() // A BitArray of partSet.Total() 0's

// In a gossip network the parts would arrive in arbitrary order, perhaps
// in response to explicit requests for parts, or optimistically in response
// to the receiving peer's partSet.BitArray().
for !partSet2.IsComplete() {
    part := receivePartFromGossipNetwork()
    added, err := partSet2.AddPart(part)
    if err != nil {
		// A wrong part,
        // the merkle trail does not hash to partSet2.Hash()
    } else if !added {
        // A duplicate part already received
    }
}

data2, _ := ioutil.ReadAll(partSet2.GetReader())
bytes.Equal(data, data2) // true

Documentation

Index

Constants

View Source
const (
	EventDataTypeNewBlock = byte(0x01)
	EventDataTypeFork     = byte(0x02)
	EventDataTypeTx       = byte(0x03)
	EventDataTypeCall     = byte(0x04)
	EventDataTypeLog      = byte(0x05)

	EventDataTypeRoundState = byte(0x11)
	EventDataTypeVote       = byte(0x12)
)
View Source
const (
	// Account transactions
	TxTypeSend = byte(0x01)
	TxTypeCall = byte(0x02)
	TxTypeName = byte(0x03)

	// Validation transactions
	TxTypeBond    = byte(0x11)
	TxTypeUnbond  = byte(0x12)
	TxTypeRebond  = byte(0x13)
	TxTypeDupeout = byte(0x14)

	// Admin transactions
	TxTypePermissions = byte(0x20)
)

Types of Tx implementations

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

Types of votes

Variables

View Source
var (
	PeerStateKey     = "ConsensusReactor.peerState"
	PeerMempoolChKey = "MempoolReactor.peerMempoolCh"
)
View Source
var (
	MinNameRegistrationPeriod int = 5

	// cost for storing a name for a block is
	// CostPerBlock*CostPerByte*(len(data) + 32)
	NameByteCostMultiplier  int64 = 1
	NameBlockCostMultiplier int64 = 1

	MaxNameLength = 64
	MaxDataLength = 1 << 16
)
View Source
var (
	ErrPartSetUnexpectedIndex = errors.New("Error part set unexpected index")
	ErrPartSetInvalidProof    = errors.New("Error part set invalid proof")
)
View Source
var (
	ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
	ErrInvalidBlockPartHash      = errors.New("Error invalid block part hash")
)
View Source
var (
	ErrTxInvalidAddress       = errors.New("Error invalid address")
	ErrTxDuplicateAddress     = errors.New("Error duplicate address")
	ErrTxInvalidAmount        = errors.New("Error invalid amount")
	ErrTxInsufficientFunds    = errors.New("Error insufficient funds")
	ErrTxInsufficientGasPrice = errors.New("Error insufficient gas price")
	ErrTxUnknownPubKey        = errors.New("Error unknown pubkey")
	ErrTxInvalidPubKey        = errors.New("Error invalid pubkey")
	ErrTxInvalidSignature     = errors.New("Error invalid signature")
	ErrTxPermissionDenied     = errors.New("Error permission denied")
)
View Source
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")
)
View Source
var ValidatorCodec = validatorCodec{}
View Source
var ValidatorInfoCodec = wire.Codec{
	Encode: ValidatorInfoEncoder,
	Decode: ValidatorInfoDecoder,
}

Functions

func EventStringAccCall

func EventStringAccCall(addr []byte) string

func EventStringAccInput

func EventStringAccInput(addr []byte) string

func EventStringAccOutput

func EventStringAccOutput(addr []byte) string

func EventStringBond

func EventStringBond() string

func EventStringCompleteProposal

func EventStringCompleteProposal() string

func EventStringDupeout

func EventStringDupeout() string

func EventStringFork

func EventStringFork() string

func EventStringLock

func EventStringLock() string

func EventStringLogEvent

func EventStringLogEvent(addr []byte) string

func EventStringNameReg

func EventStringNameReg(name string) string

func EventStringNewBlock

func EventStringNewBlock() string

func EventStringNewRound

func EventStringNewRound() string

func EventStringPermissions

func EventStringPermissions(name string) string

func EventStringPolka

func EventStringPolka() string

func EventStringRebond

func EventStringRebond() string

func EventStringRelock

func EventStringRelock() string

func EventStringTimeoutPropose

func EventStringTimeoutPropose() string

func EventStringTimeoutWait

func EventStringTimeoutWait() string

func EventStringUnbond

func EventStringUnbond() string

func EventStringUnlock

func EventStringUnlock() string

func EventStringVote

func EventStringVote() string

func NameBaseCost

func NameBaseCost(name, data string) int64

base cost is "effective" number of bytes

func NameCostPerBlock

func NameCostPerBlock(baseCost int64) int64

func NewContractAddress

func NewContractAddress(caller []byte, nonce int) []byte

func RandValidator

func RandValidator(randBonded bool, minBonded int64) (*ValidatorInfo, *Validator, *PrivValidator)

func TxID

func TxID(chainID string, tx Tx) []byte

This should match the leaf hashes of Block.Data.Hash()'s SimpleMerkleTree.

func ValidatorInfoDecoder

func ValidatorInfoDecoder(r io.Reader, n *int64, err *error) interface{}

func ValidatorInfoEncoder

func ValidatorInfoEncoder(o interface{}, w io.Writer, n *int64, err *error)

Types

type AccountGetter

type AccountGetter interface {
	GetAccount(addr []byte) *acm.Account
}

type Block

type Block struct {
	*Header        `json:"header"`
	*Data          `json:"data"`
	LastValidation *Validation `json:"last_validation"`
}

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 (e.g. missing Header.StateHash) then the hash is nil, to prevent the usage of that hash.

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() *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) ValidateBasic

func (b *Block) ValidateBasic(chainID string, lastBlockHeight int, lastBlockHash []byte,
	lastBlockParts PartSetHeader, lastBlockTime time.Time) error

Basic validation that doesn't involve state data.

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 BondTx

type BondTx struct {
	PubKey    acm.PubKeyEd25519    `json:"pub_key"`
	Signature acm.SignatureEd25519 `json:"signature"`
	Inputs    []*TxInput           `json:"inputs"`
	UnbondTo  []*TxOutput          `json:"unbond_to"`
}

func NewBondTx

func NewBondTx(pubkey acm.PubKey) (*BondTx, error)

func (*BondTx) AddInput

func (tx *BondTx) AddInput(st AccountGetter, pubkey acm.PubKey, amt int64) error

func (*BondTx) AddInputWithNonce

func (tx *BondTx) AddInputWithNonce(pubkey acm.PubKey, amt int64, nonce int) error

func (*BondTx) AddOutput

func (tx *BondTx) AddOutput(addr []byte, amt int64) error

func (*BondTx) SignBond

func (tx *BondTx) SignBond(chainID string, privAccount *acm.PrivAccount) error

func (*BondTx) SignInput

func (tx *BondTx) SignInput(chainID string, i int, privAccount *acm.PrivAccount) error

func (*BondTx) String

func (tx *BondTx) String() string

func (*BondTx) WriteSignBytes

func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error)

type CallData

type CallData struct {
	Caller []byte `json:"caller"`
	Callee []byte `json:"callee"`
	Data   []byte `json:"data"`
	Value  int64  `json:"value"`
	Gas    int64  `json:"gas"`
}

type CallTx

type CallTx struct {
	Input    *TxInput `json:"input"`
	Address  []byte   `json:"address"`
	GasLimit int64    `json:"gas_limit"`
	Fee      int64    `json:"fee"`
	Data     []byte   `json:"data"`
}

func NewCallTx

func NewCallTx(st AccountGetter, from acm.PubKey, to, data []byte, amt, gasLimit, fee int64) (*CallTx, error)

func NewCallTxWithNonce

func NewCallTxWithNonce(from acm.PubKey, to, data []byte, amt, gasLimit, fee int64, nonce int) *CallTx

func (*CallTx) Sign

func (tx *CallTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*CallTx) String

func (tx *CallTx) String() string

func (*CallTx) WriteSignBytes

func (tx *CallTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error)

type Data

type Data struct {
	Txs []Tx `json:"txs"`
	// contains filtered or unexported fields
}

func (*Data) Hash

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

func (*Data) StringIndented

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

type DupeoutTx

type DupeoutTx struct {
	Address []byte `json:"address"`
	VoteA   Vote   `json:"vote_a"`
	VoteB   Vote   `json:"vote_b"`
}

func (*DupeoutTx) String

func (tx *DupeoutTx) String() string

func (*DupeoutTx) WriteSignBytes

func (tx *DupeoutTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error)

type ErrTxInvalidSequence

type ErrTxInvalidSequence struct {
	Got      int
	Expected int
}

func (ErrTxInvalidSequence) Error

func (e ErrTxInvalidSequence) Error() string

type ErrTxInvalidString

type ErrTxInvalidString struct {
	Msg string
}

func (ErrTxInvalidString) Error

func (e ErrTxInvalidString) Error() string

type ErrVoteConflictingSignature

type ErrVoteConflictingSignature struct {
	VoteA *Vote
	VoteB *Vote
}

func (*ErrVoteConflictingSignature) Error

func (err *ErrVoteConflictingSignature) Error() string

type EventData

type EventData interface {
	AssertIsEventData()
}

type EventDataCall

type EventDataCall struct {
	CallData  *CallData `json:"call_data"`
	Origin    []byte    `json:"origin"`
	TxID      []byte    `json:"tx_id"`
	Return    []byte    `json:"return"`
	Exception string    `json:"exception"`
}

EventDataCall fires when we call a contract, and when a contract calls another contract

func (EventDataCall) AssertIsEventData

func (_ EventDataCall) AssertIsEventData()

type EventDataLog

type EventDataLog struct {
	Address Word256   `json:"address"`
	Topics  []Word256 `json:"topics"`
	Data    []byte    `json:"data"`
	Height  int64     `json:"height"`
}

EventDataLog fires when a contract executes the LOG opcode

func (EventDataLog) AssertIsEventData

func (_ EventDataLog) AssertIsEventData()

type EventDataNewBlock

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

func (EventDataNewBlock) AssertIsEventData

func (_ EventDataNewBlock) AssertIsEventData()

type EventDataRoundState

type EventDataRoundState struct {
	CurrentTime time.Time `json:"current_time"`

	Height        int       `json:"height"`
	Round         int       `json:"round"`
	Step          string    `json:"step"`
	StartTime     time.Time `json:"start_time"`
	CommitTime    time.Time `json:"commit_time"`
	Proposal      *Proposal `json:"proposal"`
	ProposalBlock *Block    `json:"proposal_block"`
	LockedRound   int       `json:"locked_round"`
	LockedBlock   *Block    `json:"locked_block"`
	POLRound      int       `json:"pol_round"`
}

We fire the most recent round state that led to the event (ie. NewRound will have the previous rounds state)

func (EventDataRoundState) AssertIsEventData

func (_ EventDataRoundState) AssertIsEventData()

type EventDataTx

type EventDataTx struct {
	Tx        Tx     `json:"tx"`
	Return    []byte `json:"return"`
	Exception string `json:"exception"`
}

All txs fire EventDataTx, but only CallTx might have Return or Exception

func (EventDataTx) AssertIsEventData

func (_ EventDataTx) AssertIsEventData()

type EventDataVote

type EventDataVote struct {
	Index   int
	Address []byte
	Vote    *Vote
}

func (EventDataVote) AssertIsEventData

func (_ EventDataVote) AssertIsEventData()
type Header struct {
	ChainID            string        `json:"chain_id"`
	Height             int           `json:"height"`
	Time               time.Time     `json:"time"`
	Fees               int64         `json:"fees"`
	NumTxs             int           `json:"num_txs"`
	LastBlockHash      []byte        `json:"last_block_hash"`
	LastBlockParts     PartSetHeader `json:"last_block_parts"`
	LastValidationHash []byte        `json:"last_validation_hash"`
	DataHash           []byte        `json:"data_hash"`
	StateHash          []byte        `json:"state_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 NameRegEntry

type NameRegEntry struct {
	Name    string `json:"name"`    // registered name for the entry
	Owner   []byte `json:"owner"`   // address that created the entry
	Data    string `json:"data"`    // data to store under this name
	Expires int    `json:"expires"` // block at which this entry expires
}

func (*NameRegEntry) Copy

func (entry *NameRegEntry) Copy() *NameRegEntry

type NameTx

type NameTx struct {
	Input *TxInput `json:"input"`
	Name  string   `json:"name"`
	Data  string   `json:"data"`
	Fee   int64    `json:"fee"`
}

func NewNameTx

func NewNameTx(st AccountGetter, from acm.PubKey, name, data string, amt, fee int64) (*NameTx, error)

func NewNameTxWithNonce

func NewNameTxWithNonce(from acm.PubKey, name, data string, amt, fee int64, nonce int) *NameTx

func (*NameTx) Sign

func (tx *NameTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*NameTx) String

func (tx *NameTx) String() string

func (*NameTx) ValidateStrings

func (tx *NameTx) ValidateStrings() error

func (*NameTx) WriteSignBytes

func (tx *NameTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error)

type NodeInfo

type NodeInfo struct {
	PubKey  acm.PubKeyEd25519 `json:"pub_key"`
	Moniker string            `json:"moniker"`
	ChainID string            `json:"chain_id"`
	Host    string            `json:"host"`
	P2PPort uint16            `json:"p2p_port"`
	RPCPort uint16            `json:"rpc_port"`

	Version Versions `json:"versions"`
}

func (*NodeInfo) CompatibleWith

func (ni *NodeInfo) CompatibleWith(no *NodeInfo) error

CONTRACT: two nodes with the same Tendermint major and minor version and with the same ChainID are compatible

type Part

type Part struct {
	Proof merkle.SimpleProof `json:"proof"`
	Bytes []byte             `json:"bytes"`
	// 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) *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) (bool, error)

func (*PartSet) BitArray

func (ps *PartSet) BitArray() *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 *int64, err *error)

type PermissionsTx

type PermissionsTx struct {
	Input    *TxInput        `json:"input"`
	PermArgs ptypes.PermArgs `json:"args"`
}

func NewPermissionsTx

func NewPermissionsTx(st AccountGetter, from acm.PubKey, args ptypes.PermArgs) (*PermissionsTx, error)

func NewPermissionsTxWithNonce

func NewPermissionsTxWithNonce(from acm.PubKey, args ptypes.PermArgs, nonce int) *PermissionsTx

func (*PermissionsTx) Sign

func (tx *PermissionsTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*PermissionsTx) String

func (tx *PermissionsTx) String() string

func (*PermissionsTx) WriteSignBytes

func (tx *PermissionsTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error)

type PrivValidator

type PrivValidator struct {
	Address    []byte             `json:"address"`
	PubKey     acm.PubKeyEd25519  `json:"pub_key"`
	PrivKey    acm.PrivKeyEd25519 `json:"priv_key"`
	LastHeight int                `json:"last_height"`
	LastRound  int                `json:"last_round"`
	LastStep   int8               `json:"last_step"`
	// contains filtered or unexported fields
}

func GenPrivValidator

func GenPrivValidator() *PrivValidator

Generates a new validator with private key.

func LoadOrGenPrivValidator

func LoadOrGenPrivValidator(filePath string) *PrivValidator

func LoadPrivValidator

func LoadPrivValidator(filePath string) *PrivValidator

func (*PrivValidator) Save

func (privVal *PrivValidator) Save()

func (*PrivValidator) SetFile

func (privVal *PrivValidator) SetFile(filePath string)

func (*PrivValidator) SignProposal

func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) error

func (*PrivValidator) SignRebondTx

func (privVal *PrivValidator) SignRebondTx(chainID string, rebondTx *RebondTx) error

func (*PrivValidator) SignVote

func (privVal *PrivValidator) SignVote(chainID string, vote *Vote) error

func (*PrivValidator) SignVoteUnsafe

func (privVal *PrivValidator) SignVoteUnsafe(chainID string, vote *Vote)

func (*PrivValidator) String

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        acm.SignatureEd25519 `json:"signature"`
}

func NewProposal

func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int) *Proposal

func (*Proposal) String

func (p *Proposal) String() string

func (*Proposal) WriteSignBytes

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

type RebondTx

type RebondTx struct {
	Address   []byte               `json:"address"`
	Height    int                  `json:"height"`
	Signature acm.SignatureEd25519 `json:"signature"`
}

func NewRebondTx

func NewRebondTx(addr []byte, height int) *RebondTx

func (*RebondTx) Sign

func (tx *RebondTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*RebondTx) String

func (tx *RebondTx) String() string

func (*RebondTx) WriteSignBytes

func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error)

type SendTx

type SendTx struct {
	Inputs  []*TxInput  `json:"inputs"`
	Outputs []*TxOutput `json:"outputs"`
}

func NewSendTx

func NewSendTx() *SendTx

func (*SendTx) AddInput

func (tx *SendTx) AddInput(st AccountGetter, pubkey acm.PubKey, amt int64) error

func (*SendTx) AddInputWithNonce

func (tx *SendTx) AddInputWithNonce(pubkey acm.PubKey, amt int64, nonce int) error

func (*SendTx) AddOutput

func (tx *SendTx) AddOutput(addr []byte, amt int64) error

func (*SendTx) SignInput

func (tx *SendTx) SignInput(chainID string, i int, privAccount *acm.PrivAccount) error

func (*SendTx) String

func (tx *SendTx) String() string

func (*SendTx) WriteSignBytes

func (tx *SendTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error)

type Tx

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

type TxInput

type TxInput struct {
	Address   []byte        `json:"address"`   // Hash of the PubKey
	Amount    int64         `json:"amount"`    // Must not exceed account balance
	Sequence  int           `json:"sequence"`  // Must be 1 greater than the last committed TxInput
	Signature acm.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx
	PubKey    acm.PubKey    `json:"pub_key"`   // Must not be nil, may be nil
}

func (*TxInput) String

func (txIn *TxInput) String() string

func (*TxInput) ValidateBasic

func (txIn *TxInput) ValidateBasic() error

func (*TxInput) WriteSignBytes

func (txIn *TxInput) WriteSignBytes(w io.Writer, n *int64, err *error)

type TxOutput

type TxOutput struct {
	Address []byte `json:"address"` // Hash of the PubKey
	Amount  int64  `json:"amount"`  // The sum of all outputs must not exceed the inputs.
}

func (*TxOutput) String

func (txOut *TxOutput) String() string

func (*TxOutput) ValidateBasic

func (txOut *TxOutput) ValidateBasic() error

func (*TxOutput) WriteSignBytes

func (txOut *TxOutput) WriteSignBytes(w io.Writer, n *int64, err *error)

type UnbondTx

type UnbondTx struct {
	Address   []byte               `json:"address"`
	Height    int                  `json:"height"`
	Signature acm.SignatureEd25519 `json:"signature"`
}

func NewUnbondTx

func NewUnbondTx(addr []byte, height int) *UnbondTx

func (*UnbondTx) Sign

func (tx *UnbondTx) Sign(chainID string, privAccount *acm.PrivAccount)

func (*UnbondTx) String

func (tx *UnbondTx) String() string

func (*UnbondTx) WriteSignBytes

func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error)

type Validation

type Validation 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: Validation is empty for height 1, but never nil.

func (*Validation) BitArray

func (v *Validation) BitArray() *BitArray

func (*Validation) FirstPrecommit

func (v *Validation) FirstPrecommit() *Vote

func (*Validation) GetByIndex

func (v *Validation) GetByIndex(index int) *Vote

func (*Validation) Hash

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

func (*Validation) Height

func (v *Validation) Height() int

func (*Validation) IsCommit

func (v *Validation) IsCommit() bool

func (*Validation) Round

func (v *Validation) Round() int

func (*Validation) Size

func (v *Validation) Size() int

func (*Validation) StringIndented

func (v *Validation) StringIndented(indent string) string

func (*Validation) Type

func (v *Validation) Type() byte

func (*Validation) ValidateBasic

func (v *Validation) ValidateBasic() error

type Validator

type Validator struct {
	Address          []byte            `json:"address"`
	PubKey           acm.PubKeyEd25519 `json:"pub_key"`
	BondHeight       int               `json:"bond_height"`
	UnbondHeight     int               `json:"unbond_height"`
	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

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 ValidatorInfo

type ValidatorInfo struct {
	Address         []byte            `json:"address"`
	PubKey          acm.PubKeyEd25519 `json:"pub_key"`
	UnbondTo        []*TxOutput       `json:"unbond_to"`
	FirstBondHeight int               `json:"first_bond_height"`
	FirstBondAmount int64             `json:"first_bond_amount"`
	DestroyedHeight int               `json:"destroyed_height"` // If destroyed
	DestroyedAmount int64             `json:"destroyed_amount"` // If destroyed
	ReleasedHeight  int               `json:"released_height"`  // If released
}

Persistent (mostly) static data for each Validator

func (*ValidatorInfo) Copy

func (valInfo *ValidatorInfo) Copy() *ValidatorInfo

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

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

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

func (*ValidatorSet) VerifyValidation

func (valSet *ValidatorSet) VerifyValidation(chainID string,
	hash []byte, parts PartSetHeader, height int, v *Validation) 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 Versions

type Versions struct {
	Revision   string `json:"revision"`
	Tendermint string `json:"tendermint"`
	P2P        string `json:"p2p"`
	RPC        string `json:"rpc"`
	Wire       string `json:"wire"`
}

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        acm.SignatureEd25519 `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 *int64, 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. 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

func NewVoteSet(height int, round int, type_ byte, valSet *ValidatorSet) *VoteSet

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

func (*VoteSet) AddByAddress

func (voteSet *VoteSet) AddByAddress(address []byte, vote *Vote) (added bool, index int, 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) AddByIndex

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

func (voteSet *VoteSet) BitArray() *BitArray

func (*VoteSet) GetByAddress

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

func (*VoteSet) GetByIndex

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

func (*VoteSet) HasTwoThirdsAny

func (voteSet *VoteSet) HasTwoThirdsAny() bool

func (*VoteSet) HasTwoThirdsMajority

func (voteSet *VoteSet) HasTwoThirdsMajority() bool

func (*VoteSet) Height

func (voteSet *VoteSet) Height() int

func (*VoteSet) IsCommit

func (voteSet *VoteSet) IsCommit() bool

func (*VoteSet) MakeValidation

func (voteSet *VoteSet) MakeValidation() *Validation

func (*VoteSet) Round

func (voteSet *VoteSet) Round() int

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

func (*VoteSet) Type

func (voteSet *VoteSet) Type() byte

type VoteSetReader

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

Common interface between *consensus.VoteSet and types.Validation

Jump to

Keyboard shortcuts

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