Skip to content

Commit

Permalink
fix our check_known check for blocks/headers (#2943)
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp authored Jul 11, 2019
1 parent 7434eca commit 2348214
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
1 change: 0 additions & 1 deletion chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ impl Chain {
verifier_cache: self.verifier_cache.clone(),
txhashset,
batch,
orphans: self.orphans.clone(),
})
}

Expand Down
14 changes: 1 addition & 13 deletions chain/src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

//! Implementation of the chain block acceptance (or refusal) pipeline.
use crate::chain::OrphanBlockPool;
use crate::core::consensus;
use crate::core::core::hash::Hashed;
use crate::core::core::verifier_cache::VerifierCache;
Expand Down Expand Up @@ -45,8 +44,6 @@ pub struct BlockContext<'a> {
pub batch: store::Batch<'a>,
/// The verifier cache (caching verifier for rangeproofs and kernel signatures)
pub verifier_cache: Arc<RwLock<dyn VerifierCache>>,
/// Recent orphan blocks to avoid double-processing
pub orphans: Arc<OrphanBlockPool>,
}

/// Process a block header as part of processing a full block.
Expand Down Expand Up @@ -77,7 +74,6 @@ fn process_header_for_block(
// from cheapest to most expensive (delay hitting the db until last).
fn check_known(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<(), Error> {
check_known_head(header, ctx)?;
check_known_orphans(header, ctx)?;
check_known_store(header, ctx)?;
Ok(())
}
Expand Down Expand Up @@ -261,6 +257,7 @@ pub fn process_block_header(header: &BlockHeader, ctx: &mut BlockContext<'_>) ->
); // keep this

// Check if this header is already "known" from processing a previous block.
// Note: We are looking for a full block based on this header, not just the header itself.
check_known(header, ctx)?;

validate_header(header, ctx)?;
Expand All @@ -279,15 +276,6 @@ fn check_known_head(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<
Ok(())
}

/// Check if this block is in the set of known orphans.
fn check_known_orphans(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<(), Error> {
if ctx.orphans.contains(&header.hash()) {
Err(ErrorKind::Unfit("already known in orphans".to_string()).into())
} else {
Ok(())
}
}

// Check if this block is in the store already.
fn check_known_store(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<(), Error> {
match ctx.batch.block_exists(&header.hash()) {
Expand Down

0 comments on commit 2348214

Please sign in to comment.