This commit is contained in:
Hanh 2022-10-23 18:29:07 +08:00
parent b49210849e
commit 3539c45771
4 changed files with 12 additions and 51 deletions

View File

@ -138,7 +138,7 @@ async fn fetch_and_store_tree_state(
.get_tree_state(Request::new(block_id)) .get_tree_state(Request::new(block_id))
.await? .await?
.into_inner(); .into_inner();
let tree = CTree::read(&*hex::decode(&tree_state.sapling_tree)?)?; let tree = CTree::read(&*hex::decode(&tree_state.sapling_tree)?)?; // retrieve orchard state and store it too
let db = c.db()?; let db = c.db()?;
DbAdapter::store_block(&db.connection, height, &block.hash, block.time, &tree, None)?; DbAdapter::store_block(&db.connection, height, &block.hash, block.time, &tree, None)?;
Ok(()) Ok(())

View File

@ -543,54 +543,6 @@ fn calculate_tree_state_v1(
witnesses witnesses
} }
#[allow(dead_code)]
fn calculate_tree_state_v2(cbs: &[CompactBlock], blocks: &[DecryptedBlock]) -> Vec<Witness> {
let mut p = 0usize;
let mut nodes: Vec<Node> = vec![];
let mut positions: Vec<usize> = vec![];
let start = Instant::now();
for (cb, block) in cbs.iter().zip(blocks) {
assert_eq!(cb.height as u32, block.height);
if !block.notes.is_empty() {
println!("{} {}", block.height, block.notes.len());
}
let mut notes = block.notes.iter();
let mut n = notes.next();
let mut i = 0usize;
for tx in cb.vtx.iter() {
for co in tx.outputs.iter() {
let mut cmu = [0u8; 32];
cmu.copy_from_slice(&co.cmu);
let node = Node::new(cmu);
nodes.push(node);
if let Some(nn) = n {
if i == nn.position_in_block {
positions.push(p);
n = notes.next();
}
}
i += 1;
p += 1;
}
}
}
info!(
"Build CMU list: {} ms - {} nodes",
start.elapsed().as_millis(),
nodes.len()
);
let witnesses: Vec<_> = positions
.iter()
.map(|p| Witness::new(*p, 0, None))
.collect();
let (_, new_witnesses) = advance_tree(&CTree::new(), &witnesses, &mut nodes, true);
info!("Tree State & Witnesses: {} ms", start.elapsed().as_millis());
new_witnesses
}
/// Connect to a lightwalletd server /// Connect to a lightwalletd server
pub async fn connect_lightwalletd(url: &str) -> anyhow::Result<CompactTxStreamerClient<Channel>> { pub async fn connect_lightwalletd(url: &str) -> anyhow::Result<CompactTxStreamerClient<Channel>> {
log::info!("LWD URL: {}", url); log::info!("LWD URL: {}", url);

View File

@ -500,10 +500,10 @@ impl DbAdapter {
} }
pub fn get_tree(&self) -> anyhow::Result<(TreeCheckpoint, TreeCheckpoint)> { pub fn get_tree(&self) -> anyhow::Result<(TreeCheckpoint, TreeCheckpoint)> {
self.get_tree_by_name("sapling"); self.get_tree_by_name("sapling"); // TODO: pack in TreeCheckpoint
} }
pub fn get_tree_by_name(&self, shielded_pool: &str) -> anyhow::Result<(TreeCheckpoint)> { pub fn get_tree_by_name(&self, shielded_pool: &str) -> anyhow::Result<TreeCheckpoint> {
let res = self.connection.query_row( let res = self.connection.query_row(
&format!("SELECT height, {}_tree FROM blocks WHERE height = (SELECT MAX(height) FROM blocks)", shielded_pool), &format!("SELECT height, {}_tree FROM blocks WHERE height = (SELECT MAX(height) FROM blocks)", shielded_pool),
[], |row| { [], |row| {

View File

@ -143,6 +143,15 @@ pub async fn sync_async(
} }
progress.downloaded += blocks_size; progress.downloaded += blocks_size;
let (mut sapling_checkpoint, mut orchard_checkpoint) = db.get_tree()?; let (mut sapling_checkpoint, mut orchard_checkpoint) = db.get_tree()?;
/* TODO
- Change to WarpProcessors & Trial Decryptors - sapling & orchard
- Feed block into WP sapling
- Check height vs orchard activation height -> Feed block into WP orchard
- Refactor into function
- Remove new_idtx
*/
let mut bp = BlockProcessor::new(&tree, &witnesses); let mut bp = BlockProcessor::new(&tree, &witnesses);
let mut absolute_position_at_block_start = tree.get_position(); let mut absolute_position_at_block_start = tree.get_position();