Skip to content

Commit ef61aea

Browse files
committed
Hint to MASP client block range to fetch
1 parent 7e71508 commit ef61aea

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

crates/sdk/src/masp/utilities.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ impl<M: Clone> Clone for LinearBackoffSleepMaspClient<M> {
6969
impl<M: MaspClient> MaspClient for LinearBackoffSleepMaspClient<M> {
7070
type Error = <M as MaspClient>::Error;
7171

72+
#[inline]
73+
fn hint(&mut self, from: BlockHeight, to: BlockHeight) {
74+
self.middleware_client.hint(from, to);
75+
}
76+
7277
async fn last_block_height(
7378
&self,
7479
) -> Result<Option<BlockHeight>, Self::Error> {
@@ -181,6 +186,8 @@ impl<C> LedgerMaspClient<C> {
181186
impl<C: Client + Send + Sync> MaspClient for LedgerMaspClient<C> {
182187
type Error = Error;
183188

189+
fn hint(&mut self, _from: BlockHeight, _to: BlockHeight) {}
190+
184191
async fn last_block_height(&self) -> Result<Option<BlockHeight>, Error> {
185192
let maybe_block = crate::rpc::query_block(&self.inner.client).await?;
186193
Ok(maybe_block.map(|b| b.height))
@@ -426,6 +433,12 @@ impl IndexerMaspClient {
426433
impl MaspClient for IndexerMaspClient {
427434
type Error = Error;
428435

436+
fn hint(&mut self, from: BlockHeight, to: BlockHeight) {
437+
if to.0 - from.0 + 1 > self.shared.max_concurrent_fetches as _ {
438+
_ = self.shared.block_index.set(None);
439+
}
440+
}
441+
429442
async fn last_block_height(&self) -> Result<Option<BlockHeight>, Error> {
430443
use serde::Deserialize;
431444

crates/shielded_token/src/masp/shielded_sync/dispatcher.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,9 @@ where
546546

547547
self.force_redraw_progress_bars();
548548

549+
self.client
550+
.hint(initial_state.start_height, initial_state.last_query_height);
551+
549552
Ok(initial_state)
550553
}
551554

crates/shielded_token/src/masp/shielded_sync/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ pub trait MaspClient: Clone {
385385
/// Error type returned by the methods of this trait
386386
type Error: std::error::Error + Send + Sync + 'static;
387387

388+
/// Hint to this [`MaspClient`] implementation the block range
389+
/// that will be fetched.
390+
fn hint(&mut self, from: BlockHeight, to: BlockHeight);
391+
388392
/// Return the last block height we can retrieve data from.
389393
#[allow(async_fn_in_trait)]
390394
async fn last_block_height(

crates/shielded_token/src/masp/test_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ pub enum TestError {
386386
impl MaspClient for TestingMaspClient {
387387
type Error = TestError;
388388

389+
fn hint(&mut self, _from: BlockHeight, _to: BlockHeight) {}
390+
389391
async fn last_block_height(
390392
&self,
391393
) -> Result<Option<BlockHeight>, Self::Error> {

0 commit comments

Comments
 (0)