Skip to content

Commit

Permalink
fix merge conflict issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Cmdv committed Jun 5, 2024
1 parent d08e79e commit f2b8e01
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion cardano-chain-gen/src/Cardano/Mock/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Cardano.Mock.Query (
) where

import qualified Cardano.Db as Db
import Cardano.Prelude hiding (from, isNothing)
import Cardano.Prelude hiding (from, isNothing, on)
import qualified Data.ByteString.Base16 as Base16
import Data.ByteString.Short (ShortByteString, toShort)
import Database.Esqueleto.Experimental
Expand Down
34 changes: 14 additions & 20 deletions cardano-db-sync/src/Cardano/DbSync/Era/Universal/Epoch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ import Cardano.DbSync.Api
import Cardano.DbSync.Api.Types (InsertOptions (..), SyncEnv (..))
import Cardano.DbSync.Cache (queryOrInsertStakeAddress, queryPoolKeyOrInsert)
import Cardano.DbSync.Cache.Types (Cache, CacheNew (..))
import Cardano.DbSync.Config.Types (isShelleyModeActive)
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
import Cardano.DbSync.Era.Universal.Insert.Certificate (insertPots)
import Cardano.DbSync.Era.Universal.Insert.GovAction (insertCostModel, insertDrepDistr, insertUpdateEnacted, updateExpired, updateRatified)
import Cardano.DbSync.Era.Universal.Insert.Other (toDouble)
import Cardano.DbSync.Error
import Cardano.DbSync.Ledger.Event
import Cardano.DbSync.Types
import Cardano.DbSync.Util (whenFalseEmpty, whenStrictJust)
import Cardano.DbSync.Util (whenStrictJust, whenFalseEmpty)
import Cardano.DbSync.Util.Constraint (constraintNameEpochStake, constraintNameReward)
import Cardano.DbSync.Util.Whitelist (shelleyStakeAddrWhitelistCheck)
import qualified Cardano.Ledger.Address as Ledger
import Cardano.Ledger.Address (RewardAccount (..))
import Cardano.Ledger.BaseTypes (Network, unEpochInterval)
import qualified Cardano.Ledger.BaseTypes as Ledger
import Cardano.Ledger.Binary.Version (getVersion)
Expand All @@ -56,12 +54,16 @@ import Control.Monad.Trans.Control (MonadBaseControl)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Database.Persist.Sql (SqlBackend)
import Cardano.DbSync.Config.Types (isShelleyModeActive)
import Cardano.DbSync.Util.Whitelist (shelleyStakeAddrWhitelistCheck)
import qualified Cardano.Ledger.Address as Ledger

--------------------------------------------------------------------------------------------
-- Insert Epoch
--------------------------------------------------------------------------------------------
insertOnNewEpoch ::
(MonadBaseControl IO m, MonadIO m) =>
SyncEnv ->
DB.BlockId ->
SlotNo ->
EpochNo ->
Expand All @@ -75,22 +77,14 @@ insertOnNewEpoch syncEnv blkId slotNo epochNo newEpoch = do
whenStrictJust (Generic.neDRepState newEpoch) $ \dreps -> when (ioGov iopts) $ do
let (drepSnapshot, ratifyState) = finishDRepPulser dreps
lift $ insertDrepDistr epochNo drepSnapshot
<<<<<<< HEAD
updateRatified epochNo (toList $ rsEnacted ratifyState)
updateExpired epochNo (toList $ rsExpired ratifyState)
whenStrictJust (Generic.neEnacted newEpoch) $ \enactedSt -> do
when (ioGov iopts) $ do
insertUpdateEnacted tracer blkId epochNo enactedSt
=======
updateRatified syncEnv epochNo (toList $ rsEnacted ratifyState)
updateExpired syncEnv epochNo (toList $ rsExpired ratifyState)
whenStrictJust (Generic.neEnacted newEpoch) $ \enactedSt ->
when (ioGov iopts) $
updateEnacted syncEnv epochNo enactedSt
>>>>>>> 328815aa (fix merge conflict errors)
whenStrictJust (Generic.neEnacted newEpoch) $ \enactedSt -> do
when (ioGov iopts) $ do
insertUpdateEnacted syncEnv blkId epochNo enactedSt
where
epochUpdate :: Generic.EpochUpdate
epochUpdate = Generic.neEpochUpdate newEpoc
epochUpdate = Generic.neEpochUpdate newEpoch
tracer = getTrace syncEnv
iopts = getInsertOptions syncEnv

