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

refactor(axelarnet): archive failed transfer #2200

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions client/docs/static/openapi/index.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions client/docs/static/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15268,6 +15268,7 @@ paths:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
default: TRANSFER_STATE_UNSPECIFIED
title: >-
CrossChainTransfer represents a generalized transfer of
Expand Down Expand Up @@ -15487,6 +15488,7 @@ paths:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
- name: pagination.key
description: |-
key is a value returned in PageResponse.next_key to begin
Expand Down Expand Up @@ -51544,6 +51546,7 @@ components:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
default: TRANSFER_STATE_UNSPECIFIED
title: |-
CrossChainTransfer represents a generalized transfer of some asset to a
Expand Down Expand Up @@ -51667,6 +51670,7 @@ components:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
default: TRANSFER_STATE_UNSPECIFIED
axelar.nexus.v1beta1.ActivateChainRequest:
type: object
Expand Down Expand Up @@ -52373,6 +52377,7 @@ components:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
default: TRANSFER_STATE_UNSPECIFIED
title: >-
CrossChainTransfer represents a generalized transfer of some asset
Expand Down
5 changes: 5 additions & 0 deletions client/docs/static/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16781,6 +16781,7 @@ paths:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
default: TRANSFER_STATE_UNSPECIFIED
title: >-
CrossChainTransfer represents a generalized transfer of some
Expand Down Expand Up @@ -17020,6 +17021,7 @@ paths:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
- name: pagination.key
description: |-
key is a value returned in PageResponse.next_key to begin
Expand Down Expand Up @@ -55964,6 +55966,7 @@ definitions:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
default: TRANSFER_STATE_UNSPECIFIED
title: |-
CrossChainTransfer represents a generalized transfer of some asset to a
Expand Down Expand Up @@ -56089,6 +56092,7 @@ definitions:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
default: TRANSFER_STATE_UNSPECIFIED
axelar.nexus.v1beta1.ActivateChainRequest:
type: object
Expand Down Expand Up @@ -56798,6 +56802,7 @@ definitions:
- TRANSFER_STATE_PENDING
- TRANSFER_STATE_ARCHIVED
- TRANSFER_STATE_INSUFFICIENT_AMOUNT
- TRANSFER_STATE_FAILED
default: TRANSFER_STATE_UNSPECIFIED
title: >-
CrossChainTransfer represents a generalized transfer of some asset
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/proto/proto-docs.md

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

1 change: 1 addition & 0 deletions proto/axelar/nexus/exported/v1beta1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum TransferState {
TRANSFER_STATE_ARCHIVED = 2 [ (gogoproto.enumvalue_customname) = "Archived" ];
TRANSFER_STATE_INSUFFICIENT_AMOUNT = 3
[ (gogoproto.enumvalue_customname) = "InsufficientAmount" ];
TRANSFER_STATE_FAILED = 4 [ (gogoproto.enumvalue_customname) = "TransferFailed" ];
haiyizxx marked this conversation as resolved.
Show resolved Hide resolved
}

// TransferFee represents accumulated fees generated by the network
Expand Down
42 changes: 24 additions & 18 deletions x/axelarnet/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,33 @@
}

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
}
success := utils.RunCached(ctx, s, func(ctx sdk.Context) (bool, error) {
recipient, err := sdk.AccAddressFromBech32(pendingTransfer.Recipient.Address)
haiyizxx marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
s.Logger(ctx).Error(fmt.Sprintf("discard invalid recipient %s and continue", pendingTransfer.Recipient.Address))
haiyizxx marked this conversation as resolved.
Show resolved Hide resolved
return false, err
}

Check warning on line 263 in x/axelarnet/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/axelarnet/keeper/msg_server.go#L261-L263

Added lines #L261 - L263 were not covered by tests

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
}
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
}

events.Emit(ctx,
&types.AxelarTransferCompleted{
ID: pendingTransfer.ID,
Receipient: pendingTransfer.Recipient.Address,
Asset: pendingTransfer.Asset,
Recipient: pendingTransfer.Recipient.Address,
})
s.nexus.ArchivePendingTransfer(ctx, pendingTransfer)
events.Emit(ctx,
&types.AxelarTransferCompleted{
ID: pendingTransfer.ID,
Receipient: pendingTransfer.Recipient.Address,
Asset: pendingTransfer.Asset,
Recipient: pendingTransfer.Recipient.Address,
})

s.nexus.ArchivePendingTransfer(ctx, pendingTransfer)
return true, nil
})

if !success {
s.nexus.MarkTransferAsFailed(ctx, pendingTransfer)
}
}

// release transfer fees
Expand Down
7 changes: 5 additions & 2 deletions x/axelarnet/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ func TestHandleMsgExecutePendingTransfers(t *testing.T) {
GetTransferFeesFunc: func(sdk.Context) sdk.Coins {
return sdk.Coins{}
},
SubTransferFeeFunc: func(sdk.Context, sdk.Coin) {},
SubTransferFeeFunc: func(sdk.Context, sdk.Coin) {},
MarkTransferAsFailedFunc: func(sdk.Context, nexus.CrossChainTransfer) {},
}
bankK = &mock.BankKeeperMock{}
transferK = &mock.IBCTransferKeeperMock{}
Expand Down Expand Up @@ -357,11 +358,13 @@ func TestHandleMsgExecutePendingTransfers(t *testing.T) {
}
}).
When2(requestIsMade).
Then("should not archive the transfer", func(t *testing.T) {
Then("should mark the transfer as failed", 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.MarkTransferAsFailedCalls(), 1)
assert.Len(t, ctx.EventManager().Events(), 0)
}),

whenHasPendingTransfers.
Expand Down
1 change: 1 addition & 0 deletions x/axelarnet/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Nexus interface {
EnqueueTransfer(ctx sdk.Context, senderChain nexus.Chain, recipient nexus.CrossChainAddress, asset sdk.Coin) (nexus.TransferID, error)
GetTransfersForChainPaginated(ctx sdk.Context, chain nexus.Chain, state nexus.TransferState, pageRequest *query.PageRequest) ([]nexus.CrossChainTransfer, *query.PageResponse, error)
ArchivePendingTransfer(ctx sdk.Context, transfer nexus.CrossChainTransfer)
MarkTransferAsFailed(ctx sdk.Context, transfer nexus.CrossChainTransfer)
RegisterAsset(ctx sdk.Context, chain nexus.Chain, asset nexus.Asset, limit sdk.Uint, window time.Duration) error
GetRecipient(ctx sdk.Context, sender nexus.CrossChainAddress) (nexus.CrossChainAddress, bool)
SetChain(ctx sdk.Context, chain nexus.Chain)
Expand Down
50 changes: 50 additions & 0 deletions x/axelarnet/types/mock/expected_keepers.go

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

Loading
Loading