From c958bfbab37324a0e12a5fd5e90af6f9418d99b3 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Wed, 10 Sep 2025 15:31:26 +0200 Subject: [PATCH] fix(config): Conditionally process governance events The insertNewEpochLedgerEvents function was attempting to process LedgerGovInfo events even when governance was explicitly disabled in the configuration. This led to a runtime error when trying to look up governance actions that were never inserted into the database. This commit fixes the issue by adding a conditional check to the LedgerGovInfo handler, ensuring that the related database operations are only performed when governance is enabled (ioGov iopts is true). --- .../Era/Universal/Insert/LedgerEvent.hs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/LedgerEvent.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/LedgerEvent.hs index 3ae976147..9d873a5ea 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/LedgerEvent.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/LedgerEvent.hs @@ -18,7 +18,7 @@ import Cardano.Prelude import Cardano.Slotting.Slot (EpochNo (..)) import Cardano.DbSync.Api -import Cardano.DbSync.Api.Types (EpochStatistics (..), SyncEnv (..), UnicodeNullSource, formatUnicodeNullSource) +import Cardano.DbSync.Api.Types (EpochStatistics (..), SyncEnv (..), InsertOptions (..), UnicodeNullSource, formatUnicodeNullSource) import Cardano.DbSync.Cache.Types (textShowCacheStats) import Cardano.DbSync.Era.Cardano.Util (insertEpochSyncTime, resetEpochStatistics) import qualified Cardano.DbSync.Era.Shelley.Generic as Generic @@ -54,6 +54,7 @@ insertNewEpochLedgerEvents syncEnv currentEpochNo@(EpochNo curEpoch) = tracer = getTrace syncEnv cache = envCache syncEnv ntw = getNetwork syncEnv +    iopts = getInsertOptions syncEnv subFromCurrentEpoch :: Word64 -> EpochNo subFromCurrentEpoch m = @@ -127,19 +128,20 @@ insertNewEpochLedgerEvents syncEnv currentEpochNo@(EpochNo curEpoch) = LedgerAdaPots _ -> pure () -- These are handled separately by insertBlock LedgerGovInfo enacted dropped expired uncl -> do - unless (Set.null uncl) $ - liftIO $ - logInfo tracer $ - "Found " <> textShow (Set.size uncl) <> " unclaimed proposal refunds" - updateDropped syncEnv (EpochNo curEpoch) (garGovActionId <$> (dropped <> expired)) - let refunded = filter (\e -> Set.notMember (garGovActionId e) uncl) (enacted <> dropped <> expired) - insertProposalRefunds syncEnv ntw (subFromCurrentEpoch 1) currentEpochNo refunded -- TODO: check if they are disjoint to avoid double entries. - forM_ enacted $ \gar -> do - gaId <- resolveGovActionProposal syncEnv (garGovActionId gar) - void $ lift $ DB.updateGovActionEnacted gaId (unEpochNo currentEpochNo) - whenJust (garMTreasury gar) $ \treasuryMap -> do - let rewards = Map.mapKeys Ledger.raCredential $ Map.map (Set.singleton . mkTreasuryReward) treasuryMap - insertRewardRests syncEnv ntw (subFromCurrentEpoch 1) currentEpochNo (Map.toList rewards) + when (ioGov iopts) $ do + unless (Set.null uncl) $ + liftIO $ + logInfo tracer $ + "Found " <> textShow (Set.size uncl) <> " unclaimed proposal refunds" + updateDropped syncEnv (EpochNo curEpoch) (garGovActionId <$> (dropped <> expired)) + let refunded = filter (\e -> Set.notMember (garGovActionId e) uncl) (enacted <> dropped <> expired) + insertProposalRefunds syncEnv ntw (subFromCurrentEpoch 1) currentEpochNo refunded -- TODO: check if they are disjoint to avoid double entries. + forM_ enacted $ \gar -> do + gaId <- resolveGovActionProposal syncEnv (garGovActionId gar) + void $ lift $ DB.updateGovActionEnacted gaId (unEpochNo currentEpochNo) + whenJust (garMTreasury gar) $ \treasuryMap -> do + let rewards = Map.mapKeys Ledger.raCredential $ Map.map (Set.singleton . mkTreasuryReward) treasuryMap + insertRewardRests syncEnv ntw (subFromCurrentEpoch 1) currentEpochNo (Map.toList rewards) LedgerMirDist rwd -> do unless (Map.null rwd) $ do let rewards = Map.toList rwd