Skip to content

Commit 09ee2ba

Browse files
authored
Partial tokens regression test and fix (#2221)
fix #2180 - This PR is the outcome of user reported issue where in their use case it is required to be able to partially commit some assets from the provided UTxO. My opinion is that we should mark this feature as **experimental** until we get confirmations from more users that it is actually working nicely for them which should be tracked in the documentation. - In order to successfully test the fix I had to add the option to mint some tokens in our e2e tests so this adds on to the number of altered files. NOTE: This PR changes our Head script since I had to use `==` from Plinth instead of our own strict equality `===`. This leads to smaller script size so it seems like Plinth equality check is now improved therefore we drop our own strict equality everywhere. --- <!-- Consider each and tick it off one way or the other --> * [x] CHANGELOG updated or not needed * [x] Documentation updated or not needed * [x] Haddocks updated or not needed * [x] No new TODOs introduced or explained herafter
2 parents 69ce551 + 4ecdd88 commit 09ee2ba

File tree

21 files changed

+538
-162
lines changed

21 files changed

+538
-162
lines changed

docs/docs/how-to/incremental-commit.md

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,153 @@ cardano-cli query utxo \
5050
```
5151

5252
:::info
53-
You can also specify `amount` of lovelace you want to commit together with the `UTxO` and hydra-node would
54-
commit only the specified amount and return any leftover to the user address.
53+
You can also specify `amount` of lovelace you want to commit as well as `assets` together with the `UTxO` and hydra-node would
54+
commit only the specified amount of lovelace or any potential non ADA assets and return any leftover to the user address.
5555
:::
5656

57+
:::danger
58+
This functionality should be treated as **experimental** for the time being until we see some user reports that this API is
59+
working well and is easy to use.
60+
:::
61+
62+
<details>
63+
<summary>Partial commit example: </summary>
64+
65+
If there exists a user UTxO that looks like this
66+
67+
```json
68+
{"0bdf069df8fa1084989a7bda419c900810fd5d5a72a95f7ab487f96df9052fb8#0":
69+
{ "address":"addr_test1vq7j5vf74jw779y6ssxk2rwart5mltr2r7ju4gtfc3kcawcy0v2v8",
70+
"datum":null,
71+
"datumhash":null,
72+
"inlineDatum":null,
73+
"inlineDatumRaw":null,
74+
"referenceScript":null,
75+
"value":
76+
{ "dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75":
77+
{ "34":2007797983096461947,
78+
"7041ef64f4476c6f6d8a3c74b7":4866145859671050979,
79+
"b7a7b64d585f973e82be6ca36ae948":2,
80+
"beb7e61cb67dd301":2
81+
},
82+
"lovelace":5000000
83+
}
84+
}
85+
}
86+
87+
```
88+
Then the user can decide to commit some amount of lovelace and assets while the _change_ would be given back to the origin address.
89+
In order to do that they can send a http POST request to the `/commit` endpoint
90+
specifying the _amount_ of ADA and map of _tokens_ with quantities to commit:
91+
92+
```json
93+
94+
{
95+
"amount":3000000,
96+
"tokens":
97+
[
98+
[ "dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75",
99+
{ "34":2007797983096461947,
100+
"7041ef64f4476c6f6d8a3c74b7":4866145859671050979
101+
}
102+
]
103+
],
104+
"utxoToCommit":
105+
{ "0bdf069df8fa1084989a7bda419c900810fd5d5a72a95f7ab487f96df9052fb8#0":
106+
{ "address":"addr_test1vq7j5vf74jw779y6ssxk2rwart5mltr2r7ju4gtfc3kcawcy0v2v8",
107+
"datum":null,
108+
"datumhash":null,
109+
"inlineDatum":null,
110+
"inlineDatumRaw":null,
111+
"referenceScript":null,
112+
"value":
113+
{ "dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75":
114+
{ "34":2007797983096461947,
115+
"7041ef64f4476c6f6d8a3c74b7":4866145859671050979,
116+
"b7a7b64d585f973e82be6ca36ae948":2,
117+
"beb7e61cb67dd301":2
118+
},
119+
"lovelace":5000000
120+
}
121+
}
122+
}
123+
}
124+
125+
```
126+
Hydra node returns a deposit transaction which then needs to be signed and submitted to the network:
127+
128+
```
129+
130+
"d22e92621c1b66d947eff97887feb19c1fb5751ecb7440cd6749ac8d734af04f"
131+
132+
== INPUTS (2)
133+
- 0bdf069df8fa1084989a7bda419c900810fd5d5a72a95f7ab487f96df9052fb8#0
134+
ShelleyAddress Testnet (KeyHashObj (KeyHash {unKeyHash = "3d2a313eac9def149a840d650ddd1ae9bfac6a1fa5caa169c46d8ebb"})) StakeRefNull
135+
5000000 lovelace
136+
2007797983096461947 dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75.34
137+
4866145859671050979 dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75.7041ef64f4476c6f6d8a3c74b7
138+
2 dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75.b7a7b64d585f973e82be6ca36ae948
139+
2 dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75.beb7e61cb67dd301
140+
TxOutDatumNone
141+
ReferenceScriptNone
142+
- 799028d0132ec355d6870704e040b73dbab67dba40313cb4f5dbc42d0e66bd40#1
143+
144+
== COLLATERAL INPUTS (1)
145+
- 799028d0132ec355d6870704e040b73dbab67dba40313cb4f5dbc42d0e66bd40#1
146+
147+
== REFERENCE INPUTS (0)
148+
149+
== OUTPUTS (3)
150+
Total number of assets: 5
151+
- ShelleyAddress Testnet (ScriptHashObj (ScriptHash "ae01dade3a9c346d5c93ae3ce339412b90a0b8f83f94ec6baa24e30c")) StakeRefNull
152+
3000000 lovelace
153+
2007797983096461947 dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75.34
154+
4866145859671050979 dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75.7041ef64f4476c6f6d8a3c74b7
155+
TxOutDatumInline [0,["0x3fbb97e02ed6f34def7b87d9aaff67b4fe707f338d72bc2a7f93a409",1757516160812,[[0,[[0,["0x0bdf069df8fa1084989a7bda419c900810fd5d5a72a95f7ab487f96df9052fb8",0]],"0xd8799fd8799fd8799f581c3d2a313eac9def149a840d650ddd1ae9bfac6a1fa5caa169c46d8ebbffd87a80ffa240a1401a002dc6c0581cdcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75a241341b1bdd21a0bb35da7b4d7041ef64f4476c6f6d8a3c74b71b438805e09eee4ae3d87980d87a80ff"]]]]]
156+
- ShelleyAddress Testnet (KeyHashObj (KeyHash {unKeyHash = "3d2a313eac9def149a840d650ddd1ae9bfac6a1fa5caa169c46d8ebb"})) StakeRefNull
157+
2000000 lovelace
158+
2 dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75.b7a7b64d585f973e82be6ca36ae948
159+
2 dcf5fdd1d01c04b0e6262bba173a89c4b81b6570211f08bc059c8a75.beb7e61cb67dd301
160+
TxOutDatumNone
161+
- ShelleyAddress Testnet (KeyHashObj (KeyHash {unKeyHash = "f8a68cd18e59a6ace848155a0e967af64f4d00cf8acee8adc95a6b0d"})) StakeRefNull
162+
19625359 lovelace
163+
TxOutDatumNone
164+
165+
== TOTAL COLLATERAL
166+
TxTotalCollateralNone
167+
168+
== RETURN COLLATERAL
169+
TxReturnCollateralNone
170+
171+
== FEE
172+
TxFeeExplicit ShelleyBasedEraConway (Coin 197973)
173+
174+
== VALIDITY
175+
TxValidityNoLowerBound
176+
TxValidityUpperBound ShelleyBasedEraConway (Just (SlotNo 38))
177+
178+
== MINT/BURN
179+
0 lovelace
180+
181+
== SCRIPTS (0)
182+
Total size (bytes): 0
183+
184+
== DATUMS (0)
185+
186+
== REDEEMERS (0)
187+
188+
== REQUIRED SIGNERS
189+
[]
190+
191+
== METADATA
192+
TxMetadataInEra ShelleyBasedEraConway (TxMetadata {unTxMetadata = fromList [(55555,TxMetaText "HydraV1/DepositTx")]})
193+
```
194+
195+
If you take a look at the outputs you will see that we only locked specified ADA amount + tokens at the deposit address and gave back any leftover to the
196+
user address.
197+
198+
</details>
199+
57200
Then a request to the `/commit` endpoint provides us with a transaction:
58201

59202
```shell

hydra-cluster/bench/Bench/EndToEnd.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Data.Set ((\\))
2828
import Data.Set qualified as Set
2929
import Data.Text (pack)
3030
import Data.Time (UTCTime (UTCTime), utctDayTime)
31-
import Hydra.Cardano.Api (NetworkId, SocketPath, Tx, TxId, UTxO, getVerificationKey, signTx)
31+
import Hydra.Cardano.Api (NetworkId, SocketPath, Tx, TxId, UTxO, getVerificationKey, lovelaceToValue, signTx)
3232
import Hydra.Chain.Backend (ChainBackend)
3333
import Hydra.Chain.Backend qualified as Backend
3434
import Hydra.Cluster.Faucet (FaucetLog (..), publishHydraScriptsAs, returnFundsToFaucet', seedFromFaucet)
@@ -352,7 +352,7 @@ seedNetwork backend Dataset{fundingTransaction, hydraNodeKeys} tracer = do
352352
fuelWith100Ada signingKey = do
353353
let vk = getVerificationKey signingKey
354354
putTextLn $ "Fuel node key " <> show vk
355-
seedFromFaucet backend vk 100_000_000 tracer
355+
seedFromFaucet backend vk (lovelaceToValue 100_000_000) tracer
356356

357357
-- | Commit all (expected to exit) 'initialUTxO' from the dataset using the
358358
-- (assumed same sequence) of clients.

hydra-cluster/src/Hydra/Cluster/Faucet.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,29 @@ data FaucetLog
4444
deriving stock (Eq, Show, Generic)
4545
deriving anyclass (ToJSON)
4646

47-
-- | Create a specially marked "seed" UTXO containing requested 'Lovelace' by
47+
-- | Create a specially marked "seed" UTXO containing requested 'Value' by
4848
-- redeeming funds available to the well-known faucet.
4949
seedFromFaucet ::
5050
ChainBackend backend =>
5151
backend ->
5252
-- | Recipient of the funds
5353
VerificationKey PaymentKey ->
54-
-- | Amount to get from faucet
55-
Coin ->
54+
-- | Value to get from faucet
55+
Value ->
5656
Tracer IO FaucetLog ->
5757
IO UTxO
58-
seedFromFaucet backend receivingVerificationKey lovelace tracer = do
58+
seedFromFaucet backend receivingVerificationKey val tracer = do
5959
(faucetVk, faucetSk) <- keysFor Faucet
6060
networkId <- Backend.queryNetworkId backend
6161
seedTx <- retryOnExceptions tracer $ submitSeedTx faucetVk faucetSk networkId
6262
producedUTxO <- Backend.awaitTransaction backend seedTx receivingVerificationKey
6363
pure $ UTxO.filter (== toCtxUTxOTxOut (theOutput networkId)) producedUTxO
6464
where
6565
submitSeedTx faucetVk faucetSk networkId = do
66-
faucetUTxO <- findFaucetUTxO networkId backend lovelace
66+
faucetUTxO <- findFaucetUTxO networkId backend (selectLovelace val)
6767
let changeAddress = mkVkAddress networkId faucetVk
6868

69-
buildTransaction backend changeAddress faucetUTxO [] [theOutput networkId] >>= \case
69+
buildTransaction backend changeAddress faucetUTxO (toList $ UTxO.inputSet faucetUTxO) [theOutput networkId] >>= \case
7070
Left e -> throwIO $ FaucetFailedToBuildTx{reason = e}
7171
Right tx -> do
7272
let signedTx = sign faucetSk $ getTxBody tx
@@ -78,7 +78,7 @@ seedFromFaucet backend receivingVerificationKey lovelace tracer = do
7878
theOutput networkId =
7979
TxOut
8080
(shelleyAddressInEra shelleyBasedEra (receivingAddress networkId))
81-
(lovelaceToValue lovelace)
81+
val
8282
TxOutDatumNone
8383
ReferenceScriptNone
8484

@@ -152,7 +152,7 @@ seedFromFaucet_ ::
152152
Tracer IO FaucetLog ->
153153
IO ()
154154
seedFromFaucet_ backend vk ll tracer =
155-
void $ seedFromFaucet backend vk ll tracer
155+
void $ seedFromFaucet backend vk (lovelaceToValue ll) tracer
156156

157157
-- | Return the remaining funds to the faucet
158158
returnFundsToFaucet ::

0 commit comments

Comments
 (0)