state

package
v3.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetricsSubsystem is a subsystem shared by all metrics exposed by this
	// package.
	MetricsSubsystem = "state"
)

Variables

This section is empty.

Functions

func ExecCommitBlock added in v0.9.1

func ExecCommitBlock(
	appConnConsensus proxy.AppConnConsensus,
	block *types.Block,
	logger log.Logger,
	lastValSet *types.ValidatorSet,
	stateDB dbm.DB,
) ([]byte, error)

ExecCommitBlock executes and commits a block on the proxyApp without validating or mutating the state. It returns the application root hash (result of abci.Commit).

func LoadConsensusParams added in v0.15.0

func LoadConsensusParams(db dbm.DB, height int64) (types.ConsensusParams, error)

LoadConsensusParams loads the ConsensusParams for a given height.

func LoadValidators added in v0.15.0

func LoadValidators(db dbm.DB, height int64) (*types.ValidatorSet, error)

LoadValidators loads the ValidatorSet for a given height. Returns ErrNoValSetForHeight if the validator set can't be found for this height.

func MakeGenesisDocFromFile added in v0.11.0

func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error)

MakeGenesisDocFromFile reads and unmarshals genesis doc from the given file.

func MedianTime added in v0.24.0

func MedianTime(commit *types.Commit, validators *types.ValidatorSet) time.Time

MedianTime computes a median time for a given Commit (based on Timestamp field of votes messages) and the corresponding validator set. The computed time is always between timestamps of the votes sent by honest processes, i.e., a faulty processes can not arbitrarily increase or decrease the computed value.

func SaveState added in v0.15.0

func SaveState(db dbm.DB, state State)

SaveState persists the State, the ValidatorsInfo, and the ConsensusParamsInfo to the database. This flushes the writes (e.g. calls SetSync).

func TxPostCheck added in v0.26.1

func TxPostCheck(state State) mempl.PostCheckFunc

TxPostCheck returns a function to filter transactions after processing. The function limits the gas wanted by a transaction to the block's maximum total gas.

func TxPreCheck added in v0.26.1

func TxPreCheck(state State) mempl.PreCheckFunc

TxPreCheck returns a function to filter transactions before processing. The function limits the size of a transaction to the block's maximum data size.

func VerifyEvidence added in v0.15.0

func VerifyEvidence(stateDB dbm.DB, state State, evidence types.Evidence) error

VerifyEvidence verifies the evidence fully by checking: - it is sufficiently recent (MaxAge) - it is from a key who was a validator at the given height - it is internally consistent - it was properly signed by the alleged equivocator

Types

type ABCIResponses added in v0.9.1

type ABCIResponses struct {
	DeliverTx  []*abci.ResponseDeliverTx
	EndBlock   *abci.ResponseEndBlock
	BeginBlock *abci.ResponseBeginBlock
}

ABCIResponses retains the responses of the various ABCI calls during block processing. It is persisted to disk for each height before calling Commit.

func LoadABCIResponses added in v0.15.0

func LoadABCIResponses(db dbm.DB, height int64) (*ABCIResponses, error)

LoadABCIResponses loads the ABCIResponses for the given height from the database. This is useful for recovering from crashes where we called app.Commit and before we called s.Save(). It can also be used to produce Merkle proofs of the result of txs.

func NewABCIResponses added in v0.9.1

func NewABCIResponses(block *types.Block) *ABCIResponses

NewABCIResponses returns a new ABCIResponses

func (*ABCIResponses) Bytes added in v0.9.1

func (arz *ABCIResponses) Bytes() []byte

Bytes serializes the ABCIResponse using go-amino.

func (*ABCIResponses) ResultsHash added in v0.15.0

func (arz *ABCIResponses) ResultsHash() []byte

type BlockExecutor added in v0.15.0

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

BlockExecutor provides the context and accessories for properly executing a block.

func NewBlockExecutor added in v0.15.0

func NewBlockExecutor(db dbm.DB, logger log.Logger, proxyApp proxy.AppConnConsensus, mempool Mempool, evpool EvidencePool, options ...BlockExecutorOption) *BlockExecutor

NewBlockExecutor returns a new BlockExecutor with a NopEventBus. Call SetEventBus to provide one.

func (*BlockExecutor) ApplyBlock added in v0.15.0

