Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injective Cherry Picks for v0.50.x #21

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
11faa47
cherry pick: af4b61c
alexanderbez Dec 12, 2023
b90b568
cherry pick: f1ab5db
alexanderbez Dec 12, 2023
5995da9
cherry pick: c33c5e7
alexanderbez Dec 13, 2023
99bddcd
cherry pick: 42cbd4
alexanderbez Dec 13, 2023
a53729c
patch some x/staking tests
alexanderbez Dec 13, 2023
53295da
cherry pick: 140749
alexanderbez Dec 13, 2023
47b0907
cherry pick: 3d27fac5
alexanderbez Dec 18, 2023
a5c5f11
cherry pick: 2ec442da9
alexanderbez Dec 18, 2023
0bd8045
cherry pick: bd4b4580d
alexanderbez Dec 18, 2023
78ce3fc
cherry pick: 9cbd6048e
alexanderbez Dec 18, 2023
099592c
cherry pick: f3a4246e45
alexanderbez Dec 18, 2023
8b4be44
cherry pick: 1fdb0f55bf
alexanderbez Dec 18, 2023
85b5519
cherry pick: 2a6009162
alexanderbez Dec 18, 2023
68f66ce
cherry pick: cfbd896eb
alexanderbez Dec 18, 2023
743451e
cherry pick: 88ca41d7bdf
alexanderbez Dec 18, 2023
bae333c
cherry pick: 88ca41d7bdf
alexanderbez Dec 18, 2023
ea049d7
cherry pick: 726fea9e0b9
alexanderbez Dec 18, 2023
a2c4205
cherry pick: c6e918bbee1
alexanderbez Dec 18, 2023
23bcf14
cherry pick: d6115f387ac0
alexanderbez Dec 18, 2023
9a88930
cherry pick: fbb4d525bd433
alexanderbez Dec 18, 2023
b726928
cherry pick: 6b233a7877c
alexanderbez Dec 18, 2023
dddb8b4
cherry pick: 003a8c9c0
alexanderbez Dec 19, 2023
3ef76da
cherry pick: 5c9627ded
alexanderbez Dec 19, 2023
ebf5a40
cherry pick: 0427b6f53
alexanderbez Dec 19, 2023
562218d
cherry pick: d5f931fe0b
alexanderbez Dec 19, 2023
4bb2d50
cherry pick: 3a97c08f884
alexanderbez Dec 19, 2023
dc17911
fix Proto and tests
alexanderbez Dec 19, 2023
c34e1d8
updates
alexanderbez Dec 19, 2023
e42311a
updates
alexanderbez Dec 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,282 changes: 1,282 additions & 0 deletions api/cosmos/bank/v1beta1/events.pulsar.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,10 @@ func gRPCErrorToSDKError(err error) error {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

if len(status.Details()) > 0 {
err = errorsmod.Wrapf(err, "%v", status.Details())
}

switch status.Code() {
case codes.NotFound:
return errorsmod.Wrap(sdkerrors.ErrKeyNotFound, err.Error())
Expand Down
6 changes: 6 additions & 0 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (
// File for storing in-package BaseApp optional functions,
// for options that need access to non-exported fields of the BaseApp

func SetCommitSync(sync bool) func(app *BaseApp) {
return func(bapp *BaseApp) {
bapp.cms.SetCommitSync(sync)
}
}

// SetPruning sets a pruning option on the multistore associated with the app
func SetPruning(opts pruningtypes.PruningOptions) func(*BaseApp) {
return func(bapp *BaseApp) { bapp.cms.SetPruning(opts) }
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ require (
github.com/magiconair/properties v1.8.7
github.com/manifoldco/promptui v0.9.0
github.com/mattn/go-isatty v0.0.20
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
github.com/prometheus/common v0.45.0
github.com/rs/zerolog v1.31.0
Expand All @@ -59,6 +60,7 @@ require (
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sync v0.3.0
google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
gotest.tools/v3 v3.5.1
Expand Down Expand Up @@ -134,7 +136,6 @@ require (
github.com/oklog/run v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
Expand All @@ -155,7 +156,6 @@ require (
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -170,6 +170,7 @@ require (

// Below are the long-lived replace of the Cosmos SDK
replace (
cosmossdk.io/store => ./store
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk=
cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4=
cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig=
cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
cosmossdk.io/store v1.0.1 h1:XBDhCqlL+2MUgE8CHWwndKVJ4beX+TyaPIjB5SV62dM=
cosmossdk.io/store v1.0.1/go.mod h1:EFtENTqVTuWwitGW1VwaBct+yDagk7oG/axBMPH+FXs=
cosmossdk.io/x/tx v0.12.0 h1:Ry2btjQdrfrje9qZ3iZeZSmDArjgxUJMMcLMrX4wj5U=
cosmossdk.io/x/tx v0.12.0/go.mod h1:qTth2coAGkwCwOCjqQ8EAQg+9udXNRzcnSbMgGKGEI0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
Expand Down
5 changes: 5 additions & 0 deletions math/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func ZeroInt() Int { return Int{big.NewInt(0)} }
// OneInt returns Int value with one
func OneInt() Int { return Int{big.NewInt(1)} }

// ToDec converts Int to Dec
func (i Int) ToDec() LegacyDec {
return LegacyNewDecFromInt(i)
}

// Int64 converts Int to int64
// Panics if the value is out of range
func (i Int) Int64() int64 {
Expand Down
26 changes: 26 additions & 0 deletions proto/cosmos/bank/v1beta1/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package cosmos.bank.v1beta1;

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "amino/amino.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types";

// EventSetBalance is an event that tracks the latest bank balance.
message EventSetBalances {
repeated BalanceUpdate balance_updates = 1;
}

// BalanceUpdate contains a given address's latest balance
message BalanceUpdate {
bytes addr = 1;
bytes denom = 2;
// the latest amount
string amt = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}
4 changes: 4 additions & 0 deletions runtime/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type transientStoreService struct {
key *storetypes.TransientStoreKey
}

func NewTransientKVStoreService(tKey *storetypes.TransientStoreKey) store.TransientStoreService {
return &transientStoreService{key: tKey}
}

func (t transientStoreService) OpenTransientStore(ctx context.Context) store.KVStore {
return newKVStore(sdk.UnwrapSDKContext(ctx).KVStore(t.key))
}
Expand Down
3 changes: 2 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func NewSimApp(
panic(err)
}

tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey, banktypes.TStoreKey)
app := &SimApp{
BaseApp: bApp,
legacyAmino: legacyAmino,
Expand All @@ -288,6 +288,7 @@ func NewSimApp(
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
runtime.NewTransientKVStoreService(tkeys[banktypes.TStoreKey]),
app.AccountKeeper,
BlockedAddresses(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand Down
32 changes: 28 additions & 4 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,40 @@ 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, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics) (types.CommitKVStore, error) {
return LoadStoreWithInitialVersion(db, logger, key, id, 0, cacheSize, disableFastNode, metrics)
func LoadStore(
db dbm.DB,
logger log.Logger,
key types.StoreKey,
id types.CommitID,
cacheSize int,
disableFastNode, commitSync bool,
metrics metrics.StoreMetrics,
) (types.CommitKVStore, error) {
return LoadStoreWithInitialVersion(db, logger, key, id, 0, cacheSize, disableFastNode, commitSync, metrics)
}

// 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, initialVersion uint64, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics) (types.CommitKVStore, error) {
tree := iavl.NewMutableTree(db, cacheSize, disableFastNode, logger, iavl.InitialVersionOption(initialVersion))
func LoadStoreWithInitialVersion(
db dbm.DB,
logger log.Logger,
key types.StoreKey,
id types.CommitID,
initialVersion uint64,
cacheSize int,
disableFastNode, commitSync bool,
metrics metrics.StoreMetrics,
) (types.CommitKVStore, error) {
tree := iavl.NewMutableTree(
db,
cacheSize,
disableFastNode,
logger,
iavl.InitialVersionOption(initialVersion),
iavl.SyncOption(commitSync),
)

isUpgradeable, err := tree.IsUpgradeable()
if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Store struct {
listeners map[types.StoreKey]*types.MemoryListener
metrics metrics.StoreMetrics
commitHeader cmtproto.Header
commitSync bool
}

var (
Expand Down Expand Up @@ -106,6 +107,14 @@ func (rs *Store) GetPruning() pruningtypes.PruningOptions {
return rs.pruningManager.GetOptions()
}

func (rs *Store) GetCommitSync() bool {
return rs.commitSync
}

func (rs *Store) SetCommitSync(sync bool) {
rs.commitSync = sync
}

// SetPruning sets the pruning strategy on the root store and all the sub-stores.
// Note, calling SetPruning on the root store prior to LoadVersion or
// LoadLatestVersion performs a no-op as the stores aren't mounted yet.
Expand Down Expand Up @@ -1009,9 +1018,9 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID
var err error

if params.initialVersion == 0 {
store, err = iavl.LoadStore(db, rs.logger, key, id, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics)
store, err = iavl.LoadStore(db, rs.logger, key, id, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.commitSync, rs.metrics)
} else {
store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics)
store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.commitSync, rs.metrics)
}

if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ type CommitMultiStore interface {

// SetMetrics sets the metrics for the KVStore
SetMetrics(metrics metrics.StoreMetrics)

// SetCommitSync set store commit sync mode
SetCommitSync(sync bool)

// GetCommitSync get store commit sync mode
GetCommitSync() bool
}

//---------subsp-------------------------------
Expand Down
6 changes: 6 additions & 0 deletions x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,13 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
return sdk.Context{}, err
}

feeTx, isFeeTx := tx.(sdk.FeeTx)
for _, signer := range signers {
// skip sequence increment of fee payer, when multiple signers exist
if isFeeTx && len(signers) > 1 && bytes.Equal(feeTx.FeePayer(), signer) {
continue
}

acc := isd.ak.GetAccount(ctx, signer)
if err := acc.SetSequence(acc.GetSequence() + 1); err != nil {
panic(err)
Expand Down
29 changes: 28 additions & 1 deletion x/auth/tx/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"fmt"
"strings"

errorsmod "cosmossdk.io/errors"
gogogrpc "github.com/cosmos/gogoproto/grpc"
"github.com/golang/protobuf/proto" //nolint:staticcheck // keep legacy for now
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/pkg/errors"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -97,7 +100,7 @@ func (s txServer) Simulate(ctx context.Context, req *txtypes.SimulateRequest) (*

gasInfo, result, err := s.simulate(txBytes)
if err != nil {
return nil, status.Errorf(codes.Unknown, "%v With gas wanted: '%d' and gas used: '%d' ", err, gasInfo.GasWanted, gasInfo.GasUsed)
return nil, GRPCWrap(err, codes.Unknown, fmt.Sprintf("%v With gas wanted: '%d' and gas used: '%d' ", err, gasInfo.GasWanted, gasInfo.GasUsed))
}

return &txtypes.SimulateResponse{
Expand Down Expand Up @@ -333,3 +336,27 @@ func parseOrderBy(orderBy txtypes.OrderBy) string {
return "" // Defaults to CometBFT's default, which is `asc` now.
}
}

func GRPCWrap(err error, c codes.Code, msg string) error {
if err == nil {
return nil
}

st := status.New(c, msg)
var sdkErr *errorsmod.Error

if errors.As(err, &sdkErr) {
errorInfo := &errdetails.ErrorInfo{
Reason: sdkErr.Error(),
Metadata: map[string]string{"Codespace": sdkErr.Codespace(), "ABCICode": fmt.Sprintf("%d", sdkErr.ABCICode())},
}

var withDetailsErr error
st, withDetailsErr = st.WithDetails(errorInfo)
if withDetailsErr != nil {
return status.Errorf(c, "%v (failed to add error details: %v)", msg, withDetailsErr)
}
}

return st.Err()
}
11 changes: 11 additions & 0 deletions x/bank/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package bank

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
)

// EndBlocker is called every block, emits balance event
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
k.EmitAllTransientBalances(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
}
5 changes: 4 additions & 1 deletion x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type Keeper interface {
DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error

EmitAllTransientBalances(ctx sdk.Context)

types.QueryServer
}

Expand Down Expand Up @@ -84,6 +86,7 @@ func (k BaseKeeper) GetPaginatedTotalSupply(ctx context.Context, pagination *que
func NewBaseKeeper(
cdc codec.BinaryCodec,
storeService store.KVStoreService,
tStoreService store.TransientStoreService,
ak types.AccountKeeper,
blockedAddrs map[string]bool,
authority string,
Expand All @@ -97,7 +100,7 @@ func NewBaseKeeper(
logger = logger.With(log.ModuleKey, "x/"+types.ModuleName)

return BaseKeeper{
BaseSendKeeper: NewBaseSendKeeper(cdc, storeService, ak, blockedAddrs, authority, logger),
BaseSendKeeper: NewBaseSendKeeper(cdc, storeService, tStoreService, ak, blockedAddrs, authority, logger),
ak: ak,
cdc: cdc,
storeService: storeService,
Expand Down
3 changes: 2 additions & 1 deletion x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type BaseSendKeeper struct {
func NewBaseSendKeeper(
cdc codec.BinaryCodec,
storeService store.KVStoreService,
tStoreService store.TransientStoreService,
ak types.AccountKeeper,
blockedAddrs map[string]bool,
authority string,
Expand All @@ -84,7 +85,7 @@ func NewBaseSendKeeper(
}

return BaseSendKeeper{
BaseViewKeeper: NewBaseViewKeeper(cdc, storeService, ak, logger),
BaseViewKeeper: NewBaseViewKeeper(cdc, storeService, tStoreService, ak, logger),
cdc: cdc,
ak: ak,
storeService: storeService,
Expand Down
Loading
Loading