-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(axelarnet)!: retry failed transfer (#2203)
Co-authored-by: Milap Sheth <[email protected]>
- Loading branch information
1 parent
05f1d5e
commit 8fa58f2
Showing
8 changed files
with
210 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,75 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/axelarnetwork/axelar-core/x/axelarnet/types" | ||
nexus "github.com/axelarnetwork/axelar-core/x/nexus/types" | ||
) | ||
|
||
// Migrate5to6 returns the handler that performs in-place store migrations from version 5 to 6 | ||
func Migrate5to6(k Keeper) func(ctx sdk.Context) error { | ||
// Migrate6to7 returns the handler that performs in-place store migrations from version 6 to 7 | ||
func Migrate6to7(k Keeper, bankK types.BankKeeper, accountK types.AccountKeeper, nexusK types.Nexus, ibcK IBCKeeper) func(ctx sdk.Context) error { | ||
return func(ctx sdk.Context) error { | ||
addModuleParamCallContractsProposalMinDeposits(ctx, k) | ||
// Failed IBC transfers are held in Axelarnet module account for later retry. | ||
// This migration escrows tokens back to escrow accounts so that we can use the same code path for retry. | ||
err := escrowFundsFromFailedTransfers(ctx, k, bankK, accountK, nexusK, ibcK) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// All IBC transfer are routed from AxelarIBCAccount after v1.1 | ||
// This migration updates the sender of failed transfers to AxelarIBCAccount for retry | ||
err = migrateFailedTransfersToAxelarIBCAccount(ctx, k) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func addModuleParamCallContractsProposalMinDeposits(ctx sdk.Context, k Keeper) { | ||
k.params.Set(ctx, types.KeyCallContractsProposalMinDeposits, types.DefaultParams().CallContractsProposalMinDeposits) | ||
func escrowFundsFromFailedTransfers(ctx sdk.Context, k Keeper, bankK types.BankKeeper, accountK types.AccountKeeper, nexusK types.Nexus, ibcK IBCKeeper) error { | ||
axelarnetModuleAccount := accountK.GetModuleAddress(types.ModuleName) | ||
nexusModuleAccount := accountK.GetModuleAddress(nexus.ModuleName) | ||
|
||
balances := bankK.SpendableCoins(ctx, axelarnetModuleAccount) | ||
for _, coin := range balances { | ||
asset, err := nexusK.NewLockableAsset(ctx, ibcK, bankK, coin) | ||
if err != nil { | ||
k.Logger(ctx).Info(fmt.Sprintf("coin %s is not a lockable asset", coin), "error", err) | ||
continue | ||
} | ||
|
||
// Transfer coins from the Axelarnet module account to the Nexus module account for subsequent locking, | ||
// as the Axelarnet module account is now restricted from sending coins. | ||
err = bankK.SendCoinsFromModuleToModule(ctx, axelarnetModuleAccount.String(), nexusModuleAccount.String(), sdk.NewCoins(asset.GetAsset())) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = asset.LockFrom(ctx, nexusModuleAccount) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func migrateFailedTransfersToAxelarIBCAccount(ctx sdk.Context, k Keeper) error { | ||
transfers := k.getIBCTransfers(ctx) | ||
for _, transfer := range transfers { | ||
if transfer.Status != types.TransferFailed { | ||
continue | ||
} | ||
|
||
transfer.Sender = types.AxelarIBCAccount | ||
if err := k.setTransfer(ctx, transfer); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.