Skip to content

Commit

Permalink
Merge pull request #4 from irisnet/irisnet/develop
Browse files Browse the repository at this point in the history
Release/v0.22.6-iris1
  • Loading branch information
zhangyelong authored Aug 15, 2018
2 parents 5fdbcd7 + 65e95fb commit fb697db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
// database keys
var (
stateKey = []byte("stateKey")
//////////////////// iris/tendermint begin ///////////////////////////
statePreKey = []byte("statePreKey")
//////////////////// iris/tendermint end ///////////////////////////
)

//-----------------------------------------------------------------------------
Expand Down
16 changes: 15 additions & 1 deletion state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 ///////////////////////////
}

//------------------------------------------------------------------------
Expand Down

0 comments on commit fb697db

Please sign in to comment.