Skip to content

Commit b83499e

Browse files
iohk-bors[bot]cblp
andauthored
Merge #3208
3208: Add update proposal friendly rendering r=cblp a=cblp Including Alonzo-specific updates Co-authored-by: Yuriy Syrovetskiy <[email protected]>
2 parents cbdc6b5 + e6a2195 commit b83499e

File tree

7 files changed

+258
-16
lines changed

7 files changed

+258
-16
lines changed

cardano-cli/src/Cardano/CLI/Run/Friendly.hs

+92-1
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,104 @@ friendlyStakeReference = \case
150150
friendlyUpdateProposal :: TxUpdateProposal era -> Aeson.Value
151151
friendlyUpdateProposal = \case
152152
TxUpdateProposalNone -> Null
153-
TxUpdateProposal _ p -> String $ textShow p
153+
TxUpdateProposal _ (UpdateProposal parameterUpdates epoch) ->
154+
object
155+
[ "epoch" .= epoch
156+
, "updates" .=
157+
[ object
158+
[ "genesis key hash" .= serialiseToRawBytesHexText genesisKeyHash
159+
, "update" .= friendlyProtocolParametersUpdate parameterUpdate
160+
]
161+
| (genesisKeyHash, parameterUpdate) <- Map.assocs parameterUpdates
162+
]
163+
]
164+
165+
friendlyProtocolParametersUpdate :: ProtocolParametersUpdate -> Aeson.Value
166+
friendlyProtocolParametersUpdate
167+
ProtocolParametersUpdate
168+
{ protocolUpdateProtocolVersion
169+
, protocolUpdateDecentralization
170+
, protocolUpdateExtraPraosEntropy
171+
, protocolUpdateMaxBlockHeaderSize
172+
, protocolUpdateMaxBlockBodySize
173+
, protocolUpdateMaxTxSize
174+
, protocolUpdateTxFeeFixed
175+
, protocolUpdateTxFeePerByte
176+
, protocolUpdateMinUTxOValue
177+
, protocolUpdateStakeAddressDeposit
178+
, protocolUpdateStakePoolDeposit
179+
, protocolUpdateMinPoolCost
180+
, protocolUpdatePoolRetireMaxEpoch
181+
, protocolUpdateStakePoolTargetNum
182+
, protocolUpdatePoolPledgeInfluence
183+
, protocolUpdateMonetaryExpansion
184+
, protocolUpdateTreasuryCut
185+
, protocolUpdateUTxOCostPerWord
186+
, protocolUpdateCollateralPercent
187+
, protocolUpdateMaxBlockExUnits
188+
, protocolUpdateMaxCollateralInputs
189+
, protocolUpdateMaxTxExUnits
190+
, protocolUpdateMaxValueSize
191+
, protocolUpdatePrices
192+
} =
193+
object . catMaybes $
194+
[ protocolUpdateProtocolVersion <&> \(major, minor) ->
195+
"protocol version" .= (textShow major <> "." <> textShow minor)
196+
, protocolUpdateDecentralization <&>
197+
("decentralization parameter" .=) . friendlyRational
198+
, protocolUpdateExtraPraosEntropy <&>
199+
("extra entropy" .=) . maybe "reset" toJSON
200+
, protocolUpdateMaxBlockHeaderSize <&> ("max block header size" .=)
201+
, protocolUpdateMaxBlockBodySize<&> ("max block body size" .=)
202+
, protocolUpdateMaxTxSize <&> ("max transaction size" .=)
203+
, protocolUpdateTxFeeFixed <&> ("transaction fee constant" .=)
204+
, protocolUpdateTxFeePerByte <&> ("transaction fee linear per byte" .=)
205+
, protocolUpdateMinUTxOValue <&> ("min UTxO value" .=) . friendlyLovelace
206+
, protocolUpdateStakeAddressDeposit <&>
207+
("key registration deposit" .=) . friendlyLovelace
208+
, protocolUpdateStakePoolDeposit <&>
209+
("pool registration deposit" .=) . friendlyLovelace
210+
, protocolUpdateMinPoolCost <&> ("min pool cost" .=) . friendlyLovelace
211+
, protocolUpdatePoolRetireMaxEpoch <&> ("pool retirement epoch boundary" .=)
212+
, protocolUpdateStakePoolTargetNum <&> ("number of pools" .=)
213+
, protocolUpdatePoolPledgeInfluence <&>
214+
("pool influence" .=) . friendlyRational
215+
, protocolUpdateMonetaryExpansion <&>
216+
("monetary expansion" .=) . friendlyRational
217+
, protocolUpdateTreasuryCut <&> ("treasury expansion" .=) . friendlyRational
218+
, protocolUpdateUTxOCostPerWord <&>
219+
("UTxO storage cost per unit" .=) . friendlyLovelace
220+
, protocolUpdateCollateralPercent <&>
221+
("collateral inputs share" .=) . (<> "%") . textShow
222+
, protocolUpdateMaxBlockExUnits <&> ("max block execution units" .=)
223+
, protocolUpdateMaxCollateralInputs <&> ("max collateral inputs" .=)
224+
, protocolUpdateMaxTxExUnits <&> ("max transaction execution units" .=)
225+
, protocolUpdateMaxValueSize <&> ("max value size" .=)
226+
, protocolUpdatePrices <&> ("execution prices" .=) . friendlyPrices
227+
]
228+
229+
friendlyPrices :: ExecutionUnitPrices -> Aeson.Value
230+
friendlyPrices ExecutionUnitPrices{priceExecutionMemory, priceExecutionSteps} =
231+
object
232+
[ "memory" .= friendlyRational priceExecutionMemory
233+
, "steps" .= friendlyRational priceExecutionSteps
234+
]
154235

