poolDeficit wrongly sent to Bond Module instead of Reserve Module
In x/thorchain/manager_network_current.go ,
the full bondReward (bonderSplit in calcBlockRewards)
is rightly sent to the Bond Module (and incremented in BondRewardRune),
being the full Bond entitlement of systemIncome for the block.
When the Pool Module's portion of systemIncome is more than its liquidity fees
(such as when there are no fees and all income is from block reward emission),
the Reserve Module sends the Pool Module the rest of its entitled amount.
However, when the Pool Module's liquidity fees are more than its portion of systemIncome
(such as when there's been a huge swap in one block),
the Pool Module keeps its own portion (rightly) yet sends the extra to the
Bond Module (which has already received its full entitled portion from the Reserve)
rather than to the Reserve Module.
A specific historical example:
https://thornode-v0.ninerealms.com/txs?limit=100&tx.height=4713124https://thornode-v0.ninerealms.com/txs?limit=100&tx.height=4713361
https://midgard.thorchain.info/v2/debug/block/4713124
https://midgard.thorchain.info/v2/debug/block/4713361
Block rewards (emission only) of 2.69359868 and 2.69356495 RUNE.
|
https://midgard.thorchain.info/v2/debug/block/4713269
Pool Module (.67c0) sends 8.10380358 RUNE outbound fee (for an unrelated refund) and 0.02 RUNE network fee to Reserve Module (.xtxt).
Reserve Module (.xtxt) sends 750.26543696 RUNE to **Bond** Module (.ncsv).
Pool Module (.67c0) sends 747.56721065 RUNE to **Bond** Module (.ncsv).
My suggested code changes (three term replacements, one line deletion):
Here change the one instance of 'BondName' to 'ReserveName', and the two instances of 'bond' to 'reserve':
coin := common.NewCoin(common.RuneNative, poolDeficit)
if !poolDeficit.IsZero() {
if err := vm.k.SendFromModuleToModule(ctx, AsgardName, BondName, common.NewCoins(coin)); err != nil {
ctx.Logger().Error("fail to transfer funds from asgard to bond", "error", err)
return fmt.Errorf("fail to transfer funds from asgard to bond: %w", err)
}
}
Delete this line:
network.BondRewardRune = network.BondRewardRune.Add(poolDeficit)