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

Add Tx-boundary module #224

Merged
merged 14 commits into from
Aug 28, 2023
4 changes: 4 additions & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
ante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
tfmwKeeper "github.com/notional-labs/centauri/v4/x/transfermiddleware/keeper"
txBoundaryAnte "github.com/notional-labs/centauri/v4/x/tx-boundary/ante"
txBoundaryKeeper "github.com/notional-labs/centauri/v4/x/tx-boundary/keeper"
)

// Link to default ante handler used by cosmos sdk:
Expand All @@ -21,6 +23,7 @@ func NewAnteHandler(
signModeHandler signing.SignModeHandler,
channelKeeper *ibckeeper.Keeper,
tfmwKeeper tfmwKeeper.Keeper,
txBoundaryKeeper txBoundaryKeeper.Keeper,
codec codec.BinaryCodec,
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
Expand All @@ -30,6 +33,7 @@ func NewAnteHandler(
ante.NewValidateMemoDecorator(ak),
ante.NewConsumeGasForTxSizeDecorator(ak),
NewIBCPermissionDecorator(codec, tfmwKeeper),
txBoundaryAnte.NewStakingPermissionDecorator(codec, txBoundaryKeeper),
ante.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(ak),
ante.NewSigGasConsumeDecorator(ak, sigGasConsumer),
Expand Down
10 changes: 10 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ import (
transfermiddleware "github.com/notional-labs/centauri/v4/x/transfermiddleware"
transfermiddlewaretypes "github.com/notional-labs/centauri/v4/x/transfermiddleware/types"

txBoundary "github.com/notional-labs/centauri/v4/x/tx-boundary"
txBoundaryTypes "github.com/notional-labs/centauri/v4/x/tx-boundary/types"

ratelimitmodule "github.com/notional-labs/centauri/v4/x/ratelimit"
ratelimitmoduletypes "github.com/notional-labs/centauri/v4/x/ratelimit/types"

Expand Down Expand Up @@ -208,6 +211,7 @@ var (
ica.AppModuleBasic{},
ibc_hooks.AppModuleBasic{},
transfermiddleware.AppModuleBasic{},
txBoundary.AppModuleBasic{},
ratelimitmodule.AppModuleBasic{},
consensus.AppModuleBasic{},
alliancemodule.AppModuleBasic{},
Expand Down Expand Up @@ -322,6 +326,7 @@ func NewCentauriApp(
transferModule := transfer.NewAppModule(app.TransferKeeper)
routerModule := router.NewAppModule(app.RouterKeeper)
transfermiddlewareModule := transfermiddleware.NewAppModule(&app.TransferMiddlewareKeeper)
txBoundaryModule := txBoundary.NewAppModule(appCodec, app.TxBoundaryKeepper)
ratelimitModule := ratelimitmodule.NewAppModule(&app.RatelimitKeeper)
icqModule := icq.NewAppModule(app.ICQKeeper)
ibcHooksModule := ibc_hooks.NewAppModule()
Expand Down Expand Up @@ -364,6 +369,7 @@ func NewCentauriApp(
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
routerModule,
transfermiddlewareModule,
txBoundaryModule,
icaModule,
ratelimitModule,
alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
Expand All @@ -387,6 +393,7 @@ func NewCentauriApp(
ibctransfertypes.ModuleName,
routertypes.ModuleName,
transfermiddlewaretypes.ModuleName,
txBoundaryTypes.ModuleName,
ratelimitmoduletypes.ModuleName,
ibchookstypes.ModuleName,
icqtypes.ModuleName,
Expand Down Expand Up @@ -426,6 +433,7 @@ func NewCentauriApp(
ibchost.ModuleName,
routertypes.ModuleName,
transfermiddlewaretypes.ModuleName,
txBoundaryTypes.ModuleName,
ratelimitmoduletypes.ModuleName,
ibchookstypes.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -462,6 +470,7 @@ func NewCentauriApp(
icqtypes.ModuleName,
routertypes.ModuleName,
transfermiddlewaretypes.ModuleName,
txBoundaryTypes.ModuleName,
ratelimitmoduletypes.ModuleName,
ibchookstypes.ModuleName,
feegrant.ModuleName,
Expand Down Expand Up @@ -521,6 +530,7 @@ func NewCentauriApp(
encodingConfig.TxConfig.SignModeHandler(),
app.IBCKeeper,
app.TransferMiddlewareKeeper,
app.TxBoundaryKeepper,
appCodec,
))
app.SetEndBlocker(app.EndBlocker)
Expand Down
51 changes: 51 additions & 0 deletions app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"cosmossdk.io/math"
"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
dbm "github.com/cometbft/cometbft-db"
Expand All @@ -15,11 +16,14 @@ import (
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/ibc-go/v7/testing/mock"
centauri "github.com/notional-labs/centauri/v4/app"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -171,3 +175,50 @@ func SetupCentauriAppWithValSet(t *testing.T) *centauri.CentauriApp {
centauriApp := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, "notional", balance)
return centauriApp
}

func SetupCentauriAppWithValSetWithGenAccout(t *testing.T) (*centauri.CentauriApp, sdk.AccAddress, []stakingtypes.Validator) {
t.Helper()
// generate validator private/public key
privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
require.NoError(t, err)

// create validator set with single validator
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
amount, ok := sdk.NewIntFromString("10000000000000000000")
require.True(t, ok)

balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)),
}

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
for _, val := range valSet.Validators {
pk, _ := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pkAny, _ := codectypes.NewAnyWithValue(pk)

validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: sdk.DefaultPowerReduction,
DelegatorShares: math.LegacyOneDec(),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()),
MinSelfDelegation: math.ZeroInt(),
}
validators = append(validators, validator)
}
centauriApp := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, "notional", balance)

return centauriApp, acc.GetAddress(), validators
}
10 changes: 10 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ import (
transfermiddlewarekeeper "github.com/notional-labs/centauri/v4/x/transfermiddleware/keeper"
transfermiddlewaretypes "github.com/notional-labs/centauri/v4/x/transfermiddleware/types"

txBoundaryKeeper "github.com/notional-labs/centauri/v4/x/tx-boundary/keeper"
txBoundaryTypes "github.com/notional-labs/centauri/v4/x/tx-boundary/types"

ratelimitmodule "github.com/notional-labs/centauri/v4/x/ratelimit"
ratelimitmodulekeeper "github.com/notional-labs/centauri/v4/x/ratelimit/keeper"
ratelimitmoduletypes "github.com/notional-labs/centauri/v4/x/ratelimit/types"
Expand Down Expand Up @@ -145,6 +148,7 @@ type AppKeepers struct {
ConsensusParamsKeeper consensusparamkeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration
TransferMiddlewareKeeper transfermiddlewarekeeper.Keeper
TxBoundaryKeepper txBoundaryKeeper.Keeper
RouterKeeper *routerkeeper.Keeper
RatelimitKeeper ratelimitmodulekeeper.Keeper
AllianceKeeper alliancemodulekeeper.Keeper
Expand Down Expand Up @@ -273,6 +277,12 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
authorityAddress,
)

appKeepers.TxBoundaryKeepper = txBoundaryKeeper.NewKeeper(
appCodec,
appKeepers.keys[txBoundaryTypes.StoreKey],
authorityAddress,
)

appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, appKeepers.keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
Expand Down
3 changes: 2 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
ibchookstypes "github.com/notional-labs/centauri/v4/x/ibc-hooks/types"
ratelimitmoduletypes "github.com/notional-labs/centauri/v4/x/ratelimit/types"
transfermiddlewaretypes "github.com/notional-labs/centauri/v4/x/transfermiddleware/types"
txBoundaryTypes "github.com/notional-labs/centauri/v4/x/tx-boundary/types"

consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"

Expand All @@ -48,7 +49,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, icqtypes.StoreKey, capabilitytypes.StoreKey, consensusparamtypes.StoreKey, wasm08types.StoreKey,
crisistypes.StoreKey, routertypes.StoreKey, transfermiddlewaretypes.StoreKey, group.StoreKey, minttypes.StoreKey, alliancemoduletypes.StoreKey, wasm.StoreKey, ibchookstypes.StoreKey, icahosttypes.StoreKey, ratelimitmoduletypes.StoreKey,
crisistypes.StoreKey, routertypes.StoreKey, transfermiddlewaretypes.StoreKey, group.StoreKey, minttypes.StoreKey, alliancemoduletypes.StoreKey, wasm.StoreKey, ibchookstypes.StoreKey, icahosttypes.StoreKey, ratelimitmoduletypes.StoreKey, txBoundaryTypes.StoreKey,
)

// Define transient store keys
Expand Down
21 changes: 21 additions & 0 deletions proto/centauri/txboundary/v1beta1/boundary.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";
package centauri.txboundary.v1beta1;

import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option go_package = "x/tx-boundary/types";

// Boundary defines the number of tx limit and block per tx generation time
message Boundary {
uint64 tx_limit = 1;
uint64 blocks_per_generation = 2;
}

// Boundary defines the number of delegate and redelegate per Addr
message LimitPerAddr {
uint64 delegate_count = 1;
uint64 reledegate_count = 2;
int64 latest_update_block = 3;
}
21 changes: 21 additions & 0 deletions proto/centauri/txboundary/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";
package centauri.txboundary.v1beta1;

import "gogoproto/gogo.proto";
import "centauri/txboundary/v1beta1/boundary.proto";

option go_package = "x/tx-boundary/types";

// GenesisState defines the module various parameters when first
// initialized
message GenesisState {
Boundary delegate_boundary = 1 [
(gogoproto.moretags) = "yaml:\"delegate_boundary\"",
(gogoproto.nullable) = false
];
Boundary redelegate_boundary = 2 [
(gogoproto.moretags) = "yaml:\"redelegate_boundary\"",
(gogoproto.nullable) = false
];
}

40 changes: 40 additions & 0 deletions proto/centauri/txboundary/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";
package centauri.txboundary.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "centauri/txboundary/v1beta1/boundary.proto";

option go_package = "x/tx-boundary/types";

// Query provides defines the gRPC querier service.
service Query {
// DelegateBoundary returns the boundary for the delegate tx.
rpc DelegateBoundary(QueryDelegateBoundaryRequest) returns (QueryDelegateBoundaryResponse) {
option (google.api.http).get = "/cosmos/txboundary/v1beta1/delegateboundary";
}

// RedelegateBoundary returns the boundary for the redelegate tx.
rpc RedelegateBoundary(QueryRedelegateBoundaryRequest) returns (QueryRedelegateBoundaryResponse) {
option (google.api.http).get = "/cosmos/txboundary/v1beta1/redelegateboundary";
}
}

// QueryDelegateBoundaryRequest is the request type for the Query/DelegateBoundary RPC method.
message QueryDelegateBoundaryRequest {}

// QueryDelegateBoundaryResponse is the response type for the Query/DelegateBoundary RPC method.
message QueryDelegateBoundaryResponse {
// boundary defines the boundary for the delegate tx
Boundary boundary = 1 [ (gogoproto.nullable) = false ];
}

// QueryRedelegateBoundaryRequest is the request type for the Query/ReDelegateBoundary RPC method.
message QueryRedelegateBoundaryRequest {}

// QueryRedelegateBoundaryResponse is the response type for the Query/ReDelegateBoundary RPC
// method.
message QueryRedelegateBoundaryResponse {
// boundary defines the boundary for the redelegate tx
Boundary boundary = 1 [ (gogoproto.nullable) = false ];
}
68 changes: 68 additions & 0 deletions proto/centauri/txboundary/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
syntax = "proto3";
package centauri.txboundary.v1beta1;

import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "centauri/txboundary/v1beta1/boundary.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "x/tx-boundary/types";

// Msg defines the x/mint Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

rpc UpdateDelegateBoundary(MsgUpdateDelegateBoundary) returns (MsgUpdateDelegateBoundaryResponse);

rpc UpdateRedelegateBoundary(MsgUpdateRedelegateBoundary) returns (MsgUpdateRedelegateBoundaryResponse);
}

// MsgUpdateDelegateBoundary is the Msg/UpdateDelegateBoundary request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateDelegateBoundary {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "centauri/x/txboundary/MsgUpdateDelegateBoundary";

// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// boundary defines the x/tx-boundary parameters to update.
//
// NOTE: All parameters must be supplied.
Boundary boundary = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

// MsgUpdateDelegateBoundaryResponse defines the response structure for executing a
// MsgUpdateDelegateBoundary message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateDelegateBoundaryResponse {}

// MsgUpdateRedelegateBoundary is the Msg/MsgUpdateRedelegateBoundary request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateRedelegateBoundary {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "centauri/x/txboundary/MsgUpdateDelegateBoundary";

// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// boundary defines the x/tx-boundary parameters to update.
//
// NOTE: All parameters must be supplied.
Boundary boundary = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

// MsgUpdateRedelegateBoundaryResponse defines the response structure for executing a
// MsgUpdateRedelegateBoundary message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateRedelegateBoundaryResponse {}
1 change: 0 additions & 1 deletion x/mint/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestDecodeStore(t *testing.T) {
}
for i, tt := range tests {
i, tt := i, tt
fmt.Println("hehe")
t.Run(tt.name, func(t *testing.T) {
switch i {
case len(tests) - 1:
Expand Down
Loading
Loading