From 401c619e8c4cb2783e53a1e708b60608609a65f5 Mon Sep 17 00:00:00 2001 From: satan Date: Fri, 15 Mar 2024 07:00:41 -0700 Subject: [PATCH 1/2] [fix]: Added an optional starting block argument for shielded sync --- crates/apps/src/lib/bench_utils.rs | 1 + crates/apps/src/lib/cli.rs | 15 +++++++++++++-- crates/apps/src/lib/cli/client.rs | 1 + crates/apps/src/lib/client/masp.rs | 12 +++++++++++- crates/sdk/src/args.rs | 2 ++ crates/sdk/src/masp.rs | 5 ++++- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/crates/apps/src/lib/bench_utils.rs b/crates/apps/src/lib/bench_utils.rs index 7b886eacdb..766f73e20b 100644 --- a/crates/apps/src/lib/bench_utils.rs +++ b/crates/apps/src/lib/bench_utils.rs @@ -1000,6 +1000,7 @@ impl BenchShieldedCtx { &StdIo, 1, None, + None, &[spending_key.into()], &[], )) diff --git a/crates/apps/src/lib/cli.rs b/crates/apps/src/lib/cli.rs index 109c0d78af..b3b1bc533a 100644 --- a/crates/apps/src/lib/cli.rs +++ b/crates/apps/src/lib/cli.rs @@ -2987,6 +2987,9 @@ pub mod args { arg_default("batch-size", DefaultFn(|| 1)); pub const BLOCK_HEIGHT: Arg = arg("block-height"); pub const BLOCK_HEIGHT_OPT: ArgOpt = arg_opt("height"); + pub const BLOCK_HEIGHT_FROM_OPT: ArgOpt = + arg_opt("from-height"); + pub const BLOCK_HEIGHT_TO_OPT: ArgOpt = arg_opt("to-height"); pub const BRIDGE_POOL_GAS_AMOUNT: ArgDefault = arg_default( "pool-gas-amount", @@ -5722,12 +5725,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); let spending_keys = SPENDING_KEYS.parse(matches); let viewing_keys = VIEWING_KEYS.parse(matches); Self { ledger_address, batch_size, + start_query_height, last_query_height, spending_keys, viewing_keys, @@ -5740,9 +5745,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( "Option block height to sync up to. Default is latest.", )) + .arg( + BLOCK_HEIGHT_FROM_OPT + .def() + .help("Option block height to sync from."), + ) .arg(SPENDING_KEYS.def().help( "List of new spending keys with which to check note \ ownership. These will be added to the shielded context.", @@ -5760,6 +5770,7 @@ pub mod args { ShieldedSync { ledger_address: self.ledger_address, batch_size: self.batch_size, + start_query_height: self.start_query_height, last_query_height: self.last_query_height, spending_keys: self .spending_keys diff --git a/crates/apps/src/lib/cli/client.rs b/crates/apps/src/lib/cli/client.rs index 566cfab888..8fe864203c 100644 --- a/crates/apps/src/lib/cli/client.rs +++ b/crates/apps/src/lib/cli/client.rs @@ -343,6 +343,7 @@ impl CliApi { &client, &io, args.batch_size, + args.start_query_height, args.last_query_height, &sks, &vks, diff --git a/crates/apps/src/lib/client/masp.rs b/crates/apps/src/lib/client/masp.rs index 929f575e6b..983be6d718 100644 --- a/crates/apps/src/lib/client/masp.rs +++ b/crates/apps/src/lib/client/masp.rs @@ -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, @@ -22,6 +23,7 @@ pub async fn syncing< client: &C, io: &IO, batch_size: u64, + start_query_height: Option, last_query_height: Option, sks: &[ExtendedSpendingKey], fvks: &[ViewingKey], @@ -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, + ) .await .map(|_| shielded) }; diff --git a/crates/sdk/src/args.rs b/crates/sdk/src/args.rs index 1b3617be49..b14d0240bf 100644 --- a/crates/sdk/src/args.rs +++ b/crates/sdk/src/args.rs @@ -1818,6 +1818,8 @@ pub struct ShieldedSync { 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, /// Height to sync up to. Defaults to most recent pub last_query_height: Option, /// Spending keys used to determine note ownership diff --git a/crates/sdk/src/masp.rs b/crates/sdk/src/masp.rs index 35315ea39a..ea605533b4 100644 --- a/crates/sdk/src/masp.rs +++ b/crates/sdk/src/masp.rs @@ -697,10 +697,12 @@ impl ShieldedContext { /// Fetch the current state of the multi-asset shielded pool into a /// ShieldedContext + #[allow(clippy::too_many_arguments)] pub async fn fetch( &mut self, client: &C, logger: &impl ProgressLogger, + start_query_height: Option, last_query_height: Option, _batch_size: u64, sks: &[ExtendedSpendingKey], @@ -739,6 +741,7 @@ impl ShieldedContext { // 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); // Load all transactions accepted until this point // N.B. the cache is a hash map self.unscanned.extend( @@ -2396,7 +2399,7 @@ impl ShieldedContext { .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) .await?; // Save the update state so that future fetches can be short-circuited let _ = self.save().await; From 80be8d6195dafcede47ce03d9e4adc44b7dcc439 Mon Sep 17 00:00:00 2001 From: satan Date: Fri, 15 Mar 2024 07:31:33 -0700 Subject: [PATCH 2/2] added changelog --- .../unreleased/improvements/2902-shielded-sync-start-height.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changelog/unreleased/improvements/2902-shielded-sync-start-height.md diff --git a/.changelog/unreleased/improvements/2902-shielded-sync-start-height.md b/.changelog/unreleased/improvements/2902-shielded-sync-start-height.md new file mode 100644 index 0000000000..ad86ba6769 --- /dev/null +++ b/.changelog/unreleased/improvements/2902-shielded-sync-start-height.md @@ -0,0 +1 @@ + - Added an optional starting block argument for shielded sync ([\#2902](https://github.com/anoma/namada/pull/2902)) \ No newline at end of file