state

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0, Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeliverTxsExecModeSerial   DeliverTxsExecMode = iota // execute [deliverTx,...] sequentially
	DeliverTxsExecModeParallel                    = 2    // execute [deliverTx,...] parallel

	// There are two modes.
	// 0: execute [deliverTx,...] sequentially (default)
	// 1: execute [deliverTx,...] deprecated
	// 2: execute [deliverTx,...] parallel
	FlagDeliverTxsExecMode = "deliver-txs-mode"
	FlagEnableConcurrency  = "enable-concurrency"
)
View Source
const (
	MAXCHAN_LEN           = 2
	FEEDBACK_LEN          = 2
	QUIT_SIG              = -99
	MAX_WAIT_TIME_SECONDS = 30
)
View Source
const (
	FlagApplyBlockPprofTime = "applyblock-pprof-time"
)
View Source
const (
	// MetricsSubsystem is a subsystem shared by all metrics exposed by this
	// package.
	MetricsSubsystem = "state"
)

Variables

View Source
var (
	IgnoreSmbCheck bool = false

	ApplyBlockPprofTime = -1
	HomeDir             = ""
)
View Source
var EmptyGenerateWatchDataF = func() ([]byte, error) { return nil, nil }
View Source
var ModuleCodec *amino.Codec

Functions

func ExecCommitBlock

func ExecCommitBlock(
	appConnConsensus proxy.AppConnConsensus,
	block *types.Block,
	logger log.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) (types.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 ErrNoValSetForHeight if the validator set can't be found for this height.

func LoadValidatorsWithStoredHeight

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

LoadValidators loads the ValidatorSet for a given height. plus the last LastHeightChanged Returns ErrNoValSetForHeight 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.

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 PprofEnd

func PprofEnd(height int, f *os.File, startTime time.Time)

func PprofStart

func PprofStart() (*os.File, time.Time)

func PruneStates

func PruneStates(db dbm.DB, from int64, to int64) error

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

Exposed for testing.

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 SetEvmWatchDataManager

func SetEvmWatchDataManager(manager WatchDataManager)

func SetIgnoreSmbCheck

func SetIgnoreSmbCheck(check bool)

func SetWasmWatchDataManager

func SetWasmWatchDataManager(manager WatchDataManager)

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.

func VerifyEvidence

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

type ABCIResponses struct {
	DeliverTxs []*abci.ResponseDeliverTx `json:"deliver_txs"`
	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 (ABCIResponses) AminoSize

func (arz ABCIResponses) AminoSize(cdc *amino.Codec) int

func (*ABCIResponses) Bytes

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

Bytes serializes the ABCIResponse using go-amino.

func (ABCIResponses) MarshalAminoTo

func (arz ABCIResponses) MarshalAminoTo(cdc *amino.Codec, buf *bytes.Buffer) error

func (ABCIResponses) MarshalToAmino

func (arz ABCIResponses) MarshalToAmino(cdc *amino.Codec) ([]byte, error)

func (*ABCIResponses) ResultsHash

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

func (*ABCIResponses) String

func (arz *ABCIResponses) String() string

func (*ABCIResponses) UnmarshalFromAmino

func (arz *ABCIResponses) UnmarshalFromAmino(cdc *amino.Codec, data []byte) error

UnmarshalFromAmino unmarshal data from amino bytes.

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 log.Logger,
	proxyApp proxy.AppConnConsensus,
	mempool mempl.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) ApplyBlockWithTrace

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

func (*BlockExecutor) CleanZeroRpcState

func (blockExec *BlockExecutor) CleanZeroRpcState()

func (*BlockExecutor) CreateProposalBlock

func (blockExec *BlockExecutor) CreateProposalBlock(
	height int64,
	state State, commit *types.Commit,
	proposerAddr []byte,
	latestBH int64,
) (*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) DB

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

func (*BlockExecutor) DeliverTxsForBrczeroRpc

func (blockExec *BlockExecutor) DeliverTxsForBrczeroRpc(block *types.Block) (*ABCIResponses, error)

func (*BlockExecutor) FireBlockTimeEvents

func (blockExec *BlockExecutor) FireBlockTimeEvents(height int64, txNum int, available bool)

func (*BlockExecutor) GetZeroDataByBTCHeight

func (blockExec *BlockExecutor) GetZeroDataByBTCHeight(btcHeight int64) (types.ZeroData, error)

func (*BlockExecutor) GetZeroDataMinHeight

func (blockExec *BlockExecutor) GetZeroDataMinHeight() int64

func (*BlockExecutor) RpcReorgRoutine

func (blockExec *BlockExecutor) RpcReorgRoutine()

func (*BlockExecutor) SaveABCIResponsesAsync

func (blockExec *BlockExecutor) SaveABCIResponsesAsync(height int64, responses *ABCIResponses)

func (*BlockExecutor) SaveStateAsync

func (blockExec *BlockExecutor) SaveStateAsync(state State)

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

func (blockExec *BlockExecutor) SetIsAsyncSaveDB(isAsyncSaveDB bool)

SetIsAsyncSaveDB switches to open async write db feature

func (*BlockExecutor) SetIsFastSyncing

func (blockExec *BlockExecutor) SetIsFastSyncing(isSyncing bool)

func (*BlockExecutor) SetIsNullIndexer

func (blockExec *BlockExecutor) SetIsNullIndexer(isNullIndexer bool)

func (*BlockExecutor) SetZeroDataDelivered

func (BlockExec *BlockExecutor) SetZeroDataDelivered(btcH int64, value bool)

func (*BlockExecutor) Stop

func (blockExec *BlockExecutor) Stop()

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.

func (*BlockExecutor) ZeroReorgChain

func (BlockExec *BlockExecutor) ZeroReorgChain() <-chan int64

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

	LoadBlockMeta(height int64) *types.BlockMeta
	LoadBlock(height int64) *types.Block
	LoadBTCMeta(height int64) (*types.BTCBlockMeta, error)

	SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)

	PruneBlocks(height int64) (uint64, error)
	DeleteBlocksFromTop(height int64) (uint64, error)

	LoadBlockByHash(hash []byte) *types.Block
	LoadZeroHeightByBtcHash(hash string) (int64, error)
	LoadBtcBlockHashByBtcTxid(btcTxid string) (string, error)
	LoadBtcBlockHashByBtcHeight(btcHeight int64) (string, error)
	LoadMapTxhashTxidByBtcHash(btcHash, protocolName string) (map[string]string, error)
	LoadBlockPart(height int64, index int) *types.Part

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

