Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug IRISHUB-152: crash in replay #135

Merged
merged 4 commits into from
Aug 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@

[[override]]
name = "github.com/tendermint/iavl"
version = "=v0.9.2"
# version = "=v0.9.2"
branch = "irisnet/feature_upgrade"
source = "https://github.com/irisnet/iavl.git"

[[override]]
name = "github.com/tendermint/tendermint"
Expand Down
29 changes: 23 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/node"
sm "github.com/tendermint/tendermint/state"
bc "github.com/tendermint/tendermint/blockchain"
"strings"
)

Expand Down Expand Up @@ -322,13 +323,29 @@ func (app *IrisApp) replay() int64 {
dbType := dbm.DBBackendType(dbContext.Config.DBBackend)
stateDB := dbm.NewDB(dbContext.ID, dbType, dbContext.Config.DBDir())

blockDBContext := node.DBContext{"blockstore", ctx.Config}
blockStoreDB := dbm.NewDB(blockDBContext.ID, dbType, dbContext.Config.DBDir())
blockStore := bc.NewBlockStore(blockStoreDB)

defer func() {
stateDB.Close()
blockStoreDB.Close()
} ()

curState := sm.LoadState(stateDB)
preState := sm.LoadPreState(stateDB)
if preState.LastBlockHeight == 0 {
panic(errors.New("can't replay the last block, last block height is 0"))
if curState.LastBlockHeight == preState.LastBlockHeight {
panic(errors.New("there is no block now, can't replay"))
}
var loadHeight int64
if blockStore.Height() == curState.LastBlockHeight {
sm.SaveState(stateDB, preState)
loadHeight = preState.LastBlockHeight
} else if blockStore.Height() == curState.LastBlockHeight+1 {
loadHeight = curState.LastBlockHeight
} else {
panic(errors.New("tendermint block store height should be at most one ahead of the its state height"))
}

sm.SaveState(stateDB, preState)
stateDB.Close()

return preState.LastBlockHeight
return loadHeight
}