Merge pull request #5782 from nuttycom/cleanup/incrementalmerkletree_positions
Update to the latest incrementalmerkletree.
This commit is contained in:
commit
4afec83947
|
@ -855,8 +855,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "incrementalmerkletree"
|
||||
version = "0.3.0-beta.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cad6be282c89afc05aebe4801b0d5f9d6b7c556a8f398e447f4b26ea56a6b45e"
|
||||
source = "git+https://github.com/nuttycom/incrementalmerkletree?rev=027a98e53ad59699662d258ac22cd2095ae02aea#027a98e53ad59699662d258ac22cd2095ae02aea"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
|
|
@ -87,6 +87,7 @@ codegen-units = 1
|
|||
|
||||
[patch.crates-io]
|
||||
hdwallet = { git = "https://github.com/nuttycom/hdwallet", rev = "576683b9f2865f1118c309017ff36e01f84420c9" }
|
||||
incrementalmerkletree = { git = "https://github.com/nuttycom/incrementalmerkletree", rev = "027a98e53ad59699662d258ac22cd2095ae02aea" }
|
||||
zcash_address = { git = "https://github.com/zcash/librustzcash.git", rev = "9c1ed86c5aa8ae3b6d6dcc1478f2d6ba1264488f" }
|
||||
zcash_encoding = { git = "https://github.com/zcash/librustzcash.git", rev = "9c1ed86c5aa8ae3b6d6dcc1478f2d6ba1264488f" }
|
||||
zcash_history = { git = "https://github.com/zcash/librustzcash.git", rev = "9c1ed86c5aa8ae3b6d6dcc1478f2d6ba1264488f" }
|
||||
|
|
|
@ -5,7 +5,7 @@ use incrementalmerkletree::{
|
|||
bridgetree::{BridgeTree, Checkpoint},
|
||||
Hashable,
|
||||
};
|
||||
use zcash_encoding::Vector;
|
||||
use zcash_encoding::{Optional, Vector};
|
||||
use zcash_primitives::merkle_tree::{
|
||||
incremental::{
|
||||
read_bridge_v1, read_leu64_usize, read_position, write_bridge_v1, write_position,
|
||||
|
@ -14,18 +14,14 @@ use zcash_primitives::merkle_tree::{
|
|||
HashSer,
|
||||
};
|
||||
|
||||
pub fn write_checkpoint_v1<H: HashSer + Ord, W: Write>(
|
||||
mut writer: W,
|
||||
checkpoint: &Checkpoint<H>,
|
||||
) -> io::Result<()> {
|
||||
pub fn write_checkpoint_v1<W: Write>(mut writer: W, checkpoint: &Checkpoint) -> io::Result<()> {
|
||||
write_usize_leu64(&mut writer, checkpoint.bridges_len())?;
|
||||
writer.write_u8(if checkpoint.is_witnessed() { 1 } else { 0 })?;
|
||||
Vector::write_sized(
|
||||
&mut writer,
|
||||
checkpoint.forgotten().iter(),
|
||||
|mut w, ((pos, leaf_value), idx)| {
|
||||
|mut w, (pos, idx)| {
|
||||
write_position(&mut w, *pos)?;
|
||||
leaf_value.write(&mut w)?;
|
||||
write_usize_leu64(&mut w, *idx)
|
||||
},
|
||||
)?;
|
||||
|
@ -33,15 +29,12 @@ pub fn write_checkpoint_v1<H: HashSer + Ord, W: Write>(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read_checkpoint_v1<H: HashSer + Ord, R: Read>(mut reader: R) -> io::Result<Checkpoint<H>> {
|
||||
pub fn read_checkpoint_v1<R: Read>(mut reader: R) -> io::Result<Checkpoint> {
|
||||
Ok(Checkpoint::from_parts(
|
||||
read_leu64_usize(&mut reader)?,
|
||||
reader.read_u8()? == 1,
|
||||
Vector::read_collected(&mut reader, |mut r| {
|
||||
Ok((
|
||||
(read_position(&mut r)?, H::read(&mut r)?),
|
||||
read_leu64_usize(&mut r)?,
|
||||
))
|
||||
Ok((read_position(&mut r)?, read_leu64_usize(&mut r)?))
|
||||
})?,
|
||||
))
|
||||
}
|
||||
|
@ -50,13 +43,17 @@ pub fn write_tree_v1<H: Hashable + HashSer + Ord, W: Write>(
|
|||
mut writer: W,
|
||||
tree: &BridgeTree<H, 32>,
|
||||
) -> io::Result<()> {
|
||||
Vector::write(&mut writer, tree.bridges(), |w, b| write_bridge_v1(w, b))?;
|
||||
Vector::write(&mut writer, tree.prior_bridges(), |w, b| {
|
||||
write_bridge_v1(w, b)
|
||||
})?;
|
||||
Optional::write(&mut writer, tree.current_bridge().as_ref(), |w, b| {
|
||||
write_bridge_v1(w, b)
|
||||
})?;
|
||||
Vector::write_sized(
|
||||
&mut writer,
|
||||
tree.witnessed_indices().iter(),
|
||||
|mut w, ((pos, a), i)| {
|
||||
|mut w, (pos, i)| {
|
||||
write_position(&mut w, *pos)?;
|
||||
a.write(&mut w)?;
|
||||
write_usize_leu64(&mut w, *i)
|
||||
},
|
||||
)?;
|
||||
|
@ -74,11 +71,9 @@ pub fn read_tree_v1<H: Hashable + HashSer + Ord + Clone, R: Read>(
|
|||
) -> io::Result<BridgeTree<H, 32>> {
|
||||
BridgeTree::from_parts(
|
||||
Vector::read(&mut reader, |r| read_bridge_v1(r))?,
|
||||
Optional::read(&mut reader, |r| read_bridge_v1(r))?,
|
||||
Vector::read_collected(&mut reader, |mut r| {
|
||||
Ok((
|
||||
(read_position(&mut r)?, H::read(&mut r)?),
|
||||
read_leu64_usize(&mut r)?,
|
||||
))
|
||||
Ok((read_position(&mut r)?, read_leu64_usize(&mut r)?))
|
||||
})?,
|
||||
Vector::read(&mut reader, |r| read_checkpoint_v1(r))?,
|
||||
read_leu64_usize(&mut reader)?,
|
||||
|
|
|
@ -559,8 +559,7 @@ impl Wallet {
|
|||
.and_then(|n| n.decrypted_notes.get(&action_idx))
|
||||
.is_some()
|
||||
{
|
||||
let (pos, cmx) = self.witness_tree.witness().expect("tree is not empty");
|
||||
assert_eq!(cmx, MerkleHashOrchard::from_cmx(action.cmx()));
|
||||
let pos = self.witness_tree.witness().expect("tree is not empty");
|
||||
self.wallet_note_positions
|
||||
.get_mut(txid)
|
||||
.expect("We created this above")
|
||||
|
@ -653,12 +652,15 @@ impl Wallet {
|
|||
.and_then(|tx_notes| tx_notes.note_positions.get(&outpoint.action_idx)),
|
||||
)
|
||||
.map(|(fvk, position)| {
|
||||
assert_eq!(
|
||||
self.witness_tree
|
||||
.get_witnessed_leaf(*position)
|
||||
.expect("tree has witnessed the leaf for this note."),
|
||||
&MerkleHashOrchard::from_cmx(&dnote.note.commitment().into()),
|
||||
);
|
||||
let path = self
|
||||
.witness_tree
|
||||
.authentication_path(
|
||||
*position,
|
||||
&MerkleHashOrchard::from_cmx(&dnote.note.commitment().into()),
|
||||
)
|
||||
.authentication_path(*position)
|
||||
.expect("wallet always has paths to positioned notes");
|
||||
OrchardSpendInfo::from_parts(
|
||||
fvk.clone(),
|
||||
|
|
Loading…
Reference in New Issue