BlockStore defines the interface used by the ConsensusState.

type ConsensusParamsInfo

type ConsensusParamsInfo struct {
	ConsensusParams   types.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 DeliverTxsExecMode

type DeliverTxsExecMode int

Enum mode for executing [deliverTx, ...]

type DeltaContext

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

type DeltaInfo

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

type EmptyWatchDataManager

type EmptyWatchDataManager struct{}

func (EmptyWatchDataManager) ApplyWatchData

func (e EmptyWatchDataManager) ApplyWatchData(interface{})

func (EmptyWatchDataManager) CreateWatchDataGenerator

func (e EmptyWatchDataManager) CreateWatchDataGenerator() func() ([]byte, error)

func (EmptyWatchDataManager) UnmarshalWatchData

func (e EmptyWatchDataManager) UnmarshalWatchData([]byte) (interface{}, error)

type ErrAppBlockHeightTooHigh

type ErrAppBlockHeightTooHigh struct {
	CoreHeight int64
	AppHeight  int64
}

func (ErrAppBlockHeightTooHigh) Error

func (e ErrAppBlockHeightTooHigh) Error() string

type ErrAppBlockHeightTooLow

type ErrAppBlockHeightTooLow struct {
	AppHeight int64
	StoreBase int64
}

func (ErrAppBlockHeightTooLow) Error

func (e ErrAppBlockHeightTooLow) Error() string

type ErrBlockHashMismatch

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

func (ErrBlockHashMismatch) Error

func (e ErrBlockHashMismatch) Error() string

type ErrInvalidBlock

type ErrInvalidBlock error

type ErrLastStateMismatch

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

func (ErrLastStateMismatch) Error

func (e ErrLastStateMismatch) Error() string

type ErrNoABCIResponsesForHeight

type ErrNoABCIResponsesForHeight struct {
	Height int64
}

func (ErrNoABCIResponsesForHeight) Error

type ErrNoConsensusParamsForHeight

type ErrNoConsensusParamsForHeight struct {
	Height int64
}

func (ErrNoConsensusParamsForHeight) Error

type ErrNoValSetForHeight

type ErrNoValSetForHeight struct {
	Height int64
}

func (ErrNoValSetForHeight) Error

func (e ErrNoValSetForHeight) Error() string

type ErrProxyAppConn

type ErrProxyAppConn error

type ErrStateMismatch

type ErrStateMismatch struct {
	Got      *State
	Expected *State
}

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

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

	// Time between last block and current block.
	IntervalTime metrics.Gauge

	// Time during executes abci
	AbciTime metrics.Gauge
	// Time during commiting app state
	CommitTime metrics.Gauge

	CommittedHeight metrics.Gauge
	// contains filtered or unexported fields
}

Metrics contains metrics exposed by this package.

func NopMetrics

func NopMetrics() *Metrics

NopMetrics returns no-op Metrics.

func PrometheusMetrics

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

type MockEvidencePool struct{}

MockEvidencePool is an empty implementation of EvidencePool, useful for testing.

func (MockEvidencePool) AddEvidence

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

func (MockEvidencePool) IsCommitted

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

func (MockEvidencePool) PendingEvidence

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

func (MockEvidencePool) Update

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

type State

type State struct {
	Version Version

	// immutable
	ChainID string

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

func (State) MakeBlockBrc

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

func (*State) String

func (state *State) String() 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.

type Version

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.

func GetStateVersion

func GetStateVersion(h int64) Version

func (Version) UpgradeToIBCVersion

func (v Version) UpgradeToIBCVersion() Version

type WatchDataManager

type WatchDataManager interface {
	CreateWatchDataGenerator() func() ([]byte, error)
	UnmarshalWatchData([]byte) (interface{}, error)
	ApplyWatchData(interface{})
}

Directories

Path Synopsis
kv

Jump to

Keyboard shortcuts

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