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

feat: feePayer for Sudo fees #129

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func New(
&app.WasmKeeper,
)

app.FeeKeeper = feekeeper.NewKeeper(appCodec, keys[feetypes.StoreKey], memKeys[feetypes.MemStoreKey], app.GetSubspace(feetypes.ModuleName), app.IBCKeeper.ChannelKeeper, app.BankKeeper)
app.FeeKeeper = feekeeper.NewKeeper(appCodec, keys[feetypes.StoreKey], memKeys[feetypes.MemStoreKey], app.GetSubspace(feetypes.ModuleName), app.IBCKeeper.ChannelKeeper, app.BankKeeper, app.FeeGrantKeeper)
feeModule := feerefunder.NewAppModule(appCodec, *app.FeeKeeper, app.AccountKeeper, app.BankKeeper)

app.FeeBurnerKeeper = feeburnerkeeper.NewKeeper(
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/CosmWasm/wasmvm v1.1.1
github.com/confio/ics23/go v0.7.0
github.com/cosmos/admin-module v0.0.0-00010101000000-000000000000
github.com/cosmos/cosmos-proto v1.0.0-beta.1
NeverHappened marked this conversation as resolved.
Show resolved Hide resolved
github.com/cosmos/cosmos-sdk v0.45.7-0.20221104161803-456ca5663c5e
github.com/cosmos/ibc-go/v3 v3.0.0
github.com/cosmos/interchain-security v0.2.0
Expand All @@ -17,7 +18,6 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.2
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.1
Expand Down Expand Up @@ -105,6 +105,7 @@ require (
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/rs/zerolog v1.27.0 // indirect
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44=
github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU=
github.com/cosmos/cosmos-proto v1.0.0-beta.1 h1:iDL5qh++NoXxG8hSy93FdYJut4XfgbShIocllGaXx/0=
github.com/cosmos/cosmos-proto v1.0.0-beta.1/go.mod h1:8k2GNZghi5sDRFw/scPL8gMSowT1vDA+5ouxL8GjaUE=
github.com/cosmos/cosmos-sdk v0.44.2/go.mod h1:fwQJdw+aECatpTvQTo1tSfHEsxACdZYU80QCZUPnHr4=
github.com/cosmos/cosmos-sdk v0.44.3/go.mod h1:bA3+VenaR/l/vDiYzaiwbWvRPWHMBX2jG0ygiFtiBp0=
github.com/cosmos/cosmos-sdk v0.45.0/go.mod h1:XXS/asyCqWNWkx2rW6pSuen+EVcpAFxq6khrhnZgHaQ=
Expand Down
1 change: 1 addition & 0 deletions proto/feerefunder/fee.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ message Fee {
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
string payer = 4;
}

message PacketID {
Expand Down
2 changes: 1 addition & 1 deletion proto/interchaintxs/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ message MsgSubmitTx {

// MsgSubmitTxResponse defines the response for Msg/SubmitTx
message MsgSubmitTxResponse {
// channel's sequence_id for outgoing ibc packet. Unique per a channel.
// channel's sequence_id for outgoing ibc packet. Unique per a channel.y
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

NeverHappened marked this conversation as resolved.
Show resolved Hide resolved
uint64 sequence_id = 1;
// channel src channel on neutron side trasaction was submitted from
string channel = 2;
Expand Down
3 changes: 2 additions & 1 deletion testutil/feerefunder/keeper/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/neutron-org/neutron/x/feerefunder/types"
)

func FeeKeeper(t testing.TB, channelKeeper types.ChannelKeeper, bankKeeper types.BankKeeper) (*keeper.Keeper, sdk.Context) {
func FeeKeeper(t testing.TB, channelKeeper types.ChannelKeeper, bankKeeper types.BankKeeper, feegrantKeeper types.FeeGrantKeeper) (*keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

Expand All @@ -44,6 +44,7 @@ func FeeKeeper(t testing.TB, channelKeeper types.ChannelKeeper, bankKeeper types
paramsSubspace,
channelKeeper,
bankKeeper,
feegrantKeeper,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
Expand Down
64 changes: 64 additions & 0 deletions testutil/mocks/feegrant/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions testutil/mocks/feerefunder/types/keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions testutil/mocks/gomock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ package mocks
//go:generate mockgen -source=./../../x/interchainqueries/types/expected_keepers.go -destination ./interchainqueries/types/expected_keepers.go
//go:generate mockgen -source=./../../x/interchaintxs/types/expected_keepers.go -destination ./interchaintxs/types/expected_keepers.go
//go:generate mockgen -source=./../../x/transfer/types/expected_keepers.go -destination ./transfer/types/expected_keepers.go
//go:generate mockgen -destination ./feegrant/types.go github.com/cosmos/cosmos-sdk/x/feegrant FeeAllowanceI
10 changes: 5 additions & 5 deletions testutil/mocks/interchaintxs/types/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions testutil/mocks/transfer/types/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/feerefunder/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestGenesis(t *testing.T) {

require.EqualValues(t, genesisState.Params, types.DefaultParams())

k, ctx := keeper.FeeKeeper(t, nil, nil)
k, ctx := keeper.FeeKeeper(t, nil, nil, nil)
feerefunder.InitGenesis(ctx, *k, genesisState)
got := feerefunder.ExportGenesis(ctx, *k)

Expand Down
2 changes: 1 addition & 1 deletion x/feerefunder/keeper/grpc_query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestParamsQuery(t *testing.T) {
keeper, ctx := testkeeper.FeeKeeper(t, nil, nil)
keeper, ctx := testkeeper.FeeKeeper(t, nil, nil, nil)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()
keeper.SetParams(ctx, params)
Expand Down
48 changes: 35 additions & 13 deletions x/feerefunder/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import (

type (
Keeper struct {
cdc codec.BinaryCodec
bankKeeper types.BankKeeper
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
channelKeeper types.ChannelKeeper
cdc codec.BinaryCodec
bankKeeper types.BankKeeper
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
channelKeeper types.ChannelKeeper
feegrantKeeper types.FeeGrantKeeper
}
)

Expand All @@ -34,37 +35,58 @@ func NewKeeper(
ps paramtypes.Subspace,
channelKeeper types.ChannelKeeper,
bankKeeper types.BankKeeper,
feegrantKeeper types.FeeGrantKeeper,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
}

return &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
paramstore: ps,
channelKeeper: channelKeeper,
bankKeeper: bankKeeper,
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
paramstore: ps,
channelKeeper: channelKeeper,
bankKeeper: bankKeeper,
feegrantKeeper: feegrantKeeper,
}
}

func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

func (k Keeper) LockFees(ctx sdk.Context, payer sdk.AccAddress, packetID types.PacketID, fee types.Fee) error {
func (k Keeper) LockFees(ctx sdk.Context, payerInfo types.PayerInfo, packetID types.PacketID, fee types.Fee) error {
k.Logger(ctx).Debug("Trying to lock fees", "packetID", packetID, "fee", fee)

if _, ok := k.channelKeeper.GetChannel(ctx, packetID.PortId, packetID.ChannelId); !ok {
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "channel with id %s and port %s not found", packetID.ChannelId, packetID.PortId)
}
payer := payerInfo.Sender

if err := k.checkFees(ctx, fee); err != nil {
return sdkerrors.Wrapf(err, "failed to lock fees")
}

if payerInfo.FeePayer != nil && !payerInfo.FeePayer.Empty() {
allowance, err := k.feegrantKeeper.GetAllowance(ctx, payerInfo.FeePayer, payerInfo.Sender)
if err != nil {
return err
NeverHappened marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap error to make it more meaningful?

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line after error handling, please

if allowance != nil { // otherwise there is no allowance
coins := sdk.NewCoins()
coins = append(coins, fee.TimeoutFee...)
coins = append(coins, fee.AckFee...)
coins = append(coins, fee.RecvFee...)
_, err = allowance.Accept(ctx, coins, []sdk.Msg{})
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap an error

}
payer = payerInfo.FeePayer
}
}

feeInfo := types.FeeInfo{
Payer: payer.String(),
Fee: fee,
Expand Down
Loading