diff --git a/state/execution.go b/state/execution.go index f38f5e0bb9a..90520a1fd4c 100644 --- a/state/execution.go +++ b/state/execution.go @@ -86,6 +86,9 @@ func (blockExec *BlockExecutor) ApplyBlock(state State, blockID types.BlockID, b fail.Fail() // XXX // update the state with the block and responses + //////////////////// iris/tendermint begin /////////////////////////// + preState := state.Copy() + //////////////////// iris/tendermint end /////////////////////////// state, err = updateState(state, blockID, &block.Header, abciResponses) if err != nil { return state, fmt.Errorf("Commit failed for application: %v", err) @@ -105,6 +108,9 @@ func (blockExec *BlockExecutor) ApplyBlock(state State, blockID types.BlockID, b // update the app hash and save the state state.AppHash = appHash SaveState(blockExec.db, state) + //////////////////// iris/tendermint begin /////////////////////////// + SavePreState(blockExec.db, preState) + //////////////////// iris/tendermint end /////////////////////////// fail.Fail() // XXX diff --git a/state/state.go b/state/state.go index fb589a2404b..6dd8e0d610d 100644 --- a/state/state.go +++ b/state/state.go @@ -12,6 +12,9 @@ import ( // database keys var ( stateKey = []byte("stateKey") + //////////////////// iris/tendermint begin /////////////////////////// + statePreKey = []byte("statePreKey") + //////////////////// iris/tendermint end /////////////////////////// ) //----------------------------------------------------------------------------- diff --git a/state/store.go b/state/store.go index 9e94e36faab..a5a311a6186 100644 --- a/state/store.go +++ b/state/store.go @@ -62,6 +62,12 @@ func LoadState(db dbm.DB) State { return loadState(db, stateKey) } +//////////////////// iris/tendermint begin /////////////////////////// +func LoadPreState(db dbm.DB) State { + return loadState(db, statePreKey) +} +//////////////////// iris/tendermint end /////////////////////////// + func loadState(db dbm.DB, key []byte) (state State) { buf := db.Get(key) if len(buf) == 0 { @@ -84,11 +90,19 @@ func SaveState(db dbm.DB, state State) { saveState(db, state, stateKey) } +//////////////////// iris/tendermint begin /////////////////////////// +func SavePreState(db dbm.DB, state State) { + saveState(db, state, statePreKey) +} +//////////////////// iris/tendermint end /////////////////////////// + func saveState(db dbm.DB, state State, key []byte) { nextHeight := state.LastBlockHeight + 1 saveValidatorsInfo(db, nextHeight, state.LastHeightValidatorsChanged, state.Validators) saveConsensusParamsInfo(db, nextHeight, state.LastHeightConsensusParamsChanged, state.ConsensusParams) - db.SetSync(stateKey, state.Bytes()) + //////////////////// iris/tendermint begin /////////////////////////// + db.SetSync(key, state.Bytes()) + //////////////////// iris/tendermint end /////////////////////////// } //------------------------------------------------------------------------