From 0e6cc560e65f68cce037e78aba3e02444ab8eb1e Mon Sep 17 00:00:00 2001 From: Ziyang Liu Date: Sat, 13 Jan 2024 11:04:00 -0800 Subject: [PATCH] Update the `NewCommittee` variant of `GovernanceAction` to `UpdateCommittee` (#5718) --- .../test/9.6/checkScriptContext1.pir.golden | 154 +++++++----------- .../test/9.6/checkScriptContext1.size.golden | 2 +- .../test/9.6/checkScriptContext2.pir.golden | 154 +++++++----------- .../test/9.6/checkScriptContext2.size.golden | 2 +- .../20240113_070604_unsafeFixIO_sc.md | 4 + plutus-ledger-api/src/PlutusLedgerApi/V3.hs | 11 +- .../src/PlutusLedgerApi/V3/Contexts.hs | 17 +- 7 files changed, 140 insertions(+), 204 deletions(-) create mode 100644 plutus-ledger-api/changelog.d/20240113_070604_unsafeFixIO_sc.md diff --git a/plutus-benchmark/script-contexts/test/9.6/checkScriptContext1.pir.golden b/plutus-benchmark/script-contexts/test/9.6/checkScriptContext1.pir.golden index 6bcb2031e0e..5ca387a716e 100644 --- a/plutus-benchmark/script-contexts/test/9.6/checkScriptContext1.pir.golden +++ b/plutus-benchmark/script-contexts/test/9.6/checkScriptContext1.pir.golden @@ -233,22 +233,14 @@ Unit in \(d : data) -> go (unMapData d) - data Rational | Rational_match where - Rational : integer -> integer -> Rational - data Committee | Committee_match where - Committee : - (\k v -> List (Tuple2 k v)) Credential integer -> Rational -> Committee data ProtocolVersion | ProtocolVersion_match where ProtocolVersion : integer -> integer -> ProtocolVersion + data Rational | Rational_match where + Rational : integer -> integer -> Rational data GovernanceAction | GovernanceAction_match where HardForkInitiation : Maybe GovernanceActionId -> ProtocolVersion -> GovernanceAction InfoAction : GovernanceAction - NewCommittee : - Maybe GovernanceActionId -> - List Credential -> - Committee -> - GovernanceAction NewConstitution : Maybe GovernanceActionId -> Maybe bytestring -> GovernanceAction NoConfidence : Maybe GovernanceActionId -> GovernanceAction @@ -258,6 +250,12 @@ (\k v -> List (Tuple2 k v)) Credential integer -> Maybe bytestring -> GovernanceAction + UpdateCommittee : + Maybe GovernanceActionId -> + List Credential -> + (\k v -> List (Tuple2 k v)) Credential integer -> + Rational -> + GovernanceAction data ProposalProcedure | ProposalProcedure_match where ProposalProcedure : integer -> Credential -> GovernanceAction -> ProposalProcedure @@ -407,8 +405,9 @@ let !l : list data = tailList {data} args + !l : list data = tailList {data} l in - NewCommittee + UpdateCommittee (`$fUnsafeFromDataMaybe_$cunsafeFromBuiltinData` {GovernanceActionId} `$fUnsafeFromDataGovernanceAction_$cunsafeFromBuiltinData` @@ -417,98 +416,59 @@ {Credential} `$fUnsafeFromDataCredential_$cunsafeFromBuiltinData` (headList {data} l)) + (`$fUnsafeFromDataMap_$cunsafeFromBuiltinData` + {Credential} + {integer} + `$fUnsafeFromDataCredential_$cunsafeFromBuiltinData` + unIData + (headList {data} l)) (let - !tup : pair integer (list data) - = unConstrData - (headList - {data} - (tailList {data} l)) - !index : integer - = fstPair - {integer} - {list data} - tup - !args : list data - = sndPair - {integer} - {list data} - tup + !x : data + = headList + {data} + (tailList {data} l) in - ifThenElse - {all dead. Committee} - (equalsInteger 0 index) - (/\dead -> - Committee - (`$fUnsafeFromDataMap_$cunsafeFromBuiltinData` - {Credential} + Tuple2_match + {integer} + {integer} + (let + !tup : pair integer (list data) + = unConstrData x + !index : integer + = fstPair {integer} - `$fUnsafeFromDataCredential_$cunsafeFromBuiltinData` - unIData - (headList {data} args)) - (let - !x : data - = headList + {list data} + tup + !args : list data + = sndPair + {integer} + {list data} + tup + in + ifThenElse + {all dead. + Tuple2 integer integer} + (equalsInteger 0 index) + (/\dead -> + Tuple2 + {integer} + {integer} + (unIData + (headList {data} args)) + (unIData + (headList {data} (tailList {data} - args) - in - Tuple2_match - {integer} - {integer} - (let - !tup : - pair - integer - (list data) - = unConstrData x - !index : integer - = fstPair - {integer} - {list data} - tup - !args : list data - = sndPair - {integer} - {list data} - tup - in - ifThenElse - {all dead. - Tuple2 - integer - integer} - (equalsInteger 0 index) - (/\dead -> - Tuple2 - {integer} - {integer} - (unIData - (headList - {data} - args)) - (unIData - (headList - {data} - (tailList - {data} - args)))) - (/\dead -> - traceError - {Tuple2 - integer - integer} - reconstructCaseError) - {all dead. dead}) - {Rational} - (\(a : integer) - (b : integer) -> - unsafeRatio a b))) - (/\dead -> - traceError - {Committee} - reconstructCaseError) - {all dead. dead})) + args)))) + (/\dead -> + traceError + {Tuple2 integer integer} + reconstructCaseError) + {all dead. dead}) + {Rational} + (\(a : integer) (b : integer) -> + unsafeRatio a b))) (/\dead -> ifThenElse {all dead. GovernanceAction} diff --git a/plutus-benchmark/script-contexts/test/9.6/checkScriptContext1.size.golden b/plutus-benchmark/script-contexts/test/9.6/checkScriptContext1.size.golden index 4f5a05a7169..633e3dc28dd 100644 --- a/plutus-benchmark/script-contexts/test/9.6/checkScriptContext1.size.golden +++ b/plutus-benchmark/script-contexts/test/9.6/checkScriptContext1.size.golden @@ -1 +1 @@ -2869 \ No newline at end of file +2833 \ No newline at end of file diff --git a/plutus-benchmark/script-contexts/test/9.6/checkScriptContext2.pir.golden b/plutus-benchmark/script-contexts/test/9.6/checkScriptContext2.pir.golden index aae40b8fe82..abf14022a76 100644 --- a/plutus-benchmark/script-contexts/test/9.6/checkScriptContext2.pir.golden +++ b/plutus-benchmark/script-contexts/test/9.6/checkScriptContext2.pir.golden @@ -202,22 +202,14 @@ Unit in \(d : data) -> go (unMapData d) - data Rational | Rational_match where - Rational : integer -> integer -> Rational - data Committee | Committee_match where - Committee : - (\k v -> List (Tuple2 k v)) Credential integer -> Rational -> Committee data ProtocolVersion | ProtocolVersion_match where ProtocolVersion : integer -> integer -> ProtocolVersion + data Rational | Rational_match where + Rational : integer -> integer -> Rational data GovernanceAction | GovernanceAction_match where HardForkInitiation : Maybe GovernanceActionId -> ProtocolVersion -> GovernanceAction InfoAction : GovernanceAction - NewCommittee : - Maybe GovernanceActionId -> - List Credential -> - Committee -> - GovernanceAction NewConstitution : Maybe GovernanceActionId -> Maybe bytestring -> GovernanceAction NoConfidence : Maybe GovernanceActionId -> GovernanceAction @@ -227,6 +219,12 @@ (\k v -> List (Tuple2 k v)) Credential integer -> Maybe bytestring -> GovernanceAction + UpdateCommittee : + Maybe GovernanceActionId -> + List Credential -> + (\k v -> List (Tuple2 k v)) Credential integer -> + Rational -> + GovernanceAction data ProposalProcedure | ProposalProcedure_match where ProposalProcedure : integer -> Credential -> GovernanceAction -> ProposalProcedure @@ -376,8 +374,9 @@ let !l : list data = tailList {data} args + !l : list data = tailList {data} l in - NewCommittee + UpdateCommittee (`$fUnsafeFromDataMaybe_$cunsafeFromBuiltinData` {GovernanceActionId} `$fUnsafeFromDataGovernanceAction_$cunsafeFromBuiltinData` @@ -386,98 +385,59 @@ {Credential} `$fUnsafeFromDataCredential_$cunsafeFromBuiltinData` (headList {data} l)) + (`$fUnsafeFromDataMap_$cunsafeFromBuiltinData` + {Credential} + {integer} + `$fUnsafeFromDataCredential_$cunsafeFromBuiltinData` + unIData + (headList {data} l)) (let - !tup : pair integer (list data) - = unConstrData - (headList - {data} - (tailList {data} l)) - !index : integer - = fstPair - {integer} - {list data} - tup - !args : list data - = sndPair - {integer} - {list data} - tup + !x : data + = headList + {data} + (tailList {data} l) in - ifThenElse - {all dead. Committee} - (equalsInteger 0 index) - (/\dead -> - Committee - (`$fUnsafeFromDataMap_$cunsafeFromBuiltinData` - {Credential} + Tuple2_match + {integer} + {integer} + (let + !tup : pair integer (list data) + = unConstrData x + !index : integer + = fstPair {integer} - `$fUnsafeFromDataCredential_$cunsafeFromBuiltinData` - unIData - (headList {data} args)) - (let - !x : data - = headList + {list data} + tup + !args : list data + = sndPair + {integer} + {list data} + tup + in + ifThenElse + {all dead. + Tuple2 integer integer} + (equalsInteger 0 index) + (/\dead -> + Tuple2 + {integer} + {integer} + (unIData + (headList {data} args)) + (unIData + (headList {data} (tailList {data} - args) - in - Tuple2_match - {integer} - {integer} - (let - !tup : - pair - integer - (list data) - = unConstrData x - !index : integer - = fstPair - {integer} - {list data} - tup - !args : list data - = sndPair - {integer} - {list data} - tup - in - ifThenElse - {all dead. - Tuple2 - integer - integer} - (equalsInteger 0 index) - (/\dead -> - Tuple2 - {integer} - {integer} - (unIData - (headList - {data} - args)) - (unIData - (headList - {data} - (tailList - {data} - args)))) - (/\dead -> - traceError - {Tuple2 - integer - integer} - reconstructCaseError) - {all dead. dead}) - {Rational} - (\(a : integer) - (b : integer) -> - unsafeRatio a b))) - (/\dead -> - traceError - {Committee} - reconstructCaseError) - {all dead. dead})) + args)))) + (/\dead -> + traceError + {Tuple2 integer integer} + reconstructCaseError) + {all dead. dead}) + {Rational} + (\(a : integer) (b : integer) -> + unsafeRatio a b))) (/\dead -> ifThenElse {all dead. GovernanceAction} diff --git a/plutus-benchmark/script-contexts/test/9.6/checkScriptContext2.size.golden b/plutus-benchmark/script-contexts/test/9.6/checkScriptContext2.size.golden index 92370c57a04..80863af5046 100644 --- a/plutus-benchmark/script-contexts/test/9.6/checkScriptContext2.size.golden +++ b/plutus-benchmark/script-contexts/test/9.6/checkScriptContext2.size.golden @@ -1 +1 @@ -2809 \ No newline at end of file +2773 \ No newline at end of file diff --git a/plutus-ledger-api/changelog.d/20240113_070604_unsafeFixIO_sc.md b/plutus-ledger-api/changelog.d/20240113_070604_unsafeFixIO_sc.md new file mode 100644 index 00000000000..30d1f35aac8 --- /dev/null +++ b/plutus-ledger-api/changelog.d/20240113_070604_unsafeFixIO_sc.md @@ -0,0 +1,4 @@ + +### Changed + +- Updated the `NewCommittee` variant of `GovernanceAction` to `UpdateCommittee`. diff --git a/plutus-ledger-api/src/PlutusLedgerApi/V3.hs b/plutus-ledger-api/src/PlutusLedgerApi/V3.hs index 25ff3a0b135..b7dbc94c8b9 100644 --- a/plutus-ledger-api/src/PlutusLedgerApi/V3.hs +++ b/plutus-ledger-api/src/PlutusLedgerApi/V3.hs @@ -28,6 +28,7 @@ module PlutusLedgerApi.V3 ( GovernanceActionId (..), Committee (..), Constitution (..), + ProtocolVersion (..), GovernanceAction (..), ChangedParameters (..), ProposalProcedure (..), @@ -111,6 +112,12 @@ module PlutusLedgerApi.V3 ( V2.strictLowerBound, V2.strictUpperBound, + -- *** Ratio + Ratio.Rational, + Ratio.ratio, + Ratio.fromGHC, + Ratio.toGHC, + -- *** Association maps V2.Map, V2.fromList, @@ -138,6 +145,7 @@ module PlutusLedgerApi.V3 ( V2.ScriptDecodeError (..), ) where +import PlutusCore.Data qualified as PLC import PlutusLedgerApi.Common as Common hiding (deserialiseScript, evaluateScriptCounting, evaluateScriptRestricting) import PlutusLedgerApi.Common qualified as Common (deserialiseScript, evaluateScriptCounting, @@ -147,8 +155,7 @@ import PlutusLedgerApi.V2 qualified as V2 hiding (ScriptContext (..), ScriptPurp import PlutusLedgerApi.V3.Contexts import PlutusLedgerApi.V3.EvaluationContext import PlutusLedgerApi.V3.ParamName - -import PlutusCore.Data qualified as PLC +import PlutusTx.Ratio qualified as Ratio import Control.Monad.Except (MonadError) diff --git a/plutus-ledger-api/src/PlutusLedgerApi/V3/Contexts.hs b/plutus-ledger-api/src/PlutusLedgerApi/V3/Contexts.hs index d6e04387b25..b65896aa7cd 100644 --- a/plutus-ledger-api/src/PlutusLedgerApi/V3/Contexts.hs +++ b/plutus-ledger-api/src/PlutusLedgerApi/V3/Contexts.hs @@ -21,6 +21,7 @@ import PlutusLedgerApi.V2 qualified as V2 import PlutusTx qualified import PlutusTx.AssocMap hiding (filter, mapMaybe) import PlutusTx.Prelude qualified as PlutusTx +import PlutusTx.Ratio (Rational) import Prelude qualified as Haskell @@ -271,10 +272,11 @@ data GovernanceAction (Map V2.Credential V2.Lovelace) (Haskell.Maybe V2.ScriptHash) -- ^ Hash of the constitution script | NoConfidence (Haskell.Maybe GovernanceActionId) - | NewCommittee + | UpdateCommittee (Haskell.Maybe GovernanceActionId) - [ColdCommitteeCredential] -- ^ Old committee - Committee -- ^ New Committee + [ColdCommitteeCredential] -- ^ Committee members to be removed + (Map ColdCommitteeCredential Haskell.Integer) -- ^ Committee members to be added + Rational -- ^ New quorum | NewConstitution (Haskell.Maybe GovernanceActionId) Constitution | InfoAction deriving stock (Generic, Haskell.Show, Haskell.Eq) @@ -289,8 +291,11 @@ instance PlutusTx.Eq GovernanceAction where TreasuryWithdrawals a b == TreasuryWithdrawals a' b' = a PlutusTx.== a' PlutusTx.&& b PlutusTx.== b' NoConfidence a == NoConfidence a' = a PlutusTx.== a' - NewCommittee a b c == NewCommittee a' b' c' = - a PlutusTx.== a' PlutusTx.&& b PlutusTx.== b' PlutusTx.&& c PlutusTx.== c' + UpdateCommittee a b c d == UpdateCommittee a' b' c' d' = + a PlutusTx.== a' + PlutusTx.&& b PlutusTx.== b' + PlutusTx.&& c PlutusTx.== c' + PlutusTx.&& d PlutusTx.== d' NewConstitution a b == NewConstitution a' b' = a PlutusTx.== a' PlutusTx.&& b PlutusTx.== b' InfoAction == InfoAction = Haskell.True @@ -643,7 +648,7 @@ PlutusTx.makeIsDataIndexed , ('HardForkInitiation, 1) , ('TreasuryWithdrawals, 2) , ('NoConfidence, 3) - , ('NewCommittee, 4) + , ('UpdateCommittee, 4) , ('NewConstitution, 5) , ('InfoAction, 6) ]