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 1 commit
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
41 changes: 23 additions & 18 deletions x/axelarnet/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,32 @@
}

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)
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 265 in x/axelarnet/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L263 - L265 were not covered by tests

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
Expand Down
5 changes: 3 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 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.
Expand Down
Loading