155236
friendlyCertificates :: TxCertificates ViewTx era -> Aeson.Value
156237
friendlyCertificates = \case
157238
TxCertificatesNone -> Null
158239
TxCertificates _ cs _ -> toJSON $ map textShow cs
159240

241+
friendlyRational :: Rational -> Aeson.Value
242+
friendlyRational r =
243+
String $
244+
case d of
245+
1 -> textShow n
246+
_ -> textShow n <> "/" <> textShow d
247+
where
248+
n = numerator r
249+
d = denominator r
250+
160251
friendlyFee :: TxFee era -> Aeson.Value
161252
friendlyFee = \case
162253
TxFeeImplicit _ -> "implicit"

cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ pPoolMargin :: Parser Rational
24312431
pPoolMargin =
24322432
Opt.option readRationalUnitInterval
24332433
( Opt.long "pool-margin"
2434-
<> Opt.metavar "DOUBLE"
2434+
<> Opt.metavar "RATIONAL"
24352435
<> Opt.help "The stake pool's margin."
24362436
)
24372437

@@ -2683,31 +2683,31 @@ pPoolInfluence :: Parser Rational
26832683
pPoolInfluence =
26842684
Opt.option readRational
26852685
( Opt.long "pool-influence"
2686-
<> Opt.metavar "DOUBLE"
2686+
<> Opt.metavar "RATIONAL"
26872687
<> Opt.help "Pool influence."
26882688
)
26892689

26902690
pTreasuryExpansion :: Parser Rational
26912691
pTreasuryExpansion =
26922692
Opt.option readRationalUnitInterval
26932693
( Opt.long "treasury-expansion"
2694-
<> Opt.metavar "DOUBLE"
2694+
<> Opt.metavar "RATIONAL"
26952695
<> Opt.help "Treasury expansion."
26962696
)
26972697

26982698
pMonetaryExpansion :: Parser Rational
26992699
pMonetaryExpansion =
27002700
Opt.option readRationalUnitInterval
27012701
( Opt.long "monetary-expansion"
2702-
<> Opt.metavar "DOUBLE"
2702+
<> Opt.metavar "RATIONAL"
27032703
<> Opt.help "Monetary expansion."
27042704
)
27052705

27062706
pDecentralParam :: Parser Rational
27072707
pDecentralParam =
27082708
Opt.option readRationalUnitInterval
27092709
( Opt.long "decentralization-parameter"
2710-
<> Opt.metavar "DOUBLE"
2710+
<> Opt.metavar "RATIONAL"
27112711
<> Opt.help "Decentralization parameter."
27122712
)
27132713

