Added bad block header hash for ropsten (#49)

* Added bad block header hash for ropsten
This commit is contained in:
rakita 2020-09-22 13:29:03 +02:00 committed by GitHub
parent d17ee979b8
commit ae312bcb01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -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<H256>,
}
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<K: Kind> VerificationQueue<K> {
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),

View File

@ -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);

View File

@ -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<RotatingLogger>) -> Result<RunningClient
);
client_config.queue.verifier_settings = cmd.verifier_settings;
client_config.queue.verifier_settings.bad_hashes = verification_bad_blocks(&cmd.spec);
client_config.transaction_verification_queue_size = ::std::cmp::max(2048, txpool_size / 4);
client_config.snapshot = cmd.snapshot_conf.clone();
@ -594,6 +596,16 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
})
}
/// Set bad blocks in VerificationQeueu. By omiting header we can omit particular fork of chain.
fn verification_bad_blocks(spec: &SpecType) -> Vec<H256> {
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