-
Notifications
You must be signed in to change notification settings - Fork 217
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
Balance endpoint integration #2906
Balance endpoint integration #2906
Conversation
e83a76f
to
19e95df
Compare
2914: Add updateSealedTx and ExtraTxBodyContent r=Anviking a=Anviking - [x] Refactoring: Replace `to{Shelley, Allegra, Mary, Alonzo}TxOut` with `toCardanoTxOut` for easier re-use. - [x] Add `updateSealedTx :: SealedTx -> ExtraTxBodyContent -> Either ErrUpdateSealedTx SealedTx` - [x] Test that `updateSealedTx noExtraBodyContent` works with all PAB goldens - [x] Test that `updateSealedTx noExtraBodyContent` fails when there are existing key witnesses - [x] Test that inputs and outputs are combined correctly. ### Comments Not tested: - That it works for all previous eras. <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1140 Relates to / should be needed by #2906 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <[email protected]>
2914: Add updateSealedTx and ExtraTxBodyContent r=Anviking a=Anviking - [x] Refactoring: Replace `to{Shelley, Allegra, Mary, Alonzo}TxOut` with `toCardanoTxOut` for easier re-use. - [x] Add `updateSealedTx :: SealedTx -> ExtraTxBodyContent -> Either ErrUpdateSealedTx SealedTx` - [x] Test that `updateSealedTx noExtraBodyContent` works with all PAB goldens - [x] Test that `updateSealedTx noExtraBodyContent` fails when there are existing key witnesses - [x] Test that inputs and outputs are combined correctly. ### Comments Not tested: - That it works for all previous eras. <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1140 Relates to / should be needed by #2906 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <[email protected]>
2914: Add updateSealedTx and ExtraTxBodyContent r=Anviking a=Anviking - [x] Refactoring: Replace `to{Shelley, Allegra, Mary, Alonzo}TxOut` with `toCardanoTxOut` for easier re-use. - [x] Add `updateSealedTx :: SealedTx -> ExtraTxBodyContent -> Either ErrUpdateSealedTx SealedTx` - [x] Test that `updateSealedTx noExtraBodyContent` works with all PAB goldens - [x] Test that `updateSealedTx noExtraBodyContent` fails when there are existing key witnesses - [x] Test that inputs and outputs are combined correctly. ### Comments Not tested: - That it works for all previous eras. <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1140 Relates to / should be needed by #2906 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <[email protected]>
2914: Add updateSealedTx and ExtraTxBodyContent r=Anviking a=Anviking - [x] Refactoring: Replace `to{Shelley, Allegra, Mary, Alonzo}TxOut` with `toCardanoTxOut` for easier re-use. - [x] Add `updateSealedTx :: SealedTx -> ExtraTxBodyContent -> Either ErrUpdateSealedTx SealedTx` - [x] Test that `updateSealedTx noExtraBodyContent` works with all PAB goldens - [x] Test that `updateSealedTx noExtraBodyContent` fails when there are existing key witnesses - [x] Test that inputs and outputs are combined correctly. ### Comments Not tested: - That it works for all previous eras. <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1140 Relates to / should be needed by #2906 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <[email protected]>
2914: Add updateSealedTx and ExtraTxBodyContent r=Anviking a=Anviking - [x] Refactoring: Replace `to{Shelley, Allegra, Mary, Alonzo}TxOut` with `toCardanoTxOut` for easier re-use. - [x] Add `updateSealedTx :: SealedTx -> ExtraTxBodyContent -> Either ErrUpdateSealedTx SealedTx` - [x] Test that `updateSealedTx noExtraBodyContent` works with all PAB goldens - [x] Test that `updateSealedTx noExtraBodyContent` fails when there are existing key witnesses - [x] Test that inputs and outputs are combined correctly. ### Comments Not tested: - That it works for all previous eras. <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1140 Relates to / should be needed by #2906 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <[email protected]>
c0165d1
to
386791f
Compare
UTxOIndex.fromSequence externalInputs | ||
|
||
let utxoAvailable = UTxOSelection.fromIndexPair | ||
(internalUtxoAvailable, externalSelectedUtxo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. 👍🏻
|
||
let UnsignedTx colls inps _outs change _wdrl = unsignedtx | ||
let extraBody = ExtraTxBodyContent | ||
{ extraInputs = (\(txin, _, _) -> txin) <$> F.toList inps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't inps
already include the pre-selected inputs from sealedTxIncoming
?
updateTx
would then try to append the whole inps
to the pre-selected inputs.
Although as the ledger represents the inputs as a Set
, it might not actually matter in the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we may filter out preselected inputs. although ledger stores inputs as set so it should not affect txbody or fee.
19cd20c
to
5d0a3ea
Compare
9a35f0e
to
37bdb06
Compare
(wdrl, _) <- | ||
if Map.member acct wdrlMap then | ||
mkRewardAccountBuilder @_ @s @_ @n ctx wid (Just SelfWithdrawal) | ||
else | ||
mkRewardAccountBuilder @_ @s @_ @n ctx wid Nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(wdrl, _) <- | |
if Map.member acct wdrlMap then | |
mkRewardAccountBuilder @_ @s @_ @n ctx wid (Just SelfWithdrawal) | |
else | |
mkRewardAccountBuilder @_ @s @_ @n ctx wid Nothing | |
(wdrl, _) <- mkRewardAccountBuilder @_ @s @_ @n ctx wid $ | |
if Map.member acct wdrlMap | |
then Just SelfWithdrawal | |
else Nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
-- *However* when used to respresent the inputs known by the wallet, in | ||
-- contrast to all inputs, it can be empty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- *However* when used to respresent the inputs known by the wallet, in | |
-- contrast to all inputs, it can be empty. | |
-- *However* when used to represent the inputs known by the wallet, in | |
-- contrast to all inputs, it can be empty. |
let transform s sel' = | ||
W.assignChangeAddresses genChange sel' s | ||
& uncurry (W.selectionToUnsignedTx (txWithdrawal txCtx)) | ||
unsignedtx <- liftHandler $ W.selectAssets @_ @s @k wrk W.SelectAssetsParams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because selectAssets
only knows about the things we tell it, and not the entire sealedTxIncoming
, I think exotic things like submitting update proposals will result in imbalanced txs.
In a re-thought approach, related to ADP-891, and I think which you've mentioned, we could calculate minfee sealedTxIncoming
instead and go from there (either by overestimating for the TxExtraBodyContent, or trying to find some fix point)
But I guess the similar and more pressing issue is datums, which everyone was aware of on today's call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree here, it is reasonable to start with minFee, and then increment knowing the cost per inp/out/coll. But we need to remember that evaluation of min fee requires number of witnesses, so it would influence selecting inputs/collaterals in feedback loop. It is not staightforward for me how, in details, it should work
@@ -1346,28 +1346,24 @@ selectionToUnsignedTx wdrl sel s = | |||
fullyQualifiedWithdrawal wdrl | |||
} | |||
where | |||
-- NOTE: External addresses, not known to the wallet, will be filtered out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When talking briefly with Nikola and hearing / being reminded that they will present the result of balanceTransaction in full detail to the user, this seems wrong.
We probably should:
- Make the
DerivationPath
optional onApiCoinSelection
- Don't filter out pre-selected inputs/outputs
- Ensure all other possible tx data is exposed. (We're probably missing glue code for showing datums in api here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Not critical for merging this PR and I could have a look)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Daedalus will invoke balance tx, so it will know details of external inputs already - see "inputs" in https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/balanceTransaction And in ApiCoinSelection
we will present ADDED inps/outs/colls (always being the resource of the wallet). So the client will know everything having "inputs" and response.
Some argument in favor of what is now is that it is in line what constructTx responds, and as both construct and balance are first step before sign+submit. It makes sense to be compatible....
37bdb06
to
f93e437
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is great to see this start coming together concretely!
My take is that remaining problems are:
- Critical: Ensure fees are not underestimated because of
datums
- Critical: Ensure e.g. ProtocolParameter Hash, or other stuff won't lead to underestimated fees
- Moderate: Is the API response for CoinSelection appropriate for Daedalus?
- Low/Moderate: Certificates, update proposals leading to underestimated fees
and that we shouldn't rush to merge this before seeing how the critical things will pan out.
I suspect there are 3 potential solutions for (1):
a. Tweak the coin selection in a minimal / hacky way to account for datums
b. Call ledger/node's minfee
in a loop - first on the partial input tx, and then after adding inputs and outputs until you converge.
c. Call ledger/node's minfee
once, and then use the existing TxConstraints
overestimations to add additional inputs and outputs.
Edit
I must have gotten confused in the original message. Got things a bit wrong. Now edited. We are adjusting the original binary. Ensuring tx body content is preserved is not the problem. The problem is ensuring the fee estimation also is aware of all that content.
(ApiTxOut (ApiT addr, _) _ (Quantity amt) (ApiT assets))) = | ||
(TxIn hashTx ix, TxOut addr (TokenBundle (Coin $ fromIntegral amt) assets)) | ||
externalInputs = toTxInTxOut <$> apiExternalInps | ||
sealedTxIncoming = body ^. #transaction . #getApiT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some stylistic thoughts:
I think I have more of a taste for either:
- Defining important values as
let
bindings at the top - Making the
where
definitions all functions rather than values
such that you can read it from top to bottom and easily see where txIncoming
is coming from.
balanceTransaction ctx genChange (ApiT wid) body = do | ||
pp <- liftIO $ NW.currentProtocolParameters nl | ||
|
||
--TODO deal with coll and validity and delegations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Yes.
Collateral we could simply forbid as discussed.
Delegations and other stuff could be present in the sealedTxIncoming, but are probably not crucial. (unused by PAB)
Validity, however, does sound crucial to support. (used by PAB)
Related to #2906 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 might have gotten this slightly wrong. Will revisit tomorrow.
lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs
Show resolved
Hide resolved
fc3ea41
to
18be8f9
Compare
bors r+ |
2906: Balance endpoint integration r=paweljakubas a=paweljakubas <!-- Detail in a few bullet points the work accomplished in this PR. Before you submit, don't forget to: * Make sure the GitHub PR fields are correct: ✓ Set a good Title for your PR. ✓ Assign yourself to the PR. ✓ Assign one or more reviewer(s). ✓ Link to a Jira issue, and/or other GitHub issues or PRs. ✓ In the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages. * Don't waste reviewers' time: ✓ If it's a draft, select the Create Draft PR option. ✓ Self-review your changes to make sure nothing unexpected slipped through. * Try to make your intent clear: ✓ Write a good Description that explains what this PR is meant to do. ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding Jira ticket. ✓ Highlight what Testing you have done. ✓ Acknowledge any changes required to the Documentation. --> adp-656 We have preliminary impl of balanceTransaction that needs to work: 1. coin selection with external inputs (@jonathanknowles ) DONE 2. updateTx impl in shelley (@Anviking ) DONE running tests: ``` stack test --ta '-m "TRANS_NEW_BALANCE_"' cardano-wallet:integration ``` ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Pawel Jakubas <[email protected]> Co-authored-by: Johannes Lund <[email protected]>
For pre-selected external addresses, we cannot find derivation paths. So rather than erroring: ``` "selectionToUnsignedTx: unable to find derivation path of a known \ \input or change address. This is impossible.") (traverse withDerivationPath hasAddresses) ``` This commit filters them out. This has the effect of: 1. Making `stack test --ta '-m "TRANS_NEW_BALANCE_"' cardano-wallet:integration pass` 2. Removing the requirement that all ApiCoinSelections have a non-empty list of inputs.
some cleaning
some cleaning
18be8f9
to
ac30014
Compare
Canceled. |
bors r+ |
Build succeeded: |
adp-656
We have preliminary impl of balanceTransaction that needs to work:
running tests:
Comments
Issue Number