Skip to content

Commit

Permalink
Merge #3208
Browse files Browse the repository at this point in the history
3208: Add update proposal friendly rendering r=cblp a=cblp

Including Alonzo-specific updates

Co-authored-by: Yuriy Syrovetskiy <yuriy.syrovetskiy@iohk.io>
  • Loading branch information
iohk-bors[bot] and cblp committed Jan 18, 2022
2 parents cbdc6b5 + e6a2195 commit b83499e
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 16 deletions.
93 changes: 92 additions & 1 deletion cardano-cli/src/Cardano/CLI/Run/Friendly.hs
Expand Up @@ -150,13 +150,104 @@ friendlyStakeReference = \case
friendlyUpdateProposal :: TxUpdateProposal era -> Aeson.Value
friendlyUpdateProposal = \case
TxUpdateProposalNone -> Null
TxUpdateProposal _ p -> String $ textShow p
TxUpdateProposal _ (UpdateProposal parameterUpdates epoch) ->
object
[ "epoch" .= epoch
, "updates" .=
[ object
[ "genesis key hash" .= serialiseToRawBytesHexText genesisKeyHash
, "update" .= friendlyProtocolParametersUpdate parameterUpdate
]
| (genesisKeyHash, parameterUpdate) <- Map.assocs parameterUpdates
]
]

friendlyProtocolParametersUpdate :: ProtocolParametersUpdate -> Aeson.Value
friendlyProtocolParametersUpdate
ProtocolParametersUpdate
{ protocolUpdateProtocolVersion
, protocolUpdateDecentralization
, protocolUpdateExtraPraosEntropy
, protocolUpdateMaxBlockHeaderSize
, protocolUpdateMaxBlockBodySize
, protocolUpdateMaxTxSize
, protocolUpdateTxFeeFixed
, protocolUpdateTxFeePerByte
, protocolUpdateMinUTxOValue
, protocolUpdateStakeAddressDeposit
, protocolUpdateStakePoolDeposit
, protocolUpdateMinPoolCost
, protocolUpdatePoolRetireMaxEpoch
, protocolUpdateStakePoolTargetNum
, protocolUpdatePoolPledgeInfluence
, protocolUpdateMonetaryExpansion
, protocolUpdateTreasuryCut
, protocolUpdateUTxOCostPerWord
, protocolUpdateCollateralPercent
, protocolUpdateMaxBlockExUnits
, protocolUpdateMaxCollateralInputs
, protocolUpdateMaxTxExUnits
, protocolUpdateMaxValueSize
, protocolUpdatePrices
} =
object . catMaybes $
[ protocolUpdateProtocolVersion <&> \(major, minor) ->
"protocol version" .= (textShow major <> "." <> textShow minor)
, protocolUpdateDecentralization <&>
("decentralization parameter" .=) . friendlyRational
, protocolUpdateExtraPraosEntropy <&>
("extra entropy" .=) . maybe "reset" toJSON
, protocolUpdateMaxBlockHeaderSize <&> ("max block header size" .=)
, protocolUpdateMaxBlockBodySize<&> ("max block body size" .=)
, protocolUpdateMaxTxSize <&> ("max transaction size" .=)
, protocolUpdateTxFeeFixed <&> ("transaction fee constant" .=)
, protocolUpdateTxFeePerByte <&> ("transaction fee linear per byte" .=)
, protocolUpdateMinUTxOValue <&> ("min UTxO value" .=) . friendlyLovelace
, protocolUpdateStakeAddressDeposit <&>
("key registration deposit" .=) . friendlyLovelace
, protocolUpdateStakePoolDeposit <&>
("pool registration deposit" .=) . friendlyLovelace
, protocolUpdateMinPoolCost <&> ("min pool cost" .=) . friendlyLovelace
, protocolUpdatePoolRetireMaxEpoch <&> ("pool retirement epoch boundary" .=)
, protocolUpdateStakePoolTargetNum <&> ("number of pools" .=)
, protocolUpdatePoolPledgeInfluence <&>
("pool influence" .=) . friendlyRational
, protocolUpdateMonetaryExpansion <&>
("monetary expansion" .=) . friendlyRational
, protocolUpdateTreasuryCut <&> ("treasury expansion" .=) . friendlyRational
, protocolUpdateUTxOCostPerWord <&>
("UTxO storage cost per unit" .=) . friendlyLovelace
, protocolUpdateCollateralPercent <&>
("collateral inputs share" .=) . (<> "%") . textShow
, protocolUpdateMaxBlockExUnits <&> ("max block execution units" .=)
, protocolUpdateMaxCollateralInputs <&> ("max collateral inputs" .=)
, protocolUpdateMaxTxExUnits <&> ("max transaction execution units" .=)
, protocolUpdateMaxValueSize <&> ("max value size" .=)
, protocolUpdatePrices <&> ("execution prices" .=) . friendlyPrices
]

