Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pay back funds to faucet after smoke-test run #770

Closed
wants to merge 7 commits into from

Conversation

v0d1ch
Copy link
Contributor

@v0d1ch v0d1ch commented Mar 10, 2023

Why

As part of the Mainnet compatibility issue #713 we would like to be able to return the funds back to our faucet.

NOTE: This PR introduces a hardcoded amount for the fees 1_200_000 and we should look into calculating fees for smoke-tests in the future.

  • CHANGELOG updated
  • Documentation updated
  • Added and/or updated haddocks
  • No new TODOs introduced or explained herafter

@v0d1ch v0d1ch self-assigned this Mar 10, 2023
@v0d1ch v0d1ch force-pushed the smoke-tests-can-run-on-mainnet branch from 260090f to 3ba4d4a Compare March 10, 2023 15:28
v0d1ch added 6 commits March 10, 2023 16:28
- We want to also be able to return funds to the faucet on mainnet
- Now they are not only refering to the Faucet but can also be
an exception for Actor when we are returning funds to the faucet.
… better

- When returning funds use queryUTxOFor instead of queryMarkedUTxo
- When we _seed from faucet_ we expect one faucet utxo to contain more
lovelace than expected. BUT when we want to return the funds to the
faucet we actually don't care about filtering.

- Added a todo on how to handle fees when returning funds?
@v0d1ch v0d1ch force-pushed the smoke-tests-can-run-on-mainnet branch from 3ba4d4a to 44dc719 Compare March 10, 2023 15:28
@github-actions
Copy link

github-actions bot commented Mar 10, 2023

Transactions Costs

Sizes and execution budgets for Hydra protocol transactions. Note that unlisted parameters are currently using arbitrary values and results are not fully deterministic and comparable to previous runs.

Metadata
Generated at 2023-03-14 15:16:55.771940988 UTC
Max. memory units 14000000
Max. CPU units 10000000000
Max. tx size (kB) 16384

Script summary

Name Hash Size (Bytes)
νInitial 9492414f8f96e8483a0b8ee268fc06a954641cb2cbaa9a8b093c2c9b 4621
νCommit 5d3f107aaa56d06188cf231941cf8163e777236a9cfdc48fd4bbfa23 2422
νHead 82f16b51e2d81c6f4d42dd7398b4713a445464902f63dfd86ffe754e 8954
μHead 4083fa7081a0f4b4092fb02867c9ac594bb0e8bab8110ab242ba5a72* 4458
  • The minting policy hash is only usable for comparison. As the script is parameterized, the actual script is unique per Head.

Cost of Init Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 5056 15.70 6.23 0.54
2 5260 15.59 6.10 0.55
3 5468 17.87 6.95 0.59
5 5875 23.88 9.27 0.67
10 6897 34.64 13.29 0.83
37 12437 99.27 37.71 1.77

Cost of Commit Transaction

Currently only one UTxO per commit allowed (this is about to change soon)

UTxO Tx size % max Mem % max CPU Min fee ₳
1 603 15.75 6.19 0.35

Cost of CollectCom Transaction

Parties UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
1 57 817 24.67 10.02 0.46
2 113 1139 40.66 16.63 0.65
3 169 1460 59.08 24.31 0.87
4 227 1785 80.78 33.37 1.12

Cost of Close Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 635 16.99 7.31 0.37
2 813 18.69 8.19 0.40
3 969 19.78 8.84 0.42
5 1299 22.95 10.54 0.47
10 2132 29.62 14.27 0.59
50 8725 85.71 45.19 1.55

Cost of Contest Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 668 22.21 9.29 0.43
2 841 23.49 10.01 0.45
3 998 25.64 11.06 0.48
5 1344 29.02 12.81 0.54
10 2152 37.67 17.26 0.67
46 8094 99.96 49.28 1.67

Cost of Abort Transaction

Some variation because of random mixture of still initial and already committed outputs.

Parties Tx size % max Mem % max CPU Min fee ₳
1 5244 30.47 13.09 0.72
2 5493 47.99 20.73 0.93
3 5814 70.08 30.47 1.19
4 6140 95.72 41.76 1.49

Cost of FanOut Transaction

Involves spending head output and burning head tokens. Uses ada-only UTxO for better comparability.

Parties UTxO UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
5 0 0 5077 10.59 4.43 0.49
5 1 57 5113 12.12 5.31 0.51
5 5 285 5262 18.22 8.83 0.59
5 10 569 5437 25.85 13.24 0.69
5 20 1140 5798 41.11 22.05 0.90
5 30 1708 6161 56.37 30.86 1.10
5 40 2278 6513 71.64 39.68 1.30
5 50 2847 6877 86.92 48.50 1.50
5 58 3297 7156 99.14 55.56 1.67

@github-actions
Copy link

github-actions bot commented Mar 10, 2023

Test Results

296 tests   - 1   290 ✔️  - 1   24m 55s ⏱️ + 5m 14s
  99 suites ±0       6 💤 ±0 
    5 files   ±0       0 ±0 