@@ -2716,7 +2716,7 @@ pExtraEntropy =
27162716
Opt.option (Just <$> readerFromParsecParser parsePraosNonce)
27172717
( Opt.long "extra-entropy"
27182718
<> Opt.metavar "HEX"
2719-
<> Opt.help "Praos extra entropy, as a hex byte string."
2719+
<> Opt.help "Praos extra entropy seed, as a hex byte string."
27202720
)
27212721
<|> Opt.flag' Nothing
27222722
( Opt.long "reset-extra-entropy"

cardano-cli/test/Test/Golden/TxView.hs

+93-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Test.Golden.TxView (txViewTests) where
55
import Cardano.Prelude
66

77
import Hedgehog (Group (..), Property, checkSequential)
8-
import Hedgehog.Extras.Test.Base (moduleWorkspace, propertyOnce)
8+
import Hedgehog.Extras (moduleWorkspace, note_, propertyOnce)
99

1010
import Test.OptParse (execCardanoCLI, noteTempFile)
1111
import Test.Utilities (diffVsGoldenFile)
@@ -16,11 +16,11 @@ txViewTests :: IO Bool
1616
txViewTests =
1717
checkSequential $
1818
Group "`transaction view` Goldens"
19-
[ ("golden_view_byron", golden_view_byron)
19+
[ ("golden_view_byron", golden_view_byron)
2020
, ("golden_view_shelley", golden_view_shelley)
2121
, ("golden_view_allegra", golden_view_allegra)
22-
, ("golden_view_mary", golden_view_mary)
23-
-- , ("golden_view_alonzo", golden_view_alonzo)
22+
, ("golden_view_mary", golden_view_mary)
23+
, ("golden_view_alonzo", golden_view_alonzo)
2424
]
2525

2626
golden_view_byron :: Property
@@ -53,7 +53,46 @@ golden_view_shelley :: Property
5353
golden_view_shelley =
5454
propertyOnce $
5555
moduleWorkspace "tmp" $ \tempDir -> do
56-
transactionBodyFile <- noteTempFile tempDir "transaction-body-file"
56+
updateProposalFile <- noteTempFile tempDir "update-proposal"
57+
transactionBodyFile <- noteTempFile tempDir "transaction-body"
58+
59+
let extraEntropySeed = "c0ffee"
60+
note_ $ "extra entropy seed: " ++ extraEntropySeed
61+
note_
62+
"extra entropy hash:\
63+
\ 88f04f011dcded879039ae4b9b20219d9448e5c7b42c2d1f638fb8740e0ab8be"
64+
65+
note_
66+
"genesis-verification-key-file hash:\
67+
\ 81cb0bc5b6fbba391e6f7ec3d9271cbea25bcbf907181b7c4d5f8c2f"
68+
69+
-- Create update proposal
70+
void $
71+
execCardanoCLI
72+
[ "governance", "create-update-proposal"
73+
, "--decentralization-parameter", "63/64"
74+
, "--epoch", "64"
75+
, "--extra-entropy", extraEntropySeed
76+
, "--genesis-verification-key-file"
77+
, "test/data/golden/shelley/keys/genesis_keys/verification_key"
78+
, "--key-reg-deposit-amt", "71"
79+
, "--max-block-body-size", "72"
80+
, "--max-block-header-size", "73"
81+
, "--max-tx-size", "74"
82+
, "--min-fee-constant", "75"
83+
, "--min-fee-linear", "76"
84+
, "--min-pool-cost", "77"
85+
, "--min-utxo-value", "78"
86+
, "--monetary-expansion", "79/80"
87+
, "--number-of-pools", "80"
88+
, "--out-file", updateProposalFile
89+
, "--pool-influence", "82/83"
90+
, "--pool-reg-deposit", "83"
91+
, "--pool-retirement-epoch-boundary", "84"
92+
, "--protocol-major-version", "85"
93+
, "--protocol-minor-version", "86"
94+
, "--treasury-expansion", "87/88"
95+
]
5796

5897
-- Create transaction body
5998
void $
@@ -70,6 +109,7 @@ golden_view_shelley =
70109
, "--withdrawal"
71110
, "stake_test1up00fz9lyqs5sjks82k22eqz7a9srym9vysjgp3h2ua2v2cm522kg\
72111
\+42"
112+
, "--update-proposal-file", updateProposalFile
73113
, "--out-file", transactionBodyFile
74114
]
75115

@@ -173,3 +213,51 @@ golden_view_mary =
173213
execCardanoCLI
174214
["transaction", "view", "--tx-body-file", transactionBodyFile]
175215
diffVsGoldenFile result "test/data/golden/mary/transaction-view.out"
216+
217+
golden_view_alonzo :: Property
218+
golden_view_alonzo =
219+
propertyOnce $
220+
moduleWorkspace "tmp" $ \tempDir -> do
221+
updateProposalFile <- noteTempFile tempDir "update-proposal"
222+
transactionBodyFile <- noteTempFile tempDir "transaction-body"
223+
224+
note_
225+
"genesis-verification-key-file hash:\
226+
\ 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114"
227+
228+
-- Create update proposal
229+
void $
230+
execCardanoCLI
231+
[ "governance", "create-update-proposal"
232+
, "--epoch", "190"
233+
, "--genesis-verification-key-file"
234+
, "test/data/golden/shelley/keys/genesis_keys/verification_key"
235+
, "--utxo-cost-per-word", "194"
236+
, "--price-execution-steps", "195/196"
237+
, "--price-execution-memory", "196/197"
238+
, "--max-tx-execution-units", "(197, 198)"
239+
, "--max-block-execution-units", "(198, 199)"
240+
, "--max-value-size", "199"
241+
, "--collateral-percent", "200"
242+
, "--max-collateral-inputs", "201"
243+
, "--out-file", updateProposalFile
244+
]
245+
246+
-- Create transaction body
247+
void $
248+
execCardanoCLI
249+
[ "transaction", "build-raw"
250+
, "--alonzo-era"
251+
, "--tx-in"
252+
, "ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20\
253+
\#212"
254+
, "--fee", "213"
255+
, "--update-proposal-file", updateProposalFile
256+
, "--out-file", transactionBodyFile
257+
]
258+
259+
-- View transaction body
260+
result <-
261+
execCardanoCLI
262+
["transaction", "view", "--tx-body-file", transactionBodyFile]
263+
diffVsGoldenFile result "test/data/golden/alonzo/transaction-view.out"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
auxiliary scripts: null
2+
certificates: null
3+
era: Alonzo
4+
fee: 213 Lovelace
5+
inputs:
6+
- ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20#212
7+
metadata: null
8+
mint: null
9+
outputs: []
10+
update proposal:
11+
epoch: 190
12+
updates:
13+
- genesis key hash: 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114
14+
update:
15+
UTxO storage cost per unit: 194 Lovelace
16+
collateral inputs share: 200%
17+
execution prices:
18+
memory: 196/197
19+
steps: 195/196
20+
max block execution units:
21+
memory: 199
22+
steps: 198
23+
max collateral inputs: 201
24+
max transaction execution units:
25+
memory: 198
26+
steps: 197
27+
max value size: 199
28+
validity range:
29+
lower bound: null
30+
upper bound: null
31+
withdrawals: null

cardano-cli/test/data/golden/shelley/transaction-view.out

+22-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,28 @@ outputs:
1414
payment credential:
1515
key hash: bce78cb90f6da9ee778ef07ca881b489c38a188993e6870bd5a9ef77
1616
stake reference: null
17-
update proposal: null
17+
update proposal:
18+
epoch: 64
19+
updates:
20+
- genesis key hash: 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114
21+
update:
22+
decentralization parameter: 63/64
23+
extra entropy: 88f04f011dcded879039ae4b9b20219d9448e5c7b42c2d1f638fb8740e0ab8be
24+
key registration deposit: 71 Lovelace
25+
max block body size: 72
26+
max block header size: 73
27+
max transaction size: 74
28+
min UTxO value: 78 Lovelace
29+
min pool cost: 77 Lovelace
30+
monetary expansion: 79/80
31+
number of pools: 80
32+
pool influence: 82/83
33+
pool registration deposit: 83 Lovelace
34+
pool retirement epoch boundary: 84
35+
protocol version: '85.86'
36+
transaction fee constant: 75
37+
transaction fee linear per byte: 76
38+
treasury expansion: 87/88
1839
validity range:
1940
time to live: 33
2041
withdrawals:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "UpdateProposalShelley",
3+
"description": "",
4+
"cborHex": "82a1581ca2512fa96a5f51d7aa8b8558669561fdd905f505ad7e0f4047b15c9eb100197a6601197a6702197a6e03197a6804197a6d05197a6406197a6307197a6108197a6009d81e82197a5f1903e80ad81e82197a5b1a000186a00bd81e82197a591a000186a00cd81e82197a6f1a000186a00d82015820ee32869218e317d16b9cba9e8f0737e23a6c9328e71068f161e5cc3cf54c45be0e82197a6a197a6b0f197a6510197a62197a69"
5+
}

