Skip to content

Commit

Permalink
Merge #2727
Browse files Browse the repository at this point in the history
2727: Update cli to allow Alonzo era queries r=dcoutts a=Jimbo4350



Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
Co-authored-by: Duncan Coutts <duncan@well-typed.com>
  • Loading branch information
3 people committed May 31, 2021
2 parents 6264c6c + 45bc383 commit 98a069e
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 14 deletions.
4 changes: 4 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,10 @@ pCardanoEra = asum
( Opt.long "mary-era"
<> Opt.help "Specify the Mary era (default)"
)
, Opt.flag' (AnyCardanoEra AlonzoEra)
( Opt.long "alonzo-era"
<> Opt.help "Specify the Alonzo era"
)

-- Default for now:
, pure (AnyCardanoEra MaryEra)
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ runGenesisCreate (GenesisDir rootdir)
-- Shelley genesis parameters
start genDlgs mAmount utxoAddrs mempty (Lovelace 0) [] [] template
-- Alono genesis parameters TODO: Parameterize
(Lovelace 10) (Lovelace 1, Lovelace 1) (1,1) (1,1) 1 1 1
(Lovelace 10) (Lovelace 1, Lovelace 1) (1,1) (1,1) 100 1 1

writeFileGenesis (rootdir </> "genesis.json") shelleyGenesis
writeFileGenesis (rootdir </> "genesis.alonzo.json") alonzoGenesis
Expand Down
12 changes: 10 additions & 2 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ printFilteredUTxOs shelleyBasedEra' (UTxO utxo) = do
mapM_ (printUtxo shelleyBasedEra') $ Map.toList utxo
ShelleyBasedEraMary ->
mapM_ (printUtxo shelleyBasedEra') $ Map.toList utxo
ShelleyBasedEraAlonzo -> panic "printFilteredUTxOs: Alonzo era not implemented yet"
ShelleyBasedEraAlonzo ->
mapM_ (printUtxo shelleyBasedEra') $ Map.toList utxo
where
title :: Text
title =
Expand Down Expand Up @@ -620,7 +621,14 @@ printUtxo shelleyBasedEra' txInOutTuple =
, textShowN 6 index
, " " <> printableValue value
]
ShelleyBasedEraAlonzo -> panic "printUtxo: Alonzo era not implemented yet"
ShelleyBasedEraAlonzo ->
let (TxIn (TxId txhash) (TxIx index), TxOut _ value _) = txInOutTuple
in Text.putStrLn $
mconcat
[ Text.decodeLatin1 (hashToBytesAsHex txhash)
, textShowN 6 index
, " " <> printableValue value
]
where
textShowN :: Show a => Int -> a -> Text
textShowN len x =
Expand Down
151 changes: 141 additions & 10 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ import qualified Ouroboros.Consensus.Shelley.Protocol.HotKey as HotKey

import qualified Cardano.Crypto.Hash.Class as Crypto
import Cardano.Ledger.Alonzo as Alonzo
import qualified Cardano.Ledger.Alonzo.PlutusScriptApi as Alonzo
import Cardano.Ledger.Alonzo.Rules.Bbody (AlonzoBbodyPredFail)
import qualified Cardano.Ledger.Alonzo.Rules.Utxo as Alonzo
import qualified Cardano.Ledger.Alonzo.Rules.Utxos as Alonzo
import Cardano.Ledger.Alonzo.Rules.Utxow (AlonzoPredFail (..))
import qualified Cardano.Ledger.Alonzo.Tx as Alonzo
import qualified Cardano.Ledger.Alonzo.TxBody as Alonzo
Expand All @@ -63,6 +65,7 @@ import qualified Cardano.Ledger.SafeHash as SafeHash
import qualified Cardano.Ledger.ShelleyMA.Rules.Utxo as MA
import qualified Cardano.Ledger.ShelleyMA.Timelocks as MA


-- TODO: this should be exposed via Cardano.Api
import Shelley.Spec.Ledger.API hiding (ShelleyBasedEra)
import Shelley.Spec.Ledger.BlockChain (LastAppliedBlock (..))
Expand Down Expand Up @@ -334,15 +337,15 @@ renderUnredeemableScripts scripts = Aeson.object $ map renderTuple scripts
renderTuple :: (Alonzo.ScriptPurpose StandardCrypto, ScriptHash StandardCrypto) -> Aeson.Pair
renderTuple (scriptPurpose, sHash) = renderScriptHash sHash .= renderScriptPurpose scriptPurpose

renderScriptPurpose :: Alonzo.ScriptPurpose StandardCrypto -> Aeson.Value
renderScriptPurpose (Alonzo.Minting pid) =
Aeson.object [ "minting" .= toJSON pid]
renderScriptPurpose (Alonzo.Spending txin) =
Aeson.object [ "spending" .= Api.fromShelleyTxIn txin]
renderScriptPurpose (Alonzo.Rewarding rwdAcct) =
Aeson.object [ "rewarding" .= Aeson.String (Api.serialiseAddress $ Api.fromShelleyStakeAddr rwdAcct)]
renderScriptPurpose (Alonzo.Certifying cert) =
Aeson.object [ "certifying" .= toJSON (Api.textEnvelopeDefaultDescr $ Api.fromShelleyCertificate cert)]
renderScriptPurpose :: Alonzo.ScriptPurpose StandardCrypto -> Aeson.Value
renderScriptPurpose (Alonzo.Minting pid) =
Aeson.object [ "minting" .= toJSON pid]
renderScriptPurpose (Alonzo.Spending txin) =
Aeson.object [ "spending" .= Api.fromShelleyTxIn txin]
renderScriptPurpose (Alonzo.Rewarding rwdAcct) =
Aeson.object [ "rewarding" .= Aeson.String (Api.serialiseAddress $ Api.fromShelleyStakeAddr rwdAcct)]
renderScriptPurpose (Alonzo.Certifying cert) =
Aeson.object [ "certifying" .= toJSON (Api.textEnvelopeDefaultDescr $ Api.fromShelleyCertificate cert)]

instance ( ShelleyBasedEra era
, ToObject (PredicateFailure (UTXO era))
Expand Down Expand Up @@ -825,6 +828,7 @@ instance ToObject (OcertPredicateFailure crypto) where
]



instance ToObject (UpdnPredicateFailure crypto) where
toObject _verb x = case x of {} -- no constructors

Expand All @@ -842,7 +846,134 @@ instance ToObject (UpecPredicateFailure era) where


instance ToObject (Alonzo.UtxoPredicateFailure (Alonzo.AlonzoEra StandardCrypto)) where
toObject _ _ = panic "ToJSON: UtxoPredicateFailure not implemented yet"
toObject _verb (Alonzo.BadInputsUTxO badInputs) =
mkObject [ "kind" .= String "BadInputsUTxO"
, "badInputs" .= badInputs
, "error" .= renderBadInputsUTxOErr badInputs
]
toObject _verb (Alonzo.OutsideValidityIntervalUTxO validtyInterval slot) =
mkObject [ "kind" .= String "ExpiredUTxO"
, "validityInterval" .= validtyInterval
, "slot" .= slot
]
toObject _verb (Alonzo.MaxTxSizeUTxO txsize maxtxsize) =
mkObject [ "kind" .= String "MaxTxSizeUTxO"
, "size" .= txsize
, "maxSize" .= maxtxsize
]
toObject _verb Alonzo.InputSetEmptyUTxO =
mkObject [ "kind" .= String "InputSetEmptyUTxO" ]
toObject _verb (Alonzo.FeeTooSmallUTxO minfee currentFee) =
mkObject [ "kind" .= String "FeeTooSmallUTxO"
, "minimum" .= minfee
, "fee" .= currentFee
]
toObject _verb (Alonzo.ValueNotConservedUTxO consumed produced) =
mkObject [ "kind" .= String "ValueNotConservedUTxO"
, "consumed" .= consumed
, "produced" .= produced
, "error" .= renderValueNotConservedErr consumed produced
]
toObject _verb (Alonzo.WrongNetwork network addrs) =
mkObject [ "kind" .= String "WrongNetwork"
, "network" .= network
, "addrs" .= addrs
]
toObject _verb (Alonzo.WrongNetworkWithdrawal network addrs) =
mkObject [ "kind" .= String "WrongNetworkWithdrawal"
, "network" .= network
, "addrs" .= addrs
]
toObject _verb (Alonzo.OutputTooSmallUTxO badOutputs) =
mkObject [ "kind" .= String "OutputTooSmallUTxO"
, "outputs" .= badOutputs
, "error" .= String "The output is smaller than the allow minimum \
\UTxO value defined in the protocol parameters"
]
toObject verb (Alonzo.UtxosFailure predFailure) =
toObject verb predFailure
toObject _verb (Alonzo.OutputBootAddrAttrsTooBig txouts) =
mkObject [ "kind" .= String "OutputBootAddrAttrsTooBig"
, "outputs" .= txouts
, "error" .= String "The Byron address attributes are too big"
]
toObject _verb Alonzo.TriesToForgeADA =
mkObject [ "kind" .= String "TriesToForgeADA" ]
toObject _verb (Alonzo.OutputTooBigUTxO badOutputs) =
mkObject [ "kind" .= String "OutputTooBigUTxO"
, "outputs" .= badOutputs
, "error" .= String "Too many asset ids in the tx output"
]
toObject _verb (Alonzo.InsufficientCollateral computedBalance suppliedFee) =
mkObject [ "kind" .= String "InsufficientCollateral"
, "balance" .= computedBalance
, "txfee" .= suppliedFee
]
toObject _verb (Alonzo.ScriptsNotPaidUTxO utxos) =
mkObject [ "kind" .= String "ScriptsNotPaidUTxO"
, "utxos" .= utxos
]
toObject _verb (Alonzo.ExUnitsTooBigUTxO pParamsMaxExUnits suppliedExUnits) =
mkObject [ "kind" .= String "ExUnitsTooBigUTxO"
, "maxexunits" .= pParamsMaxExUnits
, "exunits" .= suppliedExUnits
]
toObject _verb (Alonzo.CollateralContainsNonADA inputs) =
mkObject [ "kind" .= String "CollateralContainsNonADA"
, "inputs" .= inputs
]
toObject _verb (Alonzo.WrongNetworkInTxBody actualNetworkId netIdInTxBody) =
mkObject [ "kind" .= String "WrongNetworkInTxBody"
, "networkid" .= actualNetworkId
, "txbodyNetworkId" .= netIdInTxBody
]
toObject _verb (Alonzo.OutsideForecast slotNum) =
mkObject [ "kind" .= String "OutsideForecast"
, "slot" .= slotNum
]
toObject _verb (Alonzo.TooManyCollateralInputs maxCollateralInputs numberCollateralInputs) =
mkObject [ "kind" .= String "TooManyCollateralInputs"
, "max" .= maxCollateralInputs
, "inputs" .= numberCollateralInputs
]
toObject _verb Alonzo.NoCollateralInputs =
mkObject [ "kind" .= String "NoCollateralInputs" ]

instance ToObject (Alonzo.UtxosPredicateFailure (AlonzoEra StandardCrypto)) where
toObject _ (Alonzo.ValidationTagMismatch isValidating) =
mkObject [ "kind" .= String "ValidationTagMismatch"
, "isvalidating" .= isValidating
]
toObject _ (Alonzo.CollectErrors errors) =
mkObject [ "kind" .= String "CollectErrors"
, "errors" .= errors
]
toObject verb (Alonzo.UpdateFailure pFailure) =
toObject verb pFailure

deriving newtype instance ToJSON Alonzo.IsValidating

instance ToJSON (Alonzo.CollectError StandardCrypto) where
toJSON cError =
case cError of
Alonzo.NoRedeemer sPurpose ->
object
[ "kind" .= String "CollectError"
, "error" .= String "NoRedeemer"
, "scriptpurpose" .= renderScriptPurpose sPurpose
]
Alonzo.NoWitness sHash ->
object
[ "kind" .= String "CollectError"
, "error" .= String "NoWitness"
, "scripthash" .= toJSON sHash
]
Alonzo.NoCostModel lang ->
object
[ "kind" .= String "CollectError"
, "error" .= String "NoCostModel"
, "language" .= toJSON lang
]

instance ToObject (AlonzoBbodyPredFail (Alonzo.AlonzoEra StandardCrypto)) where
toObject _ _ = panic "ToJSON: AlonzoBbodyPredFail not implemented yet"
Expand Down
2 changes: 1 addition & 1 deletion scripts/byron-to-alonzo/mkfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,4 @@ elif [ "$1" = "shelley" ]; then

else
echo "Default yaml configuration applied."
fi
fi
1 change: 1 addition & 0 deletions scripts/byron-to-alonzo/update-3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ cardano-cli key convert-byron-key \
# We'll include the update proposal

cardano-cli transaction build-raw \
--shelley-era \
--invalid-hereafter 100000 \
--fee 0 \
--tx-in ${TXID0}#0\
Expand Down
76 changes: 76 additions & 0 deletions scripts/byron-to-alonzo/update-5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

set -e
# set -x

# This script will initiate the transition to protocol version 5 (Alonzo).

# You need to provide the current epoch as a positional argument (the Shelley
# update system requires this to be includded in the update proposal).


# In order for this to be successful, you need to already be in protocol version
# 4 (which happens one or two epoch boundaries after invoking update-4.sh).
# Also, you need to restart the nodes after running this script in order for the
# update to be endorsed by the nodes.

if [ ! "$1" ]; then echo "update-5.sh: expects an <N> epoch argument"; exit; fi

EPOCH=$1
VERSION=5

ROOT=example
COINS_IN_INPUT=1000000000

pushd ${ROOT}

export CARDANO_NODE_SOCKET_PATH=node-pool1/node.sock

TXID2=$(cardano-cli transaction txid --tx-file tx3.tx)


# Create the update proposal to change the protocol version to 5

cardano-cli governance create-update-proposal \
--out-file update-proposal-alonzo \
--epoch ${EPOCH} \
--genesis-verification-key-file shelley/genesis-keys/genesis1.vkey \
--genesis-verification-key-file shelley/genesis-keys/genesis2.vkey \
--protocol-major-version ${VERSION} \
--protocol-minor-version 0

# Create a transaction body containing the update proposal.

cardano-cli transaction build-raw \
--mary-era \
--fee 0 \
--tx-in $TXID2#0\
--tx-in $TXID2#1\
--tx-out $(cat addresses/user1.addr)+$((${COINS_IN_INPUT} / 2)) \
--tx-out $(cat addresses/user1.addr)+$((${COINS_IN_INPUT} / 2)) \
--update-proposal-file update-proposal-alonzo \
--out-file tx4.txbody

# Sign the transaction body with the two genesis delegate keys,
# and the the uxto spending key.

cardano-cli transaction sign \
--signing-key-file addresses/user1.skey \
--signing-key-file shelley/delegate-keys/delegate1.skey \
--signing-key-file shelley/delegate-keys/delegate2.skey \
--testnet-magic 42 \
--tx-body-file tx4.txbody \
--out-file tx4.tx


cardano-cli transaction submit --tx-file tx4.tx --testnet-magic 42

sed -i configuration.yaml \
-e 's/LastKnownBlockVersion-Major: 4/LastKnownBlockVersion-Major: 5/' \


popd

echo "Restart the nodes now to endorse the update."

cardano-cli transaction submit --cardano-mode --testnet-magic 42 --tx-file mary.tx

0 comments on commit 98a069e

Please sign in to comment.