Skip to content

Commit

Permalink
Merge #4431
Browse files Browse the repository at this point in the history
4431: Infer protocol params in transaction build r=LudvikGalois a=LudvikGalois

We now ignore the `--protocol-params-file` in the `transaction build` command. Instead we
fetch it from the node directly. If the user still supplies it, we display a warning, but otherwise
continue.

Fixes #4058

Co-authored-by: Robert 'Probie' Offner <[email protected]>
  • Loading branch information
iohk-bors[bot] and Robert 'Probie' Offner authored Oct 31, 2022
2 parents 521b64a + 933ba81 commit ff36ddd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 44 deletions.
3 changes: 3 additions & 0 deletions cardano-cli/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

- Add `query tx-mempool` ([PR 4276](https://github.com/input-output-hk/cardano-node/pull/4276))


### Bugs

- Allow reading signing keys from a pipe ([PR 4342](https://github.com/input-output-hk/cardano-node/pull/4342))

- Query protocol parameters from the node in the `transaction build` command ([PR 4431](https://github.com/input-output-hk/cardano-node/pull/4431))

## 1.35.3 -- August 2022

- Update build and build-raw commands to accept simple reference minting scripts (#4087)
Expand Down
15 changes: 11 additions & 4 deletions cardano-cli/src/Cardano/CLI/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module Cardano.CLI.Helpers
( HelpersError(..)
, printWarning
, deprecationWarning
, ensureNewFile
, ensureNewFileLBS
Expand Down Expand Up @@ -60,12 +61,18 @@ decodeCBOR
decodeCBOR bs decoder =
first CBORDecodingError $ deserialiseFromBytes decoder bs

deprecationWarning :: String -> IO ()
deprecationWarning cmd = do
printWarning :: String -> IO ()
printWarning warning = do
ANSI.hSetSGR IO.stderr [SetColor Foreground Vivid Yellow]
IO.hPutStrLn IO.stderr $ "WARNING: This CLI command is deprecated. Please use "
<> cmd <> " command instead."
IO.hPutStrLn IO.stderr $ "WARNING: " <> warning
ANSI.hSetSGR IO.stderr [Reset]
-- We need to flush, or otherwise what's on stdout may have the wrong colour
-- since it's likely sharing a console with stderr
IO.hFlush IO.stderr

deprecationWarning :: String -> IO ()
deprecationWarning cmd = printWarning $
"This CLI command is deprecated. Please use " <> cmd <> " command instead."

-- | Checks if a path exists and throws and error if it does.
ensureNewFile :: (FilePath -> a -> IO ()) -> FilePath -> a -> ExceptT HelpersError IO ()
Expand Down
84 changes: 44 additions & 40 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import qualified Cardano.Binary as CBOR
--TODO: following import needed for orphan Eq Script instance
import Cardano.Ledger.Shelley.Scripts ()

import Cardano.CLI.Helpers (printWarning)
import Cardano.CLI.Run.Friendly (friendlyTxBS, friendlyTxBodyBS)
import Cardano.CLI.Shelley.Key (InputDecodeError, readSigningKeyFileAnyOf)
import Cardano.CLI.Shelley.Output
Expand Down Expand Up @@ -586,52 +587,16 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
(TxOutChangeAddress changeAddr) valuesWithScriptWits mLowerBound mUpperBound
certsAndMaybeScriptWits withdrawals reqSigners txAuxScripts txMetadata mpparams
mUpdatePropF mOverrideWits outputOptions = do

liftIO $ forM_ mpparams $ \_ ->
printWarning "'--protocol-params-file' for 'transaction build' is deprecated"

let consensusMode = consensusModeOnly cModeParams
dummyFee = Just $ Lovelace 0
inputsThatRequireWitnessing = [input | (input,_) <- inputsAndMaybeScriptWits]

-- Pure
let allReferenceInputs = getAllReferenceInputs
inputsAndMaybeScriptWits
(snd valuesWithScriptWits)
certsAndMaybeScriptWits
withdrawals readOnlyRefIns

validatedCollateralTxIns <- hoistEither $ validateTxInsCollateral era txinsc
validatedRefInputs <- hoistEither $ validateTxInsReference era allReferenceInputs
validatedTotCollateral <- hoistEither $ validateTxTotalCollateral era mTotCollateral
validatedRetCol <- hoistEither $ validateTxReturnCollateral era mReturnCollateral
dFee <- hoistEither $ validateTxFee era dummyFee
validatedBounds <- (,) <$> hoistEither (validateTxValidityLowerBound era mLowerBound)
<*> hoistEither (validateTxValidityUpperBound era mUpperBound)
validatedReqSigners <- hoistEither $ validateRequiredSigners era reqSigners
validatedPParams <- hoistEither $ validateProtocolParameters era mpparams
validatedTxWtdrwls <- hoistEither $ validateTxWithdrawals era withdrawals
validatedTxCerts <- hoistEither $ validateTxCertificates era certsAndMaybeScriptWits
validatedTxUpProp <- hoistEither $ validateTxUpdateProposal era mUpdatePropF
validatedMintValue <- hoistEither $ createTxMintValue era valuesWithScriptWits
validatedTxScriptValidity <- hoistEither $ validateTxScriptValidity era mScriptValidity

case (consensusMode, cardanoEraStyle era) of
(CardanoMode, ShelleyBasedEra _sbe) -> do
let txBodyContent = TxBodyContent
(validateTxIns inputsAndMaybeScriptWits)
validatedCollateralTxIns
validatedRefInputs
txouts
validatedTotCollateral
validatedRetCol
dFee
validatedBounds
txMetadata
txAuxScripts
validatedReqSigners
validatedPParams
validatedTxWtdrwls
validatedTxCerts
validatedTxUpProp
validatedMintValue
validatedTxScriptValidity

eInMode <- case toEraInMode era CardanoMode of
Just result -> return result
Expand All @@ -641,6 +606,12 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity

SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError
$ newExceptT readEnvSocketPath
-- Pure
let allReferenceInputs = getAllReferenceInputs
inputsAndMaybeScriptWits
(snd valuesWithScriptWits)
certsAndMaybeScriptWits
withdrawals readOnlyRefIns

let allTxInputs = inputsThatRequireWitnessing ++ allReferenceInputs ++ txinsc
localNodeConnInfo = LocalNodeConnectInfo
Expand Down Expand Up @@ -671,6 +642,39 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
txEraUtxo <- case first ShelleyTxCmdTxEraCastErr (eraCast era nodeEraUTxO) of
Right txEraUtxo -> return txEraUtxo
Left e -> left e
validatedCollateralTxIns <- hoistEither $ validateTxInsCollateral era txinsc
validatedRefInputs <- hoistEither $ validateTxInsReference era allReferenceInputs
validatedTotCollateral <- hoistEither $ validateTxTotalCollateral era mTotCollateral
validatedRetCol <- hoistEither $ validateTxReturnCollateral era mReturnCollateral
dFee <- hoistEither $ validateTxFee era dummyFee
validatedBounds <- (,) <$> hoistEither (validateTxValidityLowerBound era mLowerBound)
<*> hoistEither (validateTxValidityUpperBound era mUpperBound)
validatedReqSigners <- hoistEither $ validateRequiredSigners era reqSigners
validatedPParams <- hoistEither $ validateProtocolParameters era (Just pparams)
validatedTxWtdrwls <- hoistEither $ validateTxWithdrawals era withdrawals
validatedTxCerts <- hoistEither $ validateTxCertificates era certsAndMaybeScriptWits
validatedTxUpProp <- hoistEither $ validateTxUpdateProposal era mUpdatePropF
validatedMintValue <- hoistEither $ createTxMintValue era valuesWithScriptWits
validatedTxScriptValidity <- hoistEither $ validateTxScriptValidity era mScriptValidity

let txBodyContent = TxBodyContent
(validateTxIns inputsAndMaybeScriptWits)
validatedCollateralTxIns
validatedRefInputs
txouts
validatedTotCollateral
validatedRetCol
dFee
validatedBounds
txMetadata
txAuxScripts
validatedReqSigners
validatedPParams
validatedTxWtdrwls
validatedTxCerts
validatedTxUpProp
validatedMintValue
validatedTxScriptValidity

balancedTxBody@(BalancedTxBody _ _ _ fee) <-
firstExceptT ShelleyTxCmdBalanceTxBody
Expand Down

0 comments on commit ff36ddd

Please sign in to comment.