skip rangeproof and kernel signature verification unless we are doing a "full" chain validation (#1678)

This commit is contained in:
Antioch Peverell 2018-10-07 13:39:40 +01:00 committed by GitHub
parent 463567b19e
commit acf61db463
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View file

@ -524,7 +524,6 @@ pub struct ChainValidationHandler {
impl Handler for ChainValidationHandler {
fn get(&self, _req: Request<Body>) -> ResponseFuture {
// TODO - read skip_rproofs from query params
match w(&self.chain).validate(true) {
Ok(_) => response(StatusCode::OK, ""),
Err(e) => response(

View file

@ -462,7 +462,7 @@ impl Chain {
}
/// Validate the current chain state.
pub fn validate(&self, skip_rproofs: bool) -> Result<(), Error> {
pub fn validate(&self, fast_validation: bool) -> Result<(), Error> {
let header = self.store.head_header()?;
// Lets just treat an "empty" node that just got started up as valid.
@ -477,7 +477,7 @@ impl Chain {
// ensure the view is consistent.
txhashset::extending_readonly(&mut txhashset, |extension| {
extension.rewind(&header)?;
extension.validate(skip_rproofs, &NoStatus)?;
extension.validate(fast_validation, &NoStatus)?;
Ok(())
})
}
@ -636,6 +636,7 @@ impl Chain {
extension.rewind(&header)?;
// Validate the extension, generating the utxo_sum and kernel_sum.
// Full validation, including rangeproofs and kernel signature verification.
let (utxo_sum, kernel_sum) = extension.validate(false, status)?;
// Now that we have block_sums the total_kernel_sum on the block_header is redundant.

View file

@ -796,9 +796,10 @@ impl<'a> Extension<'a> {
}
/// Validate the txhashset state against the provided block header.
/// A "fast validation" will skip rangeproof verification and kernel signature verification.
pub fn validate(
&self,
skip_rproofs: bool,
fast_validation: bool,
status: &TxHashsetWriteStatus,
) -> Result<((Commitment, Commitment)), Error> {
self.validate_mmrs()?;
@ -814,13 +815,13 @@ impl<'a> Extension<'a> {
// sum of unspent outputs minus total supply.
let (output_sum, kernel_sum) = self.validate_kernel_sums()?;
// This is an expensive verification step.
self.verify_kernel_signatures(status)?;
// Verify the rangeproof for each output in the sum above.
// This is an expensive verification step (skip for faster verification).
if !skip_rproofs {
// These are expensive verification step (skipped for "fast validation").
if !fast_validation {
// Verify the rangeproof associated with each unspent output.
self.verify_rangeproofs(status)?;
// Verify all the kernel signatures.
self.verify_kernel_signatures(status)?;
}
Ok((output_sum, kernel_sum))