mirror of
https://github.com/fluencelabs/tendermint
synced 2025-08-01 04:31:57 +00:00
applyBlock to simplify replay of many blocks. still wip
This commit is contained in:
@@ -272,6 +272,27 @@ func (s *State) CommitStateUpdateMempool(proxyAppConn proxy.AppConnConsensus, bl
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apply a nd commit a block, but with out all the state validation
|
||||||
|
// returns the application root hash (result of abci.Commit)
|
||||||
|
func applyBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block) ([]byte, error) {
|
||||||
|
var eventCache types.Fireable // nil
|
||||||
|
_, err := execBlockOnProxyApp(eventCache, appConnConsensus, block)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn("Error executing block on proxy app", "height", i, "err", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Commit block, get hash back
|
||||||
|
res := appConnConsensus.CommitSync()
|
||||||
|
if res.IsErr() {
|
||||||
|
log.Warn("Error in proxyAppConn.CommitSync", "error", res)
|
||||||
|
return nil, res
|
||||||
|
}
|
||||||
|
if res.Log != "" {
|
||||||
|
log.Info("Commit.Log: " + res.Log)
|
||||||
|
}
|
||||||
|
return res.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Updates to the mempool need to be synchronized with committing a block
|
// Updates to the mempool need to be synchronized with committing a block
|
||||||
// so apps can reset their transient state on Commit
|
// so apps can reset their transient state on Commit
|
||||||
type Mempool interface {
|
type Mempool interface {
|
||||||
@@ -382,39 +403,25 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp p
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// store is more than one ahead,
|
// store is more than one ahead,
|
||||||
// so app wants to replay many blocks
|
// so app wants to replay many blocks.
|
||||||
/*
|
// replay all blocks from appBlockHeight+1 to storeBlockHeight-1.
|
||||||
|
// Replay the final block through consensus
|
||||||
|
|
||||||
// replay all blocks starting with appBlockHeight+1
|
var appHash []byte
|
||||||
var eventCache types.Fireable // nil
|
var err error
|
||||||
|
for i := appBlockHeight + 1; i <= storeBlockHeight-1; i++ {
|
||||||
// TODO: use stateBlockHeight instead and let the consensus state
|
h.nBlocks += 1
|
||||||
// do the replay
|
block := h.store.LoadBlock(i)
|
||||||
|
appHash, err = applyBlock(proxyApp.Consensus(), block)
|
||||||
var appHash []byte
|
if err != nil {
|
||||||
for i := appBlockHeight + 1; i <= storeBlockHeight; i++ {
|
return err
|
||||||
h.nBlocks += 1
|
|
||||||
block := h.store.LoadBlock(i)
|
|
||||||
_, err := execBlockOnProxyApp(eventCache, appConnConsensus, block)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("Error executing block on proxy app", "height", i, "err", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Commit block, get hash back
|
|
||||||
res := appConnConsensus.CommitSync()
|
|
||||||
if res.IsErr() {
|
|
||||||
log.Warn("Error in proxyAppConn.CommitSync", "error", res)
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
if res.Log != "" {
|
|
||||||
log.Info("Commit.Log: " + res.Log)
|
|
||||||
}
|
|
||||||
appHash = res.Data
|
|
||||||
}
|
}
|
||||||
if !bytes.Equal(h.state.AppHash, appHash) {
|
}
|
||||||
return errors.New(Fmt("Tendermint state.AppHash does not match AppHash after replay. Got %X, expected %X", appHash, h.state.AppHash))
|
|
||||||
}
|
h.replayLastBlock(h.config, h.state, proxyApp.Consensus(), h.store)
|
||||||
*/
|
if !bytes.Equal(h.state.AppHash, appHash) {
|
||||||
|
return errors.New(Fmt("Tendermint state.AppHash does not match AppHash after replay. Got %X, expected %X", appHash, h.state.AppHash))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user