diff --git a/Gopkg.lock b/Gopkg.lock index 1acce5a54..aaf83e09b 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -744,7 +744,7 @@ "version", ] pruneopts = "UT" - revision = "164fd2a7e53bf2c47b447dfb1335ac1c1d443e42" + revision = "650b6ddd80d00b193b3ba47a87800e72f12dd619" source = "https://github.com/irisnet/tendermint.git" [[projects]] @@ -932,6 +932,7 @@ "github.com/cosmos/cosmos-sdk/x/slashing", "github.com/cosmos/cosmos-sdk/x/stake", "github.com/cosmos/cosmos-sdk/x/stake/client/rest", + "github.com/cosmos/cosmos-sdk/x/stake/keeper", "github.com/cosmos/cosmos-sdk/x/stake/tags", "github.com/cosmos/cosmos-sdk/x/stake/types", "github.com/emicklei/proto", @@ -966,6 +967,7 @@ "github.com/tendermint/tendermint/crypto", "github.com/tendermint/tendermint/crypto/ed25519", "github.com/tendermint/tendermint/crypto/merkle", + "github.com/tendermint/tendermint/crypto/multisig", "github.com/tendermint/tendermint/crypto/secp256k1", "github.com/tendermint/tendermint/crypto/tmhash", "github.com/tendermint/tendermint/libs/cli", diff --git a/app/app.go b/app/app.go index 5aea29ca4..77f032c91 100644 --- a/app/app.go +++ b/app/app.go @@ -2,7 +2,6 @@ package app import ( "encoding/json" - "errors" "fmt" "io" "os" @@ -10,7 +9,6 @@ import ( "strings" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" @@ -24,21 +22,16 @@ import ( "github.com/irisnet/irishub/iparam" "github.com/irisnet/irishub/modules/gov" "github.com/irisnet/irishub/modules/gov/params" - + "github.com/irisnet/irishub/modules/record" "github.com/irisnet/irishub/modules/service" "github.com/irisnet/irishub/modules/service/params" - "github.com/irisnet/irishub/modules/record" "github.com/irisnet/irishub/modules/upgrade" "github.com/irisnet/irishub/modules/upgrade/params" "github.com/spf13/viper" abci "github.com/tendermint/tendermint/abci/types" - bc "github.com/tendermint/tendermint/blockchain" - tmcli "github.com/tendermint/tendermint/libs/cli" cmn "github.com/tendermint/tendermint/libs/common" dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/node" - sm "github.com/tendermint/tendermint/state" tmtypes "github.com/tendermint/tendermint/types" ) @@ -126,7 +119,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio var lastHeight int64 if viper.GetBool(FlagReplay) { - lastHeight = app.replay() + lastHeight = bam.Replay(app.Logger) } // define the AccountKeeper @@ -502,40 +495,6 @@ func (app *IrisApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode bam.RunTxMode) return result } -func (app *IrisApp) replay() int64 { - ctx := server.NewDefaultContext() - ctx.Config.RootDir = viper.GetString(tmcli.HomeFlag) - dbContext := node.DBContext{"state", ctx.Config} - 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 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")) - } - - return loadHeight -} - //______________________________________________________________________________________________ // Combined Staking Hooks diff --git a/baseapp/replay.go b/baseapp/replay.go new file mode 100644 index 000000000..99374a49c --- /dev/null +++ b/baseapp/replay.go @@ -0,0 +1,54 @@ +package baseapp + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/server" + "github.com/spf13/viper" + bc "github.com/tendermint/tendermint/blockchain" + tmcli "github.com/tendermint/tendermint/libs/cli" + dbm "github.com/tendermint/tendermint/libs/db" + "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/node" + sm "github.com/tendermint/tendermint/state" +) + +func Replay(logger log.Logger) int64 { + ctx := server.NewDefaultContext() + ctx.Config.RootDir = viper.GetString(tmcli.HomeFlag) + dbContext := node.DBContext{"state", ctx.Config} + 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 curState.LastBlockHeight == preState.LastBlockHeight { + panic(fmt.Errorf("there is no block now, can't replay")) + } + var loadHeight int64 + if blockStore.Height() == curState.LastBlockHeight { + logger.Info(fmt.Sprintf("blockstore height equals to current state height %d", curState.LastBlockHeight)) + logger.Info("Just reset state DB to last height") + sm.SaveState(stateDB, preState) + loadHeight = preState.LastBlockHeight + } else if blockStore.Height() == curState.LastBlockHeight+1 { + logger.Info(fmt.Sprintf("blockstore height %d, current state height %d", blockStore.Height(), curState.LastBlockHeight)) + logger.Info(fmt.Sprintf("Retreat block %d in block store and reset state DB to last height", blockStore.Height())) + blockStore.RetreatLastBlock() + sm.SaveState(stateDB, preState) + loadHeight = preState.LastBlockHeight + } else { + panic(fmt.Errorf("tendermint block store height should be at most one ahead of the its state height")) + } + + return loadHeight +} diff --git a/examples/irishub-bugfix-2/app/app.go b/examples/irishub-bugfix-2/app/app.go index 60423b302..2daac7175 100644 --- a/examples/irishub-bugfix-2/app/app.go +++ b/examples/irishub-bugfix-2/app/app.go @@ -2,7 +2,6 @@ package app import ( "encoding/json" - "errors" "fmt" "io" "os" @@ -10,7 +9,6 @@ import ( "strings" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" @@ -32,13 +30,9 @@ import ( "github.com/irisnet/irishub/modules/upgrade/params" "github.com/spf13/viper" abci "github.com/tendermint/tendermint/abci/types" - bc "github.com/tendermint/tendermint/blockchain" - tmcli "github.com/tendermint/tendermint/libs/cli" cmn "github.com/tendermint/tendermint/libs/common" dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/node" - sm "github.com/tendermint/tendermint/state" tmtypes "github.com/tendermint/tendermint/types" ) @@ -127,7 +121,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio var lastHeight int64 if viper.GetBool(FlagReplay) { - lastHeight = app.replay() + lastHeight = bam.Replay(app.Logger) } // define the AccountKeeper @@ -507,40 +501,6 @@ func (app *IrisApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode bam.RunTxMode) return result } -func (app *IrisApp) replay() int64 { - ctx := server.NewDefaultContext() - ctx.Config.RootDir = viper.GetString(tmcli.HomeFlag) - dbContext := node.DBContext{"state", ctx.Config} - 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 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")) - } - - return loadHeight -} - //______________________________________________________________________________________________ // Combined Staking Hooks diff --git a/examples/irishub1/app/app.go b/examples/irishub1/app/app.go index 990b69cb3..973b88551 100644 --- a/examples/irishub1/app/app.go +++ b/examples/irishub1/app/app.go @@ -2,7 +2,6 @@ package app import ( "encoding/json" - "errors" "fmt" "io" "os" @@ -10,7 +9,6 @@ import ( "strings" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" @@ -32,13 +30,9 @@ import ( "github.com/irisnet/irishub/modules/upgrade/params" "github.com/spf13/viper" abci "github.com/tendermint/tendermint/abci/types" - bc "github.com/tendermint/tendermint/blockchain" - tmcli "github.com/tendermint/tendermint/libs/cli" cmn "github.com/tendermint/tendermint/libs/common" dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/node" - sm "github.com/tendermint/tendermint/state" tmtypes "github.com/tendermint/tendermint/types" ) @@ -127,7 +121,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio var lastHeight int64 if viper.GetBool(FlagReplay) { - lastHeight = app.replay() + lastHeight = bam.Replay(app.Logger) } // define the AccountKeeper @@ -507,40 +501,6 @@ func (app *IrisApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode bam.RunTxMode) return result } -func (app *IrisApp) replay() int64 { - ctx := server.NewDefaultContext() - ctx.Config.RootDir = viper.GetString(tmcli.HomeFlag) - dbContext := node.DBContext{"state", ctx.Config} - 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 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")) - } - - return loadHeight -} - //______________________________________________________________________________________________ // Combined Staking Hooks