From 09a59008b55b2b8b58d915da1e7ee89f8fff6f9a Mon Sep 17 00:00:00 2001 From: Chris Czub Date: Tue, 10 Sep 2024 14:25:36 -0400 Subject: [PATCH] Properly sum Penumbra-minted values returned in total supply API (#4836) ## Describe your changes This fixes an issue in the `TotalSupply` API where tokens minted on Penumbra and received from different counterparties weren't correctly summing together. It should be noted that this API returns two subtly different values depending on the asset: * For a Penumbra-minted token, it's really the "Total Outstanding IBC Supply" API rather than the "Total Supply" API -- it will return the amount of the token that has been sent to and remains on other chains * For an externally-originating token, it indicates the total supply of the token transferred into and remaining on the Penumbra chain ## Checklist before requesting a review - [ ] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: > no consensus changes --- .../shielded-pool/src/component/rpc/bank_query.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/core/component/shielded-pool/src/component/rpc/bank_query.rs b/crates/core/component/shielded-pool/src/component/rpc/bank_query.rs index e774f731ef..2af2edae7c 100644 --- a/crates/core/component/shielded-pool/src/component/rpc/bank_query.rs +++ b/crates/core/component/shielded-pool/src/component/rpc/bank_query.rs @@ -30,7 +30,7 @@ use super::Server; impl BankQuery for Server { /// Returns the total supply for all IBC assets. /// Internally-minted assets (Penumbra tokens, LP tokens, delegation tokens, etc.) - /// are also included but the supplies are hardcoded at 0 for now. + /// are also included but the supplies are will only reflect what has been transferred out. /// /// TODO: Implement a way to fetch the total supply for these assets. /// TODO: implement pagination @@ -107,7 +107,11 @@ impl BankQuery for Server { } let denom_metadata = denom_metadata.expect("should not be an error"); - total_supply.insert(denom_metadata, amount); + // Add to the total supply seen for this denom. + total_supply + .entry(denom_metadata) + .and_modify(|a| *a += amount) + .or_insert(amount); } Ok(tonic::Response::new(QueryTotalSupplyResponse {