Skip to content

Commit

Permalink
perf: avoid tiny delegations and redelegations (#1001)
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Gadikian <[email protected]>
  • Loading branch information
Joe Bowman and faddat authored Jan 5, 2024
1 parent cb8c2c7 commit 14015c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 5 additions & 1 deletion x/interchainstaking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ func (*Keeper) PrepareDelegationMessagesForCoins(zone *types.Zone, allocations m
var msgs []sdk.Msg
for _, valoper := range utils.Keys(allocations) {
if allocations[valoper].IsPositive() {
msgs = append(msgs, &stakingtypes.MsgDelegate{DelegatorAddress: zone.DelegationAddress.Address, ValidatorAddress: valoper, Amount: sdk.NewCoin(zone.BaseDenom, allocations[valoper])})
if allocations[valoper].GTE(sdk.NewInt(1_000_000)) {
// don't delegate tiny amounts. TODO: make configurable per zone.
msgs = append(msgs, &stakingtypes.MsgDelegate{DelegatorAddress: zone.DelegationAddress.Address, ValidatorAddress: valoper, Amount: sdk.NewCoin(zone.BaseDenom, allocations[valoper])})
}
}
}
return msgs
Expand All @@ -205,6 +208,7 @@ func (*Keeper) PrepareDelegationMessagesForShares(zone *types.Zone, coins sdk.Co
var msgs []sdk.Msg
for _, coin := range coins.Sort() {
if coin.IsPositive() {
// no min amount here.
msgs = append(msgs, &lsmstakingtypes.MsgRedeemTokensForShares{DelegatorAddress: zone.DelegationAddress.Address, Amount: coin})
}
}
Expand Down
19 changes: 11 additions & 8 deletions x/interchainstaking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,17 @@ func (k *Keeper) Rebalance(ctx sdk.Context, zone *types.Zone, epochNumber int64)
rebalances := types.DetermineAllocationsForRebalancing(currentAllocations, currentLocked, currentSum, lockedSum, targetAllocations, maxCanAllocate, k.Logger(ctx)).RemoveDuplicates()
msgs := make([]sdk.Msg, 0)
for _, rebalance := range rebalances {
msgs = append(msgs, &stakingtypes.MsgBeginRedelegate{DelegatorAddress: zone.DelegationAddress.Address, ValidatorSrcAddress: rebalance.Source, ValidatorDstAddress: rebalance.Target, Amount: sdk.NewCoin(zone.BaseDenom, rebalance.Amount)})
k.SetRedelegationRecord(ctx, types.RedelegationRecord{
ChainId: zone.ChainId,
EpochNumber: epochNumber,
Source: rebalance.Source,
Destination: rebalance.Target,
Amount: rebalance.Amount.Int64(),
})
if rebalance.Amount.GTE(sdk.NewInt(1_000_000)) {
// don't redelegate dust; TODO: config per zone
msgs = append(msgs, &stakingtypes.MsgBeginRedelegate{DelegatorAddress: zone.DelegationAddress.Address, ValidatorSrcAddress: rebalance.Source, ValidatorDstAddress: rebalance.Target, Amount: sdk.NewCoin(zone.BaseDenom, rebalance.Amount)})
k.SetRedelegationRecord(ctx, types.RedelegationRecord{
ChainId: zone.ChainId,
EpochNumber: epochNumber,
Source: rebalance.Source,
Destination: rebalance.Target,
Amount: rebalance.Amount.Int64(),
})
}
}
if len(msgs) == 0 {
k.Logger(ctx).Debug("No rebalancing required")
Expand Down

0 comments on commit 14015c9

Please sign in to comment.