Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve grpc get_balance response (#6755)
Description --- - Improved the wallet grpc method `get_balance` response by implementing an event-driven balance cache update. All events that could change the balance are monitored and consecutive calls to the wallet backend are only made when the balance changed. - Cleaned up unused events (events that were monitored somewhere but never set) in `pub enum TransactionEvent`. - Added a missing shutdown signal to grpc method `async fn stream_transaction_events` in the wallet grpc server. Closes #6754 Motivation and Context --- When calling the wallet grpc method `get_balance` repeatedly and quickly in succession on wallets with many outputs, resources are wasted in the wallet when nothing changes, and the client experiences unnecessary long response times. How Has This Been Tested? --- System-level testing on a large wallet with an external grpc client. See logs with response times below. ``` [wallet::ui::grpc::get_balance_debounced] TRACE start_event_monitor [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'true' [wallet::ui::grpc::get_balance_debounced] TRACE set_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 172.28ms [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 29.40µs [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 36.00µs [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 26.40µs [wallet::ui::grpc::get_balance_debounced] TRACE set_refresh_needed 'true' [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'true' [wallet::ui::grpc::get_balance_debounced] TRACE set_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 145.39ms [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 22.00µs [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 33.70µs [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 25.40µs [wallet::ui::grpc::get_balance_debounced] TRACE set_refresh_needed 'true' [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'true' [wallet::ui::grpc::get_balance_debounced] TRACE set_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 156.75ms [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 35.70µs [wallet::ui::grpc::get_balance_debounced] TRACE is_refresh_needed 'false' [wallet::ui::grpc] TRACE 'get_balance' completed in 23.40µs ``` What process can a PR reviewer use to test or verify this change? --- System-level testing with an external grpc client. <!-- Checklist --> <!-- 1. Is the title of your PR in the form that would make nice release notes? The title, excluding the conventional commit tag, will be included exactly as is in the CHANGELOG, so please think about it carefully. --> Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify <!-- Does this include a breaking change? If so, include this line as a footer --> <!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain -->
- Loading branch information