diff --git a/Gopkg.lock b/Gopkg.lock index 69ccbb848..b032ac5f8 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -413,10 +413,11 @@ version = "0.10.1" [[projects]] + branch = "irisnet/feature_upgrade" name = "github.com/tendermint/iavl" packages = ["."] - revision = "35f66e53d9b01e83b30de68b931f54b2477a94c9" - version = "v0.9.2" + revision = "849c21e8f93ce782cb9f9f64fabcccb5580b4f90" + source = "https://github.com/irisnet/iavl.git" [[projects]] name = "github.com/tendermint/tendermint" diff --git a/Gopkg.toml b/Gopkg.toml index 4ecc85193..5c25024be 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -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" diff --git a/app/app.go b/app/app.go index 2d17754ba..0ce2d88c0 100644 --- a/app/app.go +++ b/app/app.go @@ -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" ) @@ -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 }