node icon indicating copy to clipboard operation
node copied to clipboard

`zetachain`: remove legacy func stability pool function

Open kingpinXD opened this issue 9 months ago • 0 comments

We can remove the legacy fund stability pool function once the update version has been deployed

// FundGasStabilityPoolFromRemainingFees funds the gas stability pool with the remaining fees of an outbound tx
func (k Keeper) FundGasStabilityPoolFromRemainingFees(
	ctx sdk.Context,
	OutboundParams types.OutboundParams,
	chainID int64,
) error {
	gasUsed := OutboundParams.GasUsed
	gasLimit := OutboundParams.EffectiveGasLimit
	gasPrice := math.NewUintFromBigInt(OutboundParams.EffectiveGasPrice.BigInt())

	if gasLimit == gasUsed {
		return nil
	}

	// We skip gas stability pool funding if one of the params is zero
	if gasLimit > 0 && gasUsed > 0 && !gasPrice.IsZero() {
		if gasLimit > gasUsed {
			remainingGas := gasLimit - gasUsed
			remainingFees := math.NewUint(remainingGas).Mul(gasPrice)

			// We fund the stability pool with a portion of the remaining fees.
			remainingFees = PercentOf(remainingFees, RemainingFeesToStabilityPoolPercent)

			// Fund the gas stability pool.
			if err := k.fungibleKeeper.FundGasStabilityPool(ctx, chainID, remainingFees.BigInt()); err != nil {
				return err
			}
		} else {
			return fmt.Errorf("%s: The gas limit %d is less than the gas used %d", voteOutboundID, gasLimit, gasUsed)
		}
	}

	return nil
}

// PercentOf returns the percentage of a number
func PercentOf(n math.Uint, percent uint64) math.Uint {
	// Convert percent to math.Uint
	percentUint := math.NewUint(percent)

	// Calculate n * percent
	result := n.Mul(percentUint)

	// Divide by 100
	hundred := math.NewUint(100)
	result = result.Quo(hundred)

	return result
}

// SaveOutbound saves the outbound transaction.It does the following things in one function:
// 1. Set the ballot index for the outbound vote to the cctx
// 2. Remove the nonce from the pending nonces
// 3. Remove the outbound tx tracker
// 4. Set the cctx and nonce to cctx and inboundHash to cctx
func (k Keeper) SaveOutbound(ctx sdk.Context, cctx *types.CrossChainTx, tssPubkey string) {
	// #nosec G115 always in range
	for _, outboundParams := range cctx.OutboundParams {
		k.GetObserverKeeper().
			RemoveFromPendingNonces(ctx, outboundParams.TssPubkey, outboundParams.ReceiverChainId, int64(outboundParams.TssNonce))
		k.RemoveOutboundTrackerFromStore(ctx, outboundParams.ReceiverChainId, outboundParams.TssNonce)
	}
	// This should set nonce to cctx only if a new revert is created.
	k.SaveCCTXUpdate(ctx, *cctx, tssPubkey)
}

We would need to keep it for now so that we are able to process CCTXs created before the upgrade

kingpinXD avatar Mar 26 '25 21:03 kingpinXD