Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit f911070

Browse files
committed
Cleanup URI usage
1 parent 570c572 commit f911070

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

lib/src/blaze/block_witness_data.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -440,22 +440,13 @@ impl BlockAndWitnessData {
440440
let prev_height = { u64::from(height) - 1 };
441441

442442
let (cb, mut tree) = {
443-
let tree = {
444-
let maybe_tree = if prev_height < self.sapling_activation_height {
445-
Some(CommitmentTree::empty())
446-
} else {
447-
None
448-
};
449-
450-
match maybe_tree {
451-
Some(t) => t,
452-
None => {
453-
let tree_state = GrpcConnector::get_sapling_tree(uri, prev_height).await?;
454-
let sapling_tree = hex::decode(&tree_state.tree).unwrap();
455-
self.verification_list.write().await.push(tree_state);
456-
CommitmentTree::read(&sapling_tree[..]).map_err(|e| format!("{}", e))?
457-
}
458-
}
443+
let tree = if prev_height < self.sapling_activation_height {
444+
CommitmentTree::empty()
445+
} else {
446+
let tree_state = GrpcConnector::get_sapling_tree(uri, prev_height).await?;
447+
let sapling_tree = hex::decode(&tree_state.tree).unwrap();
448+
self.verification_list.write().await.push(tree_state);
449+
CommitmentTree::read(&sapling_tree[..]).map_err(|e| format!("{}", e))?
459450
};
460451

461452
// Get the current compact block

lib/src/blaze/syncdata.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::sync::Arc;
22

3+
use http::Uri;
34
use tokio::sync::RwLock;
45

56
use super::{block_witness_data::BlockAndWitnessData, sync_status::SyncStatus};
@@ -8,8 +9,8 @@ use crate::{lightclient::lightclient_config::LightClientConfig, lightwallet::dat
89

910
pub struct BlazeSyncData {
1011
pub(crate) sync_status: Arc<RwLock<SyncStatus>>,
11-
1212
pub(crate) block_data: BlockAndWitnessData,
13+
uri: Uri,
1314
}
1415

1516
impl BlazeSyncData {
@@ -18,10 +19,15 @@ impl BlazeSyncData {
1819

1920
Self {
2021
sync_status: sync_status.clone(),
22+
uri: config.server.clone(),
2123
block_data: BlockAndWitnessData::new(config, sync_status),
2224
}
2325
}
2426

27+
pub fn uri(&self) -> &'_ Uri {
28+
&self.uri
29+
}
30+
2531
pub async fn setup_for_sync(
2632
&mut self,
2733
start_block: u64,

lib/src/blaze/trial_decryptions.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
lightwallet::{data::WalletTx, keys::Keys, wallet_txns::WalletTxns},
44
};
55
use futures::future;
6-
use http::Uri;
76
use log::info;
87
use std::sync::Arc;
98
use tokio::{
@@ -35,7 +34,6 @@ impl TrialDecryptions {
3534

3635
pub async fn start(
3736
&self,
38-
uri: Uri,
3937
bsync_data: Arc<RwLock<BlazeSyncData>>,
4038
detected_txid_sender: UnboundedSender<(TxId, Nullifier, BlockHeight, Option<u32>)>,
4139
) -> (JoinHandle<()>, UnboundedSender<CompactBlock>) {
@@ -67,12 +65,10 @@ impl TrialDecryptions {
6765
let ivks = ivks.clone();
6866
let wallet_txns = wallet_txns.clone();
6967
let bsync_data = bsync_data.clone();
70-
let uri = uri.clone();
7168

7269
let detected_txid_sender = detected_txid_sender.clone();
7370

7471
tasks.push(tokio::spawn(async move {
75-
let keys = keys.read().await;
7672
let height = BlockHeight::from_u32(cb.height as u32);
7773

7874
for (tx_num, ctx) in cb.vtx.iter().enumerate() {
@@ -84,20 +80,22 @@ impl TrialDecryptions {
8480
if let Some((note, to)) = try_sapling_compact_note_decryption(
8581
&MAIN_NETWORK,
8682
height,
87-
ivk,
83+
&ivk,
8884
&epk,
8985
&cmu,
9086
&co.ciphertext,
9187
) {
88+
let keys = keys.read().await;
9289
let extfvk = keys.zkeys[i].extfvk();
9390
let have_spending_key = keys.have_spending_key(extfvk);
91+
let uri = bsync_data.read().await.uri().clone();
9492

9593
// Get the witness for the note
9694
let witness = bsync_data
9795
.read()
9896
.await
9997
.block_data
100-
.get_note_witness(uri.clone(), height, tx_num, output_num)
98+
.get_note_witness(uri, height, tx_num, output_num)
10199
.await?;
102100

103101
let txid = WalletTx::new_txid(&ctx.hash);

lib/src/lightclient.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ impl LightClient {
13611361
// Do Trial decryptions of all the sapling outputs, and pass on the successful ones to the update_notes processor
13621362
let trial_decryptions_processor = TrialDecryptions::new(self.wallet.keys(), self.wallet.txns());
13631363
let (trial_decrypts_handle, trial_decrypts_tx) = trial_decryptions_processor
1364-
.start(uri.clone(), bsync_data.clone(), detected_txns_tx)
1364+
.start(bsync_data.clone(), detected_txns_tx)
13651365
.await;
13661366

13671367
// Fetch Compact blocks and send them to nullifier cache, node-and-witness cache and the trial-decryption processor

0 commit comments

Comments
 (0)