diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 1280f6a7020a..f40e0fecb4aa 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/gogoproto/jsonpb" "github.com/stretchr/testify/require" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/snapshots" @@ -43,7 +44,7 @@ func TestABCI_Info(t *testing.T) { func TestABCI_InitChain(t *testing.T) { name := t.Name() db := dbm.NewMemDB() - logger := defaultLogger() + logger := log.NewTestLogger(t) app := baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetChainID("test-chain-id")) capKey := sdk.NewKVStoreKey("main") @@ -128,7 +129,7 @@ func TestABCI_InitChain(t *testing.T) { func TestABCI_InitChain_WithInitialHeight(t *testing.T) { name := t.Name() db := dbm.NewMemDB() - logger := defaultLogger() + logger := log.NewTestLogger(t) app := baseapp.NewBaseApp(name, logger, db, nil) app.InitChain( @@ -144,7 +145,7 @@ func TestABCI_InitChain_WithInitialHeight(t *testing.T) { func TestABCI_BeginBlock_WithInitialHeight(t *testing.T) { name := t.Name() db := dbm.NewMemDB() - logger := defaultLogger() + logger := log.NewTestLogger(t) app := baseapp.NewBaseApp(name, logger, db, nil) app.InitChain( @@ -568,7 +569,7 @@ func TestABCI_ApplySnapshotChunk(t *testing.T) { func TestABCI_EndBlock(t *testing.T) { db := dbm.NewMemDB() name := t.Name() - logger := defaultLogger() + logger := log.NewTestLogger(t) cp := &tmproto.ConsensusParams{ Block: &tmproto.BlockParams{ @@ -1213,7 +1214,7 @@ func TestABCI_Query(t *testing.T) { } func TestABCI_GetBlockRetentionHeight(t *testing.T) { - logger := defaultLogger() + logger := log.NewTestLogger(t) db := dbm.NewMemDB() name := t.Name() diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 3e80c44e25e5..22cdec357f24 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -58,10 +58,9 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) - logger := defaultLogger() db := dbm.NewMemDB() - app := baseapp.NewBaseApp(t.Name(), logger, db, txConfig.TxDecoder(), opts...) + app := baseapp.NewBaseApp(t.Name(), log.NewTestLogger(t), db, txConfig.TxDecoder(), opts...) require.Equal(t, t.Name(), app.Name()) app.SetInterfaceRegistry(cdc.InterfaceRegistry()) @@ -158,11 +157,10 @@ func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...fun } func TestLoadVersion(t *testing.T) { - logger := defaultLogger() pruningOpt := baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil, pruningOpt) // make a cap key and mount the store err := app.LoadLatestVersion() // needed to make stores non-nil @@ -189,7 +187,7 @@ func TestLoadVersion(t *testing.T) { commitID2 := storetypes.CommitID{Version: 2, Hash: res.Data} // reload with LoadLatestVersion - app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app = baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil, pruningOpt) app.MountStores() err = app.LoadLatestVersion() @@ -199,7 +197,7 @@ func TestLoadVersion(t *testing.T) { // Reload with LoadVersion, see if you can commit the same block and get // the same result. - app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app = baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil, pruningOpt) err = app.LoadVersion(1) require.Nil(t, err) @@ -283,7 +281,7 @@ func TestSetLoader(t *testing.T) { if tc.setLoader != nil { opts = append(opts, tc.setLoader) } - app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) + app := baseapp.NewBaseApp(t.Name(), log.NewTestLogger(t), db, nil, opts...) app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) err := app.LoadLatestVersion() require.Nil(t, err) @@ -301,11 +299,10 @@ func TestSetLoader(t *testing.T) { } func TestVersionSetterGetter(t *testing.T) { - logger := defaultLogger() pruningOpt := baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault)) db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil, pruningOpt) require.Equal(t, "", app.Version()) res := app.Query(abci.RequestQuery{Path: "app/version"}) @@ -360,9 +357,8 @@ func TestOptionFunction(t *testing.T) { } } - logger := defaultLogger() db := dbm.NewMemDB() - bap := baseapp.NewBaseApp("starting name", logger, db, nil, testChangeNameHelper("new name")) + bap := baseapp.NewBaseApp("starting name", log.NewTestLogger(t), db, nil, testChangeNameHelper("new name")) require.Equal(t, bap.Name(), "new name", "BaseApp should have had name changed via option function") } @@ -542,10 +538,9 @@ func TestBaseAppAnteHandler(t *testing.T) { func TestABCI_CreateQueryContext(t *testing.T) { t.Parallel() - logger := defaultLogger() db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 1}}) app.Commit() diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 71b269536bb6..e3733bfe5088 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -6,7 +6,6 @@ import ( "math" "testing" - "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmjson "github.com/cometbft/cometbft/libs/json" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -15,6 +14,7 @@ import ( "cosmossdk.io/depinject" + "cosmossdk.io/log" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" @@ -81,7 +81,8 @@ func TestBaseApp_BlockGas(t *testing.T) { err error ) - appConfig := depinject.Configs(makeTestConfig()) + appConfig := depinject.Configs( + makeTestConfig(), depinject.Supply(log.NewNopLogger())) err = depinject.Inject(appConfig, &bankKeeper, @@ -93,7 +94,7 @@ func TestBaseApp_BlockGas(t *testing.T) { &appBuilder) require.NoError(t, err) - bapp := appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil) + bapp := appBuilder.Build(dbm.NewMemDB(), nil) err = bapp.Load(true) require.NoError(t, err) diff --git a/baseapp/grpcrouter_test.go b/baseapp/grpcrouter_test.go index 476241ff45d4..df0b11c02c3a 100644 --- a/baseapp/grpcrouter_test.go +++ b/baseapp/grpcrouter_test.go @@ -2,15 +2,14 @@ package baseapp_test import ( "context" - "os" "sync" "testing" - "cosmossdk.io/log" dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -56,10 +55,14 @@ func TestGRPCQueryRouter(t *testing.T) { func TestRegisterQueryServiceTwice(t *testing.T) { // Setup baseapp. var appBuilder *runtime.AppBuilder - err := depinject.Inject(makeMinimalConfig(), &appBuilder) + err := depinject.Inject( + depinject.Configs( + makeMinimalConfig(), + depinject.Supply(log.NewNopLogger()), + ), &appBuilder) require.NoError(t, err) db := dbm.NewMemDB() - app := appBuilder.Build(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil) + app := appBuilder.Build(db, nil) // First time registering service shouldn't panic. require.NotPanics(t, func() { diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 3d866c7ae8d6..eeb1d9b165eb 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -1,16 +1,15 @@ package baseapp_test import ( - "os" "testing" - "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -27,9 +26,13 @@ func TestRegisterMsgService(t *testing.T) { appBuilder *runtime.AppBuilder registry codectypes.InterfaceRegistry ) - err := depinject.Inject(makeMinimalConfig(), &appBuilder, ®istry) + err := depinject.Inject( + depinject.Configs( + makeMinimalConfig(), + depinject.Supply(log.NewNopLogger()), + ), &appBuilder, ®istry) require.NoError(t, err) - app := appBuilder.Build(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), dbm.NewMemDB(), nil) + app := appBuilder.Build(dbm.NewMemDB(), nil) require.Panics(t, func() { testdata.RegisterMsgServer( @@ -55,10 +58,14 @@ func TestRegisterMsgServiceTwice(t *testing.T) { appBuilder *runtime.AppBuilder registry codectypes.InterfaceRegistry ) - err := depinject.Inject(makeMinimalConfig(), &appBuilder, ®istry) + err := depinject.Inject( + depinject.Configs( + makeMinimalConfig(), + depinject.Supply(log.NewNopLogger()), + ), &appBuilder, ®istry) require.NoError(t, err) db := dbm.NewMemDB() - app := appBuilder.Build(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil) + app := appBuilder.Build(db, nil) testdata.RegisterInterfaces(registry) // First time registering service shouldn't panic. @@ -86,9 +93,13 @@ func TestMsgService(t *testing.T) { cdc codec.ProtoCodecMarshaler interfaceRegistry codectypes.InterfaceRegistry ) - err := depinject.Inject(makeMinimalConfig(), &appBuilder, &cdc, &interfaceRegistry) + err := depinject.Inject( + depinject.Configs( + makeMinimalConfig(), + depinject.Supply(log.NewNopLogger()), + ), &appBuilder, &cdc, &interfaceRegistry) require.NoError(t, err) - app := appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil) + app := appBuilder.Build(dbm.NewMemDB(), nil) // patch in TxConfig instead of using an output from x/auth/tx txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index eb6e82665b6c..9a5dcd16589d 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "net/url" - "os" "reflect" "strconv" "testing" @@ -25,7 +24,6 @@ import ( txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" "cosmossdk.io/core/appconfig" "cosmossdk.io/depinject" - "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmtypes "github.com/cometbft/cometbft/types" dbm "github.com/cosmos/cosmos-db" @@ -62,14 +60,6 @@ var ( ParamStoreKey = []byte("paramstore") ) -func defaultLogger() log.Logger { - if testing.Verbose() { - return log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "baseapp/test") - } - - return log.NewNopLogger() -} - // GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts // that also act as delegators. func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]json.RawMessage { diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index 5e7533d7c80f..d45097687f0f 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -4,7 +4,6 @@ import ( "context" "testing" - "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmjson "github.com/cometbft/cometbft/libs/json" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -14,6 +13,7 @@ import ( "google.golang.org/grpc/metadata" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -51,10 +51,13 @@ func (s *IntegrationTestSuite) SetupSuite() { // TODO duplicated from testutils/sims/app_helpers.go // need more composable startup options for simapp, this test needed a handle to the closed over genesis account // to query balances - err := depinject.Inject(testutil.AppConfig, &interfaceRegistry, &bankKeeper, &appBuilder, &cdc) + err := depinject.Inject(depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &interfaceRegistry, &bankKeeper, &appBuilder, &cdc) s.NoError(err) - app := appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil) + app := appBuilder.Build(dbm.NewMemDB(), nil) err = app.Load(true) s.NoError(err) diff --git a/client/pruning/main.go b/client/pruning/main.go index 0145588dafd7..5c371c070603 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -2,7 +2,6 @@ package pruning import ( "fmt" - "os" "path/filepath" "github.com/spf13/cobra" @@ -80,7 +79,7 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, return err } - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + logger := log.NewLogger(cmd.OutOrStdout()) app := appCreator(logger, db, nil, vp) cms := app.CommitMultiStore() @@ -94,19 +93,10 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, return fmt.Errorf("the database has no valid heights to prune, the latest height: %v", latestHeight) } - var pruningHeights []int64 - for height := int64(1); height < latestHeight; height++ { - if height < latestHeight-int64(pruningOptions.KeepRecent) { - pruningHeights = append(pruningHeights, height) - } - } - if len(pruningHeights) == 0 { - cmd.Println("no heights to prune") - return nil - } - cmd.Printf("pruning heights start from %v, end at %v\n", pruningHeights[0], pruningHeights[len(pruningHeights)-1]) + pruningHeight := latestHeight - int64(pruningOptions.KeepRecent) + cmd.Printf("pruning heights up to %v\n", pruningHeight) - if err = rootMultiStore.PruneStores(false, pruningHeights); err != nil { + if err = rootMultiStore.PruneStores(pruningHeight); err != nil { return err } diff --git a/client/testutil/util.go b/client/testutil/util.go index 8d09f5de4777..f067e5939c0f 100644 --- a/client/testutil/util.go +++ b/client/testutil/util.go @@ -9,6 +9,7 @@ import ( appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" "cosmossdk.io/core/appconfig" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" _ "github.com/cosmos/cosmos-sdk/runtime" ) @@ -26,7 +27,11 @@ var TestConfig = appconfig.Compose(&appv1alpha1.Config{ func MakeTestCodec(t *testing.T) codec.Codec { var cdc codec.Codec - err := depinject.Inject(TestConfig, &cdc) + err := depinject.Inject( + depinject.Configs( + TestConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(t, err) return cdc } diff --git a/client/tx/aux_builder_test.go b/client/tx/aux_builder_test.go index 5f183c4a9d09..5747676cb344 100644 --- a/client/tx/aux_builder_test.go +++ b/client/tx/aux_builder_test.go @@ -7,6 +7,7 @@ import ( _ "cosmossdk.io/api/cosmos/bank/v1beta1" "cosmossdk.io/depinject" + "cosmossdk.io/log" clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" @@ -24,7 +25,11 @@ func TestAuxTxBuilder(t *testing.T) { reg codectypes.InterfaceRegistry cdc codec.Codec ) - err := depinject.Inject(clienttestutil.TestConfig, ®, &cdc) + err := depinject.Inject( + depinject.Configs( + clienttestutil.TestConfig, + depinject.Supply(log.NewNopLogger()), + ), ®, &cdc) bankModule := bank.AppModuleBasic{} require.NoError(t, err) diff --git a/client/tx/legacy_test.go b/client/tx/legacy_test.go index 640995ae8ad3..36572c49c97e 100644 --- a/client/tx/legacy_test.go +++ b/client/tx/legacy_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" tx2 "github.com/cosmos/cosmos-sdk/client/tx" @@ -70,7 +71,11 @@ func (s *TestSuite) SetupSuite() { reg codectypes.InterfaceRegistry amino *codec.LegacyAmino ) - err := depinject.Inject(clienttestutil.TestConfig, ®, &amino) + err := depinject.Inject( + depinject.Configs( + clienttestutil.TestConfig, + depinject.Supply(log.NewNopLogger()), + ), ®, &amino) require.NoError(s.T(), err) s.protoCfg = tx.NewTxConfig(codec.NewProtoCodec(reg), tx.DefaultSignModes) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index b9eb1a7a42b8..05237165948a 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" clienttestutil "github.com/cosmos/cosmos-sdk/client/testutil" @@ -35,7 +36,11 @@ func newTestTxConfig(t *testing.T) (client.TxConfig, codec.Codec) { pcdc codec.ProtoCodecMarshaler cdc codec.Codec ) - err := depinject.Inject(clienttestutil.TestConfig, &pcdc, &cdc) + err := depinject.Inject( + depinject.Configs( + clienttestutil.TestConfig, + depinject.Supply(log.NewNopLogger()), + ), &pcdc, &cdc) require.NoError(t, err) return authtx.NewTxConfig(pcdc, authtx.DefaultSignModes), cdc } diff --git a/crypto/armor_test.go b/crypto/armor_test.go index bdd7f0d95365..fb311cc71b86 100644 --- a/crypto/armor_test.go +++ b/crypto/armor_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/crypto" @@ -75,7 +76,11 @@ func TestArmorUnarmorPrivKey(t *testing.T) { func TestArmorUnarmorPubKey(t *testing.T) { // Select the encryption and storage for your cryptostore var cdc codec.Codec - err := depinject.Inject(configurator.NewAppConfig(), &cdc) + err := depinject.Inject( + depinject.Configs( + configurator.NewAppConfig(), + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(t, err) cstore := keyring.NewInMemory(cdc) diff --git a/crypto/keys/multisig/multisig_test.go b/crypto/keys/multisig/multisig_test.go index 0d6d51d2166c..abd5fc3bb58f 100644 --- a/crypto/keys/multisig/multisig_test.go +++ b/crypto/keys/multisig/multisig_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/codec/types" @@ -356,7 +357,11 @@ func TestDisplay(t *testing.T) { require.NotEmpty(msig.String()) var cdc codec.Codec - err := depinject.Inject(configurator.NewAppConfig(), &cdc) + err := depinject.Inject( + depinject.Configs( + configurator.NewAppConfig(), + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(err) bz, err := cdc.MarshalInterfaceJSON(msig) require.NoError(err) diff --git a/go.mod b/go.mod index 292282071564..7af711fdf1eb 100644 --- a/go.mod +++ b/go.mod @@ -17,8 +17,6 @@ require ( github.com/chzyer/readline v1.5.1 github.com/cockroachdb/apd/v2 v2.0.2 github.com/cometbft/cometbft v0.37.2 - github.com/cometbft/cometbft-db v0.7.0 - github.com/confio/ics23/go v0.9.0 github.com/cosmos/btcutil v1.0.5 github.com/cosmos/cosmos-db v1.0.0 github.com/cosmos/cosmos-proto v1.0.0-beta.2 @@ -27,6 +25,7 @@ require ( github.com/cosmos/gogogateway v1.2.0 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/iavl v1.0.0 + github.com/cosmos/ics23/go v0.10.0 github.com/cosmos/ledger-cosmos-go v0.12.1 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 @@ -89,7 +88,7 @@ require ( github.com/cockroachdb/pebble v0.0.0-20220817183557-09c6e030a677 // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect - github.com/cosmos/ics23/go v0.10.0 // indirect + github.com/cometbft/cometbft-db v0.7.0 // indirect github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect github.com/danieljoos/wincred v1.1.2 // indirect diff --git a/go.sum b/go.sum index b9e69ef993c8..0ff1bd63b3c2 100644 --- a/go.sum +++ b/go.sum @@ -338,8 +338,6 @@ github.com/cometbft/cometbft v0.37.2 h1:XB0yyHGT0lwmJlFmM4+rsRnczPlHoAKFX6K8Zgc2 github.com/cometbft/cometbft v0.37.2/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs= github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= -github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4= -github.com/confio/ics23/go v0.9.0/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e/mYVRak= github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= diff --git a/orm/types/kv/store.go b/orm/types/kv/store.go index a25ae296ba18..f1281b356a0a 100644 --- a/orm/types/kv/store.go +++ b/orm/types/kv/store.go @@ -33,7 +33,7 @@ type ReadonlyStore interface { ReverseIterator(start, end []byte) (Iterator, error) } -// Iterator aliases github.com/cometbft/cometbft-db.Iterator. +// Iterator aliases github.com/cosmos/cosmos-db.Iterator. type Iterator = dbm.Iterator // Store is an interface for writing to a kv-store. diff --git a/runtime/app.go b/runtime/app.go index b5cfcc54cecb..fef05a74ad8d 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -9,6 +9,7 @@ import ( runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -48,6 +49,7 @@ type App struct { baseAppOptions []BaseAppOption msgServiceRouter *baseapp.MsgServiceRouter appConfig *appv1alpha1.Config + logger log.Logger // initChainer is the init chainer function defined by the app config. // this is only required if the chain wants to add special InitChainer logic. initChainer sdk.InitChainer diff --git a/runtime/builder.go b/runtime/builder.go index a720a608e1c9..a1fca494adb8 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -4,7 +4,6 @@ import ( "encoding/json" "io" - "cosmossdk.io/log" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" @@ -26,7 +25,6 @@ func (a *AppBuilder) DefaultGenesis() map[string]json.RawMessage { // Build builds an *App instance. func (a *AppBuilder) Build( - logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*baseapp.BaseApp), @@ -35,7 +33,7 @@ func (a *AppBuilder) Build( baseAppOptions = append(baseAppOptions, option) } - bApp := baseapp.NewBaseApp(a.app.config.AppName, logger, db, nil, baseAppOptions...) + bApp := baseapp.NewBaseApp(a.app.config.AppName, a.app.logger, db, nil, baseAppOptions...) bApp.SetMsgServiceRouter(a.app.msgServiceRouter) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) diff --git a/runtime/module.go b/runtime/module.go index ed3b5c8c71e1..7f11b024a056 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -78,12 +79,14 @@ type AppInputs struct { BaseAppOptions []BaseAppOption InterfaceRegistry codectypes.InterfaceRegistry LegacyAmino *codec.LegacyAmino + Logger log.Logger } func SetupAppBuilder(inputs AppInputs) { app := inputs.AppBuilder.app app.baseAppOptions = inputs.BaseAppOptions app.config = inputs.Config + app.logger = inputs.Logger app.ModuleManager = module.NewManagerFromMap(inputs.Modules) app.appConfig = inputs.AppConfig diff --git a/server/api/server.go b/server/api/server.go index 18d18327d798..8aa44ca54f32 100644 --- a/server/api/server.go +++ b/server/api/server.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/server/config" + servercmtlog "github.com/cosmos/cosmos-sdk/server/log" "github.com/cosmos/cosmos-sdk/telemetry" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" ) @@ -108,11 +109,11 @@ func (s *Server) Start(cfg config.Config) error { if cfg.API.EnableUnsafeCORS { allowAllCORS := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"})) - return tmrpcserver.Serve(s.listener, allowAllCORS(h), s.logger, tmCfg) + return tmrpcserver.Serve(s.listener, allowAllCORS(h), servercmtlog.CometLoggerWrapper{Logger: s.logger}, tmCfg) } s.logger.Info("starting API server...") - return tmrpcserver.Serve(s.listener, s.Router, s.logger, tmCfg) + return tmrpcserver.Serve(s.listener, s.Router, servercmtlog.CometLoggerWrapper{Logger: s.logger}, tmCfg) } // Close closes the API server. diff --git a/server/log/cmt_logger.go b/server/log/cmt_logger.go index 11901685e2f6..82d7a783f3ef 100644 --- a/server/log/cmt_logger.go +++ b/server/log/cmt_logger.go @@ -2,7 +2,7 @@ package server import ( "cosmossdk.io/log" - cmtlog "cosmossdk.io/log" + cmtlog "github.com/cometbft/cometbft/libs/log" ) var _ cmtlog.Logger = (*CometLoggerWrapper)(nil) diff --git a/server/mock/app.go b/server/mock/app.go index 4afede53c7e0..405e7038ffac 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -24,7 +24,7 @@ import ( // similar to a real app. Make sure rootDir is empty before running the test, // in order to guarantee consistent results. func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { - db, err := db.NewGoLevelDB("mock", filepath.Join(rootDir, "data")) + db, err := db.NewGoLevelDB("mock", filepath.Join(rootDir, "data"), nil) if err != nil { return nil, err } diff --git a/server/mock/app_test.go b/server/mock/app_test.go index 6e96241b0b68..f0dc49251f0f 100644 --- a/server/mock/app_test.go +++ b/server/mock/app_test.go @@ -14,7 +14,7 @@ import ( ) func TestInitApp(t *testing.T) { - app, closer, err := SetupApp() + app, closer, err := SetupApp(t) // closer may need to be run, even when error in later stage if closer != nil { defer closer() @@ -42,7 +42,7 @@ func TestInitApp(t *testing.T) { } func TestDeliverTx(t *testing.T) { - app, closer, err := SetupApp() + app, closer, err := SetupApp(t) // closer may need to be run, even when error in later stage if closer != nil { defer closer() diff --git a/server/mock/helpers.go b/server/mock/helpers.go index d991a1603c02..510de8eb4456 100644 --- a/server/mock/helpers.go +++ b/server/mock/helpers.go @@ -11,10 +11,10 @@ import ( // SetupApp returns an application as well as a clean-up function to be used to // quickly setup a test case with an app. -func SetupApp() (abci.Application, func(), error) { +func SetupApp(t *testing.T) (abci.Application, func(), error) { var logger tmlog.Logger if testing.Verbose() { - logger = tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)).With("module", "mock") + logger = tmlog.NewTestLogger(t).With("module", "mock") } else { logger = tmlog.NewNopLogger() } diff --git a/server/start.go b/server/start.go index 30f0b14cdd4a..2d4c58635116 100644 --- a/server/start.go +++ b/server/start.go @@ -30,6 +30,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/api" serverconfig "github.com/cosmos/cosmos-sdk/server/config" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" + servercmtlog "github.com/cosmos/cosmos-sdk/server/log" "github.com/cosmos/cosmos-sdk/server/types" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/telemetry" @@ -238,7 +239,7 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error { return fmt.Errorf("error creating listener: %v", err) } - svr.SetLogger(ctx.Logger.With("module", "abci-server")) + svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: ctx.Logger.With("module", "abci-server")}) err = svr.Start() if err != nil { @@ -324,7 +325,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App genDocProvider, node.DefaultDBProvider, node.DefaultMetricsProvider(cfg.Instrumentation), - ctx.Logger, + servercmtlog.CometLoggerWrapper{Logger: ctx.Logger}, ) if err != nil { return err diff --git a/server/tm_cmds.go b/server/tm_cmds.go index 772c4fc897c8..2a3bc891cfe0 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -20,6 +20,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + servercmtlog "github.com/cosmos/cosmos-sdk/server/log" "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -176,7 +177,7 @@ func BootstrapStateCmd(appCreator types.AppCreator) *cobra.Command { Period: cfg.StateSync.TrustPeriod, Height: cfg.StateSync.TrustHeight, Hash: cfg.StateSync.TrustHashBytes(), - }, serverCtx.Logger.With("module", "light")) + }, servercmtlog.CometLoggerWrapper{Logger: serverCtx.Logger.With("module", "light")}) if err != nil { return fmt.Errorf("failed to set up light client state provider: %w", err) } diff --git a/server/util.go b/server/util.go index 566cf3c160fa..1204ca2fca30 100644 --- a/server/util.go +++ b/server/util.go @@ -21,7 +21,6 @@ import ( "github.com/spf13/viper" "cosmossdk.io/log" - tmlog "cosmossdk.io/log" tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" tmcfg "github.com/cometbft/cometbft/config" tmtypes "github.com/cometbft/cometbft/types" @@ -30,7 +29,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/config" - serverlog "github.com/cosmos/cosmos-sdk/server/log" "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" @@ -50,7 +48,7 @@ const ServerContextKey = sdk.ContextKey("server.context") type Context struct { Viper *viper.Viper Config *tmcfg.Config - Logger tmlog.Logger + Logger log.Logger } // ErrorCode contains the exit code for server exit. @@ -66,11 +64,11 @@ func NewDefaultContext() *Context { return NewContext( viper.New(), tmcfg.DefaultConfig(), - tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)), + log.NewLogger(os.Stdout), ) } -func NewContext(v *viper.Viper, config *tmcfg.Config, logger tmlog.Logger) *Context { +func NewContext(v *viper.Viper, config *tmcfg.Config, logger log.Logger) *Context { return &Context{v, config, logger} } @@ -181,12 +179,46 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate s // Check if the CometBFT flag for trace logging is set and enable stack traces if so. opts = append(opts, log.TraceOption(serverCtx.Viper.GetBool("trace"))) // cmtcli.TraceFlag - logger := log.NewLogger(tmlog.NewSyncWriter(os.Stdout), opts...).With(log.ModuleKey, "server") - serverCtx.Logger = serverlog.CometLoggerWrapper{Logger: logger} + logger, err := CreateSDKLogger(serverCtx, cmd.OutOrStdout()) + if err != nil { + return err + } + serverCtx.Logger = logger.With(log.ModuleKey, "server") return SetCmdServerContext(cmd, serverCtx) } +// CreateSDKLogger creates a the default SDK logger. +// It reads the log level and format from the server context. +func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { + var opts []log.Option + + // check and set filter level or keys for the logger if any + logLvlStr := ctx.Viper.GetString(flags.FlagLogLevel) + if logLvlStr == "" { + return log.NewLogger(out, opts...), nil + } + + logLvl, err := zerolog.ParseLevel(logLvlStr) + switch { + case err != nil: + // If the log level is not a valid zerolog level, then we try to parse it as a key filter. + filterFunc, err := log.ParseLogLevel(logLvlStr) + if err != nil { + return nil, err + } + + opts = append(opts, log.FilterOption(filterFunc)) + default: + opts = append(opts, log.LevelOption(logLvl)) + } + + // Check if the CometBFT flag for trace logging is set and enable stack traces if so. + opts = append(opts, log.TraceOption(ctx.Viper.GetBool("trace"))) // cmtcli.TraceFlag + + return log.NewLogger(out, opts...), nil +} + // GetServerContextFromCmd returns a Context from a command or an empty Context // if it has not been set. func GetServerContextFromCmd(cmd *cobra.Command) *Context { diff --git a/simapp/app_test.go b/simapp/app_test.go index 09ca1c1b7bb8..e78839822407 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -3,7 +3,6 @@ package simapp import ( "encoding/json" "fmt" - "os" "testing" "cosmossdk.io/log" @@ -40,7 +39,7 @@ import ( func TestSimAppExportAndBlockedAddrs(t *testing.T) { db := dbm.NewMemDB() - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + logger := log.NewTestLogger(t) app := NewSimappWithCustomOptions(t, false, SetupOptions{ Logger: logger, DB: db, @@ -65,20 +64,19 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { app.Commit() - logger2 := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) // Making a new app object with the db, so that initchain hasn't been called - app2 := NewSimApp(logger2, db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) + app2 := NewSimApp(logger.With("instance", "second"), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) _, err := app2.ExportAppStateAndValidators(false, []string{}, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } func TestRunMigrations(t *testing.T) { db := dbm.NewMemDB() - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) - app := NewSimApp(logger, db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) + logger := log.NewTestLogger(t) + app := NewSimApp(logger.With("instance", "simapp"), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) // Create a new baseapp and configurator for the purpose of this test. - bApp := baseapp.NewBaseApp(app.Name(), logger, db, app.TxConfig().TxDecoder()) + bApp := baseapp.NewBaseApp(app.Name(), logger.With("instance", "baseapp"), db, app.TxConfig().TxDecoder()) bApp.SetCommitMultiStoreTracer(nil) bApp.SetInterfaceRegistry(app.InterfaceRegistry()) app.BaseApp = bApp @@ -208,8 +206,7 @@ func TestRunMigrations(t *testing.T) { func TestInitGenesisOnMigration(t *testing.T) { db := dbm.NewMemDB() - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) - app := NewSimApp(logger, db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) + app := NewSimApp(log.NewTestLogger(t), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) // Create a mock module. This module will serve as the new module we're @@ -251,9 +248,8 @@ func TestInitGenesisOnMigration(t *testing.T) { func TestUpgradeStateOnGenesis(t *testing.T) { db := dbm.NewMemDB() - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) app := NewSimappWithCustomOptions(t, false, SetupOptions{ - Logger: logger, + Logger: log.NewTestLogger(t), DB: db, AppOpts: simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), }) diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 4ef9fb07eded..d0db89faabe9 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -201,7 +201,11 @@ func NewSimApp( ) ) - if err := depinject.Inject(appConfig, + if err := depinject.Inject( + depinject.Configs( + appConfig, + depinject.Supply(log.NewNopLogger()), + ), &appBuilder, &app.appCodec, &app.legacyAmino, @@ -254,7 +258,7 @@ func NewSimApp( // } // baseAppOptions = append(baseAppOptions, prepareOpt) - app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) + app.App = appBuilder.Build(db, traceStore, baseAppOptions...) // load state streaming if enabled if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, logger, app.kvStoreKeys()); err != nil { diff --git a/simapp/sim_test.go b/simapp/sim_test.go index ffe90a4295d7..dcacd6c2ffab 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -349,7 +349,7 @@ func TestAppStateDeterminism(t *testing.T) { for j := 0; j < numTimesToRunPerSeed; j++ { var logger log.Logger if simcli.FlagVerboseValue { - logger = log.TestingLogger() + logger = log.NewTestLogger(t) } else { logger = log.NewNopLogger() } diff --git a/snapshots/helpers_test.go b/snapshots/helpers_test.go index 5e05c1c9a9f1..c19c3b532fcf 100644 --- a/snapshots/helpers_test.go +++ b/snapshots/helpers_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/cometbft/cometbft/libs/log" + "cosmossdk.io/log" db "github.com/cosmos/cosmos-db" protoio "github.com/cosmos/gogoproto/io" "github.com/stretchr/testify/require" diff --git a/snapshots/manager_test.go b/snapshots/manager_test.go index 1f727e1e2f92..976818399401 100644 --- a/snapshots/manager_test.go +++ b/snapshots/manager_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - "github.com/cometbft/cometbft/libs/log" + "cosmossdk.io/log" db "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/store/iavl/store.go b/store/iavl/store.go index 9adc56cda978..41925d774bd3 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -6,12 +6,12 @@ import ( "io" "time" - dbm "github.com/cometbft/cometbft-db" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" - "github.com/cometbft/cometbft/libs/log" tmcrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" - ics23 "github.com/confio/ics23/go" + dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/iavl" + ics23 "github.com/cosmos/ics23/go" "github.com/cosmos/cosmos-sdk/store/cachekv" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" @@ -43,19 +43,16 @@ type Store struct { // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the // store's version (id) from the provided DB. An error is returned if the version // fails to load, or if called with a positive version on an empty tree. -func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, cacheSize int, disableFastNode bool) (types.CommitKVStore, error) { - return LoadStoreWithInitialVersion(db, logger, key, id, lazyLoading, 0, cacheSize, disableFastNode) +func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, cacheSize int, disableFastNode bool) (types.CommitKVStore, error) { + return LoadStoreWithInitialVersion(db, logger, key, id, 0, cacheSize, disableFastNode) } // LoadStoreWithInitialVersion returns an IAVL Store as a CommitKVStore setting its initialVersion // to the one given. Internally, it will load the store's version (id) from the // provided DB. An error is returned if the version fails to load, or if called with a positive // version on an empty tree. -func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, initialVersion uint64, cacheSize int, disableFastNode bool) (types.CommitKVStore, error) { - tree, err := iavl.NewMutableTreeWithOpts(db, cacheSize, &iavl.Options{InitialVersion: initialVersion}, disableFastNode) - if err != nil { - return nil, err - } +func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, initialVersion uint64, cacheSize int, disableFastNode bool) (types.CommitKVStore, error) { + tree := iavl.NewMutableTree(db, cacheSize, disableFastNode, logger, iavl.InitialVersionOption(initialVersion)) isUpgradeable, err := tree.IsUpgradeable() if err != nil { @@ -68,20 +65,15 @@ func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKe "store_key", key.String(), "version", initialVersion, "commit", fmt.Sprintf("%X", id), - "is_lazy", lazyLoading, ) } - if lazyLoading { - _, err = tree.LazyLoadVersion(id.Version) - } else { - _, err = tree.LoadVersion(id.Version) - } + _, err = tree.LoadVersion(id.Version) if err != nil { return nil, err } - istore.tree.(*immutableTree) + if logger != nil { logger.Debug("Finished loading IAVL tree") } @@ -226,30 +218,31 @@ func (st *Store) Delete(key []byte) { // DeleteVersions deletes a series of versions from the MutableTree. An error // is returned if any single version is invalid or the delete fails. All writes // happen in a single batch with a single commit. -func (st *Store) DeleteVersions(versions ...int64) error { - return st.tree.DeleteVersions(versions...) +func (st *Store) DeleteVersionsTo(version int64) error { + return st.tree.DeleteVersionsTo(version) } // LoadVersionForOverwriting attempts to load a tree at a previously committed // version, or the latest version below it. Any versions greater than targetVersion will be deleted. -func (st *Store) LoadVersionForOverwriting(targetVersion int64) (int64, error) { +func (st *Store) LoadVersionForOverwriting(targetVersion int64) error { return st.tree.LoadVersionForOverwriting(targetVersion) } -// LazyLoadVersionForOverwriting is the lazy version of LoadVersionForOverwriting. -func (st *Store) LazyLoadVersionForOverwriting(targetVersion int64) (int64, error) { - return st.tree.LazyLoadVersionForOverwriting(targetVersion) -} - // Implements types.KVStore. func (st *Store) Iterator(start, end []byte) types.Iterator { - iterator := st.tree.Iterator(start, end, true) + iterator, err := st.tree.Iterator(start, end, true) + if err != nil { + panic(err) + } return iterator } // Implements types.KVStore. func (st *Store) ReverseIterator(start, end []byte) types.Iterator { - iterator := st.tree.Iterator(start, end, false) + iterator, err := st.tree.Iterator(start, end, false) + if err != nil { + panic(err) + } return iterator } diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index 5febb2f49f63..9cd80fd33209 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -37,13 +37,15 @@ func newAlohaTree(t *testing.T, db dbm.DB) (*iavl.MutableTree, types.CommitID) { tree := iavl.NewMutableTree(dbm.NewMemDB(), 100, false, log.NewNopLogger()) for k, v := range treeData { - tree.Set([]byte(k), []byte(v)) + _, err := tree.Set([]byte(k), []byte(v)) + require.NoError(t, err) } for i := 0; i < nMoreData; i++ { key := randBytes(12) value := randBytes(50) - tree.Set(key, value) + _, err := tree.Set(key, value) + require.NoError(t, err) } hash, ver, err := tree.SaveVersion() @@ -99,17 +101,17 @@ func TestLoadStore(t *testing.T) { require.Equal(t, string(hcStore.Get([]byte("hello"))), "ciao") // Querying a new store at some previous non-pruned height H - newHStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDH, false, DefaultIAVLCacheSize, false) + newHStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDH, DefaultIAVLCacheSize, false) require.NoError(t, err) require.Equal(t, string(newHStore.Get([]byte("hello"))), "hallo") // Querying a new store at some previous pruned height Hp - newHpStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHp, false, DefaultIAVLCacheSize, false) + newHpStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHp, DefaultIAVLCacheSize, false) require.NoError(t, err) require.Equal(t, string(newHpStore.Get([]byte("hello"))), "hola") // Querying a new store at current height H - newHcStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHc, false, DefaultIAVLCacheSize, false) + newHcStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHc, DefaultIAVLCacheSize, false) require.NoError(t, err) require.Equal(t, string(newHcStore.Get([]byte("hello"))), "ciao") } @@ -374,8 +376,7 @@ func TestIAVLPrefixIterator(t *testing.T) { func TestIAVLReversePrefixIterator(t *testing.T) { db := dbm.NewMemDB() - tree, err := iavl.NewMutableTree(db, cacheSize, false) - require.NoError(t, err) + tree := iavl.NewMutableTree(db, cacheSize, false, log.NewNopLogger()) iavlStore := UnsafeNewStore(tree) @@ -442,8 +443,7 @@ func nextVersion(iavl *Store) { func TestIAVLNoPrune(t *testing.T) { db := dbm.NewMemDB() - tree, err := iavl.NewMutableTree(db, cacheSize, false) - require.NoError(t, err) + tree := iavl.NewMutableTree(db, cacheSize, false, log.NewNopLogger()) iavlStore := UnsafeNewStore(tree) nextVersion(iavlStore) diff --git a/store/iavl/tree.go b/store/iavl/tree.go index 82bb1d961a85..67abff906b34 100644 --- a/store/iavl/tree.go +++ b/store/iavl/tree.go @@ -28,6 +28,7 @@ type ( Hash() []byte VersionExists(version int64) bool GetVersioned(key []byte, version int64) ([]byte, error) + DeleteVersionsTo(version int64) error GetImmutable(version int64) (*iavl.ImmutableTree, error) SetInitialVersion(version uint64) Iterator(start, end []byte, ascending bool) (types.Iterator, error) @@ -55,14 +56,10 @@ func (it *immutableTree) SaveVersion() ([]byte, int64, error) { panic("cannot call 'SaveVersion' on an immutable IAVL tree") } -func (it *immutableTree) DeleteVersion(_ int64) error { +func (it *immutableTree) DeleteVersionsTo(_ int64) error { panic("cannot call 'DeleteVersion' on an immutable IAVL tree") } -func (it *immutableTree) DeleteVersions(_ ...int64) error { - panic("cannot call 'DeleteVersions' on an immutable IAVL tree") -} - func (it *immutableTree) SetInitialVersion(_ uint64) { panic("cannot call 'SetInitialVersion' on an immutable IAVL tree") } @@ -94,4 +91,3 @@ func (it *immutableTree) AvailableVersions() []int { func (it *immutableTree) LoadVersionForOverwriting(targetVersion int64) error { panic("cannot call 'LoadVersionForOverwriting' on an immutable IAVL tree") } - diff --git a/store/iavl/tree_test.go b/store/iavl/tree_test.go index 74046da25190..f74282b912d6 100644 --- a/store/iavl/tree_test.go +++ b/store/iavl/tree_test.go @@ -15,8 +15,8 @@ func TestImmutableTreePanics(t *testing.T) { it := &immutableTree{immTree} require.Panics(t, func() { it.Set([]byte{}, []byte{}) }) require.Panics(t, func() { it.Remove([]byte{}) }) - require.Panics(t, func() { it.SaveVersion() }) // nolint:errcheck - require.Panics(t, func() { it.DeleteVersion(int64(1)) }) // nolint:errcheck + require.Panics(t, func() { it.SaveVersion() }) // nolint:errcheck + require.Panics(t, func() { it.DeleteVersionsTo(int64(1)) }) // nolint:errcheck val, err := it.GetVersioned(nil, 1) require.Error(t, err) diff --git a/store/internal/proofs/convert.go b/store/internal/proofs/convert.go index f6b213fb9bf9..6bf1084c7627 100644 --- a/store/internal/proofs/convert.go +++ b/store/internal/proofs/convert.go @@ -5,7 +5,7 @@ import ( "math/bits" "github.com/cometbft/cometbft/proto/tendermint/crypto" - ics23 "github.com/confio/ics23/go" + ics23 "github.com/cosmos/ics23/go" ) // ConvertExistenceProof will convert the given proof into a valid diff --git a/store/internal/proofs/create.go b/store/internal/proofs/create.go index a202408324a9..48b48f034d48 100644 --- a/store/internal/proofs/create.go +++ b/store/internal/proofs/create.go @@ -5,7 +5,7 @@ import ( "fmt" "sort" - ics23 "github.com/confio/ics23/go" + ics23 "github.com/cosmos/ics23/go" sdkmaps "github.com/cosmos/cosmos-sdk/store/internal/maps" ) diff --git a/store/internal/proofs/create_test.go b/store/internal/proofs/create_test.go index e65a365b62a4..16818e657a81 100644 --- a/store/internal/proofs/create_test.go +++ b/store/internal/proofs/create_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - ics23 "github.com/confio/ics23/go" + ics23 "github.com/cosmos/ics23/go" "github.com/stretchr/testify/assert" ) diff --git a/store/pruning/export_test.go b/store/pruning/export_test.go index 8c38778bf93d..0b67d6ceda31 100644 --- a/store/pruning/export_test.go +++ b/store/pruning/export_test.go @@ -6,6 +6,5 @@ var ( Int64SliceToBytes = int64SliceToBytes ListToBytes = listToBytes - LoadPruningHeights = loadPruningHeights LoadPruningSnapshotHeights = loadPruningSnapshotHeights ) diff --git a/store/pruning/manager.go b/store/pruning/manager.go index 1c08567b092d..e1a734f95473 100644 --- a/store/pruning/manager.go +++ b/store/pruning/manager.go @@ -4,6 +4,7 @@ import ( "container/list" "encoding/binary" "fmt" + "sort" "sync" "cosmossdk.io/log" @@ -23,14 +24,13 @@ type Manager struct { // Although pruneHeights happen in the same goroutine with the normal execution, // we sync access to them to avoid soundness issues in the future if concurrency pattern changes. pruneHeightsMx sync.Mutex - pruneHeights []int64 // Snapshots are taken in a separate goroutine from the regular execution // and can be delivered asynchrounously via HandleHeightSnapshot. // Therefore, we sync access to pruneSnapshotHeights with this mutex. pruneSnapshotHeightsMx sync.Mutex // These are the heights that are multiples of snapshotInterval and kept for state sync snapshots. // The heights are added to this list to be pruned when a snapshot is complete. - pruneSnapshotHeights *list.List + pruneSnapshotHeights []int64 } // NegativeHeightsError is returned when a negative height is provided to the manager. @@ -58,8 +58,7 @@ func NewManager(db dbm.DB, logger log.Logger) *Manager { db: db, logger: logger, opts: types.NewPruningOptions(types.PruningNothing), - pruneHeights: []int64{}, - pruneSnapshotHeights: list.New(), + pruneSnapshotHeights: []int64{}, } } @@ -73,82 +72,61 @@ func (m *Manager) GetOptions() types.PruningOptions { return m.opts } -// GetFlushAndResetPruningHeights returns all heights to be pruned during the next call to Prune(). -// It also flushes and resets the pruning heights. -func (m *Manager) GetFlushAndResetPruningHeights() ([]int64, error) { +// GetPruningHeight returns the height which can prune upto if it is able to prune at the given height. +func (m *Manager) GetPruningHeight(height int64) int64 { if m.opts.GetPruningStrategy() == types.PruningNothing { - return []int64{}, nil + return 0 + } + if m.opts.Interval <= 0 { + return 0 } - m.pruneHeightsMx.Lock() - defer m.pruneHeightsMx.Unlock() - // flush the updates to disk so that it is not lost if crash happens. - if err := m.db.SetSync(pruneHeightsKey, int64SliceToBytes(m.pruneHeights)); err != nil { - return nil, err + if height%int64(m.opts.Interval) != 0 || height <= int64(m.opts.KeepRecent) { + return 0 } - // Return a copy to prevent data races. - pruningHeights := make([]int64, len(m.pruneHeights)) - copy(pruningHeights, m.pruneHeights) - m.pruneHeights = m.pruneHeights[:0] + // Consider the snapshot height + pruneHeight := height - 1 - int64(m.opts.KeepRecent) // we should keep the current height at least - return pruningHeights, nil -} + m.pruneSnapshotHeightsMx.Lock() + defer m.pruneSnapshotHeightsMx.Unlock() -// HandleHeight determines if previousHeight height needs to be kept for pruning at the right interval prescribed by -// the pruning strategy. Returns previousHeight, if it was kept to be pruned at the next call to Prune(), 0 otherwise. -// previousHeight must be greater than 0 for the handling to take effect since valid heights start at 1 and 0 represents -// the latest height. The latest height cannot be pruned. As a result, if previousHeight is less than or equal to 0, 0 is returned. -func (m *Manager) HandleHeight(previousHeight int64) int64 { - if m.opts.GetPruningStrategy() == types.PruningNothing || previousHeight <= 0 { + // snapshotInterval is zero, indicating that all heights can be pruned + if m.snapshotInterval <= 0 { + return pruneHeight + } + + if len(m.pruneSnapshotHeights) == 0 { // the length should be greater than zero return 0 } - defer func() { - m.pruneHeightsMx.Lock() - defer m.pruneHeightsMx.Unlock() + // the snapshot `m.pruneSnapshotHeights[0]` is already operated, + // so we can prune upto `m.pruneSnapshotHeights[0] + int64(m.snapshotInterval) - 1` + snHeight := m.pruneSnapshotHeights[0] + int64(m.snapshotInterval) - 1 + if snHeight < pruneHeight { + return snHeight + } + return pruneHeight +} + +// LoadSnapshotHeights loads the snapshot heights from the database as a crash recovery. +func (m *Manager) LoadSnapshotHeights(db dbm.DB) error { + if m.opts.GetPruningStrategy() == types.PruningNothing { + return nil + } + loadedPruneSnapshotHeights, err := loadPruningSnapshotHeights(db) + if err != nil { + return err + } + + if len(loadedPruneSnapshotHeights) > 0 { m.pruneSnapshotHeightsMx.Lock() defer m.pruneSnapshotHeightsMx.Unlock() - - // move persisted snapshot heights to pruneHeights which - // represent the heights to be pruned at the next pruning interval. - var next *list.Element - for e := m.pruneSnapshotHeights.Front(); e != nil; e = next { - snHeight := e.Value.(int64) - if snHeight < previousHeight-int64(m.opts.KeepRecent) { - m.pruneHeights = append(m.pruneHeights, snHeight) - - // We must get next before removing to be able to continue iterating. - next = e.Next() - m.pruneSnapshotHeights.Remove(e) - } else { - next = e.Next() - } - } - - // flush the updates to disk so that they are not lost if crash happens. - if err := m.db.SetSync(pruneHeightsKey, int64SliceToBytes(m.pruneHeights)); err != nil { - panic(err) - } - }() - - if int64(m.opts.KeepRecent) < previousHeight { - pruneHeight := previousHeight - int64(m.opts.KeepRecent) - // We consider this height to be pruned iff: - // - // - snapshotInterval is zero as that means that all heights should be pruned. - // - snapshotInterval % (height - KeepRecent) != 0 as that means the height is not - // a 'snapshot' height. - if m.snapshotInterval == 0 || pruneHeight%int64(m.snapshotInterval) != 0 { - m.pruneHeightsMx.Lock() - defer m.pruneHeightsMx.Unlock() - - m.pruneHeights = append(m.pruneHeights, pruneHeight) - return pruneHeight - } + m.pruneSnapshotHeights = loadedPruneSnapshotHeights } - return 0 + + return nil } // HandleHeightSnapshot persists the snapshot height to be pruned at the next appropriate @@ -164,10 +142,18 @@ func (m *Manager) HandleHeightSnapshot(height int64) { defer m.pruneSnapshotHeightsMx.Unlock() m.logger.Debug("HandleHeightSnapshot", "height", height) - m.pruneSnapshotHeights.PushBack(height) + m.pruneSnapshotHeights = append(m.pruneSnapshotHeights, height) + sort.Slice(m.pruneSnapshotHeights, func(i, j int) bool { return m.pruneSnapshotHeights[i] < m.pruneSnapshotHeights[j] }) + k := 1 + for ; k < len(m.pruneSnapshotHeights); k++ { + if m.pruneSnapshotHeights[k] != m.pruneSnapshotHeights[k-1]+int64(m.snapshotInterval) { + break + } + } + m.pruneSnapshotHeights = m.pruneSnapshotHeights[k-1:] // flush the updates to disk so that they are not lost if crash happens. - if err := m.db.SetSync(pruneSnapshotHeightsKey, listToBytes(m.pruneSnapshotHeights)); err != nil { + if err := m.db.SetSync(pruneSnapshotHeightsKey, int64SliceToBytes(m.pruneSnapshotHeights)); err != nil { panic(err) } } @@ -183,27 +169,16 @@ func (m *Manager) ShouldPruneAtHeight(height int64) bool { } // LoadPruningHeights loads the pruning heights from the database as a crash recovery. -func (m *Manager) LoadPruningHeights(db dbm.DB) error { +func (m *Manager) LoadPruningSnapshotHeights(db dbm.DB) error { if m.opts.GetPruningStrategy() == types.PruningNothing { return nil } - loadedPruneHeights, err := loadPruningHeights(db) - if err != nil { - return err - } - - if len(loadedPruneHeights) > 0 { - m.pruneHeightsMx.Lock() - defer m.pruneHeightsMx.Unlock() - m.pruneHeights = loadedPruneHeights - } - loadedPruneSnapshotHeights, err := loadPruningSnapshotHeights(db) if err != nil { return err } - if loadedPruneSnapshotHeights.Len() > 0 { + if len(loadedPruneSnapshotHeights) > 0 { m.pruneSnapshotHeightsMx.Lock() defer m.pruneSnapshotHeightsMx.Unlock() m.pruneSnapshotHeights = loadedPruneSnapshotHeights @@ -212,74 +187,12 @@ func (m *Manager) LoadPruningHeights(db dbm.DB) error { return nil } -// GetPruningHeight returns the height which can prune upto if it is able to prune at the given height. -func (m *Manager) GetPruningHeight(height int64) int64 { - if m.opts.GetPruningStrategy() == types.PruningNothing { - return 0 - } - if m.opts.Interval <= 0 { - return 0 - } - - if height%int64(m.opts.Interval) != 0 || height <= int64(m.opts.KeepRecent) { - return 0 - } - - // Consider the snapshot height - pruneHeight := height - 1 - int64(m.opts.KeepRecent) // we should keep the current height at least - - m.pruneSnapshotHeightsMx.RLock() - defer m.pruneSnapshotHeightsMx.RUnlock() - - // snapshotInterval is zero, indicating that all heights can be pruned - if m.snapshotInterval <= 0 { - return pruneHeight - } - - if len(m.pruneSnapshotHeights) == 0 { // the length should be greater than zero - return 0 - } - - // the snapshot `m.pruneSnapshotHeights[0]` is already operated, - // so we can prune upto `m.pruneSnapshotHeights[0] + int64(m.snapshotInterval) - 1` - snHeight := m.pruneSnapshotHeights[0] + int64(m.snapshotInterval) - 1 - if snHeight < pruneHeight { - return snHeight - } - return pruneHeight -} - -func loadPruningHeights(db dbm.DB) ([]int64, error) { - bz, err := db.Get(pruneHeightsKey) - if err != nil { - return nil, fmt.Errorf("failed to get pruned heights: %w", err) - } - if len(bz) == 0 { - return []int64{}, nil - } - - prunedHeights := make([]int64, len(bz)/8) - i, offset := 0, 0 - for offset < len(bz) { - h := int64(binary.BigEndian.Uint64(bz[offset : offset+8])) - if h < 0 { - return []int64{}, &NegativeHeightsError{Height: h} - } - - prunedHeights[i] = h - i++ - offset += 8 - } - - return prunedHeights, nil -} - -func loadPruningSnapshotHeights(db dbm.DB) (*list.List, error) { +func loadPruningSnapshotHeights(db dbm.DB) ([]int64, error) { bz, err := db.Get(pruneSnapshotHeightsKey) if err != nil { return nil, fmt.Errorf("failed to get post-snapshot pruned heights: %w", err) } - pruneSnapshotHeights := list.New() + pruneSnapshotHeights := make([]int64, len(bz)/8) if len(bz) == 0 { return pruneSnapshotHeights, nil } @@ -290,7 +203,7 @@ func loadPruningSnapshotHeights(db dbm.DB) (*list.List, error) { if h < 0 { return nil, &NegativeHeightsError{Height: h} } - pruneSnapshotHeights.PushBack(h) + pruneSnapshotHeights[i] = h i++ offset += 8 } diff --git a/store/pruning/manager_test.go b/store/pruning/manager_test.go index e6910b2e4b50..63e666ffab5c 100644 --- a/store/pruning/manager_test.go +++ b/store/pruning/manager_test.go @@ -1,7 +1,6 @@ package pruning_test import ( - "container/list" "errors" "fmt" "testing" @@ -22,9 +21,6 @@ func TestNewManager(t *testing.T) { manager := pruning.NewManager(db.NewMemDB(), log.NewNopLogger()) require.NotNil(t, manager) - heights, err := manager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.NotNil(t, heights) require.Equal(t, types.PruningNothing, manager.GetOptions().GetPruningStrategy()) } @@ -107,89 +103,82 @@ func TestStrategies(t *testing.T) { } manager.SetOptions(curStrategy) + snHeight := int64(tc.snapshotInterval - 1) require.Equal(t, tc.strategy, manager.GetOptions()) curKeepRecent := curStrategy.KeepRecent curInterval := curStrategy.Interval for curHeight := int64(0); curHeight < 110000; curHeight++ { - handleHeightActual := manager.HandleHeight(curHeight) shouldPruneAtHeightActual := manager.ShouldPruneAtHeight(curHeight) - curPruningHeihts, err := manager.GetFlushAndResetPruningHeights() - require.Nil(t, err) + pruningHeightActual := manager.GetPruningHeight(curHeight) curHeightStr := fmt.Sprintf("height: %d", curHeight) switch curStrategy.GetPruningStrategy() { case types.PruningNothing: - require.Equal(t, int64(0), handleHeightActual, curHeightStr) - require.False(t, shouldPruneAtHeightActual, curHeightStr) - - heights, err := manager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Equal(t, 0, len(heights)) + require.Equal(t, int64(0), pruningHeightActual, curHeightStr) default: - if curHeight > int64(curKeepRecent) && (tc.snapshotInterval != 0 && (curHeight-int64(curKeepRecent))%int64(tc.snapshotInterval) != 0 || tc.snapshotInterval == 0) { - expectedHeight := curHeight - int64(curKeepRecent) - require.Equal(t, curHeight-int64(curKeepRecent), handleHeightActual, curHeightStr) - - require.Contains(t, curPruningHeihts, expectedHeight, curHeightStr) + if curHeight > int64(curKeepRecent) && curHeight%int64(curStrategy.Interval) == 0 { + pruningHeightExpected := curHeight - int64(curKeepRecent) - 1 + if tc.snapshotInterval > 0 && snHeight < pruningHeightExpected { + pruningHeightExpected = snHeight + } + require.Equal(t, pruningHeightExpected, pruningHeightActual, curHeightStr) } else { - require.Equal(t, int64(0), handleHeightActual, curHeightStr) - - heights, err := manager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Equal(t, 0, len(heights)) + require.Equal(t, int64(0), pruningHeightActual, curHeightStr) } require.Equal(t, curHeight%int64(curInterval) == 0, shouldPruneAtHeightActual, curHeightStr) } - heights, err := manager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Equal(t, 0, len(heights)) } }) } } -func TestHandleHeight_Inputs(t *testing.T) { - var keepRecent int64 = int64(types.NewPruningOptions(types.PruningEverything).KeepRecent) +func TestPruningHeight_Inputs(t *testing.T) { + keepRecent := int64(types.NewPruningOptions(types.PruningEverything).KeepRecent) + interval := int64(types.NewPruningOptions(types.PruningEverything).Interval) testcases := map[string]struct { - height int64 - expectedResult int64 - strategy types.PruningStrategy - expectedHeights []int64 + height int64 + expectedResult int64 + strategy types.PruningStrategy }{ - "previousHeight is negative - prune everything - invalid previousHeight": { + "currentHeight is negative - prune everything - invalid currentHeight": { -1, 0, types.PruningEverything, - []int64{}, }, - "previousHeight is zero - prune everything - invalid previousHeight": { + "currentHeight is zero - prune everything - invalid currentHeight": { 0, 0, types.PruningEverything, - []int64{}, }, - "previousHeight is positive but within keep recent- prune everything - not kept": { + "currentHeight is positive but within keep recent- prune everything - not kept": { keepRecent, 0, types.PruningEverything, - []int64{}, }, - "previousHeight is positive and greater than keep recent - kept": { + "currentHeight is positive and equal to keep recent+1 - no kept": { keepRecent + 1, - keepRecent + 1 - keepRecent, + 0, types.PruningEverything, - []int64{keepRecent + 1 - keepRecent}, }, - "pruning nothing, previousHeight is positive and greater than keep recent - not kept": { - keepRecent + 1, + "currentHeight is positive and greater than keep recent+1 but not multiple of interval - no kept": { + keepRecent + 2, + 0, + types.PruningEverything, + }, + "currentHeight is positive and greater than keep recent+1 and multiple of interval - kept": { + interval, + interval - keepRecent - 1, + types.PruningEverything, + }, + "pruning nothing, currentHeight is positive and greater than keep recent - not kept": { + interval, 0, types.PruningNothing, - []int64{}, }, } @@ -199,113 +188,8 @@ func TestHandleHeight_Inputs(t *testing.T) { require.NotNil(t, manager) manager.SetOptions(types.NewPruningOptions(tc.strategy)) - handleHeightActual := manager.HandleHeight(tc.height) - require.Equal(t, tc.expectedResult, handleHeightActual) - - actualHeights, err := manager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Equal(t, len(tc.expectedHeights), len(actualHeights)) - require.Equal(t, tc.expectedHeights, actualHeights) - }) - } -} - -func TestHandleHeight_FlushLoadFromDisk(t *testing.T) { - testcases := map[string]struct { - previousHeight int64 - keepRecent uint64 - snapshotInterval uint64 - movedSnapshotHeights []int64 - expectedHandleHeightResult int64 - expectedLoadPruningHeightsResult error - expectedLoadedHeights []int64 - }{ - "simple flush occurs": { - previousHeight: 11, - keepRecent: 10, - snapshotInterval: 0, - movedSnapshotHeights: []int64{}, - expectedHandleHeightResult: 11 - 10, - expectedLoadPruningHeightsResult: nil, - expectedLoadedHeights: []int64{11 - 10}, - }, - "previous height <= keep recent - no update and no flush": { - previousHeight: 9, - keepRecent: 10, - snapshotInterval: 0, - movedSnapshotHeights: []int64{}, - expectedHandleHeightResult: 0, - expectedLoadPruningHeightsResult: nil, - expectedLoadedHeights: []int64{}, - }, - "previous height alligns with snapshot interval - no update and no flush": { - previousHeight: 12, - keepRecent: 10, - snapshotInterval: 2, - movedSnapshotHeights: []int64{}, - expectedHandleHeightResult: 0, - expectedLoadPruningHeightsResult: nil, - expectedLoadedHeights: []int64{}, - }, - "previous height does not align with snapshot interval - flush": { - previousHeight: 12, - keepRecent: 10, - snapshotInterval: 3, - movedSnapshotHeights: []int64{}, - expectedHandleHeightResult: 2, - expectedLoadPruningHeightsResult: nil, - expectedLoadedHeights: []int64{2}, - }, - "moved snapshot heights - flushed": { - previousHeight: 32, - keepRecent: 10, - snapshotInterval: 5, - movedSnapshotHeights: []int64{15, 20, 25}, - expectedHandleHeightResult: 22, - expectedLoadPruningHeightsResult: nil, - expectedLoadedHeights: []int64{15, 20, 22}, - }, - "previous height alligns with snapshot interval - no update but flush snapshot heights": { - previousHeight: 30, - keepRecent: 10, - snapshotInterval: 5, - movedSnapshotHeights: []int64{15, 20, 25}, - expectedHandleHeightResult: 0, - expectedLoadPruningHeightsResult: nil, - expectedLoadedHeights: []int64{15}, - }, - } - - for name, tc := range testcases { - t.Run(name, func(t *testing.T) { - // Setup - db := db.NewMemDB() - manager := pruning.NewManager(db, log.NewNopLogger()) - require.NotNil(t, manager) - - manager.SetSnapshotInterval(tc.snapshotInterval) - manager.SetOptions(types.NewCustomPruningOptions(uint64(tc.keepRecent), uint64(10))) - - for _, snapshotHeight := range tc.movedSnapshotHeights { - manager.HandleHeightSnapshot(snapshotHeight) - } - - // Test HandleHeight and flush - handleHeightActual := manager.HandleHeight(tc.previousHeight) - require.Equal(t, tc.expectedHandleHeightResult, handleHeightActual) - - loadedPruneHeights, err := pruning.LoadPruningHeights(db) - require.NoError(t, err) - require.Equal(t, len(loadedPruneHeights), len(loadedPruneHeights)) - - // Test load back - err = manager.LoadPruningHeights(db) - require.NoError(t, err) - - heights, err := manager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Equal(t, len(tc.expectedLoadedHeights), len(heights)) - require.ElementsMatch(t, tc.expectedLoadedHeights, heights) + pruningHeightActual := manager.GetPruningHeight(tc.height) + require.Equal(t, tc.expectedResult, pruningHeightActual) }) } } @@ -328,7 +212,7 @@ func TestHandleHeight_DbErr_Panic(t *testing.T) { } }() - manager.HandleHeight(10) + manager.HandleHeightSnapshot(10) } func TestHandleHeightSnapshot_FlushLoadFromDisk(t *testing.T) { @@ -352,15 +236,15 @@ func TestHandleHeightSnapshot_FlushLoadFromDisk(t *testing.T) { loadedSnapshotHeights, err := pruning.LoadPruningSnapshotHeights(db) require.NoError(t, err) - require.Equal(t, len(loadedHeightsMirror), loadedSnapshotHeights.Len()) + require.Equal(t, len(loadedHeightsMirror), len(loadedSnapshotHeights)) // Test load back - err = manager.LoadPruningHeights(db) + err = manager.LoadPruningSnapshotHeights(db) require.NoError(t, err) loadedSnapshotHeights, err = pruning.LoadPruningSnapshotHeights(db) require.NoError(t, err) - require.Equal(t, len(loadedHeightsMirror), loadedSnapshotHeights.Len()) + require.Equal(t, len(loadedHeightsMirror), len(loadedSnapshotHeights)) } } @@ -385,56 +269,7 @@ func TestHandleHeightSnapshot_DbErr_Panic(t *testing.T) { manager.HandleHeightSnapshot(10) } -func TestFlushLoad(t *testing.T) { - db := db.NewMemDB() - manager := pruning.NewManager(db, log.NewNopLogger()) - require.NotNil(t, manager) - - curStrategy := types.NewCustomPruningOptions(100, 15) - - snapshotInterval := uint64(10) - manager.SetSnapshotInterval(snapshotInterval) - - manager.SetOptions(curStrategy) - require.Equal(t, curStrategy, manager.GetOptions()) - - keepRecent := curStrategy.KeepRecent - - heightsToPruneMirror := make([]int64, 0) - - for curHeight := int64(0); curHeight < 1000; curHeight++ { - handleHeightActual := manager.HandleHeight(curHeight) - - curHeightStr := fmt.Sprintf("height: %d", curHeight) - - if curHeight > int64(keepRecent) && (snapshotInterval != 0 && (curHeight-int64(keepRecent))%int64(snapshotInterval) != 0 || snapshotInterval == 0) { - expectedHandleHeight := curHeight - int64(keepRecent) - require.Equal(t, expectedHandleHeight, handleHeightActual, curHeightStr) - heightsToPruneMirror = append(heightsToPruneMirror, expectedHandleHeight) - } else { - require.Equal(t, int64(0), handleHeightActual, curHeightStr) - } - - if manager.ShouldPruneAtHeight(curHeight) && curHeight > int64(keepRecent) { - actualHeights, err := manager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Equal(t, len(heightsToPruneMirror), len(actualHeights)) - require.Equal(t, heightsToPruneMirror, actualHeights) - - err = manager.LoadPruningHeights(db) - require.NoError(t, err) - - actualHeights, err = manager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Equal(t, len(heightsToPruneMirror), len(actualHeights)) - require.Equal(t, heightsToPruneMirror, actualHeights) - - heightsToPruneMirror = make([]int64, 0) - } - } -} - -func TestLoadPruningHeights(t *testing.T) { +func TestLoadSnapshotPruningHeights(t *testing.T) { var ( manager = pruning.NewManager(db.NewMemDB(), log.NewNopLogger()) err error @@ -445,43 +280,18 @@ func TestLoadPruningHeights(t *testing.T) { manager.SetOptions(types.NewPruningOptions(types.PruningDefault)) testcases := map[string]struct { - flushedPruningHeights []int64 - getFlushedPruningSnapshotHeights func() *list.List + getFlushedPruningSnapshotHeights func() []int64 expectedResult error }{ - "negative pruningHeight - error": { - flushedPruningHeights: []int64{10, 0, -1}, - expectedResult: &pruning.NegativeHeightsError{Height: -1}, - }, "negative snapshotPruningHeight - error": { - getFlushedPruningSnapshotHeights: func() *list.List { - l := list.New() - l.PushBack(int64(5)) - l.PushBack(int64(-2)) - l.PushBack(int64(3)) - return l + getFlushedPruningSnapshotHeights: func() []int64 { + return []int64{5, -2, 3} }, expectedResult: &pruning.NegativeHeightsError{Height: -2}, }, - "both have negative - pruningHeight error": { - flushedPruningHeights: []int64{10, 0, -1}, - getFlushedPruningSnapshotHeights: func() *list.List { - l := list.New() - l.PushBack(int64(5)) - l.PushBack(int64(-2)) - l.PushBack(int64(3)) - return l - }, - expectedResult: &pruning.NegativeHeightsError{Height: -1}, - }, - "both non-negative - success": { - flushedPruningHeights: []int64{10, 0, 3}, - getFlushedPruningSnapshotHeights: func() *list.List { - l := list.New() - l.PushBack(int64(5)) - l.PushBack(int64(0)) - l.PushBack(int64(3)) - return l + "non-negative - success": { + getFlushedPruningSnapshotHeights: func() []int64 { + return []int64{5, 0, 3} }, }, } @@ -489,44 +299,23 @@ func TestLoadPruningHeights(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { db := db.NewMemDB() - if tc.flushedPruningHeights != nil { - err = db.Set(pruning.PruneHeightsKey, pruning.Int64SliceToBytes(tc.flushedPruningHeights)) - require.NoError(t, err) - } if tc.getFlushedPruningSnapshotHeights != nil { - err = db.Set(pruning.PruneSnapshotHeightsKey, pruning.ListToBytes(tc.getFlushedPruningSnapshotHeights())) + err = db.Set(pruning.PruneSnapshotHeightsKey, pruning.Int64SliceToBytes(tc.getFlushedPruningSnapshotHeights())) require.NoError(t, err) } - err = manager.LoadPruningHeights(db) + err = manager.LoadPruningSnapshotHeights(db) require.Equal(t, tc.expectedResult, err) }) } } -func TestLoadPruningHeights_PruneNothing(t *testing.T) { +func TestLoadSnapshotPruningHeights_PruneNothing(t *testing.T) { manager := pruning.NewManager(db.NewMemDB(), log.NewNopLogger()) require.NotNil(t, manager) manager.SetOptions(types.NewPruningOptions(types.PruningNothing)) - require.Nil(t, manager.LoadPruningHeights(db.NewMemDB())) -} - -func TestGetFlushAndResetPruningHeights_DbErr_Panic(t *testing.T) { - ctrl := gomock.NewController(t) - - // Setup - dbMock := mock.NewMockDB(ctrl) - - dbMock.EXPECT().SetSync(gomock.Any(), gomock.Any()).Return(errors.New(dbErr)).Times(1) - - manager := pruning.NewManager(dbMock, log.NewNopLogger()) - manager.SetOptions(types.NewPruningOptions(types.PruningEverything)) - require.NotNil(t, manager) - - heights, err := manager.GetFlushAndResetPruningHeights() - require.Error(t, err) - require.Nil(t, heights) + require.Nil(t, manager.LoadPruningSnapshotHeights(db.NewMemDB())) } diff --git a/store/pruning/mock/db_mock.go b/store/pruning/mock/db_mock.go index 45e0c35c2b62..13233a852755 100644 --- a/store/pruning/mock/db_mock.go +++ b/store/pruning/mock/db_mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: /home/roman/projects/cosmos-sdk/vendor/github.com/cometbft/cometbft-db/types.go +// Source: /home/roman/projects/cosmos-sdk/vendor/github.com/cosmos/cosmos-db/types.go // Package mock_db is a generated GoMock package. package mock @@ -42,6 +42,14 @@ func (m *MockDB) Close() error { return ret0 } +// NewBatchWithSize mocks base method. +func (m *MockDB) NewBatchWithSize(arg0 int) db.Batch { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewBatchWithSize", arg0) + ret0, _ := ret[0].(db.Batch) + return ret0 +} + // Close indicates an expected call of Close. func (mr *MockDBMockRecorder) Close() *gomock.Call { mr.mock.ctrl.T.Helper() diff --git a/store/rootmulti/proof_test.go b/store/rootmulti/proof_test.go index 1871763e7e50..bca95c8200d9 100644 --- a/store/rootmulti/proof_test.go +++ b/store/rootmulti/proof_test.go @@ -15,7 +15,7 @@ import ( func TestVerifyIAVLStoreQueryProof(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - iStore, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, false, iavl.DefaultIAVLCacheSize, false) + iStore, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, iavl.DefaultIAVLCacheSize, false) store := iStore.(*iavl.Store) require.Nil(t, err) store.Set([]byte("MYKEY"), []byte("MYVALUE")) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 09c891e3d6ed..49ba19d19a91 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -282,7 +282,7 @@ func (rs *Store) loadVersion(ver int64, upgrades *types.StoreUpgrades) error { rs.stores = newStores // load any pruned heights we missed from disk to be pruned on the next run - if err := rs.pruningManager.LoadPruningHeights(rs.db); err != nil { + if err := rs.pruningManager.LoadPruningSnapshotHeights(rs.db); err != nil { return err } @@ -1000,12 +1000,7 @@ func (rs *Store) RollbackToVersion(target int64) error { // If the store is wrapped with an inter-block cache, we must first unwrap // it to get the underlying IAVL store. store = rs.GetCommitKVStore(key) - var err error - if rs.lazyLoading { - _, err = store.(*iavl.Store).LazyLoadVersionForOverwriting(target) - } else { - _, err = store.(*iavl.Store).LoadVersionForOverwriting(target) - } + err := store.(*iavl.Store).LoadVersionForOverwriting(target) if err != nil { return err } diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index f0c5b62850b5..8dc33546c4be 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -563,11 +563,7 @@ func TestMultiStore_Pruning_SameHeightsTwice(t *testing.T) { require.NoError(t, err) // Ensure already pruned heights were loaded - heights, err := ms.pruningManager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Equal(t, expectedHeights, heights) - - require.NoError(t, ms.pruningManager.LoadPruningHeights(db)) + require.NoError(t, ms.pruningManager.LoadPruningSnapshotHeights(db)) // Test pruning the same heights again lastCommitInfo = ms.Commit() @@ -590,35 +586,23 @@ func TestMultiStore_PruningRestart(t *testing.T) { ms.Commit() } - pruneHeights := []int64{1, 2, 4, 5, 7} - - // ensure we've persisted the current batch of heights to prune to the store's DB - err := ms.pruningManager.LoadPruningHeights(ms.db) - require.NoError(t, err) - - actualHeightsToPrune, err := ms.pruningManager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Equal(t, len(pruneHeights), len(actualHeightsToPrune)) - require.Equal(t, pruneHeights, actualHeightsToPrune) - + actualHeightToPrune := ms.pruningManager.GetPruningHeight(ms.LatestVersion()) + require.Equal(t, int64(0), actualHeightToPrune) // "restart" ms = newMultiStoreWithMounts(db, pruningtypes.NewCustomPruningOptions(2, 11)) ms.SetSnapshotInterval(3) - err = ms.LoadLatestVersion() - require.NoError(t, err) - - actualHeightsToPrune, err = ms.pruningManager.GetFlushAndResetPruningHeights() + err := ms.LoadLatestVersion() require.NoError(t, err) - require.Equal(t, pruneHeights, actualHeightsToPrune) + actualHeightToPrune = ms.pruningManager.GetPruningHeight(ms.LatestVersion()) + require.Equal(t, int64(0), actualHeightToPrune) // commit one more block and ensure the heights have been pruned ms.Commit() - actualHeightsToPrune, err = ms.pruningManager.GetFlushAndResetPruningHeights() - require.NoError(t, err) - require.Empty(t, actualHeightsToPrune) + actualHeightToPrune = ms.pruningManager.GetPruningHeight(ms.LatestVersion()) + require.Equal(t, int64(8), actualHeightToPrune) - for _, v := range pruneHeights { + for v := int64(1); v <= actualHeightToPrune; v++ { _, err := ms.CacheMultiStoreWithVersion(v) require.NoError(t, err, "expected error when loading height: %d", v) } diff --git a/store/types/iterator_test.go b/store/types/iterator_test.go index 6e31f0ea80e2..ce20785f5b2d 100644 --- a/store/types/iterator_test.go +++ b/store/types/iterator_test.go @@ -3,8 +3,8 @@ package types_test import ( "testing" - dbm "github.com/cosmos/cosmos-db" "cosmossdk.io/log" + dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/store/iavl" diff --git a/store/types/proof.go b/store/types/proof.go index a01ac3387e56..72cbabd00b71 100644 --- a/store/types/proof.go +++ b/store/types/proof.go @@ -5,7 +5,7 @@ import ( "github.com/cometbft/cometbft/crypto/merkle" tmmerkle "github.com/cometbft/cometbft/proto/tendermint/crypto" - ics23 "github.com/confio/ics23/go" + ics23 "github.com/cosmos/ics23/go" sdkmaps "github.com/cosmos/cosmos-sdk/store/internal/maps" sdkproofs "github.com/cosmos/cosmos-sdk/store/internal/proofs" diff --git a/store/types/store.go b/store/types/store.go index 9fc845238722..4767c4439b8d 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -4,8 +4,8 @@ import ( "fmt" "io" - dbm "github.com/cosmos/cosmos-db" abci "github.com/cometbft/cometbft/abci/types" + dbm "github.com/cosmos/cosmos-db" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" @@ -188,9 +188,6 @@ type CommitMultiStore interface { // SetIAVLDisableFastNode enables/disables fastnode feature on iavl. SetIAVLDisableFastNode(disable bool) - // SetIAVLLazyLoading enable/disable lazy loading on iavl. - SetLazyLoading(lazyLoading bool) - // RollbackToVersion rollback the db to specific version(height). RollbackToVersion(version int64) error diff --git a/testutil/mock/tendermint_tendermint_libs_log_DB.go b/testutil/mock/tendermint_tendermint_libs_log_DB.go index c194214f7e31..37ab589cda8f 100644 --- a/testutil/mock/tendermint_tendermint_libs_log_DB.go +++ b/testutil/mock/tendermint_tendermint_libs_log_DB.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/cometbft/cometbft/libs/log (interfaces: Logger) +// Source: cosmossdk.io/log (interfaces: Logger) // Package mock is a generated GoMock package. package mock @@ -68,6 +68,14 @@ func (mr *MockLoggerMockRecorder) Error(arg0 interface{}, arg1 ...interface{}) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Error", reflect.TypeOf((*MockLogger)(nil).Error), varargs...) } +// Impl mocks base method. +func (m *MockLogger) Impl() interface{} { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Impl") + ret0, _ := ret[0].(interface{}) + return ret0 +} + // Info mocks base method. func (m *MockLogger) Info(arg0 string, arg1 ...interface{}) { m.ctrl.T.Helper() diff --git a/testutil/mock/tendermint_tm_db_DB.go b/testutil/mock/tendermint_tm_db_DB.go index e2ff6306a409..ed4f941f4de2 100644 --- a/testutil/mock/tendermint_tm_db_DB.go +++ b/testutil/mock/tendermint_tm_db_DB.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/cometbft/cometbft-db (interfaces: DB) +// Source: github.com/cosmos/cosmos-db (interfaces: DB) // Package mock is a generated GoMock package. package mock @@ -85,6 +85,14 @@ func (m *MockDB) Get(arg0 []byte) ([]byte, error) { return ret0, ret1 } +// NewBatchWithSize mocks base method. +func (m *MockDB) NewBatchWithSize(arg0 int) db.Batch { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewBatchWithSize", arg0) + ret0, _ := ret[0].(db.Batch) + return ret0 +} + // Get indicates an expected call of Get. func (mr *MockDBMockRecorder) Get(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() diff --git a/testutil/network/network.go b/testutil/network/network.go index 156f6db3877f..7e4f1a4d7673 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -158,7 +158,11 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) { interfaceRegistry codectypes.InterfaceRegistry ) - if err := depinject.Inject(appConfig, + if err := depinject.Inject( + depinject.Configs( + appConfig, + depinject.Supply(tmlog.NewNopLogger()), + ), &appBuilder, &txConfig, &cdc, @@ -179,11 +183,14 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) { cfg.AppConstructor = func(val ValidatorI) servertypes.Application { // we build a unique app instance for every validator here var appBuilder *runtime.AppBuilder - if err := depinject.Inject(appConfig, &appBuilder); err != nil { + if err := depinject.Inject( + depinject.Configs( + appConfig, + depinject.Supply(val.GetCtx().Logger), + ), &appBuilder); err != nil { panic(err) } app := appBuilder.Build( - val.GetCtx().Logger, dbm.NewMemDB(), nil, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), @@ -390,7 +397,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { logger := tmlog.NewNopLogger() if cfg.EnableTMLogging { - logger = tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)) + logger = tmlog.NewLogger(os.Stdout) } ctx.Logger = logger diff --git a/testutil/network/util.go b/testutil/network/util.go index 24ad548f9418..ebdaa254c4e2 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/api" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" + servercmtlog "github.com/cosmos/cosmos-sdk/server/log" srvtypes "github.com/cosmos/cosmos-sdk/server/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -49,7 +50,7 @@ func startInProcess(cfg Config, val *Validator) error { genDocProvider, node.DefaultDBProvider, node.DefaultMetricsProvider(tmCfg.Instrumentation), - logger.With("module", val.Moniker), + servercmtlog.CometLoggerWrapper{Logger: logger.With("module", val.Moniker)}, ) if err != nil { return err diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index 86f56ba2db9d..6ffdb540cc79 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -5,7 +5,6 @@ import ( "fmt" "time" - "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmjson "github.com/cometbft/cometbft/libs/json" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -125,9 +124,9 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon } if startupConfig.BaseAppOption != nil { - app = appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil, startupConfig.BaseAppOption) + app = appBuilder.Build(dbm.NewMemDB(), nil, startupConfig.BaseAppOption) } else { - app = appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil) + app = appBuilder.Build(dbm.NewMemDB(), nil) } if err := app.Load(true); err != nil { return nil, fmt.Errorf("failed to load app: %w", err) diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index 6857df297fad..2f572e960343 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -25,7 +25,7 @@ func SetupSimulation(config simtypes.Config, dirPrefix, dbName string, verbose, var logger log.Logger if verbose { - logger = log.TestingLogger() + logger = log.NewLogger(os.Stdout) } else { logger = log.NewNopLogger() } diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index 49a09619a44d..4ca986d345e0 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -5,6 +5,8 @@ import ( "fmt" "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" @@ -64,12 +66,15 @@ func (s *paginationTestSuite) SetupTest() { ) app, err := testutilsims.Setup( - configurator.NewAppConfig( - configurator.AuthModule(), - configurator.BankModule(), - configurator.ParamsModule(), - configurator.ConsensusModule(), - configurator.OmitInitGenesis(), + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.BankModule(), + configurator.ParamsModule(), + configurator.ConsensusModule(), + configurator.OmitInitGenesis(), + ), + depinject.Supply(log.NewNopLogger()), ), &bankKeeper, &accountKeeper, ®, &cdc) diff --git a/types/store_test.go b/types/store_test.go index 461d83deeb50..fa3186aee41f 100644 --- a/types/store_test.go +++ b/types/store_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/cometbft/cometbft/libs/log" + "cosmossdk.io/log" dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/suite" diff --git a/x/auth/client/cli/encode_test.go b/x/auth/client/cli/encode_test.go index 219491b2fce6..4982107e543a 100644 --- a/x/auth/client/cli/encode_test.go +++ b/x/auth/client/cli/encode_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/testutil" @@ -24,7 +25,10 @@ func TestGetCommandEncode(t *testing.T) { ) err := depinject.Inject( - authtestutil.AppConfig, + depinject.Configs( + authtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &txCfg, &legacyAmino, &codec, @@ -64,7 +68,10 @@ func TestGetCommandDecode(t *testing.T) { ) err := depinject.Inject( - authtestutil.AppConfig, + depinject.Configs( + authtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &txCfg, &legacyAmino, &codec, diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 9be7a9015646..e08992b0ab06 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -62,7 +63,10 @@ func TestReadTxFromFile(t *testing.T) { interfaceRegistry codectypes.InterfaceRegistry ) err := depinject.Inject( - authtestutil.AppConfig, + depinject.Configs( + authtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &interfaceRegistry, &txCfg, ) @@ -101,7 +105,10 @@ func TestBatchScanner_Scan(t *testing.T) { t.Parallel() var txGen client.TxConfig err := depinject.Inject( - authtestutil.AppConfig, + depinject.Configs( + authtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &txGen, ) require.NoError(t, err) diff --git a/x/auth/migrations/v2/__debug_bin1560482944 b/x/auth/migrations/v2/__debug_bin1560482944 new file mode 100755 index 000000000000..09ef11c84d2d Binary files /dev/null and b/x/auth/migrations/v2/__debug_bin1560482944 differ diff --git a/x/auth/migrations/v2/store_test.go b/x/auth/migrations/v2/store_test.go index fd6e80b37108..61ba23d1e89e 100644 --- a/x/auth/migrations/v2/store_test.go +++ b/x/auth/migrations/v2/store_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -54,7 +56,10 @@ func TestMigrateVestingAccounts(t *testing.T) { stakingKeeper *stakingkeeper.Keeper ) app, err := simtestutil.Setup( - authtestutil.AppConfig, + depinject.Configs( + authtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper, &bankKeeper, &stakingKeeper, diff --git a/x/auth/migrations/v3/store_test.go b/x/auth/migrations/v3/store_test.go index 6e19cab3672d..fffb5cc7349e 100644 --- a/x/auth/migrations/v3/store_test.go +++ b/x/auth/migrations/v3/store_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -47,7 +49,10 @@ func TestMigrateMapAccAddressToAccNumberKey(t *testing.T) { var accountKeeper keeper.AccountKeeper app, err := simtestutil.Setup( - authtestutil.AppConfig, + depinject.Configs( + authtestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper, ) require.NoError(t, err) diff --git a/x/auth/module_test.go b/x/auth/module_test.go index 1ded4c74a38b..04b5c62c3cd9 100644 --- a/x/auth/module_test.go +++ b/x/auth/module_test.go @@ -3,6 +3,8 @@ package auth_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -14,7 +16,12 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { var accountKeeper keeper.AccountKeeper - app, err := simtestutil.SetupAtGenesis(testutil.AppConfig, &accountKeeper) + app, err := simtestutil.SetupAtGenesis( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), + &accountKeeper) require.NoError(t, err) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) diff --git a/x/auth/simulation/decoder_test.go b/x/auth/simulation/decoder_test.go index 1d71ce7ece9a..a11e357ececc 100644 --- a/x/auth/simulation/decoder_test.go +++ b/x/auth/simulation/decoder_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -30,7 +31,11 @@ func TestDecodeStore(t *testing.T) { cdc codec.Codec accountKeeper authkeeper.AccountKeeper ) - err := depinject.Inject(testutil.AppConfig, &cdc, &accountKeeper) + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc, &accountKeeper) require.NoError(t, err) acc := types.NewBaseAccountWithAddress(delAddr1) diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 023b7b477ad7..3a2efc5d8970 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" clienttx "github.com/cosmos/cosmos-sdk/client/tx" @@ -44,7 +45,11 @@ func TestBuilderWithAux(t *testing.T) { txConfig client.TxConfig ) - err := depinject.Inject(testutil.AppConfig, + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &interfaceRegistry, &txConfig, ) diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 74ab5784b199..b6d075aa4f5a 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -10,6 +10,7 @@ import ( "sigs.k8s.io/yaml" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -72,7 +73,11 @@ func TestBaseSequence(t *testing.T) { func TestBaseAccountMarshal(t *testing.T) { var accountKeeper authkeeper.AccountKeeper - err := depinject.Inject(testutil.AppConfig, &accountKeeper) + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper) require.NoError(t, err) _, pub, addr := testdata.KeyTestPubAddr() acc := types.NewBaseAccountWithAddress(addr) diff --git a/x/auth/types/genesis_test.go b/x/auth/types/genesis_test.go index 5f2001482877..a4aa46f1c349 100644 --- a/x/auth/types/genesis_test.go +++ b/x/auth/types/genesis_test.go @@ -5,6 +5,7 @@ import ( "testing" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" proto "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" @@ -55,7 +56,11 @@ func TestValidateGenesisDuplicateAccounts(t *testing.T) { func TestGenesisAccountIterator(t *testing.T) { var cdc codec.Codec - depinject.Inject(testutil.AppConfig, &cdc) + depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) acc2 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr2)) diff --git a/x/authz/migrations/v2/store_test.go b/x/authz/migrations/v2/store_test.go index 52fbf4f08eab..bb4cd38119da 100644 --- a/x/authz/migrations/v2/store_test.go +++ b/x/authz/migrations/v2/store_test.go @@ -5,6 +5,7 @@ import ( "time" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -20,7 +21,11 @@ import ( func TestMigration(t *testing.T) { var cdc codec.Codec - depinject.Inject(authztestutil.AppConfig, &cdc) + depinject.Inject( + depinject.Configs( + authztestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) authzKey := sdk.NewKVStoreKey("authz") ctx := testutil.DefaultContext(authzKey, sdk.NewTransientStoreKey("transient_test")) diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 20636a02611c..c8647cb13b83 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" @@ -41,7 +43,10 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { app, err := simtestutil.Setup( - testutil.AppConfig, + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &suite.legacyAmino, &suite.codec, &suite.interfaceRegistry, diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 5baabb258039..c75964715b51 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -3,6 +3,8 @@ package bank_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -105,16 +107,19 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s startupCfg := simtestutil.DefaultStartUpConfig() startupCfg.GenesisAccounts = genAccounts - app, err := simtestutil.SetupWithConfiguration(configurator.NewAppConfig( - configurator.ParamsModule(), - configurator.AuthModule(), - configurator.StakingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.BankModule(), - configurator.GovModule(), - ), - startupCfg, &res.BankKeeper, &res.AccountKeeper) + app, err := simtestutil.SetupWithConfiguration( + depinject.Configs( + configurator.NewAppConfig( + configurator.ParamsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ConsensusModule(), + configurator.BankModule(), + configurator.GovModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), startupCfg, &res.BankKeeper, &res.AccountKeeper) res.App = app diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index e7af77508fbe..6f950a8f4b9a 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -4,6 +4,8 @@ import ( "math/rand" "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" @@ -41,14 +43,18 @@ func (suite *SimTestSuite) SetupTest() { appBuilder *runtime.AppBuilder err error ) - suite.app, err = simtestutil.Setup(configurator.NewAppConfig( - configurator.AuthModule(), - configurator.ParamsModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.ConsensusModule(), - configurator.TxModule(), - ), &suite.accountKeeper, &suite.bankKeeper, &suite.cdc, &appBuilder) + suite.app, err = simtestutil.Setup( + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.ParamsModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.ConsensusModule(), + configurator.TxModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), &suite.accountKeeper, &suite.bankKeeper, &suite.cdc, &appBuilder) suite.NoError(err) diff --git a/x/capability/capability_test.go b/x/capability/capability_test.go index a090eec6013e..a5bbf97a0730 100644 --- a/x/capability/capability_test.go +++ b/x/capability/capability_test.go @@ -3,6 +3,8 @@ package capability_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" @@ -38,7 +40,11 @@ func (suite *CapabilityTestSuite) SetupTest() { ba.MountStores(suite.memKey) } - app, err := simtestutil.SetupWithConfiguration(testutil.AppConfig, + app, err := simtestutil.SetupWithConfiguration( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), startupCfg, &suite.cdc, &suite.keeper, diff --git a/x/capability/genesis_test.go b/x/capability/genesis_test.go index c6575ea0e226..b8f0bfb5885a 100644 --- a/x/capability/genesis_test.go +++ b/x/capability/genesis_test.go @@ -1,6 +1,8 @@ package capability_test import ( + "cosmossdk.io/depinject" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -32,7 +34,13 @@ func (suite *CapabilityTestSuite) TestGenesis() { // create new app that does not share persistent or in-memory state // and initialize app from exported genesis state above. var newKeeper *keeper.Keeper - newApp, err := simtestutil.SetupAtGenesis(testutil.AppConfig, &newKeeper) + newApp, err := simtestutil.SetupAtGenesis( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), + &newKeeper, + ) suite.Require().NoError(err) newSk1 := newKeeper.ScopeToModule(banktypes.ModuleName) diff --git a/x/capability/simulation/decoder_test.go b/x/capability/simulation/decoder_test.go index 1c3c7e6d0dd5..838b9468bc40 100644 --- a/x/capability/simulation/decoder_test.go +++ b/x/capability/simulation/decoder_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -17,7 +18,11 @@ import ( func TestDecodeStore(t *testing.T) { var cdc codec.Codec - err := depinject.Inject(testutil.AppConfig, &cdc) + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(t, err) dec := simulation.NewDecodeStore(cdc) diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go index 6667f169333f..2c6ffba1b5e1 100644 --- a/x/distribution/simulation/decoder_test.go +++ b/x/distribution/simulation/decoder_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -26,7 +27,11 @@ var ( func TestDecodeDistributionStore(t *testing.T) { var cdc codec.Codec - err := depinject.Inject(testutil.AppConfig, &cdc) + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(t, err) dec := simulation.NewDecodeStore(cdc) diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 3f9896287d21..bf590ee0cd0c 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -4,6 +4,8 @@ import ( "math/rand" "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -239,15 +241,19 @@ func (suite *SimTestSuite) SetupTest() { appBuilder *runtime.AppBuilder err error ) - suite.app, err = simtestutil.Setup(configurator.NewAppConfig( - configurator.AuthModule(), - configurator.ParamsModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.DistributionModule(), - ), &suite.accountKeeper, + suite.app, err = simtestutil.Setup( + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.ParamsModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ConsensusModule(), + configurator.DistributionModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), &suite.accountKeeper, &suite.bankKeeper, &suite.cdc, &appBuilder, diff --git a/x/evidence/genesis_test.go b/x/evidence/genesis_test.go index b8b28208abf0..67c6f5a6cc34 100644 --- a/x/evidence/genesis_test.go +++ b/x/evidence/genesis_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -29,7 +31,11 @@ type GenesisTestSuite struct { func (suite *GenesisTestSuite) SetupTest() { var evidenceKeeper keeper.Keeper - app, err := simtestutil.Setup(testutil.AppConfig, &evidenceKeeper) + app, err := simtestutil.Setup( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &evidenceKeeper) require.NoError(suite.T(), err) suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: 1}) diff --git a/x/evidence/simulation/decoder_test.go b/x/evidence/simulation/decoder_test.go index fdba04c41c2a..f39c75df7a39 100644 --- a/x/evidence/simulation/decoder_test.go +++ b/x/evidence/simulation/decoder_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -20,7 +21,11 @@ import ( func TestDecodeStore(t *testing.T) { var evidenceKeeper keeper.Keeper - err := depinject.Inject(testutil.AppConfig, &evidenceKeeper) + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &evidenceKeeper) require.NoError(t, err) dec := simulation.NewDecodeStore(evidenceKeeper) diff --git a/x/feegrant/migrations/v2/store_test.go b/x/feegrant/migrations/v2/store_test.go index 746cf0386506..d5a076b079ef 100644 --- a/x/feegrant/migrations/v2/store_test.go +++ b/x/feegrant/migrations/v2/store_test.go @@ -5,6 +5,7 @@ import ( "time" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/testutil" @@ -17,7 +18,11 @@ import ( func TestMigration(t *testing.T) { var cdc codec.Codec - depinject.Inject(feegranttestutil.AppConfig, &cdc) + depinject.Inject( + depinject.Configs( + feegranttestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) feegrantKey := sdk.NewKVStoreKey(v2.ModuleName) ctx := testutil.DefaultContext(feegrantKey, sdk.NewTransientStoreKey("transient_test")) diff --git a/x/feegrant/simulation/decoder_test.go b/x/feegrant/simulation/decoder_test.go index 055b99db8670..4e9664bf6274 100644 --- a/x/feegrant/simulation/decoder_test.go +++ b/x/feegrant/simulation/decoder_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -24,7 +25,11 @@ var ( func TestDecodeStore(t *testing.T) { var cdc codec.Codec - depinject.Inject(feegranttestutil.AppConfig, &cdc) + depinject.Inject( + depinject.Configs( + feegranttestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) dec := simulation.NewDecodeStore(cdc) grant, err := feegrant.NewGrant(granterAddr, granteeAddr, &feegrant.BasicAllowance{ diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 8b97f524046a..44825b737439 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" @@ -38,7 +40,11 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { var err error - suite.app, err = simtestutil.Setup(testutil.AppConfig, + suite.app, err = simtestutil.Setup( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &suite.feegrantKeeper, &suite.bankKeeper, &suite.accountKeeper, diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index ba08ac4f235a..ed4678bc9cd4 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/server" + servercmtlog "github.com/cosmos/cosmos-sdk/server/log" "github.com/cosmos/cosmos-sdk/server/mock" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -201,7 +202,7 @@ func TestEmptyState(t *testing.T) { func TestStartStandAlone(t *testing.T) { home := t.TempDir() - logger := log.NewNopLogger() + logger := log.NewTestLogger(t) interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) err := genutiltest.ExecInitCmd(testMbm, home, marshaler) @@ -216,7 +217,7 @@ func TestStartStandAlone(t *testing.T) { svr, err := abci_server.NewServer(svrAddr, "socket", app) require.NoError(t, err, "error creating listener") - svr.SetLogger(logger.With("module", "abci-server")) + svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: logger.With("module", "abci-server")}) err = svr.Start() require.NoError(t, err) diff --git a/x/gov/common_test.go b/x/gov/common_test.go index 6bca2818cb83..bdd45a49297b 100644 --- a/x/gov/common_test.go +++ b/x/gov/common_test.go @@ -6,6 +6,8 @@ import ( "sort" "testing" + "cosmossdk.io/depinject" + cmtlog "cosmossdk.io/log" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -109,15 +111,17 @@ func createTestSuite(t *testing.T) suite { res := suite{} app, err := simtestutil.SetupWithConfiguration( - configurator.NewAppConfig( - configurator.ParamsModule(), - configurator.AuthModule(), - configurator.StakingModule(), - configurator.BankModule(), - configurator.GovModule(), - configurator.ConsensusModule(), - ), - simtestutil.DefaultStartUpConfig(), + depinject.Configs( + configurator.NewAppConfig( + configurator.ParamsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.BankModule(), + configurator.GovModule(), + configurator.ConsensusModule(), + ), + depinject.Supply(cmtlog.NewNopLogger()), + ), simtestutil.DefaultStartUpConfig(), &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, ) require.NoError(t, err) diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 20d20f539cfa..1410eaed5cac 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -338,15 +340,19 @@ type suite struct { func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) { res := suite{} - app, err := simtestutil.Setup(configurator.NewAppConfig( - configurator.AuthModule(), - configurator.TxModule(), - configurator.ParamsModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.ConsensusModule(), - configurator.GovModule(), - ), &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, &res.cdc) + app, err := simtestutil.Setup( + depinject.Configs( + configurator.NewAppConfig( + configurator.AuthModule(), + configurator.TxModule(), + configurator.ParamsModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.ConsensusModule(), + configurator.GovModule(), + ), + depinject.Supply(log.NewNopLogger()), + ), &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, &res.cdc) require.NoError(t, err) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) diff --git a/x/group/module/abci_test.go b/x/group/module/abci_test.go index 78b68fa655bc..ff52ca731a34 100644 --- a/x/group/module/abci_test.go +++ b/x/group/module/abci_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmtime "github.com/cometbft/cometbft/types/time" "github.com/stretchr/testify/suite" @@ -41,7 +43,10 @@ func TestIntegrationTestSuite(t *testing.T) { func (s *IntegrationTestSuite) SetupTest() { app, err := simtestutil.Setup( - grouptestutil.AppConfig, + depinject.Configs( + grouptestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &s.interfaceRegistry, &s.bankKeeper, &s.stakingKeeper, diff --git a/x/group/proposal_test.go b/x/group/proposal_test.go index 8e741908db70..b97968ce206f 100644 --- a/x/group/proposal_test.go +++ b/x/group/proposal_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/group" "github.com/cosmos/cosmos-sdk/x/group/testutil" @@ -17,7 +18,11 @@ import ( // multiple times into the same reference. func TestGogoUnmarshalProposal(t *testing.T) { var cdc codec.Codec - err := depinject.Inject(testutil.AppConfig, &cdc) + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(t, err) p1 := group.Proposal{Proposers: []string{"foo"}} diff --git a/x/group/simulation/decoder_test.go b/x/group/simulation/decoder_test.go index 74106303f6ba..10adfce5ceb5 100644 --- a/x/group/simulation/decoder_test.go +++ b/x/group/simulation/decoder_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types/kv" @@ -19,7 +20,11 @@ import ( func TestDecodeStore(t *testing.T) { var cdc codec.Codec - err := depinject.Inject(grouptestutil.AppConfig, &cdc) + err := depinject.Inject( + depinject.Configs( + grouptestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(t, err) dec := simulation.NewDecodeStore(cdc) diff --git a/x/group/simulation/genesis_test.go b/x/group/simulation/genesis_test.go index db09434920ac..df8d43619d66 100644 --- a/x/group/simulation/genesis_test.go +++ b/x/group/simulation/genesis_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/depinject" + "cosmossdk.io/log" sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" @@ -19,7 +20,11 @@ import ( func TestRandomizedGenState(t *testing.T) { var cdc codec.Codec - err := depinject.Inject(testutil.AppConfig, &cdc) + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc) require.NoError(t, err) s := rand.NewSource(1) diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index 31d196ca75e4..19c2bb197eac 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/suite" @@ -40,7 +42,10 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { app, err := simtestutil.Setup( - grouptestutil.AppConfig, + depinject.Configs( + grouptestutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &suite.codec, &suite.interfaceRegistry, &suite.accountKeeper, diff --git a/x/mint/module_test.go b/x/mint/module_test.go index 4de8ab6f61db..cb0dfb3144e0 100644 --- a/x/mint/module_test.go +++ b/x/mint/module_test.go @@ -3,6 +3,8 @@ package mint_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -16,7 +18,11 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { var accountKeeper authkeeper.AccountKeeper - app, err := simtestutil.SetupAtGenesis(testutil.AppConfig, &accountKeeper) + app, err := simtestutil.SetupAtGenesis( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper) require.NoError(t, err) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) diff --git a/x/nft/simulation/operations_test.go b/x/nft/simulation/operations_test.go index f46bdc61e03a..5a6f4754150e 100644 --- a/x/nft/simulation/operations_test.go +++ b/x/nft/simulation/operations_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/stretchr/testify/suite" abci "github.com/cometbft/cometbft/abci/types" @@ -42,7 +44,10 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { app, err := simtestutil.Setup( - testutil.AppConfig, + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &suite.codec, &suite.interfaceRegistry, &suite.accountKeeper, diff --git a/x/params/keeper/common_test.go b/x/params/keeper/common_test.go index 27b6295a65b1..b79523513259 100644 --- a/x/params/keeper/common_test.go +++ b/x/params/keeper/common_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "cosmossdk.io/depinject" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdktestutil "github.com/cosmos/cosmos-sdk/testutil" @@ -12,7 +13,11 @@ import ( func testComponents() (*codec.LegacyAmino, sdk.Context, storetypes.StoreKey, storetypes.StoreKey, paramskeeper.Keeper) { var cdc codec.Codec - if err := depinject.Inject(testutil.AppConfig, &cdc); err != nil { + if err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &cdc); err != nil { panic(err) } diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index 733ff5a02cdd..d85c175861ef 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -37,7 +37,11 @@ func (suite *SubspaceTestSuite) SetupTest() { ms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) suite.NoError(ms.LoadLatestVersion()) - err := depinject.Inject(testutil.AppConfig, + err := depinject.Inject( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &suite.cdc, &suite.amino, ) diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index f0758ea9b711..c2f9aabd26e3 100644 --- a/x/slashing/abci_test.go +++ b/x/slashing/abci_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -28,7 +30,10 @@ func TestBeginBlocker(t *testing.T) { var slashingKeeper slashingkeeper.Keeper app, err := simtestutil.Setup( - testutil.AppConfig, + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &interfaceRegistry, &bankKeeper, &stakingKeeper, diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 9f5b47aedb17..f65562609408 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -8,6 +8,8 @@ import ( tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -51,14 +53,18 @@ func TestSlashingMsgs(t *testing.T) { slashingKeeper keeper.Keeper ) - app, err := sims.SetupWithConfiguration(configurator.NewAppConfig( - configurator.ParamsModule(), - configurator.AuthModule(), - configurator.StakingModule(), - configurator.SlashingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.BankModule()), + app, err := sims.SetupWithConfiguration( + depinject.Configs( + configurator.NewAppConfig( + configurator.ParamsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.SlashingModule(), + configurator.TxModule(), + configurator.ConsensusModule(), + configurator.BankModule()), + depinject.Supply(log.NewNopLogger()), + ), startupCfg, &stakingKeeper, &bankKeeper, &slashingKeeper) baseApp := app.BaseApp diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 991ac17f0b3c..43f9963b9a4d 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -11,6 +11,8 @@ import ( tmtypes "github.com/cometbft/cometbft/types" "github.com/stretchr/testify/suite" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" @@ -76,7 +78,10 @@ func (suite *SimTestSuite) SetupTest() { startupCfg.ValidatorSet = createValidator app, err := simtestutil.SetupWithConfiguration( - testutil.AppConfig, + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), startupCfg, &suite.legacyAmino, &suite.codec, diff --git a/x/staking/app_test.go b/x/staking/app_test.go index fb5305a39992..8099eafa779f 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -5,6 +5,8 @@ import ( "github.com/stretchr/testify/require" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -53,7 +55,11 @@ func TestStakingMsgs(t *testing.T) { startupCfg := simtestutil.DefaultStartUpConfig() startupCfg.GenesisAccounts = accs - app, err := simtestutil.SetupWithConfiguration(testutil.AppConfig, startupCfg, &bankKeeper, &stakingKeeper) + app, err := simtestutil.SetupWithConfiguration( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), startupCfg, &bankKeeper, &stakingKeeper) require.NoError(t, err) ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) diff --git a/x/staking/module_test.go b/x/staking/module_test.go index d2dcd54d956e..51a05c4d7825 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -3,6 +3,8 @@ package staking_test import ( "testing" + "cosmossdk.io/depinject" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -15,7 +17,10 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { var accountKeeper authKeeper.AccountKeeper - app, err := simtestutil.SetupAtGenesis(testutil.AppConfig, &accountKeeper) + app, err := simtestutil.SetupAtGenesis(depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), &accountKeeper) require.NoError(t, err) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index de7bbb4f05ee..f914a1a4918e 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "cosmossdk.io/depinject" + "cosmossdk.io/log" "cosmossdk.io/math" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -86,7 +88,11 @@ func (s *SimTestSuite) SetupTest() { stakingKeeper *stakingkeeper.Keeper ) - app, err := simtestutil.SetupWithConfiguration(testutil.AppConfig, startupCfg, &bankKeeper, &accountKeeper, &mintKeeper, &distrKeeper, &stakingKeeper) + app, err := simtestutil.SetupWithConfiguration( + depinject.Configs( + testutil.AppConfig, + depinject.Supply(log.NewNopLogger()), + ), startupCfg, &bankKeeper, &accountKeeper, &mintKeeper, &distrKeeper, &stakingKeeper) require.NoError(s.T(), err) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index c17eaea2f88a..72320ea7a26e 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -7,7 +7,6 @@ import ( "testing" "cosmossdk.io/log" - tmlog "cosmossdk.io/log" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" @@ -26,10 +25,6 @@ func useUpgradeLoader(height int64, upgrades *storetypes.StoreUpgrades) func(*ba } } -func defaultLogger() log.Logger { - return tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)) -} - func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db, log.NewNopLogger()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) @@ -121,7 +116,9 @@ func TestSetLoader(t *testing.T) { // load the app with the existing db opts := []func(*baseapp.BaseApp){baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))} - origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) + logger := log.NewTestLogger(t) + + origapp := baseapp.NewBaseApp(t.Name(), logger.With("instance", "orig"), db, nil, opts...) origapp.MountStores(sdk.NewKVStoreKey(tc.origStoreKey)) err := origapp.LoadLatestVersion() require.Nil(t, err) @@ -137,7 +134,7 @@ func TestSetLoader(t *testing.T) { } // load the new app with the original app db - app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) + app := baseapp.NewBaseApp(t.Name(), logger.With("instance", "new"), db, nil, opts...) app.MountStores(sdk.NewKVStoreKey(tc.loadStoreKey)) err = app.LoadLatestVersion() require.Nil(t, err)