Skip to content

Commit 87c4529

Browse files
committed
Add EpochState table
Fixes #1706
1 parent 7a36983 commit 87c4529

File tree

13 files changed

+241
-102
lines changed

13 files changed

+241
-102
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ generateNewEpochEvents env details = do
280280
newEpochEvent lastEpochNo =
281281
case cenEpochNo lastEpochNo of
282282
Strict.Nothing -> Just $ LedgerStartAtEpoch currentEpochNo
283-
Strict.Just oldEpoch | currentEpochNo == EpochNo (1 + unEpochNo oldEpoch)
284-
-> Just $ LedgerNewEpoch currentEpochNo (getSyncStatus details)
283+
Strict.Just oldEpoch
284+
| currentEpochNo == EpochNo (1 + unEpochNo oldEpoch) ->
285+
Just $ LedgerNewEpoch currentEpochNo (getSyncStatus details)
285286
_ -> Nothing
286287

287288
newCurrentEpochNo :: CurrentEpochNo

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
2222
import Cardano.DbSync.Era.Universal.Block (insertBlockUniversal)
2323
import Cardano.DbSync.Era.Universal.Epoch (hasEpochStartEvent, hasNewEpochEvent)
2424
import Cardano.DbSync.Era.Universal.Insert.Certificate (mkAdaPots)
25-
import Cardano.DbSync.Era.Universal.Insert.LedgerEvent (insertBlockLedgerEvents)
25+
import Cardano.DbSync.Era.Universal.Insert.LedgerEvent (insertNewEpochLedgerEvents)
2626
import Cardano.DbSync.Error
2727
import Cardano.DbSync.Fix.EpochStake
2828
import Cardano.DbSync.Ledger.State (applyBlockAndSnapshot, defaultApplyResult)
@@ -129,7 +129,7 @@ insertBlock syncEnv cblk applyRes firstAfterRollback tookSnapshot = do
129129
let !details = apSlotDetails applyResult
130130
let !withinTwoMin = isWithinTwoMin details
131131
let !withinHalfHour = isWithinHalfHour details
132-
insertBlockLedgerEvents syncEnv (sdEpochNo details) (apEvents applyResult)
132+
insertNewEpochLedgerEvents syncEnv (sdEpochNo details) (apEvents applyResult)
133133
let isNewEpochEvent = hasNewEpochEvent (apEvents applyResult)
134134
let isStartEventOrRollback = hasEpochStartEvent (apEvents applyResult) || firstAfterRollback
135135
let isMember poolId = Set.member poolId (apPoolsRegistered applyResult)

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/EpochUpdate.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module Cardano.DbSync.Era.Shelley.Generic.EpochUpdate (
99
import Cardano.DbSync.Era.Shelley.Generic.ProtoParams
1010
import Cardano.DbSync.Types
1111
import Cardano.DbSync.Util
12-
import Cardano.Ledger.BaseTypes (StrictMaybe)
1312
import qualified Cardano.Ledger.BaseTypes as Ledger
1413
import Cardano.Ledger.Conway.Governance
1514
import qualified Cardano.Ledger.Shelley.API.Wallet as Shelley
@@ -31,7 +30,7 @@ data NewEpoch = NewEpoch
3130
, neAdaPots :: !(Maybe Shelley.AdaPots)
3231
, neEpochUpdate :: !EpochUpdate
3332
, neDRepState :: !(Maybe (DRepPulsingState StandardConway))
34-
, neEnacted :: !(Maybe (GovRelation StrictMaybe StandardConway))
33+
, neEnacted :: !(Maybe (ConwayGovState StandardConway))
3534
}
3635

