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

Add W.balanceTx helper #4629

Merged
merged 1 commit into from
Jun 25, 2024
Merged

Add W.balanceTx helper #4629

merged 1 commit into from
Jun 25, 2024

Conversation

Anviking
Copy link
Member

@Anviking Anviking commented Jun 13, 2024

Add W.balanceTx helper used by the following endpoints

  • constructTransaction
  • constructTransactionShared
  • balanceTransaction

such that

  • A future PR can make W.balanceTx automatically query the node for the UTxO corresponding to the inputs of the PartialTx (this is part of the fix for the integration test in the 8.11 branch; if we have the UTxO of the reference input, then Ledger.getMinFeeTxUtxo pp tx utxo will correctly account for minFeeRefScriptCoinsPerByte * totalRefScriptSize)
  • We can hide some balanceTx configuration (utxoAssumptions, argGenChange) to the api handlers

Comments

Issue Number

ADP-3373

@Anviking Anviking self-assigned this Jun 13, 2024
@Anviking Anviking force-pushed the anviking/ADP-3373/wrap-balanceTx branch 2 times, most recently from 03326ac to 92d8064 Compare June 13, 2024 17:49
Comment on lines 2201 to 2214
sharedWalletScriptLookup
:: SharedState (NetworkOf s) SharedKey -> Address -> CA.Script KeyHash
sharedWalletScriptLookup s addr = case fst (isShared addr s) of
Nothing ->
error $ "Some inputs selected by coin selection do not belong "
<> "to multi-signature wallet"
Just (ix,role) ->
let template = paymentTemplate s
role' = case role of
UtxoExternal -> CAShelley.UTxOExternal
UtxoInternal -> CAShelley.UTxOInternal
MutableAccount ->
error "role is specified only for payment credential"
in replaceCosignersWithVerKeys role' template ix
Copy link
Member Author

Choose a reason for hiding this comment

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

Simply moved from constructUnbalancedSharedTransaction

Comment on lines -397 to +388
:<|> balanceTransaction
shelley
(delegationAddressS @n)
(utxoAssumptionsForWallet ShelleyWallet)
mempty
:<|> balanceTransaction shelley
Copy link
Member Author

@Anviking Anviking Jun 13, 2024

Choose a reason for hiding this comment

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

☝️ (nicer)

(Shared.paymentTemplate (getState wallet))
(sharedWalletScriptLookup (getState wallet)
. Convert.toWalletAddress)

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we are in IO, we will be able to query the node for extra UTxO info here later.

@Anviking Anviking marked this pull request as ready for review June 13, 2024 20:01
-> IO (Write.Tx era)
balanceTx wrk pp timeTranslation partialTx = do
(utxo, wallet, _txs) <- liftIO $ readWalletUTxO wrk
-- FIXME: Why are we not using the availableUTxO here?
Copy link
Member Author

@Anviking Anviking Jun 13, 2024

Choose a reason for hiding this comment

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

🤔

This is not the PR to change it, but it probably should be changed.

@@ -3854,6 +3892,13 @@ data PoolRetirementEpochInfo = PoolRetirementEpochInfo
}
deriving (Eq, Generic, Show)

throwOnErr :: (MonadIO m, Exception e) => Either e a -> m a
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if those things should not be somewhere else to be reused by other modules and packages... Possible here https://github.com/cardano-foundation/cardano-wallet/blob/master/lib/wallet/src/UnliftIO/Compat.hs or somewhere close to it. Maybe this is proper place as it is not needed elsewhere

Copy link
Member

Choose a reason for hiding this comment

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

I agree it would be nice to co-locate these helpers.

But perhaps somewhere else other than UnliftIO, as that is specific to the unliftio way of doing things.

Thoughts?

Copy link
Contributor

@paweljakubas paweljakubas left a comment

Choose a reason for hiding this comment

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

Looks like a nice code reshuffling that gives rise to simplification on api side and moving logic and details under the hood 👍 If everything passes we are good here IMHO

Copy link
Member

@jonathanknowles jonathanknowles left a comment

Choose a reason for hiding this comment

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

LGTM! Just have a small number of suggestions.

Comment on lines +5101 to +5106
toApiSerialisedTransaction maybeEncoding tx =
let
encoding = fromMaybe Base64Encoded maybeEncoding
in
ApiSerialisedTransaction (ApiT $ sealWriteTx tx) encoding
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, why not:

Suggested change
toApiSerialisedTransaction maybeEncoding tx =
let
encoding = fromMaybe Base64Encoded maybeEncoding
in
ApiSerialisedTransaction (ApiT $ sealWriteTx tx) encoding
toApiSerialisedTransaction maybeEncoding tx =
ApiSerialisedTransaction (ApiT $ sealWriteTx tx) encoding
where
encoding = fromMaybe Base64Encoded maybeEncoding

(Saves both horizontal and vertical space.)

Copy link
Member Author

Choose a reason for hiding this comment

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

In this specific example I think I like how you see the flow of

  1. maybeEncoding introduced (parameter)
  2. maybeEncoding transformed into encoding
  3. encoding is used

in order, as opposed to 1-3-2 with where.

lib/wallet/src/Cardano/Wallet.hs Outdated Show resolved Hide resolved
@@ -3854,6 +3892,13 @@ data PoolRetirementEpochInfo = PoolRetirementEpochInfo
}
deriving (Eq, Generic, Show)

throwOnErr :: (MonadIO m, Exception e) => Either e a -> m a
Copy link
Member

Choose a reason for hiding this comment

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

I agree it would be nice to co-locate these helpers.

But perhaps somewhere else other than UnliftIO, as that is specific to the unliftio way of doing things.

Thoughts?

lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs Outdated Show resolved Hide resolved
@Anviking Anviking force-pushed the anviking/ADP-3373/wrap-balanceTx branch 2 times, most recently from 6b6f182 to 81b160c Compare June 24, 2024 19:15
@Anviking Anviking added this pull request to the merge queue Jun 24, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jun 25, 2024
@Anviking Anviking added this pull request to the merge queue Jun 25, 2024
@Anviking Anviking removed this pull request from the merge queue due to a manual request Jun 25, 2024
@Anviking Anviking force-pushed the anviking/ADP-3373/wrap-balanceTx branch from 81b160c to 620ff36 Compare June 25, 2024 11:00
@Anviking Anviking enabled auto-merge June 25, 2024 11:01
@Anviking Anviking added this pull request to the merge queue Jun 25, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 25, 2024
@Anviking Anviking added this pull request to the merge queue Jun 25, 2024
Merged via the queue into master with commit fae66a5 Jun 25, 2024
3 checks passed
@Anviking Anviking deleted the anviking/ADP-3373/wrap-balanceTx branch June 25, 2024 12:54
github-merge-queue bot pushed a commit that referenced this pull request Jun 27, 2024
- Add `getUTxOByTxIn` local state query
- Resolve `PartialTx` inputs over LSQ in `Cardano.Wallet.balanceTx`

### Comments

This is part of the fix for the [integration test in the 8.11
branch](https://buildkite.com/cardano-foundation/cardano-wallet/builds/5254#018fee3c-01ad-441e-bb7e-25acd78cb7f3);
if we have the UTxO of the reference input containing the script used
for minting in constructTx, then `Ledger.getMinFeeTxUtxo pp tx utxo`
will correctly account for minFeeRefScriptCoinsPerByte *
totalRefScriptSize.

Previous step: #4629
Next step: #4631

### Issue Number

ADP-3373
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.

3 participants