Documentation ¶
Index ¶
- Constants
- Variables
- func ABCIResponsesResultsHash(ar *cmtstate.ABCIResponses) []byte
- func ExecCommitBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block, logger log.Logger, ...) ([]byte, error)
- func IsEmpty(store dbStore) (bool, error)
- func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error)
- func MedianTime(commit *types.Commit, validators *types.ValidatorSet) time.Time
- func Rollback(bs BlockStore, ss Store, removeBlock bool) (int64, []byte, error)
- func TxPostCheck(state State) mempl.PostCheckFunc
- func TxPreCheck(state State) mempl.PreCheckFunc
- type BlockExecutor
- func (blockExec *BlockExecutor) ApplyBlock(state State, blockID types.BlockID, block *types.Block) (State, int64, error)
- func (blockExec *BlockExecutor) ApplyVerifiedBlock(state State, blockID types.BlockID, block *types.Block) (State, int64, error)
- func (blockExec *BlockExecutor) Commit(state State, block *types.Block, deliverTxResponses []*abci.ResponseDeliverTx) ([]byte, int64, error)
- func (blockExec *BlockExecutor) CreateProposalBlock(height int64, state State, commit *types.Commit, proposerAddr []byte) (*types.Block, error)
- func (blockExec *BlockExecutor) ProcessProposal(block *types.Block, state State) (bool, error)
- func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher)
- func (blockExec *BlockExecutor) Store() Store
- func (blockExec *BlockExecutor) ValidateBlock(state State, block *types.Block) error
- type BlockExecutorOption
- type BlockStore
- type BootstrapStore
- func (store BootstrapStore) Bootstrap(state State) error
- func (store BootstrapStore) Close() error
- func (store BootstrapStore) GetOfflineStateSyncHeight() (int64, error)
- func (store BootstrapStore) Load() (State, error)
- func (store BootstrapStore) LoadABCIResponses(height int64) (*cmtstate.ABCIResponses, error)
- func (store BootstrapStore) LoadConsensusParams(height int64) (types.ConsensusParams, error)
- func (store BootstrapStore) LoadFromDBOrGenesisDoc(genesisDoc *types.GenesisDoc) (State, error)
- func (store BootstrapStore) LoadFromDBOrGenesisFile(genesisFilePath string) (State, error)
- func (store BootstrapStore) LoadLastABCIResponse(height int64) (*cmtstate.ABCIResponses, error)
- func (store BootstrapStore) LoadValidators(height int64) (*types.ValidatorSet, error)
- func (store BootstrapStore) PruneStates(from int64, to int64) error
- func (store BootstrapStore) Save(state State) error
- func (store BootstrapStore) SaveABCIResponses(height int64, abciResponses *cmtstate.ABCIResponses) error
- func (store BootstrapStore) SetOfflineStateSyncHeight(height int64) error
- type EmptyEvidencePool
- func (EmptyEvidencePool) AddEvidence(types.Evidence) error
- func (EmptyEvidencePool) CheckEvidence(evList types.EvidenceList) error
- func (EmptyEvidencePool) PendingEvidence(maxBytes int64) (ev []types.Evidence, size int64)
- func (EmptyEvidencePool) ReportConflictingVotes(voteA, voteB *types.Vote)
- func (EmptyEvidencePool) Update(State, types.EvidenceList)
- type ErrAppBlockHeightTooHigh
- type ErrAppBlockHeightTooLow
- type ErrBlockHashMismatch
- type ErrInvalidBlock
- type ErrLastStateMismatch
- type ErrNoABCIResponsesForHeight
- type ErrNoConsensusParamsForHeight
- type ErrNoValSetForHeight
- type ErrProxyAppConn
- type ErrStateMismatch
- type ErrUnknownBlock
- type EvidencePool
- type Metrics
- type State
- func (state State) Bytes() []byte
- func (state State) Copy() State
- func (state State) Equals(state2 State) bool
- func (state State) IsEmpty() bool
- func (state State) MakeBlock(height int64, txs []types.Tx, lastCommit *types.Commit, ...) *types.Block
- func (state *State) ToProto() (*cmtstate.State, error)
- type Store
- type StoreOptions
Constants ¶
const ( // MetricsSubsystem is a subsystem shared by all metrics exposed by this // package. MetricsSubsystem = "state" )
Variables ¶
var ErrABCIResponsesNotPersisted = errors.New("node is not persisting abci responses")
var InitStateVersion = cmtstate.Version{ Consensus: cmtversion.Consensus{ Block: version.BlockProtocol, App: 0, }, Software: version.TMCoreSemVer, }
InitStateVersion sets the Consensus.Block and Software versions, but leaves the Consensus.App version blank. The Consensus.App version will be set during the Handshake, once we hear from the app what protocol version it is running.
Functions ¶
func ABCIResponsesResultsHash ¶
func ABCIResponsesResultsHash(ar *cmtstate.ABCIResponses) []byte
ABCIResponsesResultsHash returns the root hash of a Merkle tree of ResponseDeliverTx responses (see ABCIResults.Hash)
See merkle.SimpleHashFromByteSlices
func ExecCommitBlock ¶
func ExecCommitBlock( appConnConsensus proxy.AppConnConsensus, block *types.Block, logger log.Logger, store Store, initialHeight int64, ) ([]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 MakeGenesisDocFromFile ¶
func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error)
MakeGenesisDocFromFile reads and unmarshals genesis doc from the given file.
func MedianTime ¶
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 Rollback ¶
Rollback overwrites the current CometBFT state (height n) with the most recent previous state (height n - 1). Note that this function does not affect application state.
func TxPostCheck ¶
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 ¶
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.
Types ¶
type BlockExecutor ¶
type BlockExecutor struct {
// contains filtered or unexported fields
}
BlockExecutor provides the context and accessories for properly executing a block.
func NewBlockExecutor ¶
func NewBlockExecutor( stateStore Store, logger log.Logger, proxyApp proxy.AppConnConsensus, mempool mempool.Mempool, evpool EvidencePool, options ...BlockExecutorOption, ) *BlockExecutor
NewBlockExecutor returns a new BlockExecutor with a NopEventBus. Call SetEventBus to provide one.
func (*BlockExecutor) ApplyBlock ¶
func (blockExec *BlockExecutor) ApplyBlock( state State, blockID types.BlockID, block *types.Block, ) (State, int64, 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 returns the new state and the block height to retain (pruning older blocks). 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) ApplyVerifiedBlock ¶ added in v0.37.7
func (blockExec *BlockExecutor) ApplyVerifiedBlock( state State, blockID types.BlockID, block *types.Block, ) (State, int64, error)
ApplyVerifiedBlock does the same as `ApplyBlock`, but skips verification.
func (*BlockExecutor) Commit ¶
func (blockExec *BlockExecutor) Commit( state State, block *types.Block, deliverTxResponses []*abci.ResponseDeliverTx, ) ([]byte, int64, 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 the height to retain (if any). 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, error)
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 allocated for maximum sized evidence. The rest is given to txs, up to the max gas.
Contract: application will not return more bytes than are sent over the wire.
func (*BlockExecutor) ProcessProposal ¶
func (*BlockExecutor) SetEventBus ¶
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) Store ¶
func (blockExec *BlockExecutor) Store() Store
func (*BlockExecutor) ValidateBlock ¶
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 ¶
type BlockExecutorOption func(executor *BlockExecutor)
func BlockExecutorWithMetrics ¶
func BlockExecutorWithMetrics(metrics *Metrics) BlockExecutorOption
type BlockStore ¶
type BlockStore interface { Base() int64 Height() int64 Size() int64 LoadBaseMeta() *types.BlockMeta LoadBlockMeta(height int64) *types.BlockMeta LoadBlock(height int64) *types.Block SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) PruneBlocks(height int64) (uint64, error) LoadBlockByHash(hash []byte) *types.Block LoadBlockMetaByHash(hash []byte) *types.BlockMeta LoadBlockPart(height int64, index int) *types.Part LoadBlockCommit(height int64) *types.Commit LoadSeenCommit(height int64) *types.Commit DeleteLatestBlock() error }
BlockStore defines the interface used by the ConsensusState.
type BootstrapStore ¶ added in v0.37.3
type BootstrapStore struct {
// contains filtered or unexported fields
}
func NewBootstrapStore ¶ added in v0.37.3
func NewBootstrapStore(db dbm.DB, options StoreOptions) BootstrapStore
func (BootstrapStore) Bootstrap ¶ added in v0.37.3
BootstrapState saves a new state, used e.g. by state sync when starting from non-zero height.
func (BootstrapStore) GetOfflineStateSyncHeight ¶ added in v0.37.3
func (store BootstrapStore) GetOfflineStateSyncHeight() (int64, error)
Gets the height at which the store is bootstrapped after out of band statesync
func (BootstrapStore) LoadABCIResponses ¶ added in v0.37.3
func (store BootstrapStore) LoadABCIResponses(height int64) (*cmtstate.ABCIResponses, error)
LoadABCIResponses loads the ABCIResponses for the given height from the database. If the node has DiscardABCIResponses set to true, ErrABCIResponsesNotPersisted is persisted. If not found, ErrNoABCIResponsesForHeight is returned.
func (BootstrapStore) LoadConsensusParams ¶ added in v0.37.3
func (store BootstrapStore) LoadConsensusParams(height int64) (types.ConsensusParams, error)
LoadConsensusParams loads the ConsensusParams for a given height.
func (BootstrapStore) LoadFromDBOrGenesisDoc ¶ added in v0.37.3
func (store BootstrapStore) LoadFromDBOrGenesisDoc(genesisDoc *types.GenesisDoc) (State, error)
LoadStateFromDBOrGenesisDoc loads the most recent state from the database, or creates a new one from the given genesisDoc.
func (BootstrapStore) LoadFromDBOrGenesisFile ¶ added in v0.37.3
LoadStateFromDBOrGenesisFile loads the most recent state from the database, or creates a new one from the given genesisFilePath.
func (BootstrapStore) LoadLastABCIResponse ¶ added in v0.37.3
func (store BootstrapStore) LoadLastABCIResponse(height int64) (*cmtstate.ABCIResponses, error)
LoadLastABCIResponses loads the ABCIResponses from the most recent height. The height parameter is used to ensure that the response corresponds to the latest height. If not, an error is returned.
This method is used for recovering in the case that we called the Commit ABCI method on the application but crashed before persisting the results.
func (BootstrapStore) LoadValidators ¶ added in v0.37.3
func (store BootstrapStore) LoadValidators(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 (BootstrapStore) PruneStates ¶ added in v0.37.3
PruneStates deletes states between the given heights (including from, excluding to). It is not guaranteed to delete all states, since the last checkpointed state and states being pointed to by e.g. `LastHeightChanged` must remain. The state at to must also exist.
The from parameter is necessary since we can't do a key scan in a performant way due to the key encoding not preserving ordering: https://github.com/tendermint/tendermint/issues/4567 This will cause some old states to be left behind when doing incremental partial prunes, specifically older checkpoints and LastHeightChanged targets.
func (BootstrapStore) Save ¶ added in v0.37.3
Save persists the State, the ValidatorsInfo, and the ConsensusParamsInfo to the database. This flushes the writes (e.g. calls SetSync).
func (BootstrapStore) SaveABCIResponses ¶ added in v0.37.3
func (store BootstrapStore) SaveABCIResponses(height int64, abciResponses *cmtstate.ABCIResponses) error
SaveABCIResponses persists the ABCIResponses to the database. This is useful in case we crash after app.Commit and before s.Save(). Responses are indexed by height so they can also be loaded later to produce Merkle proofs.
CONTRACT: height must be monotonically increasing every time this is called.
func (BootstrapStore) SetOfflineStateSyncHeight ¶ added in v0.37.3
func (store BootstrapStore) SetOfflineStateSyncHeight(height int64) error
type EmptyEvidencePool ¶
type EmptyEvidencePool struct{}
EmptyEvidencePool is an empty implementation of EvidencePool, useful for testing. It also complies to the consensus evidence pool interface
func (EmptyEvidencePool) AddEvidence ¶
func (EmptyEvidencePool) AddEvidence(types.Evidence) error
func (EmptyEvidencePool) CheckEvidence ¶
func (EmptyEvidencePool) CheckEvidence(evList types.EvidenceList) error
func (EmptyEvidencePool) PendingEvidence ¶
func (EmptyEvidencePool) PendingEvidence(maxBytes int64) (ev []types.Evidence, size int64)
func (EmptyEvidencePool) ReportConflictingVotes ¶
func (EmptyEvidencePool) ReportConflictingVotes(voteA, voteB *types.Vote)
func (EmptyEvidencePool) Update ¶
func (EmptyEvidencePool) Update(State, types.EvidenceList)
type ErrAppBlockHeightTooHigh ¶
func (ErrAppBlockHeightTooHigh) Error ¶
func (e ErrAppBlockHeightTooHigh) Error() string
type ErrAppBlockHeightTooLow ¶
func (ErrAppBlockHeightTooLow) Error ¶
func (e ErrAppBlockHeightTooLow) Error() string
type ErrBlockHashMismatch ¶
func (ErrBlockHashMismatch) Error ¶
func (e ErrBlockHashMismatch) Error() string
type ErrInvalidBlock ¶
type ErrInvalidBlock error
type ErrLastStateMismatch ¶
func (ErrLastStateMismatch) Error ¶
func (e ErrLastStateMismatch) Error() string
type ErrNoABCIResponsesForHeight ¶
type ErrNoABCIResponsesForHeight struct {
Height int64
}
func (ErrNoABCIResponsesForHeight) Error ¶
func (e ErrNoABCIResponsesForHeight) Error() string
type ErrNoConsensusParamsForHeight ¶
type ErrNoConsensusParamsForHeight struct {
Height int64
}
func (ErrNoConsensusParamsForHeight) Error ¶
func (e ErrNoConsensusParamsForHeight) Error() string
type ErrNoValSetForHeight ¶
type ErrNoValSetForHeight struct {
Height int64
}
func (ErrNoValSetForHeight) Error ¶
func (e ErrNoValSetForHeight) Error() string
type ErrProxyAppConn ¶
type ErrProxyAppConn error
type ErrStateMismatch ¶
func (ErrStateMismatch) Error ¶
func (e ErrStateMismatch) Error() string
type ErrUnknownBlock ¶
type ErrUnknownBlock struct {
Height int64
}
func (ErrUnknownBlock) Error ¶
func (e ErrUnknownBlock) Error() string
type EvidencePool ¶
type EvidencePool interface { PendingEvidence(maxBytes int64) (ev []types.Evidence, size int64) AddEvidence(types.Evidence) error Update(State, types.EvidenceList) CheckEvidence(types.EvidenceList) error }
EvidencePool defines the EvidencePool interface used by State.
type Metrics ¶
type Metrics struct { // Time between BeginBlock and EndBlock in ms. BlockProcessingTime metrics.Histogram `metrics_buckettype:"lin" metrics_bucketsizes:"1, 10, 10"` // ConsensusParamUpdates is the total number of times the application has // udated the consensus params since process start. ConsensusParamUpdates metrics.Counter // ValidatorSetUpdates is the total number of times the application has // udated the validator set since process start. ValidatorSetUpdates metrics.Counter }
Metrics contains metrics exposed by this package.
func NopMetrics ¶
func NopMetrics() *Metrics
func PrometheusMetrics ¶
type State ¶
type State struct { Version cmtstate.Version // immutable ChainID string InitialHeight int64 // should be 1, not 0, when starting from height 1 // LastBlockHeight=0 at genesis (ie. block(H=0) does not exist) LastBlockHeight 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 consensus protocol. 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 MakeGenesisState ¶
func MakeGenesisState(genDoc *types.GenesisDoc) (State, error)
MakeGenesisState creates state from types.GenesisDoc.
func MakeGenesisStateFromFile ¶
MakeGenesisStateFromFile reads and unmarshals state from the given file.
Used during replay and in tests.
func (State) Bytes ¶
Bytes serializes the State using protobuf. It panics if either casting to protobuf or serialization fails.
func (State) MakeBlock ¶
func (state State) MakeBlock( height int64, txs []types.Tx, lastCommit *types.Commit, evidence []types.Evidence, proposerAddress []byte, ) *types.Block
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 Store ¶
type Store interface { // LoadFromDBOrGenesisFile loads the most recent state. // If the chain is new it will use the genesis file from the provided genesis file path as the current state. LoadFromDBOrGenesisFile(string) (State, error) // LoadFromDBOrGenesisDoc loads the most recent state. // If the chain is new it will use the genesis doc as the current state. LoadFromDBOrGenesisDoc(*types.GenesisDoc) (State, error) // Load loads the current state of the blockchain Load() (State, error) // LoadValidators loads the validator set at a given height LoadValidators(int64) (*types.ValidatorSet, error) // LoadABCIResponses loads the abciResponse for a given height LoadABCIResponses(int64) (*cmtstate.ABCIResponses, error) // LoadLastABCIResponse loads the last abciResponse for a given height LoadLastABCIResponse(int64) (*cmtstate.ABCIResponses, error) // LoadConsensusParams loads the consensus params for a given height LoadConsensusParams(int64) (types.ConsensusParams, error) // Save overwrites the previous state with the updated one Save(State) error // SaveABCIResponses saves ABCIResponses for a given height SaveABCIResponses(int64, *cmtstate.ABCIResponses) error // Bootstrap is used for bootstrapping state when not starting from a initial height. Bootstrap(State) error // PruneStates takes the height from which to start prning and which height stop at PruneStates(int64, int64) error // Close closes the connection with the database Close() error }
Store defines the state store interface
It is used to retrieve current state and save and load ABCI responses, validators and consensus parameters
type StoreOptions ¶
type StoreOptions struct { // DiscardABCIResponses determines whether or not the store // retains all ABCIResponses. If DiscardABCiResponses is enabled, // the store will maintain only the response object from the latest // height. DiscardABCIResponses bool }