zcash_client_backend::scanning: Use `checked_sub` instead of manual check.
Co-authored-by: str4d <thestr4d@gmail.com>
This commit is contained in:
parent
09e37bcc8d
commit
7720a4fc58
|
@ -381,14 +381,12 @@ pub(crate) fn scan_block_with_runner<
|
||||||
// The default for m.sapling_commitment_tree_size is zero, so we need to check
|
// The default for m.sapling_commitment_tree_size is zero, so we need to check
|
||||||
// that the subtraction will not underflow; if it would do so, we were given
|
// that the subtraction will not underflow; if it would do so, we were given
|
||||||
// invalid chain metadata for a block with Sapling outputs.
|
// invalid chain metadata for a block with Sapling outputs.
|
||||||
if m.sapling_commitment_tree_size >= sapling_output_count {
|
m.sapling_commitment_tree_size
|
||||||
Ok(m.sapling_commitment_tree_size - sapling_output_count)
|
.checked_sub(sapling_output_count)
|
||||||
} else {
|
.ok_or(ScanError::TreeSizeInvalid {
|
||||||
Err(ScanError::TreeSizeInvalid {
|
|
||||||
protocol: ShieldedProtocol::Sapling,
|
protocol: ShieldedProtocol::Sapling,
|
||||||
at_height: cur_height,
|
at_height: cur_height,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -427,14 +425,12 @@ pub(crate) fn scan_block_with_runner<
|
||||||
// The default for m.orchard_commitment_tree_size is zero, so we need to check
|
// The default for m.orchard_commitment_tree_size is zero, so we need to check
|
||||||
// that the subtraction will not underflow; if it would do so, we were given
|
// that the subtraction will not underflow; if it would do so, we were given
|
||||||
// invalid chain metadata for a block with Orchard actions.
|
// invalid chain metadata for a block with Orchard actions.
|
||||||
if m.orchard_commitment_tree_size >= orchard_action_count {
|
m.orchard_commitment_tree_size
|
||||||
Ok(m.orchard_commitment_tree_size - orchard_action_count)
|
.checked_sub(orchard_action_count)
|
||||||
} else {
|
.ok_or(ScanError::TreeSizeInvalid {
|
||||||
Err(ScanError::TreeSizeInvalid {
|
|
||||||
protocol: ShieldedProtocol::Orchard,
|
protocol: ShieldedProtocol::Orchard,
|
||||||
at_height: cur_height,
|
at_height: cur_height,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue