Fix decoy tx fetching

This commit is contained in:
Aditya Kulkarni 2019-10-09 12:27:31 -07:00
parent 1356ef809b
commit b489870480
3 changed files with 20 additions and 13 deletions

View File

@ -40,33 +40,33 @@ rand = "0.7.2"
[dependencies.bellman] [dependencies.bellman]
git = "https://github.com/adityapk00/librustzcash.git" git = "https://github.com/adityapk00/librustzcash.git"
rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" rev = "188537ea025fcb7fbdfc11266f307a084a5451e4"
default-features = false default-features = false
features = ["groth16"] features = ["groth16"]
[dependencies.pairing] [dependencies.pairing]
git = "https://github.com/adityapk00/librustzcash.git" git = "https://github.com/adityapk00/librustzcash.git"
rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" rev = "188537ea025fcb7fbdfc11266f307a084a5451e4"
[dependencies.zcash_client_backend] [dependencies.zcash_client_backend]
git = "https://github.com/adityapk00/librustzcash.git" git = "https://github.com/adityapk00/librustzcash.git"
rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" rev = "188537ea025fcb7fbdfc11266f307a084a5451e4"
default-features = false default-features = false
[dependencies.zcash_primitives] [dependencies.zcash_primitives]
git = "https://github.com/adityapk00/librustzcash.git" git = "https://github.com/adityapk00/librustzcash.git"
rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" rev = "188537ea025fcb7fbdfc11266f307a084a5451e4"
default-features = false default-features = false
features = ["transparent-inputs"] features = ["transparent-inputs"]
[dependencies.zcash_proofs] [dependencies.zcash_proofs]
git = "https://github.com/adityapk00/librustzcash.git" git = "https://github.com/adityapk00/librustzcash.git"
rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" rev = "188537ea025fcb7fbdfc11266f307a084a5451e4"
default-features = false default-features = false
[dependencies.ff] [dependencies.ff]
git = "https://github.com/adityapk00/librustzcash.git" git = "https://github.com/adityapk00/librustzcash.git"
rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" rev = "188537ea025fcb7fbdfc11266f307a084a5451e4"
features = ["ff_derive"] features = ["ff_derive"]
[build-dependencies] [build-dependencies]

View File

@ -619,7 +619,7 @@ impl LightClient {
match local_light_wallet.scan_block(encoded_block) { match local_light_wallet.scan_block(encoded_block) {
Ok(block_txns) => { Ok(block_txns) => {
all_txs.write().unwrap().copy_from_slice(&block_txns.iter().map(|txid| (txid.clone(), height as i32)).collect::<Vec<_>>()[..]); all_txs.write().unwrap().extend_from_slice(&block_txns.iter().map(|txid| (txid.clone(), height as i32)).collect::<Vec<_>>()[..]);
}, },
Err(invalid_height) => { Err(invalid_height) => {
// Block at this height seems to be invalid, so invalidate up till that point // Block at this height seems to be invalid, so invalidate up till that point
@ -698,18 +698,23 @@ impl LightClient {
.map(|wtx| (wtx.txid, wtx.block)) .map(|wtx| (wtx.txid, wtx.block))
.collect::<Vec<(TxId, i32)>>(); .collect::<Vec<(TxId, i32)>>();
info!("Fetching {} new txids, along with {} decoy", txids_to_fetch.len(), all_new_txs.read().unwrap().len()); info!("Fetching {} new txids, total {} with decoy", txids_to_fetch.len(), all_new_txs.read().unwrap().len());
txids_to_fetch.extend_from_slice(&all_new_txs.read().unwrap()[..]); txids_to_fetch.extend_from_slice(&all_new_txs.read().unwrap()[..]);
txids_to_fetch.sort();
txids_to_fetch.dedup();
let mut rng = OsRng; let mut rng = OsRng;
txids_to_fetch.shuffle(&mut rng); txids_to_fetch.shuffle(&mut rng);
// And go and fetch the txids, getting the full transaction, so we can // And go and fetch the txids, getting the full transaction, so we can
// read the memos // read the memos
for (txid, height) in txids_to_fetch { for (txid, height) in txids_to_fetch {
let light_wallet_clone = self.wallet.clone(); let light_wallet_clone = self.wallet.clone();
info!("Fetching full Tx: {}", txid); info!("Fetching full Tx: {}", txid);
if print_updates {
responses.push(format!("Fetching full Tx: {}", txid)); responses.push(format!("Fetching full Tx: {}", txid));
}
fetch_full_tx(&self.get_server_uri(), txid, self.config.no_cert_verification, move |tx_bytes: &[u8] | { fetch_full_tx(&self.get_server_uri(), txid, self.config.no_cert_verification, move |tx_bytes: &[u8] | {
let tx = Transaction::read(tx_bytes).unwrap(); let tx = Transaction::read(tx_bytes).unwrap();

View File

@ -816,8 +816,10 @@ impl LightWallet {
// Mark this Tx as scanned // Mark this Tx as scanned
{ {
let mut txs = self.txs.write().unwrap(); let mut txs = self.txs.write().unwrap();
let mut wtx = txs.get_mut(&tx.txid()).unwrap(); match txs.get_mut(&tx.txid()) {
wtx.full_tx_scanned = true; Some(wtx) => wtx.full_tx_scanned = true,
None => {},
};
} }
} }