From 7355becf649741d50db33644c2b90254af5de2a0 Mon Sep 17 00:00:00 2001 From: shellvish <104537253+shellvish@users.noreply.github.com> Date: Tue, 10 Dec 2024 21:47:43 -0500 Subject: [PATCH] Increment Rebalance Period by 1 Day (#1308) This PR increments the rebalance period to (`unbonding_period + 1`), to avoid any race conditions with the timing of rebalance ICAs --- x/stakeibc/keeper/rebalance.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x/stakeibc/keeper/rebalance.go b/x/stakeibc/keeper/rebalance.go index cd23517f23..f03a1f1c46 100644 --- a/x/stakeibc/keeper/rebalance.go +++ b/x/stakeibc/keeper/rebalance.go @@ -38,7 +38,12 @@ func (k Keeper) RebalanceAllHostZones(ctx sdk.Context) { } for _, hostZone := range k.GetAllActiveHostZone(ctx) { - if dayEpoch.EpochNumber%hostZone.UnbondingPeriod != 0 { + // We add 1 to the UnbondingPeriod to avoid any race conditions + // In particular, you can only rebalance _away_ from a validator once per UnbondingPeriod + // Roughly half the time, a rebalance message will get sent a few seconds _before_ + // the last rebalance fully completed. By adding an extra day, we ensure that + // all rebalances are completed before initiating any new ones + if dayEpoch.EpochNumber%(hostZone.UnbondingPeriod+1) != 0 { k.Logger(ctx).Info(utils.LogWithHostZone(hostZone.ChainId, "Host does not rebalance this epoch (Unbonding Period: %d, Epoch: %d)", hostZone.UnbondingPeriod, dayEpoch.EpochNumber)) continue