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

Get reward account balance #1750

Closed
rvl opened this issue Jun 12, 2020 · 2 comments
Closed

Get reward account balance #1750

rvl opened this issue Jun 12, 2020 · 2 comments
Assignees

Comments

@rvl
Copy link
Contributor

rvl commented Jun 12, 2020

Context

Jira ticket: ADP-302

User Story

As a user, I want to check the rewards I have currently accumulated

Given my wallet is in sync

And I have the public key

Or I have the mnemonic

Then I can check the current delegation certificates

Overview

The delegation rewards balance is shown as part of the shelley wallet balance in the API.

This task is to implement the function in the shelley network layer which queries the cardano-node backend for the reward account balance.

There is some overlap with ADP-301 Check current delegation preference because the same cardano-node query method is used.

Decision

The wallet rewards address is already known. It is passed as the parameter to this network layer method.

getAccountBalance
    :: NetworkLayer IO (IO Shelley) ShelleyBlock
    -> ChimericAccount
    -> ExceptT ErrGetAccountBalance m (Quantity "lovelace" Word64)

The shelley implementation of this method should use the node local state query protocol to get the stake address info.

A model for this could be the cardano-cli shelley query stake-address-info command. Its implementation is in Cardano.Api.LocalStateQuery.queryDelegationsAndRewardsFromLocalState (cardano-node repo / cardano-api package).

The ChimericAccount address must be converted to a shelley stake credential.

In the shelley network layer, create a queue of LocalStateQueryCmd ShelleyBlock GetFilteredDelegationsAndRewardAccounts

-- cardano-wallet-shelley
data LocalStateQueryCmd block state (m :: * -> *)
    = CmdQueryLocalState
        (Point block)
        (Query block state)
        (LocalStateQueryResult state -> m ())

