mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
cleanup verifier_cache (add it to block ctx) (#1638)
rename process_block_no_orphans -> process_block_single
This commit is contained in:
parent
85d5feafa3
commit
0635945740
2 changed files with 8 additions and 6 deletions
|
@ -215,7 +215,7 @@ impl Chain {
|
|||
b: Block,
|
||||
opts: Options,
|
||||
) -> Result<(Option<Tip>, Option<Block>), 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;
|
||||
|
|
|
@ -53,6 +53,8 @@ pub struct BlockContext {
|
|||
pub txhashset: Arc<RwLock<txhashset::TxHashSet>>,
|
||||
/// Recently processed blocks to avoid double-processing
|
||||
pub block_hashes_cache: Arc<RwLock<LruCache<Hash, bool>>>,
|
||||
/// The verifier cache (caching verifier for rangeproofs and kernel signatures)
|
||||
pub verifier_cache: Arc<RwLock<VerifierCache>>,
|
||||
/// Recent orphan blocks to avoid double-processing
|
||||
pub orphans: Arc<OrphanBlockPool>,
|
||||
}
|
||||
|
@ -70,7 +72,6 @@ pub fn process_block(
|
|||
b: &Block,
|
||||
ctx: &mut BlockContext,
|
||||
batch: &mut store::Batch,
|
||||
verifier_cache: Arc<RwLock<VerifierCache>>,
|
||||
) -> Result<Option<Tip>, 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
|
||||
|
|
Loading…
Reference in a new issue