Skip to content

Commit b46b43b

Browse files
committed
Use the updated GovInfoEvent
1 parent 8e417e3 commit b46b43b

File tree

4 files changed

+22
-37
lines changed

4 files changed

+22
-37
lines changed

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Governance.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ drepDistr =
7171

7272
newCommittee :: IOManager -> [(Text, Text)] -> Assertion
7373
newCommittee =
74-
withFullConfig conwayConfigDir testLabel $ \interpreter server dbSync -> do
74+
withFullConfigAndLogs conwayConfigDir testLabel $ \interpreter server dbSync -> do
7575
startDBSync dbSync
7676

7777
-- Add stake
@@ -118,7 +118,7 @@ newCommittee =
118118
assertEqQuery
119119
dbSync
120120
Query.queryGovActionCounts
121-
(1, 1, 1, 0)
121+
(1, 1, 0, 0)
122122
"Unexpected committee hashes"
123123
where
124124
testLabel = "conwayNewCommittee"
@@ -187,7 +187,7 @@ updateConstitution =
187187

188188
treasuryWithdrawal :: IOManager -> [(Text, Text)] -> Assertion
189189
treasuryWithdrawal =
190-
withFullConfig conwayConfigDir testLabel $ \interpreter server dbSync -> do
190+
withFullConfigAndLogs conwayConfigDir testLabel $ \interpreter server dbSync -> do
191191
startDBSync dbSync
192192

193193
-- Add stake

cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/GovAction.hs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,8 @@ insertUpdateEnacted ::
429429
ConwayGovState StandardConway ->
430430
ExceptT SyncNodeError (ReaderT SqlBackend m) ()
431431
insertUpdateEnacted trce cache blkId epochNo enactedState = do
432-
whenJust (strictMaybeToMaybe (grPParamUpdate govIds)) $ \prevId -> do
433-
gaId <- resolveGovActionProposal cache $ unGovPurposeId prevId
434-
void $ lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)
435-
436-
whenJust (strictMaybeToMaybe (grHardFork govIds)) $ \prevId -> do
437-
gaId <- resolveGovActionProposal cache $ unGovPurposeId prevId
438-
void $ lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)
439-
440432
(mcommitteeId, mnoConfidenceGaId) <- handleCommittee
441-
442433
constitutionId <- handleConstitution
443-
444434
void $
445435
lift $
446436
DB.insertEpochState
@@ -456,10 +446,8 @@ insertUpdateEnacted trce cache blkId epochNo enactedState = do
456446
handleCommittee = do
457447
mCommitteeGaId <- case strictMaybeToMaybe (grCommittee govIds) of
458448
Nothing -> pure Nothing
459-
Just prevId -> do
460-
gaId <- resolveGovActionProposal cache $ unGovPurposeId prevId
461-
_nCommittee <- lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)
462-
pure $ Just gaId
449+
Just prevId ->
450+
fmap Just <$> resolveGovActionProposal cache $ unGovPurposeId prevId
463451

464452
case (mCommitteeGaId, strictMaybeToMaybe (cgsCommittee enactedState)) of
465453
(Nothing, Nothing) -> pure (Nothing, Nothing)
@@ -496,10 +484,8 @@ insertUpdateEnacted trce cache blkId epochNo enactedState = do
496484
handleConstitution = do
497485
mConstitutionGaId <- case strictMaybeToMaybe (grConstitution govIds) of
498486
Nothing -> pure Nothing
499-
Just prevId -> do
500-
gaId <- resolveGovActionProposal cache $ unGovPurposeId prevId
501-
_nConstitution <- lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)
502-
pure $ Just gaId
487+
Just prevId ->
488+
fmap Just <$> resolveGovActionProposal cache $ unGovPurposeId prevId
503489

504490
constitutionIds <- lift $ DB.queryProposalConstitution mConstitutionGaId
505491
case constitutionIds of

cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/LedgerEvent.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ insertNewEpochLedgerEvents syncEnv currentEpochNo@(EpochNo curEpoch) =
9494
lift $ validateEpochRewards tracer ntw (subFromCurrentEpoch 2) currentEpochNo rwd
9595
LedgerAdaPots _ ->
9696
pure () -- These are handled separately by insertBlock
97-
LedgerGovInfo en ex uncl -> do
97+
LedgerGovInfo enacted dropped expired uncl -> do
9898
unless (Set.null uncl) $
9999
liftIO $
100100
logInfo tracer $
101101
"Found " <> textShow (Set.size uncl) <> " unclaimed proposal refunds"
102-
updateDropped cache (EpochNo curEpoch) (garGovActionId <$> (en <> ex))
103-
let en' = filter (\e -> Set.notMember (garGovActionId e) uncl) en
104-
ex' = filter (\e -> Set.notMember (garGovActionId e) uncl) ex
105-
insertProposalRefunds tracer ntw (subFromCurrentEpoch 1) currentEpochNo cache (en' <> ex') -- TODO: check if they are disjoint to avoid double entries.
106-
forM_ en $ \gar -> whenJust (garMTreasury gar) $ \treasuryMap -> do
102+
updateDropped cache (EpochNo curEpoch) (garGovActionId <$> (dropped <> expired))
103+
let refunded = filter (\e -> Set.notMember (garGovActionId e) uncl) (enacted <> dropped <> expired)
104+
insertProposalRefunds tracer ntw (subFromCurrentEpoch 1) currentEpochNo cache refunded -- TODO: check if they are disjoint to avoid double entries.
105+
forM_ enacted $ \gar -> do
107106
gaId <- resolveGovActionProposal cache (garGovActionId gar)
108107
lift $ void $ DB.updateGovActionEnacted gaId (unEpochNo currentEpochNo)
109-
let rewards = Map.mapKeys Ledger.raCredential $ Map.map (Set.singleton . mkTreasuryReward) treasuryMap
110-
insertRewardRests tracer ntw (subFromCurrentEpoch 1) currentEpochNo cache (Map.toList rewards)
108+
whenJust (garMTreasury gar) $ \treasuryMap -> do
109+
let rewards = Map.mapKeys Ledger.raCredential $ Map.map (Set.singleton . mkTreasuryReward) treasuryMap
110+
insertRewardRests tracer ntw (subFromCurrentEpoch 1) currentEpochNo cache (Map.toList rewards)
111111
LedgerMirDist rwd -> do
112112
unless (Map.null rwd) $ do
113113
let rewards = Map.toList rwd

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ data LedgerEvent
7474
| LedgerRestrainedRewards !EpochNo !Generic.Rewards !(Set StakeCred)
7575
| LedgerTotalRewards !EpochNo !(Map StakeCred (Set (Ledger.Reward StandardCrypto)))
7676
| LedgerAdaPots !AdaPots
77-
| LedgerGovInfo [GovActionRefunded] [GovActionRefunded] (Set (GovActionId StandardCrypto))
77+
| LedgerGovInfo [GovActionRefunded] [GovActionRefunded] [GovActionRefunded] (Set (GovActionId StandardCrypto))
7878
| LedgerDeposits (SafeHash StandardCrypto Ledger.EraIndependentTxBody) Coin
7979
| LedgerStartAtEpoch !EpochNo
8080
| LedgerNewEpoch !EpochNo !SyncState
@@ -85,7 +85,6 @@ data GovActionRefunded = GovActionRefunded
8585
, garDeposit :: Coin
8686
, garReturnAddr :: RewardAccount StandardCrypto
8787
, garMTreasury :: Maybe (Map (RewardAccount StandardCrypto) Coin)
88-
, garIsEnacted :: Bool -- True for enacted, False for retired, possibly redundant
8988
}
9089
deriving (Eq)
9190

@@ -253,24 +252,24 @@ toLedgerEventConway evt hasRewards =
253252
ShelleyLedgerEventTICK
254253
( TickNewEpochEvent
255254
( Conway.EpochEvent
256-
(Conway.GovInfoEvent _ en ex uncl)
255+
(Conway.GovInfoEvent en droppedEnacted expired uncl)
257256
)
258257
) ->
259258
Just $
260259
LedgerGovInfo
261-
(toGovActionRefunded True <$> toList en)
262-
(toGovActionRefunded False <$> toList ex)
260+
(toGovActionRefunded <$> toList en)
261+
(toGovActionRefunded <$> toList droppedEnacted)
262+
(toGovActionRefunded <$> toList expired)
263263
(Map.keysSet uncl)
264264
_ -> Nothing
265265
where
266-
toGovActionRefunded :: EraCrypto era ~ StandardCrypto => Bool -> GovActionState era -> GovActionRefunded
267-
toGovActionRefunded isEnacted gas =
266+
toGovActionRefunded :: EraCrypto era ~ StandardCrypto => GovActionState era -> GovActionRefunded
267+
toGovActionRefunded gas =
268268
GovActionRefunded
269269
{ garGovActionId = gasId gas
270270
, garDeposit = pProcDeposit $ gasProposalProcedure gas
271271
, garReturnAddr = pProcReturnAddr $ gasProposalProcedure gas
272272
, garMTreasury = mWithrawal
273-
, garIsEnacted = isEnacted
274273
}
275274
where
276275
mWithrawal = case pProcGovAction (gasProposalProcedure gas) of

0 commit comments

Comments
 (0)