call validate_kernel_history directly from txhashset_write (#1234)

no need for thr skip_kernel_hist bool now
This commit is contained in:
Antioch Peverell 2018-07-09 19:04:17 +01:00 committed by GitHub
parent d5a6992be9
commit f33c39cb66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 16 deletions

View file

@ -425,9 +425,6 @@ impl Chain {
return Ok(()); return Ok(());
} }
// We want to validate the full kernel history here for completeness.
let skip_kernel_hist = false;
let mut txhashset = self.txhashset.write().unwrap(); let mut txhashset = self.txhashset.write().unwrap();
// Now create an extension from the txhashset and validate against the // Now create an extension from the txhashset and validate against the
@ -435,7 +432,7 @@ impl Chain {
// ensure the view is consistent. // ensure the view is consistent.
txhashset::extending_readonly(&mut txhashset, |extension| { txhashset::extending_readonly(&mut txhashset, |extension| {
extension.rewind(&header, &header)?; extension.rewind(&header, &header)?;
extension.validate(&header, skip_rproofs, skip_kernel_hist, &NoStatus)?; extension.validate(&header, skip_rproofs, &NoStatus)?;
Ok(()) Ok(())
}) })
} }
@ -546,17 +543,23 @@ impl Chain {
let mut txhashset = let mut txhashset =
txhashset::TxHashSet::open(self.db_root.clone(), self.store.clone(), Some(&header))?; txhashset::TxHashSet::open(self.db_root.clone(), self.store.clone(), Some(&header))?;
// validate against a read-only extension first (some of the validation // Validate against a read-only extension first.
// runs additional rewinds) // The kernel history validation requires a read-only extension
// due to the internal rewind behavior.
debug!(LOGGER, "chain: txhashset_write: rewinding and validating (read-only)"); debug!(LOGGER, "chain: txhashset_write: rewinding and validating (read-only)");
txhashset::extending_readonly(&mut txhashset, |extension| { txhashset::extending_readonly(&mut txhashset, |extension| {
extension.rewind(&header, &header)?; extension.rewind(&header, &header)?;
extension.validate(&header, false, false, status)?; extension.validate(&header, false, status)?;
// Now validate kernel sums at each historical header height
// so we know we can trust the kernel history.
extension.validate_kernel_history(&header)?;
Ok(()) Ok(())
})?; })?;
// all good, prepare a new batch and update all the required records // all good, prepare a new batch and update all the required records
debug!(LOGGER, "chain: txhashset_write: rewinding and validating a 2nd time (writeable)"); debug!(LOGGER, "chain: txhashset_write: rewinding a 2nd time (writeable)");
let mut batch = self.store.batch()?; let mut batch = self.store.batch()?;
txhashset::extending(&mut txhashset, &mut batch, |extension| { txhashset::extending(&mut txhashset, &mut batch, |extension| {
extension.rewind(&header, &header)?; extension.rewind(&header, &header)?;

View file

@ -869,7 +869,6 @@ impl<'a> Extension<'a> {
&mut self, &mut self,
header: &BlockHeader, header: &BlockHeader,
skip_rproofs: bool, skip_rproofs: bool,
skip_kernel_hist: bool,
status: &T, status: &T,
) -> Result<((Commitment, Commitment)), Error> ) -> Result<((Commitment, Commitment)), Error>
where where
@ -897,12 +896,6 @@ impl<'a> Extension<'a> {
self.verify_rangeproofs(status)?; self.verify_rangeproofs(status)?;
} }
// Verify kernel roots for all past headers, need to be last as it rewinds
// a lot without resetting
if !skip_kernel_hist {
self.verify_kernel_history(header)?;
}
Ok((output_sum, kernel_sum)) Ok((output_sum, kernel_sum))
} }
@ -1035,7 +1028,7 @@ impl<'a> Extension<'a> {
// header, rewind and check each root. This fixes a potential weakness in // header, rewind and check each root. This fixes a potential weakness in
// fast sync where a reorg past the horizon could allow a whole rewrite of // fast sync where a reorg past the horizon could allow a whole rewrite of
// the kernel set. // the kernel set.
fn verify_kernel_history(&mut self, header: &BlockHeader) -> Result<(), Error> { pub fn validate_kernel_history(&mut self, header: &BlockHeader) -> Result<(), Error> {
assert!(self.rollback, "verified kernel history on writeable txhashset extension"); assert!(self.rollback, "verified kernel history on writeable txhashset extension");
let mut current = header.clone(); let mut current = header.clone();