Expand Down Expand Up @@ -261,7 +255,7 @@ insertRewards syncEnv nw earnedEpoch spendableEpoch cache rewardsChunk = do
(MonadBaseControl IO m, MonadIO m) =>
(StakeCred, Set Generic.Reward) ->
ExceptT SyncNodeError (ReaderT SqlBackend m) [DB.Reward]
mkRewards (saddr, rset) =
mkRewards (saddr, rset) = do
-- Check if the stake address is in the shelley whitelist
if shelleyStakeAddrWhitelistCheck syncEnv $ Ledger.RewardAccount nw saddr
then do
Expand Down Expand Up @@ -314,8 +308,8 @@ insertRewardRests syncEnv nw earnedEpoch spendableEpoch cache rewardsChunk = do
(MonadBaseControl IO m, MonadIO m) =>
(StakeCred, Set Generic.RewardRest) ->
ExceptT SyncNodeError (ReaderT SqlBackend m) [DB.RewardRest]
mkRewards (saddr, rset) =
-- Check if the stake address is in the shelley whitelist
mkRewards (saddr, rset) = do
-- Check if the stake address is in the shelley whitelist
if shelleyStakeAddrWhitelistCheck syncEnv $ Ledger.RewardAccount nw saddr
then do
saId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw saddr
Expand Down Expand Up @@ -353,7 +347,7 @@ insertProposalRefunds syncEnv nw earnedEpoch spendableEpoch cache refunds = do
GovActionRefunded ->
ExceptT SyncNodeError (ReaderT SqlBackend m) DB.RewardRest
mkReward refund = do
saId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw (Ledger.raCredential $ garReturnAddr refund)
saId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw (raCredential $ garReturnAddr refund)
pure $
DB.RewardRest
{ DB.rewardRestAddrId = saId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeOperators #-}

module Cardano.DbSync.Era.Universal.Insert.GovAction (
insertConstitution,
Expand Down Expand Up @@ -51,7 +52,7 @@ import Cardano.Ledger.CertState (DRep (..))
import Cardano.Ledger.Coin (Coin)
import qualified Cardano.Ledger.Coin as Ledger
import Cardano.Ledger.Compactible (Compactible (..))
import Cardano.Ledger.Conway.Core (DRepVotingThresholds (..), PoolVotingThresholds (..))
import Cardano.Ledger.Conway.Core (DRepVotingThresholds (..), PoolVotingThresholds (..), Era (..))
import Cardano.Ledger.Conway.Governance
import qualified Cardano.Ledger.Credential as Ledger
import Cardano.Ledger.DRep (DRepState (..))
Expand All @@ -69,6 +70,8 @@ import qualified Data.Text.Encoding as Text
import Database.Persist.Sql (SqlBackend)
import Ouroboros.Consensus.Cardano.Block (StandardConway, StandardCrypto)
import Prelude (zip3)
import Cardano.DbSync.Api (getTrace)
import Cardano.BM.Trace (logWarning)

insertGovActionProposal ::
forall m.
Expand All @@ -84,7 +87,7 @@ insertGovActionProposal syncEnv blkId txId govExpiresAt mmCommittee (index, pp)
-- check if shelley stake address is in the whitelist
when (shelleyStakeAddrWhitelistCheck syncEnv $ pProcReturnAddr pp) $ do
addrId <- lift $ queryOrInsertRewardAccount syncEnv cache CacheNew $ pProcReturnAddr pp
votingAnchorId <- lift $ insertVotingAnchor txId DB.GovActionAnchor $ pProcAnchor pp
votingAnchorId <- lift $ insertVotingAnchor blkId DB.GovActionAnchor $ pProcAnchor pp
mParamProposalId <- lift $
case pProcGovAction pp of
ParameterChange _ pparams _ ->
Expand Down Expand Up @@ -114,8 +117,8 @@ insertGovActionProposal syncEnv blkId txId govExpiresAt mmCommittee (index, pp)
}
case pProcGovAction pp of
TreasuryWithdrawals mp _ -> lift $ mapM_ (insertTreasuryWithdrawal govActionProposalId) (Map.toList mp)
UpdateCommittee _ removed added q -> lift $ insertNewCommittee govActionProposalId removed added q
NewConstitution _ constitution -> lift $ insertConstitution txId govActionProposalId constitution
UpdateCommittee _ removed added q -> lift $ insertNewCommittee (Just govActionProposalId) removed added q
NewConstitution _ constitution -> void $ lift $ insertConstitution blkId (Just govActionProposalId) constitution
_ -> pure ()
where
cache = envCache syncEnv
Expand All @@ -133,7 +136,7 @@ insertGovActionProposal syncEnv blkId txId govExpiresAt mmCommittee (index, pp)
ReaderT SqlBackend m DB.TreasuryWithdrawalId
insertTreasuryWithdrawal gaId (rwdAcc, coin) = do
addrId <-
queryOrInsertRewardAccount cache CacheNew rwdAcc
queryOrInsertRewardAccount syncEnv cache CacheNew rwdAcc
DB.insertTreasuryWithdrawal $
DB.TreasuryWithdrawal
{ DB.treasuryWithdrawalGovActionProposalId = gaId
Expand Down Expand Up @@ -290,29 +293,31 @@ insertConstitution blockId mgapId constitution = do
insertVotingProcedures ::
(MonadIO m, MonadBaseControl IO m) =>
SyncEnv ->
DB.BlockId ->
DB.TxId ->
[ProposalProcedure StandardConway] ->
(Voter StandardCrypto, [(GovActionId StandardCrypto, VotingProcedure StandardConway)]) ->
ExceptT SyncNodeError (ReaderT SqlBackend m) ()
insertVotingProcedures syncEnv txId proposalPs (voter, actions) =
insertVotingProcedures syncEnv blkId txId proposalPs (voter, actions) =
-- TODO: cmdv will actions & proposalPs always be the same length?
mapM_ (insertVotingProcedure syncEnv txId voter) (zip3 [0 ..] actions proposalPs)
mapM_ (insertVotingProcedure syncEnv blkId txId voter) (zip3 [0 ..] actions proposalPs)

insertVotingProcedure ::
(MonadIO m, MonadBaseControl IO m) =>
SyncEnv ->
DB.BlockId ->
DB.TxId ->
Voter StandardCrypto ->
(Word16, (GovActionId StandardCrypto, VotingProcedure StandardConway), ProposalProcedure StandardConway) ->
ExceptT SyncNodeError (ReaderT SqlBackend m) ()
insertVotingProcedure syncEnv txId voter (index, (gaId, vp), proposalP) = do
insertVotingProcedure syncEnv blkId txId voter (index, (gaId, vp), proposalP) = do
-- check if shelley stake address is in the whitelist
when (shelleyStakeAddrWhitelistCheck syncEnv $ pProcReturnAddr proposalP) $ do
maybeGovActionId <- resolveGovActionProposal syncEnv gaId
case maybeGovActionId of
Nothing -> pure ()
Just govActionId -> do
votingAnchorId <- whenMaybe (strictMaybeToMaybe $ vProcAnchor vp) $ lift . insertVotingAnchor txId DB.OtherAnchor
votingAnchorId <- whenMaybe (strictMaybeToMaybe $ vProcAnchor vp) $ lift . insertVotingAnchor blkId DB.OtherAnchor
(mCommitteeVoterId, mDRepVoter, mStakePoolVoter) <- case voter of
CommitteeVoter cred -> do
khId <- lift $ insertCommitteeHash cred
Expand Down Expand Up @@ -459,19 +464,19 @@ insertUpdateEnacted ::
ExceptT SyncNodeError (ReaderT SqlBackend m) ()
insertUpdateEnacted syncEnv blkId epochNo enactedState = do
whenJust (strictMaybeToMaybe (grPParamUpdate govIds)) $ \prevId -> do
maybeGaId <- resolveGovActionProposal syncEnv $ getPrevId prevId
maybeGaId <- resolveGovActionProposal syncEnv $ unGovPurposeId prevId
case maybeGaId of
Nothing -> pure ()
Just gaId -> lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)
Just gaId -> void $ lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)

