mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
skip rangeproof and kernel signature verification unless we are doing a "full" chain validation (#1678)
This commit is contained in:
parent
463567b19e
commit
acf61db463
3 changed files with 11 additions and 10 deletions
|
@ -524,7 +524,6 @@ pub struct ChainValidationHandler {
|
||||||
|
|
||||||
impl Handler for ChainValidationHandler {
|
impl Handler for ChainValidationHandler {
|
||||||
fn get(&self, _req: Request<Body>) -> ResponseFuture {
|
fn get(&self, _req: Request<Body>) -> ResponseFuture {
|
||||||
// TODO - read skip_rproofs from query params
|
|
||||||
match w(&self.chain).validate(true) {
|
match w(&self.chain).validate(true) {
|
||||||
Ok(_) => response(StatusCode::OK, ""),
|
Ok(_) => response(StatusCode::OK, ""),
|
||||||
Err(e) => response(
|
Err(e) => response(
|
||||||
|
|
|
@ -462,7 +462,7 @@ impl Chain {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Validate the current chain state.
|
/// 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()?;
|
let header = self.store.head_header()?;
|
||||||
|
|
||||||
// Lets just treat an "empty" node that just got started up as valid.
|
// Lets just treat an "empty" node that just got started up as valid.
|
||||||
|
@ -477,7 +477,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)?;
|
extension.rewind(&header)?;
|
||||||
extension.validate(skip_rproofs, &NoStatus)?;
|
extension.validate(fast_validation, &NoStatus)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -636,6 +636,7 @@ impl Chain {
|
||||||
extension.rewind(&header)?;
|
extension.rewind(&header)?;
|
||||||
|
|
||||||
// Validate the extension, generating the utxo_sum and kernel_sum.
|
// 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)?;
|
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.
|
// Now that we have block_sums the total_kernel_sum on the block_header is redundant.
|
||||||
|
|
|
@ -796,9 +796,10 @@ impl<'a> Extension<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Validate the txhashset state against the provided block header.
|
/// Validate the txhashset state against the provided block header.
|
||||||
|
/// A "fast validation" will skip rangeproof verification and kernel signature verification.
|
||||||
pub fn validate(
|
pub fn validate(
|
||||||
&self,
|
&self,
|
||||||
skip_rproofs: bool,
|
fast_validation: bool,
|
||||||
status: &TxHashsetWriteStatus,
|
status: &TxHashsetWriteStatus,
|
||||||
) -> Result<((Commitment, Commitment)), Error> {
|
) -> Result<((Commitment, Commitment)), Error> {
|
||||||
self.validate_mmrs()?;
|
self.validate_mmrs()?;
|
||||||
|
@ -814,13 +815,13 @@ impl<'a> Extension<'a> {
|
||||||
// sum of unspent outputs minus total supply.
|
// sum of unspent outputs minus total supply.
|
||||||
let (output_sum, kernel_sum) = self.validate_kernel_sums()?;
|
let (output_sum, kernel_sum) = self.validate_kernel_sums()?;
|
||||||
|
|
||||||
// This is an expensive verification step.
|
// These are expensive verification step (skipped for "fast validation").
|
||||||
self.verify_kernel_signatures(status)?;
|
if !fast_validation {
|
||||||
|
// Verify the rangeproof associated with each unspent output.
|
||||||
// Verify the rangeproof for each output in the sum above.
|
|
||||||
// This is an expensive verification step (skip for faster verification).
|
|
||||||
if !skip_rproofs {
|
|
||||||
self.verify_rangeproofs(status)?;
|
self.verify_rangeproofs(status)?;
|
||||||
|
|
||||||
|
// Verify all the kernel signatures.
|
||||||
|
self.verify_kernel_signatures(status)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((output_sum, kernel_sum))
|
Ok((output_sum, kernel_sum))
|
||||||
|
|
Loading…
Reference in a new issue