mirror of
https://github.com/mimblewimble/grin.git
synced 2025-05-03 07:41:14 +03:00
process_block check_known() check orphans also, to avoid double-processing (#1287)
This commit is contained in:
parent
3b6b85ec57
commit
724b19e648
2 changed files with 10 additions and 3 deletions
|
@ -52,7 +52,7 @@ struct Orphan {
|
|||
added: Instant,
|
||||
}
|
||||
|
||||
struct OrphanBlockPool {
|
||||
pub struct OrphanBlockPool {
|
||||
// blocks indexed by their hash
|
||||
orphans: RwLock<HashMap<Hash, Orphan>>,
|
||||
// additional index of height -> hash
|
||||
|
@ -117,7 +117,7 @@ impl OrphanBlockPool {
|
|||
.map(|hs| hs.iter().filter_map(|h| orphans.remove(h)).collect())
|
||||
}
|
||||
|
||||
fn contains(&self, hash: &Hash) -> bool {
|
||||
pub fn contains(&self, hash: &Hash) -> bool {
|
||||
let orphans = self.orphans.read().unwrap();
|
||||
orphans.contains_key(hash)
|
||||
}
|
||||
|
@ -336,6 +336,7 @@ impl Chain {
|
|||
pow_verifier: self.pow_verifier,
|
||||
block_hashes_cache: self.block_hashes_cache.clone(),
|
||||
txhashset: self.txhashset.clone(),
|
||||
orphans: self.orphans.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -378,7 +379,7 @@ impl Chain {
|
|||
trace!(
|
||||
LOGGER,
|
||||
"chain: done check_orphans at {}. # remaining orphans {}",
|
||||
height,
|
||||
height-1,
|
||||
self.orphans.len(),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ use error::{Error, ErrorKind};
|
|||
use grin_store;
|
||||
use store;
|
||||
use txhashset;
|
||||
use chain::{OrphanBlockPool};
|
||||
use types::{Options, Tip};
|
||||
use util::LOGGER;
|
||||
|
||||
|
@ -48,6 +49,8 @@ pub struct BlockContext {
|
|||
pub txhashset: Arc<RwLock<txhashset::TxHashSet>>,
|
||||
/// Recently processed blocks to avoid double-processing
|
||||
pub block_hashes_cache: Arc<RwLock<VecDeque<Hash>>>,
|
||||
/// Recent orphan blocks to avoid double-processing
|
||||
pub orphans: Arc<OrphanBlockPool>,
|
||||
}
|
||||
|
||||
/// Runs the block processing pipeline, including validation and finding a
|
||||
|
@ -194,6 +197,9 @@ fn check_known(bh: Hash, ctx: &mut BlockContext) -> Result<(), Error> {
|
|||
if cache.contains(&bh) {
|
||||
return Err(ErrorKind::Unfit("already known in cache".to_string()).into());
|
||||
}
|
||||
if ctx.orphans.contains(&bh) {
|
||||
return Err(ErrorKind::Unfit("already known in orphans".to_string()).into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue