zcash_client_sqlite: Use correct offsets for Orchard commitment positions.
This commit is contained in:
parent
b62763d689
commit
8dfa836a03
|
@ -427,7 +427,7 @@ impl<AccountId: Eq + Hash> WalletSummary<AccountId> {
|
||||||
/// belonging to a wallet.
|
/// belonging to a wallet.
|
||||||
pub trait InputSource {
|
pub trait InputSource {
|
||||||
/// The type of errors produced by a wallet backend.
|
/// The type of errors produced by a wallet backend.
|
||||||
type Error;
|
type Error: Debug;
|
||||||
|
|
||||||
/// Backend-specific account identifier.
|
/// Backend-specific account identifier.
|
||||||
///
|
///
|
||||||
|
@ -498,7 +498,7 @@ pub trait InputSource {
|
||||||
/// be abstracted away from any particular data storage substrate.
|
/// be abstracted away from any particular data storage substrate.
|
||||||
pub trait WalletRead {
|
pub trait WalletRead {
|
||||||
/// The type of errors that may be generated when querying a wallet data store.
|
/// The type of errors that may be generated when querying a wallet data store.
|
||||||
type Error;
|
type Error: Debug;
|
||||||
|
|
||||||
/// The type of the account identifier.
|
/// The type of the account identifier.
|
||||||
///
|
///
|
||||||
|
@ -1312,7 +1312,8 @@ pub trait WalletWrite: WalletRead {
|
||||||
/// At present, this only serves the Sapling protocol, but it will be modified to
|
/// At present, this only serves the Sapling protocol, but it will be modified to
|
||||||
/// also provide operations related to Orchard note commitment trees in the future.
|
/// also provide operations related to Orchard note commitment trees in the future.
|
||||||
pub trait WalletCommitmentTrees {
|
pub trait WalletCommitmentTrees {
|
||||||
type Error;
|
type Error: Debug;
|
||||||
|
|
||||||
/// The type of the backing [`ShardStore`] for the Sapling note commitment tree.
|
/// The type of the backing [`ShardStore`] for the Sapling note commitment tree.
|
||||||
type SaplingShardStore<'a>: ShardStore<
|
type SaplingShardStore<'a>: ShardStore<
|
||||||
H = sapling::Node,
|
H = sapling::Node,
|
||||||
|
|
|
@ -512,15 +512,25 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
|
||||||
&mut self,
|
&mut self,
|
||||||
blocks: Vec<ScannedBlock<Self::AccountId>>,
|
blocks: Vec<ScannedBlock<Self::AccountId>>,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
|
struct BlockPositions {
|
||||||
|
height: BlockHeight,
|
||||||
|
sapling_start_position: Position,
|
||||||
|
#[cfg(feature = "orchard")]
|
||||||
|
orchard_start_position: Position,
|
||||||
|
}
|
||||||
|
|
||||||
self.transactionally(|wdb| {
|
self.transactionally(|wdb| {
|
||||||
let start_positions = blocks.first().map(|block| {
|
let start_positions = blocks.first().map(|block| BlockPositions {
|
||||||
(
|
height: block.height(),
|
||||||
block.height(),
|
sapling_start_position: Position::from(
|
||||||
Position::from(
|
u64::from(block.sapling().final_tree_size())
|
||||||
u64::from(block.sapling().final_tree_size())
|
- u64::try_from(block.sapling().commitments().len()).unwrap(),
|
||||||
- u64::try_from(block.sapling().commitments().len()).unwrap(),
|
),
|
||||||
),
|
#[cfg(feature = "orchard")]
|
||||||
)
|
orchard_start_position: Position::from(
|
||||||
|
u64::from(block.orchard().final_tree_size())
|
||||||
|
- u64::try_from(block.orchard().commitments().len()).unwrap(),
|
||||||
|
),
|
||||||
});
|
});
|
||||||
let mut sapling_commitments = vec![];
|
let mut sapling_commitments = vec![];
|
||||||
#[cfg(feature = "orchard")]
|
#[cfg(feature = "orchard")]
|
||||||
|
@ -655,7 +665,7 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
|
||||||
|
|
||||||
// We will have a start position and a last scanned height in all cases where
|
// We will have a start position and a last scanned height in all cases where
|
||||||
// `blocks` is non-empty.
|
// `blocks` is non-empty.
|
||||||
if let Some(((start_height, start_position), last_scanned_height)) =
|
if let Some((start_positions, last_scanned_height)) =
|
||||||
start_positions.zip(last_scanned_height)
|
start_positions.zip(last_scanned_height)
|
||||||
{
|
{
|
||||||
// Create subtrees from the note commitments in parallel.
|
// Create subtrees from the note commitments in parallel.
|
||||||
|
@ -665,7 +675,8 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
|
||||||
.par_chunks_mut(CHUNK_SIZE)
|
.par_chunks_mut(CHUNK_SIZE)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, chunk)| {
|
.filter_map(|(i, chunk)| {
|
||||||
let start = start_position + (i * CHUNK_SIZE) as u64;
|
let start =
|
||||||
|
start_positions.sapling_start_position + (i * CHUNK_SIZE) as u64;
|
||||||
let end = start + chunk.len() as u64;
|
let end = start + chunk.len() as u64;
|
||||||
|
|
||||||
shardtree::LocatedTree::from_iter(
|
shardtree::LocatedTree::from_iter(
|
||||||
|
@ -695,7 +706,8 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
|
||||||
.par_chunks_mut(CHUNK_SIZE)
|
.par_chunks_mut(CHUNK_SIZE)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, chunk)| {
|
.filter_map(|(i, chunk)| {
|
||||||
let start = start_position + (i * CHUNK_SIZE) as u64;
|
let start =
|
||||||
|
start_positions.orchard_start_position + (i * CHUNK_SIZE) as u64;
|
||||||
let end = start + chunk.len() as u64;
|
let end = start + chunk.len() as u64;
|
||||||
|
|
||||||
shardtree::LocatedTree::from_iter(
|
shardtree::LocatedTree::from_iter(
|
||||||
|
@ -725,7 +737,7 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
|
||||||
wdb.conn.0,
|
wdb.conn.0,
|
||||||
&wdb.params,
|
&wdb.params,
|
||||||
Range {
|
Range {
|
||||||
start: start_height,
|
start: start_positions.height,
|
||||||
end: last_scanned_height + 1,
|
end: last_scanned_height + 1,
|
||||||
},
|
},
|
||||||
¬e_positions,
|
¬e_positions,
|
||||||
|
|
Loading…
Reference in New Issue