Skip to content

Commit 3cbbace

Browse files
authored
Merge pull request #5693 from IntersectMBO/jordan/propose-constitution-with-guardrail-script
Propose constitution with guardrail script
2 parents 479df51 + c575ff9 commit 3cbbace

File tree

5 files changed

+63
-24
lines changed

5 files changed

+63
-24
lines changed

bench/cardano-topology/cardano-topology.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ license: Apache-2.0
1313
license-files: LICENSE
1414
NOTICE
1515
build-type: Simple
16-
extra-source-files: README.md
1716
data-files: data/bench-torus-52.json
1817
data/bench-torus-dense-52.json
1918
data/ci-test-nomadcwqa.json

cardano-testnet/cardano-testnet.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@ test-suite cardano-testnet-test
199199
, cardano-cli
200200
, cardano-crypto-class
201201
, cardano-ledger-conway
202+
, cardano-ledger-core
202203
, cardano-ledger-shelley
203204
, cardano-node
205+
, cardano-strict-containers ^>= 0.1
204206
, cardano-testnet
205207
, containers
206208
, directory

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/LedgerEvents/Gov/ProposeNewConstitution.hs

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@ import Cardano.Api as Api
2222
import Cardano.Api.Error (displayError)
2323
import Cardano.Api.Shelley
2424

25+
import qualified Cardano.Crypto.Hash as L
2526
import qualified Cardano.Ledger.Conway.Governance as L
2627
import qualified Cardano.Ledger.Conway.Governance as Ledger
28+
import qualified Cardano.Ledger.Hashes as L
29+
import qualified Cardano.Ledger.Shelley.LedgerState as L
2730
import Cardano.Testnet
2831

2932
import Prelude
3033

3134
import Control.Monad
3235
import Control.Monad.State.Strict (StateT)
3336
import qualified Data.Map.Strict as Map
37+
import Data.Maybe
38+
import Data.Maybe.Strict
3439
import Data.String
3540
import qualified Data.Text as Text
3641
import Data.Word
@@ -39,7 +44,9 @@ import GHC.Stack (HasCallStack, callStack)
3944
import Lens.Micro
4045
import System.FilePath ((</>))
4146

47+
import Testnet.Components.Configuration
4248
import Testnet.Components.Query
49+
import Testnet.Defaults
4350
import qualified Testnet.Process.Cli as P
4451
import qualified Testnet.Process.Run as H
4552
import qualified Testnet.Property.Utils as H
@@ -175,6 +182,16 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n
175182

176183
-- Create constitution proposal
177184

185+
guardRailScriptFp <- H.note $ work </> "guard-rail-script.plutusV3"
186+
H.writeFile guardRailScriptFp $ Text.unpack plutusV3NonSpendingScript
187+
-- TODO: Update help text for policyid. The script hash is not
188+
-- only useful for minting scripts
189+
constitutionScriptHash <- filter (/= '\n') <$>
190+
H.execCli' execConfig
191+
[ convertToEraString cEra, "transaction"
192+
, "policyid"
193+
, "--script-file", guardRailScriptFp
194+
]
178195
void $ H.execCli' execConfig
179196
[ "conway", "governance", "action", "create-constitution"
180197
, "--testnet"
@@ -184,6 +201,7 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n
184201
, "--anchor-data-hash", proposalAnchorDataHash
185202
, "--constitution-url", "https://tinyurl.com/2pahcy6z"
186203
, "--constitution-hash", constitutionHash
204+
, "--constitution-script-hash", constitutionScriptHash
187205
, "--out-file", constitutionActionFp
188206
]
189207

@@ -289,10 +307,16 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n
289307

290308
-- We check that constitution was succcessfully ratified
291309

292-
!eConstitutionAdopted <- runExceptT
293-
$ foldEpochState (File configurationFile) (File socketPath) QuickValidation (EpochNo 10) ()
294-
$ checkConstitutionWasRatified constitutionHash
295-
evalEither $ void eConstitutionAdopted
310+
!eConstitutionAdopted
311+
<- runExceptT $ foldEpochState
312+
(File configurationFile)
313+
(File socketPath)
314+
FullValidation
315+
(EpochNo 10)
316+
()
317+
(foldBlocksCheckConstitutionWasRatified constitutionHash constitutionScriptHash)
318+
319+
void $ evalEither eConstitutionAdopted
296320

