Skip to content

Commit 360e5c5

Browse files
committed
Move hot key committee to a new table
Fixes #1571
1 parent e08a7bf commit 360e5c5

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import Cardano.DbSync.Cache (
3535
)
3636
import Cardano.DbSync.Cache.Types (Cache (..), CacheNew (..))
3737
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
38-
import Cardano.DbSync.Era.Universal.Insert.GovAction (insertCredDrepHash, insertDrep, insertVotingAnchor)
38+
import Cardano.DbSync.Era.Universal.Insert.GovAction (insertCommitteeHash, insertCredDrepHash, insertDrep, insertVotingAnchor)
3939
import Cardano.DbSync.Era.Universal.Insert.Pool (IsPoolMember, insertPoolCert)
4040
import Cardano.DbSync.Error
4141
import Cardano.DbSync.Types
@@ -280,14 +280,15 @@ insertCommitteeRegistration ::
280280
Ledger.Credential 'ColdCommitteeRole StandardCrypto ->
281281
Ledger.Credential 'HotCommitteeRole StandardCrypto ->
282282
ReaderT SqlBackend m ()
283-
insertCommitteeRegistration txId idx khCold khHot = do
283+
insertCommitteeRegistration txId idx khCold cred = do
284+
khHotId <- insertCommitteeHash cred
284285
void
285286
. DB.insertCommitteeRegistration
286287
$ DB.CommitteeRegistration
287288
{ DB.committeeRegistrationTxId = txId
288289
, DB.committeeRegistrationCertIndex = idx
289290
, DB.committeeRegistrationColdKey = Generic.unCredentialHash khCold
290-
, DB.committeeRegistrationHotKey = Generic.unCredentialHash khHot
291+
, DB.committeeRegistrationHotKeyId = khHotId
291292
}
292293

