Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: str4d <[email protected]>
  • Loading branch information
nuttycom and str4d committed Jul 6, 2023
1 parent 98147e0 commit f06ab68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion zcash_client_backend/src/data_api/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
use zcash_primitives::{
consensus::{self, BlockHeight},
sapling::{self, note_encryption::PreparedIncomingViewingKey},
zip32::Scope,
zip32::Scope, block::BlockHash,
};

use crate::{
Expand Down Expand Up @@ -197,6 +197,16 @@ where
if let Some(scan_error) = check_continuity(&block, continuity_check_metadata.as_ref()) {
return Err(Error::Scan(scan_error));
}

if from_height == BlockHeight::from(0) {
// We can always derive a valid `continuity_check_metadata` for the
// genesis block, even if the block source doesn't have
// `sapling_commitment_tree_size`. So briefly set it to a dummy value that
// ensures the `map` below produces the correct genesis block value.
assert!(continuity_check_metadata.is_none());
continuity_check_metadata =
Some(BlockMetadata::from_parts(BlockHeight::from(0), BlockHash([0; 32]), 0));

Check warning on line 208 in zcash_client_backend/src/data_api/chain.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api/chain.rs#L206-L208

Added lines #L206 - L208 were not covered by tests
}
continuity_check_metadata = continuity_check_metadata.as_ref().map(|m| {
BlockMetadata::from_parts(
block.height(),
Expand Down
2 changes: 1 addition & 1 deletion zcash_client_backend/src/scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl fmt::Display for ScanError {
write!(f, "Block height discontinuity at height {}; next height is : {}", prev_height, new_height)

Check warning on line 153 in zcash_client_backend/src/scanning.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/scanning.rs#L152-L153

Added lines #L152 - L153 were not covered by tests
}
ScanError::TreeSizeMismatch { protocol, at_height, given, computed } => {
write!(f, "The the {:?} note commitment tree size provided by a compact block did not match the expected size at height {}; given {}, expected {}", protocol, at_height, given, computed)
write!(f, "The {:?} note commitment tree size provided by a compact block did not match the expected size at height {}; given {}, expected {}", protocol, at_height, given, computed)

Check warning on line 156 in zcash_client_backend/src/scanning.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/scanning.rs#L155-L156

Added lines #L155 - L156 were not covered by tests
}
ScanError::TreeSizeUnknown { protocol, at_height } => {
write!(f, "Unable to determine {:?} note commitment tree size at height {}", protocol, at_height)

Check warning on line 159 in zcash_client_backend/src/scanning.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/scanning.rs#L158-L159

Added lines #L158 - L159 were not covered by tests
Expand Down

0 comments on commit f06ab68

Please sign in to comment.