Skip to content

Commit b8cf6d7

Browse files
authored
Merge of #4776
2 parents 77bd1e3 + 882fbbd commit b8cf6d7

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- Querying the conversion state becomes more difficult as nodes progress
2+
to higher and higher epochs. For instance, on a mainnet clone running on
3+
accelerated epochs, client queries for conversions always timeout (even after
4+
modifying timeout_broadcast_tx_commit) when the node goes beyond a certain
5+
MASP epoch. This happens because the conversion state grows linearly with
6+
the MASP epoch counter. This PR attempts to address this problem by making
7+
the conversions RPC endpoint require that clients specify the MASP epoch
8+
they want conversions from. This implies two things: first the size of the
9+
response from the conversions RPC endpoint should now be constant (equal to
10+
the number of tokens in the shielded rewards program), and second a client
11+
requiring all conversions now has to do a separate query for each MASP epoch.
12+
([\#4776](https://github.com/namada-net/namada/pull/4776))

crates/apps_lib/src/client/masp.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,37 @@ pub async fn syncing<
117117

118118
#[cfg(feature = "testing")]
119119
{
120+
use std::collections::BTreeMap;
121+
122+
use futures::StreamExt;
123+
use namada_core::masp::MaspEpoch;
124+
120125
// Load the confirmed context (if present) and update the conversions
121126
// for the shielded history. This is needed for integration
122127
// tests only as the cli wallet is not supposed to compile the
123128
// history of shielded transactions
124129
shielded.load_confirmed().await;
125-
for (asset_type, (token, denom, position, epoch, _conv)) in
126-
namada_sdk::rpc::query_conversions(&client).await?
130+
let current_masp_epoch =
131+
namada_sdk::rpc::query_masp_epoch(&client).await?;
132+
let epochs: Vec<_> = MaspEpoch::iter_bounds_inclusive(
133+
MaspEpoch::zero(),
134+
current_masp_epoch,
135+
)
136+
.collect();
137+
let conversion_tasks = epochs
138+
.iter()
139+
.map(|epoch| namada_sdk::rpc::query_conversions(&client, epoch));
140+
let conversions = futures::stream::iter(conversion_tasks)
141+
.buffer_unordered(100)
142+
.fold(BTreeMap::default(), async |mut acc, conversion| {
143+
acc.append(
144+
&mut conversion.expect("Conversion should be defined"),
145+
);
146+
acc
147+
})
148+
.await;
149+
150+
for (asset_type, (token, denom, position, epoch, _conv)) in conversions
127151
{
128152
let pre_asset_type = AssetData {
129153
token,

crates/apps_lib/src/client/rpc.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io;
66
use color_eyre::owo_colors::OwoColorize;
77
use data_encoding::HEXLOWER;
88
use either::Either;
9+
use futures::StreamExt;
910
use masp_primitives::asset_type::AssetType;
1011
use masp_primitives::merkle_tree::MerklePath;
1112
use masp_primitives::sapling::Node;
@@ -2143,16 +2144,31 @@ pub async fn query_conversions(
21432144
.wallet()
21442145
.await
21452146
.get_addresses_with_vp_type(AddressVpType::Token);
2146-
let conversions = rpc::query_conversions(context.client())
2147+
2148+
// Download conversions from all epochs to facilitate decoding asset types
2149+
let from = MaspEpoch::zero();
2150+
let to = rpc::query_masp_epoch(context.client())
21472151
.await
2148-
.expect("Conversions should be defined");
2152+
.expect("Unable to query current MASP epoch");
2153+
let epochs: Vec<_> = MaspEpoch::iter_bounds_inclusive(from, to).collect();
2154+
let conversion_tasks = epochs
2155+
.iter()
2156+
.map(|epoch| rpc::query_conversions(context.client(), epoch));
2157+
let conversions = futures::stream::iter(conversion_tasks)
2158+
.buffer_unordered(100)
2159+
.fold(BTreeMap::default(), async |mut acc, conversion| {
2160+
acc.append(&mut conversion.expect("Conversion should be defined"));
2161+
acc
2162+
})
2163+
.await;
21492164

21502165
if args.dump_tree {
21512166
display_line!(context.io(), "Conversions: {conversions:?}");
21522167
}
21532168

21542169
// Track whether any non-sentinel conversions are found
21552170
let mut conversions_found = false;
2171+
21562172
for (addr, _denom, digit, epoch, amt) in conversions.values() {
21572173
// If the user has specified any targets, then meet them
21582174
// If we have a sentinel conversion, then skip printing

crates/sdk/src/queries/shell.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ router! {SHELL,
9898
( "conv" / [asset_type: AssetType] ) -> Option<Conversion> = read_conversion,
9999

100100
// Conversion state access - read conversion
101-
( "conversions" ) -> BTreeMap<AssetType, ConversionWithoutPath> = read_conversions,
101+
( "conversions" / [masp_epoch: MaspEpoch] ) -> BTreeMap<AssetType, ConversionWithoutPath> = read_conversions,
102102

103103
// Conversion state access - read conversion
104104
( "masp_reward_tokens" ) -> Vec<MaspTokenRewardData> = masp_reward_tokens,
@@ -211,6 +211,7 @@ where
211211
/// Query to read the conversion state
212212
fn read_conversions<D, H, V, T>(
213213
ctx: RequestCtx<'_, D, H, V, T>,
214+
masp_epoch: MaspEpoch,
214215
) -> namada_storage::Result<BTreeMap<AssetType, ConversionWithoutPath>>
215216
where
216217
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
@@ -222,6 +223,7 @@ where
222223
.conversion_state
223224
.assets
224225
.iter()
226+
.filter(|&(_, asset)| (asset.epoch == masp_epoch))
225227
.map(|(&asset_type, asset)| {
226228
(
227229
asset_type,

crates/sdk/src/rpc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ pub async fn query_conversion<C: namada_io::Client + Sync>(
390390
/// Query conversions
391391
pub async fn query_conversions<C: namada_io::Client + Sync>(
392392
client: &C,
393+
masp_epoch: &MaspEpoch,
393394
) -> Result<
394395
BTreeMap<
395396
AssetType,
@@ -403,7 +404,9 @@ pub async fn query_conversions<C: namada_io::Client + Sync>(
403404
>,
404405
error::Error,
405406
> {
406-
convert_response::<C, _>(RPC.shell().read_conversions(client).await)
407+
convert_response::<C, _>(
408+
RPC.shell().read_conversions(client, masp_epoch).await,
409+
)
407410
}
408411

409412
/// Query the total rewards minted by MASP

0 commit comments

Comments
 (0)