friendlyPrices :: ExecutionUnitPrices -> Aeson.Value
friendlyPrices ExecutionUnitPrices{priceExecutionMemory, priceExecutionSteps} =
object
[ "memory" .= friendlyRational priceExecutionMemory
, "steps" .= friendlyRational priceExecutionSteps
]

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

friendlyRational :: Rational -> Aeson.Value
friendlyRational r =
String $
case d of
1 -> textShow n
_ -> textShow n <> "/" <> textShow d
where
n = numerator r
d = denominator r

friendlyFee :: TxFee era -> Aeson.Value
friendlyFee = \case
TxFeeImplicit _ -> "implicit"
Expand Down
12 changes: 6 additions & 6 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -2431,7 +2431,7 @@ pPoolMargin :: Parser Rational
pPoolMargin =
Opt.option readRationalUnitInterval
( Opt.long "pool-margin"
<> Opt.metavar "DOUBLE"
<> Opt.metavar "RATIONAL"
<> Opt.help "The stake pool's margin."
)

Expand Down Expand Up @@ -2683,31 +2683,31 @@ pPoolInfluence :: Parser Rational
pPoolInfluence =
Opt.option readRational
( Opt.long "pool-influence"
<> Opt.metavar "DOUBLE"
<> Opt.metavar "RATIONAL"
<> Opt.help "Pool influence."
)

pTreasuryExpansion :: Parser Rational
pTreasuryExpansion =
Opt.option readRationalUnitInterval
( Opt.long "treasury-expansion"
<> Opt.metavar "DOUBLE"
<> Opt.metavar "RATIONAL"
<> Opt.help "Treasury expansion."
)

pMonetaryExpansion :: Parser Rational
pMonetaryExpansion =
Opt.option readRationalUnitInterval
( Opt.long "monetary-expansion"
<> Opt.metavar "DOUBLE"
<> Opt.metavar "RATIONAL"
<> Opt.help "Monetary expansion."
)

pDecentralParam :: Parser Rational
pDecentralParam =
Opt.option readRationalUnitInterval
( Opt.long "decentralization-parameter"
<> Opt.metavar "DOUBLE"
<> Opt.metavar "RATIONAL"
<> Opt.help "Decentralization parameter."
)