func (blockExec *BlockExecutor) ApplyBlock(state State, blockID types.BlockID, block *types.Block) (State, error)

ApplyBlock validates the block against the state, executes it against the app, fires the relevant events, commits the app, and saves the new state and responses. It's the only function that needs to be called from outside this package to process and commit an entire block. It takes a blockID to avoid recomputing the parts hash.

func (*BlockExecutor) Commit added in v0.15.0

func (blockExec *BlockExecutor) Commit(
	state State,
	block *types.Block,
) ([]byte, error)

Commit locks the mempool, runs the ABCI Commit message, and updates the mempool. It returns the result of calling abci.Commit (the AppHash), and an error. The Mempool must be locked during commit and update because state is typically reset on Commit and old txs must be replayed against committed state before new txs are run in the mempool, lest they be invalid.

func (*BlockExecutor) CreateProposalBlock

func (blockExec *BlockExecutor) CreateProposalBlock(
	height int64,
	state State, commit *types.Commit,
	proposerAddr []byte,
) (*types.Block, *types.PartSet)

CreateProposalBlock calls state.MakeBlock with evidence from the evpool and txs from the mempool. The max bytes must be big enough to fit the commit. Up to 1/10th of the block space is allcoated for maximum sized evidence. The rest is given to txs, up to the max gas.

func (*BlockExecutor) SetEventBus added in v0.15.0

func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher)

SetEventBus - sets the event bus for publishing block related events. If not called, it defaults to types.NopEventBus.

func (*BlockExecutor) ValidateBlock added in v0.15.0

func (blockExec *BlockExecutor) ValidateBlock(state State, block *types.Block) error

ValidateBlock validates the given block against the given state. If the block is invalid, it returns an error. Validation does not mutate state, but does require historical information from the stateDB, ie. to verify evidence from a validator at an old height.

type BlockExecutorOption added in v0.26.0

type BlockExecutorOption func(executor *BlockExecutor)

func BlockExecutorWithMetrics added in v0.26.0

func BlockExecutorWithMetrics(metrics *Metrics) BlockExecutorOption

type BlockStore added in v0.8.0

type BlockStore interface {
	BlockStoreRPC
	SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
}

BlockStore defines the BlockStore interface used by the ConsensusState.

type BlockStoreRPC added in v0.19.9

type BlockStoreRPC interface {
	Height() int64

	LoadBlockMeta(height int64) *types.BlockMeta
	LoadBlock(height int64) *types.Block
	LoadBlockPart(height int64, index int) *types.Part

	LoadBlockCommit(height int64) *types.Commit
	LoadSeenCommit(height int64) *types.Commit
}

BlockStoreRPC is the block store interface used by the RPC.

type ConsensusParamsInfo added in v0.15.0

type ConsensusParamsInfo struct {
	ConsensusParams   types.ConsensusParams
	LastHeightChanged int64
}

ConsensusParamsInfo represents the latest consensus params, or the last height it changed

func (ConsensusParamsInfo) Bytes added in v0.15.0

func (params ConsensusParamsInfo) Bytes() []byte

Bytes serializes the ConsensusParamsInfo using go-amino.

type ErrAppBlockHeightTooHigh added in v0.8.0

type ErrAppBlockHeightTooHigh struct {
	CoreHeight int64
	AppHeight  int64
}

func (ErrAppBlockHeightTooHigh) Error added in v0.8.0

func (e ErrAppBlockHeightTooHigh) Error() string

type ErrBlockHashMismatch added in v0.8.0

type ErrBlockHashMismatch struct {
	CoreHash []byte
	AppHash  []byte
	Height   int64
}

func (ErrBlockHashMismatch) Error added in v0.8.0

func (e ErrBlockHashMismatch) Error() string

type ErrInvalidBlock added in v0.8.0

type ErrInvalidBlock error

type ErrLastStateMismatch added in v0.8.0

type ErrLastStateMismatch struct {
	Height int64
	Core   []byte
	App    []byte
}

func (ErrLastStateMismatch) Error added in v0.8.0

func (e ErrLastStateMismatch) Error() string

type ErrNoABCIResponsesForHeight added in v0.15.0

type ErrNoABCIResponsesForHeight struct {
	Height int64
}

func (ErrNoABCIResponsesForHeight) Error added in v0.15.0

type ErrNoConsensusParamsForHeight added in v0.15.0

