Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2111: Faster listing of stake pools. r=jonathanknowles a=jonathanknowles ## Issue Number #2082 (_Listing stake pools time grows when there are wallets syncing in background_.) ## Overview This PR: * changes the implementation of `ListStakePools` to execute a small number of handwritten SQL queries with native joins, rather than issuing multiple queries and joining together the results in memory. * adds a new operation [`listPoolLifeCycleData`](https://github.com/input-output-hk/cardano-wallet/blob/d00c608e47d2d189a282a02946cc8e46b843375b/lib/core/src/Cardano/Pool/DB.hs#L180). The [SQLite implementation](https://github.com/input-output-hk/cardano-wallet/blob/d00c608e47d2d189a282a02946cc8e46b843375b/lib/core/src/Cardano/Pool/DB/Sqlite.hs#L384) of this operation uses a [single hand-optimized query](https://github.com/input-output-hk/cardano-wallet/blob/d00c608e47d2d189a282a02946cc8e46b843375b/lib/core/src/Cardano/Pool/DB/Sqlite.hs#L595) to return lifecycle data for all pools. ## Benefits ### ⭐ **Faster execution time** The time taken to execute `ListStakePools` is greatly reduced, even when there are multiple wallets syncing in the background. <details><summary>Click to view data</summary><br> | No. of <br>Wallets<br>Syncing | Time Required<br>(seconds)<br>`master` | Time Required<br>(seconds)<br>`more-efficient-list-pools` | | ---: | ---: | ---: | | 0 | 8 | 3 | | 5 | 30 | 7 | | 10 | 60 | 8 | | 15 | 72 | 9 | | 20 | 95 | 10 | </details> ### ⭐ **Fewer database queries** The number of `select` queries required for a single call to `ListStakePools` is greatly reduced. <details><summary>Click to view data</summary><br> | Branch | Network | No. of Pools | No. of Queries | | :--- | :--- | ---: | ---: | | `master` | `mainnet` | 1,124 | 12,365 | | `more-efficient-list-pools`| `mainnet` | 1,124 | 4 | </details> ## Testing ### ✔️ Properties This PR adds a [property test](https://github.com/input-output-hk/cardano-wallet/blob/d00c608e47d2d189a282a02946cc8e46b843375b/lib/core/test/unit/Cardano/Pool/DB/Properties.hs#L987) for `listPoolLifeCycleData`, consisting of the following steps: 1. Add an arbitrary sequence of pool registration and retirement certificates to the database, for multiple pools. 2. Call `listPoolLifeCycleData` once to fetch lifecycle data for all active pools. 3. Call `readPoolLifeCycleStatus` multiple times, once for each known pool, and coalesce the results. 4. Test that the results returned in steps 2 and 3 are identical. ### ✔️ Live Data Run the following command to get a list of all stake pools sorted by ID: ```sh cardano-wallet stake-pool list --stake 1000 | jq 'sort_by(.id)' > stake-pool-list ``` The results should be identical for both `master` and this branch. ## Notes ### System used for Benchmarking The system used for benchmarking (4 cores): ``` vendor_id : GenuineIntel cpu family : 6 model : 85 model name : Intel(R) Xeon(R) CPU stepping : 7 microcode : 0x1 cpu MHz : 2800.176 cache size : 33792 KB ``` Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
- Loading branch information