Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle invalid MMR root to prevent sync thread panic #3774

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chain/src/txhashset/desegmenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chain/tests/test_pibd_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl DesegmenterRequestor {
}

pub fn check_roots(&self) {
let roots = self.chain.txhashset().read().roots();
let roots = self.chain.txhashset().read().roots().unwrap();
let archive_header = self.chain.txhashset_archive_header_header_only().unwrap();
debug!("Archive Header is {:?}", archive_header);
debug!("TXHashset output root is {:?}", roots);
Expand Down