state

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcABCIResponsesKey

func CalcABCIResponsesKey(height int64) []byte

func CalcTxResultKey

func CalcTxResultKey(hash []byte) []byte

CalcTxResultKey calculates the storage key for the transaction result

func ExecCommitBlock

func ExecCommitBlock(
	appConnConsensus appconn.Consensus,
	block *types.Block,
	logger *slog.Logger,
	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

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

LoadConsensusParams loads the ConsensusParams for a given height.

func LoadValidators

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

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

func MakeGenesisDocFromFile

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

MakeGenesisDocFromFile reads and unmarshals genesis doc from the given file. XXX duplicated in bft/types/genesis.go, remove this.

func MedianTime

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 SaveABCIResponses

func SaveABCIResponses(db dbm.DB, height int64, abciResponses *ABCIResponses)

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. NOTE: this should only be used internally by the bft package and subpackages.

func SaveState

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 TxPreCheck

func TxPreCheck(state State) mempl.PreCheckFunc

TxPreCheck returns a function to filter transactions before processing. The function does nothing yet.

Types

type ABCIResponses

type ABCIResponses struct {
	DeliverTxs []abci.ResponseDeliverTx `json:"deliver_tx"`
	EndBlock   abci.ResponseEndBlock    `json:"end_block"`
	BeginBlock abci.ResponseBeginBlock  `json:"begin_block"`
}

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

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

func NewABCIResponses(block *types.Block) *ABCIResponses

NewABCIResponses returns a new ABCIResponses

func NewABCIResponsesFromNum

func NewABCIResponsesFromNum(numTxs int64) *ABCIResponses

NewABCIResponsesFromNum returns a new ABCIResponses with a set number of txs

func (*ABCIResponses) Bytes

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

Bytes serializes the ABCIResponse using go-amino.

func (*ABCIResponses) ResultsHash

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

type AppBlockHeightTooHighError

type AppBlockHeightTooHighError struct {
	CoreHeight int64
	AppHeight  int64
}

func (AppBlockHeightTooHighError) Error

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(db dbm.DB, logger *slog.Logger, proxyApp appconn.Consensus, mempool mempl.Mempool, 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, 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

func (blockExec *BlockExecutor) Commit(
	state State,
	block *types.Block,
	deliverTxResponses []abci.ResponseDeliverTx,
) ([]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 crypto.Address,
) (*types.Block, *types.PartSet)

CreateProposalBlock calls state.MakeBlock with txs from the mempool.

func (*BlockExecutor) DB

func (blockExec *BlockExecutor) DB() dbm.DB

func (*BlockExecutor) SetEventSwitch

func (blockExec *BlockExecutor) SetEventSwitch(evsw events.EventSwitch)

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

type BlockExecutorOption

type BlockExecutorOption func(executor *BlockExecutor)

type BlockHashMismatchError

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

func (BlockHashMismatchError) Error

func (e BlockHashMismatchError) Error() string

type BlockStore

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

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

type ConsensusParamsInfo struct {
	ConsensusParams   abci.ConsensusParams
	LastHeightChanged int64
}

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

func (ConsensusParamsInfo) Bytes

func (params ConsensusParamsInfo) Bytes() []byte

Bytes serializes the ConsensusParamsInfo using go-amino.

type InvalidBlockError

type InvalidBlockError error

type LastStateMismatchError

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

func (LastStateMismatchError) Error

func (e LastStateMismatchError) Error() string

type NoABCIResponsesForHeightError

type NoABCIResponsesForHeightError struct {
	Height int64
}

func (NoABCIResponsesForHeightError) Error

type NoConsensusParamsForHeightError

type NoConsensusParamsForHeightError struct {
	Height int64
}

func (NoConsensusParamsForHeightError) Error

type NoTxResultForHashError

type NoTxResultForHashError struct {
	Hash []byte
}

func (NoTxResultForHashError) Error

func (e NoTxResultForHashError) Error() string

type NoValSetForHeightError

type NoValSetForHeightError struct {
	Height int64
}

func (NoValSetForHeightError) Error

func (e NoValSetForHeightError) Error() string

type ProxyAppConnError

type ProxyAppConnError error

type State

type State struct {
	SoftwareVersion string
	BlockVersion    string
	AppVersion      string

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

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

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

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

func (state State) Equals(state2 State) bool

Equals returns true if the States are identical.

func (State) IsEmpty

func (state State) IsEmpty() bool

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

func (State) MakeBlock

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

MakeBlock builds a block from the current state with the given txs and commit. 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 StateMismatchError

type StateMismatchError struct {
	Got      *State
	Expected *State
}

func (StateMismatchError) Error

func (e StateMismatchError) Error() string

type TxResultIndex

type TxResultIndex struct {
	BlockNum int64  // the block number the tx was contained in
	TxIndex  uint32 // the index of the transaction within the block
}

TxResultIndex keeps the result index information for a transaction

func LoadTxResultIndex

func LoadTxResultIndex(db dbm.DB, txHash []byte) (*TxResultIndex, error)

LoadTxResultIndex loads the tx result associated with the given tx hash from the database, if any

func (*TxResultIndex) Bytes

func (t *TxResultIndex) Bytes() []byte

type UnknownBlockError

type UnknownBlockError struct {
	Height int64
}

func (UnknownBlockError) Error

func (e UnknownBlockError) Error() string

type ValidatorsInfo

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

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

func (*ValidatorsInfo) Bytes

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

Bytes serializes the ValidatorsInfo using go-amino.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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