fix: handle invalid mmr root to prevent sync thread panic

This commit is contained in:
ardocrat 2023-10-18 18:03:02 +03:00
parent 5dcbe96d5c
commit f412f3e80f
2 changed files with 7 additions and 7 deletions
chain/src/txhashset

View file

@ -237,7 +237,7 @@ impl Desegmenter {
// Quick root check first:
{
let txhashset = self.txhashset.read();
txhashset.roots().validate(&self.archive_header)?;
txhashset.roots()?.validate(&self.archive_header)?;
}
// TODO: Possibly Keep track of this in the DB so we can pick up where we left off if needed

View file

@ -479,19 +479,19 @@ impl TxHashSet {
}
/// Get MMR roots.
pub fn roots(&self) -> TxHashSetRoots {
pub fn roots(&self) -> Result<TxHashSetRoots, Error> {
let output_pmmr = ReadonlyPMMR::at(&self.output_pmmr_h.backend, self.output_pmmr_h.size);
let rproof_pmmr = ReadonlyPMMR::at(&self.rproof_pmmr_h.backend, self.rproof_pmmr_h.size);
let kernel_pmmr = ReadonlyPMMR::at(&self.kernel_pmmr_h.backend, self.kernel_pmmr_h.size);
TxHashSetRoots {
Ok(TxHashSetRoots {
output_roots: OutputRoots {
pmmr_root: output_pmmr.root().expect("no root, invalid tree"),
pmmr_root: output_pmmr.root().map_err(|_| Error::InvalidRoot)?,
bitmap_root: self.bitmap_accumulator.root(),
},
rproof_root: rproof_pmmr.root().expect("no root, invalid tree"),
kernel_root: kernel_pmmr.root().expect("no root, invalid tree"),
}
rproof_root: rproof_pmmr.root().map_err(|_| Error::InvalidRoot)?,
kernel_root: kernel_pmmr.root().map_err(|_| Error::InvalidRoot)?,
})
}
/// Return Commit's MMR position