Add more debug and trace logging

The `Debug` impl for `sapling::Node` is updated to output hex-encoded
bytes for readability.
This commit is contained in:
Jack Grigg 2023-07-13 01:12:39 +00:00
parent 510944777c
commit 2a98f94f05
5 changed files with 57 additions and 2 deletions

View File

@ -1,3 +1,4 @@
use std::fmt;
use std::ops::Range;
use zcash_primitives::consensus::BlockHeight;
@ -26,10 +27,25 @@ pub struct ScanRange {
priority: ScanPriority,
}
impl fmt::Display for ScanRange {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{:?}({}..{})",
self.priority, self.block_range.start, self.block_range.end,
)
}
}
impl ScanRange {
/// Constructs a scan range from its constituent parts.
pub fn from_parts(block_range: Range<BlockHeight>, priority: ScanPriority) -> Self {
assert!(block_range.end >= block_range.start);
assert!(
block_range.end >= block_range.start,
"{:?} is invalid for ScanRange({:?})",
block_range,
priority,
);
ScanRange {
block_range,
priority,

View File

@ -2,6 +2,7 @@
use either::Either;
use incrementalmerkletree::Retention;
use std::{collections::HashMap, fmt, io};
use tracing::debug;
use rusqlite::{self, types::ToSql};
use schemer::{Migrator, MigratorError};
@ -318,6 +319,7 @@ pub fn init_blocks_table<P: consensus::Parameters>(
)?;
if let Some(nonempty_frontier) = block_end_tree.to_frontier().value() {
debug!("Inserting frontier into ShardTree: {:?}", nonempty_frontier);
let shard_store =
SqliteShardStore::<_, sapling::Node, SAPLING_SHARD_HEIGHT>::from_connection(
wdb.conn.0,

View File

@ -9,6 +9,7 @@ use rusqlite::{self, named_params, params};
use schemer;
use schemer_rusqlite::RusqliteMigration;
use shardtree::ShardTree;
use tracing::{debug, trace};
use uuid::Uuid;
use zcash_client_backend::data_api::{
@ -61,6 +62,7 @@ impl RusqliteMigration for Migration {
fn up(&self, transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// Add commitment tree sizes to block metadata.
debug!("Adding new columns");
transaction.execute_batch(
"ALTER TABLE blocks ADD COLUMN sapling_commitment_tree_size INTEGER;
ALTER TABLE blocks ADD COLUMN orchard_commitment_tree_size INTEGER;
@ -68,6 +70,7 @@ impl RusqliteMigration for Migration {
)?;
// Add shard persistence
debug!("Creating tables for shard persistence");
transaction.execute_batch(
"CREATE TABLE sapling_tree_shards (
shard_index INTEGER PRIMARY KEY,
@ -86,6 +89,7 @@ impl RusqliteMigration for Migration {
)?;
// Add checkpoint persistence
debug!("Creating tables for checkpoint persistence");
transaction.execute_batch(
"CREATE TABLE sapling_tree_checkpoints (
checkpoint_id INTEGER PRIMARY KEY,
@ -133,10 +137,23 @@ impl RusqliteMigration for Migration {
)
})?;
if block_height % 1000 == 0 {
debug!(height = block_height, "Migrating tree data to shardtree");
}
trace!(
height = block_height,
size = block_end_tree.size(),
"Storing Sapling commitment tree size"
);
stmt_update_block_sapling_tree_size
.execute(params![block_end_tree.size(), block_height])?;
if let Some(nonempty_frontier) = block_end_tree.to_frontier().value() {
trace!(
height = block_height,
frontier = ?nonempty_frontier,
"Inserting frontier nodes",
);
shard_tree.insert_frontier_nodes(
nonempty_frontier.clone(),
Retention::Checkpoint {
@ -149,6 +166,7 @@ impl RusqliteMigration for Migration {
}
// Insert all the tree information that we can get from existing incremental witnesses
debug!("Migrating witness data to shardtree");
{
let mut stmt_blocks =
transaction.prepare("SELECT note, block, witness FROM sapling_witnesses")?;
@ -190,6 +208,7 @@ impl RusqliteMigration for Migration {
}
// Establish the scan queue & wallet history table
debug!("Creating table for scan queue");
transaction.execute_batch(
"CREATE TABLE scan_queue (
block_range_start INTEGER NOT NULL,

View File

@ -3,6 +3,7 @@ use std::cmp::{max, min, Ordering};
use std::collections::BTreeSet;
use std::ops::{Not, Range};
use std::rc::Rc;
use tracing::{debug, trace};
use zcash_client_backend::data_api::scanning::{ScanPriority, ScanRange};
use incrementalmerkletree::{Address, Position};
@ -413,6 +414,7 @@ pub(crate) fn insert_queue_entries<'a>(
)?;
for entry in entries {
trace!("Inserting queue entry {}", entry);
if !entry.is_empty() {
stmt.execute(named_params![
":block_range_start": u32::from(entry.block_range().start) ,
@ -654,6 +656,12 @@ pub(crate) fn update_chain_tip<P: consensus::Parameters>(
}
}
});
if let Some(entry) = &shard_entry {
debug!("{} will update latest shard", entry);
}
if let Some(entry) = &tip_entry {
debug!("{} will connect prior tip to new tip", entry);
}
let query_range = match (shard_entry.as_ref(), tip_entry.as_ref()) {
(Some(se), Some(te)) => Some(Range {

View File

@ -2,6 +2,8 @@ use bitvec::{order::Lsb0, view::AsBits};
use group::{ff::PrimeField, Curve};
use incrementalmerkletree::{Hashable, Level};
use lazy_static::lazy_static;
use std::fmt;
use std::io::{self, Read, Write};
use super::{
@ -64,11 +66,19 @@ pub fn merkle_hash(depth: usize, lhs: &[u8; 32], rhs: &[u8; 32]) -> [u8; 32] {
}
/// A node within the Sapling commitment tree.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Node {
pub(super) repr: [u8; 32],
}
impl fmt::Debug for Node {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Node")
.field("repr", &hex::encode(self.repr))
.finish()
}
}
impl Node {
#[cfg(test)]
pub(crate) fn new(repr: [u8; 32]) -> Self {