Skip to content

Commit

Permalink
Merge branch 'osmosis-main' into remove-genesis-supply-offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslara committed Aug 15, 2022
2 parents b5f3b54 + a296bdc commit 63ff3a2
Show file tree
Hide file tree
Showing 32 changed files with 1,184 additions and 80 deletions.
4 changes: 2 additions & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"github.com/cosmos/cosmos-sdk/snapshots"
"github.com/cosmos/cosmos-sdk/store"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/exported"
)

const (
Expand Down Expand Up @@ -129,7 +129,7 @@ type BaseApp struct { // nolint: maligned
indexEvents map[string]struct{}
}

var _ upgrade.AppVersionManager = (*BaseApp)(nil)
var _ storetypes.AppVersionManager = (*BaseApp)(nil)

// NewBaseApp returns a reference to an initialized BaseApp. It accepts a
// variadic number of option functions, which act on the BaseApp to set
Expand Down
50 changes: 50 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,13 @@
- [cosmos/upgrade/v1beta1/upgrade.proto](#cosmos/upgrade/v1beta1/upgrade.proto)
- [CancelSoftwareUpgradeProposal](#cosmos.upgrade.v1beta1.CancelSoftwareUpgradeProposal)
- [ModuleVersion](#cosmos.upgrade.v1beta1.ModuleVersion)
- [Params](#cosmos.upgrade.v1beta1.Params)
- [Plan](#cosmos.upgrade.v1beta1.Plan)
- [SoftwareUpgradeProposal](#cosmos.upgrade.v1beta1.SoftwareUpgradeProposal)

- [cosmos/upgrade/v1beta1/genesis.proto](#cosmos/upgrade/v1beta1/genesis.proto)
- [GenesisState](#cosmos.upgrade.v1beta1.GenesisState)

- [cosmos/upgrade/v1beta1/query.proto](#cosmos/upgrade/v1beta1/query.proto)
- [QueryAppliedPlanRequest](#cosmos.upgrade.v1beta1.QueryAppliedPlanRequest)
- [QueryAppliedPlanResponse](#cosmos.upgrade.v1beta1.QueryAppliedPlanResponse)
Expand Down Expand Up @@ -8060,6 +8064,21 @@ Since: cosmos-sdk 0.43



<a name="cosmos.upgrade.v1beta1.Params"></a>

### Params
Params defines the x/upgrade parameters.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `is_mainnet` | [bool](#bool) | | |






<a name="cosmos.upgrade.v1beta1.Plan"></a>

### Plan
Expand Down Expand Up @@ -8096,6 +8115,37 @@ upgrade.



<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="cosmos/upgrade/v1beta1/genesis.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## cosmos/upgrade/v1beta1/genesis.proto



<a name="cosmos.upgrade.v1beta1.GenesisState"></a>

### GenesisState
GenesisState defines the x/upgrade module's genesis state.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#cosmos.upgrade.v1beta1.Params) | | params defines the x/upgrade parameters. |





<!-- end messages -->

<!-- end enums -->
Expand Down
13 changes: 13 additions & 0 deletions proto/cosmos/upgrade/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package cosmos.upgrade.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/upgrade/v1beta1/upgrade.proto";

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

// GenesisState defines the x/upgrade module's genesis state.
message GenesisState {
// params defines the x/upgrade parameters.
Params params = 1 [(gogoproto.nullable) = false];
}
31 changes: 21 additions & 10 deletions proto/cosmos/upgrade/v1beta1/upgrade.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "google/protobuf/any.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/upgrade/types";
option go_package = "github.com/cosmos/cosmos-sdk/x/upgrade/types";
option (gogoproto.goproto_getters_all) = false;

// Plan specifies information about a planned upgrade and when it should occur.
Expand All @@ -22,10 +22,14 @@ message Plan {
// reached and the software will exit.
string name = 1;

// Deprecated: Time based upgrades have been deprecated. Time based upgrade logic
// has been removed from the SDK.
// If this field is not empty, an error will be thrown.
google.protobuf.Timestamp time = 2 [deprecated = true, (gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// Deprecated: Time based upgrades have been deprecated. Time based upgrade
// logic has been removed from the SDK. If this field is not empty, an error
// will be thrown.
google.protobuf.Timestamp time = 2 [
deprecated = true,
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false
];

// The height at which the upgrade must be performed.
// Only used if Time is not set.
Expand All @@ -35,11 +39,13 @@ message Plan {
// such as a git commit that validators could automatically upgrade to
string info = 4;

// Deprecated: UpgradedClientState field has been deprecated. IBC upgrade logic has been
// moved to the IBC module in the sub module 02-client.
// If this field is not empty, an error will be thrown.
google.protobuf.Any upgraded_client_state = 5
[deprecated = true, (gogoproto.moretags) = "yaml:\"upgraded_client_state\""];
// Deprecated: UpgradedClientState field has been deprecated. IBC upgrade
// logic has been moved to the IBC module in the sub module 02-client. If this
// field is not empty, an error will be thrown.
google.protobuf.Any upgraded_client_state = 5 [
deprecated = true,
(gogoproto.moretags) = "yaml:\"upgraded_client_state\""
];
}

// SoftwareUpgradeProposal is a gov Content type for initiating a software
Expand Down Expand Up @@ -76,3 +82,8 @@ message ModuleVersion {
// consensus version of the app module
uint64 version = 2;
}

// Params defines the x/upgrade parameters.
message Params {
bool is_mainnet = 1;
}
3 changes: 2 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func NewSimApp(
)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, app.GetSubspace(upgradetypes.ModuleName))

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand Down Expand Up @@ -582,6 +582,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(upgradetypes.ModuleName)

return paramsKeeper
}
11 changes: 5 additions & 6 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strings"
"sync"

"github.com/cosmos/cosmos-sdk/pruning"
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
iavltree "github.com/cosmos/iavl"
protoio "github.com/gogo/protobuf/io"
gogotypes "github.com/gogo/protobuf/types"
Expand All @@ -20,6 +18,8 @@ import (
"github.com/tendermint/tendermint/proto/tendermint/crypto"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/pruning"
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/store/cachemulti"
"github.com/cosmos/cosmos-sdk/store/dbadapter"
Expand All @@ -30,7 +30,6 @@ import (
"github.com/cosmos/cosmos-sdk/store/transient"
"github.com/cosmos/cosmos-sdk/store/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
vm "github.com/cosmos/cosmos-sdk/x/upgrade/exported"
)

const (
Expand Down Expand Up @@ -73,9 +72,9 @@ type Store struct {
}

var (
_ types.CommitMultiStore = (*Store)(nil)
_ vm.AppVersionManager = (*Store)(nil)
_ types.Queryable = (*Store)(nil)
_ types.CommitMultiStore = (*Store)(nil)
_ types.AppVersionManager = (*Store)(nil)
_ types.Queryable = (*Store)(nil)
)

// NewStore returns a reference to a new Store object with the provided DB. The
Expand Down
3 changes: 1 addition & 2 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/types/kv"
vm "github.com/cosmos/cosmos-sdk/x/upgrade/exported"
)

type Store interface {
Expand Down Expand Up @@ -152,7 +151,7 @@ type CommitMultiStore interface {
Committer
MultiStore
snapshottypes.Snapshotter
vm.AppVersionManager
AppVersionManager

// Mount a store of type using the given db.
// If db == nil, the new store will use the CommitMultiStore db.
Expand Down
8 changes: 8 additions & 0 deletions store/types/version_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package types

// AppVersionManager defines the interface which allows managing the appVersion
// field.
type AppVersionManager interface {
GetAppVersion() (uint64, error)
SetAppVersion(version uint64) error
}
17 changes: 17 additions & 0 deletions x/bank/keeper/hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package keeper

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

// Implements StakingHooks interface
var _ types.BankHooks = BaseSendKeeper{}

// BeforeSend executes the BeforeSend hook if registered.
func (k BaseSendKeeper) BeforeSend(ctx sdk.Context, from, to sdk.AccAddress, amount sdk.Coins) error {
if k.hooks != nil {
return k.hooks.BeforeSend(ctx, from, to, amount)
}
return nil
}
101 changes: 101 additions & 0 deletions x/bank/keeper/hooks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package keeper_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/types"

stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var _ types.BankHooks = &MockBankHooksReceiver{}

// BankHooks event hooks for bank (noalias)
type MockBankHooksReceiver struct{}

// Mock BeforeSend bank hook that doesn't allow the sending of exactly 100 coins of any denom.
func (h *MockBankHooksReceiver) BeforeSend(ctx sdk.Context, from, to sdk.AccAddress, amount sdk.Coins) error {
for _, coin := range amount {
if coin.Amount.Equal(sdk.NewInt(100)) {
return fmt.Errorf("not allowed; expected %v, got: %v", 100, coin.Amount)
}
}

return nil
}

func TestHooks(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(1000))
simapp.FundModuleAccount(app.BankKeeper, ctx, stakingtypes.BondedPoolName, sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1000))))

// create a valid send amount which is 1 coin, and an invalidSendAmount which is 100 coins
validSendAmount := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(1)))
invalidSendAmount := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.NewInt(100)))

// setup our mock bank hooks receiver that prevents the send of 100 coins
bankHooksReceiver := MockBankHooksReceiver{}
baseBankKeeper, ok := app.BankKeeper.(keeper.BaseKeeper)
require.True(t, ok)
keeper.UnsafeSetHooks(
&baseBankKeeper, types.NewMultiBankHooks(&bankHooksReceiver),
)
app.BankKeeper = baseBankKeeper

// try sending a validSendAmount and it should work
err := app.BankKeeper.SendCoins(ctx, addrs[0], addrs[1], validSendAmount)
require.NoError(t, err)

// try sending an invalidSendAmount and it should not work
err = app.BankKeeper.SendCoins(ctx, addrs[0], addrs[1], invalidSendAmount)
require.Error(t, err)

// try doing SendManyCoins and make sure if even a single subsend is invalid, the entire function fails
err = app.BankKeeper.SendManyCoins(ctx, addrs[0], []sdk.AccAddress{addrs[0], addrs[1]}, []sdk.Coins{invalidSendAmount, validSendAmount})
require.Error(t, err)

// make sure that account to module doesn't bypass hook
err = app.BankKeeper.SendCoinsFromAccountToModule(ctx, addrs[0], stakingtypes.BondedPoolName, validSendAmount)
require.NoError(t, err)
err = app.BankKeeper.SendCoinsFromAccountToModule(ctx, addrs[0], stakingtypes.BondedPoolName, invalidSendAmount)
require.Error(t, err)

// make sure that module to account doesn't bypass hook
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, stakingtypes.BondedPoolName, addrs[0], validSendAmount)
require.NoError(t, err)
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, stakingtypes.BondedPoolName, addrs[0], invalidSendAmount)
require.Error(t, err)

// make sure that module to module doesn't bypass hook
err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, stakingtypes.BondedPoolName, stakingtypes.NotBondedPoolName, validSendAmount)
require.NoError(t, err)
err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, stakingtypes.BondedPoolName, stakingtypes.NotBondedPoolName, invalidSendAmount)
require.Error(t, err)

// make sure that module to many accounts doesn't bypass hook
err = app.BankKeeper.SendCoinsFromModuleToManyAccounts(ctx, stakingtypes.BondedPoolName, []sdk.AccAddress{addrs[0], addrs[1]}, []sdk.Coins{validSendAmount, validSendAmount})
require.NoError(t, err)
err = app.BankKeeper.SendCoinsFromModuleToManyAccounts(ctx, stakingtypes.BondedPoolName, []sdk.AccAddress{addrs[0], addrs[1]}, []sdk.Coins{validSendAmount, invalidSendAmount})
require.Error(t, err)

// make sure that DelegateCoins doesn't bypass the hook
err = app.BankKeeper.DelegateCoins(ctx, addrs[0], app.AccountKeeper.GetModuleAddress(stakingtypes.BondedPoolName), validSendAmount)
require.NoError(t, err)
err = app.BankKeeper.DelegateCoins(ctx, addrs[0], app.AccountKeeper.GetModuleAddress(stakingtypes.BondedPoolName), invalidSendAmount)
require.Error(t, err)

// make sure that UndelegateCoins doesn't bypass the hook
err = app.BankKeeper.UndelegateCoins(ctx, app.AccountKeeper.GetModuleAddress(stakingtypes.BondedPoolName), addrs[0], validSendAmount)
require.NoError(t, err)
err = app.BankKeeper.UndelegateCoins(ctx, app.AccountKeeper.GetModuleAddress(stakingtypes.BondedPoolName), addrs[0], invalidSendAmount)
require.Error(t, err)
}
11 changes: 11 additions & 0 deletions x/bank/keeper/internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package keeper

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

// UnsafeSetHooks updates the x/bank keeper's hooks, overriding any potential
// pre-existing hooks.
//
// WARNING: this function should only be used in tests.
func UnsafeSetHooks(k *BaseKeeper, h types.BankHooks) {
k.hooks = h
}
Loading

0 comments on commit 63ff3a2

Please sign in to comment.