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

Display serialised tx endpoint #2977

Merged
merged 31 commits into from
Nov 2, 2021

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Oct 15, 2021

adp-974

  • swagger update
  • adding types
  • adding decodeTransaction in Server
  • add lookupTxIns in Wallet
  • add lookupTxOuts in Wallet
  • adjust unit testing
  • add integration tests for inputs/outputs/withdrawals/metadata

The endpoint acts in the context of a given wallet and is able to detect the wallet's resources. In detail, the enpdoint detects:

  • id of tx
  • fee
  • inputs, belonging to other wallets and the wallets - in that case it lookups utxo and give amount and derivation path
  • outputs, belonging to other wallets or to the wallets - in that case it either see its output or change (here it looks ahead using gap) and enrich info by current amount and derivation path of address
  • withdrawals, belonging to other wallet or the wallet
  • metadata
  • script validity

Comments

Issue Number

@paweljakubas paweljakubas self-assigned this Oct 15, 2021
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-974/display-serialised-tx-endpoint branch 4 times, most recently from 2a0666c to db7a720 Compare October 22, 2021 13:22
@paweljakubas paweljakubas marked this pull request as ready for review October 25, 2021 19:03
@paweljakubas paweljakubas requested review from rvl and Anviking October 25, 2021 19:04
[] -> (txin, Nothing) -- will probably use error here
path':_ -> (txin, Just (txout, path'))

extAddr
Copy link
Member

Choose a reason for hiding this comment

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

  1. We could probably find a more descriptive name than extAddr. Seems similar to the existing normalizeDelegationAddress, but perhaps different enough not to combine.
  2. But... Why are we modifying the address in the first place? 🤔 That seems very off to me. We should be looking up addresses based on their payment key hashes only, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ad 1. yes, normaliseDelegationAddress does almost the same as extAddr
ad 2. Why we needed? Because in the cbor there is delegation address as represented in the chain. and we store fingerprints really, so we need to adjust them in order to compare.

lib/core/src/Cardano/Wallet.hs Outdated Show resolved Hide resolved
where
db = ctx ^. dbLayer @IO @s @k
tryGetTxOutPath cp walletAddrs txin =
case UTxO.lookup txin (totalUTxO mempty cp) of
Copy link
Member

@Anviking Anviking Oct 26, 2021

Choose a reason for hiding this comment

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

Isn't totalUTxO mempty cp the same thing as utxo cp? But seems good that we don't remove the inputs from the pending txs — I take the pending txs wouldn't be decodable/displayable then.

Also, not sure we need to nor if we should, but we could:

  • Use changeUTxO pending s <> utxo (but not excluding pending inputs), to be able to resolve chains of dependent txs (I don't think this would work currently)
  • Use LSQ to (potentially) lookup the txin in the node's full UTxO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about pending txs. I would for now use totalUTxO mempty cp and think about pending tx in the next move

lib/core/src/Cardano/Wallet.hs Outdated Show resolved Hide resolved
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-974/display-serialised-tx-endpoint branch from 128ca64 to e8ee5bf Compare October 28, 2021 15:09
@paweljakubas paweljakubas requested a review from Anviking October 28, 2021 15:13
@Anviking
Copy link
Member

@paweljakubas Sorry, but I didn't see the point of most of the complicated (and seemingly a bit out-of-place) logic in lookupTx{Ins,Outs} 😅 I tried replacing most of it with just isOurs in 32480e1, and tests seemed to pass, except for in one place where I believe the test expected the wrong value (c0c9b73).

Could you let me know if it looks good to you or whether I have misunderstood something?

@paweljakubas
Copy link
Contributor Author

maybe it is ok to reuse isOurs but you erased the code that adds change addresses to "candidate" addresses. Why it is needed? Because this endpoint should work after construction, signing and discovery. And after construction we can omit these change addresses, right? so we need to sneak them (here assumption is that pool gap restriction is used)

, ix )
let walletAddrs = map f $ knownAddresses (getState cp)

