@@ -281,6 +281,7 @@ evalGenerator :: forall era. IsShelleyBasedEra era => Generator -> TxGenTxParams
281
281
evalGenerator generator txParams@ TxGenTxParams {txParamFee = fee} era = do
282
282
networkId <- getEnvNetworkId
283
283
protocolParameters <- getProtocolParameters
284
+
284
285
case generator of
285
286
SecureGenesis wallet genesisKeyName destKeyName -> do
286
287
genesis <- getEnvGenesis
@@ -294,6 +295,7 @@ evalGenerator generator txParams@TxGenTxParams{txParamFee = fee} era = do
294
295
walletRefInsertFund destWallet fund
295
296
return $ Right tx
296
297
return $ Streaming. effect (Streaming. yield <$> gen)
298
+
297
299
Split walletName payMode payModeChange coins -> do
298
300
wallet <- getEnvWallets walletName
299
301
(toUTxO, addressOut) <- interpretPayMode payMode
@@ -306,6 +308,7 @@ evalGenerator generator txParams@TxGenTxParams{txParamFee = fee} era = do
306
308
txGenerator = genTx protocolParameters (TxInsCollateralNone , [] ) feeInEra TxMetadataNone
307
309
sourceToStore = sourceToStoreTransactionNew txGenerator fundSource inToOut $ mangleWithChange toUTxOChange toUTxO
308
310
return $ Streaming. effect (Streaming. yield <$> sourceToStore)
311
+
309
312
SplitN walletName payMode count -> do
310
313
wallet <- getEnvWallets walletName
311
314
(toUTxO, addressOut) <- interpretPayMode payMode
@@ -327,16 +330,36 @@ evalGenerator generator txParams@TxGenTxParams{txParamFee = fee} era = do
327
330
inToOut = Utils. inputsToOutputsWithFee fee outputs
328
331
txGenerator = genTx protocolParameters collaterals feeInEra (toMetadata metadataSize)
329
332
sourceToStore = sourceToStoreTransactionNew txGenerator fundSource inToOut (mangle $ repeat toUTxO)
333
+
334
+ fundPreview <- liftIO $ walletPreview wallet inputs
335
+ case sourceTransactionPreview txGenerator fundPreview inToOut (mangle $ repeat toUTxO) of
336
+ Left err -> traceDebug $ " Error creating Tx preview: " ++ show err
337
+ Right tx -> do
338
+ let txSize = txSizeInBytes tx
339
+ traceDebug $ " Projected Tx size in bytes: " ++ show txSize
340
+ summary_ <- getEnvSummary
341
+ forM_ summary_ $ \ summary -> do
342
+ let summary' = summary {projectedTxSize = Just txSize}
343
+ setEnvSummary summary'
344
+ traceBenchTxSubmit TraceBenchPlutusBudgetSummary summary'
345
+ dumpBudgetSummaryIfExisting
346
+
330
347
return $ Streaming. effect (Streaming. yield <$> sourceToStore)
348
+
331
349
Sequence l -> do
332
350
gList <- forM l $ \ g -> evalGenerator g txParams era
333
351
return $ Streaming. for (Streaming. each gList) id
352
+
334
353
Cycle g -> Streaming. cycle <$> evalGenerator g txParams era
354
+
335
355
Take count g -> Streaming. take count <$> evalGenerator g txParams era
356
+
336
357
RoundRobin l -> do
337
358
_gList <- forM l $ \ g -> evalGenerator g txParams era
338
359
error " return $ foldr1 Streaming.interleaves gList"
360
+
339
361
OneOf _l -> error " todo: implement Quickcheck style oneOf generator"
362
+
340
363
where
341
364
feeInEra = Utils. mkTxFee fee
342
365
@@ -414,29 +437,30 @@ makePlutusContext ScriptSpec{..} = do
414
437
]
415
438
return (sData, redeemer, units)
416
439
417
- AutoScript redeemerFile budgetFraction -> do
440
+ AutoScript redeemerFile txInputs -> do
418
441
redeemer <- liftIOSafe $ readScriptData redeemerFile
419
442
let
420
- budget = ExecutionUnits
421
- (executionSteps perTxBudget `div` fromIntegral budgetFraction)
422
- (executionMemory perTxBudget `div` fromIntegral budgetFraction)
443
+ strategy = case scriptSpecPlutusType of
444
+ LimitTxPerBlock_8 -> TargetTxsPerBlock 8
445
+ _ -> TargetTxExpenditure
423
446
424
447
-- reflects properties hard-coded into the loop scripts for benchmarking:
425
448
-- 1. script datum is not used
426
449
-- 2. the loop terminates at 1_000_000 when counting down
427
450
-- 3. the loop's initial value is the first numerical value in the redeemer argument structure
428
451
autoBudget = PlutusAutoBudget
429
- { autoBudgetUnits = budget
452
+ { autoBudgetUnits = perTxBudget
430
453
, autoBudgetDatum = ScriptDataNumber 0
431
454
, autoBudgetRedeemer = scriptDataModifyNumber (const 1_000_000 ) redeemer
432
455
}
433
- traceDebug $ " Plutus auto mode : Available budget per Tx input / script run : " ++ show budget
434
- ++ " -- fraction of protocolParamMaxTxExUnits budget: 1/ " ++ show budgetFraction
456
+ traceDebug $ " Plutus auto mode : Available budget per Tx: " ++ show perTxBudget
457
+ ++ " -- split between inputs per Tx: " ++ show txInputs
435
458
436
- case plutusAutoBudgetMaxOut protocolParameters script autoBudget of
459
+ case plutusAutoScaleBlockfit protocolParameters scriptSpecFile script autoBudget strategy txInputs of
437
460
Left err -> liftTxGenError err
438
- Right PlutusAutoBudget {.. } -> do
439
- preRun <- preExecuteScriptAction protocolParameters script autoBudgetDatum autoBudgetRedeemer
461
+ Right (summary, PlutusAutoBudget {.. }, preRun) -> do
462
+ setEnvSummary summary
463
+ dumpBudgetSummaryIfExisting
440
464
return (autoBudgetDatum, autoBudgetRedeemer, preRun)
441
465
442
466
let msg = mconcat [ " Plutus Benchmark :"
@@ -485,6 +509,16 @@ preExecuteScriptAction protocolParameters script scriptData redeemer
485
509
Left err -> throwE $ WalletError ( " makePlutusContext preExecuteScript failed: " ++ show err )
486
510
Right costs -> return costs
487
511
512
+ dumpBudgetSummaryIfExisting :: ActionM ()
513
+ dumpBudgetSummaryIfExisting
514
+ = do
515
+ summary_ <- getEnvSummary
516
+ forM_ summary_ $ \ summary -> do
517
+ liftIO $ BSL. writeFile summaryFile $ prettyPrintOrdered summary
518
+ traceDebug $ " dumpBudgetSummaryIfExisting : budget summary created/updated in: " ++ summaryFile
519
+ where
520
+ summaryFile = " plutus-budget-summary.json"
521
+
488
522
traceTxGeneratorVersion :: ActionM ()
489
523
traceTxGeneratorVersion = traceBenchTxSubmit TraceTxGeneratorVersion Version. txGeneratorVersion
490
524
0 commit comments