From 06359457405ad036fc2dbb49a14ebeed90a386cc Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Tue, 2 Oct 2018 16:13:02 +0100 Subject: [PATCH] cleanup verifier_cache (add it to block ctx) (#1638) rename process_block_no_orphans -> process_block_single --- chain/src/chain.rs | 9 +++++---- chain/src/pipe.rs | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index cfba4f5db..3970adbed 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -215,7 +215,7 @@ impl Chain { b: Block, opts: Options, ) -> Result<(Option, Option), Error> { - match self.process_block_no_orphans(b, opts) { + match self.process_block_single(b, opts) { Ok((t, b)) => { // We accepted a block, so see if we can accept any orphans if let Some(ref b) = b { @@ -230,7 +230,7 @@ impl Chain { /// Attempt to add a new block to the chain. Returns the new chain tip if it /// has been added to the longest chain, None if it's added to an (as of /// now) orphan chain. - pub fn process_block_no_orphans( + fn process_block_single( &self, b: Block, opts: Options, @@ -239,7 +239,7 @@ impl Chain { let bhash = b.hash(); let mut ctx = self.new_ctx(opts, &mut batch)?; - let res = pipe::process_block(&b, &mut ctx, &mut batch, self.verifier_cache.clone()); + let res = pipe::process_block(&b, &mut ctx, &mut batch); let add_to_hash_cache = || { // only add to hash cache below if block is definitively accepted @@ -365,6 +365,7 @@ impl Chain { header_head, pow_verifier: self.pow_verifier, block_hashes_cache: self.block_hashes_cache.clone(), + verifier_cache: self.verifier_cache.clone(), txhashset: self.txhashset.clone(), orphans: self.orphans.clone(), }) @@ -410,7 +411,7 @@ impl Chain { String::new() }, ); - let res = self.process_block_no_orphans(orphan.block, orphan.opts); + let res = self.process_block_single(orphan.block, orphan.opts); if let Ok((_, Some(b))) = res { orphan_accepted = true; height_accepted = b.header.height; diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index e1a6c5a29..ae6d03fff 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -53,6 +53,8 @@ pub struct BlockContext { pub txhashset: Arc>, /// Recently processed blocks to avoid double-processing pub block_hashes_cache: Arc>>, + /// The verifier cache (caching verifier for rangeproofs and kernel signatures) + pub verifier_cache: Arc>, /// Recent orphan blocks to avoid double-processing pub orphans: Arc, } @@ -70,7 +72,6 @@ pub fn process_block( b: &Block, ctx: &mut BlockContext, batch: &mut store::Batch, - verifier_cache: Arc>, ) -> Result, Error> { // TODO should just take a promise for a block with a full header so we don't // spend resources reading the full block when its header is invalid @@ -140,7 +141,7 @@ pub fn process_block( // Validate the block itself, make sure it is internally consistent. // Use the verifier_cache for verifying rangeproofs and kernel signatures. - validate_block(b, batch, verifier_cache)?; + validate_block(b, batch, ctx.verifier_cache.clone())?; // Start a chain extension unit of work dependent on the success of the // internal validation and saving operations