Expand All @@ -2716,7 +2716,7 @@ pExtraEntropy =
Opt.option (Just <$> readerFromParsecParser parsePraosNonce)
( Opt.long "extra-entropy"
<> Opt.metavar "HEX"
<> Opt.help "Praos extra entropy, as a hex byte string."
<> Opt.help "Praos extra entropy seed, as a hex byte string."
)
<|> Opt.flag' Nothing
( Opt.long "reset-extra-entropy"
Expand Down
98 changes: 93 additions & 5 deletions cardano-cli/test/Test/Golden/TxView.hs
Expand Up @@ -5,7 +5,7 @@ module Test.Golden.TxView (txViewTests) where
import Cardano.Prelude

import Hedgehog (Group (..), Property, checkSequential)
import Hedgehog.Extras.Test.Base (moduleWorkspace, propertyOnce)
import Hedgehog.Extras (moduleWorkspace, note_, propertyOnce)

import Test.OptParse (execCardanoCLI, noteTempFile)
import Test.Utilities (diffVsGoldenFile)
Expand All @@ -16,11 +16,11 @@ txViewTests :: IO Bool
txViewTests =
checkSequential $
Group "`transaction view` Goldens"
[ ("golden_view_byron", golden_view_byron)
[ ("golden_view_byron", golden_view_byron)
, ("golden_view_shelley", golden_view_shelley)
, ("golden_view_allegra", golden_view_allegra)
, ("golden_view_mary", golden_view_mary)
-- , ("golden_view_alonzo", golden_view_alonzo)
, ("golden_view_mary", golden_view_mary)
, ("golden_view_alonzo", golden_view_alonzo)
]

golden_view_byron :: Property
Expand Down Expand Up @@ -53,7 +53,46 @@ golden_view_shelley :: Property
golden_view_shelley =
propertyOnce $
moduleWorkspace "tmp" $ \tempDir -> do
transactionBodyFile <- noteTempFile tempDir "transaction-body-file"
updateProposalFile <- noteTempFile tempDir "update-proposal"
transactionBodyFile <- noteTempFile tempDir "transaction-body"

let extraEntropySeed = "c0ffee"
note_ $ "extra entropy seed: " ++ extraEntropySeed
note_
"extra entropy hash:\
\ 88f04f011dcded879039ae4b9b20219d9448e5c7b42c2d1f638fb8740e0ab8be"

note_
"genesis-verification-key-file hash:\
\ 81cb0bc5b6fbba391e6f7ec3d9271cbea25bcbf907181b7c4d5f8c2f"

-- Create update proposal
void $
execCardanoCLI
[ "governance", "create-update-proposal"
, "--decentralization-parameter", "63/64"
, "--epoch", "64"
, "--extra-entropy", extraEntropySeed
, "--genesis-verification-key-file"
, "test/data/golden/shelley/keys/genesis_keys/verification_key"
, "--key-reg-deposit-amt", "71"
, "--max-block-body-size", "72"
, "--max-block-header-size", "73"
, "--max-tx-size", "74"
, "--min-fee-constant", "75"
, "--min-fee-linear", "76"
, "--min-pool-cost", "77"
, "--min-utxo-value", "78"
, "--monetary-expansion", "79/80"
, "--number-of-pools", "80"
, "--out-file", updateProposalFile
, "--pool-influence", "82/83"
, "--pool-reg-deposit", "83"
, "--pool-retirement-epoch-boundary", "84"
, "--protocol-major-version", "85"
, "--protocol-minor-version", "86"
, "--treasury-expansion", "87/88"
]

-- Create transaction body
void $
Expand All @@ -70,6 +109,7 @@ golden_view_shelley =
, "--withdrawal"
, "stake_test1up00fz9lyqs5sjks82k22eqz7a9srym9vysjgp3h2ua2v2cm522kg\
\+42"
, "--update-proposal-file", updateProposalFile
, "--out-file", transactionBodyFile
]

Expand Down Expand Up @@ -173,3 +213,51 @@ golden_view_mary =
execCardanoCLI
["transaction", "view", "--tx-body-file", transactionBodyFile]
diffVsGoldenFile result "test/data/golden/mary/transaction-view.out"

golden_view_alonzo :: Property
golden_view_alonzo =
propertyOnce $
moduleWorkspace "tmp" $ \tempDir -> do
updateProposalFile <- noteTempFile tempDir "update-proposal"
transactionBodyFile <- noteTempFile tempDir "transaction-body"

note_
"genesis-verification-key-file hash:\
\ 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114"

-- Create update proposal
void $
execCardanoCLI
[ "governance", "create-update-proposal"
, "--epoch", "190"
, "--genesis-verification-key-file"
, "test/data/golden/shelley/keys/genesis_keys/verification_key"
, "--utxo-cost-per-word", "194"
, "--price-execution-steps", "195/196"
, "--price-execution-memory", "196/197"
, "--max-tx-execution-units", "(197, 198)"
, "--max-block-execution-units", "(198, 199)"
, "--max-value-size", "199"
, "--collateral-percent", "200"
, "--max-collateral-inputs", "201"
, "--out-file", updateProposalFile
]

-- Create transaction body
void $
execCardanoCLI
[ "transaction", "build-raw"
, "--alonzo-era"
, "--tx-in"
, "ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20\
\#212"
, "--fee", "213"
, "--update-proposal-file", updateProposalFile
, "--out-file", transactionBodyFile
]

-- View transaction body
result <-
execCardanoCLI
["transaction", "view", "--tx-body-file", transactionBodyFile]
diffVsGoldenFile result "test/data/golden/alonzo/transaction-view.out"
31 changes: 31 additions & 0 deletions cardano-cli/test/data/golden/alonzo/transaction-view.out
@@ -0,0 +1,31 @@
auxiliary scripts: null
certificates: null
era: Alonzo
fee: 213 Lovelace
inputs:
- ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20#212
metadata: null
mint: null
outputs: []
update proposal:
epoch: 190
updates:
- genesis key hash: 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114
update:
UTxO storage cost per unit: 194 Lovelace
collateral inputs share: 200%
execution prices:
memory: 196/197
steps: 195/196
max block execution units:
memory: 199
steps: 198
max collateral inputs: 201
max transaction execution units:
memory: 198
steps: 197
max value size: 199
validity range:
lower bound: null
upper bound: null
withdrawals: null
23 changes: 22 additions & 1 deletion cardano-cli/test/data/golden/shelley/transaction-view.out
Expand Up @@ -14,7 +14,28 @@ outputs:
payment credential:
key hash: bce78cb90f6da9ee778ef07ca881b489c38a188993e6870bd5a9ef77
stake reference: null
update proposal: null
update proposal:
epoch: 64
updates:
- genesis key hash: 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114
update:
decentralization parameter: 63/64
extra entropy: 88f04f011dcded879039ae4b9b20219d9448e5c7b42c2d1f638fb8740e0ab8be
key registration deposit: 71 Lovelace
max block body size: 72
max block header size: 73
max transaction size: 74
min UTxO value: 78 Lovelace
min pool cost: 77 Lovelace
monetary expansion: 79/80
number of pools: 80
pool influence: 82/83
pool registration deposit: 83 Lovelace
pool retirement epoch boundary: 84
protocol version: '85.86'
transaction fee constant: 75
transaction fee linear per byte: 76
treasury expansion: 87/88
validity range:
time to live: 33
withdrawals:
Expand Down
5 changes: 5 additions & 0 deletions cardano-cli/test/data/golden/shelley/update-proposal
@@ -0,0 +1,5 @@
{
"type": "UpdateProposalShelley",
"description": "",
"cborHex": "82a1581ca2512fa96a5f51d7aa8b8558669561fdd905f505ad7e0f4047b15c9eb100197a6601197a6702197a6e03197a6804197a6d05197a6406197a6307197a6108197a6009d81e82197a5f1903e80ad81e82197a5b1a000186a00bd81e82197a591a000186a00cd81e82197a6f1a000186a00d82015820ee32869218e317d16b9cba9e8f0737e23a6c9328e71068f161e5cc3cf54c45be0e82197a6a197a6b0f197a6510197a62197a69"
}
12 changes: 9 additions & 3 deletions scripts/reconfigure-hlint.sh
Expand Up @@ -7,11 +7,17 @@
#
# To use, simply run the script from the project's top-level directory.

UNAME=$(uname -s) SED=
case $UNAME in
Darwin ) SED="gsed";;
Linux ) SED="sed";;
esac

extract_rules() {
for x in $(find . -type f -name '*.hs' | grep -v dist); do
module="$(grep '^module' $x | cut -d ' ' -f 2 | head -n 1)"
grep '{- HLINT ignore "' $x | cut -d '"' -f 2 | \
sed "s|^|$module,|g"
$SED "s|^|$module,|g"
done
}

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

0 comments on commit b83499e

Please sign in to comment.