Skip to content

Commit 13e596f

Browse files
Merge pull request #1447 from input-output-hk/lc/remove-benchmark-fees
Remove redundant fee calculation.
2 parents d82a44f + 6f0600d commit 13e596f

File tree

4 files changed

+11
-47
lines changed

4 files changed

+11
-47
lines changed

hydra-cluster/bench/Main.hs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ import Bench.EndToEnd (bench)
99
import Bench.Options (Options (..), benchOptionsParser)
1010
import Bench.Summary (Summary (..), markdownReport, textReport)
1111
import Data.Aeson (eitherDecodeFileStrict', encodeFile)
12-
import Hydra.Cardano.Api (
13-
ShelleyBasedEra (..),
14-
ShelleyGenesis (..),
15-
fromLedgerPParams,
16-
)
1712
import Hydra.Generator (Dataset (..), generateConstantUTxODataset)
1813
import Options.Applicative (execParser)
1914
import System.Directory (createDirectoryIfMissing, doesDirectoryExist)
@@ -42,12 +37,7 @@ main =
4237
play outputDirectory timeoutSeconds scalingFactor clusterSize startingNodeId workDir = do
4338
putStrLn $ "Generating single dataset in work directory: " <> workDir
4439
numberOfTxs <- generate $ scale (* scalingFactor) getSize
45-
pparams <-
46-
eitherDecodeFileStrict' ("config" </> "devnet" </> "genesis-shelley.json") >>= \case
47-
Left err -> fail $ show err
48-
Right shelleyGenesis ->
49-
pure $ fromLedgerPParams ShelleyBasedEraShelley (sgProtocolParams shelleyGenesis)
50-
dataset <- generateConstantUTxODataset pparams (fromIntegral clusterSize) numberOfTxs
40+
dataset <- generateConstantUTxODataset (fromIntegral clusterSize) numberOfTxs
5141
let datasetPath = workDir </> "dataset.json"
5242
saveDataset datasetPath dataset
5343
run outputDirectory timeoutSeconds startingNodeId [datasetPath]

hydra-cluster/src/CardanoClient.hs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,12 @@ buildScriptAddress script networkId =
3434
in makeShelleyAddress networkId (PaymentCredentialByScript hashed) NoStakeAddress
3535

3636
-- | Build a "raw" transaction from a bunch of inputs, outputs and fees.
37-
buildRaw :: [TxIn] -> [TxOut CtxTx] -> Coin -> Either TxBodyError TxBody
38-
buildRaw ins outs fee =
37+
buildRaw :: [TxIn] -> [TxOut CtxTx] -> Either TxBodyError TxBody
38+
buildRaw ins outs =
3939
createAndValidateTransactionBody $
4040
defaultTxBodyContent
4141
& setTxIns (map (,BuildTxWith $ KeyWitness KeyWitnessForSpending) ins)
4242
& setTxOuts outs
43-
& setTxFee (TxFeeExplicit fee)
44-
45-
calculateMinFee :: NetworkId -> TxBody -> Sizes -> ProtocolParameters -> Coin
46-
calculateMinFee networkId body Sizes{inputs, outputs, witnesses} pparams =
47-
let tx = makeSignedTransaction [] body
48-
noByronWitnesses = 0
49-
in estimateTransactionFee
50-
shelleyBasedEra
51-
networkId
52-
(protocolParamTxFeeFixed pparams)
53-
(protocolParamTxFeePerByte pparams)
54-
tx
55-
inputs
56-
outputs
57-
noByronWitnesses
58-
witnesses
5943

6044
data Sizes = Sizes
6145
{ inputs :: Int
@@ -126,16 +110,15 @@ waitForUTxO networkId nodeSocket utxo =
126110

127111
mkGenesisTx ::
128112
NetworkId ->
129-
ProtocolParameters ->
130113
-- | Owner of the 'initialFund'.
131114
SigningKey PaymentKey ->
132115
-- | Amount of initialFunds
133116
Coin ->
134117
-- | Recipients and amounts to pay in this transaction.
135118
[(VerificationKey PaymentKey, Coin)] ->
136119
Tx
137-
mkGenesisTx networkId pparams signingKey initialAmount recipients =
138-
case buildRaw [initialInput] (recipientOutputs <> [changeOutput]) fee of
120+
mkGenesisTx networkId signingKey initialAmount recipients =
121+
case buildRaw [initialInput] (recipientOutputs <> [changeOutput]) of
139122
Left err -> error $ "Fail to build genesis transations: " <> show err
140123
Right tx -> sign signingKey tx
141124
where
@@ -144,18 +127,13 @@ mkGenesisTx networkId pparams signingKey initialAmount recipients =
144127
networkId
145128
(unsafeCastHash $ verificationKeyHash $ getVerificationKey signingKey)
146129

147-
fee = calculateMinFee networkId rawTx Sizes{inputs = 1, outputs = length recipients + 1, witnesses = 1} pparams
148-
rawTx = case buildRaw [initialInput] [] 0 of
149-
Left err -> error $ "Fail to build genesis transactions: " <> show err
150-
Right tx -> tx
151-
152130
totalSent = foldMap snd recipients
153131

154132
changeAddr = mkVkAddress networkId (getVerificationKey signingKey)
155133
changeOutput =
156134
TxOut
157135
changeAddr
158-
(lovelaceToValue $ initialAmount - totalSent - fee)
136+
(lovelaceToValue $ initialAmount - totalSent)
159137
TxOutDatumNone
160138
ReferenceScriptNone
161139

hydra-cluster/src/Hydra/Generator.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ data Dataset = Dataset
3232
instance Arbitrary Dataset where
3333
arbitrary = sized $ \n -> do
3434
sk <- genSigningKey
35-
genDatasetConstantUTxO sk defaultProtocolParameters (n `div` 10) n
35+
genDatasetConstantUTxO sk (n `div` 10) n
3636

3737
data ClientKeys = ClientKeys
3838
{ signingKey :: SigningKey PaymentKey
@@ -79,26 +79,24 @@ defaultProtocolParameters = fromLedgerPParams ShelleyBasedEraShelley def
7979
-- The sequence of transactions generated consist only of simple payments from
8080
-- and to arbitrary keys controlled by the individual clients.
8181
generateConstantUTxODataset ::
82-
ProtocolParameters ->
8382
-- | Number of clients
8483
Int ->
8584
-- | Number of transactions
8685
Int ->
8786
IO Dataset
88-
generateConstantUTxODataset pparams nClients nTxs = do
87+
generateConstantUTxODataset nClients nTxs = do
8988
(_, faucetSk) <- keysFor Faucet
90-
generate $ genDatasetConstantUTxO faucetSk pparams nClients nTxs
89+
generate $ genDatasetConstantUTxO faucetSk nClients nTxs
9190

9291
genDatasetConstantUTxO ::
9392
-- | The faucet signing key
9493
SigningKey PaymentKey ->
95-
ProtocolParameters ->
9694
-- | Number of clients
9795
Int ->
9896
-- | Number of transactions
9997
Int ->
10098
Gen Dataset
101-
genDatasetConstantUTxO faucetSk pparams nClients nTxs = do
99+
genDatasetConstantUTxO faucetSk nClients nTxs = do
102100
clientKeys <- replicateM nClients arbitrary
103101
-- Prepare funding transaction which will give every client's
104102
-- 'externalSigningKey' "some" lovelace. The internal 'signingKey' will get
@@ -109,7 +107,6 @@ genDatasetConstantUTxO faucetSk pparams nClients nTxs = do
109107
let fundingTransaction =
110108
mkGenesisTx
111109
networkId
112-
pparams
113110
faucetSk
114111
(Coin availableInitialFunds)
115112
clientFunds

hydra-cluster/test/Test/GeneratorSpec.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Hydra.Cluster.Util (keysFor)
1313
import Hydra.Generator (
1414
ClientDataset (..),
1515
Dataset (..),
16-
defaultProtocolParameters,
1716
genDatasetConstantUTxO,
1817
)
1918
import Hydra.Ledger (ChainSlot (ChainSlot), applyTransactions)
@@ -46,7 +45,7 @@ prop_keepsUTxOConstant =
4645
let ledgerEnv = newLedgerEnv defaultPParams
4746
-- XXX: non-exhaustive pattern match
4847
pure $
49-
forAll (genDatasetConstantUTxO faucetSk defaultProtocolParameters 1 n) $
48+
forAll (genDatasetConstantUTxO faucetSk 1 n) $
5049
\Dataset{fundingTransaction, clientDatasets = [ClientDataset{txSequence}]} ->
5150
let initialUTxO = utxoFromTx fundingTransaction
5251
finalUTxO = foldl' (apply defaultGlobals ledgerEnv) initialUTxO txSequence

0 commit comments

Comments
 (0)