Skip to content

Commit a31862a

Browse files
committed
Fix query mismatch bug in transaction build command when using flag
--calculate-plutus-script-cost with an era prior to the node's era Resolves #4535
1 parent 249d42a commit a31862a

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,23 @@ runTransactionCmd cmd =
291291
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mPparams
292292
mUpProp outputOptions -> do
293293

294+
-- The user can specify an era prior to the era that the node is currently in.
295+
-- We cannot use the user specified era to construct a query against a node because it may differ
296+
-- from the node's era and this will result in the 'QueryEraMismatch' failure.
297+
298+
SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError
299+
$ newExceptT readEnvSocketPath
300+
301+
let localNodeConnInfo = LocalNodeConnectInfo
302+
{ localConsensusModeParams = cModeParams
303+
, localNodeNetworkId = nid
304+
, localNodeSocketPath = sockPath
305+
}
306+
307+
AnyCardanoEra nodeEra
308+
<- firstExceptT (ShelleyTxCmdQueryConvenienceError . AcqFailure)
309+
. newExceptT $ determineEra cModeParams localNodeConnInfo
310+
294311
inputsAndMaybeScriptWits <- readScriptWitnessFiles cEra txins
295312
certFilesAndMaybeScriptWits <- readScriptWitnessFiles cEra certs
296313
certsAndMaybeScriptWits <- sequence
@@ -315,6 +332,7 @@ runTransactionCmd cmd =
315332
mReturnCollateral <- case mReturnColl of
316333
Just retCol -> Just <$> toTxOutInAnyEra cEra retCol
317334
Nothing -> return Nothing
335+
318336
txOuts <- mapM (toTxOutInAnyEra cEra) txouts
319337

320338
-- We need to construct the txBodycontent outside of runTxBuild
@@ -347,18 +365,25 @@ runTransactionCmd cmd =
347365
let consensusMode = consensusModeOnly cModeParams
348366
case consensusMode of
349367
CardanoMode -> do
350-
(utxo, _, eraHistory, systemStart, _)
368+
(nodeEraUTxO, _, eraHistory, systemStart, _)
351369
<- firstExceptT ShelleyTxCmdQueryConvenienceError
352-
. newExceptT $ queryStateForBalancedTx cEra nid allTxInputs
370+
. newExceptT $ queryStateForBalancedTx nodeEra nid allTxInputs
353371
case toEraInMode cEra CardanoMode of
354372
Just eInMode -> do
373+
-- Why do we cast the era? The user can specify an era prior to the era that the node is currently in.
374+
-- We cannot use the user specified era to construct a query against a node because it may differ
375+
-- from the node's era and this will result in the 'QueryEraMismatch' failure.
376+
txEraUtxo <- case first ShelleyTxCmdTxEraCastErr (eraCast cEra nodeEraUTxO) of
377+
Right txEraUtxo -> return txEraUtxo
378+
Left e -> left e
379+
355380
scriptExecUnitsMap <- firstExceptT ShelleyTxCmdTxExecUnitsErr $ hoistEither
356381
$ evaluateTransactionExecutionUnits
357382
eInMode systemStart eraHistory
358-
pparams utxo balancedTxBody
383+
pparams txEraUtxo balancedTxBody
359384
scriptCostOutput <- firstExceptT ShelleyTxCmdPlutusScriptCostErr $ hoistEither
360385
$ renderScriptCosts
361-
utxo
386+
txEraUtxo
362387
executionUnitPrices
363388
(collectTxBodyScriptWitnesses txBodycontent)
364389
scriptExecUnitsMap

0 commit comments

Comments
 (0)