Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debug points
Browse files Browse the repository at this point in the history
ffakenz committed Apr 4, 2024
1 parent fdc23db commit 98432c5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions hydra-cluster/src/Hydra/Cluster/Faucet.hs
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import Control.Exception (IOException)
import Control.Monad.Class.MonadThrow (Handler (Handler), catches)
import Control.Tracer (Tracer, traceWith)
import GHC.IO.Exception (IOErrorType (ResourceExhausted), IOException (ioe_type))
import Hydra.Cardano.Api.Pretty (renderTx)
import Hydra.Chain.CardanoClient (queryProtocolParameters)
import Hydra.Chain.Direct.ScriptRegistry (
publishHydraScripts,
@@ -112,16 +113,24 @@ returnFundsToFaucet tracer node@RunningNode{networkId, nodeSocket} sender = do

(senderVk, senderSk) <- keysFor sender
utxo <- queryUTxOFor networkId nodeSocket QueryTip senderVk
traceShowM ("RemainingFunds utxo:" <> renderUTxO utxo)
retryOnExceptions tracer $ do
let utxoValue = balance @Tx utxo
let allLovelace = selectLovelace utxoValue
traceShowM ("allLovelace:" <> show allLovelace)
-- select tokens other than ADA here so we can burn it afterwards
let otherTokens = filterValue (/= AdaAssetId) utxoValue
traceShowM ("otherTokens:" <> renderValue otherTokens)
-- XXX: Using a hard-coded high-enough value to satisfy the min utxo value.
-- NOTE: We use the faucet address as the change deliberately here.
fee <- calculateTxFee node senderSk utxo faucetAddress 1_500_000
fee <- calculateTxFee node senderSk utxo faucetAddress 1_000_000
traceShowM ("fee:" <> show fee)
let returnBalance = allLovelace - fee
tx <- sign senderSk <$> buildTxBody utxo faucetAddress returnBalance otherTokens
traceShowM ("returnBalance:" <> show returnBalance)
returnTxBody <- buildTxBody utxo faucetAddress returnBalance otherTokens
traceShowM ("returnTxBody:" <> show returnTxBody)
let tx = sign senderSk returnTxBody
traceShowM ("tx:" <> renderTx tx)
submitTransaction networkId nodeSocket tx
void $ awaitTransaction networkId nodeSocket tx
traceWith tracer $ ReturnedFunds{actor = actorName sender, returnAmount = returnBalance}

0 comments on commit 98432c5

Please sign in to comment.