Merge pull request #1290 from nuttycom/fix/empty_tree_deserialization

zcash_client_backend: Treat protobuf default as the empty `CommitmentTree`.
This commit is contained in:
str4d 2024-03-19 23:55:02 +00:00 committed by GitHub
commit e795174809
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 17 deletions

View File

@ -263,15 +263,19 @@ impl service::TreeState {
pub fn sapling_tree(
&self,
) -> io::Result<CommitmentTree<Node, { sapling::NOTE_COMMITMENT_TREE_DEPTH }>> {
let sapling_tree_bytes = hex::decode(&self.sapling_tree).map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Hex decoding of Sapling tree bytes failed: {:?}", e),
if self.sapling_tree.is_empty() {
Ok(CommitmentTree::empty())
} else {
let sapling_tree_bytes = hex::decode(&self.sapling_tree).map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Hex decoding of Sapling tree bytes failed: {:?}", e),
)
})?;
read_commitment_tree::<Node, _, { sapling::NOTE_COMMITMENT_TREE_DEPTH }>(
&sapling_tree_bytes[..],
)
})?;
read_commitment_tree::<Node, _, { sapling::NOTE_COMMITMENT_TREE_DEPTH }>(
&sapling_tree_bytes[..],
)
}
}
/// Deserializes and returns the Sapling note commitment tree field of the tree state.
@ -280,15 +284,21 @@ impl service::TreeState {
&self,
) -> io::Result<CommitmentTree<MerkleHashOrchard, { orchard::NOTE_COMMITMENT_TREE_DEPTH as u8 }>>
{
let orchard_tree_bytes = hex::decode(&self.orchard_tree).map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Hex decoding of Orchard tree bytes failed: {:?}", e),
)
})?;
read_commitment_tree::<MerkleHashOrchard, _, { orchard::NOTE_COMMITMENT_TREE_DEPTH as u8 }>(
&orchard_tree_bytes[..],
)
if self.orchard_tree.is_empty() {
Ok(CommitmentTree::empty())
} else {
let orchard_tree_bytes = hex::decode(&self.orchard_tree).map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Hex decoding of Orchard tree bytes failed: {:?}", e),
)
})?;
read_commitment_tree::<
MerkleHashOrchard,
_,
{ orchard::NOTE_COMMITMENT_TREE_DEPTH as u8 },
>(&orchard_tree_bytes[..])
}
}
/// Parses this tree state into a [`ChainState`] for use with [`scan_cached_blocks`].