Documentation ¶
Index ¶
- Constants
- func ExecCommitBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block, logger log.Logger, ...) ([]byte, error)
- func LoadConsensusParams(db dbm.DB, height int64) (types.ConsensusParams, error)
- func LoadValidators(db dbm.DB, height int64) (*types.ValidatorSet, error)
- func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error)
- func MedianTime(commit *types.Commit, validators *types.ValidatorSet) time.Time
- func PruneStates(db dbm.DB, from int64, to int64) error
- func SaveABCIResponses(db dbm.DB, height int64, abciResponses *ABCIResponses)
- func SaveState(db dbm.DB, state State)
- func TxPostCheck(state State) mempl.PostCheckFunc
- func TxPreCheck(state State) mempl.PreCheckFunc
- func VerifyEvidence(stateDB dbm.DB, state State, evidence types.Evidence) error
- type ABCIResponses
- type BlockExecutor
- func (blockExec *BlockExecutor) ApplyBlock(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, *types.PartSet)
- func (blockExec *BlockExecutor) DB() dbm.DB
- func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher)
- func (blockExec *BlockExecutor) ValidateBlock(state State, block *types.Block) error
- type BlockExecutorOption
- type BlockStore
- type ConsensusParamsInfo
- 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 MockEvidencePool
- type State
- func LoadState(db dbm.DB) State
- func LoadStateFromDBOrGenesisDoc(stateDB dbm.DB, genesisDoc *types.GenesisDoc) (State, error)
- func LoadStateFromDBOrGenesisFile(stateDB dbm.DB, genesisFilePath string) (State, error)
- func MakeGenesisState(genDoc *types.GenesisDoc) (State, error)
- func MakeGenesisStateFromFile(genDocFile string) (State, error)
- type ValidatorsInfo
- type Version
Constants ¶
const ( // MetricsSubsystem is a subsystem shared by all metrics exposed by this // package. MetricsSubsystem = "state" )
Variables ¶
This section is empty.
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 ¶
LoadConsensusParams loads the ConsensusParams for a given height.
func LoadValidators ¶
LoadValidators loads the ValidatorSet for a given height. Returns ErrNoValSetForHeight if the validator set can't be found for this height.
func MakeGenesisDocFromFile ¶
func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error)
MakeGenesisDocFromFile 读取并反序列化创世文档
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. MedianTime为给定的Commit(基于投票消息的Timestamp字段)和相应的验证器集计算中值时间。 计算的时间总是在诚实处理发送的投票的时间戳之间,即,有缺陷的处理不能任意增加或减少计算值。
func PruneStates ¶
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/wjbbig/candy/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 ¶
SaveState persists the State, the ValidatorsInfo, and the ConsensusParamsInfo to the database. This flushes the writes (e.g. calls SetSync).
func VerifyEvidence ¶
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) Bytes ¶
func (arz *ABCIResponses) Bytes() []byte
Bytes serializes the ABCIResponse using go-amino.
func (*ABCIResponses) ResultsHash ¶
func (arz *ABCIResponses) ResultsHash() []byte
type BlockExecutor ¶
type BlockExecutor struct {
// contains filtered or unexported fields
}
----------------------------------------------------------------------------- BlockExecutor处理区块的执行和状态的更新。 它暴露出ApplyBlock()方法,用于验证和处理区块,使用ABCI响应更新状态,自动提交和更新内存池,然后保存状态。 BlockExecutor提供了上下文和用于正确执行块的附件。
func NewBlockExecutor ¶
func NewBlockExecutor( db dbm.DB, logger log.Logger, proxyApp proxy.AppConnConsensus, mempool mempl.Mempool, evpool EvidencePool, options ...BlockExecutorOption, ) *BlockExecutor
NewBlockExecutor 返回一个没有eventBus的区块处理器. 调用SetEventBus来提供eventBus.
func (*BlockExecutor) ApplyBlock ¶
func (blockExec *BlockExecutor) ApplyBlock( state State, blockID types.BlockID, block *types.Block, ) (State, int64, error)
ApplyBlock 针对状态验证该块,针对应用执行该块,触发相关事件, 提交应用,并保存新状态和响应。它返回新状态和要保留的块高度(修剪较旧的块)。 这是唯一需要从此程序包外部调用以处理和提交整个块的函数。它采用blockID以避免重新计算零件哈希。
func (*BlockExecutor) Commit ¶
func (blockExec *BlockExecutor) Commit( state State, block *types.Block, deliverTxResponses []*abci.ResponseDeliverTx, ) ([]byte, int64, error)
Commit 锁定内存池, 运行ABCI.Commit, 更新内存池 它返回调用abci.Commit(AppHash)的结果和要保留的高度(如果有)。 内存池必须在提交和更新期间锁定,因为通常会在“提交”上重置状态,' 并且必须在内存池中运行新的TX之前针对提交的状态重播旧的TX,以免它们无效。
func (*BlockExecutor) CreateProposalBlock ¶
func (blockExec *BlockExecutor) CreateProposalBlock( height int64, state State, commit *types.Commit, proposerAddr []byte, ) (*types.Block, *types.PartSet)
CreateProposalBlock调用state.MakeBlock,其中包含来自evpool的证据和来自mempool的交易。 最大字节数必须足够大以适合提交。最多分配1/10的块空间用于最大大小的证据。 剩余的部分将被分配给交易,直到最大gas用量。
func (*BlockExecutor) DB ¶
func (blockExec *BlockExecutor) DB() dbm.DB
func (*BlockExecutor) SetEventBus ¶
func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher)
SetEventBus - 设置事件总线以发布与块相关的事件。 如果未调用,则默认为types.NopEventBus。
func (*BlockExecutor) ValidateBlock ¶
func (blockExec *BlockExecutor) ValidateBlock(state State, block *types.Block) error
ValidateBlock 针对给定状态验证给定块。如果该块无效,则返回错误。 验证不会改变状态,但是需要来自stateDB的历史信息,即,验证来自验证者的旧高度的证据。
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 SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) PruneBlocks(height int64) (uint64, error) LoadBlockByHash(hash []byte) *types.Block LoadBlockPart(height int64, index int) *types.Part LoadBlockCommit(height int64) *types.Commit LoadSeenCommit(height int64) *types.Commit }
BlockStore 区块保存接口,实现在store文件夹中
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 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(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 }
证据池接口,实现在evidence文件夹中 Get/Set/Commit
type Metrics ¶
type Metrics struct { // Time between BeginBlock and EndBlock. BlockProcessingTime metrics.Histogram }
Metrics contains metrics exposed by this package.
func PrometheusMetrics ¶
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 测试用证据池
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
type State ¶
type State struct { Version Version // 链ID 整个链中都是不会变化的 ChainID string // LastBlockHeight=0 at genesis (ie. block(H=0) does not exist) LastBlockHeight int64 // 上一个区块ID LastBlockID types.BlockID LastBlockTime time.Time // LastValidators被用于验证block.LastCommit. // 验证器每次更改时都会分别保存到数据库中,因此我们可以查询历史验证器集。 // 注意:如果s.LastBlockHeight导致了验证者集合的改变,我们设置 // s.LastHeightValidatorsChanged = s.LastBlockHeight + 1 + 1 // 由于nextValSet延迟,额外加1 . NextValidators *types.ValidatorSet Validators *types.ValidatorSet LastValidators *types.ValidatorSet LastHeightValidatorsChanged int64 // 共识参数用于验证区块。 // 参数在EndBlock中改变并在commit之后更新。 // 共识参数的配置 主要是 一个区块的大小 一个交易的大小 区块每个部分的大小 ConsensusParams types.ConsensusParams LastHeightConsensusParamsChanged int64 // 执行prev块的结果的Merkle根 LastResultsHash []byte // 我们通过调用abci.Commit()收到的最新AppHash AppHash []byte }
State 是Tendermint共识模块的最新提交的块的简短描述。 它保留所有必要的信息来验证新的区块,包括最后的验证者集合和共识参数。 所有字段都是公开的,因此可以轻松序列化该结构,但是都不应该直接对其进行改变, 而是使用state.Copy()或state.NextState(...)。 NOTE: not goroutine-safe.
func LoadStateFromDBOrGenesisDoc ¶
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 ¶
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 使用创世文件中的数据生成初始状态
func MakeGenesisStateFromFile ¶
MakeGenesisStateFromFile reads and unmarshals state from the given file.
Used during replay and in tests.
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.