feat(x/feegrant): Add limits to grant pruning and enable message to aid manually (backport #18047) (#18128)
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Co-authored-by: Facundo <facundomedica@gmail.com> Co-authored-by: marbar3778 <marbar3778@yahoo.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
aa72f10b5f
commit
026631cd83
File diff suppressed because it is too large
Load Diff
@ -23,6 +23,7 @@ const _ = grpc.SupportPackageIsVersion7
|
||||
const (
|
||||
Msg_GrantAllowance_FullMethodName = "/cosmos.feegrant.v1beta1.Msg/GrantAllowance"
|
||||
Msg_RevokeAllowance_FullMethodName = "/cosmos.feegrant.v1beta1.Msg/RevokeAllowance"
|
||||
Msg_PruneAllowances_FullMethodName = "/cosmos.feegrant.v1beta1.Msg/PruneAllowances"
|
||||
)
|
||||
|
||||
// MsgClient is the client API for Msg service.
|
||||
@ -35,6 +36,10 @@ type MsgClient interface {
|
||||
// RevokeAllowance revokes any fee allowance of granter's account that
|
||||
// has been granted to the grantee.
|
||||
RevokeAllowance(ctx context.Context, in *MsgRevokeAllowance, opts ...grpc.CallOption) (*MsgRevokeAllowanceResponse, error)
|
||||
// PruneAllowances prunes expired fee allowances, currently up to 75 at a time.
|
||||
//
|
||||
// Since cosmos-sdk 0.50
|
||||
PruneAllowances(ctx context.Context, in *MsgPruneAllowances, opts ...grpc.CallOption) (*MsgPruneAllowancesResponse, error)
|
||||
}
|
||||
|
||||
type msgClient struct {
|
||||
@ -63,6 +68,15 @@ func (c *msgClient) RevokeAllowance(ctx context.Context, in *MsgRevokeAllowance,
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *msgClient) PruneAllowances(ctx context.Context, in *MsgPruneAllowances, opts ...grpc.CallOption) (*MsgPruneAllowancesResponse, error) {
|
||||
out := new(MsgPruneAllowancesResponse)
|
||||
err := c.cc.Invoke(ctx, Msg_PruneAllowances_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// MsgServer is the server API for Msg service.
|
||||
// All implementations must embed UnimplementedMsgServer
|
||||
// for forward compatibility
|
||||
@ -73,6 +87,10 @@ type MsgServer interface {
|
||||
// RevokeAllowance revokes any fee allowance of granter's account that
|
||||
// has been granted to the grantee.
|
||||
RevokeAllowance(context.Context, *MsgRevokeAllowance) (*MsgRevokeAllowanceResponse, error)
|
||||
// PruneAllowances prunes expired fee allowances, currently up to 75 at a time.
|
||||
//
|
||||
// Since cosmos-sdk 0.50
|
||||
PruneAllowances(context.Context, *MsgPruneAllowances) (*MsgPruneAllowancesResponse, error)
|
||||
mustEmbedUnimplementedMsgServer()
|
||||
}
|
||||
|
||||
@ -86,6 +104,9 @@ func (UnimplementedMsgServer) GrantAllowance(context.Context, *MsgGrantAllowance
|
||||
func (UnimplementedMsgServer) RevokeAllowance(context.Context, *MsgRevokeAllowance) (*MsgRevokeAllowanceResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method RevokeAllowance not implemented")
|
||||
}
|
||||
func (UnimplementedMsgServer) PruneAllowances(context.Context, *MsgPruneAllowances) (*MsgPruneAllowancesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method PruneAllowances not implemented")
|
||||
}
|
||||
func (UnimplementedMsgServer) mustEmbedUnimplementedMsgServer() {}
|
||||
|
||||
// UnsafeMsgServer may be embedded to opt out of forward compatibility for this service.
|
||||
@ -135,6 +156,24 @@ func _Msg_RevokeAllowance_Handler(srv interface{}, ctx context.Context, dec func
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Msg_PruneAllowances_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(MsgPruneAllowances)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(MsgServer).PruneAllowances(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Msg_PruneAllowances_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(MsgServer).PruneAllowances(ctx, req.(*MsgPruneAllowances))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Msg_ServiceDesc is the grpc.ServiceDesc for Msg service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@ -150,6 +189,10 @@ var Msg_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "RevokeAllowance",
|
||||
Handler: _Msg_RevokeAllowance_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "PruneAllowances",
|
||||
Handler: _Msg_PruneAllowances_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "cosmos/feegrant/v1beta1/tx.proto",
|
||||
|
||||
@ -20,6 +20,11 @@ service Msg {
|
||||
// RevokeAllowance revokes any fee allowance of granter's account that
|
||||
// has been granted to the grantee.
|
||||
rpc RevokeAllowance(MsgRevokeAllowance) returns (MsgRevokeAllowanceResponse);
|
||||
|
||||
// PruneAllowances prunes expired fee allowances, currently up to 75 at a time.
|
||||
//
|
||||
// Since cosmos-sdk 0.50
|
||||
rpc PruneAllowances(MsgPruneAllowances) returns (MsgPruneAllowancesResponse);
|
||||
}
|
||||
|
||||
// MsgGrantAllowance adds permission for Grantee to spend up to Allowance
|
||||
@ -55,3 +60,18 @@ message MsgRevokeAllowance {
|
||||
|
||||
// MsgRevokeAllowanceResponse defines the Msg/RevokeAllowanceResponse response type.
|
||||
message MsgRevokeAllowanceResponse {}
|
||||
|
||||
// MsgPruneAllowances prunes expired fee allowances.
|
||||
//
|
||||
// Since cosmos-sdk 0.50
|
||||
message MsgPruneAllowances {
|
||||
option (cosmos.msg.v1.signer) = "pruner";
|
||||
|
||||
// pruner is the address of the user pruning expired allowances.
|
||||
string pruner = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
}
|
||||
|
||||
// MsgPruneAllowancesResponse defines the Msg/PruneAllowancesResponse response type.
|
||||
//
|
||||
// Since cosmos-sdk 0.50
|
||||
message MsgPruneAllowancesResponse {}
|
||||
@ -14,7 +14,7 @@ require (
|
||||
cosmossdk.io/tools/confix v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231020161330-8acf4f8853ca
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe
|
||||
cosmossdk.io/x/tx v0.11.0
|
||||
cosmossdk.io/x/upgrade v0.0.0-20230925151519-64e0e8980834
|
||||
|
||||
@ -211,8 +211,8 @@ cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe h1:xcQTAlbv1l8PBHXI5/x
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe/go.mod h1:syo6njNlaE1KLXRFd1gZQr/7pMstANp2zMqVUC+u4h4=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834 h1:h4ooSV3X5BxEfl3EUbOlXNFMnEc/mXTXF5mdl17CQLg=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834/go.mod h1:yUgv71a56ZEJu7c8BXWCliDrQ7Ag+FCZ//rYKw9S93U=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8 h1:e3JUrisu36fIf+EzppkSeryOocs7oUue4e1IepdhMMI=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8/go.mod h1:nnIKdJKz1Os+sOlJHrjgMOh1WAlle0aV7Y+0x434OyI=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231020161330-8acf4f8853ca h1:YuagGZRMuE6lg913jEVGHTf6b4cWjt+gJdnhTmFQ1LA=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231020161330-8acf4f8853ca/go.mod h1:vmiW+2cIfGZULh6ReN03sawbhn8UUGrttNMxiIiduKI=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe h1:xDWsbJp/9Tdwh2w8/KT7E0sxb52ASTn1M+UO4pq6kko=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe/go.mod h1:QQROAXjZWeJzH6dNHUNCPhs7zHrYjknH8gYynf0IvXs=
|
||||
cosmossdk.io/x/tx v0.11.0 h1:Ak2LIC06bXqPbpMIEorkQbwVddRvRys1sL3Cjm+KPfs=
|
||||
|
||||
@ -12,7 +12,7 @@ require (
|
||||
cosmossdk.io/simapp v0.0.0-20230620040119-e078f1a49e8b
|
||||
cosmossdk.io/store v1.0.0-rc.0
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231020161330-8acf4f8853ca
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe // indirect
|
||||
cosmossdk.io/x/tx v0.11.0
|
||||
cosmossdk.io/x/upgrade v0.0.0-20230925151519-64e0e8980834
|
||||
|
||||
@ -209,8 +209,8 @@ cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe h1:xcQTAlbv1l8PBHXI5/x
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe/go.mod h1:syo6njNlaE1KLXRFd1gZQr/7pMstANp2zMqVUC+u4h4=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834 h1:h4ooSV3X5BxEfl3EUbOlXNFMnEc/mXTXF5mdl17CQLg=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834/go.mod h1:yUgv71a56ZEJu7c8BXWCliDrQ7Ag+FCZ//rYKw9S93U=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8 h1:e3JUrisu36fIf+EzppkSeryOocs7oUue4e1IepdhMMI=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8/go.mod h1:nnIKdJKz1Os+sOlJHrjgMOh1WAlle0aV7Y+0x434OyI=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231020161330-8acf4f8853ca h1:YuagGZRMuE6lg913jEVGHTf6b4cWjt+gJdnhTmFQ1LA=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231020161330-8acf4f8853ca/go.mod h1:vmiW+2cIfGZULh6ReN03sawbhn8UUGrttNMxiIiduKI=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe h1:xDWsbJp/9Tdwh2w8/KT7E0sxb52ASTn1M+UO4pq6kko=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe/go.mod h1:QQROAXjZWeJzH6dNHUNCPhs7zHrYjknH8gYynf0IvXs=
|
||||
cosmossdk.io/x/tx v0.11.0 h1:Ak2LIC06bXqPbpMIEorkQbwVddRvRys1sL3Cjm+KPfs=
|
||||
|
||||
@ -27,6 +27,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Features
|
||||
|
||||
* [#18047](https://github.com/cosmos/cosmos-sdk/pull/18047) Added a limit of 200 grants pruned per EndBlock and the method PruneAllowances that prunes 75 expired grants on every run.
|
||||
* [#14649](https://github.com/cosmos/cosmos-sdk/pull/14649) The `x/feegrant` module is extracted to have a separate go.mod file which allows it to be a standalone module.
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
@ -206,6 +206,14 @@ The feegrant module emits the following events:
|
||||
| message | granter | {granterAddress} |
|
||||
| message | grantee | {granteeAddress} |
|
||||
|
||||
### Prune fee allowances
|
||||
|
||||
| Type | Attribute Key | Attribute Value |
|
||||
| ------- | ------------- | ---------------- |
|
||||
| message | action | prune_feegrant |
|
||||
| message | pruner | {prunerAddress} |
|
||||
|
||||
|
||||
## Client
|
||||
|
||||
### CLI
|
||||
|
||||
@ -6,7 +6,9 @@ const (
|
||||
EventTypeRevokeFeeGrant = "revoke_feegrant"
|
||||
EventTypeSetFeeGrant = "set_feegrant"
|
||||
EventTypeUpdateFeeGrant = "update_feegrant"
|
||||
EventTypePruneFeeGrant = "prune_feegrant"
|
||||
|
||||
AttributeKeyGranter = "granter"
|
||||
AttributeKeyGrantee = "grantee"
|
||||
AttributeKeyPruner = "pruner"
|
||||
)
|
||||
|
||||
@ -233,12 +233,7 @@ func (k Keeper) IterateAllFeeAllowances(ctx context.Context, cb func(grant feegr
|
||||
|
||||
// UseGrantedFees will try to pay the given fee from the granter's account as requested by the grantee
|
||||
func (k Keeper) UseGrantedFees(ctx context.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error {
|
||||
f, err := k.getGrant(ctx, granter, grantee)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
grant, err := f.GetGrant()
|
||||
grant, err := k.GetAllowance(ctx, granter, grantee)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -322,10 +317,11 @@ func (k Keeper) addToFeeAllowanceQueue(ctx context.Context, grantKey []byte, exp
|
||||
}
|
||||
|
||||
// RemoveExpiredAllowances iterates grantsByExpiryQueue and deletes the expired grants.
|
||||
func (k Keeper) RemoveExpiredAllowances(ctx context.Context) error {
|
||||
func (k Keeper) RemoveExpiredAllowances(ctx context.Context, limit int32) error {
|
||||
exp := sdk.UnwrapSDKContext(ctx).BlockTime()
|
||||
store := k.storeService.OpenKVStore(ctx)
|
||||
iterator, err := store.Iterator(feegrant.FeeAllowanceQueueKeyPrefix, storetypes.InclusiveEndBytes(feegrant.AllowanceByExpTimeKey(&exp)))
|
||||
var count int32
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -342,6 +338,12 @@ func (k Keeper) RemoveExpiredAllowances(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// limit the amount of iterations to avoid taking too much time
|
||||
count++
|
||||
if count == limit {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ func TestKeeperTestSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) SetupTest() {
|
||||
suite.addrs = simtestutil.CreateIncrementalAccounts(4)
|
||||
suite.addrs = simtestutil.CreateIncrementalAccounts(20)
|
||||
key := storetypes.NewKVStoreKey(feegrant.StoreKey)
|
||||
testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test"))
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{})
|
||||
@ -46,10 +46,9 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||
// setup gomock and initialize some globally expected executions
|
||||
ctrl := gomock.NewController(suite.T())
|
||||
suite.accountKeeper = feegranttestutil.NewMockAccountKeeper(ctrl)
|
||||
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[0]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[0])).AnyTimes()
|
||||
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[1]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[1])).AnyTimes()
|
||||
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2])).AnyTimes()
|
||||
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3])).AnyTimes()
|
||||
for i := 0; i < len(suite.addrs); i++ {
|
||||
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[i]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[i])).AnyTimes()
|
||||
}
|
||||
|
||||
suite.accountKeeper.EXPECT().AddressCodec().Return(codecaddress.NewBech32Codec("cosmos")).AnyTimes()
|
||||
|
||||
@ -395,7 +394,9 @@ func (suite *KeeperTestSuite) TestPruneGrants() {
|
||||
}
|
||||
err := suite.feegrantKeeper.GrantAllowance(suite.ctx, tc.granter, tc.grantee, tc.allowance)
|
||||
suite.NoError(err)
|
||||
suite.feegrantKeeper.RemoveExpiredAllowances(tc.ctx)
|
||||
err = suite.feegrantKeeper.RemoveExpiredAllowances(tc.ctx, 5)
|
||||
suite.NoError(err)
|
||||
|
||||
grant, err := suite.feegrantKeeper.GetAllowance(tc.ctx, tc.granter, tc.grantee)
|
||||
if tc.expErrMsg != "" {
|
||||
suite.Error(err)
|
||||
|
||||
@ -89,3 +89,22 @@ func (k msgServer) RevokeAllowance(goCtx context.Context, msg *feegrant.MsgRevok
|
||||
|
||||
return &feegrant.MsgRevokeAllowanceResponse{}, nil
|
||||
}
|
||||
|
||||
// PruneAllowances removes expired allowances from the store.
|
||||
func (k msgServer) PruneAllowances(ctx context.Context, req *feegrant.MsgPruneAllowances) (*feegrant.MsgPruneAllowancesResponse, error) {
|
||||
// 75 is an arbitrary value, we can change it later if needed
|
||||
err := k.RemoveExpiredAllowances(ctx, 75)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
||||
sdkCtx.EventManager().EmitEvent(
|
||||
sdk.NewEvent(
|
||||
feegrant.EventTypePruneFeeGrant,
|
||||
sdk.NewAttribute(feegrant.AttributeKeyPruner, req.Pruner),
|
||||
),
|
||||
)
|
||||
|
||||
return &feegrant.MsgPruneAllowancesResponse{}, nil
|
||||
}
|
||||
|
||||
@ -284,3 +284,66 @@ func (suite *KeeperTestSuite) TestRevokeAllowance() {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestPruneAllowances() {
|
||||
ctx := suite.ctx.WithBlockTime(time.Now())
|
||||
oneYear := ctx.BlockTime().AddDate(1, 0, 0)
|
||||
|
||||
// We create 76 allowances, all expiring in one year
|
||||
count := 0
|
||||
for i := 0; i < len(suite.addrs); i++ {
|
||||
for j := 0; j < len(suite.addrs); j++ {
|
||||
if count == 76 {
|
||||
break
|
||||
}
|
||||
if suite.addrs[i].String() == suite.addrs[j].String() {
|
||||
continue
|
||||
}
|
||||
|
||||
any, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{
|
||||
SpendLimit: suite.atom,
|
||||
Expiration: &oneYear,
|
||||
})
|
||||
suite.Require().NoError(err)
|
||||
req := &feegrant.MsgGrantAllowance{
|
||||
Granter: suite.addrs[i].String(),
|
||||
Grantee: suite.addrs[j].String(),
|
||||
Allowance: any,
|
||||
}
|
||||
|
||||
_, err = suite.msgSrvr.GrantAllowance(ctx, req)
|
||||
if err != nil {
|
||||
// do not fail, just try with another pair
|
||||
continue
|
||||
}
|
||||
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
// we have 76 allowances
|
||||
count = 0
|
||||
err := suite.feegrantKeeper.IterateAllFeeAllowances(ctx, func(grant feegrant.Grant) bool {
|
||||
count++
|
||||
return false
|
||||
})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(76, count)
|
||||
|
||||
// after a year and one day passes, they are all expired
|
||||
oneYearAndADay := ctx.BlockTime().AddDate(1, 0, 1)
|
||||
ctx = suite.ctx.WithBlockTime(oneYearAndADay)
|
||||
|
||||
// we prune them, but currently only 75 will be pruned
|
||||
_, err = suite.msgSrvr.PruneAllowances(ctx, &feegrant.MsgPruneAllowances{})
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// we have 1 allowance left
|
||||
count = 0
|
||||
err = suite.feegrantKeeper.IterateAllFeeAllowances(ctx, func(grant feegrant.Grant) bool {
|
||||
count++
|
||||
return false
|
||||
})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(1, count)
|
||||
}
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"cosmossdk.io/x/feegrant/keeper"
|
||||
"context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"cosmossdk.io/x/feegrant/keeper"
|
||||
)
|
||||
|
||||
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
|
||||
err := k.RemoveExpiredAllowances(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
func EndBlocker(ctx context.Context, k keeper.Keeper) error {
|
||||
// 200 is an arbitrary value, we can change it later if needed
|
||||
return k.RemoveExpiredAllowances(ctx, 200)
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ func TestFeegrantPruning(t *testing.T) {
|
||||
feegrant.RegisterQueryServer(queryHelper, feegrantKeeper)
|
||||
queryClient := feegrant.NewQueryClient(queryHelper)
|
||||
|
||||
module.EndBlocker(testCtx.Ctx, feegrantKeeper)
|
||||
require.NoError(t, module.EndBlocker(testCtx.Ctx, feegrantKeeper))
|
||||
|
||||
res, err := queryClient.Allowances(testCtx.Ctx.Context(), &feegrant.QueryAllowancesRequest{
|
||||
Grantee: grantee.String(),
|
||||
|
||||
@ -60,6 +60,13 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
{ProtoField: "grantee"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "PruneAllowances",
|
||||
Use: "prune",
|
||||
Short: "Prune expired allowances",
|
||||
Long: "Prune up to 75 expired allowances in order to reduce the size of the store when the number of expired allowances is large.",
|
||||
Example: fmt.Sprintf(`$ %s tx feegrant prune --from [mykey]`, version.AppName),
|
||||
},
|
||||
},
|
||||
EnhanceCustomCommand: true,
|
||||
},
|
||||
|
||||
@ -162,9 +162,7 @@ func (AppModule) ConsensusVersion() uint64 { return 2 }
|
||||
// EndBlock returns the end blocker for the feegrant module. It returns no validator
|
||||
// updates.
|
||||
func (am AppModule) EndBlock(ctx context.Context) error {
|
||||
c := sdk.UnwrapSDKContext(ctx)
|
||||
EndBlocker(c, am.keeper)
|
||||
return nil
|
||||
return EndBlocker(ctx, am.keeper)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@ -225,17 +225,106 @@ func (m *MsgRevokeAllowanceResponse) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_MsgRevokeAllowanceResponse proto.InternalMessageInfo
|
||||
|
||||
// MsgPruneAllowances prunes expired fee allowances.
|
||||
//
|
||||
// Since cosmos-sdk 0.50
|
||||
type MsgPruneAllowances struct {
|
||||
// pruner is the address of the user pruning expired allowances.
|
||||
Pruner string `protobuf:"bytes,1,opt,name=pruner,proto3" json:"pruner,omitempty"`
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowances) Reset() { *m = MsgPruneAllowances{} }
|
||||
func (m *MsgPruneAllowances) String() string { return proto.CompactTextString(m) }
|
||||
func (*MsgPruneAllowances) ProtoMessage() {}
|
||||
func (*MsgPruneAllowances) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_dd44ad7946dad783, []int{4}
|
||||
}
|
||||
func (m *MsgPruneAllowances) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *MsgPruneAllowances) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_MsgPruneAllowances.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *MsgPruneAllowances) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_MsgPruneAllowances.Merge(m, src)
|
||||
}
|
||||
func (m *MsgPruneAllowances) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *MsgPruneAllowances) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_MsgPruneAllowances.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_MsgPruneAllowances proto.InternalMessageInfo
|
||||
|
||||
func (m *MsgPruneAllowances) GetPruner() string {
|
||||
if m != nil {
|
||||
return m.Pruner
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// MsgPruneAllowancesResponse defines the Msg/PruneAllowancesResponse response type.
|
||||
//
|
||||
// Since cosmos-sdk 0.50
|
||||
type MsgPruneAllowancesResponse struct {
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowancesResponse) Reset() { *m = MsgPruneAllowancesResponse{} }
|
||||
func (m *MsgPruneAllowancesResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*MsgPruneAllowancesResponse) ProtoMessage() {}
|
||||
func (*MsgPruneAllowancesResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_dd44ad7946dad783, []int{5}
|
||||
}
|
||||
func (m *MsgPruneAllowancesResponse) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *MsgPruneAllowancesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_MsgPruneAllowancesResponse.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *MsgPruneAllowancesResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_MsgPruneAllowancesResponse.Merge(m, src)
|
||||
}
|
||||
func (m *MsgPruneAllowancesResponse) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *MsgPruneAllowancesResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_MsgPruneAllowancesResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_MsgPruneAllowancesResponse proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*MsgGrantAllowance)(nil), "cosmos.feegrant.v1beta1.MsgGrantAllowance")
|
||||
proto.RegisterType((*MsgGrantAllowanceResponse)(nil), "cosmos.feegrant.v1beta1.MsgGrantAllowanceResponse")
|
||||
proto.RegisterType((*MsgRevokeAllowance)(nil), "cosmos.feegrant.v1beta1.MsgRevokeAllowance")
|
||||
proto.RegisterType((*MsgRevokeAllowanceResponse)(nil), "cosmos.feegrant.v1beta1.MsgRevokeAllowanceResponse")
|
||||
proto.RegisterType((*MsgPruneAllowances)(nil), "cosmos.feegrant.v1beta1.MsgPruneAllowances")
|
||||
proto.RegisterType((*MsgPruneAllowancesResponse)(nil), "cosmos.feegrant.v1beta1.MsgPruneAllowancesResponse")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("cosmos/feegrant/v1beta1/tx.proto", fileDescriptor_dd44ad7946dad783) }
|
||||
|
||||
var fileDescriptor_dd44ad7946dad783 = []byte{
|
||||
// 409 bytes of a gzipped FileDescriptorProto
|
||||
// 455 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce,
|
||||
0xcd, 0x2f, 0xd6, 0x4f, 0x4b, 0x4d, 0x4d, 0x2f, 0x4a, 0xcc, 0x2b, 0xd1, 0x2f, 0x33, 0x4c, 0x4a,
|
||||
0x2d, 0x49, 0x34, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x87, 0xa8,
|
||||
@ -254,14 +343,17 @@ var fileDescriptor_dd44ad7946dad783 = []byte{
|
||||
0xb2, 0xf5, 0x31, 0x7c, 0xad, 0x24, 0xcd, 0x25, 0x89, 0x21, 0x18, 0x94, 0x5a, 0x5c, 0x90, 0x9f,
|
||||
0x57, 0x9c, 0xaa, 0xb4, 0x86, 0x91, 0x4b, 0xc8, 0xb7, 0x38, 0x3d, 0x28, 0xb5, 0x2c, 0x3f, 0x3b,
|
||||
0x95, 0xee, 0x21, 0x65, 0xa5, 0x87, 0xee, 0x15, 0x59, 0x54, 0xaf, 0xa0, 0xb9, 0x4b, 0x49, 0x86,
|
||||
0x4b, 0x0a, 0x53, 0x14, 0xe6, 0x19, 0xa3, 0xcf, 0x8c, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, 0x42, 0x05,
|
||||
0x5c, 0x7c, 0x68, 0x31, 0xaf, 0xa5, 0x87, 0x2b, 0x94, 0x31, 0x82, 0x46, 0xca, 0x88, 0x78, 0xb5,
|
||||
0x30, 0x9b, 0x85, 0x8a, 0xb9, 0xf8, 0xd1, 0x83, 0x50, 0x1b, 0x9f, 0x31, 0x68, 0x8a, 0xa5, 0x8c,
|
||||
0x49, 0x50, 0x0c, 0xb3, 0x54, 0x8a, 0xb5, 0xe1, 0xf9, 0x06, 0x2d, 0x46, 0x27, 0xc3, 0x13, 0x8f,
|
||||
0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b,
|
||||
0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x82, 0xe6, 0x98, 0xe2, 0x94, 0x6c, 0xbd, 0xcc,
|
||||
0x7c, 0xfd, 0x0a, 0x78, 0x56, 0x4d, 0x62, 0x03, 0xa7, 0x42, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff,
|
||||
0xff, 0x3f, 0x13, 0x6c, 0x2e, 0xc4, 0x03, 0x00, 0x00,
|
||||
0x4b, 0x0a, 0x53, 0x14, 0xee, 0x99, 0x60, 0xb0, 0x5f, 0x02, 0x8a, 0x4a, 0xf3, 0x10, 0x92, 0xc5,
|
||||
0x42, 0x06, 0x5c, 0x6c, 0x05, 0x20, 0x21, 0xc2, 0x5e, 0x81, 0xaa, 0xb3, 0xe2, 0x06, 0xb9, 0x0a,
|
||||
0xca, 0x81, 0x5a, 0x89, 0x66, 0x28, 0xcc, 0x4a, 0xa3, 0x17, 0x4c, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9,
|
||||
0x42, 0x05, 0x5c, 0x7c, 0x68, 0x89, 0x4d, 0x4b, 0x0f, 0x57, 0xc4, 0x62, 0xc4, 0x86, 0x94, 0x11,
|
||||
0xf1, 0x6a, 0x61, 0x36, 0x0b, 0x15, 0x73, 0xf1, 0xa3, 0xc7, 0x9a, 0x36, 0x3e, 0x63, 0xd0, 0x14,
|
||||
0x4b, 0x19, 0x93, 0xa0, 0x18, 0xd9, 0x52, 0xf4, 0xe0, 0xc5, 0x6b, 0x29, 0x9a, 0x62, 0xfc, 0x96,
|
||||
0xe2, 0x08, 0x63, 0x29, 0xd6, 0x86, 0xe7, 0x1b, 0xb4, 0x18, 0x9d, 0x0c, 0x4f, 0x3c, 0x92, 0x63,
|
||||
0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96,
|
||||
0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x0a, 0x5a, 0x32, 0x14, 0xa7, 0x64, 0xeb, 0x65, 0xe6, 0xeb,
|
||||
0x57, 0xc0, 0x8b, 0xa4, 0x24, 0x36, 0x70, 0x6e, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8d,
|
||||
0x04, 0xdd, 0xf4, 0xac, 0x04, 0x00, 0x00,
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
@ -282,6 +374,10 @@ type MsgClient interface {
|
||||
// RevokeAllowance revokes any fee allowance of granter's account that
|
||||
// has been granted to the grantee.
|
||||
RevokeAllowance(ctx context.Context, in *MsgRevokeAllowance, opts ...grpc.CallOption) (*MsgRevokeAllowanceResponse, error)
|
||||
// PruneAllowances prunes expired fee allowances, currently up to 75 at a time.
|
||||
//
|
||||
// Since cosmos-sdk 0.50
|
||||
PruneAllowances(ctx context.Context, in *MsgPruneAllowances, opts ...grpc.CallOption) (*MsgPruneAllowancesResponse, error)
|
||||
}
|
||||
|
||||
type msgClient struct {
|
||||
@ -310,6 +406,15 @@ func (c *msgClient) RevokeAllowance(ctx context.Context, in *MsgRevokeAllowance,
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *msgClient) PruneAllowances(ctx context.Context, in *MsgPruneAllowances, opts ...grpc.CallOption) (*MsgPruneAllowancesResponse, error) {
|
||||
out := new(MsgPruneAllowancesResponse)
|
||||
err := c.cc.Invoke(ctx, "/cosmos.feegrant.v1beta1.Msg/PruneAllowances", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// MsgServer is the server API for Msg service.
|
||||
type MsgServer interface {
|
||||
// GrantAllowance grants fee allowance to the grantee on the granter's
|
||||
@ -318,6 +423,10 @@ type MsgServer interface {
|
||||
// RevokeAllowance revokes any fee allowance of granter's account that
|
||||
// has been granted to the grantee.
|
||||
RevokeAllowance(context.Context, *MsgRevokeAllowance) (*MsgRevokeAllowanceResponse, error)
|
||||
// PruneAllowances prunes expired fee allowances, currently up to 75 at a time.
|
||||
//
|
||||
// Since cosmos-sdk 0.50
|
||||
PruneAllowances(context.Context, *MsgPruneAllowances) (*MsgPruneAllowancesResponse, error)
|
||||
}
|
||||
|
||||
// UnimplementedMsgServer can be embedded to have forward compatible implementations.
|
||||
@ -330,6 +439,9 @@ func (*UnimplementedMsgServer) GrantAllowance(ctx context.Context, req *MsgGrant
|
||||
func (*UnimplementedMsgServer) RevokeAllowance(ctx context.Context, req *MsgRevokeAllowance) (*MsgRevokeAllowanceResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method RevokeAllowance not implemented")
|
||||
}
|
||||
func (*UnimplementedMsgServer) PruneAllowances(ctx context.Context, req *MsgPruneAllowances) (*MsgPruneAllowancesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method PruneAllowances not implemented")
|
||||
}
|
||||
|
||||
func RegisterMsgServer(s grpc1.Server, srv MsgServer) {
|
||||
s.RegisterService(&_Msg_serviceDesc, srv)
|
||||
@ -371,6 +483,24 @@ func _Msg_RevokeAllowance_Handler(srv interface{}, ctx context.Context, dec func
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Msg_PruneAllowances_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(MsgPruneAllowances)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(MsgServer).PruneAllowances(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/cosmos.feegrant.v1beta1.Msg/PruneAllowances",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(MsgServer).PruneAllowances(ctx, req.(*MsgPruneAllowances))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _Msg_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "cosmos.feegrant.v1beta1.Msg",
|
||||
HandlerType: (*MsgServer)(nil),
|
||||
@ -383,6 +513,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{
|
||||
MethodName: "RevokeAllowance",
|
||||
Handler: _Msg_RevokeAllowance_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "PruneAllowances",
|
||||
Handler: _Msg_PruneAllowances_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "cosmos/feegrant/v1beta1/tx.proto",
|
||||
@ -520,6 +654,59 @@ func (m *MsgRevokeAllowanceResponse) MarshalToSizedBuffer(dAtA []byte) (int, err
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowances) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowances) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowances) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Pruner) > 0 {
|
||||
i -= len(m.Pruner)
|
||||
copy(dAtA[i:], m.Pruner)
|
||||
i = encodeVarintTx(dAtA, i, uint64(len(m.Pruner)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowancesResponse) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowancesResponse) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowancesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintTx(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovTx(v)
|
||||
base := offset
|
||||
@ -587,6 +774,28 @@ func (m *MsgRevokeAllowanceResponse) Size() (n int) {
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowances) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Pruner)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovTx(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *MsgPruneAllowancesResponse) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
return n
|
||||
}
|
||||
|
||||
func sovTx(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
@ -957,6 +1166,138 @@ func (m *MsgRevokeAllowanceResponse) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *MsgPruneAllowances) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowTx
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: MsgPruneAllowances: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: MsgPruneAllowances: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Pruner", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowTx
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthTx
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthTx
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Pruner = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipTx(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthTx
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *MsgPruneAllowancesResponse) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowTx
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: MsgPruneAllowancesResponse: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: MsgPruneAllowancesResponse: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipTx(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthTx
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipTx(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user