Skip to content

Commit 70bc3df

Browse files
committed
Parallel epoch queries
1 parent dca71ec commit 70bc3df

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

crates/apps_lib/src/client/masp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ pub async fn syncing<
122122
// tests only as the cli wallet is not supposed to compile the
123123
// history of shielded transactions
124124
shielded.load_confirmed().await;
125+
let masp_epoch = namada_sdk::rpc::query_masp_epoch(&client).await?;
125126
for (asset_type, (token, denom, position, epoch, _conv)) in
126-
namada_sdk::rpc::query_conversions(&client).await?
127+
namada_sdk::rpc::query_conversions(&client, &masp_epoch).await?
127128
{
128129
let pre_asset_type = AssetData {
129130
token,

crates/apps_lib/src/client/rpc.rs

Lines changed: 13 additions & 8 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;
@@ -2145,18 +2146,22 @@ pub async fn query_conversions(
21452146
.get_addresses_with_vp_type(AddressVpType::Token);
21462147

21472148
// Download conversions from all epochs to facilitate decoding asset types
2148-
let mut conversions = BTreeMap::new();
21492149
let from = MaspEpoch::zero();
21502150
let to = rpc::query_masp_epoch(context.client())
21512151
.await
21522152
.expect("Unable to query current MASP epoch");
2153-
for epoch in MaspEpoch::iter_bounds_inclusive(from, to) {
2154-
conversions.append(
2155-
&mut rpc::query_conversions(context.client(), &epoch)
2156-
.await
2157-
.expect("Conversions should be defined"),
2158-
);
2159-
}
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 task_stream = futures::stream::iter(conversion_tasks);
2158+
let conversions = task_stream
2159+
.buffer_unordered(100)
2160+
.fold(BTreeMap::default(), async |mut acc, conversion| {
2161+
acc.append(&mut conversion.expect("Conversion should be defined"));
2162+
acc
2163+
})
2164+
.await;
21602165

21612166
if args.dump_tree {
21622167
display_line!(context.io(), "Conversions: {conversions:?}");

0 commit comments

Comments
 (0)