scripts/reconfigure-hlint.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
#
88
# To use, simply run the script from the project's top-level directory.
99

10+
UNAME=$(uname -s) SED=
11+
case $UNAME in
12+
Darwin ) SED="gsed";;
13+
Linux ) SED="sed";;
14+
esac
15+
1016
extract_rules() {
1117
for x in $(find . -type f -name '*.hs' | grep -v dist); do
1218
module="$(grep '^module' $x | cut -d ' ' -f 2 | head -n 1)"
1319
grep '{- HLINT ignore "' $x | cut -d '"' -f 2 | \
14-
sed "s|^|$module,|g"
20+
$SED "s|^|$module,|g"
1521
done
1622
}
1723

@@ -29,6 +35,6 @@ gen_rules() {
2935
echo "# This file is generated from .hlint.template.yaml by scripts/reconfigure-hlint.sh"
3036
echo ""
3137
cat .hlint.template.yaml \
32-
| sed '/^# BEGIN-GENERATED/,/^# END-GENERATED/{/^# BEGIN-GENERATED/!{/^# END-GENERATED/!d}}' \
33-
| gsed -e "/^# BEGIN-GENERATED/ r "<(gen_rules)
38+
| $SED '/^# BEGIN-GENERATED/,/^# END-GENERATED/{/^# BEGIN-GENERATED/!{/^# END-GENERATED/!d}}' \
39+
| $SED -e "/^# BEGIN-GENERATED/ r "<(gen_rules)
3440
) > ".hlint.yaml"

0 commit comments

Comments
 (0)