@@ -51,10 +51,11 @@ import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
5151import Cardano.Ledger.Alonzo.Scripts
5252import Cardano.Ledger.BaseTypes (StrictMaybe )
5353import qualified Cardano.Ledger.BaseTypes as Ledger
54+ import Cardano.Ledger.Coin
5455import Cardano.Ledger.Conway.Core as Shelley
5556import Cardano.Ledger.Conway.Governance
5657import qualified Cardano.Ledger.Conway.Governance as Shelley
57- import Cardano.Ledger.Shelley.AdaPots (AdaPots )
58+ import Cardano.Ledger.Shelley.AdaPots (AdaPots ( .. ), sumAdaPots )
5859import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
5960import Cardano.Prelude hiding (atomically )
6061import Cardano.Slotting.EpochInfo (EpochInfo , epochInfoEpoch )
@@ -158,10 +159,11 @@ mkHasLedgerEnv ::
158159 Consensus. ProtocolInfo CardanoBlock ->
159160 LedgerStateDir ->
160161 Ledger. Network ->
162+ Word64 ->
161163 SystemStart ->
162164 SyncOptions ->
163165 IO HasLedgerEnv
164- mkHasLedgerEnv trce protoInfo dir nw systemStart syncOptions = do
166+ mkHasLedgerEnv trce protoInfo dir nw maxLovelaceSupply systemStart syncOptions = do
165167 svar <- newTVarIO Strict. Nothing
166168 intervar <- newTVarIO Strict. Nothing
167169 swQueue <- newTBQueueIO 5 -- Should be relatively shallow.
@@ -173,6 +175,7 @@ mkHasLedgerEnv trce protoInfo dir nw systemStart syncOptions = do
173175 , leProtocolInfo = protoInfo
174176 , leDir = dir
175177 , leNetwork = nw
178+ , leMaxSupply = maxLovelaceSupply
176179 , leSystemStart = systemStart
177180 , leAbortOnPanic = soptAbortOnInvalid syncOptions
178181 , leSnapshotNearTipEpoch = sicNearTipEpoch $ soptSnapshotInterval syncOptions
@@ -286,13 +289,21 @@ applyBlock env blk = do
286289 Generic. NewEpoch
287290 { Generic. neEpoch = currEpoch
288291 , Generic. neIsEBB = isJust $ blockIsEBB blk
289- , Generic. neAdaPots = maybeToStrict mPots
292+ , Generic. neAdaPots = fixUTxOPots <$> maybeToStrict mPots
290293 , Generic. neEpochUpdate = Generic. epochUpdate newState
291294 , Generic. neDRepState = maybeToStrict $ getDrepState newState
292295 , Generic. neEnacted = maybeToStrict $ getGovState newState
293296 , Generic. nePoolDistr = maybeToStrict $ Generic. getPoolDistr newState
294297 }
295298
299+ fixUTxOPots :: AdaPots -> AdaPots
300+ fixUTxOPots adaPots =
301+ adaPots
302+ { utxoAdaPot =
303+ Coin $
304+ fromIntegral (leMaxSupply env) - unCoin (sumAdaPots adaPots)
305+ }
306+
296307 applyToEpochBlockNo :: Bool -> Bool -> EpochBlockNo -> EpochBlockNo
297308 applyToEpochBlockNo True _ _ = EBBEpochBlockNo
298309 applyToEpochBlockNo _ True _ = EpochBlockNo 0
0 commit comments