Remove some unwrap/expect in chain crate (#2621)
* Return Result instead of calling expect in root(). It would kill peer's thread. Perhaps we should ban this peer as malicious. * Remove some unwraps
This commit is contained in:
committed by
Ignotus Peverell
parent
2df633b622
commit
e71eca1977
@@ -68,7 +68,8 @@ impl<'a> RewindableKernelView<'a> {
|
||||
/// fast sync where a reorg past the horizon could allow a whole rewrite of
|
||||
/// the kernel set.
|
||||
pub fn validate_root(&self) -> Result<(), Error> {
|
||||
if self.pmmr.root() != self.header.kernel_root {
|
||||
let root = self.pmmr.root().map_err(|_| ErrorKind::InvalidRoot)?;
|
||||
if root != self.header.kernel_root {
|
||||
return Err(ErrorKind::InvalidTxHashSet(format!(
|
||||
"Kernel root at {} does not match",
|
||||
self.header.height
|
||||
|
||||
@@ -272,9 +272,11 @@ impl TxHashSet {
|
||||
}
|
||||
|
||||
/// build a new merkle proof for the given position.
|
||||
pub fn merkle_proof(&mut self, commit: Commitment) -> Result<MerkleProof, String> {
|
||||
let pos = self.commit_index.get_output_pos(&commit).unwrap();
|
||||
PMMR::at(&mut self.output_pmmr_h.backend, self.output_pmmr_h.last_pos).merkle_proof(pos)
|
||||
pub fn merkle_proof(&mut self, commit: Commitment) -> Result<MerkleProof, Error> {
|
||||
let pos = self.commit_index.get_output_pos(&commit)?;
|
||||
PMMR::at(&mut self.output_pmmr_h.backend, self.output_pmmr_h.last_pos)
|
||||
.merkle_proof(pos)
|
||||
.map_err(|_| ErrorKind::MerkleProof.into())
|
||||
}
|
||||
|
||||
/// Compact the MMR data files and flush the rm logs
|
||||
@@ -1590,6 +1592,5 @@ pub fn input_pos_to_rewind(
|
||||
current = batch.get_previous_header(¤t)?;
|
||||
}
|
||||
|
||||
let bitmap = bitmap_fast_or(None, &mut block_input_bitmaps).unwrap();
|
||||
Ok(bitmap)
|
||||
bitmap_fast_or(None, &mut block_input_bitmaps).ok_or_else(|| ErrorKind::Bitmap.into())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user