From ae312bcb01dd7f48330fac939f8e3e636886c55b Mon Sep 17 00:00:00 2001 From: rakita Date: Tue, 22 Sep 2020 13:29:03 +0200 Subject: [PATCH] Added bad block header hash for ropsten (#49) * Added bad block header hash for ropsten --- ethcore/src/verification/queue/mod.rs | 6 +++++- ethcore/sync/src/block_sync.rs | 4 ++++ parity/run.rs | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index e15063924..4c547f5d3 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -29,6 +29,7 @@ use parking_lot::{Condvar, Mutex, RwLock}; use std::{ cmp, collections::{HashMap, HashSet, VecDeque}, + iter::FromIterator, sync::{ atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering}, Arc, @@ -85,6 +86,8 @@ pub struct VerifierSettings { pub scale_verifiers: bool, /// Beginning amount of verifiers. pub num_verifiers: usize, + /// list of block and header hashes that will marked as bad and not included into chain. + pub bad_hashes: Vec, } impl Default for VerifierSettings { @@ -92,6 +95,7 @@ impl Default for VerifierSettings { VerifierSettings { scale_verifiers: false, num_verifiers: ::num_cpus::get(), + bad_hashes: Vec::new(), } } } @@ -232,7 +236,7 @@ impl VerificationQueue { unverified: LenCachingMutex::new(VecDeque::new()), verifying: LenCachingMutex::new(VecDeque::new()), verified: LenCachingMutex::new(VecDeque::new()), - bad: Mutex::new(HashSet::new()), + bad: Mutex::new(HashSet::from_iter(config.verifier_settings.bad_hashes)), sizes: Sizes { unverified: AtomicUsize::new(0), verifying: AtomicUsize::new(0), diff --git a/ethcore/sync/src/block_sync.rs b/ethcore/sync/src/block_sync.rs index cb0def189..dc072e783 100644 --- a/ethcore/sync/src/block_sync.rs +++ b/ethcore/sync/src/block_sync.rs @@ -286,6 +286,7 @@ impl BlockDownloader { let number = BlockNumber::from(info.header.number()); let hash = info.header.hash(); + // This part checks if first header is what we expect and that all other header are chained correctly. let valid_response = match last_header { // First header must match expected hash. None => expected_hash == hash, @@ -305,6 +306,7 @@ impl BlockDownloader { return Err(BlockDownloaderImportError::Invalid); } + // If header is already included skip and go to next one in chain. last_header = Some((number, hash)); if self.blocks.contains(&hash) { trace_sync!( @@ -316,6 +318,7 @@ impl BlockDownloader { continue; } + // Check if received header is present in chain. If it is in chain include header into list that will be inserted match io.chain().block_status(BlockId::Hash(hash.clone())) { BlockStatus::InChain | BlockStatus::Queued => { match self.state { @@ -343,6 +346,7 @@ impl BlockDownloader { } } + // Set highest block that we receive from network. This is only used as stat and nothing more. if let Some((number, _)) = last_header { if self.highest_block.as_ref().map_or(true, |n| number > *n) { self.highest_block = Some(number); diff --git a/parity/run.rs b/parity/run.rs index bcd2bce69..49b552269 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -34,6 +34,7 @@ use ethcore::{ }; use ethcore_logger::{Config as LogConfig, RotatingLogger}; use ethcore_service::ClientService; +use ethereum_types::H256; use helpers::{execute_upgrades, passwords_from_files, to_client_config}; use informant::{FullNodeInformantData, Informant}; use journaldb::Algorithm; @@ -329,6 +330,7 @@ pub fn execute(cmd: RunCmd, logger: Arc) -> Result) -> Result Vec { + match *spec { + SpecType::Ropsten => { + vec!["1eac3d16c642411f13c287e29144c6f58fda859407c8f24c38deb168e1040714".into()] + } + _ => vec![], + } +} + /// Parity client currently executing in background threads. /// /// Should be destroyed by calling `shutdown()`, otherwise execution will continue in the