Skip to content

Commit 17072f2

Browse files
authored
Merge pull request #99 from mlabs-haskell/misha/potentially-unknownTns-fix
Fix risk of getting `UnknownTxIns` during statistics saving
2 parents 629023e + 2134b63 commit 17072f2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/BotPlutusInterface/Contract.hs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ writeBalancedTx contractEnv (Right tx) = do
274274
, "Signatories (pkh): " <> Text.unwords (map pkhToText requiredSigners)
275275
]
276276

277+
when (pabConf.pcCollectStats && signable) $
278+
collectBudgetStats (Tx.txId tx) pabConf
279+
277280
when (not pabConf.pcDryRun && signable) $ do
278281
newEitherT $ CardanoCLI.submitTx @w pabConf tx
279282

@@ -284,9 +287,6 @@ writeBalancedTx contractEnv (Right tx) = do
284287
mvFiles (Files.txFilePath pabConf "raw" (Tx.txId tx)) (Files.txFilePath pabConf "raw" cardanoTxId)
285288
when signable $ mvFiles signedSrcPath signedDstPath
286289

287-
when contractEnv.cePABConfig.pcCollectStats $
288-
collectBudgetStats cardanoTxId signedDstPath
289-
290290
pure cardanoTx
291291
where
292292
mvFiles :: Text -> Text -> EitherT Text (Eff effs) ()
@@ -299,10 +299,17 @@ writeBalancedTx contractEnv (Right tx) = do
299299
, cmdOutParser = const ()
300300
}
301301

302-
collectBudgetStats txId txPath = do
303-
let path = Text.unpack txPath
304-
b <- firstEitherT (Text.pack . show) $ newEitherT $ estimateBudget @w (Signed path)
305-
void $ newEitherT (Right <$> saveBudget @w txId b)
302+
collectBudgetStats txId pabConf = do
303+
let path = Text.unpack (Files.txFilePath pabConf "signed" (Tx.txId tx))
304+
txBudget <-
305+
firstEitherT toBudgetSaveError $
306+
newEitherT $ estimateBudget @w (Signed path)
307+
void $ newEitherT (Right <$> saveBudget @w txId txBudget)
308+
309+
toBudgetSaveError =
310+
Text.pack
311+
. ("Failed to save Tx budgets statistics: " ++)
312+
. show
306313

307314
pkhToText :: Ledger.PubKey -> Text
308315
pkhToText = encodeByteString . fromBuiltin . Ledger.getPubKeyHash . Ledger.pubKeyHash

0 commit comments

Comments
 (0)