Skip to content

Commit c8e4281

Browse files
committed
Fix ada_pots utxo field
Fixes #2039
1 parent 26bd059 commit c8e4281

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

cardano-db-sync/src/Cardano/DbSync/Api.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,15 @@ mkSyncEnv ::
305305
SyncOptions ->
306306
ProtocolInfo CardanoBlock ->
307307
Ledger.Network ->
308+
Word64 ->
308309
NetworkMagic ->
309310
SystemStart ->
310311
SyncNodeConfig ->
311312
SyncNodeParams ->
312313
RunMigration ->
313314
Bool ->
314315
IO SyncEnv
315-
mkSyncEnv metricSetters trce dbEnv syncOptions protoInfo nw nwMagic systemStart syncNodeConfigFromFile syncNP runNearTipMigrationFnc isJsonbInSchema = do
316+
mkSyncEnv metricSetters trce dbEnv syncOptions protoInfo nw maxLovelaceSupply nwMagic systemStart syncNodeConfigFromFile syncNP runNearTipMigrationFnc isJsonbInSchema = do
316317
dbCNamesVar <- newTVarIO =<< DB.runDbDirectSilent dbEnv DB.queryRewardAndEpochStakeConstraints
317318
cache <-
318319
if soptCache syncOptions
@@ -349,6 +350,7 @@ mkSyncEnv metricSetters trce dbEnv syncOptions protoInfo nw nwMagic systemStart
349350
protoInfo
350351
dir
351352
nw
353+
maxLovelaceSupply
352354
systemStart
353355
syncOptions
354356
(Nothing, False) -> NoLedger <$> mkNoLedgerEnv trce protoInfo nw systemStart
@@ -432,6 +434,7 @@ mkSyncEnvFromConfig metricsSetters trce dbEnv syncOptions genCfg syncNodeConfigF
432434
syncOptions
433435
(fst $ mkProtocolInfoCardano genCfg [])
434436
(Shelley.sgNetworkId $ scConfig sCfg)
437+
(Shelley.sgMaxLovelaceSupply $ scConfig sCfg)
435438
(NetworkMagic . unProtocolMagicId $ Byron.configProtocolMagicId bCfg)
436439
(SystemStart . Byron.gdStartTime $ Byron.configGenesisData bCfg)
437440
syncNodeConfigFromFile

cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
5151
import Cardano.Ledger.Alonzo.Scripts
5252
import Cardano.Ledger.BaseTypes (StrictMaybe)
5353
import qualified Cardano.Ledger.BaseTypes as Ledger
54+
import Cardano.Ledger.Coin
5455
import Cardano.Ledger.Conway.Core as Shelley
5556
import Cardano.Ledger.Conway.Governance
5657
import qualified Cardano.Ledger.Conway.Governance as Shelley
57-
import Cardano.Ledger.Shelley.AdaPots (AdaPots)
58+
import Cardano.Ledger.Shelley.AdaPots (AdaPots (..), sumAdaPots)
5859
import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
5960
import Cardano.Prelude hiding (atomically)
6061
import 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

cardano-db-sync/src/Cardano/DbSync/Ledger/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ data HasLedgerEnv = HasLedgerEnv
6868
, leProtocolInfo :: !(Consensus.ProtocolInfo CardanoBlock)
6969
, leDir :: !LedgerStateDir
7070
, leNetwork :: !Ledger.Network
71+
, leMaxSupply :: !Word64
7172
, leSystemStart :: !SystemStart
7273
, leAbortOnPanic :: !Bool
7374
, leSnapshotNearTipEpoch :: !Word64

0 commit comments

Comments
 (0)