whenJust (strictMaybeToMaybe (grHardFork govIds)) $ \prevId -> do
maybeGaId <- resolveGovActionProposal $ unGovPurposeId prevId
maybeGaId <- resolveGovActionProposal syncEnv $ unGovPurposeId prevId
case maybeGaId of
Nothing -> pure ()
Just gaId -> void $ lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)
(mcommitteeId, mnoConfidenceGaId) <- handleCommittee syncEnv blkId
(mcommitteeId, mnoConfidenceGaId) <- handleCommittee syncEnv govIds epochNo enactedState

constitutionId <- handleConstitution syncEnv blkId
constitutionId <- handleConstitution syncEnv blkId govIds epochNo enactedState

void $
lift $
Expand All @@ -485,7 +490,13 @@ insertUpdateEnacted syncEnv blkId epochNo enactedState = do
where
govIds = govStatePrevGovActionIds enactedState

handleCommittee syncEnv govIds blkId = do
handleCommittee :: (EraCrypto era ~ StandardCrypto, MonadIO m, MonadBaseControl IO m) =>
SyncEnv ->
GovRelation StrictMaybe era ->
EpochNo ->
ConwayGovState StandardConway ->
ExceptT SyncNodeError (ReaderT SqlBackend m) (Maybe DB.CommitteeId, Maybe DB.GovActionProposalId)
handleCommittee syncEnv govIds epochNo enactedState = do
mCommitteeGaId <- case strictMaybeToMaybe (grCommittee govIds) of
Nothing -> pure Nothing
Just prevId -> do
Expand Down Expand Up @@ -517,7 +528,7 @@ handleCommittee syncEnv govIds blkId = do
-- This should never happen. Having a committee and an enacted action, means
-- the committee came from a proposal which should be returned from the query.
liftIO $
logWarning trce $
logWarning (getTrace syncEnv) $
mconcat
[ "The impossible happened! Couldn't find the committee "
, textShow committee
Expand All @@ -528,7 +539,15 @@ handleCommittee syncEnv govIds blkId = do
(committeeId : _rest) ->
pure (Just committeeId, Nothing)

handleConstitution syncEnv govIds = do
handleConstitution ::
(EraCrypto era ~ StandardCrypto, MonadIO m, MonadBaseControl IO m) =>
SyncEnv ->
DB.BlockId ->
GovRelation StrictMaybe era ->
EpochNo ->
ConwayGovState StandardConway ->
ExceptT SyncNodeError (ReaderT SqlBackend m) DB.ConstitutionId
handleConstitution syncEnv blkId govIds epochNo enactedState = do
mConstitutionGaId <- case strictMaybeToMaybe (grConstitution govIds) of
Nothing -> pure Nothing
Just prevId -> do
Expand All @@ -547,24 +566,11 @@ handleConstitution syncEnv govIds = do
constitutionId : rest -> do
unless (null rest) $
liftIO $
logWarning trce $
logWarning (getTrace syncEnv) $
mconcat
[ "Found multiple constitutions for proposal "
, textShow mConstitutionGaId
, ": "
, textShow constitutionIds
]
pure constitutionId
=======
whenJust (strictMaybeToMaybe (grCommittee enactedState)) $ \prevId -> do
maybeGaId <- resolveGovActionProposal syncEnv $ unGovPurposeId prevId
case maybeGaId of
Nothing -> pure ()
Just gaId -> lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)

whenJust (strictMaybeToMaybe (grConstitution enactedState)) $ \prevId -> do
maybeGaId <- resolveGovActionProposal syncEnv $ unGovPurposeId prevId
case maybeGaId of
Nothing -> pure ()
Just gaId -> lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)
>>>>>>> 328815aa (fix merge conflict errors)
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped

when (ioGov iopts) $ do
mapM_ (insertGovActionProposal syncEnv blkId txId (getGovExpiresAt applyResult epochNo) (apCommittee applyResult)) $ zip [0 ..] (Generic.txProposalProcedure tx)
mapM_ (insertVotingProcedures syncEnv txId (Generic.txProposalProcedure tx)) (Generic.txVotingProcedure tx)
mapM_ (insertVotingProcedures syncEnv blkId txId (Generic.txProposalProcedure tx)) (Generic.txVotingProcedure tx)

let !txIns = map (prepareTxIn txId redeemers) resolvedInputs
pure (grouped <> BlockGroupedData txIns txOutsGrouped txMetadata maTxMint resolvedFees outSum)
Expand Down

0 comments on commit f2b8e01

Please sign in to comment.