type ErrNoConsensusParamsForHeight struct {
	Height int64
}

func (ErrNoConsensusParamsForHeight) Error added in v0.15.0

type ErrNoValSetForHeight added in v0.11.0

type ErrNoValSetForHeight struct {
	Height int64
}

func (ErrNoValSetForHeight) Error added in v0.11.0

func (e ErrNoValSetForHeight) Error() string

type ErrProxyAppConn added in v0.8.0

type ErrProxyAppConn error

type ErrStateMismatch added in v0.8.0

type ErrStateMismatch struct {
	Got      *State
	Expected *State
}

func (ErrStateMismatch) Error added in v0.8.0

func (e ErrStateMismatch) Error() string

type ErrUnknownBlock added in v0.8.0

type ErrUnknownBlock struct {
	Height int64
}

func (ErrUnknownBlock) Error added in v0.8.0

func (e ErrUnknownBlock) Error() string

type EvidencePool added in v0.19.9

type EvidencePool interface {
	PendingEvidence(int64) []types.Evidence
	AddEvidence(types.Evidence) error
	Update(*types.Block, State)
	// IsCommitted indicates if this evidence was already marked committed in another block.
	IsCommitted(types.Evidence) bool
}

EvidencePool defines the EvidencePool interface used by the ConsensusState. Get/Set/Commit

type Mempool added in v0.8.0

type Mempool interface {
	Lock()
	Unlock()

	Size() int
	CheckTx(types.Tx, func(*abci.Response)) error
	CheckTxWithInfo(types.Tx, func(*abci.Response), mempool.TxInfo) error
	ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs
	Update(int64, types.Txs, mempool.PreCheckFunc, mempool.PostCheckFunc) error
	Flush()
	FlushAppConn() error

	TxsAvailable() <-chan struct{}
	EnableTxsAvailable()
}

Mempool defines the mempool interface as used by the ConsensusState. Updates to the mempool need to be synchronized with committing a block so apps can reset their transient state on Commit

type Metrics added in v0.26.0

type Metrics struct {
	// Time between BeginBlock and EndBlock.
	BlockProcessingTime metrics.Histogram
}

Metrics contains metrics exposed by this package.

func NopMetrics added in v0.26.0

func NopMetrics() *Metrics

NopMetrics returns no-op Metrics.

func PrometheusMetrics added in v0.26.0

func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics

PrometheusMetrics returns Metrics build using Prometheus client library. Optionally, labels can be provided along with their values ("foo", "fooValue").

type MockEvidencePool added in v0.19.9

type MockEvidencePool struct{}

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

func (MockEvidencePool) AddEvidence added in v0.19.9

func (m MockEvidencePool) AddEvidence(types.Evidence) error

func (MockEvidencePool) IsCommitted

func (m MockEvidencePool) IsCommitted(types.Evidence) bool

func (MockEvidencePool) PendingEvidence added in v0.19.9

func (m MockEvidencePool) PendingEvidence(int64) []types.Evidence

func (MockEvidencePool) Update added in v0.19.9

func (m MockEvidencePool) Update(*types.Block, State)

type MockMempool added in v0.8.0

type MockMempool struct{}

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

func (MockMempool) CheckTx added in v0.19.9

func (MockMempool) CheckTx(_ types.Tx, _ func(*abci.Response)) error

func (MockMempool) CheckTxWithInfo

func (MockMempool) CheckTxWithInfo(_ types.Tx, _ func(*abci.Response),
	_ mempool.TxInfo) error

func (MockMempool) EnableTxsAvailable added in v0.19.9

func (MockMempool) EnableTxsAvailable()

func (MockMempool) Flush added in v0.19.9

func (MockMempool) Flush()

func (MockMempool) FlushAppConn added in v0.19.9

func (MockMempool) FlushAppConn() error

func (MockMempool) Lock added in v0.8.0

func (MockMempool) Lock()

func (MockMempool) ReapMaxBytesMaxGas added in v0.25.0

func (MockMempool) ReapMaxBytesMaxGas(_, _ int64) types.Txs

func (MockMempool) Size added in v0.19.9

func (MockMempool) Size() int

func (MockMempool) TxsAvailable added in v0.19.9

func (MockMempool) TxsAvailable() <-chan struct{}

func (MockMempool) Unlock added in v0.8.0