-- ouroboros-consensus-shelley
-- Ouroboros.Consensus.Shelley.Ledger.Ledger
instance TPraosCrypto c => QueryLedger (ShelleyBlock c) where
  data Query (ShelleyBlock c) :: Type -> Type where

    -- ...

    GetFilteredDelegationsAndRewardAccounts
      :: Set (SL.Credential 'SL.Staking c)
      -> Query (ShelleyBlock c) (Delegations c, SL.RewardAccounts c)

In mkWalletClient, add a local state query protocol which handles the reward account query commands. The block queried is tip of the wallet's chain sync protocol.

Acceptance Criteria

  1. Network layer getAccountBalance method must return the rewards balance of the wallet (if it is synced).

Development

QA

  1. There is an integration test STAKE_POOLS_JOIN_04 - Rewards accumulate and stop to cover:

    • rewards flow once stake is delegated
    • rewards cease after delegation has stopped

    However the test case is pending until we have stake pool nodes working in the integration test cluster.

iohk-bors bot added a commit that referenced this issue Jun 13, 2020
1752: Shelley get reward account balance r=paweljakubas a=rvl

### Issue Number

ADP-302 / #1750 

### Overview

Adds implementation of network layer `getAccountBalance` for shelley.

### Comments

The integration test is not passing because stake pools are not connected with the test cluster network.


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: Pawel Jakubas <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 14, 2020
1757: Shelley network: remove queryRewardQ from wallet client r=rvl a=rvl

### Issue Number

ADP-302 / #1750

### Overview

Review comment:
#1752 (comment)



Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 16, 2020
1755: Bump cardano-node r=Anviking a=Anviking

- Appears to break compatibility with the most recent FF genesis
- Should include what we need to get non myopic member rewards

1765: Add script to show cardano-node and cardano-cli versions r=rvl a=rvl

Run this script if you would like to know which version of `cardano-node` will be in the `nix-shell` (i.e. CI).

This PR IntersectMBO/cardano-node#1283 fixes the CLI version strings.


1767: Better tracing of shelley network local state query r=rvl a=rvl

### Issue Number

ADP-302 / #1750

### Overview

More detail in the logs.


Co-authored-by: Johannes Lund <[email protected]>
Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 16, 2020
1755: Bump cardano-node r=rvl a=Anviking

- Appears to break compatibility with the most recent FF genesis
- Should include what we need to get non myopic member rewards

1765: Add script to show cardano-node and cardano-cli versions r=rvl a=rvl

Run this script if you would like to know which version of `cardano-node` will be in the `nix-shell` (i.e. CI).

This PR IntersectMBO/cardano-node#1283 fixes the CLI version strings.


1767: Better tracing of shelley network local state query r=rvl a=rvl

### Issue Number

ADP-302 / #1750

### Overview

More detail in the logs.


Co-authored-by: Johannes Lund <[email protected]>
Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 16, 2020
1765: Add script to show cardano-node and cardano-cli versions r=rvl a=rvl

Run this script if you would like to know which version of `cardano-node` will be in the `nix-shell` (i.e. CI).

This PR IntersectMBO/cardano-node#1283 fixes the CLI version strings.


1767: Better tracing of shelley network local state query r=rvl a=rvl

### Issue Number

ADP-302 / #1750

### Overview

More detail in the logs.


Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 16, 2020
1767: Better tracing of shelley network local state query r=rvl a=rvl

### Issue Number

ADP-302 / #1750

### Overview

More detail in the logs.


Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 17, 2020
1767: Better tracing of shelley network local state query r=rvl a=rvl

### Issue Number

ADP-302 / #1750

### Overview

More detail in the logs.


Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 22, 2020
1772: More integration test cluster logging improvements r=KtorZ a=rvl

### Issue Number

ADP-302 / #1750

### Overview

- Output Debug-severity log files for each cardano-node process to the temporary directory, while only showing Error-severity logs on stdout.
- Show different hostnames in cardano-node logs so that it's possible to see which node produced the log message.
- Add a new helper function for starting the cardano-node process.
- Use a single temp directory for all nodes in the cluster - makes inspecting configs and logs easier.
- The environment variable `NO_CLEANUP` causes the integration tests to not delete the temp directory after they have finished.
- The environment variable `CARDANO_NODE_TRACING_MIN_SEVERITY` sets the log level the the cluster nodes for stdout.
- The environment variable `CARDANO_WALLET_TRACING_MIN_SEVERITY` sets the log level for the wallet server.
- Also bumps cardano-node and libraries to latest master (to get latest logging features).


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: IOHK <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 23, 2020
1785: integration tests: Shorten cardano-node socket path r=Anviking a=rvl

### Issue Number

ADP-302 / #1750

### Overview

The socket path needs to be short enough to work in the default temp directory on macOS.


Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 25, 2020
1790: Fix logging in shelley integration test cluster r=KtorZ a=rvl

### Issue Number

ADP-302 / #1750

### Overview

1. Block forging and adoption was not being logged by the integration tests cluster. Fixed it. The default minimum severity for stdout remains as Error. The default minimum severity for the log file is Debug.

2. This adds a passive node which the wallet connects to, rather than using the bft node. My hope is that this will cause transactions to be broadcast to _all_ stake pools, meaning that transactions won't be lost with rollbacks. But in any case, this updated topology makes for a more "realistic" integration test.


Co-authored-by: Rodney Lorrimar <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 27, 2020
1768: Store delegation reward account balances in the database r=KtorZ a=rvl

### Issue Number

ADP-302 / #1750 

### Overview

Turns out querying reward account balances can be slow.
This is not good if it's done when listing/getting wallets.
Better to do these queries in a separate thread and cache the results in the database.

- [x] Add new database table for the latest known wallet reward account balance.
- [x] Use the database when getting the reward account balance.
- [x] Add a network layer method to watch the node tip.
- [x] Update the account balance in each wallet when the node tip changes (asynchronously).
- [x] Store reward account balance in db as it arrives.
- [x] Adapt Jörmungandr network layer

### Comments

- [ ] STAKE_POOLS_JOIN_04 test passes


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 27, 2020
1768: Store delegation reward account balances in the database r=KtorZ a=rvl

### Issue Number

ADP-302 / #1750 

### Overview

Turns out querying reward account balances can be slow.
This is not good if it's done when listing/getting wallets.
Better to do these queries in a separate thread and cache the results in the database.

- [x] Add new database table for the latest known wallet reward account balance.
- [x] Use the database when getting the reward account balance.
- [x] Add a network layer method to watch the node tip.
- [x] Update the account balance in each wallet when the node tip changes (asynchronously).
- [x] Store reward account balance in db as it arrives.
- [x] Adapt Jörmungandr network layer

### Comments

- [ ] STAKE_POOLS_JOIN_04 test passes


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 27, 2020
1768: Store delegation reward account balances in the database r=KtorZ a=rvl

### Issue Number

ADP-302 / #1750 

### Overview

Turns out querying reward account balances can be slow.
This is not good if it's done when listing/getting wallets.
Better to do these queries in a separate thread and cache the results in the database.

- [x] Add new database table for the latest known wallet reward account balance.
- [x] Use the database when getting the reward account balance.
- [x] Add a network layer method to watch the node tip.
- [x] Update the account balance in each wallet when the node tip changes (asynchronously).
- [x] Store reward account balance in db as it arrives.
- [x] Adapt Jörmungandr network layer

### Comments

- [ ] STAKE_POOLS_JOIN_04 test passes


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: IOHK <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 27, 2020
1768: Store delegation reward account balances in the database r=KtorZ a=rvl

### Issue Number

ADP-302 / #1750 

### Overview

Turns out querying reward account balances can be slow.
This is not good if it's done when listing/getting wallets.
Better to do these queries in a separate thread and cache the results in the database.

- [x] Add new database table for the latest known wallet reward account balance.
- [x] Use the database when getting the reward account balance.
- [x] Add a network layer method to watch the node tip.
- [x] Update the account balance in each wallet when the node tip changes (asynchronously).
- [x] Store reward account balance in db as it arrives.
- [x] Adapt Jörmungandr network layer

### Comments

- [ ] STAKE_POOLS_JOIN_04 test passes


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: IOHK <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 29, 2020
1768: Store delegation reward account balances in the database r=rvl a=rvl

### Issue Number

ADP-302 / #1750 / #1759

### Overview

Turns out querying reward account balances can be slow.
This is not good if it's done when listing/getting wallets.
Better to do these queries in a separate thread and cache the results in the database.

- [x] Add new database table for the latest known wallet reward account balance.
- [x] Use the database when getting the reward account balance.
- [x] Add a network layer method to watch the node tip.
- [x] Update the account balance in each wallet when the node tip changes (asynchronously).
- [x] Store reward account balance in db as it arrives.
- [x] Adapt Jörmungandr network layer


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 29, 2020
1768: Store delegation reward account balances in the database r=KtorZ a=rvl

### Issue Number

ADP-302 / #1750 / #1759

### Overview

Turns out querying reward account balances can be slow.
This is not good if it's done when listing/getting wallets.
Better to do these queries in a separate thread and cache the results in the database.

- [x] Add new database table for the latest known wallet reward account balance.
- [x] Use the database when getting the reward account balance.
- [x] Add a network layer method to watch the node tip.
- [x] Update the account balance in each wallet when the node tip changes (asynchronously).
- [x] Store reward account balance in db as it arrives.
- [x] Adapt Jörmungandr network layer


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 29, 2020
1768: Store delegation reward account balances in the database r=KtorZ a=rvl

### Issue Number

ADP-302 / #1750 / #1759

### Overview

Turns out querying reward account balances can be slow.
This is not good if it's done when listing/getting wallets.
Better to do these queries in a separate thread and cache the results in the database.

- [x] Add new database table for the latest known wallet reward account balance.
- [x] Use the database when getting the reward account balance.
- [x] Add a network layer method to watch the node tip.
- [x] Update the account balance in each wallet when the node tip changes (asynchronously).
- [x] Store reward account balance in db as it arrives.
- [x] Adapt Jörmungandr network layer


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 29, 2020
1768: Store delegation reward account balances in the database r=KtorZ a=rvl

### Issue Number

ADP-302 / #1750 / #1759

### Overview

Turns out querying reward account balances can be slow.
This is not good if it's done when listing/getting wallets.
Better to do these queries in a separate thread and cache the results in the database.

- [x] Add new database table for the latest known wallet reward account balance.
- [x] Use the database when getting the reward account balance.
- [x] Add a network layer method to watch the node tip.
- [x] Update the account balance in each wallet when the node tip changes (asynchronously).
- [x] Store reward account balance in db as it arrives.
- [x] Adapt Jörmungandr network layer


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
iohk-bors bot added a commit that referenced this issue Jun 30, 2020
1768: Store delegation reward account balances in the database r=rvl a=rvl

### Issue Number

ADP-302 / #1750 / #1759

### Overview

Turns out querying reward account balances can be slow.
This is not good if it's done when listing/getting wallets.
Better to do these queries in a separate thread and cache the results in the database.

- [x] Add new database table for the latest known wallet reward account balance.
- [x] Use the database when getting the reward account balance.
- [x] Add a network layer method to watch the node tip.
- [x] Update the account balance in each wallet when the node tip changes (asynchronously).
- [x] Store reward account balance in db as it arrives.
- [x] Adapt Jörmungandr network layer


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
@piotr-iohk
Copy link
Contributor

lgtm. However cannot really see if rewards stop due to "Can't quit pools when reward account is non-empty #1824". Also for that matter I suppose the part of the test STAKE_POOLS_JOIN_04 - Rewards accumulate and stop is commented out.( https://github.com/input-output-hk/cardano-wallet/blob/master/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/StakePools.hs#L304)

@rvl
Copy link
Contributor Author

rvl commented Jul 3, 2020

@piotr-iohk Thanks, yes the STAKE_POOLS_JOIN_04 scenario is testing multiple things. The "rewards accumulate" part applies to this user story ADP-302. The "rewards stop" part is blocked by #1824 - I added a note there.

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

No branches or pull requests

3 participants