3736
data EpochUpdate = EpochUpdate

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Cardano.DbSync.Cache (queryOrInsertStakeAddress, queryPoolKeyOrInsert)
2929
import Cardano.DbSync.Cache.Types (Cache, CacheNew (..))
3030
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
3131
import Cardano.DbSync.Era.Universal.Insert.Certificate (insertPots)
32-
import Cardano.DbSync.Era.Universal.Insert.GovAction (insertCostModel, insertDrepDistr, updateEnacted, updateExpired, updateRatified)
32+
import Cardano.DbSync.Era.Universal.Insert.GovAction (insertCostModel, insertDrepDistr, insertUpdateEnacted, updateExpired, updateRatified)
3333
import Cardano.DbSync.Era.Universal.Insert.Other (toDouble)
3434
import Cardano.DbSync.Error
3535
import Cardano.DbSync.Ledger.Event
@@ -77,9 +77,9 @@ insertOnNewEpoch tracer iopts blkId slotNo epochNo newEpoch = do
7777
lift $ insertDrepDistr epochNo drepSnapshot
7878
updateRatified epochNo (toList $ rsEnacted ratifyState)
7979
updateExpired epochNo (toList $ rsExpired ratifyState)
80-
whenStrictJust (Generic.neEnacted newEpoch) $ \enactedSt ->
81-
when (ioGov iopts) $
82-
updateEnacted epochNo enactedSt
80+
whenStrictJust (Generic.neEnacted newEpoch) $ \enactedSt -> do
81+
when (ioGov iopts) $ do
82+
insertUpdateEnacted tracer blkId epochNo enactedSt
8383
where
8484
epochUpdate :: Generic.EpochUpdate
8585
epochUpdate = Generic.neEpochUpdate newEpoch

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ insertCertificate syncEnv isMember mDeposits blkId txId epochNo slotNo redeemers
8888
Right (ConwayTxCertGov c) ->
8989
when (ioGov iopts) $ case c of
9090
ConwayRegDRep cred coin anchor ->
91-
lift $ insertDrepRegistration txId idx cred (Just coin) (strictMaybeToMaybe anchor)
91+
lift $ insertDrepRegistration blkId txId idx cred (Just coin) (strictMaybeToMaybe anchor)
9292
ConwayUnRegDRep cred coin ->
9393
lift $ insertDrepDeRegistration txId idx cred coin
9494
ConwayAuthCommitteeHotKey khCold khHot ->
9595
lift $ insertCommitteeRegistration txId idx khCold khHot
9696
ConwayResignCommitteeColdKey khCold anchor ->
97-
lift $ insertCommitteeDeRegistration txId idx khCold (strictMaybeToMaybe anchor)
97+
lift $ insertCommitteeDeRegistration blkId txId idx khCold (strictMaybeToMaybe anchor)
9898
ConwayUpdateDRep cred anchor ->
99-
lift $ insertDrepRegistration txId idx cred Nothing (strictMaybeToMaybe anchor)
99+
lift $ insertDrepRegistration blkId txId idx cred Nothing (strictMaybeToMaybe anchor)
100100
where
101101
tracer = getTrace syncEnv
102102
cache = envCache syncEnv
@@ -236,15 +236,16 @@ insertMirCert _tracer cache network txId idx mcert = do
236236
--------------------------------------------------------------------------------------------
237237
insertDrepRegistration ::
238238
(MonadBaseControl IO m, MonadIO m) =>
239+
DB.BlockId ->
239240
DB.TxId ->
240241
Word16 ->
241242
Ledger.Credential 'DRepRole StandardCrypto ->
242243
Maybe Coin ->
243244
Maybe (Anchor StandardCrypto) ->
244245
ReaderT SqlBackend m ()
245-
insertDrepRegistration txId idx cred mcoin mAnchor = do
246+
insertDrepRegistration blkId txId idx cred mcoin mAnchor = do
246247
drepId <- insertCredDrepHash cred
247-
votingAnchorId <- whenMaybe mAnchor $ insertVotingAnchor txId DB.OtherAnchor
248+
votingAnchorId <- whenMaybe mAnchor $ insertVotingAnchor blkId DB.OtherAnchor
248249
void
249250
. DB.insertDrepRegistration
250251
$ DB.DrepRegistration
@@ -295,13 +296,14 @@ insertCommitteeRegistration txId idx khCold cred = do
295296

296297
insertCommitteeDeRegistration ::
297298
(MonadBaseControl IO m, MonadIO m) =>
299+
DB.BlockId ->
298300
DB.TxId ->
299301
Word16 ->
300302
Ledger.Credential 'ColdCommitteeRole StandardCrypto ->
301303
Maybe (Anchor StandardCrypto) ->
302304
ReaderT SqlBackend m ()
303-
insertCommitteeDeRegistration txId idx khCold mAnchor = do
304-
votingAnchorId <- whenMaybe mAnchor $ insertVotingAnchor txId DB.OtherAnchor
305+
insertCommitteeDeRegistration blockId txId idx khCold mAnchor = do
306+
votingAnchorId <- whenMaybe mAnchor $ insertVotingAnchor blockId DB.OtherAnchor
305307
khColdId <- insertCommitteeHash khCold
306308
void
307309
. DB.insertCommitteeDeRegistration

0 commit comments

Comments
 (0)