From 9baf7039f421d1a61bd9f32d91e6eaed6986893d Mon Sep 17 00:00:00 2001 From: Haiyi Zhong Date: Tue, 22 Oct 2024 04:46:07 +0800 Subject: [PATCH 1/3] refactor(axelarnet): archive failed transfer --- x/axelarnet/keeper/msg_server.go | 41 +++++++++++++++------------ x/axelarnet/keeper/msg_server_test.go | 5 ++-- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/x/axelarnet/keeper/msg_server.go b/x/axelarnet/keeper/msg_server.go index efaadbc48..66f882c34 100644 --- a/x/axelarnet/keeper/msg_server.go +++ b/x/axelarnet/keeper/msg_server.go @@ -255,27 +255,32 @@ func (s msgServer) ExecutePendingTransfers(c context.Context, _ *types.ExecutePe } for _, pendingTransfer := range pendingTransfers { - recipient, err := sdk.AccAddressFromBech32(pendingTransfer.Recipient.Address) - if err != nil { - s.Logger(ctx).Error(fmt.Sprintf("discard invalid recipient %s and continue", pendingTransfer.Recipient.Address)) - s.nexus.ArchivePendingTransfer(ctx, pendingTransfer) - continue - } + s.nexus.ArchivePendingTransfer(ctx, pendingTransfer) - if err = transfer(ctx, s.Keeper, s.nexus, s.bank, s.ibcK, recipient, pendingTransfer.Asset); err != nil { - s.Logger(ctx).Error("failed to transfer asset to axelarnet", "err", err) - continue - } + success := utils.RunCached(ctx, s, func(ctx sdk.Context) (bool, error) { + recipient, err := sdk.AccAddressFromBech32(pendingTransfer.Recipient.Address) + if err != nil { + s.Logger(ctx).Error(fmt.Sprintf("discard invalid recipient %s and continue", pendingTransfer.Recipient.Address)) + return false, err + } - events.Emit(ctx, - &types.AxelarTransferCompleted{ - ID: pendingTransfer.ID, - Receipient: pendingTransfer.Recipient.Address, - Asset: pendingTransfer.Asset, - Recipient: pendingTransfer.Recipient.Address, - }) + if err = transfer(ctx, s.Keeper, s.nexus, s.bank, s.ibcK, recipient, pendingTransfer.Asset); err != nil { + s.Logger(ctx).Error("failed to transfer asset to axelarnet", "err", err) + return false, err + } - s.nexus.ArchivePendingTransfer(ctx, pendingTransfer) + return true, nil + }) + + if success { + events.Emit(ctx, + &types.AxelarTransferCompleted{ + ID: pendingTransfer.ID, + Receipient: pendingTransfer.Recipient.Address, + Asset: pendingTransfer.Asset, + Recipient: pendingTransfer.Recipient.Address, + }) + } } // release transfer fees diff --git a/x/axelarnet/keeper/msg_server_test.go b/x/axelarnet/keeper/msg_server_test.go index 9fc7250a3..c8dedf73e 100644 --- a/x/axelarnet/keeper/msg_server_test.go +++ b/x/axelarnet/keeper/msg_server_test.go @@ -357,11 +357,12 @@ func TestHandleMsgExecutePendingTransfers(t *testing.T) { } }). When2(requestIsMade). - Then("should not archive the transfer", func(t *testing.T) { + Then("should archive the failed transfer", func(t *testing.T) { _, err := server.ExecutePendingTransfers(sdk.WrapSDKContext(ctx), req) assert.NoError(t, err) - assert.Len(t, nexusK.ArchivePendingTransferCalls(), 0) + assert.Len(t, nexusK.ArchivePendingTransferCalls(), 1) + assert.Len(t, ctx.EventManager().Events(), 0) }), whenHasPendingTransfers. From 062cd653680e8ec8fc5b2e4c30bd135727f2236c Mon Sep 17 00:00:00 2001 From: Haiyi Zhong Date: Mon, 28 Oct 2024 14:53:37 -0400 Subject: [PATCH 2/3] transfer failed status --- client/docs/static/openapi/index.html | 4 +- client/docs/static/openapi/openapi.yaml | 5 + client/docs/static/swagger/swagger.yaml | 5 + client/docs/statik/statik.go | 2 +- docs/proto/proto-docs.md | 1 + .../axelar/nexus/exported/v1beta1/types.proto | 1 + x/axelarnet/keeper/msg_server.go | 13 +- x/axelarnet/keeper/msg_server_test.go | 8 +- x/axelarnet/types/expected_keepers.go | 1 + x/axelarnet/types/mock/expected_keepers.go | 50 ++++++ x/nexus/exported/types.pb.go | 170 +++++++++--------- x/nexus/keeper/transfer.go | 8 + 12 files changed, 173 insertions(+), 95 deletions(-) diff --git a/client/docs/static/openapi/index.html b/client/docs/static/openapi/index.html index 5c02427c7..bf009273b 100644 --- a/client/docs/static/openapi/index.html +++ b/client/docs/static/openapi/index.html @@ -2500,7 +2500,7 @@

JSON

TransferRateLimit queries the transfer rate limit for a given chain and asset. If a rate limit is not set, nil is returned.

path Parameters
chain
required
string
asset
required
string

Responses

TransfersForChain queries transfers by chain

path Parameters
chain
required
string
state
required
string
Enum: "TRANSFER_STATE_UNSPECIFIED" "TRANSFER_STATE_PENDING" "TRANSFER_STATE_ARCHIVED" "TRANSFER_STATE_INSUFFICIENT_AMOUNT"
query Parameters
pagination.key
string <byte>

key is a value returned in PageResponse.next_key to begin +

TransfersForChain queries transfers by chain

path Parameters
chain
required
string
state
required
string
Enum: "TRANSFER_STATE_UNSPECIFIED" "TRANSFER_STATE_PENDING" "TRANSFER_STATE_ARCHIVED" "TRANSFER_STATE_INSUFFICIENT_AMOUNT" "TRANSFER_STATE_FAILED"
query Parameters
pagination.key
string <byte>

key is a value returned in PageResponse.next_key to begin querying the next page most efficiently. Only one of offset or key should be set.

pagination.offset
string <uint64>

offset is a numeric offset that can be used when key is unavailable. @@ -3493,7 +3493,7 @@

JSON