From fce33125c861d027bdb9cb3fe143a59911b71c83 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 21 Dec 2023 10:44:51 -0600 Subject: [PATCH 01/11] Remove GetAccount calls in epoch --- x/bank/keeper/send.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index e1f2c9b65f20..fce3008aa8eb 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -292,11 +292,12 @@ func (k BaseSendKeeper) SendManyCoins(ctx sdk.Context, fromAddr sdk.AccAddress, return err } - acc := k.ak.GetAccount(ctx, toAddr) - if acc == nil { - defer telemetry.IncrCounter(1, "new", "account") - k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, toAddr)) - } + // Not needed for epoch code, every user must have an account + // acc := k.ak.GetAccount(ctx, toAddr) + // if acc == nil { + // defer telemetry.IncrCounter(1, "new", "account") + // k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, toAddr)) + // } ctx.EventManager().EmitEvent(sdk.NewEvent( types.EventTypeTransfer, From cc29414c72c73d567e0c75b4a0800961a26d7af4 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 22 Dec 2023 14:25:44 -0600 Subject: [PATCH 02/11] Types speedups --- math/int.go | 4 ---- types/coin.go | 8 ++++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/math/int.go b/math/int.go index 6811893f7a47..3bf9ac624ee6 100644 --- a/math/int.go +++ b/math/int.go @@ -263,10 +263,6 @@ func (i Int) Mul(i2 Int) (res Int) { panic("Int overflow") } res = Int{mul(i.i, i2.i)} - // Check overflow if sign of both are same - if res.i.BitLen() > MaxBitLen { - panic("Int overflow") - } return } diff --git a/types/coin.go b/types/coin.go index ec3c90f3527c..41a8b24f52cf 100644 --- a/types/coin.go +++ b/types/coin.go @@ -310,6 +310,8 @@ func (coins Coins) Add(coinsB ...Coin) Coins { return coins.safeAdd(coinsB) } +var zeroInt = NewInt(0) + // safeAdd will perform addition of two coins sets. If both coin sets are // empty, then an empty set is returned. If only a single set is empty, the // other set is returned. Otherwise, the coins are compared in order of their @@ -335,7 +337,7 @@ func (coins Coins) safeAdd(coinsB Coins) (coalesced Coins) { } for denom, cL := range uniqCoins { //#nosec - comboCoin := Coin{Denom: denom, Amount: NewInt(0)} + comboCoin := Coin{Denom: denom, Amount: zeroInt} for _, c := range cL { comboCoin = comboCoin.Add(c) } @@ -827,7 +829,9 @@ var _ sort.Interface = Coins{} // Sort is a helper function to sort the set of coins in-place func (coins Coins) Sort() Coins { - sort.Sort(coins) + if len(coins) > 1 { + sort.Sort(coins) + } return coins } From 6652b67a6ae8be03a8bc9c54ee776c4169e5f81a Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Wed, 3 Jan 2024 16:53:27 -0600 Subject: [PATCH 03/11] feat!: bring back the cliff vesting command (#111) #271 --- x/auth/vesting/client/cli/tx.go | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/x/auth/vesting/client/cli/tx.go b/x/auth/vesting/client/cli/tx.go index c0f5189f7562..5c2770840417 100644 --- a/x/auth/vesting/client/cli/tx.go +++ b/x/auth/vesting/client/cli/tx.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "strconv" + "time" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) @@ -40,6 +42,7 @@ func GetTxCmd() *cobra.Command { NewMsgCreatePermanentLockedAccountCmd(), NewMsgCreatePeriodicVestingAccountCmd(), NewMsgCreateClawbackVestingAccountCmd(), + NewMsgCreateCliffVestingAccountCmd(), NewMsgClawbackCmd(), ) @@ -377,3 +380,50 @@ func NewMsgClawbackCmd() *cobra.Command { flags.AddTxFlagsToCmd(cmd) return cmd } + +// NewMsgCreateDelayedVestingAccountCmd returns a CLI command handler for creating a +// NewMsgCreateDelayedVestingAccountCmd transaction. +// This is hacky, but meant to mitigate the pain of a very specific use case. +// Namely, make it easy to make cliff locks to an address. +func NewMsgCreateCliffVestingAccountCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-cliff-vesting-account [to_address] [amount] [cliff_duration]", + Short: "Create a new cliff vesting account funded with an allocation of tokens.", + Long: `Create a new delayed vesting account funded with an allocation of tokens. All vesting accouts created will have their start time +set by the committed block's time. The cliff duration should be specified in hours.`, + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + toAddr, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + amount, err := sdk.ParseCoinsNormalized(args[1]) + if err != nil { + return err + } + + cliffDuration, err := time.ParseDuration(args[2]) + if err != nil { + err = errors.Wrap(err, "duration incorrectly formatted, see https://pkg.go.dev/time#ParseDuration") + return err + } + cliffVesting := true + + endTime := time.Now().Add(cliffDuration) + endEpochTime := endTime.Unix() + + msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, endEpochTime, cliffVesting) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} From b85d6b8f70a67d3a36ddcc849e7da48694383a79 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 5 Jan 2024 16:22:56 -0600 Subject: [PATCH 04/11] De-dup param getting --- x/slashing/keeper/params.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/keeper/params.go b/x/slashing/keeper/params.go index 4c7fc1824694..b21a4f5a84c8 100644 --- a/x/slashing/keeper/params.go +++ b/x/slashing/keeper/params.go @@ -15,7 +15,7 @@ func (k Keeper) SignedBlocksWindow(ctx sdk.Context) (res int64) { // MinSignedPerWindow - minimum blocks signed per window func (k Keeper) MinSignedPerWindow(ctx sdk.Context) int64 { params := k.GetParams(ctx) - signedBlocksWindow := k.SignedBlocksWindow(ctx) + signedBlocksWindow := params.SignedBlocksWindow // NOTE: RoundInt64 will never panic as minSignedPerWindow is // less than 1. From 7d98c6aea6614476eb1c708fbe5ddbe80e775260 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 5 Jan 2024 16:38:42 -0600 Subject: [PATCH 05/11] Disable DenomOwners tracking --- x/bank/keeper/grpc_query.go | 37 +---------------------- x/bank/keeper/grpc_query_test.go | 22 ++++---------- x/bank/keeper/send.go | 50 +------------------------------- 3 files changed, 7 insertions(+), 102 deletions(-) diff --git a/x/bank/keeper/grpc_query.go b/x/bank/keeper/grpc_query.go index 7cfc9beb8eca..93f92fce87c8 100644 --- a/x/bank/keeper/grpc_query.go +++ b/x/bank/keeper/grpc_query.go @@ -250,42 +250,7 @@ func (k BaseKeeper) DenomOwners( if req == nil { return nil, status.Errorf(codes.InvalidArgument, "empty request") } - - if err := sdk.ValidateDenom(req.Denom); err != nil { - return nil, status.Error(codes.InvalidArgument, err.Error()) - } - - ctx := sdk.UnwrapSDKContext(goCtx) - denomPrefixStore := k.getDenomAddressPrefixStore(ctx, req.Denom) - - var denomOwners []*types.DenomOwner - pageRes, err := query.FilteredPaginate( - denomPrefixStore, - req.Pagination, - func(key []byte, _ []byte, accumulate bool) (bool, error) { - if accumulate { - address, _, err := types.AddressAndDenomFromBalancesStore(key) - if err != nil { - return false, err - } - - denomOwners = append( - denomOwners, - &types.DenomOwner{ - Address: address.String(), - Balance: k.GetBalance(ctx, address, req.Denom), - }, - ) - } - - return true, nil - }, - ) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - - return &types.QueryDenomOwnersResponse{DenomOwners: denomOwners, Pagination: pageRes}, nil + return nil, status.Error(codes.Unimplemented, "not implemented on Osmosis. Use an indexer.") } func (k BaseKeeper) SendEnabled(goCtx context.Context, req *types.QuerySendEnabledRequest) (*types.QuerySendEnabledResponse, error) { diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index 610bc356e5be..abd2fcbaaeb0 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -495,7 +495,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { req: &types.QueryDenomOwnersRequest{ Denom: "foo", }, - expPass: true, + expPass: false, numAddrs: 0, hasNext: false, total: 0, @@ -508,7 +508,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { CountTotal: true, }, }, - expPass: true, + expPass: false, numAddrs: 6, hasNext: true, total: 10, @@ -522,7 +522,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { CountTotal: true, }, }, - expPass: true, + expPass: false, numAddrs: 4, hasNext: false, total: 10, @@ -532,20 +532,8 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { for name, tc := range testCases { suite.Run(name, func() { resp, err := suite.queryClient.DenomOwners(gocontext.Background(), tc.req) - if tc.expPass { - suite.NoError(err) - suite.NotNil(resp) - suite.Len(resp.DenomOwners, tc.numAddrs) - suite.Equal(tc.total, resp.Pagination.Total) - - if tc.hasNext { - suite.NotNil(resp.Pagination.NextKey) - } else { - suite.Nil(resp.Pagination.NextKey) - } - } else { - suite.Require().Error(err) - } + suite.Require().Error(err) + suite.Require().Nil(resp) }) } diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index fce3008aa8eb..666d335df1b4 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -368,7 +368,6 @@ func (k BaseSendKeeper) addCoinsImproved(ctx sdk.Context, addr sdk.AccAddress, a balance := k.GetBalance(ctx, addr, coin.Denom) newBalance := balance.Add(coin) - // err := k.setBalance(ctx, addr, balance, newBalance) err := k.setBalance(ctx, addr, newBalance) if err != nil { return err @@ -444,47 +443,6 @@ func (k BaseSendKeeper) initBalances(ctx sdk.Context, addr sdk.AccAddress, balan // 2 blocks after osmosis first epoch var osmosisFirstEpochHeight = int64(12834361) -// Better add coins implementation for code that is not gas metered. Reduces I/O overhead. -// Used in osmosis epoch. -// Also removes event that should not exist. -// SDK should always use this for teh denom reverse map, but we can't edit right now as that would be a state break. -// Furthermore, this reverse map code should just get deleted. -func (k BaseSendKeeper) setBalanceImproved(ctx sdk.Context, addr sdk.AccAddress, oldBalance sdk.Coin, newBalance sdk.Coin) error { - if !newBalance.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, oldBalance.String()) - } - - accountStore := k.getAccountStore(ctx, addr) - denomPrefixStore := k.getDenomAddressPrefixStore(ctx, oldBalance.Denom) - // x/bank invariants prohibit persistence of zero balances - if newBalance.IsZero() { - accountStore.Delete([]byte(newBalance.Denom)) - denomPrefixStore.Delete(address.MustLengthPrefix(addr)) - } else { - amount, err := newBalance.Amount.Marshal() - if err != nil { - return err - } - - accountStore.Set([]byte(newBalance.Denom), amount) - - mustSetDenom := oldBalance.IsZero() - if ctx.BlockHeight() <= osmosisFirstEpochHeight || newBalance.Denom != "uosmo" { - mustSetDenom = true - } - if mustSetDenom { - // Store a reverse index from denomination to account address with a - // sentinel value. - denomAddrKey := address.MustLengthPrefix(addr) - if !denomPrefixStore.Has(denomAddrKey) { - denomPrefixStore.Set(denomAddrKey, []byte{0}) - } - } - } - - return nil -} - // setBalance sets the coin balance for an account by address. func (k BaseSendKeeper) setBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error { if !balance.IsValid() { @@ -505,13 +463,7 @@ func (k BaseSendKeeper) setBalance(ctx sdk.Context, addr sdk.AccAddress, balance } accountStore.Set([]byte(balance.Denom), amount) - - // Store a reverse index from denomination to account address with a - // sentinel value. - denomAddrKey := address.MustLengthPrefix(addr) - if !denomPrefixStore.Has(denomAddrKey) { - denomPrefixStore.Set(denomAddrKey, []byte{0}) - } + // We deleted denomPrefixStore setting. } return nil From 7ff0763fd1f96b46dc7f6527a3ef08d47b785493 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Sat, 6 Jan 2024 13:53:51 -0600 Subject: [PATCH 06/11] feat: extra app hash logs (#500) * app hash error print * extra logging for app hash * remove old comment --- go.mod | 1 + go.sum | 4 ++-- server/mock/store.go | 4 ++++ server/start.go | 56 ++++++++++++++++++++++++++++++++++++++++++++ store/types/store.go | 3 +++ 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index b8c8ac122d25..b77a2fe25ac6 100644 --- a/go.mod +++ b/go.mod @@ -181,6 +181,7 @@ require ( replace ( // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 + github.com/cometbft/cometbft => github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146 // dgrijalva/jwt-go is deprecated and doesn't receive security updates. // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 diff --git a/go.sum b/go.sum index f827f8cff5d1..6b8df5b084ab 100644 --- a/go.sum +++ b/go.sum @@ -312,8 +312,6 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coinbase/rosetta-sdk-go/types v1.0.0 h1:jpVIwLcPoOeCR6o1tU+Xv7r5bMONNbHU7MuEHboiFuA= github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c= -github.com/cometbft/cometbft v0.37.2 h1:XB0yyHGT0lwmJlFmM4+rsRnczPlHoAKFX6K8Zgc2/Jc= -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= @@ -806,6 +804,8 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA= +github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146 h1:Qkshh58fZCRoHSzbyW8NJf1wBhf9bg1MPFZEuyuI9lE= +github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= diff --git a/server/mock/store.go b/server/mock/store.go index 192c58e5526e..45624f159c84 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -160,6 +160,10 @@ func (ms multiStore) LatestVersion() int64 { panic("not implemented") } +func (ms multiStore) GetCommitInfo(key int64) (*storetypes.CommitInfo, error) { + panic("not implemented") +} + var _ sdk.KVStore = kvStore{} type kvStore struct { diff --git a/server/start.go b/server/start.go index 061b736cf6a5..374dc5e98572 100644 --- a/server/start.go +++ b/server/start.go @@ -9,6 +9,8 @@ import ( "net/http" "os" "runtime/pprof" + "sort" + "strings" "time" "github.com/cometbft/cometbft/abci/server" @@ -22,6 +24,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "encoding/hex" + "cosmossdk.io/tools/rosetta" crgserver "cosmossdk.io/tools/rosetta/lib/server" "github.com/cosmos/cosmos-sdk/client" @@ -32,6 +36,7 @@ import ( servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" "github.com/cosmos/cosmos-sdk/server/types" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" @@ -334,6 +339,18 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App if err := tmNode.Start(); err != nil { return err } + + // Start a goroutine to listen for appHash errors from consensus layer. + go func() { + for appHashError := range tmNode.BCReactor().AppHashErrorsCh() { + // If an error is received, call returnCommitInfo + if appHashError.Err != nil { + if commitInfoErr := returnCommitInfo(ctx, app, int64(appHashError.Height)); commitInfoErr != nil { + ctx.Logger.Error("failed to return commit info", "err", commitInfoErr) + } + } + } + }() } // Add the tx service to the gRPC router. We only need to register this @@ -566,3 +583,42 @@ func wrapCPUProfile(ctx *Context, callback func() error) error { return WaitForQuitSignals() } + +// returnCommitInfo returns the individual app hashes for every module given a version (height). +func returnCommitInfo(ctx *Context, app types.Application, version int64) error { + commitInfoForHeight, err := app.CommitMultiStore().GetCommitInfo(version) + if err != nil { + return err + } + + // Create a new slice of StoreInfos for storing the modified hashes. + storeInfos := make([]storetypes.StoreInfo, len(commitInfoForHeight.StoreInfos)) + + for i, storeInfo := range commitInfoForHeight.StoreInfos { + // Convert the hash to a hexadecimal string. + hash := strings.ToUpper(hex.EncodeToString(storeInfo.CommitId.Hash)) + + // Create a new StoreInfo with the modified hash. + storeInfos[i] = storetypes.StoreInfo{ + Name: storeInfo.Name, + CommitId: storetypes.CommitID{ + Version: storeInfo.CommitId.Version, + Hash: []byte(hash), + }, + } + } + + // Sort the storeInfos slice based on the module name. + sort.Slice(storeInfos, func(i, j int) bool { + return storeInfos[i].Name < storeInfos[j].Name + }) + + // Create a new CommitInfo with the modified StoreInfos. + commitInfoForHeight = &storetypes.CommitInfo{ + Version: commitInfoForHeight.Version, + StoreInfos: storeInfos, + } + + ctx.Logger.Error("your node has app hashed. Compare each module's hashes with a node that did not app hash to determine the problematic module", "commitInfo", commitInfoForHeight.String()) + return nil +} diff --git a/store/types/store.go b/store/types/store.go index 992173195661..01a71306d068 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -154,6 +154,9 @@ type CommitMultiStore interface { // Panics on a nil key. GetCommitKVStore(key StoreKey) CommitKVStore + // Panics on a nil version. + GetCommitInfo(ver int64) (*CommitInfo, error) + // Load the latest persisted version. Called once after all calls to // Mount*Store() are complete. LoadLatestVersion() error From 65d7acfdc2a94cc49837bb9abec462f129029540 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 8 Jan 2024 12:38:48 -0600 Subject: [PATCH 07/11] split param getter and unmarshal (#502) --- x/consensus/keeper/keeper.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index a4a255055bfd..4a7ac9ffe2bc 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -56,3 +56,17 @@ func (k *Keeper) Set(ctx sdk.Context, cp *tmproto.ConsensusParams) { store := ctx.KVStore(k.storeKey) store.Set(types.ParamStoreKeyConsensusParams, k.cdc.MustMarshal(cp)) } + +func (k *Keeper) GetParamsNoUnmarshal(ctx sdk.Context) []byte { + store := ctx.KVStore(k.storeKey) + return store.Get(types.ParamStoreKeyConsensusParams) +} + +func (k *Keeper) UnmarshalParamBytes(ctx sdk.Context, bz []byte) (*tmproto.ConsensusParams, error) { + cp := &tmproto.ConsensusParams{} + if err := k.cdc.Unmarshal(bz, cp); err != nil { + return nil, err + } + + return cp, nil +} From ca869a2b10d0dbffb767ae7240b4977e61f6922c Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Tue, 9 Jan 2024 10:42:02 -0600 Subject: [PATCH 08/11] Fix some tests --- baseapp/block_gas_test.go | 2 +- x/bank/migrations/v3/store_test.go | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 81b39a0c2a81..d14f9077e801 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -167,7 +167,7 @@ func TestBaseApp_BlockGas(t *testing.T) { require.Equal(t, []byte("ok"), okValue) } // check block gas is always consumed - baseGas := uint64(51682) // baseGas is the gas consumed before tx msg + baseGas := uint64(47842) // baseGas is the gas consumed before tx msg expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas) if expGasConsumed > uint64(simtestutil.DefaultConsensusParams.Block.MaxGas) { // capped by gasLimit diff --git a/x/bank/migrations/v3/store_test.go b/x/bank/migrations/v3/store_test.go index 52e9efdcd324..51ff85067895 100644 --- a/x/bank/migrations/v3/store_test.go +++ b/x/bank/migrations/v3/store_test.go @@ -5,12 +5,9 @@ import ( "github.com/stretchr/testify/require" - "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/store/prefix" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" v2 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2" v3 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v3" @@ -40,19 +37,19 @@ func TestMigrateStore(t *testing.T) { require.NoError(t, v3.MigrateStore(ctx, bankKey, encCfg.Codec)) - for _, b := range balances { - addrPrefixStore := prefix.NewStore(store, types.CreateAccountBalancesPrefix(addr)) - bz := addrPrefixStore.Get([]byte(b.Denom)) - var expected math.Int - require.NoError(t, expected.Unmarshal(bz)) - require.Equal(t, expected, b.Amount) - } - - for _, b := range balances { - denomPrefixStore := prefix.NewStore(store, v3.CreateDenomAddressPrefix(b.Denom)) - bz := denomPrefixStore.Get(address.MustLengthPrefix(addr)) - require.NotNil(t, bz) - } + // for _, b := range balances { + // addrPrefixStore := prefix.NewStore(store, types.CreateAccountBalancesPrefix(addr)) + // bz := addrPrefixStore.Get([]byte(b.Denom)) + // var expected math.Int + // require.NoError(t, expected.Unmarshal(bz)) + // require.Equal(t, expected, b.Amount) + // } + + // for _, b := range balances { + // denomPrefixStore := prefix.NewStore(store, v3.CreateDenomAddressPrefix(b.Denom)) + // bz := denomPrefixStore.Get(address.MustLengthPrefix(addr)) + // require.NotNil(t, bz) + // } } func TestMigrateDenomMetaData(t *testing.T) { From cf358f6fc20cabfb5cb8ce75fc10b2623150869e Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Fri, 12 Jan 2024 12:30:34 -0700 Subject: [PATCH 09/11] chore(types): replace amino json encoder with stdlib --- types/result.go | 2 +- types/result_test.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/types/result.go b/types/result.go index 7f4910ac45ec..536a37828271 100644 --- a/types/result.go +++ b/types/result.go @@ -49,7 +49,7 @@ func NewABCIMessageLog(i uint32, log string, events Events) ABCIMessageLog { // String implements the fmt.Stringer interface for the ABCIMessageLogs type. func (logs ABCIMessageLogs) String() (str string) { if logs != nil { - raw, err := cdc.MarshalJSON(logs) + raw, err := json.Marshal(logs) if err == nil { str = string(raw) } diff --git a/types/result_test.go b/types/result_test.go index fe79c8c13f84..d68b05a6608c 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -2,6 +2,7 @@ package types_test import ( "encoding/hex" + "encoding/json" "fmt" "strings" "testing" @@ -13,7 +14,6 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -41,14 +41,13 @@ func (s *resultTestSuite) TestParseABCILog() { } func (s *resultTestSuite) TestABCIMessageLog() { - cdc := codec.NewLegacyAmino() events := sdk.Events{ sdk.NewEvent("transfer", sdk.NewAttribute("sender", "foo")), sdk.NewEvent("transfer", sdk.NewAttribute("sender", "bar")), } msgLog := sdk.NewABCIMessageLog(0, "", events) msgLogs := sdk.ABCIMessageLogs{msgLog} - bz, err := cdc.MarshalJSON(msgLogs) + bz, err := json.Marshal(msgLogs) s.Require().NoError(err) s.Require().Equal(string(bz), msgLogs.String()) From e731ee92142765ab85caeded9946535e4a33f021 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Sun, 14 Jan 2024 14:52:46 -0600 Subject: [PATCH 10/11] feat: config option to log gRPC queries (#503) * config option to log gRPC queries * clarify gRPC log comment * create var --- baseapp/grpcserver.go | 7 ++++++- server/config/config.go | 8 ++++++++ server/config/toml.go | 5 +++++ server/grpc/server.go | 2 +- server/types/app.go | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/baseapp/grpcserver.go b/baseapp/grpcserver.go index d04f71d1abce..0b77d7c471e4 100644 --- a/baseapp/grpcserver.go +++ b/baseapp/grpcserver.go @@ -2,6 +2,7 @@ package baseapp import ( "context" + "fmt" "strconv" gogogrpc "github.com/cosmos/gogoproto/grpc" @@ -21,7 +22,7 @@ import ( func (app *BaseApp) GRPCQueryRouter() *GRPCQueryRouter { return app.grpcQueryRouter } // RegisterGRPCServer registers gRPC services directly with the gRPC server. -func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { +func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server, logQueries bool) { // Define an interceptor for all gRPC queries: this interceptor will create // a new sdk.Context, and pass it into the query handler. interceptor := func(grpcCtx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { @@ -65,6 +66,10 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { app.logger.Error("failed to set gRPC header", "err", err) } + if logQueries { + app.logger.Info("gRPC query received of type: " + fmt.Sprintf("%#v", req)) + } + return handler(grpcCtx, req) } diff --git a/server/config/config.go b/server/config/config.go index 90dad0c943cb..cd9d814abe81 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -34,6 +34,10 @@ const ( // bytes the server can send. DefaultGRPCMaxSendMsgSize = math.MaxInt32 + // DefaultLogQueries defines the default value for the log_queries parameter. + // Should be set to false unless debugging. + DefaultLogQueries = false + // FileStreamer defines the store streaming type for file streaming. FileStreamer = "file" ) @@ -177,6 +181,9 @@ type GRPCConfig struct { // MaxSendMsgSize defines the max message size in bytes the server can send. // The default value is math.MaxInt32. MaxSendMsgSize int `mapstructure:"max-send-msg-size"` + + // LogQueries logs every gRPC query to the console as an info log. + LogQueries bool `mapstructure:"log-queries"` } // GRPCWebConfig defines configuration for the gRPC-web server. @@ -319,6 +326,7 @@ func DefaultConfig() *Config { Address: DefaultGRPCAddress, MaxRecvMsgSize: DefaultGRPCMaxRecvMsgSize, MaxSendMsgSize: DefaultGRPCMaxSendMsgSize, + LogQueries: DefaultLogQueries, }, Rosetta: RosettaConfig{ Enable: false, diff --git a/server/config/toml.go b/server/config/toml.go index 1ec7ce6a2e2d..5a560ccff51b 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -207,6 +207,11 @@ max-recv-msg-size = "{{ .GRPC.MaxRecvMsgSize }}" # The default value is math.MaxInt32. max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}" +# LogQueries if enabled will print an info log containing the query request +# that was submitted to this node on every submission. +# This is useful strictly for debugging purposes and should be disabled otherwise. +log-queries = "{{ .GRPC.LogQueries }}" + ############################################################################### ### gRPC Web Configuration ### ############################################################################### diff --git a/server/grpc/server.go b/server/grpc/server.go index 79a9be3dca24..b21d9afa629c 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -35,7 +35,7 @@ func StartGRPCServer(clientCtx client.Context, app types.Application, cfg config grpc.MaxRecvMsgSize(maxRecvMsgSize), ) - app.RegisterGRPCServer(grpcSrv) + app.RegisterGRPCServer(grpcSrv, cfg.LogQueries) // Reflection allows consumers to build dynamic clients that can write to any // Cosmos SDK application without relying on application packages at compile diff --git a/server/types/app.go b/server/types/app.go index 727f767fc35e..eb8d4e78c83e 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -46,7 +46,7 @@ type ( // RegisterGRPCServer registers gRPC services directly with the gRPC // server. - RegisterGRPCServer(grpc.Server) + RegisterGRPCServer(grpc.Server, bool) // RegisterTxService registers the gRPC Query service for tx (such as tx // simulation, fetching txs by hash...). From 55b53a127b6937d66a40084e9f7383a3762ea7f5 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Sun, 14 Jan 2024 15:19:17 -0700 Subject: [PATCH 11/11] remove quotes --- server/config/toml.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/config/toml.go b/server/config/toml.go index 5a560ccff51b..ec84f4347da1 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -210,7 +210,7 @@ max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}" # LogQueries if enabled will print an info log containing the query request # that was submitted to this node on every submission. # This is useful strictly for debugging purposes and should be disabled otherwise. -log-queries = "{{ .GRPC.LogQueries }}" +log-queries = {{ .GRPC.LogQueries }} ############################################################################### ### gRPC Web Configuration ###