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