mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-22 01:11:32 +00:00
ValidateBlock is a method on blockExec
This commit is contained in:
@ -153,6 +153,7 @@ func (cs *ConsensusState) SetLogger(l log.Logger) {
|
|||||||
// SetEventBus sets event bus.
|
// SetEventBus sets event bus.
|
||||||
func (cs *ConsensusState) SetEventBus(b *types.EventBus) {
|
func (cs *ConsensusState) SetEventBus(b *types.EventBus) {
|
||||||
cs.eventBus = b
|
cs.eventBus = b
|
||||||
|
cs.blockExec.SetEventBus(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a string.
|
// String returns a string.
|
||||||
@ -922,7 +923,7 @@ func (cs *ConsensusState) defaultDoPrevote(height int64, round int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate proposal block
|
// Validate proposal block
|
||||||
err := sm.ValidateBlock(cs.state, cs.ProposalBlock)
|
err := cs.blockExec.ValidateBlock(cs.state, cs.ProposalBlock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// ProposalBlock is invalid, prevote nil.
|
// ProposalBlock is invalid, prevote nil.
|
||||||
logger.Error("enterPrevote: ProposalBlock is invalid", "err", err)
|
logger.Error("enterPrevote: ProposalBlock is invalid", "err", err)
|
||||||
@ -1030,7 +1031,7 @@ func (cs *ConsensusState) enterPrecommit(height int64, round int) {
|
|||||||
if cs.ProposalBlock.HashesTo(blockID.Hash) {
|
if cs.ProposalBlock.HashesTo(blockID.Hash) {
|
||||||
cs.Logger.Info("enterPrecommit: +2/3 prevoted proposal block. Locking", "hash", blockID.Hash)
|
cs.Logger.Info("enterPrecommit: +2/3 prevoted proposal block. Locking", "hash", blockID.Hash)
|
||||||
// Validate the block.
|
// Validate the block.
|
||||||
if err := sm.ValidateBlock(cs.state, cs.ProposalBlock); err != nil {
|
if err := cs.blockExec.ValidateBlock(cs.state, cs.ProposalBlock); err != nil {
|
||||||
cmn.PanicConsensus(cmn.Fmt("enterPrecommit: +2/3 prevoted for an invalid block: %v", err))
|
cmn.PanicConsensus(cmn.Fmt("enterPrecommit: +2/3 prevoted for an invalid block: %v", err))
|
||||||
}
|
}
|
||||||
cs.LockedRound = round
|
cs.LockedRound = round
|
||||||
@ -1165,7 +1166,7 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
|
|||||||
if !block.HashesTo(blockID.Hash) {
|
if !block.HashesTo(blockID.Hash) {
|
||||||
cmn.PanicSanity(cmn.Fmt("Cannot finalizeCommit, ProposalBlock does not hash to commit hash"))
|
cmn.PanicSanity(cmn.Fmt("Cannot finalizeCommit, ProposalBlock does not hash to commit hash"))
|
||||||
}
|
}
|
||||||
if err := sm.ValidateBlock(cs.state, block); err != nil {
|
if err := cs.blockExec.ValidateBlock(cs.state, block); err != nil {
|
||||||
cmn.PanicConsensus(cmn.Fmt("+2/3 committed an invalid block: %v", err))
|
cmn.PanicConsensus(cmn.Fmt("+2/3 committed an invalid block: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ func NewNode(config *cfg.Config,
|
|||||||
eventBus.SetLogger(logger.With("module", "events"))
|
eventBus.SetLogger(logger.With("module", "events"))
|
||||||
|
|
||||||
// services which will be publishing and/or subscribing for messages (events)
|
// services which will be publishing and/or subscribing for messages (events)
|
||||||
blockExec.SetEventBus(eventBus)
|
// consensusReactor will set it on consensusState and blockExecutor
|
||||||
consensusReactor.SetEventBus(eventBus)
|
consensusReactor.SetEventBus(eventBus)
|
||||||
|
|
||||||
// Transaction indexing
|
// Transaction indexing
|
||||||
|
@ -56,6 +56,14 @@ func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher)
|
|||||||
blockExec.eventBus = eventBus
|
blockExec.eventBus = eventBus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 (blockExec *BlockExecutor) ValidateBlock(s State, block *types.Block) error {
|
||||||
|
return validateBlock(blockExec.db, s, block)
|
||||||
|
}
|
||||||
|
|
||||||
// ApplyBlock validates the block against the state, executes it against the app,
|
// ApplyBlock validates the block against the state, executes it against the app,
|
||||||
// fires the relevent events, commits the app, and saves the new state and responses.
|
// fires the relevent events, commits the app, and saves the new state and responses.
|
||||||
// It's the only function that needs to be called
|
// It's the only function that needs to be called
|
||||||
@ -63,7 +71,7 @@ func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher)
|
|||||||
// It takes a blockID to avoid recomputing the parts hash.
|
// It takes a blockID to avoid recomputing the parts hash.
|
||||||
func (blockExec *BlockExecutor) ApplyBlock(s State, blockID types.BlockID, block *types.Block) (State, error) {
|
func (blockExec *BlockExecutor) ApplyBlock(s State, blockID types.BlockID, block *types.Block) (State, error) {
|
||||||
|
|
||||||
if err := validateBlock(s, block); err != nil {
|
if err := blockExec.ValidateBlock(s, block); err != nil {
|
||||||
return s, ErrInvalidBlock(err)
|
return s, ErrInvalidBlock(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,17 +6,18 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
dbm "github.com/tendermint/tmlibs/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
// Validate block
|
// Validate block
|
||||||
|
|
||||||
// ValidateBlock validates the block against the state.
|
// ValidateBlock validates the block against the state.
|
||||||
func ValidateBlock(s State, block *types.Block) error {
|
func _ValidateBlock(s State, block *types.Block) error {
|
||||||
return validateBlock(s, block)
|
return validateBlock(dbm.NewMemDB(), s, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateBlock(s State, b *types.Block) error {
|
func validateBlock(stateDB dbm.DB, s State, b *types.Block) error {
|
||||||
// validate internal consistency
|
// validate internal consistency
|
||||||
if err := b.ValidateBasic(); err != nil {
|
if err := b.ValidateBasic(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user