Skip to content

Commit

Permalink
Chore: Claim Deposits in Batches (#318) (#319)
Browse files Browse the repository at this point in the history
* add batch claim deposits

* remove old claimdeposit msg

(cherry picked from commit cdc0e4f)

Co-authored-by: tkernell <[email protected]>
  • Loading branch information
github-actions[bot] and tkernell authored Sep 4, 2024
1 parent 76c2d53 commit 67bb26b
Show file tree
Hide file tree
Showing 11 changed files with 875 additions and 564 deletions.
781 changes: 523 additions & 258 deletions api/layer/bridge/tx.pulsar.go

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions api/layer/bridge/tx_grpc.pb.go

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

10 changes: 5 additions & 5 deletions proto/layer/bridge/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ service Msg {
option (cosmos.msg.v1.service) = true;
rpc RequestAttestations(MsgRequestAttestations) returns (MsgRequestAttestationsResponse);
rpc WithdrawTokens(MsgWithdrawTokens) returns (MsgWithdrawTokensResponse);
rpc ClaimDeposit(MsgClaimDepositRequest) returns (MsgClaimDepositResponse);
rpc ClaimDeposits(MsgClaimDepositsRequest) returns (MsgClaimDepositsResponse);
}

message MsgRequestAttestations {
Expand All @@ -36,12 +36,12 @@ message MsgWithdrawTokens {

message MsgWithdrawTokensResponse {}

message MsgClaimDepositRequest {
message MsgClaimDepositsRequest {
option (cosmos.msg.v1.signer) = "creator";

string creator = 1;
uint64 deposit_id = 2;
uint64 index = 3;
repeated uint64 deposit_ids = 2;
repeated uint64 indices = 3;
}

message MsgClaimDepositResponse {}
message MsgClaimDepositsResponse {}
8 changes: 4 additions & 4 deletions x/bridge/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "creator"}, {ProtoField: "recipient"}, {ProtoField: "amount"}},
},
{
RpcMethod: "ClaimDeposit",
Use: "claim-deposit [creator] [deposit-id] [index]",
Short: "Execute the ClaimDeposit RPC method",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "creator"}, {ProtoField: "deposit_id"}, {ProtoField: "index"}},
RpcMethod: "ClaimDeposits",
Use: "claim-deposits [creator] [deposit-ids] [indices]",
Short: "Execute the ClaimDeposits RPC method",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "creator"}, {ProtoField: "deposit_ids"}, {ProtoField: "indices"}},
},
// this line is used by ignite scaffolding # autocli/tx
},
Expand Down
27 changes: 0 additions & 27 deletions x/bridge/keeper/msg_server_claim_deposit.go

This file was deleted.

32 changes: 32 additions & 0 deletions x/bridge/keeper/msg_server_claim_deposits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package keeper

import (
"context"
"strconv"

"github.com/tellor-io/layer/x/bridge/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k msgServer) ClaimDeposits(goCtx context.Context, msg *types.MsgClaimDepositsRequest) (*types.MsgClaimDepositsResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(goCtx)
if len(msg.DepositIds) != len(msg.Indices) {
return nil, types.ErrInvalidDepositIdsAndIndicesLength
}
msgSender := sdk.MustAccAddressFromBech32(msg.Creator)
for i, depositId := range msg.DepositIds {
index := msg.Indices[i]
if err := k.Keeper.ClaimDeposit(sdkCtx, depositId, index, msgSender); err != nil {
return nil, err
}
sdk.UnwrapSDKContext(goCtx).EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"deposit_claimed",
sdk.NewAttribute("deposit_id", strconv.FormatUint(depositId, 10)),
),
})
}

return &types.MsgClaimDepositsResponse{}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestMsgClaimDeposit(t *testing.T) {
func TestMsgClaimDeposits(t *testing.T) {
k, _, bk, ok, _, _, ctx := setupKeeper(t)
msgServer := keeper.NewMsgServerImpl(k)

require.Panics(t, func() {
_, err := msgServer.ClaimDeposit(ctx, nil)
_, err := msgServer.ClaimDeposits(ctx, nil)
require.Error(t, err)
})

Expand Down Expand Up @@ -73,10 +73,10 @@ func TestMsgClaimDeposit(t *testing.T) {
depositId := uint64(0)
reportIndex := uint64(0)

result, err := msgServer.ClaimDeposit(sdkCtx, &bridgetypes.MsgClaimDepositRequest{
Creator: msgSender.String(),
DepositId: depositId,
Index: reportIndex,
result, err := msgServer.ClaimDeposits(sdkCtx, &bridgetypes.MsgClaimDepositsRequest{
Creator: msgSender.String(),
DepositIds: []uint64{depositId},
Indices: []uint64{reportIndex},
})
require.NoError(t, err)
require.NotNil(t, result)
Expand Down
15 changes: 8 additions & 7 deletions x/bridge/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (

// x/bridge module sentinel errors
var (
ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error")
ErrNoAggregate = sdkerrors.Register(ModuleName, 1101, "no aggregate found")
ErrAggregateFlagged = sdkerrors.Register(ModuleName, 1102, "aggregate flagged")
ErrInsufficientReporterPower = sdkerrors.Register(ModuleName, 1103, "insufficient reporter power")
ErrReportTooYoung = sdkerrors.Register(ModuleName, 1104, "report too young")
ErrInvalidDepositReportValue = sdkerrors.Register(ModuleName, 1105, "invalid deposit report value")
ErrDepositAlreadyClaimed = sdkerrors.Register(ModuleName, 1106, "deposit already claimed")
ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error")
ErrNoAggregate = sdkerrors.Register(ModuleName, 1101, "no aggregate found")
ErrAggregateFlagged = sdkerrors.Register(ModuleName, 1102, "aggregate flagged")
ErrInsufficientReporterPower = sdkerrors.Register(ModuleName, 1103, "insufficient reporter power")
ErrReportTooYoung = sdkerrors.Register(ModuleName, 1104, "report too young")
ErrInvalidDepositReportValue = sdkerrors.Register(ModuleName, 1105, "invalid deposit report value")
ErrDepositAlreadyClaimed = sdkerrors.Register(ModuleName, 1106, "deposit already claimed")
ErrInvalidDepositIdsAndIndicesLength = sdkerrors.Register(ModuleName, 1107, "invalid deposit ids and indices length")
)
49 changes: 0 additions & 49 deletions x/bridge/types/message_claim_deposit.go

This file was deleted.

59 changes: 0 additions & 59 deletions x/bridge/types/message_claim_deposit_test.go

This file was deleted.

Loading

0 comments on commit 67bb26b

Please sign in to comment.