Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit 669100d

Browse files
authored
develop to main (#355)
* Puneet/fixes (#354) * use ibc transfer hook to remove transient state. * use ibc transfer hook to remove transient state. * fix spelling * Puneet/fixes (#356) * fix spelling * add validation to genesis state. * fix tests. * increase ibc transfer revision height and undelegation buffers. * remove unwanted todo
1 parent c484430 commit 669100d

File tree

7 files changed

+52
-14
lines changed

7 files changed

+52
-14
lines changed

x/lscosmos/keeper/handshake.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ func (k Keeper) handleResetMsgs(ctx sdk.Context, msg sdk.Msg, hostChainParams ty
495495
hostAccounts := k.GetHostAccounts(ctx)
496496
err := k.GenerateAndExecuteICATx(ctx, hostChainParams.ConnectionID, hostAccounts.DelegatorAccountPortID(), []sdk.Msg{parsedMsg})
497497
if err != nil {
498-
//TODO disable module?
499498
return err
500499
}
501500

x/lscosmos/keeper/hooks.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,37 @@ func (k Keeper) OnAcknowledgementIBCTransferPacket(ctx sdk.Context, packet chann
325325
}
326326

327327
func (k Keeper) OnTimeoutIBCTransferPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress, transferTimeoutErr error) error {
328-
// Do nothing because amount will be reverted to delegationModuleAccount.
328+
// transient store needs to be reverted here.
329+
if transferTimeoutErr != nil {
330+
return transferTimeoutErr
331+
}
332+
var data ibctransfertypes.FungibleTokenPacketData
333+
if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
334+
return err
335+
}
336+
// check for tokens moved from delegationModuleAccount to it's ica counterpart.
337+
hostChainParams := k.GetHostChainParams(ctx)
338+
delegationState := k.GetDelegationState(ctx)
339+
if packet.GetSourceChannel() != hostChainParams.TransferChannel ||
340+
packet.GetSourcePort() != hostChainParams.TransferPort {
341+
// no need to return err, since most likely code is expected to enter this condition
342+
return nil
343+
}
344+
345+
if data.GetSender() != authtypes.NewModuleAddress(lscosmostypes.DelegationModuleAccount).String() ||
346+
data.GetReceiver() != delegationState.HostChainDelegationAddress ||
347+
data.GetDenom() != ibctransfertypes.GetPrefixedDenom(hostChainParams.TransferPort, hostChainParams.TransferChannel, hostChainParams.BaseDenom) {
348+
// no need to return err, since most likely code is expected to enter this condition
349+
return nil
350+
}
351+
k.Logger(ctx).Info(fmt.Sprintf("atoms tokens timedout while transferring to host chain address %s, amount: %s, denom: %s", data.Receiver, data.Amount, data.Denom))
352+
353+
amount, ok := sdk.NewIntFromString(data.GetAmount())
354+
if !ok {
355+
return ibctransfertypes.ErrInvalidAmount
356+
}
357+
ibcDenom := ibctransfertypes.ParseDenomTrace(data.GetDenom())
358+
k.RemoveIBCTransferFromTransientStore(ctx, sdk.NewCoin(ibcDenom.IBCDenom(), amount))
329359
return nil
330360
}
331361

x/lscosmos/keeper/msg_server.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (m msgServer) LiquidStake(goCtx context.Context, msg *types.MsgLiquidStake)
127127
types.EventTypeLiquidStake,
128128
sdktypes.NewAttribute(types.AttributeDelegatorAddress, delegatorAddress.String()),
129129
sdktypes.NewAttribute(types.AttributeAmount, mintToken.String()),
130-
sdktypes.NewAttribute(types.AttributeAmountRecieved, mintToken.Sub(protocolCoin).String()),
130+
sdktypes.NewAttribute(types.AttributeAmountReceived, mintToken.Sub(protocolCoin).String()),
131131
sdktypes.NewAttribute(types.AttributePstakeDepositFee, protocolCoin.String()),
132132
),
133133
sdktypes.NewEvent(
@@ -193,7 +193,7 @@ func (m msgServer) Juice(goCtx context.Context, msg *types.MsgJuice) (*types.Msg
193193
sdktypes.NewEvent(
194194
types.EventTypeRewardBoost,
195195
sdktypes.NewAttribute(types.AttributeRewarderAddress, rewarderAddress.String()),
196-
sdktypes.NewAttribute(types.AttributeAmountRecieved, rewardsBoostAmount.String()),
196+
sdktypes.NewAttribute(types.AttributeAmountReceived, rewardsBoostAmount.String()),
197197
),
198198
sdktypes.NewEvent(
199199
sdktypes.EventTypeMessage,
@@ -256,16 +256,16 @@ func (m msgServer) LiquidUnstake(goCtx context.Context, msg *types.MsgLiquidUnst
256256
return nil, err
257257
}
258258
totalDelegations := delegationState.TotalDelegations(hostChainParams.BaseDenom)
259-
baseDenomUndelegtions, _ := m.ConvertStkToToken(ctx, sdktypes.NewDecCoinFromCoin(undelegations.TotalUndelegationAmount), m.GetCValue(ctx))
260-
if totalDelegations.IsLT(sdktypes.NewCoin(hostChainParams.BaseDenom, baseDenomUndelegtions.Amount)) {
259+
baseDenomUndelegations, _ := m.ConvertStkToToken(ctx, sdktypes.NewDecCoinFromCoin(undelegations.TotalUndelegationAmount), m.GetCValue(ctx))
260+
if totalDelegations.IsLT(sdktypes.NewCoin(hostChainParams.BaseDenom, baseDenomUndelegations.Amount)) {
261261
return nil, sdkerrors.Wrapf(types.ErrHostChainDelegationsLTUndelegations, "Delegated amount: %s is less than total undelegations for the epoch: %s", totalDelegations, undelegations.TotalUndelegationAmount)
262262
}
263263

264264
ctx.EventManager().EmitEvents(sdktypes.Events{
265265
sdktypes.NewEvent(
266266
types.EventTypeLiquidUnstake,
267267
sdktypes.NewAttribute(types.AttributeDelegatorAddress, msg.GetDelegatorAddress()),
268-
sdktypes.NewAttribute(types.AttributeAmountRecieved, msg.Amount.String()),
268+
sdktypes.NewAttribute(types.AttributeAmountReceived, msg.Amount.String()),
269269
sdktypes.NewAttribute(types.AttributePstakeUnstakeFee, pstakeFee.String()),
270270
sdktypes.NewAttribute(types.AttributeUnstakeAmount, unstakeCoin.String()),
271271
),
@@ -365,7 +365,7 @@ func (m msgServer) Redeem(goCtx context.Context, msg *types.MsgRedeem) (*types.M
365365
types.EventTypeRedeem,
366366
sdktypes.NewAttribute(types.AttributeDelegatorAddress, redeemAddress.String()),
367367
sdktypes.NewAttribute(types.AttributeAmount, msg.Amount.String()),
368-
sdktypes.NewAttribute(types.AttributeAmountRecieved, redeemToken.String()),
368+
sdktypes.NewAttribute(types.AttributeAmountReceived, redeemToken.String()),
369369
sdktypes.NewAttribute(types.AttributePstakeRedeemFee, protocolCoin.String()),
370370
),
371371
sdktypes.NewEvent(

x/lscosmos/types/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const (
1616
AttributeKeyAck = "acknowledgement"
1717
AttributeKeyAckError = "error"
1818
AttributeAmount = "amount"
19-
AttributeAmountRecieved = "received"
19+
AttributeAmountReceived = "received"
2020
AttributeUnstakeAmount = "undelegation-amount"
2121
AttributePstakeDepositFee = "pstake-deposit-fee"
2222
AttributePstakeRedeemFee = "pstake-redeem-fee"

x/lscosmos/types/genesis.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ func DefaultGenesis() *GenesisState {
2626
func (gs GenesisState) Validate() error {
2727

2828
// this line is used by starport scaffolding # genesis/types/validate
29-
29+
if !gs.AllowListedValidators.Equal(AllowListedValidators{}) {
30+
ok := gs.AllowListedValidators.Valid()
31+
if !ok {
32+
return ErrInValidAllowListedValidators
33+
}
34+
}
35+
err := gs.HostAccounts.Validate()
36+
if err != nil {
37+
return err
38+
}
3039
return gs.Params.Validate()
3140
}

x/lscosmos/types/genesis_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ func TestGenesisState_Validate(t *testing.T) {
2020
valid: true,
2121
},
2222
{
23-
desc: "valid genesis state",
23+
desc: "invalid genesis state, host accounts not set",
2424
genState: &types.GenesisState{
2525
// this line is used by starport scaffolding # types/genesis/validField
2626
},
27-
valid: true,
27+
valid: false,
2828
},
2929
// this line is used by starport scaffolding # types/genesis/testcase
3030
} {

x/lscosmos/types/keys.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ const (
6262
RewardEpochIdentifier = "day"
6363
UndelegationEpochIdentifier = "day"
6464
UndelegationEpochNumberFactor int64 = 4
65-
UndelegationCompletionTimeBuffer = time.Second * 10 //TODO change
65+
UndelegationCompletionTimeBuffer = time.Second * 60 //Does tendermint still have time drifts?
6666

67-
IBCTimeoutHeightIncrement uint64 = 100
67+
IBCTimeoutHeightIncrement uint64 = 1000
6868
ICATimeoutTimestamp = time.Minute
6969

7070
CosmosValOperPrefix = "cosmosvaloper"

0 commit comments

Comments
 (0)