--We are analyzing the next gapPool change addresses
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so we need this changeAddrs, otherwise source wallet will not see change address in outputs UNTIL the wallet discovers tx (so after submit). That is consequence of decoupling construction/signing/submitting and persisting pending things only during submitting

@@ -479,7 +479,7 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
let addrDest = (addrs !! addrIx) ^. #id
let expectedTxOutTarget = WalletOutput $ ApiWalletOutput
{ address = addrDest
, amount = Quantity 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no it should be 0. This is what is currently in this address. So after construction, source wallet does not see this as WalletOutput but ExternalOutput. Target wallet see this as WalletOuptut, and see amountIncoming=Quantity amt, but amount=Quantity 0 as there is nothing at THIS stage in this wallet. Right? It is going to be amount=amountIncoming after discovery. I did this on purpose to have a way to see whole cycle if this resource is ours :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see line 548 and

        let expectedTxOutTarget' = WalletOutput $ ApiWalletOutput
                { address = addrDest
                , amount = Quantity amt -- now we have this
                , assets = ApiT TokenMap.empty
                , derivationPath = NE.fromList
                    [ ApiT (DerivationIndex 2147485500)
                    , ApiT (DerivationIndex 2147485463)
                    , ApiT (DerivationIndex 2147483648)
                    , ApiT (DerivationIndex 0)
                    , ApiT (DerivationIndex $ fromIntegral addrIx)
                    ]
                , amountIncoming = Quantity amt
                , assetsIncoming = ApiT TokenMap.empty
                }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is after submitting and discovering

@Anviking Anviking force-pushed the paweljakubas/adp-974/display-serialised-tx-endpoint branch from 32480e1 to 1746cac Compare November 1, 2021 14:22
This commit does sacrifice the distinction between amount and
amount_incoming. The next commit addresses that.
My reason being the combination of:

1. Unclear why we need it for this task / now. There might be interesting things to do here,
   but that we should be clear about what problem we're trying to solve, such that we can create
   a solution we're fully confident in.
2. Exposing balances of individual addresses feels at odds with the point of the wallet otherwise
   being maintaining a concept of balance for all addresses combined.
3. It seemed to make the implementation much more complicated
1. Check that the change output is recognized
2. Use `shouldContain` and `shouldNotContain` rather than
`shouldSatisfy` and `elem` for nicer error messages.
@Anviking Anviking force-pushed the paweljakubas/adp-974/display-serialised-tx-endpoint branch from 2dd3ccd to f7977b8 Compare November 2, 2021 12:03
Copy link
Member

@Anviking Anviking left a comment

Choose a reason for hiding this comment

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

lgtm! Hoping we at some point later on can get CBOR <-> JSON roundtrip properties, which I believe would be the ultimate test that we display all information!

@Anviking
Copy link
Member

Anviking commented Nov 2, 2021

bors r+

, expectField #outputs (`shouldNotContain` [expectedTxOutTarget])

-- Check that the change output is there:
, expectField (#outputs) ((`shouldBe` 1) . length . filter isOutOurs)
Copy link
Member

Choose a reason for hiding this comment

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

I added a check for the change output in the last commit along with a slight tweak, using should{Not}Contain [txOut] rather than shouldSatisfy and elem, which should produce nicer error messages and be slightly simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good change

@paweljakubas
Copy link
Contributor Author

paweljakubas commented Nov 2, 2021

@Anviking thanks for the thorough review and commits! I will create following ticket in which we property test using genTx and expose mint/burn and other things in this endpoint

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 2, 2021

Build succeeded:

@iohk-bors iohk-bors bot merged commit c8cbdb8 into master Nov 2, 2021
@iohk-bors iohk-bors bot deleted the paweljakubas/adp-974/display-serialised-tx-endpoint branch November 2, 2021 13:15
WilliamKingNoel-Bot pushed a commit that referenced this pull request Nov 2, 2021
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