Skip to content

Commit

Permalink
transfer failed status
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx committed Oct 28, 2024
1 parent 9baf703 commit 0765f85
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 94 deletions.
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" ];
}

// TransferFee represents accumulated fees generated by the network
Expand Down
13 changes: 7 additions & 6 deletions x/axelarnet/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ func (s msgServer) ExecutePendingTransfers(c context.Context, _ *types.ExecutePe
}

for _, pendingTransfer := range pendingTransfers {
s.nexus.ArchivePendingTransfer(ctx, pendingTransfer)

success := utils.RunCached(ctx, s, func(ctx sdk.Context) (bool, error) {
recipient, err := sdk.AccAddressFromBech32(pendingTransfer.Recipient.Address)
if err != nil {
Expand All @@ -269,17 +267,20 @@ func (s msgServer) ExecutePendingTransfers(c context.Context, _ *types.ExecutePe
return false, err
}

return true, nil
})

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

return true, nil
})

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

Expand Down
6 changes: 4 additions & 2 deletions x/axelarnet/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,12 @@ func TestHandleMsgExecutePendingTransfers(t *testing.T) {
}
}).
When2(requestIsMade).
Then("should archive the failed 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(), 1)
assert.Len(t, nexusK.ArchivePendingTransferCalls(), 0)
assert.Len(t, nexusK.MarkTransferAsFailedCalls(), 1)
assert.Len(t, ctx.EventManager().Events(), 0)
}),

Expand Down Expand Up @@ -435,6 +436,7 @@ func TestHandleMsgRouteIBCTransfers(t *testing.T) {
return nexustestutils.RandomChain(), true
},
ArchivePendingTransferFunc: func(sdk.Context, nexus.CrossChainTransfer) {},
MarkTransferAsFailedFunc: func(sdk.Context, nexus.CrossChainTransfer) {},
}
bankK = &mock.BankKeeperMock{}
transferK = &mock.IBCTransferKeeperMock{}
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

0 comments on commit 0765f85

Please sign in to comment.