Skip to content

Commit

Permalink
Deprecate LoadLatest flag (#228)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
This flag is redundant since it should always be set to the opposite of
DBSync.Enable (in tendermint config)

## Testing performed to validate your change
loadtest cluster
  • Loading branch information
codchen authored Apr 26, 2023
1 parent 355f18b commit ec35e9c
Show file tree
Hide file tree
Showing 27 changed files with 78 additions and 92 deletions.
18 changes: 9 additions & 9 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ func TestGetBlockRentionHeight(t *testing.T) {
expected int64
}{
"defaults": {
bapp: NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{}),
bapp: NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{}),
maxAgeBlocks: 0,
commitHeight: 499000,
expected: 0,
},
"pruning unbonding time only": {
bapp: NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{}, SetMinRetainBlocks(1)),
bapp: NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{}, SetMinRetainBlocks(1)),
maxAgeBlocks: 362880,
commitHeight: 499000,
expected: 136120,
},
"pruning iavl snapshot only": {
bapp: NewBaseApp(
name, logger, db, nil, &testutil.TestAppOpts{},
name, logger, db, nil, nil, &testutil.TestAppOpts{},
SetPruning(sdk.PruningOptions{KeepEvery: 10000}),
SetMinRetainBlocks(1),
),
Expand All @@ -50,7 +50,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"pruning state sync snapshot only": {
bapp: NewBaseApp(
name, logger, db, nil, &testutil.TestAppOpts{},
name, logger, db, nil, nil, &testutil.TestAppOpts{},
SetSnapshotInterval(50000),
SetSnapshotKeepRecent(3),
SetMinRetainBlocks(1),
Expand All @@ -61,7 +61,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"pruning min retention only": {
bapp: NewBaseApp(
name, logger, db, nil, &testutil.TestAppOpts{},
name, logger, db, nil, nil, &testutil.TestAppOpts{},
SetMinRetainBlocks(400000),
),
maxAgeBlocks: 0,
Expand All @@ -70,7 +70,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"pruning all conditions": {
bapp: NewBaseApp(
name, logger, db, nil, &testutil.TestAppOpts{},
name, logger, db, nil, nil, &testutil.TestAppOpts{},
SetPruning(sdk.PruningOptions{KeepEvery: 10000}),
SetMinRetainBlocks(400000),
SetSnapshotInterval(50000), SetSnapshotKeepRecent(3),
Expand All @@ -81,7 +81,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"no pruning due to no persisted state": {
bapp: NewBaseApp(
name, logger, db, nil, &testutil.TestAppOpts{},
name, logger, db, nil, nil, &testutil.TestAppOpts{},
SetPruning(sdk.PruningOptions{KeepEvery: 10000}),
SetMinRetainBlocks(400000),
SetSnapshotInterval(50000), SetSnapshotKeepRecent(3),
Expand All @@ -92,7 +92,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
},
"disable pruning": {
bapp: NewBaseApp(
name, logger, db, nil, &testutil.TestAppOpts{},
name, logger, db, nil, nil, &testutil.TestAppOpts{},
SetPruning(sdk.PruningOptions{KeepEvery: 10000}),
SetMinRetainBlocks(0),
SetSnapshotInterval(50000), SetSnapshotKeepRecent(3),
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestBaseAppCreateQueryContext(t *testing.T) {
logger := defaultLogger()
db := dbm.NewMemDB()
name := t.Name()
app := NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{})
app := NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{})

app.FinalizeBlock(context.Background(), &abci.RequestFinalizeBlock{Height: 1})
app.SetDeliverStateToCommit()
Expand Down
11 changes: 4 additions & 7 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type BaseApp struct { //nolint: maligned

compactionInterval uint64

tmConfig *tmcfg.Config
TmConfig *tmcfg.Config
}

type appStore struct {
Expand Down Expand Up @@ -207,7 +207,7 @@ type snapshotData struct {
//
// NOTE: The db is used to store the version number for now.
func NewBaseApp(
name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, appOpts servertypes.AppOptions, options ...func(*BaseApp),
name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, tmConfig *tmcfg.Config, appOpts servertypes.AppOptions, options ...func(*BaseApp),
) *BaseApp {
cms := store.NewCommitMultiStore(db)
archivalVersion := cast.ToInt64(appOpts.Get(FlagArchivalVersion))
Expand Down Expand Up @@ -239,6 +239,7 @@ func NewBaseApp(
msgServiceRouter: NewMsgServiceRouter(),
},
txDecoder: txDecoder,
TmConfig: tmConfig,
}

for _, option := range options {
Expand All @@ -259,10 +260,6 @@ func NewBaseApp(
return app
}

func (app *BaseApp) SetTendermintConfig(cfg *tmcfg.Config) {
app.tmConfig = cfg
}

// Name returns the name of the BaseApp.
func (app *BaseApp) Name() string {
return app.name
Expand Down Expand Up @@ -1112,7 +1109,7 @@ func (app *BaseApp) ReloadDB() error {
if err := app.db.Close(); err != nil {
return err
}
db, err := sdk.NewLevelDB("application", app.tmConfig.DBDir())
db, err := sdk.NewLevelDB("application", app.TmConfig.DBDir())
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp {
db := dbm.NewMemDB()
codec := codec.NewLegacyAmino()
registerTestCodec(codec)
return NewBaseApp(name, logger, db, testTxDecoder(codec), &testutil.TestAppOpts{}, options...)
return NewBaseApp(name, logger, db, testTxDecoder(codec), nil, &testutil.TestAppOpts{}, options...)
}

func registerTestCodec(cdc *codec.LegacyAmino) {
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestLoadVersionPruning(t *testing.T) {
pruningOpt := SetPruning(pruningOptions)
db := dbm.NewMemDB()
name := t.Name()
app := NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{}, pruningOpt)
app := NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{}, pruningOpt)

// make a cap key and mount the store
capKey := sdk.NewKVStoreKey("key1")
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestLoadVersionPruning(t *testing.T) {
}

// reload with LoadLatestVersion, check it loads last version
app = NewBaseApp(name, logger, db, nil, &testutil.TestAppOpts{}, pruningOpt)
app = NewBaseApp(name, logger, db, nil, nil, &testutil.TestAppOpts{}, pruningOpt)
app.MountStores(capKey)

err = app.LoadLatestVersion()
Expand Down
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
encCfg.InterfaceRegistry.RegisterImplementations((*sdk.Msg)(nil),
&testdata.TestMsg{},
)
app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, "", 0, encCfg, &simapp.EmptyAppOptions{}, routerOpt)
app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, "", 0, nil, encCfg, &simapp.EmptyAppOptions{}, routerOpt)
genState := simapp.NewDefaultGenesisState(encCfg.Marshaler)
stateBytes, err := json.MarshalIndent(genState, "", " ")
require.NoError(t, err)
Expand Down
22 changes: 11 additions & 11 deletions baseapp/deliver_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestBaseApp_EndBlock(t *testing.T) {
}

codec := codec.NewLegacyAmino()
app := NewBaseApp(name, logger, db, testTxDecoder(codec), &testutil.TestAppOpts{})
app := NewBaseApp(name, logger, db, testTxDecoder(codec), nil, &testutil.TestAppOpts{})
app.SetParamStore(&paramStore{db: dbm.NewMemDB()})
app.InitChain(context.Background(), &abci.RequestInitChain{
ConsensusParams: cp,
Expand Down Expand Up @@ -1062,7 +1062,7 @@ func TestInitChainer(t *testing.T) {
db := dbm.NewMemDB()
logger := defaultLogger()
cc := codec.NewLegacyAmino()
app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{})
app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{})
capKey := sdk.NewKVStoreKey("main")
capKey2 := sdk.NewKVStoreKey("key2")
app.MountStores(capKey, capKey2)
Expand Down Expand Up @@ -1118,7 +1118,7 @@ func TestInitChainer(t *testing.T) {

// reload app
cc = codec.NewLegacyAmino()
app = NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{})
app = NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{})
app.SetInitChainer(initChainer)
app.MountStores(capKey, capKey2)
err = app.LoadLatestVersion() // needed to make stores non-nil
Expand Down Expand Up @@ -1146,7 +1146,7 @@ func TestInitChain_WithInitialHeight(t *testing.T) {
db := dbm.NewMemDB()
logger := defaultLogger()
cc := codec.NewLegacyAmino()
app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{})
app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{})

app.InitChain(
context.Background(), &abci.RequestInitChain{
Expand All @@ -1163,7 +1163,7 @@ func TestBeginBlock_WithInitialHeight(t *testing.T) {
db := dbm.NewMemDB()
logger := defaultLogger()
cc := codec.NewLegacyAmino()
app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{})
app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{})

app.InitChain(
context.Background(), &abci.RequestInitChain{
Expand Down Expand Up @@ -1539,7 +1539,7 @@ func TestOptionFunction(t *testing.T) {
logger := defaultLogger()
db := dbm.NewMemDB()
cc := codec.NewLegacyAmino()
bap := NewBaseApp("starting name", logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, testChangeNameHelper("new name"))
bap := NewBaseApp("starting name", logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, testChangeNameHelper("new name"))
require.Equal(t, bap.name, "new name", "BaseApp should have had name changed via option function")
}

Expand Down Expand Up @@ -1631,7 +1631,7 @@ func TestVersionSetterGetter(t *testing.T) {
db := dbm.NewMemDB()
name := t.Name()
cc := codec.NewLegacyAmino()
app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, pruningOpt)
app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, pruningOpt)

require.Equal(t, "", app.Version())
res, _ := app.Query(context.Background(), &abci.RequestQuery{Path: "app/version"})
Expand All @@ -1652,7 +1652,7 @@ func TestLoadVersionInvalid(t *testing.T) {
db := dbm.NewMemDB()
name := t.Name()
cc := codec.NewLegacyAmino()
app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, pruningOpt)
app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, pruningOpt)

err := app.LoadLatestVersion()
require.Nil(t, err)
Expand All @@ -1670,7 +1670,7 @@ func TestLoadVersionInvalid(t *testing.T) {

// create a new app with the stores mounted under the same cap key
cc = codec.NewLegacyAmino()
app = NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, pruningOpt)
app = NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, pruningOpt)

// require we can load the latest version
err = app.LoadVersion(1)
Expand Down Expand Up @@ -1776,7 +1776,7 @@ func TestLoadVersion(t *testing.T) {
db := dbm.NewMemDB()
name := t.Name()
cc := codec.NewLegacyAmino()
app := NewBaseApp(name, logger, db, testTxDecoder(cc), &testutil.TestAppOpts{}, pruningOpt)
app := NewBaseApp(name, logger, db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, pruningOpt)

// make a cap key and mount the store
err := app.LoadLatestVersion() // needed to make stores non-nil
Expand Down Expand Up @@ -1878,7 +1878,7 @@ func TestSetLoader(t *testing.T) {
opts = append(opts, tc.setLoader)
}
cc := codec.NewLegacyAmino()
app := NewBaseApp(t.Name(), defaultLogger(), db, testTxDecoder(cc), &testutil.TestAppOpts{}, opts...)
app := NewBaseApp(t.Name(), defaultLogger(), db, testTxDecoder(cc), nil, &testutil.TestAppOpts{}, opts...)
app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey))
err := app.LoadLatestVersion()
require.Nil(t, err)
Expand Down
5 changes: 3 additions & 2 deletions baseapp/grpcrouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package baseapp_test

import (
"context"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"testing"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestRegisterQueryServiceTwice(t *testing.T) {
// Setup baseapp.
db := dbm.NewMemDB()
encCfg := simapp.MakeTestEncodingConfig()
app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), &testutil.TestAppOpts{})
app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), nil, &testutil.TestAppOpts{})
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)

Expand Down
6 changes: 3 additions & 3 deletions baseapp/msg_service_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestRegisterMsgService(t *testing.T) {

// Create an encoding config that doesn't register testdata Msg services.
encCfg := simapp.MakeTestEncodingConfig()
app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), &testutil.TestAppOpts{})
app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), nil, &testutil.TestAppOpts{})
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
require.Panics(t, func() {
testdata.RegisterMsgServer(
Expand All @@ -47,7 +47,7 @@ func TestRegisterMsgServiceTwice(t *testing.T) {
// Setup baseapp.
db := dbm.NewMemDB()
encCfg := simapp.MakeTestEncodingConfig()
app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), &testutil.TestAppOpts{})
app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), nil, &testutil.TestAppOpts{})
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)

Expand All @@ -73,7 +73,7 @@ func TestMsgService(t *testing.T) {
encCfg := simapp.MakeTestEncodingConfig()
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)
db := dbm.NewMemDB()
app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), &testutil.TestAppOpts{})
app := baseapp.NewBaseApp("test", log.NewTestingLogger(t), db, encCfg.TxConfig.TxDecoder(), nil, &testutil.TestAppOpts{})
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
testdata.RegisterMsgServer(
app.MsgServiceRouter(),
Expand Down
2 changes: 1 addition & 1 deletion client/pruning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command {
}

logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
app := appCreator(logger, db, nil, vp)
app := appCreator(logger, db, nil, nil, vp)
cms := app.CommitMultiStore()

rootMultiStore, ok := cms.(*rootmulti.Store)
Expand Down
10 changes: 0 additions & 10 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ type BaseConfig struct {
// CompactionInterval sets (in seconds) the interval between forced levelDB
// compaction. A value of 0 means no forced levelDB
CompactionInterval uint64 `mapstructure:"compaction-interval"`

LoadLatest bool `mapstructure:"load-latest"`
}

// APIConfig defines the API listener configuration.
Expand Down Expand Up @@ -225,7 +223,6 @@ func DefaultConfig() *Config {
IAVLCacheSize: 781250, // 50 MB
IAVLDisableFastNode: true,
CompactionInterval: 0,
LoadLatest: true,
},
Telemetry: telemetry.Config{
Enabled: false,
Expand Down Expand Up @@ -294,7 +291,6 @@ func GetConfig(v *viper.Viper) (Config, error) {
IAVLCacheSize: v.GetUint64("iavl-cache-size"),
IAVLDisableFastNode: v.GetBool("iavl-disable-fastnode"),
CompactionInterval: v.GetUint64("compaction-interval"),
LoadLatest: v.GetBool("load-latest"),
},
Telemetry: telemetry.Config{
ServiceName: v.GetString("telemetry.service-name"),
Expand Down Expand Up @@ -349,12 +345,6 @@ func (c Config) ValidateBasic(tendermintConfig *tmcfg.Config) error {
"cannot enable state sync snapshots with '%s' pruning setting", storetypes.PruningOptionEverything,
)
}
if c.BaseConfig.LoadLatest && tendermintConfig.DBSync.Enable {
return sdkerrors.ErrAppConfig.Wrap("cannot load latest with DB sync enabled")
}
if !c.BaseConfig.LoadLatest && !tendermintConfig.DBSync.Enable {
return sdkerrors.ErrAppConfig.Wrap("shoulkd load latest with DB sync disabled")
}

return nil
}
3 changes: 0 additions & 3 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ min-retain-blocks = {{ .BaseConfig.MinRetainBlocks }}
# InterBlockCache enables inter-block caching.
inter-block-cache = {{ .BaseConfig.InterBlockCache }}
# Whether to load the latest version of store immediately upon start
load-latest = {{ .BaseConfig.LoadLatest }}
# IndexEvents defines the set of events in the form {eventType}.{attributeKey},
# which informs Tendermint what to index. If empty, all events will be indexed.
#
Expand Down
6 changes: 3 additions & 3 deletions server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t
logger := log.NewTestingLogger(t)
db := dbm.NewMemDB()
encCfg := simapp.MakeTestEncodingConfig()
app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg, &simapp.EmptyAppOptions{})
app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, nil, encCfg, &simapp.EmptyAppOptions{})

serverCtx := server.NewDefaultContext()
serverCtx.Config.RootDir = tempDir
Expand All @@ -152,13 +152,13 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t

var simApp *simapp.SimApp
if height != -1 {
simApp = simapp.NewSimApp(logger, db, nil, false, map[int64]bool{}, "", 0, encCfg, &simapp.EmptyAppOptions{})
simApp = simapp.NewSimApp(logger, db, nil, false, map[int64]bool{}, "", 0, nil, encCfg, &simapp.EmptyAppOptions{})

if err := simApp.LoadHeight(height); err != nil {
return types.ExportedApp{}, err
}
} else {
simApp = simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, "", 0, encCfg, &simapp.EmptyAppOptions{})
simApp = simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, "", 0, nil, encCfg, &simapp.EmptyAppOptions{})
}

return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
Expand Down
Loading

0 comments on commit ec35e9c

Please sign in to comment.