-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PENDING status to IBC / ICA function calls (#296)
## Context and purpose of the change Currently, our ICA / IBC logic assumes efficient relayers. In practice, this has not been the case, and packets sometimes fail to relay. To improve the stability of our ICA / IBC logic and make it easier to reason about the current state, this PR adds a PENDING flag to all ICA / IBC function calls. Specifically, the PENDING status is tracked on various records. The following functions are async and need to be accounted for in a PENDING state: **Staking direction** (represented on `DepositRecord`s) - IBC transfer from Stride --> Host Zone - ICA bank send from withdrawal account -> delegation account (NOTE: we don't need a PENDING state here, since the record is created in the callback upon a successful MsgSend) - ICA delegation call **Unstaking direction** (represented on `EpochUnbondingRecords`s) - ICA unstaking call - ICA bank send from the delegation ICA to the redemption ICA Claims already have a pending state (to prevent double claims). The logic is as follows: after the ICA / IBC message is triggered, the state of the record is set to `PENDING`. Then, in the callback, the state either (1) progresses based on the action taken, if the ICA / IBC call was a success, or (2) reverts to the previous state, if the call failed. Took the opportunity here to rename some of the flags to make them more clear. Also note, the updates to PENDING status should happen as close to the ICA call site as possible. Please check this as you review! ## Brief Changelog Hooks changes - Add `PENDING` flag to `DepositRecord` `TRANSFER` -> `TRANSFER_QUEUE` `STAKE` -> `DELEGATION_QUEUE` ``` enum Status { // in transfer queue to be sent to the delegation ICA TRANSFER_QUEUE = 0; // transfer in progress (IBC packet sent, ack not received) TRANSFER_IN_PROGRESS = 2; // in staking queue on delegation ICA DELEGATION_QUEUE = 1; // staking in progress (ICA packet sent, ack not received) DELEGATION_IN_PROGRESS = 3; } ``` - Add `PENDING` flag to `EpochUnbondingRecord` `BONDED` -> `UNBONDING_QUEUE` `UNBONDED` -> `EXIT_TRANSFER_QUEUE` `TRANSFERRED` -> `CLAIMABLE` ``` enum Status { // tokens bonded on delegate account UNBONDING_QUEUE = 0; UNBONDING_IN_PROGRESS = 3; // unbonding completed on delegate account EXIT_TRANSFER_QUEUE = 1; EXIT_TRANSFER_IN_PROGRESS = 4; // transfer success CLAIMABLE = 2; } ``` - In `TransferExistingDepositsToHostZones`, after IBC transferring tokens to the host zone - In `StakeExistingDepositsOnHostZones`, set the deposit record to status `PENDING` after sending a delegation ICA - Set `HostZoneUnbonding`s to `PENDING` after transferring tokens to the redemption account in `SweepAllUnbondedTokens` - Set `HostZoneUnbonding`s to `PENDING` after sending unstaking ICAs Callback changes - Update `DepositRecord` status in `DelegateCallback` - Update `DepositRecord` status in `TransferCallback` - Update `HostZoneUnbonding` in `UndelegateCallback` - Update `HostZoneUnbonding` in `RedemptionCallback` ## Tests Force (1) timeout and (2) transaction failure for - IBC transfer 1. DepostRecord has status TRANSFER_QUEUE 2. DepostRecord has status TRANSFER_IN_PROGRESS 3. DepostRecord has status TRANSFER_QUEUE timeout: set IBC transfer timeout very low ``` // set timeout to 1s // observe record change from TRANSFER_QUEUE -> TRANSFER_IN_PROGRESS -> TRANSFER_QUEUE ``` failure: transfer to an invalid account ``` // set delegateAddress to osmo1j6vwz24hddx4t6kukmzgmk0764x0evs74002e3 // observe record change from TRANSFER_QUEUE -> TRANSFER_IN_PROGRESS -> TRANSFER_QUEUE ``` - ICA MsgDelegate 1. DepostRecord has status DELEGATION_QUEUE 2. DepostRecord has status DELEGATION_IN_PROGRESS 3. DepostRecord has status DELEGATION_QUEUE timeout: set ICA timeout very low ``` if callbackId == "delegate" { timeoutTimestamp = uint64(ctx.BlockTime().UnixNano()) + uint64(1000000000) } // observe the following state transition DELEGATION_QUEUE -> DELEGATION_IN_PROGRESS -> DELEGATION_QUEUE ``` failure: stake to non-existent validator ``` // stake to stridevaloper1dqpg0hfva0k0awzhxwarjpgzj82hlmvrnxlzsd // observe the following state transition DELEGATION_QUEUE -> DELEGATION_IN_PROGRESS -> DELEGATION_QUEUE ``` - ICA MsgUndelegate 1. HZU has status UNBONDING_QUEUE 2. HZU has status UNBONDING_IN_PROGRESS 3. HZU has status UNBONDING_QUEUE timeout: set ICA timeout very low ``` if callbackId == "undelegate" { timeoutTimestamp = uint64(ctx.BlockTime().UnixNano()) + uint64(1000000000) } // observe the following state transition ``` failure: unstake from non-existent validator ``` // unstake from stridevaloper1dqpg0hfva0k0awzhxwarjpgzj82hlmvrnxlzsd // observe the following state transition UNBONDING_QUEUE -> UNBONDING_IN_PROGRESS -> UNBONDING_QUEUE ``` - ICA MsgSend 1. HZU has status EXIT_TRANSFER_QUEUE 2. HZU has status EXIT_TRANSFER_IN_PROGRESS 3. HZU has status EXIT_TRANSFER_QUEUE timeout: set ICA timeout very low ``` // set timeout to 1s // observe the following state transition EXIT_TRANSFER_QUEUE -> EXIT_TRANSFER_IN_PROGRESS -> EXIT_TRANSFER_QUEUE ``` failure: send to invalid address ``` // MsgSend to the wrong address // observe the following state transition EXIT_TRANSFER_QUEUE -> EXIT_TRANSFER_IN_PROGRESS -> EXIT_TRANSFER_QUEUE ``` ## Author's Checklist I have... - [ ] Run and PASSED locally all GAIA integration tests - [ ] If the change is contentful, I either: - [ ] Added a new unit test OR - [ ] Added test cases to existing unit tests - [ ] OR this change is a trivial rework / code cleanup without any test coverage If skipped any of the tests above, explain. ## Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] manually tested (if applicable) - [ ] confirmed the author wrote unit tests for new logic - [ ] reviewed documentation exists and is accurate ## Documentation and Release Note - [ ] Does this pull request introduce a new feature or user-facing behavior changes? - [ ] Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? - [ ] This pull request updates existing proto field values (and require a backend and frontend migration)? - [ ] Does this pull request change existing proto field names (and require a frontend migration)? How is the feature or change documented? - [ ] not applicable - [ ] jira ticket `XXX` - [ ] specification (`x/<module>/spec/`) - [ ] README.md - [ ] not documented
- Loading branch information
Showing
39 changed files
with
488 additions
and
335 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
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
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
Oops, something went wrong.