297321
foldBlocksCheckProposalWasSubmitted
298322
:: TxId -- TxId of submitted tx
@@ -335,26 +359,34 @@ filterNewGovProposals txid (NewGovernanceProposals eventTxId (AnyProposals props
335359
filterNewGovProposals _ _ = False
336360

337361

338-
checkConstitutionWasRatified
362+
foldBlocksCheckConstitutionWasRatified
339363
:: String -- submitted constitution hash
364+
-> String -- submitted guard rail script hash
340365
-> AnyNewEpochState
341-
-> StateT () IO LedgerStateCondition -- ^ Accumulator at block i and fold status
342-
checkConstitutionWasRatified submittedConstitutionHash (AnyNewEpochState sbe newEpochState) = do
343-
caseShelleyToBabbageOrConwayEraOnwards
344-
(const $ error "checkConstitutionWasRatified: Only Conway era supported")
345-
(const $ do
346-
let ratifyState = L.extractDRepPulsingState (newEpochState ^. L.newEpochStateDRepPulsingStateL)
347-
if filterRatificationState submittedConstitutionHash ratifyState
348-
then return ConditionMet
349-
else return ConditionNotMet
350-
)
351-
sbe
366+
-> StateT s IO LedgerStateCondition -- ^ Accumulator at block i and fold status
367+
foldBlocksCheckConstitutionWasRatified submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState =
368+
if filterRatificationState submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState
369+
then return ConditionMet
370+
else return ConditionNotMet
352371

353372
-- cgsDRepPulsingStateL . ratifyStateL
354373
filterRatificationState
355374
:: String -- ^ Submitted constitution anchor hash
356-
-> L.RatifyState (ShelleyLedgerEra era)
375+
-> String -- ^ Submitted guard rail script hash
376+
-> AnyNewEpochState
357377
-> Bool
358-
filterRatificationState c rState =
359-
let constitutionAnchorHash = Ledger.anchorDataHash $ Ledger.constitutionAnchor (rState ^. Ledger.rsEnactStateL . Ledger.ensConstitutionL)
360-
in Text.pack c == renderSafeHashAsHex constitutionAnchorHash
378+
filterRatificationState c guardRailScriptHash (AnyNewEpochState sbe newEpochState) =
379+
caseShelleyToBabbageOrConwayEraOnwards
380+
(const $ error "filterRatificationState: Only conway era supported")
381+
382+
(const $ do
383+
let rState = Ledger.extractDRepPulsingState $ newEpochState ^. L.newEpochStateGovStateL . L.drepPulsingStateGovStateL
384+
constitution = rState ^. Ledger.rsEnactStateL . Ledger.ensConstitutionL
385+
constitutionAnchorHash = Ledger.anchorDataHash $ Ledger.constitutionAnchor constitution
386+
L.ScriptHash constitutionScriptHash = fromMaybe (error "filterRatificationState: consitution does not have a guardrail script")
387+
$ strictMaybeToMaybe $ constitution ^. Ledger.constitutionScriptL
388+
Text.pack c == renderSafeHashAsHex constitutionAnchorHash && L.hashToTextAsHex constitutionScriptHash == Text.pack guardRailScriptHash
389+
390+
)
391+
sbe
392+

cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import qualified Cardano.Testnet.Test.Cli.Conway.Plutus
1313
import qualified Cardano.Testnet.Test.Cli.KesPeriodInfo
1414
import qualified Cardano.Testnet.Test.Cli.QuerySlotNumber
1515
import qualified Cardano.Testnet.Test.FoldBlocks
16+
import qualified Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitution
1617
import qualified Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitutionSPO as LedgerEvents
1718
import qualified Cardano.Testnet.Test.LedgerEvents.SanityCheck as LedgerEvents
1819
import qualified Cardano.Testnet.Test.LedgerEvents.TreasuryGrowth as LedgerEvents
@@ -40,10 +41,10 @@ tests = do
4041
, H.ignoreOnWindows "Treasury Growth" LedgerEvents.prop_check_if_treasury_is_growing
4142
-- TODO: Replace foldBlocks with checkLedgerStateCondition
4243
, testGroup "Governance"
43-
-- FIXME Those tests are flaky
44-
[ -- H.ignoreOnMacAndWindows "ProposeAndRatifyNewConstitution" LedgerEvents.hprop_ledger_events_propose_new_constitution
44+
[ H.ignoreOnMacAndWindows "ProposeAndRatifyNewConstitution" Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitution.hprop_ledger_events_propose_new_constitution
45+
-- FIXME Those tests are flaky
4546
-- , H.ignoreOnWindows "InfoAction" LedgerEvents.hprop_ledger_events_info_action
46-
H.ignoreOnWindows "ProposeNewConstitutionSPO" LedgerEvents.hprop_ledger_events_propose_new_constitution_spo
47+
, H.ignoreOnWindows "ProposeNewConstitutionSPO" LedgerEvents.hprop_ledger_events_propose_new_constitution_spo
4748
, H.ignoreOnWindows "DRepRetirement" DRepRetirement.hprop_drep_retirement
4849
]
4950
, testGroup "Plutus"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "PlutusScriptV3",
3+
"description": "",
4+
"cborHex": "4746010100228001"
5+
}

0 commit comments

Comments
 (0)