Results for commit 5011714. ± Comparison against base commit 497ccb1.

This pull request removes 1 test.
Hydra.Chain.Direct.State/commit ‑ reject Commits with more than maxMainnetLovelace Lovelace

♻️ This comment has been updated with latest results.

(senderVk, senderSk) <- keysFor sender
utxo <- queryUTxOFor networkId nodeSocket QueryTip senderVk
-- TODO: 'balance' here is just `foldMap txOutValue` so it doesn't actually ballance anything.
-- How to exclude the fees from the amount? This hardcoded subtraction needs to go away
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precise error is hydra-cluster: FailedToBuildTx {reason = TxBodyErrorAdaBalanceNegative (Lovelace (-173949))}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We introduced a hardcoded fix for the fees since we are missing the fee calculation in smoke-tests.

@v0d1ch v0d1ch marked this pull request as ready for review March 14, 2023 09:43
@v0d1ch v0d1ch requested review from ffakenz and ch1bo March 14, 2023 09:44
@v0d1ch v0d1ch changed the title Smoke tests can run on mainnet Pay back funds to faucet after smoke-test run Mar 14, 2023
@ch1bo ch1bo mentioned this pull request Mar 14, 2023
4 tasks
@v0d1ch v0d1ch force-pushed the smoke-tests-can-run-on-mainnet branch from 2cc3d65 to 5011714 Compare March 14, 2023 15:01
Copy link
Member

@ch1bo ch1bo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments on how to do this differently. Happy to pair with you on this if you want, just mention it.

@@ -37,8 +37,8 @@ import Hydra.Ledger.Cardano ()
data Marked = Fuel | Normal

data FaucetException
= FaucetHasNotEnoughFunds {faucetUTxO :: UTxO}
| FaucetFailedToBuildTx {reason :: TxBodyErrorAutoBalance}
= NotEnoughFunds {utxos :: UTxO, requestedAmount :: Lovelace}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: use utxo for a name as it's more often used in the code base.

-- | Sender signing key
SigningKey PaymentKey ->
-- | Should we filter utxo to find the one containing more lovelace than we want to send?
Bool ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: not compose functions this way.

This Bool is a smell to me. It indicates that you are using only a part of the code below in some cases. Why not structure it differently to assemble what you need and don't need better?

I'll point out more comments at the usage sites.

let fuelBalance = selectLovelace $ balance @Tx fuelUTxO
when (fuelBalance < amount) $ do
utxo <- seedFromFaucet node actorVk amount Fuel (contramap FromFaucet tracer)
traceWith tracer $ RefueledFunds{actor = actorName actor, refuelingAmount = amount, fuelUTxO = utxo}
utxo <- sendFundsTo node (senderVk, senderSk) receivingVk amount Fuel (contramap FromFaucet tracer) True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: use the better named and higher-level API (using the actor type) seedFromFaucet here.

It's not clear to me why the lower-level sendFundsTo was used here. The whole refuelIfNeeded should stay as it was.

-- Bit ugly bit we need to subtract the fees manually here.
-- TODO: Implement the fee calculation for our smoke-tests
let returnBalance = (selectLovelace $ balance @Tx utxo) - 1_200_000
void $ sendFundsTo node (senderVk, senderSk) receivingVk returnBalance Normal (contramap FromFaucet tracer) False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: do what sendFundsTo ... Normal ... False means directly here.

This is the only usage of sendFundsTo with this parameterization, so there is no point in creating a function, which even contains optional semantics (smelly).

else utxos
when (null foundUTxO) $
throwIO $ NotEnoughFunds{utxos, requestedAmount = lovelace}
pure foundUTxO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: not compose functions this way.

This is seedFromFaucet specific functionality and the Bool flag is smelly. Keep this functionality in seedFromFaucet, and not change it .. or change it with the enhancement of selecting multiple UTxo to meet the requested lovelace. (This is what this PR should be about).

If you want to reduce boiler plate of the queryUTxO networkId nodeSocket QueryTip [buildAddress faucetVk networkId], that would be a good function to have a separate queryFaucetUTxO or so if you want (but not do refactor too early).

-- | Determine the amount we want to grab from the faucet based on network
seedFromFaucetAmount :: NetworkId -> Lovelace
seedFromFaucetAmount Mainnet = 100_000_000
seedFromFaucetAmount _ = 100_000_000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: not do this, but just find a common denominator between networks.

I see why you want to do this, but I think it's not important how much we seed things with. It just needs to meet the minimum UTxO requirements. We don't expect these tests don't behave different with big or small amounts (if we would, we also should test NFTs). These are only E2E or even smoke tests - their scope is limited.

This parameter can stay uniform for all networks as we do not change valuation or minima in the parameters.

@v0d1ch
Copy link
Contributor Author

v0d1ch commented Mar 15, 2023

closing in favor of #773

@v0d1ch v0d1ch closed this Mar 15, 2023
@ch1bo ch1bo deleted the smoke-tests-can-run-on-mainnet branch March 17, 2023 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants