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

Withdrawals as part of core and API transactions #1892

Merged
merged 11 commits into from
Jul 10, 2020

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented Jul 9, 2020

Issue Number

#1881

Overview

  • 74abe1c
    📍 add withdrawals to API & core transaction data types
    Still to be done: withdrawals must be discovered when processing blocks

  • 0211c5c
    📍 upgrade Byron & Jormungandr compatibility code with empty withdrawals
    Withdrawals are only a thing in Shelley, so for this targets, we can safely replace them by empty lists

  • 861a792
    📍 wire withdrawals in Shelley compatibility code
    Here, we extract withdrawals directly from the TxBody, the conversion is straightforward

  • c36f23a
    📍 include withdrawals where relevant in test and arbitrary generators

  • 9f6738e
    📍 add withdrawals to the API Swagger specification
    We represent them as a list and not a key:value map with stake address as key because clients typically don't know the stake address associated with their wallet, so it'd be quite impractical for them to access this data if returned as a map...

  • e7fcedb
    📍 add roundtrip tests for stake address and show that withdrawals are returned from the API

  • 00c2d69
    📍 Add stake address constraints to Jormungandr and Byron

  • 533b772
    📍 add 'minWithdrawal' query parameter to the swagger specification

  • 07a0f23
    📍 extend transaction API to allow filtering by minimal withdrawals amount
    This is a 'any' sort of filter, such that it returns any transaction where there's at least one withdrawal matching the criteria. The use-case is typically to ask for all transactions where there's a min withdrawal of 1, such that we get the entire withdrawal history

  • 3dd7257
    📍 review integration and unit tests, add additional checks to cover withdrawals

Comments

⚠️ Sorry, the PR spans over many files because I needed to add a new class constraints DecodeStakeAddress which goes side-by-side with the current DecodeAddress.

@KtorZ KtorZ added the ADDING FEATURE Mark a PR as adding a new feature, for auto-generated CHANGELOG label Jul 9, 2020
@KtorZ KtorZ requested a review from paweljakubas July 9, 2020 15:32
@KtorZ KtorZ self-assigned this Jul 9, 2020
_ <- Sqlite.step query
Sqlite.finalize query
ColumnPresent ->
traceWith tr $ MsgManualMigrationNotNeeded field
Copy link
Member Author

Choose a reason for hiding this comment

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

I originally started adding the withdrawal to the TxMeta table but I reverted and went for a new table instead since it behaves much more like current TxIn and TxOut. I however kept this refactor as I thought it wouldn't hurt 😊

txWithdrawalAccount W.ChimericAccount sql=account

Primary txWithdrawalTxId txWithdrawalAccount
deriving Show Generic
Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting stuff actually here ☝️

, withdrawals
:: !(Map ChimericAccount Coin)
-- ^ Withdrawals (of funds from a registered reward account) embedded in
-- a transaction. The order does not matter.
Copy link
Member Author

Choose a reason for hiding this comment

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

And here 👆

Right a
where
msg = TextDecodingError
"Unable to decode stake-address: not a well-formed address."
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a roundtrip test for these instances.

@@ -911,9 +983,6 @@ instance Buildable addr => Buildable (ConnectionId addr) where
instance Buildable LocalAddress where
build (LocalAddress p) = build p

instance Buildable W.ChimericAccount where
build (W.ChimericAccount addr) = hexF addr
Copy link
Member Author

Choose a reason for hiding this comment

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

Found this little orphan 🙃 ... No longer needed since it's define in the core package next to its relevant type declaration.

- amount
properties:
stake_address: *stakeAddress
amount: *amount
Copy link
Member Author

Choose a reason for hiding this comment

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

Here, I've chosen not to represent withdrawals as a key:value map in the API because it would otherwise be a key:value map where all keys are pretty much unknown by the client 😶 ... wallet clients aren't typically aware of what their stake address is, so having something like:

{ "stake_addr1sjck9mdmfyhzvjhydcjllgj9vjvl522w0573ncustrrr2rg7h9azg4cyqd36yyd48t5ut72hgld0fg2x": 42 }

Would make it quite hard for them to inspect the content of that value ^^"... Hence, in the API, I am turning the Map we have internally into a list of object with a stake_address and amount properties.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, sound decision

Copy link
Contributor

@paweljakubas paweljakubas Jul 9, 2020

Choose a reason for hiding this comment

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

Was thinking before how absent withdrawals are going to be represented: either by 0-length array or by making withdrawals in ApiTransaction not required... Why the first option is better?

Copy link
Member Author

Choose a reason for hiding this comment

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

It'll be a 0-length array.

, status :: !(ApiT TxStatus)
} deriving (Eq, Generic, Show)

data ApiWithdrawal n = ApiWithdrawal
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

, mapMaybe fromShelleyDelegationCert (toList certs)
, mapMaybe fromShelleyRegistrationCert (toList certs)
)

fromShelleyWdrl :: SL.Wdrl TPraosStandardCrypto -> Map W.ChimericAccount W.Coin
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -387,15 +387,15 @@ computeTxSize proxy action cs =

dummyKeyHashRaw = BS.pack (replicate 28 0)

withdrawals = mkWithdrawals
wdrls = mkWithdrawals
Copy link
Contributor

Choose a reason for hiding this comment

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

frankly speaking like more previous naming, but understand the probable rationale (80-line styling)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I usually try to keep naming consistent with the surrounding context.

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.

LGTM! would be good not to forget _decodeStakeAddress . _encodeStakeAddress roundtrip. Also some changes are needed in /build/cardano-wallet/lib/core/test/bench/db/Main.hs:408 but it is no surprise when changes in such a core place are made.

@KtorZ KtorZ force-pushed the KtorZ/1881/withdrawals-in-transactions branch from a64f033 to a40b93e Compare July 10, 2020 13:37
@KtorZ
Copy link
Member Author

KtorZ commented Jul 10, 2020

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 10, 2020

Canceled

@KtorZ
Copy link
Member Author

KtorZ commented Jul 10, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Jul 10, 2020
1892: Withdrawals as part of core and API transactions r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#1881 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- 589609e
  📍 **factor out common code in database migration**
  Turns out that adding column is a pretty common and straighfordward migration. I originally intended to add a new column to the TxMeta table, hence the refactor. In the end, I've used a different table for withdrawals, but the refactor is still worth it as it is IMO.

- e9e516c
  📍 **add withdrawals to API & core transaction data types**
  Still to be done: withdrawals must be discovered when processing blocks

- ff58489
  📍 **upgrade Byron & Jormungandr compatibility code with empty withdrawals**
  Withdrawals are only a thing in Shelley, so for this targets, we can safely replace them by empty lists

- 533b787
  📍 **wire withdrawals in Shelley compatibility code**
  Here, we extract withdrawals directly from the TxBody, the conversion is straightforward

- e2e6fbb
  📍 **include withdrawals where relevant in test and arbitrary generators**
  
- 4b6eaba
  📍 **add withdrawals to the API Swagger specification**
  We represent them as a list and not a key:value map with stake address as key because clients typically don't know the stake address associated with their wallet, so it'd be quite impractical for them to access this data if returned as a map...



# Comments

<!-- Additional comments or screenshots to attach if any -->

⚠️ Sorry, the PR spans over many files because I needed to add a new class constraints `DecodeStakeAddress` which goes side-by-side with the current `DecodeAddress`.

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


1895: hydra: Prevent caching of shelley integration test failures r=KtorZ a=rvl

### Issue Number

Not sure.

### Overview

This change causes integration tests to be re-run whenever the git revision changes, even if everything else is identical. Since these tests tend to fail a lot, we don't want to cache false failures.