func (MockMempool) Unlock()

func (MockMempool) Update added in v0.8.0

type State

type State struct {
	Version Version

	// immutable
	ChainID string

	// LastBlockHeight=0 at genesis (ie. block(H=0) does not exist)
	LastBlockHeight  int64
	LastBlockTotalTx int64
	LastBlockID      types.BlockID
	LastBlockTime    time.Time

	// LastValidators is used to validate block.LastCommit.
	// Validators are persisted to the database separately every time they change,
	// so we can query for historical validator sets.
	// Note that if s.LastBlockHeight causes a valset change,
	// we set s.LastHeightValidatorsChanged = s.LastBlockHeight + 1 + 1
	// Extra +1 due to nextValSet delay.
	NextValidators              *types.ValidatorSet
	Validators                  *types.ValidatorSet
	LastValidators              *types.ValidatorSet
	LastHeightValidatorsChanged int64

	// Consensus parameters used for validating blocks.
	// Changes returned by EndBlock and updated after Commit.
	ConsensusParams                  types.ConsensusParams
	LastHeightConsensusParamsChanged int64

	// Merkle root of the results from executing prev block
	LastResultsHash []byte

	// the latest AppHash we've received from calling abci.Commit()
	AppHash []byte
}

State is a short description of the latest committed block of the Tendermint consensus. It keeps all information necessary to validate new blocks, including the last validator set and the consensus params. All fields are exposed so the struct can be easily serialized, but none of them should be mutated directly. Instead, use state.Copy() or state.NextState(...). NOTE: not goroutine-safe.

func LoadState

func LoadState(db dbm.DB) State

LoadState loads the State from the database.

func LoadStateFromDBOrGenesisDoc added in v0.15.0

func LoadStateFromDBOrGenesisDoc(stateDB dbm.DB, genesisDoc *types.GenesisDoc) (State, error)

LoadStateFromDBOrGenesisDoc loads the most recent state from the database, or creates a new one from the given genesisDoc and persists the result to the database.

func LoadStateFromDBOrGenesisFile added in v0.15.0

func LoadStateFromDBOrGenesisFile(stateDB dbm.DB, genesisFilePath string) (State, error)

LoadStateFromDBOrGenesisFile loads the most recent state from the database, or creates a new one from the given genesisFilePath and persists the result to the database.

func MakeGenesisState

func MakeGenesisState(genDoc *types.GenesisDoc) (State, error)

MakeGenesisState creates state from types.GenesisDoc.

func MakeGenesisStateFromFile

func MakeGenesisStateFromFile(genDocFile string) (State, error)

MakeGenesisStateFromFile reads and unmarshals state from the given file.

Used during replay and in tests.

func (State) Bytes added in v0.8.0

func (state State) Bytes() []byte

Bytes serializes the State using go-amino.

func (State) Copy

func (state State) Copy() State

Copy makes a copy of the State for mutating.

func (State) Equals added in v0.8.0

func (state State) Equals(state2 State) bool

Equals returns true if the States are identical.

func (State) IsEmpty added in v0.15.0

func (state State) IsEmpty() bool

IsEmpty returns true if the State is equal to the empty State.

func (State) MakeBlock added in v0.15.0

func (state State) MakeBlock(
	height int64,
	txs []types.Tx,
	commit *types.Commit,
	evidence []types.Evidence,
	proposerAddress []byte,
) (*types.Block, *types.PartSet)

MakeBlock builds a block from the current state with the given txs, commit, and evidence. Note it also takes a proposerAddress because the state does not track rounds, and hence does not know the correct proposer. TODO: fix this!

type ValidatorsInfo added in v0.11.0

type ValidatorsInfo struct {
	ValidatorSet      *types.ValidatorSet
	LastHeightChanged int64
}

ValidatorsInfo represents the latest validator set, or the last height it changed

func (*ValidatorsInfo) Bytes added in v0.11.0

func (valInfo *ValidatorsInfo) Bytes() []byte

Bytes serializes the ValidatorsInfo using go-amino.

type Version added in v0.26.0

type Version struct {
	Consensus version.Consensus
	Software  string
}

Version is for versioning the State. It holds the Block and App version needed for making blocks, and the software version to support upgrades to the format of the State as stored on disk.

Directories

Path Synopsis
kv

Jump to

Keyboard shortcuts

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