Skip to content

Commit

Permalink
Update masp.rs
Browse files Browse the repository at this point in the history
Fetch block & sync faster upon new spending key
  • Loading branch information
chimmykk authored Mar 17, 2024
1 parent cc3edde commit 871ab4b
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions crates/apps/src/lib/client/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,66 @@ use namada_sdk::queries::Client;
use namada_sdk::storage::BlockHeight;
use namada_sdk::{display, display_line, MaybeSend, MaybeSync};

pub async fn syncing_with_height_increment<
U: ShieldedUtils + MaybeSend + MaybeSync,
C: Client + Sync,
IO: Io,
>(
mut shielded: ShieldedContext<U>,
client: &C,
io: &IO,
batch_size: u64,
mut last_query_height: Option<BlockHeight>,
sks: &[ExtendedSpendingKey],
fvks: &[ViewingKey],
) -> Result<ShieldedContext<U>, Error> {
let shutdown_signal = async {
let (tx, rx) = tokio::sync::oneshot::channel();
namada_sdk::control_flow::shutdown_send(tx).await;
rx.await
};

Check warning on line 33 in crates/apps/src/lib/client/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/masp.rs#L16-L33

Added lines #L16 - L33 were not covered by tests

// add function to check if new spending key populates on
// wallet list

display_line!(io, "{}", "==== Shielded sync started first step ====".on_white());
display_line!(io, "\n\n");

let logger = CliLogger::new(io);

Check warning on line 41 in crates/apps/src/lib/client/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/masp.rs#L38-L41

Added lines #L38 - L41 were not covered by tests

// Increment the height based on the current value
if let Some(mut height) = last_query_height {
if height < BlockHeight(1000) {
height += BlockHeight(1000);
} else if height < BlockHeight(10000) {
height += BlockHeight(10000);
} else {
height += BlockHeight(100000);
}
last_query_height = Some(height);
}

Check warning on line 53 in crates/apps/src/lib/client/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/masp.rs#L44-L53

Added lines #L44 - L53 were not covered by tests

let sync = async move {
shielded
.fetch(client, &logger, last_query_height, batch_size, sks, fvks)
.await
.map(|_| shielded)
};

Check warning on line 60 in crates/apps/src/lib/client/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/masp.rs#L55-L60

Added lines #L55 - L60 were not covered by tests

tokio::select! {
sync = sync => {
let shielded = sync?;
display!(io, "Syncing finished\n");
Ok(shielded)
},
sig = shutdown_signal => {
sig.map_err(|e| Error::Other(e.to_string()))?;

Check warning on line 69 in crates/apps/src/lib/client/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/masp.rs#L69

Added line #L69 was not covered by tests
display!(io, "\n");
Ok(ShieldedContext::default())
},
}
}

Check warning on line 74 in crates/apps/src/lib/client/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/masp.rs#L74

Added line #L74 was not covered by tests

pub async fn syncing<
U: ShieldedUtils + MaybeSend + MaybeSync,
C: Client + Sync,
Expand All @@ -34,13 +94,16 @@ pub async fn syncing<

display_line!(io, "{}", "==== Shielded sync started ====".on_white());
display_line!(io, "\n\n");

Check warning on line 97 in crates/apps/src/lib/client/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/masp.rs#L97

Added line #L97 was not covered by tests
let logger = CliLogger::new(io);

Check warning on line 99 in crates/apps/src/lib/client/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/masp.rs#L99

Added line #L99 was not covered by tests
let sync = async move {
shielded
.fetch(client, &logger, last_query_height, batch_size, sks, fvks)
.await
.map(|_| shielded)
};

tokio::select! {
sync = sync => {
let shielded = sync?;
Expand Down

0 comments on commit 871ab4b

Please sign in to comment.