293294
insertCommitteeDeRegistration ::

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Cardano.DbSync.Era.Universal.Insert.GovAction (
1717
insertGovActionProposal,
1818
insertParamProposal,
1919
insertVotingProcedures,
20+
insertCommitteeHash,
2021
insertVotingAnchor,
2122
resolveGovActionProposal,
2223
updateEnacted,
@@ -254,9 +255,10 @@ insertVotingProcedure ::
254255
insertVotingProcedure trce cache txId voter (index, (gaId, vp)) = do
255256
govActionId <- resolveGovActionProposal gaId
256257
votingAnchorId <- whenMaybe (strictMaybeToMaybe $ vProcAnchor vp) $ lift . insertVotingAnchor txId
257-
(mCommitteeVoter, mDRepVoter, mStakePoolVoter) <- case voter of
258-
CommitteeVoter cred ->
259-
pure (Just $ Generic.unCredentialHash cred, Nothing, Nothing)
258+
(mCommitteeVoterId, mDRepVoter, mStakePoolVoter) <- case voter of
259+
CommitteeVoter cred -> do
260+
khId <- lift $ insertCommitteeHash cred
261+
pure (Just khId, Nothing, Nothing)
260262
DRepVoter cred -> do
261263
drep <- lift $ insertCredDrepHash cred
262264
pure (Nothing, Just drep, Nothing)
@@ -270,7 +272,7 @@ insertVotingProcedure trce cache txId voter (index, (gaId, vp)) = do
270272
{ DB.votingProcedureTxId = txId
271273
, DB.votingProcedureIndex = index
272274
, DB.votingProcedureGovActionProposalId = govActionId
273-
, DB.votingProcedureCommitteeVoter = mCommitteeVoter
275+
, DB.votingProcedureCommitteeVoter = mCommitteeVoterId
274276
, DB.votingProcedureDrepVoter = mDRepVoter
275277
, DB.votingProcedurePoolVoter = mStakePoolVoter
276278
, DB.votingProcedureVoterRole = Generic.toVoterRole voter
@@ -296,6 +298,14 @@ insertAnchor txId anchor =
296298
, DB.votingAnchorDataHash = Generic.safeHashToByteString $ anchorDataHash anchor
297299
}
298300

301+
insertCommitteeHash :: (MonadBaseControl IO m, MonadIO m) => Ledger.Credential kr StandardCrypto -> ReaderT SqlBackend m DB.CommitteeHashId
302+
insertCommitteeHash cred = do
303+
DB.insertCommitteeHash
304+
DB.CommitteeHash
305+
{ DB.committeeHashRaw = Generic.unCredentialHash cred
306+
, DB.committeeHashHasScript = Generic.hasCredScript cred
307+
}
308+
299309
--------------------------------------------------------------------------------------
300310
-- DREP
301311
--------------------------------------------------------------------------------------

cardano-db/src/Cardano/Db/Insert.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ module Cardano.Db.Insert (
7474
insertNewCommittee,
7575
insertVotingProcedure,
7676
insertDrepHash,
77+
insertCommitteeHash,
7778
insertDelegationVote,
7879
insertCommitteeRegistration,
7980
insertCommitteeDeRegistration,
@@ -404,6 +405,9 @@ insertVotingProcedure = insertUnchecked "VotingProcedure"
404405
insertDrepHash :: (MonadBaseControl IO m, MonadIO m) => DrepHash -> ReaderT SqlBackend m DrepHashId
405406
insertDrepHash = insertCheckUnique "DrepHash"
406407

408+
insertCommitteeHash :: (MonadBaseControl IO m, MonadIO m) => CommitteeHash -> ReaderT SqlBackend m CommitteeHashId
409+
insertCommitteeHash = insertCheckUnique "CommitteeHash"
410+
407411
insertDelegationVote :: (MonadBaseControl IO m, MonadIO m) => DelegationVote -> ReaderT SqlBackend m DelegationVoteId
408412
insertDelegationVote = insertUnchecked "DelegationVote"
409413

cardano-db/src/Cardano/Db/Query.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module Cardano.Db.Query (
6060
queryGovActionProposalId,
6161
queryDrepHashAlwaysAbstain,
6262
queryDrepHashAlwaysNoConfidence,
63+
queryCommitteeHash,
6364
-- queries used in smash
6465
queryOffChainPoolData,
6566
queryPoolRegister,
@@ -807,6 +808,14 @@ queryDrepHashAlwaysNoConfidence = do
807808
pure $ dh ^. DrepHashId
808809
pure $ unValue <$> listToMaybe res
809810

811+
queryCommitteeHash :: MonadIO m => ByteString -> ReaderT SqlBackend m (Maybe CommitteeHashId)
812+
queryCommitteeHash hash = do
813+
res <- select $ do
814+
ch <- from $ table @CommitteeHash
815+
where_ (ch ^. CommitteeHashRaw ==. val hash)
816+
pure $ ch ^. CommitteeHashId
817+
pure $ unValue <$> listToMaybe res
818+
810819
{--------------------------------------------
811820
Queries use in SMASH
812821
----------------------------------------------}

cardano-db/src/Cardano/Db/Schema.hs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,12 @@ share
554554
raw ByteString Maybe sqltype=hash28type
555555
view Text
556556
hasScript Bool
557-
UniqueDrepHash raw !force
557+
UniqueDrepHash raw hasScript !force
558+
559+
CommitteeHash
560+
raw ByteString sqltype=hash28type
561+
hasScript Bool
562+
UniqueCommitteeHash raw hasScript
558563

559564
DelegationVote
560565
addrId StakeAddressId noreference
@@ -567,7 +572,7 @@ share
567572
txId TxId noreference
568573
certIndex Word16
569574
coldKey ByteString sqltype=hash28type
570-
hotKey ByteString sqltype=hash28type
575+
hotKeyId CommitteeHashId noreference
571576

572577
CommitteeDeRegistration
573578
txId TxId noreference
@@ -626,7 +631,7 @@ share
626631
index Word16
627632
govActionProposalId GovActionProposalId noreference
628633
voterRole VoterRole sqltype=voterrole
629-
committeeVoter ByteString Maybe
634+
committeeVoter CommitteeHashId Maybe noreference
630635
drepVoter DrepHashId Maybe noreference
631636
poolVoter PoolHashId Maybe noreference
632637
vote Vote sqltype=vote
@@ -1182,12 +1187,17 @@ schemaDocs =
11821187

11831188
DrepHash --^ do
11841189
"A table for every unique drep key hash.\
1185-
\ The existance of an entry doesn't mean the DRep is registered or in fact that is was ever registered.\
1190+
\ The existance of an entry doesn't mean the DRep is registered.\
11861191
\ New in 13.2-Conway."
11871192
DrepHashRaw # "The raw bytes of the DRep."
11881193
DrepHashView # "The human readable encoding of the Drep."
11891194
DrepHashHasScript # "Flag which shows if this DRep credentials are a script hash"
11901195

1196+
CommitteeHash --^ do
1197+
"A table for all committee hot credentials"
1198+
CommitteeHashRaw # "The key or script hash"
1199+
CommitteeHashHasScript # "Flag which shows if this credential is a script hash"
1200+
11911201
DelegationVote --^ do
11921202
"A table containing delegations from a stake address to a stake pool. New in 13.2-Conway."
11931203
DelegationVoteAddrId # "The StakeAddress table index for the stake address."
@@ -1201,7 +1211,7 @@ schemaDocs =
12011211
CommitteeRegistrationTxId # "The Tx table index of the tx that includes this certificate."
12021212
CommitteeRegistrationCertIndex # "The index of this registration within the certificates of this transaction."
12031213
CommitteeRegistrationColdKey # "The registered cold hey hash. TODO: should this reference DrepHashId or some separate hash table?"
1204-
CommitteeRegistrationHotKey # "The registered hot hey hash"
1214+
CommitteeRegistrationHotKeyId # "The registered hot hey hash id"
12051215

12061216
CommitteeDeRegistration --^ do
12071217
"A table for every committee key de-registration. New in 13.2-Conway."
@@ -1273,7 +1283,9 @@ schemaDocs =
12731283
VotingProcedureIndex # "The index of this VotingProcedure within this transaction."
12741284
VotingProcedureGovActionProposalId # "The index of the GovActionProposal that this vote targets."
12751285
VotingProcedureVoterRole # "The role of the voter. Can be one of ConstitutionalCommittee, DRep, SPO."
1276-
VotingProcedureCommitteeVoter # ""
1286+
VotingProcedureCommitteeVoter # "A reference to the hot key committee hash entry that voted"
1287+
VotingProcedureDrepVoter # "A reference to the drep hash entry that voted"
1288+
VotingProcedurePoolVoter # "A reference to the pool hash entry that voted"
12771289
VotingProcedureVote # "The Vote. Can be one of Yes, No, Abstain."
12781290
VotingProcedureVotingAnchorId # "The VotingAnchor table index associated with this VotingProcedure."
12791291

0 commit comments

Comments
 (0)