Skip to content

Commit

Permalink
Merge branch 'bat+fraccaman/shielded-sync-start-height' (#2902)
Browse files Browse the repository at this point in the history
* bat+fraccaman/shielded-sync-start-height:
  added changelog
  [fix]: Added an optional starting block argument for shielded sync
  • Loading branch information
brentstone committed Mar 15, 2024
2 parents ad10c01 + 80be8d6 commit 81ffc7d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added an optional starting block argument for shielded sync ([\#2902](https://github.com/anoma/namada/pull/2902))
1 change: 1 addition & 0 deletions crates/apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ impl BenchShieldedCtx {
&StdIo,
1,
None,
None,

Check warning on line 1003 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L1003

Added line #L1003 was not covered by tests
&[spending_key.into()],
&[],
))
Expand Down
15 changes: 13 additions & 2 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3065,6 +3065,9 @@ pub mod args {
arg_default("batch-size", DefaultFn(|| 1));
pub const BLOCK_HEIGHT: Arg<BlockHeight> = arg("block-height");
pub const BLOCK_HEIGHT_OPT: ArgOpt<BlockHeight> = arg_opt("height");
pub const BLOCK_HEIGHT_FROM_OPT: ArgOpt<BlockHeight> =
arg_opt("from-height");
pub const BLOCK_HEIGHT_TO_OPT: ArgOpt<BlockHeight> = arg_opt("to-height");
pub const BRIDGE_POOL_GAS_AMOUNT: ArgDefault<token::DenominatedAmount> =
arg_default(
"pool-gas-amount",
Expand Down Expand Up @@ -5863,12 +5866,14 @@ pub mod args {
fn parse(matches: &ArgMatches) -> Self {
let ledger_address = LEDGER_ADDRESS.parse(matches);
let batch_size = BATCH_SIZE_OPT.parse(matches);
let last_query_height = BLOCK_HEIGHT_OPT.parse(matches);
let start_query_height = BLOCK_HEIGHT_FROM_OPT.parse(matches);
let last_query_height = BLOCK_HEIGHT_TO_OPT.parse(matches);

Check warning on line 5870 in crates/apps/src/lib/cli.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/cli.rs#L5869-L5870

Added lines #L5869 - L5870 were not covered by tests
let spending_keys = SPENDING_KEYS.parse(matches);
let viewing_keys = VIEWING_KEYS.parse(matches);
Self {
ledger_address,
batch_size,
start_query_height,

Check warning on line 5876 in crates/apps/src/lib/cli.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/cli.rs#L5876

Added line #L5876 was not covered by tests
last_query_height,
spending_keys,
viewing_keys,
Expand All @@ -5881,9 +5886,14 @@ pub mod args {
"Optional batch size which determines how many txs to \
fetch before caching locally. Default is 1.",
))
.arg(BLOCK_HEIGHT_OPT.def().help(
.arg(BLOCK_HEIGHT_TO_OPT.def().help(

Check warning on line 5889 in crates/apps/src/lib/cli.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/cli.rs#L5889

Added line #L5889 was not covered by tests
"Option block height to sync up to. Default is latest.",
))
.arg(
BLOCK_HEIGHT_FROM_OPT
.def()
.help("Option block height to sync from."),
)

Check warning on line 5896 in crates/apps/src/lib/cli.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/cli.rs#L5892-L5896

Added lines #L5892 - L5896 were not covered by tests
.arg(SPENDING_KEYS.def().help(
"List of new spending keys with which to check note \
ownership. These will be added to the shielded context.",
Expand All @@ -5901,6 +5911,7 @@ pub mod args {
ShieldedSync {
ledger_address: self.ledger_address,
batch_size: self.batch_size,
start_query_height: self.start_query_height,

Check warning on line 5914 in crates/apps/src/lib/cli.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/cli.rs#L5914

Added line #L5914 was not covered by tests
last_query_height: self.last_query_height,
spending_keys: self
.spending_keys
Expand Down
1 change: 1 addition & 0 deletions crates/apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ impl CliApi {
&client,
&io,
args.batch_size,
args.start_query_height,

Check warning on line 348 in crates/apps/src/lib/cli/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/cli/client.rs#L348

Added line #L348 was not covered by tests
args.last_query_height,
&sks,
&vks,
Expand Down
12 changes: 11 additions & 1 deletion crates/apps/src/lib/client/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use namada_sdk::queries::Client;
use namada_sdk::storage::BlockHeight;
use namada_sdk::{display, display_line, MaybeSend, MaybeSync};

#[allow(clippy::too_many_arguments)]
pub async fn syncing<
U: ShieldedUtils + MaybeSend + MaybeSync,
C: Client + Sync,
Expand All @@ -22,6 +23,7 @@ pub async fn syncing<
client: &C,
io: &IO,
batch_size: u64,
start_query_height: Option<BlockHeight>,

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L26 was not covered by tests
last_query_height: Option<BlockHeight>,
sks: &[ExtendedSpendingKey],
fvks: &[ViewingKey],
Expand All @@ -37,7 +39,15 @@ pub async fn syncing<
let logger = CliLogger::new(io);
let sync = async move {
shielded
.fetch(client, &logger, last_query_height, batch_size, sks, fvks)
.fetch(
client,
&logger,
start_query_height,
last_query_height,
batch_size,
sks,
fvks,
)

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

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/masp.rs#L42-L50

Added lines #L42 - L50 were not covered by tests
.await
.map(|_| shielded)
};
Expand Down
2 changes: 2 additions & 0 deletions crates/sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,8 @@ pub struct ShieldedSync<C: NamadaTypes = SdkTypes> {
pub ledger_address: C::TendermintAddress,
/// The number of txs to fetch before caching
pub batch_size: u64,
/// Height to start syncing from. Defaults to the correct one.
pub start_query_height: Option<BlockHeight>,
/// Height to sync up to. Defaults to most recent
pub last_query_height: Option<BlockHeight>,
/// Spending keys used to determine note ownership
Expand Down
5 changes: 4 additions & 1 deletion crates/sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,12 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {

/// Fetch the current state of the multi-asset shielded pool into a
/// ShieldedContext
#[allow(clippy::too_many_arguments)]
pub async fn fetch<C: Client + Sync, IO: Io>(
&mut self,
client: &C,
logger: &impl ProgressLogger<IO>,
start_query_height: Option<BlockHeight>,

Check warning on line 710 in crates/sdk/src/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/masp.rs#L710

Added line #L710 was not covered by tests
last_query_height: Option<BlockHeight>,
_batch_size: u64,
sks: &[ExtendedSpendingKey],
Expand Down Expand Up @@ -744,6 +746,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
// get the bounds on the block heights to fetch
let start_idx =
std::cmp::min(last_witnessed_tx, least_idx).map(|ix| ix.height);
let start_idx = start_query_height.or(start_idx);

Check warning on line 749 in crates/sdk/src/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/masp.rs#L749

Added line #L749 was not covered by tests
// Load all transactions accepted until this point
// N.B. the cache is a hash map
self.unscanned.extend(
Expand Down Expand Up @@ -2401,7 +2404,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
.values()
.map(|fvk| ExtendedFullViewingKey::from(*fvk).fvk.vk)
.collect();
self.fetch(client, &DefaultLogger::new(io), None, 1, &[], &fvks)
self.fetch(client, &DefaultLogger::new(io), None, None, 1, &[], &fvks)

Check warning on line 2407 in crates/sdk/src/masp.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/masp.rs#L2407

Added line #L2407 was not covered by tests
.await?;
// Save the update state so that future fetches can be short-circuited
let _ = self.save().await;
Expand Down

0 comments on commit 81ffc7d

Please sign in to comment.