Skip to content

Commit

Permalink
Something is wrong with pparam updates because you vote with the hot
Browse files Browse the repository at this point in the history
keys and the dreps
  • Loading branch information
Jimbo4350 committed May 17, 2024
1 parent b808115 commit fd8a20b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 12 deletions.
1 change: 1 addition & 0 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ test-suite cardano-testnet-test
, cardano-api:{cardano-api, internal}
, cardano-cli
, cardano-crypto-class
, cardano-ledger-api
, cardano-ledger-core
, cardano-ledger-conway
, cardano-ledger-core
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
Expand All @@ -14,6 +15,7 @@ import Cardano.Api.Ledger (EpochInterval (..))
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley

import qualified Cardano.Ledger.Api.State.Query as L
import qualified Cardano.Ledger.Conway.Governance as L
import qualified Cardano.Ledger.Conway.PParams as L
import qualified Cardano.Ledger.Shelley.LedgerState as L
Expand All @@ -26,11 +28,14 @@ import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Bifunctor (first)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Maybe
import qualified Data.Set as Set
import Data.String
import qualified Data.Text as Text
import Data.Word
import GHC.Stack
import Lens.Micro
import System.FilePath ((</>))

Expand Down Expand Up @@ -120,12 +125,25 @@ hprop_update_pparam = H.integrationWorkspace "pparam-update" $ \tempAbsBasePath'
, "--signing-key-file", work </> defaultCommitteeHotSkeyFp 1
]

hotKeyHash1 <- H.execCli' execConfigOffline
[ anyEraToString cEra, "governance", "committee"
, "key-hash"
, "--verification-key-file", work </> defaultCommitteeHotVkeyFp 1
]

CommitteeHotKeyHash comHotKeyHash1 <-
evalEither
$ deserialiseFromRawBytesHex (AsHash AsCommitteeHotKey)
$ BSC.pack $ filter (/= '\n') hotKeyHash1

let comHotKeyCred1 = L.KeyHashObj comHotKeyHash1

void $ H.execCli' execConfigOffline
[ anyEraToString cEra, "governance", "committee"
, "create-hot-key-authorization-certificate"
, "--cold-verification-key-file", work </> defaultCommitteeVkeyFp 1
, "--hot-key-file", work </> defaultCommitteeHotVkeyFp 1
, "--out-file", work </> defaultCommitteeHotAuthCertFp 1
, "--out-file", work </> defaultCommitteeHotAuthCertFp 1
]

committeeVkey1Fp <- H.noteShow $ work </> defaultCommitteeVkeyFp 1
Expand Down Expand Up @@ -271,13 +289,16 @@ hprop_update_pparam = H.integrationWorkspace "pparam-update" $ \tempAbsBasePath'
-- Need to vote on proposal. Drep threshold must be met
governanceActionTxIdPParamUpdate <- retrieveTransactionId execConfig signedPParamsProposalTx

!pparamsPropSubmittedResult
<- H.leftFailM $ watchEpochStateView
epochStateView
(maybeExtractGovernanceActionIndex (fromString governanceActionTxIdPParamUpdate))
(EpochInterval 5)
!governanceActionIndexPParams
<- H.nothingFailM $ watchEpochStateView
epochStateView
(return . maybeExtractGovernanceActionIndex (fromString governanceActionTxIdPParamUpdate))
(EpochInterval 5)

governanceActionIndexPParams <- H.nothingFail pparamsPropSubmittedResult
-- Confirm that committee hot keys have been authorized
H.nothingFailM $ watchEpochStateView epochStateView
(checkCommitteeHotKeyAuthorizationStatus [comHotKeyCred1])
(EpochInterval 5)

-- Proposal was successfully submitted, now we vote on the proposal and confirm it was ratified
pparamsDRepVoteFiles <- generateVoteFiles execConfig work "pparams-update-vote-files"
Expand Down Expand Up @@ -305,13 +326,10 @@ hprop_update_pparam = H.integrationWorkspace "pparam-update" $ \tempAbsBasePath'
pparamsVoteTxFp <- signTx execConfig cEra work "signed-vote-tx" pparamsVoteTxBodyFp signingKeys
submitTx execConfig cEra pparamsVoteTxFp

mPParamsUpdate
<- H.leftFailM $ watchEpochStateView epochStateView
(checkPParamsUpdated (EpochInterval newCommitteeTermLength))
H.nothingFailM $ watchEpochStateView epochStateView
(return . checkPParamsUpdated (EpochInterval newCommitteeTermLength))
(EpochInterval 10)

H.nothingFail mPParamsUpdate

checkPParamsUpdated
:: EpochInterval -- ^ The epoch interval to check for in the updated protocol parameters
-> AnyNewEpochState
Expand All @@ -325,3 +343,27 @@ checkPParamsUpdated committeeTermLength (AnyNewEpochState sbe nes) =
in if curCommTermLength == committeeTermLength
then Just () -- PParams was successfully updated and we terminate the fold.
else Nothing -- PParams was not updated yet, we continue the fold.

checkCommitteeHotKeyAuthorizationStatus
:: MonadTest m
=> [L.Credential L.HotCommitteeRole L.StandardCrypto]
-> AnyNewEpochState
-> m (Maybe ())
checkCommitteeHotKeyAuthorizationStatus hotCreds (AnyNewEpochState sbe nes) =
caseShelleyToBabbageOrConwayEraOnwards
(const $ error "Committee hot key authorization only exists in Conway era onwards")
(const $
let commMemStat = L.queryCommitteeMembersState mempty (Set.fromList hotCreds) (Set.singleton L.Active) nes
activeMembers = [ hotKeyCred
| L.MemberAuthorized hotKeyCred <- map L.cmsHotCredAuthStatus $ Map.elems $ L.csCommittee commMemStat
]
unregisteredHotKeys = hotCreds List.\\ activeMembers
in if null activeMembers
then return Nothing
else if null unregisteredHotKeys
then return $ Just ()
else H.failMessage callStack
$ "Some hot keys were not authorized: " <> show unregisteredHotKeys

)
sbe

0 comments on commit fd8a20b

Please sign in to comment.