parent
4094c5d25b
commit
b49210849e
|
@ -9,7 +9,6 @@ use tokio::sync::Mutex;
|
|||
use tonic::transport::Channel;
|
||||
use tonic::Request;
|
||||
use zcash_primitives::sapling::Note;
|
||||
use crate::commitment::CTree;
|
||||
|
||||
const DEFAULT_CHUNK_SIZE: u32 = 100_000;
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
use crate::commitment::{CTree, Witness};
|
||||
use crate::db::AccountViewKey;
|
||||
use crate::lw_rpc::compact_tx_streamer_client::CompactTxStreamerClient;
|
||||
use crate::lw_rpc::*;
|
||||
use crate::scan::Blocks;
|
||||
use crate::builder::advance_tree;
|
||||
use ff::PrimeField;
|
||||
use futures::{future, FutureExt};
|
||||
use log::info;
|
||||
|
|
15
src/db.rs
15
src/db.rs
|
@ -3,7 +3,7 @@ use crate::contact::Contact;
|
|||
use crate::prices::Quote;
|
||||
use crate::taddr::{derive_tkeys, TBalance};
|
||||
use crate::transaction::TransactionInfo;
|
||||
use crate::commitment::{CTree, Witness};
|
||||
use crate::sync::tree::{CTree, TreeCheckpoint, Witness};
|
||||
use rusqlite::Error::QueryReturnedNoRows;
|
||||
use rusqlite::{params, Connection, OptionalExtension, Transaction};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -499,11 +499,11 @@ impl DbAdapter {
|
|||
}))
|
||||
}
|
||||
|
||||
pub fn get_tree(&self) -> anyhow::Result<(CTree, Vec<Witness>)> {
|
||||
todo!()
|
||||
pub fn get_tree(&self) -> anyhow::Result<(TreeCheckpoint, TreeCheckpoint)> {
|
||||
self.get_tree_by_name("sapling");
|
||||
}
|
||||
|
||||
pub fn get_tree_by_name(&self, shielded_pool: &str) -> anyhow::Result<(sync::CTree, Vec<sync::Witness>)> {
|
||||
pub fn get_tree_by_name(&self, shielded_pool: &str) -> anyhow::Result<(TreeCheckpoint)> {
|
||||
let res = self.connection.query_row(
|
||||
&format!("SELECT height, {}_tree FROM blocks WHERE height = (SELECT MAX(height) FROM blocks)", shielded_pool),
|
||||
[], |row| {
|
||||
|
@ -525,9 +525,12 @@ impl DbAdapter {
|
|||
for w in ws {
|
||||
witnesses.push(w?);
|
||||
}
|
||||
(tree, witnesses)
|
||||
TreeCheckpoint { tree, witnesses }
|
||||
}
|
||||
None => (sync::CTree::new(), vec![]),
|
||||
None => TreeCheckpoint {
|
||||
tree: CTree::new(),
|
||||
witnesses: vec![],
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -74,15 +74,15 @@ const LWD_URL: &str = "https://mainnet.lightwalletd.com:9067";
|
|||
|
||||
pub type Hash = [u8; 32];
|
||||
|
||||
mod builder;
|
||||
// mod builder;
|
||||
mod chain;
|
||||
mod coinconfig;
|
||||
mod commitment;
|
||||
// mod commitment;
|
||||
mod contact;
|
||||
mod db;
|
||||
mod fountain;
|
||||
mod hash;
|
||||
pub mod sync;
|
||||
pub(crate) mod sync;
|
||||
pub mod sapling;
|
||||
mod key;
|
||||
mod key2;
|
||||
|
@ -90,7 +90,7 @@ mod mempool;
|
|||
mod misc;
|
||||
mod pay;
|
||||
mod prices;
|
||||
mod print;
|
||||
// mod print;
|
||||
mod scan;
|
||||
mod taddr;
|
||||
mod transaction;
|
||||
|
|
19
src/print.rs
19
src/print.rs
|
@ -1,6 +1,7 @@
|
|||
use crate::commitment::{CTree, Witness};
|
||||
use zcash_primitives::merkle_tree::{CommitmentTree, IncrementalWitness};
|
||||
use zcash_primitives::sapling::Node;
|
||||
use std::io::{Read, Write};
|
||||
use crate::sync::tree::{CTree, Witness};
|
||||
use zcash_primitives::merkle_tree::{CommitmentTree, HashSer, IncrementalWitness};
|
||||
use crate::sync::Node;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn print_node(n: &Node) {
|
||||
|
@ -30,10 +31,10 @@ pub fn print_witness(w: &IncrementalWitness<Node>) {
|
|||
|
||||
pub fn print_ctree(t: &CTree) {
|
||||
println!("Tree");
|
||||
println!("{:?}", t.left.map(|n| hex::encode(n.repr)));
|
||||
println!("{:?}", t.right.map(|n| hex::encode(n.repr)));
|
||||
println!("{:?}", t.left.map(|n| hex::encode(n)));
|
||||
println!("{:?}", t.right.map(|n| hex::encode(n)));
|
||||
for p in t.parents.iter() {
|
||||
println!("{:?}", p.map(|n| hex::encode(n.repr)));
|
||||
println!("{:?}", p.map(|n| hex::encode(n)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,9 +48,9 @@ pub fn print_witness2(w: &Witness) {
|
|||
}
|
||||
let t = &w.cursor;
|
||||
println!("Cursor");
|
||||
println!("{:?}", t.left.map(|n| hex::encode(n.repr)));
|
||||
println!("{:?}", t.right.map(|n| hex::encode(n.repr)));
|
||||
println!("{:?}", t.left.map(|n| hex::encode(n)));
|
||||
println!("{:?}", t.right.map(|n| hex::encode(n)));
|
||||
for p in t.parents.iter() {
|
||||
println!("{:?}", p.map(|n| hex::encode(n.repr)));
|
||||
println!("{:?}", p.map(|n| hex::encode(n)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::builder::BlockProcessor;
|
||||
use crate::chain::{DecryptedBlock, get_latest_height, Nf, NfRef};
|
||||
use crate::db::{AccountViewKey, DbAdapter, PlainNote, ReceivedNote};
|
||||
use serde::Serialize;
|
||||
|
@ -10,7 +9,6 @@ use crate::{
|
|||
CompactTx
|
||||
};
|
||||
use crate::chain::{DecryptNode, download_chain};
|
||||
use crate::commitment::Witness;
|
||||
use ff::PrimeField;
|
||||
|
||||
use anyhow::anyhow;
|
||||
|
@ -144,7 +142,7 @@ pub async fn sync_async(
|
|||
continue;
|
||||
}
|
||||
progress.downloaded += blocks_size;
|
||||
let (mut tree, witnesses) = db.get_tree()?;
|
||||
let (mut sapling_checkpoint, mut orchard_checkpoint) = db.get_tree()?;
|
||||
let mut bp = BlockProcessor::new(&tree, &witnesses);
|
||||
let mut absolute_position_at_block_start = tree.get_position();
|
||||
|
||||
|
|
|
@ -9,11 +9,12 @@ use crate::{CompactBlock, DbAdapter};
|
|||
use crate::chain::Nf;
|
||||
use crate::db::{DbAdapterBuilder, ReceivedNote, ReceivedNoteShort};
|
||||
|
||||
mod tree;
|
||||
mod trial_decrypt;
|
||||
pub mod tree;
|
||||
pub mod trial_decrypt;
|
||||
|
||||
pub use trial_decrypt::{ViewKey, DecryptedNote, TrialDecrypter, CompactOutputBytes, OutputPosition};
|
||||
pub use tree::{Hasher, Node, WarpProcessor, Witness, CTree};
|
||||
use crate::sync::tree::TreeCheckpoint;
|
||||
|
||||
pub struct Synchronizer<N: Parameters, D: BatchDomain<ExtractedCommitmentBytes = [u8; 32]>, VK: ViewKey<D>, DN: DecryptedNote<D, VK>,
|
||||
TD: TrialDecrypter<N, D, VK, DN>, H: Hasher> {
|
||||
|
@ -38,7 +39,7 @@ impl <N: Parameters + Sync,
|
|||
H: Hasher> Synchronizer<N, D, VK, DN, TD, H> {
|
||||
pub fn initialize(&mut self) -> Result<()> {
|
||||
let db = self.db.build()?;
|
||||
let (tree, witnesses) = db.get_tree_by_name(&self.shielded_pool)?;
|
||||
let TreeCheckpoint { tree, witnesses } = db.get_tree_by_name(&self.shielded_pool)?;
|
||||
self.tree = tree;
|
||||
self.witnesses = witnesses;
|
||||
for vk in self.vks.iter() {
|
||||
|
|
|
@ -215,6 +215,11 @@ impl Witness {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct TreeCheckpoint {
|
||||
pub tree: CTree,
|
||||
pub witnesses: Vec<Witness>,
|
||||
}
|
||||
|
||||
trait Builder {
|
||||
type Context;
|
||||
type Output;
|
||||
|
|
Loading…
Reference in New Issue