Browse Source

check appHash

pull/408/head
Ethan Buchman 8 years ago
parent
commit
756213c5f5
2 changed files with 12 additions and 11 deletions
  1. +1
    -1
      consensus/state.go
  2. +11
    -10
      state/execution.go

+ 1
- 1
consensus/state.go View File

@ -253,7 +253,7 @@ type ConsensusState struct {
done chan struct{}
}
// Replay the last block through the consensus and return the AppHash after commit.
// Replay the last block through the consensus and return the AppHash from after Commit.
func ReplayLastBlock(config cfg.Config, state *sm.State, proxyApp proxy.AppConnConsensus, blockStore sm.BlockStore) ([]byte, error) {
mempool := sm.MockMempool{}
cs := NewConsensusState(config, state, proxyApp, blockStore, mempool)


+ 11
- 10
state/execution.go View File

@ -364,19 +364,17 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
// TODO: check version
// replay blocks up to the latest in the blockstore
appHash, err = h.ReplayBlocks(appHash, blockHeight, proxyApp)
_, err = h.ReplayBlocks(appHash, blockHeight, proxyApp)
if err != nil {
return errors.New(Fmt("Error on replay: %v", err))
}
// NOTE: the h.state may now be behind the cs state
// TODO: (on restart) replay mempool
return nil
}
// Replay all blocks after blockHeight and ensure the result matches the current state.
// Replay all blocks since appBlockHeight and ensure the result matches the current state.
// Returns the final AppHash or an error
func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp proxy.AppConns) ([]byte, error) {
@ -386,11 +384,11 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp p
// First handle edge cases and constraints on the storeBlockHeight
if storeBlockHeight == 0 {
return nil, nil
return appHash, h.checkAppHash(appHash)
} else if storeBlockHeight < appBlockHeight {
// the app should never be ahead of the store (but this is under app's control)
return nil, ErrAppBlockHeightTooHigh{storeBlockHeight, appBlockHeight}
return appHash, ErrAppBlockHeightTooHigh{storeBlockHeight, appBlockHeight}
} else if storeBlockHeight < stateBlockHeight {
// the state should never be ahead of the store (this is under tendermint's control)
@ -412,7 +410,7 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp p
} else if appBlockHeight == storeBlockHeight {
// we're good!
return appHash, nil
return appHash, h.checkAppHash(appHash)
}
} else if storeBlockHeight == stateBlockHeight+1 {
@ -473,11 +471,14 @@ func (h *Handshaker) replayBlocks(proxyApp proxy.AppConns, appBlockHeight, store
}
}
return appHash, h.checkAppHash(appHash)
}
func (h *Handshaker) checkAppHash(appHash []byte) error {
if !bytes.Equal(h.state.AppHash, appHash) {
return nil, errors.New(Fmt("Tendermint state.AppHash does not match AppHash after replay. Got %X, expected %X", appHash, h.state.AppHash))
return errors.New(Fmt("Tendermint state.AppHash does not match AppHash after replay. Got %X, expected %X", appHash, h.state.AppHash))
}
return appHash, nil
return nil
}
//--------------------------------------------------------------------------------


Loading…
Cancel
Save