taprpc+tapdb: add GenesisInfo to AssetGroupBalance in ListBalances#2130
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the 'ListBalances' RPC functionality by including comprehensive metadata for grouped assets. By adding genesis information and decimal display settings to the 'AssetGroupBalance' response, clients can now display asset details directly without requiring additional API calls. The changes involve updates to the protocol buffers, database query logic, and the RPC server implementation to populate these new fields efficiently. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request enhances the ListBalances RPC by including representative genesis information and decimal display metadata for asset groups. The changes involve updating the database queries to select anchor genesis data, extending the AssetGroupBalance structures in both the database and RPC layers, and populating these new fields in the RPC server. Feedback was provided regarding a potential N+1 query performance issue when fetching decimal displays and a requirement to use structured logging for debug messages as per the repository style guide.
| decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID( | ||
| ctx, balance.ID, | ||
| ) |
There was a problem hiding this comment.
Fetching the decimal display for each asset ID inside the loop results in an N+1 query pattern. If the number of asset groups is large, this will significantly degrade the performance of the ListBalances RPC. Consider batching these lookups by collecting all unique asset IDs first and performing a single query to the AddrBook component.
There was a problem hiding this comment.
The DecDisplayForAssetID method has an internal cache that pre-populates with ALL asset metadata on first call (address/book.go line 482: FetchAllAssetMeta). So the N+1 concern is largely mitigated, after the first lookup, subsequent calls are cache hits.
2cff3d3 to
2b0f3f4
Compare
Added GenesisInfo and DecimalDisplay fields to the AssetGroupBalance message, making the group_by=group_key mode of ListBalances useful for clients that need asset metadata alongside balances. The SQL query was modified to join genesis_info_view and return genesis data for a representative issuance per group (selected via MIN to get the earliest-inserted genesis, which is the anchor for locally-minted assets). Fixes lightninglabs#2066. Signed-off-by: kaldun-tech <tsmereka@protonmail.com>
2b0f3f4 to
48f4267
Compare
|
I believe these CI failures are flakes. @claude please code review and investigate whether the failed CI is due to code changes or flakes |
|
@jtobin @darioAnongba Please re-run the failed CI jobs. My investigation is that the failures were due to flakes but let me know if you want me to look into anything on my end |
Add
GenesisInfoandDecimalDisplayfields toAssetGroupBalancein theListBalancesRPC response when usinggroup_by=group_keymode.Previously,
AssetGroupBalanceonly containedgroup_keyandbalance, making it impossible for clients to display asset metadata (name, type, decimal display) alongside grouped balances without additional RPC calls.Changes
asset_genesis(field 3) anddecimal_display(field 4) toAssetGroupBalancemessageQueryAssetBalancesByGroupto joingenesis_info_viewand return genesis data for a representative issuance per groupAssetGroupBalancestruct with genesis fields and updated query result mappinglistBalancesByGroupKey, includingDecimalDisplaylookup viaDecDisplayForAssetIDDesign Notes
MIN(gen_asset_id), which gives the earliest-inserted genesis. For locally-minted assets, this is the group anchor. For fungible assets, all tranches share the same name/type, so any genesis provides correct metadata.DecimalDisplaylookup failures are logged at debug level and do not fail the request, since decimal display is optional metadata.QueryAssetBalancesByGroupresults (usegroup_by=asset_idmode for those).Test Plan
make unit pkg=tapdb- verify DB layer changesmake unit pkg=rpcserver- verify RPC marshalingmake itest icase=minting_multi_asset_groupstapcli assets balance --by-groupreturns genesis infoFixes issue #2066