Also increase the minimum severity for integration test logging, because debug level produces quite a lot of output.


Co-authored-by: KtorZ <[email protected]>
Co-authored-by: IOHK <[email protected]>
Co-authored-by: Rodney Lorrimar <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 10, 2020

Build failed (retrying...)

@KtorZ KtorZ force-pushed the KtorZ/1881/withdrawals-in-transactions branch from ab7bb2b to c947ed4 Compare July 10, 2020 15:01
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 10, 2020

Canceled

@KtorZ KtorZ force-pushed the KtorZ/1881/withdrawals-in-transactions branch 2 times, most recently from c947ed4 to d344780 Compare July 10, 2020 20:06
KtorZ added 7 commits July 10, 2020 23:50
Still to be done: withdrawals must be discovered when processing blocks
Withdrawals are only a thing in Shelley, so for this targets, we can safely replace them by empty lists
Here, we extract withdrawals directly from the TxBody, the conversion is straightforward
We represent them as a list and not a key:value map with stake address as key because clients typically don't know the stake address associated with their wallet, so it'd be quite impractical for them to access this data if returned as a map...
KtorZ added 3 commits July 10, 2020 23:50
This is a 'any' sort of filter, such that it returns any transaction where there's at least one withdrawal matching the criteria. The use-case is typically to ask for all transactions where there's a min withdrawal of 1, such that we get the entire withdrawal history
@KtorZ KtorZ force-pushed the KtorZ/1881/withdrawals-in-transactions branch from 675d507 to 3dd7257 Compare July 10, 2020 21:50
@KtorZ
Copy link
Member Author

KtorZ commented Jul 10, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Jul 10, 2020
1892: Withdrawals as part of core and API transactions r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#1881 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- 74abe1c
  📍 **add withdrawals to API & core transaction data types**
  Still to be done: withdrawals must be discovered when processing blocks

- 0211c5c
  📍 **upgrade Byron & Jormungandr compatibility code with empty withdrawals**
  Withdrawals are only a thing in Shelley, so for this targets, we can safely replace them by empty lists

- 861a792
  📍 **wire withdrawals in Shelley compatibility code**
  Here, we extract withdrawals directly from the TxBody, the conversion is straightforward

- c36f23a
  📍 **include withdrawals where relevant in test and arbitrary generators**
  
- 9f6738e
  📍 **add withdrawals to the API Swagger specification**
  We represent them as a list and not a key:value map with stake address as key because clients typically don't know the stake address associated with their wallet, so it'd be quite impractical for them to access this data if returned as a map...

- e7fcedb
  📍 **add roundtrip tests for stake address and show that withdrawals are returned from the API**
  
- 00c2d69
  📍 **Add stake address constraints to Jormungandr and Byron**
  
- 533b772
  📍 **add 'minWithdrawal' query parameter to the swagger specification**
  
- 07a0f23
  📍 **extend transaction API to allow filtering by minimal withdrawals amount**
  This is a 'any' sort of filter, such that it returns any transaction where there's at least one withdrawal matching the criteria. The use-case is typically to ask for all transactions where there's a min withdrawal of 1, such that we get the entire withdrawal history

- 3dd7257
  📍 **review integration and unit tests, add additional checks to cover withdrawals**



# Comments

<!-- Additional comments or screenshots to attach if any -->

⚠️ Sorry, the PR spans over many files because I needed to add a new class constraints `DecodeStakeAddress` which goes side-by-side with the current `DecodeAddress`.

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: KtorZ <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 10, 2020

Canceled

@KtorZ
Copy link
Member Author

KtorZ commented Jul 10, 2020

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 10, 2020

@iohk-bors iohk-bors bot merged commit df141f5 into master Jul 10, 2020
@iohk-bors iohk-bors bot deleted the KtorZ/1881/withdrawals-in-transactions branch July 10, 2020 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADDING FEATURE Mark a PR as adding a new feature, for auto-generated CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants