Skip to content

Commit

Permalink
feat: use ibc transfer timeouts instead of block height. (#757)
Browse files Browse the repository at this point in the history
* use ibc transfer timeouts instead of block height.

* add CHANGELOG.md

* add CHANGELOG.md

* use zeroheight function instead of hardcoded 0 values
  • Loading branch information
puneet2019 authored Feb 7, 2024
1 parent 21c3e38 commit 3f56ff5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 36 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
## Unreleased

### Features
- [755](https://github.com/persistenceOne/pstake-native/pull/755) Add channel-id, port to ratesync host-chains and liquidstake instantiate.

- [757](https://github.com/persistenceOne/pstake-native/pull/757) Change ibc transfer to use timeoutTimestamp instead of
timeoutHeight
- [755](https://github.com/persistenceOne/pstake-native/pull/755) Add channel-id, port to ratesync host-chains and
liquidstake instantiate.
- [737](https://github.com/persistenceOne/pstake-native/pull/737) Unhandled errors.
- [736](https://github.com/persistenceOne/pstake-native/pull/736) Check for host denom duplicates.
- [733](https://github.com/persistenceOne/pstake-native/pull/733) Add more validation for host-chain.
Expand Down
30 changes: 6 additions & 24 deletions x/liquidstakeibc/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,25 +523,15 @@ func (k *Keeper) DepositWorkflow(ctx sdk.Context, epoch int64) {
continue
}

clientState, err := k.GetClientState(ctx, hc.ConnectionId)
if err != nil {
// we can't error out here as all the deposits need to be executed
continue
}

timeoutHeight := clienttypes.NewHeight(
clientState.GetLatestHeight().GetRevisionNumber(),
clientState.GetLatestHeight().GetRevisionHeight()+liquidstakeibctypes.IBCTimeoutHeightIncrement,
)

timeoutTimestamp := uint64(ctx.BlockTime().UnixNano() + (liquidstakeibctypes.IBCTimeoutTimestamp).Nanoseconds())
msg := ibctransfertypes.NewMsgTransfer(
ibctransfertypes.PortID,
hc.ChannelId,
deposit.Amount,
authtypes.NewModuleAddress(liquidstakeibctypes.DepositModuleAccount).String(),
hc.DelegationAccount.Address,
timeoutHeight,
0,
clienttypes.ZeroHeight(),
timeoutTimestamp,
"",
)

Expand Down Expand Up @@ -868,16 +858,8 @@ func (k *Keeper) LSMWorkflow(ctx sdk.Context) {
// attempt to transfer all available LSM deposits
totalLSMDepositsSharesAmount := math.LegacyZeroDec()
for _, deposit := range k.GetTransferableLSMDeposits(ctx, hc.ChainId) {
clientState, err := k.GetClientState(ctx, hc.ConnectionId)
if err != nil {
// we can't error out here as all the deposits need to be executed
continue
}

timeoutHeight := clienttypes.NewHeight(
clientState.GetLatestHeight().GetRevisionNumber(),
clientState.GetLatestHeight().GetRevisionHeight()+liquidstakeibctypes.IBCTimeoutHeightIncrement,
)
timeoutTimestamp := uint64(ctx.BlockTime().UnixNano() + (liquidstakeibctypes.IBCTimeoutTimestamp).Nanoseconds())

// craft the IBC message
msg := ibctransfertypes.NewMsgTransfer(
Expand All @@ -886,8 +868,8 @@ func (k *Keeper) LSMWorkflow(ctx sdk.Context) {
sdk.NewCoin(deposit.IbcDenom, deposit.Shares.TruncateInt()),
authtypes.NewModuleAddress(liquidstakeibctypes.DepositModuleAccount).String(),
hc.DelegationAccount.Address,
timeoutHeight,
0,
clienttypes.ZeroHeight(),
timeoutTimestamp,
"",
)

Expand Down
2 changes: 1 addition & 1 deletion x/liquidstakeibc/keeper/ica.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (k *Keeper) GenerateAndExecuteICATx(
Owner: ownerID,
ConnectionId: connectionID,
PacketData: icaPacketData,
RelativeTimeout: uint64(liquidstakeibctypes.ICATimeoutTimestamp.Nanoseconds()),
RelativeTimeout: uint64(liquidstakeibctypes.IBCTimeoutTimestamp.Nanoseconds()),
}

handler := k.msgRouter.Handler(msgSendTx)
Expand Down
9 changes: 3 additions & 6 deletions x/liquidstakeibc/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,7 @@ func (k *Keeper) SendICATransfer(
)
}

timeoutHeight := clienttypes.NewHeight(
clienttypes.GetSelfHeight(ctx).GetRevisionNumber(),
clienttypes.GetSelfHeight(ctx).GetRevisionHeight()+types.IBCTimeoutHeightIncrement,
)
timeoutTimestamp := uint64(ctx.BlockTime().UnixNano() + (types.IBCTimeoutTimestamp).Nanoseconds())

// prepare the msg transfer to bring the undelegation back
msgTransfer := ibctransfertypes.NewMsgTransfer(
Expand All @@ -231,8 +228,8 @@ func (k *Keeper) SendICATransfer(
amount,
sender,
receiver,
timeoutHeight,
0,
clienttypes.ZeroHeight(),
timeoutTimestamp,
"",
)

Expand Down
2 changes: 1 addition & 1 deletion x/liquidstakeibc/keeper/setup_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (suite *IntegrationTestSuite) TestOneFullFlow() {
suite.Require().True(found)
suite.Require().Equal(types.Deposit_DEPOSIT_DELEGATING, deposit.State)

timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().UnixNano()) + uint64(types.ICATimeoutTimestamp.Nanoseconds()) - uint64(time.Second*5) // sub one b
timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().UnixNano()) + uint64(types.IBCTimeoutTimestamp.Nanoseconds()) - uint64(time.Second*5) // sub one b
data, err := suite.CreateICAData(deposit.Amount.Amount, hc, 0)
suite.NoError(err)

Expand Down
4 changes: 1 addition & 3 deletions x/liquidstakeibc/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ const (

LiquidStakeDenomPrefix = "stk"

IBCTimeoutHeightIncrement uint64 = 1000

ICATimeoutTimestamp = 120 * time.Minute
IBCTimeoutTimestamp = 120 * time.Minute

ICAMessagesChunkSize = 10

Expand Down

0 comments on commit 3f56ff5

Please sign in to comment.