From ffc46e9a4f7108faa108e06e6d6ae2f545f9f79e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joosep=20J=C3=A4=C3=A4ger?= Date: Mon, 27 Jan 2025 13:35:25 +0200 Subject: [PATCH] Made divisions that are supposed to fail on zero fail again --- eras/shelley/impl/src/Cardano/Ledger/Shelley/Rewards.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rewards.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rewards.hs index 508e0a59c1a..d675221bb96 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rewards.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rewards.hs @@ -66,6 +66,7 @@ import Lens.Micro ((^.)) import NoThunks.Class (NoThunks (..)) import Numeric.Natural (Natural) import Quiet +import Data.Ratio ((%)) -- | StakeShare type newtype StakeShare = StakeShare {unStakeShare :: Rational} @@ -289,7 +290,9 @@ rewardOnePoolMember pool = poolPs rewardInfo sigma = poolRelativeStake rewardInfo poolR = poolPot rewardInfo - stakeShare = StakeShare $ c %? unCoin totalStake + -- warning: totalStake could be zero! + stakeShare = + StakeShare $ c % unCoin totalStake r = memberRew poolR pool stakeShare sigma -- | Calculate single stake pool specific values for the reward computation. @@ -332,7 +335,8 @@ mkPoolRewardInfo -- intermediate values needed for the individual reward calculations. Just blocksN -> let Coin pledge = ppPledge pool - pledgeRelative = pledge %? unCoin totalStake + -- warning: totalStake could be zero! + pledgeRelative = pledge % unCoin totalStake sigmaA = pstakeTot %? unCoin activeStake Coin maxP = if pledge <= ostake