Skip to content

Commit 213dfd4

Browse files
authored
Handle invalid MMR root to prevent sync thread panic (#3774)
* fix: handle invalid mmr root to prevent sync thread panic * test: fix roots check
1 parent 5dcbe96 commit 213dfd4

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

chain/src/txhashset/desegmenter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl Desegmenter {
237237
// Quick root check first:
238238
{
239239
let txhashset = self.txhashset.read();
240-
txhashset.roots().validate(&self.archive_header)?;
240+
txhashset.roots()?.validate(&self.archive_header)?;
241241
}
242242

243243
// TODO: Possibly Keep track of this in the DB so we can pick up where we left off if needed

chain/src/txhashset/txhashset.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,19 +479,19 @@ impl TxHashSet {
479479
}
480480

481481
/// Get MMR roots.
482-
pub fn roots(&self) -> TxHashSetRoots {
482+
pub fn roots(&self) -> Result<TxHashSetRoots, Error> {
483483
let output_pmmr = ReadonlyPMMR::at(&self.output_pmmr_h.backend, self.output_pmmr_h.size);
484484
let rproof_pmmr = ReadonlyPMMR::at(&self.rproof_pmmr_h.backend, self.rproof_pmmr_h.size);
485485
let kernel_pmmr = ReadonlyPMMR::at(&self.kernel_pmmr_h.backend, self.kernel_pmmr_h.size);
486486

487-
TxHashSetRoots {
487+
Ok(TxHashSetRoots {
488488
output_roots: OutputRoots {
489-
pmmr_root: output_pmmr.root().expect("no root, invalid tree"),
489+
pmmr_root: output_pmmr.root().map_err(|_| Error::InvalidRoot)?,
490490
bitmap_root: self.bitmap_accumulator.root(),
491491
},
492-
rproof_root: rproof_pmmr.root().expect("no root, invalid tree"),
493-
kernel_root: kernel_pmmr.root().expect("no root, invalid tree"),
494-
}
492+
rproof_root: rproof_pmmr.root().map_err(|_| Error::InvalidRoot)?,
493+
kernel_root: kernel_pmmr.root().map_err(|_| Error::InvalidRoot)?,
494+
})
495495
}
496496

497497
/// Return Commit's MMR position

chain/tests/test_pibd_copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl DesegmenterRequestor {
238238
}
239239

240240
pub fn check_roots(&self) {
241-
let roots = self.chain.txhashset().read().roots();
241+
let roots = self.chain.txhashset().read().roots().unwrap();
242242
let archive_header = self.chain.txhashset_archive_header_header_only().unwrap();
243243
debug!("Archive Header is {:?}", archive_header);
244244
debug!("TXHashset output root is {:?}", roots);

0 commit comments

Comments
 (0)