From 56e2dd302303e2fc3204594a899f7c0f2fad1f09 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 17 Jul 2023 20:37:00 +0200 Subject: [PATCH 001/687] Revert "Integrating feature into dev: I40 transaction fee distribution" --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index e022cbf13..940298897 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -456,9 +456,6 @@ impl HoneyBadgerBFT { .map(|(_, c)| c.timestamp) .sorted(); - // todo: use timstamps for calculating negative score. - // https://github.com/DMDcoin/diamond-node/issues/37 - let timestamp = match timestamps.iter().nth(timestamps.len() / 2) { Some(t) => t.clone(), None => { @@ -484,19 +481,9 @@ impl HoneyBadgerBFT { .write() .insert(batch.epoch, random_number); - if let Some(mut header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) - { + if let Some(header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) { let block_num = header.number(); let hash = header.bare_hash(); - if let Some(reward_contract_address) = self.params.block_reward_contract_address { - header.set_author(reward_contract_address); - } else { - warn!( - "Creating block with no blockRewardContractAddress {}", - block_num - ); - } - trace!(target: "consensus", "Sending signature share of {} for block {}", hash, block_num); let step = match self .sealing @@ -1528,8 +1515,6 @@ impl Engine for HoneyBadgerBFT { // only if no block reward skips are defined for this block. let header_number = block.header.number(); - block.header.set_author(address); - if self .params .should_do_block_reward_contract_call(header_number) From 909d73bb2dfba37caf598e37cde90ff64512cd19 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Aug 2023 23:34:16 +0200 Subject: [PATCH 002/687] this build works on testnet, but fails in tests --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index e022cbf13..278a5ccc7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -801,7 +801,7 @@ impl HoneyBadgerBFT { let steps = match self.hbbft_state.try_write_for(Duration::from_millis(10)) { Some(mut hbbft_state_lock) => hbbft_state_lock.replay_cached_messages(client.clone()), None => { - trace!(target: "engine", "could not acquire write lock for replaying cached messages, stepping back..",); + debug!(target: "engine", "could not acquire write lock for replaying cached messages, stepping back..",); return None; } }; @@ -1438,7 +1438,7 @@ impl Engine for HoneyBadgerBFT { } fn use_block_author(&self) -> bool { - false + true } fn on_before_transactions(&self, block: &mut ExecutedBlock) -> Result<(), Error> { @@ -1506,7 +1506,7 @@ impl Engine for HoneyBadgerBFT { /// Allow mutating the header during seal generation. fn on_seal_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> { - let random_numbers = self.random_numbers.read(); + let random_numbers = self.random_numbers.read(); match random_numbers.get(&block.header.number()) { None => { warn!("No rng value available for header."); From 92884a07ecf494e8e5f20df65aafed6153f6673c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Aug 2023 22:05:33 +0200 Subject: [PATCH 003/687] cli parsing for metrics_port --- .../hbbft/hbbft_config_generator/src/main.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 03862f7b2..47025529e 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -109,6 +109,7 @@ fn to_toml( signer_address: &Address, total_num_of_nodes: usize, tx_queue_per_sender: Option, + metrics_port: Option, ) -> Value { let base_port = 30300i64; let base_rpc_port = 8540i64; @@ -243,6 +244,8 @@ fn to_toml( ); misc.insert("log_file".into(), Value::String("parity.log".into())); + // metrics.insert(""); + let mut map = Map::new(); map.insert("parity".into(), Value::Table(parity)); map.insert("network".into(), Value::Table(network)); @@ -253,6 +256,13 @@ fn to_toml( map.insert("account".into(), Value::Table(account)); map.insert("mining".into(), Value::Table(mining)); map.insert("misc".into(), Value::Table(misc)); + + if let Some(port) = metrics_port { + let mut metrics = Map::new(); + + map.insert("metrics".into(), Value::Table(metrics)); + } + Value::Table(map) } @@ -323,6 +333,12 @@ fn main() { .required(false) .takes_value(true), ) + .arg( + Arg::with_name("metrics_port") + .long("metrics_port") + .required(false) + .takes_value(true), + ) .get_matches(); let num_nodes_validators: usize = matches @@ -345,6 +361,13 @@ fn main() { ) }); + let metrics_port: Option = matches.value_of("metrics_port").map_or(None, |v| { + Some( + v.parse::() + .expect("metrics_port need to be an integer port definition 1-65555"), + ) + }); + assert!( num_nodes_total >= num_nodes_validators, "max_nodes must be greater than nodes" @@ -405,6 +428,7 @@ fn main() { &enode.address, num_nodes_total, tx_queue_per_sender.clone(), + metrics_port, )) .expect("TOML string generation should succeed"); fs::write(file_name, toml_string).expect("Unable to write config file"); @@ -435,6 +459,7 @@ fn main() { &Address::default(), // todo: insert HBBFT Contracts pot here. num_nodes_total, tx_queue_per_sender.clone(), + metrics_port )) .expect("TOML string generation should succeed"); fs::write("rpc_node.toml", rpc_string).expect("Unable to write rpc config file"); From 96dbda158b98e95ec4d683abe3532f411a7697bb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 26 Aug 2023 01:44:28 +0200 Subject: [PATCH 004/687] included metrics_interface into hbbft_config_generator --- .../hbbft/hbbft_config_generator/src/main.rs | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 47025529e..c867699c8 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -109,7 +109,8 @@ fn to_toml( signer_address: &Address, total_num_of_nodes: usize, tx_queue_per_sender: Option, - metrics_port: Option, + base_metrics_port: Option, + metrics_interface: Option<&str>, ) -> Value { let base_port = 30300i64; let base_rpc_port = 8540i64; @@ -257,9 +258,27 @@ fn to_toml( map.insert("mining".into(), Value::Table(mining)); map.insert("misc".into(), Value::Table(misc)); - if let Some(port) = metrics_port { + if let Some(port_base) = base_metrics_port { let mut metrics = Map::new(); + let port = (port_base as usize) + i; + + // metrics.insert("interface".into(), Value::String("local".into())); + // Metrics: + // --metrics + // Enable prometheus metrics (only full client). + + // --metrics-port=[PORT] + // Specify the port portion of the metrics server. (default: 3000) + + // --metrics-interface=[IP] + // Specify the hostname portion of the metrics server, IP should be an interface's IP address, or all (all + // interfaces) or local. (default: local) + + if let Some(metrics_interface_) = metrics_interface { + metrics.insert("interface".into(), Value::String(metrics_interface_.into())); + } + map.insert("metrics".into(), Value::Table(metrics)); } @@ -334,8 +353,16 @@ fn main() { .takes_value(true), ) .arg( - Arg::with_name("metrics_port") + Arg::with_name("metrics_port_base") .long("metrics_port") + .help("activates prometheus metrics. The port is the base port, the node index is added to it.") + .required(false) + .takes_value(true), + ) + .arg( + Arg::with_name("metrics_interface") + .long("metrics_interface") + .help("internet interface of metrics. 'all', 'local' or ip address.") .required(false) .takes_value(true), ) @@ -361,13 +388,15 @@ fn main() { ) }); - let metrics_port: Option = matches.value_of("metrics_port").map_or(None, |v| { + let metrics_port_base: Option = matches.value_of("metrics_port").map_or(None, |v| { Some( v.parse::() .expect("metrics_port need to be an integer port definition 1-65555"), ) }); + let metrics_interface = matches.value_of("metrics_interface"); + assert!( num_nodes_total >= num_nodes_validators, "max_nodes must be greater than nodes" @@ -428,7 +457,8 @@ fn main() { &enode.address, num_nodes_total, tx_queue_per_sender.clone(), - metrics_port, + metrics_port_base, + metrics_interface, )) .expect("TOML string generation should succeed"); fs::write(file_name, toml_string).expect("Unable to write config file"); @@ -459,7 +489,8 @@ fn main() { &Address::default(), // todo: insert HBBFT Contracts pot here. num_nodes_total, tx_queue_per_sender.clone(), - metrics_port + metrics_port_base, + metrics_interface, )) .expect("TOML string generation should succeed"); fs::write("rpc_node.toml", rpc_string).expect("Unable to write rpc config file"); From 684b5e7b1843e8718de2d720bede2b99c2d4ef58 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Aug 2023 11:50:18 +0200 Subject: [PATCH 005/687] metrics fix: it is "enable" to enable not "enabled". --- .../hbbft/hbbft_config_generator/src/main.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index c867699c8..a9e9e0635 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -46,7 +46,7 @@ impl ToString for Enode { fn to_string(&self) -> String { // Example: // enode://30ccdeb8c31972f570e4eea0673cd08cbe7cefc5de1d70119b39c63b1cba33b48e494e9916c0d1eab7d296774f3573da46025d1accdef2f3690bc9e6659a34b4@192.168.0.101:30300 - let port = 30300usize + self.idx; + let port = 31300usize + self.idx; format!("enode://{:x}@{}:{}", self.public, self.ip, port) } } @@ -112,9 +112,9 @@ fn to_toml( base_metrics_port: Option, metrics_interface: Option<&str>, ) -> Value { - let base_port = 30300i64; - let base_rpc_port = 8540i64; - let base_ws_port = 9540i64; + let base_port = 31300i64; + let base_rpc_port = 18540i64; + let base_ws_port = 19540i64; let mut parity = Map::new(); match config_type { @@ -263,6 +263,10 @@ fn to_toml( let port = (port_base as usize) + i; + metrics.insert("enable".into(), Value::Boolean(true)); + + metrics.insert("port".into(), Value::Integer(port as i64)); + // metrics.insert("interface".into(), Value::String("local".into())); // Metrics: // --metrics @@ -354,7 +358,7 @@ fn main() { ) .arg( Arg::with_name("metrics_port_base") - .long("metrics_port") + .long("metrics_port_base") .help("activates prometheus metrics. The port is the base port, the node index is added to it.") .required(false) .takes_value(true), @@ -388,13 +392,15 @@ fn main() { ) }); - let metrics_port_base: Option = matches.value_of("metrics_port").map_or(None, |v| { + let metrics_port_base: Option = matches.value_of("metrics_port_base").map_or(None, |v| { Some( v.parse::() .expect("metrics_port need to be an integer port definition 1-65555"), ) }); + std::println!("metrics_port_base: {:?}", metrics_port_base); + let metrics_interface = matches.value_of("metrics_interface"); assert!( From f3c579650f9a8f696b2f29d2ce71e6b9481785b0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Sep 2023 13:49:29 +0200 Subject: [PATCH 006/687] experimental fix for prometheus metrics problem. formatting labels with a smaller 9 character annotation (n + 8 first hex digits of public key) --- crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index e6930c874..b914d09a2 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -981,7 +981,12 @@ impl PrometheusMetrics for NodeStakingEpochHistory { //let metric: Metric = Metric::new(); //r.registry().register(c) - let label = self.get_node_id().0.to_hex(); + //let label = self.get_node_id().0.to_hex(); + + let node_id = self.get_node_id().0.0; + + let label = std::format!("n{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", node_id[0], node_id[1], node_id[2], node_id[3], node_id[4], node_id[5], node_id[6], node_id[7]); + //r.register_gauge_with_label(name, help, label, value) r.register_gauge_with_label( format!("cumulative_lateness").as_str(), From 2bfa17cf6170c20335174d771b5face3a9f569f2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Sep 2023 14:27:29 +0200 Subject: [PATCH 007/687] patch upgrade of prometheus --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 160630d61..5049ed1ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,7 @@ kvdb = "0.1" kvdb-rocksdb = "0.1.3" journaldb = { path = "crates/db/journaldb" } stats = { path = "crates/util/stats" } -prometheus = "0.13.0" +prometheus = "0.13.3" fs-swap = "0.2.6" net2 = "0.2.38" From bef2f82eacc53039ff13067709561259aaf5a76b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Sep 2023 16:14:49 +0200 Subject: [PATCH 008/687] experimental fix for InconsistentCardinality --- crates/util/stats/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/util/stats/src/lib.rs b/crates/util/stats/src/lib.rs index dbbaf2a7c..8a6ab6aef 100644 --- a/crates/util/stats/src/lib.rs +++ b/crates/util/stats/src/lib.rs @@ -79,10 +79,10 @@ impl PrometheusRegistry { // add labels here . opts.variable_labels.push(label.to_string()); - match prometheus::IntGauge::with_opts(opts) { + + match prometheus::register_int_gauge_with_registry!(opts, self.registry) { Ok(g) => { g.set(value); - self.registry .register(Box::new(g)) .expect("prometheus identifiers must be are unique"); From dbaf056585ac678d01630614ef9e9059fb34c5bd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Sep 2023 19:21:44 +0200 Subject: [PATCH 009/687] Revert "experimental fix for InconsistentCardinality" This reverts commit bef2f82eacc53039ff13067709561259aaf5a76b. --- crates/util/stats/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/util/stats/src/lib.rs b/crates/util/stats/src/lib.rs index 8a6ab6aef..dbbaf2a7c 100644 --- a/crates/util/stats/src/lib.rs +++ b/crates/util/stats/src/lib.rs @@ -79,10 +79,10 @@ impl PrometheusRegistry { // add labels here . opts.variable_labels.push(label.to_string()); - - match prometheus::register_int_gauge_with_registry!(opts, self.registry) { + match prometheus::IntGauge::with_opts(opts) { Ok(g) => { g.set(value); + self.registry .register(Box::new(g)) .expect("prometheus identifiers must be are unique"); From 4f8543e9523abbf98380145678637557cdb105fb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 7 Sep 2023 11:33:05 +0200 Subject: [PATCH 010/687] using combined gauge names again, was not woking with labels --- crates/util/stats/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/util/stats/src/lib.rs b/crates/util/stats/src/lib.rs index dbbaf2a7c..838c7f5e5 100644 --- a/crates/util/stats/src/lib.rs +++ b/crates/util/stats/src/lib.rs @@ -72,12 +72,12 @@ impl PrometheusRegistry { /// Adds a new prometheus gauge with a label pub fn register_gauge_with_label(&mut self, name: &str, help: &str, label: &str, value: i64) { - //let label_formated = format!("{}", label); - let name_formatted = format!("{}{}", self.prefix, name); - let mut opts = prometheus::Opts::new(name_formatted, help); + let label_formated = format!("{}{}",name, label); + // let label_formated = format!("{}{}", self.prefix, name); + let opts = prometheus::Opts::new(label_formated, help); // add labels here . - opts.variable_labels.push(label.to_string()); + //&&opts.variable_labels.push(label.to_string()); match prometheus::IntGauge::with_opts(opts) { Ok(g) => { From 47e6e8f112bea21989d422a37d0db518092174b1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 7 Sep 2023 18:15:52 +0200 Subject: [PATCH 011/687] cargo fmt --all -- --config imports_granularity=Crate --- .../hbbft/hbbft_config_generator/src/main.rs | 2 +- .../src/engines/hbbft/hbbft_message_memorium.rs | 16 +++++++++++++--- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 9 ++++++--- crates/util/stats/src/lib.rs | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index a9e9e0635..cd7e94bea 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -496,7 +496,7 @@ fn main() { num_nodes_total, tx_queue_per_sender.clone(), metrics_port_base, - metrics_interface, + metrics_interface, )) .expect("TOML string generation should succeed"); fs::write("rpc_node.toml", rpc_string).expect("Unable to write rpc config file"); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index b914d09a2..f981aec34 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -983,9 +983,19 @@ impl PrometheusMetrics for NodeStakingEpochHistory { //let label = self.get_node_id().0.to_hex(); - let node_id = self.get_node_id().0.0; - - let label = std::format!("n{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", node_id[0], node_id[1], node_id[2], node_id[3], node_id[4], node_id[5], node_id[6], node_id[7]); + let node_id = self.get_node_id().0 .0; + + let label = std::format!( + "n{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", + node_id[0], + node_id[1], + node_id[2], + node_id[3], + node_id[4], + node_id[5], + node_id[6], + node_id[7] + ); //r.register_gauge_with_label(name, help, label, value) r.register_gauge_with_label( diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 517122bf8..83a4c5112 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -116,13 +116,16 @@ impl HbbftState { // apply DAO updates here. // update the current minimum gas price. - match get_minimum_gas_from_permission_contract(client.as_ref(), BlockId::Number(self.current_posdao_epoch_start_block)) { + match get_minimum_gas_from_permission_contract( + client.as_ref(), + BlockId::Number(self.current_posdao_epoch_start_block), + ) { Ok(min_gas) => { *current_minimum_gas_price.lock() = Some(min_gas); - }, + } Err(err) => { warn!(target: "engine", "Could not read min gas from hbbft permission contract. {:?}.", err); - }, + } } if sks.is_none() { diff --git a/crates/util/stats/src/lib.rs b/crates/util/stats/src/lib.rs index 838c7f5e5..00ba2c4ae 100644 --- a/crates/util/stats/src/lib.rs +++ b/crates/util/stats/src/lib.rs @@ -72,7 +72,7 @@ impl PrometheusRegistry { /// Adds a new prometheus gauge with a label pub fn register_gauge_with_label(&mut self, name: &str, help: &str, label: &str, value: i64) { - let label_formated = format!("{}{}",name, label); + let label_formated = format!("{}{}", name, label); // let label_formated = format!("{}{}", self.prefix, name); let opts = prometheus::Opts::new(label_formated, help); From b12e886f200bdb1e825db215a18fc8bb16ee32db Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 7 Sep 2023 18:22:53 +0200 Subject: [PATCH 012/687] version upgrade to 4.0.0 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e258a34c1..5ff71d575 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -806,7 +806,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.8.9" +version = "4.0.0" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3548,7 +3548,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.8.9" +version = "4.0.0" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 160630d61..7a83633a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.8.9" +version = "4.0.0" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 745282b49..772e5e965 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.8.9" +version = "4.0.0" authors = ["Parity Technologies "] build = "build.rs" From 823704be48e3a6ccec285f445c137b4aff789fd1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 7 Sep 2023 18:27:53 +0200 Subject: [PATCH 013/687] setting version to 3.3.5-hbbft-0.9.0 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ff71d575..ecb291db4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -806,7 +806,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "4.0.0" +version = "3.3.5-hbbft-0.9.0" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3548,7 +3548,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "4.0.0" +version = "3.3.5-hbbft-0.9.0" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 7a83633a4..9ecf0e178 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "4.0.0" +version = "3.3.5-hbbft-0.9.0" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 772e5e965..885128cd9 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "4.0.0" +version = "3.3.5-hbbft-0.9.0" authors = ["Parity Technologies "] build = "build.rs" From 646c503adeb2fde5ecb183d5b415cf452d763cc8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 7 Sep 2023 18:40:09 +0200 Subject: [PATCH 014/687] cargo fmt --all -- --config imports_granularity=Crate --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index a9e9e0635..cd7e94bea 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -496,7 +496,7 @@ fn main() { num_nodes_total, tx_queue_per_sender.clone(), metrics_port_base, - metrics_interface, + metrics_interface, )) .expect("TOML string generation should succeed"); fs::write("rpc_node.toml", rpc_string).expect("Unable to write rpc config file"); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 517122bf8..83a4c5112 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -116,13 +116,16 @@ impl HbbftState { // apply DAO updates here. // update the current minimum gas price. - match get_minimum_gas_from_permission_contract(client.as_ref(), BlockId::Number(self.current_posdao_epoch_start_block)) { + match get_minimum_gas_from_permission_contract( + client.as_ref(), + BlockId::Number(self.current_posdao_epoch_start_block), + ) { Ok(min_gas) => { *current_minimum_gas_price.lock() = Some(min_gas); - }, + } Err(err) => { warn!(target: "engine", "Could not read min gas from hbbft permission contract. {:?}.", err); - }, + } } if sks.is_none() { From 177385f0f17ea4949c73b1d7e86236505b583ec6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Sep 2023 15:57:44 +0200 Subject: [PATCH 015/687] introduced new concept: Shutdown Manager allows engines to request a controlled shutdown. The ExitStatus was moved from oe to ethcore, so it can be accessed by engines. --- bin/oe/blockchain.rs | 7 +++ bin/oe/lib.rs | 17 ++++-- bin/oe/main.rs | 43 +++++--------- bin/oe/run.rs | 8 ++- bin/oe/snapshot.rs | 2 + crates/ethcore/service/src/service.rs | 3 + crates/ethcore/src/client/client.rs | 6 ++ crates/ethcore/src/exit.rs | 81 +++++++++++++++++++++++++++ crates/ethcore/src/lib.rs | 1 + 9 files changed, 134 insertions(+), 34 deletions(-) create mode 100644 crates/ethcore/src/exit.rs diff --git a/bin/oe/blockchain.rs b/bin/oe/blockchain.rs index d7f585758..3a105145d 100644 --- a/bin/oe/blockchain.rs +++ b/bin/oe/blockchain.rs @@ -34,6 +34,7 @@ use ethcore::{ Balance, BlockChainClient, BlockChainReset, BlockId, DatabaseCompactionProfile, ImportExportBlocks, Mode, Nonce, VMType, }, + exit::ShutdownManager, miner::Miner, verification::queue::VerifierSettings, }; @@ -212,6 +213,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> { // TODO [ToDr] don't use test miner here // (actually don't require miner at all) Arc::new(Miner::new_for_tests(&spec, None)), + ShutdownManager::null(), ) .map_err(|e| format!("Client service error: {:?}", e))?; @@ -277,6 +279,7 @@ fn start_client( cache_config: CacheConfig, require_fat_db: bool, max_round_blocks_to_import: usize, + shutdown: ShutdownManager, ) -> Result { // load spec file let spec = spec.spec(&dirs.cache)?; @@ -347,6 +350,7 @@ fn start_client( // It's fine to use test version here, // since we don't care about miner parameters at all Arc::new(Miner::new_for_tests(&spec, None)), + shutdown, ) .map_err(|e| format!("Client service error: {:?}", e))?; @@ -367,6 +371,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result<(), String> { cmd.cache_config, false, cmd.max_round_blocks_to_import, + ShutdownManager::null(), )?; let client = service.client(); @@ -396,6 +401,7 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> { cmd.cache_config, true, cmd.max_round_blocks_to_import, + ShutdownManager::null(), )?; let client = service.client(); @@ -514,6 +520,7 @@ fn execute_reset(cmd: ResetBlockchain) -> Result<(), String> { cmd.cache_config, false, 0, + ShutdownManager::null(), )?; let client = service.client(); diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index 7202dc0df..65f5388a6 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -127,6 +127,7 @@ use crate::{ use std::alloc::System; pub use self::{configuration::Configuration, run::RunningClient}; +pub use ethcore::exit::ShutdownManager; pub use ethcore_logger::{setup_log, Config as LoggerConfig, RotatingLogger}; pub use parity_rpc::PubSubSession; @@ -199,13 +200,17 @@ pub enum ExecutionAction { Running(RunningClient), } -fn execute(command: Execute, logger: Arc) -> Result { +fn execute( + command: Execute, + logger: Arc, + shutdown: ShutdownManager, +) -> Result { #[cfg(feature = "deadlock_detection")] run_deadlock_detection_thread(); match command.cmd { Cmd::Run(run_cmd) => { - let outcome = run::execute(run_cmd, logger)?; + let outcome = run::execute(run_cmd, logger, shutdown)?; Ok(ExecutionAction::Running(outcome)) } Cmd::Version => Ok(ExecutionAction::Instant(Some(Args::print_version()))), @@ -250,6 +255,10 @@ fn execute(command: Execute, logger: Arc) -> Result) -> Result { - execute(conf.into_command()?, logger) +pub fn start( + conf: Configuration, + logger: Arc, + shutdown: ShutdownManager, +) -> Result { + execute(conf.into_command()?, logger, shutdown) } diff --git a/bin/oe/main.rs b/bin/oe/main.rs index e9317e9ba..f24557441 100644 --- a/bin/oe/main.rs +++ b/bin/oe/main.rs @@ -33,9 +33,11 @@ extern crate ethcore_logger; #[cfg(windows)] extern crate winapi; +extern crate ethcore; + use std::{ io::Write, - process, + process::{self}, sync::{ atomic::{AtomicBool, Ordering}, Arc, @@ -43,21 +45,13 @@ use std::{ }; use ansi_term::Colour; -use diamond_node::{start, ExecutionAction}; +use diamond_node::{start, ExecutionAction, ShutdownManager}; +use ethcore::exit::ExitStatus; use ethcore_logger::setup_log; use fdlimit::raise_fd_limit; use parity_daemonize::AsHandle; use parking_lot::{Condvar, Mutex}; -#[derive(Debug)] -/// Status used to exit or restart the program. -struct ExitStatus { - /// Whether the program panicked. - panicking: bool, - /// Whether the program should exit. - should_exit: bool, -} - fn main() -> Result<(), i32> { let conf = { let args = std::env::args().collect::>(); @@ -92,20 +86,17 @@ fn main() -> Result<(), i32> { // increase max number of open files raise_fd_limit(); - let exit = Arc::new(( - Mutex::new(ExitStatus { - panicking: false, - should_exit: false, - }), - Condvar::new(), - )); + //let lockMutex = + + let exit = Arc::new((Mutex::new(ExitStatus::new()), Condvar::new())); // Double panic can happen. So when we lock `ExitStatus` after the main thread is notified, it cannot be locked // again. let exiting = Arc::new(AtomicBool::new(false)); trace!(target: "mode", "Not hypervised: not setting exit handlers."); - let exec = start(conf, logger); + let shutdown = ShutdownManager::new(&exit); + let exec = start(conf, logger, shutdown); match exec { Ok(result) => match result { @@ -122,10 +113,7 @@ fn main() -> Result<(), i32> { warn!("Panic occured, see stderr for details"); eprintln!("{}", panic_msg); if !exiting.swap(true, Ordering::SeqCst) { - *e.0.lock() = ExitStatus { - panicking: true, - should_exit: true, - }; + *e.0.lock() = ExitStatus::new_panicking(); e.1.notify_all(); } } @@ -136,10 +124,7 @@ fn main() -> Result<(), i32> { let exiting = exiting.clone(); move || { if !exiting.swap(true, Ordering::SeqCst) { - *e.0.lock() = ExitStatus { - panicking: false, - should_exit: true, - }; + *e.0.lock() = ExitStatus::new_should_exit(); e.1.notify_all(); } } @@ -160,13 +145,13 @@ fn main() -> Result<(), i32> { // Wait for signal let mut lock = exit.0.lock(); - if !lock.should_exit { + if !lock.should_exit() { let _ = exit.1.wait(&mut lock); } client.shutdown(); - if lock.panicking { + if lock.is_panicking() { return Err(1); } } diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 23bc9817a..267862eb9 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -46,6 +46,7 @@ use ethcore::{ client::{ BlockChainClient, BlockInfo, ChainSyncing, Client, DatabaseCompactionProfile, Mode, VMType, }, + exit::ShutdownManager, miner::{self, stratum, Miner, MinerOptions, MinerService}, snapshot::{self, SnapshotConfiguration}, verification::queue::VerifierSettings, @@ -163,7 +164,11 @@ impl ChainSyncing for SyncProviderWrapper { /// Executes the given run command. /// /// On error, returns what to print on stderr. -pub fn execute(cmd: RunCmd, logger: Arc) -> Result { +pub fn execute( + cmd: RunCmd, + logger: Arc, + shutdown: ShutdownManager, +) -> Result { // load spec let spec = cmd.spec.spec(&cmd.dirs.cache)?; @@ -378,6 +383,7 @@ pub fn execute(cmd: RunCmd, logger: Arc) -> Result, _ipc_path: &Path, miner: Arc, + shutdown: ShutdownManager, ) -> Result { let io_service = IoService::::start("Client")?; @@ -71,6 +73,7 @@ impl ClientService { blockchain_db.clone(), miner.clone(), io_service.channel(), + shutdown, )?; miner.set_io_channel(io_service.channel()); miner.set_in_chain_checker(&client.clone()); diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index b3ce271c4..2b5860153 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -107,6 +107,8 @@ use db::{keys::BlockDetails, Readable, Writable}; pub use reth_util::queue::ExecutionQueue; pub use types::{block_status::BlockStatus, blockchain_info::BlockChainInfo}; pub use verification::QueueInfo as BlockQueueInfo; + +use crate::exit::ShutdownManager; use_contract!(registry, "res/contracts/registrar.json"); const ANCIENT_BLOCKS_QUEUE_SIZE: usize = 4096; @@ -260,6 +262,8 @@ pub struct Client { reserved_peers_management: Mutex>>, importer: Importer, + + shutdown: ShutdownManager, } impl Importer { @@ -946,6 +950,7 @@ impl Client { db: Arc, miner: Arc, message_channel: IoChannel, + shutdown: ShutdownManager, ) -> Result, ::error::Error> { let trie_spec = match config.fat_db { true => TrieSpec::Fat, @@ -1054,6 +1059,7 @@ impl Client { reserved_peers_management: Mutex::new(None), importer, config, + shutdown, }); let exec_client = client.clone(); diff --git a/crates/ethcore/src/exit.rs b/crates/ethcore/src/exit.rs new file mode 100644 index 000000000..02131245b --- /dev/null +++ b/crates/ethcore/src/exit.rs @@ -0,0 +1,81 @@ +use std::sync::Arc; + +use parking_lot::{Condvar, Mutex}; + +#[derive(Debug)] +/// Status used to exit or restart the program. +pub struct ExitStatus { + /// Whether the program panicked. + panicking: bool, + /// Whether the program should exit. + should_exit: bool, +} + +impl ExitStatus { + pub fn new() -> Self { + ExitStatus { + panicking: false, + should_exit: false, + } + } + + pub fn new_panicking() -> Self { + ExitStatus { + panicking: true, + should_exit: true, + } + } + + pub fn new_should_exit() -> Self { + ExitStatus { + panicking: false, + should_exit: true, + } + } + + /// Signals the overlaying system to perform a shutdown. + pub fn do_shutdown(self: &mut Self) { + self.should_exit = true; + } + + pub fn should_exit(self: &Self) -> bool { + return self.should_exit; + } + + pub fn is_panicking(self: &Self) -> bool { + return self.panicking; + } +} + +/// Shutdown Manager allows engines to signal the system to shutdown. +pub struct ShutdownManager { + exit_mutex: Arc<(Mutex, Condvar)>, +} + +impl ShutdownManager { + /// get's a Null Object that does not interact with the system at all. + pub fn null() -> Self { + return ShutdownManager { + exit_mutex: Arc::new(( + Mutex::new(ExitStatus { + panicking: false, + should_exit: false, + }), + Condvar::new(), + )), + }; + } + + pub fn new(mutex_original: &Arc<(Mutex, Condvar)>) -> Self { + return ShutdownManager { + exit_mutex: mutex_original.clone(), + }; + } + + pub fn demand_shutdown(self: &Self) { + todo!(); + //self.exit_mutex.lock().do_shutdown(); + //exit_mutex. + // e.1.notify_all(); + } +} diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index e499cd87e..4b2229c9e 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -123,6 +123,7 @@ pub mod error; pub mod ethereum; pub mod executed; pub mod executive; +pub mod exit; pub mod machine; pub mod miner; pub mod pod_account; From f32c2a7c081247cf20475e2e21a4e5a4c60c18d3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 16 Sep 2023 20:05:16 +0200 Subject: [PATCH 016/687] demanding shutdown now in a much smoother way --- crates/ethcore/src/client/client.rs | 4 ++++ crates/ethcore/src/client/traits.rs | 3 +++ .../ethcore/src/engines/hbbft/hbbft_engine.rs | 19 ++++++++++++------- crates/ethcore/src/exit.rs | 7 +++---- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 2b5860153..8a06381bb 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -3229,6 +3229,10 @@ impl super::traits::EngineClient for Client { self.importer.miner.queued_transactions(self) } + fn demand_shutdown(&self) { + self.shutdown.demand_shutdown(); + } + fn create_pending_block_at( &self, txns: Vec, diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 10a75eadd..84acdb603 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -666,6 +666,9 @@ pub trait EngineClient: Sync + Send + ChainInfo { /// Get raw block header data by block id. fn block_header(&self, id: BlockId) -> Option; + /// demand a shutdown out of the nodesoftware. + fn demand_shutdown(&self); + /// Get currently pending transactions fn queued_transactions(&self) -> Vec>; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 940298897..70cc47fe9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -299,15 +299,20 @@ impl IoHandler<()> for TransitionHandler { // info!(target: "engine", "Signal result: {signal_result}"); // } - let child = Command::new("/bin/kill") - .arg(id.to_string()) - .spawn() - .expect("failed to execute child"); + //let child = Command::new("/bin/kill") + // .arg(id.to_string()) + // .spawn() + // .expect("failed to execute child"); - let kill_id = child.id(); - info!(target: "engine", "Signaling shutdown SENT to process ID: {id} with process: {kill_id} "); + //let kill_id = child.id(); + //info!(target: "engine", "Signaling shutdown SENT to process ID: {id} with process: {kill_id} "); + + if let Some(ref weak) = *self.client.read() { + if let Some(client) = weak.upgrade() { + client.demand_shutdown(); + } + } - // if let Some(ref weak) = *self.client.read() { // if let Some(client) = weak.upgrade() { // match client.as_full_client() { diff --git a/crates/ethcore/src/exit.rs b/crates/ethcore/src/exit.rs index 02131245b..042f81fff 100644 --- a/crates/ethcore/src/exit.rs +++ b/crates/ethcore/src/exit.rs @@ -73,9 +73,8 @@ impl ShutdownManager { } pub fn demand_shutdown(self: &Self) { - todo!(); - //self.exit_mutex.lock().do_shutdown(); - //exit_mutex. - // e.1.notify_all(); + + self.exit_mutex.0.lock().do_shutdown(); + self.exit_mutex.1.notify_all(); } } From 63f540d5d2294853f2e3955d7b34c3d4f8ada7b6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 16 Sep 2023 21:31:59 +0200 Subject: [PATCH 017/687] fixed missing comments --- crates/ethcore/src/exit.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/ethcore/src/exit.rs b/crates/ethcore/src/exit.rs index 042f81fff..c156bebcc 100644 --- a/crates/ethcore/src/exit.rs +++ b/crates/ethcore/src/exit.rs @@ -12,6 +12,8 @@ pub struct ExitStatus { } impl ExitStatus { + + /// new not panicking pub fn new() -> Self { ExitStatus { panicking: false, @@ -19,6 +21,7 @@ impl ExitStatus { } } + /// new one that panics pub fn new_panicking() -> Self { ExitStatus { panicking: true, @@ -26,6 +29,7 @@ impl ExitStatus { } } + /// regular exit wihout panic pub fn new_should_exit() -> Self { ExitStatus { panicking: false, @@ -38,10 +42,12 @@ impl ExitStatus { self.should_exit = true; } + /// has someone requested a shutdown? pub fn should_exit(self: &Self) -> bool { return self.should_exit; } + /// has someone requested a panic? pub fn is_panicking(self: &Self) -> bool { return self.panicking; } @@ -66,12 +72,14 @@ impl ShutdownManager { }; } + /// creates a new shutdown manager, use ::null() if you do not wish to provide a mutex. pub fn new(mutex_original: &Arc<(Mutex, Condvar)>) -> Self { return ShutdownManager { exit_mutex: mutex_original.clone(), }; } + /// demands a shutdown of the node software pub fn demand_shutdown(self: &Self) { self.exit_mutex.0.lock().do_shutdown(); From 6f91da7bacd40c842dc952b2462cc2bd32be9063 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 16 Sep 2023 21:32:27 +0200 Subject: [PATCH 018/687] ShutdownManager for testhelpers --- crates/ethcore/src/test_helpers.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index ff75b0979..00d956591 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -56,6 +56,8 @@ use state::*; use state_db::StateDB; use verification::queue::kind::blocks::Unverified; +use crate::exit::ShutdownManager; + /// Creates test block with corresponding header pub fn create_test_block(header: &Header) -> Bytes { let mut rlp = RlpStream::new_list(3); @@ -164,6 +166,7 @@ where client_db, Arc::new(miner), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let test_engine = &*test_spec.engine; @@ -370,6 +373,7 @@ pub fn get_test_client_with_blocks(blocks: Vec) -> Arc { client_db, Arc::new(Miner::new_for_tests(&test_spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); From 773338fd5c4cf17724dd8fb7613de71d62510179 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 16 Sep 2023 21:32:43 +0200 Subject: [PATCH 019/687] testclient an json tests --- crates/ethcore/src/client/test_client.rs | 4 ++++ crates/ethcore/src/json_tests/chain.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index b1d151721..929e2091b 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -1241,6 +1241,10 @@ impl super::traits::EngineClient for TestBlockChainClient { self.miner .create_pending_block_at(self, txns, timestamp, block_number) } + + fn demand_shutdown(&self) { + + } } impl PrometheusMetrics for TestBlockChainClient { diff --git a/crates/ethcore/src/json_tests/chain.rs b/crates/ethcore/src/json_tests/chain.rs index cd1c93941..f4501d26c 100644 --- a/crates/ethcore/src/json_tests/chain.rs +++ b/crates/ethcore/src/json_tests/chain.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::exit::ShutdownManager; + use super::HookType; use client::{ Balance, BlockChainClient, BlockId, ChainInfo, Client, ClientConfig, EvmTestClient, @@ -199,6 +201,7 @@ pub fn json_chain_test( db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .expect("Failed to instantiate a new Client"); From 86274e222ef9e2d3b4e88b2790578f6be6201fa7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Sep 2023 12:18:15 +0200 Subject: [PATCH 020/687] improved logging of synckeygen errors --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 83a4c5112..36a5490fd 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -478,7 +478,8 @@ impl HbbftState { ) { Ok(synckeygen) => synckeygen, Err(e) => { - error!(target: "consensus", "Synckeygen failed with error: {:?}", e); + let diff = parent_block_nr - posdao_epoch_start.low_u64(); + error!(target: "consensus", "Synckeygen failed. parent block: {} epoch_start: {} diff {} with error: {:?} ", parent_block_nr, posdao_epoch_start, diff, e); return false; } }; From 5829e3efcab4a24d6c7f07dbbfa793ed331d12a6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Sep 2023 12:18:26 +0200 Subject: [PATCH 021/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/client/test_client.rs | 4 +--- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- crates/ethcore/src/exit.rs | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index 755c9106e..1cf8e308f 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -1248,9 +1248,7 @@ impl super::traits::EngineClient for TestBlockChainClient { .create_pending_block_at(self, txns, timestamp, block_number) } - fn demand_shutdown(&self) { - - } + fn demand_shutdown(&self) {} } impl PrometheusMetrics for TestBlockChainClient { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 403053c3c..fac382d5c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -312,7 +312,7 @@ impl IoHandler<()> for TransitionHandler { if let Some(client) = weak.upgrade() { client.demand_shutdown(); } - } + } // if let Some(client) = weak.upgrade() { diff --git a/crates/ethcore/src/exit.rs b/crates/ethcore/src/exit.rs index c156bebcc..e51fd91a3 100644 --- a/crates/ethcore/src/exit.rs +++ b/crates/ethcore/src/exit.rs @@ -12,7 +12,6 @@ pub struct ExitStatus { } impl ExitStatus { - /// new not panicking pub fn new() -> Self { ExitStatus { @@ -81,7 +80,6 @@ impl ShutdownManager { /// demands a shutdown of the node software pub fn demand_shutdown(self: &Self) { - self.exit_mutex.0.lock().do_shutdown(); self.exit_mutex.1.notify_all(); } From 39bcfd1a0c3761015cc06176eaef98e7f216d95c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Sep 2023 14:01:36 +0200 Subject: [PATCH 022/687] added message log for demanding shutdown. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index fac382d5c..2e83d62b2 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -310,6 +310,7 @@ impl IoHandler<()> for TransitionHandler { if let Some(ref weak) = *self.client.read() { if let Some(client) = weak.upgrade() { + info!(target: "engine", "demanding shutdown from hbbft engine."); client.demand_shutdown(); } } From df5a7090c7217a4f75eba579f1f582f1eda7103e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Sep 2023 15:01:06 +0200 Subject: [PATCH 023/687] "Detected an attempt to send a hbbft contribution for block" debug level was reduced from "info" to "debug" --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 36a5490fd..e9b2750bf 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -336,7 +336,7 @@ impl HbbftState { if let Some(latest_block) = client.block_number(BlockId::Latest) { if honey_badger.epoch() != latest_block + 1 { - info!(target: "consensus", "Detected an attempt to send a hbbft contribution for block {} before the previous block was imported to the chain.", honey_badger.epoch()); + debug!(target: "consensus", "Detected an attempt to send a hbbft contribution for block {} before the previous block was imported to the chain.", honey_badger.epoch()); return None; } } From 7198ae3d066ad4ade16226ee0747282b1a4a498f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Sep 2023 16:24:17 +0200 Subject: [PATCH 024/687] implemented a pruning protection prood of concept. --- crates/ethcore/src/client/client.rs | 10 +++++++++- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 15 +++++++++++++++ crates/ethcore/src/engines/mod.rs | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 9dad94a73..357d0ba66 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -1313,7 +1313,7 @@ impl Client { break; } match state_db.journal_db().earliest_era() { - Some(earliest_era) if earliest_era + self.history <= latest_era => { + Some(mut earliest_era) if earliest_era + self.history <= latest_era => { let freeze_at = self.snapshotting_at.load(AtomicOrdering::SeqCst); if freeze_at > 0 && freeze_at == earliest_era { // Note: journal_db().mem_used() can be used for a more accurate memory @@ -1323,6 +1323,14 @@ impl Client { freeze_at, earliest_era, latest_era, state_db.journal_db().journal_size()); break; } + + // if the engine still needs that block, we are not going to prune it. + if let Some(protected_block) = self.engine.pruning_protection_block_number() { + if earliest_era < protected_block { + info!(target: "pruning", "Detected attempt from pruning ancient block that is still required by the engine. protected block: {protected_block}, earliest_era: {earliest_era}"); + earliest_era = protected_block - 1; + } + } trace!(target: "client", "Pruning state for ancient era {}", earliest_era); match chain.block_hash(earliest_era) { Some(ancient_hash) => { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 2e83d62b2..f6e869ad1 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1106,6 +1106,21 @@ impl HoneyBadgerBFT { } } + /// hbbft protects the start of the current posdao epoch start from being pruned. + pub fn pruning_protection_block_number(&self) -> Option { + + // we try to get a read lock for 500 ms. + // that is a very long duration, but the information is important. + if let Some(hbbft_state_lock) = self.hbbft_state.try_read_for(Duration::from_millis(500)) { + return Some(hbbft_state_lock.get_current_posdao_epoch_start_block()); + } else { + // better a potential stage 3 verification error instead of a deadlock ?! + // https://github.com/DMDcoin/diamond-node/issues/68 + warn!(target: "engine", "could not aquire read lock for retrieving the pruning_protection_block_number. Stage 3 verification error might follow up."); + return None; + } + } + /** returns if the signer of hbbft is tracked as available in the hbbft contracts. */ pub fn is_available(&self) -> Result { match self.signer.read().as_ref() { diff --git a/crates/ethcore/src/engines/mod.rs b/crates/ethcore/src/engines/mod.rs index ba019d79f..d80365cf1 100644 --- a/crates/ethcore/src/engines/mod.rs +++ b/crates/ethcore/src/engines/mod.rs @@ -709,6 +709,12 @@ pub trait EthEngine: Engine<::machine::EthereumMachine> { fn minimum_gas_price(&self) -> Option { None } + + /// allows engines to define a block that should not get pruned in the DB. + /// This is useful for engines that need to keep a certain block in the DB. + fn pruning_protection_block_number(&self) -> Option { + None + } } // convenience wrappers for existing functions. From 6464b5990bd2ddfedc69c5488ec2f435a4292dce Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Sep 2023 16:35:35 +0200 Subject: [PATCH 025/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index f6e869ad1..48cb081ff 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1108,7 +1108,6 @@ impl HoneyBadgerBFT { /// hbbft protects the start of the current posdao epoch start from being pruned. pub fn pruning_protection_block_number(&self) -> Option { - // we try to get a read lock for 500 ms. // that is a very long duration, but the information is important. if let Some(hbbft_state_lock) = self.hbbft_state.try_read_for(Duration::from_millis(500)) { From de37ba16178e060a0fb1e8f880f7d90b43c779dd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 27 Sep 2023 18:41:39 +0200 Subject: [PATCH 026/687] don't trigger "Error on handling HoneyBadger message from" errors for messages that are comming for late hbbft epoch --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index e9b2750bf..0c8fe4ad6 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -284,10 +284,12 @@ impl HbbftState { match honey_badger.handle_message(&sender_id, message) { Ok(step) => return Ok(Some((step, network_info.clone()))), Err(err) => { - // TODO: Report consensus step errors - // maybe we are not part of the HBBFT Set anymore ? - // maybe the sender is not Part of the hbbft set ? - // maybe we have the wrong hbbft for decryption ? + // the sender is possible not in the hbbft set anymore + // and can ignore this error and not process a step. + let epoch = message_epoch; + if epoch < self.current_posdao_epoch_start_block { + return Ok(None); + } error!(target: "consensus", "Error on handling HoneyBadger message from {} in epoch {} error: {:?}", sender_id, message_epoch, err); return Err(err); From f6341e90d7d7fdce68b45b9f79c904a86328be1c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 27 Sep 2023 23:24:09 +0200 Subject: [PATCH 027/687] version logging --- Cargo.lock | 1 + bin/oe/metrics.rs | 2 ++ crates/util/stats/Cargo.toml | 1 + crates/util/stats/src/lib.rs | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ecb291db4..a379de09a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4848,6 +4848,7 @@ version = "0.1.0" dependencies = [ "log", "prometheus", + "vergen", ] [[package]] diff --git a/bin/oe/metrics.rs b/bin/oe/metrics.rs index 7c7119bcf..ae357d3a8 100644 --- a/bin/oe/metrics.rs +++ b/bin/oe/metrics.rs @@ -59,6 +59,8 @@ fn handle_request( elapsed.as_millis() as i64, ); + reg.register_version(); + let mut buffer = vec![]; let encoder = prometheus::TextEncoder::new(); let metric_families = reg.registry().gather(); diff --git a/crates/util/stats/Cargo.toml b/crates/util/stats/Cargo.toml index 09fdeb8a3..47e8d20af 100644 --- a/crates/util/stats/Cargo.toml +++ b/crates/util/stats/Cargo.toml @@ -6,3 +6,4 @@ authors = ["Parity Technologies "] [dependencies] log = "0.4" prometheus = "0.13.0" +vergen = "0.1" \ No newline at end of file diff --git a/crates/util/stats/src/lib.rs b/crates/util/stats/src/lib.rs index 00ba2c4ae..3cf827451 100644 --- a/crates/util/stats/src/lib.rs +++ b/crates/util/stats/src/lib.rs @@ -108,6 +108,27 @@ impl PrometheusRegistry { ); t } + + pub fn register_version(&mut self) { + let sha3 = vergen::SHORT_SHA; + let version = sha3.bits(); + self.register_gauge("version_sha3_bits", "version_sha3", version as i64); + self.register_gauge( + "version_semver_bits", + "Sementic Versioning bits", + vergen::SEMVER.bits() as i64, + ); + self.register_gauge( + "version_commit_date", + "commit date", + vergen::COMMIT_DATE.bits() as i64, + ); + self.register_gauge( + "version_vergen_target", + "vergen targets", + vergen::TARGET.bits() as i64, + ); + } } /// Implements a prometheus metrics collector From ae52a7c358d47ef5761a7e1469b5bc422515a401 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 28 Sep 2023 16:28:42 +0200 Subject: [PATCH 028/687] improved loggings of key gen errors --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 0c8fe4ad6..55277d52c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -91,13 +91,19 @@ impl HbbftState { } let posdao_epoch_start = get_posdao_epoch_start(&*client, block_id).ok()?; - let synckeygen = initialize_synckeygen( + let synckeygen = match initialize_synckeygen( &*client, signer, BlockId::Number(posdao_epoch_start.low_u64()), ValidatorType::Current, - ) - .ok()?; + ) { + Ok(synckey) => synckey, + Err(e) => { + error!(target: "engine", "error initializing synckeygen for block: {:?}: {:?}", block_id, e); + return None; + } + }; + assert!(synckeygen.is_ready()); let (pks, sks) = synckeygen.generate().ok()?; From df3a83a7c492ba2f9ae4132abdff46b21103e9c8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 28 Sep 2023 19:16:26 +0200 Subject: [PATCH 029/687] release 0.9.1 --- CHANGELOG.md | 10 ++++++++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a6120a6..44477b5da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## Diamond Node Software 3.3.5-hbbft-0.9.1 + +- [pruning protection for hbbft engine] https://github.com/DMDcoin/diamond-node/issues/6 +- [reported fault: UnknownSender] https://github.com/DMDcoin/diamond-node/issues/69 + +## Diamond Node Software 3.3.5-hbbft-0.9.0 + +- Start of Alpha 2 Testnet +- Improved Stability +- Feature preparation for Hbbft Block Reward support ## Diamond Node Software 3.3.5-hbbft-0.8.9 diff --git a/Cargo.lock b/Cargo.lock index ecb291db4..fa1bc72e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -806,7 +806,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.9.0" +version = "3.3.5-hbbft-0.9.1" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3548,7 +3548,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.9.0" +version = "3.3.5-hbbft-0.9.1" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 9ef24173c..79e49d579 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.9.0" +version = "3.3.5-hbbft-0.9.1" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 885128cd9..a9001fe29 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.9.0" +version = "3.3.5-hbbft-0.9.1" authors = ["Parity Technologies "] build = "build.rs" From 1bd15398095f8d92b303ad0ce7e0862b753c890a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 14:44:01 +0200 Subject: [PATCH 030/687] added missing documentation --- crates/ethcore/src/exit.rs | 2 ++ crates/ethcore/src/test_helpers.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/crates/ethcore/src/exit.rs b/crates/ethcore/src/exit.rs index e51fd91a3..cf4445335 100644 --- a/crates/ethcore/src/exit.rs +++ b/crates/ethcore/src/exit.rs @@ -1,3 +1,5 @@ +//! allows controlled shutdown of the node software. + use std::sync::Arc; use parking_lot::{Condvar, Mutex}; diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index 00d956591..4f07a47e6 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -324,6 +324,7 @@ pub fn push_block_with_transactions(client: &Arc, transactions: &[Signed client.import_verified_blocks(); } +/// integrates blocks into the client pub fn push_block_with_transactions_and_author( client: &Arc, transactions: &[SignedTransaction], From 6039fd59f50144e66412007d2792a00694cdf153 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 15:00:51 +0200 Subject: [PATCH 031/687] updated rust version to 1.72 for unit tests. --- .github/workflows/build-test.yml | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/check.yml | 2 +- .github/workflows/fmt.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 660b8da11..ee7e5709b 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -15,7 +15,7 @@ jobs: - ubuntu-latest # - macos-latest toolchain: - - 1.59 + - 1.72 runs-on: ${{ matrix.platform }} steps: - name: Checkout sources diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a0c9ef4a..124b37f9c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: - ubuntu-16.04 # - macos-latest toolchain: - - 1.59 + - 1.72 runs-on: ${{ matrix.platform }} steps: - name: Checkout sources diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 401bd0c0c..a9e96c801 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -18,7 +18,7 @@ jobs: - name: Install 1.59 toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.59 + toolchain: 1.72 profile: minimal override: true - name: Run cargo check 1/3 diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml index d7ef4a52c..aa93deb2c 100644 --- a/.github/workflows/fmt.yml +++ b/.github/workflows/fmt.yml @@ -11,7 +11,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.59 + toolchain: 1.72 override: true - run: rustup component add rustfmt - uses: actions-rs/cargo@v1 From 7dfedfac172f14924a0e500804a75320453b9982 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 15:30:55 +0200 Subject: [PATCH 032/687] fixed test helper for sync crate --- crates/ethcore/sync/src/tests/helpers.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index c5793ab23..600b63cb6 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -28,7 +28,7 @@ use ethcore::{ miner::Miner, snapshot::SnapshotService, spec::Spec, - test_helpers, + test_helpers, exit::ShutdownManager, }; use ethereum_types::H256; @@ -447,6 +447,7 @@ impl TestNet> { test_helpers::new_db(), miner.clone(), channel.clone(), + ShutdownManager::null() ) .unwrap(); From ab9b0250a8f51f3ecce8c0bce78b946460f2c37a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 15:32:10 +0200 Subject: [PATCH 033/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/sync/src/tests/helpers.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index 600b63cb6..79ef780f0 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -25,10 +25,11 @@ use ethcore::{ BlockChainClient, ChainMessageType, ChainNotify, Client as EthcoreClient, ClientConfig, ClientIoMessage, NewBlocks, TestBlockChainClient, }, + exit::ShutdownManager, miner::Miner, snapshot::SnapshotService, spec::Spec, - test_helpers, exit::ShutdownManager, + test_helpers, }; use ethereum_types::H256; @@ -447,7 +448,7 @@ impl TestNet> { test_helpers::new_db(), miner.clone(), channel.clone(), - ShutdownManager::null() + ShutdownManager::null(), ) .unwrap(); From 5fce30ddc860d665e5afdea53e194831cfd77e16 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 15:57:58 +0200 Subject: [PATCH 034/687] updated CI build pipeline fromn ubuntu 16 to ubuntu 20 --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 124b37f9c..9942069dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: platform: - - ubuntu-16.04 + - ubuntu-20.04 # - macos-latest toolchain: - 1.72 @@ -61,7 +61,7 @@ jobs: - name: Upload Linux build uses: actions/upload-artifact@v2 - if: matrix.platform == 'ubuntu-16.04' + if: matrix.platform == 'ubuntu-20.04' with: name: linux-artifacts path: artifacts @@ -76,7 +76,7 @@ jobs: zip-artifacts-creator: name: Create zip artifacts needs: build - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 steps: - name: Set env run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV @@ -197,7 +197,7 @@ jobs: draft-release: name: Draft Release needs: zip-artifacts-creator - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 steps: - name: Set env run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV From 0c9f41c37876983f105edd2200874179f4af6e61 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 15:58:32 +0200 Subject: [PATCH 035/687] fixed ethcore tests because of shutdown manager change. --- crates/ethcore/service/src/service.rs | 1 + crates/ethcore/src/snapshot/tests/service.rs | 5 +++++ crates/ethcore/src/tests/client.rs | 8 ++++++++ crates/ethcore/src/tests/trace.rs | 3 +++ 4 files changed, 17 insertions(+) diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index de8b68598..3dd2986f5 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -272,6 +272,7 @@ mod tests { restoration_db_handler, tempdir.path(), Arc::new(Miner::new_for_tests(&spec, None)), + ShutdownManager::null(), ); assert!(service.is_ok()); drop(service.unwrap()); diff --git a/crates/ethcore/src/snapshot/tests/service.rs b/crates/ethcore/src/snapshot/tests/service.rs index 13e1d7756..1a5b41227 100644 --- a/crates/ethcore/src/snapshot/tests/service.rs +++ b/crates/ethcore/src/snapshot/tests/service.rs @@ -38,6 +38,8 @@ use kvdb_rocksdb::DatabaseConfig; use parking_lot::Mutex; use verification::queue::kind::blocks::Unverified; +use crate::exit::ShutdownManager; + #[test] fn restored_is_equivalent() { let _ = ::env_logger::try_init(); @@ -69,6 +71,7 @@ fn restored_is_equivalent() { blockchain_db, Arc::new(::miner::Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); @@ -232,6 +235,7 @@ fn keep_ancient_blocks() { client_db, Arc::new(::miner::Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); @@ -318,6 +322,7 @@ fn recover_aborted_recovery() { client_db, Arc::new(::miner::Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let service_params = ServiceParams { diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index 5509a483b..29b7c30ff 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -51,6 +51,8 @@ use types::{ }; use verification::queue::kind::blocks::Unverified; +use crate::exit::ShutdownManager; + #[test] fn imports_from_empty() { let db = test_helpers::new_db(); @@ -62,6 +64,7 @@ fn imports_from_empty() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); client.import_verified_blocks(); @@ -80,6 +83,7 @@ fn should_return_registrar() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let params = client.additional_params(); @@ -100,6 +104,7 @@ fn imports_good_block() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let good_block = get_good_dummy_block(); @@ -127,6 +132,7 @@ fn query_none_block() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let non_existant = client.block_header(BlockId::Number(188)); @@ -329,6 +335,7 @@ fn change_history_size() { db.clone(), Arc::new(Miner::new_for_tests(&test_spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); @@ -361,6 +368,7 @@ fn change_history_size() { db, Arc::new(Miner::new_for_tests(&test_spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); assert_eq!(client.state().balance(&address).unwrap(), 100.into()); diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index af1664f57..7aae884c7 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -35,6 +35,8 @@ use types::{ }; use verification::queue::kind::blocks::Unverified; +use crate::exit::ShutdownManager; + #[test] fn can_trace_block_and_uncle_reward() { let db = test_helpers::new_db(); @@ -50,6 +52,7 @@ fn can_trace_block_and_uncle_reward() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); From 825a93fb1bfc521f0927c5da80040fef7f8a9731 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 16:04:04 +0200 Subject: [PATCH 036/687] fixed unit tests for node-filter. --- crates/net/node-filter/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/net/node-filter/src/lib.rs b/crates/net/node-filter/src/lib.rs index 6d72290a1..d59f0ed6f 100644 --- a/crates/net/node-filter/src/lib.rs +++ b/crates/net/node-filter/src/lib.rs @@ -99,6 +99,7 @@ mod test { use super::NodeFilter; use ethcore::{ client::{BlockChainClient, Client, ClientConfig}, + exit::ShutdownManager, miner::Miner, spec::Spec, test_helpers, @@ -127,6 +128,7 @@ mod test { client_db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let filter = NodeFilter::new( From 3b320cd2babb0e5329ffc650ba9cf541c82d80f1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 16:16:17 +0200 Subject: [PATCH 037/687] fixed tx_filter test --- crates/ethcore/src/tx_filter.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 963dcb06a..8abceb86e 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -213,6 +213,8 @@ impl TransactionFilter { #[cfg(test)] mod test { + use crate::exit::ShutdownManager; + use super::TransactionFilter; use client::{BlockChainClient, BlockId, Client, ClientConfig}; use crypto::publickey::{KeyPair, Secret}; @@ -242,6 +244,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let key1 = KeyPair::from_secret( @@ -477,6 +480,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let key1 = KeyPair::from_secret( @@ -545,6 +549,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let key1 = KeyPair::from_secret( @@ -613,6 +618,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let key1 = KeyPair::from_secret( @@ -684,6 +690,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let key1 = KeyPair::from_secret( From 9411afe9c92e2b04d2cad47b6c1b545065d8a469 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 16:16:38 +0200 Subject: [PATCH 038/687] fixed warning for authority_round. --- crates/ethcore/src/engines/authority_round/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index 0b8b351e7..8848dad19 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -3725,7 +3725,7 @@ mod tests { } }"#; let deserialized: ethjson::spec::AuthorityRound = serde_json::from_str(config).unwrap(); - AuthorityRoundParams::from(deserialized.params); + let _ = AuthorityRoundParams::from(deserialized.params); } #[test] From c919ef8f924c07ac38df3634da749f5d53154602 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 18:50:19 +0200 Subject: [PATCH 039/687] removed moc to first validator unit test - To be done soon. --- crates/ethcore/src/engines/hbbft/test/mod.rs | 182 +++++++++---------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/test/mod.rs b/crates/ethcore/src/engines/hbbft/test/mod.rs index 218753882..175f00e75 100644 --- a/crates/ethcore/src/engines/hbbft/test/mod.rs +++ b/crates/ethcore/src/engines/hbbft/test/mod.rs @@ -225,97 +225,97 @@ fn sync_two_validators() { moc.sync_transactions_to(&mut validator_1); } -#[test] -fn test_moc_to_first_validator() { - // Create MOC client - let mut moc = create_hbbft_client(MASTER_OF_CEREMONIES_KEYPAIR.clone()); - - // Create first validator client - let mut validator_1 = create_hbbft_client(Random.generate()); - - // To avoid performing external transactions with the MoC we create and fund a random address. - let transactor: KeyPair = Random.generate(); - - // Fund the transactor. - // Also triggers the creation of a block. - // This implicitly calls the block reward contract, which should trigger a phase transition - // since we already verified that the genesis transition time threshold has been reached. - moc.transfer_to( - &transactor.address(), - &U256::from_dec_str("1000000000000000000000000").unwrap(), - ); - - let transaction_funds = U256::from(9000000000000000000u64); - moc.transfer(&transactor, &validator_1.address(), &transaction_funds); - - // Create first pool - // Create staking address - let _staker_1 = create_staker(&mut moc, &transactor, &validator_1, transaction_funds); - - // Wait for moc keygen phase to finish - moc.create_some_transaction(Some(&transactor)); - moc.create_some_transaction(Some(&transactor)); - //moc.create_some_transaction(Some(&transactor)); - - // In the next block the POSDAO contracts realize they need to - // switch to the new validator. - moc.create_some_transaction(Some(&transactor)); - // We need to create another block to give the new validator a chance - // to find out it is in the pending validator set. - moc.create_some_transaction(Some(&transactor)); - - // Now we should be part of the pending validator set. - assert!( - is_pending_validator(moc.client.as_ref(), &validator_1.address()) - .expect("Constant call must succeed") - ); - // ..and the MOC should not be a pending validator. - assert!(!is_pending_validator(moc.client.as_ref(), &moc.address()) - .expect("Constant call must succeed")); - - // Sync blocks from MOC to validator_1. - // On importing the last block validator_1 should realize he is the next - // validator and generate a Parts transaction. - moc.sync_blocks_to(&mut validator_1); - - // validator_1 created a transaction to write its part, but it is not - // the current validator and cannot create a block. - // We need to gossip the transaction from validator_1 to the moc for a new block - // to be created, including the transaction from validator_1. - validator_1.sync_transactions_to(&mut moc); - - // Write another dummy block to give validator_1 the chance to realize he wrote - // his Part already so he sends his Acks. - // Due to the Parts/Acks sending delay of 3 blocks we have to inject 3 blocks here - moc.create_some_transaction(Some(&transactor)); - moc.create_some_transaction(Some(&transactor)); - moc.create_some_transaction(Some(&transactor)); - - // At this point the transaction from validator_1 has written its Keygen part, - // and we need to sync the new blocks from moc to validator_1. - moc.sync_blocks_to(&mut validator_1); - - // At this point validator_1 realizes his Part is included on the chain and - // generates a transaction to write it Acks. - // We need to gossip the transactions from validator_1 to the moc. - validator_1.sync_transactions_to(&mut moc); - - // Create a dummy transaction for the moc to see the Acks on the chain state, - // and make him switch to the new validator. - moc.create_some_transaction(Some(&transactor)); - - // Sync blocks from moc to validator_1, which is now the only active validator. - moc.sync_blocks_to(&mut validator_1); - - let pre_block_nr = validator_1.client.chain().best_block_number(); - - // Create a dummy transaction on the validator_1 client to verify it can create blocks. - validator_1.create_some_transaction(Some(&transactor)); - - let post_block_nr = validator_1.client.chain().best_block_number(); - - assert_eq!(post_block_nr, pre_block_nr + 1); -} +// #[test] +// fn test_moc_to_first_validator() { +// // Create MOC client +// let mut moc = create_hbbft_client(MASTER_OF_CEREMONIES_KEYPAIR.clone()); + +// // Create first validator client +// let mut validator_1 = create_hbbft_client(Random.generate()); + +// // To avoid performing external transactions with the MoC we create and fund a random address. +// let transactor: KeyPair = Random.generate(); + +// // Fund the transactor. +// // Also triggers the creation of a block. +// // This implicitly calls the block reward contract, which should trigger a phase transition +// // since we already verified that the genesis transition time threshold has been reached. +// moc.transfer_to( +// &transactor.address(), +// &U256::from_dec_str("1000000000000000000000000").unwrap(), +// ); + +// let transaction_funds = U256::from(9000000000000000000u64); +// moc.transfer(&transactor, &validator_1.address(), &transaction_funds); + +// // Create first pool +// // Create staking address +// let _staker_1 = create_staker(&mut moc, &transactor, &validator_1, transaction_funds); + +// // Wait for moc keygen phase to finish +// moc.create_some_transaction(Some(&transactor)); +// moc.create_some_transaction(Some(&transactor)); +// //moc.create_some_transaction(Some(&transactor)); + +// // In the next block the POSDAO contracts realize they need to +// // switch to the new validator. +// moc.create_some_transaction(Some(&transactor)); +// // We need to create another block to give the new validator a chance +// // to find out it is in the pending validator set. +// moc.create_some_transaction(Some(&transactor)); + +// // Now we should be part of the pending validator set. +// assert!( +// is_pending_validator(moc.client.as_ref(), &validator_1.address()) +// .expect("Constant call must succeed") +// ); +// // ..and the MOC should not be a pending validator. +// assert!(!is_pending_validator(moc.client.as_ref(), &moc.address()) +// .expect("Constant call must succeed")); + +// // Sync blocks from MOC to validator_1. +// // On importing the last block validator_1 should realize he is the next +// // validator and generate a Parts transaction. +// moc.sync_blocks_to(&mut validator_1); + +// // validator_1 created a transaction to write its part, but it is not +// // the current validator and cannot create a block. +// // We need to gossip the transaction from validator_1 to the moc for a new block +// // to be created, including the transaction from validator_1. +// validator_1.sync_transactions_to(&mut moc); + +// // Write another dummy block to give validator_1 the chance to realize he wrote +// // his Part already so he sends his Acks. +// // Due to the Parts/Acks sending delay of 3 blocks we have to inject 3 blocks here +// moc.create_some_transaction(Some(&transactor)); +// moc.create_some_transaction(Some(&transactor)); +// moc.create_some_transaction(Some(&transactor)); + +// // At this point the transaction from validator_1 has written its Keygen part, +// // and we need to sync the new blocks from moc to validator_1. +// moc.sync_blocks_to(&mut validator_1); + +// // At this point validator_1 realizes his Part is included on the chain and +// // generates a transaction to write it Acks. +// // We need to gossip the transactions from validator_1 to the moc. +// validator_1.sync_transactions_to(&mut moc); + +// // Create a dummy transaction for the moc to see the Acks on the chain state, +// // and make him switch to the new validator. +// moc.create_some_transaction(Some(&transactor)); + +// // Sync blocks from moc to validator_1, which is now the only active validator. +// moc.sync_blocks_to(&mut validator_1); + +// let pre_block_nr = validator_1.client.chain().best_block_number(); + +// // Create a dummy transaction on the validator_1 client to verify it can create blocks. +// validator_1.create_some_transaction(Some(&transactor)); + +// let post_block_nr = validator_1.client.chain().best_block_number(); + +// assert_eq!(post_block_nr, pre_block_nr + 1); +// } #[test] fn test_initialize_n_validators() { From 61cbd1101b806c2266e52bc924f89e6b48a83896 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 19:28:19 +0200 Subject: [PATCH 040/687] fixed rpc v1 tests --- crates/rpc/src/v1/tests/eth.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/rpc/src/v1/tests/eth.rs b/crates/rpc/src/v1/tests/eth.rs index 0a5ae4d6c..98091785e 100644 --- a/crates/rpc/src/v1/tests/eth.rs +++ b/crates/rpc/src/v1/tests/eth.rs @@ -23,7 +23,7 @@ use ethcore::{ miner::Miner, spec::{Genesis, Spec}, test_helpers, - verification::{queue::kind::blocks::Unverified, VerifierType}, + verification::{queue::kind::blocks::Unverified, VerifierType}, exit::ShutdownManager, }; use ethereum_types::{Address, H256, U256}; use ethjson::{blockchain::BlockChain, spec::ForkSpec}; @@ -130,6 +130,7 @@ impl EthTester { test_helpers::new_db(), miner_service.clone(), IoChannel::disconnected(), + ShutdownManager::null(), ) .unwrap(); let sync_provider = sync_provider(); From 36ef6c98583ba03d264993b435c72ea976aee0c0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Sep 2023 19:30:04 +0200 Subject: [PATCH 041/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/rpc/src/v1/tests/eth.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/rpc/src/v1/tests/eth.rs b/crates/rpc/src/v1/tests/eth.rs index 98091785e..5fcc02f44 100644 --- a/crates/rpc/src/v1/tests/eth.rs +++ b/crates/rpc/src/v1/tests/eth.rs @@ -20,10 +20,11 @@ use std::{env, sync::Arc}; use accounts::AccountProvider; use ethcore::{ client::{BlockChainClient, ChainInfo, Client, ClientConfig, EvmTestClient, ImportBlock}, + exit::ShutdownManager, miner::Miner, spec::{Genesis, Spec}, test_helpers, - verification::{queue::kind::blocks::Unverified, VerifierType}, exit::ShutdownManager, + verification::{queue::kind::blocks::Unverified, VerifierType}, }; use ethereum_types::{Address, H256, U256}; use ethjson::{blockchain::BlockChain, spec::ForkSpec}; From 2f309a87368a3016dc32976abb1d50d8152f9ac0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 2 Oct 2023 17:15:59 +0200 Subject: [PATCH 042/687] fixed build-linux.sh for diamond-node --- scripts/actions/build-linux.sh | 2 +- scripts/actions/build-windows.sh | 21 --------------------- 2 files changed, 1 insertion(+), 22 deletions(-) delete mode 100755 scripts/actions/build-windows.sh diff --git a/scripts/actions/build-linux.sh b/scripts/actions/build-linux.sh index dcfc2e9ae..7df17df35 100755 --- a/scripts/actions/build-linux.sh +++ b/scripts/actions/build-linux.sh @@ -16,7 +16,7 @@ echo "_____ Post-processing binaries _____" rm -rf artifacts/* mkdir -p artifacts/ -cp -v target/release/openethereum artifacts/openethereum +cp -v target/release/diamond-node artifacts/diamond-node cp -v target/release/openethereum-evm artifacts/openethereum-evm cp -v target/release/ethstore artifacts/ethstore cp -v target/release/ethkey artifacts/ethkey diff --git a/scripts/actions/build-windows.sh b/scripts/actions/build-windows.sh deleted file mode 100755 index 948e7f85e..000000000 --- a/scripts/actions/build-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -set -e # fail on any error -set -u # treat unset variables as error -# NOTE: Enables the aes-ni instructions for RustCrypto dependency. -# If you change this please remember to also update .cargo/config -export RUSTFLAGS=" -Ctarget-feature=+aes,+sse2,+ssse3 -Ctarget-feature=+crt-static -Clink-arg=-s" - -echo "_____ Build Parity and tools _____" -time cargo build --verbose --release --features final -time cargo build --verbose --release -p evmbin -time cargo build --verbose --release -p ethstore-cli -time cargo build --verbose --release -p ethkey-cli - -echo "_____ Post-processing binaries _____" -rm -rf artifacts -mkdir -p artifacts - -cp --verbose target/release/openethereum.exe artifacts/openethereum.exe -cp --verbose target/release/openethereum-evm.exe artifacts/openethereum-evm.exe -cp --verbose target/release/ethstore.exe artifacts/ethstore.exe -cp --verbose target/release/ethkey.exe artifacts/ethkey.exe From 59e9da28be2a667e2ca1800561c72a6e5a89a5a3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 3 Oct 2023 13:05:15 +0200 Subject: [PATCH 043/687] extented the pruning protection for a further epoch. https://github.com/DMDcoin/diamond-node/issues/68 --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 5 +++++ crates/ethcore/src/engines/hbbft/hbbft_state.rs | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 48cb081ff..7e93bbcd3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1111,6 +1111,11 @@ impl HoneyBadgerBFT { // we try to get a read lock for 500 ms. // that is a very long duration, but the information is important. if let Some(hbbft_state_lock) = self.hbbft_state.try_read_for(Duration::from_millis(500)) { + if let Some(last_epoch_start_block) = + hbbft_state_lock.get_last_posdao_epoch_start_block() + { + return Some(last_epoch_start_block); + } return Some(hbbft_state_lock.get_current_posdao_epoch_start_block()); } else { // better a potential stage 3 verification error instead of a deadlock ?! diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 55277d52c..3671ac001 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -40,6 +40,7 @@ pub(crate) struct HbbftState { public_master_key: Option, current_posdao_epoch: u64, current_posdao_epoch_start_block: u64, + last_posdao_epoch_start_block: Option, future_messages_cache: BTreeMap>, } @@ -51,6 +52,7 @@ impl HbbftState { public_master_key: None, current_posdao_epoch: 0, current_posdao_epoch_start_block: 0, + last_posdao_epoch_start_block: None, future_messages_cache: BTreeMap::new(), } } @@ -115,6 +117,7 @@ impl HbbftState { self.honey_badger = None; // Set the current POSDAO epoch # self.current_posdao_epoch = target_posdao_epoch; + self.last_posdao_epoch_start_block = Some(self.current_posdao_epoch_start_block); self.current_posdao_epoch_start_block = posdao_epoch_start.as_u64(); trace!(target: "engine", "Switched hbbft state to epoch {}.", self.current_posdao_epoch); @@ -487,7 +490,7 @@ impl HbbftState { Ok(synckeygen) => synckeygen, Err(e) => { let diff = parent_block_nr - posdao_epoch_start.low_u64(); - error!(target: "consensus", "Synckeygen failed. parent block: {} epoch_start: {} diff {} with error: {:?} ", parent_block_nr, posdao_epoch_start, diff, e); + error!(target: "consensus", "Error: Synckeygen failed. parent block: {} epoch_start: {} diff {} with error: {:?}. current posdao: {:?} target epoch {:?}", parent_block_nr, posdao_epoch_start, diff, e, self.current_posdao_epoch, target_posdao_epoch); return false; } }; @@ -550,4 +553,8 @@ impl HbbftState { pub fn get_current_posdao_epoch_start_block(&self) -> u64 { self.current_posdao_epoch_start_block } + + pub fn get_last_posdao_epoch_start_block(&self) -> Option { + self.last_posdao_epoch_start_block + } } From 5a9690b9b223b3ab45f75305b013f895495e06a0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 4 Oct 2023 12:52:20 +0200 Subject: [PATCH 044/687] log cleanup, do not log do_validator_engine_actions anymore. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 7e93bbcd3..400dde3cf 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -357,7 +357,6 @@ impl IoHandler<()> for TransitionHandler { trace!(target: "consensus", "All Operation that had to be done after syncing have been done now."); } } else if timer == ENGINE_VALIDATOR_CANDIDATE_ACTIONS { - warn!(target: "consensus", "do_validator_engine_actions"); if let Err(err) = self.engine.do_validator_engine_actions() { error!(target: "consensus", "do_validator_engine_actions failed: {:?}", err); } From 4c03bb16f1deaec32924d9bb6f644e7aada51fcf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 6 Oct 2023 13:47:47 +0200 Subject: [PATCH 045/687] moved pruning_protection_block_number from EthEngine to Engine, pruning protection was not used before. --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 38 +++++++++---------- crates/ethcore/src/engines/mod.rs | 12 +++--- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 400dde3cf..21d767555 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1105,25 +1105,6 @@ impl HoneyBadgerBFT { } } - /// hbbft protects the start of the current posdao epoch start from being pruned. - pub fn pruning_protection_block_number(&self) -> Option { - // we try to get a read lock for 500 ms. - // that is a very long duration, but the information is important. - if let Some(hbbft_state_lock) = self.hbbft_state.try_read_for(Duration::from_millis(500)) { - if let Some(last_epoch_start_block) = - hbbft_state_lock.get_last_posdao_epoch_start_block() - { - return Some(last_epoch_start_block); - } - return Some(hbbft_state_lock.get_current_posdao_epoch_start_block()); - } else { - // better a potential stage 3 verification error instead of a deadlock ?! - // https://github.com/DMDcoin/diamond-node/issues/68 - warn!(target: "engine", "could not aquire read lock for retrieving the pruning_protection_block_number. Stage 3 verification error might follow up."); - return None; - } - } - /** returns if the signer of hbbft is tracked as available in the hbbft contracts. */ pub fn is_available(&self) -> Result { match self.signer.read().as_ref() { @@ -1606,6 +1587,25 @@ impl Engine for HoneyBadgerBFT { fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { self.hbbft_message_dispatcher.prometheus_metrics(registry); } + + /// hbbft protects the start of the current posdao epoch start from being pruned. + fn pruning_protection_block_number(&self) -> Option { + // we try to get a read lock for 500 ms. + // that is a very long duration, but the information is important. + if let Some(hbbft_state_lock) = self.hbbft_state.try_read_for(Duration::from_millis(500)) { + if let Some(last_epoch_start_block) = + hbbft_state_lock.get_last_posdao_epoch_start_block() + { + return Some(last_epoch_start_block); + } + return Some(hbbft_state_lock.get_current_posdao_epoch_start_block()); + } else { + // better a potential stage 3 verification error instead of a deadlock ?! + // https://github.com/DMDcoin/diamond-node/issues/68 + warn!(target: "engine", "could not aquire read lock for retrieving the pruning_protection_block_number. Stage 3 verification error might follow up."); + return None; + } + } } #[cfg(test)] diff --git a/crates/ethcore/src/engines/mod.rs b/crates/ethcore/src/engines/mod.rs index d80365cf1..dec95fe63 100644 --- a/crates/ethcore/src/engines/mod.rs +++ b/crates/ethcore/src/engines/mod.rs @@ -575,6 +575,12 @@ pub trait Engine: Sync + Send { true } + /// allows engines to define a block that should not get pruned in the DB. + /// This is useful for engines that need to keep a certain block in the DB. + fn pruning_protection_block_number(&self) -> Option { + None + } + /// Optional entry point for adding engine specific metrics. fn prometheus_metrics(&self, _registry: &mut stats::PrometheusRegistry) {} } @@ -709,12 +715,6 @@ pub trait EthEngine: Engine<::machine::EthereumMachine> { fn minimum_gas_price(&self) -> Option { None } - - /// allows engines to define a block that should not get pruned in the DB. - /// This is useful for engines that need to keep a certain block in the DB. - fn pruning_protection_block_number(&self) -> Option { - None - } } // convenience wrappers for existing functions. From e3c2f40f2a22ccb39e34f0d39275ce1cb65867d6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 10 Oct 2023 20:09:51 +0200 Subject: [PATCH 046/687] pruning protection: only prune at blocks that come from journal_db().earlierst_era() --- crates/ethcore/src/client/client.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 357d0ba66..d52003c28 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -1313,7 +1313,7 @@ impl Client { break; } match state_db.journal_db().earliest_era() { - Some(mut earliest_era) if earliest_era + self.history <= latest_era => { + Some(earliest_era) if earliest_era + self.history <= latest_era => { let freeze_at = self.snapshotting_at.load(AtomicOrdering::SeqCst); if freeze_at > 0 && freeze_at == earliest_era { // Note: journal_db().mem_used() can be used for a more accurate memory @@ -1328,7 +1328,8 @@ impl Client { if let Some(protected_block) = self.engine.pruning_protection_block_number() { if earliest_era < protected_block { info!(target: "pruning", "Detected attempt from pruning ancient block that is still required by the engine. protected block: {protected_block}, earliest_era: {earliest_era}"); - earliest_era = protected_block - 1; + //earliest_era = protected_block - 1; + break; } } trace!(target: "client", "Pruning state for ancient era {}", earliest_era); From bb13108e10fba5b3dcdf72d20de4115de4fefab4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 12 Oct 2023 14:06:33 +0200 Subject: [PATCH 047/687] fixed bug in pruning protection. --- crates/ethcore/src/client/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index d52003c28..f05133b1a 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -1326,7 +1326,7 @@ impl Client { // if the engine still needs that block, we are not going to prune it. if let Some(protected_block) = self.engine.pruning_protection_block_number() { - if earliest_era < protected_block { + if earliest_era > protected_block { info!(target: "pruning", "Detected attempt from pruning ancient block that is still required by the engine. protected block: {protected_block}, earliest_era: {earliest_era}"); //earliest_era = protected_block - 1; break; From d4d424812c93db20727e70e9753051b5b193472e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Oct 2023 21:24:45 +0200 Subject: [PATCH 048/687] updated README.md for diamond-node adoptions --- README.md | 49 ++++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 588b25bb3..cc1c3a38c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ -# OpenEthereum +# Diamond Node -Fast and feature-rich multi-network Ethereum client. - -[» Download the latest release «](https://github.com/openethereum/openethereum/releases/latest) +Node client for the protocol version 4 of the bit.diamonds network. [![GPL licensed][license-badge]][license-url] [![Build Status][ci-badge]][ci-url] @@ -10,10 +8,7 @@ Fast and feature-rich multi-network Ethereum client. [license-badge]: https://img.shields.io/badge/license-GPL_v3-green.svg [license-url]: LICENSE -[ci-badge]: https://github.com/openethereum/openethereum/workflows/Build%20and%20Test%20Suite/badge.svg -[ci-url]: https://github.com/openethereum/openethereum/actions -[chat-badge]: https://img.shields.io/discord/669192218728202270.svg?logo=discord -[chat-url]: https://discord.io/openethereum +[chat-url]: (https://dmdcoin.slack.com/) ## Table of Contents @@ -32,29 +27,25 @@ Fast and feature-rich multi-network Ethereum client. ## 1. Description -**Built for mission-critical use**: Miners, service providers, and exchanges need fast synchronisation and maximum uptime. OpenEthereum provides the core infrastructure essential for speedy and reliable services. - -- Clean, modular codebase for easy customisation -- Advanced CLI-based client -- Minimal memory and storage footprint -- Synchronise in hours, not days with Warp Sync -- Modular for light integration into your service or product +diamond-node is the node software for the upcomming V4 of the diamond network. +The Node Software is on a alpha level and still under active development. ## 2. Technical Overview -OpenEthereum's goal is to be the fastest, lightest, and most secure Ethereum client. We are developing OpenEthereum using the **Rust programming language**. OpenEthereum is licensed under the GPLv3 and can be used for all your Ethereum needs. +diamond-node builds on OpenEthereum, and shares a lot of base features, +covered in the [OpenEthereum Documentation](https://openethereum.github.io/). -By default, OpenEthereum runs a JSON-RPC HTTP server on port `:8545` and a Web-Sockets server on port `:8546`. This is fully configurable and supports a number of APIs. +By default, diamond-node runs a JSON-RPC HTTP server on port `:8545` and a Web-Sockets server on port `:8546`. This is fully configurable and supports a number of APIs. -If you run into problems while using OpenEthereum, check out the [old wiki for documentation](https://openethereum.github.io/), feel free to [file an issue in this repository](https://github.com/openethereum/openethereum/issues/new), or hop on our [Discord](https://discord.io/openethereum) chat room to ask a question. We are glad to help! +If you run into problems while using diamond-node, feel free to [file an issue in this repository](https://github.com/dmdcoind/diamond-node/issues/new), or hop on our [Slack](https://dmdcoin.slack.com/), [Telegram](https://t.me/DMDcoin) or [Discord](https://discord.gg/TStv6gm) chat room to ask a question. We are glad to help! -You can download OpenEthereum's latest release at [the releases page](https://github.com/openethereum/openethereum/releases) or follow the instructions below to build from source. Read the [CHANGELOG.md](CHANGELOG.md) for a list of all changes between different versions. +We do not provide binaries and suggest to build from source. ## 3. Building ### 3.1 Build Dependencies -OpenEthereum requires **latest stable Rust version** to build. +diamond-node requires **latest stable Rust version** to build. We recommend installing Rust through [rustup](https://www.rustup.rs/). If you don't already have `rustup`, you can install it like this: @@ -63,7 +54,7 @@ We recommend installing Rust through [rustup](https://www.rustup.rs/). If you do $ curl https://sh.rustup.rs -sSf | sh ``` - OpenEthereum also requires `clang` (>= 9.0), `clang++`, `pkg-config`, `file`, `make`, and `cmake` packages to be installed. + diamond-node also requires `clang` (>= 9.0), `clang++`, `pkg-config`, `file`, `make`, and `cmake` packages to be installed. - OSX: ```bash @@ -83,14 +74,14 @@ Once you have `rustup` installed, then you need to install: * [Perl](https://www.perl.org) * [Yasm](https://yasm.tortall.net) -Make sure that these binaries are in your `PATH`. After that, you should be able to build OpenEthereum from source. +Make sure that these binaries are in your `PATH`. After that, you should be able to build diamond-node from source. ### 3.2 Build from Source Code ```bash # download OpenEthereum code -$ git clone https://github.com/openethereum/openethereum -$ cd openethereum +$ git clone https://github.com/DMDcoin/diamond-node +$ cd diamond-node # build in release mode $ cargo build --release --features final @@ -116,26 +107,26 @@ This always compiles the latest nightly builds. If you want to build stable, do $ git checkout stable ``` -### 3.3 Starting OpenEthereum +### 3.3 Starting diamond-node #### Manually -To start OpenEthereum manually, just run +To start diamond-node manually, just run ```bash $ ./target/release/openethereum ``` -so OpenEthereum begins syncing the Ethereum blockchain. +so diamond-node begins syncing the Ethereum blockchain. #### Using `systemd` service file -To start OpenEthereum as a regular user using `systemd` init: +To start diamond-node as a regular user using `systemd` init: 1. Copy `./scripts/openethereum.service` to your `systemd` user directory (usually `~/.config/systemd/user`). 2. Copy release to bin folder, write `sudo install ./target/release/openethereum /usr/bin/openethereum` -3. To configure OpenEthereum, see [our wiki](https://openethereum.github.io/Configuring-OpenEthereum) for details. +3. To configure diamond-node, see [our wiki](https://openethereum.github.io/Configuring-OpenEthereum) for details. ## 4. Testing From 5f42fc426e9b8017fdec23ae25a07b1e2e47a381 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Oct 2023 21:50:34 +0200 Subject: [PATCH 049/687] Changelog for 0.9.2 release --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44477b5da..ceab188d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Diamond Node Software 3.3.5-hbbft-0.9.2 + +- [FIXED: pruning as root cause for stage 3 errors] https://github.com/DMDcoin/diamond-node/issues/68 + ## Diamond Node Software 3.3.5-hbbft-0.9.1 - [pruning protection for hbbft engine] https://github.com/DMDcoin/diamond-node/issues/6 From 1add6f988184d1f7961c8da60f2fee2e044262c5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Oct 2023 11:19:25 +0200 Subject: [PATCH 050/687] changelog of v 0.9.1 pointed to the wrong version --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceab188d9..707d6c943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## Diamond Node Software 3.3.5-hbbft-0.9.1 -- [pruning protection for hbbft engine] https://github.com/DMDcoin/diamond-node/issues/6 +- [pruning protection for hbbft engine] https://github.com/DMDcoin/diamond-node/issues/62 - [reported fault: UnknownSender] https://github.com/DMDcoin/diamond-node/issues/69 ## Diamond Node Software 3.3.5-hbbft-0.9.0 From 58a0695108fef2a999cacb5cb505d5f158cadf43 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Oct 2023 12:00:25 +0200 Subject: [PATCH 051/687] version upgrade to 0.9.2 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- bin/oe/cli/usage_header.txt | 4 ++-- crates/util/version/Cargo.toml | 8 ++++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2fddddeb0..a3022cd0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -806,7 +806,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.9.1" +version = "3.3.5-hbbft-0.9.2" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3548,7 +3548,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.9.1" +version = "3.3.5-hbbft-0.9.2" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 79e49d579..92c53edfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.9.1" +version = "3.3.5-hbbft-0.9.2" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/bin/oe/cli/usage_header.txt b/bin/oe/cli/usage_header.txt index a7f156d1f..09b31531a 100644 --- a/bin/oe/cli/usage_header.txt +++ b/bin/oe/cli/usage_header.txt @@ -1,5 +1,5 @@ -OpenEthereum Client. - By Wood/Paronyan/Kotewicz/Drwięga/Volf/Greeff +diamond-node bit.diamonds Node Software + By Haller/Forstenlechner/Wood/Paronyan/Kotewicz/Drwięga/Volf/Greeff Habermeier/Czaban/Gotchac/Redman/Nikolsky Schoedon/Tang/Adolfsson/Silva/Palm/Hirsz et al. Copyright 2015-2020 Parity Technologies (UK) Ltd. diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index a9001fe29..a378be83e 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,8 +1,12 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.9.1" -authors = ["Parity Technologies "] +version = "3.3.5-hbbft-0.9.2" +authors = [ + "bit.diamonds developers", + "OpenEthereum developers", + "Parity Technologies " +] build = "build.rs" [package.metadata] From 5d16f6e6b02122f4a5dc0a8caa6d9651a91fd582 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 18 Oct 2023 13:19:25 +0200 Subject: [PATCH 052/687] removed binary builds - dmd does not provide binaries. build from source!! --- .github/workflows/build.yml | 285 ------------------------------------ 1 file changed, 285 deletions(-) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 9942069dd..000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,285 +0,0 @@ -name: Build Release Suite - -on: - push: - tags: - - v* - -# Global vars -env: - AWS_REGION: "us-east-1" - AWS_S3_ARTIFACTS_BUCKET: "openethereum-releases" - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - -jobs: - build: - name: Build Release - strategy: - matrix: - platform: - - ubuntu-20.04 - # - macos-latest - toolchain: - - 1.72 - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout sources - uses: actions/checkout@main - - name: Install toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.toolchain }} - profile: minimal - override: true - - # ============================== - # Windows Build - # ============================== - - # - name: Install LLVM for Windows - # if: matrix.platform == 'windows2019' - # run: choco install llvm - - # - name: Build OpenEthereum for Windows - # if: matrix.platform == 'windows2019' - # run: sh scripts/actions/build-windows.sh ${{matrix.platform}} - - # - name: Upload Windows build - # uses: actions/upload-artifact@v2 - # if: matrix.platform == 'windows2019' - # with: - # name: windows-artifacts - # path: artifacts - - # ============================== - # Linux/Macos Build - # ============================== - - - name: Build OpenEthereum for ${{matrix.platform}} - if: matrix.platform != 'windows2019' - run: sh scripts/actions/build-linux.sh ${{matrix.platform}} - - - name: Upload Linux build - uses: actions/upload-artifact@v2 - if: matrix.platform == 'ubuntu-20.04' - with: - name: linux-artifacts - path: artifacts - - - name: Upload MacOS build - uses: actions/upload-artifact@v2 - if: matrix.platform == 'macos-latest' - with: - name: macos-artifacts - path: artifacts - - zip-artifacts-creator: - name: Create zip artifacts - needs: build - runs-on: ubuntu-20.04 - steps: - - name: Set env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - # ============================== - # Create ZIP files - # ============================== - - # - name: Download Windows artifacts - # uses: actions/download-artifact@v2 - # with: - # name: windows-artifacts - # path: windows-artifacts - - - name: Download Linux artifacts - uses: actions/download-artifact@v2 - with: - name: linux-artifacts - path: linux-artifacts - - - name: Download MacOS artifacts - uses: actions/download-artifact@v2 - with: - name: macos-artifacts - path: macos-artifacts - - - name: Display structure of downloaded files - run: ls - - - name: Create zip Linux - id: create_zip_linux - run: | - cd linux-artifacts/ - zip -rT openethereum-linux-${{ env.RELEASE_VERSION }}.zip * - ls openethereum-linux-${{ env.RELEASE_VERSION }}.zip - cd .. - mv linux-artifacts/openethereum-linux-${{ env.RELEASE_VERSION }}.zip . - - echo "Setting outputs..." - echo ::set-output name=LINUX_ARTIFACT::openethereum-linux-${{ env.RELEASE_VERSION }}.zip - echo ::set-output name=LINUX_SHASUM::$(shasum -a 256 openethereum-linux-${{ env.RELEASE_VERSION }}.zip | awk '{print $1}') - - - name: Create zip MacOS - id: create_zip_macos - run: | - cd macos-artifacts/ - zip -rT openethereum-macos-${{ env.RELEASE_VERSION }}.zip * - ls openethereum-macos-${{ env.RELEASE_VERSION }}.zip - cd .. - mv macos-artifacts/openethereum-macos-${{ env.RELEASE_VERSION }}.zip . - - echo "Setting outputs..." - echo ::set-output name=MACOS_ARTIFACT::openethereum-macos-${{ env.RELEASE_VERSION }}.zip - echo ::set-output name=MACOS_SHASUM::$(shasum -a 256 openethereum-macos-${{ env.RELEASE_VERSION }}.zip | awk '{print $1}') - - # - name: Create zip Windows - # id: create_zip_windows - # run: | - # cd windows-artifacts/ - # zip -rT openethereum-windows-${{ env.RELEASE_VERSION }}.zip * - # ls openethereum-windows-${{ env.RELEASE_VERSION }}.zip - # cd .. - # mv windows-artifacts/openethereum-windows-${{ env.RELEASE_VERSION }}.zip . - - # echo "Setting outputs..." - # echo ::set-output name=WINDOWS_ARTIFACT::openethereum-windows-${{ env.RELEASE_VERSION }}.zip - # echo ::set-output name=WINDOWS_SHASUM::$(shasum -a 256 openethereum-windows-${{ env.RELEASE_VERSION }}.zip | awk '{print $1}') - - # ======================================================================= - # Upload artifacts - # This is required to share artifacts between different jobs - # ======================================================================= - - - name: Upload artifacts - uses: actions/upload-artifact@v2 - with: - name: openethereum-linux-${{ env.RELEASE_VERSION }}.zip - path: openethereum-linux-${{ env.RELEASE_VERSION }}.zip - - - name: Upload artifacts - uses: actions/upload-artifact@v2 - with: - name: openethereum-macos-${{ env.RELEASE_VERSION }}.zip - path: openethereum-macos-${{ env.RELEASE_VERSION }}.zip - - # - name: Upload artifacts - # uses: actions/upload-artifact@v2 - # with: - # name: openethereum-windows-${{ env.RELEASE_VERSION }}.zip - # path: openethereum-windows-${{ env.RELEASE_VERSION }}.zip - - # ======================================================================= - # Upload artifacts to S3 - # This is required by some software distribution systems which require - # artifacts to be downloadable, like Brew on MacOS. - # ======================================================================= - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ env.AWS_REGION }} - - - name: Copy files to S3 with the AWS CLI - run: | - # Deploy zip artifacts to S3 bucket to a directory whose name is the tagged release version. - # Deploy macos binary artifact (if required, add more `aws s3 cp` commands to deploy specific OS versions) - aws s3 cp macos-artifacts/openethereum s3://${{ env.AWS_S3_ARTIFACTS_BUCKET }}/${{ env.RELEASE_VERSION }}/macos/ --region ${{ env.AWS_REGION }} - - outputs: - linux-artifact: ${{ steps.create_zip_linux.outputs.LINUX_ARTIFACT }} - linux-shasum: ${{ steps.create_zip_linux.outputs.LINUX_SHASUM }} - macos-artifact: ${{ steps.create_zip_macos.outputs.MACOS_ARTIFACT }} - macos-shasum: ${{ steps.create_zip_macos.outputs.MACOS_SHASUM }} - # windows-artifact: ${{ steps.create_zip_windows.outputs.WINDOWS_ARTIFACT }} - # windows-shasum: ${{ steps.create_zip_windows.outputs.WINDOWS_SHASUM }} - - draft-release: - name: Draft Release - needs: zip-artifacts-creator - runs-on: ubuntu-20.04 - steps: - - name: Set env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - # ============================== - # Download artifacts - # ============================== - - - name: Download artifacts - uses: actions/download-artifact@v2 - with: - name: openethereum-linux-${{ env.RELEASE_VERSION }}.zip - - - name: Download artifacts - uses: actions/download-artifact@v2 - with: - name: openethereum-macos-${{ env.RELEASE_VERSION }}.zip - - # - name: Download artifacts - # uses: actions/download-artifact@v2 - # with: - # name: openethereum-windows-${{ env.RELEASE_VERSION }}.zip - - - name: Display structure of downloaded files - run: ls - - # ============================== - # Create release draft - # ============================== - - - name: Create Release Draft - id: create_release_draft - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag_name: ${{ github.ref }} - release_name: OpenEthereum ${{ github.ref }} - body: | - This release contains - - | System | Architecture | Binary | Sha256 Checksum | - |:---:|:---:|:---:|:---| - | Apple Icon by Pixel Perfect from https://www.flaticon.com/authors/pixel-perfect | x64 | [${{ needs.zip-artifacts-creator.outputs.macos-artifact }}](https://github.com/openethereum/openethereum/releases/download/${{ env.RELEASE_VERSION }}/${{ needs.zip-artifacts-creator.outputs.macos-artifact }}) | `${{ needs.zip-artifacts-creator.outputs.macos-shasum }}` | - | Linux Icon by Pixel Perfect from https://www.flaticon.com/authors/pixel-perfect | x64 | [${{ needs.zip-artifacts-creator.outputs.linux-artifact }}](https://github.com/openethereum/openethereum/releases/download/${{ env.RELEASE_VERSION }}/${{ needs.zip-artifacts-creator.outputs.linux-artifact }}) | `${{ needs.zip-artifacts-creator.outputs.linux-shasum }}` | - | Windows Icon by Pixel Perfect from https://www.flaticon.com/authors/pixel-perfect | x64 | [${{ needs.zip-artifacts-creator.outputs.windows-artifact }}](https://github.com/openethereum/openethereum/releases/download/${{ env.RELEASE_VERSION }}/${{ needs.zip-artifacts-creator.outputs.windows-artifact }}) | `${{ needs.zip-artifacts-creator.outputs.windows-shasum }}` | - | | | | | - | **System** | **Option** | - | **Resource** | - | Settings Icon by Pixel Perfect from https://www.flaticon.com/authors/pixel-perfect | Docker | - | [hub.docker.com/r/openethereum/openethereum](https://hub.docker.com/r/openethereum/openethereum) | - - draft: true - prerelease: true - - - name: Upload Release Asset - Linux - id: upload_release_asset_linux - uses: actions/upload-release-asset@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release_draft.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./openethereum-linux-${{ env.RELEASE_VERSION }}.zip - asset_name: openethereum-linux-${{ env.RELEASE_VERSION }}.zip - asset_content_type: application/zip - - - name: Upload Release Asset - MacOS - id: upload_release_asset_macos - uses: actions/upload-release-asset@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release_draft.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./openethereum-macos-${{ env.RELEASE_VERSION }}.zip - asset_name: openethereum-macos-${{ env.RELEASE_VERSION }}.zip - asset_content_type: application/zip - - # - name: Upload Release Asset - Windows - # id: upload_release_asset_windows - # uses: actions/upload-release-asset@v1 - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # with: - # upload_url: ${{ steps.create_release_draft.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - # asset_path: ./openethereum-windows-${{ env.RELEASE_VERSION }}.zip - # asset_name: openethereum-windows-${{ env.RELEASE_VERSION }}.zip - # asset_content_type: application/zip From 63a9f895b3373d97f575cdf2125f13f352bf0e1a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 23 Oct 2023 21:41:00 +0200 Subject: [PATCH 053/687] branding diamond-node --- crates/util/version/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/util/version/src/lib.rs b/crates/util/version/src/lib.rs index beca730df..93ff5091d 100644 --- a/crates/util/version/src/lib.rs +++ b/crates/util/version/src/lib.rs @@ -82,7 +82,7 @@ pub fn version_data() -> Bytes { .parse::() .expect("Environment variables are known to be valid; qed"); s.append(&v); - s.append(&"OpenEthereum"); + s.append(&"diamond-node"); s.append(&generated::rustc_version()); s.append(&&Target::os()[0..2]); s.out() From 8a2fc50d3aa2acad2cdb2a3c10f87ced2ab94327 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 23 Oct 2023 22:01:07 +0200 Subject: [PATCH 054/687] new cli arg: --shutdown-on-missing-blockproduction Shuts down if no block has been produced for N seconds. Defaults to 1800 (30 Minutes). Set to None to disable this feature Not implemented yet. --- bin/oe/cli/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/oe/cli/mod.rs b/bin/oe/cli/mod.rs index 1b7bdc58f..3aa1f17bc 100644 --- a/bin/oe/cli/mod.rs +++ b/bin/oe/cli/mod.rs @@ -748,6 +748,10 @@ usage! { "--log-file=[FILENAME]", "Specify a filename into which logging should be appended.", + ARG arg_shutdown_on_missing_blockproduction: (Option) = Some(1800), or |c: &Config| c.misc.as_ref()?.shutdown_on_missing_blockproduction.clone(), + "--shutdown-on-missing-blockproduction=[STRING]", + "Shuts down if no block has been produced for N seconds. Defaults to 1800 (30 Minutes). Set to None to disable this feature", + ["Footprint Options"] FLAG flag_scale_verifiers: (bool) = false, or |c: &Config| c.footprint.as_ref()?.scale_verifiers.clone(), "--scale-verifiers", @@ -834,6 +838,7 @@ struct Config { misc: Option, stratum: Option, metrics: Option, + } #[derive(Default, Debug, PartialEq, Deserialize)] @@ -1039,6 +1044,8 @@ struct Misc { color: Option, ports_shift: Option, unsafe_expose: Option, + /// seconds, until the system shuts down if no block has been produced. None disables this feature. + shutdown_on_missing_blockproduction: Option, } #[cfg(test)] From 63e2cf5c00073af089d5130c12f38ea809d25799 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 24 Oct 2023 07:39:43 +0200 Subject: [PATCH 055/687] test implementations for shutdown_on_missing_blockproduction --- bin/oe/cli/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/oe/cli/mod.rs b/bin/oe/cli/mod.rs index 3aa1f17bc..11f455698 100644 --- a/bin/oe/cli/mod.rs +++ b/bin/oe/cli/mod.rs @@ -1457,6 +1457,7 @@ mod tests { arg_log_file: Some("/var/log/openethereum.log".into()), flag_no_color: false, flag_no_config: false, + arg_shutdown_on_missing_blockproduction: Some(1800), } ); } @@ -1647,6 +1648,7 @@ mod tests { color: Some(true), ports_shift: Some(0), unsafe_expose: Some(false), + shutdown_on_missing_blockproduction: None, }), stratum: None, } From e5663f55fe5a6c2e649e144ffd85802f5f4f707d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 24 Oct 2023 13:53:37 +0200 Subject: [PATCH 056/687] implementation of shutdown-on-missing-block-import TODO: Passing through of configuration does not have an effect. it is always 1800 seconds. --- bin/oe/cli/mod.rs | 13 +- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 118 +++++++++++------- 2 files changed, 79 insertions(+), 52 deletions(-) diff --git a/bin/oe/cli/mod.rs b/bin/oe/cli/mod.rs index 11f455698..4c5c5af8a 100644 --- a/bin/oe/cli/mod.rs +++ b/bin/oe/cli/mod.rs @@ -748,9 +748,9 @@ usage! { "--log-file=[FILENAME]", "Specify a filename into which logging should be appended.", - ARG arg_shutdown_on_missing_blockproduction: (Option) = Some(1800), or |c: &Config| c.misc.as_ref()?.shutdown_on_missing_blockproduction.clone(), - "--shutdown-on-missing-blockproduction=[STRING]", - "Shuts down if no block has been produced for N seconds. Defaults to 1800 (30 Minutes). Set to None to disable this feature", + ARG arg_shutdown_on_missing_block_import: (Option) = Some(1800), or |c: &Config| c.misc.as_ref()?.shutdown_on_missing_block_import.clone(), + "--shutdown-on-missing-block-import=[STRING]", + "Shuts down if no block has been imported for N seconds. Defaults to 1800 (30 Minutes). Set to None or 0 to disable this feature. This setting is only respected by the HBBFT Engine", ["Footprint Options"] FLAG flag_scale_verifiers: (bool) = false, or |c: &Config| c.footprint.as_ref()?.scale_verifiers.clone(), @@ -838,7 +838,6 @@ struct Config { misc: Option, stratum: Option, metrics: Option, - } #[derive(Default, Debug, PartialEq, Deserialize)] @@ -1045,7 +1044,7 @@ struct Misc { ports_shift: Option, unsafe_expose: Option, /// seconds, until the system shuts down if no block has been produced. None disables this feature. - shutdown_on_missing_blockproduction: Option, + shutdown_on_missing_block_import: Option, } #[cfg(test)] @@ -1457,7 +1456,7 @@ mod tests { arg_log_file: Some("/var/log/openethereum.log".into()), flag_no_color: false, flag_no_config: false, - arg_shutdown_on_missing_blockproduction: Some(1800), + arg_shutdown_on_missing_block_import: Some(1800), } ); } @@ -1648,7 +1647,7 @@ mod tests { color: Some(true), ports_shift: Some(0), unsafe_expose: Some(false), - shutdown_on_missing_blockproduction: None, + shutdown_on_missing_block_import: None, }), stratum: None, } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 21d767555..ab2f27bae 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -95,6 +95,10 @@ pub struct HoneyBadgerBFT { struct TransitionHandler { client: Arc>>>, engine: Arc, + /// the last known block for the auto shutdown on stuck node feature. + /// https://github.com/DMDcoin/diamond-node/issues/78 + auto_shutdown_last_known_block_number: Mutex, + auto_shutdown_interval_config: Option, } const DEFAULT_DURATION: Duration = Duration::from_secs(1); @@ -153,13 +157,17 @@ impl TransitionHandler { // Arbitrary identifier for the timer we register with the event handler. const ENGINE_TIMEOUT_TOKEN: TimerToken = 1; -const ENGINE_SHUTDOWN_IF_UNAVAILABLE: TimerToken = 2; +const ENGINE_SHUTDOWN: TimerToken = 2; // Some Operations should be executed if the chain is synced to the current tail. const ENGINE_DELAYED_UNITL_SYNCED_TOKEN: TimerToken = 3; // Some Operations have no urge on the timing, but are rather expensive. // those are handeled by this slow ticking timer. const ENGINE_VALIDATOR_CANDIDATE_ACTIONS: TimerToken = 4; +// Timer token for shutdown-on-missing-block-import +// https://github.com/DMDcoin/diamond-node/issues/78 +const ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT: TimerToken = 5; + impl IoHandler<()> for TransitionHandler { fn initialize(&self, io: &IoContext<()>) { // Start the event loop with an arbitrary timer @@ -168,7 +176,7 @@ impl IoHandler<()> for TransitionHandler { |e| warn!(target: "consensus", "Failed to start consensus timer: {}.", e), ); - io.register_timer(ENGINE_SHUTDOWN_IF_UNAVAILABLE, Duration::from_secs(1200)) + io.register_timer(ENGINE_SHUTDOWN, Duration::from_secs(1200)) .unwrap_or_else(|e| warn!(target: "consensus", "HBBFT Shutdown Timer failed: {}.", e)); // io.register_timer_once(ENGINE_DELAYED_UNITL_SYNCED_TOKEN, Duration::from_secs(10)) @@ -176,6 +184,15 @@ impl IoHandler<()> for TransitionHandler { io.register_timer(ENGINE_VALIDATOR_CANDIDATE_ACTIONS, Duration::from_secs(120)) .unwrap_or_else(|e| warn!(target: "consensus", "ENGINE_VALIDATOR_CANDIDATE_ACTIONS Timer failed: {}.", e)); + + // if the auto_shutdown_last_known_block_number + + if let Some(interval) = self.auto_shutdown_interval_config { + if interval > 0 { + io.register_timer(ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT, Duration::from_secs(interval)) + .unwrap_or_else(|e| warn!(target: "consensus", "HBBFT shutdown-on-missing-block-import failed: {}.", e)); + } + } } fn timeout(&self, io: &IoContext<()>, timer: TimerToken) { @@ -229,7 +246,7 @@ impl IoHandler<()> for TransitionHandler { .unwrap_or_else( |e| warn!(target: "consensus", "Failed to restart consensus step timer: {}.", e), ); - } else if timer == ENGINE_SHUTDOWN_IF_UNAVAILABLE { + } else if timer == ENGINE_SHUTDOWN { // we do not run this on the first occurence, // the first occurence could mean that the client is not fully set up // (e.g. it should sync, but it does not know it yet.) @@ -279,60 +296,19 @@ impl IoHandler<()> for TransitionHandler { } } } - //TODO: implement shutdown. - // panic!("Shutdown hard. Todo: implement Soft Shutdown."); - //if let c = self.engine.client.read() { - //} let id: usize = std::process::id() as usize; let thread_id = std::thread::current().id(); - //let child_id = std::process::en; - info!(target: "engine", "Waiting for Signaling shutdown to process ID: {id} thread: {:?}", thread_id); - // Using libc resulted in errors. - // can't a process not send a signal to it's own ?! - - // unsafe { - // let signal_result = libc::signal(libc::SIGTERM, id); - // info!(target: "engine", "Signal result: {signal_result}"); - // } - - //let child = Command::new("/bin/kill") - // .arg(id.to_string()) - // .spawn() - // .expect("failed to execute child"); - - //let kill_id = child.id(); - //info!(target: "engine", "Signaling shutdown SENT to process ID: {id} with process: {kill_id} "); - if let Some(ref weak) = *self.client.read() { if let Some(client) = weak.upgrade() { info!(target: "engine", "demanding shutdown from hbbft engine."); client.demand_shutdown(); } } - - // if let Some(client) = weak.upgrade() { - - // match client.as_full_client() { - // Some(full_client) => { - // //full_client.shutdown(); - // } - // None => { - - // } - // } - - // match client.as_full_client() { - // Some(full_client) => full_client.is_major_syncing(), - // // We only support full clients at this point. - // None => true, - // } - // } - // } } // if the node is available, everythign is fine! } @@ -360,6 +336,56 @@ impl IoHandler<()> for TransitionHandler { if let Err(err) = self.engine.do_validator_engine_actions() { error!(target: "consensus", "do_validator_engine_actions failed: {:?}", err); } + } else if timer == ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT { + // if auto shutdown at missing block production (or import) is configured. + // ... we need to check if enough time has passed since the last block was imported. + let current_block_number_option = if let Some(ref weak) = *self.client.read() { + if let Some(c) = weak.upgrade() { + c.block_number(BlockId::Latest) + + // // let current_block = + // if let Some(mut client_option) = self.engine.client.try_read_for(Duration::from_millis(250)) { + // if let Some(bla) = client_option.take() { + + // } + // } else { + // warn!(target: "consensus", "could not acquire client readlock within time to process ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT"); + // return; + // }; + } else { + return; + } + } else { + return; + }; + + if let Some(current_block_number) = current_block_number_option { + if current_block_number == 0 { + return; + } + + let last_known_block_number: u64 = + self.auto_shutdown_last_known_block_number.lock().clone(); + + if current_block_number == last_known_block_number { + // lock the client and signal shutdown. + warn!("shutdown-on-missing-block-import: Detected stalled block import. Demanding shut down of hbbft engine."); + + // if auto shutdown at missing block production (or import) is configured. + // ... we need to check if enough time has passed since the last block was imported. + if let Some(ref weak) = *self.client.read() { + if let Some(c) = weak.upgrade() { + c.demand_shutdown(); + } else { + error!("shutdown-on-missing-block-import: Error during Shutdown: could not upgrade weak reference."); + } + } else { + error!("shutdown-on-missing-block-import: Error during Shutdown: No client found."); + } + } else { + *self.auto_shutdown_last_known_block_number.lock() = current_block_number; + } + } } } } @@ -401,6 +427,8 @@ impl HoneyBadgerBFT { let handler = TransitionHandler { client: engine.client.clone(), engine: engine.clone(), + auto_shutdown_last_known_block_number: Mutex::new(0), + auto_shutdown_interval_config: Some(1800), }; engine .transition_service @@ -875,7 +903,7 @@ impl HoneyBadgerBFT { false } - // some actions are required for hbbft validator nodes. + // some actions are required for hbbft nodes. // this functions figures out what kind of actions are required and executes them. // this will lock the client and some deeper layers. fn do_validator_engine_actions(&self) -> Result<(), String> { From cea53d101e9b3dfe61a7cdeb6651567509c1ebfc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 26 Oct 2023 23:17:13 +0200 Subject: [PATCH 057/687] EngineClient: config_shutdown_on_missing_block_import --- crates/ethcore/src/client/client.rs | 4 +++ crates/ethcore/src/client/config.rs | 5 ++++ crates/ethcore/src/client/traits.rs | 5 ++++ .../ethcore/src/engines/hbbft/hbbft_engine.rs | 30 ++++++++++--------- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index f05133b1a..2eee969fc 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -3248,6 +3248,10 @@ impl super::traits::EngineClient for Client { self.shutdown.demand_shutdown(); } + fn config_shutdown_on_missing_block_import(&self) -> Option { + self.config.shutdown_on_missing_block_import + } + fn create_pending_block_at( &self, txns: Vec, diff --git a/crates/ethcore/src/client/config.rs b/crates/ethcore/src/client/config.rs index d23f5028b..a023678c5 100644 --- a/crates/ethcore/src/client/config.rs +++ b/crates/ethcore/src/client/config.rs @@ -125,6 +125,10 @@ pub struct ClientConfig { pub transaction_verification_queue_size: usize, /// Maximal number of blocks to import at each round. pub max_round_blocks_to_import: usize, + + /// Shutdown client if block has not happed for n seconds. + pub shutdown_on_missing_block_import: Option, + /// Snapshot configuration pub snapshot: SnapshotConfiguration, } @@ -152,6 +156,7 @@ impl Default for ClientConfig { check_seal: true, transaction_verification_queue_size: 8192, max_round_blocks_to_import: 1, + shutdown_on_missing_block_import: Some(1800), snapshot: Default::default(), } } diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 17bfa670f..836f71115 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -682,6 +682,11 @@ pub trait EngineClient: Sync + Send + ChainInfo { timestamp: u64, block_number: u64, ) -> Option
; + + /// Time in seconds until the Engine shuts down if no Block Import is performed. + fn config_shutdown_on_missing_block_import(&self) -> Option { + None + } } /// Extended client interface for providing proofs of the state. diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index ab2f27bae..9f69aab0d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -153,6 +153,19 @@ impl TransitionHandler { warn!(target: "consensus", "execute_delayed_unitl_synced_operations has been called"); true } + + fn get_shutdown_interval(&self) -> Option { + + if let Some(ref weak) = *self.client.read() { + if let Some(c) = weak.upgrade() { + return c.config_shutdown_on_missing_block_import() + } + return None; + } else { + return None; + }; + } + } // Arbitrary identifier for the timer we register with the event handler. @@ -184,11 +197,10 @@ impl IoHandler<()> for TransitionHandler { io.register_timer(ENGINE_VALIDATOR_CANDIDATE_ACTIONS, Duration::from_secs(120)) .unwrap_or_else(|e| warn!(target: "consensus", "ENGINE_VALIDATOR_CANDIDATE_ACTIONS Timer failed: {}.", e)); - - // if the auto_shutdown_last_known_block_number - - if let Some(interval) = self.auto_shutdown_interval_config { + + if let Some(interval) = self.get_shutdown_interval() { if interval > 0 { + io.register_timer(ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT, Duration::from_secs(interval)) .unwrap_or_else(|e| warn!(target: "consensus", "HBBFT shutdown-on-missing-block-import failed: {}.", e)); } @@ -342,16 +354,6 @@ impl IoHandler<()> for TransitionHandler { let current_block_number_option = if let Some(ref weak) = *self.client.read() { if let Some(c) = weak.upgrade() { c.block_number(BlockId::Latest) - - // // let current_block = - // if let Some(mut client_option) = self.engine.client.try_read_for(Duration::from_millis(250)) { - // if let Some(bla) = client_option.take() { - - // } - // } else { - // warn!(target: "consensus", "could not acquire client readlock within time to process ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT"); - // return; - // }; } else { return; } From e4a47ca30734ec393ef41fda9eb20fb78fdcec61 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 26 Oct 2023 23:18:30 +0200 Subject: [PATCH 058/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 9f69aab0d..8a109425f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -155,17 +155,15 @@ impl TransitionHandler { } fn get_shutdown_interval(&self) -> Option { - if let Some(ref weak) = *self.client.read() { if let Some(c) = weak.upgrade() { - return c.config_shutdown_on_missing_block_import() + return c.config_shutdown_on_missing_block_import(); } return None; } else { return None; }; } - } // Arbitrary identifier for the timer we register with the event handler. @@ -197,10 +195,9 @@ impl IoHandler<()> for TransitionHandler { io.register_timer(ENGINE_VALIDATOR_CANDIDATE_ACTIONS, Duration::from_secs(120)) .unwrap_or_else(|e| warn!(target: "consensus", "ENGINE_VALIDATOR_CANDIDATE_ACTIONS Timer failed: {}.", e)); - - if let Some(interval) = self.get_shutdown_interval() { - if interval > 0 { + if let Some(interval) = self.get_shutdown_interval() { + if interval > 0 { io.register_timer(ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT, Duration::from_secs(interval)) .unwrap_or_else(|e| warn!(target: "consensus", "HBBFT shutdown-on-missing-block-import failed: {}.", e)); } From eec8e50e34a3388ff7fa0a890e632ce683aa3e5b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 27 Oct 2023 19:09:41 +0200 Subject: [PATCH 059/687] glued together args, commands, and client: Configuration of auto shutdown on missing import should work now. to be tested. --- bin/oe/blockchain.rs | 6 ++++++ bin/oe/configuration.rs | 1 + bin/oe/helpers.rs | 2 ++ bin/oe/run.rs | 2 ++ bin/oe/snapshot.rs | 1 + 5 files changed, 12 insertions(+) diff --git a/bin/oe/blockchain.rs b/bin/oe/blockchain.rs index 3a105145d..eb9c10a5c 100644 --- a/bin/oe/blockchain.rs +++ b/bin/oe/blockchain.rs @@ -193,6 +193,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> { cmd.pruning_memory, cmd.check_seal, 12, + None, ); client_config.queue.verifier_settings = cmd.verifier_settings; @@ -279,6 +280,7 @@ fn start_client( cache_config: CacheConfig, require_fat_db: bool, max_round_blocks_to_import: usize, + shutdown_on_missing_block_import: Option, shutdown: ShutdownManager, ) -> Result { // load spec file @@ -333,6 +335,7 @@ fn start_client( pruning_memory, true, max_round_blocks_to_import, + shutdown_on_missing_block_import, ); let restoration_db_handler = db::restoration_db_handler(&client_path, &client_config); @@ -371,6 +374,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result<(), String> { cmd.cache_config, false, cmd.max_round_blocks_to_import, + None, ShutdownManager::null(), )?; let client = service.client(); @@ -401,6 +405,7 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> { cmd.cache_config, true, cmd.max_round_blocks_to_import, + None, ShutdownManager::null(), )?; @@ -520,6 +525,7 @@ fn execute_reset(cmd: ResetBlockchain) -> Result<(), String> { cmd.cache_config, false, 0, + None, ShutdownManager::null(), )?; diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index df7a23daa..567a8af45 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -433,6 +433,7 @@ impl Configuration { no_persistent_txqueue: self.args.flag_no_persistent_txqueue, max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import, metrics_conf, + shutdown_on_missing_block_import: self.args.arg_shutdown_on_missing_block_import, }; Cmd::Run(run_cmd) }; diff --git a/bin/oe/helpers.rs b/bin/oe/helpers.rs index 688ba25e4..0b05cbb1d 100644 --- a/bin/oe/helpers.rs +++ b/bin/oe/helpers.rs @@ -263,6 +263,7 @@ pub fn to_client_config( pruning_memory: usize, check_seal: bool, max_round_blocks_to_import: usize, + shutdown_on_missing_block_import: Option, ) -> ClientConfig { let mut client_config = ClientConfig::default(); @@ -301,6 +302,7 @@ pub fn to_client_config( }; client_config.spec_name = spec_name; client_config.max_round_blocks_to_import = max_round_blocks_to_import; + client_config.shutdown_on_missing_block_import = shutdown_on_missing_block_import; client_config } diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 267862eb9..59488afe7 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -113,6 +113,7 @@ pub struct RunCmd { pub no_persistent_txqueue: bool, pub max_round_blocks_to_import: usize, pub metrics_conf: MetricsConfiguration, + pub shutdown_on_missing_block_import: Option, } // node info fetcher for the local store. @@ -353,6 +354,7 @@ pub fn execute( cmd.pruning_memory, cmd.check_seal, cmd.max_round_blocks_to_import, + cmd.shutdown_on_missing_block_import, ); client_config.queue.verifier_settings = cmd.verifier_settings; diff --git a/bin/oe/snapshot.rs b/bin/oe/snapshot.rs index ac0cc4ffe..137e8c895 100644 --- a/bin/oe/snapshot.rs +++ b/bin/oe/snapshot.rs @@ -221,6 +221,7 @@ impl SnapshotCommand { self.pruning_memory, true, self.max_round_blocks_to_import, + None, ); client_config.snapshot = self.snapshot_conf; From 53db43f652debb6d715c77397babd57771b1868d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 27 Oct 2023 20:28:00 +0200 Subject: [PATCH 060/687] changed default value of shutdown-on-missing-block-import to none --- bin/oe/cli/mod.rs | 6 +++--- bin/oe/configuration.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/oe/cli/mod.rs b/bin/oe/cli/mod.rs index 4c5c5af8a..6079a663f 100644 --- a/bin/oe/cli/mod.rs +++ b/bin/oe/cli/mod.rs @@ -748,9 +748,9 @@ usage! { "--log-file=[FILENAME]", "Specify a filename into which logging should be appended.", - ARG arg_shutdown_on_missing_block_import: (Option) = Some(1800), or |c: &Config| c.misc.as_ref()?.shutdown_on_missing_block_import.clone(), + ARG arg_shutdown_on_missing_block_import: (Option) = None, or |c: &Config| c.misc.as_ref()?.shutdown_on_missing_block_import.clone(), "--shutdown-on-missing-block-import=[STRING]", - "Shuts down if no block has been imported for N seconds. Defaults to 1800 (30 Minutes). Set to None or 0 to disable this feature. This setting is only respected by the HBBFT Engine", + "Shuts down if no block has been imported for N seconds. Defaults to None. Set to None or 0 to disable this feature. This setting is only respected by the HBBFT Engine", ["Footprint Options"] FLAG flag_scale_verifiers: (bool) = false, or |c: &Config| c.footprint.as_ref()?.scale_verifiers.clone(), @@ -1456,7 +1456,7 @@ mod tests { arg_log_file: Some("/var/log/openethereum.log".into()), flag_no_color: false, flag_no_config: false, - arg_shutdown_on_missing_block_import: Some(1800), + arg_shutdown_on_missing_block_import: None, } ); } diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 567a8af45..6788f6b38 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -1571,6 +1571,7 @@ mod tests { no_persistent_txqueue: false, max_round_blocks_to_import: 1, metrics_conf: MetricsConfiguration::default(), + shutdown_on_missing_block_import: None, }; expected.secretstore_conf.enabled = cfg!(feature = "secretstore"); expected.secretstore_conf.http_enabled = cfg!(feature = "secretstore"); From d38797469db6c813daaf0493406e97ac4ac01465 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 27 Oct 2023 21:47:22 +0200 Subject: [PATCH 061/687] change log --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 707d6c943..711c8a4b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +## Diamond Node Software 3.3.5-hbbft-0.9.3 + +[Autoshutdown after a period without block creation] https://github.com/DMDcoin/diamond-node/issues/78 + +to activate feature via CLI Arg: +`--shutdown-on-missing-block-import=1800` + +or in node.toml +node.toml: +``` +[Misc] +shutdown_on_missing_block_import = 1800 +``` + + ## Diamond Node Software 3.3.5-hbbft-0.9.2 - [FIXED: pruning as root cause for stage 3 errors] https://github.com/DMDcoin/diamond-node/issues/68 From 81a283731cbf850e3135bef5e217a5e1b1d5ba83 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 27 Oct 2023 21:50:48 +0200 Subject: [PATCH 062/687] version update in Cargo files --- CHANGELOG.md | 1 - Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 711c8a4b2..dd5e17cfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,6 @@ node.toml: shutdown_on_missing_block_import = 1800 ``` - ## Diamond Node Software 3.3.5-hbbft-0.9.2 - [FIXED: pruning as root cause for stage 3 errors] https://github.com/DMDcoin/diamond-node/issues/68 diff --git a/Cargo.lock b/Cargo.lock index a3022cd0f..cf989d225 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -806,7 +806,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.9.2" +version = "3.3.5-hbbft-0.9.3" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3548,7 +3548,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.9.2" +version = "3.3.5-hbbft-0.9.3" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 92c53edfe..3bf5201a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.9.2" +version = "3.3.5-hbbft-0.9.3" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index a378be83e..de527cf69 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.9.2" +version = "3.3.5-hbbft-0.9.3" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 79e1c350b9aebe4ff7d43d694e4c58379a99df57 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 28 Oct 2023 11:18:18 +0200 Subject: [PATCH 063/687] unit test should_parse_shutdown_on_missing_block_import --- bin/oe/configuration.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 6788f6b38..21f8cd58d 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -2046,4 +2046,16 @@ mod tests { _ => panic!("Should be Cmd::Run"), } } + + #[test] + fn should_parse_shutdown_on_missing_block_import() { + let args = vec!["openethereum", "--shutdown-on-missing-block-import=1234"]; + let conf = Configuration::parse_cli(&args).unwrap(); + match conf.into_command().unwrap().cmd { + Cmd::Run(c) => { + assert_eq!(c.shutdown_on_missing_block_import, Some(1234)); + } + _ => panic!("Should be Cmd::Run"), + } + } } From 0e61077723ed4da26a841bd7485e881268d05632 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 28 Oct 2023 11:20:07 +0200 Subject: [PATCH 064/687] log level reduced to debug for "Detected attempt from pruning ancient block that is still required by the engine. protected block" --- crates/ethcore/src/client/client.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 2eee969fc..dab31cf86 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -1327,8 +1327,7 @@ impl Client { // if the engine still needs that block, we are not going to prune it. if let Some(protected_block) = self.engine.pruning_protection_block_number() { if earliest_era > protected_block { - info!(target: "pruning", "Detected attempt from pruning ancient block that is still required by the engine. protected block: {protected_block}, earliest_era: {earliest_era}"); - //earliest_era = protected_block - 1; + debug!(target: "pruning", "Detected attempt from pruning ancient block that is still required by the engine. protected block: {protected_block}, earliest_era: {earliest_era}"); break; } } From c90404425935dbffd2ce5c730b0b0170aee89c4c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 28 Oct 2023 11:22:46 +0200 Subject: [PATCH 065/687] unused import cleanup --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 8a109425f..85dae3eeb 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -60,8 +60,6 @@ use engines::hbbft::{ }; use std::{ops::Deref, sync::atomic::Ordering}; -use std::process::Command; - type TargetedMessage = hbbft::TargetedMessage; /// A message sent between validators that is part of Honey Badger BFT or the block sealing process. From a31211c6d26756fc4c9ff6fc32538e90f8284285 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 28 Oct 2023 11:36:08 +0200 Subject: [PATCH 066/687] loggin: setting up shutdown-on-missing-block-import timer with interval --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 85dae3eeb..095040901 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -196,6 +196,7 @@ impl IoHandler<()> for TransitionHandler { if let Some(interval) = self.get_shutdown_interval() { if interval > 0 { + info!(target: "consensus", "setting up shutdown-on-missing-block-import timer with interval {interval}"); io.register_timer(ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT, Duration::from_secs(interval)) .unwrap_or_else(|e| warn!(target: "consensus", "HBBFT shutdown-on-missing-block-import failed: {}.", e)); } From b12f7dd12c5a52669c43ec772c8115fb1ac7de36 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 28 Oct 2023 17:52:53 +0200 Subject: [PATCH 067/687] logging if shutdown-on-missing-block-import is not configured --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 095040901..b6bf26161 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -200,6 +200,8 @@ impl IoHandler<()> for TransitionHandler { io.register_timer(ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT, Duration::from_secs(interval)) .unwrap_or_else(|e| warn!(target: "consensus", "HBBFT shutdown-on-missing-block-import failed: {}.", e)); } + } else { + info!(target: "consensus", "shutdown-on-missing-block-import is not configured."); } } From c59a0bc4bd096a2d9072fa3e5df57b2adb998cd2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 28 Oct 2023 17:56:59 +0200 Subject: [PATCH 068/687] warning if get_shutdown_interval() cannot be read. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index b6bf26161..a35e290e0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -157,8 +157,10 @@ impl TransitionHandler { if let Some(c) = weak.upgrade() { return c.config_shutdown_on_missing_block_import(); } + warn!(target: "consensus", "shutdown-on-missing-block-import Could not upgrade weak reference to client."); return None; } else { + warn!(target: "consensus", "shutdown-on-missing-block-import Could not read client."); return None; }; } From ab4acd6ebffa6990399c526172b7a2f5e05ec095 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 28 Oct 2023 19:44:53 +0200 Subject: [PATCH 069/687] rewritten shutdown-on-missing-block-import: It is now part of the main timer of HBBFT, instead of setting up an own timer, what was not possible, since the client is not available during setup phase of the timers. this is an experimental version - to be tested. --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 162 ++++++++++-------- 1 file changed, 93 insertions(+), 69 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index a35e290e0..4f76a9ae6 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -31,7 +31,7 @@ use std::{ convert::TryFrom, ops::BitXor, sync::{atomic::AtomicBool, Arc, Weak}, - time::Duration, + time::{Duration, Instant}, }; use types::{ header::{ExtendedHeader, Header}, @@ -96,7 +96,7 @@ struct TransitionHandler { /// the last known block for the auto shutdown on stuck node feature. /// https://github.com/DMDcoin/diamond-node/issues/78 auto_shutdown_last_known_block_number: Mutex, - auto_shutdown_interval_config: Option, + auto_shutdown_last_known_block_import: Mutex, } const DEFAULT_DURATION: Duration = Duration::from_secs(1); @@ -151,19 +151,6 @@ impl TransitionHandler { warn!(target: "consensus", "execute_delayed_unitl_synced_operations has been called"); true } - - fn get_shutdown_interval(&self) -> Option { - if let Some(ref weak) = *self.client.read() { - if let Some(c) = weak.upgrade() { - return c.config_shutdown_on_missing_block_import(); - } - warn!(target: "consensus", "shutdown-on-missing-block-import Could not upgrade weak reference to client."); - return None; - } else { - warn!(target: "consensus", "shutdown-on-missing-block-import Could not read client."); - return None; - }; - } } // Arbitrary identifier for the timer we register with the event handler. @@ -175,9 +162,90 @@ const ENGINE_DELAYED_UNITL_SYNCED_TOKEN: TimerToken = 3; // those are handeled by this slow ticking timer. const ENGINE_VALIDATOR_CANDIDATE_ACTIONS: TimerToken = 4; -// Timer token for shutdown-on-missing-block-import -// https://github.com/DMDcoin/diamond-node/issues/78 -const ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT: TimerToken = 5; +impl TransitionHandler { + fn handle_shutdown_on_missing_block_import( + &self, + shutdown_on_missing_block_import_config_option: Option, + ) { + let mut shutdown_on_missing_block_import_config: u64 = 0; + + if let Some(c) = shutdown_on_missing_block_import_config_option { + if c == 0 { + // if shutdown_on_missing_block_import is configured to 0, we do not have to do anything. + return; + } + shutdown_on_missing_block_import_config = c; + } else { + // if shutdown_on_missing_block_import is not configured at all, we do not have to do anything. + return; + } + + // ... we need to check if enough time has passed since the last block was imported. + let current_block_number_option = if let Some(ref weak) = *self.client.read() { + if let Some(c) = weak.upgrade() { + c.block_number(BlockId::Latest) + } else { + warn!(target: "consensus", "shutdown-on-missing-block-import: Could not upgrade weak reference to client."); + return; + } + } else { + warn!(target: "consensus", "shutdown-on-missing-block-import: Could not read client."); + return; + }; + + let now = std::time::Instant::now(); + + if let Some(current_block_number) = current_block_number_option { + if current_block_number <= 1 { + // we do not do an auto shutdown for the first block. + // it is normal for a network to have no blocks at the beginning, until everything is settled. + return; + } + + let last_known_block_number: u64 = + self.auto_shutdown_last_known_block_number.lock().clone(); + + if current_block_number == last_known_block_number { + // if the last known block number is the same as the current block number, + // we have not imported a new block since the last check. + // we need to check if enough time has passed since the last check. + + let last_known_block_import = + self.auto_shutdown_last_known_block_import.lock().clone(); + let duration_since_last_block_import = + now.duration_since(last_known_block_import).as_secs(); + + if duration_since_last_block_import < shutdown_on_missing_block_import_config { + // if the time since the last block import is less than the configured interval, + // we do not have to do anything. + return; + } + + // lock the client and signal shutdown. + warn!("shutdown-on-missing-block-import: Detected stalled block import. no import for {duration_since_last_block_import}. last known import: {:?} now: {:?} Demanding shut down of hbbft engine.", last_known_block_import, now); + + // if auto shutdown at missing block production (or import) is configured. + // ... we need to check if enough time has passed since the last block was imported. + if let Some(ref weak) = *self.client.read() { + if let Some(c) = weak.upgrade() { + c.demand_shutdown(); + } else { + error!("shutdown-on-missing-block-import: Error during Shutdown: could not upgrade weak reference."); + } + } else { + error!( + "shutdown-on-missing-block-import: Error during Shutdown: No client found." + ); + } + } else { + *self.auto_shutdown_last_known_block_import.lock() = now; + *self.auto_shutdown_last_known_block_number.lock() = current_block_number; + } + } else { + warn!(target: "consensus", "shutdown-on-missing-block-import: Could not read current block number."); + } + } +} impl IoHandler<()> for TransitionHandler { fn initialize(&self, io: &IoContext<()>) { @@ -195,32 +263,28 @@ impl IoHandler<()> for TransitionHandler { io.register_timer(ENGINE_VALIDATOR_CANDIDATE_ACTIONS, Duration::from_secs(120)) .unwrap_or_else(|e| warn!(target: "consensus", "ENGINE_VALIDATOR_CANDIDATE_ACTIONS Timer failed: {}.", e)); - - if let Some(interval) = self.get_shutdown_interval() { - if interval > 0 { - info!(target: "consensus", "setting up shutdown-on-missing-block-import timer with interval {interval}"); - io.register_timer(ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT, Duration::from_secs(interval)) - .unwrap_or_else(|e| warn!(target: "consensus", "HBBFT shutdown-on-missing-block-import failed: {}.", e)); - } - } else { - info!(target: "consensus", "shutdown-on-missing-block-import is not configured."); - } } fn timeout(&self, io: &IoContext<()>, timer: TimerToken) { if timer == ENGINE_TIMEOUT_TOKEN { + let mut shutdown_on_missing_block_import_config: Option = None; + // trace!(target: "consensus", "Honey Badger IoHandler timeout called"); // The block may be complete, but not have been ready to seal - trigger a new seal attempt. // TODO: In theory, that should not happen. The seal is ready exactly when the sealing entry is `Complete`. if let Some(ref weak) = *self.client.read() { if let Some(c) = weak.upgrade() { c.update_sealing(ForceUpdateSealing::No); + shutdown_on_missing_block_import_config = + c.config_shutdown_on_missing_block_import(); } } // Periodically allow messages received for future epochs to be processed. self.engine.replay_cached_messages(); + self.handle_shutdown_on_missing_block_import(shutdown_on_missing_block_import_config); + // The client may not be registered yet on startup, we set the default duration. let mut timer_duration = DEFAULT_DURATION; if let Some(ref weak) = *self.client.read() { @@ -348,46 +412,6 @@ impl IoHandler<()> for TransitionHandler { if let Err(err) = self.engine.do_validator_engine_actions() { error!(target: "consensus", "do_validator_engine_actions failed: {:?}", err); } - } else if timer == ENGINE_SHUTDOWN_ON_MISSING_BLOCK_IMPORT { - // if auto shutdown at missing block production (or import) is configured. - // ... we need to check if enough time has passed since the last block was imported. - let current_block_number_option = if let Some(ref weak) = *self.client.read() { - if let Some(c) = weak.upgrade() { - c.block_number(BlockId::Latest) - } else { - return; - } - } else { - return; - }; - - if let Some(current_block_number) = current_block_number_option { - if current_block_number == 0 { - return; - } - - let last_known_block_number: u64 = - self.auto_shutdown_last_known_block_number.lock().clone(); - - if current_block_number == last_known_block_number { - // lock the client and signal shutdown. - warn!("shutdown-on-missing-block-import: Detected stalled block import. Demanding shut down of hbbft engine."); - - // if auto shutdown at missing block production (or import) is configured. - // ... we need to check if enough time has passed since the last block was imported. - if let Some(ref weak) = *self.client.read() { - if let Some(c) = weak.upgrade() { - c.demand_shutdown(); - } else { - error!("shutdown-on-missing-block-import: Error during Shutdown: could not upgrade weak reference."); - } - } else { - error!("shutdown-on-missing-block-import: Error during Shutdown: No client found."); - } - } else { - *self.auto_shutdown_last_known_block_number.lock() = current_block_number; - } - } } } } @@ -430,7 +454,7 @@ impl HoneyBadgerBFT { client: engine.client.clone(), engine: engine.clone(), auto_shutdown_last_known_block_number: Mutex::new(0), - auto_shutdown_interval_config: Some(1800), + auto_shutdown_last_known_block_import: Mutex::new(Instant::now()), }; engine .transition_service From 7b85a4e69dff5c444187c865f79804c2733414d7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 28 Oct 2023 20:58:37 +0200 Subject: [PATCH 070/687] updated changelog for 0.9.3 --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd5e17cfc..9f14a3c79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## Diamond Node Software 3.3.5-hbbft-0.9.3 -[Autoshutdown after a period without block creation] https://github.com/DMDcoin/diamond-node/issues/78 +[Autoshutdown after a period without block import] https://github.com/DMDcoin/diamond-node/issues/78 + +Those examples show how to confige the node to activate this feature, restarting the node if no block import has been detected for 1800 seconds (30 minutes) to activate feature via CLI Arg: `--shutdown-on-missing-block-import=1800` From 6b34c53cbf11f1db82eae5060751fcde32644270 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 28 Oct 2023 23:44:40 +0200 Subject: [PATCH 071/687] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index cc1c3a38c..ed4d9b415 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ Node client for the protocol version 4 of the bit.diamonds network. [![GPL licensed][license-badge]][license-url] -[![Build Status][ci-badge]][ci-url] -[![Discord chat][chat-badge]][chat-url] [license-badge]: https://img.shields.io/badge/license-GPL_v3-green.svg [license-url]: LICENSE From 24ca361f24dd418d4509c0838550fd36480a6795 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 2 Nov 2023 15:38:45 +0100 Subject: [PATCH 072/687] Fixed warnings in all files except in message_memorium and peers_management --- crates/concensus/ethash/src/shared.rs | 15 ++++++++++----- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- crates/ethcore/src/miner/pool_client.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/concensus/ethash/src/shared.rs b/crates/concensus/ethash/src/shared.rs index 4f72b61a8..4bbd16f5e 100644 --- a/crates/concensus/ethash/src/shared.rs +++ b/crates/concensus/ethash/src/shared.rs @@ -70,6 +70,10 @@ pub type NodeBytes = [u8; NODE_BYTES]; pub type NodeWords = [u32; NODE_WORDS]; pub type NodeDwords = [u64; NODE_DWORDS]; +unsafe trait AsBigAsUsize: Sized { + const _DUMMY: [(); 0]; +} + macro_rules! static_assert_size_eq { (@inner $a:ty, $b:ty, $($rest:ty),*) => { fn first() { @@ -81,10 +85,11 @@ macro_rules! static_assert_size_eq { } }; (@inner $a:ty, $b:ty) => { - unsafe { - let val: $b = ::mem::MaybeUninit::uninit().assume_init(); - let _: $a = ::std::mem::transmute(val); - } + unsafe impl AsBigAsUsize for $a { + #[allow(dead_code)] + const _DUMMY: [(); 0] = + [(); (::std::mem::size_of::<$a>() - ::std::mem::size_of::<$b>())]; + } }; ($($rest:ty),*) => { static_assert_size_eq!(size_eq: $($rest),*); @@ -97,7 +102,7 @@ macro_rules! static_assert_size_eq { }; } -static_assert_size_eq!(Node, NodeBytes, NodeWords, NodeDwords); +static_assert_size_eq!(Node, NodeBytes, NodeWords); #[repr(C)] pub union Node { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 4f76a9ae6..d97cf6e3c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -167,7 +167,7 @@ impl TransitionHandler { &self, shutdown_on_missing_block_import_config_option: Option, ) { - let mut shutdown_on_missing_block_import_config: u64 = 0; + let shutdown_on_missing_block_import_config: u64; if let Some(c) = shutdown_on_missing_block_import_config_option { if c == 0 { diff --git a/crates/ethcore/src/miner/pool_client.rs b/crates/ethcore/src/miner/pool_client.rs index 1d549ef56..33eaa2d37 100644 --- a/crates/ethcore/src/miner/pool_client.rs +++ b/crates/ethcore/src/miner/pool_client.rs @@ -134,7 +134,7 @@ impl<'a, C: 'a> Clone for PoolClient<'a, C> { cached_nonces: self.cached_nonces.clone(), cached_balances: self.cached_balances.clone(), engine: self.engine, - accounts: self.accounts.clone(), + accounts: self.accounts, best_block_header: self.best_block_header.clone(), service_transaction_checker: self.service_transaction_checker.clone(), } diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 3ceb3fc30..c3a81bbf1 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -830,7 +830,7 @@ impl ChainSync { pub fn status(&self) -> SyncStatus { let last_imported_number = self.new_blocks.last_imported_block_number(); let mut item_sizes = BTreeMap::::new(); - self.old_blocks + let _ = self.old_blocks .as_ref() .map_or((), |d| d.get_sizes(&mut item_sizes)); self.new_blocks.get_sizes(&mut item_sizes); From b1fe40759ee52ff3a111964cf33b90fd15a2acb5 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 2 Nov 2023 20:50:45 +0100 Subject: [PATCH 073/687] Temporarily deactivated warnings in the message_memorium implementation --- crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index f981aec34..0de31d754 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -1,3 +1,6 @@ +// Temporarily deactivated warnings, remove after implementation is complete. +#![allow(warnings)] + use bytes::ToPretty; //use hbbft::honey_badger::{self, MessageContent}; use hbbft::honey_badger::{self}; From 81911095e79c35028d6ec535e2072f57de3676b9 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Fri, 3 Nov 2023 08:45:13 +0100 Subject: [PATCH 074/687] rustfmt fix --- crates/ethcore/sync/src/chain/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index c3a81bbf1..ebca850af 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -830,7 +830,8 @@ impl ChainSync { pub fn status(&self) -> SyncStatus { let last_imported_number = self.new_blocks.last_imported_block_number(); let mut item_sizes = BTreeMap::::new(); - let _ = self.old_blocks + let _ = self + .old_blocks .as_ref() .map_or((), |d| d.get_sizes(&mut item_sizes)); self.new_blocks.get_sizes(&mut item_sizes); From 3aa6cab0aa2e630b44ab0c96a998e17dd7719eb8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Nov 2023 23:04:01 +0100 Subject: [PATCH 075/687] format --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index d97cf6e3c..0f0d1ed0b 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -374,9 +374,7 @@ impl IoHandler<()> for TransitionHandler { } let id: usize = std::process::id() as usize; - let thread_id = std::thread::current().id(); - info!(target: "engine", "Waiting for Signaling shutdown to process ID: {id} thread: {:?}", thread_id); if let Some(ref weak) = *self.client.read() { From 061e160efd341f0e1b7a8407dd2adf89cff9947f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 4 Nov 2023 22:48:53 +0100 Subject: [PATCH 076/687] ChainSyncing::is_syncing(&self) : are we syncing in any means ? hbbft engine does now use is_syncing instead of is_major_syncing. both values are tracked now in the prometheus interface. --- bin/oe/run.rs | 13 +++++++++++++ crates/ethcore/src/client/client.rs | 18 +++++++++++++++--- crates/ethcore/src/client/traits.rs | 9 ++++++++- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- crates/rpc/src/v1/helpers/block_import.rs | 1 + 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 59488afe7..76b0cff03 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -59,6 +59,7 @@ use node_filter::NodeFilter; use parity_rpc::{informant, is_major_importing, NetworkSettings}; use parity_runtime::Runtime; use parity_version::version; +use sync::SyncState; // How often we attempt to take a snapshot: only snapshot on blocknumbers that are multiples of this. const SNAPSHOT_PERIOD: u64 = 20000; @@ -160,6 +161,18 @@ impl ChainSyncing for SyncProviderWrapper { None => true, } } + + /// are we syncing in any means ? + fn is_syncing(&self) -> bool { + + match self.sync_provider.upgrade() { + Some(sync_arc) => { + return sync_arc.status().state != SyncState::Idle; + }, + // We also indicate the "syncing" state when the SyncProvider has already been destroyed. + None => true, + } + } } /// Executes the given run command. diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index dab31cf86..1024211d4 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -2886,6 +2886,16 @@ impl BlockChainClient for Client { } } + fn is_syncing(&self) -> bool { + // so far we know, this lock cannot result into a deadlock. + match &*self.sync_provider.lock() { + Some(sync_provider) => sync_provider.is_syncing(), + // We also indicate the "syncing" state when the SyncProvider has not been set, + // which usually only happens when the client is not fully configured yet. + None => true, + } + } + fn next_nonce(&self, address: &Address) -> U256 { self.importer.miner.next_nonce(self, address) } @@ -3652,9 +3662,11 @@ impl PrometheusMetrics for Client { chain.best_block_number as i64, ); - let is_syncing_val: i64 = self.is_major_syncing() as i64; - // 0 or 1 if we are syncing. - r.register_gauge("is_major_syncing", "syncing, boolean", is_syncing_val); + // 0 or 1 if we are major syncing. + r.register_gauge("is_major_syncing", "syncing, boolean", self.is_major_syncing() as i64); + + + r.register_gauge("is_syncing", "syncing, boolean", self.is_syncing() as i64); // prunning info let prunning = self.pruning_info(); diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 836f71115..26a42bc30 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -215,6 +215,10 @@ pub trait EngineInfo { /// Provides information about the chain sync state. pub trait ChainSyncing: Send + Sync { + + /// are we syncing? + fn is_syncing(&self) -> bool; + /// are we in the middle of a major sync? fn is_major_syncing(&self) -> bool; } @@ -524,9 +528,12 @@ pub trait BlockChainClient: /// Used by engines to queue transactions without causing deadlocks due to re-entrant calls. fn transact_silently(&self, tx_request: TransactionRequest) -> Result<(), transaction::Error>; - /// Returns true if the chain is currently syncing. + /// Returns true if the chain is currently syncing in major states. fn is_major_syncing(&self) -> bool; + // Returns true if the chain is currently syncing. + fn is_syncing(&self) -> bool; + /// Returns the next nonce for the given address, taking the transaction queue into account. fn next_nonce(&self, address: &Address) -> U256; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index d97cf6e3c..21fc8bbcc 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1153,7 +1153,7 @@ impl HoneyBadgerBFT { fn is_syncing(&self, client: &Arc) -> bool { match client.as_full_client() { - Some(full_client) => full_client.is_major_syncing(), + Some(full_client) => full_client.is_syncing(), // We only support full clients at this point. None => true, } diff --git a/crates/rpc/src/v1/helpers/block_import.rs b/crates/rpc/src/v1/helpers/block_import.rs index b97933428..3d817f548 100644 --- a/crates/rpc/src/v1/helpers/block_import.rs +++ b/crates/rpc/src/v1/helpers/block_import.rs @@ -26,6 +26,7 @@ pub fn is_major_importing_or_waiting( queue_info: BlockQueueInfo, waiting_is_syncing_state: bool, ) -> bool { + let is_syncing_state = sync_state.map_or(false, |s| match s { SyncState::Idle | SyncState::NewBlocks => false, SyncState::WaitingPeers if !waiting_is_syncing_state => false, From 5b1ce146f9ce0266cbac0cfa8ee3d2822c56bc88 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 5 Nov 2023 13:38:35 +0100 Subject: [PATCH 077/687] is_syncing() for BlockChainTestClient + cargo fmt --all -- --config imports_granularity=Crate --- bin/oe/run.rs | 3 +-- crates/ethcore/src/client/client.rs | 7 +++++-- crates/ethcore/src/client/test_client.rs | 4 ++++ crates/ethcore/src/client/traits.rs | 1 - crates/rpc/src/v1/helpers/block_import.rs | 1 - 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 76b0cff03..ff19042e2 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -164,11 +164,10 @@ impl ChainSyncing for SyncProviderWrapper { /// are we syncing in any means ? fn is_syncing(&self) -> bool { - match self.sync_provider.upgrade() { Some(sync_arc) => { return sync_arc.status().state != SyncState::Idle; - }, + } // We also indicate the "syncing" state when the SyncProvider has already been destroyed. None => true, } diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 1024211d4..e6857c03f 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -3663,8 +3663,11 @@ impl PrometheusMetrics for Client { ); // 0 or 1 if we are major syncing. - r.register_gauge("is_major_syncing", "syncing, boolean", self.is_major_syncing() as i64); - + r.register_gauge( + "is_major_syncing", + "syncing, boolean", + self.is_major_syncing() as i64, + ); r.register_gauge("is_syncing", "syncing, boolean", self.is_syncing() as i64); diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index 1cf8e308f..df9a7dcd5 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -1114,6 +1114,10 @@ impl BlockChainClient for TestBlockChainClient { false } + fn is_syncing(&self) -> bool { + false + } + fn next_nonce(&self, address: &Address) -> U256 { self.miner.next_nonce(self, address) } diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 26a42bc30..63afe1229 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -215,7 +215,6 @@ pub trait EngineInfo { /// Provides information about the chain sync state. pub trait ChainSyncing: Send + Sync { - /// are we syncing? fn is_syncing(&self) -> bool; diff --git a/crates/rpc/src/v1/helpers/block_import.rs b/crates/rpc/src/v1/helpers/block_import.rs index 3d817f548..b97933428 100644 --- a/crates/rpc/src/v1/helpers/block_import.rs +++ b/crates/rpc/src/v1/helpers/block_import.rs @@ -26,7 +26,6 @@ pub fn is_major_importing_or_waiting( queue_info: BlockQueueInfo, waiting_is_syncing_state: bool, ) -> bool { - let is_syncing_state = sync_state.map_or(false, |s| match s { SyncState::Idle | SyncState::NewBlocks => false, SyncState::WaitingPeers if !waiting_is_syncing_state => false, From c30c0b619a1715577d713f3d65d7096d8b1f3f4f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Nov 2023 09:59:39 +0100 Subject: [PATCH 078/687] hbbft peers management: improved error messag --- crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index f5b44f53f..a67438847 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -318,7 +318,7 @@ impl HbbftPeersManagement { let mut guard = client .reserved_peers_management() .try_lock_for(Duration::from_millis(100)) - .ok_or("Error".to_string())?; + .ok_or("Could not acquire reserved peers management within 100ms".to_string())?; if let Some(reserved_peers_management) = guard.as_deref_mut() { let mut kept_peers = Vec::::new(); From 5ef3d6a5897efe303ee0c3ffaac05271fffe3944 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Nov 2023 09:59:49 +0100 Subject: [PATCH 079/687] prometheus update --- crates/util/stats/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/util/stats/Cargo.toml b/crates/util/stats/Cargo.toml index 47e8d20af..724270c19 100644 --- a/crates/util/stats/Cargo.toml +++ b/crates/util/stats/Cargo.toml @@ -5,5 +5,5 @@ authors = ["Parity Technologies "] [dependencies] log = "0.4" -prometheus = "0.13.0" +prometheus = "0.13.3" vergen = "0.1" \ No newline at end of file From bb0984fbede1f8b772555d46c17289518b772070 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Nov 2023 10:34:03 +0100 Subject: [PATCH 080/687] added real prometheus labels again. --- crates/util/stats/src/lib.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/util/stats/src/lib.rs b/crates/util/stats/src/lib.rs index 3cf827451..2aafa8406 100644 --- a/crates/util/stats/src/lib.rs +++ b/crates/util/stats/src/lib.rs @@ -72,17 +72,31 @@ impl PrometheusRegistry { /// Adds a new prometheus gauge with a label pub fn register_gauge_with_label(&mut self, name: &str, help: &str, label: &str, value: i64) { - let label_formated = format!("{}{}", name, label); + //let label_formated = format!("{}{}", name, label); // let label_formated = format!("{}{}", self.prefix, name); - let opts = prometheus::Opts::new(label_formated, help); + let mut opts = prometheus::Opts::new(name, help); // add labels here . - //&&opts.variable_labels.push(label.to_string()); + opts.variable_labels.push(label.to_string()); + + //prometheus::push_metrics() + + //let mut labels = HashMap::new(); + // labels.insert(label, value.to_string()); + + // Custom metrics, to be collected by a dedicated registry. + + // registry.register(Box::new(CUSTOM_COUNTER.clone())).unwrap(); + + // self.registry. + + // CUSTOM_COUNTER.inc_by(42); + // assert_eq!(CUSTOM_COUNTER.get(), 42); + // } match prometheus::IntGauge::with_opts(opts) { Ok(g) => { g.set(value); - self.registry .register(Box::new(g)) .expect("prometheus identifiers must be are unique"); From 7b198a04b9d0ab6fc743458a4d5b2b4f71a3d0d1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Nov 2023 10:58:42 +0100 Subject: [PATCH 081/687] experimental try for adding label. --- crates/util/stats/src/lib.rs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/crates/util/stats/src/lib.rs b/crates/util/stats/src/lib.rs index 2aafa8406..074d1ee29 100644 --- a/crates/util/stats/src/lib.rs +++ b/crates/util/stats/src/lib.rs @@ -72,27 +72,9 @@ impl PrometheusRegistry { /// Adds a new prometheus gauge with a label pub fn register_gauge_with_label(&mut self, name: &str, help: &str, label: &str, value: i64) { - //let label_formated = format!("{}{}", name, label); - // let label_formated = format!("{}{}", self.prefix, name); - let mut opts = prometheus::Opts::new(name, help); - + let opts = prometheus::Opts::new(name, help).const_label("other_node", label); // add labels here . - opts.variable_labels.push(label.to_string()); - - //prometheus::push_metrics() - - //let mut labels = HashMap::new(); - // labels.insert(label, value.to_string()); - - // Custom metrics, to be collected by a dedicated registry. - - // registry.register(Box::new(CUSTOM_COUNTER.clone())).unwrap(); - - // self.registry. - - // CUSTOM_COUNTER.inc_by(42); - // assert_eq!(CUSTOM_COUNTER.get(), 42); - // } + //opts.variable_labels.push(label.to_string()); match prometheus::IntGauge::with_opts(opts) { Ok(g) => { From 8562350651229770b50aeffbe5115480d771edd9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Nov 2023 19:41:58 +0100 Subject: [PATCH 082/687] other_node labels without n-prefix --- crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 0de31d754..37d384cf9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -989,7 +989,7 @@ impl PrometheusMetrics for NodeStakingEpochHistory { let node_id = self.get_node_id().0 .0; let label = std::format!( - "n{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", + "{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", node_id[0], node_id[1], node_id[2], From ffab76b3ded0c783e722b512a0e77ae22c1a6e62 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Nov 2023 19:48:23 +0100 Subject: [PATCH 083/687] prometheus: fixed bug where last_message_good gauge was displaying the last_message_faulty value. --- crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 37d384cf9..d0ef9be50 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -1061,14 +1061,14 @@ impl PrometheusMetrics for NodeStakingEpochHistory { // num_good_messages: u64, r.register_gauge_with_label( - format!("last_message_faulty").as_str(), + format!("last_message_good").as_str(), format!("block number").as_str(), label.as_str(), - self.last_message_faulty as i64, + self.last_message_good as i64, ); r.register_gauge_with_label( - format!("last_message_good").as_str(), + format!("last_message_faulty").as_str(), format!("block number").as_str(), label.as_str(), self.last_message_faulty as i64, From ecd8582c2b7b2bc87f9f6bf6b8c22e0162888b49 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 7 Nov 2023 10:48:16 +0100 Subject: [PATCH 084/687] fixed missing documentation warning for fn is_syncing(&self) -> bool; --- crates/ethcore/src/client/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 63afe1229..c54036b91 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -530,7 +530,7 @@ pub trait BlockChainClient: /// Returns true if the chain is currently syncing in major states. fn is_major_syncing(&self) -> bool; - // Returns true if the chain is currently syncing. + /// Returns true if the chain is currently syncing. fn is_syncing(&self) -> bool; /// Returns the next nonce for the given address, taking the transaction queue into account. From c145cd2f7900527a7d4ddadc035830346107959d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 7 Nov 2023 10:51:50 +0100 Subject: [PATCH 085/687] refactoring prometheus interface for message memo: made register_gauge_with_label does not imply "other_node" as label name, register_gauge_with_other_node_label does. --- .../engines/hbbft/hbbft_message_memorium.rs | 74 +++++++++---------- crates/util/stats/src/lib.rs | 10 ++- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index d0ef9be50..6b3fa0622 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -988,7 +988,7 @@ impl PrometheusMetrics for NodeStakingEpochHistory { let node_id = self.get_node_id().0 .0; - let label = std::format!( + let other_node = std::format!( "{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", node_id[0], node_id[1], @@ -1001,31 +1001,31 @@ impl PrometheusMetrics for NodeStakingEpochHistory { ); //r.register_gauge_with_label(name, help, label, value) - r.register_gauge_with_label( - format!("cumulative_lateness").as_str(), - format!("cumulative lateness").as_str(), - label.as_str(), + r.register_gauge_with_other_node_label( + "cumulative_lateness", + "cumulative lateness", + other_node.as_str(), self.cumulative_lateness as i64, ); - r.register_gauge_with_label( - format!("sealing_blocks_good").as_str(), - format!("good sealed block messages").as_str(), - label.as_str(), + r.register_gauge_with_other_node_label( + "sealing_blocks_good", + "good sealed block messages", + other_node.as_str(), self.sealing_blocks_good.len() as i64, ); - r.register_gauge_with_label( - format!("sealing_blocks_late").as_str(), - format!("late sealed blocks").as_str(), - label.as_str(), + r.register_gauge_with_other_node_label( + "sealing_blocks_late", + "late sealed blocks", + other_node.as_str(), self.sealing_blocks_late.len() as i64, ); - r.register_gauge_with_label( - format!("sealing_blocks_bad").as_str(), - format!("bad block seals").as_str(), - label.as_str(), + r.register_gauge_with_other_node_label( + "sealing_blocks_bad", + "bad block seals", + other_node.as_str(), self.sealing_blocks_bad.len() as i64, ); @@ -1033,24 +1033,24 @@ impl PrometheusMetrics for NodeStakingEpochHistory { // last_late_sealing_message: u64, // last_error_sealing_message: u64, - r.register_gauge_with_label( - format!("last_good_sealing_message").as_str(), - format!("block number").as_str(), - label.as_str(), + r.register_gauge_with_other_node_label( + "last_good_sealing_message", + "block number", + other_node.as_str(), self.last_good_sealing_message as i64, ); - r.register_gauge_with_label( - format!("last_late_sealing_message").as_str(), - format!("block number").as_str(), - label.as_str(), + r.register_gauge_with_other_node_label( + "last_late_sealing_message", + "block number", + other_node.as_str(), self.last_late_sealing_message as i64, ); - r.register_gauge_with_label( - format!("last_error_sealing_message").as_str(), - format!("block number").as_str(), - label.as_str(), + r.register_gauge_with_other_node_label( + "last_error_sealing_message", + "block number", + other_node.as_str(), self.last_error_sealing_message as i64, ); @@ -1060,17 +1060,17 @@ impl PrometheusMetrics for NodeStakingEpochHistory { // num_faulty_messages: u64, // num_good_messages: u64, - r.register_gauge_with_label( - format!("last_message_good").as_str(), - format!("block number").as_str(), - label.as_str(), + r.register_gauge_with_other_node_label( + "last_message_good", + "block number", + other_node.as_str(), self.last_message_good as i64, ); - r.register_gauge_with_label( - format!("last_message_faulty").as_str(), - format!("block number").as_str(), - label.as_str(), + r.register_gauge_with_other_node_label( + "last_message_faulty", + "block number", + other_node.as_str(), self.last_message_faulty as i64, ); } diff --git a/crates/util/stats/src/lib.rs b/crates/util/stats/src/lib.rs index 074d1ee29..87b02153c 100644 --- a/crates/util/stats/src/lib.rs +++ b/crates/util/stats/src/lib.rs @@ -70,9 +70,15 @@ impl PrometheusRegistry { .expect("prometheus identifiers must be are unique"); } + /// Adds a new prometheus gauge with a "other_node" label. + /// Designed for tracking communication partner values. + pub fn register_gauge_with_other_node_label(&mut self, name: &str, help: &str, other_node: &str, value: i64) { + self.register_gauge_with_label(name, help, "other_node", other_node, value); + } + /// Adds a new prometheus gauge with a label - pub fn register_gauge_with_label(&mut self, name: &str, help: &str, label: &str, value: i64) { - let opts = prometheus::Opts::new(name, help).const_label("other_node", label); + pub fn register_gauge_with_label(&mut self, name: &str, help: &str, label: &str, label_value: &str, value: i64) { + let opts = prometheus::Opts::new(name, help).const_label(label, label_value); // add labels here . //opts.variable_labels.push(label.to_string()); From d742f4934741fe3731254f77607fddbd2c27021b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Nov 2023 11:35:58 +0100 Subject: [PATCH 086/687] https://github.com/DMDcoin/diamond-node/issues/14 new metric: cumulative_lateness_raw shows the raw cumulative lateness, without taking missing block seals into account. `cumulative_lateness` now calculates the value of missing block seals as well. --- .../engines/hbbft/hbbft_message_memorium.rs | 229 ++++++++++-------- crates/util/stats/src/lib.rs | 17 +- 2 files changed, 142 insertions(+), 104 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 6b3fa0622..74b225b84 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -203,6 +203,128 @@ impl NodeStakingEpochHistory { return format!("{staking_epoch},{node_id},{total_sealing_messages},{total_good_sealing_messages},{total_late_sealing_messages},{total_error_sealing_messages},{last_good_sealing_message},{last_late_sealing_message},{last_error_sealing_message},{cumulative_lateness},{total_good_messages},{total_faulty_messages},{last_message_good},{last_message_faulty}\n"); } + + // prometheus metrics + + fn prometheus_metrics(&self, r: &mut stats::PrometheusRegistry, known_highest_block: u64) { + // one problem that occurs here is that we have a dynamic name of the gauges. + // that could lead to troubles later in the UI, because we would have to adapt the UI to the dynamic names. + // a solution could be to give every node a number from 0 to n (n=25 for DMD), and supply the name as a text value, + // so we still can figure out the node id, but the name of the gauge keeps static. + + //let metric: Metric = Metric::new(); + //r.registry().register(c) + + //let label = self.get_node_id().0.to_hex(); + + let node_id = self.get_node_id().0 .0; + + let other_node = std::format!( + "{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", + node_id[0], + node_id[1], + node_id[2], + node_id[3], + node_id[4], + node_id[5], + node_id[6], + node_id[7] + ); + + //r.register_gauge_with_label(name, help, label, value) + r.register_gauge_with_other_node_label( + "cumulative_lateness_raw", + "cumulative lateness, raw value without lateness from missing seals", + other_node.as_str(), + self.cumulative_lateness as i64, + ); + + // if the node has not send an sealing message, + // it's cumulative lateness is not tracked. + // we can calculate it by applying the sum formula to all missing blocks. + let non_tracked_cumulative_lateness = + if self.last_good_sealing_message < known_highest_block + 1 { + let difference = self.last_good_sealing_message - known_highest_block - 1; + (difference * (difference + 1)) / 2 + } else { + 0 + }; + + let cumulative_lateness = + self.cumulative_lateness + (known_highest_block - self.last_good_sealing_message); + r.register_gauge_with_other_node_label( + "cumulative_lateness", + "cumulative lateness, including missing seals from that node.", + other_node.as_str(), + (self.cumulative_lateness + non_tracked_cumulative_lateness) as i64, + ); + + r.register_gauge_with_other_node_label( + "sealing_blocks_good", + "good sealed block messages", + other_node.as_str(), + self.sealing_blocks_good.len() as i64, + ); + + r.register_gauge_with_other_node_label( + "sealing_blocks_late", + "late sealed blocks", + other_node.as_str(), + self.sealing_blocks_late.len() as i64, + ); + + r.register_gauge_with_other_node_label( + "sealing_blocks_bad", + "bad block seals", + other_node.as_str(), + self.sealing_blocks_bad.len() as i64, + ); + + // last_good_sealing_message: u64, + // last_late_sealing_message: u64, + // last_error_sealing_message: u64, + + r.register_gauge_with_other_node_label( + "last_good_sealing_message", + "block number", + other_node.as_str(), + self.last_good_sealing_message as i64, + ); + + r.register_gauge_with_other_node_label( + "last_late_sealing_message", + "block number", + other_node.as_str(), + self.last_late_sealing_message as i64, + ); + + r.register_gauge_with_other_node_label( + "last_error_sealing_message", + "block number", + other_node.as_str(), + self.last_error_sealing_message as i64, + ); + + // last_message_faulty: u64, + // last_message_good: u64, + + // num_faulty_messages: u64, + // num_good_messages: u64, + + r.register_gauge_with_other_node_label( + "last_message_good", + "block number", + other_node.as_str(), + self.last_message_good as i64, + ); + + r.register_gauge_with_other_node_label( + "last_message_faulty", + "block number", + other_node.as_str(), + self.last_message_faulty as i64, + ); + } } /// holds up the history of all nodes for a staking epoch history. @@ -211,6 +333,7 @@ pub(crate) struct StakingEpochHistory { staking_epoch: u64, staking_epoch_start_block: u64, staking_epoch_end_block: u64, + highest_block_num: u64, // stored the node staking epoch history. // since 25 is the exected maximum, a Vec has about the same perforamnce than a HashMap. @@ -229,6 +352,7 @@ impl StakingEpochHistory { staking_epoch, staking_epoch_start_block, staking_epoch_end_block, + highest_block_num: staking_epoch_start_block, node_staking_epoch_histories: Vec::new(), exported: false, } @@ -253,6 +377,9 @@ impl StakingEpochHistory { } pub fn on_seal_good(&mut self, event: &SealEventGood) { + if event.block_num > self.highest_block_num { + self.highest_block_num = event.block_num; + } let node_staking_epoch_history = self.get_history_for_node(&event.node_id); node_staking_epoch_history.add_good_seal_event(event); self.exported = false; @@ -974,108 +1101,6 @@ impl PrometheusMetrics for HbbftMessageDispatcher { } } -impl PrometheusMetrics for NodeStakingEpochHistory { - fn prometheus_metrics(&self, r: &mut stats::PrometheusRegistry) { - // one problem that occurs here is that we have a dynamic name of the gauges. - // that could lead to troubles later in the UI, because we would have to adapt the UI to the dynamic names. - // a solution could be to give every node a number from 0 to n (n=25 for DMD), and supply the name as a text value, - // so we still can figure out the node id, but the name of the gauge keeps static. - - //let metric: Metric = Metric::new(); - //r.registry().register(c) - - //let label = self.get_node_id().0.to_hex(); - - let node_id = self.get_node_id().0 .0; - - let other_node = std::format!( - "{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", - node_id[0], - node_id[1], - node_id[2], - node_id[3], - node_id[4], - node_id[5], - node_id[6], - node_id[7] - ); - - //r.register_gauge_with_label(name, help, label, value) - r.register_gauge_with_other_node_label( - "cumulative_lateness", - "cumulative lateness", - other_node.as_str(), - self.cumulative_lateness as i64, - ); - - r.register_gauge_with_other_node_label( - "sealing_blocks_good", - "good sealed block messages", - other_node.as_str(), - self.sealing_blocks_good.len() as i64, - ); - - r.register_gauge_with_other_node_label( - "sealing_blocks_late", - "late sealed blocks", - other_node.as_str(), - self.sealing_blocks_late.len() as i64, - ); - - r.register_gauge_with_other_node_label( - "sealing_blocks_bad", - "bad block seals", - other_node.as_str(), - self.sealing_blocks_bad.len() as i64, - ); - - // last_good_sealing_message: u64, - // last_late_sealing_message: u64, - // last_error_sealing_message: u64, - - r.register_gauge_with_other_node_label( - "last_good_sealing_message", - "block number", - other_node.as_str(), - self.last_good_sealing_message as i64, - ); - - r.register_gauge_with_other_node_label( - "last_late_sealing_message", - "block number", - other_node.as_str(), - self.last_late_sealing_message as i64, - ); - - r.register_gauge_with_other_node_label( - "last_error_sealing_message", - "block number", - other_node.as_str(), - self.last_error_sealing_message as i64, - ); - - // last_message_faulty: u64, - // last_message_good: u64, - - // num_faulty_messages: u64, - // num_good_messages: u64, - - r.register_gauge_with_other_node_label( - "last_message_good", - "block number", - other_node.as_str(), - self.last_message_good as i64, - ); - - r.register_gauge_with_other_node_label( - "last_message_faulty", - "block number", - other_node.as_str(), - self.last_message_faulty as i64, - ); - } -} - impl PrometheusMetrics for StakingEpochHistory { fn prometheus_metrics(&self, r: &mut stats::PrometheusRegistry) { r.register_gauge( diff --git a/crates/util/stats/src/lib.rs b/crates/util/stats/src/lib.rs index 87b02153c..33b40dd6c 100644 --- a/crates/util/stats/src/lib.rs +++ b/crates/util/stats/src/lib.rs @@ -72,12 +72,25 @@ impl PrometheusRegistry { /// Adds a new prometheus gauge with a "other_node" label. /// Designed for tracking communication partner values. - pub fn register_gauge_with_other_node_label(&mut self, name: &str, help: &str, other_node: &str, value: i64) { + pub fn register_gauge_with_other_node_label( + &mut self, + name: &str, + help: &str, + other_node: &str, + value: i64, + ) { self.register_gauge_with_label(name, help, "other_node", other_node, value); } /// Adds a new prometheus gauge with a label - pub fn register_gauge_with_label(&mut self, name: &str, help: &str, label: &str, label_value: &str, value: i64) { + pub fn register_gauge_with_label( + &mut self, + name: &str, + help: &str, + label: &str, + label_value: &str, + value: i64, + ) { let opts = prometheus::Opts::new(name, help).const_label(label, label_value); // add labels here . //opts.variable_labels.push(label.to_string()); From fb71a0a5c1fe358d4c8b8fb85d4012650fd4fcbb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Nov 2023 11:36:23 +0100 Subject: [PATCH 087/687] https://github.com/DMDcoin/diamond-node/issues/14 new metric: cumulative_lateness_raw shows the raw cumulative lateness, without taking missing block seals into account. `cumulative_lateness` now calculates the value of missing block seals as well. --- crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 74b225b84..c5c1e0bbd 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -333,6 +333,9 @@ pub(crate) struct StakingEpochHistory { staking_epoch: u64, staking_epoch_start_block: u64, staking_epoch_end_block: u64, + + /// highest block number that was processed for this epoch. + /// used to calculate the real lateness of Nodes. highest_block_num: u64, // stored the node staking epoch history. @@ -1115,7 +1118,7 @@ impl PrometheusMetrics for StakingEpochHistory { ); for epoch_history in self.node_staking_epoch_histories.iter() { - epoch_history.prometheus_metrics(r); + epoch_history.prometheus_metrics(r, self.highest_block_num); } } } From 405a33bc65db4d45297d97b0d3dae7473d3091eb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Nov 2023 13:05:48 +0100 Subject: [PATCH 088/687] fixed bug calculating cumulative lateness --- crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index c5c1e0bbd..e81c6f74f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -244,7 +244,7 @@ impl NodeStakingEpochHistory { // we can calculate it by applying the sum formula to all missing blocks. let non_tracked_cumulative_lateness = if self.last_good_sealing_message < known_highest_block + 1 { - let difference = self.last_good_sealing_message - known_highest_block - 1; + let difference = known_highest_block - self.last_good_sealing_message - 1; (difference * (difference + 1)) / 2 } else { 0 @@ -333,7 +333,7 @@ pub(crate) struct StakingEpochHistory { staking_epoch: u64, staking_epoch_start_block: u64, staking_epoch_end_block: u64, - + /// highest block number that was processed for this epoch. /// used to calculate the real lateness of Nodes. highest_block_num: u64, From c86028cf24213709d0802feda06db35a3ab06b87 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Nov 2023 13:39:49 +0100 Subject: [PATCH 089/687] fixed calculation of non_tracked_cumulative_lateness --- .../engines/hbbft/hbbft_message_memorium.rs | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index e81c6f74f..4d8769b08 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -206,7 +206,12 @@ impl NodeStakingEpochHistory { // prometheus metrics - fn prometheus_metrics(&self, r: &mut stats::PrometheusRegistry, known_highest_block: u64) { + fn prometheus_metrics( + &self, + r: &mut stats::PrometheusRegistry, + known_highest_block: u64, + epoch_start_block: u64, + ) { // one problem that occurs here is that we have a dynamic name of the gauges. // that could lead to troubles later in the UI, because we would have to adapt the UI to the dynamic names. // a solution could be to give every node a number from 0 to n (n=25 for DMD), and supply the name as a text value, @@ -241,14 +246,18 @@ impl NodeStakingEpochHistory { // if the node has not send an sealing message, // it's cumulative lateness is not tracked. + + // we begin counting from the first block of the epoch. + let last_good_sealing_message = u64::max(self.last_good_sealing_message, epoch_start_block); + // we can calculate it by applying the sum formula to all missing blocks. - let non_tracked_cumulative_lateness = - if self.last_good_sealing_message < known_highest_block + 1 { - let difference = known_highest_block - self.last_good_sealing_message - 1; - (difference * (difference + 1)) / 2 - } else { - 0 - }; + let non_tracked_cumulative_lateness = if last_good_sealing_message + 1 < known_highest_block + { + let difference = known_highest_block - (last_good_sealing_message + 1); + (difference * (difference + 1)) / 2 + } else { + 0 + }; let cumulative_lateness = self.cumulative_lateness + (known_highest_block - self.last_good_sealing_message); @@ -1118,7 +1127,11 @@ impl PrometheusMetrics for StakingEpochHistory { ); for epoch_history in self.node_staking_epoch_histories.iter() { - epoch_history.prometheus_metrics(r, self.highest_block_num); + epoch_history.prometheus_metrics( + r, + self.highest_block_num, + self.staking_epoch_start_block, + ); } } } From 2e560b33af8e393a0077fb1f3a069afb01bbba36 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 9 Nov 2023 10:55:15 +0100 Subject: [PATCH 090/687] cumulative lateness: filling gaps of missing hbbft messages --- .../engines/hbbft/hbbft_message_memorium.rs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 4d8769b08..f28ca1379 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -97,17 +97,27 @@ impl NodeStakingEpochHistory { /// protocols a good seal event. pub fn add_seal_event_late(&mut self, event: &SealEventLate) { + // by definition a "good sealing" is always on the latest block. let block_num = event.block_num; - let last_late_sealing_message = self.last_late_sealing_message; + + if block_num < self.last_late_sealing_message { + warn!(target: "hbbft_message_memorium", "out of order seal events: add_late_seal_event: event.block_num {block_num} <= self.last_late_sealing_message {}", self.last_late_sealing_message); + return; + } - if block_num > last_late_sealing_message { - self.last_late_sealing_message = event.block_num; - } else { - warn!(target: "hbbft_message_memorium", "add_late_seal_event: event.block_num {block_num} <= self.last_late_sealing_message {last_late_sealing_message}"); + // add cumulative lateness, for all blocks between the last tracked block + // and the current block. + if self.last_late_sealing_message > 0 && self.last_late_sealing_message < event.block_num - 1 { + let difference = event.block_num - 1 - self.last_late_sealing_message; + self.cumulative_lateness += (difference * (difference + 1)) / 2; } + + self.last_late_sealing_message = event.block_num; self.cumulative_lateness += event.get_lateness(); self.sealing_blocks_late.push(event.block_num); + + } pub(crate) fn add_bad_seal_event(&mut self, event: &SealEventBad) { @@ -1147,4 +1157,8 @@ impl PrometheusMetrics for HbbftMessageMemorium { } #[cfg(test)] -mod tests {} +mod tests { + + + +} From bd6f70f74dab7898894e2290796288512f3be6f7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 9 Nov 2023 10:55:49 +0100 Subject: [PATCH 091/687] cargo fmt --all -- --config imports_granularity=Crate --- .../src/engines/hbbft/hbbft_message_memorium.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index f28ca1379..492f42729 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -97,10 +97,9 @@ impl NodeStakingEpochHistory { /// protocols a good seal event. pub fn add_seal_event_late(&mut self, event: &SealEventLate) { - // by definition a "good sealing" is always on the latest block. let block_num = event.block_num; - + if block_num < self.last_late_sealing_message { warn!(target: "hbbft_message_memorium", "out of order seal events: add_late_seal_event: event.block_num {block_num} <= self.last_late_sealing_message {}", self.last_late_sealing_message); return; @@ -108,7 +107,9 @@ impl NodeStakingEpochHistory { // add cumulative lateness, for all blocks between the last tracked block // and the current block. - if self.last_late_sealing_message > 0 && self.last_late_sealing_message < event.block_num - 1 { + if self.last_late_sealing_message > 0 + && self.last_late_sealing_message < event.block_num - 1 + { let difference = event.block_num - 1 - self.last_late_sealing_message; self.cumulative_lateness += (difference * (difference + 1)) / 2; } @@ -116,8 +117,6 @@ impl NodeStakingEpochHistory { self.last_late_sealing_message = event.block_num; self.cumulative_lateness += event.get_lateness(); self.sealing_blocks_late.push(event.block_num); - - } pub(crate) fn add_bad_seal_event(&mut self, event: &SealEventBad) { @@ -1157,8 +1156,4 @@ impl PrometheusMetrics for HbbftMessageMemorium { } #[cfg(test)] -mod tests { - - - -} +mod tests {} From b3cdf288dead074d372f7b91de2fda94691b14e3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 9 Nov 2023 11:13:39 +0100 Subject: [PATCH 092/687] fixed bug in tracking last message good and last message faulty --- crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 492f42729..7c406b181 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -152,9 +152,9 @@ impl NodeStakingEpochHistory { let last_message_good = self.last_message_good; if block_num > last_message_good { - self.last_message_faulty = block_num; + self.last_message_good = block_num; } else { - warn!(target: "hbbft_message_memorium", "add_message_event_good: event.block_num {block_num} <= last_message_faulty {last_message_good}"); + warn!(target: "hbbft_message_memorium", "add_message_event_good: event.block_num {block_num} <= last_message_good {last_message_good}"); } self.num_good_messages += 1; } From 88640a2fea04f544fdc863a05c2b945ab73501f8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 9 Nov 2023 11:33:26 +0100 Subject: [PATCH 093/687] do not report last_block information of any kind, if the information is 0. this leads to analysis graphs that are easier to read. --- .../engines/hbbft/hbbft_message_memorium.rs | 72 ++++++++++--------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 7c406b181..452ce1c11 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -302,26 +302,32 @@ impl NodeStakingEpochHistory { // last_late_sealing_message: u64, // last_error_sealing_message: u64, - r.register_gauge_with_other_node_label( - "last_good_sealing_message", - "block number", - other_node.as_str(), - self.last_good_sealing_message as i64, - ); + if self.last_good_sealing_message > 0 { + r.register_gauge_with_other_node_label( + "last_good_sealing_message", + "block number", + other_node.as_str(), + self.last_good_sealing_message as i64, + ); + } - r.register_gauge_with_other_node_label( - "last_late_sealing_message", - "block number", - other_node.as_str(), - self.last_late_sealing_message as i64, - ); + if self.last_late_sealing_message > 0 { + r.register_gauge_with_other_node_label( + "last_late_sealing_message", + "block number", + other_node.as_str(), + self.last_late_sealing_message as i64, + ); + } - r.register_gauge_with_other_node_label( - "last_error_sealing_message", - "block number", - other_node.as_str(), - self.last_error_sealing_message as i64, - ); + if self.last_error_sealing_message > 0 { + r.register_gauge_with_other_node_label( + "last_error_sealing_message", + "block number", + other_node.as_str(), + self.last_error_sealing_message as i64, + ); + } // last_message_faulty: u64, // last_message_good: u64, @@ -329,19 +335,23 @@ impl NodeStakingEpochHistory { // num_faulty_messages: u64, // num_good_messages: u64, - r.register_gauge_with_other_node_label( - "last_message_good", - "block number", - other_node.as_str(), - self.last_message_good as i64, - ); + if self.last_message_good > 0 { + r.register_gauge_with_other_node_label( + "last_message_good", + "block number", + other_node.as_str(), + self.last_message_good as i64, + ); + } - r.register_gauge_with_other_node_label( - "last_message_faulty", - "block number", - other_node.as_str(), - self.last_message_faulty as i64, - ); + if self.last_message_faulty > 0 { + r.register_gauge_with_other_node_label( + "last_message_faulty", + "block number", + other_node.as_str(), + self.last_message_faulty as i64, + ); + } } } @@ -987,7 +997,6 @@ impl HbbftMessageMemorium { } // good seals - if let Some(good_seal) = self.dispatched_seal_event_good.front() { // rust borrow system forced me into this useless clone... debug!(target: "hbbft_message_memorium", "work: good Seal!"); @@ -1000,7 +1009,6 @@ impl HbbftMessageMemorium { } // late seals - if let Some(late_seal) = self.dispatched_seal_event_late.front() { // rust borrow system forced me into this useless clone... if self.on_seal_late(&late_seal.clone()) { From c6c19ddf584660b1385814823d82ea9deeb185bb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 9 Nov 2023 15:39:16 +0100 Subject: [PATCH 094/687] redesigned cumulative lateness gap calculation to be used on all Block Seal events. --- .../engines/hbbft/hbbft_message_memorium.rs | 100 ++++++++++++------ 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 452ce1c11..229692851 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -79,24 +79,40 @@ impl NodeStakingEpochHistory { } } - /// mut ADD_... + /// calculates the cumulative lateness for that communication partner, + /// based on existing data, detecting blocks with missing late or good seals + fn calc_cumulative_lateness_gap(&self, block_num: u64, staking_epoch_start_block_num: u64) -> u64 { + + // add cumulative lateness, for all blocks between the last tracked block + // and the current block. + if self.last_late_sealing_message + 1 < block_num || self.last_good_sealing_message + 1 < block_num + { + let difference = block_num - u64::max(u64::max(u64::max(self.last_late_sealing_message, staking_epoch_start_block_num), self.last_good_sealing_message), self.last_error_sealing_message); + return (difference * (difference + 1)) / 2; + } + return 0; + } + + /// protocols a good seal event. - pub fn add_good_seal_event(&mut self, event: &SealEventGood) { + pub fn add_good_seal_event(&mut self, event: &SealEventGood, staking_epoch_start_block_num: u64) { // by definition a "good sealing" is always on the latest block. let block_num = event.block_num; let last_good_sealing_message = self.last_good_sealing_message; - if block_num > last_good_sealing_message { - self.last_good_sealing_message = event.block_num; - } else { + if block_num < last_good_sealing_message { warn!(target: "hbbft_message_memorium", "add_good_seal_event: event.block_num {block_num} <= self.last_good_sealing_message {last_good_sealing_message}"); + return; } + + self.cumulative_lateness += self.calc_cumulative_lateness_gap(event.block_num, staking_epoch_start_block_num); + self.last_good_sealing_message = event.block_num; self.sealing_blocks_good.push(event.block_num); } /// protocols a good seal event. - pub fn add_seal_event_late(&mut self, event: &SealEventLate) { + pub fn add_seal_event_late(&mut self, event: &SealEventLate, staking_epoch_start_block: u64) { // by definition a "good sealing" is always on the latest block. let block_num = event.block_num; @@ -105,31 +121,27 @@ impl NodeStakingEpochHistory { return; } - // add cumulative lateness, for all blocks between the last tracked block - // and the current block. - if self.last_late_sealing_message > 0 - && self.last_late_sealing_message < event.block_num - 1 - { - let difference = event.block_num - 1 - self.last_late_sealing_message; - self.cumulative_lateness += (difference * (difference + 1)) / 2; - } + + self.cumulative_lateness += self.calc_cumulative_lateness_gap(event.block_num, staking_epoch_start_block); self.last_late_sealing_message = event.block_num; self.cumulative_lateness += event.get_lateness(); self.sealing_blocks_late.push(event.block_num); } - pub(crate) fn add_bad_seal_event(&mut self, event: &SealEventBad) { + pub(crate) fn add_bad_seal_event(&mut self, event: &SealEventBad, staking_epoch_start_block_num: u64) { // by definition a "good sealing" is always on the latest block. let block_num = event.block_num; let last_bad_sealing_message = self.last_error_sealing_message; - if block_num > last_bad_sealing_message { - self.last_good_sealing_message = event.block_num; - } else { + if block_num < last_bad_sealing_message { warn!(target: "hbbft_message_memorium", "add_bad_seal_event: event.block_num {block_num} <= self.last_bad_sealing_message {last_bad_sealing_message}"); + return; } + + self.cumulative_lateness += self.calc_cumulative_lateness_gap(block_num, staking_epoch_start_block_num); + self.last_error_sealing_message = event.block_num; self.sealing_blocks_good.push(event.block_num); } @@ -259,17 +271,9 @@ impl NodeStakingEpochHistory { // we begin counting from the first block of the epoch. let last_good_sealing_message = u64::max(self.last_good_sealing_message, epoch_start_block); - // we can calculate it by applying the sum formula to all missing blocks. - let non_tracked_cumulative_lateness = if last_good_sealing_message + 1 < known_highest_block - { - let difference = known_highest_block - (last_good_sealing_message + 1); - (difference * (difference + 1)) / 2 - } else { - 0 - }; - let cumulative_lateness = - self.cumulative_lateness + (known_highest_block - self.last_good_sealing_message); + let non_tracked_cumulative_lateness = self.calc_cumulative_lateness_gap(known_highest_block, epoch_start_block); + r.register_gauge_with_other_node_label( "cumulative_lateness", "cumulative lateness, including missing seals from that node.", @@ -408,23 +412,26 @@ impl StakingEpochHistory { } pub fn on_seal_good(&mut self, event: &SealEventGood) { + let staking_epoch_start_block = self.staking_epoch_start_block; if event.block_num > self.highest_block_num { self.highest_block_num = event.block_num; } let node_staking_epoch_history = self.get_history_for_node(&event.node_id); - node_staking_epoch_history.add_good_seal_event(event); + node_staking_epoch_history.add_good_seal_event(event, staking_epoch_start_block); self.exported = false; } pub fn on_seal_late(&mut self, event: &SealEventLate) { + let staking_epoch_start_block = self.staking_epoch_start_block; let node_staking_epoch_history = self.get_history_for_node(&event.node_id); - node_staking_epoch_history.add_seal_event_late(event); + node_staking_epoch_history.add_seal_event_late(event, staking_epoch_start_block); self.exported = false; } pub fn on_seal_bad(&mut self, event: &SealEventBad) { + let staking_epoch_start_block = self.staking_epoch_start_block; let node_staking_epoch_history = self.get_history_for_node(&event.node_id); - node_staking_epoch_history.add_bad_seal_event(event); + node_staking_epoch_history.add_bad_seal_event(event, staking_epoch_start_block); self.exported = false; } @@ -481,7 +488,7 @@ pub struct SealEventLate { impl SealEventLate { // get's the block lateness in blocks. pub fn get_lateness(&self) -> u64 { - self.received_block_num - self.block_num + (self.received_block_num - self.block_num ) + 1 } } @@ -1164,4 +1171,31 @@ impl PrometheusMetrics for HbbftMessageMemorium { } #[cfg(test)] -mod tests {} +mod tests { + // use crate::engines::hbbft::NodeId; + + //use super::{HbbftMessageMemorium, MessageEventGood}; + + + + // #[test] + // fn test_late_message_tracking() { + // use super::SealEventGood; + + // let memorium = HbbftMessageMemorium::new( 0, "".to_string(), 0); + // memorium.report_new_epoch(1, 100); + + // let node1 = NodeId::random(); + + // //memorium.on_seal_good(SealEventGood { }); + + // memorium.on_seal_good(&MessageEventGood { + // node_id: node1.clone(), + // block_num: 100, + // }); + + // memorium.staking_epoch_history[0].node_staking_epoch_histories[0].last_good_sealing_message + + // } + +} From eab2e6dc22d8c5eb5cf4aa04ae6401a15b6269d4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 10 Nov 2023 17:26:25 +0100 Subject: [PATCH 095/687] is_syncing for Hbbft tests --- crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs index ccefa88c2..a2abb00d9 100644 --- a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs +++ b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs @@ -26,6 +26,10 @@ impl ChainSyncing for SyncProviderWrapper { fn is_major_syncing(&self) -> bool { false } + + fn is_syncing(&self) -> bool { + false + } } pub fn hbbft_client() -> std::sync::Arc { From fba4d3b7e82ed55730d3e1a857e65525ccc66ca1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 11 Nov 2023 11:55:15 +0100 Subject: [PATCH 096/687] counting cumulative lateness in hbbft message memorium + unit tests --- .../engines/hbbft/hbbft_message_memorium.rs | 254 +++++++++++++++--- 1 file changed, 222 insertions(+), 32 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 229692851..adad6a4c7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -48,6 +48,7 @@ pub(crate) struct NodeStakingEpochHistory { last_good_sealing_message: u64, last_late_sealing_message: u64, last_error_sealing_message: u64, + // summed up lateness of all seals, including bad seals. cumulative_lateness: u64, sealing_blocks_good: Vec, sealing_blocks_late: Vec, @@ -79,24 +80,46 @@ impl NodeStakingEpochHistory { } } - /// calculates the cumulative lateness for that communication partner, + /// calculates the cumulative lateness for that communication partner, /// based on existing data, detecting blocks with missing late or good seals - fn calc_cumulative_lateness_gap(&self, block_num: u64, staking_epoch_start_block_num: u64) -> u64 { - + fn calc_cumulative_lateness_gap( + &self, + block_num: u64, + staking_epoch_start_block_num: u64, + ) -> u64 { + if block_num <= 1 { + return 0; + } // add cumulative lateness, for all blocks between the last tracked block // and the current block. - if self.last_late_sealing_message + 1 < block_num || self.last_good_sealing_message + 1 < block_num + if self.last_late_sealing_message + 1 < block_num + || self.last_good_sealing_message + 1 < block_num + || self.last_error_sealing_message + 1 < block_num { - let difference = block_num - u64::max(u64::max(u64::max(self.last_late_sealing_message, staking_epoch_start_block_num), self.last_good_sealing_message), self.last_error_sealing_message); + let difference = block_num + - 1 + - u64::max( + u64::max( + u64::max( + self.last_late_sealing_message, + staking_epoch_start_block_num, + ), + self.last_good_sealing_message, + ), + self.last_error_sealing_message, + ); return (difference * (difference + 1)) / 2; } return 0; } - /// protocols a good seal event. - pub fn add_good_seal_event(&mut self, event: &SealEventGood, staking_epoch_start_block_num: u64) { + pub fn add_good_seal_event( + &mut self, + event: &SealEventGood, + staking_epoch_start_block_num: u64, + ) { // by definition a "good sealing" is always on the latest block. let block_num = event.block_num; let last_good_sealing_message = self.last_good_sealing_message; @@ -106,7 +129,8 @@ impl NodeStakingEpochHistory { return; } - self.cumulative_lateness += self.calc_cumulative_lateness_gap(event.block_num, staking_epoch_start_block_num); + self.cumulative_lateness += + self.calc_cumulative_lateness_gap(event.block_num, staking_epoch_start_block_num); self.last_good_sealing_message = event.block_num; self.sealing_blocks_good.push(event.block_num); } @@ -121,15 +145,19 @@ impl NodeStakingEpochHistory { return; } - - self.cumulative_lateness += self.calc_cumulative_lateness_gap(event.block_num, staking_epoch_start_block); + self.cumulative_lateness += + self.calc_cumulative_lateness_gap(event.block_num, staking_epoch_start_block); self.last_late_sealing_message = event.block_num; self.cumulative_lateness += event.get_lateness(); self.sealing_blocks_late.push(event.block_num); } - pub(crate) fn add_bad_seal_event(&mut self, event: &SealEventBad, staking_epoch_start_block_num: u64) { + pub(crate) fn add_bad_seal_event( + &mut self, + event: &SealEventBad, + staking_epoch_start_block_num: u64, + ) { // by definition a "good sealing" is always on the latest block. let block_num = event.block_num; @@ -140,7 +168,9 @@ impl NodeStakingEpochHistory { return; } - self.cumulative_lateness += self.calc_cumulative_lateness_gap(block_num, staking_epoch_start_block_num); + self.cumulative_lateness += + self.calc_cumulative_lateness_gap(block_num, staking_epoch_start_block_num); + self.cumulative_lateness += 1; self.last_error_sealing_message = event.block_num; self.sealing_blocks_good.push(event.block_num); } @@ -271,8 +301,8 @@ impl NodeStakingEpochHistory { // we begin counting from the first block of the epoch. let last_good_sealing_message = u64::max(self.last_good_sealing_message, epoch_start_block); - - let non_tracked_cumulative_lateness = self.calc_cumulative_lateness_gap(known_highest_block, epoch_start_block); + let non_tracked_cumulative_lateness = + self.calc_cumulative_lateness_gap(known_highest_block, epoch_start_block); r.register_gauge_with_other_node_label( "cumulative_lateness", @@ -488,7 +518,7 @@ pub struct SealEventLate { impl SealEventLate { // get's the block lateness in blocks. pub fn get_lateness(&self) -> u64 { - (self.received_block_num - self.block_num ) + 1 + (self.received_block_num - self.block_num) + 1 } } @@ -1172,30 +1202,190 @@ impl PrometheusMetrics for HbbftMessageMemorium { #[cfg(test)] mod tests { - // use crate::engines::hbbft::NodeId; + use crate::engines::hbbft::{hbbft_message_memorium::BadSealReason, NodeId}; + + use super::{HbbftMessageMemorium, MessageEventGood, SealEventBad}; + + use crypto::publickey::{Generator, Random}; + use ethereum_types::Public; + + #[test] + fn test_message_memorium() { + use super::SealEventGood; + let mut memorium = HbbftMessageMemorium::new(0, "".to_string(), "".to_string()); + memorium.report_new_epoch(1, 100); + + let node1 = NodeId(Public::random()); + + // we need a second node, that sends good seals every block. + let node2 = NodeId(Public::random()); + + //memorium.on_seal_good(SealEventGood { }); - //use super::{HbbftMessageMemorium, MessageEventGood}; + memorium.on_seal_good(&SealEventGood { + node_id: node1.clone(), + block_num: 101, + }); + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 101, + }); + assert_eq!( + memorium.staking_epoch_history[0].node_staking_epoch_histories[0] + .last_good_sealing_message, + 101 + ); + assert_eq!( + memorium.staking_epoch_history[0].node_staking_epoch_histories[0].cumulative_lateness, + 0 + ); + + // if we do skip block 101 with node1, and do not send a message at all - a late block should be tracked. + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 102, + }); + + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 103, + }); + + memorium.on_seal_good(&SealEventGood { + node_id: node1.clone(), + block_num: 103, + }); + + assert_eq!( + memorium.staking_epoch_history[0].node_staking_epoch_histories[0].cumulative_lateness, + 1 + ); - // #[test] - // fn test_late_message_tracking() { - // use super::SealEventGood; + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 104, + }); - // let memorium = HbbftMessageMemorium::new( 0, "".to_string(), 0); - // memorium.report_new_epoch(1, 100); + memorium.on_seal_good(&SealEventGood { + node_id: node1.clone(), + block_num: 104, + }); + + // node was on time, so cumulative_lateness should be still one. + assert_eq!( + memorium.staking_epoch_history[0].node_staking_epoch_histories[0].cumulative_lateness, + 1 + ); + + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 105, + }); + + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 106, + }); + + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 107, + }); + + // node 1 was missing 3 blocks now. + // the cumulative lateness should sum up as follows: + // 1 - base value + // 1 - block 107 + // 2 - block 106 + // 3 - block 105 + // ------ + // 7 - total + + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 108, + }); + + memorium.on_seal_good(&SealEventGood { + node_id: node1.clone(), + block_num: 108, + }); + + // node was on time, so cumulative_lateness should be still one. + assert_eq!( + memorium.staking_epoch_history[0].node_staking_epoch_histories[0].cumulative_lateness, + 7 + ); - // let node1 = NodeId::random(); + // test the bad message seals. - // //memorium.on_seal_good(SealEventGood { }); - - // memorium.on_seal_good(&MessageEventGood { - // node_id: node1.clone(), - // block_num: 100, - // }); + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 109, + }); - // memorium.staking_epoch_history[0].node_staking_epoch_histories[0].last_good_sealing_message - - // } + memorium.on_seal_bad(&SealEventBad { + node_id: node1.clone(), + block_num: 109, + reason: BadSealReason::MismatchedNetworkInfo, + }); + assert_eq!( + memorium.staking_epoch_history[0].node_staking_epoch_histories[0].cumulative_lateness, + 8 + ); + + // check if sealing message gaps are calculated the correct way with Bad Sealing Messages as well. + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 110, + }); + + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 111, + }); + + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 112, + }); + + // we will receive a bad Seal for block 113 + memorium.on_seal_good(&SealEventGood { + node_id: node2.clone(), + block_num: 113, + }); + + memorium.on_seal_bad(&SealEventBad { + node_id: node1.clone(), + block_num: 113, + reason: BadSealReason::MismatchedNetworkInfo, + }); + + // node 1 was missing 3 blocks now, and has written 1 bad block. + // the cumulative lateness should sum up as follows: + // 8 - base value + // 1 - block 113 (bad) + // 1 - block 112 (missed) + // 2 - block 111 (missed) + // 3 - block 110 (missed) + // 0 - block 109 (bad - already counted.) + // ------ + // 15 - total + + assert_eq!( + memorium.staking_epoch_history[0].node_staking_epoch_histories[0].cumulative_lateness, + 15 + ); + + // since node2 was our reference node, that always created blocks, it's cumulative lateness should be 0 + + assert_eq!( + memorium.staking_epoch_history[0].node_staking_epoch_histories[1].cumulative_lateness, + 0 + ); + } } From adb42ea234461273b0e51c1186c613c9d2ed244e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 12 Nov 2023 23:18:21 +0100 Subject: [PATCH 097/687] changelog for upcomming 0.9.4 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f14a3c79..3e39597f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Diamond Node Software 3.3.5-hbbft-0.9.4 + +- [Fixed: is major syncing information is wrong.] (https://github.com/DMDcoin/diamond-node/issues/73) +- [Improvements for HBBFT Message Tracking] (https://github.com/DMDcoin/openethereum-3.x/issues/17) + ## Diamond Node Software 3.3.5-hbbft-0.9.3 [Autoshutdown after a period without block import] https://github.com/DMDcoin/diamond-node/issues/78 From dc026a055b9b5d6770ca7ac169983079d33fa521 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 12 Nov 2023 23:19:12 +0100 Subject: [PATCH 098/687] version update of tomls --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf989d225..8e64aa5c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -806,7 +806,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.9.3" +version = "3.3.5-hbbft-0.9.4" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3548,7 +3548,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.9.3" +version = "3.3.5-hbbft-0.9.4" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 3bf5201a6..0a824f01a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.9.3" +version = "3.3.5-hbbft-0.9.4" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index de527cf69..4ace8576c 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.9.3" +version = "3.3.5-hbbft-0.9.4" authors = [ "bit.diamonds developers", "OpenEthereum developers", From dcda92f3eb5ff10ccaf9bb4c91cf08ca6fd2c9d8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 14 Nov 2023 21:50:41 +0100 Subject: [PATCH 099/687] moved minimum_gas_price from EthEngine to Engine and wired it in hbbft_engine. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 4 ++++ crates/ethcore/src/engines/mod.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 3540a6915..e08f1f239 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1286,6 +1286,10 @@ impl Engine for HoneyBadgerBFT { &self.machine } + fn minimum_gas_price(&self) -> Option { + self.current_minimum_gas_price.lock().clone() + } + fn fork_choice(&self, new: &ExtendedHeader, current: &ExtendedHeader) -> ForkChoice { crate::engines::total_difficulty_fork_choice(new, current) } diff --git a/crates/ethcore/src/engines/mod.rs b/crates/ethcore/src/engines/mod.rs index dec95fe63..a21b9498a 100644 --- a/crates/ethcore/src/engines/mod.rs +++ b/crates/ethcore/src/engines/mod.rs @@ -492,6 +492,12 @@ pub trait Engine: Sync + Send { true } + /// Some Engine might define the minimum gas price by themselve. + /// (for example: contract) + fn minimum_gas_price(&self) -> Option { + None + } + /// Sign using the EngineSigner, to be used for consensus tx signing. fn sign(&self, _hash: H256) -> Result { unimplemented!() @@ -709,12 +715,6 @@ pub trait EthEngine: Engine<::machine::EthereumMachine> { fn allow_non_eoa_sender(&self, best_block_number: BlockNumber) -> bool { self.params().eip3607_transition > best_block_number } - - /// Some Engine might define the minimum gas price by themselve. - /// (for example: contract) - fn minimum_gas_price(&self) -> Option { - None - } } // convenience wrappers for existing functions. From 0c435429deaad0d146ae6d5226a6c9c92b97b5c5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 19 Nov 2023 09:24:03 +0100 Subject: [PATCH 100/687] early epoch end manager struct --- .../hbbft/hbbft_early_epoch_end_manager.rs | 19 +++++++++++++++++++ crates/ethcore/src/engines/hbbft/mod.rs | 1 + 2 files changed, 20 insertions(+) create mode 100644 crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs new file mode 100644 index 000000000..683687d41 --- /dev/null +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -0,0 +1,19 @@ +use std::time::{Instant, Duration}; +use super::NodeId; + + +pub(crate) struct EarlyEpochEndManager { + + /// The current epoch number. + current_tracked_epoch_number: u64, + + /// epoch manager start up time. + start_time: Instant, + + /// allowed devp2p warmup time. + allowed_devp2p_warmup_time: Duration, + + /// public keys of all validators for this epoch. + validators: Vec, + +} \ No newline at end of file diff --git a/crates/ethcore/src/engines/hbbft/mod.rs b/crates/ethcore/src/engines/hbbft/mod.rs index aebeb69ff..99aad0602 100644 --- a/crates/ethcore/src/engines/hbbft/mod.rs +++ b/crates/ethcore/src/engines/hbbft/mod.rs @@ -1,6 +1,7 @@ mod block_reward_hbbft; mod contracts; mod contribution; +mod hbbft_early_epoch_end_manager; mod hbbft_engine; mod hbbft_message_memorium; mod hbbft_peers_management; From 9b9d3b9a01d38db41814131842f9f4893bf0d483 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 19 Nov 2023 21:40:09 +0100 Subject: [PATCH 101/687] EarlyEpochEndManager Impl --- .../hbbft/hbbft_early_epoch_end_manager.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 683687d41..016d1a836 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -16,4 +16,26 @@ pub(crate) struct EarlyEpochEndManager { /// public keys of all validators for this epoch. validators: Vec, +} + + +impl EarlyEpochEndManager { + + // new + pub fn new(allowed_devp2p_warmup_time: Duration) -> Self { + Self { + current_tracked_epoch_number: 0, + start_time: Instant::now(), + allowed_devp2p_warmup_time: allowed_devp2p_warmup_time, + validators: Vec::new(), + } + } + + pub fn notify_new_epoch(&mut self, epoch: u64, validators: Vec ) { + + self.current_tracked_epoch_number = epoch; + self.validators = validators; + self.start_time = Instant::now(); + } + } \ No newline at end of file From 1b8732cb75e4d451dcc263f5ae484d00b9585982 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 21 Nov 2023 16:59:56 +0100 Subject: [PATCH 102/687] early epoch end manager skeleton --- .../hbbft/hbbft_early_epoch_end_manager.rs | 65 +++++++++++++++++-- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 016d1a836..ff3eb01cb 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -1,5 +1,7 @@ use std::time::{Instant, Duration}; -use super::NodeId; +use crate::client::BlockChainClient; + +use super::{NodeId, hbbft_message_memorium::HbbftMessageMemorium}; pub(crate) struct EarlyEpochEndManager { @@ -16,21 +18,51 @@ pub(crate) struct EarlyEpochEndManager { /// public keys of all validators for this epoch. validators: Vec, + /// current flagged validators + flagged_validators: Vec, } impl EarlyEpochEndManager { - // new - pub fn new(allowed_devp2p_warmup_time: Duration) -> Self { - Self { + /// creates a new EarlyEpochEndManager, + /// if conditions are matching to create one. + /// It is expected that this function is only called if the node is a validator. + /// This prerequesite will be checked and if not met, panics. + pub fn create_early_epoch_end_manager(allowed_devp2p_warmup_time: Duration, client: &dyn BlockChainClient) -> Option { + + + if client.is_syncing() { + // if we are syncing, we do not need to create an early epoch end manager yet. + // if we are syncing as a validator, and it is really this epoch, + // this way the creation of the early epoch end manager is created in a subsequent call, + // when we are at the tip of the chain, and get the correct state for + // - flagged validators + // - start_time + // The whole window for the devp2p warmup time is granted in this case, + // therefore this node won't flag anyone in the near future. + return None; + } + + // figure out if we have to retrieve the data from the smart contracts. + // if the epoch start did just happen, + // we do not have to retrieve the data from the smart contracts. + + + let result = Self { current_tracked_epoch_number: 0, start_time: Instant::now(), - allowed_devp2p_warmup_time: allowed_devp2p_warmup_time, + allowed_devp2p_warmup_time, validators: Vec::new(), - } + flagged_validators: Vec::new(), + }; + + return Some(result); + } + /// notifies about a new epoch. + /// This (re)inits the Manager, no early epoch end happened. pub fn notify_new_epoch(&mut self, epoch: u64, validators: Vec ) { self.current_tracked_epoch_number = epoch; @@ -38,4 +70,25 @@ impl EarlyEpochEndManager { self.start_time = Instant::now(); } + /// retrieves the information from smart contracts which validators are currently flagged. + fn get_current_flagged_validators_from_contracts() -> Vec { + + // todo: call smart contract. + return Vec::new(); + } + + fn notify_about_missing_validator(&mut self, validator: NodeId, full_client: &dyn BlockChainClient) { + + // todo: send transaction to smart contract about missing validator. + } + + /// decides on the memorium data if we should update to contract data. + pub fn decide(memorium: &HbbftMessageMemorium) { + + + // note: We do not take care if hbbft message memorium might not have processed some of the messages yet, + // since it is not important to do the decision based on the latest data, since the decide method will be called + // again. + } + } \ No newline at end of file From ab40f4d78aa5f17accdad5cf505a752eb1e5db8a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 21 Nov 2023 18:14:41 +0100 Subject: [PATCH 103/687] refactored hbbft_message_memorium, so it allows read access from not mut references. --- .../engines/hbbft/hbbft_message_memorium.rs | 103 ++++++++++++++---- 1 file changed, 80 insertions(+), 23 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index adad6a4c7..fa8e95118 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -221,6 +221,14 @@ impl NodeStakingEpochHistory { + self.get_total_error_sealing_messages() } + pub fn get_sealing_message(&self) -> u64 { + u64::max(self.last_late_sealing_message, self.last_good_sealing_message) + } + + pub fn get_last_late_sealing_message(&self) -> u64 { + self.last_late_sealing_message + } + pub fn get_last_good_sealing_message(&self) -> u64 { self.last_good_sealing_message } @@ -423,7 +431,23 @@ impl StakingEpochHistory { } } - fn get_history_for_node(&mut self, node_id: &NodeId) -> &mut NodeStakingEpochHistory { + pub fn get_history_for_node(&self, node_id: &NodeId) -> Option<&NodeStakingEpochHistory> { + let index_result = self + .node_staking_epoch_histories + .iter() + .position(|x| &x.get_node_id() == node_id); + + match index_result { + Some(index) => { + return Some(&self.node_staking_epoch_histories[index]); + } + None => { + return None; + } + }; + } + + pub fn ensure_history_for_node(&mut self, node_id: &NodeId) -> &mut NodeStakingEpochHistory { let index_result = self .node_staking_epoch_histories .iter_mut() @@ -441,38 +465,39 @@ impl StakingEpochHistory { }; } + pub fn on_seal_good(&mut self, event: &SealEventGood) { let staking_epoch_start_block = self.staking_epoch_start_block; if event.block_num > self.highest_block_num { self.highest_block_num = event.block_num; } - let node_staking_epoch_history = self.get_history_for_node(&event.node_id); + let node_staking_epoch_history = self.ensure_history_for_node(&event.node_id); node_staking_epoch_history.add_good_seal_event(event, staking_epoch_start_block); self.exported = false; } pub fn on_seal_late(&mut self, event: &SealEventLate) { let staking_epoch_start_block = self.staking_epoch_start_block; - let node_staking_epoch_history = self.get_history_for_node(&event.node_id); + let node_staking_epoch_history = self.ensure_history_for_node(&event.node_id); node_staking_epoch_history.add_seal_event_late(event, staking_epoch_start_block); self.exported = false; } pub fn on_seal_bad(&mut self, event: &SealEventBad) { let staking_epoch_start_block = self.staking_epoch_start_block; - let node_staking_epoch_history = self.get_history_for_node(&event.node_id); + let node_staking_epoch_history = self.ensure_history_for_node(&event.node_id); node_staking_epoch_history.add_bad_seal_event(event, staking_epoch_start_block); self.exported = false; } pub fn on_message_faulty(&mut self, event: &MessageEventFaulty) { - let node_staking_epoch_history = self.get_history_for_node(&event.node_id); + let node_staking_epoch_history = self.ensure_history_for_node(&event.node_id); node_staking_epoch_history.add_message_event_faulty(event); self.exported = false; } pub fn on_message_good(&mut self, event: &MessageEventGood) { - let node_staking_epoch_history = self.get_history_for_node(&event.node_id); + let node_staking_epoch_history = self.ensure_history_for_node(&event.node_id); node_staking_epoch_history.add_message_event_good(event); self.exported = false; } @@ -846,7 +871,7 @@ impl HbbftMessageMemorium { fn on_seal_good(&mut self, seal: &SealEventGood) -> bool { debug!(target: "hbbft_message_memorium", "working on good seal!: {:?}", seal); let block_num = seal.block_num; - if let Some(epoch_history) = self.get_staking_epoch_history(block_num) { + if let Some(epoch_history) = self.get_staking_epoch_history_mut(block_num) { epoch_history.on_seal_good(seal); return true; } else { @@ -873,7 +898,7 @@ impl HbbftMessageMemorium { fn on_seal_late(&mut self, seal: &SealEventLate) -> bool { debug!(target: "hbbft_message_memorium", "working on good seal!: {:?}", seal); let block_num = seal.block_num; - if let Some(epoch_history) = self.get_staking_epoch_history(block_num) { + if let Some(epoch_history) = self.get_staking_epoch_history_mut(block_num) { epoch_history.on_seal_late(seal); return true; } else { @@ -884,7 +909,7 @@ impl HbbftMessageMemorium { fn on_seal_bad(&mut self, seal: &SealEventBad) -> bool { debug!(target: "hbbft_message_memorium", "working on good seal!: {:?}", seal); let block_num = seal.block_num; - if let Some(epoch_history) = self.get_staking_epoch_history(block_num) { + if let Some(epoch_history) = self.get_staking_epoch_history_mut(block_num) { epoch_history.on_seal_bad(seal); return true; } else { @@ -895,7 +920,7 @@ impl HbbftMessageMemorium { fn on_message_faulty(&mut self, event: &MessageEventFaulty) -> bool { debug!(target: "hbbft_message_memorium", "working on faulty message event!: {:?}", event); let block_num = event.block_num; - if let Some(epoch_history) = self.get_staking_epoch_history(block_num) { + if let Some(epoch_history) = self.get_staking_epoch_history_mut(block_num) { epoch_history.on_message_faulty(event); return true; } else { @@ -905,12 +930,26 @@ impl HbbftMessageMemorium { fn on_message_good(&mut self, event: &MessageEventGood) -> bool { debug!(target: "hbbft_message_memorium", "working on good message event!: {:?}", event); - if let Some(epoch_history) = self.get_staking_epoch_history(event.block_num) { + if let Some(epoch_history) = self.get_staking_epoch_history_mut(event.block_num) { epoch_history.on_message_good(event); return true; } else { return self.event_handle_history_not_set_up(event.block_num); } + } + + pub fn get_validator_data(&self, block_num: u64, node_id: &NodeId) -> Option<&Vec>{ + + if let Some(epoch_history) = self.get_staking_epoch_history(block_num) { + return Some(&epoch_history.node_staking_epoch_histories) + } + None + } + + pub fn get_validator_last_late_block(&self, hbbft_epoch_number: u64) { + + + } // report that hbbft has switched to a new staking epoch @@ -950,20 +989,38 @@ impl HbbftMessageMemorium { } } - fn get_staking_epoch_history(&mut self, block_num: u64) -> Option<&mut StakingEpochHistory> { - { - //let histories = &mut self.staking_epoch_history; - - // self.staking_epoch_history.get_mut(index) - for i in 0..self.staking_epoch_history.len() { - let e = &self.staking_epoch_history[i]; - if block_num >= e.staking_epoch_start_block - && (e.staking_epoch_end_block == 0 || block_num <= e.staking_epoch_end_block) - { - return Some(&mut self.staking_epoch_history[i]); - } + + pub fn get_staking_epoch_history(&self, block_num: u64) -> Option<&StakingEpochHistory> { + + //let histories = &mut self.staking_epoch_history; + + // self.staking_epoch_history.get_mut(index) + for i in 0..self.staking_epoch_history.len() { + let e = &self.staking_epoch_history[i]; + if block_num >= e.staking_epoch_start_block + && (e.staking_epoch_end_block == 0 || block_num <= e.staking_epoch_end_block) + { + return Some(&self.staking_epoch_history[i]); + } + } + + None + } + + fn get_staking_epoch_history_mut(&mut self, block_num: u64) -> Option<&mut StakingEpochHistory> { + + //let histories = &mut self.staking_epoch_history; + + // self.staking_epoch_history.get_mut(index) + for i in 0..self.staking_epoch_history.len() { + let e = &self.staking_epoch_history[i]; + if block_num >= e.staking_epoch_start_block + && (e.staking_epoch_end_block == 0 || block_num <= e.staking_epoch_end_block) + { + return Some(&mut self.staking_epoch_history[i]); } } + // if we have not found a staking epoch, we add it if possible. // this can happen during timings, where new messages get's process, From 151caf813702dda1f4a3fcfdc3ef571db6661f33 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 21 Nov 2023 18:15:24 +0100 Subject: [PATCH 104/687] cargo fmt --all -- --config imports_granularity=Crate --- .../engines/hbbft/hbbft_message_memorium.rs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index fa8e95118..ef2067a42 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -222,7 +222,10 @@ impl NodeStakingEpochHistory { } pub fn get_sealing_message(&self) -> u64 { - u64::max(self.last_late_sealing_message, self.last_good_sealing_message) + u64::max( + self.last_late_sealing_message, + self.last_good_sealing_message, + ) } pub fn get_last_late_sealing_message(&self) -> u64 { @@ -465,7 +468,6 @@ impl StakingEpochHistory { }; } - pub fn on_seal_good(&mut self, event: &SealEventGood) { let staking_epoch_start_block = self.staking_epoch_start_block; if event.block_num > self.highest_block_num { @@ -938,20 +940,19 @@ impl HbbftMessageMemorium { } } - pub fn get_validator_data(&self, block_num: u64, node_id: &NodeId) -> Option<&Vec>{ - + pub fn get_validator_data( + &self, + block_num: u64, + node_id: &NodeId, + ) -> Option<&Vec> { if let Some(epoch_history) = self.get_staking_epoch_history(block_num) { - return Some(&epoch_history.node_staking_epoch_histories) + return Some(&epoch_history.node_staking_epoch_histories); } None - } - - pub fn get_validator_last_late_block(&self, hbbft_epoch_number: u64) { - - - } + pub fn get_validator_last_late_block(&self, hbbft_epoch_number: u64) {} + // report that hbbft has switched to a new staking epoch pub fn report_new_epoch(&mut self, staking_epoch: u64, staking_epoch_start_block: u64) { warn!(target: "hbbft_message_memorium", "report new epoch: {}", staking_epoch); @@ -989,9 +990,7 @@ impl HbbftMessageMemorium { } } - pub fn get_staking_epoch_history(&self, block_num: u64) -> Option<&StakingEpochHistory> { - //let histories = &mut self.staking_epoch_history; // self.staking_epoch_history.get_mut(index) @@ -1007,8 +1006,10 @@ impl HbbftMessageMemorium { None } - fn get_staking_epoch_history_mut(&mut self, block_num: u64) -> Option<&mut StakingEpochHistory> { - + fn get_staking_epoch_history_mut( + &mut self, + block_num: u64, + ) -> Option<&mut StakingEpochHistory> { //let histories = &mut self.staking_epoch_history; // self.staking_epoch_history.get_mut(index) @@ -1020,7 +1021,6 @@ impl HbbftMessageMemorium { return Some(&mut self.staking_epoch_history[i]); } } - // if we have not found a staking epoch, we add it if possible. // this can happen during timings, where new messages get's process, From 0d3ea6dcf2b8c3bb1e9bfaf83af6d8f022cc1125 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 21 Nov 2023 18:15:48 +0100 Subject: [PATCH 105/687] decision implementation --- .../hbbft/hbbft_early_epoch_end_manager.rs | 81 +++++++++++++------ 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index ff3eb01cb..1a76e716e 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -1,17 +1,17 @@ -use std::time::{Instant, Duration}; use crate::client::BlockChainClient; +use std::time::{Duration, Instant}; -use super::{NodeId, hbbft_message_memorium::HbbftMessageMemorium}; - +use super::{hbbft_message_memorium::HbbftMessageMemorium, NodeId}; pub(crate) struct EarlyEpochEndManager { - /// The current epoch number. current_tracked_epoch_number: u64, /// epoch manager start up time. start_time: Instant, + start_block: u64, + /// allowed devp2p warmup time. allowed_devp2p_warmup_time: Duration, @@ -22,21 +22,22 @@ pub(crate) struct EarlyEpochEndManager { flagged_validators: Vec, } - -impl EarlyEpochEndManager { - +impl EarlyEpochEndManager { /// creates a new EarlyEpochEndManager, /// if conditions are matching to create one. /// It is expected that this function is only called if the node is a validator. /// This prerequesite will be checked and if not met, panics. - pub fn create_early_epoch_end_manager(allowed_devp2p_warmup_time: Duration, client: &dyn BlockChainClient) -> Option { - - + pub fn create_early_epoch_end_manager( + allowed_devp2p_warmup_time: Duration, + client: &dyn BlockChainClient, + epoch_number: u64, + epoch_start_block: u64, + ) -> Option { if client.is_syncing() { // if we are syncing, we do not need to create an early epoch end manager yet. // if we are syncing as a validator, and it is really this epoch, // this way the creation of the early epoch end manager is created in a subsequent call, - // when we are at the tip of the chain, and get the correct state for + // when we are at the tip of the chain, and get the correct state for // - flagged validators // - start_time // The whole window for the devp2p warmup time is granted in this case, @@ -45,26 +46,24 @@ impl EarlyEpochEndManager { } // figure out if we have to retrieve the data from the smart contracts. - // if the epoch start did just happen, + // if the epoch start did just happen, // we do not have to retrieve the data from the smart contracts. - let result = Self { - current_tracked_epoch_number: 0, + current_tracked_epoch_number: epoch_number, start_time: Instant::now(), + start_block: epoch_start_block, allowed_devp2p_warmup_time, validators: Vec::new(), flagged_validators: Vec::new(), }; return Some(result); - } /// notifies about a new epoch. /// This (re)inits the Manager, no early epoch end happened. - pub fn notify_new_epoch(&mut self, epoch: u64, validators: Vec ) { - + pub fn notify_new_epoch(&mut self, epoch: u64, validators: Vec) { self.current_tracked_epoch_number = epoch; self.validators = validators; self.start_time = Instant::now(); @@ -72,23 +71,59 @@ impl EarlyEpochEndManager { /// retrieves the information from smart contracts which validators are currently flagged. fn get_current_flagged_validators_from_contracts() -> Vec { - // todo: call smart contract. return Vec::new(); } - fn notify_about_missing_validator(&mut self, validator: NodeId, full_client: &dyn BlockChainClient) { - + fn notify_about_missing_validator( + &mut self, + validator: &NodeId, + full_client: &dyn BlockChainClient, + ) /* -> result of contract call errr */ + { // todo: send transaction to smart contract about missing validator. + + warn!(target: "engine", "early-epoch-end: notify about missing validator: {:?}", validator); } /// decides on the memorium data if we should update to contract data. - pub fn decide(memorium: &HbbftMessageMemorium) { + pub fn decide( + &mut self, + memorium: &HbbftMessageMemorium, + block_num: u64, + full_client: &dyn BlockChainClient, + ) { + // if devp2p warmup time is not over yet, we do not have to do anything. + if self.start_time.elapsed() < self.allowed_devp2p_warmup_time { + return; + } + let treshold: u64 = 10; + + if self.start_block + treshold < block_num { + // not enought blocks have passed this epoch, + // to judge other nodes. + return; + } + + //full_client.best_block_header() + // get current state of missing validators from hbbftMemorium. + if let Some(epoch_history) = memorium.get_staking_epoch_history(block_num) { + for validator in &self.validators.clone() { + if let Some(node_history) = epoch_history.get_history_for_node(validator) { + let last_sealing_message = node_history.get_sealing_message(); + + if last_sealing_message < block_num - treshold { + self.notify_about_missing_validator(&validator, full_client); + } + } + // todo: if the systems switched from block based measurement to time based measurement. + } + } + // nothing to do: no history yet. // note: We do not take care if hbbft message memorium might not have processed some of the messages yet, // since it is not important to do the decision based on the latest data, since the decide method will be called // again. } - -} \ No newline at end of file +} From fc798ee6b990b72826f930fc7a5f3a1981b335da Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 21 Nov 2023 18:22:24 +0100 Subject: [PATCH 106/687] if we are syncing, we wont do any blaming. --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 1a76e716e..b75f08845 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -98,6 +98,11 @@ impl EarlyEpochEndManager { return; } + if full_client.is_syncing() { + // if we are syncing, we wont do any blaming. + return; + } + let treshold: u64 = 10; if self.start_block + treshold < block_num { From b2d1f3697b98380c94f40fd897b78de0bfa1c64a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 22 Nov 2023 13:20:02 +0100 Subject: [PATCH 107/687] renamed EarlyEpochEndManager to HbbftEarlyEpochEndManager data interation in hbbt engine --- .../hbbft/hbbft_early_epoch_end_manager.rs | 19 ++++++++++++++++--- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 4 +++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index b75f08845..4564d715f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -3,7 +3,7 @@ use std::time::{Duration, Instant}; use super::{hbbft_message_memorium::HbbftMessageMemorium, NodeId}; -pub(crate) struct EarlyEpochEndManager { +pub(crate) struct HbbftEarlyEpochEndManager { /// The current epoch number. current_tracked_epoch_number: u64, @@ -22,7 +22,7 @@ pub(crate) struct EarlyEpochEndManager { flagged_validators: Vec, } -impl EarlyEpochEndManager { +impl HbbftEarlyEpochEndManager { /// creates a new EarlyEpochEndManager, /// if conditions are matching to create one. /// It is expected that this function is only called if the node is a validator. @@ -32,7 +32,7 @@ impl EarlyEpochEndManager { client: &dyn BlockChainClient, epoch_number: u64, epoch_start_block: u64, - ) -> Option { + ) -> Option { if client.is_syncing() { // if we are syncing, we do not need to create an early epoch end manager yet. // if we are syncing as a validator, and it is really this epoch, @@ -132,3 +132,16 @@ impl EarlyEpochEndManager { // again. } } + + + +/// testing early epoch stop manager. +#[cfg(test)] +mod tests { + + #[test] + fn test_early_epoch_end() { + + // should + } +} \ No newline at end of file diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index e08f1f239..db87e14e2 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1,4 +1,4 @@ -use super::block_reward_hbbft::BlockRewardContract; +use super::{block_reward_hbbft::BlockRewardContract, hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager}; use crate::{ client::BlockChainClient, engines::hbbft::{ @@ -88,6 +88,7 @@ pub struct HoneyBadgerBFT { has_connected_to_validator_set: AtomicBool, peers_management: Mutex, current_minimum_gas_price: Mutex>, + early_epoch_manager: Mutex>, } struct TransitionHandler { @@ -445,6 +446,7 @@ impl HoneyBadgerBFT { has_connected_to_validator_set: AtomicBool::new(false), peers_management: Mutex::new(HbbftPeersManagement::new()), current_minimum_gas_price: Mutex::new(None), + early_epoch_manager: Mutex::new(None), }); if !engine.params.is_unit_test.unwrap_or(false) { From da36579d77dd58f32f3b85c4b34981126d4ee36a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 23 Nov 2023 13:17:50 +0100 Subject: [PATCH 108/687] dispatchers allows to access the memorium data now. --- crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index ef2067a42..ef6a01ff2 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -719,6 +719,10 @@ impl HbbftMessageDispatcher { .write() .report_new_epoch(staking_epoch, staking_epoch_start_block); } + + pub fn get_memorium(&self) -> &std::sync::Arc> { + return &self.memorial; + } } pub(crate) struct HbbftMessageMemorium { From a8bc7adf8a15afc66ac55f9ff68a2382651979f5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 23 Nov 2023 13:30:17 +0100 Subject: [PATCH 109/687] comments for hbbft_early_epoch_end_manager --- .../hbbft/hbbft_early_epoch_end_manager.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 4564d715f..f0267b590 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -81,12 +81,23 @@ impl HbbftEarlyEpochEndManager { full_client: &dyn BlockChainClient, ) /* -> result of contract call errr */ { + // let mining_address = match self.signer.read().as_ref() { + // Some(signer) => signer.address(), + // None => { + // // we do not have a signer on Full and RPC nodes. + // // here is a possible performance improvement: + // // this won't change during the lifetime of the application ?! + // return Ok(()); + // } + // }; + // todo: send transaction to smart contract about missing validator. warn!(target: "engine", "early-epoch-end: notify about missing validator: {:?}", validator); } /// decides on the memorium data if we should update to contract data. + /// end executes them. pub fn decide( &mut self, memorium: &HbbftMessageMemorium, @@ -133,8 +144,6 @@ impl HbbftEarlyEpochEndManager { } } - - /// testing early epoch stop manager. #[cfg(test)] mod tests { @@ -142,6 +151,6 @@ mod tests { #[test] fn test_early_epoch_end() { - // should + // should } -} \ No newline at end of file +} From 0c11c4c9a2f378be58953519c3be956b51016191 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 23 Nov 2023 13:31:45 +0100 Subject: [PATCH 110/687] first integration of hbbft_early_epoch_end_manager into the hbbft_engine. TODO: get correct numbers for epoch_num and block_num. --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index db87e14e2..5be1d78e8 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1,4 +1,7 @@ -use super::{block_reward_hbbft::BlockRewardContract, hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager}; +use super::{ + block_reward_hbbft::BlockRewardContract, + hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, +}; use crate::{ client::BlockChainClient, engines::hbbft::{ @@ -970,6 +973,53 @@ impl HoneyBadgerBFT { let should_connect_to_validator_set = self.should_connect_to_validator_set(); + if let Some(memorium) = self + .hbbft_message_dispatcher + .get_memorium() + .try_read_for(Duration::from_millis(300)) + { + let epoch_num = 0; + let block_num = 0; + + // this is currently the only location where we lock early epoch manager - + // so this should never cause a deadlock, and we do not have to try_lock_for + let mut lock_guard = self.early_epoch_manager.lock(); + + match lock_guard.as_mut() { + Some(ealry_epoch_end_manager) => { + ealry_epoch_end_manager.decide( + &memorium, + block_num, + block_chain_client, + ); + } + None => { + warn!(target: "engine", "no Early Epoch END Manager configured found yet."); + + let allowed_devp2p_warmup_time = Duration::from_secs(120); + + // todo: get epoch start block + let epoch_start_block = 0; + + // let ealry_epoch_manager + *lock_guard = + HbbftEarlyEpochEndManager::create_early_epoch_end_manager( + allowed_devp2p_warmup_time, + block_chain_client, + epoch_num, + epoch_start_block, + ); + + if let Some(manager) = lock_guard.as_mut() { + + manager.decide(&memorium, block_num, block_chain_client); + } + } + } + } else { + warn!(target: "engine", "could not acquire read lock for memorium to decide on ealry_epoch_end_manager in do_validator_engine_actions."); + } + // if we do not have to do anything, we can return early. if !(should_handle_availability_announcements || should_handle_internet_address_announcements @@ -982,7 +1032,7 @@ impl HoneyBadgerBFT { // staking by mining address could be cached. // but it COULD also get changed in the contracts, during the time the node is running. // most likely since a Node can get staked, and than it becomes a mining address. - // a good solution for this is not to do this that fequently. + // a good solution for this is not to do this expensive operation that fequently. let staking_address = match staking_by_mining_address( engine_client, &mining_address, @@ -1052,6 +1102,7 @@ impl HoneyBadgerBFT { } } } + return Ok(()); } From ac0946c2e0a45993c85a2e662bbff42a8089b134 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 23 Nov 2023 14:23:36 +0100 Subject: [PATCH 111/687] cache for flagged validators and respecting of that cache in the decide function. --- .../hbbft/hbbft_early_epoch_end_manager.rs | 40 +++++++++++++++++-- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 18 ++++----- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index f0267b590..08b55f233 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -18,7 +18,8 @@ pub(crate) struct HbbftEarlyEpochEndManager { /// public keys of all validators for this epoch. validators: Vec, - /// current flagged validators + /// current flagged validators, unordered list - no performance issue, since this can + /// only grow up to 7 elements for a usual set of 25 nodes. flagged_validators: Vec, } @@ -70,7 +71,9 @@ impl HbbftEarlyEpochEndManager { } /// retrieves the information from smart contracts which validators are currently flagged. - fn get_current_flagged_validators_from_contracts() -> Vec { + fn get_current_flagged_validators_from_contracts( + full_client: &dyn BlockChainClient, + ) -> Vec { // todo: call smart contract. return Vec::new(); } @@ -93,7 +96,21 @@ impl HbbftEarlyEpochEndManager { // todo: send transaction to smart contract about missing validator. - warn!(target: "engine", "early-epoch-end: notify about missing validator: {:?}", validator); + self.flagged_validators.push(validator.clone()); + warn!(target: "engine", "TODO: early-epoch-end: notify about missing validator: {:?}", validator); + } + + fn notify_about_validator_reconnect( + &mut self, + validator: &NodeId, + full_client: &dyn BlockChainClient, + ) { + if let Some(index) = self.flagged_validators.iter().position(|x| x == validator) { + self.flagged_validators.remove(index); + warn!(target: "engine", "TODO: early-epoch-end: notify about reconnected validator: {:?}", validator); + } else { + error!(target: "engine", " Could not find reconnected validator in flagged validators."); + } } /// decides on the memorium data if we should update to contract data. @@ -122,6 +139,9 @@ impl HbbftEarlyEpochEndManager { return; } + let current_flagged_validators = + Self::get_current_flagged_validators_from_contracts(full_client); + //full_client.best_block_header() // get current state of missing validators from hbbftMemorium. if let Some(epoch_history) = memorium.get_staking_epoch_history(block_num) { @@ -130,7 +150,19 @@ impl HbbftEarlyEpochEndManager { let last_sealing_message = node_history.get_sealing_message(); if last_sealing_message < block_num - treshold { - self.notify_about_missing_validator(&validator, full_client); + // we do not have to send notification, if we already did so. + + if !current_flagged_validators.contains(validator) { + // this function will also add the validator to the list of flagged validators. + self.notify_about_missing_validator(&validator, full_client); + } + } else { + // this validator is OK. + // maybe it was flagged and we need to unflag it ? + + if current_flagged_validators.contains(validator) { + self.notify_about_validator_reconnect(&validator, full_client); + } } } // todo: if the systems switched from block based measurement to time based measurement. diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 5be1d78e8..41881f1cc 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -981,7 +981,7 @@ impl HoneyBadgerBFT { let epoch_num = 0; let block_num = 0; - // this is currently the only location where we lock early epoch manager - + // this is currently the only location where we lock early epoch manager - // so this should never cause a deadlock, and we do not have to try_lock_for let mut lock_guard = self.early_epoch_manager.lock(); @@ -1002,16 +1002,14 @@ impl HoneyBadgerBFT { let epoch_start_block = 0; // let ealry_epoch_manager - *lock_guard = - HbbftEarlyEpochEndManager::create_early_epoch_end_manager( - allowed_devp2p_warmup_time, - block_chain_client, - epoch_num, - epoch_start_block, - ); - - if let Some(manager) = lock_guard.as_mut() { + *lock_guard = HbbftEarlyEpochEndManager::create_early_epoch_end_manager( + allowed_devp2p_warmup_time, + block_chain_client, + epoch_num, + epoch_start_block, + ); + if let Some(manager) = lock_guard.as_mut() { manager.decide(&memorium, block_num, block_chain_client); } } From 4d07709fee020c413a8ddc01b53e117d5cceb2c1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 23 Nov 2023 14:35:22 +0100 Subject: [PATCH 112/687] fixed: do not query current validators - use cached values. retrieve cached values from contracts. --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 08b55f233..5a99dde2f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -56,7 +56,7 @@ impl HbbftEarlyEpochEndManager { start_block: epoch_start_block, allowed_devp2p_warmup_time, validators: Vec::new(), - flagged_validators: Vec::new(), + flagged_validators: Self::get_current_flagged_validators_from_contracts(client), }; return Some(result); @@ -139,9 +139,6 @@ impl HbbftEarlyEpochEndManager { return; } - let current_flagged_validators = - Self::get_current_flagged_validators_from_contracts(full_client); - //full_client.best_block_header() // get current state of missing validators from hbbftMemorium. if let Some(epoch_history) = memorium.get_staking_epoch_history(block_num) { @@ -152,7 +149,7 @@ impl HbbftEarlyEpochEndManager { if last_sealing_message < block_num - treshold { // we do not have to send notification, if we already did so. - if !current_flagged_validators.contains(validator) { + if !self.flagged_validators.contains(validator) { // this function will also add the validator to the list of flagged validators. self.notify_about_missing_validator(&validator, full_client); } @@ -160,7 +157,7 @@ impl HbbftEarlyEpochEndManager { // this validator is OK. // maybe it was flagged and we need to unflag it ? - if current_flagged_validators.contains(validator) { + if self.flagged_validators.contains(validator) { self.notify_about_validator_reconnect(&validator, full_client); } } From 082f2a53d3e127ae827c01f8371f2da8a84a9d5c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 24 Nov 2023 07:26:07 +0100 Subject: [PATCH 113/687] refactored ealry epoch end into new function handle_early_epoch_end . now gathering epoch number and epoch start block from hbbft state --- .../hbbft/hbbft_early_epoch_end_manager.rs | 13 ++- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 102 ++++++++++-------- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 5a99dde2f..cbaed64fd 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -1,3 +1,5 @@ +use types::ids::BlockId; + use crate::client::BlockChainClient; use std::time::{Duration, Instant}; @@ -118,7 +120,6 @@ impl HbbftEarlyEpochEndManager { pub fn decide( &mut self, memorium: &HbbftMessageMemorium, - block_num: u64, full_client: &dyn BlockChainClient, ) { // if devp2p warmup time is not over yet, we do not have to do anything. @@ -131,6 +132,16 @@ impl HbbftEarlyEpochEndManager { return; } + //full_client. + + + let block_num = if let Some(block) = full_client.block(BlockId::Latest) { + block.number() + } else { + error!(target:"engine", "could not retrieve latest block."); + return; + }; + let treshold: u64 = 10; if self.start_block + treshold < block_num { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 41881f1cc..3fd47a1b0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -932,6 +932,61 @@ impl HoneyBadgerBFT { false } + fn handle_early_epoch_end( + &self, + block_chain_client: &dyn BlockChainClient, + mining_address: Address, + ) { + if let Some(memorium) = self + .hbbft_message_dispatcher + .get_memorium() + .try_read_for(Duration::from_millis(300)) + { + // this is currently the only location where we lock early epoch manager - + // so this should never cause a deadlock, and we do not have to try_lock_for + let mut lock_guard = self.early_epoch_manager.lock(); + + match lock_guard.as_mut() { + Some(ealry_epoch_end_manager) => { + ealry_epoch_end_manager.decide(&memorium, block_chain_client); + } + None => { + + // todo: acquire allowed devp2p warmup time from contracts ?! + let allowed_devp2p_warmup_time = Duration::from_secs(120); + + let hbbft_state = if let Some(s) = + self.hbbft_state.try_read_for(Duration::from_millis(300)) + { + s + } else { + warn!(target: "engine", "early-epoch-end: could not acquire read lock for hbbft state."); + return; + }; + + let epoch_num = hbbft_state.get_current_posdao_epoch(); + let epoch_start_block = hbbft_state.get_current_posdao_epoch_start_block(); + + // we got everything we need from hbbft_state - drop lock ASAP. + std::mem::drop(hbbft_state); + + *lock_guard = HbbftEarlyEpochEndManager::create_early_epoch_end_manager( + allowed_devp2p_warmup_time, + block_chain_client, + epoch_num, + epoch_start_block, + ); + + if let Some(manager) = lock_guard.as_mut() { + manager.decide(&memorium, block_chain_client); + } + } + } + } else { + warn!(target: "engine", "could not acquire read lock for memorium to decide on ealry_epoch_end_manager in do_validator_engine_actions."); + } + } + // some actions are required for hbbft nodes. // this functions figures out what kind of actions are required and executes them. // this will lock the client and some deeper layers. @@ -966,6 +1021,8 @@ impl HoneyBadgerBFT { } }; + self.handle_early_epoch_end(block_chain_client, mining_address); + let should_handle_availability_announcements = self.should_handle_availability_announcements(); let should_handle_internet_address_announcements = @@ -973,51 +1030,6 @@ impl HoneyBadgerBFT { let should_connect_to_validator_set = self.should_connect_to_validator_set(); - if let Some(memorium) = self - .hbbft_message_dispatcher - .get_memorium() - .try_read_for(Duration::from_millis(300)) - { - let epoch_num = 0; - let block_num = 0; - - // this is currently the only location where we lock early epoch manager - - // so this should never cause a deadlock, and we do not have to try_lock_for - let mut lock_guard = self.early_epoch_manager.lock(); - - match lock_guard.as_mut() { - Some(ealry_epoch_end_manager) => { - ealry_epoch_end_manager.decide( - &memorium, - block_num, - block_chain_client, - ); - } - None => { - warn!(target: "engine", "no Early Epoch END Manager configured found yet."); - - let allowed_devp2p_warmup_time = Duration::from_secs(120); - - // todo: get epoch start block - let epoch_start_block = 0; - - // let ealry_epoch_manager - *lock_guard = HbbftEarlyEpochEndManager::create_early_epoch_end_manager( - allowed_devp2p_warmup_time, - block_chain_client, - epoch_num, - epoch_start_block, - ); - - if let Some(manager) = lock_guard.as_mut() { - manager.decide(&memorium, block_num, block_chain_client); - } - } - } - } else { - warn!(target: "engine", "could not acquire read lock for memorium to decide on ealry_epoch_end_manager in do_validator_engine_actions."); - } - // if we do not have to do anything, we can return early. if !(should_handle_availability_announcements || should_handle_internet_address_announcements From 4df26324ab599ab7e4b48c12d548666651bdd155 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 24 Nov 2023 13:03:15 +0100 Subject: [PATCH 114/687] made locks linear where possible instead of nested. passed through mining address for early epoch switch --- .../hbbft/hbbft_early_epoch_end_manager.rs | 19 ++++++-- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 44 +++++++++---------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index cbaed64fd..385747dcc 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -1,3 +1,4 @@ +use ethereum_types::Address; use types::ids::BlockId; use crate::client::BlockChainClient; @@ -84,6 +85,7 @@ impl HbbftEarlyEpochEndManager { &mut self, validator: &NodeId, full_client: &dyn BlockChainClient, + mining_address: &Address, ) /* -> result of contract call errr */ { // let mining_address = match self.signer.read().as_ref() { @@ -106,6 +108,7 @@ impl HbbftEarlyEpochEndManager { &mut self, validator: &NodeId, full_client: &dyn BlockChainClient, + mining_address: &Address, ) { if let Some(index) = self.flagged_validators.iter().position(|x| x == validator) { self.flagged_validators.remove(index); @@ -121,6 +124,7 @@ impl HbbftEarlyEpochEndManager { &mut self, memorium: &HbbftMessageMemorium, full_client: &dyn BlockChainClient, + mining_address: &Address, ) { // if devp2p warmup time is not over yet, we do not have to do anything. if self.start_time.elapsed() < self.allowed_devp2p_warmup_time { @@ -133,9 +137,8 @@ impl HbbftEarlyEpochEndManager { } //full_client. - - let block_num = if let Some(block) = full_client.block(BlockId::Latest) { + let block_num = if let Some(block) = full_client.block(BlockId::Latest) { block.number() } else { error!(target:"engine", "could not retrieve latest block."); @@ -162,14 +165,22 @@ impl HbbftEarlyEpochEndManager { if !self.flagged_validators.contains(validator) { // this function will also add the validator to the list of flagged validators. - self.notify_about_missing_validator(&validator, full_client); + self.notify_about_missing_validator( + &validator, + full_client, + mining_address, + ); } } else { // this validator is OK. // maybe it was flagged and we need to unflag it ? if self.flagged_validators.contains(validator) { - self.notify_about_validator_reconnect(&validator, full_client); + self.notify_about_validator_reconnect( + &validator, + full_client, + mining_address, + ); } } } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 3fd47a1b0..6f2357689 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -935,8 +935,25 @@ impl HoneyBadgerBFT { fn handle_early_epoch_end( &self, block_chain_client: &dyn BlockChainClient, - mining_address: Address, + mining_address: &Address, ) { + // todo: acquire allowed devp2p warmup time from contracts ?! + let allowed_devp2p_warmup_time = Duration::from_secs(120); + + let hbbft_state = if let Some(s) = self.hbbft_state.try_read_for(Duration::from_millis(300)) + { + s + } else { + warn!(target: "engine", "early-epoch-end: could not acquire read lock for hbbft state."); + return; + }; + + let epoch_num = hbbft_state.get_current_posdao_epoch(); + let epoch_start_block = hbbft_state.get_current_posdao_epoch_start_block(); + + // we got everything we need from hbbft_state - drop lock ASAP. + std::mem::drop(hbbft_state); + if let Some(memorium) = self .hbbft_message_dispatcher .get_memorium() @@ -948,28 +965,9 @@ impl HoneyBadgerBFT { match lock_guard.as_mut() { Some(ealry_epoch_end_manager) => { - ealry_epoch_end_manager.decide(&memorium, block_chain_client); + ealry_epoch_end_manager.decide(&memorium, block_chain_client, mining_address); } None => { - - // todo: acquire allowed devp2p warmup time from contracts ?! - let allowed_devp2p_warmup_time = Duration::from_secs(120); - - let hbbft_state = if let Some(s) = - self.hbbft_state.try_read_for(Duration::from_millis(300)) - { - s - } else { - warn!(target: "engine", "early-epoch-end: could not acquire read lock for hbbft state."); - return; - }; - - let epoch_num = hbbft_state.get_current_posdao_epoch(); - let epoch_start_block = hbbft_state.get_current_posdao_epoch_start_block(); - - // we got everything we need from hbbft_state - drop lock ASAP. - std::mem::drop(hbbft_state); - *lock_guard = HbbftEarlyEpochEndManager::create_early_epoch_end_manager( allowed_devp2p_warmup_time, block_chain_client, @@ -978,7 +976,7 @@ impl HoneyBadgerBFT { ); if let Some(manager) = lock_guard.as_mut() { - manager.decide(&memorium, block_chain_client); + manager.decide(&memorium, block_chain_client, mining_address); } } } @@ -1021,7 +1019,7 @@ impl HoneyBadgerBFT { } }; - self.handle_early_epoch_end(block_chain_client, mining_address); + self.handle_early_epoch_end(block_chain_client, &mining_address); let should_handle_availability_announcements = self.should_handle_availability_announcements(); From 3a336abcb68dea3004b60a2d1be2681e25077f3c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 24 Nov 2023 13:07:21 +0100 Subject: [PATCH 115/687] comment for linking github issue --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 6f2357689..00ab1f7c0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -932,6 +932,8 @@ impl HoneyBadgerBFT { false } + /// early epoch ends + /// https://github.com/DMDcoin/diamond-node/issues/87 fn handle_early_epoch_end( &self, block_chain_client: &dyn BlockChainClient, From ae869434b224d52108ee76a6fde882e9426fc29e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 24 Nov 2023 14:54:56 +0100 Subject: [PATCH 116/687] initializing early epoch end manager with the validator set collection on instantiation. --- .../hbbft/hbbft_early_epoch_end_manager.rs | 5 ++- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 18 +++++++--- .../engines/hbbft/hbbft_peers_management.rs | 8 ++--- .../ethcore/src/engines/hbbft/hbbft_state.rs | 35 +++++++++++++++++-- 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 385747dcc..4bc8121fd 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -36,6 +36,7 @@ impl HbbftEarlyEpochEndManager { client: &dyn BlockChainClient, epoch_number: u64, epoch_start_block: u64, + validator_set: Vec, ) -> Option { if client.is_syncing() { // if we are syncing, we do not need to create an early epoch end manager yet. @@ -58,7 +59,7 @@ impl HbbftEarlyEpochEndManager { start_time: Instant::now(), start_block: epoch_start_block, allowed_devp2p_warmup_time, - validators: Vec::new(), + validators: validator_set, flagged_validators: Self::get_current_flagged_validators_from_contracts(client), }; @@ -136,8 +137,6 @@ impl HbbftEarlyEpochEndManager { return; } - //full_client. - let block_num = if let Some(block) = full_client.block(BlockId::Latest) { block.number() } else { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 00ab1f7c0..1770cc185 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -952,7 +952,7 @@ impl HoneyBadgerBFT { let epoch_num = hbbft_state.get_current_posdao_epoch(); let epoch_start_block = hbbft_state.get_current_posdao_epoch_start_block(); - + let validator_set = hbbft_state.get_validator_set(); // we got everything we need from hbbft_state - drop lock ASAP. std::mem::drop(hbbft_state); @@ -966,8 +966,9 @@ impl HoneyBadgerBFT { let mut lock_guard = self.early_epoch_manager.lock(); match lock_guard.as_mut() { - Some(ealry_epoch_end_manager) => { - ealry_epoch_end_manager.decide(&memorium, block_chain_client, mining_address); + Some(early_epoch_end_manager) => { + // should we check here if the epoch number has changed ? + early_epoch_end_manager.decide(&memorium, block_chain_client, mining_address); } None => { *lock_guard = HbbftEarlyEpochEndManager::create_early_epoch_end_manager( @@ -975,6 +976,7 @@ impl HoneyBadgerBFT { block_chain_client, epoch_num, epoch_start_block, + validator_set, ); if let Some(manager) = lock_guard.as_mut() { @@ -1093,8 +1095,11 @@ impl HoneyBadgerBFT { } if should_connect_to_validator_set { - let network_info_o = if let Some(hbbft_state) = self.hbbft_state.try_read() { - hbbft_state.get_current_network_info() + // we + let network_info_o = if let Some(hbbft_state) = + self.hbbft_state.try_read_for(Duration::from_millis(50)) + { + Some(hbbft_state.get_validator_set()) } else { None }; @@ -1414,6 +1419,7 @@ impl Engine for HoneyBadgerBFT { client, &self.signer, &self.peers_management, + &self.early_epoch_manager, &self.current_minimum_gas_price, BlockId::Latest, true, @@ -1455,6 +1461,7 @@ impl Engine for HoneyBadgerBFT { client, &self.signer, &self.peers_management, + &self.early_epoch_manager, &self.current_minimum_gas_price, BlockId::Latest, true, @@ -1676,6 +1683,7 @@ impl Engine for HoneyBadgerBFT { client.clone(), &self.signer, &self.peers_management, + &self.early_epoch_manager, &self.current_minimum_gas_price, BlockId::Hash(block_hash.clone()), false, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index a67438847..29f2ee6ce 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -158,10 +158,10 @@ impl HbbftPeersManagement { // a current validator. pub fn connect_to_current_validators( &mut self, - network_info: &NetworkInfo, + validator_set: &Vec, client_arc: &Arc, ) { - warn!(target: "Engine", "adding current validators as reserved peers: {}", network_info.validator_set().all_ids().count()); + info!(target: "Engine", "adding current validators as reserved peers: {}", validator_set.len()); // todo: iterate over NodeIds, extract the address // we do not need to connect to ourself. // figure out the IP and port from the contracts @@ -181,8 +181,6 @@ impl HbbftPeersManagement { return; } - let ids: Vec<&NodeId> = network_info.validator_set().all_ids().collect(); - // let mut validators_to_remove: BTreeSet = BTreeSet::new(); let mut validators_to_remove: BTreeSet
= self @@ -194,7 +192,7 @@ impl HbbftPeersManagement { // validators_to_remove let mut current_validator_connections: Vec = Vec::new(); - for node in ids.iter() { + for node in validator_set.iter() { let address = public_key_to_address(&node.0); if address == self.own_validator_address { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 3671ac001..401351bed 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -12,6 +12,7 @@ use rand::seq::IteratorRandom; use std::{ collections::{BTreeMap, HashMap}, sync::Arc, + time::Duration, }; use types::{header::Header, ids::BlockId}; @@ -24,6 +25,7 @@ use super::{ validator_set::ValidatorType, }, contribution::Contribution, + hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_peers_management::HbbftPeersManagement, NodeId, }; @@ -73,6 +75,7 @@ impl HbbftState { client: Arc, signer: &Arc>>>, peers_management_mutex: &Mutex, + early_epoch_end_manager_mutex: &Mutex>, current_minimum_gas_price: &Mutex>, block_id: BlockId, force: bool, @@ -159,7 +162,7 @@ impl HbbftState { if let Some(mut peers_management) = peers_management_mutex.try_lock_for(std::time::Duration::from_millis(250)) { - peers_management.connect_to_current_validators(&network_info, &client); + peers_management.connect_to_current_validators(&self.get_validator_set(), &client); } else { // maybe we should work with signals that signals that connect_to_current_validators should happen // instead of trying to achieve a lock here. @@ -170,6 +173,19 @@ impl HbbftState { warn!(target: "engine", "could not acquire to connect to current validators on switching to new validator set for staking epoch {}.", self.current_posdao_epoch); } + let allowed_devp2p_warmup_time = Duration::from_secs(120); + + if let Some(full_client) = client.as_full_client() { + *early_epoch_end_manager_mutex.lock() = + HbbftEarlyEpochEndManager::create_early_epoch_end_manager( + allowed_devp2p_warmup_time, + full_client, + self.current_posdao_epoch, + self.current_posdao_epoch_start_block, + self.get_validator_set(), + ); + } + Some(()) } @@ -542,8 +558,21 @@ impl HbbftState { self.network_info.clone() } - pub fn get_current_network_info(&self) -> Option> { - return self.network_info.clone(); + // pub fn get_current_network_info(&self) -> &Option> { + // return &self.network_info; + // } + + pub fn get_validator_set(&self) -> Vec { + if let Some(network_info) = &self.network_info { + let result: Vec = network_info + .validator_set() + .all_ids() + .map(|n| n.clone()) + .collect(); + return result; + } + + return Vec::new(); } pub fn get_current_posdao_epoch(&self) -> u64 { From 63f8a959798deaa4bacf91f636af9124eb14a1be Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 24 Nov 2023 15:00:40 +0100 Subject: [PATCH 117/687] early epoch end manager: removed notify_new_epoch --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 4bc8121fd..4c35def5b 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -66,14 +66,6 @@ impl HbbftEarlyEpochEndManager { return Some(result); } - /// notifies about a new epoch. - /// This (re)inits the Manager, no early epoch end happened. - pub fn notify_new_epoch(&mut self, epoch: u64, validators: Vec) { - self.current_tracked_epoch_number = epoch; - self.validators = validators; - self.start_time = Instant::now(); - } - /// retrieves the information from smart contracts which validators are currently flagged. fn get_current_flagged_validators_from_contracts( full_client: &dyn BlockChainClient, From ebef9de2a505857367ba4338372f73729735e485 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 25 Nov 2023 09:41:56 +0100 Subject: [PATCH 118/687] early epoch end: also notify about missing validator if there is no memorium info at all. --- .../engines/hbbft/hbbft_early_epoch_end_manager.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 4c35def5b..fe9eca7c3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -148,6 +148,7 @@ impl HbbftEarlyEpochEndManager { // get current state of missing validators from hbbftMemorium. if let Some(epoch_history) = memorium.get_staking_epoch_history(block_num) { for validator in &self.validators.clone() { + // we need to exclude ourself. if let Some(node_history) = epoch_history.get_history_for_node(validator) { let last_sealing_message = node_history.get_sealing_message(); @@ -174,6 +175,16 @@ impl HbbftEarlyEpochEndManager { ); } } + } else { + // we do not have any history for this node. + if !self.flagged_validators.contains(validator) { + // this function will also add the validator to the list of flagged validators. + self.notify_about_missing_validator( + &validator, + full_client, + mining_address, + ); + } } // todo: if the systems switched from block based measurement to time based measurement. } From 437c289ba748ce5ea05f12223d46e404e957a410 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 26 Nov 2023 23:36:07 +0100 Subject: [PATCH 119/687] hint for not banned self --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 1770cc185..51a87677b 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -952,7 +952,10 @@ impl HoneyBadgerBFT { let epoch_num = hbbft_state.get_current_posdao_epoch(); let epoch_start_block = hbbft_state.get_current_posdao_epoch_start_block(); - let validator_set = hbbft_state.get_validator_set(); + let mut validator_set = hbbft_state.get_validator_set(); + // todo: remove own node from validator set. + + // we got everything we need from hbbft_state - drop lock ASAP. std::mem::drop(hbbft_state); From b5bd4c3e9e3608b2fea7a09742a9c2dd313634e4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 27 Nov 2023 23:21:34 +0100 Subject: [PATCH 120/687] skipping self for checking in hbbft early epoch end manager --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 8 +++++++- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index fe9eca7c3..4f7b1f900 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -1,7 +1,7 @@ use ethereum_types::Address; use types::ids::BlockId; -use crate::client::BlockChainClient; +use crate::{client::BlockChainClient, ethereum::public_key_to_address::public_key_to_address}; use std::time::{Duration, Instant}; use super::{hbbft_message_memorium::HbbftMessageMemorium, NodeId}; @@ -148,6 +148,12 @@ impl HbbftEarlyEpochEndManager { // get current state of missing validators from hbbftMemorium. if let Some(epoch_history) = memorium.get_staking_epoch_history(block_num) { for validator in &self.validators.clone() { + let validator_eth_address = public_key_to_address(&validator.0); + // we do not have to check ourself. + if validator_eth_address == *mining_address { + continue; + } + // we need to exclude ourself. if let Some(node_history) = epoch_history.get_history_for_node(validator) { let last_sealing_message = node_history.get_sealing_message(); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 51a87677b..4eebe1dd8 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -954,8 +954,7 @@ impl HoneyBadgerBFT { let epoch_start_block = hbbft_state.get_current_posdao_epoch_start_block(); let mut validator_set = hbbft_state.get_validator_set(); // todo: remove own node from validator set. - - + // we got everything we need from hbbft_state - drop lock ASAP. std::mem::drop(hbbft_state); From f71345f5865c115d059e5208a000fc2e23488896 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Nov 2023 16:40:01 +0100 Subject: [PATCH 121/687] reverted back default ports for hbbft configuration since we currently only have 1 alpha network. --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index cd7e94bea..64c32e3b7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -112,9 +112,9 @@ fn to_toml( base_metrics_port: Option, metrics_interface: Option<&str>, ) -> Value { - let base_port = 31300i64; - let base_rpc_port = 18540i64; - let base_ws_port = 19540i64; + let base_port = 30300i64; + let base_rpc_port = 8540i64; + let base_ws_port = 9540i64; let mut parity = Map::new(); match config_type { From 54ff378a746414fb4d7299f8ec11479aa3b8a7a9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Nov 2023 16:49:38 +0100 Subject: [PATCH 122/687] hbbft_config_generator: fixed wrong peer id --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 64c32e3b7..d5c456aa3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -46,7 +46,7 @@ impl ToString for Enode { fn to_string(&self) -> String { // Example: // enode://30ccdeb8c31972f570e4eea0673cd08cbe7cefc5de1d70119b39c63b1cba33b48e494e9916c0d1eab7d296774f3573da46025d1accdef2f3690bc9e6659a34b4@192.168.0.101:30300 - let port = 31300usize + self.idx; + let port = 30300usize + self.idx; format!("enode://{:x}@{}:{}", self.public, self.ip, port) } } From 9f7f68af8f00786deea9e2688273e1e9fe0ab96b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Nov 2023 22:21:38 +0100 Subject: [PATCH 123/687] NodeId now has a as_8_byte_string() method for convinient printing the first 8 bytes of the public key. --- .../engines/hbbft/hbbft_message_memorium.rs | 18 +++--------------- crates/ethcore/src/engines/hbbft/mod.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index ef6a01ff2..6662c42ba 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -282,21 +282,9 @@ impl NodeStakingEpochHistory { //let metric: Metric = Metric::new(); //r.registry().register(c) - //let label = self.get_node_id().0.to_hex(); - - let node_id = self.get_node_id().0 .0; - - let other_node = std::format!( - "{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", - node_id[0], - node_id[1], - node_id[2], - node_id[3], - node_id[4], - node_id[5], - node_id[6], - node_id[7] - ); + //let node_id = self.get_node_id().0 .0; + + let other_node = self.get_node_id().as_8_byte_string(); //r.register_gauge_with_label(name, help, label, value) r.register_gauge_with_other_node_label( diff --git a/crates/ethcore/src/engines/hbbft/mod.rs b/crates/ethcore/src/engines/hbbft/mod.rs index 99aad0602..39ddaf09d 100644 --- a/crates/ethcore/src/engines/hbbft/mod.rs +++ b/crates/ethcore/src/engines/hbbft/mod.rs @@ -31,3 +31,19 @@ impl fmt::Display for NodeId { write!(f, "NodeId({})", self.0) } } + +impl NodeId { + pub fn as_8_byte_string(&self) -> String { + std::format!( + "{:x}{:x}{:x}{:x}{:x}{:x}{:x}{:x}", + self.0[0], + self.0[1], + self.0[2], + self.0[3], + self.0[4], + self.0[5], + self.0[6], + self.0[7] + ) + } +} From 9b90c4b5a9b01b18a4168f4c8ff932092ae66f33 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Nov 2023 22:22:13 +0100 Subject: [PATCH 124/687] prometheus metrics implementation for exporting node flag status. --- .../hbbft/hbbft_early_epoch_end_manager.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 4f7b1f900..e55813948 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -1,4 +1,5 @@ use ethereum_types::Address; +use stats::PrometheusMetrics; use types::ids::BlockId; use crate::{client::BlockChainClient, ethereum::public_key_to_address::public_key_to_address}; @@ -203,6 +204,26 @@ impl HbbftEarlyEpochEndManager { } } +impl PrometheusMetrics for HbbftEarlyEpochEndManager { + fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { + registry.register_gauge( + "early_epoch_end_flagged_validators", + "number of validators flagged for missing communication", + self.flagged_validators.len() as i64, + ); + + for v in self.validators.iter() { + let is_flagged = self.flagged_validators.contains(v); + let label_value = v.as_8_byte_string(); + registry.register_gauge_with_other_node_label( + "early_epoch_end_flag", + "node has flagged other_node [0-1]", + label_value.as_str(), + is_flagged as i64, + ); + } + } +} /// testing early epoch stop manager. #[cfg(test)] mod tests { From 6388d488c9abb3c46e7fb48670da6b0248c386ef Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Nov 2023 22:35:50 +0100 Subject: [PATCH 125/687] integrated prometheus metrics for early epoch end --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 4eebe1dd8..3e8178e63 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1715,6 +1715,14 @@ impl Engine for HoneyBadgerBFT { fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { self.hbbft_message_dispatcher.prometheus_metrics(registry); + if let Some(early_epoch_manager_option) = self + .early_epoch_manager + .try_lock_for(Duration::from_millis(250)) + { + if let Some(early_epoch_manager) = early_epoch_manager_option.as_ref() { + early_epoch_manager.prometheus_metrics(registry); + } + } } /// hbbft protects the start of the current posdao epoch start from being pruned. From 98a2a495c56a3dd91109b1cc13aa72d0c287c520 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Nov 2023 22:54:26 +0100 Subject: [PATCH 126/687] moved HoneyBadgerBFT prometheus_metrics to PrometheusMetrics trait implementation --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 3e8178e63..fa2d51225 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1713,18 +1713,6 @@ impl Engine for HoneyBadgerBFT { } } - fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { - self.hbbft_message_dispatcher.prometheus_metrics(registry); - if let Some(early_epoch_manager_option) = self - .early_epoch_manager - .try_lock_for(Duration::from_millis(250)) - { - if let Some(early_epoch_manager) = early_epoch_manager_option.as_ref() { - early_epoch_manager.prometheus_metrics(registry); - } - } - } - /// hbbft protects the start of the current posdao epoch start from being pruned. fn pruning_protection_block_number(&self) -> Option { // we try to get a read lock for 500 ms. @@ -1745,6 +1733,21 @@ impl Engine for HoneyBadgerBFT { } } +impl PrometheusMetrics for HoneyBadgerBFT { + + fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { + self.hbbft_message_dispatcher.prometheus_metrics(registry); + if let Some(early_epoch_manager_option) = self + .early_epoch_manager + .try_lock_for(Duration::from_millis(250)) + { + if let Some(early_epoch_manager) = early_epoch_manager_option.as_ref() { + early_epoch_manager.prometheus_metrics(registry); + } + } + } +} + #[cfg(test)] mod tests { use super::super::{contribution::Contribution, test::create_transactions::create_transaction}; From ca895d34957a2a799383c1fd4a51daa29033598f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Nov 2023 22:57:34 +0100 Subject: [PATCH 127/687] showing tracked staking epoch in prometheus interface for early epoch manager. --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 8 +++++++- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index e55813948..f71145529 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -207,7 +207,13 @@ impl HbbftEarlyEpochEndManager { impl PrometheusMetrics for HbbftEarlyEpochEndManager { fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { registry.register_gauge( - "early_epoch_end_flagged_validators", + "early_epoch_end_staking_epoch", + "staking epoch information for early epoch end manager", + self.current_tracked_epoch_number as i64, + ); + + registry.register_gauge( + "early_epoch_end_num_flagged_validators", "number of validators flagged for missing communication", self.flagged_validators.len() as i64, ); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index fa2d51225..6fef9a442 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1734,7 +1734,6 @@ impl Engine for HoneyBadgerBFT { } impl PrometheusMetrics for HoneyBadgerBFT { - fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { self.hbbft_message_dispatcher.prometheus_metrics(registry); if let Some(early_epoch_manager_option) = self From 56a6ede611cbcd79d8d47b97f75e4e49d4b76ef0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 29 Nov 2023 10:58:22 +0100 Subject: [PATCH 128/687] removed log entry for good and faulty message log in memorium, probabably more than one message can happen per block.. add_message_event_good: ! event.block_num {block_num} > last_message_good {last_message_good} --- .../engines/hbbft/hbbft_message_memorium.rs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 6662c42ba..ebe87422b 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -182,9 +182,10 @@ impl NodeStakingEpochHistory { if block_num > last_message_faulty { self.last_message_faulty = block_num; - } else { - warn!(target: "hbbft_message_memorium", "add_message_event_faulty: event.block_num {block_num} <= last_message_faulty {last_message_faulty}"); - } + } // else { + // this log entry is trigering often, probably there are more than 1 good messages able per block.// this log entry is trigering often, probably there are more than 1 good messages able per block. + // warn!(target: "hbbft_message_memorium", "add_message_event_faulty: event.block_num {block_num} <= last_message_faulty {last_message_faulty}"); + // } self.num_faulty_messages += 1; } @@ -195,9 +196,10 @@ impl NodeStakingEpochHistory { if block_num > last_message_good { self.last_message_good = block_num; - } else { - warn!(target: "hbbft_message_memorium", "add_message_event_good: event.block_num {block_num} <= last_message_good {last_message_good}"); - } + } // else { + // this log entry is trigering often, probably there are more than 1 good messages able per block. + // warn!(target: "hbbft_message_memorium", "add_message_event_good: ! event.block_num {block_num} > last_message_good {last_message_good}"); + // } self.num_good_messages += 1; } @@ -1243,6 +1245,17 @@ impl PrometheusMetrics for HbbftMessageMemorium { fn prometheus_metrics(&self, r: &mut stats::PrometheusRegistry) { //let epoch_history_len = self.staking_epoch_history.len() as i64; + // r.register_gauge( + // "HbbftMessageMemorium_dispatched_message_event_faulty", + // "dispatched_message_event_faulty", + // self.dispatched_message_event_faulty.len() as i64, + // ); + // r.register_gauge( + // "HbbftMessageMemorium_dispatched_message_event_good", + // "dispatched_message_event_good", + // self.dispatched_message_event_good.len() as i64, + // ); + if let Some(history) = self.staking_epoch_history.iter().last() { history.prometheus_metrics(r); } From c7b55fd60de3cfa928254ee6c51e84e5bb072b81 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 29 Nov 2023 10:58:40 +0100 Subject: [PATCH 129/687] disconnect_all_validators comment --- .../ethcore/src/engines/hbbft/hbbft_peers_management.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 29f2ee6ce..42e0b3042 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -245,10 +245,10 @@ impl HbbftPeersManagement { self.connected_current_validators = current_validator_connections; } - // if we drop out as a current validator, - // as well a pending validator, we should drop - // all reserved connections. - // in later addition, we will keep the Partner Node Connections here. (upcomming feature) + /// if we drop out as a current validator, + /// as well a pending validator, we should drop + /// all reserved connections. + /// in later addition, we will keep the Partner Node Connections here. (upcomming feature) pub fn disconnect_all_validators(&mut self, client_arc: &Arc) { // we safely can disconnect even in situation where we are syncing. From c8dd02cf5750efaa81f3bc32fa0d59366eda1556 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 29 Nov 2023 11:28:20 +0100 Subject: [PATCH 130/687] improved logging for send_keygen_transactions --- .../src/engines/hbbft/keygen_transactions.rs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 507cabca4..8faf742d4 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -107,7 +107,7 @@ impl KeygenTransactionSender { let address = match signer.read().as_ref() { Some(signer) => signer.address(), None => { - trace!(target: "engine", "Could not send keygen transactions, because signer module could not be retrieved"); + warn!(target: "engine", "Could not send keygen transactions, because signer module could not be retrieved"); return Err(CallError::ReturnValueInvalid); } }; @@ -131,12 +131,18 @@ impl KeygenTransactionSender { // if synckeygen creation fails then either signer or validator pub keys are problematic. // Todo: We should expect up to f clients to write invalid pub keys. Report and re-start pending validator set selection. let (mut synckeygen, part) = engine_signer_to_synckeygen(signer, Arc::new(pub_keys)) - .map_err(|_| CallError::ReturnValueInvalid)?; + .map_err(|e| { + warn!(target:"engine", "engine_signer_to_synckeygen error {:?}", e); + CallError::ReturnValueInvalid + })?; // If there is no part then we are not part of the pending validator set and there is nothing for us to do. let part_data = match part { Some(part) => part, - None => return Err(CallError::ReturnValueInvalid), + None => { + warn!(target:"engine", "no part to write."); + return Err(CallError::ReturnValueInvalid); + } }; let upcoming_epoch = get_posdao_epoch(client, BlockId::Latest)? + 1; @@ -147,7 +153,10 @@ impl KeygenTransactionSender { ShouldSendKeyAnswer::Yes => { let serialized_part = match bincode::serialize(&part_data) { Ok(part) => part, - Err(_) => return Err(CallError::ReturnValueInvalid), + Err(e) => { + warn!(target:"engine", "could not serialize part: {:?}", e); + return Err(CallError::ReturnValueInvalid); + } }; let serialized_part_len = serialized_part.len(); let current_round = get_current_key_gen_round(client)?; @@ -171,7 +180,10 @@ impl KeygenTransactionSender { .gas_price(U256::from(10000000000u64)); full_client .transact_silently(part_transaction) - .map_err(|_| CallError::ReturnValueInvalid)?; + .map_err(|e| { + warn!(target:"engine", "could not transact_silently: {:?}", e); + CallError::ReturnValueInvalid + })?; trace!(target:"engine", "PART Transaction send."); return Ok(()); From 35df6811ce24a400f6a57fd69c6560a8d6c6262b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 29 Nov 2023 21:58:52 +0100 Subject: [PATCH 131/687] move prometheus_metrics from own trait to the Engine Impl, so it get's called again. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 6fef9a442..098ce60cf 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1731,9 +1731,9 @@ impl Engine for HoneyBadgerBFT { return None; } } -} -impl PrometheusMetrics for HoneyBadgerBFT { + // note: this is by design not part of the PrometheusMetrics trait, + // it is part of the Engine trait and does nothing by default. fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { self.hbbft_message_dispatcher.prometheus_metrics(registry); if let Some(early_epoch_manager_option) = self From 9de2603daa2af3aa265dbe0b331d94e59f12aac2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Dec 2023 14:55:02 +0100 Subject: [PATCH 132/687] early epoch manager: filtering of own node moved from decide to the construction of the early epoch manager. --- .../hbbft/hbbft_early_epoch_end_manager.rs | 15 ++++++++------- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 1 + crates/ethcore/src/engines/hbbft/hbbft_state.rs | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index f71145529..eab81fdce 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -38,6 +38,7 @@ impl HbbftEarlyEpochEndManager { epoch_number: u64, epoch_start_block: u64, validator_set: Vec, + signing_address: &Address, ) -> Option { if client.is_syncing() { // if we are syncing, we do not need to create an early epoch end manager yet. @@ -51,6 +52,12 @@ impl HbbftEarlyEpochEndManager { return None; } + let validators: Vec = validator_set + .iter() + .filter(|n| public_key_to_address(&n.0) != *signing_address) + .cloned() + .collect(); + // figure out if we have to retrieve the data from the smart contracts. // if the epoch start did just happen, // we do not have to retrieve the data from the smart contracts. @@ -60,7 +67,7 @@ impl HbbftEarlyEpochEndManager { start_time: Instant::now(), start_block: epoch_start_block, allowed_devp2p_warmup_time, - validators: validator_set, + validators: validators, flagged_validators: Self::get_current_flagged_validators_from_contracts(client), }; @@ -149,12 +156,6 @@ impl HbbftEarlyEpochEndManager { // get current state of missing validators from hbbftMemorium. if let Some(epoch_history) = memorium.get_staking_epoch_history(block_num) { for validator in &self.validators.clone() { - let validator_eth_address = public_key_to_address(&validator.0); - // we do not have to check ourself. - if validator_eth_address == *mining_address { - continue; - } - // we need to exclude ourself. if let Some(node_history) = epoch_history.get_history_for_node(validator) { let last_sealing_message = node_history.get_sealing_message(); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 098ce60cf..59fc091f3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -979,6 +979,7 @@ impl HoneyBadgerBFT { epoch_num, epoch_start_block, validator_set, + mining_address, ); if let Some(manager) = lock_guard.as_mut() { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 401351bed..966a6587a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -176,6 +176,13 @@ impl HbbftState { let allowed_devp2p_warmup_time = Duration::from_secs(120); if let Some(full_client) = client.as_full_client() { + let signing_address = if let Some(s) = signer.read().as_ref() { + s.address() + } else { + error!(target: "engine", "early epoch manager: signer is not set!"); + ethereum_types::Address::zero() + }; + *early_epoch_end_manager_mutex.lock() = HbbftEarlyEpochEndManager::create_early_epoch_end_manager( allowed_devp2p_warmup_time, @@ -183,6 +190,7 @@ impl HbbftState { self.current_posdao_epoch, self.current_posdao_epoch_start_block, self.get_validator_set(), + &signing_address, ); } From a94cc8ce8f515a80c20c4aded70b2dd314d24823 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 10 Dec 2023 13:56:56 +0100 Subject: [PATCH 133/687] report new epoch is now a info instead of a warning --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 59fc091f3..7099f6268 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1432,7 +1432,7 @@ impl Engine for HoneyBadgerBFT { let epoch_start_block = state.get_current_posdao_epoch_start_block(); // we got all infos from the state, we can drop the lock. std::mem::drop(state); - warn!(target: "engine", "report new epoch: {} at block: {}", posdao_epoch, epoch_start_block); + info!(target: "engine", "report new epoch: {} at block: {}", posdao_epoch, epoch_start_block); self.hbbft_message_dispatcher .report_new_epoch(posdao_epoch, epoch_start_block); } From 42109770fd61fc9763c953a7d0de29ce828a6671 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 10 Dec 2023 14:00:19 +0100 Subject: [PATCH 134/687] info logging for early-epoch-end: HbbftEarlyEpochEndManager created. --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index eab81fdce..4d28620bf 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -62,15 +62,19 @@ impl HbbftEarlyEpochEndManager { // if the epoch start did just happen, // we do not have to retrieve the data from the smart contracts. + let now = Instant::now(); + let result = Self { current_tracked_epoch_number: epoch_number, - start_time: Instant::now(), + start_time: now, start_block: epoch_start_block, allowed_devp2p_warmup_time, validators: validators, flagged_validators: Self::get_current_flagged_validators_from_contracts(client), }; + info!(target: "engine", "early-epoch-end: HbbftEarlyEpochEndManager created. start_time {now:?}, start_block: {epoch_start_block}"); + return Some(result); } From c94fa8809ecb20a11d5ad51d92e6f4c8d98e3aad Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 10 Dec 2023 14:22:23 +0100 Subject: [PATCH 135/687] debug logging for early epoch end manager --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 4d28620bf..fd27bb3a6 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -133,11 +133,14 @@ impl HbbftEarlyEpochEndManager { ) { // if devp2p warmup time is not over yet, we do not have to do anything. if self.start_time.elapsed() < self.allowed_devp2p_warmup_time { + debug!(target: "engine", "early-epoch-end: no decision: Devp2p warmup time"); + } else { return; } if full_client.is_syncing() { // if we are syncing, we wont do any blaming. + debug!(target: "engine", "early-epoch-end: no decision: syncing"); return; } @@ -153,6 +156,7 @@ impl HbbftEarlyEpochEndManager { if self.start_block + treshold < block_num { // not enought blocks have passed this epoch, // to judge other nodes. + debug!(target: "engine", "early-epoch-end: no decision: not enough blocks."); return; } @@ -166,7 +170,6 @@ impl HbbftEarlyEpochEndManager { if last_sealing_message < block_num - treshold { // we do not have to send notification, if we already did so. - if !self.flagged_validators.contains(validator) { // this function will also add the validator to the list of flagged validators. self.notify_about_missing_validator( @@ -188,6 +191,7 @@ impl HbbftEarlyEpochEndManager { } } } else { + debug!(target: "engine", "early-epoch-end: no history info for validator {validator}"); // we do not have any history for this node. if !self.flagged_validators.contains(validator) { // this function will also add the validator to the list of flagged validators. From 1fcd0d2029dffa82ad0af8ff6ea3f3a5d307977b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 10 Dec 2023 15:08:57 +0100 Subject: [PATCH 136/687] fixed mut warn. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 7099f6268..754f106d6 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -952,8 +952,7 @@ impl HoneyBadgerBFT { let epoch_num = hbbft_state.get_current_posdao_epoch(); let epoch_start_block = hbbft_state.get_current_posdao_epoch_start_block(); - let mut validator_set = hbbft_state.get_validator_set(); - // todo: remove own node from validator set. + let validator_set = hbbft_state.get_validator_set(); // we got everything we need from hbbft_state - drop lock ASAP. std::mem::drop(hbbft_state); @@ -988,7 +987,7 @@ impl HoneyBadgerBFT { } } } else { - warn!(target: "engine", "could not acquire read lock for memorium to decide on ealry_epoch_end_manager in do_validator_engine_actions."); + warn!(target: "engine", "early-epoch-end: could not acquire read lock for memorium to decide on ealry_epoch_end_manager in do_validator_engine_actions."); } } @@ -1014,7 +1013,7 @@ impl HoneyBadgerBFT { // here is a possible performance improvement: // this won't change during the lifetime of the application ?! return Ok(()); - } + } }; let engine_client = client_arc.deref(); From 101e24ea275dc055fb9b3a76d8da53a7c6fbecfb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 11 Dec 2023 10:22:57 +0100 Subject: [PATCH 137/687] fixed: early-epoch-end: no decision: Devp2p warmup time --- .../ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index fd27bb3a6..566cec97a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -134,7 +134,6 @@ impl HbbftEarlyEpochEndManager { // if devp2p warmup time is not over yet, we do not have to do anything. if self.start_time.elapsed() < self.allowed_devp2p_warmup_time { debug!(target: "engine", "early-epoch-end: no decision: Devp2p warmup time"); - } else { return; } From e17346b161320c96a54fbc1357ef1d6e3168f113 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 11 Dec 2023 10:31:00 +0100 Subject: [PATCH 138/687] error tagging: early-epoch-end: could not retrieve latest block --- .../ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 566cec97a..6cffb02e0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -146,7 +146,7 @@ impl HbbftEarlyEpochEndManager { let block_num = if let Some(block) = full_client.block(BlockId::Latest) { block.number() } else { - error!(target:"engine", "could not retrieve latest block."); + error!(target:"engine", "early-epoch-end: could not retrieve latest block."); return; }; From 377878ee3ccd4dcdcb62e6ba4d17d821bffe1de1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 11 Dec 2023 11:04:49 +0100 Subject: [PATCH 139/687] fixed: early-epoch-end: no decision: not enough blocks --- .../ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 6cffb02e0..bfcec7a7a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -152,7 +152,7 @@ impl HbbftEarlyEpochEndManager { let treshold: u64 = 10; - if self.start_block + treshold < block_num { + if block_num < self.start_block + treshold { // not enought blocks have passed this epoch, // to judge other nodes. debug!(target: "engine", "early-epoch-end: no decision: not enough blocks."); From 18dab956e7746138c9c356e3698e7cea374f9d26 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 11 Dec 2023 11:20:55 +0100 Subject: [PATCH 140/687] "could not retrieve part for" is Ok, do not report ReturnValueInvalid --- crates/ethcore/src/engines/hbbft/keygen_transactions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 8faf742d4..e0d6ee567 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -207,7 +207,7 @@ impl KeygenTransactionSender { Some(ack) => ack, None => { trace!(target:"engine", "could not retrieve part for {}", *v); - return Err(CallError::ReturnValueInvalid); + return Ok(()); } } } From 6512eb74c94e413ad33b333e46da43bc17811403 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 11 Dec 2023 23:26:07 +0100 Subject: [PATCH 141/687] abi for hbbft_connectivity_tracker crates/ethcore/res/contracts/hbbft_connectivity_tracker.json 4ba1b6b88a9b45949651a4e0ef79afbf0ab79412 --- .../contracts/hbbft_connectivity_tracker.json | 538 ++++++++++++++++++ 1 file changed, 538 insertions(+) create mode 100644 crates/ethcore/res/contracts/hbbft_connectivity_tracker.json diff --git a/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json b/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json new file mode 100644 index 000000000..c890642ac --- /dev/null +++ b/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json @@ -0,0 +1,538 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "reporter", + "type": "address" + }, + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "AlreadyReported", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "reporter", + "type": "address" + } + ], + "name": "CannotReportByFlaggedValidator", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidAddress", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidBlock", + "type": "error" + }, + { + "inputs": [], + "name": "OnlyValidator", + "type": "error" + }, + { + "inputs": [], + "name": "ReportTooEarly", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "reporter", + "type": "address" + }, + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "UnknownReconnectReporter", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "reporter", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + } + ], + "name": "ReportMissingConnectivity", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "reporter", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + } + ], + "name": "ReportReconnect", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_level", + "type": "uint256" + } + ], + "name": "SetEarlyEpochEndToleranceLevel", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_minReportAge", + "type": "uint256" + } + ], + "name": "SetMinReportAgeBlocks", + "type": "event" + }, + { + "inputs": [], + "name": "blockRewardContract", + "outputs": [ + { + "internalType": "contract IBlockRewardHbbft", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + } + ], + "name": "checkReportMissingConnectivityCallable", + "outputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + } + ], + "name": "checkReportReconnectCallable", + "outputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "currentEpoch", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "earlyEpochEndThreshold", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "earlyEpochEndToleranceLevel", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + } + ], + "name": "getCurrentConnectionStatus", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getFlaggedValidators", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_contractOwner", + "type": "address" + }, + { + "internalType": "address", + "name": "_validatorSetContract", + "type": "address" + }, + { + "internalType": "address", + "name": "_stakingContract", + "type": "address" + }, + { + "internalType": "address", + "name": "_blockRewardContract", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_minReportAgeBlocks", + "type": "uint256" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "isEarlyEpochEnd", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "minReportAgeBlocks", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + } + ], + "name": "reportMissingConnectivity", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + } + ], + "name": "reportReconnect", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_level", + "type": "uint256" + } + ], + "name": "setEarlyEpochEndToleranceLevel", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_minReportAge", + "type": "uint256" + } + ], + "name": "setMinReportAge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "stakingContract", + "outputs": [ + { + "internalType": "contract IStakingHbbft", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "validatorConnectivityScore", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "validatorSetContract", + "outputs": [ + { + "internalType": "contract IValidatorSetHbbft", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } + ] \ No newline at end of file From 6ea68645b2d9b952233f18e58a3040307abd8158 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Dec 2023 00:09:48 +0100 Subject: [PATCH 142/687] fixed hbbft_connectivity_tracker.json --- .../contracts/hbbft_connectivity_tracker.json | 354 ------------------ 1 file changed, 354 deletions(-) diff --git a/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json b/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json index c890642ac..65e1dbbf3 100644 --- a/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json +++ b/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json @@ -1,221 +1,4 @@ [ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "reporter", - "type": "address" - }, - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "AlreadyReported", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "reporter", - "type": "address" - } - ], - "name": "CannotReportByFlaggedValidator", - "type": "error" - }, - { - "inputs": [], - "name": "InvalidAddress", - "type": "error" - }, - { - "inputs": [], - "name": "InvalidBlock", - "type": "error" - }, - { - "inputs": [], - "name": "OnlyValidator", - "type": "error" - }, - { - "inputs": [], - "name": "ReportTooEarly", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "reporter", - "type": "address" - }, - { - "internalType": "address", - "name": "validator", - "type": "address" - } - ], - "name": "UnknownReconnectReporter", - "type": "error" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "version", - "type": "uint8" - } - ], - "name": "Initialized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "reporter", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "validator", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "blockNumber", - "type": "uint256" - } - ], - "name": "ReportMissingConnectivity", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "reporter", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "validator", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "blockNumber", - "type": "uint256" - } - ], - "name": "ReportReconnect", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "_level", - "type": "uint256" - } - ], - "name": "SetEarlyEpochEndToleranceLevel", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "_minReportAge", - "type": "uint256" - } - ], - "name": "SetMinReportAgeBlocks", - "type": "event" - }, - { - "inputs": [], - "name": "blockRewardContract", - "outputs": [ - { - "internalType": "contract IBlockRewardHbbft", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "caller", - "type": "address" - }, - { - "internalType": "address", - "name": "validator", - "type": "address" - }, - { - "internalType": "uint256", - "name": "blockNumber", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "blockHash", - "type": "bytes32" - } - ], - "name": "checkReportMissingConnectivityCallable", - "outputs": [], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { @@ -315,58 +98,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [ - { - "internalType": "address", - "name": "_contractOwner", - "type": "address" - }, - { - "internalType": "address", - "name": "_validatorSetContract", - "type": "address" - }, - { - "internalType": "address", - "name": "_stakingContract", - "type": "address" - }, - { - "internalType": "address", - "name": "_blockRewardContract", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_minReportAgeBlocks", - "type": "uint256" - } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "isEarlyEpochEnd", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "minReportAgeBlocks", @@ -380,26 +111,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "owner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "renounceOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { @@ -446,58 +157,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_level", - "type": "uint256" - } - ], - "name": "setEarlyEpochEndToleranceLevel", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_minReportAge", - "type": "uint256" - } - ], - "name": "setMinReportAge", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "stakingContract", - "outputs": [ - { - "internalType": "contract IStakingHbbft", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { @@ -521,18 +180,5 @@ ], "stateMutability": "view", "type": "function" - }, - { - "inputs": [], - "name": "validatorSetContract", - "outputs": [ - { - "internalType": "contract IValidatorSetHbbft", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" } ] \ No newline at end of file From d4c638da91d816805b9ea9669a32e985f4de1b4d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Dec 2023 00:46:58 +0100 Subject: [PATCH 143/687] implemented get_current_flagged_validators_from_contract --- .../contracts/connectivity_tracker_hbbft.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs new file mode 100644 index 000000000..f9f08602c --- /dev/null +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -0,0 +1,28 @@ +use ethereum_types::{Address, U256}; +use std::str::FromStr; +use client::EngineClient; +use types::ids::BlockId; + +use crate::engines::hbbft::utils::bound_contract::{CallError, BoundContract}; + +use_contract!(connectivity_tracker_hbbft_contract, "res/contracts//hbbft_connectivity_tracker.json"); + +lazy_static! { + static ref CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS: Address = + Address::from_str("0x1200000000000000000000000000000000000001").unwrap(); +} + +macro_rules! call_const_connectivity_tracker_hbbft { + ($c:ident, $x:ident $(, $a:expr )*) => { + $c.call_const(connectivity_tracker_hbbft_contract::functions::$x::call($($a),*)) + }; +} + + +pub fn get_current_flagged_validators_from_contract( + client: &dyn EngineClient, + block_id: BlockId, +) -> Result, CallError> { + let c = BoundContract::bind(client, block_id, *CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS); + return Ok(call_const_connectivity_tracker_hbbft!(c, get_flagged_validators)?); +} \ No newline at end of file From 4bbc1a978dba8d4fbd8fd10be99010e7e8e6f80e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Dec 2023 00:59:51 +0100 Subject: [PATCH 144/687] connectivity_tracker_hbbft module inclusion --- crates/ethcore/src/engines/hbbft/contracts/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/contracts/mod.rs b/crates/ethcore/src/engines/hbbft/contracts/mod.rs index 691d0cc50..07f652a0b 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/mod.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/mod.rs @@ -3,3 +3,4 @@ pub mod permission; pub mod random_hbbft; pub mod staking; pub mod validator_set; +pub mod connectivity_tracker_hbbft; From 39ccb31b737ad7730fb980df5947541738a81891 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Dec 2023 11:15:25 +0100 Subject: [PATCH 145/687] hbbft_early_epoch_end_manager - introduced address <> nodeID cache. - calling for contract function. - requiring now EngineClient in addition to BlockchainClient --- .../hbbft/hbbft_early_epoch_end_manager.rs | 69 +++++++++++++++---- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 4 +- .../ethcore/src/engines/hbbft/hbbft_state.rs | 1 + 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index bfcec7a7a..4650dd8df 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -2,10 +2,10 @@ use ethereum_types::Address; use stats::PrometheusMetrics; use types::ids::BlockId; -use crate::{client::BlockChainClient, ethereum::public_key_to_address::public_key_to_address}; -use std::time::{Duration, Instant}; +use crate::{client::{BlockChainClient, EngineClient}, ethereum::public_key_to_address::public_key_to_address}; +use std::{time::{Duration, Instant}, collections::BTreeMap}; -use super::{hbbft_message_memorium::HbbftMessageMemorium, NodeId}; +use super::{hbbft_message_memorium::HbbftMessageMemorium, NodeId, contracts::connectivity_tracker_hbbft::get_current_flagged_validators_from_contract}; pub(crate) struct HbbftEarlyEpochEndManager { /// The current epoch number. @@ -25,6 +25,12 @@ pub(crate) struct HbbftEarlyEpochEndManager { /// current flagged validators, unordered list - no performance issue, since this can /// only grow up to 7 elements for a usual set of 25 nodes. flagged_validators: Vec, + + + node_id_to_address: BTreeMap, + + + address_to_node_id: BTreeMap, } impl HbbftEarlyEpochEndManager { @@ -35,11 +41,13 @@ impl HbbftEarlyEpochEndManager { pub fn create_early_epoch_end_manager( allowed_devp2p_warmup_time: Duration, client: &dyn BlockChainClient, + engine_client: &dyn EngineClient, epoch_number: u64, epoch_start_block: u64, validator_set: Vec, signing_address: &Address, ) -> Option { + if client.is_syncing() { // if we are syncing, we do not need to create an early epoch end manager yet. // if we are syncing as a validator, and it is really this epoch, @@ -52,16 +60,27 @@ impl HbbftEarlyEpochEndManager { return None; } - let validators: Vec = validator_set - .iter() - .filter(|n| public_key_to_address(&n.0) != *signing_address) - .cloned() - .collect(); + let mut node_id_to_address: BTreeMap = BTreeMap::new(); + let mut address_to_node_id: BTreeMap = BTreeMap::new(); + + let mut validators: Vec = Vec::new(); + + for validator in validator_set.iter() { + + let address = public_key_to_address(&validator.0); + node_id_to_address.insert(validator.clone(), address); + address_to_node_id.insert(address, validator.clone()); + + if address == *signing_address { + continue; + } + + validators.push(validator.clone()); + }; // figure out if we have to retrieve the data from the smart contracts. // if the epoch start did just happen, // we do not have to retrieve the data from the smart contracts. - let now = Instant::now(); let result = Self { @@ -70,7 +89,9 @@ impl HbbftEarlyEpochEndManager { start_block: epoch_start_block, allowed_devp2p_warmup_time, validators: validators, - flagged_validators: Self::get_current_flagged_validators_from_contracts(client), + flagged_validators: Self::get_current_flagged_validators_from_contracts(engine_client, BlockId::Latest, &address_to_node_id), + node_id_to_address, + address_to_node_id, }; info!(target: "engine", "early-epoch-end: HbbftEarlyEpochEndManager created. start_time {now:?}, start_block: {epoch_start_block}"); @@ -80,10 +101,34 @@ impl HbbftEarlyEpochEndManager { /// retrieves the information from smart contracts which validators are currently flagged. fn get_current_flagged_validators_from_contracts( - full_client: &dyn BlockChainClient, + client: &dyn EngineClient, + block_id: BlockId, + address_to_node_id: &BTreeMap ) -> Vec { // todo: call smart contract. - return Vec::new(); + + match get_current_flagged_validators_from_contract(client, block_id) { + Ok(v) => { + let mut result : Vec = Vec::new(); + + for a in v.iter() { + if let Some(node_id) = address_to_node_id.get(a) { + result.push(node_id.clone()); + } else { + error!(target: "engine","early-epoch-end: could not find validator in address cache: {a:?}"); + } + } + + return result; + // address_to_node_id.get(key) + }, + Err(e) => { + error!(target: "engine","early-epoch-end: could not get_current_flagged_validators_from_contracts {e:?}" ); + Vec::new() + }, + } + + } fn notify_about_missing_validator( diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 754f106d6..57f15ad90 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -937,6 +937,7 @@ impl HoneyBadgerBFT { fn handle_early_epoch_end( &self, block_chain_client: &dyn BlockChainClient, + engine_client: &dyn EngineClient, mining_address: &Address, ) { // todo: acquire allowed devp2p warmup time from contracts ?! @@ -975,6 +976,7 @@ impl HoneyBadgerBFT { *lock_guard = HbbftEarlyEpochEndManager::create_early_epoch_end_manager( allowed_devp2p_warmup_time, block_chain_client, + engine_client, epoch_num, epoch_start_block, validator_set, @@ -1025,7 +1027,7 @@ impl HoneyBadgerBFT { } }; - self.handle_early_epoch_end(block_chain_client, &mining_address); + self.handle_early_epoch_end(block_chain_client, engine_client, &mining_address); let should_handle_availability_announcements = self.should_handle_availability_announcements(); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 966a6587a..9138a7bc3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -187,6 +187,7 @@ impl HbbftState { HbbftEarlyEpochEndManager::create_early_epoch_end_manager( allowed_devp2p_warmup_time, full_client, + client.as_ref(), self.current_posdao_epoch, self.current_posdao_epoch_start_block, self.get_validator_set(), From 91648405ca8f5acdc23de812c49398dec175b720 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Dec 2023 12:23:28 +0100 Subject: [PATCH 146/687] report missin connectivity contract call implementation --- .../contracts/connectivity_tracker_hbbft.rs | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index f9f08602c..3a712c39c 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use client::EngineClient; use types::ids::BlockId; -use crate::engines::hbbft::utils::bound_contract::{CallError, BoundContract}; +use crate::{engines::hbbft::utils::bound_contract::{CallError, BoundContract}, client::{traits::TransactionRequest, BlockChainClient}}; use_contract!(connectivity_tracker_hbbft_contract, "res/contracts//hbbft_connectivity_tracker.json"); @@ -25,4 +25,47 @@ pub fn get_current_flagged_validators_from_contract( ) -> Result, CallError> { let c = BoundContract::bind(client, block_id, *CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS); return Ok(call_const_connectivity_tracker_hbbft!(c, get_flagged_validators)?); +} + + +pub fn report_missing_connectivity( + client: &dyn EngineClient, + full_client: &dyn BlockChainClient, + missing_validator: &Address, + signing_address: &Address, +) -> bool { + + let (block_number, block_hash) = + if let Some(block_number) = client.block_number(BlockId::Latest) { + if let Some(header) = client.block_header(BlockId::Number(block_number)) { + let hash = header.hash(); + (block_number, hash) + } else { + warn!(target:"engine", "could not get block number for block: {block_number}"); + return false; + } + } else { + warn!(target:"engine", "report_missing_connectivity: could not get latest block."); + return false; + }; + + let send_data = connectivity_tracker_hbbft_contract::functions::report_missing_connectivity::call( + *missing_validator, + block_number, + block_hash + ); + + let nonce = full_client.next_nonce(signing_address); + + let transaction = TransactionRequest::call(*CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, send_data.0) + .gas(U256::from(200_000)) + .nonce(nonce); + + info!(target:"consensus", "sending report_missing_connectivity for with nonce: {nonce}, missing: {:?} ", missing_validator); + if let Err(e) = full_client.transact_silently(transaction) { + warn!(target:"consensus", "could not report_missing_connectivity {e:?}"); + return false; + } + return true; + } \ No newline at end of file From dcfbb544a2dc63865d91455fb67d7b24869f98e6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Dec 2023 13:02:17 +0100 Subject: [PATCH 147/687] implementation: notify_about_missing_validator --- .../hbbft/hbbft_early_epoch_end_manager.rs | 46 +++++++++---------- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 4 +- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 4650dd8df..8999124aa 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -2,7 +2,7 @@ use ethereum_types::Address; use stats::PrometheusMetrics; use types::ids::BlockId; -use crate::{client::{BlockChainClient, EngineClient}, ethereum::public_key_to_address::public_key_to_address}; +use crate::{client::{BlockChainClient, EngineClient}, ethereum::public_key_to_address::public_key_to_address, engines::hbbft::contracts::connectivity_tracker_hbbft::report_missing_connectivity}; use std::{time::{Duration, Instant}, collections::BTreeMap}; use super::{hbbft_message_memorium::HbbftMessageMemorium, NodeId, contracts::connectivity_tracker_hbbft::get_current_flagged_validators_from_contract}; @@ -31,6 +31,8 @@ pub(crate) struct HbbftEarlyEpochEndManager { address_to_node_id: BTreeMap, + + signing_address: Address } impl HbbftEarlyEpochEndManager { @@ -92,6 +94,7 @@ impl HbbftEarlyEpochEndManager { flagged_validators: Self::get_current_flagged_validators_from_contracts(engine_client, BlockId::Latest, &address_to_node_id), node_id_to_address, address_to_node_id, + signing_address: signing_address.clone(), }; info!(target: "engine", "early-epoch-end: HbbftEarlyEpochEndManager created. start_time {now:?}, start_block: {epoch_start_block}"); @@ -134,31 +137,25 @@ impl HbbftEarlyEpochEndManager { fn notify_about_missing_validator( &mut self, validator: &NodeId, - full_client: &dyn BlockChainClient, - mining_address: &Address, - ) /* -> result of contract call errr */ + client: &dyn EngineClient, + full_client: &dyn BlockChainClient) { - // let mining_address = match self.signer.read().as_ref() { - // Some(signer) => signer.address(), - // None => { - // // we do not have a signer on Full and RPC nodes. - // // here is a possible performance improvement: - // // this won't change during the lifetime of the application ?! - // return Ok(()); - // } - // }; - - // todo: send transaction to smart contract about missing validator. - - self.flagged_validators.push(validator.clone()); - warn!(target: "engine", "TODO: early-epoch-end: notify about missing validator: {:?}", validator); + + if let Some(validator_address) = self.node_id_to_address.get(validator) { + if report_missing_connectivity(client, full_client, validator_address, &self.signing_address) { + self.flagged_validators.push(validator.clone()); + } + } else { + warn!("Could not find validator_address for node id in cache: {validator:?}"); + return; + } + } fn notify_about_validator_reconnect( &mut self, validator: &NodeId, full_client: &dyn BlockChainClient, - mining_address: &Address, ) { if let Some(index) = self.flagged_validators.iter().position(|x| x == validator) { self.flagged_validators.remove(index); @@ -174,7 +171,7 @@ impl HbbftEarlyEpochEndManager { &mut self, memorium: &HbbftMessageMemorium, full_client: &dyn BlockChainClient, - mining_address: &Address, + client: &dyn EngineClient, ) { // if devp2p warmup time is not over yet, we do not have to do anything. if self.start_time.elapsed() < self.allowed_devp2p_warmup_time { @@ -218,8 +215,8 @@ impl HbbftEarlyEpochEndManager { // this function will also add the validator to the list of flagged validators. self.notify_about_missing_validator( &validator, - full_client, - mining_address, + client, + full_client ); } } else { @@ -230,7 +227,6 @@ impl HbbftEarlyEpochEndManager { self.notify_about_validator_reconnect( &validator, full_client, - mining_address, ); } } @@ -241,8 +237,8 @@ impl HbbftEarlyEpochEndManager { // this function will also add the validator to the list of flagged validators. self.notify_about_missing_validator( &validator, - full_client, - mining_address, + client, + full_client ); } } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 57f15ad90..90798ea37 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -970,7 +970,7 @@ impl HoneyBadgerBFT { match lock_guard.as_mut() { Some(early_epoch_end_manager) => { // should we check here if the epoch number has changed ? - early_epoch_end_manager.decide(&memorium, block_chain_client, mining_address); + early_epoch_end_manager.decide(&memorium, block_chain_client, engine_client); } None => { *lock_guard = HbbftEarlyEpochEndManager::create_early_epoch_end_manager( @@ -984,7 +984,7 @@ impl HoneyBadgerBFT { ); if let Some(manager) = lock_guard.as_mut() { - manager.decide(&memorium, block_chain_client, mining_address); + manager.decide(&memorium, block_chain_client, engine_client); } } } From 4ac62b02eac9e11ab602602f2581a37d0a37d977 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Dec 2023 13:14:31 +0100 Subject: [PATCH 148/687] refactured contract calls for connectivity_tracker_hbbft: function reusability --- .../contracts/connectivity_tracker_hbbft.rs | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index 3a712c39c..e9798b27c 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -1,4 +1,4 @@ -use ethereum_types::{Address, U256}; +use ethereum_types::{Address, U256, H256}; use std::str::FromStr; use client::EngineClient; use types::ids::BlockId; @@ -28,26 +28,33 @@ pub fn get_current_flagged_validators_from_contract( } -pub fn report_missing_connectivity( - client: &dyn EngineClient, - full_client: &dyn BlockChainClient, - missing_validator: &Address, - signing_address: &Address, -) -> bool { +fn get_block_data(client: &dyn EngineClient) -> (u64, H256) { - let (block_number, block_hash) = if let Some(block_number) = client.block_number(BlockId::Latest) { if let Some(header) = client.block_header(BlockId::Number(block_number)) { let hash = header.hash(); - (block_number, hash) + return (block_number, hash); } else { warn!(target:"engine", "could not get block number for block: {block_number}"); - return false; + return (0, H256::zero()); } } else { - warn!(target:"engine", "report_missing_connectivity: could not get latest block."); - return false; + warn!(target:"engine", "could not get latest block."); + return (0, H256::zero()); }; +} + +pub fn report_missing_connectivity( + client: &dyn EngineClient, + full_client: &dyn BlockChainClient, + missing_validator: &Address, + signing_address: &Address, +) -> bool { + + let (block_number, block_hash) = get_block_data(client); + if block_number == 0 { + return false; + } let send_data = connectivity_tracker_hbbft_contract::functions::report_missing_connectivity::call( *missing_validator, @@ -68,4 +75,5 @@ pub fn report_missing_connectivity( } return true; -} \ No newline at end of file +} + From cda75043698b45557b278cc62f74023ec8939c75 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Dec 2023 13:42:11 +0100 Subject: [PATCH 149/687] early-epoch-end: report_reconnect --- .../contracts/connectivity_tracker_hbbft.rs | 32 +++++++++++++++++++ .../hbbft/hbbft_early_epoch_end_manager.rs | 22 ++++++++++--- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index e9798b27c..ca623859c 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -77,3 +77,35 @@ pub fn report_missing_connectivity( } + +pub fn report_reconnect( + client: &dyn EngineClient, + full_client: &dyn BlockChainClient, + reconnected_validator: &Address, + signing_address: &Address, +) -> bool { + + let (block_number, block_hash) = get_block_data(client); + if block_number == 0 { + return false; + } + + let send_data = connectivity_tracker_hbbft_contract::functions::report_reconnect::call( + *reconnected_validator, + block_number, + block_hash + ); + + let nonce = full_client.next_nonce(signing_address); + + let transaction = TransactionRequest::call(*CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, send_data.0) + .gas(U256::from(200_000)) + .nonce(nonce); + + info!(target:"consensus", "early-epoch-end: sending report_missing_connectivity for with nonce: {nonce}, missing: {:?} ", reconnected_validator); + if let Err(e) = full_client.transact_silently(transaction) { + warn!(target:"consensus", "early-epoch-end: could not report_missing_connectivity {e:?}"); + return false; + } + return true; +} \ No newline at end of file diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 8999124aa..b68b62dda 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -5,7 +5,7 @@ use types::ids::BlockId; use crate::{client::{BlockChainClient, EngineClient}, ethereum::public_key_to_address::public_key_to_address, engines::hbbft::contracts::connectivity_tracker_hbbft::report_missing_connectivity}; use std::{time::{Duration, Instant}, collections::BTreeMap}; -use super::{hbbft_message_memorium::HbbftMessageMemorium, NodeId, contracts::connectivity_tracker_hbbft::get_current_flagged_validators_from_contract}; +use super::{hbbft_message_memorium::HbbftMessageMemorium, NodeId, contracts::connectivity_tracker_hbbft::{get_current_flagged_validators_from_contract, report_reconnect}}; pub(crate) struct HbbftEarlyEpochEndManager { /// The current epoch number. @@ -156,12 +156,23 @@ impl HbbftEarlyEpochEndManager { &mut self, validator: &NodeId, full_client: &dyn BlockChainClient, + engine_client: &dyn EngineClient ) { - if let Some(index) = self.flagged_validators.iter().position(|x| x == validator) { - self.flagged_validators.remove(index); - warn!(target: "engine", "TODO: early-epoch-end: notify about reconnected validator: {:?}", validator); + + let index = if let Some(index) = self.flagged_validators.iter().position(|x| x == validator) { + index } else { - error!(target: "engine", " Could not find reconnected validator in flagged validators."); + error!(target: "engine", "early-epoch-end: notify_about_validator_reconnect Could not find reconnected validator in flagged validators."); + return; + }; + + if let Some(validator_address) = self.node_id_to_address.get(validator) { + if report_reconnect(engine_client, full_client, validator_address, &self.signing_address) { + self.flagged_validators.remove(index); + } + } else { + warn!("Could not find validator_address for node id in cache: {validator:?}"); + return; } } @@ -227,6 +238,7 @@ impl HbbftEarlyEpochEndManager { self.notify_about_validator_reconnect( &validator, full_client, + client ); } } From 007768272f733ff9594155faa1e58118ae46376a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Dec 2023 14:20:42 +0100 Subject: [PATCH 150/687] cargo fmt --all -- --config imports_granularity=Crate --- .../contracts/connectivity_tracker_hbbft.rs | 65 +++++++------ .../src/engines/hbbft/contracts/mod.rs | 2 +- .../hbbft/hbbft_early_epoch_end_manager.rs | 93 ++++++++++--------- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 4 files changed, 89 insertions(+), 73 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index ca623859c..16715b35d 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -1,11 +1,17 @@ -use ethereum_types::{Address, U256, H256}; -use std::str::FromStr; use client::EngineClient; +use ethereum_types::{Address, H256, U256}; +use std::str::FromStr; use types::ids::BlockId; -use crate::{engines::hbbft::utils::bound_contract::{CallError, BoundContract}, client::{traits::TransactionRequest, BlockChainClient}}; +use crate::{ + client::{traits::TransactionRequest, BlockChainClient}, + engines::hbbft::utils::bound_contract::{BoundContract, CallError}, +}; -use_contract!(connectivity_tracker_hbbft_contract, "res/contracts//hbbft_connectivity_tracker.json"); +use_contract!( + connectivity_tracker_hbbft_contract, + "res/contracts//hbbft_connectivity_tracker.json" +); lazy_static! { static ref CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS: Address = @@ -18,18 +24,22 @@ macro_rules! call_const_connectivity_tracker_hbbft { }; } - pub fn get_current_flagged_validators_from_contract( client: &dyn EngineClient, block_id: BlockId, ) -> Result, CallError> { - let c = BoundContract::bind(client, block_id, *CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS); - return Ok(call_const_connectivity_tracker_hbbft!(c, get_flagged_validators)?); + let c = BoundContract::bind( + client, + block_id, + *CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, + ); + return Ok(call_const_connectivity_tracker_hbbft!( + c, + get_flagged_validators + )?); } - fn get_block_data(client: &dyn EngineClient) -> (u64, H256) { - if let Some(block_number) = client.block_number(BlockId::Latest) { if let Some(header) = client.block_header(BlockId::Number(block_number)) { let hash = header.hash(); @@ -49,24 +59,25 @@ pub fn report_missing_connectivity( full_client: &dyn BlockChainClient, missing_validator: &Address, signing_address: &Address, -) -> bool { - +) -> bool { let (block_number, block_hash) = get_block_data(client); if block_number == 0 { return false; } - let send_data = connectivity_tracker_hbbft_contract::functions::report_missing_connectivity::call( - *missing_validator, - block_number, - block_hash - ); + let send_data = + connectivity_tracker_hbbft_contract::functions::report_missing_connectivity::call( + *missing_validator, + block_number, + block_hash, + ); let nonce = full_client.next_nonce(signing_address); - let transaction = TransactionRequest::call(*CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, send_data.0) - .gas(U256::from(200_000)) - .nonce(nonce); + let transaction = + TransactionRequest::call(*CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, send_data.0) + .gas(U256::from(200_000)) + .nonce(nonce); info!(target:"consensus", "sending report_missing_connectivity for with nonce: {nonce}, missing: {:?} ", missing_validator); if let Err(e) = full_client.transact_silently(transaction) { @@ -74,17 +85,14 @@ pub fn report_missing_connectivity( return false; } return true; - } - pub fn report_reconnect( client: &dyn EngineClient, full_client: &dyn BlockChainClient, reconnected_validator: &Address, signing_address: &Address, -) -> bool { - +) -> bool { let (block_number, block_hash) = get_block_data(client); if block_number == 0 { return false; @@ -93,14 +101,15 @@ pub fn report_reconnect( let send_data = connectivity_tracker_hbbft_contract::functions::report_reconnect::call( *reconnected_validator, block_number, - block_hash + block_hash, ); let nonce = full_client.next_nonce(signing_address); - let transaction = TransactionRequest::call(*CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, send_data.0) - .gas(U256::from(200_000)) - .nonce(nonce); + let transaction = + TransactionRequest::call(*CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, send_data.0) + .gas(U256::from(200_000)) + .nonce(nonce); info!(target:"consensus", "early-epoch-end: sending report_missing_connectivity for with nonce: {nonce}, missing: {:?} ", reconnected_validator); if let Err(e) = full_client.transact_silently(transaction) { @@ -108,4 +117,4 @@ pub fn report_reconnect( return false; } return true; -} \ No newline at end of file +} diff --git a/crates/ethcore/src/engines/hbbft/contracts/mod.rs b/crates/ethcore/src/engines/hbbft/contracts/mod.rs index 07f652a0b..95253501f 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/mod.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/mod.rs @@ -1,6 +1,6 @@ +pub mod connectivity_tracker_hbbft; pub mod keygen_history; pub mod permission; pub mod random_hbbft; pub mod staking; pub mod validator_set; -pub mod connectivity_tracker_hbbft; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index b68b62dda..f35a28fea 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -2,10 +2,23 @@ use ethereum_types::Address; use stats::PrometheusMetrics; use types::ids::BlockId; -use crate::{client::{BlockChainClient, EngineClient}, ethereum::public_key_to_address::public_key_to_address, engines::hbbft::contracts::connectivity_tracker_hbbft::report_missing_connectivity}; -use std::{time::{Duration, Instant}, collections::BTreeMap}; - -use super::{hbbft_message_memorium::HbbftMessageMemorium, NodeId, contracts::connectivity_tracker_hbbft::{get_current_flagged_validators_from_contract, report_reconnect}}; +use crate::{ + client::{BlockChainClient, EngineClient}, + engines::hbbft::contracts::connectivity_tracker_hbbft::report_missing_connectivity, + ethereum::public_key_to_address::public_key_to_address, +}; +use std::{ + collections::BTreeMap, + time::{Duration, Instant}, +}; + +use super::{ + contracts::connectivity_tracker_hbbft::{ + get_current_flagged_validators_from_contract, report_reconnect, + }, + hbbft_message_memorium::HbbftMessageMemorium, + NodeId, +}; pub(crate) struct HbbftEarlyEpochEndManager { /// The current epoch number. @@ -26,13 +39,11 @@ pub(crate) struct HbbftEarlyEpochEndManager { /// only grow up to 7 elements for a usual set of 25 nodes. flagged_validators: Vec, - node_id_to_address: BTreeMap, - address_to_node_id: BTreeMap, - signing_address: Address + signing_address: Address, } impl HbbftEarlyEpochEndManager { @@ -49,7 +60,6 @@ impl HbbftEarlyEpochEndManager { validator_set: Vec, signing_address: &Address, ) -> Option { - if client.is_syncing() { // if we are syncing, we do not need to create an early epoch end manager yet. // if we are syncing as a validator, and it is really this epoch, @@ -62,13 +72,12 @@ impl HbbftEarlyEpochEndManager { return None; } - let mut node_id_to_address: BTreeMap = BTreeMap::new(); + let mut node_id_to_address: BTreeMap = BTreeMap::new(); let mut address_to_node_id: BTreeMap = BTreeMap::new(); let mut validators: Vec = Vec::new(); for validator in validator_set.iter() { - let address = public_key_to_address(&validator.0); node_id_to_address.insert(validator.clone(), address); address_to_node_id.insert(address, validator.clone()); @@ -78,7 +87,7 @@ impl HbbftEarlyEpochEndManager { } validators.push(validator.clone()); - }; + } // figure out if we have to retrieve the data from the smart contracts. // if the epoch start did just happen, @@ -91,7 +100,11 @@ impl HbbftEarlyEpochEndManager { start_block: epoch_start_block, allowed_devp2p_warmup_time, validators: validators, - flagged_validators: Self::get_current_flagged_validators_from_contracts(engine_client, BlockId::Latest, &address_to_node_id), + flagged_validators: Self::get_current_flagged_validators_from_contracts( + engine_client, + BlockId::Latest, + &address_to_node_id, + ), node_id_to_address, address_to_node_id, signing_address: signing_address.clone(), @@ -106,16 +119,16 @@ impl HbbftEarlyEpochEndManager { fn get_current_flagged_validators_from_contracts( client: &dyn EngineClient, block_id: BlockId, - address_to_node_id: &BTreeMap + address_to_node_id: &BTreeMap, ) -> Vec { // todo: call smart contract. match get_current_flagged_validators_from_contract(client, block_id) { Ok(v) => { - let mut result : Vec = Vec::new(); + let mut result: Vec = Vec::new(); for a in v.iter() { - if let Some(node_id) = address_to_node_id.get(a) { + if let Some(node_id) = address_to_node_id.get(a) { result.push(node_id.clone()); } else { error!(target: "engine","early-epoch-end: could not find validator in address cache: {a:?}"); @@ -124,42 +137,43 @@ impl HbbftEarlyEpochEndManager { return result; // address_to_node_id.get(key) - }, + } Err(e) => { error!(target: "engine","early-epoch-end: could not get_current_flagged_validators_from_contracts {e:?}" ); Vec::new() - }, + } } - - } fn notify_about_missing_validator( &mut self, validator: &NodeId, client: &dyn EngineClient, - full_client: &dyn BlockChainClient) - { - + full_client: &dyn BlockChainClient, + ) { if let Some(validator_address) = self.node_id_to_address.get(validator) { - if report_missing_connectivity(client, full_client, validator_address, &self.signing_address) { + if report_missing_connectivity( + client, + full_client, + validator_address, + &self.signing_address, + ) { self.flagged_validators.push(validator.clone()); } } else { warn!("Could not find validator_address for node id in cache: {validator:?}"); return; } - } fn notify_about_validator_reconnect( &mut self, validator: &NodeId, full_client: &dyn BlockChainClient, - engine_client: &dyn EngineClient + engine_client: &dyn EngineClient, ) { - - let index = if let Some(index) = self.flagged_validators.iter().position(|x| x == validator) { + let index = if let Some(index) = self.flagged_validators.iter().position(|x| x == validator) + { index } else { error!(target: "engine", "early-epoch-end: notify_about_validator_reconnect Could not find reconnected validator in flagged validators."); @@ -167,7 +181,12 @@ impl HbbftEarlyEpochEndManager { }; if let Some(validator_address) = self.node_id_to_address.get(validator) { - if report_reconnect(engine_client, full_client, validator_address, &self.signing_address) { + if report_reconnect( + engine_client, + full_client, + validator_address, + &self.signing_address, + ) { self.flagged_validators.remove(index); } } else { @@ -224,22 +243,14 @@ impl HbbftEarlyEpochEndManager { // we do not have to send notification, if we already did so. if !self.flagged_validators.contains(validator) { // this function will also add the validator to the list of flagged validators. - self.notify_about_missing_validator( - &validator, - client, - full_client - ); + self.notify_about_missing_validator(&validator, client, full_client); } } else { // this validator is OK. // maybe it was flagged and we need to unflag it ? if self.flagged_validators.contains(validator) { - self.notify_about_validator_reconnect( - &validator, - full_client, - client - ); + self.notify_about_validator_reconnect(&validator, full_client, client); } } } else { @@ -247,11 +258,7 @@ impl HbbftEarlyEpochEndManager { // we do not have any history for this node. if !self.flagged_validators.contains(validator) { // this function will also add the validator to the list of flagged validators. - self.notify_about_missing_validator( - &validator, - client, - full_client - ); + self.notify_about_missing_validator(&validator, client, full_client); } } // todo: if the systems switched from block based measurement to time based measurement. diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 90798ea37..bbf04151c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1015,7 +1015,7 @@ impl HoneyBadgerBFT { // here is a possible performance improvement: // this won't change during the lifetime of the application ?! return Ok(()); - } + } }; let engine_client = client_arc.deref(); From c245354d9ae8fedf344d36ad69016804a5287d7f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 13 Dec 2023 13:51:21 +0100 Subject: [PATCH 151/687] panic hook now reports to diamond-node --- crates/util/panic-hook/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/util/panic-hook/src/lib.rs b/crates/util/panic-hook/src/lib.rs index f30f9ac99..ca23bb0f4 100644 --- a/crates/util/panic-hook/src/lib.rs +++ b/crates/util/panic-hook/src/lib.rs @@ -51,7 +51,7 @@ where static ABOUT_PANIC: &str = " This is a bug. Please report it at: - https://github.com/openethereum/openethereum/issues/new + https://github.com/dmdcoin/diamond-node/issues/new "; fn gen_panic_msg(info: &PanicInfo) -> String { From bfe58d06e744230b185cacaf0943500cbea276d7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 00:27:01 +0100 Subject: [PATCH 152/687] fixed bug with accessing the connectivity tracker --- .../src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index 16715b35d..3e15bc0dc 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -15,7 +15,7 @@ use_contract!( lazy_static! { static ref CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS: Address = - Address::from_str("0x1200000000000000000000000000000000000001").unwrap(); + Address::from_str("1200000000000000000000000000000000000001").unwrap(); } macro_rules! call_const_connectivity_tracker_hbbft { From eab3156e8cefa0933c0c5ef08e0317c1501c2806 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 00:28:50 +0100 Subject: [PATCH 153/687] streamlined logging in connectivity_tracker_hbbft to early-epoch-end --- .../engines/hbbft/contracts/connectivity_tracker_hbbft.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index 3e15bc0dc..d549ed667 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -45,11 +45,11 @@ fn get_block_data(client: &dyn EngineClient) -> (u64, H256) { let hash = header.hash(); return (block_number, hash); } else { - warn!(target:"engine", "could not get block number for block: {block_number}"); + warn!(target:"engine", "early-epoch-end: could not get block number for block: {block_number}"); return (0, H256::zero()); } } else { - warn!(target:"engine", "could not get latest block."); + warn!(target:"engine", "early-epoch-end: could not get latest block."); return (0, H256::zero()); }; } @@ -79,9 +79,9 @@ pub fn report_missing_connectivity( .gas(U256::from(200_000)) .nonce(nonce); - info!(target:"consensus", "sending report_missing_connectivity for with nonce: {nonce}, missing: {:?} ", missing_validator); + info!(target:"engine", "early-epoch-end: sending report_missing_connectivity for with nonce: {nonce}, missing: {:?} ", missing_validator); if let Err(e) = full_client.transact_silently(transaction) { - warn!(target:"consensus", "could not report_missing_connectivity {e:?}"); + warn!(target:"engine", "early-epoch-end: could not report_missing_connectivity {e:?}"); return false; } return true; From 62b191c73205996145ce53a9026371e72c99bcd8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 00:30:19 +0100 Subject: [PATCH 154/687] reduced default log levels for hbbft testnetworks. --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index d5c456aa3..685faf374 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -241,7 +241,7 @@ fn to_toml( let mut misc = Map::new(); misc.insert( "logging".into(), - Value::String("txqueue=trace,consensus=trace,engine=trace".into()), + Value::String("txqueue=info,consensus=debug,engine=trace".into()), ); misc.insert("log_file".into(), Value::String("parity.log".into())); From c92e98caa28b6096beb0faf04839b650f25094d0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 10:56:51 +0100 Subject: [PATCH 155/687] default logging to diamond-node.log instead of parity.log --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 685faf374..aa6cd242a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -243,7 +243,7 @@ fn to_toml( "logging".into(), Value::String("txqueue=info,consensus=debug,engine=trace".into()), ); - misc.insert("log_file".into(), Value::String("parity.log".into())); + misc.insert("log_file".into(), Value::String("diamond-node.log".into())); // metrics.insert(""); From 4d058477afcd185ac21dd121e0ad4e3bc2092656 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 11:01:29 +0100 Subject: [PATCH 156/687] improved logging --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index bbf04151c..01cfe3555 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -943,6 +943,8 @@ impl HoneyBadgerBFT { // todo: acquire allowed devp2p warmup time from contracts ?! let allowed_devp2p_warmup_time = Duration::from_secs(120); + debug!(target: "engine", "early-epoch-end: handle_early_epoch_end."); + let hbbft_state = if let Some(s) = self.hbbft_state.try_read_for(Duration::from_millis(300)) { s @@ -999,7 +1001,7 @@ impl HoneyBadgerBFT { fn do_validator_engine_actions(&self) -> Result<(), String> { // here we need to differentiate the different engine functions, // that requre different levels of access to the client. - + debug!(target: "engine", "do_validator_engine_actions."); match self.client_arc() { Some(client_arc) => { if self.is_syncing(&client_arc) { @@ -1314,8 +1316,7 @@ impl HoneyBadgerBFT { return Ok(stake_amount.ge(&min_stake)); } Err(err) => { - warn!(target: "consensus", "Error get candidate_min_stake: ! {:?}", err); - warn!(target: "consensus", "stake amount: {}", stake_amount); + error!(target: "consensus", "Error get candidate_min_stake: ! {:?}", err); } } } From 2e33f333c53e1131bf2f2e6a8a42f959f714a162 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 11:03:17 +0100 Subject: [PATCH 157/687] reduced logging levels in hbbft_peers_management --- crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 42e0b3042..27c7ff684 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -369,7 +369,7 @@ impl HbbftPeersManagement { // we do not need to do a special handling for 0.0.0.0, because // our IP is always different to that. - warn!(target: "engine", "checking if internet address needs to be updated."); + trace!(target: "engine", "checking if internet address needs to be updated."); let current_endpoint = if let Some(peers_management) = block_chain_client .reserved_peers_management() @@ -388,14 +388,14 @@ impl HbbftPeersManagement { }; //let peers_management = - warn!(target: "engine", "current Endpoint: {:?}", current_endpoint); + trace!(target: "engine", "current Endpoint: {:?}", current_endpoint); // todo: we can improve performance, // by assuming that we are the only one who writes the internet address. // so we have to query this data only once, and then we can cache it. match get_validator_internet_address(engine_client, &staking_address) { Ok(validator_internet_address) => { - warn!(target: "engine", "stored validator address{:?}", validator_internet_address); + trace!(target: "engine", "stored validator address{:?}", validator_internet_address); if validator_internet_address.eq(¤t_endpoint) { // if the current stored endpoint is the same as the current endpoint, // we don't need to do anything. From dda50e1f77e70be1e5ac15a14b8994955385623e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 14:25:03 +0100 Subject: [PATCH 158/687] improved logging for hbbft_peers_management for identifying the problem with could not add pending validator to reserved peers: --- crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 27c7ff684..c42bfa0cd 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -534,6 +534,7 @@ fn connect_to_validator_core( }; if socket_addr.port() == 0 { + error!(target: "engine", "connect_to_validator_core: no port specified for Node ( Public (NodeId): {:?} , staking address: {}, socket_addr: {:?}", node_id, staking_address, socket_addr); // we interprate port 0 as NULL. return None; } From ecfe2efb7e1e8e066fd59149084f02ad06e2014b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 14:25:39 +0100 Subject: [PATCH 159/687] improved logging about own_tx cancelled transactions. --- crates/concensus/miner/src/pool/local_transactions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/concensus/miner/src/pool/local_transactions.rs b/crates/concensus/miner/src/pool/local_transactions.rs index bb86f76f9..c9309a9bb 100644 --- a/crates/concensus/miner/src/pool/local_transactions.rs +++ b/crates/concensus/miner/src/pool/local_transactions.rs @@ -225,7 +225,7 @@ impl txpool::Listener for LocalTransactionsList { return; } - warn!(target: "own_tx", "Transaction canceled (hash {:?})", tx.hash()); + warn!(target: "own_tx", "Transaction canceled (hash {:?}), zero gas price: {}, nonce: {} data: {} ", tx.hash(), tx.has_zero_gas_price(), tx.nonce(), rustc_hex::ToHex::to_hex(tx.transaction.tx().data.as_slice())); self.insert(*tx.hash(), Status::Canceled(tx.clone())); self.clear_old(); } From b8c658469fa6be100b687fa38934ca166eb6b1e9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 14:27:07 +0100 Subject: [PATCH 160/687] improved logging about own_tx cancelled transactions. --- crates/concensus/miner/Cargo.toml | 1 + crates/concensus/miner/src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/concensus/miner/Cargo.toml b/crates/concensus/miner/Cargo.toml index 10f0de5a1..309aa1663 100644 --- a/crates/concensus/miner/Cargo.toml +++ b/crates/concensus/miner/Cargo.toml @@ -37,6 +37,7 @@ serde_derive = "1.0" serde_json = "1.0" trace-time = "0.1" txpool = { path = "../../transaction-pool" } +rustc-hex = "1.0" [dev-dependencies] env_logger = "0.5" diff --git a/crates/concensus/miner/src/lib.rs b/crates/concensus/miner/src/lib.rs index bdd0ad67e..5aa617dfe 100644 --- a/crates/concensus/miner/src/lib.rs +++ b/crates/concensus/miner/src/lib.rs @@ -35,6 +35,7 @@ extern crate parking_lot; #[cfg(feature = "price-info")] extern crate price_info; extern crate rlp; +extern crate rustc_hex; extern crate txpool; #[macro_use] @@ -52,8 +53,7 @@ extern crate trace_time; extern crate env_logger; #[cfg(test)] extern crate ethkey; -#[cfg(test)] -extern crate rustc_hex; + pub mod external; #[cfg(feature = "price-info")] From 5699d5a8bb0274e501c946fad9bf3d531b111994 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 15:09:28 +0100 Subject: [PATCH 161/687] reduced logging for HBBFT block creation transactions. --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 9138a7bc3..05f0df11d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -445,13 +445,13 @@ impl HbbftState { if tx.nonce() >= min_nonce { transactions_subset.push(tx); } else { - info!(target: "consensus", "Block creation: Pending transaction with nonce too low, got {}, expected at least {}", tx.nonce(), min_nonce); + debug!(target: "consensus", "Block creation: Pending transaction with nonce too low, got {}, expected at least {}", tx.nonce(), min_nonce); } } } } - info!(target: "consensus", "Block creation: Honeybadger epoch {}, Transactions subset target size: {}, actual size: {}, from available {}.", honey_badger.epoch(), transactions_subset_size, transactions_subset.len(), max_transactions_for_block.len()); + trace!(target: "consensus", "Block creation: Honeybadger epoch {}, Transactions subset target size: {}, actual size: {}, from available {}.", honey_badger.epoch(), transactions_subset_size, transactions_subset.len(), max_transactions_for_block.len()); let signed_transactions = transactions_subset .iter() From dd1f837e59c587741476a8d7d55d065adb1dee03 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Dec 2023 15:09:51 +0100 Subject: [PATCH 162/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/concensus/miner/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/concensus/miner/src/lib.rs b/crates/concensus/miner/src/lib.rs index 5aa617dfe..062da7f37 100644 --- a/crates/concensus/miner/src/lib.rs +++ b/crates/concensus/miner/src/lib.rs @@ -54,7 +54,6 @@ extern crate env_logger; #[cfg(test)] extern crate ethkey; - pub mod external; #[cfg(feature = "price-info")] pub mod gas_price_calibrator; From 7b3e4e372439c57ed5ded0a15203340b9b72e9aa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 15 Dec 2023 00:58:47 +0100 Subject: [PATCH 163/687] early-epoich-end improved logging --- .../ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index f35a28fea..a6524f4d8 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -231,6 +231,8 @@ impl HbbftEarlyEpochEndManager { return; } + trace!(target: "engine", "checking epoch history for {} validators", &self.validators.len()); + //full_client.best_block_header() // get current state of missing validators from hbbftMemorium. if let Some(epoch_history) = memorium.get_staking_epoch_history(block_num) { From 246bf272d4d6e2405b95bb7ecc67742f31ce2350 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 16 Dec 2023 23:51:42 +0100 Subject: [PATCH 164/687] gas_price for connectivity tracker --- .../src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index d549ed667..b4513b7f5 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -77,6 +77,7 @@ pub fn report_missing_connectivity( let transaction = TransactionRequest::call(*CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, send_data.0) .gas(U256::from(200_000)) + .gas_price(U256::from(10000000000u64)) .nonce(nonce); info!(target:"engine", "early-epoch-end: sending report_missing_connectivity for with nonce: {nonce}, missing: {:?} ", missing_validator); From 6d8360a0fe0af27612f1fe5e087b6384219f91e5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 18 Dec 2023 21:44:46 +0100 Subject: [PATCH 165/687] possible solution:: detected attempt to break because of is_major_syncing() instead of is_synincg()no decision: syncing --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index a6524f4d8..12e6bf010 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -209,12 +209,18 @@ impl HbbftEarlyEpochEndManager { return; } - if full_client.is_syncing() { + if full_client.is_major_syncing() { // if we are syncing, we wont do any blaming. debug!(target: "engine", "early-epoch-end: no decision: syncing"); return; } + + if full_client.is_syncing() { + // if we are syncing, we wont do any blaming. + debug!(target: "engine", "early-epoch-end: detected attempt to break because of is_major_syncing() instead of is_synincg()no decision: syncing"); + } + let block_num = if let Some(block) = full_client.block(BlockId::Latest) { block.number() } else { From 2b62c2c826b3b8ef3aa7ef1476ca7e51eb63aaea Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 18 Dec 2023 23:02:10 +0100 Subject: [PATCH 166/687] don't cache flagged validators --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 12e6bf010..040b3bf4e 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -263,8 +263,11 @@ impl HbbftEarlyEpochEndManager { } } else { debug!(target: "engine", "early-epoch-end: no history info for validator {validator}"); + + let current_flagged = Self::get_current_flagged_validators_from_contracts(client, BlockId::Latest, &self.address_to_node_id); + // we do not have any history for this node. - if !self.flagged_validators.contains(validator) { + if !current_flagged.contains(validator) { // this function will also add the validator to the list of flagged validators. self.notify_about_missing_validator(&validator, client, full_client); } From b6cfbac3a7bbb8ee817456b699d2bdb43f99789c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 18 Dec 2023 23:02:39 +0100 Subject: [PATCH 167/687] added more gas for testing --- .../src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index b4513b7f5..b379caf30 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -76,7 +76,7 @@ pub fn report_missing_connectivity( let transaction = TransactionRequest::call(*CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, send_data.0) - .gas(U256::from(200_000)) + .gas(U256::from(500_000)) .gas_price(U256::from(10000000000u64)) .nonce(nonce); From cf7b1033d37c5bdc50ec77d26e40b301602a3592 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 28 Dec 2023 20:12:41 +0100 Subject: [PATCH 168/687] config generator: show trace information for own transactions --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index aa6cd242a..5c1895b52 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -241,7 +241,7 @@ fn to_toml( let mut misc = Map::new(); misc.insert( "logging".into(), - Value::String("txqueue=info,consensus=debug,engine=trace".into()), + Value::String("txqueue=info,consensus=debug,engine=trace,tx_own=trace".into()), ); misc.insert("log_file".into(), Value::String("diamond-node.log".into())); From ed2c7a7ca16201f6cad90af9aeb33f44dff82146 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 4 Jan 2024 16:43:12 +0100 Subject: [PATCH 169/687] Switched from the deprecated "failure" crate to "thiserror" --- Cargo.lock | 2 +- crates/util/EIP-712/Cargo.toml | 2 +- crates/util/EIP-712/src/encode.rs | 2 +- crates/util/EIP-712/src/error.rs | 93 ++++++------------------------- crates/util/EIP-712/src/lib.rs | 2 - 5 files changed, 19 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e64aa5c8..dc500e42c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -949,7 +949,6 @@ version = "0.1.0" dependencies = [ "ethabi 12.0.0", "ethereum-types 0.9.2", - "failure", "indexmap", "itertools 0.7.11", "keccak-hash", @@ -960,6 +959,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", + "thiserror", "validator", "validator_derive", ] diff --git a/crates/util/EIP-712/Cargo.toml b/crates/util/EIP-712/Cargo.toml index 2a2d0f8ae..f98fc0161 100644 --- a/crates/util/EIP-712/Cargo.toml +++ b/crates/util/EIP-712/Cargo.toml @@ -18,7 +18,7 @@ ethabi = "12.0.0" keccak-hash = "0.5.0" ethereum-types = "0.9.2" logos = "0.12.0" -failure = "0.1.7" +thiserror = "1.0" itertools = "0.7" lazy_static = "1.1" regex = "1.0" diff --git a/crates/util/EIP-712/src/encode.rs b/crates/util/EIP-712/src/encode.rs index a63f8300c..e09410687 100644 --- a/crates/util/EIP-712/src/encode.rs +++ b/crates/util/EIP-712/src/encode.rs @@ -438,7 +438,7 @@ mod tests { let typed_data = from_str::(TEST).expect("alas error!"); assert_eq!( - hash_structured_data(typed_data).unwrap_err().kind(), + hash_structured_data(typed_data).unwrap_err(), ErrorKind::UnequalArrayItems(2, "Person[2]".into(), 1) ) } diff --git a/crates/util/EIP-712/src/error.rs b/crates/util/EIP-712/src/error.rs index 6ce839eb4..41b77cb3a 100644 --- a/crates/util/EIP-712/src/error.rs +++ b/crates/util/EIP-712/src/error.rs @@ -14,56 +14,32 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use failure::{Backtrace, Context, Fail}; -use std::fmt::{self, Display}; use validator::{ValidationErrors, ValidationErrorsKind}; +use thiserror::Error; -pub(crate) type Result = ::std::result::Result; -/// Error type -#[derive(Debug)] -pub struct Error { - inner: Context, -} -/// Possible errors encountered while hashing/encoding an EIP-712 compliant data structure -#[derive(Clone, Fail, Debug, PartialEq)] +pub(crate) type Result = ::std::result::Result; + +#[derive(Error, Debug, PartialEq)] pub enum ErrorKind { - /// if we fail to deserialize from a serde::Value as a type specified in message types - /// fail with this error. - #[fail(display = "Expected type '{}' for field '{}'", _0, _1)] + #[error("Expected type '{0}' for field '{1}'")] UnexpectedType(String, String), - /// the primary type supplied doesn't exist in the MessageTypes - #[fail(display = "The given primaryType wasn't found in the types field")] + #[error("The given primaryType wasn't found in the types field")] NonExistentType, - /// an invalid address was encountered during encoding - #[fail( - display = "Address string should be a 0x-prefixed 40 character string, got '{}'", - _0 - )] + #[error("Address string should be a 0x-prefixed 40 character string, got '{0}'")] InvalidAddressLength(usize), - /// a hex parse error occured - #[fail(display = "Failed to parse hex '{}'", _0)] + #[error("Failed to parse hex '{0}'")] HexParseError(String), - /// the field was declared with a unknown type - #[fail(display = "The field '{}' has an unknown type '{}'", _0, _1)] + #[error("The field '{0}' has an unknown type '{1}'")] UnknownType(String, String), - /// Unexpected token - #[fail(display = "Unexpected token '{}' while parsing typename '{}'", _0, _1)] + #[error("Unexpected token '{0}' while parsing typename '{1}'")] UnexpectedToken(String, String), - /// the user has attempted to define a typed array with a depth > 10 - #[fail(display = "Maximum depth for nested arrays is 10")] + #[error("Maximum depth for nested arrays is 10")] UnsupportedArrayDepth, - /// FieldType validation error - #[fail(display = "{}", _0)] + #[error("{0}")] ValidationError(String), - /// the typed array defined in message types was declared with a fixed length - /// that is of unequal length with the items to be encoded - #[fail( - display = "Expected {} items for array type {}, got {} items", - _0, _1, _2 - )] + #[error("Expected {0} items for array type {1}, got {2} items")] UnequalArrayItems(u64, String, u64), - /// Typed array length doesn't fit into a u64 - #[fail(display = "Attempted to declare fixed size with length {}", _0)] + #[error("Attempted to declare fixed size with length {0}")] InvalidArraySize(String), } @@ -71,44 +47,7 @@ pub(crate) fn serde_error(expected: &str, field: Option<&str>) -> ErrorKind { ErrorKind::UnexpectedType(expected.to_owned(), field.unwrap_or("").to_owned()) } -impl Fail for Error { - fn cause(&self) -> Option<&dyn Fail> { - self.inner.cause() - } - - fn backtrace(&self) -> Option<&Backtrace> { - self.inner.backtrace() - } -} - -impl Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.inner, f) - } -} - -impl Error { - /// extract the error kind - pub fn kind(&self) -> ErrorKind { - self.inner.get_context().clone() - } -} - -impl From for Error { - fn from(kind: ErrorKind) -> Error { - Error { - inner: Context::new(kind), - } - } -} - -impl From> for Error { - fn from(inner: Context) -> Error { - Error { inner } - } -} - -impl From for Error { +impl From for ErrorKind { fn from(error: ValidationErrors) -> Self { let mut string: String = "".into(); for (field_name, error_kind) in error.errors() { @@ -128,6 +67,6 @@ impl From for Error { ), } } - ErrorKind::ValidationError(string).into() + ErrorKind::ValidationError(string) } } diff --git a/crates/util/EIP-712/src/lib.rs b/crates/util/EIP-712/src/lib.rs index 21eafc3a4..ed7670e24 100644 --- a/crates/util/EIP-712/src/lib.rs +++ b/crates/util/EIP-712/src/lib.rs @@ -172,5 +172,3 @@ mod parser; pub use crate::eip712::EIP712; /// the EIP-712 encoding function pub use crate::encode::hash_structured_data; -/// encoding Error types -pub use crate::error::{Error, ErrorKind}; From c1860afd249234709d0470b0d525e21e414804f0 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 4 Jan 2024 16:48:21 +0100 Subject: [PATCH 170/687] Rustfmt fix --- crates/util/EIP-712/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/util/EIP-712/src/error.rs b/crates/util/EIP-712/src/error.rs index 41b77cb3a..78861cd19 100644 --- a/crates/util/EIP-712/src/error.rs +++ b/crates/util/EIP-712/src/error.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use validator::{ValidationErrors, ValidationErrorsKind}; use thiserror::Error; +use validator::{ValidationErrors, ValidationErrorsKind}; pub(crate) type Result = ::std::result::Result; From b77f31f76f24a22727840535ede32d04ccc1d8dd Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 4 Jan 2024 19:51:06 +0100 Subject: [PATCH 171/687] Build/warning fixes --- crates/rpc/src/v1/helpers/eip191.rs | 2 +- crates/rpc/src/v1/impls/personal.rs | 2 +- crates/runtime/io/src/lib.rs | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/rpc/src/v1/helpers/eip191.rs b/crates/rpc/src/v1/helpers/eip191.rs index 51bd1580d..044629a54 100644 --- a/crates/rpc/src/v1/helpers/eip191.rs +++ b/crates/rpc/src/v1/helpers/eip191.rs @@ -33,7 +33,7 @@ pub fn hash_message(version: EIP191Version, message: Value) -> Result(message).map_err(map_serde_err("StructuredData"))?; - hash_structured_data(typed_data).map_err(|err| errors::invalid_call_data(err.kind()))? + hash_structured_data(typed_data).map_err(|err| errors::invalid_call_data(err))? } EIP191Version::PresignedTransaction => { diff --git a/crates/rpc/src/v1/impls/personal.rs b/crates/rpc/src/v1/impls/personal.rs index 813790333..0763443a9 100644 --- a/crates/rpc/src/v1/impls/personal.rs +++ b/crates/rpc/src/v1/impls/personal.rs @@ -253,7 +253,7 @@ impl Personal for PersonalClient { let data = match hash_structured_data(typed_data) { Ok(d) => d, - Err(err) => return Box::new(future::err(errors::invalid_call_data(err.kind()))), + Err(err) => return Box::new(future::err(errors::invalid_call_data(err))), }; let dispatcher = self.dispatcher.clone(); let accounts = Arc::new(dispatch::Signer::new(self.accounts.clone())) as _; diff --git a/crates/runtime/io/src/lib.rs b/crates/runtime/io/src/lib.rs index 369b3b164..455a26a31 100644 --- a/crates/runtime/io/src/lib.rs +++ b/crates/runtime/io/src/lib.rs @@ -254,9 +254,7 @@ mod tests { struct MyHandler(atomic::AtomicBool); #[derive(Clone)] - struct MyMessage { - data: u32, - } + struct MyMessage {} impl IoHandler for MyHandler { fn initialize(&self, io: &IoContext) { @@ -285,9 +283,7 @@ mod tests { struct MyHandler(atomic::AtomicUsize); #[derive(Clone)] - struct MyMessage { - data: u32, - } + struct MyMessage {} impl IoHandler for MyHandler { fn initialize(&self, io: &IoContext) { From caec917c76f0f8f6862ac656e71a3a737b15e099 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 4 Jan 2024 20:10:40 +0100 Subject: [PATCH 172/687] Updated from the compromised crossbeam-deque 0.6 to 0.7.4 --- Cargo.lock | 34 +++++++++--------------- crates/runtime/io/Cargo.toml | 2 +- crates/runtime/io/src/service_mio.rs | 3 ++- crates/runtime/io/src/service_non_mio.rs | 9 ++++--- crates/runtime/io/src/worker.rs | 2 +- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc500e42c..e6ad3c473 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -615,34 +615,26 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e44b8cf3e1a625844d1750e1f7820da46044ff6d28f4d43e455ba3e5bb2c13" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils 0.6.6", -] - -[[package]] -name = "crossbeam-deque" -version = "0.7.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71" +checksum = "c20ff29ded3204c5106278a81a38f4b482636ed4fa1e6cfbeef193291beb29ed" dependencies = [ "crossbeam-epoch", - "crossbeam-utils 0.6.6", + "crossbeam-utils 0.7.2", + "maybe-uninit", ] [[package]] name = "crossbeam-epoch" -version = "0.7.2" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9" +checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" dependencies = [ - "arrayvec 0.4.12", + "autocfg 1.0.0", "cfg-if 0.1.10", - "crossbeam-utils 0.6.6", + "crossbeam-utils 0.7.2", "lazy_static", + "maybe-uninit", "memoffset", "scopeguard 1.1.0", ] @@ -1350,7 +1342,7 @@ dependencies = [ name = "ethcore-io" version = "1.12.0" dependencies = [ - "crossbeam-deque 0.6.3", + "crossbeam-deque", "fnv", "futures", "log", @@ -4274,7 +4266,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83a27732a533a1be0a0035a111fe76db89ad312f6f0347004c220c57f209a123" dependencies = [ - "crossbeam-deque 0.7.1", + "crossbeam-deque", "either", "rayon-core", ] @@ -4285,7 +4277,7 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98dcf634205083b17d0861252431eb2acbfb698ab7478a2d20de07954f47ec7b" dependencies = [ - "crossbeam-deque 0.7.1", + "crossbeam-deque", "crossbeam-queue 0.1.2", "crossbeam-utils 0.6.6", "lazy_static", @@ -5345,7 +5337,7 @@ version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df720b6581784c118f0eb4310796b12b1d242a7eb95f716a8367855325c25f89" dependencies = [ - "crossbeam-deque 0.7.1", + "crossbeam-deque", "crossbeam-queue 0.2.3", "crossbeam-utils 0.7.2", "futures", diff --git a/crates/runtime/io/Cargo.toml b/crates/runtime/io/Cargo.toml index 730625796..2270ca840 100644 --- a/crates/runtime/io/Cargo.toml +++ b/crates/runtime/io/Cargo.toml @@ -9,7 +9,7 @@ authors = ["Parity Technologies "] [dependencies] fnv = "1.0" mio = { version = "0.6.8", optional = true } -crossbeam-deque = "0.6" +crossbeam-deque = "0.7.4" parking_lot = "0.11.1" log = "0.4" slab = "0.4" diff --git a/crates/runtime/io/src/service_mio.rs b/crates/runtime/io/src/service_mio.rs index 41cd7b19e..32d2ea6dc 100644 --- a/crates/runtime/io/src/service_mio.rs +++ b/crates/runtime/io/src/service_mio.rs @@ -214,7 +214,8 @@ where event_loop: &mut EventLoop>, handlers: Arc>>>>, ) -> Result<(), IoError> { - let (worker, stealer) = deque::fifo(); + let worker = deque::Worker::new_fifo(); + let stealer = worker.stealer(); let num_workers = 4; let work_ready_mutex = Arc::new(Mutex::new(())); let work_ready = Arc::new(Condvar::new()); diff --git a/crates/runtime/io/src/service_non_mio.rs b/crates/runtime/io/src/service_non_mio.rs index 376abb9d9..4d7651a5d 100644 --- a/crates/runtime/io/src/service_non_mio.rs +++ b/crates/runtime/io/src/service_non_mio.rs @@ -270,7 +270,8 @@ where pub fn start(_symbolic_name: &'static str) -> Result, IoError> { // This minimal implementation of IoService does have named Workers // like the mio-dependent one does, so _symbolic_name is ignored. - let (tx, rx) = deque::fifo(); + let tx = deque::Worker::new_fifo(); + let rx = tx.stealer(); let shared = Arc::new(Shared { handlers: RwLock::new(Slab::with_capacity(MAX_HANDLERS)), @@ -370,8 +371,8 @@ where match rx.steal() { deque::Steal::Retry => continue, deque::Steal::Empty => thread::park(), - deque::Steal::Data(WorkTask::Shutdown) => break, - deque::Steal::Data(WorkTask::UserMessage(message)) => { + deque::Steal::Success(WorkTask::Shutdown) => break, + deque::Steal::Success(WorkTask::UserMessage(message)) => { for id in 0..MAX_HANDLERS { if let Some(handler) = shared.handlers.read().get(id) { let ctxt = IoContext { @@ -382,7 +383,7 @@ where } } } - deque::Steal::Data(WorkTask::TimerTrigger { handler_id, token }) => { + deque::Steal::Success(WorkTask::TimerTrigger { handler_id, token }) => { if let Some(handler) = shared.handlers.read().get(handler_id) { let ctxt = IoContext { handler: handler_id, diff --git a/crates/runtime/io/src/worker.rs b/crates/runtime/io/src/worker.rs index 7d875121c..8b04bee72 100644 --- a/crates/runtime/io/src/worker.rs +++ b/crates/runtime/io/src/worker.rs @@ -94,7 +94,7 @@ impl Worker { while !deleting.load(AtomicOrdering::SeqCst) { match stealer.steal() { - deque::Steal::Data(work) => { + deque::Steal::Success(work) => { Worker::do_work(work, channel.clone()) } deque::Steal::Retry => {} From 2f6e8cac0843c123a37059b3434928c4266805f5 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 4 Jan 2024 20:27:55 +0100 Subject: [PATCH 173/687] Updated smallvec to version 0.6.14 --- Cargo.lock | 18 +++++++++--------- crates/accounts/ethstore/Cargo.toml | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6ad3c473..570ffe200 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1649,7 +1649,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "smallvec 0.6.13", + "smallvec 0.6.14", "tempdir", "time", ] @@ -3648,7 +3648,7 @@ dependencies = [ "libc", "rand 0.5.6", "rustc_version", - "smallvec 0.6.13", + "smallvec 0.6.14", "winapi 0.3.8", ] @@ -3663,7 +3663,7 @@ dependencies = [ "libc", "redox_syscall 0.1.56", "rustc_version", - "smallvec 0.6.13", + "smallvec 0.6.14", "winapi 0.3.8", ] @@ -3851,7 +3851,7 @@ dependencies = [ "hamming", "primal-bit", "primal-estimate", - "smallvec 0.6.13", + "smallvec 0.6.14", ] [[package]] @@ -4317,7 +4317,7 @@ dependencies = [ "cc", "libc", "rayon", - "smallvec 0.6.13", + "smallvec 0.6.14", ] [[package]] @@ -4797,9 +4797,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" +checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" dependencies = [ "maybe-uninit", ] @@ -5495,7 +5495,7 @@ version = "1.0.0-alpha" dependencies = [ "ethereum-types 0.7.0", "log", - "smallvec 0.6.13", + "smallvec 0.6.14", "trace-time", ] @@ -5557,7 +5557,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" dependencies = [ - "smallvec 0.6.13", + "smallvec 0.6.14", ] [[package]] diff --git a/crates/accounts/ethstore/Cargo.toml b/crates/accounts/ethstore/Cargo.toml index 540554059..bdfd93af8 100644 --- a/crates/accounts/ethstore/Cargo.toml +++ b/crates/accounts/ethstore/Cargo.toml @@ -18,7 +18,7 @@ itertools = "0.5" parking_lot = "0.11.1" parity-crypto = { version = "0.6.2", features = [ "publickey"] } ethereum-types = "0.9.2" -smallvec = "0.6" +smallvec = "0.6.14" parity-wordlist = "1.3" tempdir = "0.3" lazy_static = "1.2.0" From 7a2390aa52d686ec7a3b0c08693482c1b182461b Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 4 Jan 2024 20:39:08 +0100 Subject: [PATCH 174/687] Updated from igd 0.7 to 0.8, and with it eliminated the compromised hyper version 11 --- Cargo.lock | 225 +++++---------------------- crates/net/network-devp2p/Cargo.toml | 2 +- 2 files changed, 43 insertions(+), 184 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 570ffe200..32663ff5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,15 +83,6 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" -[[package]] -name = "aho-corasick" -version = "0.6.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" -dependencies = [ - "memchr", -] - [[package]] name = "aho-corasick" version = "0.7.6" @@ -829,7 +820,7 @@ dependencies = [ "fetch", "fs-swap", "futures", - "hyper 0.12.35", + "hyper", "ipnetwork", "journaldb", "jsonrpc-core", @@ -857,7 +848,7 @@ dependencies = [ "parking_lot 0.11.1", "pretty_assertions", "prometheus", - "regex 1.3.9", + "regex", "rlp", "rpassword", "rustc-hex 1.0.0", @@ -917,7 +908,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f525a586d310c87df72ebcd98009e57f1cc030c8c268305287a476beb653969" dependencies = [ "lazy_static", - "regex 1.3.9", + "regex", "serde", "strsim 0.9.2", ] @@ -946,7 +937,7 @@ dependencies = [ "keccak-hash", "lazy_static", "logos", - "regex 1.3.9", + "regex", "rustc-hex 2.1.0", "serde", "serde_derive", @@ -989,7 +980,7 @@ dependencies = [ "atty", "humantime", "log", - "regex 1.3.9", + "regex", "termcolor", ] @@ -1002,7 +993,7 @@ dependencies = [ "atty", "humantime", "log", - "regex 1.3.9", + "regex", "termcolor", ] @@ -1209,7 +1200,7 @@ dependencies = [ "rand 0.7.3", "rand_xorshift 0.2.0", "rayon", - "regex 1.3.9", + "regex", "reth-util", "rlp", "rlp_compress", @@ -1366,7 +1357,7 @@ dependencies = [ "lazy_static", "log", "parking_lot 0.11.1", - "regex 1.3.9", + "regex", "time", ] @@ -1387,7 +1378,7 @@ dependencies = [ "ethkey", "fetch", "futures", - "hyper 0.12.35", + "hyper", "keccak-hash", "linked-hash-map", "log", @@ -1743,7 +1734,7 @@ version = "0.0.1" dependencies = [ "fetch", "futures", - "hyper 0.12.35", + "hyper", ] [[package]] @@ -1776,7 +1767,7 @@ dependencies = [ "bytes", "futures", "http", - "hyper 0.12.35", + "hyper", "hyper-rustls", "log", "tokio", @@ -1943,11 +1934,11 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ad1da430bd7281dde2576f44c84cc3f0f7b475e7202cd503042dff01a8c8120" dependencies = [ - "aho-corasick 0.7.6", + "aho-corasick", "bstr", "fnv", "log", - "regex 1.3.9", + "regex", ] [[package]] @@ -2247,32 +2238,6 @@ dependencies = [ "quick-error", ] -[[package]] -name = "hyper" -version = "0.11.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34a590ca09d341e94cddf8e5af0bbccde205d5fbc2fa3c09dd67c7f85cea59d7" -dependencies = [ - "base64 0.9.3", - "bytes", - "futures", - "futures-cpupool", - "httparse", - "iovec", - "language-tags", - "log", - "mime", - "net2", - "percent-encoding 1.0.1", - "relay", - "time", - "tokio-core", - "tokio-io", - "tokio-service", - "unicase", - "want 0.0.4", -] - [[package]] name = "hyper" version = "0.12.35" @@ -2300,7 +2265,7 @@ dependencies = [ "tokio-tcp", "tokio-threadpool", "tokio-timer 0.2.13", - "want 0.2.0", + "want", ] [[package]] @@ -2312,7 +2277,7 @@ dependencies = [ "bytes", "ct-logs", "futures", - "hyper 0.12.35", + "hyper", "rustls", "tokio-io", "tokio-rustls", @@ -2350,18 +2315,13 @@ checksum = "4bac95d9aa0624e7b78187d6fb8ab012b41d9f6f54b1bcb61e61c4845f8357ec" [[package]] name = "igd" -version = "0.7.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8aef7814a769f156ef3a86169a8b04c066e3aebc324f522c159978466e32a1c" +checksum = "b1c44a9cf56a894ff1b90dc83d108a313e05f07c7b0c882f3783ce406525b947" dependencies = [ - "futures", - "hyper 0.11.27", + "lynx", "rand 0.4.6", - "regex 0.2.11", - "tokio-core", - "tokio-retry", - "tokio-timer 0.1.2", - "xml-rs", + "url 1.7.2", "xmltree", ] @@ -2560,7 +2520,7 @@ version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9996b26c0c7a59626d0ed6c5ec8bf06218e62ce1474bd2849f9b9fd38a0158c0" dependencies = [ - "hyper 0.12.35", + "hyper", "jsonrpc-core", "jsonrpc-server-utils", "log", @@ -2725,15 +2685,9 @@ dependencies = [ "num_cpus", "parity-rocksdb", "parking_lot 0.9.0", - "regex 1.3.9", + "regex", ] -[[package]] -name = "language-tags" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" - [[package]] name = "lazy_static" version = "1.4.0" @@ -2842,7 +2796,7 @@ dependencies = [ "fnv", "proc-macro2 1.0.58", "quote 1.0.27", - "regex-syntax 0.6.18", + "regex-syntax", "syn 1.0.94", "utf8-ranges", ] @@ -2865,6 +2819,17 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "lynx" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5296e8244cb83aa1b71bd5b070b56e7a5a7d693a809c3051badc5332319a8419" +dependencies = [ + "http", + "log", + "url 1.7.2", +] + [[package]] name = "macros" version = "0.1.0" @@ -2964,12 +2929,6 @@ dependencies = [ "tempdir", ] -[[package]] -name = "mime" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd1d63acd1b78403cc0c325605908475dd9b9a3acbf65ed8bcab97e27014afcf" - [[package]] name = "miniz_oxide" version = "0.4.4" @@ -3943,7 +3902,7 @@ dependencies = [ "rand 0.6.5", "rand_chacha 0.1.1", "rand_xorshift 0.1.1", - "regex-syntax 0.6.18", + "regex-syntax", "rusty-fork", "tempfile", ] @@ -4329,29 +4288,16 @@ dependencies = [ "smallvec 1.6.1", ] -[[package]] -name = "regex" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" -dependencies = [ - "aho-corasick 0.6.10", - "memchr", - "regex-syntax 0.5.6", - "thread_local 0.3.6", - "utf8-ranges", -] - [[package]] name = "regex" version = "1.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" dependencies = [ - "aho-corasick 0.7.6", + "aho-corasick", "memchr", - "regex-syntax 0.6.18", - "thread_local 1.0.1", + "regex-syntax", + "thread_local", ] [[package]] @@ -4363,30 +4309,12 @@ dependencies = [ "byteorder", ] -[[package]] -name = "regex-syntax" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" -dependencies = [ - "ucd-util", -] - [[package]] name = "regex-syntax" version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" -[[package]] -name = "relay" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1576e382688d7e9deecea24417e350d3062d97e32e45d70b1cde65994ff1489a" -dependencies = [ - "futures", -] - [[package]] name = "remove_dir_all" version = "0.5.2" @@ -4598,12 +4526,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scoped-tls" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" - [[package]] name = "scopeguard" version = "0.3.3" @@ -5038,15 +4960,6 @@ dependencies = [ "winapi 0.3.8", ] -[[package]] -name = "thread_local" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -dependencies = [ - "lazy_static", -] - [[package]] name = "thread_local" version = "1.0.1" @@ -5181,25 +5094,6 @@ dependencies = [ "tokio-io", ] -[[package]] -name = "tokio-core" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeeffbbb94209023feaef3c196a41cbcdafa06b4a6f893f68779bb5e53796f71" -dependencies = [ - "bytes", - "futures", - "iovec", - "log", - "mio", - "scoped-tls", - "tokio", - "tokio-executor", - "tokio-io", - "tokio-reactor", - "tokio-timer 0.2.13", -] - [[package]] name = "tokio-current-thread" version = "0.1.6" @@ -5274,18 +5168,6 @@ dependencies = [ "tokio-sync", ] -[[package]] -name = "tokio-retry" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05746ae87dca83a2016b4f5dba5b237b897dd12fd324f60afe282112f16969a" -dependencies = [ - "futures", - "rand 0.3.23", - "tokio-core", - "tokio-service", -] - [[package]] name = "tokio-rustls" version = "0.9.4" @@ -5477,12 +5359,6 @@ dependencies = [ "triehash", ] -[[package]] -name = "try-lock" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2" - [[package]] name = "try-lock" version = "0.2.2" @@ -5505,12 +5381,6 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" -[[package]] -name = "ucd-util" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85f514e095d348c279b1e5cd76795082cf15bd59b93207832abe0b1d8fed236" - [[package]] name = "uint" version = "0.8.5" @@ -5636,7 +5506,7 @@ checksum = "236a5eda3df2c877872e98dbc55d497d943792e6405d8fc65bd4f8a5e3b53c99" dependencies = [ "idna 0.1.5", "lazy_static", - "regex 1.3.9", + "regex", "serde", "serde_derive", "serde_json", @@ -5653,7 +5523,7 @@ dependencies = [ "lazy_static", "proc-macro2 0.4.30", "quote 0.6.13", - "regex 1.3.9", + "regex", "syn 0.15.26", "validator", ] @@ -5712,17 +5582,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "want" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a05d9d966753fa4b5c8db73fcab5eed4549cfe0e1e4e66911e5564a0085c35d1" -dependencies = [ - "futures", - "log", - "try-lock 0.1.0", -] - [[package]] name = "want" version = "0.2.0" @@ -5731,7 +5590,7 @@ checksum = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" dependencies = [ "futures", "log", - "try-lock 0.2.2", + "try-lock", ] [[package]] @@ -5939,9 +5798,9 @@ dependencies = [ [[package]] name = "xmltree" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9cfb54ca6b8f17d2377219ce485b134d53561b77e1393c7ea416f543a527431" +checksum = "ff8eaee9d17062850f1e6163b509947969242990ee59a35801af437abe041e70" dependencies = [ "xml-rs", ] diff --git a/crates/net/network-devp2p/Cargo.toml b/crates/net/network-devp2p/Cargo.toml index bcd80899c..a145fe816 100644 --- a/crates/net/network-devp2p/Cargo.toml +++ b/crates/net/network-devp2p/Cargo.toml @@ -14,7 +14,7 @@ rand = "0.7.3" tiny-keccak = "1.4" rust-crypto = "0.2.34" slab = "0.2" -igd = "0.7" +igd = "0.8" libc = "0.2.7" parking_lot = "0.11.1" ansi_term = "0.10" From c32f994287c028cc9ac2f09023220f489e0ef959 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Fri, 5 Jan 2024 07:21:14 +0100 Subject: [PATCH 175/687] Removed rust-crypto --- Cargo.lock | 30 ---------------------------- crates/net/network-devp2p/Cargo.toml | 1 - crates/net/network-devp2p/src/lib.rs | 1 - 3 files changed, 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 32663ff5f..729418842 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1444,7 +1444,6 @@ dependencies = [ "parking_lot 0.11.1", "rand 0.7.3", "rlp", - "rust-crypto", "rustc-hex 1.0.0", "serde", "serde_derive", @@ -1876,12 +1875,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" - [[package]] name = "generic-array" version = "0.12.3" @@ -3969,16 +3962,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" -[[package]] -name = "rand" -version = "0.3.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" -dependencies = [ - "libc", - "rand 0.4.6", -] - [[package]] name = "rand" version = "0.4.6" @@ -4433,19 +4416,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1601f32bc5858aae3cbfa1c645c96c4d820cc5c16be0194f089560c00b6eb625" -[[package]] -name = "rust-crypto" -version = "0.2.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" -dependencies = [ - "gcc", - "libc", - "rand 0.3.23", - "rustc-serialize", - "time", -] - [[package]] name = "rustc-demangle" version = "0.1.16" diff --git a/crates/net/network-devp2p/Cargo.toml b/crates/net/network-devp2p/Cargo.toml index a145fe816..096b7fdb6 100644 --- a/crates/net/network-devp2p/Cargo.toml +++ b/crates/net/network-devp2p/Cargo.toml @@ -12,7 +12,6 @@ mio = "0.6.8" bytes = "0.4" rand = "0.7.3" tiny-keccak = "1.4" -rust-crypto = "0.2.34" slab = "0.2" igd = "0.8" libc = "0.2.7" diff --git a/crates/net/network-devp2p/src/lib.rs b/crates/net/network-devp2p/src/lib.rs index 5b955ea45..1acd96607 100644 --- a/crates/net/network-devp2p/src/lib.rs +++ b/crates/net/network-devp2p/src/lib.rs @@ -64,7 +64,6 @@ extern crate ansi_term; //TODO: remove this extern crate bytes; -extern crate crypto as rcrypto; extern crate ethcore_io as io; extern crate ethcore_network as network; extern crate ethereum_types; From 98bea1770d6821ab7a7cbb39323bf65c398fe766 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 7 Jan 2024 11:00:17 +0100 Subject: [PATCH 176/687] Migrated to hbbft without deprecated "failure" dependency --- crates/ethcore/Cargo.toml | 4 ++-- .../ethcore/src/engines/hbbft/contracts/keygen_history.rs | 6 +++--- crates/ethcore/src/engines/hbbft/contribution.rs | 4 ++-- .../src/engines/hbbft/hbbft_config_generator/Cargo.toml | 6 +++--- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 4 ++-- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 2 +- crates/ethcore/src/engines/hbbft/sealing.rs | 4 ++-- crates/ethcore/src/lib.rs | 1 - 8 files changed, 15 insertions(+), 16 deletions(-) diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index 58f97beb9..519b17e5b 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -34,8 +34,8 @@ ethkey = { path = "../accounts/ethkey" } evm = { path = "../vm/evm" } globset = "0.4" hash-db = "0.11.0" -hbbft = { git = "https://github.com/surfingnerd/hbbft", rev = "cf0c45aa669b9c10abab1a0f4f2b33595879b60b" } -hbbft_testing = { git = "https://github.com/poanetwork/hbbft" } +hbbft = { git = "https://github.com/dforsten/hbbft", rev = "d25315eb1c3a8313db9d99d5d9ba021e0d74a52e" } +hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "d25315eb1c3a8313db9d99d5d9ba021e0d74a52e" } hex_fmt = "0.3.0" itertools = "0.5" journaldb = { path = "../db/journaldb" } diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index 7f6f3e1e3..066c10d47 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -51,7 +51,7 @@ pub fn engine_signer_to_synckeygen<'a>( .expect("Signer's public key must be available!"), None => Public::from(H512::from_low_u64_be(0)), }; - let mut rng = rand_065::thread_rng(); + let mut rng = rand::thread_rng(); let num_nodes = pub_keys.len(); SyncKeyGen::new(public, wrapper, pub_keys, max_faulty(num_nodes), &mut rng) } @@ -100,7 +100,7 @@ pub fn part_of_address( return Ok(None); } let deserialized_part: Part = bincode::deserialize(&serialized_part).unwrap(); - let mut rng = rand_065::thread_rng(); + let mut rng = rand::thread_rng(); let outcome = skg .handle_part(vmap.get(&address).unwrap(), deserialized_part, &mut rng) .unwrap(); @@ -171,7 +171,7 @@ pub struct KeyPairWrapper { impl<'a> PublicKey for PublicWrapper { type Error = crypto::publickey::Error; type SecretKey = KeyPairWrapper; - fn encrypt, R: rand_065::Rng>( + fn encrypt, R: rand::Rng>( &self, msg: M, _rng: &mut R, diff --git a/crates/ethcore/src/engines/hbbft/contribution.rs b/crates/ethcore/src/engines/hbbft/contribution.rs index 91eaf7561..b058addcc 100644 --- a/crates/ethcore/src/engines/hbbft/contribution.rs +++ b/crates/ethcore/src/engines/hbbft/contribution.rs @@ -1,4 +1,4 @@ -use rand_065::{self, distributions::Standard, Rng}; +use rand::{self, distributions::Standard, Rng}; use rlp::RlpStream; use std::time::UNIX_EPOCH; use types::transaction::SignedTransaction; @@ -42,7 +42,7 @@ impl Contribution { s.drain() }) .collect(); - let mut rng = rand_065::thread_rng(); + let mut rng = rand::thread_rng(); Contribution { transactions: ser_txns, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml index ff2a79ef0..85d4788da 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml @@ -14,10 +14,10 @@ ethcore = { path = "../../../.." } ethereum-types = "0.9.2" ethkey = { path = "../../../../../accounts/ethkey" } ethstore = { path = "../../../../../accounts/ethstore"} -hbbft = { git = "https://github.com/poanetwork/hbbft", rev = "4857b7f9c7a0f513caca97c308d352c6a77fe5c2" } -hbbft_testing = { git = "https://github.com/poanetwork/hbbft" } +hbbft = { git = "https://github.com/dforsten/hbbft", rev = "d25315eb1c3a8313db9d99d5d9ba021e0d74a52e" } +hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "d25315eb1c3a8313db9d99d5d9ba021e0d74a52e" } parity-crypto = { version = "0.6.2", features = ["publickey"] } -rand = "0.6.5" +rand = "0.7.3" rustc-hex = "2.1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 3540a6915..c9a3c42a3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1669,13 +1669,13 @@ mod tests { honey_badger::{HoneyBadger, HoneyBadgerBuilder}, NetworkInfo, }; - use rand_065; + use rand; use std::sync::Arc; use types::transaction::SignedTransaction; #[test] fn test_single_contribution() { - let mut rng = rand_065::thread_rng(); + let mut rng = rand::thread_rng(); let net_infos = NetworkInfo::generate_map(0..1usize, &mut rng) .expect("NetworkInfo generation is expected to always succeed"); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 3671ac001..2cc6e9b94 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -436,7 +436,7 @@ impl HbbftState { // Now we can select the transactions to include in our contribution. let input_contribution = Contribution::new(&signed_transactions); - let mut rng = rand_065::thread_rng(); + let mut rng = rand::thread_rng(); let step = honey_badger.propose(&input_contribution, &mut rng); match step { Ok(step) => Some((step, network_info)), diff --git a/crates/ethcore/src/engines/hbbft/sealing.rs b/crates/ethcore/src/engines/hbbft/sealing.rs index 3cf1b58fb..4eb78fc67 100644 --- a/crates/ethcore/src/engines/hbbft/sealing.rs +++ b/crates/ethcore/src/engines/hbbft/sealing.rs @@ -72,12 +72,12 @@ impl Decodable for RlpSig { #[cfg(test)] mod tests { use super::*; - use rand_065; + use rand; use rlp; #[test] fn test_rlp_signature() { - let sig: Signature = rand_065::random(); + let sig: Signature = rand::random(); let encoded = rlp::encode(&RlpSig(&sig)); let decoded: RlpSig = rlp::decode(&encoded).expect("decode RlpSignature"); assert_eq!(decoded.0, sig); diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index 4b2229c9e..d09dfd7c0 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -52,7 +52,6 @@ extern crate parity_util_mem; extern crate parking_lot; extern crate patricia_trie_ethereum as ethtrie; extern crate rand; -extern crate rand_065; extern crate rayon; extern crate reth_util; extern crate rlp; From 9412b9d5edc7a178902f3c2cd0b391a89fe703fe Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 7 Jan 2024 11:16:00 +0100 Subject: [PATCH 177/687] Using a version of hbbft without dependency on the poanetwork threshold_crypto version --- crates/ethcore/Cargo.toml | 4 ++-- .../src/engines/hbbft/hbbft_config_generator/Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index 519b17e5b..2423a6881 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -34,8 +34,8 @@ ethkey = { path = "../accounts/ethkey" } evm = { path = "../vm/evm" } globset = "0.4" hash-db = "0.11.0" -hbbft = { git = "https://github.com/dforsten/hbbft", rev = "d25315eb1c3a8313db9d99d5d9ba021e0d74a52e" } -hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "d25315eb1c3a8313db9d99d5d9ba021e0d74a52e" } +hbbft = { git = "https://github.com/dforsten/hbbft", rev = "6665031f796799a5287fcd95fcfd64d5e5a92113" } +hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "6665031f796799a5287fcd95fcfd64d5e5a92113" } hex_fmt = "0.3.0" itertools = "0.5" journaldb = { path = "../db/journaldb" } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml index 85d4788da..73cad8830 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml @@ -14,8 +14,8 @@ ethcore = { path = "../../../.." } ethereum-types = "0.9.2" ethkey = { path = "../../../../../accounts/ethkey" } ethstore = { path = "../../../../../accounts/ethstore"} -hbbft = { git = "https://github.com/dforsten/hbbft", rev = "d25315eb1c3a8313db9d99d5d9ba021e0d74a52e" } -hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "d25315eb1c3a8313db9d99d5d9ba021e0d74a52e" } +hbbft = { git = "https://github.com/dforsten/hbbft", rev = "6665031f796799a5287fcd95fcfd64d5e5a92113" } +hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "6665031f796799a5287fcd95fcfd64d5e5a92113" } parity-crypto = { version = "0.6.2", features = ["publickey"] } rand = "0.7.3" rustc-hex = "2.1.0" From a46040847d5ed26523ea6232d1ccf4fc1de8f626 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 7 Jan 2024 12:08:47 +0100 Subject: [PATCH 178/687] Using a version of hbbft less restrictive on the thiserror version used --- Cargo.lock | 183 +++++++----------- crates/ethcore/Cargo.toml | 4 +- .../hbbft/hbbft_config_generator/Cargo.toml | 4 +- 3 files changed, 73 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 729418842..f9ef996c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -754,17 +754,6 @@ dependencies = [ "winapi 0.3.8", ] -[[package]] -name = "derivative" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c6d883546668a3e2011b6a716a7330b82eabb0151b138217f632c8243e17135" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.26", -] - [[package]] name = "derivative" version = "2.2.0" @@ -1169,7 +1158,7 @@ dependencies = [ "fetch", "globset", "hash-db 0.11.0", - "hbbft 0.1.1 (git+https://github.com/surfingnerd/hbbft?rev=cf0c45aa669b9c10abab1a0f4f2b33595879b60b)", + "hbbft", "hbbft_testing", "hex-literal", "hex_fmt", @@ -1773,6 +1762,31 @@ dependencies = [ "url 2.1.0", ] +[[package]] +name = "ff" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4b967a3ee6ae993f0094174257d404a5818f58be79d67a1aea1ec8996d28906" +dependencies = [ + "byteorder", + "ff_derive", + "rand_core 0.5.1", +] + +[[package]] +name = "ff_derive" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3776aaf60a45037a9c3cabdd8542b38693acaa3e241ff957181b72579d29feb" +dependencies = [ + "num-bigint 0.2.3", + "num-integer", + "num-traits 0.2.15", + "proc-macro2 1.0.58", + "quote 1.0.27", + "syn 1.0.94", +] + [[package]] name = "fixed-hash" version = "0.4.0" @@ -1934,6 +1948,17 @@ dependencies = [ "regex", ] +[[package]] +name = "group" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f15be54742789e36f03307c8fdf0621201e1345e94f1387282024178b5e9ec8c" +dependencies = [ + "ff", + "rand 0.7.3", + "rand_xorshift 0.2.0", +] + [[package]] name = "h2" version = "0.1.26" @@ -2011,62 +2036,20 @@ dependencies = [ [[package]] name = "hbbft" version = "0.1.1" -source = "git+https://github.com/poanetwork/hbbft?rev=4857b7f9c7a0f513caca97c308d352c6a77fe5c2#4857b7f9c7a0f513caca97c308d352c6a77fe5c2" -dependencies = [ - "bincode", - "byteorder", - "derivative 1.0.4", - "env_logger 0.7.1", - "failure", - "hex_fmt", - "init_with", - "log", - "rand 0.6.5", - "rand_derive", - "reed-solomon-erasure 3.1.1", - "serde", - "threshold_crypto", - "tiny-keccak 2.0.2", -] - -[[package]] -name = "hbbft" -version = "0.1.1" -source = "git+https://github.com/surfingnerd/hbbft?rev=cf0c45aa669b9c10abab1a0f4f2b33595879b60b#cf0c45aa669b9c10abab1a0f4f2b33595879b60b" -dependencies = [ - "bincode", - "byteorder", - "derivative 2.2.0", - "env_logger 0.7.1", - "failure", - "hex_fmt", - "init_with", - "log", - "rand 0.6.5", - "rand_derive", - "reed-solomon-erasure 4.0.2", - "serde", - "threshold_crypto", - "tiny-keccak 2.0.2", -] - -[[package]] -name = "hbbft" -version = "0.1.1" -source = "git+https://github.com/poanetwork/hbbft#d52be00d0e3a1e2872c8d42a076e0dc3cb86b175" +source = "git+https://github.com/dforsten/hbbft?rev=f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd#f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" dependencies = [ "bincode", "byteorder", - "derivative 2.2.0", + "derivative", "env_logger 0.7.1", - "failure", "hex_fmt", "init_with", "log", - "rand 0.6.5", + "rand 0.7.3", "rand_derive", - "reed-solomon-erasure 4.0.2", + "reed-solomon-erasure", "serde", + "thiserror", "threshold_crypto", "tiny-keccak 2.0.2", ] @@ -2081,10 +2064,10 @@ dependencies = [ "ethereum-types 0.9.2", "ethkey", "ethstore", - "hbbft 0.1.1 (git+https://github.com/poanetwork/hbbft?rev=4857b7f9c7a0f513caca97c308d352c6a77fe5c2)", + "hbbft", "hbbft_testing", "parity-crypto", - "rand 0.6.5", + "rand 0.7.3", "rustc-hex 2.1.0", "serde", "serde_json", @@ -2094,14 +2077,14 @@ dependencies = [ [[package]] name = "hbbft_testing" version = "0.1.0" -source = "git+https://github.com/poanetwork/hbbft#d52be00d0e3a1e2872c8d42a076e0dc3cb86b175" +source = "git+https://github.com/dforsten/hbbft?rev=f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd#f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" dependencies = [ - "failure", - "hbbft 0.1.1 (git+https://github.com/poanetwork/hbbft)", + "hbbft", "integer-sqrt", "proptest", - "rand 0.6.5", - "rand_xorshift 0.1.1", + "rand 0.7.3", + "rand_xorshift 0.2.0", + "thiserror", "threshold_crypto", ] @@ -3217,12 +3200,14 @@ dependencies = [ [[package]] name = "pairing" -version = "0.14.2" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceda21136251c6d5a422d3d798d8ac22515a6e8d3521bb60c59a8349d36d0d57" +checksum = "b8290dea210a712682cd65031dc2b34fd132cf2729def3df7ee08f0737ff5ed6" dependencies = [ "byteorder", - "rand 0.4.6", + "ff", + "group", + "rand_core 0.5.1", ] [[package]] @@ -3882,9 +3867,9 @@ dependencies = [ [[package]] name = "proptest" -version = "0.9.6" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c477819b845fe023d33583ebf10c9f62518c8d79a0960ba5c36d6ac8a55a5b" +checksum = "12e6c80c1139113c28ee4670dc50cc42915228b51f56a9e407f0ec60f966646f" dependencies = [ "bit-set 0.5.2", "bitflags 1.2.1", @@ -3892,9 +3877,9 @@ dependencies = [ "lazy_static", "num-traits 0.2.15", "quick-error", - "rand 0.6.5", - "rand_chacha 0.1.1", - "rand_xorshift 0.1.1", + "rand 0.7.3", + "rand_chacha 0.2.1", + "rand_xorshift 0.2.0", "regex-syntax", "rusty-fork", "tempfile", @@ -4020,25 +4005,6 @@ dependencies = [ "rand_hc 0.2.0", ] -[[package]] -name = "rand04" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58595cc8bb12add45412667f9b422d5a9842d61d36e8607bc7c84ff738bf9263" -dependencies = [ - "rand 0.4.6", -] - -[[package]] -name = "rand04_compat" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cc0eb4bbb0cbc6c2a8081aa11303b9520369eea474cf865f7b7e3f11b284b" -dependencies = [ - "rand 0.6.5", - "rand04", -] - [[package]] name = "rand_chacha" version = "0.1.1" @@ -4250,18 +4216,6 @@ dependencies = [ "bitflags 1.2.1", ] -[[package]] -name = "reed-solomon-erasure" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77cbbd4c02f53e345fe49e74255a1b10080731ffb2a03475e11df7fc8a043c37" -dependencies = [ - "cc", - "libc", - "rayon", - "smallvec 0.6.14", -] - [[package]] name = "reed-solomon-erasure" version = "4.0.2" @@ -4465,9 +4419,9 @@ dependencies = [ [[package]] name = "rusty-fork" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dd93264e10c577503e926bd1430193eeb5d21b059148910082245309b424fae" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" dependencies = [ "fnv", "quick-error", @@ -4950,19 +4904,20 @@ dependencies = [ [[package]] name = "threshold_crypto" -version = "0.3.2" -source = "git+https://github.com/poanetwork/threshold_crypto?rev=624eeee#624eeee7e4ac5e565abbe93a31580a8f806ee5c4" +version = "0.4.0" +source = "git+https://github.com/dforsten/threshold_crypto?rev=776dd301a82036abf6fca60d574197e93e15810e#776dd301a82036abf6fca60d574197e93e15810e" dependencies = [ "byteorder", - "failure", + "ff", + "group", "hex_fmt", "log", "pairing", - "rand 0.6.5", - "rand04_compat", - "rand_chacha 0.1.1", + "rand 0.7.3", + "rand_chacha 0.2.1", "serde", - "tiny-keccak 1.5.0", + "thiserror", + "tiny-keccak 2.0.2", "zeroize", ] diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index 2423a6881..066131749 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -34,8 +34,8 @@ ethkey = { path = "../accounts/ethkey" } evm = { path = "../vm/evm" } globset = "0.4" hash-db = "0.11.0" -hbbft = { git = "https://github.com/dforsten/hbbft", rev = "6665031f796799a5287fcd95fcfd64d5e5a92113" } -hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "6665031f796799a5287fcd95fcfd64d5e5a92113" } +hbbft = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" } +hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" } hex_fmt = "0.3.0" itertools = "0.5" journaldb = { path = "../db/journaldb" } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml index 73cad8830..37de51a9d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml @@ -14,8 +14,8 @@ ethcore = { path = "../../../.." } ethereum-types = "0.9.2" ethkey = { path = "../../../../../accounts/ethkey" } ethstore = { path = "../../../../../accounts/ethstore"} -hbbft = { git = "https://github.com/dforsten/hbbft", rev = "6665031f796799a5287fcd95fcfd64d5e5a92113" } -hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "6665031f796799a5287fcd95fcfd64d5e5a92113" } +hbbft = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" } +hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" } parity-crypto = { version = "0.6.2", features = ["publickey"] } rand = "0.7.3" rustc-hex = "2.1.0" From be99f6ff0906304109b6c4bbab91e55b47727be8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 12 Jan 2024 13:13:09 +0100 Subject: [PATCH 179/687] using "is_connectivity_loss_reported", instead of watching "flagged validators" --- .../contracts/connectivity_tracker_hbbft.rs | 22 ++++ .../hbbft/hbbft_early_epoch_end_manager.rs | 117 +++++++++++++----- 2 files changed, 108 insertions(+), 31 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index b379caf30..c7123dc21 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -24,6 +24,28 @@ macro_rules! call_const_connectivity_tracker_hbbft { }; } +pub fn is_connectivity_loss_reported( + client: &dyn EngineClient, + block_id: BlockId, + reporter: &Address, + epoch: u64, + validator: &Address, +) -> Result { + let c = BoundContract::bind( + client, + block_id, + *CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, + ); + return Ok(call_const_connectivity_tracker_hbbft!( + c, + is_reported, + epoch, + *validator, + *reporter + )?); +} + + pub fn get_current_flagged_validators_from_contract( client: &dyn EngineClient, block_id: BlockId, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 040b3bf4e..70b29f6c9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -14,7 +14,7 @@ use std::{ use super::{ contracts::connectivity_tracker_hbbft::{ - get_current_flagged_validators_from_contract, report_reconnect, + report_reconnect, is_connectivity_loss_reported, }, hbbft_message_memorium::HbbftMessageMemorium, NodeId, @@ -94,17 +94,22 @@ impl HbbftEarlyEpochEndManager { // we do not have to retrieve the data from the smart contracts. let now = Instant::now(); + let flagged_validators = Self::get_current_reported_validators_from_contracts( + engine_client, + BlockId::Latest, + &node_id_to_address, + &validators, + signing_address, + epoch_number, + ); + let result = Self { current_tracked_epoch_number: epoch_number, start_time: now, start_block: epoch_start_block, allowed_devp2p_warmup_time, validators: validators, - flagged_validators: Self::get_current_flagged_validators_from_contracts( - engine_client, - BlockId::Latest, - &address_to_node_id, - ), + flagged_validators: flagged_validators, node_id_to_address, address_to_node_id, signing_address: signing_address.clone(), @@ -116,33 +121,60 @@ impl HbbftEarlyEpochEndManager { } /// retrieves the information from smart contracts which validators are currently flagged. - fn get_current_flagged_validators_from_contracts( + fn get_current_reported_validators_from_contracts( client: &dyn EngineClient, block_id: BlockId, - address_to_node_id: &BTreeMap, + node_id_to_address: &BTreeMap, + validators: &Vec, + signing_address: &Address, + epoch: u64, ) -> Vec { - // todo: call smart contract. - match get_current_flagged_validators_from_contract(client, block_id) { - Ok(v) => { - let mut result: Vec = Vec::new(); + let mut result = Vec::::new(); - for a in v.iter() { - if let Some(node_id) = address_to_node_id.get(a) { - result.push(node_id.clone()); - } else { - error!(target: "engine","early-epoch-end: could not find validator in address cache: {a:?}"); - } - } + for validator in validators.iter() { - return result; - // address_to_node_id.get(key) - } - Err(e) => { - error!(target: "engine","early-epoch-end: could not get_current_flagged_validators_from_contracts {e:?}" ); - Vec::new() + let validator_address = if let Some(a) = node_id_to_address.get(validator) { + a + } else { + error!(target: "engine", "early-epoch-end: could not find address for validator in node_id_to_address cache."); + continue; + }; + + if let Ok(reported) = is_connectivity_loss_reported(client, block_id, signing_address, epoch, validator_address) { + if reported { + result.push(validator.clone()); + } + } else { + error!(target: "engine", "early-epoch-end: could not get reported status for validator {validator:?}"); } } + + return result; + // match is_connectivity_loss_reported(client, block_id, signing_address, ) { + + // } + + // match get_current_flagged_validators_from_contract(client, block_id) { + // Ok(v) => { + // let mut result: Vec = Vec::new(); + + // for a in v.iter() { + // if let Some(node_id) = address_to_node_id.get(a) { + // result.push(node_id.clone()); + // } else { + // error!(target: "engine","early-epoch-end: could not find validator in address cache: {a:?}"); + // } + // } + + // return result; + // // address_to_node_id.get(key) + // } + // Err(e) => { + // error!(target: "engine","early-epoch-end: could not get_current_flagged_validators_from_contracts {e:?}" ); + // Vec::new() + // } + // } } fn notify_about_missing_validator( @@ -195,6 +227,18 @@ impl HbbftEarlyEpochEndManager { } } + pub fn is_reported(&self, client: &dyn EngineClient, other_validator_address: &Address) -> bool { + + let result = is_connectivity_loss_reported(client, BlockId::Latest, &self.signing_address, self.current_tracked_epoch_number, other_validator_address); + + if let Ok(r) = result { + return r; + } else { + error!(target: "engine", "early-epoch-end: could not get reported status for validator {other_validator_address:?}"); + return false; + } + } + /// decides on the memorium data if we should update to contract data. /// end executes them. pub fn decide( @@ -243,31 +287,42 @@ impl HbbftEarlyEpochEndManager { // get current state of missing validators from hbbftMemorium. if let Some(epoch_history) = memorium.get_staking_epoch_history(block_num) { for validator in &self.validators.clone() { - // we need to exclude ourself. + let validator_address = match self.node_id_to_address.get(validator) { + Some(a) => a, + None => { + error!(target: "engine", "early-epoch-end: could not find validator_address for node id in cache: {validator:?}"); + continue; + } + }; + if let Some(node_history) = epoch_history.get_history_for_node(validator) { let last_sealing_message = node_history.get_sealing_message(); if last_sealing_message < block_num - treshold { // we do not have to send notification, if we already did so. - if !self.flagged_validators.contains(validator) { + + if !self.is_reported(client, validator_address) { // this function will also add the validator to the list of flagged validators. self.notify_about_missing_validator(&validator, client, full_client); } + } else { // this validator is OK. // maybe it was flagged and we need to unflag it ? - if self.flagged_validators.contains(validator) { + + + if self.is_reported(client, validator_address) { self.notify_about_validator_reconnect(&validator, full_client, client); } } } else { + debug!(target: "engine", "early-epoch-end: no history info for validator {validator}"); - let current_flagged = Self::get_current_flagged_validators_from_contracts(client, BlockId::Latest, &self.address_to_node_id); // we do not have any history for this node. - if !current_flagged.contains(validator) { + if !self.is_reported(client, validator_address) { // this function will also add the validator to the list of flagged validators. self.notify_about_missing_validator(&validator, client, full_client); } @@ -275,7 +330,7 @@ impl HbbftEarlyEpochEndManager { // todo: if the systems switched from block based measurement to time based measurement. } } - // nothing to do: no history yet. + // else: nothing to do: no history yet. // note: We do not take care if hbbft message memorium might not have processed some of the messages yet, // since it is not important to do the decision based on the latest data, since the decide method will be called From c07ead77c9eadc2f102f2030fcb17164ea39ebf1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 12 Jan 2024 23:22:48 +0100 Subject: [PATCH 180/687] contract abi change: hbbft_connectivity_tracker: isReported --- .../contracts/hbbft_connectivity_tracker.json | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json b/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json index 65e1dbbf3..c67daf202 100644 --- a/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json +++ b/crates/ethcore/res/contracts/hbbft_connectivity_tracker.json @@ -180,5 +180,34 @@ ], "stateMutability": "view", "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "epoch", + "type": "uint256" + }, + { + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "internalType": "address", + "name": "reporter", + "type": "address" + } + ], + "name": "isReported", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" } ] \ No newline at end of file From a3eca051db5cc20f34f28d51ff7227b04a5a0196 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 12 Jan 2024 23:24:01 +0100 Subject: [PATCH 181/687] connectivity tracker: get_block_data() now retrieves the previous block number and hash to avoid timing issues with txPermission contract validations on import own_tx into the transaction queue --- .../engines/hbbft/contracts/connectivity_tracker_hbbft.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index c7123dc21..8b3e7e5ba 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -63,9 +63,8 @@ pub fn get_current_flagged_validators_from_contract( fn get_block_data(client: &dyn EngineClient) -> (u64, H256) { if let Some(block_number) = client.block_number(BlockId::Latest) { - if let Some(header) = client.block_header(BlockId::Number(block_number)) { - let hash = header.hash(); - return (block_number, hash); + if let Some(header) = client.block_header(BlockId::Number(block_number - 1)) { + return (header.number(), header.hash()); } else { warn!(target:"engine", "early-epoch-end: could not get block number for block: {block_number}"); return (0, H256::zero()); From 95ed607f4ae65e18763b6e34805289590a2301b5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 13 Jan 2024 10:32:33 +0100 Subject: [PATCH 182/687] hbbft config generator: hints for more detailed logs --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 5c1895b52..305c20897 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -239,6 +239,9 @@ fn to_toml( } let mut misc = Map::new(); + + // example for a more verbose logging. + // Value::String("txqueue=trace,consensus=debug,engine=trace,own_tx=trace,miner=trace,tx_filter=trace".into()) misc.insert( "logging".into(), Value::String("txqueue=info,consensus=debug,engine=trace,tx_own=trace".into()), From b3d21363cc111b9950bde11acf59e2b8894dade8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 2 Feb 2024 19:23:49 +0100 Subject: [PATCH 183/687] fork manager: further drafts for creating the fork. --- .../hbbft/hbbft_network_fork_manager.rs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs new file mode 100644 index 000000000..1ec795af4 --- /dev/null +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -0,0 +1,48 @@ +use std::collections::VecDeque; + +use ethereum_types::Address; + + +struct HbbftFork { + start_timestamp: u64, + start_block: u64, + is_finished: bool, + end_timestamp: u64, + end_block: u64, + validator_set: Vec
, +} + + +/// Hbbft network fork manager. +/// This manager is responsible for managing the forks. +/// It allows cheap queries to see if a Fork is pending, +/// and stores information about a fork that is finished. +pub struct HbbftNetworkForkManager { + + /// If a fork is currently in progress, this is true. + is_currently_forking: bool, + + /// a ordered list with upcomming forks. + finished_forks: VecDeque, + + /// a ordered list with upcomming forks, including a fork that is in progress. + /// see @is_currently_forking for more information. + pending_forks: VecDeque, +} + + +impl HbbftNetworkForkManager { + + + + /// Returns None if not forking + /// Returns a List of Addresses that become the new validator set and + /// declares the fork as active, + pub fn should_fork(&mut self,last_block_number: u64, last_block_time_stamp: u64) -> Option> { + // fields omitted + + + None + } + +} \ No newline at end of file From afa8bae4a4f79464f4e221f500a77b1bcf42df7d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 3 Feb 2024 23:27:46 +0100 Subject: [PATCH 184/687] module hbbft fork manager --- crates/ethcore/src/engines/hbbft/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/mod.rs b/crates/ethcore/src/engines/hbbft/mod.rs index 39ddaf09d..25883f6ba 100644 --- a/crates/ethcore/src/engines/hbbft/mod.rs +++ b/crates/ethcore/src/engines/hbbft/mod.rs @@ -3,6 +3,7 @@ mod contracts; mod contribution; mod hbbft_early_epoch_end_manager; mod hbbft_engine; +mod hbbft_network_fork_manager; mod hbbft_message_memorium; mod hbbft_peers_management; mod hbbft_state; @@ -17,6 +18,7 @@ pub use self::hbbft_engine::HoneyBadgerBFT; use crypto::publickey::Public; use std::fmt; + #[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)] pub struct NodeId(pub Public); From 761ef3b3ad87142f59ef09f0690bb50720ca317c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 4 Feb 2024 23:51:41 +0100 Subject: [PATCH 185/687] fork params --- crates/ethjson/src/spec/hbbft.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index 10c6a88e7..cd033917d 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -32,6 +32,21 @@ pub struct HbbftParamsSkipBlockReward { pub to_block: Option, } +#[derive(Debug, PartialEq, Deserialize)] +#[serde(deny_unknown_fields)] +#[serde(rename_all = "camelCase")] +pub struct HbbftNetworkForks { + + +} + +pub struct HbbftNetworkFork { + /// Block number at which the fork starts. + pub block_number_start: u64, + /// Validator set at the fork. + pub validator_set: Vec
, +} + /// Hbbft parameters. #[derive(Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] @@ -54,6 +69,12 @@ pub struct HbbftParams { /// Directory where to store the Hbbft Messages. /// Usually only the latest HBBFT messages are interesting for Debug, Analytics or Evidence. pub blocks_to_keep_directory: Option, + /// Hbbft network forks. + /// A Fork defines a new Validator Set. + /// This validator set is becomming pending so it can write it's PARTs and ACKS. + /// From beginning of the fork trigger block until the finality of the key gen transactions, + /// no block verifications are done. + pub forks: HbbftNetworkForks, } /// Hbbft engine config. From af0176f2563287706f858d53134e3221b2ab75e5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 5 Feb 2024 23:52:57 +0100 Subject: [PATCH 186/687] concept for initiating fork with multiple nodes --- .../src/engines/hbbft/hbbft_network_fork_manager.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 1ec795af4..9f12d7a6a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -1,7 +1,14 @@ use std::collections::VecDeque; use ethereum_types::Address; +use hbbft::sync_key_gen::Ack; +use hbbft::sync_key_gen::Part; +struct HbbftForkKeys { + validators: Vec
, + parts: Vec, + acks: Vec, +} struct HbbftFork { start_timestamp: u64, @@ -9,7 +16,7 @@ struct HbbftFork { is_finished: bool, end_timestamp: u64, end_block: u64, - validator_set: Vec
, + validator_set: HbbftForkKeys, } From 8c84383269cf6d7c586d6008f4d9dd6597a26239 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 Feb 2024 22:55:25 +0100 Subject: [PATCH 187/687] serde_with for upcomming PART and ACKS support in the spec.json --- Cargo.lock | 308 +++++++++++++++++++++++++++++++++----- crates/ethjson/Cargo.toml | 1 + 2 files changed, 275 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9ef996c4..4ed683e86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,6 +194,12 @@ dependencies = [ "byteorder", ] +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "beef" version = "0.5.1" @@ -343,6 +349,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + [[package]] name = "byte-slice-cast" version = "0.3.5" @@ -415,14 +427,17 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.9" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" +checksum = "6127248204b9aba09a362f6c930ef6a78f2c1b2215f8a7b398c06e1083f17af0" dependencies = [ - "libc", + "js-sys", "num-integer", "num-traits 0.2.15", - "time", + "serde", + "time 0.1.45", + "wasm-bindgen", + "winapi 0.3.8", ] [[package]] @@ -711,7 +726,7 @@ checksum = "37519ccdfd73a75821cac9319d4fce15a81b9fcf75f951df5b9988aa3a0af87d" dependencies = [ "bstr", "csv-core", - "itoa", + "itoa 0.4.4", "ryu", "serde", ] @@ -754,6 +769,50 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "darling" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2 1.0.58", + "quote 1.0.27", + "strsim 0.10.0", + "syn 2.0.16", +] + +[[package]] +name = "darling_macro" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" +dependencies = [ + "darling_core", + "quote 1.0.27", + "syn 2.0.16", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "serde", +] + [[package]] name = "derivative" version = "2.2.0" @@ -921,7 +980,7 @@ version = "0.1.0" dependencies = [ "ethabi 12.0.0", "ethereum-types 0.9.2", - "indexmap", + "indexmap 1.9.3", "itertools 0.7.11", "keccak-hash", "lazy_static", @@ -986,6 +1045,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "error-chain" version = "0.12.1" @@ -1330,7 +1395,7 @@ dependencies = [ "num_cpus", "parking_lot 0.11.1", "slab 0.4.2", - "time", + "time 0.1.45", "timer", "tokio", ] @@ -1347,7 +1412,7 @@ dependencies = [ "log", "parking_lot 0.11.1", "regex", - "time", + "time 0.1.45", ] [[package]] @@ -1571,6 +1636,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", + "serde_with", ] [[package]] @@ -1630,7 +1696,7 @@ dependencies = [ "serde_json", "smallvec 0.6.14", "tempdir", - "time", + "time 0.1.45", ] [[package]] @@ -1835,9 +1901,9 @@ checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" [[package]] name = "fnv" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fs-swap" @@ -1926,7 +1992,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi 0.10.0+wasi-snapshot-preview1", ] [[package]] @@ -1970,7 +2036,7 @@ dependencies = [ "fnv", "futures", "http", - "indexmap", + "indexmap 1.9.3", "log", "slab 0.4.2", "string", @@ -2033,6 +2099,18 @@ dependencies = [ "autocfg 1.0.0", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + [[package]] name = "hbbft" version = "0.1.1" @@ -2184,7 +2262,7 @@ checksum = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0" dependencies = [ "bytes", "fnv", - "itoa", + "itoa 0.4.4", ] [[package]] @@ -2228,11 +2306,11 @@ dependencies = [ "http-body", "httparse", "iovec", - "itoa", + "itoa 0.4.4", "log", "net2", "rustc_version", - "time", + "time 0.1.45", "tokio", "tokio-buf", "tokio-executor", @@ -2261,6 +2339,12 @@ dependencies = [ "webpki-roots", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.1.5" @@ -2350,11 +2434,24 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.3.0" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ - "autocfg 0.1.7", + "autocfg 1.0.0", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", + "serde", ] [[package]] @@ -2444,6 +2541,12 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + [[package]] name = "journaldb" version = "0.2.0" @@ -2465,6 +2568,15 @@ dependencies = [ "rlp", ] +[[package]] +name = "js-sys" +version = "0.3.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "jsonrpc-core" version = "15.0.0" @@ -3704,7 +3816,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" dependencies = [ "fixedbitset", - "indexmap", + "indexmap 1.9.3", ] [[package]] @@ -4522,31 +4634,31 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.144" +version = "1.0.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" +checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.144" +version = "1.0.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" +checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" dependencies = [ "proc-macro2 1.0.58", "quote 1.0.27", - "syn 1.0.94", + "syn 2.0.16", ] [[package]] name = "serde_json" -version = "1.0.41" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2" +checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" dependencies = [ - "itoa", + "itoa 1.0.10", "ryu", "serde", ] @@ -4562,6 +4674,35 @@ dependencies = [ "syn 1.0.94", ] +[[package]] +name = "serde_with" +version = "3.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b0ed1662c5a68664f45b76d18deb0e234aff37207086803165c961eb695e981" +dependencies = [ + "base64 0.21.7", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.2.2", + "serde", + "serde_json", + "serde_with_macros", + "time 0.3.26", +] + +[[package]] +name = "serde_with_macros" +version = "3.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "568577ff0ef47b879f736cd66740e022f3672788cdf002a05a4e609ea5a6fb15" +dependencies = [ + "darling", + "proc-macro2 1.0.58", + "quote 1.0.27", + "syn 2.0.16", +] + [[package]] name = "sha-1" version = "0.8.1" @@ -4719,6 +4860,12 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "032c03039aae92b350aad2e3779c352e104d919cb192ba2fabbd7b831ce4f0f6" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "1.0.0" @@ -4764,6 +4911,17 @@ dependencies = [ "unicode-xid 0.2.0", ] +[[package]] +name = "syn" +version = "2.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" +dependencies = [ + "proc-macro2 1.0.58", + "quote 1.0.27", + "unicode-ident", +] + [[package]] name = "synom" version = "0.11.3" @@ -4923,15 +5081,43 @@ dependencies = [ [[package]] name = "time" -version = "0.1.42" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", - "redox_syscall 0.1.56", + "wasi 0.10.0+wasi-snapshot-preview1", "winapi 0.3.8", ] +[[package]] +name = "time" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a79d09ac6b08c1ab3906a2f7cc2e81a0e27c7ae89c63812df75e52bef0751e07" +dependencies = [ + "deranged", + "itoa 1.0.10", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" + +[[package]] +name = "time-macros" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75c65469ed6b3a4809d987a41eb1dc918e9bc1d92211cbad7ae82931846f7451" +dependencies = [ + "time-core", +] + [[package]] name = "time-utils" version = "0.1.0" @@ -5466,7 +5652,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3365f36c57e5df714a34be40902b27a992eeddb9996eca52d0584611cf885d" dependencies = [ "bitflags 0.7.0", - "time", + "time 0.1.45", ] [[package]] @@ -5526,9 +5712,9 @@ checksum = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm" @@ -5545,6 +5731,60 @@ dependencies = [ "wasmi", ] +[[package]] +name = "wasm-bindgen" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2 1.0.58", + "quote 1.0.27", + "syn 1.0.94", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +dependencies = [ + "quote 1.0.27", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +dependencies = [ + "proc-macro2 1.0.58", + "quote 1.0.27", + "syn 1.0.94", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" + [[package]] name = "wasmi" version = "0.3.0" diff --git a/crates/ethjson/Cargo.toml b/crates/ethjson/Cargo.toml index 436bfef02..b0d321fe0 100644 --- a/crates/ethjson/Cargo.toml +++ b/crates/ethjson/Cargo.toml @@ -16,6 +16,7 @@ rustc-hex = "1.0" serde = "1.0" serde_json = "1.0" serde_derive = "1.0" +serde_with = { version = "3.6", features = [ "hex", "std", "macros" ] } [dev-dependencies] macros = { path = "../util/macros" } From 2698fb703374d8bb3e7debc70bee3b250ce5f3aa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 Feb 2024 22:55:47 +0100 Subject: [PATCH 188/687] first working version with ACKS and PARTS from the spec file --- crates/ethjson/src/spec/hbbft.rs | 68 ++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index cd033917d..3c7b9babf 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -17,6 +17,7 @@ //! Hbbft parameter deserialization. use ethereum_types::Address; +use serde_with::serde_as; /// Skip block reward parameter. /// Defines one (potential open) range about skips @@ -32,21 +33,23 @@ pub struct HbbftParamsSkipBlockReward { pub to_block: Option, } +#[serde_as] #[derive(Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] -pub struct HbbftNetworkForks { - - -} - pub struct HbbftNetworkFork { /// Block number at which the fork starts. pub block_number_start: u64, /// Validator set at the fork. - pub validator_set: Vec
, + + pub validators: Vec
, + #[serde_as(as = "serde_with::hex::Hex")] + pub parts: Vec, + #[serde_as(as = "serde_with::hex::Hex")] + pub acks: Vec, } + /// Hbbft parameters. #[derive(Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] @@ -74,7 +77,8 @@ pub struct HbbftParams { /// This validator set is becomming pending so it can write it's PARTs and ACKS. /// From beginning of the fork trigger block until the finality of the key gen transactions, /// no block verifications are done. - pub forks: HbbftNetworkForks, + #[serde(default)] + pub forks: Vec, } /// Hbbft engine config. @@ -113,6 +117,56 @@ mod tests { use ethereum_types::Address; use std::str::FromStr; + #[test] + fn hbbft_deserialization_forks() { + // let s = r#"{ + // "params": { + // "forks": { + // { + // "blockNumberStart" : 777, + // "validators": [ + // "0xfe163fc225f3863cef09f1f68ead173f30300d13" + // ], + // "parts": [ + // "0x19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9" + // ], + // "acks": [ + // "0x19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9" + // ] + // } + // } + // } + // }"#; + + let s = r#"{ + "params": { + "minimumBlockTime": 0, + "maximumBlockTime": 600, + "transactionQueueSizeTrigger": 1, + "isUnitTest": true, + "blockRewardContractAddress": "0x2000000000000000000000000000000000000002", + "forks": [ + { + "blockNumberStart" : 777, + "validators": [ + "0xfe163fc225f3863cef09f1f68ead173f30300d13" + ], + "parts": "19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9", + "acks": "19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9" + } + ] + } + }"#; + + let deserialized: Hbbft = serde_json::from_str(s).unwrap(); + assert_eq!(deserialized.params.forks.len() , 1); + assert_eq!(deserialized.params.forks.get(0).expect("").block_number_start , 777); + assert_eq!(deserialized.params.forks.get(0).expect("").parts.len() , 64); + assert_eq!(deserialized.params.forks.get(0).expect("").acks.len() , 64); + + + } + #[test] fn hbbft_deserialization() { let s = r#"{ From 1b82825bea04c78246961bd32b9e93af765f7f4f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Feb 2024 10:05:51 +0100 Subject: [PATCH 189/687] spec: support for multiple parts&acks --- crates/ethjson/src/spec/hbbft.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index 3c7b9babf..8d1ab76f2 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -43,10 +43,10 @@ pub struct HbbftNetworkFork { /// Validator set at the fork. pub validators: Vec
, - #[serde_as(as = "serde_with::hex::Hex")] - pub parts: Vec, - #[serde_as(as = "serde_with::hex::Hex")] - pub acks: Vec, + #[serde_as(as = "Vec")] + pub parts: Vec>, + #[serde_as(as = "Vec")] + pub acks: Vec>, } @@ -151,8 +151,8 @@ mod tests { "validators": [ "0xfe163fc225f3863cef09f1f68ead173f30300d13" ], - "parts": "19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9", - "acks": "19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9" + "parts": ["19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"], + "acks": ["19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"] } ] } @@ -161,8 +161,8 @@ mod tests { let deserialized: Hbbft = serde_json::from_str(s).unwrap(); assert_eq!(deserialized.params.forks.len() , 1); assert_eq!(deserialized.params.forks.get(0).expect("").block_number_start , 777); - assert_eq!(deserialized.params.forks.get(0).expect("").parts.len() , 64); - assert_eq!(deserialized.params.forks.get(0).expect("").acks.len() , 64); + assert_eq!(deserialized.params.forks.get(0).expect("").parts.len() , 1); + assert_eq!(deserialized.params.forks.get(0).expect("").acks.len() , 1); } From a7fb83ed81241ee511bc8521c2610ca5081ebf43 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Feb 2024 10:22:03 +0100 Subject: [PATCH 190/687] cargo fmt --all -- --config imports_granularity=Crate --- .../contracts/connectivity_tracker_hbbft.rs | 1 - .../hbbft/hbbft_config_generator/src/main.rs | 2 +- .../hbbft/hbbft_early_epoch_end_manager.rs | 37 +++++++++++-------- .../hbbft/hbbft_network_fork_manager.rs | 21 ++++------- crates/ethcore/src/engines/hbbft/mod.rs | 3 +- crates/ethjson/src/spec/hbbft.rs | 30 ++++++++------- 6 files changed, 48 insertions(+), 46 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index 8b3e7e5ba..b99958f17 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -45,7 +45,6 @@ pub fn is_connectivity_loss_reported( )?); } - pub fn get_current_flagged_validators_from_contract( client: &dyn EngineClient, block_id: BlockId, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 305c20897..4eaf58315 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -239,7 +239,7 @@ fn to_toml( } let mut misc = Map::new(); - + // example for a more verbose logging. // Value::String("txqueue=trace,consensus=debug,engine=trace,own_tx=trace,miner=trace,tx_filter=trace".into()) misc.insert( diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 70b29f6c9..5646fa578 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -13,9 +13,7 @@ use std::{ }; use super::{ - contracts::connectivity_tracker_hbbft::{ - report_reconnect, is_connectivity_loss_reported, - }, + contracts::connectivity_tracker_hbbft::{is_connectivity_loss_reported, report_reconnect}, hbbft_message_memorium::HbbftMessageMemorium, NodeId, }; @@ -129,11 +127,9 @@ impl HbbftEarlyEpochEndManager { signing_address: &Address, epoch: u64, ) -> Vec { - let mut result = Vec::::new(); for validator in validators.iter() { - let validator_address = if let Some(a) = node_id_to_address.get(validator) { a } else { @@ -141,7 +137,13 @@ impl HbbftEarlyEpochEndManager { continue; }; - if let Ok(reported) = is_connectivity_loss_reported(client, block_id, signing_address, epoch, validator_address) { + if let Ok(reported) = is_connectivity_loss_reported( + client, + block_id, + signing_address, + epoch, + validator_address, + ) { if reported { result.push(validator.clone()); } @@ -227,9 +229,18 @@ impl HbbftEarlyEpochEndManager { } } - pub fn is_reported(&self, client: &dyn EngineClient, other_validator_address: &Address) -> bool { - - let result = is_connectivity_loss_reported(client, BlockId::Latest, &self.signing_address, self.current_tracked_epoch_number, other_validator_address); + pub fn is_reported( + &self, + client: &dyn EngineClient, + other_validator_address: &Address, + ) -> bool { + let result = is_connectivity_loss_reported( + client, + BlockId::Latest, + &self.signing_address, + self.current_tracked_epoch_number, + other_validator_address, + ); if let Ok(r) = result { return r; @@ -259,7 +270,6 @@ impl HbbftEarlyEpochEndManager { return; } - if full_client.is_syncing() { // if we are syncing, we wont do any blaming. debug!(target: "engine", "early-epoch-end: detected attempt to break because of is_major_syncing() instead of is_synincg()no decision: syncing"); @@ -294,7 +304,7 @@ impl HbbftEarlyEpochEndManager { continue; } }; - + if let Some(node_history) = epoch_history.get_history_for_node(validator) { let last_sealing_message = node_history.get_sealing_message(); @@ -305,22 +315,17 @@ impl HbbftEarlyEpochEndManager { // this function will also add the validator to the list of flagged validators. self.notify_about_missing_validator(&validator, client, full_client); } - } else { // this validator is OK. // maybe it was flagged and we need to unflag it ? - - if self.is_reported(client, validator_address) { self.notify_about_validator_reconnect(&validator, full_client, client); } } } else { - debug!(target: "engine", "early-epoch-end: no history info for validator {validator}"); - // we do not have any history for this node. if !self.is_reported(client, validator_address) { // this function will also add the validator to the list of flagged validators. diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 9f12d7a6a..d0546c9d7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -1,8 +1,7 @@ use std::collections::VecDeque; use ethereum_types::Address; -use hbbft::sync_key_gen::Ack; -use hbbft::sync_key_gen::Part; +use hbbft::sync_key_gen::{Ack, Part}; struct HbbftForkKeys { validators: Vec
, @@ -19,13 +18,11 @@ struct HbbftFork { validator_set: HbbftForkKeys, } - /// Hbbft network fork manager. /// This manager is responsible for managing the forks. /// It allows cheap queries to see if a Fork is pending, /// and stores information about a fork that is finished. pub struct HbbftNetworkForkManager { - /// If a fork is currently in progress, this is true. is_currently_forking: bool, @@ -37,19 +34,17 @@ pub struct HbbftNetworkForkManager { pending_forks: VecDeque, } - impl HbbftNetworkForkManager { - - - /// Returns None if not forking /// Returns a List of Addresses that become the new validator set and - /// declares the fork as active, - pub fn should_fork(&mut self,last_block_number: u64, last_block_time_stamp: u64) -> Option> { + /// declares the fork as active, + pub fn should_fork( + &mut self, + last_block_number: u64, + last_block_time_stamp: u64, + ) -> Option> { // fields omitted - None } - -} \ No newline at end of file +} diff --git a/crates/ethcore/src/engines/hbbft/mod.rs b/crates/ethcore/src/engines/hbbft/mod.rs index 25883f6ba..c181acc02 100644 --- a/crates/ethcore/src/engines/hbbft/mod.rs +++ b/crates/ethcore/src/engines/hbbft/mod.rs @@ -3,8 +3,8 @@ mod contracts; mod contribution; mod hbbft_early_epoch_end_manager; mod hbbft_engine; -mod hbbft_network_fork_manager; mod hbbft_message_memorium; +mod hbbft_network_fork_manager; mod hbbft_peers_management; mod hbbft_state; mod keygen_transactions; @@ -18,7 +18,6 @@ pub use self::hbbft_engine::HoneyBadgerBFT; use crypto::publickey::Public; use std::fmt; - #[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)] pub struct NodeId(pub Public); diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index 8d1ab76f2..25b01ebaa 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -41,15 +41,13 @@ pub struct HbbftNetworkFork { /// Block number at which the fork starts. pub block_number_start: u64, /// Validator set at the fork. - pub validators: Vec
, #[serde_as(as = "Vec")] pub parts: Vec>, #[serde_as(as = "Vec")] - pub acks: Vec>, + pub acks: Vec>, } - /// Hbbft parameters. #[derive(Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] @@ -120,8 +118,8 @@ mod tests { #[test] fn hbbft_deserialization_forks() { // let s = r#"{ - // "params": { - // "forks": { + // "params": { + // "forks": { // { // "blockNumberStart" : 777, // "validators": [ @@ -135,8 +133,8 @@ mod tests { // ] // } // } - // } - // }"#; + // } + // }"#; let s = r#"{ "params": { @@ -159,12 +157,18 @@ mod tests { }"#; let deserialized: Hbbft = serde_json::from_str(s).unwrap(); - assert_eq!(deserialized.params.forks.len() , 1); - assert_eq!(deserialized.params.forks.get(0).expect("").block_number_start , 777); - assert_eq!(deserialized.params.forks.get(0).expect("").parts.len() , 1); - assert_eq!(deserialized.params.forks.get(0).expect("").acks.len() , 1); - - + assert_eq!(deserialized.params.forks.len(), 1); + assert_eq!( + deserialized + .params + .forks + .get(0) + .expect("") + .block_number_start, + 777 + ); + assert_eq!(deserialized.params.forks.get(0).expect("").parts.len(), 1); + assert_eq!(deserialized.params.forks.get(0).expect("").acks.len(), 1); } #[test] From 4185a62e3a3f49218b8024cc2855cae1e461fa22 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Feb 2024 13:15:00 +0100 Subject: [PATCH 191/687] code cleanup for fork config tests --- crates/ethjson/src/spec/hbbft.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index 25b01ebaa..e0762ee77 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -117,24 +117,6 @@ mod tests { #[test] fn hbbft_deserialization_forks() { - // let s = r#"{ - // "params": { - // "forks": { - // { - // "blockNumberStart" : 777, - // "validators": [ - // "0xfe163fc225f3863cef09f1f68ead173f30300d13" - // ], - // "parts": [ - // "0x19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9" - // ], - // "acks": [ - // "0x19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9" - // ] - // } - // } - // } - // }"#; let s = r#"{ "params": { From 8edba46f64fc900bb68fc7a7893b2caf76ec6365 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Feb 2024 13:56:59 +0100 Subject: [PATCH 192/687] including block number end, to define the block of the epoch change when the regular validator set took over. --- crates/ethjson/src/spec/hbbft.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index e0762ee77..19f9521bb 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -40,6 +40,11 @@ pub struct HbbftParamsSkipBlockReward { pub struct HbbftNetworkFork { /// Block number at which the fork starts. pub block_number_start: u64, + + /// Forks that became finished, require a definition when the take over of the + /// specified validators was finished. + #[serde(default)] + pub block_number_end: Option, /// Validator set at the fork. pub validators: Vec
, #[serde_as(as = "Vec")] From 6a237901c73cbfcdeb0cfe54d955c650035b77a8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Feb 2024 17:52:25 +0100 Subject: [PATCH 193/687] HbbftNetworkFork: Clone --- crates/ethjson/src/spec/hbbft.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index 19f9521bb..09209c03e 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -34,21 +34,24 @@ pub struct HbbftParamsSkipBlockReward { } #[serde_as] -#[derive(Debug, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize, Clone)] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] pub struct HbbftNetworkFork { /// Block number at which the fork starts. pub block_number_start: u64, - /// Forks that became finished, require a definition when the take over of the + /// Forks that became finished, require a definition when the take over of the /// specified validators was finished. #[serde(default)] pub block_number_end: Option, + /// Validator set at the fork. pub validators: Vec
, + #[serde_as(as = "Vec")] pub parts: Vec>, + #[serde_as(as = "Vec")] pub acks: Vec>, } @@ -122,7 +125,6 @@ mod tests { #[test] fn hbbft_deserialization_forks() { - let s = r#"{ "params": { "minimumBlockTime": 0, From 272763aa69aee6a82da55620396295645cf7d788 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Feb 2024 17:52:54 +0100 Subject: [PATCH 194/687] fork manager: initialization --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 11 ++ .../hbbft/hbbft_network_fork_manager.rs | 117 ++++++++++++++++-- 2 files changed, 120 insertions(+), 8 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index af4d91d42..885a0a0f9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1,6 +1,7 @@ use super::{ block_reward_hbbft::BlockRewardContract, hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, + hbbft_network_fork_manager::HbbftNetworkForkManager, }; use crate::{ client::BlockChainClient, @@ -92,6 +93,7 @@ pub struct HoneyBadgerBFT { peers_management: Mutex, current_minimum_gas_price: Mutex>, early_epoch_manager: Mutex>, + fork_manager: Mutex, } struct TransitionHandler { @@ -422,6 +424,7 @@ impl HoneyBadgerBFT { /// Creates an instance of the Honey Badger BFT Engine. pub fn new(params: HbbftParams, machine: EthereumMachine) -> Result, Error> { let is_unit_test = params.is_unit_test.unwrap_or(false); + let engine = Arc::new(HoneyBadgerBFT { transition_service: IoService::<()>::start("Hbbft")?, client: Arc::new(RwLock::new(None)), @@ -450,6 +453,7 @@ impl HoneyBadgerBFT { peers_management: Mutex::new(HbbftPeersManagement::new()), current_minimum_gas_price: Mutex::new(None), early_epoch_manager: Mutex::new(None), + fork_manager: Mutex::new(HbbftNetworkForkManager::new()), }); if !engine.params.is_unit_test.unwrap_or(false) { @@ -1419,6 +1423,13 @@ impl Engine for HoneyBadgerBFT { fn register_client(&self, client: Weak) { *self.client.write() = Some(client.clone()); if let Some(client) = self.client_arc() { + + if let Some(latest_block) = client.block_number(BlockId::Latest) { + self.fork_manager.lock().initialize(latest_block, self.params.forks.clone()); + } else { + error!(target: "engine", "hbbft-hardfork : could not initialialize hardfork manager, no latest block found."); + } + let mut state = self.hbbft_state.write(); match state.update_honeybadger( client, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index d0546c9d7..792c9aec8 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -1,21 +1,55 @@ use std::collections::VecDeque; use ethereum_types::Address; +use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::sync_key_gen::{Ack, Part}; -struct HbbftForkKeys { +struct HbbftFork { +// start_timestamp: u64, + start_block: u64, +// end_timestamp: u64, + end_block: Option, validators: Vec
, parts: Vec, acks: Vec, } -struct HbbftFork { - start_timestamp: u64, - start_block: u64, - is_finished: bool, - end_timestamp: u64, - end_block: u64, - validator_set: HbbftForkKeys, + +impl HbbftFork { + + pub fn from_definition(fork_definiton: &HbbftNetworkFork) -> HbbftFork { + + let parts = fork_definiton.parts.iter().map(|p| { + + if let Ok(part) = bincode::deserialize( p.as_slice()) { + part + } else { + error!(target:"engine", "hbbft-hardfork: could not interprete part from spec: {:?}", p.as_slice()); + panic!("hbbft-hardfork: could not interprete part from spec: {:?}", p.as_slice()); + + } + }).collect(); + + let acks = fork_definiton.acks.iter().map(|a| { + + if let Ok(ack) = bincode::deserialize( a.as_slice()) { + ack + } else { + error!(target:"engine", "hbbft-hardfork: could not interprete part from spec: {:?}", a.as_slice()); + panic!("hbbft-hardfork: could not interprete part from spec: {:?}", a.as_slice()); + } + }).collect(); + + //bincode::deserialize(&serialized_part).unwrap(); + + HbbftFork { + start_block: fork_definiton.block_number_start, + end_block: fork_definiton.block_number_end, + validators: fork_definiton.validators.clone(), + parts, + acks + } + } } /// Hbbft network fork manager. @@ -32,6 +66,10 @@ pub struct HbbftNetworkForkManager { /// a ordered list with upcomming forks, including a fork that is in progress. /// see @is_currently_forking for more information. pending_forks: VecDeque, + + /// we cannot apply the RAI pattern because of the delayed Hbbft initialization + /// this variable tracks if the fork manager is initialized or not. + is_init: bool, } impl HbbftNetworkForkManager { @@ -47,4 +85,67 @@ impl HbbftNetworkForkManager { None } + + /// Initializes the fork Manager, + /// with the information of the current block. + /// the Fork Manager is able to determine when the next fork is pending. + /// Forks that are already known to be finished, + /// have to be declared as finished. + pub fn initialize(&mut self, startup_block_number: u64, mut fork_definition: Vec,) { + if self.is_init { + panic!("HbbftNetworkForkManager is already initialized"); + } + + fork_definition.sort_by_key(|fork| fork.block_number_start); + + // the fork definition can contain + // - forks that are already finished + // - forks that are pending + + // there is one corner case: + // we could be in a current fork, + // if there is a a fork defined, + // that started in the past, + // is ongoing, and the normal key generation did not proceed to a new block. + + // first of all, we are appending all forks that happened in the past and are considered finished. + + for fork_def in fork_definition.iter() { + if let Some(end_block) = fork_def.block_number_end { + // if the fork is known to be ended, + // and the end is after current block, + // we do not need to take care about this fork anymore. + if end_block < startup_block_number { + debug!(target: "engine", "hbbft-hardfork: ignoring already finished fork {:?}", fork_def); + continue; + } + + self.pending_forks.push_back(HbbftFork::from_definition(fork_def)); + } + } + + // self.fork_definition.iter().filter(predicate).for_each(|fork| { + // self.pending_forks.push_back(HbbftFork { + // start_timestamp: 0, + // start_block: fork.block_number_start, + // is_finished: false, + // end_timestamp: 0, + // end_block: 0, + // validator_set: HbbftForkKeys { + // validators: fork.validators.clone(), + // parts: Vec::new(), + // acks: Vec::new(), + // }, + // }); + // }); + } + + pub fn new() -> HbbftNetworkForkManager { + HbbftNetworkForkManager { + is_currently_forking: false, + finished_forks: VecDeque::new(), + pending_forks: VecDeque::new(), + is_init: false, + } + } } From 8c3ab215152255d25e3ea3642e6907a04dc45ab7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 9 Feb 2024 17:59:01 +0100 Subject: [PATCH 195/687] cargo fmt --all -- --config imports_granularity=Crate --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 5 ++-- .../hbbft/hbbft_network_fork_manager.rs | 27 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 885a0a0f9..d94a93d93 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1423,9 +1423,10 @@ impl Engine for HoneyBadgerBFT { fn register_client(&self, client: Weak) { *self.client.write() = Some(client.clone()); if let Some(client) = self.client_arc() { - if let Some(latest_block) = client.block_number(BlockId::Latest) { - self.fork_manager.lock().initialize(latest_block, self.params.forks.clone()); + self.fork_manager + .lock() + .initialize(latest_block, self.params.forks.clone()); } else { error!(target: "engine", "hbbft-hardfork : could not initialialize hardfork manager, no latest block found."); } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 792c9aec8..756a8bda0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -5,33 +5,27 @@ use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::sync_key_gen::{Ack, Part}; struct HbbftFork { -// start_timestamp: u64, + // start_timestamp: u64, start_block: u64, -// end_timestamp: u64, + // end_timestamp: u64, end_block: Option, validators: Vec
, parts: Vec, acks: Vec, } - impl HbbftFork { - pub fn from_definition(fork_definiton: &HbbftNetworkFork) -> HbbftFork { - - let parts = fork_definiton.parts.iter().map(|p| { - + let parts = fork_definiton.parts.iter().map(|p| { if let Ok(part) = bincode::deserialize( p.as_slice()) { part } else { error!(target:"engine", "hbbft-hardfork: could not interprete part from spec: {:?}", p.as_slice()); - panic!("hbbft-hardfork: could not interprete part from spec: {:?}", p.as_slice()); - + panic!("hbbft-hardfork: could not interprete part from spec: {:?}", p.as_slice()); } }).collect(); - let acks = fork_definiton.acks.iter().map(|a| { - + let acks = fork_definiton.acks.iter().map(|a| { if let Ok(ack) = bincode::deserialize( a.as_slice()) { ack } else { @@ -47,7 +41,7 @@ impl HbbftFork { end_block: fork_definiton.block_number_end, validators: fork_definiton.validators.clone(), parts, - acks + acks, } } } @@ -91,7 +85,11 @@ impl HbbftNetworkForkManager { /// the Fork Manager is able to determine when the next fork is pending. /// Forks that are already known to be finished, /// have to be declared as finished. - pub fn initialize(&mut self, startup_block_number: u64, mut fork_definition: Vec,) { + pub fn initialize( + &mut self, + startup_block_number: u64, + mut fork_definition: Vec, + ) { if self.is_init { panic!("HbbftNetworkForkManager is already initialized"); } @@ -120,7 +118,8 @@ impl HbbftNetworkForkManager { continue; } - self.pending_forks.push_back(HbbftFork::from_definition(fork_def)); + self.pending_forks + .push_back(HbbftFork::from_definition(fork_def)); } } From 922aedf0152b7bde4e8b39b2148622947752d6aa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 10 Feb 2024 22:23:35 +0100 Subject: [PATCH 196/687] fork integraton in honeybadger comment --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 29d107357..c0da81110 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -89,6 +89,17 @@ impl HbbftState { } } + // https://github.com/DMDcoin/diamond-node/issues/98 + // check here if we are in a fork scenario. + // in a fork scenario, the new honeybadger keys will come from the config, + // and not from the contracts. + // also the current block will trigger the epoch end, + // this will start the loop for finding a new validator set, + // probably it will fail multiple times, + // because nodes that do not apply to the fork rule will drop out. + // this might happen for a lot of key-gen rounds, until a set with responsive validators + // can be found. + if !force && self.current_posdao_epoch == target_posdao_epoch { // hbbft state is already up to date. // @todo Return proper error codes. From 27ca2ff1fff59f1619b1d36d0bbf652a86afa008 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 11 Feb 2024 23:41:53 +0100 Subject: [PATCH 197/687] moved fork manager from engine to state --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 9 +++++---- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 15 ++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index d94a93d93..4c965b581 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1423,15 +1423,16 @@ impl Engine for HoneyBadgerBFT { fn register_client(&self, client: Weak) { *self.client.write() = Some(client.clone()); if let Some(client) = self.client_arc() { + + let mut state = self.hbbft_state.write(); + if let Some(latest_block) = client.block_number(BlockId::Latest) { - self.fork_manager - .lock() - .initialize(latest_block, self.params.forks.clone()); + state.init_fork_manager(latest_block, self.params.forks.clone()); + } else { error!(target: "engine", "hbbft-hardfork : could not initialialize hardfork manager, no latest block found."); } - let mut state = self.hbbft_state.write(); match state.update_honeybadger( client, &self.signer, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index c0da81110..de7866246 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -2,6 +2,7 @@ use client::traits::EngineClient; use engines::signer::EngineSigner; use ethcore_miner::pool::{PoolVerifiedTransaction, ScoredTransaction}; use ethereum_types::U256; +use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::{ crypto::{PublicKey, Signature}, honey_badger::{self, HoneyBadgerBuilder}, @@ -23,11 +24,7 @@ use super::{ keygen_history::{initialize_synckeygen, synckeygen_to_network_info}, staking::{get_posdao_epoch, get_posdao_epoch_start}, validator_set::ValidatorType, - }, - contribution::Contribution, - hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, - hbbft_peers_management::HbbftPeersManagement, - NodeId, + }, contribution::Contribution, hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_network_fork_manager::HbbftNetworkForkManager, hbbft_peers_management::HbbftPeersManagement, NodeId }; pub type HbMessage = honey_badger::Message; @@ -44,6 +41,7 @@ pub(crate) struct HbbftState { current_posdao_epoch_start_block: u64, last_posdao_epoch_start_block: Option, future_messages_cache: BTreeMap>, + fork_manager: HbbftNetworkForkManager, } impl HbbftState { @@ -56,6 +54,7 @@ impl HbbftState { current_posdao_epoch_start_block: 0, last_posdao_epoch_start_block: None, future_messages_cache: BTreeMap::new(), + fork_manager: HbbftNetworkForkManager::new(), } } @@ -65,6 +64,10 @@ impl HbbftState { return Some(builder.build()); } + pub fn init_fork_manager(&mut self, latest_block: u64, fork_definition: Vec) { + self.fork_manager.initialize(latest_block, fork_definition); + } + /** * Updates the underlying honeybadger instance, possible switching into a new * honeybadger instance if according to contracts a new staking epoch has started. @@ -100,6 +103,8 @@ impl HbbftState { // this might happen for a lot of key-gen rounds, until a set with responsive validators // can be found. + + if !force && self.current_posdao_epoch == target_posdao_epoch { // hbbft state is already up to date. // @todo Return proper error codes. From 9e4fb9aee8c497d4af3497d1bd0989a0f59950da Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 11 Feb 2024 23:42:06 +0100 Subject: [PATCH 198/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 4 +--- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 4c965b581..a4bf62dc1 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1423,12 +1423,10 @@ impl Engine for HoneyBadgerBFT { fn register_client(&self, client: Weak) { *self.client.write() = Some(client.clone()); if let Some(client) = self.client_arc() { - let mut state = self.hbbft_state.write(); - + if let Some(latest_block) = client.block_number(BlockId::Latest) { state.init_fork_manager(latest_block, self.params.forks.clone()); - } else { error!(target: "engine", "hbbft-hardfork : could not initialialize hardfork manager, no latest block found."); } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index de7866246..283c902b2 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -24,7 +24,12 @@ use super::{ keygen_history::{initialize_synckeygen, synckeygen_to_network_info}, staking::{get_posdao_epoch, get_posdao_epoch_start}, validator_set::ValidatorType, - }, contribution::Contribution, hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_network_fork_manager::HbbftNetworkForkManager, hbbft_peers_management::HbbftPeersManagement, NodeId + }, + contribution::Contribution, + hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, + hbbft_network_fork_manager::HbbftNetworkForkManager, + hbbft_peers_management::HbbftPeersManagement, + NodeId, }; pub type HbMessage = honey_badger::Message; @@ -103,8 +108,6 @@ impl HbbftState { // this might happen for a lot of key-gen rounds, until a set with responsive validators // can be found. - - if !force && self.current_posdao_epoch == target_posdao_epoch { // hbbft state is already up to date. // @todo Return proper error codes. From b507e6727f9a0ba73faed396c09b71b3fef88c4d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Feb 2024 15:51:44 +0100 Subject: [PATCH 199/687] fork manager interface change: should_fork returns now directly the NetworkInfo --- .../engines/hbbft/hbbft_network_fork_manager.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 756a8bda0..79fc0437a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -2,7 +2,9 @@ use std::collections::VecDeque; use ethereum_types::Address; use ethjson::spec::hbbft::HbbftNetworkFork; -use hbbft::sync_key_gen::{Ack, Part}; +use hbbft::{sync_key_gen::{Ack, Part}, NetworkInfo}; + +use super::NodeId; struct HbbftFork { // start_timestamp: u64, @@ -67,17 +69,18 @@ pub struct HbbftNetworkForkManager { } impl HbbftNetworkForkManager { + /// Returns None if not forking /// Returns a List of Addresses that become the new validator set and /// declares the fork as active, pub fn should_fork( &mut self, - last_block_number: u64, - last_block_time_stamp: u64, - ) -> Option> { + last_block_number: u64 + ) -> Option> { // fields omitted None + } /// Initializes the fork Manager, @@ -148,3 +151,6 @@ impl HbbftNetworkForkManager { } } } + + + From a1953a9c0b4b782a1768565414c061c29a7ae9ea Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Feb 2024 16:32:34 +0100 Subject: [PATCH 200/687] fork manager: first should_fork implementation. TODO: causing panic during linking ? --- .../hbbft/hbbft_network_fork_manager.rs | 43 ++++++++++++++++--- .../ethcore/src/engines/hbbft/hbbft_state.rs | 10 +++++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 79fc0437a..445a38fb0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -9,8 +9,13 @@ use super::NodeId; struct HbbftFork { // start_timestamp: u64, start_block: u64, - // end_timestamp: u64, + + // start epoch is set, if the fork has been started. + start_epoch: Option, + + // end_block is set when the fork process is finished and the network operation has normaliced again. end_block: Option, + validators: Vec
, parts: Vec, acks: Vec, @@ -40,6 +45,7 @@ impl HbbftFork { HbbftFork { start_block: fork_definiton.block_number_start, + start_epoch: None, end_block: fork_definiton.block_number_end, validators: fork_definiton.validators.clone(), parts, @@ -53,8 +59,6 @@ impl HbbftFork { /// It allows cheap queries to see if a Fork is pending, /// and stores information about a fork that is finished. pub struct HbbftNetworkForkManager { - /// If a fork is currently in progress, this is true. - is_currently_forking: bool, /// a ordered list with upcomming forks. finished_forks: VecDeque, @@ -75,10 +79,40 @@ impl HbbftNetworkForkManager { /// declares the fork as active, pub fn should_fork( &mut self, - last_block_number: u64 + last_block_number: u64, + current_epoch: u64 ) -> Option> { // fields omitted + if let Some(next_fork) = self.pending_forks.front_mut() { + + if next_fork.start_block == last_block_number { + + todo!("Fork not implemented!"); + + // return Some(NetworkInfo { + // validators: next_fork.validators.clone(), + // parts: next_fork.parts.clone(), + // acks: next_fork.acks.clone(), + // }); + } else if next_fork.start_block > last_block_number { + + // in the following blocks after the fork process was started, + // it is possible for the network to have now ended the fork process. + // we are checking if the current epoch is greater than the start epoch. + + if let Some(start_epoch) = next_fork.start_epoch { + if current_epoch == start_epoch + 1 { + next_fork.end_block = Some(last_block_number); + + // the fork process is finished. + // we are moving the fork to the finished forks list. + + // self.finished_forks.push_back(self.pending_forks.pop_front().unwrap()); + } + } + } // else: we are just waiting for the fork to happen. + } None } @@ -144,7 +178,6 @@ impl HbbftNetworkForkManager { pub fn new() -> HbbftNetworkForkManager { HbbftNetworkForkManager { - is_currently_forking: false, finished_forks: VecDeque::new(), pending_forks: VecDeque::new(), is_init: false, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 283c902b2..8e849dcf0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -108,6 +108,16 @@ impl HbbftState { // this might happen for a lot of key-gen rounds, until a set with responsive validators // can be found. + // if let Some(last_block_number) = client.block_number(block_id) { + // if let Some(fork_start_set) = self.fork_manager.should_fork(last_block_number) { + // let network_info = synckeygen_to_network_info(&synckeygen, pks, sks)?; + // self.network_info = Some(network_info.clone()); + // self.honey_badger = Some(self.new_honey_badger(network_info.clone())?); + // } + // } + + // + if !force && self.current_posdao_epoch == target_posdao_epoch { // hbbft state is already up to date. // @todo Return proper error codes. From 9d42cfef5375e0bee76e04061cbaf2f9973692bb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Feb 2024 16:50:54 +0100 Subject: [PATCH 201/687] simplified contribution --- crates/ethcore/src/engines/hbbft/contribution.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contribution.rs b/crates/ethcore/src/engines/hbbft/contribution.rs index b058addcc..6954a23d9 100644 --- a/crates/ethcore/src/engines/hbbft/contribution.rs +++ b/crates/ethcore/src/engines/hbbft/contribution.rs @@ -42,12 +42,11 @@ impl Contribution { s.drain() }) .collect(); - let mut rng = rand::thread_rng(); Contribution { transactions: ser_txns, timestamp: unix_now_secs(), - random_data: rng + random_data: rand::thread_rng() .sample_iter(&Standard) .take(RANDOM_BYTES_PER_EPOCH) .collect(), From 16c27a46032d8b1588aca2f552ba9138bc1b983f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Feb 2024 16:51:57 +0100 Subject: [PATCH 202/687] removed unused import in hbbft_peers_management. --- crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index c42bfa0cd..4039a1fe9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -12,7 +12,7 @@ use crate::{ use bytes::ToPretty; use ethereum_types::Address; -use hbbft::NetworkInfo; + use super::{contracts::staking::get_pool_public_key, NodeId}; From 6b85b363a47afec9c3c1cde50839ba8745e1cc19 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Feb 2024 16:57:36 +0100 Subject: [PATCH 203/687] missing comments in new_test_round_rewrite_bytecode_transitions spec.rs --- crates/ethcore/src/spec/spec.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/spec/spec.rs b/crates/ethcore/src/spec/spec.rs index bf2df2a22..94b062379 100644 --- a/crates/ethcore/src/spec/spec.rs +++ b/crates/ethcore/src/spec/spec.rs @@ -1196,6 +1196,7 @@ impl Spec { load_bundled!("test/authority_round_block_reward_contract") } + /// test: authority_round_rewrite_bytecode_transitions #[cfg(any(test, feature = "test-helpers"))] pub fn new_test_round_rewrite_bytecode_transitions() -> Self { load_bundled!("test/authority_round_rewrite_bytecode_transitions") From 54adbed38e1c54c8c7ff4a300ba1cbb6f1fe7a46 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Feb 2024 17:44:14 +0100 Subject: [PATCH 204/687] ethjson spec: hardfork declaration for public keys --- crates/ethjson/src/spec/hbbft.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index 09209c03e..405dac04c 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -46,8 +46,9 @@ pub struct HbbftNetworkFork { #[serde(default)] pub block_number_end: Option, - /// Validator set at the fork. - pub validators: Vec
, + /// Validator set (public keys) of the fork. + #[serde_as(as = "Vec")] + pub validators: Vec>, #[serde_as(as = "Vec")] pub parts: Vec>, @@ -119,8 +120,9 @@ impl HbbftParams { #[cfg(test)] mod tests { - use super::Hbbft; use ethereum_types::Address; + + use super::Hbbft; use std::str::FromStr; #[test] @@ -136,7 +138,7 @@ mod tests { { "blockNumberStart" : 777, "validators": [ - "0xfe163fc225f3863cef09f1f68ead173f30300d13" + "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678" ], "parts": ["19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"], "acks": ["19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"] @@ -158,6 +160,8 @@ mod tests { ); assert_eq!(deserialized.params.forks.get(0).expect("").parts.len(), 1); assert_eq!(deserialized.params.forks.get(0).expect("").acks.len(), 1); + assert_eq!(deserialized.params.forks.get(0).expect("").validators.len(), 1); + assert_eq!(deserialized.params.forks.get(0).expect("").validators.get(0).expect("").len(), 64); } #[test] From 4d978bf96c595bc47f572d6c848b0ab04bbf6699 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 13 Feb 2024 12:07:22 +0100 Subject: [PATCH 205/687] key generation for fork, according to logic in update_honeybadger --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 24 +++- .../hbbft/hbbft_network_fork_manager.rs | 119 +++++++++++++++--- .../ethcore/src/engines/hbbft/hbbft_state.rs | 4 +- 3 files changed, 128 insertions(+), 19 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index a4bf62dc1..004b9b037 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -18,7 +18,7 @@ use engines::{ SealingState, }; use error::{BlockError, Error}; -use ethereum_types::{Address, H256, H512, U256}; +use ethereum_types::{Address, Public, H256, H512, U256}; use ethjson::spec::HbbftParams; use hbbft::{NetworkInfo, Target}; use io::{IoContext, IoHandler, IoService, TimerToken}; @@ -1421,12 +1421,32 @@ impl Engine for HoneyBadgerBFT { } fn register_client(&self, client: Weak) { + + *self.client.write() = Some(client.clone()); + + + if let Some(client) = self.client_arc() { let mut state = self.hbbft_state.write(); + // let our_addr = match *self.signer.read() { + // Some(ref signer) => signer.address(), + // None => { + // NodeId::default() + // } + // }; + + // todo: better get the own ID from devP2P communication ?! + let own_public_key = match self.signer.read().as_ref() { + Some(signer) => signer + .public() + .expect("Signer's public key must be available!"), + None => Public::from(H512::from_low_u64_be(0)), + }; + if let Some(latest_block) = client.block_number(BlockId::Latest) { - state.init_fork_manager(latest_block, self.params.forks.clone()); + state.init_fork_manager(NodeId(own_public_key), latest_block, self.params.forks.clone()); } else { error!(target: "engine", "hbbft-hardfork : could not initialialize hardfork manager, no latest block found."); } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 445a38fb0..509abd590 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -1,11 +1,15 @@ -use std::collections::VecDeque; +use std::{collections::{BTreeMap, VecDeque}, sync::Arc}; use ethereum_types::Address; use ethjson::spec::hbbft::HbbftNetworkFork; -use hbbft::{sync_key_gen::{Ack, Part}, NetworkInfo}; +use hbbft::{crypto::PublicKeySet, sync_key_gen::{Ack, Part, SyncKeyGen}, util::max_faulty, NetworkInfo}; +use parking_lot::RwLock; + +use crate::engines::{hbbft::contracts::keygen_history::{KeyPairWrapper, PublicWrapper}, EngineSigner}; use super::NodeId; +#[derive(Debug)] struct HbbftFork { // start_timestamp: u64, start_block: u64, @@ -16,7 +20,7 @@ struct HbbftFork { // end_block is set when the fork process is finished and the network operation has normaliced again. end_block: Option, - validators: Vec
, + validators: Vec, parts: Vec, acks: Vec, } @@ -36,18 +40,26 @@ impl HbbftFork { if let Ok(ack) = bincode::deserialize( a.as_slice()) { ack } else { - error!(target:"engine", "hbbft-hardfork: could not interprete part from spec: {:?}", a.as_slice()); - panic!("hbbft-hardfork: could not interprete part from spec: {:?}", a.as_slice()); + error!(target:"engine", "hbbft-hardfork: could not interprete acks from spec: {:?}", a.as_slice()); + panic!("hbbft-hardfork: could not interprete acks from spec: {:?}", a.as_slice()); } }).collect(); - //bincode::deserialize(&serialized_part).unwrap(); + + let node_ids = fork_definiton.acks.iter().map(|h| { + if let Ok(node_id) = bincode::deserialize( h.as_slice()) { + node_id + } else { + error!(target:"engine", "hbbft-hardfork: could not interprete nodeIds from spec: {:?}", h.as_slice()); + panic!("hbbft-hardfork: could not interprete part from spec: {:?}", h.as_slice()); + } + }).collect(); HbbftFork { start_block: fork_definiton.block_number_start, start_epoch: None, end_block: fork_definiton.block_number_end, - validators: fork_definiton.validators.clone(), + validators: node_ids, parts, acks, } @@ -70,6 +82,8 @@ pub struct HbbftNetworkForkManager { /// we cannot apply the RAI pattern because of the delayed Hbbft initialization /// this variable tracks if the fork manager is initialized or not. is_init: bool, + + own_id: NodeId } impl HbbftNetworkForkManager { @@ -80,7 +94,8 @@ impl HbbftNetworkForkManager { pub fn should_fork( &mut self, last_block_number: u64, - current_epoch: u64 + current_epoch: u64, + signer_lock: Arc>>>, ) -> Option> { // fields omitted @@ -88,13 +103,52 @@ impl HbbftNetworkForkManager { if next_fork.start_block == last_block_number { - todo!("Fork not implemented!"); + //let keys : PublicKeySet = PublicKeySet:: + let wrapper = KeyPairWrapper { + inner: signer_lock.clone(), + }; + + let mut rng = rand::thread_rng(); + let mut pub_keys_btree: BTreeMap = BTreeMap::new(); + + for v in next_fork.validators.iter() { + pub_keys_btree.insert(v.clone(), PublicWrapper { + inner: v.clone().0 + }); + } + + let pub_keys: Arc> = Arc::new(pub_keys_btree); + let skg = match SyncKeyGen::new(self.own_id, wrapper, pub_keys, max_faulty(next_fork.validators.len()), &mut rng) { + Ok(s) => s.0, + Err(e) => { + error!(target: "engine", "hbbft-hardfork: could not create SyncKeyGen: {:?}", e); + panic!("hbbft-hardfork: could not create SyncKeyGen: {:?}", e); + } + }; - // return Some(NetworkInfo { - // validators: next_fork.validators.clone(), - // parts: next_fork.parts.clone(), - // acks: next_fork.acks.clone(), - // }); + if !skg.is_ready() { + error!(target: "engine", "hbbft-hardfork: missing parts for SyncKeyGen for fork {:?}", next_fork); + panic!("hbbft-hardfork: missing parts for SyncKeyGen for fork {:?}", next_fork); + } + + + let (pks, sks) = match skg.generate() { + Ok((p, s)) => (p, s), + Err(e) => { + error!(target: "engine", "hbbft-hardfork: could not generate keys for fork: {:?} {:?}", e, next_fork); + panic!("hbbft-hardfork: could not generate keys for fork: {:?} {:?}", e, next_fork); + } + }; + + let result = NetworkInfo::::new( + self.own_id, + sks, + pks, + next_fork.validators.clone() + ); + + return Some(result); + } else if next_fork.start_block > last_block_number { // in the following blocks after the fork process was started, @@ -108,7 +162,7 @@ impl HbbftNetworkForkManager { // the fork process is finished. // we are moving the fork to the finished forks list. - // self.finished_forks.push_back(self.pending_forks.pop_front().unwrap()); + self.finished_forks.push_back(self.pending_forks.pop_front().unwrap()); } } } // else: we are just waiting for the fork to happen. @@ -124,6 +178,7 @@ impl HbbftNetworkForkManager { /// have to be declared as finished. pub fn initialize( &mut self, + own_id: NodeId, startup_block_number: u64, mut fork_definition: Vec, ) { @@ -131,6 +186,8 @@ impl HbbftNetworkForkManager { panic!("HbbftNetworkForkManager is already initialized"); } + self.own_id = own_id; + fork_definition.sort_by_key(|fork| fork.block_number_start); // the fork definition can contain @@ -181,9 +238,41 @@ impl HbbftNetworkForkManager { finished_forks: VecDeque::new(), pending_forks: VecDeque::new(), is_init: false, + own_id: NodeId::default(), } } } +#[cfg(test)] +mod tests { + + use super::*; + use ethjson::spec::hbbft::HbbftNetworkFork; + use hbbft::sync_key_gen::{Ack, Part}; + use ethereum_types::Address; + + #[test] + fn test_should_fork() { + // let mut fork_manager = HbbftNetworkForkManager::new(); + // let mut fork_definition = Vec::new(); + + // let mut fork = HbbftNetworkFork { + // block_number_start: 10, + // block_number_end: Some(20), + // validators: vec![Address::from([0; 20])], + // parts: vec![bincode::serialize(&Part::new(0, 0)).unwrap()], + // acks: vec![bincode::serialize(&Ack::new(0, 0)).unwrap()], + // }; + + // fork_definition.push(fork); + + // fork_manager.initialize(5, fork_definition); + + // let result = fork_manager.should_fork(10, 0); + // assert!(result.is_some()); + } + + +} \ No newline at end of file diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 8e849dcf0..c9a945992 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -69,8 +69,8 @@ impl HbbftState { return Some(builder.build()); } - pub fn init_fork_manager(&mut self, latest_block: u64, fork_definition: Vec) { - self.fork_manager.initialize(latest_block, fork_definition); + pub fn init_fork_manager(&mut self, own_id: NodeId, latest_block: u64, fork_definition: Vec) { + self.fork_manager.initialize(own_id, latest_block, fork_definition); } /** From 46e66c84800eb6c7cafc7e1373ea13b30ebcaebb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Feb 2024 23:33:22 +0100 Subject: [PATCH 206/687] improved logging if part read from blockchain is invalid --- crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index 066c10d47..fc943606c 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -106,7 +106,10 @@ pub fn part_of_address( .unwrap(); match outcome { - PartOutcome::Invalid(_) => Err(CallError::ReturnValueInvalid), + PartOutcome::Invalid(e) => { + error!(target: "engine", "Part for address {} is invalid: {:?}", address, e); + Err(CallError::ReturnValueInvalid) + }, PartOutcome::Valid(ack) => Ok(ack), } } From 50245cdd6482cc5506509016517a8996f003c6bf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Feb 2024 23:36:05 +0100 Subject: [PATCH 207/687] code cleanup --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 004b9b037..7ab367136 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1429,13 +1429,6 @@ impl Engine for HoneyBadgerBFT { if let Some(client) = self.client_arc() { let mut state = self.hbbft_state.write(); - - // let our_addr = match *self.signer.read() { - // Some(ref signer) => signer.address(), - // None => { - // NodeId::default() - // } - // }; // todo: better get the own ID from devP2P communication ?! let own_public_key = match self.signer.read().as_ref() { From 9013644642e0e5e5cfc3a113fee582190c75f427 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Feb 2024 23:40:57 +0100 Subject: [PATCH 208/687] cargo fmt --all -- --config imports_granularity=Crate --- .../engines/hbbft/contracts/keygen_history.rs | 4 +- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 14 +-- .../hbbft/hbbft_network_fork_manager.rs | 105 +++++++++++------- .../engines/hbbft/hbbft_peers_management.rs | 4 - .../ethcore/src/engines/hbbft/hbbft_state.rs | 10 +- crates/ethjson/src/spec/hbbft.rs | 18 ++- 6 files changed, 98 insertions(+), 57 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index fc943606c..94c3724db 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -108,8 +108,8 @@ pub fn part_of_address( match outcome { PartOutcome::Invalid(e) => { error!(target: "engine", "Part for address {} is invalid: {:?}", address, e); - Err(CallError::ReturnValueInvalid) - }, + Err(CallError::ReturnValueInvalid) + } PartOutcome::Valid(ack) => Ok(ack), } } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 7ab367136..c07cb68ff 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1421,15 +1421,11 @@ impl Engine for HoneyBadgerBFT { } fn register_client(&self, client: Weak) { - - *self.client.write() = Some(client.clone()); - - if let Some(client) = self.client_arc() { let mut state = self.hbbft_state.write(); - + // todo: better get the own ID from devP2P communication ?! let own_public_key = match self.signer.read().as_ref() { Some(signer) => signer @@ -1437,9 +1433,13 @@ impl Engine for HoneyBadgerBFT { .expect("Signer's public key must be available!"), None => Public::from(H512::from_low_u64_be(0)), }; - + if let Some(latest_block) = client.block_number(BlockId::Latest) { - state.init_fork_manager(NodeId(own_public_key), latest_block, self.params.forks.clone()); + state.init_fork_manager( + NodeId(own_public_key), + latest_block, + self.params.forks.clone(), + ); } else { error!(target: "engine", "hbbft-hardfork : could not initialialize hardfork manager, no latest block found."); } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 509abd590..abc308817 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -1,11 +1,22 @@ -use std::{collections::{BTreeMap, VecDeque}, sync::Arc}; +use std::{ + collections::{BTreeMap, VecDeque}, + sync::Arc, +}; use ethereum_types::Address; use ethjson::spec::hbbft::HbbftNetworkFork; -use hbbft::{crypto::PublicKeySet, sync_key_gen::{Ack, Part, SyncKeyGen}, util::max_faulty, NetworkInfo}; +use hbbft::{ + crypto::PublicKeySet, + sync_key_gen::{Ack, Part, PartOutcome, SyncKeyGen}, + util::max_faulty, + NetworkInfo, +}; use parking_lot::RwLock; -use crate::engines::{hbbft::contracts::keygen_history::{KeyPairWrapper, PublicWrapper}, EngineSigner}; +use crate::engines::{ + hbbft::contracts::keygen_history::{KeyPairWrapper, PublicWrapper}, + EngineSigner, +}; use super::NodeId; @@ -45,7 +56,6 @@ impl HbbftFork { } }).collect(); - let node_ids = fork_definiton.acks.iter().map(|h| { if let Ok(node_id) = bincode::deserialize( h.as_slice()) { node_id @@ -71,7 +81,6 @@ impl HbbftFork { /// It allows cheap queries to see if a Fork is pending, /// and stores information about a fork that is finished. pub struct HbbftNetworkForkManager { - /// a ordered list with upcomming forks. finished_forks: VecDeque, @@ -83,11 +92,10 @@ pub struct HbbftNetworkForkManager { /// this variable tracks if the fork manager is initialized or not. is_init: bool, - own_id: NodeId + own_id: NodeId, } impl HbbftNetworkForkManager { - /// Returns None if not forking /// Returns a List of Addresses that become the new validator set and /// declares the fork as active, @@ -100,57 +108,78 @@ impl HbbftNetworkForkManager { // fields omitted if let Some(next_fork) = self.pending_forks.front_mut() { - if next_fork.start_block == last_block_number { - - //let keys : PublicKeySet = PublicKeySet:: - let wrapper = KeyPairWrapper { + //let keys : PublicKeySet = PublicKeySet:: + let wrapper = KeyPairWrapper { inner: signer_lock.clone(), }; - + let mut rng = rand::thread_rng(); let mut pub_keys_btree: BTreeMap = BTreeMap::new(); for v in next_fork.validators.iter() { - pub_keys_btree.insert(v.clone(), PublicWrapper { - inner: v.clone().0 - }); + pub_keys_btree.insert(v.clone(), PublicWrapper { inner: v.clone().0 }); } - + let pub_keys: Arc> = Arc::new(pub_keys_btree); - let skg = match SyncKeyGen::new(self.own_id, wrapper, pub_keys, max_faulty(next_fork.validators.len()), &mut rng) { + let mut skg = match SyncKeyGen::new( + self.own_id, + wrapper, + pub_keys, + max_faulty(next_fork.validators.len()), + &mut rng, + ) { Ok(s) => s.0, Err(e) => { error!(target: "engine", "hbbft-hardfork: could not create SyncKeyGen: {:?}", e); panic!("hbbft-hardfork: could not create SyncKeyGen: {:?}", e); } }; - + + //adding the PARTs to the SyncKeyGen + + for i_p in 0..next_fork.validators.len() { + let part = next_fork.parts.get(i_p).unwrap(); + let node_id = next_fork.validators.get(i_p).unwrap(); + let outcome = skg.handle_part(node_id, part.clone(), &mut rng).unwrap(); + + match outcome { + PartOutcome::Invalid(e) => { + error!(target: "engine", "hbbft-hardfork: Part for node {} is invalid: {:?}", node_id.as_8_byte_string(), e); + panic!( + "hbbft-hardfork: Part for node {} is invalid: {:?}", + node_id.as_8_byte_string(), + e + ); + } + PartOutcome::Valid(_) => {} + } + } + if !skg.is_ready() { error!(target: "engine", "hbbft-hardfork: missing parts for SyncKeyGen for fork {:?}", next_fork); - panic!("hbbft-hardfork: missing parts for SyncKeyGen for fork {:?}", next_fork); + panic!( + "hbbft-hardfork: missing parts for SyncKeyGen for fork {:?}", + next_fork + ); } - let (pks, sks) = match skg.generate() { Ok((p, s)) => (p, s), Err(e) => { error!(target: "engine", "hbbft-hardfork: could not generate keys for fork: {:?} {:?}", e, next_fork); - panic!("hbbft-hardfork: could not generate keys for fork: {:?} {:?}", e, next_fork); + panic!( + "hbbft-hardfork: could not generate keys for fork: {:?} {:?}", + e, next_fork + ); } }; - let result = NetworkInfo::::new( - self.own_id, - sks, - pks, - next_fork.validators.clone() - ); + let result = + NetworkInfo::::new(self.own_id, sks, pks, next_fork.validators.clone()); return Some(result); - } else if next_fork.start_block > last_block_number { - // in the following blocks after the fork process was started, // it is possible for the network to have now ended the fork process. // we are checking if the current epoch is greater than the start epoch. @@ -161,14 +190,14 @@ impl HbbftNetworkForkManager { // the fork process is finished. // we are moving the fork to the finished forks list. - - self.finished_forks.push_back(self.pending_forks.pop_front().unwrap()); + + self.finished_forks + .push_back(self.pending_forks.pop_front().unwrap()); } } } // else: we are just waiting for the fork to happen. } None - } /// Initializes the fork Manager, @@ -186,7 +215,7 @@ impl HbbftNetworkForkManager { panic!("HbbftNetworkForkManager is already initialized"); } - self.own_id = own_id; + self.own_id = own_id; fork_definition.sort_by_key(|fork| fork.block_number_start); @@ -243,15 +272,13 @@ impl HbbftNetworkForkManager { } } - - #[cfg(test)] -mod tests { +mod tests { use super::*; + use ethereum_types::Address; use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::sync_key_gen::{Ack, Part}; - use ethereum_types::Address; #[test] fn test_should_fork() { @@ -273,6 +300,4 @@ mod tests { // let result = fork_manager.should_fork(10, 0); // assert!(result.is_some()); } - - -} \ No newline at end of file +} diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 4039a1fe9..a04a8ac11 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -13,7 +13,6 @@ use bytes::ToPretty; use ethereum_types::Address; - use super::{contracts::staking::get_pool_public_key, NodeId}; #[derive(Clone, Debug)] @@ -26,9 +25,6 @@ struct ValidatorConnectionData { mining_address: Address, } -// impl ValidatorConnectionData { -// } - pub struct HbbftPeersManagement { own_validator_address: Address, last_written_internet_address: Option, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index c9a945992..008532fd7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -69,8 +69,14 @@ impl HbbftState { return Some(builder.build()); } - pub fn init_fork_manager(&mut self, own_id: NodeId, latest_block: u64, fork_definition: Vec) { - self.fork_manager.initialize(own_id, latest_block, fork_definition); + pub fn init_fork_manager( + &mut self, + own_id: NodeId, + latest_block: u64, + fork_definition: Vec, + ) { + self.fork_manager + .initialize(own_id, latest_block, fork_definition); } /** diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index 405dac04c..e0aaef807 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -160,8 +160,22 @@ mod tests { ); assert_eq!(deserialized.params.forks.get(0).expect("").parts.len(), 1); assert_eq!(deserialized.params.forks.get(0).expect("").acks.len(), 1); - assert_eq!(deserialized.params.forks.get(0).expect("").validators.len(), 1); - assert_eq!(deserialized.params.forks.get(0).expect("").validators.get(0).expect("").len(), 64); + assert_eq!( + deserialized.params.forks.get(0).expect("").validators.len(), + 1 + ); + assert_eq!( + deserialized + .params + .forks + .get(0) + .expect("") + .validators + .get(0) + .expect("") + .len(), + 64 + ); } #[test] From 21328f62535cdaef06985f881b8ef07cde74cb3c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 Feb 2024 23:52:22 +0100 Subject: [PATCH 209/687] removed fork_manager from hbbft_engine. hbbft state is mmanaging the fork manager --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index c07cb68ff..f3f1b088b 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -93,7 +93,6 @@ pub struct HoneyBadgerBFT { peers_management: Mutex, current_minimum_gas_price: Mutex>, early_epoch_manager: Mutex>, - fork_manager: Mutex, } struct TransitionHandler { @@ -453,7 +452,6 @@ impl HoneyBadgerBFT { peers_management: Mutex::new(HbbftPeersManagement::new()), current_minimum_gas_price: Mutex::new(None), early_epoch_manager: Mutex::new(None), - fork_manager: Mutex::new(HbbftNetworkForkManager::new()), }); if !engine.params.is_unit_test.unwrap_or(false) { From 82f5cf39445f074175098fa73b7642ceff970957 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 18 Feb 2024 23:50:44 +0100 Subject: [PATCH 210/687] recovered missing changes from i98-hardfork branch due local git repo corruption. --- Cargo.lock | 1 + .../hbbft/hbbft_config_generator/Cargo.toml | 1 + .../src/keygen_history_helpers.rs | 36 +++++++- .../hbbft/hbbft_config_generator/src/main.rs | 12 ++- .../hbbft/hbbft_network_fork_manager.rs | 92 +++++++++++++------ .../ethcore/src/engines/hbbft/hbbft_state.rs | 16 ++-- crates/ethjson/src/spec/hbbft.rs | 13 ++- 7 files changed, 128 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ed683e86..d33c539bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2140,6 +2140,7 @@ dependencies = [ "clap", "ethcore", "ethereum-types 0.9.2", + "ethjson", "ethkey", "ethstore", "hbbft", diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml index 37de51a9d..91ef228f6 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml @@ -11,6 +11,7 @@ authors = [ bincode = "1.1.2" clap = "2" ethcore = { path = "../../../.." } +ethjson = { path = "../../../../../ethjson" } ethereum-types = "0.9.2" ethkey = { path = "../../../../../accounts/ethkey" } ethstore = { path = "../../../../../accounts/ethstore"} diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs index 1cbce2005..b2f0a76b0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs @@ -1,5 +1,6 @@ use crate::Enode; use ethereum_types::H128; +use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::sync_key_gen::{AckOutcome, Part, PartOutcome, PublicKey, SecretKey, SyncKeyGen}; use parity_crypto::publickey::{public_to_address, Address, Public, Secret}; use serde::{Deserialize, Serialize}; @@ -112,7 +113,7 @@ pub fn enodes_to_pub_keys( } #[derive(Serialize, Deserialize)] -struct KeyGenHistoryData { +pub struct KeyGenHistoryData { validators: Vec, staking_addresses: Vec, public_keys: Vec, @@ -121,12 +122,41 @@ struct KeyGenHistoryData { acks: Vec>>, } + +impl KeyGenHistoryData { + pub fn to_json(&self) -> String { + serde_json::to_string(self).expect("Keygen History must convert to JSON") + } + + pub fn create_example_fork_definition(&self) -> HbbftNetworkFork { + + let validators : Vec> = self.public_keys.iter().map(|v| { + let mut hex = v.clone(); + println!("public key: {}", v); + if v.starts_with("0x") { + hex = v.split_at(2).1.to_string(); + } + + let public = hex.parse::().expect("Could not parse public key"); + public.as_bytes().to_vec() + }).collect(); + + HbbftNetworkFork { + block_number_start: 10, + block_number_end: Some(100), + validators: validators, + parts: self.parts.clone(), + acks: self.acks.clone(), + } + } +} + pub fn key_sync_history_data( parts: &BTreeMap, acks: &BTreeMap>, enodes: &BTreeMap, include_validators_only: bool, -) -> String { +) -> KeyGenHistoryData { let mut data = KeyGenHistoryData { validators: Vec::new(), staking_addresses: Vec::new(), @@ -215,7 +245,7 @@ pub fn key_sync_history_data( parts_total_bytes + acks_total_bytes ); - serde_json::to_string(&data).expect("Keygen History must convert to JSON") + data } #[cfg(test)] diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 4eaf58315..97fd6d96c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -12,6 +12,7 @@ extern crate rustc_hex; extern crate serde; extern crate serde_json; extern crate toml; +extern crate ethjson; mod keygen_history_helpers; @@ -511,18 +512,23 @@ fn main() { fs::write("password.txt", "test").expect("Unable to write password.txt file"); // only pass over enodes in the enodes_map that are also available for acks and parts. - fs::write( "keygen_history.json", - key_sync_history_data(&parts, &acks, &enodes_map, true), + key_sync_history_data(&parts, &acks, &enodes_map, true).to_json(), ) .expect("Unable to write keygen history data file"); fs::write( "nodes_info.json", - key_sync_history_data(&parts, &acks, &enodes_map, false), + key_sync_history_data(&parts, &acks, &enodes_map, false).to_json(), ) .expect("Unable to write nodes_info data file"); + + fs::write( + "fork_example.json", + key_sync_history_data(&parts, &acks, &enodes_map, false).create_example_fork_definition().to_json(), + ) + .expect("Unable to write fork_example.json data file"); } #[cfg(test)] diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index abc308817..c7a7c4bab 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -7,7 +7,7 @@ use ethereum_types::Address; use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::{ crypto::PublicKeySet, - sync_key_gen::{Ack, Part, PartOutcome, SyncKeyGen}, + sync_key_gen::{Ack, AckOutcome, Part, PartOutcome, SyncKeyGen}, util::max_faulty, NetworkInfo, }; @@ -33,7 +33,7 @@ struct HbbftFork { validators: Vec, parts: Vec, - acks: Vec, + acks: Vec>, } impl HbbftFork { @@ -47,16 +47,21 @@ impl HbbftFork { } }).collect(); - let acks = fork_definiton.acks.iter().map(|a| { - if let Ok(ack) = bincode::deserialize( a.as_slice()) { - ack - } else { - error!(target:"engine", "hbbft-hardfork: could not interprete acks from spec: {:?}", a.as_slice()); - panic!("hbbft-hardfork: could not interprete acks from spec: {:?}", a.as_slice()); + let acks = fork_definiton.acks.iter().map(|acks| { + let mut fork_acks: Vec = Vec::new(); + + for ack_bytes in acks { + if let Ok(ack) = bincode::deserialize( ack_bytes.as_slice()) { + fork_acks.push(ack); + } else { + error!(target:"engine", "hbbft-hardfork: could not interprete acks from spec: {:?}", ack_bytes.as_slice()); + panic!("hbbft-hardfork: could not interprete acks from spec: {:?}", ack_bytes.as_slice()); + } } + fork_acks }).collect(); - let node_ids = fork_definiton.acks.iter().map(|h| { + let node_ids = fork_definiton.validators.iter().map(|h| { if let Ok(node_id) = bincode::deserialize( h.as_slice()) { node_id } else { @@ -109,7 +114,7 @@ impl HbbftNetworkForkManager { if let Some(next_fork) = self.pending_forks.front_mut() { if next_fork.start_block == last_block_number { - //let keys : PublicKeySet = PublicKeySet:: + let wrapper = KeyPairWrapper { inner: signer_lock.clone(), }; @@ -138,9 +143,9 @@ impl HbbftNetworkForkManager { //adding the PARTs to the SyncKeyGen - for i_p in 0..next_fork.validators.len() { - let part = next_fork.parts.get(i_p).unwrap(); - let node_id = next_fork.validators.get(i_p).unwrap(); + for i in 0..next_fork.validators.len() { + let part = next_fork.parts.get(i).unwrap(); + let node_id = next_fork.validators.get(i).unwrap(); let outcome = skg.handle_part(node_id, part.clone(), &mut rng).unwrap(); match outcome { @@ -156,6 +161,27 @@ impl HbbftNetworkForkManager { } } + for i in 0..next_fork.validators.len() { + let acks = next_fork.acks.get(i).unwrap(); + + for ack in acks.iter() { + let node_id = next_fork.validators.get(i).unwrap(); + let outcome = skg.handle_ack(node_id, ack.clone()).unwrap(); + + match outcome { + AckOutcome::Invalid(e) => { + error!(target: "engine", "hbbft-hardfork: Part for node {} is invalid: {:?}", node_id.as_8_byte_string(), e); + panic!( + "hbbft-hardfork: Part for node {} is invalid: {:?}", + node_id.as_8_byte_string(), + e + ); + } + AckOutcome::Valid => {} + } + } + } + if !skg.is_ready() { error!(target: "engine", "hbbft-hardfork: missing parts for SyncKeyGen for fork {:?}", next_fork); panic!( @@ -275,29 +301,41 @@ impl HbbftNetworkForkManager { #[cfg(test)] mod tests { + use std::{fs, str::FromStr}; + + use crate::engines::{hbbft::test::hbbft_test_client::HbbftTestClient, signer::from_keypair}; + use super::*; use ethereum_types::Address; use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::sync_key_gen::{Ack, Part}; + //use parity_crypto::publickey::{KeyPair, Secret}; #[test] - fn test_should_fork() { - // let mut fork_manager = HbbftNetworkForkManager::new(); - // let mut fork_definition = Vec::new(); + fn test_fork_manager_should_fork() { + + let mut fork_manager = HbbftNetworkForkManager::new(); + + let test_file_content = std::fs::read("res/local_tests/hbbft_test_fork.json").expect("could not read test file."); + let test_fork = serde_json::from_slice::(test_file_content.as_slice()).expect("fork file is parsable."); + + + //let test_client = HbbftTestClient::new(); + + let key1 = KeyPair::from_secret( + Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001") + .unwrap(), + ).unwrap(); - // let mut fork = HbbftNetworkFork { - // block_number_start: 10, - // block_number_end: Some(20), - // validators: vec![Address::from([0; 20])], - // parts: vec![bincode::serialize(&Part::new(0, 0)).unwrap()], - // acks: vec![bincode::serialize(&Ack::new(0, 0)).unwrap()], - // }; + let signer = from_keypair(key1); - // fork_definition.push(fork); + //let signer = Box::new(Signer (key1)); + let signer_lock = Arc::new(RwLock::new(Some(signer))); - // fork_manager.initialize(5, fork_definition); + let own_id = NodeId::default(); + fork_manager.initialize(own_id, 1, vec![test_fork]); + + assert!(fork_manager.should_fork(9, 1, signer_lock).is_none()); - // let result = fork_manager.should_fork(10, 0); - // assert!(result.is_some()); } } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 008532fd7..d8e0b7f76 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -114,14 +114,16 @@ impl HbbftState { // this might happen for a lot of key-gen rounds, until a set with responsive validators // can be found. - // if let Some(last_block_number) = client.block_number(block_id) { - // if let Some(fork_start_set) = self.fork_manager.should_fork(last_block_number) { - // let network_info = synckeygen_to_network_info(&synckeygen, pks, sks)?; - // self.network_info = Some(network_info.clone()); - // self.honey_badger = Some(self.new_honey_badger(network_info.clone())?); - // } - // } + if let Some(last_block_number) = client.block_number(block_id) { + if let Some(network_info) = self.fork_manager.should_fork(last_block_number, self.current_posdao_epoch, signer.clone()) { + info!(target: "engine", "Forking at block {last_block_number}, starting new honeybadger instance with new validator set."); + + self.public_master_key = Some(network_info.public_key_set().public_key()); + self.honey_badger = Some(self.new_honey_badger(network_info.clone())?); + self.network_info = Some(network_info); + } + } // if !force && self.current_posdao_epoch == target_posdao_epoch { diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index e0aaef807..f7529e8fd 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -34,7 +34,7 @@ pub struct HbbftParamsSkipBlockReward { } #[serde_as] -#[derive(Debug, PartialEq, Deserialize, Clone)] +#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] pub struct HbbftNetworkFork { @@ -53,8 +53,15 @@ pub struct HbbftNetworkFork { #[serde_as(as = "Vec")] pub parts: Vec>, - #[serde_as(as = "Vec")] - pub acks: Vec>, + #[serde_as(as = "Vec>")] + pub acks: Vec>>, +} + +impl HbbftNetworkFork { + /// Returns true if the fork is finished. + pub fn to_json(&self) -> String { + serde_json::to_string(self).expect("HbbftNetworkFork must convert to JSON") + } } /// Hbbft parameters. From c3d8e7f48a5fcdf514926945929ce16a95531b8d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 Feb 2024 11:54:34 +0100 Subject: [PATCH 211/687] missing testfile: hbbft_test_fork.json --- .../local_tests/hbbft/hbbft_test_fork.json | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 crates/ethcore/res/local_tests/hbbft/hbbft_test_fork.json diff --git a/crates/ethcore/res/local_tests/hbbft/hbbft_test_fork.json b/crates/ethcore/res/local_tests/hbbft/hbbft_test_fork.json new file mode 100644 index 000000000..ec136e3c0 --- /dev/null +++ b/crates/ethcore/res/local_tests/hbbft/hbbft_test_fork.json @@ -0,0 +1,22 @@ +{ + "blockNumberStart": 10, + "blockNumberEnd": 100, + "validators": [ + "091d8eba3fedbd073d07d5da39fc42f61a2f4e7100018329f5b845aa86f64d6636de27aaa4c9872942811750a3db8cb8be03584fb50aaa557f8f13d4187db686", + "bf4ee1d6d3e72fe8ab1c8ccdeef3aff73665ca0dd2ef5497cd8152e329a9ebd283eba076c369977390f4697026209a9fdfa78c2d98e76c4bafb3f8fb669ee4b0" + ], + "parts": [ + "00000000000000000100000000000000b8192b72d83b24d9d13229521f74e6664135cd9dd3d5c4fee6b46244c7fb637e099a7cf83ff84f7da56f119391a5be45020000000000000099000000000000000410da71b86de8a64eda03139cb4aa2c86d7dc30b3a8125658d25454e31b6aaadc21d8a16290cd9a9367f7c81933e517f314481fe43f0385829e843a4ff5f614c0329f8725ba757f0f05543255b5ccf70e204af8ad430a8dc7be7ba923be1e3efbcd0c2852ad29e2516972dedbe8d1cfba4f2d3af8a08caeee33cd60d294b95ecd70d60e5a2b0929106eea34d457b95487f8864ea926e9b04b990000000000000004dbb6269a2ffe83a197d9687060e1a509affa81b88b8b0b5ec37b6323abd6a4220d8d445273b5f0b937b01fb900369add18030953e62239353599d6005081526d12567acda069033fb2c82109e8b8294d9f68e49fa461a81886d7162d37d8090c5e4ce633acd0ced42200a09eb9dacfb8c9dc0dcb5d5fa9b5d645318ed856fec6bdd146367d1258d5975681084122833c910f9c2c5f6ca8bf", + "00000000000000000100000000000000b38755bce7abb9935778b1803b7a4351f68c367e20a38d7208a5c24e3af245b13ded32434b982f15dfd0de99fb5188eb0200000000000000990000000000000004634fd14e7ce463dde2973d53ea2f9638239c22a7f22ee776f900f72ea093dd64c1b9747df1348a1c9293aafc5a99abbf511be721fc898d549dc9ffe94b3f4b6348eedc44322c1c1a6e62ecccc0b266fc44901bd777bddd512c351e56e6b6e3516c12cf3713edff7df201914d071f9a80cbcaea0fc1d228dc2485653d44d8829c9036040a184ac838e80074b2b6ee56f34690b6f26b85aa7a99000000000000000451456684fa30515c8d0ef1244ac419791fb0ff5d52bf2229cbef4fcf4928961d386f9c20c75fb530b1fce6e7e9ad5f0b0cd09944e8598d20e55f0208703e37ba191261e0d302824202eda3e0150731715b88e165f17203f1406023f9cd3d898e10fef65d99fc3f5e3891ce1001fda7bcbea95ac74d030f0a369c0b8cce8bdaac1d7b682649f644677953d1dc3f076bd3befa2c4aaa9d5ea3" + ], + "acks": [ + [ + "0000000000000000020000000000000091000000000000000490a193eab4de97351348833b933705dfb903c7f5875559722a25de970a7bf58a434a9c4d251fa8412ada1e11d8b38e1530a765ef4d3f5d89264967ad75d9e0559318ea05314b8317d686ac51c4bd66ce09de4f4dc6cc64efde35efc1394d5371e968592551401240d901ee9bcde99de77bbdcfa6a65d64dc9f814ca0b4f17a0b5e35562e01c21c850903c55a2ab442699100000000000000042d9c2e94e9a5d2283fdf0dae7f0671fd9a81787ecb2908d1fccee00c57c43022e4f42f2bbf3059ce2c0bebc12d7b4fcae2c87ff1072e111bb7b67839266e23a778272003f3ec618082b750c3b7fdb5800ce76312154fd8ba33a6aaf3aa6c6aaa5880f9516c6f5094d09a69f3c7918f0e2ec92542d91a0e2ba9f65722e3a374ab01c73bff571f114b7bdd0e9298eba220", + "010000000000000002000000000000009100000000000000047eee4f119edac1a8f78f0b44426ffbb26b03ea36234678b287711d4e3a47a0215fc917d83c64ff1adfa3c4e985dcaddf550953768ab3725680f8cb4046e0b4338f351cbe49e69c4fcfd3df3285f7b1deed4e1fe41a0ca2d6962de6348db84a690e018a170b3df8a1283a16514ff58be083668fc4226a4921c35a15ac59f8c2e6e3e00adb9da20df161013beacef2330c9100000000000000049d03818e04ff4631844a94e73976653117fa97d88d029159af7cfadf71ed285202f17332cef132f3bb0ca6f5ddfdb3b9cafcc6a9e5b4b86e493d9946b3a6ab5b8e981fe70792b2ec3f63ed9b682eb5b8667398191a16fa308bf1b600541418d6673ba3902d4b58f60875e117984b970dc0d646f721285cacb759e07938ee5a8dbb2bfc70c1b5d6168446571531cccf64" + ], + [ + "00000000000000000200000000000000910000000000000004a87bbba9d5bed1aaa03a2f761213b7bcc8e9b7ae4fb9704562504a07d17f058dfc8725686682e31a12795822f748bd7925085106f2632aecd1e8f2aba231c02c619d8f9263a2683e0cc87be5bad052873cad313550e4c3509ee5cd410cf1aa3350e6ac24c3741781ffa3c5f4a64676cb533f73470e56c7679caef649785494c12c999f6bfb9053c31627ca112cffac1c9100000000000000046a88660f1c401aabfc2e565105eb6ccdaa7f403f897e63512beee5b2a8f5b5a3a63f002ee74ace2778da41935a5fc44a1f5dc5e5a58484f662edd3dbb9f5a6088a7b53b0626b5c42fd2a1ec9f78374288bab74bd0e8398d7203aa294d1c78733365b646b0d38b72447f36e3908e9f2ab31a682b4f62c37ca3240b7e607f264b63917eff09c6fbaaef0331b17260b2074", + "010000000000000002000000000000009100000000000000040a911f3a00d13a252002b042e65052016a1426e05464246145247c72b3825459d92903a1dbf8381a475f38d89b79d6c3b8ea4213a379e5c0dfd78540b633ad3aac019c199c6f22c7c484e2c405bff32d55bc650ae88088b8d930f9a0b066f4576a0c781c80feeb6fc8c220b11964807aa611dcf4dafb5386cbaab7a14f210d78438472b1f427e5e85b49bfbf97e03f7a91000000000000000406c4f04455ad55cecdecd1969ec7ad7684602056eb17b7cd656adc82e741c873eab437d54d8c9e191bc51246e25d0b5c77b2440e866d6c38b6d82a408bd02b64c1bf0584231a4201b9916ed2be1282ab1640866c347ec017a5c92a924e5012334b59d82359544177b762568ea96bb3f7ce2dd6ff60cdfa6fa52c7a78cc6a3f2ec230bddfa6974934a0f6899797493f85" + ] + ] +} \ No newline at end of file From fde9d98509db773982ee3c3b2fbbb5edd52f4a1c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 Feb 2024 11:54:49 +0100 Subject: [PATCH 212/687] fixed missing imports in tests --- .../ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index c7a7c4bab..5cb62444f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -309,6 +309,10 @@ mod tests { use ethereum_types::Address; use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::sync_key_gen::{Ack, Part}; + + use crypto::publickey::{ + KeyPair, Secret, + }; //use parity_crypto::publickey::{KeyPair, Secret}; #[test] @@ -316,7 +320,7 @@ mod tests { let mut fork_manager = HbbftNetworkForkManager::new(); - let test_file_content = std::fs::read("res/local_tests/hbbft_test_fork.json").expect("could not read test file."); + let test_file_content = std::fs::read("res/local_tests/hbbft/hbbft_test_fork.json").expect("could not read test file."); let test_fork = serde_json::from_slice::(test_file_content.as_slice()).expect("fork file is parsable."); From 2322a646329eca6db4ef30c1cb2d1c2c6ea5edc8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 Feb 2024 11:57:34 +0100 Subject: [PATCH 213/687] fixed bug in HbbftFork::from_definition --- crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 5cb62444f..686b1da95 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -61,7 +61,7 @@ impl HbbftFork { fork_acks }).collect(); - let node_ids = fork_definiton.validators.iter().map(|h| { + let node_ids = fork_definiton.parts.iter().map(|h| { if let Ok(node_id) = bincode::deserialize( h.as_slice()) { node_id } else { From c714521d705f57f1815ee00b47a044b8981f1964 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 Feb 2024 12:20:53 +0100 Subject: [PATCH 214/687] unit test for HbbftNetworkFork serialisation/deserialisation --- crates/ethjson/src/spec/hbbft.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index f7529e8fd..ec7d5215e 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -269,4 +269,26 @@ mod tests { false ); } + + #[test] + fn test_fork_serialisation() { + let fork = super::HbbftNetworkFork { + block_number_start: 10, + block_number_end: Some(100), + validators: vec![vec![1, 2, 3, 4]], + parts: vec![vec![5, 6, 7, 8]], + acks: vec![vec![vec![9, 10, 11, 12]]], + }; + + let json = fork.to_json(); + let deserialized: super::HbbftNetworkFork = serde_json::from_str(&json).unwrap(); + assert_eq!(deserialized.block_number_start, 10); + assert_eq!(deserialized.block_number_end, Some(100)); + assert_eq!(deserialized.validators.len(), 1); + assert_eq!(deserialized.parts.len(), 1); + assert_eq!(deserialized.acks.len(), 1); + + assert_eq!(deserialized.parts[0][1], 6); + assert_eq!(deserialized.acks[0][0][2], 11); + } } From a09f185b4a95a3e55571cc09261a8d093ddf3798 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 Feb 2024 13:30:26 +0100 Subject: [PATCH 215/687] hbbft_config_generator: reusing the generated key_sync_history_data --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 97fd6d96c..49db88e6a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -511,10 +511,11 @@ fn main() { // Write the password file fs::write("password.txt", "test").expect("Unable to write password.txt file"); + let key_sync_file_validators_only = key_sync_history_data(&parts, &acks, &enodes_map, true); // only pass over enodes in the enodes_map that are also available for acks and parts. fs::write( "keygen_history.json", - key_sync_history_data(&parts, &acks, &enodes_map, true).to_json(), + key_sync_file_validators_only.to_json(), ) .expect("Unable to write keygen history data file"); @@ -526,7 +527,7 @@ fn main() { fs::write( "fork_example.json", - key_sync_history_data(&parts, &acks, &enodes_map, false).create_example_fork_definition().to_json(), + key_sync_file_validators_only.create_example_fork_definition().to_json(), ) .expect("Unable to write fork_example.json data file"); } From 5071dcd68ae256270de18c2a912414c2f9489d6b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 Feb 2024 13:31:19 +0100 Subject: [PATCH 216/687] hbbft_network_fork_manager: fixed creating HbbftFork from definition --- .../src/engines/hbbft/hbbft_network_fork_manager.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 686b1da95..5224429ce 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -1,9 +1,10 @@ + use std::{ collections::{BTreeMap, VecDeque}, sync::Arc, }; -use ethereum_types::Address; +use ethereum_types::{Address, H512}; use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::{ crypto::PublicKeySet, @@ -61,13 +62,8 @@ impl HbbftFork { fork_acks }).collect(); - let node_ids = fork_definiton.parts.iter().map(|h| { - if let Ok(node_id) = bincode::deserialize( h.as_slice()) { - node_id - } else { - error!(target:"engine", "hbbft-hardfork: could not interprete nodeIds from spec: {:?}", h.as_slice()); - panic!("hbbft-hardfork: could not interprete part from spec: {:?}", h.as_slice()); - } + let node_ids = fork_definiton.validators.iter().map(|h| { + NodeId(H512::from_slice(h.as_slice())) }).collect(); HbbftFork { From 0f7113155b1f6afdf62aa22a3c914b681b2f9e21 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 Feb 2024 23:34:52 +0100 Subject: [PATCH 217/687] improved unit test for hbbft_network_fork_manager --- .../src/engines/hbbft/hbbft_network_fork_manager.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 5224429ce..fd694731a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -333,9 +333,12 @@ mod tests { let signer_lock = Arc::new(RwLock::new(Some(signer))); let own_id = NodeId::default(); - fork_manager.initialize(own_id, 1, vec![test_fork]); - - assert!(fork_manager.should_fork(9, 1, signer_lock).is_none()); + fork_manager.initialize(own_id, 8, vec![test_fork]); + assert!(fork_manager.should_fork(9, 1, signer_lock.clone()).is_none()); + let fork = fork_manager.should_fork(10, 1, signer_lock.clone()); + assert!(fork.is_some()); + assert!(fork.unwrap().num_nodes() == 2); + assert!(fork_manager.should_fork(11, 1, signer_lock.clone()).is_none()); } } From 87b54a8b0403048d0fa371a80951a0fcd5fa0394 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 Feb 2024 16:20:13 +0100 Subject: [PATCH 218/687] cargo fmt --all -- --config imports_granularity=Crate --- .../src/keygen_history_helpers.rs | 24 +++++++------ .../hbbft/hbbft_network_fork_manager.rs | 36 ++++++++++--------- .../ethcore/src/engines/hbbft/hbbft_state.rs | 9 +++-- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs index b2f0a76b0..f627499d7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs @@ -122,24 +122,26 @@ pub struct KeyGenHistoryData { acks: Vec>>, } - impl KeyGenHistoryData { pub fn to_json(&self) -> String { serde_json::to_string(self).expect("Keygen History must convert to JSON") } pub fn create_example_fork_definition(&self) -> HbbftNetworkFork { + let validators: Vec> = self + .public_keys + .iter() + .map(|v| { + let mut hex = v.clone(); + println!("public key: {}", v); + if v.starts_with("0x") { + hex = v.split_at(2).1.to_string(); + } - let validators : Vec> = self.public_keys.iter().map(|v| { - let mut hex = v.clone(); - println!("public key: {}", v); - if v.starts_with("0x") { - hex = v.split_at(2).1.to_string(); - } - - let public = hex.parse::().expect("Could not parse public key"); - public.as_bytes().to_vec() - }).collect(); + let public = hex.parse::().expect("Could not parse public key"); + public.as_bytes().to_vec() + }) + .collect(); HbbftNetworkFork { block_number_start: 10, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index fd694731a..44acbd521 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -1,4 +1,3 @@ - use std::{ collections::{BTreeMap, VecDeque}, sync::Arc, @@ -62,9 +61,11 @@ impl HbbftFork { fork_acks }).collect(); - let node_ids = fork_definiton.validators.iter().map(|h| { - NodeId(H512::from_slice(h.as_slice())) - }).collect(); + let node_ids = fork_definiton + .validators + .iter() + .map(|h| NodeId(H512::from_slice(h.as_slice()))) + .collect(); HbbftFork { start_block: fork_definiton.block_number_start, @@ -110,7 +111,6 @@ impl HbbftNetworkForkManager { if let Some(next_fork) = self.pending_forks.front_mut() { if next_fork.start_block == last_block_number { - let wrapper = KeyPairWrapper { inner: signer_lock.clone(), }; @@ -306,26 +306,25 @@ mod tests { use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::sync_key_gen::{Ack, Part}; - use crypto::publickey::{ - KeyPair, Secret, - }; + use crypto::publickey::{KeyPair, Secret}; //use parity_crypto::publickey::{KeyPair, Secret}; #[test] fn test_fork_manager_should_fork() { - let mut fork_manager = HbbftNetworkForkManager::new(); - - let test_file_content = std::fs::read("res/local_tests/hbbft/hbbft_test_fork.json").expect("could not read test file."); - let test_fork = serde_json::from_slice::(test_file_content.as_slice()).expect("fork file is parsable."); + let test_file_content = std::fs::read("res/local_tests/hbbft/hbbft_test_fork.json") + .expect("could not read test file."); + let test_fork = serde_json::from_slice::(test_file_content.as_slice()) + .expect("fork file is parsable."); //let test_client = HbbftTestClient::new(); - + let key1 = KeyPair::from_secret( Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001") .unwrap(), - ).unwrap(); + ) + .unwrap(); let signer = from_keypair(key1); @@ -334,11 +333,14 @@ mod tests { let own_id = NodeId::default(); fork_manager.initialize(own_id, 8, vec![test_fork]); - assert!(fork_manager.should_fork(9, 1, signer_lock.clone()).is_none()); + assert!(fork_manager + .should_fork(9, 1, signer_lock.clone()) + .is_none()); let fork = fork_manager.should_fork(10, 1, signer_lock.clone()); assert!(fork.is_some()); assert!(fork.unwrap().num_nodes() == 2); - assert!(fork_manager.should_fork(11, 1, signer_lock.clone()).is_none()); - + assert!(fork_manager + .should_fork(11, 1, signer_lock.clone()) + .is_none()); } } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index d8e0b7f76..c637a3a51 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -114,11 +114,14 @@ impl HbbftState { // this might happen for a lot of key-gen rounds, until a set with responsive validators // can be found. - if let Some(last_block_number) = client.block_number(block_id) { - if let Some(network_info) = self.fork_manager.should_fork(last_block_number, self.current_posdao_epoch, signer.clone()) { + if let Some(network_info) = self.fork_manager.should_fork( + last_block_number, + self.current_posdao_epoch, + signer.clone(), + ) { info!(target: "engine", "Forking at block {last_block_number}, starting new honeybadger instance with new validator set."); - + self.public_master_key = Some(network_info.public_key_set().public_key()); self.honey_badger = Some(self.new_honey_badger(network_info.clone())?); self.network_info = Some(network_info); From a7b52d3ad4f7fb66fa3ccc8c3d51f74b80fa1abe Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 25 Feb 2024 14:35:14 +0100 Subject: [PATCH 219/687] witing out a fork example definition --- .../hbbft/hbbft_config_generator/src/main.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 49db88e6a..64a011316 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -3,6 +3,7 @@ extern crate bincode; extern crate clap; extern crate ethcore; extern crate ethereum_types; +extern crate ethjson; extern crate ethkey; extern crate ethstore; extern crate hbbft; @@ -12,7 +13,6 @@ extern crate rustc_hex; extern crate serde; extern crate serde_json; extern crate toml; -extern crate ethjson; mod keygen_history_helpers; @@ -374,6 +374,11 @@ fn main() { .required(false) .takes_value(true), ) + .arg(Arg::with_name("fork_block") + .long("fork block number") + .help("defines a fork block number.") + .required(false) + .takes_value(true),) .get_matches(); let num_nodes_validators: usize = matches @@ -396,6 +401,13 @@ fn main() { ) }); + let fork_block_number: Option = matches.value_of("fork_block_number").map_or(None, |v| { + Some( + v.parse::() + .expect("fork_block_number need to be of integer type"), + ) + }); + let metrics_port_base: Option = matches.value_of("metrics_port_base").map_or(None, |v| { Some( v.parse::() @@ -527,7 +539,9 @@ fn main() { fs::write( "fork_example.json", - key_sync_file_validators_only.create_example_fork_definition().to_json(), + key_sync_file_validators_only + .create_example_fork_definition() + .to_json(), ) .expect("Unable to write fork_example.json data file"); } From 8b30c833874561b3410bcbf5454be1b456186ffb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 26 Feb 2024 12:57:56 +0100 Subject: [PATCH 220/687] support definition of Ports as CLI Argument --- .../hbbft/hbbft_config_generator/src/main.rs | 77 ++++++++++++++++--- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 64a011316..13a7c83a3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -112,11 +112,10 @@ fn to_toml( tx_queue_per_sender: Option, base_metrics_port: Option, metrics_interface: Option<&str>, + base_port: u16, + base_rpc_port: u16, + base_ws_port: u16, ) -> Value { - let base_port = 30300i64; - let base_rpc_port = 8540i64; - let base_ws_port = 9540i64; - let mut parity = Map::new(); match config_type { ConfigType::PosdaoSetup => { @@ -134,7 +133,7 @@ fn to_toml( } let mut network = Map::new(); - network.insert("port".into(), Value::Integer(base_port + i as i64)); + network.insert("port".into(), Value::Integer((base_port as usize + i) as i64)); match config_type { ConfigType::PosdaoSetup => { network.insert( @@ -183,12 +182,12 @@ fn to_toml( "traces", ]); rpc.insert("apis".into(), apis); - rpc.insert("port".into(), Value::Integer(base_rpc_port + i as i64)); + rpc.insert("port".into(), Value::Integer((base_rpc_port as usize + i) as i64)); let mut websockets = Map::new(); websockets.insert("interface".into(), Value::String("all".into())); websockets.insert("origins".into(), to_toml_array(vec!["all"])); - websockets.insert("port".into(), Value::Integer(base_ws_port + i as i64)); + websockets.insert("port".into(), Value::Integer((base_ws_port as usize + i) as i64)); let mut ipc = Map::new(); ipc.insert("disable".into(), Value::Boolean(true)); @@ -375,10 +374,33 @@ fn main() { .takes_value(true), ) .arg(Arg::with_name("fork_block") - .long("fork block number") - .help("defines a fork block number.") - .required(false) - .takes_value(true),) + .long("fork block number") + .help("defines a fork block number.") + .required(false) + .takes_value(true), + ) + .arg( + Arg::with_name("port_base") + .long("port_base") + .help("devp2p communication port base address") + .required(false) + .default_value("30300") + .takes_value(true), + ).arg( + Arg::with_name("port_base_rpc") + .long("port_base_rpc") + .help("rpc port base") + .required(false) + .default_value("8540") + .takes_value(true), + ).arg( + Arg::with_name("port_base_ws") + .long("port_base_ws") + .help("rpc web socket port base") + .required(false) + .default_value("9540") + .takes_value(true), + ) .get_matches(); let num_nodes_validators: usize = matches @@ -415,6 +437,27 @@ fn main() { ) }); + let port_base: Option = matches.value_of("port_base").map_or(None, |v| { + Some( + v.parse::() + .expect("metrics_port need to be an integer port definition 1-65555"), + ) + }); + + let port_base_rpc: Option = matches.value_of("port_base_rpc").map_or(None, |v| { + Some( + v.parse::() + .expect("metrics_port need to be an integer port definition 1-65555"), + ) + }); + + let port_base_ws: Option = matches.value_of("port_base_ws").map_or(None, |v| { + Some( + v.parse::() + .expect("metrics_port need to be an integer port definition 1-65555"), + ) + }); + std::println!("metrics_port_base: {:?}", metrics_port_base); let metrics_interface = matches.value_of("metrics_interface"); @@ -472,6 +515,7 @@ fn main() { .expect("enode should be written to the reserved peers string"); let i = enode.idx; let file_name = format!("hbbft_validator_{}.toml", i); + // the unwrap is safe, because there is a default value defined. let toml_string = toml::to_string(&to_toml( i, &config_type, @@ -481,6 +525,9 @@ fn main() { tx_queue_per_sender.clone(), metrics_port_base, metrics_interface, + port_base.unwrap(), + port_base_rpc.unwrap(), + port_base_ws.unwrap() )) .expect("TOML string generation should succeed"); fs::write(file_name, toml_string).expect("Unable to write config file"); @@ -503,6 +550,11 @@ fn main() { format!("hbbft_validator_key_{}.json", i), ); } + + // let base_port = 30300i64; + // let base_rpc_port = 8540i64; + // let base_ws_port = 9540i64; + // Write rpc node config let rpc_string = toml::to_string(&to_toml( 0, @@ -513,6 +565,9 @@ fn main() { tx_queue_per_sender.clone(), metrics_port_base, metrics_interface, + port_base.unwrap(), + port_base_rpc.unwrap(), + port_base_ws.unwrap(), )) .expect("TOML string generation should succeed"); fs::write("rpc_node.toml", rpc_string).expect("Unable to write rpc config file"); From fad68e1c8f586953ac181bac64d87b8484e98782 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 26 Feb 2024 22:45:00 +0100 Subject: [PATCH 221/687] added port management for enodes and reserved peers file generation. --- .../hbbft/hbbft_config_generator/src/main.rs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 13a7c83a3..d5af6b506 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -41,14 +41,15 @@ pub struct Enode { address: Address, idx: usize, ip: String, + port: u16, } impl ToString for Enode { fn to_string(&self) -> String { // Example: // enode://30ccdeb8c31972f570e4eea0673cd08cbe7cefc5de1d70119b39c63b1cba33b48e494e9916c0d1eab7d296774f3573da46025d1accdef2f3690bc9e6659a34b4@192.168.0.101:30300 - let port = 30300usize + self.idx; - format!("enode://{:x}@{}:{}", self.public, self.ip, port) + + format!("enode://{:x}@{}:{}", self.public, self.ip, self.port) } } @@ -56,6 +57,7 @@ fn generate_enodes( num_nodes: usize, private_keys: Vec, external_ip: Option<&str>, + port_base: u16, ) -> BTreeMap { let mut map = BTreeMap::new(); for i in 0..num_nodes { @@ -85,6 +87,7 @@ fn generate_enodes( address, idx, ip: ip.into(), + port: port_base + i as u16, }, ); } @@ -437,12 +440,11 @@ fn main() { ) }); - let port_base: Option = matches.value_of("port_base").map_or(None, |v| { - Some( + + let port_base: u16 = matches.value_of("port_base").map( |v| { v.parse::() - .expect("metrics_port need to be an integer port definition 1-65555"), - ) - }); + .expect("metrics_port need to be an integer port definition 1-65555") + }).unwrap(); let port_base_rpc: Option = matches.value_of("port_base_rpc").map_or(None, |v| { Some( @@ -487,7 +489,7 @@ fn main() { assert!(private_keys.len() == num_nodes_total); }; - let enodes_map = generate_enodes(num_nodes_total, private_keys, external_ip); + let enodes_map = generate_enodes(num_nodes_total, private_keys, external_ip, port_base); let mut rng = rand::thread_rng(); let pub_keys = enodes_to_pub_keys(&enodes_map); @@ -525,7 +527,7 @@ fn main() { tx_queue_per_sender.clone(), metrics_port_base, metrics_interface, - port_base.unwrap(), + port_base, port_base_rpc.unwrap(), port_base_ws.unwrap() )) @@ -565,7 +567,7 @@ fn main() { tx_queue_per_sender.clone(), metrics_port_base, metrics_interface, - port_base.unwrap(), + port_base, port_base_rpc.unwrap(), port_base_ws.unwrap(), )) From 1032b45ddeec669be4cb2448aee081f7a717e201 Mon Sep 17 00:00:00 2001 From: davidf Date: Thu, 29 Feb 2024 15:35:44 +0100 Subject: [PATCH 222/687] Switching to patched parity-daemonize version without "failure" dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0a824f01a..79be567b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ node-filter = { path = "crates/net/node-filter" } parity-crypto = { version = "0.6.2", features = [ "publickey" ] } rlp = { version = "0.4.6" } cli-signer= { path = "crates/util/cli-signer" } -parity-daemonize = "0.3" +parity-daemonize = { git = "https://github.com/DMDcoin/parity-daemonize.git", rev = "1d0802cd6880b0b914c6e82ba274bb3fc63238fb" } parity-local-store = { path = "crates/concensus/miner/local-store" } parity-runtime = { path = "crates/runtime/runtime" } parity-rpc = { path = "crates/rpc" } From 9ee4471da4743204757df97680d05a6109da25c1 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 29 Feb 2024 15:46:21 +0100 Subject: [PATCH 223/687] The "failure" crate is now eliminated from the lock file as well --- Cargo.lock | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9ef996c4..2b6ec9600 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1694,28 +1694,6 @@ dependencies = [ "vm", ] -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", - "failure_derive", -] - -[[package]] -name = "failure_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" -dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", - "syn 1.0.94", - "synstructure", -] - [[package]] name = "fake-fetch" version = "0.0.1" @@ -3251,14 +3229,13 @@ dependencies = [ [[package]] name = "parity-daemonize" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69b1910b2793ff52713fca0a4ee92544ebec59ccd218ea74560be6f947b4ca77" +source = "git+https://github.com/DMDcoin/parity-daemonize.git?rev=1d0802cd6880b0b914c6e82ba274bb3fc63238fb#1d0802cd6880b0b914c6e82ba274bb3fc63238fb" dependencies = [ "ansi_term 0.11.0", - "failure", "libc", "log", "mio", + "thiserror", ] [[package]] From b57aa5693f6b93de52780def969db642726a58bf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 11 Mar 2024 15:30:09 +0100 Subject: [PATCH 224/687] fixed test test_threshold_encryption_multiple --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index d5af6b506..be4ec5c6d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -647,7 +647,7 @@ mod tests { let num_nodes = 4; let t = 1; - let enodes = generate_enodes(num_nodes, Vec::new(), None); + let enodes = generate_enodes(num_nodes, Vec::new(), None, 30300); let pub_keys = enodes_to_pub_keys(&enodes); let mut rng = rand::thread_rng(); From 3e04f9c4c3c47633c0221e1e5165a97d9196e3ea Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 11 Mar 2024 17:12:49 +0100 Subject: [PATCH 225/687] fixed a bug concerning used port and port used in reserved peers, simplified some things by using Vec instead of BTreeMap. --- .../src/keygen_history_helpers.rs | 20 ++--- .../hbbft/hbbft_config_generator/src/main.rs | 85 +++++++++---------- 2 files changed, 51 insertions(+), 54 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs index f627499d7..095011159 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs @@ -93,15 +93,13 @@ pub fn generate_keygens( (sync_keygen, parts, acks) } -pub fn enodes_to_pub_keys( - enodes: &BTreeMap, -) -> Arc> { +pub fn enodes_to_pub_keys(enodes: &Vec) -> Arc> { Arc::new( enodes .iter() - .map(|(n, e)| { + .map(|e| { ( - n.clone(), + e.public.clone(), KeyPairWrapper { public: e.public, secret: e.secret.clone(), @@ -156,7 +154,7 @@ impl KeyGenHistoryData { pub fn key_sync_history_data( parts: &BTreeMap, acks: &BTreeMap>, - enodes: &BTreeMap, + enodes: &Vec, include_validators_only: bool, ) -> KeyGenHistoryData { let mut data = KeyGenHistoryData { @@ -173,10 +171,13 @@ pub fn key_sync_history_data( let mut acks_total_bytes = 0; let mut num_acks = 0; - let ids = enodes.keys(); + //let ids: Vec = enodes.iter().map(|e| e.public.clone()).collect(); + let mut staking_counter = 1; // Add Parts and Acks in strict order - for id in ids { + for enode in enodes.iter() { + let id = &enode.public; + // if there is no part available for this node, // then the it is not a initial validator. @@ -189,8 +190,7 @@ pub fn key_sync_history_data( data.staking_addresses .push(format!("{:?}", Address::from_low_u64_be(staking_counter))); staking_counter += 1; - data.public_keys - .push(format!("{:?}", enodes.get(id).unwrap().public)); + data.public_keys.push(format!("{:?}", id)); data.ip_addresses .push(format!("{:?}", H128::from_low_u64_be(1))); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index be4ec5c6d..978166c44 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -20,10 +20,7 @@ use clap::{App, Arg}; use ethstore::{KeyFile, SafeAccount}; use keygen_history_helpers::{enodes_to_pub_keys, generate_keygens, key_sync_history_data}; use parity_crypto::publickey::{Address, Generator, KeyPair, Public, Random, Secret}; -use std::{ - collections::BTreeMap, convert::TryInto, fmt::Write, fs, num::NonZeroU32, str::FromStr, - sync::Arc, -}; +use std::{convert::TryInto, fmt::Write, fs, num::NonZeroU32, str::FromStr}; use toml::{map::Map, Value}; pub fn create_account() -> (Secret, Public, Address) { @@ -48,7 +45,7 @@ impl ToString for Enode { fn to_string(&self) -> String { // Example: // enode://30ccdeb8c31972f570e4eea0673cd08cbe7cefc5de1d70119b39c63b1cba33b48e494e9916c0d1eab7d296774f3573da46025d1accdef2f3690bc9e6659a34b4@192.168.0.101:30300 - + format!("enode://{:x}@{}:{}", self.public, self.ip, self.port) } } @@ -58,8 +55,8 @@ fn generate_enodes( private_keys: Vec, external_ip: Option<&str>, port_base: u16, -) -> BTreeMap { - let mut map = BTreeMap::new(); +) -> Vec { + let mut map = Vec::new(); for i in 0..num_nodes { // Note: node 0 is a regular full node (not a validator) in the testnet setup, so we start at index 1. let idx = i + 1; @@ -79,26 +76,23 @@ fn generate_enodes( create_account() }; println!("Debug, Secret: {:?}", secret); - map.insert( + map.push(Enode { + secret, public, - Enode { - secret, - public, - address, - idx, - ip: ip.into(), - port: port_base + i as u16, - }, - ); + address, + idx, + ip: ip.into(), + port: port_base + idx as u16, + }); } // the map has the element order by their public key. // we reassign the idx here, so the index of the nodes follows // the same order like everything else. - let mut new_index = 1; - for public in map.iter_mut() { - public.1.idx = new_index; - new_index = new_index + 1; - } + // let mut new_index = 1; + // for public in map.iter_mut() { + // public.1.idx = new_index; + // new_index = new_index + 1; + // } map } @@ -136,7 +130,10 @@ fn to_toml( } let mut network = Map::new(); - network.insert("port".into(), Value::Integer((base_port as usize + i) as i64)); + network.insert( + "port".into(), + Value::Integer((base_port as usize + i) as i64), + ); match config_type { ConfigType::PosdaoSetup => { network.insert( @@ -185,12 +182,18 @@ fn to_toml( "traces", ]); rpc.insert("apis".into(), apis); - rpc.insert("port".into(), Value::Integer((base_rpc_port as usize + i) as i64)); + rpc.insert( + "port".into(), + Value::Integer((base_rpc_port as usize + i) as i64), + ); let mut websockets = Map::new(); websockets.insert("interface".into(), Value::String("all".into())); websockets.insert("origins".into(), to_toml_array(vec!["all"])); - websockets.insert("port".into(), Value::Integer((base_ws_port as usize + i) as i64)); + websockets.insert( + "port".into(), + Value::Integer((base_ws_port as usize + i) as i64), + ); let mut ipc = Map::new(); ipc.insert("disable".into(), Value::Boolean(true)); @@ -440,11 +443,13 @@ fn main() { ) }); - - let port_base: u16 = matches.value_of("port_base").map( |v| { + let port_base: u16 = matches + .value_of("port_base") + .map(|v| { v.parse::() .expect("metrics_port need to be an integer port definition 1-65555") - }).unwrap(); + }) + .unwrap(); let port_base_rpc: Option = matches.value_of("port_base_rpc").map_or(None, |v| { Some( @@ -489,30 +494,22 @@ fn main() { assert!(private_keys.len() == num_nodes_total); }; - let enodes_map = generate_enodes(num_nodes_total, private_keys, external_ip, port_base); + let enodes = generate_enodes(num_nodes_total, private_keys, external_ip, port_base); let mut rng = rand::thread_rng(); - let pub_keys = enodes_to_pub_keys(&enodes_map); + //let pub_keys = enodes_to_pub_keys(&enodes_map); - // we only need the first x pub_keys - let pub_keys_for_key_gen_btree = pub_keys - .iter() - .take(num_nodes_validators) - .map(|x| (x.0.clone(), x.1.clone())) - .collect(); + let pub_keys_for_key_gen_btree = enodes_to_pub_keys(&enodes); let (_sync_keygen, parts, acks) = generate_keygens( - Arc::new(pub_keys_for_key_gen_btree), + pub_keys_for_key_gen_btree.clone(), &mut rng, (num_nodes_validators - 1) / 3, ); let mut reserved_peers = String::new(); - for pub_key in pub_keys.iter() { - let our_id = pub_key.0; - - let enode = enodes_map.get(our_id).expect("validator id must be mapped"); + for enode in enodes.iter() { writeln!(&mut reserved_peers, "{}", enode.to_string()) .expect("enode should be written to the reserved peers string"); let i = enode.idx; @@ -529,7 +526,7 @@ fn main() { metrics_interface, port_base, port_base_rpc.unwrap(), - port_base_ws.unwrap() + port_base_ws.unwrap(), )) .expect("TOML string generation should succeed"); fs::write(file_name, toml_string).expect("Unable to write config file"); @@ -580,7 +577,7 @@ fn main() { // Write the password file fs::write("password.txt", "test").expect("Unable to write password.txt file"); - let key_sync_file_validators_only = key_sync_history_data(&parts, &acks, &enodes_map, true); + let key_sync_file_validators_only = key_sync_history_data(&parts, &acks, &enodes, true); // only pass over enodes in the enodes_map that are also available for acks and parts. fs::write( "keygen_history.json", @@ -590,7 +587,7 @@ fn main() { fs::write( "nodes_info.json", - key_sync_history_data(&parts, &acks, &enodes_map, false).to_json(), + key_sync_history_data(&parts, &acks, &enodes, false).to_json(), ) .expect("Unable to write nodes_info data file"); From 737f2291e23333f972988af47e0a55365f80b426 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Mar 2024 10:09:14 +0100 Subject: [PATCH 226/687] fork: reporting if block number could not get read --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index c637a3a51..a6b202a4d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -126,6 +126,8 @@ impl HbbftState { self.honey_badger = Some(self.new_honey_badger(network_info.clone())?); self.network_info = Some(network_info); } + } else { + error!(target: "engine", "fork: could not get block number for block_id: {:?}", block_id); } // From 9b5286a204fad2a2d8b6d6be3ec5cbb63a20e4eb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Mar 2024 11:02:34 +0100 Subject: [PATCH 227/687] log "hbbft_message_memorium report new epoch" is now Info Level --- crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 44acbd521..49d5dfff9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -237,6 +237,8 @@ impl HbbftNetworkForkManager { panic!("HbbftNetworkForkManager is already initialized"); } + debug!(target: "engine", "hbbft-hardfork: initializing HbbftNetworkForkManager. Startup block number: {}", startup_block_number); + self.own_id = own_id; fork_definition.sort_by_key(|fork| fork.block_number_start); From d9b90535d149653d377f08d828125f305875194d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Mar 2024 23:41:34 +0100 Subject: [PATCH 228/687] log level decreased for hbbft_message_memorium -> report new epoch: --- crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index ebe87422b..184c187d2 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -949,7 +949,7 @@ impl HbbftMessageMemorium { // report that hbbft has switched to a new staking epoch pub fn report_new_epoch(&mut self, staking_epoch: u64, staking_epoch_start_block: u64) { - warn!(target: "hbbft_message_memorium", "report new epoch: {}", staking_epoch); + debug!(target: "hbbft_message_memorium", "report new epoch: {}", staking_epoch); self.latest_epoch = staking_epoch; self.latest_epoch_start_block = staking_epoch_start_block; if let Ok(epoch_history_index) = self From 4e791aff91a705bf94c7a582b897430e51eb3ac4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 17 Mar 2024 18:32:48 +0100 Subject: [PATCH 229/687] fork: debug output during config --- .../hbbft/hbbft_network_fork_manager.rs | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 49d5dfff9..f5ab2df08 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -231,16 +231,23 @@ impl HbbftNetworkForkManager { &mut self, own_id: NodeId, startup_block_number: u64, - mut fork_definition: Vec, + fork_definition_config: Vec, ) { if self.is_init { panic!("HbbftNetworkForkManager is already initialized"); } - debug!(target: "engine", "hbbft-hardfork: initializing HbbftNetworkForkManager. Startup block number: {}", startup_block_number); + if fork_definition_config.len() == 0 { + + self.is_init = true; + return; + } + + debug!(target: "engine", "hbbft-hardfork: initializing HbbftNetworkForkManager. Startup block number: {} total forks defined: {}", startup_block_number, fork_definition.len()); self.own_id = own_id; + let mut fork_definition = fork_definition_config.clone(); fork_definition.sort_by_key(|fork| fork.block_number_start); // the fork definition can contain @@ -265,11 +272,23 @@ impl HbbftNetworkForkManager { continue; } + let fork = HbbftFork::from_definition(fork_def); + debug!(target: "engine", "hbbft-hardfork: added upcomming fork - add block {:?}", fork.start_block); + self.pending_forks - .push_back(HbbftFork::from_definition(fork_def)); + .push_back(fork); + } else if fork_def.block_number_start <= startup_block_number { + + let fork = HbbftFork::from_definition(fork_def); + debug!(target: "engine", "hbbft-hardfork: added upcomming fork - add block {:?}", fork.start_block); + + self.pending_forks + .push_back(fork); } } + self.is_init = true; + // self.fork_definition.iter().filter(predicate).for_each(|fork| { // self.pending_forks.push_back(HbbftFork { // start_timestamp: 0, From 3824d779b41d902a39aa1efed71d40156af283bc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 17 Mar 2024 19:15:39 +0100 Subject: [PATCH 230/687] fixed compile error --- crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index f5ab2df08..56763149e 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -243,7 +243,7 @@ impl HbbftNetworkForkManager { return; } - debug!(target: "engine", "hbbft-hardfork: initializing HbbftNetworkForkManager. Startup block number: {} total forks defined: {}", startup_block_number, fork_definition.len()); + debug!(target: "engine", "hbbft-hardfork: initializing HbbftNetworkForkManager. Startup block number: {} total forks defined: {}", startup_block_number, fork_definition_config.len()); self.own_id = own_id; From 961a677be3d51862de1295975d520d50c9004af2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 17 Mar 2024 21:06:40 +0100 Subject: [PATCH 231/687] fixed fork manager fork starts in the future --- .../engines/hbbft/hbbft_network_fork_manager.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 56763149e..4ca7b9aaa 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -277,7 +277,7 @@ impl HbbftNetworkForkManager { self.pending_forks .push_back(fork); - } else if fork_def.block_number_start <= startup_block_number { + } else if fork_def.block_number_start >= startup_block_number { let fork = HbbftFork::from_definition(fork_def); debug!(target: "engine", "hbbft-hardfork: added upcomming fork - add block {:?}", fork.start_block); @@ -288,21 +288,6 @@ impl HbbftNetworkForkManager { } self.is_init = true; - - // self.fork_definition.iter().filter(predicate).for_each(|fork| { - // self.pending_forks.push_back(HbbftFork { - // start_timestamp: 0, - // start_block: fork.block_number_start, - // is_finished: false, - // end_timestamp: 0, - // end_block: 0, - // validator_set: HbbftForkKeys { - // validators: fork.validators.clone(), - // parts: Vec::new(), - // acks: Vec::new(), - // }, - // }); - // }); } pub fn new() -> HbbftNetworkForkManager { From cebd95debd4e91469dfd01a8f90966c82ea4a6c0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 18 Mar 2024 14:59:34 +0100 Subject: [PATCH 232/687] early epoch manager: improved logging for the early epoch manager (ConnectivityTracker) --- .../engines/hbbft/hbbft_early_epoch_end_manager.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 5646fa578..5ff30bcf0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -137,18 +137,21 @@ impl HbbftEarlyEpochEndManager { continue; }; - if let Ok(reported) = is_connectivity_loss_reported( + match is_connectivity_loss_reported( client, block_id, signing_address, epoch, validator_address, ) { - if reported { - result.push(validator.clone()); + Ok(reported) => { + if reported { + result.push(validator.clone()); + } + } + Err(e) => { + error!(target: "engine", "early-epoch-end: could not get reported status for validator {validator:?}. call error: {e:?}"); } - } else { - error!(target: "engine", "early-epoch-end: could not get reported status for validator {validator:?}"); } } From e28d22eefaadcf126216b061d1a9a21b595e363a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 18 Mar 2024 19:14:57 +0100 Subject: [PATCH 233/687] commented out implementation for get_current_flagged_validators_from_contract, since we are interested only if we got other nodes flagged or not. --- .../contracts/connectivity_tracker_hbbft.rs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index b99958f17..2bef3ce7e 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -45,20 +45,22 @@ pub fn is_connectivity_loss_reported( )?); } -pub fn get_current_flagged_validators_from_contract( - client: &dyn EngineClient, - block_id: BlockId, -) -> Result, CallError> { - let c = BoundContract::bind( - client, - block_id, - *CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, - ); - return Ok(call_const_connectivity_tracker_hbbft!( - c, - get_flagged_validators - )?); -} +// currently not required for operation. +// we just check if "we" have reported the validator. +// pub fn get_current_flagged_validators_from_contract( +// client: &dyn EngineClient, +// block_id: BlockId, +// ) -> Result, CallError> { +// let c = BoundContract::bind( +// client, +// block_id, +// *CONNECTIVITY_TRACKER_HBBFT_CONTRACT_ADDRESS, +// ); +// return Ok(call_const_connectivity_tracker_hbbft!( +// c, +// get_flagged_validators +// )?); +// } fn get_block_data(client: &dyn EngineClient) -> (u64, H256) { if let Some(block_number) = client.block_number(BlockId::Latest) { From e0b350c05dc012afe0893e49180a7348580558d6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 18 Mar 2024 19:24:04 +0100 Subject: [PATCH 234/687] decreased log level for: "Block creation: Batch received for" --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index f3f1b088b..fc0514881 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -503,7 +503,7 @@ impl HoneyBadgerBFT { }) .collect(); - info!(target: "consensus", "Block creation: Batch received for epoch {}, total {} contributions, with {} unique transactions.", batch.epoch, batch + debug!(target: "consensus", "Block creation: Batch received for epoch {}, total {} contributions, with {} unique transactions.", batch.epoch, batch .contributions.iter().fold(0, |i, c| i + c.1.transactions.len()), batch_txns.len()); // Make sure the resulting transactions do not contain nonces out of order. From 4c621f79c40c3b3f34441dea5296970df6706ed4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 21 Mar 2024 22:28:55 +0100 Subject: [PATCH 235/687] - debug output of forked validators. --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index a6b202a4d..90e262769 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -44,6 +44,7 @@ pub(crate) struct HbbftState { public_master_key: Option, current_posdao_epoch: u64, current_posdao_epoch_start_block: u64, + last_fork_start_block: Option, last_posdao_epoch_start_block: Option, future_messages_cache: BTreeMap>, fork_manager: HbbftNetworkForkManager, @@ -58,6 +59,7 @@ impl HbbftState { current_posdao_epoch: 0, current_posdao_epoch_start_block: 0, last_posdao_epoch_start_block: None, + last_fork_start_block: None, future_messages_cache: BTreeMap::new(), fork_manager: HbbftNetworkForkManager::new(), } @@ -103,6 +105,7 @@ impl HbbftState { } } + let mut has_forked = false; // https://github.com/DMDcoin/diamond-node/issues/98 // check here if we are in a fork scenario. // in a fork scenario, the new honeybadger keys will come from the config, @@ -124,14 +127,23 @@ impl HbbftState { self.public_master_key = Some(network_info.public_key_set().public_key()); self.honey_badger = Some(self.new_honey_badger(network_info.clone())?); + + for x in network_info.validator_set().all_ids() { + info!(target: "engine", "Validator: {:?}", x); + } + self.network_info = Some(network_info); + self.last_fork_start_block = Some(last_block_number); + + + has_forked = true; } } else { error!(target: "engine", "fork: could not get block number for block_id: {:?}", block_id); } // - if !force && self.current_posdao_epoch == target_posdao_epoch { + if !force && self.current_posdao_epoch == target_posdao_epoch && !has_forked { // hbbft state is already up to date. // @todo Return proper error codes. return Some(()); From 9e563e66ed3e49f8e8b5b71efae648bb2e73335f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 28 Mar 2024 10:08:50 +0100 Subject: [PATCH 236/687] fixed bug where num_nodes_validators was not respected anymore. --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 978166c44..b6e99bc58 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -32,6 +32,7 @@ pub fn create_account() -> (Secret, Public, Address) { ) } +#[derive(Clone)] pub struct Enode { secret: Secret, public: Public, @@ -499,7 +500,9 @@ fn main() { //let pub_keys = enodes_to_pub_keys(&enodes_map); - let pub_keys_for_key_gen_btree = enodes_to_pub_keys(&enodes); + let enodes_for_key : Vec = enodes.iter().take(num_nodes_validators).map(|e| e.clone()).collect(); + + let pub_keys_for_key_gen_btree = enodes_to_pub_keys(&enodes_for_key); let (_sync_keygen, parts, acks) = generate_keygens( pub_keys_for_key_gen_btree.clone(), From 0f6763991390c94f97f6cca05079a68e2bd1275e Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 4 Apr 2024 11:17:48 +0200 Subject: [PATCH 237/687] Manually removed the "failure" dependency from the EIP-712 crate --- crates/util/EIP-712/Cargo.lock | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/crates/util/EIP-712/Cargo.lock b/crates/util/EIP-712/Cargo.lock index aeb4860cb..8833269a3 100644 --- a/crates/util/EIP-712/Cargo.lock +++ b/crates/util/EIP-712/Cargo.lock @@ -105,7 +105,6 @@ version = "0.1.0" dependencies = [ "ethabi", "ethereum-types", - "failure", "indexmap", "itertools", "keccak-hash", @@ -167,28 +166,6 @@ dependencies = [ "uint", ] -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", - "failure_derive", -] - -[[package]] -name = "failure_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" -dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", - "synstructure", -] - [[package]] name = "fixed-hash" version = "0.6.1" From 13b94051b41a716fb83e3ead44097107e0403d8a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 12 Apr 2024 13:32:39 +0200 Subject: [PATCH 238/687] .gitignore: add fork_example.json --- .../ethcore/src/engines/hbbft/hbbft_config_generator/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/.gitignore b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/.gitignore index e90ae314c..0c65d01ed 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/.gitignore +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/.gitignore @@ -13,3 +13,4 @@ password.txt reserved-peers rpc_node.toml nodes_info.json +fork_example.json From 61363ccb37dc87cfc95d65f36f0a645306d29a26 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 22 Apr 2024 17:28:39 +0200 Subject: [PATCH 239/687] cargo fmt --all -- --config imports_granularity=Crate --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 6 +++++- .../src/engines/hbbft/hbbft_network_fork_manager.rs | 8 ++------ crates/ethcore/src/engines/hbbft/hbbft_state.rs | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index b6e99bc58..714fd9988 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -500,7 +500,11 @@ fn main() { //let pub_keys = enodes_to_pub_keys(&enodes_map); - let enodes_for_key : Vec = enodes.iter().take(num_nodes_validators).map(|e| e.clone()).collect(); + let enodes_for_key: Vec = enodes + .iter() + .take(num_nodes_validators) + .map(|e| e.clone()) + .collect(); let pub_keys_for_key_gen_btree = enodes_to_pub_keys(&enodes_for_key); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 4ca7b9aaa..36d6e43b8 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -238,7 +238,6 @@ impl HbbftNetworkForkManager { } if fork_definition_config.len() == 0 { - self.is_init = true; return; } @@ -275,15 +274,12 @@ impl HbbftNetworkForkManager { let fork = HbbftFork::from_definition(fork_def); debug!(target: "engine", "hbbft-hardfork: added upcomming fork - add block {:?}", fork.start_block); - self.pending_forks - .push_back(fork); + self.pending_forks.push_back(fork); } else if fork_def.block_number_start >= startup_block_number { - let fork = HbbftFork::from_definition(fork_def); debug!(target: "engine", "hbbft-hardfork: added upcomming fork - add block {:?}", fork.start_block); - self.pending_forks - .push_back(fork); + self.pending_forks.push_back(fork); } } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 90e262769..90d55a913 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -128,13 +128,12 @@ impl HbbftState { self.public_master_key = Some(network_info.public_key_set().public_key()); self.honey_badger = Some(self.new_honey_badger(network_info.clone())?); - for x in network_info.validator_set().all_ids() { + for x in network_info.validator_set().all_ids() { info!(target: "engine", "Validator: {:?}", x); } self.network_info = Some(network_info); self.last_fork_start_block = Some(last_block_number); - has_forked = true; } From 1eecd4211f35002ee8057c0f242cfbf535a609be Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 22 Apr 2024 21:46:16 +0200 Subject: [PATCH 240/687] fixed hbbft_deserialization_forks test. ACKS were not provided as Array of Arrays. --- crates/ethjson/src/spec/hbbft.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethjson/src/spec/hbbft.rs b/crates/ethjson/src/spec/hbbft.rs index ec7d5215e..140195813 100644 --- a/crates/ethjson/src/spec/hbbft.rs +++ b/crates/ethjson/src/spec/hbbft.rs @@ -148,7 +148,7 @@ mod tests { "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678" ], "parts": ["19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"], - "acks": ["19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"] + "acks": [["19585436b7d97298a751e2a6020c30677497772013001420c0a6aea5790347bdf5531c1387be685a232b01ec614913b18da0a6cbcd1074f1733f902a7eb656e9"]] } ] } From 83b66d70247d1dfb244eb120413720674b7727a0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 28 Apr 2024 20:55:22 +0200 Subject: [PATCH 241/687] validator logging for fork + fix not reinitializing --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 90d55a913..52e293f03 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -105,7 +105,6 @@ impl HbbftState { } } - let mut has_forked = false; // https://github.com/DMDcoin/diamond-node/issues/98 // check here if we are in a fork scenario. // in a fork scenario, the new honeybadger keys will come from the config, @@ -125,6 +124,10 @@ impl HbbftState { ) { info!(target: "engine", "Forking at block {last_block_number}, starting new honeybadger instance with new validator set."); + for id in network_info.validator_set().all_ids() { + info!(target: "engine", "Fork Validator: {}", id); + } + self.public_master_key = Some(network_info.public_key_set().public_key()); self.honey_badger = Some(self.new_honey_badger(network_info.clone())?); @@ -134,15 +137,16 @@ impl HbbftState { self.network_info = Some(network_info); self.last_fork_start_block = Some(last_block_number); + self.current_posdao_epoch_start_block = last_block_number; - has_forked = true; + return Some(()); } } else { error!(target: "engine", "fork: could not get block number for block_id: {:?}", block_id); } // - if !force && self.current_posdao_epoch == target_posdao_epoch && !has_forked { + if !force && self.current_posdao_epoch == target_posdao_epoch { // hbbft state is already up to date. // @todo Return proper error codes. return Some(()); From 660b1552fd01181f950ff2420c53a0e3276d526f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 1 May 2024 11:32:22 +0200 Subject: [PATCH 242/687] added debug log for initialize_synckeygen. --- crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index 94c3724db..a8a642d60 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -229,6 +229,7 @@ pub fn initialize_synckeygen( block_id: BlockId, validator_type: ValidatorType, ) -> Result, CallError> { + debug!(target: "engine", "Initializing SyncKeyGen with block_id: {:?}", block_id); let vmap = get_validator_pubkeys(&*client, block_id, validator_type)?; let pub_keys: BTreeMap<_, _> = vmap .values() From 786ba14fa289a33ceee047c509f84b07f26dea7d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 18 May 2024 09:56:34 +0200 Subject: [PATCH 243/687] encode ACKS ad PARTs as hex for Key Gen JSON https://github.com/DMDcoin/diamond-node/issues/112 --- Cargo.lock | 1 + .../src/engines/hbbft/hbbft_config_generator/Cargo.toml | 4 +++- .../hbbft_config_generator/src/keygen_history_helpers.rs | 4 ++++ .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d33c539bf..60608d893 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2150,6 +2150,7 @@ dependencies = [ "rustc-hex 2.1.0", "serde", "serde_json", + "serde_with", "toml 0.5.8", ] diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml index 91ef228f6..b5a162b7e 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml @@ -4,7 +4,8 @@ name = "hbbft_config_generator" version = "0.0.1" license = "GPL-3.0" authors = [ - "David Forstenlechner " + "David Forstenlechner ", + "Thomas Haller " ] [dependencies] @@ -22,6 +23,7 @@ rand = "0.7.3" rustc-hex = "2.1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +serde_with = { version = "3.6", features = [ "hex", "std", "macros" ] } toml = "0.5.6" [dev-dependencies] diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs index 095011159..e86d8cad4 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs @@ -5,6 +5,7 @@ use hbbft::sync_key_gen::{AckOutcome, Part, PartOutcome, PublicKey, SecretKey, S use parity_crypto::publickey::{public_to_address, Address, Public, Secret}; use serde::{Deserialize, Serialize}; use std::{collections::BTreeMap, sync::Arc}; +use serde_with::serde_as; #[derive(Clone)] pub struct KeyPairWrapper { @@ -110,13 +111,16 @@ pub fn enodes_to_pub_keys(enodes: &Vec) -> Arc, staking_addresses: Vec, public_keys: Vec, ip_addresses: Vec, + #[serde_as(as = "Vec")] parts: Vec>, + #[serde_as(as = "Vec>")] acks: Vec>>, } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 714fd9988..e5084f94a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -11,6 +11,7 @@ extern crate parity_crypto; extern crate rand; extern crate rustc_hex; extern crate serde; +extern crate serde_with; extern crate serde_json; extern crate toml; From 330f2fb184607913c2e0ab6245ed50f9d97ad625 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 21 May 2024 12:24:47 +0200 Subject: [PATCH 244/687] cargo fmt --all -- --config imports_granularity=Crate --- .../hbbft/hbbft_config_generator/src/keygen_history_helpers.rs | 2 +- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs index e86d8cad4..dba6e142a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs @@ -4,8 +4,8 @@ use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::sync_key_gen::{AckOutcome, Part, PartOutcome, PublicKey, SecretKey, SyncKeyGen}; use parity_crypto::publickey::{public_to_address, Address, Public, Secret}; use serde::{Deserialize, Serialize}; -use std::{collections::BTreeMap, sync::Arc}; use serde_with::serde_as; +use std::{collections::BTreeMap, sync::Arc}; #[derive(Clone)] pub struct KeyPairWrapper { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index e5084f94a..3c7f83c10 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -11,8 +11,8 @@ extern crate parity_crypto; extern crate rand; extern crate rustc_hex; extern crate serde; -extern crate serde_with; extern crate serde_json; +extern crate serde_with; extern crate toml; mod keygen_history_helpers; From 844321ed048f3e8b8bc5f6cc7bf6ff3d7584b81c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 18 Jun 2024 21:59:35 +0200 Subject: [PATCH 245/687] pump arrayvec = "0.7" --- Cargo.lock | 8 +++++++- bin/oe/logger/Cargo.toml | 2 +- bin/oe/logger/src/rotating.rs | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edc57c6ad..78d0d30fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,6 +133,12 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "assert_matches" version = "1.3.0" @@ -1405,7 +1411,7 @@ name = "ethcore-logger" version = "1.12.0" dependencies = [ "ansi_term 0.10.2", - "arrayvec 0.4.12", + "arrayvec 0.7.4", "atty", "env_logger 0.5.13", "lazy_static", diff --git a/bin/oe/logger/Cargo.toml b/bin/oe/logger/Cargo.toml index 3e9655a25..9c388dbbe 100644 --- a/bin/oe/logger/Cargo.toml +++ b/bin/oe/logger/Cargo.toml @@ -13,5 +13,5 @@ lazy_static = "1.0" regex = "1.0" time = "0.1" parking_lot = "0.11.1" -arrayvec = "0.4" +arrayvec = "0.7" ansi_term = "0.10" diff --git a/bin/oe/logger/src/rotating.rs b/bin/oe/logger/src/rotating.rs index 7a00c85c3..e2b0567ce 100644 --- a/bin/oe/logger/src/rotating.rs +++ b/bin/oe/logger/src/rotating.rs @@ -50,7 +50,7 @@ pub struct RotatingLogger { /// Defined logger levels levels: String, /// Logs array. Latest log is always at index 0 - logs: RwLock>, + logs: RwLock>, } impl RotatingLogger { @@ -59,7 +59,7 @@ impl RotatingLogger { pub fn new(levels: String) -> Self { RotatingLogger { levels: levels, - logs: RwLock::new(ArrayVec::<[_; LOG_SIZE]>::new()), + logs: RwLock::new(ArrayVec::<_, LOG_SIZE>::new()), } } @@ -78,7 +78,7 @@ impl RotatingLogger { } /// Return logs - pub fn logs(&self) -> RwLockReadGuard> { + pub fn logs(&self) -> RwLockReadGuard> { self.logs.read() } } From 767ee924e9ead90a595e73b2495f98e5caf6b1b0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 18 Jun 2024 21:59:48 +0200 Subject: [PATCH 246/687] cleanup of unused imports --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 1 - crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index fc0514881..f2ea21420 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1,7 +1,6 @@ use super::{ block_reward_hbbft::BlockRewardContract, hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, - hbbft_network_fork_manager::HbbftNetworkForkManager, }; use crate::{ client::BlockChainClient, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 36d6e43b8..d77d91faa 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -3,10 +3,9 @@ use std::{ sync::Arc, }; -use ethereum_types::{Address, H512}; +use ethereum_types::H512; use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::{ - crypto::PublicKeySet, sync_key_gen::{Ack, AckOutcome, Part, PartOutcome, SyncKeyGen}, util::max_faulty, NetworkInfo, From 6bdaf9c1c521e4db9f961a626fa182d652923211 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 Jun 2024 09:00:51 +0200 Subject: [PATCH 247/687] spec generation: removed gas floor target, decreased min gas price to 1000 wei. --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 3c7f83c10..66083b12b 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -231,11 +231,10 @@ fn to_toml( } mining.insert("force_sealing".into(), Value::Boolean(true)); - mining.insert("min_gas_price".into(), Value::Integer(1000000000)); - mining.insert( - "gas_floor_target".into(), - Value::String("1000000000".into()), - ); + // we put an extremly low min gas price in the config + // the min gas price is gathered from the DAO + // this makes sure that the min_gas_price wont be higher then the gas pricce the DAO decides. + mining.insert("min_gas_price".into(), Value::Integer(1000)); mining.insert("reseal_on_txs".into(), Value::String("none".into())); mining.insert("reseal_min_period".into(), Value::Integer(0)); From 16fddd364c2579a42bbb44235298538e08516317 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 Jun 2024 09:15:06 +0200 Subject: [PATCH 248/687] hbbft config generation: reduced default logging level for engine from trace to debug --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 66083b12b..0a8966068 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -251,7 +251,7 @@ fn to_toml( // Value::String("txqueue=trace,consensus=debug,engine=trace,own_tx=trace,miner=trace,tx_filter=trace".into()) misc.insert( "logging".into(), - Value::String("txqueue=info,consensus=debug,engine=trace,tx_own=trace".into()), + Value::String("txqueue=info,consensus=debug,engine=debug,tx_own=trace".into()), ); misc.insert("log_file".into(), Value::String("diamond-node.log".into())); From 6f636f4e157cfa697ca740ba7a4ac1b848ba11bb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Jun 2024 21:10:35 +0200 Subject: [PATCH 249/687] remove currfently unused API from generated network configs --- .../hbbft/hbbft_config_generator/src/main.rs | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 0a8966068..81ebffd04 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -104,6 +104,7 @@ fn to_toml_array(vec: Vec<&str>) -> Value { fn to_toml( i: usize, + open_ports: bool, config_type: &ConfigType, external_ip: Option<&str>, signer_address: &Address, @@ -116,6 +117,7 @@ fn to_toml( base_ws_port: u16, ) -> Value { let mut parity = Map::new(); + match config_type { ConfigType::PosdaoSetup => { parity.insert("chain".into(), Value::String("./spec/spec.json".into())); @@ -169,33 +171,40 @@ fn to_toml( } let mut rpc = Map::new(); - rpc.insert("interface".into(), Value::String("all".into())); - rpc.insert("cors".into(), to_toml_array(vec!["all"])); - rpc.insert("hosts".into(), to_toml_array(vec!["all"])); - let apis = to_toml_array(vec![ - "web3", - "eth", - "pubsub", - "net", - "parity", - "parity_set", - "parity_pubsub", - "personal", - "traces", - ]); - rpc.insert("apis".into(), apis); - rpc.insert( - "port".into(), - Value::Integer((base_rpc_port as usize + i) as i64), - ); - let mut websockets = Map::new(); - websockets.insert("interface".into(), Value::String("all".into())); - websockets.insert("origins".into(), to_toml_array(vec!["all"])); - websockets.insert( - "port".into(), - Value::Integer((base_ws_port as usize + i) as i64), - ); + + if open_ports { + + rpc.insert("interface".into(), Value::String("all".into())); + rpc.insert("cors".into(), to_toml_array(vec!["all"])); + rpc.insert("hosts".into(), to_toml_array(vec!["all"])); + let apis = to_toml_array(vec![ + "web3", + "eth", + "pubsub", + "net", + "parity", + "parity_pubsub", + "traces", + ]); + rpc.insert("apis".into(), apis); + rpc.insert( + "port".into(), + Value::Integer((base_rpc_port as usize + i) as i64), + ); + + + websockets.insert("interface".into(), Value::String("all".into())); + websockets.insert("origins".into(), to_toml_array(vec!["all"])); + websockets.insert( + "port".into(), + Value::Integer((base_ws_port as usize + i) as i64), + ); + + } else { + rpc.insert("disable".into(), Value::Boolean(true)); + websockets.insert("disable".into(), Value::Boolean(true)); + } let mut ipc = Map::new(); ipc.insert("disable".into(), Value::Boolean(true)); @@ -524,6 +533,7 @@ fn main() { // the unwrap is safe, because there is a default value defined. let toml_string = toml::to_string(&to_toml( i, + false, &config_type, external_ip, &enode.address, @@ -564,6 +574,7 @@ fn main() { // Write rpc node config let rpc_string = toml::to_string(&to_toml( 0, + true, &ConfigType::Rpc, external_ip, &Address::default(), // todo: insert HBBFT Contracts pot here. From f602384b587b8805197ecc35cbddf86a5a96230b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 1 Jul 2024 23:46:04 +0200 Subject: [PATCH 250/687] fixed warnings --- .../hbbft/hbbft_config_generator/src/main.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 81ebffd04..e1dd9ac80 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -174,7 +174,6 @@ fn to_toml( let mut websockets = Map::new(); if open_ports { - rpc.insert("interface".into(), Value::String("all".into())); rpc.insert("cors".into(), to_toml_array(vec!["all"])); rpc.insert("hosts".into(), to_toml_array(vec!["all"])); @@ -193,14 +192,12 @@ fn to_toml( Value::Integer((base_rpc_port as usize + i) as i64), ); - websockets.insert("interface".into(), Value::String("all".into())); websockets.insert("origins".into(), to_toml_array(vec!["all"])); websockets.insert( "port".into(), Value::Integer((base_ws_port as usize + i) as i64), ); - } else { rpc.insert("disable".into(), Value::Boolean(true)); websockets.insert("disable".into(), Value::Boolean(true)); @@ -439,12 +436,12 @@ fn main() { ) }); - let fork_block_number: Option = matches.value_of("fork_block_number").map_or(None, |v| { - Some( - v.parse::() - .expect("fork_block_number need to be of integer type"), - ) - }); + // let fork_block_number: Option = matches.value_of("fork_block_number").map_or(None, |v| { + // Some( + // v.parse::() + // .expect("fork_block_number need to be of integer type"), + // ) + // }); let metrics_port_base: Option = matches.value_of("metrics_port_base").map_or(None, |v| { Some( From 05d9a0c9d559bc285debbfbc4c699079b179aaae Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 4 Jul 2024 22:44:14 +0200 Subject: [PATCH 251/687] pumb ethabi-contract = "16.0.0" --- Cargo.lock | 4 ++-- crates/concensus/miner/Cargo.toml | 2 +- crates/ethcore/Cargo.toml | 2 +- crates/net/node-filter/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78d0d30fa..b10b21bc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1133,9 +1133,9 @@ dependencies = [ [[package]] name = "ethabi-contract" -version = "11.0.0" +version = "16.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d4002f1f77d8233685dafd8589efe1c9dfa63e21ca6c11134372acc7f68032" +checksum = "4632b1b766fbf59872eb7a41e7ebaa10727b7f7000aef5bb626b87e472041c83" [[package]] name = "ethabi-derive" diff --git a/crates/concensus/miner/Cargo.toml b/crates/concensus/miner/Cargo.toml index 309aa1663..f503a72e5 100644 --- a/crates/concensus/miner/Cargo.toml +++ b/crates/concensus/miner/Cargo.toml @@ -19,7 +19,7 @@ common-types = { path = "../../ethcore/types" } error-chain = "0.12" ethabi = "12.0.0" ethabi-derive = { git = 'https://github.com/rimrakhimov/ethabi', branch = 'rimrakhimov/remove-syn-export-span' } -ethabi-contract = "11.0.0" +ethabi-contract = "16.0.0" ethcore-call-contract = { path = "../../vm/call-contract" } ethereum-types = "0.9.2" futures = "0.1" diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index 066131749..d84aaaf13 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -17,7 +17,7 @@ eip-152 = { version = "0.1", path = "../util/EIP-152" } env_logger = { version = "0.5", optional = true } error-chain = { version = "0.12", default-features = false } ethabi = "12.0.0" -ethabi-contract = "11.0.0" +ethabi-contract = "16.0.0" ethabi-derive = { git = 'https://github.com/rimrakhimov/ethabi', branch = 'rimrakhimov/remove-syn-export-span' } ethash = { path = "../concensus/ethash" } ethcore-blockchain = { path = "./blockchain" } diff --git a/crates/net/node-filter/Cargo.toml b/crates/net/node-filter/Cargo.toml index 28d8b5321..0ae43fe1b 100644 --- a/crates/net/node-filter/Cargo.toml +++ b/crates/net/node-filter/Cargo.toml @@ -15,7 +15,7 @@ log = "0.4" parking_lot = "0.11.1" ethabi = "12.0.0" ethabi-derive = { git = 'https://github.com/rimrakhimov/ethabi', branch = 'rimrakhimov/remove-syn-export-span' } -ethabi-contract = "11.0.0" +ethabi-contract = "16.0.0" lru-cache = "0.1" [dev-dependencies] From 8c75682e9b86fe05165bc340bd35335ee68504e2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 7 Jul 2024 22:44:26 +0200 Subject: [PATCH 252/687] fixed warnings --- .../src/engines/hbbft/hbbft_network_fork_manager.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index d77d91faa..59ddc2ce7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -298,16 +298,15 @@ impl HbbftNetworkForkManager { #[cfg(test)] mod tests { - use std::{fs, str::FromStr}; + use std::str::FromStr; - use crate::engines::{hbbft::test::hbbft_test_client::HbbftTestClient, signer::from_keypair}; + use crate::engines::{hbbft::{hbbft_network_fork_manager::HbbftNetworkForkManager, NodeId}, signer::from_keypair}; - use super::*; - use ethereum_types::Address; + use ethjson::spec::hbbft::HbbftNetworkFork; - use hbbft::sync_key_gen::{Ack, Part}; use crypto::publickey::{KeyPair, Secret}; + use parking_lot::RwLock; //use parity_crypto::publickey::{KeyPair, Secret}; #[test] @@ -330,7 +329,7 @@ mod tests { let signer = from_keypair(key1); //let signer = Box::new(Signer (key1)); - let signer_lock = Arc::new(RwLock::new(Some(signer))); + let signer_lock = std::sync::Arc::new(RwLock::new(Some(signer))); let own_id = NodeId::default(); fork_manager.initialize(own_id, 8, vec![test_fork]); From 8c7d34610653bdf9e213f808bcb29215db70f78a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Aug 2024 00:38:05 +0200 Subject: [PATCH 253/687] experimentation version with hardcoded Certifier contract --- .../concensus/miner/src/service_transaction_checker.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index d4ccfc8f6..a7c2cba34 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -22,6 +22,7 @@ use ethereum_types::Address; use parking_lot::RwLock; use std::{collections::HashMap, mem, sync::Arc}; use types::{ids::BlockId, transaction::SignedTransaction}; +use std::str::FromStr; use_contract!( service_transaction, @@ -67,12 +68,8 @@ impl ServiceTransactionChecker { { return Ok(*allowed); } - let contract_address = client - .registry_address( - SERVICE_TRANSACTION_CONTRACT_REGISTRY_NAME.to_owned(), - BlockId::Latest, - ) - .ok_or_else(|| "Certifier contract is not configured")?; + let x = Address::from_str("5000000000000000000000000000000000000001".into()).unwrap(); + let contract_address = x; self.call_contract(client, contract_address, sender) .and_then(|allowed| { if let Some(mut cache) = self.certified_addresses_cache.try_write() { From 26b14def44b5f1dbe6b49bf7aaeecd7052a3485b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 10 Sep 2024 21:08:11 +0200 Subject: [PATCH 254/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/concensus/miner/src/service_transaction_checker.rs | 3 +-- .../ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index a7c2cba34..305ab3aa2 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -20,9 +20,8 @@ use call_contract::{CallContract, RegistryInfo}; use ethabi::FunctionOutputDecoder; use ethereum_types::Address; use parking_lot::RwLock; -use std::{collections::HashMap, mem, sync::Arc}; +use std::{collections::HashMap, mem, str::FromStr, sync::Arc}; use types::{ids::BlockId, transaction::SignedTransaction}; -use std::str::FromStr; use_contract!( service_transaction, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 59ddc2ce7..4c2c7caab 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -300,9 +300,11 @@ mod tests { use std::str::FromStr; - use crate::engines::{hbbft::{hbbft_network_fork_manager::HbbftNetworkForkManager, NodeId}, signer::from_keypair}; + use crate::engines::{ + hbbft::{hbbft_network_fork_manager::HbbftNetworkForkManager, NodeId}, + signer::from_keypair, + }; - use ethjson::spec::hbbft::HbbftNetworkFork; use crypto::publickey::{KeyPair, Secret}; From dfdfe9ee932a86e457bd9bd9bbff429810054edb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Sep 2024 15:41:17 +0200 Subject: [PATCH 255/687] hardcoded certifier address also for refresh_cache function. --- .../miner/src/service_transaction_checker.rs | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index 305ab3aa2..1e871c3c0 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -91,21 +91,17 @@ impl ServiceTransactionChecker { HashMap::default(), ); - if let Some(contract_address) = client.registry_address( - SERVICE_TRANSACTION_CONTRACT_REGISTRY_NAME.to_owned(), - BlockId::Latest, - ) { - let addresses: Vec<_> = cache.keys().collect(); - let mut cache: HashMap = HashMap::default(); - for address in addresses { - let allowed = self.call_contract(client, contract_address, *address)?; - cache.insert(*address, allowed); - } - *self.certified_addresses_cache.write() = cache; - Ok(true) - } else { - Ok(false) + let contract_address = Address::from_str("5000000000000000000000000000000000000001".into()).unwrap(); + + let addresses: Vec<_> = cache.keys().collect(); + let mut cache: HashMap = HashMap::default(); + for address in addresses { + let allowed = self.call_contract(client, contract_address, *address)?; + cache.insert(*address, allowed); } + *self.certified_addresses_cache.write() = cache; + Ok(true) + } fn call_contract( From 2c0aaa61e6a6f853b9aad24b0c3c8452621a37a3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Sep 2024 23:52:00 +0200 Subject: [PATCH 256/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/concensus/miner/src/service_transaction_checker.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index 1e871c3c0..d581591bd 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -91,8 +91,9 @@ impl ServiceTransactionChecker { HashMap::default(), ); - let contract_address = Address::from_str("5000000000000000000000000000000000000001".into()).unwrap(); - + let contract_address = + Address::from_str("5000000000000000000000000000000000000001".into()).unwrap(); + let addresses: Vec<_> = cache.keys().collect(); let mut cache: HashMap = HashMap::default(); for address in addresses { @@ -101,7 +102,6 @@ impl ServiceTransactionChecker { } *self.certified_addresses_cache.write() = cache; Ok(true) - } fn call_contract( From 68acf28247743905e51d997c2e4a9bdad14c0d5e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Oct 2024 13:22:43 +0200 Subject: [PATCH 257/687] improved logging for key generation --- .../engines/hbbft/contracts/keygen_history.rs | 16 ++++++++++++---- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 14 +++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index a8a642d60..e008790c2 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -1,5 +1,8 @@ use client::traits::EngineClient; -use crypto::{self, publickey::Public}; +use crypto::{ + self, + publickey::{ec_math_utils::public_add, Public}, +}; use engines::{ hbbft::{ contracts::validator_set::{get_validator_pubkeys, ValidatorType}, @@ -46,9 +49,14 @@ pub fn engine_signer_to_synckeygen<'a>( inner: signer.clone(), }; let public = match signer.read().as_ref() { - Some(signer) => signer - .public() - .expect("Signer's public key must be available!"), + Some(signer) => { + if let Some(this_public) = signer.public() { + this_public + } else { + error!(target: "engine", "Signer's public key must be available for address {:?}", signer.address()); + return Err(hbbft::sync_key_gen::Error::UnknownSender); + } + } None => Public::from(H512::from_low_u64_be(0)), }; let mut rng = rand::thread_rng(); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index f2ea21420..7b9f99688 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1161,14 +1161,22 @@ impl HoneyBadgerBFT { { if all_available { let null_signer = Arc::new(RwLock::new(None)); - if let Ok(synckeygen) = initialize_synckeygen( + match initialize_synckeygen( &*client, &null_signer, BlockId::Latest, ValidatorType::Pending, ) { - if synckeygen.is_ready() { - return true; + Ok(synckeygen) => { + if synckeygen.is_ready() { + return true; + } + } + Err(e) => { + error!(target: "consensus", "Error initializing synckeygen: {:?}", e); + } + Err(_) => { + error!(target: "consensus", "Error initializing synckeygen: unknown Error"); } } } From 47e5b6c9e001f7dd854fda3c41c12741a21b206d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Oct 2024 13:38:57 +0200 Subject: [PATCH 258/687] removed assert that leads to hardcrash for synckeygen --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 52e293f03..356405696 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -166,7 +166,10 @@ impl HbbftState { } }; - assert!(synckeygen.is_ready()); + if !synckeygen.is_ready() { + error!(target: "engine", "Synckeygen not ready when it should be!"); + return None; + } let (pks, sks) = synckeygen.generate().ok()?; self.public_master_key = Some(pks.public_key()); From 439fc0a908d3cd0d64a3f625a9aa3daf542d7891 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 16 Oct 2024 18:18:52 +0200 Subject: [PATCH 259/687] fixed create_miner tool to use the correct chain name --- .../src/engines/hbbft/dmd/src/create_miner.rs | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/dmd/src/create_miner.rs b/crates/ethcore/src/engines/hbbft/dmd/src/create_miner.rs index 7cfb4e3fb..aed220889 100644 --- a/crates/ethcore/src/engines/hbbft/dmd/src/create_miner.rs +++ b/crates/ethcore/src/engines/hbbft/dmd/src/create_miner.rs @@ -1,6 +1,7 @@ use ethstore::{KeyFile, SafeAccount}; use parity_crypto::publickey::{Generator, KeyPair, Random, Secret}; -use std::{fs, num::NonZeroU32, path::Path}; +use serde_json::Value; +use std::{fs, num::NonZeroU32, path::Path, str::FromStr}; fn write_json_for_secret(secret: Secret, filename: &str) { let json_key: KeyFile = SafeAccount::create( @@ -21,6 +22,38 @@ fn write_json_for_secret(secret: Secret, filename: &str) { pub fn create_miner() { println!("Creating dmd v4 miner..."); + let mut name: String = "DPoSChain".to_string(); + match fs::read_to_string("spec.json") { + Ok(s) => { + match serde_json::from_str(s.as_str()) { + Ok(Value::Object(map)) => { + if map.contains_key("name") { + let x = &map["name"]; + + match x.as_str() { + Some(n) => { + name = String::from_str(n).expect("could not parse chain name from spec.json"); + println!("chain: {}", name); + }, + None => { + println!("could not read chain name from spec.json"); + } + } + } + }, + _ => { + println!("unable to parse spec.json"); + } + } + }, + Err(e) => { + println!("unable to to open spec.json: {:?}", e); + }, + } + + //let serialized_json_key = + //serde_json::to_string(&json_key).expect("json key object serialization should succeed"); + let acc = Random.generate(); // Create "data" and "network" subfolders. @@ -31,8 +64,8 @@ pub fn create_miner() { .expect("Unable to write the network key file"); // Create "keys" and "DPoSChain" subfolders. - let accounts_dir = Path::new("./data/keys/DPoSChain"); - fs::create_dir_all(accounts_dir).expect("Could not create accounts directory"); + let accounts_dir = Path::new("./data/keys/").join(name); + fs::create_dir_all(accounts_dir.clone()).expect("Could not create accounts directory"); // Write JSON account. write_json_for_secret( From 8a3766d2de4db5a15d266dfbf23fc0e294f3762c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Oct 2024 11:49:37 +0200 Subject: [PATCH 260/687] cargo fmt --all -- --config imports_granularity=Crate --- .../src/engines/hbbft/dmd/src/create_miner.rs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/dmd/src/create_miner.rs b/crates/ethcore/src/engines/hbbft/dmd/src/create_miner.rs index aed220889..1c2805800 100644 --- a/crates/ethcore/src/engines/hbbft/dmd/src/create_miner.rs +++ b/crates/ethcore/src/engines/hbbft/dmd/src/create_miner.rs @@ -24,31 +24,30 @@ pub fn create_miner() { println!("Creating dmd v4 miner..."); let mut name: String = "DPoSChain".to_string(); match fs::read_to_string("spec.json") { - Ok(s) => { - match serde_json::from_str(s.as_str()) { - Ok(Value::Object(map)) => { - if map.contains_key("name") { - let x = &map["name"]; + Ok(s) => match serde_json::from_str(s.as_str()) { + Ok(Value::Object(map)) => { + if map.contains_key("name") { + let x = &map["name"]; - match x.as_str() { - Some(n) => { - name = String::from_str(n).expect("could not parse chain name from spec.json"); - println!("chain: {}", name); - }, - None => { - println!("could not read chain name from spec.json"); - } + match x.as_str() { + Some(n) => { + name = String::from_str(n) + .expect("could not parse chain name from spec.json"); + println!("chain: {}", name); + } + None => { + println!("could not read chain name from spec.json"); } } - }, - _ => { - println!("unable to parse spec.json"); } } + _ => { + println!("unable to parse spec.json"); + } }, Err(e) => { println!("unable to to open spec.json: {:?}", e); - }, + } } //let serialized_json_key = From 9e130811c8eff49f3b3bd055b70603427e6f14df Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Oct 2024 11:56:36 +0200 Subject: [PATCH 261/687] setting gas_floor_target in the hbbft_config_generator. --- .../ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index e1dd9ac80..1eeadb9e7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -242,6 +242,7 @@ fn to_toml( // this makes sure that the min_gas_price wont be higher then the gas pricce the DAO decides. mining.insert("min_gas_price".into(), Value::Integer(1000)); mining.insert("reseal_on_txs".into(), Value::String("none".into())); + mining.insert("gas_floor_target".into(), Value::String("300000000".into())); mining.insert("reseal_min_period".into(), Value::Integer(0)); if let Some(tx_queue_per_sender_) = tx_queue_per_sender { From 65cb273d5c479263d17695ed23c2d24f43a663f1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 21 Oct 2024 12:30:31 +0200 Subject: [PATCH 262/687] improved logging for early epoch end reconnects --- .../src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index 2bef3ce7e..fce2bbf3c 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -134,9 +134,9 @@ pub fn report_reconnect( .gas(U256::from(200_000)) .nonce(nonce); - info!(target:"consensus", "early-epoch-end: sending report_missing_connectivity for with nonce: {nonce}, missing: {:?} ", reconnected_validator); + info!(target:"engine", "early-epoch-end: sending report_reconnect for with nonce: {nonce}, missing: {:?} ", reconnected_validator); if let Err(e) = full_client.transact_silently(transaction) { - warn!(target:"consensus", "early-epoch-end: could not report_missing_connectivity {e:?}"); + warn!(target:"engine", "early-epoch-end: could not report_missing_connectivity {e:?}"); return false; } return true; From 14877c991912a10ab433afdc4089260d36ffb2e3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Oct 2024 09:13:28 +0200 Subject: [PATCH 263/687] increased devp2p warmup time for not sending early epoch end reports from 2 minutes to 20 minutes. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 7b9f99688..7f0f32e90 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -942,7 +942,7 @@ impl HoneyBadgerBFT { mining_address: &Address, ) { // todo: acquire allowed devp2p warmup time from contracts ?! - let allowed_devp2p_warmup_time = Duration::from_secs(120); + let allowed_devp2p_warmup_time = Duration::from_secs(1200); debug!(target: "engine", "early-epoch-end: handle_early_epoch_end."); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 356405696..0cf959405 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -233,7 +233,7 @@ impl HbbftState { warn!(target: "engine", "could not acquire to connect to current validators on switching to new validator set for staking epoch {}.", self.current_posdao_epoch); } - let allowed_devp2p_warmup_time = Duration::from_secs(120); + let allowed_devp2p_warmup_time = Duration::from_secs(1200); if let Some(full_client) = client.as_full_client() { let signing_address = if let Some(s) = signer.read().as_ref() { From 03abfce2d188dd3e8cea0ded9b9d15e9563af276 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Oct 2024 15:30:12 +0100 Subject: [PATCH 264/687] logging transactions for block that gets created. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 7f0f32e90..64ee9d24e 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -505,6 +505,8 @@ impl HoneyBadgerBFT { debug!(target: "consensus", "Block creation: Batch received for epoch {}, total {} contributions, with {} unique transactions.", batch.epoch, batch .contributions.iter().fold(0, |i, c| i + c.1.transactions.len()), batch_txns.len()); + trace!(target: "consensus", "Block creation: transactions {}", batch_txns.iter().map(|x| x.hash.to_string()).join(", ")); + // Make sure the resulting transactions do not contain nonces out of order. // Not necessary any more - we select contribution transactions by sender, contributing all transactions by that sender or none. // The transaction queue's "pending" transactions already guarantee there are no nonce gaps for a selected sender. From 210c265bf52b56a921d6d8603316fced3c3fffaa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Oct 2024 09:20:54 +0100 Subject: [PATCH 265/687] logging: do_validator_engine_actions: skipping because we are syncing. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 64ee9d24e..a235d92ba 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1009,6 +1009,7 @@ impl HoneyBadgerBFT { Some(client_arc) => { if self.is_syncing(&client_arc) { // we are syncing - do not do anything. + trace!(target: "engine", "do_validator_engine_actions: skipping because we are syncing."); return Ok(()); } From 293f6aa7e1f03426d4fc6013609c1a747075f496 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Oct 2024 11:22:18 +0100 Subject: [PATCH 266/687] logging public keys of pending validators --- .../ethcore/src/engines/hbbft/keygen_transactions.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index e0d6ee567..067e21584 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -128,11 +128,19 @@ impl KeygenTransactionSender { .map(|p| (*p, PublicWrapper { inner: p.clone() })) .collect(); + let pub_leys_arc = Arc::new(pub_keys); + + //let pub_key_len = pub_keys.len(); // if synckeygen creation fails then either signer or validator pub keys are problematic. // Todo: We should expect up to f clients to write invalid pub keys. Report and re-start pending validator set selection. - let (mut synckeygen, part) = engine_signer_to_synckeygen(signer, Arc::new(pub_keys)) + let (mut synckeygen, part) = engine_signer_to_synckeygen(signer, pub_leys_arc.clone()) .map_err(|e| { - warn!(target:"engine", "engine_signer_to_synckeygen error {:?}", e); + warn!(target:"engine", "engine_signer_to_synckeygen pub keys count {:?} error {:?}", pub_leys_arc.len(), e); + + pub_leys_arc.iter().for_each(|(k, v)| { + warn!(target:"engine", "pub key {}", k); + }); + CallError::ReturnValueInvalid })?; From 6cdddabb7e758cbab01a364434ed2ca3ba5a4a57 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Oct 2024 11:23:25 +0100 Subject: [PATCH 267/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/engines/hbbft/keygen_transactions.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 067e21584..b7dd738d5 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -136,11 +136,9 @@ impl KeygenTransactionSender { let (mut synckeygen, part) = engine_signer_to_synckeygen(signer, pub_leys_arc.clone()) .map_err(|e| { warn!(target:"engine", "engine_signer_to_synckeygen pub keys count {:?} error {:?}", pub_leys_arc.len(), e); - pub_leys_arc.iter().for_each(|(k, v)| { warn!(target:"engine", "pub key {}", k); }); - CallError::ReturnValueInvalid })?; From 67cd17649a66a93c41fb42a1e6d8ea21fc904dcb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Oct 2024 12:20:48 +0100 Subject: [PATCH 268/687] PublicKey: check if public key is valid for the use of BLS 381 12 --- .../ethcore/src/engines/hbbft/contracts/keygen_history.rs | 7 +++++++ crates/ethcore/src/engines/hbbft/keygen_transactions.rs | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index e008790c2..4ebcd1a87 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -179,6 +179,13 @@ pub struct KeyPairWrapper { pub inner: Arc>>>, } +impl PublicWrapper { + /// Check if the public key is valid. + pub fn is_valid(&self) -> bool { + self.encrypt(b"a", &mut rand::thread_rng()).is_ok() + } +} + impl<'a> PublicKey for PublicWrapper { type Error = crypto::publickey::Error; type SecretKey = KeyPairWrapper; diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index b7dd738d5..5c1cd90ba 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -137,7 +137,11 @@ impl KeygenTransactionSender { .map_err(|e| { warn!(target:"engine", "engine_signer_to_synckeygen pub keys count {:?} error {:?}", pub_leys_arc.len(), e); pub_leys_arc.iter().for_each(|(k, v)| { - warn!(target:"engine", "pub key {}", k); + warn!(target:"engine", "pub key {}", k.as_bytes().iter().join("")); + + if !v.is_valid() { + warn!(target:"engine", "INVALID pub key {}", k); + } }); CallError::ReturnValueInvalid })?; From b93d9e61de7580f2c66ad4f0d085fb04176d286e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Oct 2024 22:25:37 +0100 Subject: [PATCH 269/687] i132 on detecting invalid public keys, write parts to progress into the next key gen phase for this node https://github.com/DMDcoin/diamond-node/issues/132 --- .../src/engines/hbbft/keygen_transactions.rs | 102 ++++++++++++++---- 1 file changed, 80 insertions(+), 22 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 5c1cd90ba..5bdaf668b 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -16,7 +16,7 @@ use engines::{ }, signer::EngineSigner, }; -use ethereum_types::{Address, U256}; +use ethereum_types::{Address, Public, U256}; use itertools::Itertools; use parking_lot::RwLock; use std::{collections::BTreeMap, sync::Arc}; @@ -36,6 +36,23 @@ enum ShouldSendKeyAnswer { Yes, } +#[derive(Debug)] +pub enum KeyGenError { + NoSigner, + NoFullClient, + NoPartToWrite, + InvalidPublicKey(Vec), + CallError(CallError), + Unexpected +} + + +impl From for KeyGenError { + fn from(e: CallError) -> Self { + KeyGenError::CallError(e) + } +} + static KEYGEN_TRANSACTION_SEND_DELAY: u64 = 3; static KEYGEN_TRANSACTION_RESEND_DELAY: u64 = 10; @@ -102,17 +119,17 @@ impl KeygenTransactionSender { &mut self, client: &dyn EngineClient, signer: &Arc>>>, - ) -> Result<(), CallError> { + ) -> Result<(), KeyGenError> { // If we have no signer there is nothing for us to send. let address = match signer.read().as_ref() { Some(signer) => signer.address(), None => { warn!(target: "engine", "Could not send keygen transactions, because signer module could not be retrieved"); - return Err(CallError::ReturnValueInvalid); + return Err(KeyGenError::NoSigner); } }; - let full_client = client.as_full_client().ok_or(CallError::NotFullClient)?; + let full_client = client.as_full_client().ok_or(KeyGenError::NoFullClient)?; // If the chain is still syncing, do not send Parts or Acks. if full_client.is_major_syncing() { @@ -122,40 +139,81 @@ impl KeygenTransactionSender { trace!(target:"engine", " get_validator_pubkeys..."); - let vmap = get_validator_pubkeys(&*client, BlockId::Latest, ValidatorType::Pending)?; + let vmap = get_validator_pubkeys(&*client, BlockId::Latest, ValidatorType::Pending).map_err(|e| KeyGenError::CallError(e))?; let pub_keys: BTreeMap<_, _> = vmap .values() .map(|p| (*p, PublicWrapper { inner: p.clone() })) .collect(); - let pub_leys_arc = Arc::new(pub_keys); + let pub_keys_arc = Arc::new(pub_keys); + let upcoming_epoch = get_posdao_epoch(client, BlockId::Latest).map_err(|e| KeyGenError::CallError(e))? + 1; //let pub_key_len = pub_keys.len(); // if synckeygen creation fails then either signer or validator pub keys are problematic. // Todo: We should expect up to f clients to write invalid pub keys. Report and re-start pending validator set selection. - let (mut synckeygen, part) = engine_signer_to_synckeygen(signer, pub_leys_arc.clone()) - .map_err(|e| { - warn!(target:"engine", "engine_signer_to_synckeygen pub keys count {:?} error {:?}", pub_leys_arc.len(), e); - pub_leys_arc.iter().for_each(|(k, v)| { - warn!(target:"engine", "pub key {}", k.as_bytes().iter().join("")); - - if !v.is_valid() { - warn!(target:"engine", "INVALID pub key {}", k); + let (mut synckeygen, part) = + match engine_signer_to_synckeygen(signer, pub_keys_arc.clone()) { + Ok((mut synckeygen_, part_)) => (synckeygen_, part_), + Err(e) => { + warn!(target:"engine", "engine_signer_to_synckeygen pub keys count {:?} error {:?}", pub_keys_arc.len(), e); + //let mut failure_pub_keys: Vec = Vec::new(); + let mut failure_pub_keys: Vec = Vec::new(); + pub_keys_arc.iter().for_each(|(k, v)| { + warn!(target:"engine", "pub key {}", k.as_bytes().iter().join("")); + + if !v.is_valid() { + warn!(target:"engine", "INVALID pub key {}", k); + + // append the bytes of the public key to the failure_pub_keys. + k.as_bytes().iter().for_each(|b| { + failure_pub_keys.push(*b); + }); + } + }); + + // if we should send our parts, we will send the public keys of the troublemakers instead. + + match self.should_send_part(client, &address).map_err(|e| KeyGenError::CallError(e))? { + ShouldSendKeyAnswer::NoNotThisKeyGenMode => return Err(KeyGenError::Unexpected), + ShouldSendKeyAnswer::NoWaiting => return Err(KeyGenError::Unexpected), + ShouldSendKeyAnswer::Yes => { + + // the required gas values have been approximated by + // experimenting and it's a very rough estimation. + // it can be further fine tuned to be just above the real consumption. + // ACKs require much more gas, + // and usually run into the gas limit problems. + let gas: usize = failure_pub_keys.len() * 800 + 100_000; + + let part_transaction = + TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, failure_pub_keys) + .gas(U256::from(gas)) + .nonce(full_client.nonce(&address, BlockId::Latest).unwrap()) + .gas_price(U256::from(10000000000u64)); + full_client + .transact_silently(part_transaction) + .map_err(|e| { + warn!(target:"engine", "could not transact_silently: {:?}", e); + CallError::ReturnValueInvalid + })?; + + trace!(target:"engine", "PART Transaction send."); + return Ok(()); + }, } - }); - CallError::ReturnValueInvalid - })?; + }, + }; // If there is no part then we are not part of the pending validator set and there is nothing for us to do. let part_data = match part { Some(part) => part, None => { warn!(target:"engine", "no part to write."); - return Err(CallError::ReturnValueInvalid); + return Err(KeyGenError::NoPartToWrite); } }; - let upcoming_epoch = get_posdao_epoch(client, BlockId::Latest)? + 1; + trace!(target:"engine", "preparing to send PARTS for upcoming epoch: {}", upcoming_epoch); // Check if we already sent our part. @@ -165,7 +223,7 @@ impl KeygenTransactionSender { Ok(part) => part, Err(e) => { warn!(target:"engine", "could not serialize part: {:?}", e); - return Err(CallError::ReturnValueInvalid); + return Err(KeyGenError::Unexpected); } }; let serialized_part_len = serialized_part.len(); @@ -223,7 +281,7 @@ impl KeygenTransactionSender { } Err(err) => { error!(target:"engine", "could not retrieve part for {} call failed. Error: {:?}", *v, err); - return Err(err); + return Err(KeyGenError::CallError(err)); } } ); @@ -240,7 +298,7 @@ impl KeygenTransactionSender { for ack in acks { let ack_to_push = match bincode::serialize(&ack) { Ok(serialized_ack) => serialized_ack, - Err(_) => return Err(CallError::ReturnValueInvalid), + Err(e) => return Err(KeyGenError::Unexpected), }; total_bytes_for_acks += ack_to_push.len(); serialized_acks.push(ack_to_push); From 3e6e9c611a2d32ff99674da0f54047c148417b9a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Oct 2024 23:28:57 +0100 Subject: [PATCH 270/687] compressing part as bincode , logging Nonce for Part Transaction that holds the public key. --- .../src/engines/hbbft/keygen_transactions.rs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 5bdaf668b..a9cb45c72 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -41,9 +41,9 @@ pub enum KeyGenError { NoSigner, NoFullClient, NoPartToWrite, - InvalidPublicKey(Vec), CallError(CallError), - Unexpected + Unexpected, + } @@ -185,10 +185,20 @@ impl KeygenTransactionSender { // and usually run into the gas limit problems. let gas: usize = failure_pub_keys.len() * 800 + 100_000; + let serialized_part = match bincode::serialize(&failure_pub_keys) { + Ok(part) => part, + Err(e) => { + warn!(target:"engine", "could not serialize part: {:?}", e); + return Err(KeyGenError::Unexpected); + } + }; + + let nonce = full_client.nonce(&address, BlockId::Latest).unwrap(); + let part_transaction = - TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, failure_pub_keys) + TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, serialized_part) .gas(U256::from(gas)) - .nonce(full_client.nonce(&address, BlockId::Latest).unwrap()) + .nonce(nonce) .gas_price(U256::from(10000000000u64)); full_client .transact_silently(part_transaction) @@ -197,7 +207,7 @@ impl KeygenTransactionSender { CallError::ReturnValueInvalid })?; - trace!(target:"engine", "PART Transaction send."); + trace!(target:"engine", "PART Transaction send for moving forward key gen phase with nonce: {}", nonce); return Ok(()); }, } From 65d32e8b8ddbe05ef960475e34ea2339cd952cc6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 31 Oct 2024 00:12:19 +0100 Subject: [PATCH 271/687] refactored part transactions to a function. --- .../src/engines/hbbft/keygen_transactions.rs | 90 +++++++++---------- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index a9cb45c72..c1669d599 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -22,6 +22,8 @@ use parking_lot::RwLock; use std::{collections::BTreeMap, sync::Arc}; use types::ids::BlockId; +use crate::client::BlockChainClient; + pub struct KeygenTransactionSender { last_keygen_mode: KeyGenMode, keygen_mode_counter: u64, @@ -177,13 +179,6 @@ impl KeygenTransactionSender { ShouldSendKeyAnswer::NoNotThisKeyGenMode => return Err(KeyGenError::Unexpected), ShouldSendKeyAnswer::NoWaiting => return Err(KeyGenError::Unexpected), ShouldSendKeyAnswer::Yes => { - - // the required gas values have been approximated by - // experimenting and it's a very rough estimation. - // it can be further fine tuned to be just above the real consumption. - // ACKs require much more gas, - // and usually run into the gas limit problems. - let gas: usize = failure_pub_keys.len() * 800 + 100_000; let serialized_part = match bincode::serialize(&failure_pub_keys) { Ok(part) => part, @@ -192,22 +187,9 @@ impl KeygenTransactionSender { return Err(KeyGenError::Unexpected); } }; - - let nonce = full_client.nonce(&address, BlockId::Latest).unwrap(); - - let part_transaction = - TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, serialized_part) - .gas(U256::from(gas)) - .nonce(nonce) - .gas_price(U256::from(10000000000u64)); - full_client - .transact_silently(part_transaction) - .map_err(|e| { - warn!(target:"engine", "could not transact_silently: {:?}", e); - CallError::ReturnValueInvalid - })?; - - trace!(target:"engine", "PART Transaction send for moving forward key gen phase with nonce: {}", nonce); + + send_part_transaction(full_client, client, &address, upcoming_epoch, serialized_part)?; + trace!(target:"engine", "PART Transaction send for moving forward key gen phase"); return Ok(()); }, } @@ -229,6 +211,7 @@ impl KeygenTransactionSender { // Check if we already sent our part. match self.should_send_part(client, &address)? { ShouldSendKeyAnswer::Yes => { + let serialized_part = match bincode::serialize(&part_data) { Ok(part) => part, Err(e) => { @@ -236,33 +219,8 @@ impl KeygenTransactionSender { return Err(KeyGenError::Unexpected); } }; - let serialized_part_len = serialized_part.len(); - let current_round = get_current_key_gen_round(client)?; - let write_part_data = key_history_contract::functions::write_part::call( - upcoming_epoch, - current_round, - serialized_part, - ); - - // the required gas values have been approximated by - // experimenting and it's a very rough estimation. - // it can be further fine tuned to be just above the real consumption. - // ACKs require much more gas, - // and usually run into the gas limit problems. - let gas: usize = serialized_part_len * 800 + 100_000; - - let part_transaction = - TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, write_part_data.0) - .gas(U256::from(gas)) - .nonce(full_client.nonce(&address, BlockId::Latest).unwrap()) - .gas_price(U256::from(10000000000u64)); - full_client - .transact_silently(part_transaction) - .map_err(|e| { - warn!(target:"engine", "could not transact_silently: {:?}", e); - CallError::ReturnValueInvalid - })?; + send_part_transaction(full_client, client, &address, upcoming_epoch, serialized_part)?; trace!(target:"engine", "PART Transaction send."); return Ok(()); } @@ -341,3 +299,37 @@ impl KeygenTransactionSender { Ok(()) } } + + +fn send_part_transaction(full_client: &dyn BlockChainClient, client: &dyn EngineClient, mining_address: &Address, upcoming_epoch: U256 , data: Vec) -> Result<(), KeyGenError> { + + // the required gas values have been approximated by + // experimenting and it's a very rough estimation. + // it can be further fine tuned to be just above the real consumption. + // ACKs require much more gas, + // and usually run into the gas limit problems. + let gas: usize = data.len() * 800 + 100_000; + + let nonce = full_client.nonce(&mining_address, BlockId::Latest).unwrap(); + let current_round = get_current_key_gen_round(client)?; + let write_part_data = key_history_contract::functions::write_part::call( + upcoming_epoch, + current_round, + data, + ); + + let part_transaction = + TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, write_part_data.0) + .gas(U256::from(gas)) + .nonce(nonce) + .gas_price(U256::from(10000000000u64)); + full_client + .transact_silently(part_transaction) + .map_err(|e| { + warn!(target:"engine", "could not transact_silently: {:?}", e); + CallError::ReturnValueInvalid + })?; + + return Ok(()); + +} From e74af66a52b862599ead45194d6aad1141f3815e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 31 Oct 2024 00:46:11 +0100 Subject: [PATCH 272/687] cargo fmt --all -- --config imports_granularity=Crate --- .../src/engines/hbbft/keygen_transactions.rs | 139 ++++++++++-------- 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index c1669d599..440b7c479 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -45,10 +45,8 @@ pub enum KeyGenError { NoPartToWrite, CallError(CallError), Unexpected, - } - impl From for KeyGenError { fn from(e: CallError) -> Self { KeyGenError::CallError(e) @@ -141,60 +139,72 @@ impl KeygenTransactionSender { trace!(target:"engine", " get_validator_pubkeys..."); - let vmap = get_validator_pubkeys(&*client, BlockId::Latest, ValidatorType::Pending).map_err(|e| KeyGenError::CallError(e))?; + let vmap = get_validator_pubkeys(&*client, BlockId::Latest, ValidatorType::Pending) + .map_err(|e| KeyGenError::CallError(e))?; let pub_keys: BTreeMap<_, _> = vmap .values() .map(|p| (*p, PublicWrapper { inner: p.clone() })) .collect(); let pub_keys_arc = Arc::new(pub_keys); - let upcoming_epoch = get_posdao_epoch(client, BlockId::Latest).map_err(|e| KeyGenError::CallError(e))? + 1; + let upcoming_epoch = + get_posdao_epoch(client, BlockId::Latest).map_err(|e| KeyGenError::CallError(e))? + 1; //let pub_key_len = pub_keys.len(); // if synckeygen creation fails then either signer or validator pub keys are problematic. // Todo: We should expect up to f clients to write invalid pub keys. Report and re-start pending validator set selection. - let (mut synckeygen, part) = - match engine_signer_to_synckeygen(signer, pub_keys_arc.clone()) { - Ok((mut synckeygen_, part_)) => (synckeygen_, part_), - Err(e) => { - warn!(target:"engine", "engine_signer_to_synckeygen pub keys count {:?} error {:?}", pub_keys_arc.len(), e); - //let mut failure_pub_keys: Vec = Vec::new(); - let mut failure_pub_keys: Vec = Vec::new(); - pub_keys_arc.iter().for_each(|(k, v)| { - warn!(target:"engine", "pub key {}", k.as_bytes().iter().join("")); - - if !v.is_valid() { - warn!(target:"engine", "INVALID pub key {}", k); - - // append the bytes of the public key to the failure_pub_keys. - k.as_bytes().iter().for_each(|b| { - failure_pub_keys.push(*b); - }); - } - }); - - // if we should send our parts, we will send the public keys of the troublemakers instead. - - match self.should_send_part(client, &address).map_err(|e| KeyGenError::CallError(e))? { - ShouldSendKeyAnswer::NoNotThisKeyGenMode => return Err(KeyGenError::Unexpected), - ShouldSendKeyAnswer::NoWaiting => return Err(KeyGenError::Unexpected), - ShouldSendKeyAnswer::Yes => { - - let serialized_part = match bincode::serialize(&failure_pub_keys) { - Ok(part) => part, - Err(e) => { - warn!(target:"engine", "could not serialize part: {:?}", e); - return Err(KeyGenError::Unexpected); - } - }; - - send_part_transaction(full_client, client, &address, upcoming_epoch, serialized_part)?; - trace!(target:"engine", "PART Transaction send for moving forward key gen phase"); - return Ok(()); - }, + let (mut synckeygen, part) = match engine_signer_to_synckeygen(signer, pub_keys_arc.clone()) + { + Ok((mut synckeygen_, part_)) => (synckeygen_, part_), + Err(e) => { + warn!(target:"engine", "engine_signer_to_synckeygen pub keys count {:?} error {:?}", pub_keys_arc.len(), e); + //let mut failure_pub_keys: Vec = Vec::new(); + let mut failure_pub_keys: Vec = Vec::new(); + pub_keys_arc.iter().for_each(|(k, v)| { + warn!(target:"engine", "pub key {}", k.as_bytes().iter().join("")); + + if !v.is_valid() { + warn!(target:"engine", "INVALID pub key {}", k); + + // append the bytes of the public key to the failure_pub_keys. + k.as_bytes().iter().for_each(|b| { + failure_pub_keys.push(*b); + }); } - }, - }; + }); + + // if we should send our parts, we will send the public keys of the troublemakers instead. + + match self + .should_send_part(client, &address) + .map_err(|e| KeyGenError::CallError(e))? + { + ShouldSendKeyAnswer::NoNotThisKeyGenMode => { + return Err(KeyGenError::Unexpected) + } + ShouldSendKeyAnswer::NoWaiting => return Err(KeyGenError::Unexpected), + ShouldSendKeyAnswer::Yes => { + let serialized_part = match bincode::serialize(&failure_pub_keys) { + Ok(part) => part, + Err(e) => { + warn!(target:"engine", "could not serialize part: {:?}", e); + return Err(KeyGenError::Unexpected); + } + }; + + send_part_transaction( + full_client, + client, + &address, + upcoming_epoch, + serialized_part, + )?; + trace!(target:"engine", "PART Transaction send for moving forward key gen phase"); + return Ok(()); + } + } + } + }; // If there is no part then we are not part of the pending validator set and there is nothing for us to do. let part_data = match part { @@ -205,13 +215,11 @@ impl KeygenTransactionSender { } }; - trace!(target:"engine", "preparing to send PARTS for upcoming epoch: {}", upcoming_epoch); // Check if we already sent our part. match self.should_send_part(client, &address)? { ShouldSendKeyAnswer::Yes => { - let serialized_part = match bincode::serialize(&part_data) { Ok(part) => part, Err(e) => { @@ -220,7 +228,13 @@ impl KeygenTransactionSender { } }; - send_part_transaction(full_client, client, &address, upcoming_epoch, serialized_part)?; + send_part_transaction( + full_client, + client, + &address, + upcoming_epoch, + serialized_part, + )?; trace!(target:"engine", "PART Transaction send."); return Ok(()); } @@ -300,9 +314,13 @@ impl KeygenTransactionSender { } } - -fn send_part_transaction(full_client: &dyn BlockChainClient, client: &dyn EngineClient, mining_address: &Address, upcoming_epoch: U256 , data: Vec) -> Result<(), KeyGenError> { - +fn send_part_transaction( + full_client: &dyn BlockChainClient, + client: &dyn EngineClient, + mining_address: &Address, + upcoming_epoch: U256, + data: Vec, +) -> Result<(), KeyGenError> { // the required gas values have been approximated by // experimenting and it's a very rough estimation. // it can be further fine tuned to be just above the real consumption. @@ -312,17 +330,13 @@ fn send_part_transaction(full_client: &dyn BlockChainClient, client: &dyn Engine let nonce = full_client.nonce(&mining_address, BlockId::Latest).unwrap(); let current_round = get_current_key_gen_round(client)?; - let write_part_data = key_history_contract::functions::write_part::call( - upcoming_epoch, - current_round, - data, - ); - - let part_transaction = - TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, write_part_data.0) - .gas(U256::from(gas)) - .nonce(nonce) - .gas_price(U256::from(10000000000u64)); + let write_part_data = + key_history_contract::functions::write_part::call(upcoming_epoch, current_round, data); + + let part_transaction = TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, write_part_data.0) + .gas(U256::from(gas)) + .nonce(nonce) + .gas_price(U256::from(10000000000u64)); full_client .transact_silently(part_transaction) .map_err(|e| { @@ -331,5 +345,4 @@ fn send_part_transaction(full_client: &dyn BlockChainClient, client: &dyn Engine })?; return Ok(()); - } From 86ecdbb6aad4fa93732f36f530f630d056f78cd7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Nov 2024 20:21:14 +0100 Subject: [PATCH 273/687] unused field --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 5ff30bcf0..7a959fd7a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -39,7 +39,7 @@ pub(crate) struct HbbftEarlyEpochEndManager { node_id_to_address: BTreeMap, - address_to_node_id: BTreeMap, + // address_to_node_id: BTreeMap, signing_address: Address, } @@ -109,7 +109,7 @@ impl HbbftEarlyEpochEndManager { validators: validators, flagged_validators: flagged_validators, node_id_to_address, - address_to_node_id, + // address_to_node_id, signing_address: signing_address.clone(), }; From f349d7814a867ee34773c64699f1d14434174242 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Nov 2024 20:23:04 +0100 Subject: [PATCH 274/687] cleanup --- .../src/engines/hbbft/hbbft_network_fork_manager.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index d77d91faa..59831dc38 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -298,17 +298,11 @@ impl HbbftNetworkForkManager { #[cfg(test)] mod tests { - use std::{fs, str::FromStr}; - - use crate::engines::{hbbft::test::hbbft_test_client::HbbftTestClient, signer::from_keypair}; - - use super::*; - use ethereum_types::Address; + use std::str::FromStr; + use crate::engines::signer::from_keypair; + use super::*; use ethjson::spec::hbbft::HbbftNetworkFork; - use hbbft::sync_key_gen::{Ack, Part}; - use crypto::publickey::{KeyPair, Secret}; - //use parity_crypto::publickey::{KeyPair, Secret}; #[test] fn test_fork_manager_should_fork() { From 83d3c5a0a8fc5023d908ff02b4fee7924537fc39 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Nov 2024 20:23:12 +0100 Subject: [PATCH 275/687] cleanup --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 7f0f32e90..90bbdc30e 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1175,9 +1175,6 @@ impl HoneyBadgerBFT { Err(e) => { error!(target: "consensus", "Error initializing synckeygen: {:?}", e); } - Err(_) => { - error!(target: "consensus", "Error initializing synckeygen: unknown Error"); - } } } } From 32f328d116fcddc2b1c6a29bf0fda381f8477315 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Nov 2024 20:24:31 +0100 Subject: [PATCH 276/687] cargo fmt --all -- --config imports_granularity=Crate --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 1 - .../ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 7a959fd7a..5b8f2411b 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -40,7 +40,6 @@ pub(crate) struct HbbftEarlyEpochEndManager { node_id_to_address: BTreeMap, // address_to_node_id: BTreeMap, - signing_address: Address, } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index 59831dc38..b021e5a9c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -298,11 +298,11 @@ impl HbbftNetworkForkManager { #[cfg(test)] mod tests { - use std::str::FromStr; + use super::*; use crate::engines::signer::from_keypair; - use super::*; - use ethjson::spec::hbbft::HbbftNetworkFork; use crypto::publickey::{KeyPair, Secret}; + use ethjson::spec::hbbft::HbbftNetworkFork; + use std::str::FromStr; #[test] fn test_fork_manager_should_fork() { From 63606660378fe72151da55a73906c872757cf726 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 5 Nov 2024 21:11:24 +0100 Subject: [PATCH 277/687] removed RequestMiddleware use --- bin/oe/rpc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/oe/rpc.rs b/bin/oe/rpc.rs index d098b2776..d4dd37c41 100644 --- a/bin/oe/rpc.rs +++ b/bin/oe/rpc.rs @@ -29,7 +29,7 @@ use parity_rpc::{ }; use parity_runtime::Executor; -pub use parity_rpc::{HttpServer, IpcServer, RequestMiddleware}; +pub use parity_rpc::{HttpServer, IpcServer}; //pub use parity_rpc::ws::Server as WsServer; pub use parity_rpc::ws::{ws, Server as WsServer}; From 8dfc0e9b18ea27586b6030999b5fbaedb92199b7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 5 Nov 2024 21:15:49 +0100 Subject: [PATCH 278/687] cargo fix --- crates/concensus/ethash/src/keccak.rs | 2 +- crates/ethcore/benches/builtin.rs | 3 +-- crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs | 2 +- crates/ethcore/src/engines/validator_set/safe_contract.rs | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/concensus/ethash/src/keccak.rs b/crates/concensus/ethash/src/keccak.rs index 134a11fb2..187e16b85 100644 --- a/crates/concensus/ethash/src/keccak.rs +++ b/crates/concensus/ethash/src/keccak.rs @@ -30,6 +30,6 @@ pub mod keccak_256 { use super::hash; pub use self::hash::{ - keccak256 as inplace, keccak256_range as inplace_range, keccak_256 as write, + keccak256 as inplace, keccak_256 as write, }; } diff --git a/crates/ethcore/benches/builtin.rs b/crates/ethcore/benches/builtin.rs index 47c6cd568..ffdce6242 100644 --- a/crates/ethcore/benches/builtin.rs +++ b/crates/ethcore/benches/builtin.rs @@ -50,8 +50,7 @@ impl<'a> BuiltinBenchmark<'a> { let builtin = builtins .get(&H160::from_str(builtin_address).unwrap()) - .unwrap() - .clone(); + .unwrap(); let input = FromHex::from_hex(input).unwrap(); let expected = FromHex::from_hex(expected).unwrap(); diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index e008790c2..26e7a5e2c 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -1,7 +1,7 @@ use client::traits::EngineClient; use crypto::{ self, - publickey::{ec_math_utils::public_add, Public}, + publickey::{Public}, }; use engines::{ hbbft::{ diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index 135f5a898..7d56ba5d8 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -861,7 +861,7 @@ mod tests { use types::{header::Header, log_entry::LogEntry}; let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); - let engine = client.engine().clone(); + let engine = client.engine(); let validator_contract = "0000000000000000000000000000000000000005" .parse::
() .unwrap(); @@ -900,7 +900,7 @@ mod tests { use types::header::Header; let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); - let engine = client.engine().clone(); + let engine = client.engine(); let mut new_header = Header::default(); new_header.set_number(0); // so the validator set doesn't look for a log From cff8e2f6885559e138d956f8f7e8d7cdca35a6e4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 5 Nov 2024 21:18:12 +0100 Subject: [PATCH 279/687] cargo fix --lib -p parity-rpc --- crates/rpc/src/v1/helpers/mod.rs | 1 - crates/rpc/src/v1/types/mod.rs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/rpc/src/v1/helpers/mod.rs b/crates/rpc/src/v1/helpers/mod.rs index 686ec7738..a9f4d4f2e 100644 --- a/crates/rpc/src/v1/helpers/mod.rs +++ b/crates/rpc/src/v1/helpers/mod.rs @@ -40,7 +40,6 @@ mod subscription_manager; mod work; pub use self::{ - dispatch::{Dispatcher, FullDispatcher}, network_settings::NetworkSettings, poll_filter::{limit_logs, PollFilter, SyncPollFilter}, poll_manager::PollManager, diff --git a/crates/rpc/src/v1/types/mod.rs b/crates/rpc/src/v1/types/mod.rs index df1e7d535..255065a5a 100644 --- a/crates/rpc/src/v1/types/mod.rs +++ b/crates/rpc/src/v1/types/mod.rs @@ -20,7 +20,7 @@ pub use rpc_common::Bytes; pub use self::{ account_info::{AccountInfo, EthAccount, ExtAccountInfo, RecoveredAccount, StorageProof}, - block::{Block, BlockTransactions, Header, Rich, RichBlock, RichHeader}, + block::{Block, BlockTransactions, Header, RichBlock, RichHeader}, block_number::{block_number_to_id, BlockNumber}, call_request::CallRequest, confirmations::{ @@ -41,13 +41,13 @@ pub use self::{ rpc_settings::RpcSettings, secretstore::EncryptedDocumentKey, sync::{ - ChainStatus, EthProtocolInfo, PeerInfo, PeerNetworkInfo, PeerProtocolsInfo, Peers, + ChainStatus, Peers, SyncInfo, SyncStatus, TransactionStats, }, trace::{LocalizedTrace, TraceResults, TraceResultsWithTransactionHash}, trace_filter::TraceFilter, transaction::{LocalTransactionStatus, RichRawTransaction, Transaction}, - transaction_access_list::{AccessList, AccessListItem}, + transaction_access_list::{AccessList}, transaction_condition::TransactionCondition, transaction_request::TransactionRequest, work::Work, From 0fd1bafa928f3bb02b3115604ee96bd3a1b009f0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Nov 2024 23:30:28 +0100 Subject: [PATCH 280/687] cargo fix --- crates/accounts/ethstore/src/account/mod.rs | 2 +- crates/accounts/ethstore/src/json/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/accounts/ethstore/src/account/mod.rs b/crates/accounts/ethstore/src/account/mod.rs index b1757474f..ceb8116ac 100644 --- a/crates/accounts/ethstore/src/account/mod.rs +++ b/crates/accounts/ethstore/src/account/mod.rs @@ -23,7 +23,7 @@ mod version; pub use self::{ cipher::{Aes128Ctr, Cipher}, crypto::Crypto, - kdf::{Kdf, Pbkdf2, Prf, Scrypt}, + kdf::{Kdf, Pbkdf2, Prf}, safe_account::SafeAccount, version::Version, }; diff --git a/crates/accounts/ethstore/src/json/mod.rs b/crates/accounts/ethstore/src/json/mod.rs index 02614eaea..d9a5c7f3e 100644 --- a/crates/accounts/ethstore/src/json/mod.rs +++ b/crates/accounts/ethstore/src/json/mod.rs @@ -32,13 +32,13 @@ mod version; pub use self::{ bytes::Bytes, cipher::{Aes128Ctr, Cipher, CipherSer, CipherSerParams}, - crypto::{CipherText, Crypto}, + crypto::{Crypto}, error::Error, hash::{H128, H160, H256}, id::Uuid, kdf::{Kdf, KdfSer, KdfSerParams, Pbkdf2, Prf, Scrypt}, key_file::{KeyFile, OpaqueKeyFile}, - presale::{Encseed, PresaleWallet}, + presale::{PresaleWallet}, vault_file::VaultFile, vault_key_file::{ insert_vault_name_to_json_meta, remove_vault_name_from_json_meta, VaultKeyFile, From 5ef8a348f91293b2bdfe9209944cbb47997f190a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 7 Nov 2024 08:51:44 +0100 Subject: [PATCH 281/687] formatted imports --- crates/accounts/ethstore/src/json/mod.rs | 4 ++-- crates/concensus/ethash/src/keccak.rs | 4 +--- .../ethcore/src/engines/hbbft/contracts/keygen_history.rs | 5 +---- crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs | 4 +--- crates/rpc/src/v1/types/mod.rs | 7 ++----- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/crates/accounts/ethstore/src/json/mod.rs b/crates/accounts/ethstore/src/json/mod.rs index d9a5c7f3e..27d2c994e 100644 --- a/crates/accounts/ethstore/src/json/mod.rs +++ b/crates/accounts/ethstore/src/json/mod.rs @@ -32,13 +32,13 @@ mod version; pub use self::{ bytes::Bytes, cipher::{Aes128Ctr, Cipher, CipherSer, CipherSerParams}, - crypto::{Crypto}, + crypto::Crypto, error::Error, hash::{H128, H160, H256}, id::Uuid, kdf::{Kdf, KdfSer, KdfSerParams, Pbkdf2, Prf, Scrypt}, key_file::{KeyFile, OpaqueKeyFile}, - presale::{PresaleWallet}, + presale::PresaleWallet, vault_file::VaultFile, vault_key_file::{ insert_vault_name_to_json_meta, remove_vault_name_from_json_meta, VaultKeyFile, diff --git a/crates/concensus/ethash/src/keccak.rs b/crates/concensus/ethash/src/keccak.rs index 187e16b85..d3dbf1be9 100644 --- a/crates/concensus/ethash/src/keccak.rs +++ b/crates/concensus/ethash/src/keccak.rs @@ -29,7 +29,5 @@ pub mod keccak_512 { pub mod keccak_256 { use super::hash; - pub use self::hash::{ - keccak256 as inplace, keccak_256 as write, - }; + pub use self::hash::{keccak256 as inplace, keccak_256 as write}; } diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index 26e7a5e2c..80167b4c0 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -1,8 +1,5 @@ use client::traits::EngineClient; -use crypto::{ - self, - publickey::{Public}, -}; +use crypto::{self, publickey::Public}; use engines::{ hbbft::{ contracts::validator_set::{get_validator_pubkeys, ValidatorType}, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index a04a8ac11..d219ad4f7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -9,12 +9,10 @@ use crate::{ ethereum::public_key_to_address::public_key_to_address, }; +use super::{contracts::staking::get_pool_public_key, NodeId}; use bytes::ToPretty; - use ethereum_types::Address; -use super::{contracts::staking::get_pool_public_key, NodeId}; - #[derive(Clone, Debug)] struct ValidatorConnectionData { // mining_address: Address, diff --git a/crates/rpc/src/v1/types/mod.rs b/crates/rpc/src/v1/types/mod.rs index 255065a5a..de7478bba 100644 --- a/crates/rpc/src/v1/types/mod.rs +++ b/crates/rpc/src/v1/types/mod.rs @@ -40,14 +40,11 @@ pub use self::{ receipt::Receipt, rpc_settings::RpcSettings, secretstore::EncryptedDocumentKey, - sync::{ - ChainStatus, Peers, - SyncInfo, SyncStatus, TransactionStats, - }, + sync::{ChainStatus, Peers, SyncInfo, SyncStatus, TransactionStats}, trace::{LocalizedTrace, TraceResults, TraceResultsWithTransactionHash}, trace_filter::TraceFilter, transaction::{LocalTransactionStatus, RichRawTransaction, Transaction}, - transaction_access_list::{AccessList}, + transaction_access_list::AccessList, transaction_condition::TransactionCondition, transaction_request::TransactionRequest, work::Work, From ee62bf57e3ea52545b6245ed5d60c0e981033892 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 16 Nov 2024 20:00:26 +0100 Subject: [PATCH 282/687] fixed test imports --- crates/rpc/src/v1/tests/mocked/signing.rs | 5 +++-- crates/rpc/src/v1/types/transaction.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/rpc/src/v1/tests/mocked/signing.rs b/crates/rpc/src/v1/tests/mocked/signing.rs index a1a234605..0febdcb28 100644 --- a/crates/rpc/src/v1/tests/mocked/signing.rs +++ b/crates/rpc/src/v1/tests/mocked/signing.rs @@ -16,12 +16,12 @@ use std::{str::FromStr, sync::Arc, thread, time::Duration}; -use jsonrpc_core::{futures::Future, IoHandler, Success}; +use jsonrpc_core::{futures::Future, IoHandler, Success}; use v1::{ helpers::{ dispatch, external_signer::{SignerService, SigningQueue}, - nonce, FullDispatcher, + nonce, }, impls::SigningQueueClient, metadata::Metadata, @@ -39,6 +39,7 @@ use parity_runtime::{Executor, Runtime}; use parking_lot::Mutex; use serde_json; use types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; +use crate::dispatch::FullDispatcher; struct SigningTester { pub runtime: Runtime, diff --git a/crates/rpc/src/v1/types/transaction.rs b/crates/rpc/src/v1/types/transaction.rs index 220a701a9..85231b7f4 100644 --- a/crates/rpc/src/v1/types/transaction.rs +++ b/crates/rpc/src/v1/types/transaction.rs @@ -360,11 +360,12 @@ impl LocalTransactionStatus { #[cfg(test)] mod tests { + use crate::v1::types::transaction_access_list::AccessListItem; + use super::{LocalTransactionStatus, Transaction}; use ethereum_types::H256; use serde_json; use types::transaction::TypedTxId; - use v1::types::AccessListItem; #[test] fn test_transaction_serialize() { From 474a28f14ba832f54ba8588deed87a2fa977850d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 17 Nov 2024 11:02:21 +0100 Subject: [PATCH 283/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/rpc/src/v1/tests/mocked/signing.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/rpc/src/v1/tests/mocked/signing.rs b/crates/rpc/src/v1/tests/mocked/signing.rs index 0febdcb28..64adfbf54 100644 --- a/crates/rpc/src/v1/tests/mocked/signing.rs +++ b/crates/rpc/src/v1/tests/mocked/signing.rs @@ -16,7 +16,7 @@ use std::{str::FromStr, sync::Arc, thread, time::Duration}; -use jsonrpc_core::{futures::Future, IoHandler, Success}; +use jsonrpc_core::{futures::Future, IoHandler, Success}; use v1::{ helpers::{ dispatch, @@ -30,6 +30,7 @@ use v1::{ types::{ConfirmationResponse, RichRawTransaction}, }; +use crate::dispatch::FullDispatcher; use accounts::AccountProvider; use bytes::ToPretty; use crypto::publickey::{Generator, Random, Secret}; @@ -39,7 +40,6 @@ use parity_runtime::{Executor, Runtime}; use parking_lot::Mutex; use serde_json; use types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; -use crate::dispatch::FullDispatcher; struct SigningTester { pub runtime: Runtime, From 28523a47f34a383fac23574ea59eaf28f3125bb5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 17 Nov 2024 11:51:00 +0100 Subject: [PATCH 284/687] commented out currently unused fields for hbbft peers management. peers management does not report a connected peer now, if connecting to it fails. (this COULD be a breaking change, requires testing) --- .../engines/hbbft/hbbft_peers_management.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index d219ad4f7..1b172f273 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -16,9 +16,9 @@ use ethereum_types::Address; #[derive(Clone, Debug)] struct ValidatorConnectionData { // mining_address: Address, - staking_address: Address, - socket_addr: SocketAddr, - public_key: NodeId, + // staking_address: Address, + // socket_addr: SocketAddr, + // public_key: NodeId, peer_string: String, mining_address: Address, } @@ -40,7 +40,9 @@ impl HbbftPeersManagement { } } - /// connections are not always required + /// connections are not always required. + /// - during syncing + /// - if not validator address specified. fn should_not_connect(&self, client: &dyn BlockChainClient) -> bool { // don't do any connections while the network is syncing. // the connection is not required yet, and might be outdated. @@ -62,6 +64,8 @@ impl HbbftPeersManagement { client_arc: &Arc, pending_validators: &Vec
, ) -> Result { + + let block_chain_client = client_arc .as_full_client() .ok_or("reserverd peers: could not retrieve BlockChainClient for connect_to_pending_validators")?; @@ -542,14 +546,15 @@ fn connect_to_validator_core( info!(target: "engine", "adding reserved peer: {}", peer_string); if let Err(err) = peers_management.add_reserved_peer(&peer_string) { warn!(target: "engine", "failed to adding reserved: {} : {}", peer_string, err); + return None; } return Some(ValidatorConnectionData { - staking_address: staking_address, + //staking_address: staking_address, //mining_address: *address, - socket_addr: socket_addr, + //socket_addr: socket_addr, peer_string, - public_key: node_id.clone(), + //public_key: node_id.clone(), mining_address: Address::zero(), // all caller of this function will set this value. }); } else { From 3b38650a6fd799ff8a65ea39f40f13e8bf211f0a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 17 Nov 2024 11:51:23 +0100 Subject: [PATCH 285/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 1b172f273..2bc56f91b 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -64,8 +64,6 @@ impl HbbftPeersManagement { client_arc: &Arc, pending_validators: &Vec
, ) -> Result { - - let block_chain_client = client_arc .as_full_client() .ok_or("reserverd peers: could not retrieve BlockChainClient for connect_to_pending_validators")?; From 0db8cade08d726982218dba779088db89e59b547 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 20 Nov 2024 12:06:19 +0100 Subject: [PATCH 286/687] for the sake of faster CI tests, and not overshooting the github quotas, long running tests are commented out at the moment. --- .github/workflows/build-test.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index ee7e5709b..94429019f 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -15,13 +15,14 @@ jobs: - ubuntu-latest # - macos-latest toolchain: - - 1.72 + - 1.75 runs-on: ${{ matrix.platform }} steps: - name: Checkout sources uses: actions/checkout@main with: - submodules: true + submodules: false + # submodules: true // we do not need submodules, if we are not running the JSON tests. - name: Install toolchain uses: actions-rs/toolchain@v1 with: @@ -32,7 +33,8 @@ jobs: uses: actions-rs/cargo@v1 with: command: test - args: --locked --all --release --features "json-tests" --verbose --no-run + #args: deactivated JSON Tests, so we do not run out of quota on CI tests for merge intesive time. --locked --all --release --features "json-tests" --verbose --no-run + args: --locked --all --release --verbose --no-run - name: Run tests for ${{ matrix.platform }} uses: actions-rs/cargo@v1 with: From 942c171a78e812430f062c2e976a622a411cc8b4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 20 Nov 2024 12:10:45 +0100 Subject: [PATCH 287/687] unused const since removing registry usage: SERVICE_TRANSACTION_CONTRACT_REGISTRY_NAME --- crates/concensus/miner/src/service_transaction_checker.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index d581591bd..59f3d22ec 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -28,8 +28,6 @@ use_contract!( "res/contracts/service_transaction.json" ); -const SERVICE_TRANSACTION_CONTRACT_REGISTRY_NAME: &'static str = "service_transaction_checker"; - /// Service transactions checker. #[derive(Default, Clone)] pub struct ServiceTransactionChecker { From 734622239ec9a95e78d53a866fe48e3d29861c6c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 20 Nov 2024 12:40:18 +0100 Subject: [PATCH 288/687] fix for JSON tests deactivation. --- .github/workflows/build-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 94429019f..81a1fb526 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -39,4 +39,6 @@ jobs: uses: actions-rs/cargo@v1 with: command: test - args: --locked --all --release --features "json-tests" --verbose + #args: deactivated JSON Tests --locked --all --release --features "json-tests" --verbose + args: --locked --all --release --verbose + From a112e6a271a9beda9d5e2ae151cdf5ebd60f9f29 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 22 Nov 2024 11:38:06 +0100 Subject: [PATCH 289/687] build tests: include submodules again, since it leads to compile errors of tests --- .github/workflows/build-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 94429019f..d0af0afda 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -21,8 +21,7 @@ jobs: - name: Checkout sources uses: actions/checkout@main with: - submodules: false - # submodules: true // we do not need submodules, if we are not running the JSON tests. + submodules: true - name: Install toolchain uses: actions-rs/toolchain@v1 with: From b3efe62d1d3f2613862d418b19b30417187db8d4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 24 Nov 2024 22:04:01 +0100 Subject: [PATCH 290/687] dont crash on interpreting the result of the reward call. https://github.com/DMDcoin/diamond-node/issues/143 --- .../src/engines/hbbft/block_reward_hbbft.rs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs index 3455e8832..1e75af311 100644 --- a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs @@ -49,18 +49,24 @@ impl BlockRewardContract { /// and returns the reward allocation (address - value). The block reward contract *must* be /// called by the system address so the `caller` must ensure that (e.g. using /// `machine.execute_as_system`). - pub fn reward(&self, caller: &mut SystemOrCodeCall, is_epoch_end: bool) -> Result { + pub fn reward(&self, caller: &mut SystemOrCodeCall, is_epoch_end: bool) -> Result<(), Error> { let (input, decoder) = block_reward_contract::functions::reward::call(is_epoch_end); - let output = caller(self.kind.clone(), input) .map_err(Into::into) .map_err(::engines::EngineError::FailedSystemCall)?; - let rewards_native = decoder - .decode(&output) - .map_err(|err| err.to_string()) - .map_err(::engines::EngineError::FailedSystemCall)?; + match decoder.decode(&output) { + Ok(_rewards_native) => {} + Err(err) => { + debug!(target: "engine", "Failed to decode block reward contract. output length {:?} output: {:?}: Error {:?}", output.len(), output, err); + } + } + + return Ok(()); - Ok(rewards_native) + // let rewards_native = decoder + // .decode(&output) + // .map_err(|err| err.to_string()) + // .map_err(::engines::EngineError::FailedSystemCall)?; } } From 6816906a5d90c542038b3df461f9074d6f430713 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 11 Dec 2024 19:25:12 +0100 Subject: [PATCH 291/687] Stage 5 verification fail logging improvements --- crates/ethcore/src/client/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index e6857c03f..645e26487 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -582,7 +582,7 @@ impl Importer { { let best_block_number = client.chain.read().best_block_number(); if best_block_number >= header.number() { - warn!(target: "client", "Stage 5 verification failed for #{} ({})\nBlock is ancient (current best block: #{}).", header.number(), header.hash(), best_block_number); + warn!(target: "client", "Stage 5 verification failed for #{} ({})\nBlock is ancient (current best block: #{}). Error: {:?}", header.number(), header.hash(), best_block_number, e); bail!("Block is ancient"); } else { warn!(target: "client", "Stage 5 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e); From bb74f5556275a6c4c7403b72729368fdbf92015f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Dec 2024 17:02:29 +0100 Subject: [PATCH 292/687] hbbft nessage memorium: added timestamps for tracking messages --- .../src/engines/hbbft/hbbft_message_memorium.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 184c187d2..b3f545793 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -6,7 +6,10 @@ use bytes::ToPretty; use hbbft::honey_badger::{self}; use parking_lot::RwLock; use stats::PrometheusMetrics; -use std::{collections::VecDeque, time::Duration}; +use std::{ + collections::VecDeque, + time::{Duration, Instant}, +}; // use threshold_crypto::{SignatureShare}; use engines::hbbft::{sealing, NodeId}; @@ -46,10 +49,14 @@ pub(crate) enum SealMessageState { pub(crate) struct NodeStakingEpochHistory { node_id: NodeId, last_good_sealing_message: u64, + last_good_sealing_message_time: Instant, last_late_sealing_message: u64, + last_late_sealing_message_time: Instant, last_error_sealing_message: u64, + last_error_sealing_message_time: Instant, // summed up lateness of all seals, including bad seals. cumulative_lateness: u64, + sealing_blocks_good: Vec, sealing_blocks_late: Vec, sealing_blocks_bad: Vec, @@ -64,11 +71,15 @@ pub(crate) struct NodeStakingEpochHistory { impl NodeStakingEpochHistory { pub fn new(node_id: NodeId) -> Self { + let now = Instant::now(); NodeStakingEpochHistory { node_id, last_good_sealing_message: 0, + last_good_sealing_message_time: now, last_late_sealing_message: 0, + last_late_sealing_message_time: now, last_error_sealing_message: 0, + last_error_sealing_message_time: now, cumulative_lateness: 0, sealing_blocks_good: Vec::new(), sealing_blocks_late: Vec::new(), @@ -132,6 +143,7 @@ impl NodeStakingEpochHistory { self.cumulative_lateness += self.calc_cumulative_lateness_gap(event.block_num, staking_epoch_start_block_num); self.last_good_sealing_message = event.block_num; + self.last_good_sealing_message_time = Instant::now(); self.sealing_blocks_good.push(event.block_num); } @@ -149,6 +161,7 @@ impl NodeStakingEpochHistory { self.calc_cumulative_lateness_gap(event.block_num, staking_epoch_start_block); self.last_late_sealing_message = event.block_num; + self.last_late_sealing_message_time = Instant::now(); self.cumulative_lateness += event.get_lateness(); self.sealing_blocks_late.push(event.block_num); } @@ -172,6 +185,7 @@ impl NodeStakingEpochHistory { self.calc_cumulative_lateness_gap(block_num, staking_epoch_start_block_num); self.cumulative_lateness += 1; self.last_error_sealing_message = event.block_num; + self.last_error_sealing_message_time = Instant::now(); self.sealing_blocks_good.push(event.block_num); } From caadaa6305f38ddc2eac589644e41849110cfcbc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Dec 2024 18:58:19 +0100 Subject: [PATCH 293/687] Diamond - Node: 0.9.5: Early Epoch End: switch to time based System instead of blockbased --- CHANGELOG.md | 7 +++++++ .../engines/hbbft/hbbft_early_epoch_end_manager.rs | 12 +++++++----- .../src/engines/hbbft/hbbft_message_memorium.rs | 11 ++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e39597f1..1e57e4c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +## Diamond Node Software 3.3.5-hbbft-0.9.5 + +- [Improved Logging for Stage 5 Errors] (https://github.com/DMDcoin/diamond-node/issues/147) +- [Early Epoch end: Applying new time based rules] (https://github.com/DMDcoin/diamond-node/issues/87) + + ## Diamond Node Software 3.3.5-hbbft-0.9.4 - [Fixed: is major syncing information is wrong.] (https://github.com/DMDcoin/diamond-node/issues/73) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 5b8f2411b..9274b0728 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -285,6 +285,10 @@ impl HbbftEarlyEpochEndManager { }; let treshold: u64 = 10; + // todo: read this out from contracts: ConnectivityTrackerHbbft -> reportDisallowPeriod + // requires us to update the Contracts ABIs: + // https://github.com/DMDcoin/diamond-node/issues/115 + let treshold_time = Duration::from_secs(60 * 15); if block_num < self.start_block + treshold { // not enought blocks have passed this epoch, @@ -308,11 +312,10 @@ impl HbbftEarlyEpochEndManager { }; if let Some(node_history) = epoch_history.get_history_for_node(validator) { - let last_sealing_message = node_history.get_sealing_message(); - - if last_sealing_message < block_num - treshold { + let last_sealing_message_time = node_history.get_last_sealing_message_time(); + let last_sealing_message_lateness = last_sealing_message_time.elapsed(); + if last_sealing_message_lateness > treshold_time { // we do not have to send notification, if we already did so. - if !self.is_reported(client, validator_address) { // this function will also add the validator to the list of flagged validators. self.notify_about_missing_validator(&validator, client, full_client); @@ -320,7 +323,6 @@ impl HbbftEarlyEpochEndManager { } else { // this validator is OK. // maybe it was flagged and we need to unflag it ? - if self.is_reported(client, validator_address) { self.notify_about_validator_reconnect(&validator, full_client, client); } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index b3f545793..2860c0c32 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -237,13 +237,20 @@ impl NodeStakingEpochHistory { + self.get_total_error_sealing_messages() } - pub fn get_sealing_message(&self) -> u64 { + pub fn get_last_sealing_message(&self) -> u64 { u64::max( self.last_late_sealing_message, self.last_good_sealing_message, ) } + pub fn get_last_sealing_message_time(&self) -> Instant { + Instant::max( + self.last_late_sealing_message_time, + self.last_good_sealing_message_time, + ) + } + pub fn get_last_late_sealing_message(&self) -> u64 { self.last_late_sealing_message } @@ -959,8 +966,6 @@ impl HbbftMessageMemorium { None } - pub fn get_validator_last_late_block(&self, hbbft_epoch_number: u64) {} - // report that hbbft has switched to a new staking epoch pub fn report_new_epoch(&mut self, staking_epoch: u64, staking_epoch_start_block: u64) { debug!(target: "hbbft_message_memorium", "report new epoch: {}", staking_epoch); From 42efb635058eb70b5df9d441522ffa12b86a5345 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Dec 2024 12:20:37 +0100 Subject: [PATCH 294/687] improved logging for: https://github.com/DMDcoin/diamond-node/issues/150 --- crates/ethcore/sync/src/api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 1720750d7..4ee077411 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -696,7 +696,7 @@ impl ChainNotify for EthSync { Some(session_info) => { session_info.id == node_id }, - None => { warn!(target:"sync", "No session exists for peerId {:?}", p); false}, + None => { warn!(target:"sync", "No session exists for peerId {:?} Node: {:?}", p, node_id); false}, } }); From b09090eeb73670a4101ef860eb7f04b8326d28e6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Dec 2024 12:25:07 +0100 Subject: [PATCH 295/687] Early epoch end: Only send disconnect reports if Nodes have been seen as unconnected for longer than 60 minutes. https://github.com/DMDcoin/diamond-node/issues/87 + early returning if that hour did not even had passed yet. --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 9274b0728..d52321a14 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -288,7 +288,12 @@ impl HbbftEarlyEpochEndManager { // todo: read this out from contracts: ConnectivityTrackerHbbft -> reportDisallowPeriod // requires us to update the Contracts ABIs: // https://github.com/DMDcoin/diamond-node/issues/115 - let treshold_time = Duration::from_secs(60 * 15); + let treshold_time = Duration::from_secs(60 * 60); + + if self.start_time.elapsed() < treshold_time { + debug!(target: "engine", "early-epoch-end: no decision: Treshold time not reached."); + return; + } if block_num < self.start_block + treshold { // not enought blocks have passed this epoch, From e936ece001ae999b3d36024206818e3103039739 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Dec 2024 12:30:35 +0100 Subject: [PATCH 296/687] Release 0.9.6 --- CHANGELOG.md | 13 +++++++++++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e57e4c33..23b6702c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,17 @@ + +## Diamond Node Software 3.3.5-hbbft-0.9.6 + +- [Early Epoch End: only report disconnectivities that exist for longer than 60 Minutes] (https://github.com/DMDcoin/diamond-node/issues/87) +- [Improved Logging for Hbbft Session Management] (https://github.com/DMDcoin/diamond-node/issues/150) + +## Diamond Node Software 3.3.5-hbbft-0.9.5 + +- [Improved Logging of ] (https://github.com/DMDcoin/diamond-node/issues/147) +- [Early Epoch end: Applying new time based rules] (https://github.com/DMDcoin/diamond-node/issues/87) + + + ## Diamond Node Software 3.3.5-hbbft-0.9.5 - [Improved Logging for Stage 5 Errors] (https://github.com/DMDcoin/diamond-node/issues/147) diff --git a/Cargo.lock b/Cargo.lock index b10b21bc3..4a07e3b5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -843,7 +843,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.9.4" +version = "3.3.5-hbbft-0.9.6" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3574,7 +3574,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.9.4" +version = "3.3.5-hbbft-0.9.6" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 79be567b4..d3bca4e88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.9.4" +version = "3.3.5-hbbft-0.9.6" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 4ace8576c..1a5882454 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.9.4" +version = "3.3.5-hbbft-0.9.6" authors = [ "bit.diamonds developers", "OpenEthereum developers", From fdc60da602ecf6e023c91f325cfdf42ce62c36b5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Dec 2024 00:50:55 +0100 Subject: [PATCH 297/687] Solved Issue where Validator Candidate were sending disconnect reports, even if they are not part of the current validatror set. https://github.com/DMDcoin/diamond-node/issues/153 --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 151 ++++++++++-------- .../ethcore/src/engines/hbbft/hbbft_state.rs | 4 + 2 files changed, 90 insertions(+), 65 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 16a458bd2..925eb3887 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -942,26 +942,16 @@ impl HoneyBadgerBFT { block_chain_client: &dyn BlockChainClient, engine_client: &dyn EngineClient, mining_address: &Address, + epoch_start_block: u64, + epoch_num: u64, + validator_set: &Vec, ) { // todo: acquire allowed devp2p warmup time from contracts ?! let allowed_devp2p_warmup_time = Duration::from_secs(1200); debug!(target: "engine", "early-epoch-end: handle_early_epoch_end."); - let hbbft_state = if let Some(s) = self.hbbft_state.try_read_for(Duration::from_millis(300)) - { - s - } else { - warn!(target: "engine", "early-epoch-end: could not acquire read lock for hbbft state."); - return; - }; - - let epoch_num = hbbft_state.get_current_posdao_epoch(); - let epoch_start_block = hbbft_state.get_current_posdao_epoch_start_block(); - let validator_set = hbbft_state.get_validator_set(); - // we got everything we need from hbbft_state - drop lock ASAP. - std::mem::drop(hbbft_state); if let Some(memorium) = self .hbbft_message_dispatcher @@ -984,7 +974,7 @@ impl HoneyBadgerBFT { engine_client, epoch_num, epoch_start_block, - validator_set, + validator_set.clone(), mining_address, ); @@ -1033,49 +1023,53 @@ impl HoneyBadgerBFT { } }; - self.handle_early_epoch_end(block_chain_client, engine_client, &mining_address); - let should_handle_availability_announcements = self.should_handle_availability_announcements(); let should_handle_internet_address_announcements = self.should_handle_internet_address_announcements(block_chain_client); let should_connect_to_validator_set = self.should_connect_to_validator_set(); + let mut should_handle_early_epoch_end = false; + + // we just keep those variables here, because we need them in the early_epoch_end_manager. + // this is just an optimization, so we do not acquire the lock for that much time. + let mut validator_set: Vec = Vec::new(); + let mut epoch_start_block: u64 = 0; + let mut epoch_num: u64 = 0; + + { + let hbbft_state_option = + self.hbbft_state.try_read_for(Duration::from_millis(50)); + match hbbft_state_option { + Some(hbbft_state) => { + should_handle_early_epoch_end = hbbft_state.is_validator(); + + // if we are a pending validator, we will also do the reserved peers management. + if should_handle_early_epoch_end { + // we already remember here stuff the early epoch manager needs, + // so we do not have to acquire the lock for that long. + epoch_num = hbbft_state.get_current_posdao_epoch(); + epoch_start_block = + hbbft_state.get_current_posdao_epoch_start_block(); + validator_set = hbbft_state.get_validator_set(); + } + } + None => { + // maybe improve here, to return with a result, that triggers a retry soon. + warn!(target: "engine", "Unable to do_validator_engine_actions: Could not acquire read lock for hbbft state. Unable to decide about early epoch end."); + } + }; + } // drop lock for hbbft_state // if we do not have to do anything, we can return early. if !(should_handle_availability_announcements || should_handle_internet_address_announcements - || should_connect_to_validator_set) + || should_connect_to_validator_set + || should_handle_early_epoch_end) { return Ok(()); } - // TODO: - // staking by mining address could be cached. - // but it COULD also get changed in the contracts, during the time the node is running. - // most likely since a Node can get staked, and than it becomes a mining address. - // a good solution for this is not to do this expensive operation that fequently. - let staking_address = match staking_by_mining_address( - engine_client, - &mining_address, - ) { - Ok(staking_address) => { - if staking_address.is_zero() { - //TODO: here some fine handling can improve performance. - //with this implementation every node (validator or not) - //needs to query this state every block. - //trace!(target: "engine", "availability handling not a validator"); - return Ok(()); - } - staking_address - } - Err(call_error) => { - error!(target: "engine", "unable to ask for corresponding staking address for given mining address: {:?}", call_error); - let message = format!("unable to ask for corresponding staking address for given mining address: {:?}", call_error); - return Err(message.into()); - } - }; - // if we are not a potential validator, we already have already returned here. if should_handle_availability_announcements { self.handle_availability_announcements( @@ -1088,6 +1082,32 @@ impl HoneyBadgerBFT { // since get latest nonce respects the pending transactions, // we don't have to take care of sending 2 transactions at once. if should_handle_internet_address_announcements { + // TODO: + // staking by mining address could be cached. + // but it COULD also get changed in the contracts, during the time the node is running. + // most likely since a Node can get staked, and than it becomes a mining address. + // a good solution for this is not to do this expensive operation that fequently. + let staking_address = match staking_by_mining_address( + engine_client, + &mining_address, + ) { + Ok(staking_address) => { + if staking_address.is_zero() { + //TODO: here some fine handling can improve performance. + //with this implementation every node (validator or not) + //needs to query this state every block. + //trace!(target: "engine", "availability handling not a validator"); + return Ok(()); + } + staking_address + } + Err(call_error) => { + error!(target: "engine", "unable to ask for corresponding staking address for given mining address: {:?}", call_error); + let message = format!("unable to ask for corresponding staking address for given mining address: {:?}", call_error); + return Err(message.into()); + } + }; + if let Some(mut peers_management) = self .peers_management .try_lock_for(Duration::from_millis(100)) @@ -1099,35 +1119,34 @@ impl HoneyBadgerBFT { &staking_address, ) { error!(target: "engine", "Error trying to announce own internet address: {:?}", error); - } else { } } } + // TODO: There or more trigger reasons now to access the state. if should_connect_to_validator_set { - // we - let network_info_o = if let Some(hbbft_state) = - self.hbbft_state.try_read_for(Duration::from_millis(50)) + if let Some(mut peers_management) = self + .peers_management + .try_lock_for(Duration::from_millis(100)) { - Some(hbbft_state.get_validator_set()) - } else { - None - }; - - if let Some(network_info) = network_info_o { - if let Some(mut peers_management) = self - .peers_management - .try_lock_for(Duration::from_millis(100)) - { - // connecting to current validators. - peers_management - .connect_to_current_validators(&network_info, &client_arc); - self.has_connected_to_validator_set - .store(true, Ordering::SeqCst); - } + // connecting to current validators. + peers_management.connect_to_current_validators(&validator_set, &client_arc); + self.has_connected_to_validator_set + .store(true, Ordering::SeqCst); } } + if should_handle_early_epoch_end { + self.handle_early_epoch_end( + block_chain_client, + engine_client, + &mining_address, + epoch_start_block, + epoch_num, + &validator_set, + ); + } + return Ok(()); } @@ -1204,7 +1223,9 @@ impl HoneyBadgerBFT { .connect_to_pending_validators(&client, &validators) { Ok(value) => { - debug!(target: "engine", "added to additional {:?} reserved peers, because they are pending validators.", value); + if value > 0 { + debug!(target: "engine", "added to additional {:?} reserved peers, because they are pending validators.", value); + } } Err(err) => { warn!(target: "engine", "Error connecting to other pending validators: {:?}", err); @@ -1240,7 +1261,7 @@ impl HoneyBadgerBFT { } } - /** returns if the signer of hbbft is tracked as available in the hbbft contracts. */ + /** returns if the signer of hbbft is tracked as available in the hbbft contracts. NOTE:Low Performance.*/ pub fn is_available(&self) -> Result { match self.signer.read().as_ref() { Some(signer) => { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 0cf959405..23fb7fe58 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -631,6 +631,10 @@ impl HbbftState { // return &self.network_info; // } + pub fn is_validator(&self) -> bool { + self.network_info.as_ref().is_some_and(|n| n.is_validator()) + } + pub fn get_validator_set(&self) -> Vec { if let Some(network_info) = &self.network_info { let result: Vec = network_info From 5e661e48037d991ff012af750673eda3c6d377b1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Dec 2024 00:54:44 +0100 Subject: [PATCH 298/687] RELEASE 3.3.5-hbbft-0.9.7 --- CHANGELOG.md | 3 +++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23b6702c7..9e4cabb76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ +## Diamond Node Software 3.3.5-hbbft-0.9.7 + +- [Nodes that are not a active validator seem to try to send connectivity reports] (https://github.com/DMDcoin/diamond-node/issues/153) ## Diamond Node Software 3.3.5-hbbft-0.9.6 diff --git a/Cargo.lock b/Cargo.lock index 4a07e3b5e..54f12b2d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -843,7 +843,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.9.6" +version = "3.3.5-hbbft-0.9.7" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3574,7 +3574,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.9.6" +version = "3.3.5-hbbft-0.9.7" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index d3bca4e88..a91dcce86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.9.6" +version = "3.3.5-hbbft-0.9.7" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 1a5882454..a2ae34563 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.9.6" +version = "3.3.5-hbbft-0.9.7" authors = [ "bit.diamonds developers", "OpenEthereum developers", From f51d849cc84ae21f570e0198abc43ab26a5c8f1f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Dec 2024 18:30:01 +0100 Subject: [PATCH 299/687] better information for disconnected reserved peers --- crates/ethcore/sync/src/api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 4ee077411..b1d8c09d5 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -569,7 +569,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler { fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId) { trace_time!("sync::disconnected"); if io.is_reserved_peer(*peer) { - trace!(target: "sync", "Disconnected from reserved peer {:?}", io.session_info(*peer).expect("").id); + trace!(target: "sync", "Disconnected from reserved peer peerID: {} {}",peer, io.session_info(*peer).expect("").id.map_or("".to_string(), |f| format!("{:?}", f))); } if io.subprotocol_name() != PAR_PROTOCOL { self.sync.write().on_peer_aborting( From 6e111d536c7515930424894d6e0531c363008f2d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Dec 2024 18:30:39 +0100 Subject: [PATCH 300/687] log level adjustments --- crates/ethcore/sync/src/chain/handler.rs | 2 +- crates/net/network-devp2p/src/host.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index b9c2a1072..484fcb267 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -167,7 +167,7 @@ impl SyncHandler { Some(session) => ip_addr = session.remote_address.to_string(), None => {} } - trace!(target:"sync", "Disabling Peer (this Software Version not whitelisted) {} ip:{} ", peer_version, ip_addr); + debug!(target:"sync", "Disabling Peer (this Software Version not whitelisted) {} ip:{} ", peer_version, ip_addr); io.disable_peer(peer); } else if let Err(e) = sync.send_status(io, peer) { debug!(target:"sync", "Error sending status request: {:?}", e); diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index e8d846889..0cf5ec5ad 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -1341,7 +1341,7 @@ impl IoHandler for Host { nodes.mark_as_useless(id); } } - trace!(target: "network", "Disabling peer {}", peer); + debug!(target: "network", "Disabling peer {}", peer); self.kill_connection(*peer, io, false); } NetworkIoMessage::InitPublicInterface => self From eda3ac557b334be268b3ee16e51e5d5191c6dbc3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 21 Dec 2024 20:27:28 +0100 Subject: [PATCH 301/687] refactored fetching of data for decition making for validator action: instead of fetching data one by one, we store the data in a Mutexed cache, with only short locks. This makes it happen to access the (calculation expensive) data more often, for example in the grafana interface. --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 180 ++++-------------- .../src/engines/hbbft/hbbft_engine_cache.rs | 156 +++++++++++++++ crates/ethcore/src/engines/hbbft/mod.rs | 1 + 3 files changed, 196 insertions(+), 141 deletions(-) create mode 100644 crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 925eb3887..7241917e3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1,6 +1,6 @@ use super::{ block_reward_hbbft::BlockRewardContract, - hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, + hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_engine_cache::HbbftEngineCache, }; use crate::{ client::BlockChainClient, @@ -92,6 +92,7 @@ pub struct HoneyBadgerBFT { peers_management: Mutex, current_minimum_gas_price: Mutex>, early_epoch_manager: Mutex>, + hbbft_engine_cache: Mutex, } struct TransitionHandler { @@ -360,45 +361,31 @@ impl IoHandler<()> for TransitionHandler { debug!(target: "consensus", "Honey Badger check for unavailability shutdown."); - match self.engine.is_staked() { - Ok(is_stacked) => { - if is_stacked { - debug!(target: "consensus", "is_staked: {}", is_stacked); - match self.engine.is_available() { - Ok(is_available) => { - if !is_available { - warn!(target: "consensus", "Initiating Shutdown: Honey Badger Consensus detected that this Node has been flagged as unavailable, while it should be available."); - - if let Some(ref weak) = *self.client.read() { - if let Some(c) = weak.upgrade() { - if let Some(id) = c.block_number(BlockId::Latest) { - warn!(target: "consensus", "BlockID: {id}"); - } - } - } + let is_staked = self.engine.is_staked(); + if is_staked { + debug!(target: "consensus", "We are staked!"); + let is_available = self.engine.is_available(); + if !is_available { + warn!(target: "consensus", "Initiating Shutdown: Honey Badger Consensus detected that this Node has been flagged as unavailable, while it should be available."); + + if let Some(ref weak) = *self.client.read() { + if let Some(c) = weak.upgrade() { + if let Some(id) = c.block_number(BlockId::Latest) { + warn!(target: "consensus", "BlockID: {id}"); + } + } + } - let id: usize = std::process::id() as usize; - let thread_id = std::thread::current().id(); - info!(target: "engine", "Waiting for Signaling shutdown to process ID: {id} thread: {:?}", thread_id); + let id: usize = std::process::id() as usize; + let thread_id = std::thread::current().id(); + info!(target: "engine", "Waiting for Signaling shutdown to process ID: {id} thread: {:?}", thread_id); - if let Some(ref weak) = *self.client.read() { - if let Some(client) = weak.upgrade() { - info!(target: "engine", "demanding shutdown from hbbft engine."); - client.demand_shutdown(); - } - } - } - // if the node is available, everythign is fine! - } - Err(error) => { - warn!(target: "consensus", "Could not query Honey Badger check for unavailability shutdown. {:?}", error); - } + if let Some(ref weak) = *self.client.read() { + if let Some(client) = weak.upgrade() { + info!(target: "engine", "demanding shutdown from hbbft engine."); + client.demand_shutdown(); } } - // else: just a regular node. - } - Err(error) => { - warn!(target: "consensus", "Could not query Honey Badger check if validator is staked. {:?}", error); } } } else if timer == ENGINE_DELAYED_UNITL_SYNCED_TOKEN { @@ -451,6 +438,7 @@ impl HoneyBadgerBFT { peers_management: Mutex::new(HbbftPeersManagement::new()), current_minimum_gas_price: Mutex::new(None), early_epoch_manager: Mutex::new(None), + hbbft_engine_cache: Mutex::new(HbbftEngineCache::new()), }); if !engine.params.is_unit_test.unwrap_or(false) { @@ -1014,6 +1002,15 @@ impl HoneyBadgerBFT { } }; + let engine_client = client_arc.as_ref(); + if let Err(err) = self + .hbbft_engine_cache + .lock() + .refresh_cache(mining_address, engine_client) + { + trace!(target: "engine", "do_validator_engine_actions: data could not get updated, follow up tasks might fail: {:?}", err); + } + let engine_client = client_arc.deref(); let block_chain_client = match engine_client.as_full_client() { @@ -1261,114 +1258,14 @@ impl HoneyBadgerBFT { } } - /** returns if the signer of hbbft is tracked as available in the hbbft contracts. NOTE:Low Performance.*/ - pub fn is_available(&self) -> Result { - match self.signer.read().as_ref() { - Some(signer) => { - match self.client_arc() { - Some(client) => { - let engine_client = client.deref(); - let mining_address = signer.address(); - - if mining_address.is_zero() { - debug!(target: "consensus", "is_available: not available because mining address is zero: "); - return Ok(false); - } - match super::contracts::validator_set::get_validator_available_since( - engine_client, - &mining_address, - ) { - Ok(available_since) => { - debug!(target: "consensus", "available_since: {}", available_since); - return Ok(!available_since.is_zero()); - } - Err(err) => { - warn!(target: "consensus", "Error get get_validator_available_since: ! {:?}", err); - } - } - } - None => { - // warn!("Could not retrieve address for writing availability transaction."); - warn!(target: "consensus", "is_available: could not get engine client"); - } - } - } - None => {} - } - return Ok(false); + /** returns if the signer of hbbft is tracked as available in the hbbft contracts..*/ + pub fn is_available(&self) -> bool { + self.hbbft_engine_cache.lock().is_available() } /** returns if the signer of hbbft is stacked. */ - pub fn is_staked(&self) -> Result { - // is the configured validator stacked ?? - - // TODO: improvement: - // since a signer address can not change after boot, - // we can just cash the value - // so we don't need a read lock here, - // getting the numbers of required read locks down (deadlock risk) - // and improving the performance. - - match self.signer.read().as_ref() { - Some(signer) => { - match self.client_arc() { - Some(client) => { - let engine_client = client.deref(); - let mining_address = signer.address(); - - if mining_address.is_zero() { - return Ok(false); - } - - match super::contracts::validator_set::staking_by_mining_address( - engine_client, - &mining_address, - ) { - Ok(staking_address) => { - // if there is no pool for this validator defined, we know that - if staking_address.is_zero() { - return Ok(false); - } - match super::contracts::staking::stake_amount( - engine_client, - &staking_address, - &staking_address, - ) { - Ok(stake_amount) => { - debug!(target: "consensus", "stake_amount: {}", stake_amount); - - // we need to check if the pool stake amount is >= minimum stake - match super::contracts::staking::candidate_min_stake( - engine_client, - ) { - Ok(min_stake) => { - debug!(target: "consensus", "min_stake: {}", min_stake); - return Ok(stake_amount.ge(&min_stake)); - } - Err(err) => { - error!(target: "consensus", "Error get candidate_min_stake: ! {:?}", err); - } - } - } - Err(err) => { - warn!(target: "consensus", "Error get stake_amount: ! {:?}", err); - } - } - } - Err(err) => { - warn!(target: "consensus", "Error get staking_by_mining_address: ! {:?}", err); - } - } - } - None => { - // warn!("Could not retrieve address for writing availability transaction."); - warn!(target: "consensus", "could not get engine client"); - } - } - } - None => {} - } - return Ok(false); + pub fn is_staked(&self) -> bool { + self.hbbft_engine_cache.lock().is_staked() } fn start_hbbft_epoch_if_ready(&self) { @@ -1788,6 +1685,7 @@ impl Engine for HoneyBadgerBFT { // note: this is by design not part of the PrometheusMetrics trait, // it is part of the Engine trait and does nothing by default. fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { + let is_staked = self.is_staked(); self.hbbft_message_dispatcher.prometheus_metrics(registry); if let Some(early_epoch_manager_option) = self .early_epoch_manager diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs new file mode 100644 index 000000000..24ecaaebb --- /dev/null +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs @@ -0,0 +1,156 @@ +use crate::client::EngineClient; +use error::Error; +use ethereum_types::Address; +use parking_lot::Mutex; + +#[derive(Debug, Clone)] +pub struct HbbftEngineCacheData { + pub signer_address: Address, + + pub is_staked: bool, + + pub is_available: bool, +} + +impl HbbftEngineCacheData { + pub fn new() -> Self { + HbbftEngineCacheData { + signer_address: Address::zero(), + is_staked: false, + is_available: false, + } + } +} + +pub struct HbbftEngineCache { + data: Mutex, +} + +impl HbbftEngineCache { + pub fn new() -> Self { + HbbftEngineCache { + data: Mutex::new(HbbftEngineCacheData::new()), + } + } + + pub fn is_staked(&self) -> bool { + self.data.lock().is_staked + } + + pub fn signer_address(&self) -> Address { + self.data.lock().signer_address + } + + pub fn is_available(&self) -> bool { + self.data.lock().is_available + } + + /// Refresh the cache values. + pub fn refresh_cache( + &mut self, + signer_address: Address, + engine_client: &dyn EngineClient, + ) -> Result<(), Error> { + //self.is_staked = false; + + let mut new_data = HbbftEngineCacheData::new(); + new_data.signer_address = signer_address; + let is_available = self.calc_is_available(signer_address, engine_client)?; + new_data.is_available = is_available; + new_data.is_staked = self.calc_is_staked(signer_address, engine_client)?; + + self.data.lock().clone_from(&new_data); + + return Ok(()); + } + + fn calc_is_available( + &mut self, + signer_address: Address, + engine_client: &dyn EngineClient, + ) -> Result { + // match self.signer.read().as_ref() { + // Some(signer) => { + // match self.client_arc() { + // Some(client) => { + let engine_client = engine_client; + // let mining_address = signer.address(); + + if signer_address.is_zero() { + // debug!(target: "consensus", "is_available: not available because mining address is zero: "); + return Ok(false); + } + match super::contracts::validator_set::get_validator_available_since( + engine_client, + &signer_address, + ) { + Ok(available_since) => { + debug!(target: "consensus", "available_since: {}", available_since); + return Ok(!available_since.is_zero()); + } + Err(err) => { + warn!(target: "consensus", "Error get get_validator_available_since: ! {:?}", err); + } + } + //} + // None => { + // // warn!("Could not retrieve address for writing availability transaction."); + // warn!(target: "consensus", "is_available: could not get engine client"); + // } + // } + // } + // None => {} + // } + return Ok(false); + } + + /// refreshes cache, if node is staked. + fn calc_is_staked( + &self, + mining_address: Address, + engine_client: &dyn EngineClient, + ) -> Result { + // is the configured validator stacked ?? + match super::contracts::validator_set::staking_by_mining_address( + engine_client, + &mining_address, + ) { + Ok(staking_address) => { + // if there is no pool for this validator defined, we know that + if staking_address.is_zero() { + return Ok(false); + } + match super::contracts::staking::stake_amount( + engine_client, + &staking_address, + &staking_address, + ) { + Ok(stake_amount) => { + debug!(target: "consensus", "stake_amount: {}", stake_amount); + + // we need to check if the pool stake amount is >= minimum stake + match super::contracts::staking::candidate_min_stake(engine_client) { + Ok(min_stake) => { + debug!(target: "consensus", "min_stake: {}", min_stake); + return Ok(stake_amount.ge(&min_stake)); + } + Err(err) => { + error!(target: "consensus", "Error get candidate_min_stake: ! {:?}", err); + return Ok(false); + //return Err(err.into()); + } + } + } + Err(err) => { + warn!(target: "consensus", "Error get stake_amount: ! {:?}", err); + return Ok(false); + } + } + } + Err(err) => { + warn!(target: "consensus", "Error get staking_by_mining_address: ! {:?}", err); + return Ok(false); + } + } + } +} diff --git a/crates/ethcore/src/engines/hbbft/mod.rs b/crates/ethcore/src/engines/hbbft/mod.rs index c181acc02..df1ce7459 100644 --- a/crates/ethcore/src/engines/hbbft/mod.rs +++ b/crates/ethcore/src/engines/hbbft/mod.rs @@ -3,6 +3,7 @@ mod contracts; mod contribution; mod hbbft_early_epoch_end_manager; mod hbbft_engine; +mod hbbft_engine_cache; mod hbbft_message_memorium; mod hbbft_network_fork_manager; mod hbbft_peers_management; From 07977e708cf7e6b3883d0823df67fa8fd39ae789 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 24 Dec 2024 12:30:26 +0100 Subject: [PATCH 302/687] removed double sending of flagged validator reports, asuming that the reports will get included into the blocks. --- .../src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index d52321a14..69bf66c15 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -194,7 +194,12 @@ impl HbbftEarlyEpochEndManager { validator_address, &self.signing_address, ) { - self.flagged_validators.push(validator.clone()); + if !self.flagged_validators.contains(&validator) { + // in this case, we already had this validator in the list, + // what means that the transaction previous send was not successful. + // we could here do some improvements to not spam to many disconnect reports into the system. + self.flagged_validators.push(validator.clone()); + } } } else { warn!("Could not find validator_address for node id in cache: {validator:?}"); @@ -223,6 +228,8 @@ impl HbbftEarlyEpochEndManager { validator_address, &self.signing_address, ) { + // Todo: we do not know if the transaction will get processed successful. + // shall we track transactions ? self.flagged_validators.remove(index); } } else { From 9297192828136b27dc4ae3839524ccfdfe4a13cc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 13 Jan 2025 23:01:32 +0100 Subject: [PATCH 303/687] logging stacktrace for verify_block_family (phase 3 verification) --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 7241917e3..800717725 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1334,6 +1334,8 @@ impl Engine for HoneyBadgerBFT { Ok(()) } else { error!(target: "engine", "Invalid seal for block #{}!", header.number()); + let trace = std::backtrace::Backtrace::capture(); + error!(target: "engine", "Invalid Seal Trace: #{trace:?}!"); Err(BlockError::InvalidSeal.into()) } } From 20f32ea5005d1fea897d0d8c22a1368ddac711ab Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 14 Jan 2025 09:26:48 +0100 Subject: [PATCH 304/687] Historic PublicKeys are now stored in memory. Key Generation is not triggered anymore, if a older block gets verified. --- .../ethcore/src/engines/hbbft/hbbft_state.rs | 73 ++++++++----------- 1 file changed, 29 insertions(+), 44 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 23fb7fe58..152621791 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -42,6 +42,7 @@ pub(crate) struct HbbftState { network_info: Option>, honey_badger: Option, public_master_key: Option, + historic_public_keys: BTreeMap, current_posdao_epoch: u64, current_posdao_epoch_start_block: u64, last_fork_start_block: Option, @@ -56,6 +57,7 @@ impl HbbftState { network_info: None, honey_badger: None, public_master_key: None, + historic_public_keys: BTreeMap::new(), current_posdao_epoch: 0, current_posdao_epoch_start_block: 0, last_posdao_epoch_start_block: None, @@ -131,6 +133,9 @@ impl HbbftState { self.public_master_key = Some(network_info.public_key_set().public_key()); self.honey_badger = Some(self.new_honey_badger(network_info.clone())?); + self.historic_public_keys + .insert(target_posdao_epoch, self.public_master_key.unwrap().clone()); + for x in network_info.validator_set().all_ids() { info!(target: "engine", "Validator: {:?}", x); } @@ -173,6 +178,8 @@ impl HbbftState { let (pks, sks) = synckeygen.generate().ok()?; self.public_master_key = Some(pks.public_key()); + self.historic_public_keys + .insert(target_posdao_epoch, pks.public_key()); // Clear network info and honey badger instance, since we may not be in this POSDAO epoch any more. info!(target: "engine", "public master key: {:?}", pks.public_key()); @@ -540,6 +547,8 @@ impl HbbftState { signature: &Signature, header: &Header, ) -> bool { + // maybe add the option: "not ready yet ?!" + self.skip_to_current_epoch(client.clone(), signer); // Check if posdao epoch fits the parent block of the header seal to verify. @@ -552,56 +561,32 @@ impl HbbftState { return false; } }; - if self.current_posdao_epoch != target_posdao_epoch { + + if self.current_posdao_epoch > target_posdao_epoch { trace!(target: "consensus", "verify_seal - hbbft state epoch does not match epoch at the header's parent, attempting to reconstruct the appropriate public key share from scratch."); - // If the requested block nr is already imported we try to generate the public master key from scratch. - let posdao_epoch_start = match get_posdao_epoch_start( - &*client, - BlockId::Number(parent_block_nr), - ) { - Ok(epoch_start) => epoch_start, - Err(e) => { - error!(target: "consensus", "Querying epoch start block failed with error: {:?}", e); - return false; - } - }; - let synckeygen = match initialize_synckeygen( - &*client, - &Arc::new(RwLock::new(Option::None)), - BlockId::Number(posdao_epoch_start.low_u64()), - ValidatorType::Current, - ) { - Ok(synckeygen) => synckeygen, - Err(e) => { - let diff = parent_block_nr - posdao_epoch_start.low_u64(); - error!(target: "consensus", "Error: Synckeygen failed. parent block: {} epoch_start: {} diff {} with error: {:?}. current posdao: {:?} target epoch {:?}", parent_block_nr, posdao_epoch_start, diff, e, self.current_posdao_epoch, target_posdao_epoch); + match self.historic_public_keys.get(&target_posdao_epoch) { + Some(key) => { + if key.verify(signature, header.bare_hash()) { + return true; + } else { + error!(target: "consensus", "Failed to verify seal - historic public key verification failed!"); + return false; + } + } + None => { + warn!(target: "consensus", "unable to verifiy seal for historic block, public key not available."); return false; } - }; - - if !synckeygen.is_ready() { - error!(target: "consensus", "Synckeygen not ready when it sohuld be!"); - return false; } - - let pks = match synckeygen.generate() { - Ok((pks, _)) => pks, - Err(e) => { - error!(target: "consensus", "Generating of public key share failed with error: {:?}", e); - return false; + } else { + // not a historic block, we can use the current public key. + match self.public_master_key { + Some(key) => key.verify(signature, header.bare_hash()), + None => { + error!(target: "consensus", "Failed to verify seal - public master key not available!"); + false } - }; - - trace!(target: "consensus", "verify_seal - successfully reconstructed public key share of past posdao epoch."); - return pks.public_key().verify(signature, header.bare_hash()); - } - - match self.public_master_key { - Some(key) => key.verify(signature, header.bare_hash()), - None => { - error!(target: "consensus", "Failed to verify seal - public master key not available!"); - false } } } From cd5912053323a86fc5f3399526cbb91312467e2f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 26 Jan 2025 16:01:46 +0100 Subject: [PATCH 305/687] improved logging for stage 3 errors --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 800717725..5f734b3ab 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1333,7 +1333,7 @@ impl Engine for HoneyBadgerBFT { { Ok(()) } else { - error!(target: "engine", "Invalid seal for block #{}!", header.number()); + error!(target: "engine", "Invalid seal (Stage 3) for block #{}!", header.number()); let trace = std::backtrace::Backtrace::capture(); error!(target: "engine", "Invalid Seal Trace: #{trace:?}!"); Err(BlockError::InvalidSeal.into()) From 720d84c81fb2b4ba91c4d34c13f3cbb284ac2ca9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 26 Jan 2025 16:02:53 +0100 Subject: [PATCH 306/687] removed "new lines" "\n" from log output for Stage 5 errors --- crates/ethcore/src/client/client.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 645e26487..ce45b8829 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -582,10 +582,10 @@ impl Importer { { let best_block_number = client.chain.read().best_block_number(); if best_block_number >= header.number() { - warn!(target: "client", "Stage 5 verification failed for #{} ({})\nBlock is ancient (current best block: #{}). Error: {:?}", header.number(), header.hash(), best_block_number, e); + warn!(target: "client", "Stage 5 verification failed for #{} ({}) Block is ancient (current best block: #{}). Error: {:?}", header.number(), header.hash(), best_block_number, e); bail!("Block is ancient"); } else { - warn!(target: "client", "Stage 5 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e); + warn!(target: "client", "Stage 5 block verification failed for #{} ({}) Error: {:?}", header.number(), header.hash(), e); bail!(e); } } From cae76c83943c767535b42061eb5f693d0342a134 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 30 Jan 2025 14:01:29 +0100 Subject: [PATCH 307/687] logging of sending the PART and ACKS transactions as debug --- .../ethcore/src/engines/hbbft/keygen_transactions.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 440b7c479..febfac5cb 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -228,14 +228,15 @@ impl KeygenTransactionSender { } }; - send_part_transaction( + let nonce = send_part_transaction( full_client, client, &address, upcoming_epoch, serialized_part, )?; - trace!(target:"engine", "PART Transaction send."); + + debug!(target: "engine", "sending Part with nonce: {}", nonce); return Ok(()); } ShouldSendKeyAnswer::NoWaiting => { @@ -303,6 +304,7 @@ impl KeygenTransactionSender { .gas(U256::from(gas)) .nonce(full_client.nonce(&address, BlockId::Latest).unwrap()) .gas_price(U256::from(10000000000u64)); + debug!(target: "engine", "sending acks with nonce: {}", acks_transaction.nonce.unwrap()); full_client .transact_silently(acks_transaction) .map_err(|_| CallError::ReturnValueInvalid)?; @@ -320,7 +322,7 @@ fn send_part_transaction( mining_address: &Address, upcoming_epoch: U256, data: Vec, -) -> Result<(), KeyGenError> { +) -> Result { // the required gas values have been approximated by // experimenting and it's a very rough estimation. // it can be further fine tuned to be just above the real consumption. @@ -344,5 +346,5 @@ fn send_part_transaction( CallError::ReturnValueInvalid })?; - return Ok(()); + return Ok(nonce); } From 9483b4c3b9be281c5eea67f8ac40af37af9eb1b1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 7 Feb 2025 17:41:17 +0100 Subject: [PATCH 308/687] propagated PrometheusMetrics to additional modules. - Client - Host - Network gathering details about those modules. reworked locking and DB metrics discovery --- Cargo.lock | 1 + bin/oe/db/rocksdb/mod.rs | 4 +- crates/ethcore/src/client/client.rs | 56 +++++++- .../src/engines/hbbft/block_reward_hbbft.rs | 2 +- .../src/engines/hbbft/keygen_transactions.rs | 4 +- crates/ethcore/sync/src/api.rs | 2 + crates/net/network-devp2p/Cargo.toml | 3 +- crates/net/network-devp2p/src/host.rs | 133 ++++++++++++++++-- crates/net/network-devp2p/src/lib.rs | 1 + crates/net/network-devp2p/src/node_table.rs | 10 ++ crates/net/network-devp2p/src/service.rs | 14 +- 11 files changed, 211 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54f12b2d0..0d9f4bd48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1509,6 +1509,7 @@ dependencies = [ "serde_derive", "serde_json", "slab 0.2.0", + "stats", "tempdir", "tiny-keccak 1.5.0", ] diff --git a/bin/oe/db/rocksdb/mod.rs b/bin/oe/db/rocksdb/mod.rs index e5789f89a..18052c3a5 100644 --- a/bin/oe/db/rocksdb/mod.rs +++ b/bin/oe/db/rocksdb/mod.rs @@ -55,7 +55,9 @@ impl BlockChainDB for AppDB { } impl PrometheusMetrics for AppDB { - fn prometheus_metrics(&self, _: &mut stats::PrometheusRegistry) {} + fn prometheus_metrics(&self, r: &mut stats::PrometheusRegistry) { + self.key_value.prometheus_metrics(r); + } } /// Open a secret store DB using the given secret store data path. The DB path is one level beneath the data path. diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index ce45b8829..146525f50 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use std::{ - cmp, + cmp::{self}, collections::{BTreeMap, HashSet, VecDeque}, convert::TryFrom, io::{BufRead, BufReader}, @@ -194,6 +194,28 @@ struct Importer { pub bad_blocks: bad_blocks::BadBlocks, } +#[derive(Default)] +struct ClientStatistics { + logging_enabled: bool, + broadcasted_consensus_messages: AtomicU64, + broadcasted_consensus_messages_bytes: AtomicU64, + sent_consensus_messages: AtomicU64, + sent_consensus_messages_bytes: AtomicU64, +} + + +impl PrometheusMetrics for ClientStatistics { + + fn prometheus_metrics(&self, r: &mut PrometheusRegistry) { + if self.logging_enabled { + r.register_counter("consens_messages_sent", "", self.sent_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64); + r.register_counter("consens_messages_sent_bytes", "", self.sent_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64); + r.register_counter("consens_messages_broadcasted", "", self.broadcasted_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64); + r.register_counter("consens_messages_broadcasted_bytes", "", self.broadcasted_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64); + } + } +} + /// Blockchain database client backed by a persistent database. Owns and manages a blockchain and a block queue. /// Call `import_block()` to import a block asynchronously; `flush_queue()` flushes the queue. pub struct Client { @@ -264,6 +286,8 @@ pub struct Client { importer: Importer, shutdown: ShutdownManager, + + statistics: ClientStatistics, } impl Importer { @@ -1030,6 +1054,9 @@ impl Client { trace!(target: "client", "Found registrar at {}", addr); } + let mut statistics = ClientStatistics::default(); + statistics.logging_enabled = true; + let client = Arc::new(Client { enabled: AtomicBool::new(true), sleep_state: Mutex::new(SleepState::new(awake)), @@ -1060,6 +1087,7 @@ impl Client { importer, config, shutdown, + statistics, }); let exec_client = client.clone(); @@ -3226,10 +3254,24 @@ impl super::traits::EngineClient for Client { } fn broadcast_consensus_message(&self, message: Bytes) { + self.statistics + .broadcasted_consensus_messages + .fetch_add(1, std::sync::atomic::Ordering::Relaxed); + self.statistics + .broadcasted_consensus_messages_bytes + .fetch_add(message.len() as u64, std::sync::atomic::Ordering::Relaxed); + self.notify(|notify| notify.broadcast(ChainMessageType::Consensus(message.clone()))); } fn send_consensus_message(&self, message: Bytes, node_id: Option) { + self.statistics + .sent_consensus_messages + .fetch_add(1, std::sync::atomic::Ordering::Relaxed); + self.statistics + .sent_consensus_messages_bytes + .fetch_add(message.len() as u64, std::sync::atomic::Ordering::Relaxed); + self.notify(|notify| notify.send(ChainMessageType::Consensus(message.clone()), node_id)); } @@ -3593,8 +3635,10 @@ impl PrometheusMetrics for Client { report.transactions_applied as i64, ); + let lockd = Duration::from_millis(50); + self.state_db - .try_read_for(Duration::from_millis(200)) + .try_read_for(lockd) .map(|state_db| { let state_db_size = state_db.cache_size(); r.register_gauge( @@ -3712,12 +3756,14 @@ impl PrometheusMetrics for Client { queue.verifying_queue_size as i64, ); - // database info - self.db.read().key_value().prometheus_metrics(r); + if let Some(db) = self.db.try_read_for(lockd) { + db.prometheus_metrics(r); + }; // engine specific metrics. - self.engine.prometheus_metrics(r); + + self.statistics.prometheus_metrics(r); } } diff --git a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs index 1e75af311..0b6021c3d 100644 --- a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs @@ -21,7 +21,7 @@ use engines::{SystemOrCodeCall, SystemOrCodeCallKind}; use error::Error; use ethabi::FunctionOutputDecoder; use ethabi_contract::use_contract; -use ethereum_types::{Address, U256}; +use ethereum_types::Address; use_contract!( block_reward_contract, diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index febfac5cb..4b595c584 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -16,7 +16,7 @@ use engines::{ }, signer::EngineSigner, }; -use ethereum_types::{Address, Public, U256}; +use ethereum_types::{Address, U256}; use itertools::Itertools; use parking_lot::RwLock; use std::{collections::BTreeMap, sync::Arc}; @@ -281,7 +281,7 @@ impl KeygenTransactionSender { for ack in acks { let ack_to_push = match bincode::serialize(&ack) { Ok(serialized_ack) => serialized_ack, - Err(e) => return Err(KeyGenError::Unexpected), + Err(_) => return Err(KeyGenError::Unexpected), }; total_bytes_for_acks += ack_to_push.len(); serialized_acks.push(ack_to_push); diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index b1d8c09d5..ee4cf5cb7 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -447,6 +447,8 @@ impl PrometheusMetrics for EthSync { "First block number of the present snapshot", manifest_block_num as i64, ); + + self.network.prometheus_metrics(r); } } diff --git a/crates/net/network-devp2p/Cargo.toml b/crates/net/network-devp2p/Cargo.toml index 096b7fdb6..178c9c502 100644 --- a/crates/net/network-devp2p/Cargo.toml +++ b/crates/net/network-devp2p/Cargo.toml @@ -23,7 +23,7 @@ parity-bytes = "0.1" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } ethcore-network = { path = "../network" } ethereum-types = "0.9.2" -ethkey = { path = "../../../crates/accounts/ethkey" } +ethkey = { path = "../../accounts/ethkey" } rlp = { version = "0.4.6" } parity-path = "0.1" ipnetwork = "0.12.6" @@ -34,6 +34,7 @@ serde_json = "1.0" serde_derive = "1.0" error-chain = { version = "0.12", default-features = false } lru-cache = "0.1" +stats = { path = "../../util/stats" } [dev-dependencies] env_logger = "0.5" diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 0cf5ec5ad..37c3cd1cb 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -29,7 +29,7 @@ use std::{ path::{Path, PathBuf}, str::FromStr, sync::{ - atomic::{AtomicBool, Ordering as AtomicOrdering}, + atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, Arc, }, time::Duration, @@ -47,6 +47,7 @@ use node_table::*; use parity_path::restrict_permissions_owner; use parking_lot::{Mutex, RwLock}; use session::{Session, SessionData}; +use stats::{PrometheusMetrics, PrometheusRegistry}; use PROTOCOL_VERSION; type Slab = ::slab::Slab; @@ -108,6 +109,36 @@ pub struct NetworkContext<'s> { session: Option, session_id: Option, reserved_peers: &'s HashSet, + statistics: &'s NetworkingStatistics, +} + +pub struct NetworkingStatistics { + logging_enabled: bool, + + bytes_sent: AtomicU64, + peer_losses: AtomicU64, + packages_send: AtomicU64, +} + +impl NetworkingStatistics { + pub fn new(logging_enabled: bool) -> NetworkingStatistics { + NetworkingStatistics { + logging_enabled: logging_enabled, + bytes_sent: AtomicU64::new(0), + peer_losses: AtomicU64::new(0), + packages_send: AtomicU64::new(0), + } + } +} + + +impl PrometheusMetrics for NetworkingStatistics { + + fn prometheus_metrics(&self, registry: &mut PrometheusRegistry) { + registry.register_counter("p2p_bytes_sent","", self.bytes_sent.load(std::sync::atomic::Ordering::Relaxed) as i64); + registry.register_counter("p2p_packages_sent","", self.packages_send.load(std::sync::atomic::Ordering::Relaxed) as i64); + registry.register_counter("p2p_peer_losses","", self.peer_losses.load(std::sync::atomic::Ordering::Relaxed) as i64); + } } impl<'s> NetworkContext<'s> { @@ -118,6 +149,7 @@ impl<'s> NetworkContext<'s> { session: Option, sessions: Arc>>, reserved_peers: &'s HashSet, + statistics: &'s NetworkingStatistics, ) -> NetworkContext<'s> { let id = session.as_ref().map(|s| s.lock().token()); NetworkContext { @@ -126,7 +158,8 @@ impl<'s> NetworkContext<'s> { session_id: id, session, sessions, - reserved_peers: reserved_peers, + reserved_peers, + statistics, } } @@ -155,8 +188,22 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { session .lock() .send_packet(self.io, Some(protocol), packet_id as u8, &data)?; + + if self.statistics.logging_enabled { + self.statistics + .bytes_sent + .fetch_add(data.len() as u64, std::sync::atomic::Ordering::Relaxed); + self.statistics + .packages_send + .fetch_add(1, std::sync::atomic::Ordering::Relaxed); + } } else { - trace!(target: "network", "Send: Peer no longer exist") + trace!(target: "network", "Send: Peer no longer exist"); + if self.statistics.logging_enabled { + self.statistics + .peer_losses + .fetch_add(1, std::sync::atomic::Ordering::Relaxed); + } } Ok(()) } @@ -175,13 +222,13 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { fn disable_peer(&self, peer: PeerId) { self.io .message(NetworkIoMessage::DisablePeer(peer)) - .unwrap_or_else(|e| warn!("Error sending network IO message: {:?}", e)); + .unwrap_or_else(|e| warn!("Error disable_peer: {:?} {:?}", peer, e)); } fn disconnect_peer(&self, peer: PeerId) { self.io .message(NetworkIoMessage::Disconnect(peer)) - .unwrap_or_else(|e| warn!("Error sending network IO message: {:?}", e)); + .unwrap_or_else(|e| warn!("Error disconnect_peer: {:?} {:?}", peer, e)); } fn is_expired(&self) -> bool { @@ -195,7 +242,7 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { delay, protocol: self.protocol, }) - .unwrap_or_else(|e| warn!("Error sending network IO message: {:?}", e)); + .unwrap_or_else(|e| warn!("Error register_timer: {:?}", e)); Ok(()) } @@ -302,6 +349,7 @@ pub struct Host { reserved_nodes: RwLock>, stopping: AtomicBool, filter: Option>, + statistics: NetworkingStatistics, } impl Host { @@ -373,6 +421,7 @@ impl Host { reserved_nodes: RwLock::new(HashSet::new()), stopping: AtomicBool::new(false), filter, + statistics: NetworkingStatistics::new(true), }; for n in boot_nodes { @@ -604,6 +653,26 @@ impl Host { (handshakes, egress, ingress) } + // like session count, but does not block if read can not be achieved. + fn session_count_try(&self, lock_duration: Duration) -> Option<(usize, usize, usize)> { + let mut handshakes = 0; + let mut egress = 0; + let mut ingress = 0; + + if let Some(lock) = self.sessions.try_read_for(lock_duration) { + for s in lock.iter() { + match s.try_lock() { + Some(ref s) if s.is_ready() && s.info.originated => egress += 1, + Some(ref s) if s.is_ready() && !s.info.originated => ingress += 1, + _ => handshakes += 1, + } + } + return Some((handshakes, egress, ingress)); + } + + return None; + } + fn connecting_to(&self, id: &NodeId) -> bool { self.sessions .read() @@ -970,6 +1039,7 @@ impl Host { Some(session.clone()), self.sessions.clone(), &reserved, + &self.statistics, ), &token, ); @@ -990,6 +1060,7 @@ impl Host { Some(session.clone()), self.sessions.clone(), &reserved, + &self.statistics, ), &token, packet_id, @@ -1108,6 +1179,7 @@ impl Host { expired_session.clone(), self.sessions.clone(), &reserved, + &self.statistics, ), &token, ); @@ -1145,7 +1217,14 @@ impl Host { { let reserved = { self.reserved_nodes.read() }; - let context = NetworkContext::new(io, protocol, None, self.sessions.clone(), &reserved); + let context = NetworkContext::new( + io, + protocol, + None, + self.sessions.clone(), + &reserved, + &self.statistics, + ); action(&context); } @@ -1160,7 +1239,14 @@ impl Host { { let reserved = { self.reserved_nodes.read() }; - let context = NetworkContext::new(io, protocol, None, self.sessions.clone(), &reserved); + let context = NetworkContext::new( + io, + protocol, + None, + self.sessions.clone(), + &reserved, + &self.statistics, + ); action(&context) } } @@ -1256,6 +1342,7 @@ impl IoHandler for Host { None, self.sessions.clone(), &reserved, + &self.statistics, ), timer.token, ); @@ -1286,6 +1373,7 @@ impl IoHandler for Host { None, self.sessions.clone(), &reserved, + &self.statistics, )); self.handlers.write().insert(*protocol, h); let mut info = self.info.write(); @@ -1455,6 +1543,35 @@ impl IoHandler for Host { } } +impl PrometheusMetrics for Host { + fn prometheus_metrics(&self, r: &mut PrometheusRegistry) { + + let lockdur = Duration::from_millis(20); + + if let Some((handshakes, egress, ingress)) = + self.session_count_try(Duration::from_millis(20)) + { + r.register_gauge("p2p_ingress", "", ingress as i64); + r.register_gauge("p2p_egress", "", egress as i64); + r.register_gauge("p2p_handshakes", "", handshakes as i64); + } + + if let Some(reserved_nodes) = self.reserved_nodes.try_read_for(lockdur) { + r.register_gauge("p2p_reserved_nodes", "", reserved_nodes.len() as i64); + } + + if let Some(nodes) = self.nodes.try_read_for(lockdur) { + r.register_gauge("p2p_nodes", "", nodes.count_nodes() as i64); + r.register_gauge("p2p_uselessnodes", "", nodes.count_useless() as i64); + } + + + self.statistics.prometheus_metrics(r); + } + + //r.register_gauge("connected_peers", "", self.connect_peers(io)); +} + fn save_key(path: &Path, key: &Secret) { let mut path_buf = PathBuf::from(path); if let Err(e) = fs::create_dir_all(path_buf.as_path()) { diff --git a/crates/net/network-devp2p/src/lib.rs b/crates/net/network-devp2p/src/lib.rs index 1acd96607..0072efc7b 100644 --- a/crates/net/network-devp2p/src/lib.rs +++ b/crates/net/network-devp2p/src/lib.rs @@ -85,6 +85,7 @@ extern crate rustc_hex; extern crate serde; extern crate serde_json; extern crate slab; +extern crate stats; extern crate tiny_keccak; #[macro_use] diff --git a/crates/net/network-devp2p/src/node_table.rs b/crates/net/network-devp2p/src/node_table.rs index fcf57c0c6..24dab5ba7 100644 --- a/crates/net/network-devp2p/src/node_table.rs +++ b/crates/net/network-devp2p/src/node_table.rs @@ -429,6 +429,7 @@ impl NodeTable { /// Mark as useless, no further attempts to connect until next call to `clear_useless`. pub fn mark_as_useless(&mut self, id: &NodeId) { + info!(target: "network", "Node was marked as useless: {:?}", id); self.useless_nodes.insert(id.clone()); } @@ -437,6 +438,15 @@ impl NodeTable { self.useless_nodes.clear(); } + /// count of useless nodes. + pub fn count_useless(&self) -> usize { + self.useless_nodes.len() + } + + pub fn count_nodes(&self) -> usize { + self.nodes.len() + } + /// Save the nodes.json file. pub fn save(&self) { let mut path = match self.path { diff --git a/crates/net/network-devp2p/src/service.rs b/crates/net/network-devp2p/src/service.rs index 7ebd31521..cb7dc815e 100644 --- a/crates/net/network-devp2p/src/service.rs +++ b/crates/net/network-devp2p/src/service.rs @@ -22,7 +22,8 @@ use network::{ NetworkProtocolHandler, NonReservedPeerMode, PeerId, ProtocolId, }; use parking_lot::RwLock; -use std::{net::SocketAddr, ops::RangeInclusive, sync::Arc}; +use stats::{PrometheusMetrics, PrometheusRegistry}; +use std::{net::SocketAddr, ops::RangeInclusive, sync::Arc, time::Duration}; struct HostHandler { public_url: RwLock>, @@ -225,3 +226,14 @@ impl NetworkService { .map(|ref host| host.with_context_eval(protocol, &io, action)) } } + +impl PrometheusMetrics for NetworkService { + fn prometheus_metrics(&self, r: &mut PrometheusRegistry) { + if let Some(host_o) = self.host.try_read_for(Duration::from_millis(50)) { + if let Some(host) = host_o.as_ref() { + host.prometheus_metrics(r); + } + } + //self.connected_peers() + } +} From 8be8c7cb99acf676c521c58a104876fa55b0793d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 9 Feb 2025 23:30:16 +0100 Subject: [PATCH 309/687] PrometheusMetrics, added help texts --- crates/ethcore/src/client/client.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 146525f50..d1645402d 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -208,10 +208,10 @@ impl PrometheusMetrics for ClientStatistics { fn prometheus_metrics(&self, r: &mut PrometheusRegistry) { if self.logging_enabled { - r.register_counter("consens_messages_sent", "", self.sent_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64); - r.register_counter("consens_messages_sent_bytes", "", self.sent_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64); - r.register_counter("consens_messages_broadcasted", "", self.broadcasted_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64); - r.register_counter("consens_messages_broadcasted_bytes", "", self.broadcasted_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64); + r.register_counter("consens_messages_sent", "count", self.sent_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64); + r.register_counter("consens_messages_sent_bytes", "bytes", self.sent_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64); + r.register_counter("consens_messages_broadcasted", "count", self.broadcasted_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64); + r.register_counter("consens_messages_broadcasted_bytes", "bytes", self.broadcasted_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64); } } } From d8b55f7260939641f3b407873c15bab2b068bbd5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 10 Feb 2025 00:02:32 +0100 Subject: [PATCH 310/687] help texts for new prometheus stats. --- crates/net/network-devp2p/src/host.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 37c3cd1cb..21d20cf80 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -135,9 +135,9 @@ impl NetworkingStatistics { impl PrometheusMetrics for NetworkingStatistics { fn prometheus_metrics(&self, registry: &mut PrometheusRegistry) { - registry.register_counter("p2p_bytes_sent","", self.bytes_sent.load(std::sync::atomic::Ordering::Relaxed) as i64); - registry.register_counter("p2p_packages_sent","", self.packages_send.load(std::sync::atomic::Ordering::Relaxed) as i64); - registry.register_counter("p2p_peer_losses","", self.peer_losses.load(std::sync::atomic::Ordering::Relaxed) as i64); + registry.register_counter("p2p_bytes_sent","total", self.bytes_sent.load(std::sync::atomic::Ordering::Relaxed) as i64); + registry.register_counter("p2p_packages_sent","count", self.packages_send.load(std::sync::atomic::Ordering::Relaxed) as i64); + registry.register_counter("p2p_peer_losses","count", self.peer_losses.load(std::sync::atomic::Ordering::Relaxed) as i64); } } @@ -1551,18 +1551,18 @@ impl PrometheusMetrics for Host { if let Some((handshakes, egress, ingress)) = self.session_count_try(Duration::from_millis(20)) { - r.register_gauge("p2p_ingress", "", ingress as i64); - r.register_gauge("p2p_egress", "", egress as i64); - r.register_gauge("p2p_handshakes", "", handshakes as i64); + r.register_gauge("p2p_ingress", "count", ingress as i64); + r.register_gauge("p2p_egress", "count", egress as i64); + r.register_gauge("p2p_handshakes", "count", handshakes as i64); } if let Some(reserved_nodes) = self.reserved_nodes.try_read_for(lockdur) { - r.register_gauge("p2p_reserved_nodes", "", reserved_nodes.len() as i64); + r.register_gauge("p2p_reserved_nodes", "count", reserved_nodes.len() as i64); } if let Some(nodes) = self.nodes.try_read_for(lockdur) { - r.register_gauge("p2p_nodes", "", nodes.count_nodes() as i64); - r.register_gauge("p2p_uselessnodes", "", nodes.count_useless() as i64); + r.register_gauge("p2p_nodes", "count", nodes.count_nodes() as i64); + r.register_gauge("p2p_uselessnodes", "count", nodes.count_useless() as i64); } From b7db6e7197dfa5f2ed8738b7f5f0f9caed99dc35 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Feb 2025 11:59:21 +0100 Subject: [PATCH 311/687] promoted disabling peer message from debug to info! if the Node Software Version is not whitelisted. --- crates/ethcore/sync/src/chain/handler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 484fcb267..c28af9f4f 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -167,7 +167,7 @@ impl SyncHandler { Some(session) => ip_addr = session.remote_address.to_string(), None => {} } - debug!(target:"sync", "Disabling Peer (this Software Version not whitelisted) {} ip:{} ", peer_version, ip_addr); + info!(target:"sync", "Disabling Peer (this Software Version not whitelisted) {} ip:{} ", peer_version, ip_addr); io.disable_peer(peer); } else if let Err(e) = sync.send_status(io, peer) { debug!(target:"sync", "Error sending status request: {:?}", e); From 9f19338f2f1cf7344c36125ea3a50ebaaca6b905 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Feb 2025 12:48:35 +0100 Subject: [PATCH 312/687] Early Epoch End decision making (ConnectivityTracker) is now based on ANY Hbbft Message send by the Partner Node, and node just judging by sealing Messages. In some cases the Nodes do not even send their Sealing Messages late, because the Block finalization is faster than their Sealing Message Communication. Probably due their geographical location. This also means we can reduce the grace periods again: Switched the treshhold_time from 60 minutes to 22 minutes, and reduced it from 10 blocks to 2 blocks. see: https://github.com/DMDcoin/diamond-node/issues/87 --- crates/ethcore/src/client/client.rs | 48 ++++++++++++------- .../hbbft/hbbft_early_epoch_end_manager.rs | 12 +++-- .../engines/hbbft/hbbft_message_memorium.rs | 7 +++ crates/net/network-devp2p/src/host.rs | 23 ++++++--- 4 files changed, 62 insertions(+), 28 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index d1645402d..72f5eaba5 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -203,15 +203,33 @@ struct ClientStatistics { sent_consensus_messages_bytes: AtomicU64, } - impl PrometheusMetrics for ClientStatistics { - fn prometheus_metrics(&self, r: &mut PrometheusRegistry) { if self.logging_enabled { - r.register_counter("consens_messages_sent", "count", self.sent_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64); - r.register_counter("consens_messages_sent_bytes", "bytes", self.sent_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64); - r.register_counter("consens_messages_broadcasted", "count", self.broadcasted_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64); - r.register_counter("consens_messages_broadcasted_bytes", "bytes", self.broadcasted_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64); + r.register_counter( + "consens_messages_sent", + "count", + self.sent_consensus_messages + .load(std::sync::atomic::Ordering::Relaxed) as i64, + ); + r.register_counter( + "consens_messages_sent_bytes", + "bytes", + self.sent_consensus_messages_bytes + .load(std::sync::atomic::Ordering::Relaxed) as i64, + ); + r.register_counter( + "consens_messages_broadcasted", + "count", + self.broadcasted_consensus_messages + .load(std::sync::atomic::Ordering::Relaxed) as i64, + ); + r.register_counter( + "consens_messages_broadcasted_bytes", + "bytes", + self.broadcasted_consensus_messages_bytes + .load(std::sync::atomic::Ordering::Relaxed) as i64, + ); } } } @@ -3637,16 +3655,14 @@ impl PrometheusMetrics for Client { let lockd = Duration::from_millis(50); - self.state_db - .try_read_for(lockd) - .map(|state_db| { - let state_db_size = state_db.cache_size(); - r.register_gauge( - "statedb_cache_size", - "State DB cache size", - state_db_size as i64, - ); - }); + self.state_db.try_read_for(lockd).map(|state_db| { + let state_db_size = state_db.cache_size(); + r.register_gauge( + "statedb_cache_size", + "State DB cache size", + state_db_size as i64, + ); + }); // blockchain cache let blockchain_cache_info = self.blockchain_cache_info(); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 69bf66c15..7f1c4df80 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -243,6 +243,8 @@ impl HbbftEarlyEpochEndManager { client: &dyn EngineClient, other_validator_address: &Address, ) -> bool { + // todo: for performance improvements, we could apply caching here, + // once we are up to date with the contract information and track the inclusion of our own reports. let result = is_connectivity_loss_reported( client, BlockId::Latest, @@ -291,11 +293,11 @@ impl HbbftEarlyEpochEndManager { return; }; - let treshold: u64 = 10; + let treshold: u64 = 2; // todo: read this out from contracts: ConnectivityTrackerHbbft -> reportDisallowPeriod // requires us to update the Contracts ABIs: // https://github.com/DMDcoin/diamond-node/issues/115 - let treshold_time = Duration::from_secs(60 * 60); + let treshold_time = Duration::from_secs(22 * 60); // 22 Minutes = 2 times the heartbeat + 2 minutes as grace period. if self.start_time.elapsed() < treshold_time { debug!(target: "engine", "early-epoch-end: no decision: Treshold time not reached."); @@ -324,9 +326,9 @@ impl HbbftEarlyEpochEndManager { }; if let Some(node_history) = epoch_history.get_history_for_node(validator) { - let last_sealing_message_time = node_history.get_last_sealing_message_time(); - let last_sealing_message_lateness = last_sealing_message_time.elapsed(); - if last_sealing_message_lateness > treshold_time { + let last_message_time = node_history.get_last_good_message_time(); + let last_message_time_lateness = last_message_time.elapsed(); + if last_message_time_lateness > treshold_time { // we do not have to send notification, if we already did so. if !self.is_reported(client, validator_address) { // this function will also add the validator to the list of flagged validators. diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 2860c0c32..61e34d83c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -63,6 +63,7 @@ pub(crate) struct NodeStakingEpochHistory { // messages. last_message_faulty: u64, last_message_good: u64, + last_message_good_time: Instant, num_faulty_messages: u64, num_good_messages: u64, // total_contributions_good: u64, @@ -86,6 +87,7 @@ impl NodeStakingEpochHistory { sealing_blocks_bad: Vec::new(), last_message_faulty: 0, last_message_good: 0, + last_message_good_time: now, num_faulty_messages: 0, num_good_messages: 0, } @@ -215,6 +217,7 @@ impl NodeStakingEpochHistory { // warn!(target: "hbbft_message_memorium", "add_message_event_good: ! event.block_num {block_num} > last_message_good {last_message_good}"); // } self.num_good_messages += 1; + self.last_message_good_time = Instant::now(); } /// GETTERS @@ -251,6 +254,10 @@ impl NodeStakingEpochHistory { ) } + pub fn get_last_good_message_time(&self) -> Instant { + self.last_message_good_time + } + pub fn get_last_late_sealing_message(&self) -> u64 { self.last_late_sealing_message } diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 21d20cf80..4532a3e33 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -131,13 +131,24 @@ impl NetworkingStatistics { } } - impl PrometheusMetrics for NetworkingStatistics { - fn prometheus_metrics(&self, registry: &mut PrometheusRegistry) { - registry.register_counter("p2p_bytes_sent","total", self.bytes_sent.load(std::sync::atomic::Ordering::Relaxed) as i64); - registry.register_counter("p2p_packages_sent","count", self.packages_send.load(std::sync::atomic::Ordering::Relaxed) as i64); - registry.register_counter("p2p_peer_losses","count", self.peer_losses.load(std::sync::atomic::Ordering::Relaxed) as i64); + registry.register_counter( + "p2p_bytes_sent", + "total", + self.bytes_sent.load(std::sync::atomic::Ordering::Relaxed) as i64, + ); + registry.register_counter( + "p2p_packages_sent", + "count", + self.packages_send + .load(std::sync::atomic::Ordering::Relaxed) as i64, + ); + registry.register_counter( + "p2p_peer_losses", + "count", + self.peer_losses.load(std::sync::atomic::Ordering::Relaxed) as i64, + ); } } @@ -1545,7 +1556,6 @@ impl IoHandler for Host { impl PrometheusMetrics for Host { fn prometheus_metrics(&self, r: &mut PrometheusRegistry) { - let lockdur = Duration::from_millis(20); if let Some((handshakes, egress, ingress)) = @@ -1565,7 +1575,6 @@ impl PrometheusMetrics for Host { r.register_gauge("p2p_uselessnodes", "count", nodes.count_useless() as i64); } - self.statistics.prometheus_metrics(r); } From 44213ba307624bc946b32c874d95afcd377e08a4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Feb 2025 13:38:14 +0100 Subject: [PATCH 313/687] pinnned workflow files to ubuntu 22. --- .github/workflows/build-test.yml | 2 +- .github/workflows/check.yml | 2 +- .github/workflows/fmt.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 79e18422d..9230c644d 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: platform: - - ubuntu-latest + - ubuntu-22.04 # - macos-latest toolchain: - 1.75 diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a9e96c801..906baa03c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -9,7 +9,7 @@ on: jobs: check: name: Check - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout sources uses: actions/checkout@main diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml index aa93deb2c..9c634a8b2 100644 --- a/.github/workflows/fmt.yml +++ b/.github/workflows/fmt.yml @@ -5,7 +5,7 @@ name: rustfmt jobs: fmt: name: Rustfmt - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 From 59e7ce23ac58cc5c105b6e0dacddf1d2a96fb0d6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Feb 2025 15:40:10 +0100 Subject: [PATCH 314/687] downgraded consensus message from debug to trace: available_since, stake_amount, min_stake --- crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs index 24ecaaebb..929e1035a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs @@ -85,7 +85,7 @@ impl HbbftEngineCache { &signer_address, ) { Ok(available_since) => { - debug!(target: "consensus", "available_since: {}", available_since); + trace!(target: "consensus", "available_since: {}", available_since); return Ok(!available_since.is_zero()); } Err(err) => { @@ -126,12 +126,12 @@ impl HbbftEngineCache { &staking_address, ) { Ok(stake_amount) => { - debug!(target: "consensus", "stake_amount: {}", stake_amount); + trace!(target: "consensus", "stake_amount: {}", stake_amount); // we need to check if the pool stake amount is >= minimum stake match super::contracts::staking::candidate_min_stake(engine_client) { Ok(min_stake) => { - debug!(target: "consensus", "min_stake: {}", min_stake); + trace!(target: "consensus", "min_stake: {}", min_stake); return Ok(stake_amount.ge(&min_stake)); } Err(err) => { From 4373794bc0fa78a4706f88f52d62015df6b9a7d0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Feb 2025 15:40:56 +0100 Subject: [PATCH 315/687] cleanup --- .../src/engines/hbbft/hbbft_engine_cache.rs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs index 929e1035a..956af25aa 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs @@ -69,17 +69,13 @@ impl HbbftEngineCache { signer_address: Address, engine_client: &dyn EngineClient, ) -> Result { - // match self.signer.read().as_ref() { - // Some(signer) => { - // match self.client_arc() { - // Some(client) => { let engine_client = engine_client; - // let mining_address = signer.address(); if signer_address.is_zero() { // debug!(target: "consensus", "is_available: not available because mining address is zero: "); return Ok(false); } + match super::contracts::validator_set::get_validator_available_since( engine_client, &signer_address, @@ -92,15 +88,6 @@ impl HbbftEngineCache { warn!(target: "consensus", "Error get get_validator_available_since: ! {:?}", err); } } - //} - // None => { - // // warn!("Could not retrieve address for writing availability transaction."); - // warn!(target: "consensus", "is_available: could not get engine client"); - // } - // } - // } - // None => {} - // } return Ok(false); } From d727edbd741839d360c47ab1e677ab145f838f51 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Feb 2025 16:02:36 +0100 Subject: [PATCH 316/687] added hbbft_is_staked to prometheus gauges. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 5f734b3ab..5df74065d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1688,6 +1688,13 @@ impl Engine for HoneyBadgerBFT { // it is part of the Engine trait and does nothing by default. fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { let is_staked = self.is_staked(); + + registry.register_gauge( + "hbbft_is_staked", + "Is the signer of the hbbft engine staked.", + is_staked as i64, + ); + self.hbbft_message_dispatcher.prometheus_metrics(registry); if let Some(early_epoch_manager_option) = self .early_epoch_manager From 63152d61c8f580af9415e95bc8d38efec15b9a1e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Feb 2025 16:03:07 +0100 Subject: [PATCH 317/687] uncommented dead function signer_address() from HbbftEngineCache that might be used later. --- crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs index 956af25aa..49f3c6f7f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs @@ -37,9 +37,10 @@ impl HbbftEngineCache { self.data.lock().is_staked } - pub fn signer_address(&self) -> Address { - self.data.lock().signer_address - } + // pub fn signer_address(&self) -> Address { + // // this is dead code for now, but for further optimization we will use it in the future, + // self.data.lock().signer_address + // } pub fn is_available(&self) -> bool { self.data.lock().is_available From 2e5de5855edc4baaa4757d9f8f139c8a97a441cc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Feb 2025 16:04:03 +0100 Subject: [PATCH 318/687] removed non-required mut mod --- crates/ethcore/src/engines/hbbft/keygen_transactions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 4b595c584..b4f763e7d 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -155,7 +155,7 @@ impl KeygenTransactionSender { // Todo: We should expect up to f clients to write invalid pub keys. Report and re-start pending validator set selection. let (mut synckeygen, part) = match engine_signer_to_synckeygen(signer, pub_keys_arc.clone()) { - Ok((mut synckeygen_, part_)) => (synckeygen_, part_), + Ok((synckeygen_, part_)) => (synckeygen_, part_), Err(e) => { warn!(target:"engine", "engine_signer_to_synckeygen pub keys count {:?} error {:?}", pub_keys_arc.len(), e); //let mut failure_pub_keys: Vec = Vec::new(); From 66a90cdca7d83e41340fea9fa3e648f3d52a960a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 14 Feb 2025 15:16:56 +0100 Subject: [PATCH 319/687] changelog and version setting --- CHANGELOG.md | 10 ++++++++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e4cabb76..46a5ec841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,14 @@ + +## Diamond Node Software 3.3.5-hbbft-0.9.8 + +- Improved Hbbft "No Session Exists" handling: https://github.com/DMDcoin/diamond-node/issues/150 +- Lock overhead reduction for validator actions +- Connect & Disconnect Report management: fixed double sending of reports: https://github.com/DMDcoin/diamond-node/issues/157 +- Stage 3 Verification: Fixed State Pruning related error. https://github.com/DMDcoin/diamond-node/issues/161 +- Added Network and DevP2P related Information to the Prometheus Metrics: https://github.com/DMDcoin/diamond-node/issues/163 +- Early Epoch End: Treat any HBBFT Message as being a responsive partner node: https://github.com/DMDcoin/diamond-node/issues/87 + ## Diamond Node Software 3.3.5-hbbft-0.9.7 - [Nodes that are not a active validator seem to try to send connectivity reports] (https://github.com/DMDcoin/diamond-node/issues/153) diff --git a/Cargo.lock b/Cargo.lock index 0d9f4bd48..1acec20aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -843,7 +843,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.9.7" +version = "3.3.5-hbbft-0.9.8" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3575,7 +3575,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.9.7" +version = "3.3.5-hbbft-0.9.8" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index a91dcce86..23ce1ccee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.9.7" +version = "3.3.5-hbbft-0.9.8" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index a2ae34563..a27b92ac0 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.9.7" +version = "3.3.5-hbbft-0.9.8" authors = [ "bit.diamonds developers", "OpenEthereum developers", From b107209c07ca9e7184f6aa1f01daa266e1690b3a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 14 Feb 2025 17:20:04 +0100 Subject: [PATCH 320/687] moved dependencies to dmdcoin --- Cargo.lock | 4 ++-- crates/accounts/ethkey/Cargo.toml | 2 +- crates/util/dir/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1acec20aa..4de2bb379 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,7 +110,7 @@ dependencies = [ [[package]] name = "app_dirs" version = "1.2.1" -source = "git+https://github.com/openethereum/app-dirs-rs#0b37f9481ce29e9d5174ad185bca695b206368eb" +source = "git+https://github.com/dmdcoin/app-dirs-rs#0b37f9481ce29e9d5174ad185bca695b206368eb" dependencies = [ "ole32-sys", "shell32-sys", @@ -1070,7 +1070,7 @@ dependencies = [ [[package]] name = "eth-secp256k1" version = "0.5.7" -source = "git+https://github.com/paritytech/rust-secp256k1?rev=9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4#9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" +source = "git+https://github.com/dmdcoin/rust-secp256k1?rev=9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4#9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" dependencies = [ "arrayvec 0.4.12", "cc", diff --git a/crates/accounts/ethkey/Cargo.toml b/crates/accounts/ethkey/Cargo.toml index 5b32bbaa2..1ead44f21 100644 --- a/crates/accounts/ethkey/Cargo.toml +++ b/crates/accounts/ethkey/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Parity Technologies "] [dependencies] edit-distance = "2.0" parity-crypto = { version = "0.6.2", features = ["publickey"] } -eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", rev = "9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" } +eth-secp256k1 = { git = "https://github.com/dmdcoin/rust-secp256k1", rev = "9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" } ethereum-types = "0.9.2" lazy_static = "1.0" log = "0.4" diff --git a/crates/util/dir/Cargo.toml b/crates/util/dir/Cargo.toml index bfa27f23e..934fb0819 100644 --- a/crates/util/dir/Cargo.toml +++ b/crates/util/dir/Cargo.toml @@ -7,5 +7,5 @@ license = "GPL3" [dependencies] ethereum-types = "0.9.2" journaldb = { path = "../../db/journaldb" } -app_dirs = { git = "https://github.com/openethereum/app-dirs-rs" } +app_dirs = { git = "https://github.com/dmdcoin/app-dirs-rs" } home = "0.3" From 54d43033f7614c7bf3e18d27fb3b87ec4c86d8ce Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 14 Feb 2025 17:23:34 +0100 Subject: [PATCH 321/687] version.txt --- bin/oe/cli/version.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/oe/cli/version.txt b/bin/oe/cli/version.txt index 41fa04212..e0820a015 100644 --- a/bin/oe/cli/version.txt +++ b/bin/oe/cli/version.txt @@ -1,10 +1,11 @@ -OpenEthereum Client. +diamond-node version {} Copyright 2015-2020 Parity Technologies (UK) Ltd. +Copyright 2020-2025 DMD diamond. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. -By Wood/Paronyan/Kotewicz/DrwiÄ™ga/Volf/Greeff +By Haller/Forstenlechner/Wood/Paronyan/Kotewicz/DrwiÄ™ga/Volf/Greeff Habermeier/Czaban/Gotchac/Redman/Nikolsky Schoedon/Tang/Adolfsson/Silva/Palm/Hirsz et al. From 9eb91247305effd85baed8417776e92df282e0ba Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 14 Feb 2025 17:26:07 +0100 Subject: [PATCH 322/687] homepage update --- crates/accounts/Cargo.toml | 2 +- crates/concensus/miner/Cargo.toml | 2 +- crates/concensus/miner/price-info/Cargo.toml | 2 +- crates/db/db/Cargo.toml | 2 +- crates/ethcore/Cargo.toml | 2 +- crates/ethcore/blockchain/Cargo.toml | 2 +- crates/net/fetch/Cargo.toml | 2 +- crates/net/network-devp2p/Cargo.toml | 2 +- crates/net/network/Cargo.toml | 2 +- crates/net/node-filter/Cargo.toml | 2 +- crates/runtime/io/Cargo.toml | 2 +- crates/runtime/runtime/Cargo.toml | 2 +- crates/util/cli-signer/Cargo.toml | 2 +- crates/util/cli-signer/rpc-client/Cargo.toml | 2 +- crates/util/len-caching-lock/Cargo.toml | 2 +- crates/util/panic-hook/Cargo.toml | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/accounts/Cargo.toml b/crates/accounts/Cargo.toml index a7282ecf8..98ac475c7 100644 --- a/crates/accounts/Cargo.toml +++ b/crates/accounts/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "OpenEthereum Account Management" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore-accounts" version = "0.1.0" diff --git a/crates/concensus/miner/Cargo.toml b/crates/concensus/miner/Cargo.toml index f503a72e5..46eda3c3b 100644 --- a/crates/concensus/miner/Cargo.toml +++ b/crates/concensus/miner/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "OpenEthereum Miner Interface." name = "ethcore-miner" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" version = "1.12.0" authors = ["Parity Technologies "] diff --git a/crates/concensus/miner/price-info/Cargo.toml b/crates/concensus/miner/price-info/Cargo.toml index af02b9050..ea0427831 100644 --- a/crates/concensus/miner/price-info/Cargo.toml +++ b/crates/concensus/miner/price-info/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "Fetch current ETH price" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "price-info" version = "1.12.0" diff --git a/crates/db/db/Cargo.toml b/crates/db/db/Cargo.toml index 372c986f3..ab79a1408 100644 --- a/crates/db/db/Cargo.toml +++ b/crates/db/db/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "OpenEthereum DB access utilities" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore-db" version = "0.1.0" diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index d84aaaf13..5f73e011c 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "OpenEthereum (EthCore) Library" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore" version = "1.12.0" diff --git a/crates/ethcore/blockchain/Cargo.toml b/crates/ethcore/blockchain/Cargo.toml index 9f79c3ea1..3bfe76ddb 100644 --- a/crates/ethcore/blockchain/Cargo.toml +++ b/crates/ethcore/blockchain/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "OpenEthereum Blockchain Database, Test Generator, Configuration, Caching, Importing Blocks, and Block Information" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore-blockchain" version = "0.1.0" diff --git a/crates/net/fetch/Cargo.toml b/crates/net/fetch/Cargo.toml index a094842bc..eabbbdb61 100644 --- a/crates/net/fetch/Cargo.toml +++ b/crates/net/fetch/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "HTTP/HTTPS fetching library" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "fetch" version = "0.1.0" diff --git a/crates/net/network-devp2p/Cargo.toml b/crates/net/network-devp2p/Cargo.toml index 178c9c502..0ec7e2e78 100644 --- a/crates/net/network-devp2p/Cargo.toml +++ b/crates/net/network-devp2p/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "DevP2P implementation of the ethcore network library" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore-network-devp2p" version = "1.12.0" diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index 5cc8a560a..19e583341 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "Ethcore network library" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore-network" version = "1.12.0" diff --git a/crates/net/node-filter/Cargo.toml b/crates/net/node-filter/Cargo.toml index 0ae43fe1b..e14a1bc59 100644 --- a/crates/net/node-filter/Cargo.toml +++ b/crates/net/node-filter/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "OpenEthereum Smart Contract based Node Filter, Manage Permissions of Network Connections" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "node-filter" version = "1.12.0" diff --git a/crates/runtime/io/Cargo.toml b/crates/runtime/io/Cargo.toml index 2270ca840..a0d6a1aeb 100644 --- a/crates/runtime/io/Cargo.toml +++ b/crates/runtime/io/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "Ethcore IO library" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore-io" version = "1.12.0" diff --git a/crates/runtime/runtime/Cargo.toml b/crates/runtime/runtime/Cargo.toml index 74c30b3ce..8b1ad7f73 100644 --- a/crates/runtime/runtime/Cargo.toml +++ b/crates/runtime/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "OpenEthereum Runtime" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "parity-runtime" version = "0.1.0" diff --git a/crates/util/cli-signer/Cargo.toml b/crates/util/cli-signer/Cargo.toml index 83fe9c0c2..c6434352e 100644 --- a/crates/util/cli-signer/Cargo.toml +++ b/crates/util/cli-signer/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "OpenEthereum CLI Signer Tool" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "cli-signer" version = "1.4.0" diff --git a/crates/util/cli-signer/rpc-client/Cargo.toml b/crates/util/cli-signer/rpc-client/Cargo.toml index a689d37ec..053d7413d 100644 --- a/crates/util/cli-signer/rpc-client/Cargo.toml +++ b/crates/util/cli-signer/rpc-client/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "OpenEthereum RPC Client" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "parity-rpc-client" version = "1.4.0" diff --git a/crates/util/len-caching-lock/Cargo.toml b/crates/util/len-caching-lock/Cargo.toml index 4d471000e..874485f25 100644 --- a/crates/util/len-caching-lock/Cargo.toml +++ b/crates/util/len-caching-lock/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "Atomically cached len(), for use with collections contained in parking_lot Mutex and RwLock" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "len-caching-lock" version = "0.1.1" diff --git a/crates/util/panic-hook/Cargo.toml b/crates/util/panic-hook/Cargo.toml index eac3d806a..f885bb7a4 100644 --- a/crates/util/panic-hook/Cargo.toml +++ b/crates/util/panic-hook/Cargo.toml @@ -1,6 +1,6 @@ [package] description = "OpenEthereum custom panic hook" -homepage = "https://github.com/openethereum/openethereum" +homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "panic_hook" version = "0.1.0" From 0e815de0426b8da348ce474408f605b8a32e9880 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 14 Feb 2025 17:27:08 +0100 Subject: [PATCH 323/687] Description: OpenEthereum -> diamond-node --- crates/accounts/Cargo.toml | 2 +- crates/concensus/miner/Cargo.toml | 2 +- crates/db/db/Cargo.toml | 2 +- crates/ethcore/Cargo.toml | 2 +- crates/ethcore/blockchain/Cargo.toml | 2 +- crates/net/node-filter/Cargo.toml | 2 +- crates/rpc-servers/Cargo.toml | 2 +- crates/runtime/runtime/Cargo.toml | 2 +- crates/util/cli-signer/Cargo.toml | 2 +- crates/util/cli-signer/rpc-client/Cargo.toml | 2 +- crates/util/panic-hook/Cargo.toml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/accounts/Cargo.toml b/crates/accounts/Cargo.toml index 98ac475c7..ae560b6a8 100644 --- a/crates/accounts/Cargo.toml +++ b/crates/accounts/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum Account Management" +description = "diamond-node Account Management" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore-accounts" diff --git a/crates/concensus/miner/Cargo.toml b/crates/concensus/miner/Cargo.toml index 46eda3c3b..af7f5fb71 100644 --- a/crates/concensus/miner/Cargo.toml +++ b/crates/concensus/miner/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum Miner Interface." +description = "diamond-node Miner Interface." name = "ethcore-miner" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" diff --git a/crates/db/db/Cargo.toml b/crates/db/db/Cargo.toml index ab79a1408..95ebb5071 100644 --- a/crates/db/db/Cargo.toml +++ b/crates/db/db/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum DB access utilities" +description = "diamond-node DB access utilities" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore-db" diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index 5f73e011c..be6e79a23 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum (EthCore) Library" +description = "diamond-node (EthCore) Library" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore" diff --git a/crates/ethcore/blockchain/Cargo.toml b/crates/ethcore/blockchain/Cargo.toml index 3bfe76ddb..7052b09b1 100644 --- a/crates/ethcore/blockchain/Cargo.toml +++ b/crates/ethcore/blockchain/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum Blockchain Database, Test Generator, Configuration, Caching, Importing Blocks, and Block Information" +description = "diamond-node Blockchain Database, Test Generator, Configuration, Caching, Importing Blocks, and Block Information" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "ethcore-blockchain" diff --git a/crates/net/node-filter/Cargo.toml b/crates/net/node-filter/Cargo.toml index e14a1bc59..5d2314632 100644 --- a/crates/net/node-filter/Cargo.toml +++ b/crates/net/node-filter/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum Smart Contract based Node Filter, Manage Permissions of Network Connections" +description = "diamond-node Smart Contract based Node Filter, Manage Permissions of Network Connections" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "node-filter" diff --git a/crates/rpc-servers/Cargo.toml b/crates/rpc-servers/Cargo.toml index 8c90f86c3..4e042eb2c 100644 --- a/crates/rpc-servers/Cargo.toml +++ b/crates/rpc-servers/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum RPC servers (WS, HTTP, IPC)" +description = "diamond-node RPC servers (WS, HTTP, IPC)" name = "oe-rpc-servers" version = "0.0.0" license = "GPL-3.0" diff --git a/crates/runtime/runtime/Cargo.toml b/crates/runtime/runtime/Cargo.toml index 8b1ad7f73..e537b2f4a 100644 --- a/crates/runtime/runtime/Cargo.toml +++ b/crates/runtime/runtime/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum Runtime" +description = "diamond-node Runtime" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "parity-runtime" diff --git a/crates/util/cli-signer/Cargo.toml b/crates/util/cli-signer/Cargo.toml index c6434352e..a927870cc 100644 --- a/crates/util/cli-signer/Cargo.toml +++ b/crates/util/cli-signer/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum CLI Signer Tool" +description = "diamond-node CLI Signer Tool" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "cli-signer" diff --git a/crates/util/cli-signer/rpc-client/Cargo.toml b/crates/util/cli-signer/rpc-client/Cargo.toml index 053d7413d..dced024c6 100644 --- a/crates/util/cli-signer/rpc-client/Cargo.toml +++ b/crates/util/cli-signer/rpc-client/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum RPC Client" +description = "diamond-node RPC Client" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "parity-rpc-client" diff --git a/crates/util/panic-hook/Cargo.toml b/crates/util/panic-hook/Cargo.toml index f885bb7a4..82bb89719 100644 --- a/crates/util/panic-hook/Cargo.toml +++ b/crates/util/panic-hook/Cargo.toml @@ -1,5 +1,5 @@ [package] -description = "OpenEthereum custom panic hook" +description = "diamond-node custom panic hook" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" name = "panic_hook" From 3b3967708ead5cf8abd958a4ab05753a82643188 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 14 Feb 2025 17:31:29 +0100 Subject: [PATCH 324/687] cargo: fixed repossitory links --- crates/util/EIP-152/Cargo.toml | 2 +- crates/util/EIP-712/Cargo.toml | 2 +- crates/util/memzero/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/util/EIP-152/Cargo.toml b/crates/util/EIP-152/Cargo.toml index ac46304d6..a867f4273 100644 --- a/crates/util/EIP-152/Cargo.toml +++ b/crates/util/EIP-152/Cargo.toml @@ -2,7 +2,7 @@ name = "eip-152" version = "0.1.0" authors = ["Parity Technologies "] -repository = "https://github.com/openethereum/openethereum" +repository = "https://github.com/dmdcoin/diamond-node" documentation = "https://docs.rs/eip-152" readme = "README.md" description = "eip-512 blake2 F compression function" diff --git a/crates/util/EIP-712/Cargo.toml b/crates/util/EIP-712/Cargo.toml index f98fc0161..3da8f0ab3 100644 --- a/crates/util/EIP-712/Cargo.toml +++ b/crates/util/EIP-712/Cargo.toml @@ -2,7 +2,7 @@ name = "eip-712" version = "0.1.0" authors = ["Parity Technologies "] -repository = "https://github.com/openethereum/openethereum" +repository = "https://github.com/dmdcoin/diamond-node" documentation = "https://docs.rs/eip-712" readme = "README.md" description = "eip-712 encoding" diff --git a/crates/util/memzero/Cargo.toml b/crates/util/memzero/Cargo.toml index 9eb6f731c..3829403b3 100644 --- a/crates/util/memzero/Cargo.toml +++ b/crates/util/memzero/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "A wrapper for zero-ing out memory when dropped" license = "GPL-3.0" homepage = "https://parity.io" -repository = "https://github.com/openethereum/openethereum" +repository = "https://github.com/dmdcoin/diamond-node" documentation = "https://docs.rs/crate/memzero" authors = ["Parity Technologies "] edition = "2018" From 7fd5fa776a80ab9679ab1625b892909abc00f701 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 15 Feb 2025 23:28:18 +0100 Subject: [PATCH 325/687] only print "Node was marked as useless" if it has not already be known to be useless. lowered debug level from Info to Debug for finding useless nodes. --- crates/net/network-devp2p/src/node_table.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/net/network-devp2p/src/node_table.rs b/crates/net/network-devp2p/src/node_table.rs index 24dab5ba7..b4cf3fd4b 100644 --- a/crates/net/network-devp2p/src/node_table.rs +++ b/crates/net/network-devp2p/src/node_table.rs @@ -429,8 +429,9 @@ impl NodeTable { /// Mark as useless, no further attempts to connect until next call to `clear_useless`. pub fn mark_as_useless(&mut self, id: &NodeId) { - info!(target: "network", "Node was marked as useless: {:?}", id); - self.useless_nodes.insert(id.clone()); + if self.useless_nodes.insert(id.clone()) { + debug!(target: "network", "Node was marked as useless: {:?}", id); + } } /// Attempt to connect to useless nodes again. From 7b9b855650cad06cf4a6f161505521df2125617a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 17 Feb 2025 17:03:23 +0100 Subject: [PATCH 326/687] reverted to eth-secp256k1 from paritytech --- Cargo.lock | 2 +- crates/accounts/ethkey/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4de2bb379..3ead1502a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1070,7 +1070,7 @@ dependencies = [ [[package]] name = "eth-secp256k1" version = "0.5.7" -source = "git+https://github.com/dmdcoin/rust-secp256k1?rev=9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4#9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" +source = "git+https://github.com/paritytech/rust-secp256k1?rev=9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4#9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" dependencies = [ "arrayvec 0.4.12", "cc", diff --git a/crates/accounts/ethkey/Cargo.toml b/crates/accounts/ethkey/Cargo.toml index 1ead44f21..5b32bbaa2 100644 --- a/crates/accounts/ethkey/Cargo.toml +++ b/crates/accounts/ethkey/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Parity Technologies "] [dependencies] edit-distance = "2.0" parity-crypto = { version = "0.6.2", features = ["publickey"] } -eth-secp256k1 = { git = "https://github.com/dmdcoin/rust-secp256k1", rev = "9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" } +eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", rev = "9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" } ethereum-types = "0.9.2" lazy_static = "1.0" log = "0.4" From 38f74722f4b4fcb4570e464d6fa48407dceb972d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 17 Feb 2025 17:23:40 +0100 Subject: [PATCH 327/687] release 0.10.0-rc1 --- CHANGELOG.md | 5 +++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a5ec841..54728e895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ +## Diamond Node Software 3.3.5-hbbft-0.10.0 + +### Summary for Diamond Node Software 3.3.5-hbbft-0.10.0 + +- 0.10.0 ## Diamond Node Software 3.3.5-hbbft-0.9.8 - Improved Hbbft "No Session Exists" handling: https://github.com/DMDcoin/diamond-node/issues/150 diff --git a/Cargo.lock b/Cargo.lock index 3ead1502a..790e09d72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -843,7 +843,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.9.8" +version = "3.3.5-hbbft-0.10.0-rc1" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3575,7 +3575,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.9.8" +version = "3.3.5-hbbft-0.10.0-rc1" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 23ce1ccee..5fa9abdc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.9.8" +version = "3.3.5-hbbft-0.10.0-rc1" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index a27b92ac0..c35058be0 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.9.8" +version = "3.3.5-hbbft-0.10.0-rc1" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 427b20b71cae5133db4ed9629916f24cd611007c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 17 Feb 2025 17:29:07 +0100 Subject: [PATCH 328/687] 3.3.5-hbbft-0.10.0 --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54728e895..c31302faa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,12 @@ ## Diamond Node Software 3.3.5-hbbft-0.10.0 + + ### Summary for Diamond Node Software 3.3.5-hbbft-0.10.0 -- 0.10.0 +- Bonus Score finalization + ## Diamond Node Software 3.3.5-hbbft-0.9.8 - Improved Hbbft "No Session Exists" handling: https://github.com/DMDcoin/diamond-node/issues/150 From 54e0535a6834b6b25e2c5f4b6b4642c060f3cb86 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 18 Feb 2025 21:26:40 +0100 Subject: [PATCH 329/687] lowered log level for Disabling Peer (this Software Version not whitelisted). --- crates/ethcore/sync/src/chain/handler.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index c28af9f4f..938d3fda4 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -158,8 +158,6 @@ impl SyncHandler { trace!(target: "sync", "== Connected {}: {}", peer, peer_version); let whitelisted = peer_version.is_hbbft(); - // peer_version_string.contains("hbbft") - // && peer_version_string.contains("OpenEthereum"); if !whitelisted { let mut ip_addr = String::new(); @@ -167,7 +165,7 @@ impl SyncHandler { Some(session) => ip_addr = session.remote_address.to_string(), None => {} } - info!(target:"sync", "Disabling Peer (this Software Version not whitelisted) {} ip:{} ", peer_version, ip_addr); + debug!(target:"sync", "Disabling Peer (this Software Version not whitelisted) {} ip:{} ", peer_version, ip_addr); io.disable_peer(peer); } else if let Err(e) = sync.send_status(io, peer) { debug!(target:"sync", "Error sending status request: {:?}", e); From 9c7a2a18d973abf6cedfd6186e8b9b3a905840e1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 18 Feb 2025 21:51:15 +0100 Subject: [PATCH 330/687] version: 0.10.0 --- CHANGELOG.md | 6 +----- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c31302faa..983bddefe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,7 @@ ## Diamond Node Software 3.3.5-hbbft-0.10.0 - - -### Summary for Diamond Node Software 3.3.5-hbbft-0.10.0 - -- Bonus Score finalization +- Bonus Score finalization ## Diamond Node Software 3.3.5-hbbft-0.9.8 diff --git a/Cargo.lock b/Cargo.lock index 790e09d72..cf5542252 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -843,7 +843,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.10.0-rc1" +version = "3.3.5-hbbft-0.10.0" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3575,7 +3575,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.10.0-rc1" +version = "3.3.5-hbbft-0.10.0" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 5fa9abdc1..17792a291 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.10.0-rc1" +version = "3.3.5-hbbft-0.10.0" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index c35058be0..22e62d161 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.10.0-rc1" +version = "3.3.5-hbbft-0.10.0" authors = [ "bit.diamonds developers", "OpenEthereum developers", From deaf3c64a781270459d4c34c63aed6ad710b926f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 20 Feb 2025 14:57:54 +0100 Subject: [PATCH 331/687] experimentation fix for eth_pendingTransactions --- crates/rpc/src/v1/traits/parity.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/rpc/src/v1/traits/parity.rs b/crates/rpc/src/v1/traits/parity.rs index 7199fc7a7..a404d7532 100644 --- a/crates/rpc/src/v1/traits/parity.rs +++ b/crates/rpc/src/v1/traits/parity.rs @@ -137,6 +137,19 @@ pub trait Parity { _: Option, ) -> Result>; + /// Returns all pending transactions from transaction queue. + #[rpc(name = "eth_pendingTransactions")] + fn pending_transactions_eth( + &self, + size: Option, + filter: Option, + ) -> Result> { + self.pending_transactions(size, filter) + } + + + + /// Returns all transactions from transaction queue. /// /// Some of them might not be ready to be included in a block yet. From 8b8d1b50ce1605a334d4197d94a7cfd122342c06 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 24 Feb 2025 16:55:39 +0100 Subject: [PATCH 332/687] information about what peer is did not response to status request. --- crates/ethcore/sync/src/chain/handler.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index c28af9f4f..64bde49a9 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -170,7 +170,8 @@ impl SyncHandler { info!(target:"sync", "Disabling Peer (this Software Version not whitelisted) {} ip:{} ", peer_version, ip_addr); io.disable_peer(peer); } else if let Err(e) = sync.send_status(io, peer) { - debug!(target:"sync", "Error sending status request: {:?}", e); + debug!(target:"sync", "Error sending status request: {:?} {:?}", e, io.peer_session_info(peer).map_or(" (no Session)", |f| f.remote_address.as_str())); + io.disconnect_peer(peer); } else { sync.handshaking_peers.insert(peer, Instant::now()); From 45bab8e013d8909c918d3c0a452a03d8a59dfa54 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 Feb 2025 14:27:58 +0100 Subject: [PATCH 333/687] refactored SyncPropagator to be statefull and part of ChainSync. Introduced PropagatorStatistics, to be continued with more tracking and caching. --- crates/ethcore/sync/src/api.rs | 2 +- crates/ethcore/sync/src/chain/handler.rs | 3 +- crates/ethcore/sync/src/chain/mod.rs | 39 +-- crates/ethcore/sync/src/chain/propagator.rs | 243 +++++++++--------- .../sync/src/chain/propagator_statistics.rs | 68 +++++ 5 files changed, 207 insertions(+), 148 deletions(-) create mode 100644 crates/ethcore/sync/src/chain/propagator_statistics.rs diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index ee4cf5cb7..318a9fbc4 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -588,7 +588,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler { PEERS_TIMER => self.sync.write().maintain_peers(&mut io), MAINTAIN_SYNC_TIMER => self.sync.write().maintain_sync(&mut io), CONTINUE_SYNC_TIMER => self.sync.write().continue_sync(&mut io), - TX_TIMER => self.sync.write().propagate_new_transactions(&mut io), + TX_TIMER => self.sync.write().propagate_new_ready_transactions(&mut io), PRIORITY_TIMER => self.sync.process_priority_queue(&mut io), DELAYED_PROCESSING_TIMER => self.sync.process_delayed_requests(&mut io), CONSENSUS_SEND_RETRY_TIMER => self.try_resend_consensus_messages(nc), diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 64bde49a9..4484d52f1 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -170,8 +170,7 @@ impl SyncHandler { info!(target:"sync", "Disabling Peer (this Software Version not whitelisted) {} ip:{} ", peer_version, ip_addr); io.disable_peer(peer); } else if let Err(e) = sync.send_status(io, peer) { - debug!(target:"sync", "Error sending status request: {:?} {:?}", e, io.peer_session_info(peer).map_or(" (no Session)", |f| f.remote_address.as_str())); - + debug!(target:"sync", "Error sending status request: {:?} {:?}", e, io.peer_session_info(peer).as_ref().map_or(" (no Session)", |f| f.remote_address.as_str())); io.disconnect_peer(peer); } else { sync.handshaking_peers.insert(peer, Instant::now()); diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index ebca850af..dc9a2dfe5 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -90,12 +90,14 @@ pub mod fork_filter; mod handler; mod propagator; +mod propagator_statistics; pub mod request_id; mod requester; mod supplier; pub mod sync_packet; pub use self::fork_filter::ForkFilterApi; +use self::propagator_statistics::SyncPropagatorStatistics; use super::{SyncConfig, WarpSync}; use api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, ETH_PROTOCOL, PAR_PROTOCOL}; use block_sync::{BlockDownloader, DownloadAction}; @@ -131,8 +133,8 @@ use self::{ }, }; +use self::requester::SyncRequester; pub(crate) use self::supplier::SyncSupplier; -use self::{propagator::SyncPropagator, requester::SyncRequester}; malloc_size_of_is_0!(PeerInfo); @@ -558,7 +560,7 @@ impl ChainSyncApi { for peers in sync.get_peers(&chain_info, PeerState::SameBlock).chunks(10) { check_deadline(deadline)?; for peer in peers { - SyncPropagator::send_packet(io, *peer, NewBlockPacket, rlp.clone()); + ChainSync::send_packet(io, *peer, NewBlockPacket, rlp.clone()); if let Some(ref mut peer) = sync.peers.get_mut(peer) { peer.latest_hash = hash; } @@ -568,7 +570,7 @@ impl ChainSyncApi { } PriorityTask::PropagateTransactions(time, _) => { let hashes = sync.new_transaction_hashes(None); - SyncPropagator::propagate_new_transactions(&mut sync, io, hashes, || { + sync.propagate_new_transactions(io, hashes, || { check_deadline(deadline).is_some() }); debug!(target: "sync", "Finished transaction propagation, took {}ms", as_ms(time)); @@ -732,6 +734,8 @@ pub struct ChainSync { eip1559_transition: BlockNumber, /// Number of blocks for which new transactions will be returned in a result of `parity_newTransactionsStats` RPC call new_transactions_stats_period: BlockNumber, + /// Statistics of sync propagation + statistics: SyncPropagatorStatistics, } #[derive(Debug, Default)] @@ -821,6 +825,7 @@ impl ChainSync { warp_sync: config.warp_sync, eip1559_transition: config.eip1559_transition, new_transactions_stats_period: config.new_transactions_stats_period, + statistics: SyncPropagatorStatistics::new(), }; sync.update_targets(chain); sync @@ -1725,9 +1730,10 @@ impl ChainSync { if !is_syncing || !sealed.is_empty() || !proposed.is_empty() { trace!(target: "sync", "Propagating blocks, state={:?}", self.state); // t_nb 11.4.1 propagate latest blocks - SyncPropagator::propagate_latest_blocks(self, io, sealed); + self.propagate_latest_blocks(io, sealed); + // t_nb 11.4.4 propagate proposed blocks - SyncPropagator::propagate_proposed_blocks(self, io, proposed); + self.propagate_proposed_blocks(io, proposed); } if !invalid.is_empty() { info!(target: "sync", "Bad blocks in the queue, restarting sync"); @@ -1757,29 +1763,6 @@ impl ChainSync { pub fn on_peer_connected(&mut self, io: &mut dyn SyncIo, peer: PeerId) { SyncHandler::on_peer_connected(self, io, peer); } - - /// propagates new transactions to all peers - pub fn propagate_new_transactions(&mut self, io: &mut dyn SyncIo) { - let deadline = Instant::now() + Duration::from_millis(500); - SyncPropagator::propagate_ready_transactions(self, io, || { - if deadline > Instant::now() { - true - } else { - debug!(target: "sync", "Wasn't able to finish transaction propagation within a deadline."); - false - } - }); - } - - /// Broadcast consensus message to peers. - pub fn propagate_consensus_packet(&mut self, io: &mut dyn SyncIo, packet: Bytes) { - SyncPropagator::propagate_consensus_packet(self, io, packet); - } - - /// Send consensus message to a specific peer. - pub fn send_consensus_packet(&mut self, io: &mut dyn SyncIo, packet: Bytes, peer_id: usize) { - SyncPropagator::send_consensus_packet(self, io, packet, peer_id); - } } #[cfg(test)] diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index e85d1d5de..e16e28cb1 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -14,18 +14,27 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use std::{cmp, collections::HashSet}; +use std::{ + cmp, + collections::HashSet, + sync::atomic::{AtomicBool, AtomicI64, Ordering}, + time::{Duration, Instant}, +}; use bytes::Bytes; use ethereum_types::H256; use fastmap::H256FastSet; use network::{client_version::ClientCapabilities, PeerId}; +use parking_lot::{Mutex, RwLock}; use rand::RngCore; use rlp::RlpStream; use sync_io::SyncIo; use types::{blockchain_info::BlockChainInfo, transaction::SignedTransaction, BlockNumber}; -use super::sync_packet::SyncPacket::{self, *}; +use super::{ + propagator_statistics::SyncPropagatorStatistics, + sync_packet::SyncPacket::{self, *}, +}; use super::{ random, ChainSync, ETH_PROTOCOL_VERSION_65, MAX_PEERS_PROPAGATION, MAX_PEER_LAG_PROPAGATION, @@ -37,12 +46,23 @@ use std::sync::Arc; const NEW_POOLED_HASHES_LIMIT: usize = 4096; /// The Chain Sync Propagator: propagates data to peers -pub struct SyncPropagator; +// pub struct SyncPropagator<'a> { + +// //sync: ChainSync +// } + +// SyncPropagator for +impl ChainSync { + // fn new( ) -> Self { + // SyncPropagator { + // statistics: SyncPropagatorStatistics::default(), + // sync + // } + // } -impl SyncPropagator { // t_nb 11.4.3 propagates latest block to a set of peers - pub fn propagate_blocks( - sync: &mut ChainSync, + fn propagate_blocks( + &mut self, chain_info: &BlockChainInfo, io: &mut dyn SyncIo, blocks: &[H256], @@ -52,9 +72,12 @@ impl SyncPropagator { let sent = peers.len(); let mut send_packet = |io: &mut dyn SyncIo, rlp: Bytes| { for peer_id in peers { - SyncPropagator::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); + self.statistics + .log_packet(io, *peer_id, blocks.len(), rlp.len()); + + ChainSync::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); - if let Some(ref mut peer) = sync.peers.get_mut(peer_id) { + if let Some(ref mut peer) = self.peers.get_mut(peer_id) { peer.latest_hash = chain_info.best_block_hash.clone(); } } @@ -74,8 +97,8 @@ impl SyncPropagator { } // t_nb 11.4.2 propagates new known hashes to all peers - pub fn propagate_new_hashes( - sync: &mut ChainSync, + fn propagate_new_hashes( + &mut self, chain_info: &BlockChainInfo, io: &mut dyn SyncIo, peers: &[PeerId], @@ -91,17 +114,31 @@ impl SyncPropagator { let sent = peers.len(); for peer_id in peers { - if let Some(ref mut peer) = sync.peers.get_mut(peer_id) { + if let Some(ref mut peer) = self.peers.get_mut(peer_id) { peer.latest_hash = best_block_hash; } - SyncPropagator::send_packet(io, *peer_id, NewBlockHashesPacket, rlp.clone()); + ChainSync::send_packet(io, *peer_id, NewBlockHashesPacket, rlp.clone()); } sent } + /// propagates new transactions to all peers + pub fn propagate_new_ready_transactions(&mut self, io: &mut dyn SyncIo) { + let deadline = Instant::now() + Duration::from_millis(500); + + self.propagate_ready_transactions(io, || { + if deadline > Instant::now() { + true + } else { + debug!(target: "sync", "Wasn't able to finish transaction propagation within a deadline."); + false + } + }); + } + /// propagates new transactions to all peers pub fn propagate_new_transactions bool>( - sync: &mut ChainSync, + &mut self, io: &mut dyn SyncIo, tx_hashes: Vec, should_continue: F, @@ -112,20 +149,20 @@ impl SyncPropagator { .filter_map(|hash| io.chain().transaction(hash)) .collect() }; - SyncPropagator::propagate_transactions(sync, io, transactions, true, should_continue) + self.propagate_transactions(io, transactions, true, should_continue) } - pub fn propagate_ready_transactions bool>( - sync: &mut ChainSync, + fn propagate_ready_transactions bool>( + &mut self, io: &mut dyn SyncIo, should_continue: F, ) -> usize { let transactions = |io: &dyn SyncIo| io.chain().transactions_to_propagate(); - SyncPropagator::propagate_transactions(sync, io, transactions, false, should_continue) + self.propagate_transactions(io, transactions, false, should_continue) } fn propagate_transactions_to_peers bool>( - sync: &mut ChainSync, + &mut self, io: &mut dyn SyncIo, peers: Vec, transactions: Vec<&SignedTransaction>, @@ -149,10 +186,10 @@ impl SyncPropagator { let block_number = io.chain().chain_info().best_block_number; if are_new { - sync.transactions_stats - .retain_new(block_number, sync.new_transactions_stats_period); + self.transactions_stats + .retain_new(block_number, self.new_transactions_stats_period); } else { - sync.transactions_stats + self.transactions_stats .retain_pending(&all_transactions_hashes); } @@ -162,7 +199,7 @@ impl SyncPropagator { sent: usize, rlp: Bytes| { let size = rlp.len(); - SyncPropagator::send_packet( + ChainSync::send_packet( io, peer_id, if is_hashes { @@ -185,9 +222,9 @@ impl SyncPropagator { return sent_to_peers; } - let stats = &mut sync.transactions_stats; - let peer_info = sync.peers.get_mut(&peer_id) - .expect("peer_id is form peers; peers is result of select_peers_for_transactions; select_peers_for_transactions selects peers from self.peers; qed"); + let stats = &mut self.transactions_stats; + let peer_info = self.peers.get_mut(&peer_id) + .expect("peer_id is form peers; peers is result of select_peers_for_transactions; select_peers_for_transactions selects peers from self.peers; qed"); let is_hashes = peer_info.protocol_version >= ETH_PROTOCOL_VERSION_65.0; @@ -274,69 +311,59 @@ impl SyncPropagator { } // t_nb 11.4.1 propagate latest blocks to peers - pub fn propagate_latest_blocks(sync: &mut ChainSync, io: &mut dyn SyncIo, sealed: &[H256]) { + pub fn propagate_latest_blocks<'a>(&mut self, io: &mut dyn SyncIo, sealed: &[H256]) { let chain_info = io.chain().chain_info(); - if (((chain_info.best_block_number as i64) - (sync.last_sent_block_number as i64)).abs() + if (((chain_info.best_block_number as i64) - (self.last_sent_block_number as i64)).abs() as BlockNumber) < MAX_PEER_LAG_PROPAGATION { - let peers = sync.get_lagging_peers(&chain_info); + let peers = self.get_lagging_peers(&chain_info); if sealed.is_empty() { // t_nb 11.4.2 - let hashes = SyncPropagator::propagate_new_hashes(sync, &chain_info, io, &peers); + let hashes = self.propagate_new_hashes(&chain_info, io, &peers); let peers = ChainSync::select_random_peers(&peers); // t_nb 11.4.3 - let blocks = - SyncPropagator::propagate_blocks(sync, &chain_info, io, sealed, &peers); + let blocks = self.propagate_blocks(&chain_info, io, sealed, &peers); if blocks != 0 || hashes != 0 { trace!(target: "sync", "Sent latest {} blocks and {} hashes to peers.", blocks, hashes); } } else { // t_nb 11.4.3 - SyncPropagator::propagate_blocks(sync, &chain_info, io, sealed, &peers); + self.propagate_blocks(&chain_info, io, sealed, &peers); // t_nb 11.4.2 - SyncPropagator::propagate_new_hashes(sync, &chain_info, io, &peers); + self.propagate_new_hashes(&chain_info, io, &peers); trace!(target: "sync", "Sent sealed block to all peers"); }; } - sync.last_sent_block_number = chain_info.best_block_number; + self.last_sent_block_number = chain_info.best_block_number; } // t_nb 11.4.4 Distribute valid proposed blocks to subset of current peers. (if there is any proposed) - pub fn propagate_proposed_blocks( - sync: &mut ChainSync, - io: &mut dyn SyncIo, - proposed: &[Bytes], - ) { - let peers = sync.get_consensus_peers(); + pub fn propagate_proposed_blocks(&mut self, io: &mut dyn SyncIo, proposed: &[Bytes]) { + let peers = self.get_consensus_peers(); trace!(target: "sync", "Sending proposed blocks to {:?}", peers); for block in proposed { let rlp = ChainSync::create_block_rlp(block, io.chain().chain_info().total_difficulty); for peer_id in &peers { - SyncPropagator::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); + ChainSync::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); } } } /// Broadcast consensus message to peers. - pub fn propagate_consensus_packet(sync: &mut ChainSync, io: &mut dyn SyncIo, packet: Bytes) { - let lucky_peers = ChainSync::select_random_peers(&sync.get_consensus_peers()); + pub fn propagate_consensus_packet(&self, io: &mut dyn SyncIo, packet: Bytes) { + let lucky_peers = ChainSync::select_random_peers(&self.get_consensus_peers()); trace!(target: "sync", "Sending consensus packet to {:?}", lucky_peers); for peer_id in lucky_peers { - SyncPropagator::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); + ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); } } - pub fn send_consensus_packet( - _sync: &mut ChainSync, - io: &mut dyn SyncIo, - packet: Bytes, - peer_id: usize, - ) { - SyncPropagator::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); + pub fn send_consensus_packet(&self, io: &mut dyn SyncIo, packet: Bytes, peer_id: usize) { + ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); } - fn select_peers_for_transactions(sync: &ChainSync, filter: F, are_new: bool) -> Vec + fn select_peers_for_transactions(&self, filter: F, are_new: bool) -> Vec where F: Fn(&PeerId) -> bool, { @@ -348,12 +375,12 @@ impl SyncPropagator { let mut random = random::new(); // sqrt(x)/x scaled to max u32 let fraction = - ((sync.peers.len() as f64).powf(-0.5) * (u32::max_value() as f64).round()) as u32; - let small = sync.peers.len() < MIN_PEERS_PROPAGATION; + ((self.peers.len() as f64).powf(-0.5) * (u32::max_value() as f64).round()) as u32; + let small = self.peers.len() < MIN_PEERS_PROPAGATION; Box::new(move |_| small || random.next_u32() < fraction) }; - sync.peers + self.peers .keys() .cloned() .filter(filter) @@ -369,6 +396,11 @@ impl SyncPropagator { packet_id: SyncPacket, packet: Bytes, ) { + // if let Some(session) = sync.peer_session_info(peer_id) { + + // session.remote_address + // } + if let Err(e) = sync.send(peer_id, packet_id, packet) { debug!(target:"sync", "Error sending packet: {:?}", e); sync.disconnect_peer(peer_id); @@ -377,7 +409,7 @@ impl SyncPropagator { /// propagates new transactions to all peers fn propagate_transactions<'a, F, G>( - sync: &mut ChainSync, + &mut self, io: &mut dyn SyncIo, get_transactions: G, are_new: bool, @@ -388,7 +420,7 @@ impl SyncPropagator { G: Fn(&dyn SyncIo) -> Vec>, { // Early out if nobody to send to. - if sync.peers.is_empty() { + if self.peers.is_empty() { return 0; } @@ -409,9 +441,8 @@ impl SyncPropagator { // usual transactions could be propagated to all peers let mut affected_peers = HashSet::new(); if !transactions.is_empty() { - let peers = SyncPropagator::select_peers_for_transactions(sync, |_| true, are_new); - affected_peers = SyncPropagator::propagate_transactions_to_peers( - sync, + let peers = ChainSync::select_peers_for_transactions(self, |_| true, are_new); + affected_peers = self.propagate_transactions_to_peers( io, peers, transactions, @@ -421,22 +452,19 @@ impl SyncPropagator { } // most of times service_transactions will be empty - // => there's no need to merge packets + // => we still need to merge packets if !service_transactions.is_empty() { - let service_transactions_peers = SyncPropagator::select_peers_for_transactions( - sync, + let service_transactions_peers = self.select_peers_for_transactions( |peer_id| io.peer_version(*peer_id).accepts_service_transaction(), are_new, ); - let service_transactions_affected_peers = - SyncPropagator::propagate_transactions_to_peers( - sync, - io, - service_transactions_peers, - service_transactions, - are_new, - &mut should_continue, - ); + let service_transactions_affected_peers = self.propagate_transactions_to_peers( + io, + service_transactions_peers, + service_transactions, + are_new, + &mut should_continue, + ); affected_peers.extend(&service_transactions_affected_peers); } @@ -470,8 +498,7 @@ mod tests { let mut io = TestIo::new(&mut client, &ss, &queue, None); let peers = sync.get_lagging_peers(&chain_info); - let peer_count = - SyncPropagator::propagate_new_hashes(&mut sync, &chain_info, &mut io, &peers); + let peer_count = sync.propagate_new_hashes(&chain_info, &mut io, &peers); // 1 message should be send assert_eq!(1, io.packets.len()); @@ -491,8 +518,7 @@ mod tests { let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); let peers = sync.get_lagging_peers(&chain_info); - let peer_count = - SyncPropagator::propagate_blocks(&mut sync, &chain_info, &mut io, &[], &peers); + let peer_count = sync.propagate_blocks(&chain_info, &mut io, &[], &peers); // 1 message should be send assert_eq!(1, io.packets.len()); @@ -513,13 +539,7 @@ mod tests { let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); let peers = sync.get_lagging_peers(&chain_info); - let peer_count = SyncPropagator::propagate_blocks( - &mut sync, - &chain_info, - &mut io, - &[hash.clone()], - &peers, - ); + let peer_count = sync.propagate_blocks(&chain_info, &mut io, &[hash.clone()], &peers); // 1 message should be send assert_eq!(1, io.packets.len()); @@ -563,7 +583,7 @@ mod tests { ); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - SyncPropagator::propagate_proposed_blocks(&mut sync, &mut io, &[block]); + sync.propagate_proposed_blocks(&mut sync, &mut io, &[block]); // 1 message should be sent assert_eq!(1, io.packets.len()); @@ -580,13 +600,13 @@ mod tests { let queue = RwLock::new(VecDeque::new()); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - let peer_count = SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + let peer_count = sync.propagate_ready_transactions(&mut io, || true); // Try to propagate same transactions for the second time - let peer_count2 = SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + let peer_count2 = sync.propagate_ready_transactions(&mut io, || true); // Even after new block transactions should not be propagated twice sync.chain_new_blocks(&mut io, &[], &[], &[], &[], &[], &[]); // Try to propagate same transactions for the third time - let peer_count3 = SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + let peer_count3 = sync.propagate_ready_transactions(&mut io, || true); // 1 message should be send assert_eq!(1, io.packets.len()); @@ -610,7 +630,7 @@ mod tests { let queue = RwLock::new(VecDeque::new()); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - let peer_count = SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + let peer_count = sync.propagate_ready_transactions(&mut io, || true); // Currently random implementation for test returns 8 peers as result of peers selection. assert_eq!(8, peer_count); @@ -631,8 +651,7 @@ mod tests { let queue = RwLock::new(VecDeque::new()); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - let peer_count = - SyncPropagator::propagate_new_transactions(&mut sync, &mut io, vec![tx_hash], || true); + let peer_count = sync.propagate_new_transactions(&mut io, vec![tx_hash], || true); assert_eq!(25, peer_count); } @@ -653,16 +672,13 @@ mod tests { let queue = RwLock::new(VecDeque::new()); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - let peer_count = - SyncPropagator::propagate_new_transactions(&mut sync, &mut io, vec![tx_hash], || true); + let peer_count = sync.propagate_new_transactions(&mut io, vec![tx_hash], || true); // Try to propagate same transactions for the second time - let peer_count2 = - SyncPropagator::propagate_new_transactions(&mut sync, &mut io, vec![tx_hash], || true); + let peer_count2 = sync.propagate_new_transactions(&mut io, vec![tx_hash], || true); // Even after new block transactions should not be propagated twice sync.chain_new_blocks(&mut io, &[], &[], &[], &[], &[], &[]); // Try to propagate same transactions for the third time - let peer_count3 = - SyncPropagator::propagate_new_transactions(&mut sync, &mut io, vec![tx_hash], || true); + let peer_count3 = sync.propagate_new_transactions(&mut io, vec![tx_hash], || true); // 1 message should be send assert_eq!(1, io.packets.len()); @@ -683,7 +699,7 @@ mod tests { let queue = RwLock::new(VecDeque::new()); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - let peer_count = SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + let peer_count = sync.propagate_ready_transactions(&mut io, || true); io.chain.insert_transaction_to_queue(); // New block import should not trigger propagation. // (we only propagate on timeout) @@ -713,8 +729,7 @@ mod tests { let queue = RwLock::new(VecDeque::new()); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - let peer_count = - SyncPropagator::propagate_new_transactions(&mut sync, &mut io, vec![tx_hash], || true); + let peer_count = sync.propagate_new_transactions(&mut io, vec![tx_hash], || true); io.chain.insert_transaction_to_queue(); // New block import should not trigger propagation. // (we only propagate on timeout) @@ -741,14 +756,12 @@ mod tests { let queue = RwLock::new(VecDeque::new()); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - let peer_count = SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); - let peer_count_new = - SyncPropagator::propagate_new_transactions(&mut sync, &mut io, vec![tx_hash], || true); + let peer_count = sync.propagate_ready_transactions(&mut io, || true); + let peer_count_new = sync.propagate_new_transactions(&mut io, vec![tx_hash], || true); sync.chain_new_blocks(&mut io, &[], &[], &[], &[], &[], &[]); // Try to propagate same transactions for the second time - let peer_count2 = SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); - let peer_count_new2 = - SyncPropagator::propagate_new_transactions(&mut sync, &mut io, vec![tx_hash], || true); + let peer_count2 = sync.propagate_ready_transactions(&mut io, || true); + let peer_count_new2 = sync.propagate_new_transactions(&mut io, vec![tx_hash], || true); assert_eq!(0, io.packets.len()); assert_eq!(0, peer_count); @@ -768,8 +781,7 @@ mod tests { // should sent some { let mut io = TestIo::new(&mut client, &ss, &queue, None); - let peer_count = - SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + let peer_count = sync.propagate_ready_transactions(&mut io, || true); assert_eq!(1, io.packets.len()); assert_eq!(1, peer_count); } @@ -778,11 +790,9 @@ mod tests { let (peer_count2, peer_count3) = { let mut io = TestIo::new(&mut client, &ss, &queue, None); // Propagate new transactions - let peer_count2 = - SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + let peer_count2 = sync.propagate_ready_transactions(&mut io, || true); // And now the peer should have all transactions - let peer_count3 = - SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + let peer_count3 = sync.propagate_ready_transactions(&mut io, || true); (peer_count2, peer_count3) }; @@ -814,13 +824,13 @@ mod tests { { let mut io = TestIo::new(&mut client, &ss, &queue, None); - SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + sync.propagate_ready_transactions(&mut io, || true); } let tx_hash2 = client.insert_transaction_to_queue(); { let mut io = TestIo::new(&mut client, &ss, &queue, None); - SyncPropagator::propagate_new_transactions(&mut sync, &mut io, vec![tx_hash2], || true); + sync.propagate_new_transactions(&mut io, vec![tx_hash2], || true); } let stats = sync.pending_transactions_stats(); @@ -869,7 +879,7 @@ mod tests { .insert(3, "OpenEthereum/ABCDEFGH/v2.7.3/linux/rustc".to_owned()); // and new service transaction is propagated to peers - SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + sync.propagate_ready_transactions(&mut io, || true); // peer#2 && peer#3 are receiving service transaction assert!(io @@ -900,7 +910,7 @@ mod tests { .insert(1, "OpenEthereum/v2.6.0/linux/rustc".to_owned()); // and service + non-service transactions are propagated to peers - SyncPropagator::propagate_ready_transactions(&mut sync, &mut io, || true); + sync.propagate_ready_transactions(&mut io, || true); // two separate packets for peer are queued: // 1) with non-service-transaction @@ -948,8 +958,7 @@ mod tests { let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - let peer_count = - SyncPropagator::propagate_new_transactions(&mut sync, &mut io, vec![tx_hash], || true); + let peer_count = sync.propagate_new_transactions(&mut io, vec![tx_hash], || true); assert_eq!(1, io.packets.len()); assert_eq!(1, peer_count); diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs new file mode 100644 index 000000000..2e0831f73 --- /dev/null +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -0,0 +1,68 @@ +use std::{ + borrow::Cow, + collections::HashMap, + sync::atomic::{AtomicBool, AtomicI64, Ordering}, +}; + +use parking_lot::Mutex; + +use crate::sync_io::SyncIo; + +use super::ChainSync; + +#[derive(Default)] +pub struct SyncPropagatorStatistics { + logging_enabled: AtomicBool, + propagated_blocks: AtomicI64, + propagated_blocks_bytes: AtomicI64, + + node_statistics: Mutex>, +} + +struct SyncPropagatorNodeStatistics { + address: String, + propagated_blocks: AtomicI64, + propagated_blocks_bytes: AtomicI64, +} + +impl SyncPropagatorStatistics { + pub fn new() -> Self { + SyncPropagatorStatistics { + logging_enabled: AtomicBool::new(true), + propagated_blocks: AtomicI64::new(0), + propagated_blocks_bytes: AtomicI64::new(0), + node_statistics: Mutex::new(HashMap::new()), + } + } + + pub fn logging_enabled(&self) -> bool { + return self.logging_enabled.load(Ordering::Relaxed); + } + + pub fn log_packet(&self, io: &mut dyn SyncIo, peer_id: usize, blocks: usize, bytes: usize) { + if self.logging_enabled() { + self.propagated_blocks + .fetch_add(blocks as i64, Ordering::Relaxed); + self.propagated_blocks_bytes + .fetch_add(bytes as i64, Ordering::Relaxed); + + if let Some(peer_info) = io.peer_session_info(peer_id) { + let mut node_statistics = self.node_statistics.lock(); + let node_statistics = node_statistics + .entry(peer_info.remote_address.clone()) + .or_insert_with(|| SyncPropagatorNodeStatistics { + address: peer_info.remote_address, + propagated_blocks: AtomicI64::new(0), + propagated_blocks_bytes: AtomicI64::new(0), + }); + + node_statistics + .propagated_blocks + .fetch_add(blocks as i64, Ordering::Relaxed); + node_statistics + .propagated_blocks_bytes + .fetch_add(bytes as i64, Ordering::Relaxed); + } + } + } +} From e99840c348bc4241ee5374b7fd60e790f9645b9f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 Feb 2025 23:35:20 +0100 Subject: [PATCH 334/687] github compile targets --- .github/workflows/compile-targets.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/compile-targets.yml diff --git a/.github/workflows/compile-targets.yml b/.github/workflows/compile-targets.yml new file mode 100644 index 000000000..945b6a5b0 --- /dev/null +++ b/.github/workflows/compile-targets.yml @@ -0,0 +1,24 @@ +name: Compile + +on: + pull_request: + push: + branches: + - main + - dev +jobs: + check: + name: Compile + runs-on: ubuntu-22.04 + steps: + - name: Checkout sources + uses: actions/checkout@main + with: + submodules: true + - name: Install rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.75 + profile: minimal + override: true + From 99995310b46c2f7af8656e1048dbca88ae16adaf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 05:47:18 +0100 Subject: [PATCH 335/687] Prometheus Metrics for SyncPropagatorStatistics --- crates/ethcore/sync/src/chain/mod.rs | 7 ++ crates/ethcore/sync/src/chain/propagator.rs | 7 +- .../sync/src/chain/propagator_statistics.rs | 104 ++++++++++++------ 3 files changed, 76 insertions(+), 42 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index dc9a2dfe5..729244d55 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -115,6 +115,7 @@ use parking_lot::{Mutex, RwLock, RwLockWriteGuard}; use rand::{seq::SliceRandom, Rng}; use rlp::{DecoderError, RlpStream}; use snapshot::Snapshot; +use stats::PrometheusMetrics; use std::{ cmp, collections::{BTreeMap, HashMap, HashSet}, @@ -1765,6 +1766,12 @@ impl ChainSync { } } +impl PrometheusMetrics for ChainSync { + fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { + self.statistics.prometheus_metrics(registry); + } +} + #[cfg(test)] pub mod tests { use super::{PeerAsking, PeerInfo, *}; diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index e16e28cb1..007727901 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -17,7 +17,6 @@ use std::{ cmp, collections::HashSet, - sync::atomic::{AtomicBool, AtomicI64, Ordering}, time::{Duration, Instant}, }; @@ -25,16 +24,12 @@ use bytes::Bytes; use ethereum_types::H256; use fastmap::H256FastSet; use network::{client_version::ClientCapabilities, PeerId}; -use parking_lot::{Mutex, RwLock}; use rand::RngCore; use rlp::RlpStream; use sync_io::SyncIo; use types::{blockchain_info::BlockChainInfo, transaction::SignedTransaction, BlockNumber}; -use super::{ - propagator_statistics::SyncPropagatorStatistics, - sync_packet::SyncPacket::{self, *}, -}; +use super::sync_packet::SyncPacket::{self, *}; use super::{ random, ChainSync, ETH_PROTOCOL_VERSION_65, MAX_PEERS_PROPAGATION, MAX_PEER_LAG_PROPAGATION, diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index 2e0831f73..0f81dbd8a 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -1,68 +1,100 @@ use std::{ - borrow::Cow, collections::HashMap, - sync::atomic::{AtomicBool, AtomicI64, Ordering}, + sync::atomic::{AtomicI64, Ordering}, }; -use parking_lot::Mutex; +use stats::PrometheusMetrics; use crate::sync_io::SyncIo; -use super::ChainSync; - #[derive(Default)] pub struct SyncPropagatorStatistics { - logging_enabled: AtomicBool, - propagated_blocks: AtomicI64, - propagated_blocks_bytes: AtomicI64, + logging_enabled: bool, + logging_peer_details_enabled: bool, + propagated_blocks: i64, + propagated_blocks_bytes: i64, - node_statistics: Mutex>, + node_statistics: HashMap, } struct SyncPropagatorNodeStatistics { address: String, - propagated_blocks: AtomicI64, - propagated_blocks_bytes: AtomicI64, + propagated_blocks: i64, + propagated_blocks_bytes: i64, } impl SyncPropagatorStatistics { pub fn new() -> Self { SyncPropagatorStatistics { - logging_enabled: AtomicBool::new(true), - propagated_blocks: AtomicI64::new(0), - propagated_blocks_bytes: AtomicI64::new(0), - node_statistics: Mutex::new(HashMap::new()), + logging_enabled: true, + logging_peer_details_enabled: true, + propagated_blocks: 0, + propagated_blocks_bytes: 0, + node_statistics: HashMap::new(), } } pub fn logging_enabled(&self) -> bool { - return self.logging_enabled.load(Ordering::Relaxed); + return self.logging_enabled; } - pub fn log_packet(&self, io: &mut dyn SyncIo, peer_id: usize, blocks: usize, bytes: usize) { + pub fn log_packet(&mut self, io: &mut dyn SyncIo, peer_id: usize, blocks: usize, bytes: usize) { if self.logging_enabled() { - self.propagated_blocks - .fetch_add(blocks as i64, Ordering::Relaxed); - self.propagated_blocks_bytes - .fetch_add(bytes as i64, Ordering::Relaxed); + self.propagated_blocks += blocks as i64; + self.propagated_blocks_bytes += bytes as i64; + + if self.logging_peer_details_enabled { + if let Some(peer_info) = io.peer_session_info(peer_id) { + //let mut node_statistics = &self.node_statistics; + let node_statistics = self + .node_statistics + .entry(peer_info.remote_address.clone()) + .or_insert_with(|| SyncPropagatorNodeStatistics { + address: peer_info.remote_address, + propagated_blocks: 0, + propagated_blocks_bytes: 0, + }); - if let Some(peer_info) = io.peer_session_info(peer_id) { - let mut node_statistics = self.node_statistics.lock(); - let node_statistics = node_statistics - .entry(peer_info.remote_address.clone()) - .or_insert_with(|| SyncPropagatorNodeStatistics { - address: peer_info.remote_address, - propagated_blocks: AtomicI64::new(0), - propagated_blocks_bytes: AtomicI64::new(0), - }); + node_statistics + .propagated_blocks += blocks as i64; - node_statistics - .propagated_blocks - .fetch_add(blocks as i64, Ordering::Relaxed); - node_statistics - .propagated_blocks_bytes - .fetch_add(bytes as i64, Ordering::Relaxed); + node_statistics + .propagated_blocks_bytes += bytes as i64; + } } } } } + +impl PrometheusMetrics for SyncPropagatorStatistics { + fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { + registry.register_counter( + "p2p_propagated_blocks", + "blocks sent", + self.propagated_blocks, + ); + registry.register_counter( + "p2p_propagated_blocks_bytes", + "block byte sent", + self.propagated_blocks_bytes, + ); + //registry.register_counter("p2p_propagated_blocks", "", self.propagated_blocks_bytes.load(Ordering::Relaxed)); + + self.node_statistics + .iter() + .for_each(|(address, node_statistics)| { + registry.register_gauge_with_other_node_label( + "p2p_propagated_blocks_peer", + "# blocks to peer", + &node_statistics.address, + node_statistics.propagated_blocks, + ); + registry.register_gauge_with_other_node_label( + "p2p_propagated_bytes_peer", + "bytes to peer", + &node_statistics.address, + node_statistics.propagated_blocks_bytes, + ); + }); + } +} From 652ca7d4ecee615b14aa4e299436e33fc51dcfac Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 06:01:46 +0100 Subject: [PATCH 336/687] compile fix in test, fixed unused import warnings. --- crates/ethcore/sync/src/chain/propagator.rs | 2 +- crates/ethcore/sync/src/chain/propagator_statistics.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 007727901..003906ae6 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -578,7 +578,7 @@ mod tests { ); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); - sync.propagate_proposed_blocks(&mut sync, &mut io, &[block]); + sync.propagate_proposed_blocks(&mut io, &[block]); // 1 message should be sent assert_eq!(1, io.packets.len()); diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index 0f81dbd8a..32d83b9fd 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -1,6 +1,5 @@ use std::{ collections::HashMap, - sync::atomic::{AtomicI64, Ordering}, }; use stats::PrometheusMetrics; From 1d7a83c45e42df1f3df8793eaa91324ed90ae366 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 06:02:07 +0100 Subject: [PATCH 337/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/sync/src/chain/propagator_statistics.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index 32d83b9fd..d7cccabf6 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -1,6 +1,4 @@ -use std::{ - collections::HashMap, -}; +use std::collections::HashMap; use stats::PrometheusMetrics; @@ -54,11 +52,9 @@ impl SyncPropagatorStatistics { propagated_blocks_bytes: 0, }); - node_statistics - .propagated_blocks += blocks as i64; + node_statistics.propagated_blocks += blocks as i64; - node_statistics - .propagated_blocks_bytes += bytes as i64; + node_statistics.propagated_blocks_bytes += bytes as i64; } } } From a613abd65aee2ea279367493dbe5be20d7ac9cbf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 10:00:35 +0100 Subject: [PATCH 338/687] - test fixes - visibility optimization --- crates/ethcore/sync/src/chain/mod.rs | 4 ++-- crates/ethcore/sync/src/chain/propagator.rs | 18 +++++++++--------- .../sync/src/chain/propagator_statistics.rs | 2 +- crates/ethcore/sync/src/tests/helpers.rs | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 729244d55..ec9d65cd4 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1973,7 +1973,7 @@ pub mod tests { let mut io = TestIo::new(&mut client, &ss, &queue, None); let peers = sync.get_lagging_peers(&chain_info); - SyncPropagator::propagate_new_hashes(&mut sync, &chain_info, &mut io, &peers); + sync.propagate_new_hashes(&chain_info, &mut io, &peers); let data = &io.packets[0].data.clone(); let result = SyncHandler::on_peer_new_hashes(&mut sync, &mut io, 0, &Rlp::new(data)); @@ -1993,7 +1993,7 @@ pub mod tests { let mut io = TestIo::new(&mut client, &ss, &queue, None); let peers = sync.get_lagging_peers(&chain_info); - SyncPropagator::propagate_blocks(&mut sync, &chain_info, &mut io, &[], &peers); + sync.propagate_blocks(&chain_info, &mut io, &[], &peers); let data = &io.packets[0].data.clone(); let result = SyncHandler::on_peer_new_block(&mut sync, &mut io, 0, &Rlp::new(data)); diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 003906ae6..0a45b1116 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -56,7 +56,7 @@ impl ChainSync { // } // t_nb 11.4.3 propagates latest block to a set of peers - fn propagate_blocks( + pub(crate) fn propagate_blocks( &mut self, chain_info: &BlockChainInfo, io: &mut dyn SyncIo, @@ -92,7 +92,7 @@ impl ChainSync { } // t_nb 11.4.2 propagates new known hashes to all peers - fn propagate_new_hashes( + pub(crate) fn propagate_new_hashes( &mut self, chain_info: &BlockChainInfo, io: &mut dyn SyncIo, @@ -118,7 +118,7 @@ impl ChainSync { } /// propagates new transactions to all peers - pub fn propagate_new_ready_transactions(&mut self, io: &mut dyn SyncIo) { + pub(crate) fn propagate_new_ready_transactions(&mut self, io: &mut dyn SyncIo) { let deadline = Instant::now() + Duration::from_millis(500); self.propagate_ready_transactions(io, || { @@ -132,7 +132,7 @@ impl ChainSync { } /// propagates new transactions to all peers - pub fn propagate_new_transactions bool>( + pub(crate) fn propagate_new_transactions bool>( &mut self, io: &mut dyn SyncIo, tx_hashes: Vec, @@ -306,7 +306,7 @@ impl ChainSync { } // t_nb 11.4.1 propagate latest blocks to peers - pub fn propagate_latest_blocks<'a>(&mut self, io: &mut dyn SyncIo, sealed: &[H256]) { + pub(crate) fn propagate_latest_blocks<'a>(&mut self, io: &mut dyn SyncIo, sealed: &[H256]) { let chain_info = io.chain().chain_info(); if (((chain_info.best_block_number as i64) - (self.last_sent_block_number as i64)).abs() as BlockNumber) @@ -334,7 +334,7 @@ impl ChainSync { } // t_nb 11.4.4 Distribute valid proposed blocks to subset of current peers. (if there is any proposed) - pub fn propagate_proposed_blocks(&mut self, io: &mut dyn SyncIo, proposed: &[Bytes]) { + pub(crate) fn propagate_proposed_blocks(&mut self, io: &mut dyn SyncIo, proposed: &[Bytes]) { let peers = self.get_consensus_peers(); trace!(target: "sync", "Sending proposed blocks to {:?}", peers); for block in proposed { @@ -346,7 +346,7 @@ impl ChainSync { } /// Broadcast consensus message to peers. - pub fn propagate_consensus_packet(&self, io: &mut dyn SyncIo, packet: Bytes) { + pub(crate) fn propagate_consensus_packet(&self, io: &mut dyn SyncIo, packet: Bytes) { let lucky_peers = ChainSync::select_random_peers(&self.get_consensus_peers()); trace!(target: "sync", "Sending consensus packet to {:?}", lucky_peers); for peer_id in lucky_peers { @@ -354,7 +354,7 @@ impl ChainSync { } } - pub fn send_consensus_packet(&self, io: &mut dyn SyncIo, packet: Bytes, peer_id: usize) { + pub(crate) fn send_consensus_packet(&self, io: &mut dyn SyncIo, packet: Bytes, peer_id: usize) { ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); } @@ -385,7 +385,7 @@ impl ChainSync { } /// Generic packet sender - pub fn send_packet( + pub(crate) fn send_packet( sync: &mut dyn SyncIo, peer_id: PeerId, packet_id: SyncPacket, diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index d7cccabf6..050a2b2a8 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -77,7 +77,7 @@ impl PrometheusMetrics for SyncPropagatorStatistics { self.node_statistics .iter() - .for_each(|(address, node_statistics)| { + .for_each(|(_, node_statistics)| { registry.register_gauge_with_other_node_label( "p2p_propagated_blocks_peer", "# blocks to peer", diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index 79ef780f0..b4a881a63 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -342,7 +342,7 @@ impl Peer for EthPeer { self.sync.write().maintain_peers(&mut io); self.sync.write().maintain_sync(&mut io); self.sync.write().continue_sync(&mut io); - self.sync.write().propagate_new_transactions(&mut io); + self.sync.write().propagate_new_ready_transactions(&mut io); } fn restart_sync(&self) { From 9c0c099ac8543bb14f931efa8be367a67b6fdaf7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 11:30:27 +0100 Subject: [PATCH 339/687] propagator: added consensus bytes sent and consensus packages sent --- crates/ethcore/sync/src/chain/propagator.rs | 10 ++++-- .../sync/src/chain/propagator_statistics.rs | 33 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 0a45b1116..5c8f50b02 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -68,7 +68,7 @@ impl ChainSync { let mut send_packet = |io: &mut dyn SyncIo, rlp: Bytes| { for peer_id in peers { self.statistics - .log_packet(io, *peer_id, blocks.len(), rlp.len()); + .log_propagated_block(io, *peer_id, blocks.len(), rlp.len()); ChainSync::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); @@ -354,7 +354,13 @@ impl ChainSync { } } - pub(crate) fn send_consensus_packet(&self, io: &mut dyn SyncIo, packet: Bytes, peer_id: usize) { + pub(crate) fn send_consensus_packet( + &mut self, + io: &mut dyn SyncIo, + packet: Bytes, + peer_id: usize, + ) { + self.statistics.log_consensus(io, peer_id, packet.len()); ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); } diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index 050a2b2a8..f7a367fa8 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -11,6 +11,9 @@ pub struct SyncPropagatorStatistics { propagated_blocks: i64, propagated_blocks_bytes: i64, + consensus_bytes: i64, + consensus_packages: i64, + node_statistics: HashMap, } @@ -27,6 +30,8 @@ impl SyncPropagatorStatistics { logging_peer_details_enabled: true, propagated_blocks: 0, propagated_blocks_bytes: 0, + consensus_bytes: 0, + consensus_packages: 0, node_statistics: HashMap::new(), } } @@ -35,7 +40,13 @@ impl SyncPropagatorStatistics { return self.logging_enabled; } - pub fn log_packet(&mut self, io: &mut dyn SyncIo, peer_id: usize, blocks: usize, bytes: usize) { + pub fn log_propagated_block( + &mut self, + io: &mut dyn SyncIo, + peer_id: usize, + blocks: usize, + bytes: usize, + ) { if self.logging_enabled() { self.propagated_blocks += blocks as i64; self.propagated_blocks_bytes += bytes as i64; @@ -59,6 +70,13 @@ impl SyncPropagatorStatistics { } } } + + pub(crate) fn log_consensus(&mut self, io: &mut dyn SyncIo, _peer_id: usize, bytelen: usize) { + if self.logging_peer_details_enabled { + self.consensus_bytes += bytelen as i64; + self.consensus_packages += 1; + } + } } impl PrometheusMetrics for SyncPropagatorStatistics { @@ -73,6 +91,19 @@ impl PrometheusMetrics for SyncPropagatorStatistics { "block byte sent", self.propagated_blocks_bytes, ); + + registry.register_counter( + "p2p_cons_bytes", + "consensus bytes sent", + self.consensus_bytes, + ); + + registry.register_counter( + "p2p_cons_package", + "consensus packages sent", + self.consensus_packages, + ); + //registry.register_counter("p2p_propagated_blocks", "", self.propagated_blocks_bytes.load(Ordering::Relaxed)); self.node_statistics From c423754ab20d0039797b089c08957a7a7bf77ded Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 13:17:20 +0100 Subject: [PATCH 340/687] prometheus stats: broadcasted consensus bytes --- crates/ethcore/sync/src/chain/propagator.rs | 5 +++- .../sync/src/chain/propagator_statistics.rs | 30 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 5c8f50b02..c0a1ebe45 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -346,9 +346,12 @@ impl ChainSync { } /// Broadcast consensus message to peers. - pub(crate) fn propagate_consensus_packet(&self, io: &mut dyn SyncIo, packet: Bytes) { + pub(crate) fn propagate_consensus_packet(&mut self, io: &mut dyn SyncIo, packet: Bytes) { let lucky_peers = ChainSync::select_random_peers(&self.get_consensus_peers()); trace!(target: "sync", "Sending consensus packet to {:?}", lucky_peers); + + self.statistics + .log_consensus_broadcast(lucky_peers.len(), packet.len()); for peer_id in lucky_peers { ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); } diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index f7a367fa8..db913ee7f 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -14,6 +14,9 @@ pub struct SyncPropagatorStatistics { consensus_bytes: i64, consensus_packages: i64, + consensus_broadcast_bytes: i64, + consensus_broadcast_packages: i64, + node_statistics: HashMap, } @@ -28,11 +31,7 @@ impl SyncPropagatorStatistics { SyncPropagatorStatistics { logging_enabled: true, logging_peer_details_enabled: true, - propagated_blocks: 0, - propagated_blocks_bytes: 0, - consensus_bytes: 0, - consensus_packages: 0, - node_statistics: HashMap::new(), + ..Default::default() } } @@ -72,11 +71,18 @@ impl SyncPropagatorStatistics { } pub(crate) fn log_consensus(&mut self, io: &mut dyn SyncIo, _peer_id: usize, bytelen: usize) { - if self.logging_peer_details_enabled { + if self.logging_enabled { self.consensus_bytes += bytelen as i64; self.consensus_packages += 1; } } + + pub(crate) fn log_consensus_broadcast(&mut self, num_peers: usize, bytes_len: usize) { + if self.logging_enabled { + self.consensus_broadcast_bytes += (bytes_len * num_peers) as i64; + self.consensus_broadcast_packages += num_peers as i64; + } + } } impl PrometheusMetrics for SyncPropagatorStatistics { @@ -104,6 +110,18 @@ impl PrometheusMetrics for SyncPropagatorStatistics { self.consensus_packages, ); + registry.register_counter( + "p2p_cons_broadcast_bytes", + "consensus bytes broadcasted", + self.consensus_broadcast_bytes, + ); + + registry.register_counter( + "p2p_cons_broadcast_packages", + "total number consensus packages send through broadcast", + self.consensus_broadcast_packages, + ); + //registry.register_counter("p2p_propagated_blocks", "", self.propagated_blocks_bytes.load(Ordering::Relaxed)); self.node_statistics From ec0779db7c88eba8d1f25c424d8ac248a8712524 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 13:22:10 +0100 Subject: [PATCH 341/687] Notes for https://github.com/DMDcoin/diamond-node/issues/61 --- crates/ethcore/sync/src/chain/propagator.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index c0a1ebe45..f112efdbf 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -338,6 +338,10 @@ impl ChainSync { let peers = self.get_consensus_peers(); trace!(target: "sync", "Sending proposed blocks to {:?}", peers); for block in proposed { + // todo: sometimes we get at the receiving end blocks, with missmatching total difficulty, + // so we ignore those blocks on import. + // might that be the case if we are sending more than 1 block here ? + // more about: https://github.com/DMDcoin/diamond-node/issues/61 let rlp = ChainSync::create_block_rlp(block, io.chain().chain_info().total_difficulty); for peer_id in &peers { ChainSync::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); From f32d2ffbadf6640cd0163a5f15a1a6a14c7bb7d3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 13:24:18 +0100 Subject: [PATCH 342/687] removed requirement for IO for log_consensus, atm we do not log detailed node information. --- crates/ethcore/sync/src/chain/propagator.rs | 2 +- crates/ethcore/sync/src/chain/propagator_statistics.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index f112efdbf..3daa61ecd 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -367,7 +367,7 @@ impl ChainSync { packet: Bytes, peer_id: usize, ) { - self.statistics.log_consensus(io, peer_id, packet.len()); + self.statistics.log_consensus(peer_id, packet.len()); ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); } diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index db913ee7f..5510a3ed9 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -70,7 +70,7 @@ impl SyncPropagatorStatistics { } } - pub(crate) fn log_consensus(&mut self, io: &mut dyn SyncIo, _peer_id: usize, bytelen: usize) { + pub(crate) fn log_consensus(&mut self, _peer_id: usize, bytelen: usize) { if self.logging_enabled { self.consensus_bytes += bytelen as i64; self.consensus_packages += 1; From 3c4a26f905d5a00220ed39bda7a89a11fa953672 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 13:57:17 +0100 Subject: [PATCH 343/687] prometheus metrics: consensus_message_cache + prmetheus registration for latest added p2p metrics. --- crates/ethcore/sync/src/api.rs | 17 +++++++++++++++++ crates/ethcore/sync/src/chain/mod.rs | 12 ++++++++++++ crates/ethcore/sync/src/chain/propagator.rs | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 318a9fbc4..1177e05a7 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -448,6 +448,8 @@ impl PrometheusMetrics for EthSync { manifest_block_num as i64, ); + self.eth_handler.prometheus_metrics(r); + self.network.prometheus_metrics(r); } } @@ -520,6 +522,21 @@ impl SyncProtocolHandler { } } +impl PrometheusMetrics for SyncProtocolHandler { + fn prometheus_metrics(&self, r: &mut PrometheusRegistry) { + if let Some(cache) = self.message_cache.try_read_for(Duration::from_millis(50)) { + let sum = cache.iter().map(|(_, v)| v.len()).sum::(); + r.register_gauge( + "consensus_message_cache", + "Number of cached consensus messages", + sum as i64, + ); + } + + self.sync.prometheus_metrics(r); + } +} + impl NetworkProtocolHandler for SyncProtocolHandler { fn initialize(&self, io: &dyn NetworkContext) { if io.subprotocol_name() != PAR_PROTOCOL { diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index ec9d65cd4..3880d8b82 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1766,6 +1766,18 @@ impl ChainSync { } } +impl PrometheusMetrics for ChainSyncApi { + fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { + // unfortunatly, Sync is holding the lock for quite some time, + // due its poor degree of parallism. + // since most of the metrics are counter, it should not involve a huge problem + // we are still trying to get the lock only for 50ms here... + if let Some(sync) = self.sync.try_read_for(Duration::from_millis(50)) { + sync.prometheus_metrics(registry); + } + } +} + impl PrometheusMetrics for ChainSync { fn prometheus_metrics(&self, registry: &mut stats::PrometheusRegistry) { self.statistics.prometheus_metrics(registry); diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 3daa61ecd..cab2ad8cd 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -339,7 +339,7 @@ impl ChainSync { trace!(target: "sync", "Sending proposed blocks to {:?}", peers); for block in proposed { // todo: sometimes we get at the receiving end blocks, with missmatching total difficulty, - // so we ignore those blocks on import. + // so we ignore those blocks on import. // might that be the case if we are sending more than 1 block here ? // more about: https://github.com/DMDcoin/diamond-node/issues/61 let rlp = ChainSync::create_block_rlp(block, io.chain().chain_info().total_difficulty); From 9c495d6b57b739c4cdd9054beec20285f7dbeb80 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 17:55:00 +0100 Subject: [PATCH 344/687] Prometheus: p2p_propagated_txs, p2p_propagated_hashes + bytes version of it. --- crates/ethcore/sync/src/chain/propagator.rs | 28 +++++++++++- .../sync/src/chain/propagator_statistics.rs | 44 ++++++++++++++++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index cab2ad8cd..d5d3009b9 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -29,6 +29,8 @@ use rlp::RlpStream; use sync_io::SyncIo; use types::{blockchain_info::BlockChainInfo, transaction::SignedTransaction, BlockNumber}; +use crate::chain::propagator_statistics::SyncPropagatorStatistics; + use super::sync_packet::SyncPacket::{self, *}; use super::{ @@ -189,11 +191,19 @@ impl ChainSync { } let send_packet = |io: &mut dyn SyncIo, + stats: &mut SyncPropagatorStatistics, peer_id: PeerId, is_hashes: bool, sent: usize, rlp: Bytes| { let size = rlp.len(); + + if is_hashes { + stats.log_propagated_hashes(sent, size); + } else { + stats.log_propagated_transactions(sent, size); + } + ChainSync::send_packet( io, peer_id, @@ -239,7 +249,14 @@ impl ChainSync { all_transactions_rlp.clone() } }; - send_packet(io, peer_id, is_hashes, all_transactions_hashes.len(), rlp); + send_packet( + io, + &mut self.statistics, + peer_id, + is_hashes, + all_transactions_hashes.len(), + rlp, + ); sent_to_peers.insert(peer_id); max_sent = cmp::max(max_sent, all_transactions_hashes.len()); continue; @@ -296,7 +313,14 @@ impl ChainSync { .chain(&to_send) .cloned() .collect(); - send_packet(io, peer_id, is_hashes, to_send.len(), packet.out()); + send_packet( + io, + &mut self.statistics, + peer_id, + is_hashes, + to_send.len(), + packet.out(), + ); sent_to_peers.insert(peer_id); max_sent = cmp::max(max_sent, to_send.len()); } diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index 5510a3ed9..cfcb422c2 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -17,6 +17,12 @@ pub struct SyncPropagatorStatistics { consensus_broadcast_bytes: i64, consensus_broadcast_packages: i64, + transactions_propagated: i64, + transactions_propagated_bytes: i64, + + transaction_hashes_propagated: i64, + transaction_hashes_propagated_bytes: i64, + node_statistics: HashMap, } @@ -83,6 +89,20 @@ impl SyncPropagatorStatistics { self.consensus_broadcast_packages += num_peers as i64; } } + + pub(crate) fn log_propagated_hashes(&mut self, sent: usize, size: usize) { + if self.logging_enabled { + self.transaction_hashes_propagated += sent as i64; + self.transaction_hashes_propagated_bytes += size as i64; + } + } + + pub(crate) fn log_propagated_transactions(&mut self, sent: usize, size: usize) { + if self.logging_enabled { + self.transactions_propagated += sent as i64; + self.transactions_propagated_bytes += size as i64; + } + } } impl PrometheusMetrics for SyncPropagatorStatistics { @@ -122,7 +142,29 @@ impl PrometheusMetrics for SyncPropagatorStatistics { self.consensus_broadcast_packages, ); - //registry.register_counter("p2p_propagated_blocks", "", self.propagated_blocks_bytes.load(Ordering::Relaxed)); + registry.register_counter( + "p2p_propagated_txs", + "transactions propagated", + self.transactions_propagated, + ); + + registry.register_counter( + "p2p_propagated_txs_bytes", + "transactions propagated (byte size)", + self.transactions_propagated_bytes, + ); + + registry.register_counter( + "p2p_propagated_hashes", + "transaction hashes propagated", + self.transaction_hashes_propagated, + ); + + registry.register_counter( + "p2p_propagated_hashes_bytes", + "transaction hashes propagated (byte size)", + self.transaction_hashes_propagated_bytes, + ); self.node_statistics .iter() From 5b326c8ba5bf385326fd10add7a6245b0f8a9920 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 28 Feb 2025 17:58:14 +0100 Subject: [PATCH 345/687] print and do reserved peer removal only if there are peers to remove. --- .../engines/hbbft/hbbft_peers_management.rs | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 2bc56f91b..1c3882469 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -208,32 +208,34 @@ impl HbbftPeersManagement { } } - info!("removing {} reserved peers, because they are neither a pending validator nor a current validator.", validators_to_remove.len()); + if validators_to_remove.len() > 0 { + info!("removing {} reserved peers, because they are neither a pending validator nor a current validator.", validators_to_remove.len()); - let mut peers_management_guard = block_chain_client.reserved_peers_management().lock(); + let mut peers_management_guard = block_chain_client.reserved_peers_management().lock(); - if let Some(peers_management) = peers_management_guard.as_deref_mut() { - for current_validator in self.connected_current_validators.iter() { - if validators_to_remove.contains(¤t_validator.mining_address) { - match peers_management.remove_reserved_peer(¤t_validator.peer_string) { - Ok(_) => { - info!(target: "Engine", "removed reserved peer {}", current_validator.peer_string); - } - Err(error) => { - warn!(target: "Engine", "could not remove reserved peer {}: reason: {}", current_validator.peer_string, error); + if let Some(peers_management) = peers_management_guard.as_deref_mut() { + for current_validator in self.connected_current_validators.iter() { + if validators_to_remove.contains(¤t_validator.mining_address) { + match peers_management.remove_reserved_peer(¤t_validator.peer_string) + { + Ok(_) => { + info!(target: "Engine", "removed reserved peer {}", current_validator.peer_string); + } + Err(error) => { + warn!(target: "Engine", "could not remove reserved peer {}: reason: {}", current_validator.peer_string, error); + } } } } - } - peers_management - .get_reserved_peers() - .iter() - .for_each(|peer| { - info!(target: "Engine", "reserved peer: {}", peer); - }); + peers_management + .get_reserved_peers() + .iter() + .for_each(|peer| { + info!(target: "Engine", "reserved peer: {}", peer); + }); + } } - // we have now connected all additional current validators, kept the connection for those that have already been connected, // and we have disconnected all previous validators that are not current validators anymore. // so we now can set the information of collected validators. From 4004dc6e5aba790f0c816d4cbde3c630ac0b21de Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 2 Mar 2025 19:56:09 +0100 Subject: [PATCH 346/687] Implemented transaction shuffling using the random number provided by HBBFT --- crates/ethcore/src/engines/hbbft/utils/mod.rs | 1 + .../hbbft/utils/transactions_shuffling.rs | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs diff --git a/crates/ethcore/src/engines/hbbft/utils/mod.rs b/crates/ethcore/src/engines/hbbft/utils/mod.rs index 162024fd4..c545c13df 100644 --- a/crates/ethcore/src/engines/hbbft/utils/mod.rs +++ b/crates/ethcore/src/engines/hbbft/utils/mod.rs @@ -1 +1,2 @@ pub mod bound_contract; +mod transactions_shuffling; diff --git a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs new file mode 100644 index 000000000..b6b98826f --- /dev/null +++ b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs @@ -0,0 +1,86 @@ +// Warning: Part of the Consensus protocol, changes need to produce *exactly* the same result or +// block verification will fail. Intentional breaking changes constitute a fork. + +use std::collections::HashMap; +use ethereum_types::{Address, U256}; +use rand::prelude::SliceRandom; +use rand::thread_rng; +use types::transaction::SignedTransaction; + +/// Combining an address with a random U256 seed using XOR +fn U256_xor_address(address: &Address, seed: U256) -> u64 +{ + address.to_low_u64_ne() ^ seed.low_u64() +} + +/// transactions is expected to be free of duplicates. This is no guarantee that that transactions with the same nonce +/// but different content are present in the given transactions. There is also no guarantee the transactions are sorted +/// by nonce. +/// Avoid using implementations not under our control, avoid adding dependencies on crates or standard library functions +/// which may change in future versions. +/// The implementation needs to be both portable and deterministic.6 +fn deterministic_transactions_shuffling(transactions: Vec, seed: U256) -> Vec { + + // Group transactions by sender. + // * Walk the transactions from first to last + // * Add unique senders to a vector in the order they appear in the transactions list + // * Add transactions with unique nonce to a per-sender vector + // * Discard transactions with a nonce already existing in the list of transactions + let mut txs_by_sender: HashMap<_, Vec> = HashMap::new(); + for tx in transactions { + let sender = tx.sender(); + let entry = txs_by_sender.entry(sender).or_insert_with(Vec::new); + if entry.iter().any(|existing_tx| existing_tx.tx().nonce == tx.tx().nonce) { + // Duplicate nonce found, ignore this transaction. + continue; + } + entry.push(tx); + } + + // For each sender, sort their transactions by nonce (lowest first). + // Nonces are expected to be unique at this point, guaranteeing portable + // and deterministic results independent from the sorting algorithm as long as + // the sorting algorithm works and is implemented correctly. + for txs in txs_by_sender.values_mut() { + txs.sort_by_key(|tx| tx.tx().nonce); + } + + // Randomly shuffle the list of senders in the order they appear in the transactions list. + // Use a portable and deterministic random number generator where we control the exact implementation. + // * Seed the random number generator with the given seed value, identical for all validators + // * Use the random number generator to pick a sender in the unique sender list + // * Remove the sender from the sender list + // * Assure sender removal does not change the sequence of senders + // * Add the removed sender to a new list + // * Keep moving randomly selected senders until the original sender list is empty. + let mut senders: Vec<_> = txs_by_sender.keys().cloned().collect(); + senders.sort_by_key(|address| U256_xor_address(address, seed)); + + // Create the final transaction list by iterating over the randomly shuffled senders. + let mut final_transactions = Vec::new(); + for sender in senders { + if let Some(mut sender_txs) = txs_by_sender.remove(&sender) { + // Each sender's transactions are already sorted by nonce. + final_transactions.append(&mut sender_txs); + } + } + + final_transactions +} + +// Write a test function to test the address_xor_U256 function with known seeds and addresses and known XOR results +#[cfg(test)] +mod tests { + use super::*; + use ethereum_types::H160; + + #[test] + fn test_address_xor_U256() { + let address = H160::from_low_u64_ne(0x1234567890abcdefu64); + let address_u64 = address.to_low_u64_ne(); + let seed = U256::from(0x1234567890abcdefu64); + let seed_u64 = seed.low_u64(); + let result = U256_xor_address(&address, seed); + assert_eq!(result, 0x1234567890abcdef ^ 0x1234567890abcdef); + } +} \ No newline at end of file From e6bbcdc69b00c6335abfd8f6163b18d599735690 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 2 Mar 2025 21:01:18 +0100 Subject: [PATCH 347/687] Refactored to use the entire 20-byte Address for XOR and sorting --- .../hbbft/utils/transactions_shuffling.rs | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs index b6b98826f..31d63ab70 100644 --- a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs +++ b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs @@ -1,16 +1,27 @@ // Warning: Part of the Consensus protocol, changes need to produce *exactly* the same result or // block verification will fail. Intentional breaking changes constitute a fork. -use std::collections::HashMap; use ethereum_types::{Address, U256}; -use rand::prelude::SliceRandom; -use rand::thread_rng; +use std::collections::HashMap; use types::transaction::SignedTransaction; -/// Combining an address with a random U256 seed using XOR -fn U256_xor_address(address: &Address, seed: U256) -> u64 -{ - address.to_low_u64_ne() ^ seed.low_u64() +/// Combining an address with a random U256 seed using XOR, using big-endian byte ordering always. +fn address_xor_u256(address: &Address, seed: U256) -> Address { + // Address bytes are always assuming big-endian order. + let address_bytes = address.as_bytes(); + + // Explicitly convert U256 to big endian order + let mut seed_bytes = [0u8; 32]; + seed.to_big_endian(&mut seed_bytes); + + // Byte-wise XOR, constructing a new, big-endian array + let mut result = [0u8; 20]; + for i in 0..20 { + result[i] = address_bytes[i] ^ seed_bytes[i]; + } + + // Construct a new Address from the big-endian array + Address::from(result) } /// transactions is expected to be free of duplicates. This is no guarantee that that transactions with the same nonce @@ -19,8 +30,10 @@ fn U256_xor_address(address: &Address, seed: U256) -> u64 /// Avoid using implementations not under our control, avoid adding dependencies on crates or standard library functions /// which may change in future versions. /// The implementation needs to be both portable and deterministic.6 -fn deterministic_transactions_shuffling(transactions: Vec, seed: U256) -> Vec { - +fn deterministic_transactions_shuffling( + transactions: Vec, + seed: U256, +) -> Vec { // Group transactions by sender. // * Walk the transactions from first to last // * Add unique senders to a vector in the order they appear in the transactions list @@ -30,7 +43,10 @@ fn deterministic_transactions_shuffling(transactions: Vec, se for tx in transactions { let sender = tx.sender(); let entry = txs_by_sender.entry(sender).or_insert_with(Vec::new); - if entry.iter().any(|existing_tx| existing_tx.tx().nonce == tx.tx().nonce) { + if entry + .iter() + .any(|existing_tx| existing_tx.tx().nonce == tx.tx().nonce) + { // Duplicate nonce found, ignore this transaction. continue; } @@ -54,7 +70,7 @@ fn deterministic_transactions_shuffling(transactions: Vec, se // * Add the removed sender to a new list // * Keep moving randomly selected senders until the original sender list is empty. let mut senders: Vec<_> = txs_by_sender.keys().cloned().collect(); - senders.sort_by_key(|address| U256_xor_address(address, seed)); + senders.sort_by_key(|address| address_xor_u256(address, seed)); // Create the final transaction list by iterating over the randomly shuffled senders. let mut final_transactions = Vec::new(); @@ -68,19 +84,26 @@ fn deterministic_transactions_shuffling(transactions: Vec, se final_transactions } -// Write a test function to test the address_xor_U256 function with known seeds and addresses and known XOR results +// Write a test function to test the address_xor_u256 function with known seeds and addresses and known XOR results #[cfg(test)] mod tests { use super::*; - use ethereum_types::H160; + // Convert to bytes in big-endian order. + fn u64_to_32_bytes_be(n: u64) -> [u8; 32] { + let mut result = [0u8; 32]; + result[..8].copy_from_slice(&n.to_be_bytes()); + result + } #[test] - fn test_address_xor_U256() { - let address = H160::from_low_u64_ne(0x1234567890abcdefu64); - let address_u64 = address.to_low_u64_ne(); - let seed = U256::from(0x1234567890abcdefu64); - let seed_u64 = seed.low_u64(); - let result = U256_xor_address(&address, seed); - assert_eq!(result, 0x1234567890abcdef ^ 0x1234567890abcdef); + fn test_address_xor_u256() { + let value_as_bytes = u64_to_32_bytes_be(0x1234567890abcdefu64); + let address = Address::from_slice(&value_as_bytes[..20]); + let seed = U256::from_big_endian(&value_as_bytes); + let result = address_xor_u256(&address, seed); + assert_eq!( + result, + Address::from_slice(&u64_to_32_bytes_be(0x1234567890abcdef ^ 0x1234567890abcdef)[..20]) + ); } -} \ No newline at end of file +} From 0accd00b4419362629488eafbfa135b252772a98 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 2 Mar 2025 21:37:46 +0100 Subject: [PATCH 348/687] Reworked comments to be more concise and accurate --- .../hbbft/utils/transactions_shuffling.rs | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs index 31d63ab70..d8b5ab970 100644 --- a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs +++ b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs @@ -24,19 +24,18 @@ fn address_xor_u256(address: &Address, seed: U256) -> Address { Address::from(result) } -/// transactions is expected to be free of duplicates. This is no guarantee that that transactions with the same nonce -/// but different content are present in the given transactions. There is also no guarantee the transactions are sorted -/// by nonce. -/// Avoid using implementations not under our control, avoid adding dependencies on crates or standard library functions -/// which may change in future versions. -/// The implementation needs to be both portable and deterministic.6 +/// The list of transactions is expected to be free of duplicates. fn deterministic_transactions_shuffling( transactions: Vec, seed: U256, ) -> Vec { + // The implementation needs to be both portable and deterministic. + // There is no guarantee that the input list of transactions does not contain transactions + // with the same nonce but different content. + // There is also no guarantee the transactions are sorted by nonce. + // Group transactions by sender. // * Walk the transactions from first to last - // * Add unique senders to a vector in the order they appear in the transactions list // * Add transactions with unique nonce to a per-sender vector // * Discard transactions with a nonce already existing in the list of transactions let mut txs_by_sender: HashMap<_, Vec> = HashMap::new(); @@ -55,20 +54,19 @@ fn deterministic_transactions_shuffling( // For each sender, sort their transactions by nonce (lowest first). // Nonces are expected to be unique at this point, guaranteeing portable - // and deterministic results independent from the sorting algorithm as long as + // and deterministic results independent of the sorting algorithm as long as // the sorting algorithm works and is implemented correctly. for txs in txs_by_sender.values_mut() { txs.sort_by_key(|tx| tx.tx().nonce); } - // Randomly shuffle the list of senders in the order they appear in the transactions list. - // Use a portable and deterministic random number generator where we control the exact implementation. - // * Seed the random number generator with the given seed value, identical for all validators - // * Use the random number generator to pick a sender in the unique sender list - // * Remove the sender from the sender list - // * Assure sender removal does not change the sequence of senders - // * Add the removed sender to a new list - // * Keep moving randomly selected senders until the original sender list is empty. + // Deterministically randomize the order of senders. + // Same as with transactions we rely on the uniqueness of list members and + // a properly functioning sorting algorithm. To prevent predictable order we + // XOR each sender address with the random number generated through the HBBFT + // protocol, and use the resulting address as sorting key. + // The random number is guaranteed to be identical for all validators at the + // time of block creation. let mut senders: Vec<_> = txs_by_sender.keys().cloned().collect(); senders.sort_by_key(|address| address_xor_u256(address, seed)); @@ -84,7 +82,6 @@ fn deterministic_transactions_shuffling( final_transactions } -// Write a test function to test the address_xor_u256 function with known seeds and addresses and known XOR results #[cfg(test)] mod tests { use super::*; From 5f0fb1a91d5287a7ce9375d7f3375a6bd41e0c24 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 2 Mar 2025 21:52:40 +0100 Subject: [PATCH 349/687] Minor improvements to tests --- .../hbbft/utils/transactions_shuffling.rs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs index d8b5ab970..267e651de 100644 --- a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs +++ b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs @@ -86,21 +86,30 @@ fn deterministic_transactions_shuffling( mod tests { use super::*; // Convert to bytes in big-endian order. - fn u64_to_32_bytes_be(n: u64) -> [u8; 32] { - let mut result = [0u8; 32]; + + fn u64_to_bytes_be(n: u64) -> [u8; N] { + // Make sure the array is large enough to hold 8 bytes. + assert!(N >= 8, "Target array size must be at least 8 bytes"); + let mut result = [0u8; N]; + // Copy the big-endian bytes into the first 8 bytes. result[..8].copy_from_slice(&n.to_be_bytes()); result } #[test] fn test_address_xor_u256() { - let value_as_bytes = u64_to_32_bytes_be(0x1234567890abcdefu64); - let address = Address::from_slice(&value_as_bytes[..20]); - let seed = U256::from_big_endian(&value_as_bytes); + // TODO: Cover corner cases, preferably by using a testing crate like proptest. + let address_value = 0x1234567890abcdefu64; + let seed_value = 0x7a9e4b3d1c2f0a68u64; + + let address_bytes: [u8; 20] = u64_to_bytes_be(address_value); + let address = Address::from_slice(&address_bytes); + let seed_bytes: [u8; 32] = u64_to_bytes_be(seed_value); + let seed = U256::from_big_endian(&seed_bytes); let result = address_xor_u256(&address, seed); assert_eq!( result, - Address::from_slice(&u64_to_32_bytes_be(0x1234567890abcdef ^ 0x1234567890abcdef)[..20]) + Address::from_slice(&u64_to_bytes_be::<20>(address_value ^ seed_value)) ); } } From b2a2b54f678e9e203d48cb14416fd63b423936ab Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 2 Mar 2025 22:54:05 +0100 Subject: [PATCH 350/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/rpc/src/v1/traits/parity.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/rpc/src/v1/traits/parity.rs b/crates/rpc/src/v1/traits/parity.rs index a404d7532..fc82206cf 100644 --- a/crates/rpc/src/v1/traits/parity.rs +++ b/crates/rpc/src/v1/traits/parity.rs @@ -147,9 +147,6 @@ pub trait Parity { self.pending_transactions(size, filter) } - - - /// Returns all transactions from transaction queue. /// /// Some of them might not be ready to be included in a block yet. From 8c3b74d7856b5832393b30444826b1b001c62932 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 4 Mar 2025 11:54:25 +0100 Subject: [PATCH 351/687] on connect: write protocol version --- crates/ethcore/sync/src/chain/handler.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 2809d1ddb..47a84dadf 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -155,7 +155,8 @@ impl SyncHandler { /// Called when a new peer is connected pub fn on_peer_connected(sync: &mut ChainSync, io: &mut dyn SyncIo, peer: PeerId) { let peer_version = io.peer_version(peer); - trace!(target: "sync", "== Connected {}: {}", peer, peer_version); + + trace!(target: "sync", "== Connected {}: {} protocol: {}", peer, peer_version, io.peer_session_info(peer).map_or(0, |f| f.protocol_version)); let whitelisted = peer_version.is_hbbft(); From 4eda0fc59f7f4fa689315187434e386a1d013048 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 4 Mar 2025 12:27:35 +0100 Subject: [PATCH 352/687] logging peer capabilites, instead of xRLP version --- crates/ethcore/sync/src/chain/handler.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 47a84dadf..e6b036e6f 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -156,7 +156,8 @@ impl SyncHandler { pub fn on_peer_connected(sync: &mut ChainSync, io: &mut dyn SyncIo, peer: PeerId) { let peer_version = io.peer_version(peer); - trace!(target: "sync", "== Connected {}: {} protocol: {}", peer, peer_version, io.peer_session_info(peer).map_or(0, |f| f.protocol_version)); + + trace!(target: "sync", "== Connected {}: {} protocol: {}", peer, peer_version, io.peer_session_info(peer).map_or(String::new(), |f| f.peer_capabilities.iter().map(|c| format!("{}-{}", c.protocol, c.version)).collect::>().join(" | "))); let whitelisted = peer_version.is_hbbft(); From c68f8582d1968c2942bdb944e3f2c505b28cc108 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 4 Mar 2025 12:27:46 +0100 Subject: [PATCH 353/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/sync/src/chain/handler.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index e6b036e6f..f2c1d75df 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -155,8 +155,7 @@ impl SyncHandler { /// Called when a new peer is connected pub fn on_peer_connected(sync: &mut ChainSync, io: &mut dyn SyncIo, peer: PeerId) { let peer_version = io.peer_version(peer); - - + trace!(target: "sync", "== Connected {}: {} protocol: {}", peer, peer_version, io.peer_session_info(peer).map_or(String::new(), |f| f.peer_capabilities.iter().map(|c| format!("{}-{}", c.protocol, c.version)).collect::>().join(" | "))); let whitelisted = peer_version.is_hbbft(); From f2041f14d700720d969c38b4e4ac960f975d2237 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 4 Mar 2025 13:00:25 +0100 Subject: [PATCH 354/687] switching to propagating hashes only. --- crates/ethcore/sync/src/chain/propagator.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index d5d3009b9..12aa60f21 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -231,7 +231,12 @@ impl ChainSync { let peer_info = self.peers.get_mut(&peer_id) .expect("peer_id is form peers; peers is result of select_peers_for_transactions; select_peers_for_transactions selects peers from self.peers; qed"); - let is_hashes = peer_info.protocol_version >= ETH_PROTOCOL_VERSION_65.0; + // we would need to know the Session info of the peer in order to figure out if it is supporting hashes or not, + // what would require a lock. since atm this client is only compatible with other diamond-nodes, we can assume `true`here, + // in order to avoid the lock. (instead of: io.peer_session_info(peer_id)) + + //let is_hashes = peer_info.protocol_version >= ETH_PROTOCOL_VERSION_65.0; <-- this seems wrong, its comparing the xRLP version with the Peer Capability version + let is_hashes = true; // Send all transactions, if the peer doesn't know about anything if peer_info.last_sent_transactions.is_empty() { From 90619a1950cb8bc2faca5acad95859b38b0b243a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 4 Mar 2025 14:00:35 +0100 Subject: [PATCH 355/687] adapted timings for validator actions from 2 minutes to 30 seconds and early epoch end treshold from 22 minutes to 12 minutes. --- .../ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs | 2 +- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 7f1c4df80..f27370207 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -297,7 +297,7 @@ impl HbbftEarlyEpochEndManager { // todo: read this out from contracts: ConnectivityTrackerHbbft -> reportDisallowPeriod // requires us to update the Contracts ABIs: // https://github.com/DMDcoin/diamond-node/issues/115 - let treshold_time = Duration::from_secs(22 * 60); // 22 Minutes = 2 times the heartbeat + 2 minutes as grace period. + let treshold_time = Duration::from_secs(12 * 60); // 12 Minutes = 1 times the heartbeat + 2 minutes as grace period. if self.start_time.elapsed() < treshold_time { debug!(target: "engine", "early-epoch-end: no decision: Treshold time not reached."); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 5df74065d..782aef169 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -266,7 +266,7 @@ impl IoHandler<()> for TransitionHandler { // io.register_timer_once(ENGINE_DELAYED_UNITL_SYNCED_TOKEN, Duration::from_secs(10)) // .unwrap_or_else(|e| warn!(target: "consensus", "ENGINE_DELAYED_UNITL_SYNCED_TOKEN Timer failed: {}.", e)); - io.register_timer(ENGINE_VALIDATOR_CANDIDATE_ACTIONS, Duration::from_secs(120)) + io.register_timer(ENGINE_VALIDATOR_CANDIDATE_ACTIONS, Duration::from_secs(30)) .unwrap_or_else(|e| warn!(target: "consensus", "ENGINE_VALIDATOR_CANDIDATE_ACTIONS Timer failed: {}.", e)); } From c860bbf931cbdf403c901d3aa8e96a12c352b146 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 4 Mar 2025 17:25:32 +0100 Subject: [PATCH 356/687] monitoring: prometheus: p2p_responded_transactions p2p_responded_transactions_bytes --- .../sync/src/chain/propagator_statistics.rs | 26 +++++++++++++++++++ crates/ethcore/sync/src/chain/requester.rs | 14 ++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index cfcb422c2..da66e63d5 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -23,6 +23,9 @@ pub struct SyncPropagatorStatistics { transaction_hashes_propagated: i64, transaction_hashes_propagated_bytes: i64, + responded_transactions_bytes: i64, + responded_transactions: i64, + node_statistics: HashMap, } @@ -103,6 +106,17 @@ impl SyncPropagatorStatistics { self.transactions_propagated_bytes += size as i64; } } + + pub(crate) fn log_requested_transactions_response( + &mut self, + num_txs: usize, + bytes_sent: usize, + ) { + if self.logging_enabled { + self.responded_transactions_bytes += bytes_sent as i64; + self.responded_transactions += num_txs as i64; + } + } } impl PrometheusMetrics for SyncPropagatorStatistics { @@ -166,6 +180,18 @@ impl PrometheusMetrics for SyncPropagatorStatistics { self.transaction_hashes_propagated_bytes, ); + registry.register_counter( + "p2p_responded_transactions", + "number of responded transactions", + self.responded_transactions, + ); + + registry.register_counter( + "p2p_responded_transactions_bytes", + "bytes of responded transactions", + self.responded_transactions_bytes, + ); + self.node_statistics .iter() .for_each(|(_, node_statistics)| { diff --git a/crates/ethcore/sync/src/chain/requester.rs b/crates/ethcore/sync/src/chain/requester.rs index 5714ad56d..e65a919a0 100644 --- a/crates/ethcore/sync/src/chain/requester.rs +++ b/crates/ethcore/sync/src/chain/requester.rs @@ -107,26 +107,27 @@ impl SyncRequester { } /// Request pooled transactions from a peer + /// @return number of bytes sent pub fn request_pooled_transactions( sync: &mut ChainSync, io: &mut dyn SyncIo, peer_id: PeerId, hashes: &[H256], - ) { + ) -> usize { trace!(target: "sync", "{} <- GetPooledTransactions: {:?}", peer_id, hashes); let mut rlp = RlpStream::new_list(hashes.len()); for h in hashes { rlp.append(h); } - SyncRequester::send_request( + return SyncRequester::send_request( sync, io, peer_id, PeerAsking::PooledTransactions, GetPooledTransactionsPacket, rlp.out(), - ) + ); } /// Find some headers or blocks to download for a peer. @@ -238,7 +239,7 @@ impl SyncRequester { asking: PeerAsking, packet_id: SyncPacket, packet: Bytes, - ) { + ) -> usize { if let Some(ref mut peer) = sync.peers.get_mut(&peer_id) { if peer.asking != PeerAsking::Nothing { warn!(target:"sync", "Asking {:?} while requesting {:?}", peer.asking, asking); @@ -247,13 +248,16 @@ impl SyncRequester { peer.ask_time = Instant::now(); let (packet, _) = generate_request_id(packet, peer, packet_id); - + let packet_bytes = packet.len(); let result = io.send(peer_id, packet_id, packet); if let Err(e) = result { debug!(target:"sync", "Error sending request: {:?}", e); io.disconnect_peer(peer_id); + return 0; } + return packet_bytes; } + return 0; } } From a83457c7d24a6c392cde4fbe966a7365b09bea87 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 5 Mar 2025 20:33:17 +0100 Subject: [PATCH 357/687] possible fix for some transactions are unable to be found by the requester. --- crates/concensus/miner/src/pool/queue.rs | 14 ++++++++- crates/ethcore/sync/src/chain/mod.rs | 35 +++++++++++++---------- crates/ethcore/sync/src/chain/supplier.rs | 10 ++++++- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index adede8bf4..6238e5ea9 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -117,6 +117,14 @@ impl CachedPending { self.pending = None; } + /// Find transaction by hash in cached pending set. + /// NOTE: Linear lookup, bad performance. + pub fn find(&self, hash: &H256) -> Option> { + self.pending + .as_ref() + .and_then(|pending| pending.iter().find(|tx| tx.hash == *hash).cloned()) + } + /// Returns cached pending set (if any) if it's valid. pub fn pending( &self, @@ -660,7 +668,11 @@ impl TransactionQueue { /// Given transaction hash looks up that transaction in the pool /// and returns a shared pointer to it or `None` if it's not present. pub fn find(&self, hash: &H256) -> Option> { - self.pool.read().find(hash) + self.pool + .read() + .find(hash) + .or(self.cached_enforced_pending.read().find(hash)) + .or(self.cached_non_enforced_pending.read().find(hash)) } /// Remove a set of transactions from the pool. diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 3880d8b82..d1aaf9420 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1346,21 +1346,6 @@ impl ChainSync { return; } } - - // and if we have nothing else to do, get the peer to give us at least some of announced but unfetched transactions - let mut to_send = Default::default(); - if let Some(peer) = self.peers.get_mut(&peer_id) { - if peer.asking_pooled_transactions.is_empty() { - to_send = peer.unfetched_pooled_transactions.drain().take(MAX_TRANSACTIONS_TO_REQUEST).collect::>(); - peer.asking_pooled_transactions = to_send.clone(); - } - } - - if !to_send.is_empty() { - SyncRequester::request_pooled_transactions(self, io, peer_id, &to_send); - - return; - } } else { trace!( target: "sync", @@ -1370,7 +1355,27 @@ impl ChainSync { peer_difficulty ); self.deactivate_peer(io, peer_id); + return; } + + // and if we have nothing else to do, get the peer to give us at least some of announced but unfetched transactions + let mut to_send = Default::default(); + if let Some(peer) = self.peers.get_mut(&peer_id) { + if peer.asking_pooled_transactions.is_empty() { + // todo: we might just request the same transactions from multiple peers here, at the same time. + // we should keep track of how many replicas of a transaction we had requested. + to_send = peer.unfetched_pooled_transactions.drain().take(MAX_TRANSACTIONS_TO_REQUEST).collect::>(); + peer.asking_pooled_transactions = to_send.clone(); + } + } + + if !to_send.is_empty() { + info!(target: "trace", "requesting {} pooled transactions from {}", to_send.len(), peer_id); + let bytes_sent = SyncRequester::request_pooled_transactions(self, io, peer_id, &to_send); + self.statistics.log_requested_transactions_response(to_send.len(), bytes_sent); + + return; + } }, SyncState::SnapshotData => { match io.snapshot_service().restoration_status() { diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index d51d9e2a2..7ff77de80 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -310,20 +310,28 @@ impl SyncSupplier { let mut added = 0; let mut rlp = RlpStream::new(); rlp.begin_unbounded_list(); + let mut not_found = 0; + let mut parse_errors = 0; for v in r { if let Ok(hash) = v.as_val::() { + // io.chain().transaction(hash) + if let Some(tx) = io.chain().queued_transaction(hash) { tx.signed().rlp_append(&mut rlp); added += 1; if rlp.len() > PAYLOAD_SOFT_LIMIT { break; } + } else { + not_found += 1; } + } else { + parse_errors += 1; } } rlp.finalize_unbounded_list(); - trace!(target: "sync", "{} -> GetPooledTransactions: returned {} entries", peer_id, added); + info!(target: "sync", "{} -> GetPooledTransactions: returned {} entries. Not found: {}. parse errors: {}", peer_id, added, not_found, parse_errors); Ok(Some((PooledTransactionsPacket, rlp))) } From 4926a23cfe265aff4920b3e3d6371ef147b03b20 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Mar 2025 13:15:39 +0100 Subject: [PATCH 358/687] sending announce availability transaction now with a fix gas price of 1. --- crates/ethcore/src/engines/hbbft/contracts/validator_set.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs index f76faf367..1ef64d4fc 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs @@ -190,6 +190,7 @@ pub fn send_tx_announce_availability( ); let transaction = TransactionRequest::call(*VALIDATOR_SET_ADDRESS, send_data.0) .gas(U256::from(1_000_000)) + .gas_price(U256::from(0)) .nonce(nonce); info!(target:"consensus", "sending announce availability with nonce: {}", nonce); From a1a14803b3202e283f99c609863fdd934b613ea7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Mar 2025 13:34:45 +0100 Subject: [PATCH 359/687] miner now also searches the pending block for querying up transactions. --- crates/ethcore/src/miner/miner.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 6d7a4d359..01881cf62 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -38,6 +38,7 @@ use ethcore_miner::{ }; use ethereum_types::{Address, H256, U256}; use io::IoChannel; +use itertools::Itertools; use miner::{ self, cache::Cache, @@ -1206,6 +1207,11 @@ impl miner::MinerService for Miner { transactions: Vec, ) -> Vec> { trace!(target: "external_tx", "Importing external transactions"); + info!( + "import_external_transactions {:?}", + transactions.iter().map(|f| f.hash).collect_vec() + ); + let client = self.pool_client(chain); let results = self.transaction_queue.import( client, @@ -1445,7 +1451,20 @@ impl miner::MinerService for Miner { } fn transaction(&self, hash: &H256) -> Option> { - self.transaction_queue.find(hash) + let result = self.transaction_queue.find(hash); + + if result.is_none() { + if let Some(Some(pending)) = self.map_existing_pending_block( + |b| { + + b.transactions.iter().find(|t| t.hash == *hash).cloned() + }, + 0, + ) { + return Some(Arc::new(pool::VerifiedTransaction::from_pending_block_transaction(pending))); + } + } + return result; } fn remove_transaction(&self, hash: &H256) -> Option> { From a2539b8222565f718ed10d844b1a85567d002fb5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Mar 2025 13:36:31 +0100 Subject: [PATCH 360/687] temporary log adjustments to higher log level to solve the p2p txs propagation problems. --- crates/ethcore/sync/src/chain/handler.rs | 4 ++-- crates/ethcore/sync/src/chain/propagator.rs | 4 ++++ crates/ethcore/sync/src/chain/requester.rs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index f2c1d75df..e696aeea2 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -81,7 +81,7 @@ impl SyncHandler { } SnapshotDataPacket => SyncHandler::on_snapshot_data(sync, io, peer, &rlp), _ => { - debug!(target: "sync", "{}: Unknown packet {}", peer, packet_id.id()); + warn!(target: "sync", "{}: Unknown packet {}", peer, packet_id.id()); Ok(()) } }, @@ -891,7 +891,7 @@ impl SyncHandler { trace!(target: "sync", "{} Peer sent us more transactions than was supposed to", peer_id); return Err(DownloaderImportError::Invalid); } - trace!(target: "sync", "{:02} -> PooledTransactions ({} entries)", peer_id, item_count); + info!(target: "sync", "{:02} -> PooledTransactions ({} entries)", peer_id, item_count); let mut transactions = Vec::with_capacity(item_count); for i in 0..item_count { let rlp = tx_rlp.at(i)?; diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 12aa60f21..2315fd6aa 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -190,6 +190,10 @@ impl ChainSync { .retain_pending(&all_transactions_hashes); } + info!(target: "sync", "Propagating {} transactions to {} peers", transactions.len(), peers.len()); + + info!(target: "sync", "Propagating {:?}", all_transactions_hashes); + let send_packet = |io: &mut dyn SyncIo, stats: &mut SyncPropagatorStatistics, peer_id: PeerId, diff --git a/crates/ethcore/sync/src/chain/requester.rs b/crates/ethcore/sync/src/chain/requester.rs index e65a919a0..44760c310 100644 --- a/crates/ethcore/sync/src/chain/requester.rs +++ b/crates/ethcore/sync/src/chain/requester.rs @@ -114,7 +114,7 @@ impl SyncRequester { peer_id: PeerId, hashes: &[H256], ) -> usize { - trace!(target: "sync", "{} <- GetPooledTransactions: {:?}", peer_id, hashes); + info!(target: "sync", "{} <- GetPooledTransactions: {:?}", peer_id, hashes); let mut rlp = RlpStream::new_list(hashes.len()); for h in hashes { rlp.append(h); From 11cd92df3b5bc200b0d4fb8fe1c096f303588461 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Mar 2025 13:42:03 +0100 Subject: [PATCH 361/687] request_pooled_transactions if we are idling with a peer that is in sync. --- crates/ethcore/src/miner/miner.rs | 9 ++-- crates/ethcore/sync/src/chain/mod.rs | 68 ++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 01881cf62..5d5419232 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -1455,13 +1455,12 @@ impl miner::MinerService for Miner { if result.is_none() { if let Some(Some(pending)) = self.map_existing_pending_block( - |b| { - - b.transactions.iter().find(|t| t.hash == *hash).cloned() - }, + |b| b.transactions.iter().find(|t| t.hash == *hash).cloned(), 0, ) { - return Some(Arc::new(pool::VerifiedTransaction::from_pending_block_transaction(pending))); + return Some(Arc::new( + pool::VerifiedTransaction::from_pending_block_transaction(pending), + )); } } return result; diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index d1aaf9420..dc8757617 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -925,6 +925,9 @@ impl ChainSync { /// Updates transactions were received by a peer pub fn transactions_received(&mut self, txs: &[UnverifiedTransaction], peer_id: PeerId) { + info!(target: "sync", "Received {} transactions from peer {}", txs.len(), peer_id); + info!(target: "sync", "Received {:?}", txs.iter().map(|t| t.hash).map(|t| t.0).collect::>()); + // Remove imported txs from all request queues let imported = txs.iter().map(|tx| tx.hash()).collect::(); for (pid, peer_info) in &mut self.peers { @@ -993,6 +996,7 @@ impl ChainSync { // Reactivate peers only if some progress has been made // since the last sync round of if starting fresh. self.active_peers = self.peers.keys().cloned().collect(); + info!("resetting sync state to {:?}", self.state); } /// Add a request for later processing @@ -1232,6 +1236,10 @@ impl ChainSync { /// Find something to do for a peer. Called for a new peer or when a peer is done with its task. fn sync_peer(&mut self, io: &mut dyn SyncIo, peer_id: PeerId, force: bool) { + info!( + "sync_peer: {} force {} state: {:?}", + peer_id, force, self.state + ); if !self.active_peers.contains(&peer_id) { trace!(target: "sync", "Skipping deactivated peer {}", peer_id); return; @@ -1239,7 +1247,7 @@ impl ChainSync { let (peer_latest, peer_difficulty, peer_snapshot_number, peer_snapshot_hash) = { if let Some(peer) = self.peers.get_mut(&peer_id) { if peer.asking != PeerAsking::Nothing || !peer.can_sync() { - trace!(target: "sync", "Skipping busy peer {}", peer_id); + info!(target: "sync", "Skipping busy peer {} asking: {:?}", peer_id, peer.asking); return; } ( @@ -1249,6 +1257,7 @@ impl ChainSync { peer.snapshot_hash.as_ref().cloned(), ) } else { + info!(target: "sync", "peer info not found for {}", peer_id); return; } }; @@ -1316,6 +1325,8 @@ impl ChainSync { self.maybe_start_snapshot_sync(io); }, SyncState::Idle | SyncState::Blocks | SyncState::NewBlocks => { + + info!("doing sync"); if io.chain().queue_info().is_full() { self.pause_sync(); return; @@ -1342,6 +1353,7 @@ impl ChainSync { if force || equal_or_higher_difficulty { if ancient_block_fullness < 0.8 { if let Some(request) = self.old_blocks.as_mut().and_then(|d| d.request_blocks(peer_id, io, num_active_peers)) { + info!("requesting old blocks from: {}", peer_id); SyncRequester::request_blocks(self, io, peer_id, request, BlockSet::OldBlocks); return; } @@ -1354,28 +1366,12 @@ impl ChainSync { syncing_difficulty, peer_difficulty ); + info!("deactivate_peer: {}", peer_id); self.deactivate_peer(io, peer_id); return; } - // and if we have nothing else to do, get the peer to give us at least some of announced but unfetched transactions - let mut to_send = Default::default(); - if let Some(peer) = self.peers.get_mut(&peer_id) { - if peer.asking_pooled_transactions.is_empty() { - // todo: we might just request the same transactions from multiple peers here, at the same time. - // we should keep track of how many replicas of a transaction we had requested. - to_send = peer.unfetched_pooled_transactions.drain().take(MAX_TRANSACTIONS_TO_REQUEST).collect::>(); - peer.asking_pooled_transactions = to_send.clone(); - } - } - if !to_send.is_empty() { - info!(target: "trace", "requesting {} pooled transactions from {}", to_send.len(), peer_id); - let bytes_sent = SyncRequester::request_pooled_transactions(self, io, peer_id, &to_send); - self.statistics.log_requested_transactions_response(to_send.len(), bytes_sent); - - return; - } }, SyncState::SnapshotData => { match io.snapshot_service().restoration_status() { @@ -1407,7 +1403,41 @@ impl ChainSync { SyncState::SnapshotWaiting => () } } else { - trace!(target: "sync", "Skipping peer {}, force={}, td={:?}, our td={}, state={:?}", peer_id, force, peer_difficulty, syncing_difficulty, self.state); + // if we got nothing to do, and the other peer os also at the same block, we are fetching unfetched pooled transactions. + if self.state == SyncState::Idle && peer_latest != chain_info.best_block_hash { + // and if we have nothing else to do, get the peer to give us at least some of announced but unfetched transactions + let mut to_send = Default::default(); + if let Some(peer) = self.peers.get_mut(&peer_id) { + if peer.asking_pooled_transactions.is_empty() { + // todo: we might just request the same transactions from multiple peers here, at the same time. + // we should keep track of how many replicas of a transaction we had requested. + to_send = peer + .unfetched_pooled_transactions + .drain() + .take(MAX_TRANSACTIONS_TO_REQUEST) + .collect::>(); + peer.asking_pooled_transactions = to_send.clone(); + } else { + info!( + "we are already asking from peer {}: {} transactions", + peer_id, + peer.asking_pooled_transactions.len() + ); + } + } + + if !to_send.is_empty() { + info!(target: "sync", "requesting {} pooled transactions from {}", to_send.len(), peer_id); + let bytes_sent = + SyncRequester::request_pooled_transactions(self, io, peer_id, &to_send); + self.statistics + .log_requested_transactions_response(to_send.len(), bytes_sent); + + return; + } + } else { + info!(target: "sync", "Skipping peer {}, force={}, td={:?}, our td={}, state={:?}", peer_id, force, peer_difficulty, syncing_difficulty, self.state); + } } } From b91b4ca58b58cfe46fdb0cf68aa97241bfbba5b8 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 6 Mar 2025 14:51:33 +0100 Subject: [PATCH 362/687] Checking the gas_price if the same nonce is used twice Replacing the existing transaction with the new transaction of the same nonce if its gas price is higher. --- .../engines/hbbft/utils/transactions_shuffling.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs index 267e651de..8d9a71c23 100644 --- a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs +++ b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs @@ -42,14 +42,17 @@ fn deterministic_transactions_shuffling( for tx in transactions { let sender = tx.sender(); let entry = txs_by_sender.entry(sender).or_insert_with(Vec::new); - if entry - .iter() - .any(|existing_tx| existing_tx.tx().nonce == tx.tx().nonce) + + if let Some(existing_tx) = entry + .iter_mut() + .find(|existing_tx| existing_tx.tx().nonce == tx.tx().nonce) { - // Duplicate nonce found, ignore this transaction. - continue; + if tx.tx().gas_price > existing_tx.tx().gas_price { + *existing_tx = tx; + } + } else { + entry.push(tx); } - entry.push(tx); } // For each sender, sort their transactions by nonce (lowest first). From e38e120dc0d30390aef8913ac3aaa296da173707 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 10 Mar 2025 14:38:45 +0100 Subject: [PATCH 363/687] fixes double requesting of pooled transactions --- Cargo.lock | 35 +++++++++- .../hbbft/hbbft_config_generator/src/main.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 68 ++++++++++++++++--- .../src/chain/pooled_transactions_overview.rs | 41 +++++++++++ crates/ethcore/sync/src/chain/requester.rs | 3 +- crates/util/fastmap/Cargo.toml | 1 + crates/util/fastmap/src/lib.rs | 9 +++ 7 files changed, 145 insertions(+), 14 deletions(-) create mode 100644 crates/ethcore/sync/src/chain/pooled_transactions_overview.rs diff --git a/Cargo.lock b/Cargo.lock index cf5542252..9d40dee79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "ansi_term" version = "0.10.2" @@ -1787,6 +1793,7 @@ name = "fastmap" version = "0.1.0" dependencies = [ "ethereum-types 0.9.2", + "lru 0.13.0", "plain_hasher", ] @@ -1890,6 +1897,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" + [[package]] name = "fs-swap" version = "0.2.6" @@ -2096,6 +2109,17 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + [[package]] name = "hbbft" version = "0.1.1" @@ -2885,6 +2909,15 @@ dependencies = [ "hashbrown 0.6.3", ] +[[package]] +name = "lru" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "227748d55f2f0ab4735d87fd623798cb6b664512fe979705f829c9f81c934465" +dependencies = [ + "hashbrown 0.15.2", +] + [[package]] name = "lru-cache" version = "0.1.2" @@ -3554,7 +3587,7 @@ dependencies = [ "ethereum-types 0.9.2", "hashbrown 0.8.2", "impl-trait-for-tuples", - "lru", + "lru 0.5.3", "parity-util-mem-derive", "parking_lot 0.10.2", "primitive-types 0.7.2", diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 1eeadb9e7..630f4a317 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -258,7 +258,7 @@ fn to_toml( // Value::String("txqueue=trace,consensus=debug,engine=trace,own_tx=trace,miner=trace,tx_filter=trace".into()) misc.insert( "logging".into(), - Value::String("txqueue=info,consensus=debug,engine=debug,tx_own=trace".into()), + Value::String("txqueue=trace,consensus=debug,engine=debug,own_tx=trace".into()), ); misc.insert("log_file".into(), Value::String("diamond-node.log".into())); diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index dc8757617..abac35c63 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -89,6 +89,7 @@ pub mod fork_filter; mod handler; +mod pooled_transactions_overview; mod propagator; mod propagator_statistics; pub mod request_id; @@ -97,7 +98,10 @@ mod supplier; pub mod sync_packet; pub use self::fork_filter::ForkFilterApi; -use self::propagator_statistics::SyncPropagatorStatistics; +use self::{ + pooled_transactions_overview::PooledTransactionOverview, + propagator_statistics::SyncPropagatorStatistics, +}; use super::{SyncConfig, WarpSync}; use api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, ETH_PROTOCOL, PAR_PROTOCOL}; use block_sync::{BlockDownloader, DownloadAction}; @@ -352,7 +356,7 @@ pub struct PeerInfo { /// Hashes of transactions to be requested. unfetched_pooled_transactions: H256FastSet, /// Hashes of the transactions we're requesting. - asking_pooled_transactions: Vec, + asking_pooled_transactions: H256FastSet, /// Holds requested snapshot chunk hash if any. asking_snapshot_data: Option, /// Request timestamp @@ -737,6 +741,8 @@ pub struct ChainSync { new_transactions_stats_period: BlockNumber, /// Statistics of sync propagation statistics: SyncPropagatorStatistics, + /// memorizing currently pooled transaction to reduce the number of pooled transaction requests. + asking_pooled_transaction_overview: PooledTransactionOverview, } #[derive(Debug, Default)] @@ -748,13 +754,13 @@ struct GetPooledTransactionsReport { impl GetPooledTransactionsReport { fn generate( - mut asked: Vec, + mut asked: H256FastSet, received: impl IntoIterator, ) -> Result { let mut out = GetPooledTransactionsReport::default(); let asked_set = asked.iter().copied().collect::(); - let mut asked_iter = asked.drain(std::ops::RangeFull); + let mut asked_iter = asked.drain(); let mut txs = received.into_iter(); let mut next_received: Option = None; loop { @@ -827,6 +833,7 @@ impl ChainSync { eip1559_transition: config.eip1559_transition, new_transactions_stats_period: config.new_transactions_stats_period, statistics: SyncPropagatorStatistics::new(), + asking_pooled_transaction_overview: PooledTransactionOverview::new(), }; sync.update_targets(chain); sync @@ -938,7 +945,10 @@ impl ChainSync { .collect(); if *pid == peer_id { match GetPooledTransactionsReport::generate( - std::mem::replace(&mut peer_info.asking_pooled_transactions, Vec::new()), + std::mem::replace( + &mut peer_info.asking_pooled_transactions, + H256FastSet::default(), + ), txs.iter().map(UnverifiedTransaction::hash), ) { Ok(report) => { @@ -1406,16 +1416,52 @@ impl ChainSync { // if we got nothing to do, and the other peer os also at the same block, we are fetching unfetched pooled transactions. if self.state == SyncState::Idle && peer_latest != chain_info.best_block_hash { // and if we have nothing else to do, get the peer to give us at least some of announced but unfetched transactions - let mut to_send = Default::default(); + let mut to_send = H256FastSet::default(); if let Some(peer) = self.peers.get_mut(&peer_id) { if peer.asking_pooled_transactions.is_empty() { // todo: we might just request the same transactions from multiple peers here, at the same time. // we should keep track of how many replicas of a transaction we had requested. - to_send = peer - .unfetched_pooled_transactions - .drain() - .take(MAX_TRANSACTIONS_TO_REQUEST) - .collect::>(); + // to_send = peer + // .unfetched_pooled_transactions + // .drain() + // .take(MAX_TRANSACTIONS_TO_REQUEST) + // .collect::>(); + + for hash in peer.unfetched_pooled_transactions.iter() { + if to_send.len() >= MAX_TRANSACTIONS_TO_REQUEST { + break; + } + // we should add it, + // - if it is not known to be fetched before + // - if the last fetch was more than 300ms ago. + let mut ask_this = true; + if let Some(t) = self + .asking_pooled_transaction_overview + .get_last_fetched(hash) + { + if t.elapsed().as_millis() < 300 { + ask_this = false; + } + } + + if ask_this { + to_send.insert(hash.clone()); + self.asking_pooled_transaction_overview + .report_transaction_pooling(hash); + } + } + + peer.unfetched_pooled_transactions + .retain(|u| !to_send.contains(u)); + + // peer.unfetched_pooled_transactions.difference(other) + + //to_send = peer.unfetched_pooled_transactions.iter().filter(|&h| self.asking_pooled_transaction_overview.get_num_replicas_pooled(h ) == 0).take(MAX_TRANSACTIONS_TO_REQUEST).copied().collect::(); + + // apply LRU cache here to not requery the same transaction!! + + // self.asking_pooled_transactions_overall + peer.asking_pooled_transactions = to_send.clone(); } else { info!( diff --git a/crates/ethcore/sync/src/chain/pooled_transactions_overview.rs b/crates/ethcore/sync/src/chain/pooled_transactions_overview.rs new file mode 100644 index 000000000..670c08c9c --- /dev/null +++ b/crates/ethcore/sync/src/chain/pooled_transactions_overview.rs @@ -0,0 +1,41 @@ +use std::{num::NonZeroUsize, time::Instant}; + +use fastmap::{new_h256_fast_lru_map, H256FastLruMap}; +use hash::H256; + +/// memorizs currently pooled transactions, so they are not pooled to often from different hosts. +pub(crate) struct PooledTransactionOverview { + // number_of_requests: H256FastMap, + /// The cache of pooled transactions. + last_fetched: H256FastLruMap, +} + +impl PooledTransactionOverview { + /// Create a new `PooledTransactionOverview` with a given maximum cache size. + pub fn new() -> Self { + // we are defaulting here to a memory usage of maximum 1 MB netto data. + // 40 byte per entry (32 byte hash + 8 byte usize) + // so we can store about 26214 cached entries per megabyte of date. + + Self { + last_fetched: new_h256_fast_lru_map::( + NonZeroUsize::new(26214).unwrap(), /* about 1 MB + some overhead */ + ), + } + } + + /// Check if a transaction is already pooled. + pub fn get_last_fetched(&mut self, hash: &H256) -> Option<&Instant> { + self.last_fetched.get(hash) + } + + /// Add a transaction to the cache. + pub fn report_transaction_pooling(&mut self, hash: &H256) { + self.last_fetched.push(hash.clone(), Instant::now()); + } + + // pub fn report_transaction_pooling_finished(&mut self, hash: &H256) { + // self.last_fetched.pop(hash); + // // if we tried to access an entry that is not in the map, we ignore it. + // } +} diff --git a/crates/ethcore/sync/src/chain/requester.rs b/crates/ethcore/sync/src/chain/requester.rs index 44760c310..c8037efbd 100644 --- a/crates/ethcore/sync/src/chain/requester.rs +++ b/crates/ethcore/sync/src/chain/requester.rs @@ -17,6 +17,7 @@ use block_sync::BlockRequest; use bytes::Bytes; use ethereum_types::H256; +use fastmap::H256FastSet; use network::PeerId; use rlp::RlpStream; use std::time::Instant; @@ -112,7 +113,7 @@ impl SyncRequester { sync: &mut ChainSync, io: &mut dyn SyncIo, peer_id: PeerId, - hashes: &[H256], + hashes: &H256FastSet, ) -> usize { info!(target: "sync", "{} <- GetPooledTransactions: {:?}", peer_id, hashes); let mut rlp = RlpStream::new_list(hashes.len()); diff --git a/crates/util/fastmap/Cargo.toml b/crates/util/fastmap/Cargo.toml index 6ca397d77..ea6ce1306 100644 --- a/crates/util/fastmap/Cargo.toml +++ b/crates/util/fastmap/Cargo.toml @@ -8,3 +8,4 @@ license = "GPL-3.0" [dependencies] ethereum-types = "0.9.2" plain_hasher = "0.2" +lru = "0.13.0" diff --git a/crates/util/fastmap/src/lib.rs b/crates/util/fastmap/src/lib.rs index cc39591e1..30c5be92a 100644 --- a/crates/util/fastmap/src/lib.rs +++ b/crates/util/fastmap/src/lib.rs @@ -17,13 +17,16 @@ //! Provides a `H256FastMap` type with H256 keys and fast hashing function. extern crate ethereum_types; +extern crate lru; extern crate plain_hasher; +use self::lru::LruCache; use ethereum_types::H256; use plain_hasher::PlainHasher; use std::{ collections::{HashMap, HashSet}, hash, + num::NonZeroUsize, }; /// Specialized version of `HashMap` with H256 keys and fast hashing function. @@ -31,6 +34,12 @@ pub type H256FastMap = HashMap /// Specialized version of HashSet with H256 values and fast hashing function. pub type H256FastSet = HashSet>; +pub type H256FastLruMap = LruCache>; + +pub fn new_h256_fast_lru_map(cap: NonZeroUsize) -> H256FastLruMap { + LruCache::with_hasher(cap, hash::BuildHasherDefault::::default()) +} + #[cfg(test)] mod tests { use super::*; From ecb39be8604a543db56cd971621f70dfaed8a3f5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 10 Mar 2025 22:17:28 +0100 Subject: [PATCH 364/687] service transaction checker: Instead of forcefully doing a lot of contract calls for each sender we got notified, we delete the whole cache, and consume the load once it is needed. --- .../miner/src/service_transaction_checker.rs | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index 59f3d22ec..ee82d4a0d 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -79,26 +79,12 @@ impl ServiceTransactionChecker { /// Refresh certified addresses cache pub fn refresh_cache( &self, - client: &C, + _client: &C, ) -> Result { trace!(target: "txqueue", "Refreshing certified addresses cache"); - // replace the cache with an empty list, - // since it's not recent it won't be used anyway. - let cache = mem::replace( - &mut *self.certified_addresses_cache.write(), - HashMap::default(), - ); - - let contract_address = - Address::from_str("5000000000000000000000000000000000000001".into()).unwrap(); + + self.certified_addresses_cache.write().clear(); - let addresses: Vec<_> = cache.keys().collect(); - let mut cache: HashMap = HashMap::default(); - for address in addresses { - let allowed = self.call_contract(client, contract_address, *address)?; - cache.insert(*address, allowed); - } - *self.certified_addresses_cache.write() = cache; Ok(true) } From 551f0f4ce5e7e67e3807da7837fad1be33f6cd4a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 11 Mar 2025 18:34:51 +0100 Subject: [PATCH 365/687] tracing if a transaction is not allowed by transaction filter. --- crates/ethcore/src/machine/impls.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ethcore/src/machine/impls.rs b/crates/ethcore/src/machine/impls.rs index a17d94cdc..f1872879d 100644 --- a/crates/ethcore/src/machine/impls.rs +++ b/crates/ethcore/src/machine/impls.rs @@ -418,6 +418,7 @@ impl EthereumMachine { ) -> Result<(), transaction::Error> { if let Some(ref filter) = self.tx_filter.as_ref() { if !filter.transaction_allowed(&parent.hash(), parent.number() + 1, t, client) { + trace!(target: "txqueue", "transaction {} not allowed by filter", t.hash); return Err(transaction::Error::NotAllowed.into()); } } From 5ae32e89c70d42fceb2da44df38350e2ea3f2272 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 11 Mar 2025 18:36:41 +0100 Subject: [PATCH 366/687] transaction possiping for now only with peers up to date with us. --- crates/ethcore/sync/src/chain/mod.rs | 49 ++++++++++++++++++---------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index abac35c63..5816a976a 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -128,7 +128,7 @@ use std::{ }; use sync_io::SyncIo; use transactions_stats::{Stats as TransactionStats, TransactionsStats}; -use types::{transaction::UnverifiedTransaction, BlockNumber}; +use types::{block_status, transaction::UnverifiedTransaction, BlockNumber}; use self::{ handler::SyncHandler, @@ -1273,6 +1273,7 @@ impl ChainSync { }; let chain_info = io.chain().chain_info(); let syncing_difficulty = chain_info.pending_total_difficulty; + let num_active_peers = self .peers .values() @@ -1413,19 +1414,41 @@ impl ChainSync { SyncState::SnapshotWaiting => () } } else { - // if we got nothing to do, and the other peer os also at the same block, we are fetching unfetched pooled transactions. - if self.state == SyncState::Idle && peer_latest != chain_info.best_block_hash { + + // if we got nothing to do, and the other peer is also at the same block, or is known to be just 1 behind, we are fetching unfetched pooled transactions. + // there is some delay of the information what block they are on. + + // communicate with this peer in any case if we are on the same block. + let communicate_with_peer = chain_info.best_block_hash == peer_latest; + + + // on a distributed real network, 3 seconds is about they physical minimum. + // therefore we "accept" other nodes to be 1 block behind - usually they are not! + // The other way around: if they are a validator, and we are at the tip, we might be still 1 block behind, because there is already a pending block. + // our best_block information is always accurate, so we are not notifiying them obout our transactions, that might be already included in the block. + + // todo: Further investigation if we should or should not accept a gap in block height. + + // if !communicate_with_peer { + + // // if we are not on the same block, find out if we do have a block number for their block. + // io.chain().block_number(BlockId::Hash(peer_latest)).map(|block_number| { + // // let other_best_block = peer_difficulty.unwrap_or_default().low_u64() as i64; + // // let best_block = chain_info.best_block_number as i64; + + // if block_number == chain_info.best_block_number { + // communicate_with_peer = true; + // } + // }); + // } + + if self.state == SyncState::Idle && communicate_with_peer { // and if we have nothing else to do, get the peer to give us at least some of announced but unfetched transactions let mut to_send = H256FastSet::default(); if let Some(peer) = self.peers.get_mut(&peer_id) { if peer.asking_pooled_transactions.is_empty() { // todo: we might just request the same transactions from multiple peers here, at the same time. // we should keep track of how many replicas of a transaction we had requested. - // to_send = peer - // .unfetched_pooled_transactions - // .drain() - // .take(MAX_TRANSACTIONS_TO_REQUEST) - // .collect::>(); for hash in peer.unfetched_pooled_transactions.iter() { if to_send.len() >= MAX_TRANSACTIONS_TO_REQUEST { @@ -1454,14 +1477,6 @@ impl ChainSync { peer.unfetched_pooled_transactions .retain(|u| !to_send.contains(u)); - // peer.unfetched_pooled_transactions.difference(other) - - //to_send = peer.unfetched_pooled_transactions.iter().filter(|&h| self.asking_pooled_transaction_overview.get_num_replicas_pooled(h ) == 0).take(MAX_TRANSACTIONS_TO_REQUEST).copied().collect::(); - - // apply LRU cache here to not requery the same transaction!! - - // self.asking_pooled_transactions_overall - peer.asking_pooled_transactions = to_send.clone(); } else { info!( @@ -1482,7 +1497,7 @@ impl ChainSync { return; } } else { - info!(target: "sync", "Skipping peer {}, force={}, td={:?}, our td={}, state={:?}", peer_id, force, peer_difficulty, syncing_difficulty, self.state); + info!(target: "sync", "Skipping peer {}, force={}, td={:?}, our td={}, blochhash={:?} our_blockhash={:?} state={:?}", peer_id, force, peer_difficulty, syncing_difficulty, peer_latest, chain_info.best_block_hash, self.state); } } } From a98ec197140a2bb59728fcd0c2500d6487f7d9bd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 15 Mar 2025 00:50:16 +0100 Subject: [PATCH 367/687] defaulting to tx_filter trace for debugging the missing transactions problem --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 630f4a317..36758e479 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -258,7 +258,7 @@ fn to_toml( // Value::String("txqueue=trace,consensus=debug,engine=trace,own_tx=trace,miner=trace,tx_filter=trace".into()) misc.insert( "logging".into(), - Value::String("txqueue=trace,consensus=debug,engine=debug,own_tx=trace".into()), + Value::String("txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace".into()), ); misc.insert("log_file".into(), Value::String("diamond-node.log".into())); From 92f13fa55ae696a0b4a93ae534c64837f781db30 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 19 Mar 2025 18:56:35 +0100 Subject: [PATCH 368/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/concensus/miner/src/service_transaction_checker.rs | 2 +- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 4 +++- crates/ethcore/sync/src/chain/mod.rs | 6 ++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index ee82d4a0d..16a6039d0 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -82,7 +82,7 @@ impl ServiceTransactionChecker { _client: &C, ) -> Result { trace!(target: "txqueue", "Refreshing certified addresses cache"); - + self.certified_addresses_cache.write().clear(); Ok(true) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 36758e479..0718abbb3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -258,7 +258,9 @@ fn to_toml( // Value::String("txqueue=trace,consensus=debug,engine=trace,own_tx=trace,miner=trace,tx_filter=trace".into()) misc.insert( "logging".into(), - Value::String("txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace".into()), + Value::String( + "txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace".into(), + ), ); misc.insert("log_file".into(), Value::String("diamond-node.log".into())); diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 5816a976a..30cf45389 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1273,7 +1273,7 @@ impl ChainSync { }; let chain_info = io.chain().chain_info(); let syncing_difficulty = chain_info.pending_total_difficulty; - + let num_active_peers = self .peers .values() @@ -1414,18 +1414,16 @@ impl ChainSync { SyncState::SnapshotWaiting => () } } else { - // if we got nothing to do, and the other peer is also at the same block, or is known to be just 1 behind, we are fetching unfetched pooled transactions. // there is some delay of the information what block they are on. // communicate with this peer in any case if we are on the same block. let communicate_with_peer = chain_info.best_block_hash == peer_latest; - // on a distributed real network, 3 seconds is about they physical minimum. // therefore we "accept" other nodes to be 1 block behind - usually they are not! // The other way around: if they are a validator, and we are at the tip, we might be still 1 block behind, because there is already a pending block. - // our best_block information is always accurate, so we are not notifiying them obout our transactions, that might be already included in the block. + // our best_block information is always accurate, so we are not notifiying them obout our transactions, that might be already included in the block. // todo: Further investigation if we should or should not accept a gap in block height. From 5cbab60496ba5c05bcfa561ec480176fbe402db1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 19 Mar 2025 19:02:00 +0100 Subject: [PATCH 369/687] rewritten PermissionCache: Permission cache is now an own struct, and only valid for one block. Investigation has shown that it always just using the latest block. There is no scenario known when the Node should check if a service transaction was valid in the past. Therefore: Support for getting cached results for historic transctions has been removed. --- crates/ethcore/src/tx_filter.rs | 45 +++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 8abceb86e..09a260ea6 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -52,11 +52,41 @@ mod tx_permissions { pub const _PRIVATE: u32 = 0b00001000; } +pub struct PermissionCache { + // permission cache is only valid for one block. + valid_block: H256, + cache: LruCache, +} + +impl PermissionCache { + pub fn new(size: usize) -> Self { + PermissionCache { + cache: LruCache::new(size), + valid_block: H256::zero(), + } + } + + pub fn refresh(&mut self, current_block: &H256) { + if self.valid_block != *current_block { + self.cache.clear(); + self.valid_block = current_block.clone(); + } + } + + pub fn insert(&mut self, key: Address, value: u32) { + self.cache.insert(key, value); + } + + pub fn get(&mut self, key: &Address) -> Option { + self.cache.get_mut(key).cloned() + } +} + /// Connection filter that uses a contract to manage permissions. pub struct TransactionFilter { contract_address: Address, transition_block: BlockNumber, - permission_cache: Mutex>, + permission_cache: Mutex, contract_version_cache: Mutex>>, } @@ -68,7 +98,7 @@ impl TransactionFilter { .map(|address| TransactionFilter { contract_address: address, transition_block: params.transaction_permission_contract_transition, - permission_cache: Mutex::new(LruCache::new(MAX_CACHE_SIZE)), + permission_cache: Mutex::new(PermissionCache::new(MAX_CACHE_SIZE)), contract_version_cache: Mutex::new(LruCache::new(MAX_CACHE_SIZE)), }) } @@ -85,7 +115,12 @@ impl TransactionFilter { return true; } + // todo: + // we could work on an improved version here that holds the cache for a shorter period. + // the contract call is quite expensive. + let mut permission_cache = self.permission_cache.lock(); + permission_cache.refresh(parent_hash); let mut contract_version_cache = self.contract_version_cache.lock(); let (tx_type, to) = match transaction.tx().action { @@ -109,8 +144,8 @@ impl TransactionFilter { let gas_limit = transaction.tx().gas; let key = (*parent_hash, sender); - if let Some(permissions) = permission_cache.get_mut(&key) { - return *permissions & tx_type != 0; + if let Some(permissions) = permission_cache.get(&sender) { + return permissions & tx_type != 0; } let contract_address = self.contract_address; @@ -204,7 +239,7 @@ impl TransactionFilter { }; if filter_only_sender { - permission_cache.insert((*parent_hash, sender), permissions); + permission_cache.insert(sender, permissions); } trace!(target: "tx_filter", "Given transaction data: sender: {:?} to: {:?} value: {}, gas_price: {}. Permissions required: {:X}, got: {:X}", sender, to, value, gas_price, tx_type, permissions); permissions & tx_type != 0 From 3d35733d63c1e056516fbb707b68dd899bf4d2af Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 24 Mar 2025 16:30:24 +0100 Subject: [PATCH 370/687] upgraded transaction filter LRU caches to H256FastLruMap --- Cargo.lock | 1 + crates/ethcore/Cargo.toml | 1 + crates/ethcore/src/lib.rs | 1 + crates/ethcore/src/tx_filter.rs | 106 +++++++++++++++++++++----------- 4 files changed, 72 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d40dee79..77114d4a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1232,6 +1232,7 @@ dependencies = [ "ethjson", "ethkey", "evm", + "fastmap", "fetch", "globset", "hash-db 0.11.0", diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index be6e79a23..f10b39a9f 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -87,6 +87,7 @@ walkdir = "2.3" wasm = { path = "../vm/wasm" } derive_more = "0.99" scopeguard = "1.1.0" +fastmap = { path = "../util/fastmap"} [dev-dependencies] blooms-db = { path = "../db/blooms-db" } diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index d09dfd7c0..e6d2dcd68 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -32,6 +32,7 @@ extern crate ethcore_io as io; extern crate ethcore_miner; extern crate ethereum_types; extern crate ethjson; +extern crate fastmap; extern crate hash_db; extern crate hbbft; extern crate itertools; diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 09a260ea6..827e97cb6 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -16,8 +16,11 @@ //! Smart contract based transaction filter. +use std::num::NonZeroUsize; + use ethabi::FunctionOutputDecoder; use ethereum_types::{Address, H256, U256}; +use fastmap::{new_h256_fast_lru_map, H256FastLruMap}; use lru_cache::LruCache; use call_contract::CallContract; @@ -41,7 +44,7 @@ use_contract!( ); use_contract!(transact_acl_1559, "res/contracts/tx_acl_1559.json"); -const MAX_CACHE_SIZE: usize = 4096; +const MAX_CACHE_SIZE: usize = 40960; mod tx_permissions { pub const _ALL: u32 = 0xffffffff; @@ -55,13 +58,13 @@ mod tx_permissions { pub struct PermissionCache { // permission cache is only valid for one block. valid_block: H256, - cache: LruCache, + cache: H256FastLruMap, } impl PermissionCache { pub fn new(size: usize) -> Self { PermissionCache { - cache: LruCache::new(size), + cache: new_h256_fast_lru_map(NonZeroUsize::new(MAX_CACHE_SIZE).unwrap()), valid_block: H256::zero(), } } @@ -73,13 +76,29 @@ impl PermissionCache { } } - pub fn insert(&mut self, key: Address, value: u32) { - self.cache.insert(key, value); + pub fn insert(&mut self, tx_hash: H256, value: u32) { + self.cache.push(tx_hash, value); + } + + + pub fn get(&mut self, tx_hash: &H256) -> Option { + + self.cache.get_mut(&tx_hash).cloned() } - pub fn get(&mut self, key: &Address) -> Option { - self.cache.get_mut(key).cloned() + /// returns the block number for which the cache is valid. + pub fn get_valid_block(&self) -> &H256 { + return &self.valid_block; } + + + // // we need a cheap method to get the key for the cache. + // fn calc_key(address: &Address, tx_hash: &H256) -> H256 { + + // // since both, address and tx_hash are already cryptographical products, + // // we can calculate the X-Or out of them to get a H256 cryptographicaly unique identifier. + // return H256::from_slice(address.as_bytes()) ^ *tx_hash; + // } } /// Connection filter that uses a contract to manage permissions. @@ -113,16 +132,9 @@ impl TransactionFilter { ) -> bool { if block_number < self.transition_block { return true; - } - - // todo: - // we could work on an improved version here that holds the cache for a shorter period. - // the contract call is quite expensive. - - let mut permission_cache = self.permission_cache.lock(); - permission_cache.refresh(parent_hash); - let mut contract_version_cache = self.contract_version_cache.lock(); + } + let (tx_type, to) = match transaction.tx().action { Action::Create => (tx_permissions::CREATE, Address::default()), Action::Call(address) => { @@ -144,28 +156,38 @@ impl TransactionFilter { let gas_limit = transaction.tx().gas; let key = (*parent_hash, sender); - if let Some(permissions) = permission_cache.get(&sender) { - return permissions & tx_type != 0; - } + { + let mut permission_cache = self.permission_cache.lock(); + permission_cache.refresh(parent_hash); + if let Some(permissions) = permission_cache.get(&transaction.hash) { + return permissions & tx_type != 0; + } + } let contract_address = self.contract_address; - let contract_version = contract_version_cache - .get_mut(parent_hash) - .and_then(|v| *v) - .or_else(|| { - let (data, decoder) = transact_acl::functions::contract_version::call(); - decoder - .decode( - &client - .call_contract(BlockId::Hash(*parent_hash), contract_address, data) - .ok()?, - ) - .ok() - }); - contract_version_cache.insert(*parent_hash, contract_version); + let contract_version = { + let mut contract_version_cache = self.contract_version_cache.lock(); + + let v = contract_version_cache + .get_mut(parent_hash) + .and_then(|v| *v) + .or_else(|| { + let (data, decoder) = transact_acl::functions::contract_version::call(); + decoder + .decode( + &client + .call_contract(BlockId::Hash(*parent_hash), contract_address, data) + .ok()?, + ) + .ok() + }); + contract_version_cache.insert(*parent_hash, v); + v + }; + // Check permissions in smart contract based on its version - let (permissions, filter_only_sender) = match contract_version { + let (permissions, _filter_only_sender) = match contract_version { Some(version) => { let version_u64 = version.low_u64(); trace!(target: "tx_filter", "Version of tx permission contract: {}", version); @@ -238,11 +260,21 @@ impl TransactionFilter { } }; - if filter_only_sender { - permission_cache.insert(sender, permissions); + { + let mut permission_cache = self.permission_cache.lock(); + + // it could be that cache got refreshed in the meantime by another thread. + if parent_hash == permission_cache.get_valid_block() { + // we can cache every transaciton. + permission_cache.insert( transaction.hash.clone(), permissions); + } + else { + trace!(target: "tx_filter", "did not add tx [{}] to permission cache, because block changed in the meantime.", transaction.hash); + } } + trace!(target: "tx_filter", "Given transaction data: sender: {:?} to: {:?} value: {}, gas_price: {}. Permissions required: {:X}, got: {:X}", sender, to, value, gas_price, tx_type, permissions); - permissions & tx_type != 0 + return permissions & tx_type != 0; } } From 3e2a188366a017843751f592aa1413635fad41d8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 24 Mar 2025 18:32:12 +0100 Subject: [PATCH 371/687] additional temporaral log entries --- .../miner/src/service_transaction_checker.rs | 5 ++++- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 1 + crates/ethcore/src/tx_filter.rs | 21 ++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index 16a6039d0..f8420c9f8 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -56,7 +56,7 @@ impl ServiceTransactionChecker { client: &C, sender: Address, ) -> Result { - trace!(target: "txqueue", "Checking service transaction checker contract from {}", sender); + trace!(target: "txqueue", "Checking service transaction checker contract for {}", sender); if let Some(allowed) = self .certified_addresses_cache .try_read() @@ -67,6 +67,9 @@ impl ServiceTransactionChecker { } let x = Address::from_str("5000000000000000000000000000000000000001".into()).unwrap(); let contract_address = x; + + trace!(target: "txfilter", "Checking service transaction from contract for: {}", sender); + self.call_contract(client, contract_address, sender) .and_then(|allowed| { if let Some(mut cache) = self.certified_addresses_cache.try_write() { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 782aef169..ca6bd4d19 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -539,6 +539,7 @@ impl HoneyBadgerBFT { if let Some(header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) { let block_num = header.number(); let hash = header.bare_hash(); + // TODO: trace is missleading here: we already got the signature shares, we can already trace!(target: "consensus", "Sending signature share of {} for block {}", hash, block_num); let step = match self .sealing diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 827e97cb6..29448ff8a 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -80,9 +80,7 @@ impl PermissionCache { self.cache.push(tx_hash, value); } - pub fn get(&mut self, tx_hash: &H256) -> Option { - self.cache.get_mut(&tx_hash).cloned() } @@ -91,7 +89,6 @@ impl PermissionCache { return &self.valid_block; } - // // we need a cheap method to get the key for the cache. // fn calc_key(address: &Address, tx_hash: &H256) -> H256 { @@ -132,9 +129,10 @@ impl TransactionFilter { ) -> bool { if block_number < self.transition_block { return true; - } + } + + debug!(target: "tx_filter", "Checking transaction permission for tx: {}", transaction.hash); - let (tx_type, to) = match transaction.tx().action { Action::Create => (tx_permissions::CREATE, Address::default()), Action::Call(address) => { @@ -154,8 +152,8 @@ impl TransactionFilter { let gas_price = transaction.tx().gas_price; let max_priority_fee_per_gas = transaction.max_priority_fee_per_gas(); let gas_limit = transaction.tx().gas; - let key = (*parent_hash, sender); + // this scope is for holding the lock for the permission caches only for the time we need it. { let mut permission_cache = self.permission_cache.lock(); permission_cache.refresh(parent_hash); @@ -168,7 +166,7 @@ impl TransactionFilter { let contract_version = { let mut contract_version_cache = self.contract_version_cache.lock(); - + let v = contract_version_cache .get_mut(parent_hash) .and_then(|v| *v) @@ -185,7 +183,7 @@ impl TransactionFilter { contract_version_cache.insert(*parent_hash, v); v }; - + // Check permissions in smart contract based on its version let (permissions, _filter_only_sender) = match contract_version { Some(version) => { @@ -266,10 +264,9 @@ impl TransactionFilter { // it could be that cache got refreshed in the meantime by another thread. if parent_hash == permission_cache.get_valid_block() { // we can cache every transaciton. - permission_cache.insert( transaction.hash.clone(), permissions); - } - else { - trace!(target: "tx_filter", "did not add tx [{}] to permission cache, because block changed in the meantime.", transaction.hash); + permission_cache.insert(transaction.hash.clone(), permissions); + } else { + trace!(target: "tx_filter", "did not add tx [{}] to permission cache, because block changed in the meantime.", transaction.hash); } } From 56b935a3867209396457df9562c5e23c04b826b4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 Mar 2025 17:09:01 +0100 Subject: [PATCH 372/687] package update num-big --- Cargo.lock | 57 ++++++++---------------------------- crates/vm/builtin/Cargo.toml | 2 +- crates/vm/builtin/src/lib.rs | 41 ++++++++++++++------------ crates/vm/evm/Cargo.toml | 2 +- 4 files changed, 38 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77114d4a9..17640fff8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -1113,7 +1113,7 @@ dependencies = [ [[package]] name = "ethabi" version = "11.0.0" -source = "git+https://github.com/rimrakhimov/ethabi?branch=rimrakhimov/remove-syn-export-span#222e6482ac45d9c01f9e895ade8e439f86dbfc2f" +source = "git+https://github.com/rimrakhimov/ethabi?branch=rimrakhimov%2Fremove-syn-export-span#222e6482ac45d9c01f9e895ade8e439f86dbfc2f" dependencies = [ "ethereum-types 0.9.2", "rustc-hex 2.1.0", @@ -1146,7 +1146,7 @@ checksum = "4632b1b766fbf59872eb7a41e7ebaa10727b7f7000aef5bb626b87e472041c83" [[package]] name = "ethabi-derive" version = "11.0.0" -source = "git+https://github.com/rimrakhimov/ethabi?branch=rimrakhimov/remove-syn-export-span#222e6482ac45d9c01f9e895ade8e439f86dbfc2f" +source = "git+https://github.com/rimrakhimov/ethabi?branch=rimrakhimov%2Fremove-syn-export-span#222e6482ac45d9c01f9e895ade8e439f86dbfc2f" dependencies = [ "ethabi 11.0.0", "heck", @@ -1365,7 +1365,7 @@ dependencies = [ "log", "macros", "maplit", - "num", + "num-bigint 0.4.3", "parity-bytes", "parity-crypto", "rustc-hex 1.0.0", @@ -1743,7 +1743,7 @@ dependencies = [ "lazy_static", "log", "memory-cache", - "num-bigint 0.2.3", + "num-bigint 0.4.3", "parity-bytes", "parity-util-mem", "parking_lot 0.11.1", @@ -3176,30 +3176,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" -[[package]] -name = "num" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" -dependencies = [ - "num-bigint 0.1.44", - "num-integer", - "num-iter", - "num-traits 0.2.15", -] - -[[package]] -name = "num-bigint" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1" -dependencies = [ - "num-integer", - "num-traits 0.2.15", - "rand 0.4.6", - "rustc-serialize", -] - [[package]] name = "num-bigint" version = "0.2.3" @@ -3212,23 +3188,22 @@ dependencies = [ ] [[package]] -name = "num-integer" -version = "0.1.41" +name = "num-bigint" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ - "autocfg 0.1.7", + "autocfg 1.0.0", + "num-integer", "num-traits 0.2.15", ] [[package]] -name = "num-iter" -version = "0.1.39" +name = "num-integer" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg 0.1.7", - "num-integer", "num-traits 0.2.15", ] @@ -4520,12 +4495,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustc-serialize" -version = "0.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" - [[package]] name = "rustc_version" version = "0.2.3" diff --git a/crates/vm/builtin/Cargo.toml b/crates/vm/builtin/Cargo.toml index 45167eb96..45098bb03 100644 --- a/crates/vm/builtin/Cargo.toml +++ b/crates/vm/builtin/Cargo.toml @@ -15,7 +15,7 @@ ethkey = { path = "../../accounts/ethkey" } keccak-hash = "0.5.0" log = "0.4" macros = { path = "../../util/macros" } -num = { version = "0.1", default-features = false, features = ["bigint"] } +num-bigint = { version = "0.4" } parity-bytes = "0.1" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } eth_pairings = { git = "https://github.com/matter-labs/eip1962.git", default-features = false, features = ["eip_2537"], rev = "ece6cbabc41948db4200e41f0bfdab7ab94c7af8" } diff --git a/crates/vm/builtin/src/lib.rs b/crates/vm/builtin/src/lib.rs index c54d910f8..acd062f31 100644 --- a/crates/vm/builtin/src/lib.rs +++ b/crates/vm/builtin/src/lib.rs @@ -37,7 +37,7 @@ use ethereum_types::{H256, U256}; use ethjson; use keccak_hash::keccak; use log::{trace, warn}; -use num::{BigUint, One, Zero}; +use num_bigint::BigUint; use parity_bytes::BytesRef; use parity_crypto::{ digest, @@ -923,9 +923,11 @@ impl Implementation for Ripemd160 { fn modexp(mut base: BigUint, exp: Vec, modulus: BigUint) -> BigUint { const BITS_PER_DIGIT: usize = 8; + + // n^m % 0 || n^m % 1 - if modulus <= BigUint::one() { - return BigUint::zero(); + if modulus <= BigUint::from(1 as usize) { + return BigUint::from(0 as usize); } // normalize exponent @@ -933,24 +935,25 @@ fn modexp(mut base: BigUint, exp: Vec, modulus: BigUint) -> BigUint { // n^0 % m if exp.peek().is_none() { - return BigUint::one(); + + return BigUint::from(1 as usize); } // 0^n % m, n > 0 - if base.is_zero() { - return BigUint::zero(); + if base.eq(&BigUint::from(0 as usize)) { + return BigUint::from(0 as usize); } base %= &modulus; // Fast path for base divisible by modulus. - if base.is_zero() { - return BigUint::zero(); + if base.eq(&BigUint::from(0 as usize)) { + return BigUint::from(0 as usize); } // Left-to-right binary exponentiation (Handbook of Applied Cryptography - Algorithm 14.79). // http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf - let mut result = BigUint::one(); + let mut result = BigUint::from(1 as usize); for digit in exp { let mut mask = 1 << (BITS_PER_DIGIT - 1); @@ -992,7 +995,7 @@ impl Implementation for Modexp { // Gas formula allows arbitrary large exp_len when base and modulus are empty, so we need to handle empty base first. let r = if base_len == 0 && mod_len == 0 { - BigUint::zero() + BigUint::from(0 as usize) } else { // read the numbers themselves. let mut buf = vec![0; max(mod_len, max(base_len, exp_len))]; @@ -1381,7 +1384,7 @@ mod tests { use hex_literal::hex; use macros::map; use maplit::btreemap; - use num::{BigUint, One, Zero}; + use num_bigint::BigUint; use parity_bytes::BytesRef; use rustc_hex::FromHex; use std::convert::TryFrom; @@ -1525,28 +1528,30 @@ mod tests { #[test] fn modexp_func() { // n^0 % m == 1 + + let mut base = BigUint::parse_bytes(b"12345", 10).unwrap(); - let mut exp = BigUint::zero(); + let mut exp = BigUint::from(0 as usize); let mut modulus = BigUint::parse_bytes(b"789", 10).unwrap(); - assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::one()); + assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::from(1 as usize)); // 0^n % m == 0 - base = BigUint::zero(); + base = BigUint::from(0 as usize); exp = BigUint::parse_bytes(b"12345", 10).unwrap(); modulus = BigUint::parse_bytes(b"789", 10).unwrap(); - assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::zero()); + assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::from(0 as usize)); // n^m % 1 == 0 base = BigUint::parse_bytes(b"12345", 10).unwrap(); exp = BigUint::parse_bytes(b"789", 10).unwrap(); - modulus = BigUint::one(); - assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::zero()); + modulus = BigUint::from(1 as usize); + assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::from(0 as usize)); // if n % d == 0, then n^m % d == 0 base = BigUint::parse_bytes(b"12345", 10).unwrap(); exp = BigUint::parse_bytes(b"789", 10).unwrap(); modulus = BigUint::parse_bytes(b"15", 10).unwrap(); - assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::zero()); + assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::from(0 as usize)); // others base = BigUint::parse_bytes(b"12345", 10).unwrap(); diff --git a/crates/vm/evm/Cargo.toml b/crates/vm/evm/Cargo.toml index c492a9ab5..7de3b071c 100644 --- a/crates/vm/evm/Cargo.toml +++ b/crates/vm/evm/Cargo.toml @@ -16,7 +16,7 @@ parity-util-mem = "0.7" parking_lot = "0.11.1" memory-cache = { path = "../../util/memory-cache" } ethcore-builtin = { path = "../builtin" } -num-bigint = "0.2" +num-bigint = "0.4" [dev-dependencies] rustc-hex = "1.0" From a0e8471371da8ef47ff4e5a55e2ce0446f18483c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Mar 2025 16:26:57 +0100 Subject: [PATCH 373/687] rust edition 2024 experiment --- bin/chainspec/Cargo.toml | 1 + crates/accounts/ethstore/Cargo.toml | 1 + crates/concensus/miner/Cargo.toml | 1 + crates/concensus/miner/price-info/Cargo.toml | 1 + crates/db/blooms-db/Cargo.toml | 1 + crates/db/patricia-trie-ethereum/Cargo.toml | 1 + crates/net/fetch/Cargo.toml | 1 + crates/util/stats/Cargo.toml | 1 + crates/vm/evm/Cargo.toml | 1 + 9 files changed, 9 insertions(+) diff --git a/bin/chainspec/Cargo.toml b/bin/chainspec/Cargo.toml index f990a81dd..ea58e7bd1 100644 --- a/bin/chainspec/Cargo.toml +++ b/bin/chainspec/Cargo.toml @@ -2,6 +2,7 @@ description = "Parity Ethereum Chain Specification" name = "chainspec" version = "0.1.0" +edition = "2024" authors = ["Marek Kotewicz "] [dependencies] diff --git a/crates/accounts/ethstore/Cargo.toml b/crates/accounts/ethstore/Cargo.toml index bdfd93af8..e09d4ab61 100644 --- a/crates/accounts/ethstore/Cargo.toml +++ b/crates/accounts/ethstore/Cargo.toml @@ -3,6 +3,7 @@ description = "Parity Ethereum Key Management" name = "ethstore" version = "0.2.1" authors = ["Parity Technologies "] +edition = "2024" [dependencies] log = "0.4" diff --git a/crates/concensus/miner/Cargo.toml b/crates/concensus/miner/Cargo.toml index af7f5fb71..f39981848 100644 --- a/crates/concensus/miner/Cargo.toml +++ b/crates/concensus/miner/Cargo.toml @@ -1,6 +1,7 @@ [package] description = "diamond-node Miner Interface." name = "ethcore-miner" +edition = "2024" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" version = "1.12.0" diff --git a/crates/concensus/miner/price-info/Cargo.toml b/crates/concensus/miner/price-info/Cargo.toml index ea0427831..064753808 100644 --- a/crates/concensus/miner/price-info/Cargo.toml +++ b/crates/concensus/miner/price-info/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "price-info" version = "1.12.0" authors = ["Parity Technologies "] +edition = "2024" [dependencies] fetch = { path = "../../../net/fetch" } diff --git a/crates/db/blooms-db/Cargo.toml b/crates/db/blooms-db/Cargo.toml index 6d49b0430..b37cc2af0 100644 --- a/crates/db/blooms-db/Cargo.toml +++ b/crates/db/blooms-db/Cargo.toml @@ -3,6 +3,7 @@ name = "blooms-db" version = "0.1.0" license = "GPL-3.0" authors = ["Parity Technologies "] +edition = "2024" [dependencies] byteorder = "1.2" diff --git a/crates/db/patricia-trie-ethereum/Cargo.toml b/crates/db/patricia-trie-ethereum/Cargo.toml index 1064bdb30..9f8dc4526 100644 --- a/crates/db/patricia-trie-ethereum/Cargo.toml +++ b/crates/db/patricia-trie-ethereum/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] description = "Merkle-Patricia Trie (Ethereum Style)" license = "GPL-3.0" +edition = "2024" [dependencies] trie-db = "0.11.0" diff --git a/crates/net/fetch/Cargo.toml b/crates/net/fetch/Cargo.toml index eabbbdb61..53cb9acbf 100644 --- a/crates/net/fetch/Cargo.toml +++ b/crates/net/fetch/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "fetch" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2024" [dependencies] futures = "0.1" diff --git a/crates/util/stats/Cargo.toml b/crates/util/stats/Cargo.toml index 724270c19..ab6f3d2fc 100644 --- a/crates/util/stats/Cargo.toml +++ b/crates/util/stats/Cargo.toml @@ -2,6 +2,7 @@ name = "stats" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2024" [dependencies] log = "0.4" diff --git a/crates/vm/evm/Cargo.toml b/crates/vm/evm/Cargo.toml index 7de3b071c..916714c82 100644 --- a/crates/vm/evm/Cargo.toml +++ b/crates/vm/evm/Cargo.toml @@ -3,6 +3,7 @@ description = "Parity Ethereum Virtual Machine (EVM) Rust Implementation" name = "evm" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2024" [dependencies] bit-set = "0.4" From 343f435fb1fc8489de6d4503a1cb5a6a315df732 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Mar 2025 16:38:17 +0100 Subject: [PATCH 374/687] fixed file import in bloomdb --- crates/db/blooms-db/src/db.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/db/blooms-db/src/db.rs b/crates/db/blooms-db/src/db.rs index f174ffeb1..ee6ee4b8e 100644 --- a/crates/db/blooms-db/src/db.rs +++ b/crates/db/blooms-db/src/db.rs @@ -21,7 +21,7 @@ use std::{ use ethbloom; -use file::{File, FileIterator}; +use crate::file::{File, FileIterator}; fn other_io_err(e: E) -> io::Error where From ecd3bbbe92ce355af7288371844b785358e197e0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Mar 2025 16:57:17 +0100 Subject: [PATCH 375/687] import fixes for 2024 --- crates/vm/evm/src/interpreter/gasometer.rs | 8 ++++---- crates/vm/evm/src/interpreter/informant.rs | 2 +- crates/vm/evm/src/interpreter/mod.rs | 4 ++-- crates/vm/evm/src/interpreter/stack.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/vm/evm/src/interpreter/gasometer.rs b/crates/vm/evm/src/interpreter/gasometer.rs index aec51b4ec..4fc46d53d 100644 --- a/crates/vm/evm/src/interpreter/gasometer.rs +++ b/crates/vm/evm/src/interpreter/gasometer.rs @@ -19,9 +19,9 @@ use ethereum_types::{Address, BigEndianHash, U256}; use std::cmp; use super::stack::VecStack; -use evm; -use instructions::{self, Instruction, InstructionInfo}; -use interpreter::stack::Stack; +use crate::evm; +use crate::instructions::{self, Instruction, InstructionInfo}; +use crate::interpreter::stack::Stack; use vm::{self, Schedule}; macro_rules! overflowing { @@ -34,7 +34,7 @@ macro_rules! overflowing { }}; } -enum Request { +enum Request { Gas(Cost), GasMem(Cost, Cost), GasMemProvide(Cost, Cost, Option), diff --git a/crates/vm/evm/src/interpreter/informant.rs b/crates/vm/evm/src/interpreter/informant.rs index 03ae36951..5724afd04 100644 --- a/crates/vm/evm/src/interpreter/informant.rs +++ b/crates/vm/evm/src/interpreter/informant.rs @@ -43,7 +43,7 @@ mod inner { use ethereum_types::U256; - use instructions::{Instruction, InstructionInfo}; + use crate::instructions::{Instruction, InstructionInfo}; use interpreter::stack::Stack; use CostType; diff --git a/crates/vm/evm/src/interpreter/mod.rs b/crates/vm/evm/src/interpreter/mod.rs index 827393ac7..b7d7a3b39 100644 --- a/crates/vm/evm/src/interpreter/mod.rs +++ b/crates/vm/evm/src/interpreter/mod.rs @@ -34,8 +34,8 @@ use vm::{ GasLeft, MessageCallResult, ParamsType, ReturnData, Schedule, TrapError, TrapKind, }; -use evm::CostType; -use instructions::{self, Instruction, InstructionInfo}; +use crate::evm::CostType; +use crate::instructions::{self, Instruction, InstructionInfo}; pub use self::shared_cache::SharedCache; use self::{ diff --git a/crates/vm/evm/src/interpreter/stack.rs b/crates/vm/evm/src/interpreter/stack.rs index 86c890863..ee23c5a31 100644 --- a/crates/vm/evm/src/interpreter/stack.rs +++ b/crates/vm/evm/src/interpreter/stack.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use instructions; +use crate::instructions; use std::fmt; /// Stack trait with VM-friendly API From dc7b8589107fe472ffb25588982aa5ef12395779 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 11:04:42 +0100 Subject: [PATCH 376/687] cleanup unnessary ref --- crates/vm/evm/src/interpreter/shared_cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/vm/evm/src/interpreter/shared_cache.rs b/crates/vm/evm/src/interpreter/shared_cache.rs index cc25ff464..3a016e877 100644 --- a/crates/vm/evm/src/interpreter/shared_cache.rs +++ b/crates/vm/evm/src/interpreter/shared_cache.rs @@ -74,7 +74,7 @@ impl SharedCache { let d = Self::find_jump_and_sub_destinations(code); - if let Some(ref code_hash) = code_hash { + if let Some(code_hash) = code_hash { self.jump_destinations.lock().insert(*code_hash, d.clone()); } From e560cca777671f97f33901bb89a33605bc826b77 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 11:06:36 +0100 Subject: [PATCH 377/687] cargo edition fixes (cargo fix --edition) --- bin/oe/account_utils.rs | 2 +- bin/oe/configuration.rs | 2 +- bin/oe/presale.rs | 4 ++-- bin/oe/reserved_peer_management.rs | 4 ++-- bin/oe/run.rs | 2 +- bin/oe/secretstore.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/oe/account_utils.rs b/bin/oe/account_utils.rs index 4b9415466..1011c3890 100644 --- a/bin/oe/account_utils.rs +++ b/bin/oe/account_utils.rs @@ -16,7 +16,7 @@ use std::sync::Arc; -use crypto::publickey; +use crate::crypto::publickey; use dir::Directories; use ethereum_types::{Address, H160}; use ethkey::Password; diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 21f8cd58d..4dbb57c7f 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -24,7 +24,7 @@ use crate::{ }; use ansi_term::Colour; -use crypto::publickey::{Public, Secret}; +use crate::crypto::publickey::{Public, Secret}; use ethcore::{ client::VMType, miner::{stratum, MinerOptions}, diff --git a/bin/oe/presale.rs b/bin/oe/presale.rs index c44c9fd1c..5fb83aa24 100644 --- a/bin/oe/presale.rs +++ b/bin/oe/presale.rs @@ -18,7 +18,7 @@ use crate::{ helpers::{password_from_file, password_prompt}, params::SpecType, }; -use crypto::publickey; +use crate::crypto::publickey; use ethkey::Password; use ethstore::PresaleWallet; @@ -50,7 +50,7 @@ pub fn execute(cmd: ImportWallet) -> Result { #[cfg(feature = "accounts")] pub fn import_account(cmd: &ImportWallet, kp: publickey::KeyPair, password: Password) { - use accounts::{AccountProvider, AccountProviderSettings}; + use crate::accounts::{AccountProvider, AccountProviderSettings}; use ethstore::{accounts_dir::RootDiskDirectory, EthStore}; let dir = Box::new(RootDiskDirectory::create(cmd.path.clone()).unwrap()); diff --git a/bin/oe/reserved_peer_management.rs b/bin/oe/reserved_peer_management.rs index 2d9ba32d3..d5abff2bf 100644 --- a/bin/oe/reserved_peer_management.rs +++ b/bin/oe/reserved_peer_management.rs @@ -100,13 +100,13 @@ impl ReservedPeersManagement for ReservedPeersWrapper { #[cfg(test)] mod tests { use super::*; - use network::{NetworkContext, ProtocolId}; + use crate::network::{NetworkContext, ProtocolId}; use std::{ net::{Ipv4Addr, SocketAddrV4}, ops::RangeInclusive, sync::Arc, }; - use sync::ManageNetwork; + use crate::sync::ManageNetwork; pub struct TestManageNetwork; diff --git a/bin/oe/run.rs b/bin/oe/run.rs index ff19042e2..05222d701 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -59,7 +59,7 @@ use node_filter::NodeFilter; use parity_rpc::{informant, is_major_importing, NetworkSettings}; use parity_runtime::Runtime; use parity_version::version; -use sync::SyncState; +use crate::sync::SyncState; // How often we attempt to take a snapshot: only snapshot on blocknumbers that are multiples of this. const SNAPSHOT_PERIOD: u64 = 20000; diff --git a/bin/oe/secretstore.rs b/bin/oe/secretstore.rs index d62cd844f..207dab7a0 100644 --- a/bin/oe/secretstore.rs +++ b/bin/oe/secretstore.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use crate::{account_utils::AccountProvider, sync::SyncProvider}; -use crypto::publickey::{Public, Secret}; +use crate::crypto::publickey::{Public, Secret}; use dir::{default_data_path, helpers::replace_home}; use ethcore::{client::Client, miner::Miner}; use ethereum_types::Address; From e054e1588c3334ed00a14216217159701bcdfb8e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 11:10:18 +0100 Subject: [PATCH 378/687] crate fixes --- crates/accounts/ethstore/src/accounts_dir/disk.rs | 2 +- crates/accounts/ethstore/src/secret_store.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/accounts/ethstore/src/accounts_dir/disk.rs b/crates/accounts/ethstore/src/accounts_dir/disk.rs index 13a8b7c28..71d280dc2 100644 --- a/crates/accounts/ethstore/src/accounts_dir/disk.rs +++ b/crates/accounts/ethstore/src/accounts_dir/disk.rs @@ -59,7 +59,7 @@ pub fn find_unique_filename_using_random_suffix( )); } - let suffix = ::random::random_string(4); + let suffix = crate::random::random_string(4); deduped_filename = format!("{}-{}", original_filename, suffix); path.set_file_name(&deduped_filename); retries += 1; diff --git a/crates/accounts/ethstore/src/secret_store.rs b/crates/accounts/ethstore/src/secret_store.rs index 36c6f9ed5..7d712cc51 100644 --- a/crates/accounts/ethstore/src/secret_store.rs +++ b/crates/accounts/ethstore/src/secret_store.rs @@ -17,14 +17,14 @@ use crypto::publickey::{Address, Message, Public, Secret, Signature}; use ethereum_types::H256; use ethkey::Password; -use json::{OpaqueKeyFile, Uuid}; +use crate::json::{OpaqueKeyFile, Uuid}; use std::{ cmp::Ordering, hash::{Hash, Hasher}, path::PathBuf, }; -use Error; -use OpaqueSecret; +use crate::Error; +use crate::OpaqueSecret; /// Key directory reference #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] From 0eca8c9f0014c8ba703873b96201484b65278213 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 11:12:09 +0100 Subject: [PATCH 379/687] crate:: for ethstore uses --- crates/accounts/ethstore/src/ethstore.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/accounts/ethstore/src/ethstore.rs b/crates/accounts/ethstore/src/ethstore.rs index bf674e458..59453594f 100644 --- a/crates/accounts/ethstore/src/ethstore.rs +++ b/crates/accounts/ethstore/src/ethstore.rs @@ -22,22 +22,22 @@ use std::{ time::{Duration, Instant}, }; -use account::SafeAccount; -use accounts_dir::{KeyDirectory, SetKeyError, VaultKey, VaultKeyDirectory}; +use crate::account::SafeAccount; +use crate::accounts_dir::{KeyDirectory, SetKeyError, VaultKey, VaultKeyDirectory}; use crypto::publickey::{ self, Address, ExtendedKeyPair, KeyPair, Message, Public, Secret, Signature, }; use ethkey::Password; use json::{self, OpaqueKeyFile, Uuid}; -use presale::PresaleWallet; -use random::Random; -use Derivation; -use Error; -use OpaqueSecret; -use SecretStore; -use SecretVaultRef; -use SimpleSecretStore; -use StoreAccountRef; +use crate::presale::PresaleWallet; +use crate::random::Random; +use crate::Derivation; +use crate::Error; +use crate::OpaqueSecret; +use crate::SecretStore; +use crate::SecretVaultRef; +use crate::SimpleSecretStore; +use crate::StoreAccountRef; lazy_static! { static ref KEY_ITERATIONS: NonZeroU32 = From 101cd81fc10cc98c2fadeeffa073082d42e74704 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 11:13:06 +0100 Subject: [PATCH 380/687] ethstore use fixes --- crates/accounts/ethstore/src/ethstore.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/accounts/ethstore/src/ethstore.rs b/crates/accounts/ethstore/src/ethstore.rs index 59453594f..43a2b6420 100644 --- a/crates/accounts/ethstore/src/ethstore.rs +++ b/crates/accounts/ethstore/src/ethstore.rs @@ -28,7 +28,7 @@ use crypto::publickey::{ self, Address, ExtendedKeyPair, KeyPair, Message, Public, Secret, Signature, }; use ethkey::Password; -use json::{self, OpaqueKeyFile, Uuid}; +use crate::json::{self, OpaqueKeyFile, Uuid}; use crate::presale::PresaleWallet; use crate::random::Random; use crate::Derivation; @@ -898,10 +898,10 @@ mod tests { use self::tempdir::TempDir; use super::{EthMultiStore, EthStore}; - use accounts_dir::{KeyDirectory, MemoryDirectory, RootDiskDirectory}; + use crate::accounts_dir::{KeyDirectory, MemoryDirectory, RootDiskDirectory}; use crypto::publickey::{Generator, KeyPair, Random}; use ethereum_types::H256; - use secret_store::{ + use crate::secret_store::{ Derivation, SecretStore, SecretVaultRef, SimpleSecretStore, StoreAccountRef, }; From 2dc1397e15d4d93086ddd3c438571d09b781455b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 11:13:45 +0100 Subject: [PATCH 381/687] crate:: --- crates/accounts/ethstore/src/account/safe_account.rs | 6 +++--- crates/accounts/ethstore/src/account/version.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/accounts/ethstore/src/account/safe_account.rs b/crates/accounts/ethstore/src/account/safe_account.rs index 89b4d17a5..c5940a4f1 100644 --- a/crates/accounts/ethstore/src/account/safe_account.rs +++ b/crates/accounts/ethstore/src/account/safe_account.rs @@ -15,15 +15,15 @@ // along with OpenEthereum. If not, see . use super::crypto::Crypto; -use account::Version; +use crate::account::Version; use crypto::{ self, publickey::{ecdh::agree, sign, Address, KeyPair, Message, Public, Secret, Signature}, }; use ethkey::Password; -use json; +use crate::json; use std::num::NonZeroU32; -use Error; +use crate::Error; /// Account representation. #[derive(Debug, PartialEq, Clone)] diff --git a/crates/accounts/ethstore/src/account/version.rs b/crates/accounts/ethstore/src/account/version.rs index 514873868..b68e25812 100644 --- a/crates/accounts/ethstore/src/account/version.rs +++ b/crates/accounts/ethstore/src/account/version.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use json; +use crate::json; #[derive(Debug, PartialEq, Clone)] pub enum Version { From 90d40a3a43d56cc69b9fdb5178cdcfaaba47abe0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 11:16:40 +0100 Subject: [PATCH 382/687] further use crate:: --- crates/accounts/ethstore/src/account/cipher.rs | 2 +- crates/accounts/ethstore/src/account/crypto.rs | 8 ++++---- crates/accounts/ethstore/src/account/kdf.rs | 2 +- crates/accounts/ethstore/src/accounts_dir/disk.rs | 8 ++++---- crates/accounts/ethstore/src/accounts_dir/memory.rs | 4 ++-- crates/accounts/ethstore/src/accounts_dir/mod.rs | 2 +- crates/accounts/ethstore/src/accounts_dir/vault.rs | 4 ++-- crates/accounts/ethstore/src/ethkey.rs | 2 +- crates/accounts/ethstore/src/import.rs | 2 +- crates/accounts/ethstore/src/presale.rs | 6 +++--- crates/concensus/miner/src/pool/verifier.rs | 2 +- crates/ethcore/service/src/service.rs | 2 +- crates/vm/evm/src/interpreter/shared_cache.rs | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/accounts/ethstore/src/account/cipher.rs b/crates/accounts/ethstore/src/account/cipher.rs index ba3c1e705..2407f1053 100644 --- a/crates/accounts/ethstore/src/account/cipher.rs +++ b/crates/accounts/ethstore/src/account/cipher.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use json; +use crate::json; #[derive(Debug, PartialEq, Clone)] pub struct Aes128Ctr { diff --git a/crates/accounts/ethstore/src/account/crypto.rs b/crates/accounts/ethstore/src/account/crypto.rs index ea5149c8f..852a3ee7a 100644 --- a/crates/accounts/ethstore/src/account/crypto.rs +++ b/crates/accounts/ethstore/src/account/crypto.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use account::{Aes128Ctr, Cipher, Kdf, Pbkdf2, Prf}; +use crate::account::{Aes128Ctr, Cipher, Kdf, Pbkdf2, Prf}; use crypto::{self, publickey::Secret, Keccak256}; use ethkey::Password; -use json; -use random::Random; +use crate::json; +use crate::random::Random; use smallvec::SmallVec; use std::{num::NonZeroU32, str}; -use Error; +use crate::Error; /// Encrypted data #[derive(Debug, PartialEq, Clone)] diff --git a/crates/accounts/ethstore/src/account/kdf.rs b/crates/accounts/ethstore/src/account/kdf.rs index 2841f1776..080dc15f5 100644 --- a/crates/accounts/ethstore/src/account/kdf.rs +++ b/crates/accounts/ethstore/src/account/kdf.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use json; +use crate::json; use std::num::NonZeroU32; #[derive(Debug, PartialEq, Clone)] diff --git a/crates/accounts/ethstore/src/accounts_dir/disk.rs b/crates/accounts/ethstore/src/accounts_dir/disk.rs index 71d280dc2..42366a3b3 100644 --- a/crates/accounts/ethstore/src/accounts_dir/disk.rs +++ b/crates/accounts/ethstore/src/accounts_dir/disk.rs @@ -19,7 +19,7 @@ use super::{ KeyDirectory, VaultKey, VaultKeyDirectory, VaultKeyDirectoryProvider, }; use ethkey::Password; -use json::{self, Uuid}; +use crate::json::{self, Uuid}; use std::{ collections::HashMap, fs, io, @@ -27,8 +27,8 @@ use std::{ path::{Path, PathBuf}, }; use time; -use Error; -use SafeAccount; +use crate::Error; +use crate::SafeAccount; const IGNORED_FILES: &'static [&'static str] = &[ "thumbs.db", @@ -419,7 +419,7 @@ mod test { use self::tempdir::TempDir; use super::{KeyDirectory, RootDiskDirectory, VaultKey}; - use account::SafeAccount; + use crate::account::SafeAccount; use crypto::publickey::{Generator, Random}; use std::{env, fs, num::NonZeroU32}; diff --git a/crates/accounts/ethstore/src/accounts_dir/memory.rs b/crates/accounts/ethstore/src/accounts_dir/memory.rs index 73f48ef7c..8d5234a95 100644 --- a/crates/accounts/ethstore/src/accounts_dir/memory.rs +++ b/crates/accounts/ethstore/src/accounts_dir/memory.rs @@ -20,8 +20,8 @@ use parking_lot::RwLock; use std::collections::HashMap; use super::KeyDirectory; -use Error; -use SafeAccount; +use crate::Error; +use crate::SafeAccount; /// Accounts in-memory storage. #[derive(Default)] diff --git a/crates/accounts/ethstore/src/accounts_dir/mod.rs b/crates/accounts/ethstore/src/accounts_dir/mod.rs index 29fc50f2b..afece175a 100644 --- a/crates/accounts/ethstore/src/accounts_dir/mod.rs +++ b/crates/accounts/ethstore/src/accounts_dir/mod.rs @@ -18,7 +18,7 @@ use ethkey::Password; use std::{num::NonZeroU32, path::PathBuf}; -use Error; +use crate::Error; use SafeAccount; mod disk; diff --git a/crates/accounts/ethstore/src/accounts_dir/vault.rs b/crates/accounts/ethstore/src/accounts_dir/vault.rs index 3c4cf3f5a..cedde0cf9 100644 --- a/crates/accounts/ethstore/src/accounts_dir/vault.rs +++ b/crates/accounts/ethstore/src/accounts_dir/vault.rs @@ -20,13 +20,13 @@ use super::{ KeyDirectory, SetKeyError, VaultKey, VaultKeyDirectory, }; use crypto::Keccak256; -use json; +use crate::json; use parking_lot::Mutex; use std::{ fs, io, path::{Path, PathBuf}, }; -use Error; +use crate::Error; use SafeAccount; /// Name of vault metadata file diff --git a/crates/accounts/ethstore/src/ethkey.rs b/crates/accounts/ethstore/src/ethkey.rs index aed0695bb..0290412d7 100644 --- a/crates/accounts/ethstore/src/ethkey.rs +++ b/crates/accounts/ethstore/src/ethkey.rs @@ -17,7 +17,7 @@ //! ethkey reexport to make documentation look pretty. pub use _ethkey::*; pub use crypto::publickey::Address; -use json; +use crate::json; impl Into for Address { fn into(self) -> json::H160 { diff --git a/crates/accounts/ethstore/src/import.rs b/crates/accounts/ethstore/src/import.rs index 20cbcd787..1ad56ca24 100644 --- a/crates/accounts/ethstore/src/import.rs +++ b/crates/accounts/ethstore/src/import.rs @@ -18,7 +18,7 @@ use std::{collections::HashSet, fs, path::Path}; use accounts_dir::{DiskKeyFileManager, KeyDirectory, KeyFileManager}; use crypto::publickey::Address; -use Error; +use crate::Error; /// Import an account from a file. pub fn import_account(path: &Path, dst: &dyn KeyDirectory) -> Result { diff --git a/crates/accounts/ethstore/src/presale.rs b/crates/accounts/ethstore/src/presale.rs index 45cc0de5d..9cd731ed8 100644 --- a/crates/accounts/ethstore/src/presale.rs +++ b/crates/accounts/ethstore/src/presale.rs @@ -20,9 +20,9 @@ use crypto::{ Keccak256, }; use ethkey::Password; -use json; +use crate::json; use std::{fs, num::NonZeroU32, path::Path}; -use Error; +use crate::Error; /// Pre-sale wallet. pub struct PresaleWallet { @@ -87,7 +87,7 @@ impl PresaleWallet { #[cfg(test)] mod tests { use super::PresaleWallet; - use json; + use crate::json; #[test] fn test() { diff --git a/crates/concensus/miner/src/pool/verifier.rs b/crates/concensus/miner/src/pool/verifier.rs index 4e06e5d07..db56de9a3 100644 --- a/crates/concensus/miner/src/pool/verifier.rs +++ b/crates/concensus/miner/src/pool/verifier.rs @@ -206,7 +206,7 @@ impl Verifier { } impl txpool::Verifier - for Verifier + for Verifier { type Error = transaction::Error; type VerifiedTransaction = VerifiedTransaction; diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index 3dd2986f5..f4c046676 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -35,7 +35,7 @@ use ethcore::{ spec::Spec, }; -use Error; +use crate::Error; /// Client service setup. Creates and registers client and network services with the IO subsystem. pub struct ClientService { diff --git a/crates/vm/evm/src/interpreter/shared_cache.rs b/crates/vm/evm/src/interpreter/shared_cache.rs index 3a016e877..20cd808ab 100644 --- a/crates/vm/evm/src/interpreter/shared_cache.rs +++ b/crates/vm/evm/src/interpreter/shared_cache.rs @@ -61,7 +61,7 @@ impl SharedCache { code_hash: &Option, code: &[u8], ) -> (Arc, Arc) { - if let Some(ref code_hash) = code_hash { + if let Some(code_hash) = code_hash { if code_hash == &KECCAK_EMPTY { let cache_item = Self::find_jump_and_sub_destinations(code); return (cache_item.jump_destination.0, cache_item.sub_entrypoint.0); From 532955e2c92ade11f6463c07a7749bc35cf69fb6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 11:18:41 +0100 Subject: [PATCH 383/687] further crate:: fixes --- crates/accounts/ethstore/src/accounts_dir/mod.rs | 2 +- crates/accounts/ethstore/src/accounts_dir/vault.rs | 2 +- crates/accounts/ethstore/src/import.rs | 2 +- crates/concensus/miner/src/pool/listener.rs | 2 +- crates/concensus/miner/src/pool/local_transactions.rs | 2 +- crates/concensus/miner/src/pool/queue.rs | 4 ++-- crates/concensus/miner/src/pool/ready.rs | 2 +- crates/concensus/miner/src/pool/replace.rs | 2 +- crates/concensus/miner/src/pool/scoring.rs | 2 +- crates/concensus/miner/src/pool/tests/client.rs | 2 +- crates/concensus/miner/src/pool/tests/mod.rs | 2 +- crates/concensus/miner/src/pool/tests/tx.rs | 2 +- crates/concensus/miner/src/pool/transaction_filter.rs | 2 +- 13 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/accounts/ethstore/src/accounts_dir/mod.rs b/crates/accounts/ethstore/src/accounts_dir/mod.rs index afece175a..2eff6f09e 100644 --- a/crates/accounts/ethstore/src/accounts_dir/mod.rs +++ b/crates/accounts/ethstore/src/accounts_dir/mod.rs @@ -19,7 +19,7 @@ use ethkey::Password; use std::{num::NonZeroU32, path::PathBuf}; use crate::Error; -use SafeAccount; +use crate::SafeAccount; mod disk; mod memory; diff --git a/crates/accounts/ethstore/src/accounts_dir/vault.rs b/crates/accounts/ethstore/src/accounts_dir/vault.rs index cedde0cf9..17a330f19 100644 --- a/crates/accounts/ethstore/src/accounts_dir/vault.rs +++ b/crates/accounts/ethstore/src/accounts_dir/vault.rs @@ -27,7 +27,7 @@ use std::{ path::{Path, PathBuf}, }; use crate::Error; -use SafeAccount; +use crate::SafeAccount; /// Name of vault metadata file pub const VAULT_FILE_NAME: &'static str = "vault.json"; diff --git a/crates/accounts/ethstore/src/import.rs b/crates/accounts/ethstore/src/import.rs index 1ad56ca24..5346950ec 100644 --- a/crates/accounts/ethstore/src/import.rs +++ b/crates/accounts/ethstore/src/import.rs @@ -16,7 +16,7 @@ use std::{collections::HashSet, fs, path::Path}; -use accounts_dir::{DiskKeyFileManager, KeyDirectory, KeyFileManager}; +use crate::accounts_dir::{DiskKeyFileManager, KeyDirectory, KeyFileManager}; use crypto::publickey::Address; use crate::Error; diff --git a/crates/concensus/miner/src/pool/listener.rs b/crates/concensus/miner/src/pool/listener.rs index 5d1b936b9..3f27e6a6b 100644 --- a/crates/concensus/miner/src/pool/listener.rs +++ b/crates/concensus/miner/src/pool/listener.rs @@ -21,7 +21,7 @@ use std::{fmt, sync::Arc}; use ethereum_types::H256; use txpool::{self, VerifiedTransaction}; -use pool::VerifiedTransaction as Transaction; +use crate::pool::VerifiedTransaction as Transaction; type Listener = Box; diff --git a/crates/concensus/miner/src/pool/local_transactions.rs b/crates/concensus/miner/src/pool/local_transactions.rs index c9309a9bb..7d510db6e 100644 --- a/crates/concensus/miner/src/pool/local_transactions.rs +++ b/crates/concensus/miner/src/pool/local_transactions.rs @@ -20,7 +20,7 @@ use std::{fmt, sync::Arc}; use ethereum_types::H256; use linked_hash_map::LinkedHashMap; -use pool::{ScoredTransaction, VerifiedTransaction as Transaction}; +use crate::pool::{ScoredTransaction, VerifiedTransaction as Transaction}; use txpool::{self, VerifiedTransaction}; /// Status of local transaction. diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index 6238e5ea9..5651e0a8a 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -32,7 +32,7 @@ use parking_lot::RwLock; use txpool::{self, Verifier}; use types::transaction; -use pool::{ +use crate::pool::{ self, client, listener, local_transactions::LocalTransactionsList, ready, replace, scoring, @@ -814,7 +814,7 @@ fn convert_error(err: txpool::Error) -> transa #[cfg(test)] mod tests { use super::*; - use pool::tests::client::TestClient; + use crate::pool::tests::client::TestClient; #[test] fn should_get_pending_transactions() { diff --git a/crates/concensus/miner/src/pool/ready.rs b/crates/concensus/miner/src/pool/ready.rs index d8914be5c..86c3775f9 100644 --- a/crates/concensus/miner/src/pool/ready.rs +++ b/crates/concensus/miner/src/pool/ready.rs @@ -165,7 +165,7 @@ impl Option> txpool::Ready for Opt #[cfg(test)] mod tests { use super::*; - use pool::tests::{ + use crate::pool::tests::{ client::TestClient, tx::{Tx, TxExt}, }; diff --git a/crates/concensus/miner/src/pool/replace.rs b/crates/concensus/miner/src/pool/replace.rs index ac104580d..9b66762f6 100644 --- a/crates/concensus/miner/src/pool/replace.rs +++ b/crates/concensus/miner/src/pool/replace.rs @@ -240,7 +240,7 @@ mod tests { use super::*; use crypto::publickey::{Generator, KeyPair, Random}; - use pool::{ + use crate::pool::{ scoring::*, tests::{ client::TestClient, diff --git a/crates/concensus/miner/src/pool/scoring.rs b/crates/concensus/miner/src/pool/scoring.rs index c8ef7ade5..83e20e927 100644 --- a/crates/concensus/miner/src/pool/scoring.rs +++ b/crates/concensus/miner/src/pool/scoring.rs @@ -182,7 +182,7 @@ where mod tests { use super::*; - use pool::tests::tx::{Tx, TxExt}; + use crate::pool::tests::tx::{Tx, TxExt}; use std::sync::Arc; use txpool::Scoring; diff --git a/crates/concensus/miner/src/pool/tests/client.rs b/crates/concensus/miner/src/pool/tests/client.rs index 1d2fd9ede..e11adc4c4 100644 --- a/crates/concensus/miner/src/pool/tests/client.rs +++ b/crates/concensus/miner/src/pool/tests/client.rs @@ -22,7 +22,7 @@ use types::transaction::{ self, SignedTransaction, Transaction, TypedTransaction, UnverifiedTransaction, }; -use pool::{self, client::AccountDetails}; +use crate::pool::{self, client::AccountDetails}; const MAX_TRANSACTION_SIZE: usize = 15 * 1024; diff --git a/crates/concensus/miner/src/pool/tests/mod.rs b/crates/concensus/miner/src/pool/tests/mod.rs index a31cefa25..a0ca385c5 100644 --- a/crates/concensus/miner/src/pool/tests/mod.rs +++ b/crates/concensus/miner/src/pool/tests/mod.rs @@ -19,7 +19,7 @@ use hash::KECCAK_EMPTY; use txpool; use types::transaction::{self, PendingTransaction}; -use pool::{ +use crate::pool::{ transaction_filter::TransactionFilter, verifier, PendingOrdering, PendingSettings, PrioritizationStrategy, TransactionQueue, }; diff --git a/crates/concensus/miner/src/pool/tests/tx.rs b/crates/concensus/miner/src/pool/tests/tx.rs index 9a55d8d29..fb17fd60b 100644 --- a/crates/concensus/miner/src/pool/tests/tx.rs +++ b/crates/concensus/miner/src/pool/tests/tx.rs @@ -22,7 +22,7 @@ use types::transaction::{ UnverifiedTransaction, }; -use pool::{verifier, VerifiedTransaction}; +use crate::pool::{verifier, VerifiedTransaction}; #[derive(Clone)] pub struct Tx { diff --git a/crates/concensus/miner/src/pool/transaction_filter.rs b/crates/concensus/miner/src/pool/transaction_filter.rs index b261fd08a..18ab966df 100644 --- a/crates/concensus/miner/src/pool/transaction_filter.rs +++ b/crates/concensus/miner/src/pool/transaction_filter.rs @@ -20,7 +20,7 @@ use ethereum_types::{Address, U256}; -use pool::VerifiedTransaction; +use crate::pool::VerifiedTransaction; use types::transaction::Action; #[allow(non_camel_case_types)] From fd0b1fc9b5a31da44c20ba463a90b8417f446191 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 11:19:54 +0100 Subject: [PATCH 384/687] fixed crate::, fir compiling version --- crates/concensus/miner/src/gas_pricer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/concensus/miner/src/gas_pricer.rs b/crates/concensus/miner/src/gas_pricer.rs index 6e60c447b..330eb56f5 100644 --- a/crates/concensus/miner/src/gas_pricer.rs +++ b/crates/concensus/miner/src/gas_pricer.rs @@ -18,7 +18,7 @@ use ethereum_types::U256; #[cfg(feature = "price-info")] -use gas_price_calibrator::GasPriceCalibrator; +use crate::gas_price_calibrator::GasPriceCalibrator; /// Struct to look after updating the acceptable gas price of a miner. #[derive(Debug, PartialEq)] From 60058fbf9a3b179e8e06fb0a5b4991ddee2e2d06 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 12:13:33 +0100 Subject: [PATCH 385/687] feature definitions --- Cargo.toml | 1 + crates/rpc/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 17792a291..371c7bfad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -111,6 +111,7 @@ deadlock_detection = ["parking_lot/deadlock_detection"] # `valgrind --tool=massif /path/to/parity ` # and `massif-visualizer` for visualization memory_profiling = [] +secretstore = [] [lib] path = "bin/oe/lib.rs" diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index 0ab40ff95..b019cd788 100644 --- a/crates/rpc/Cargo.toml +++ b/crates/rpc/Cargo.toml @@ -72,3 +72,4 @@ tempdir = "0.3.7" [features] accounts = ["ethcore-accounts"] +test-helpers = [] \ No newline at end of file From f454241b2b3b5ac66d3a9bfe308a6406127138fd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Mar 2025 12:16:04 +0100 Subject: [PATCH 386/687] removed TestPasswordReader --- bin/oe/configuration.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 4dbb57c7f..eb8543122 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -1283,9 +1283,6 @@ mod tests { static ref ITERATIONS: NonZeroU32 = NonZeroU32::new(10240).expect("10240 > 0; qed"); } - #[derive(Debug, PartialEq)] - struct TestPasswordReader(&'static str); - fn parse(args: &[&str]) -> Configuration { Configuration { args: Args::parse_without_config(args).unwrap(), From 97bad3f50995b0e875c49038caf95d6a72c41758 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Apr 2025 17:05:41 +0200 Subject: [PATCH 387/687] allow dead code for upgrade errors --- bin/oe/upgrade.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/oe/upgrade.rs b/bin/oe/upgrade.rs index c1a38d2c2..e6f62fb65 100644 --- a/bin/oe/upgrade.rs +++ b/bin/oe/upgrade.rs @@ -27,6 +27,7 @@ use std::{ path::{Path, PathBuf}, }; +#[allow(dead_code)] #[derive(Debug)] pub enum Error { CannotCreateConfigPath(io::Error), From 3d96b760f73e4d2bf3737b6e19728c93b4aa2df9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Apr 2025 17:05:56 +0200 Subject: [PATCH 388/687] rust edition 2018 --- bin/chainspec/Cargo.toml | 2 +- crates/accounts/ethstore/Cargo.toml | 2 +- crates/concensus/miner/Cargo.toml | 2 +- crates/concensus/miner/price-info/Cargo.toml | 2 +- crates/db/blooms-db/Cargo.toml | 2 +- crates/db/patricia-trie-ethereum/Cargo.toml | 2 +- crates/net/fetch/Cargo.toml | 2 +- crates/rpc-common/Cargo.toml | 2 +- crates/rpc-servers/Cargo.toml | 2 +- crates/util/stats/Cargo.toml | 2 +- crates/vm/evm/Cargo.toml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/chainspec/Cargo.toml b/bin/chainspec/Cargo.toml index ea58e7bd1..59d8e69d1 100644 --- a/bin/chainspec/Cargo.toml +++ b/bin/chainspec/Cargo.toml @@ -2,7 +2,7 @@ description = "Parity Ethereum Chain Specification" name = "chainspec" version = "0.1.0" -edition = "2024" +edition = "2018" authors = ["Marek Kotewicz "] [dependencies] diff --git a/crates/accounts/ethstore/Cargo.toml b/crates/accounts/ethstore/Cargo.toml index e09d4ab61..2cb224048 100644 --- a/crates/accounts/ethstore/Cargo.toml +++ b/crates/accounts/ethstore/Cargo.toml @@ -3,7 +3,7 @@ description = "Parity Ethereum Key Management" name = "ethstore" version = "0.2.1" authors = ["Parity Technologies "] -edition = "2024" +edition = "2018" [dependencies] log = "0.4" diff --git a/crates/concensus/miner/Cargo.toml b/crates/concensus/miner/Cargo.toml index f39981848..d5c9b13d9 100644 --- a/crates/concensus/miner/Cargo.toml +++ b/crates/concensus/miner/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "diamond-node Miner Interface." name = "ethcore-miner" -edition = "2024" +edition = "2018" homepage = "https://github.com/dmdcoin/diamond-node" license = "GPL-3.0" version = "1.12.0" diff --git a/crates/concensus/miner/price-info/Cargo.toml b/crates/concensus/miner/price-info/Cargo.toml index 064753808..7ed267791 100644 --- a/crates/concensus/miner/price-info/Cargo.toml +++ b/crates/concensus/miner/price-info/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "price-info" version = "1.12.0" authors = ["Parity Technologies "] -edition = "2024" +edition = "2018" [dependencies] fetch = { path = "../../../net/fetch" } diff --git a/crates/db/blooms-db/Cargo.toml b/crates/db/blooms-db/Cargo.toml index b37cc2af0..55aa8b005 100644 --- a/crates/db/blooms-db/Cargo.toml +++ b/crates/db/blooms-db/Cargo.toml @@ -3,7 +3,7 @@ name = "blooms-db" version = "0.1.0" license = "GPL-3.0" authors = ["Parity Technologies "] -edition = "2024" +edition = "2018" [dependencies] byteorder = "1.2" diff --git a/crates/db/patricia-trie-ethereum/Cargo.toml b/crates/db/patricia-trie-ethereum/Cargo.toml index 9f8dc4526..966fd548b 100644 --- a/crates/db/patricia-trie-ethereum/Cargo.toml +++ b/crates/db/patricia-trie-ethereum/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] description = "Merkle-Patricia Trie (Ethereum Style)" license = "GPL-3.0" -edition = "2024" +edition = "2018" [dependencies] trie-db = "0.11.0" diff --git a/crates/net/fetch/Cargo.toml b/crates/net/fetch/Cargo.toml index 53cb9acbf..4f19bb2d2 100644 --- a/crates/net/fetch/Cargo.toml +++ b/crates/net/fetch/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "fetch" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2024" +edition = "2018" [dependencies] futures = "0.1" diff --git a/crates/rpc-common/Cargo.toml b/crates/rpc-common/Cargo.toml index 2105b8793..e9cd18850 100644 --- a/crates/rpc-common/Cargo.toml +++ b/crates/rpc-common/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "oe-rpc-common" version = "0.0.0" -edition = "2021" +edition = "2018" description = "Modules common to RPC APIs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/crates/rpc-servers/Cargo.toml b/crates/rpc-servers/Cargo.toml index 4e042eb2c..e3c3fe70f 100644 --- a/crates/rpc-servers/Cargo.toml +++ b/crates/rpc-servers/Cargo.toml @@ -3,7 +3,7 @@ description = "diamond-node RPC servers (WS, HTTP, IPC)" name = "oe-rpc-servers" version = "0.0.0" license = "GPL-3.0" -edition = "2021" +edition = "2018" [lib] diff --git a/crates/util/stats/Cargo.toml b/crates/util/stats/Cargo.toml index ab6f3d2fc..18b954bbf 100644 --- a/crates/util/stats/Cargo.toml +++ b/crates/util/stats/Cargo.toml @@ -2,7 +2,7 @@ name = "stats" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2024" +edition = "2018" [dependencies] log = "0.4" diff --git a/crates/vm/evm/Cargo.toml b/crates/vm/evm/Cargo.toml index 916714c82..78354e8ad 100644 --- a/crates/vm/evm/Cargo.toml +++ b/crates/vm/evm/Cargo.toml @@ -3,7 +3,7 @@ description = "Parity Ethereum Virtual Machine (EVM) Rust Implementation" name = "evm" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2024" +edition = "2018" [dependencies] bit-set = "0.4" From 0b978d654becf85f802b458a02ea7304480400a1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Apr 2025 19:12:25 +0200 Subject: [PATCH 389/687] cargo check --- bin/oe/account_utils.rs | 2 +- bin/oe/blockchain.rs | 4 +- bin/oe/cache.rs | 8 +- bin/oe/cli/mod.rs | 128 +++++++++---------- bin/oe/configuration.rs | 190 ++++++++++++++--------------- bin/oe/db/rocksdb/blooms.rs | 9 +- bin/oe/db/rocksdb/helpers.rs | 10 +- bin/oe/db/rocksdb/migration.rs | 14 +-- bin/oe/db/rocksdb/mod.rs | 2 +- bin/oe/helpers.rs | 14 +-- bin/oe/informant.rs | 25 ++-- bin/oe/main.rs | 9 +- bin/oe/params.rs | 35 ++---- bin/oe/reserved_peer_management.rs | 12 +- bin/oe/rpc.rs | 10 +- bin/oe/rpc_apis.rs | 11 +- bin/oe/run.rs | 10 +- bin/oe/secretstore.rs | 2 +- bin/oe/signer.rs | 4 +- bin/oe/snapshot.rs | 2 +- bin/oe/upgrade.rs | 18 +-- bin/oe/user_defaults.rs | 12 +- 22 files changed, 253 insertions(+), 278 deletions(-) diff --git a/bin/oe/account_utils.rs b/bin/oe/account_utils.rs index 1011c3890..fd1ae28d4 100644 --- a/bin/oe/account_utils.rs +++ b/bin/oe/account_utils.rs @@ -231,7 +231,7 @@ mod accounts { Err(e) => warn!("Unable to add development account: {}", e), Ok(address) => { let _ = account_provider - .set_account_name(address.clone(), "Development Account".into()); + .set_account_name(address, "Development Account".into()); let _ = account_provider.set_account_meta( address, ::serde_json::to_string( diff --git a/bin/oe/blockchain.rs b/bin/oe/blockchain.rs index eb9c10a5c..cd82a102a 100644 --- a/bin/oe/blockchain.rs +++ b/bin/oe/blockchain.rs @@ -436,8 +436,8 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> { let balance = client .balance(&account, at.into()) .unwrap_or_else(U256::zero); - if cmd.min_balance.map_or(false, |m| balance < m) - || cmd.max_balance.map_or(false, |m| balance > m) + if cmd.min_balance.is_some_and(|m| balance < m) + || cmd.max_balance.is_some_and(|m| balance > m) { last = Some(account); continue; //filtered out diff --git a/bin/oe/cache.rs b/bin/oe/cache.rs index 26b34e899..ca2ed6870 100644 --- a/bin/oe/cache.rs +++ b/bin/oe/cache.rs @@ -67,11 +67,11 @@ impl CacheConfig { /// Creates new cache config with gitven details. pub fn new(db: u32, blockchain: u32, queue: u32, state: u32) -> Self { CacheConfig { - db: db, - blockchain: blockchain, - queue: queue, + db, + blockchain, + queue, traces: DEFAULT_TRACE_CACHE_SIZE, - state: state, + state, } } diff --git a/bin/oe/cli/mod.rs b/bin/oe/cli/mod.rs index 6079a663f..fcb93eb82 100644 --- a/bin/oe/cli/mod.rs +++ b/bin/oe/cli/mod.rs @@ -238,11 +238,11 @@ usage! { "--mode=[MODE]", "Set the operating mode. MODE can be one of: last - Uses the last-used mode, active if none; active - Parity continuously syncs the chain; passive - Parity syncs initially, then sleeps and wakes regularly to resync; dark - Parity syncs only when the JSON-RPC is active; offline - Parity doesn't sync.", - ARG arg_mode_timeout: (u64) = 300u64, or |c: &Config| c.parity.as_ref()?.mode_timeout.clone(), + ARG arg_mode_timeout: (u64) = 300u64, or |c: &Config| c.parity.as_ref()?.mode_timeout, "--mode-timeout=[SECS]", "Specify the number of seconds before inactivity timeout occurs when mode is dark or passive", - ARG arg_mode_alarm: (u64) = 3600u64, or |c: &Config| c.parity.as_ref()?.mode_alarm.clone(), + ARG arg_mode_alarm: (u64) = 3600u64, or |c: &Config| c.parity.as_ref()?.mode_alarm, "--mode-alarm=[SECS]", "Specify the number of seconds before auto sleep reawake timeout occurs when mode is passive", @@ -280,15 +280,15 @@ usage! { "Add SHIFT to all port numbers OpenEthereum is listening on. Includes network port and all servers (HTTP JSON-RPC, WebSockets JSON-RPC, SecretStore).", ["Account Options"] - FLAG flag_fast_unlock: (bool) = false, or |c: &Config| c.account.as_ref()?.fast_unlock.clone(), + FLAG flag_fast_unlock: (bool) = false, or |c: &Config| c.account.as_ref()?.fast_unlock, "--fast-unlock", "Use drastically faster unlocking mode. This setting causes raw secrets to be stored unprotected in memory, so use with care.", - ARG arg_keys_iterations: (u32) = 10240u32, or |c: &Config| c.account.as_ref()?.keys_iterations.clone(), + ARG arg_keys_iterations: (u32) = 10240u32, or |c: &Config| c.account.as_ref()?.keys_iterations, "--keys-iterations=[NUM]", "Specify the number of iterations to use when deriving key from the password (bigger is more secure)", - ARG arg_accounts_refresh: (u64) = 5u64, or |c: &Config| c.account.as_ref()?.refresh_time.clone(), + ARG arg_accounts_refresh: (u64) = 5u64, or |c: &Config| c.account.as_ref()?.refresh_time, "--accounts-refresh=[TIME]", "Specify the cache time of accounts read from disk. If you manage thousands of accounts set this to 0 to disable refresh.", @@ -306,15 +306,15 @@ usage! { "Specify directory where Trusted UIs tokens should be stored.", ["Networking Options"] - FLAG flag_no_warp: (bool) = false, or |c: &Config| c.network.as_ref()?.warp.clone().map(|w| !w), + FLAG flag_no_warp: (bool) = false, or |c: &Config| c.network.as_ref()?.warp.map(|w| !w), "--no-warp", "Disable syncing from the snapshot over the network.", - FLAG flag_no_discovery: (bool) = false, or |c: &Config| c.network.as_ref()?.discovery.map(|d| !d).clone(), + FLAG flag_no_discovery: (bool) = false, or |c: &Config| c.network.as_ref()?.discovery.map(|d| !d), "--no-discovery", "Disable new peer discovery.", - FLAG flag_reserved_only: (bool) = false, or |c: &Config| c.network.as_ref()?.reserved_only.clone(), + FLAG flag_reserved_only: (bool) = false, or |c: &Config| c.network.as_ref()?.reserved_only, "--reserved-only", "Connect only to reserved nodes.", @@ -322,11 +322,11 @@ usage! { "--no-ancient-blocks", "Disable downloading old blocks after snapshot restoration or warp sync. Not recommended.", - ARG arg_warp_barrier: (Option) = None, or |c: &Config| c.network.as_ref()?.warp_barrier.clone(), + ARG arg_warp_barrier: (Option) = None, or |c: &Config| c.network.as_ref()?.warp_barrier, "--warp-barrier=[NUM]", "When warp enabled never attempt regular sync before warping to block NUM.", - ARG arg_port: (u16) = 30303u16, or |c: &Config| c.network.as_ref()?.port.clone(), + ARG arg_port: (u16) = 30303u16, or |c: &Config| c.network.as_ref()?.port, "--port=[PORT]", "Override the port on which the node should listen.", @@ -334,15 +334,15 @@ usage! { "--interface=[IP]", "Network interfaces. Valid values are 'all', 'local' or the ip of the interface you want OpenEthereum to listen to.", - ARG arg_min_peers: (Option) = None, or |c: &Config| c.network.as_ref()?.min_peers.clone(), + ARG arg_min_peers: (Option) = None, or |c: &Config| c.network.as_ref()?.min_peers, "--min-peers=[NUM]", "Try to maintain at least NUM peers.", - ARG arg_max_peers: (Option) = None, or |c: &Config| c.network.as_ref()?.max_peers.clone(), + ARG arg_max_peers: (Option) = None, or |c: &Config| c.network.as_ref()?.max_peers, "--max-peers=[NUM]", "Allow up to NUM peers.", - ARG arg_snapshot_peers: (u16) = 0u16, or |c: &Config| c.network.as_ref()?.snapshot_peers.clone(), + ARG arg_snapshot_peers: (u16) = 0u16, or |c: &Config| c.network.as_ref()?.snapshot_peers, "--snapshot-peers=[NUM]", "Allow additional NUM peers for a snapshot sync.", @@ -354,11 +354,11 @@ usage! { "--allow-ips=[FILTER]", "Filter outbound connections. Must be one of: private - connect to private network IP addresses only; public - connect to public network IP addresses only; all - connect to any IP address.", - ARG arg_max_pending_peers: (u16) = 64u16, or |c: &Config| c.network.as_ref()?.max_pending_peers.clone(), + ARG arg_max_pending_peers: (u16) = 64u16, or |c: &Config| c.network.as_ref()?.max_pending_peers, "--max-pending-peers=[NUM]", "Allow up to NUM pending connections.", - ARG arg_network_id: (Option) = None, or |c: &Config| c.network.as_ref()?.id.clone(), + ARG arg_network_id: (Option) = None, or |c: &Config| c.network.as_ref()?.id, "--network-id=[INDEX]", "Override the network identifier from the chain we are on.", @@ -385,11 +385,11 @@ usage! { }, ["API and Console Options – HTTP JSON-RPC"] - FLAG flag_jsonrpc_allow_missing_blocks: (bool) = false, or |c: &Config| c.rpc.as_ref()?.allow_missing_blocks.clone(), + FLAG flag_jsonrpc_allow_missing_blocks: (bool) = false, or |c: &Config| c.rpc.as_ref()?.allow_missing_blocks, "--jsonrpc-allow-missing-blocks", "RPC calls will return 'null' instead of an error if ancient block sync is still in progress and the block information requested could not be found", - FLAG flag_no_jsonrpc: (bool) = false, or |c: &Config| c.rpc.as_ref()?.disable.clone(), + FLAG flag_no_jsonrpc: (bool) = false, or |c: &Config| c.rpc.as_ref()?.disable, "--no-jsonrpc", "Disable the HTTP JSON-RPC API server.", @@ -397,11 +397,11 @@ usage! { "--jsonrpc-no-keep-alive", "Disable HTTP/1.1 keep alive header. Disabling keep alive will prevent re-using the same TCP connection to fire multiple requests, recommended when using one request per connection.", - FLAG flag_jsonrpc_experimental: (bool) = false, or |c: &Config| c.rpc.as_ref()?.experimental_rpcs.clone(), + FLAG flag_jsonrpc_experimental: (bool) = false, or |c: &Config| c.rpc.as_ref()?.experimental_rpcs, "--jsonrpc-experimental", "Enable experimental RPCs. Enable to have access to methods from unfinalised EIPs in all namespaces", - ARG arg_jsonrpc_port: (u16) = 8545u16, or |c: &Config| c.rpc.as_ref()?.port.clone(), + ARG arg_jsonrpc_port: (u16) = 8545u16, or |c: &Config| c.rpc.as_ref()?.port, "--jsonrpc-port=[PORT]", "Specify the port portion of the HTTP JSON-RPC API server.", @@ -433,16 +433,16 @@ usage! { "--jsonrpc-max-payload=[MB]", "Specify maximum size for HTTP JSON-RPC requests in megabytes.", - ARG arg_poll_lifetime: (u32) = 60u32, or |c: &Config| c.rpc.as_ref()?.poll_lifetime.clone(), + ARG arg_poll_lifetime: (u32) = 60u32, or |c: &Config| c.rpc.as_ref()?.poll_lifetime, "--poll-lifetime=[S]", "Set the RPC filter lifetime to S seconds. The filter has to be polled at least every S seconds , otherwise it is removed.", ["API and Console Options – WebSockets"] - FLAG flag_no_ws: (bool) = false, or |c: &Config| c.websockets.as_ref()?.disable.clone(), + FLAG flag_no_ws: (bool) = false, or |c: &Config| c.websockets.as_ref()?.disable, "--no-ws", "Disable the WebSockets JSON-RPC server.", - ARG arg_ws_port: (u16) = 8546u16, or |c: &Config| c.websockets.as_ref()?.port.clone(), + ARG arg_ws_port: (u16) = 8546u16, or |c: &Config| c.websockets.as_ref()?.port, "--ws-port=[PORT]", "Specify the port portion of the WebSockets JSON-RPC server.", @@ -471,7 +471,7 @@ usage! { "Specify maximum size for WS JSON-RPC requests in megabytes.", ["Metrics"] - FLAG flag_metrics: (bool) = false, or |c: &Config| c.metrics.as_ref()?.enable.clone(), + FLAG flag_metrics: (bool) = false, or |c: &Config| c.metrics.as_ref()?.enable, "--metrics", "Enable prometheus metrics (only full client).", @@ -479,7 +479,7 @@ usage! { "--metrics-prefix=[prefix]", "Prepend the specified prefix to the exported metrics names.", - ARG arg_metrics_port: (u16) = 3000u16, or |c: &Config| c.metrics.as_ref()?.port.clone(), + ARG arg_metrics_port: (u16) = 3000u16, or |c: &Config| c.metrics.as_ref()?.port, "--metrics-port=[PORT]", "Specify the port portion of the metrics server.", @@ -488,7 +488,7 @@ usage! { "Specify the hostname portion of the metrics server, IP should be an interface's IP address, or all (all interfaces) or local.", ["API and Console Options – IPC"] - FLAG flag_no_ipc: (bool) = false, or |c: &Config| c.ipc.as_ref()?.disable.clone(), + FLAG flag_no_ipc: (bool) = false, or |c: &Config| c.ipc.as_ref()?.disable, "--no-ipc", "Disable JSON-RPC over IPC service.", @@ -501,15 +501,15 @@ usage! { "Specify custom API set available via JSON-RPC over IPC using a comma-delimited list of API names. Possible names are: all, safe, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, rpc, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces, rpc", ["Secret Store Options"] - FLAG flag_no_secretstore: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable.clone(), + FLAG flag_no_secretstore: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable, "--no-secretstore", "Disable Secret Store functionality.", - FLAG flag_no_secretstore_http: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable_http.clone(), + FLAG flag_no_secretstore_http: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable_http, "--no-secretstore-http", "Disable Secret Store HTTP API.", - FLAG flag_no_secretstore_auto_migrate: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable_auto_migrate.clone(), + FLAG flag_no_secretstore_auto_migrate: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable_auto_migrate, "--no-secretstore-auto-migrate", "Do not run servers set change session automatically when servers set changes. This option has no effect when servers set is read from configuration file.", @@ -549,7 +549,7 @@ usage! { "--secretstore-interface=[IP]", "Specify the hostname portion for listening to Secret Store Key Server internal requests, IP should be an interface's IP address, or local.", - ARG arg_secretstore_port: (u16) = 8083u16, or |c: &Config| c.secretstore.as_ref()?.port.clone(), + ARG arg_secretstore_port: (u16) = 8083u16, or |c: &Config| c.secretstore.as_ref()?.port, "--secretstore-port=[PORT]", "Specify the port portion for listening to Secret Store Key Server internal requests.", @@ -557,7 +557,7 @@ usage! { "--secretstore-http-interface=[IP]", "Specify the hostname portion for listening to Secret Store Key Server HTTP requests, IP should be an interface's IP address, or local.", - ARG arg_secretstore_http_port: (u16) = 8082u16, or |c: &Config| c.secretstore.as_ref()?.http_port.clone(), + ARG arg_secretstore_http_port: (u16) = 8082u16, or |c: &Config| c.secretstore.as_ref()?.http_port, "--secretstore-http-port=[PORT]", "Specify the port portion for listening to Secret Store Key Server HTTP requests.", @@ -574,31 +574,31 @@ usage! { "Hex-encoded public key of secret store administrator.", ["Sealing/Mining Options"] - FLAG flag_force_sealing: (bool) = false, or |c: &Config| c.mining.as_ref()?.force_sealing.clone(), + FLAG flag_force_sealing: (bool) = false, or |c: &Config| c.mining.as_ref()?.force_sealing, "--force-sealing", "Force the node to author new blocks as if it were always sealing/mining.", - FLAG flag_reseal_on_uncle: (bool) = false, or |c: &Config| c.mining.as_ref()?.reseal_on_uncle.clone(), + FLAG flag_reseal_on_uncle: (bool) = false, or |c: &Config| c.mining.as_ref()?.reseal_on_uncle, "--reseal-on-uncle", "Force the node to author new blocks when a new uncle block is imported.", - FLAG flag_remove_solved: (bool) = false, or |c: &Config| c.mining.as_ref()?.remove_solved.clone(), + FLAG flag_remove_solved: (bool) = false, or |c: &Config| c.mining.as_ref()?.remove_solved, "--remove-solved", "Move solved blocks from the work package queue instead of cloning them. This gives a slightly faster import speed, but means that extra solutions submitted for the same work package will go unused.", - FLAG flag_tx_queue_no_unfamiliar_locals: (bool) = false, or |c: &Config| c.mining.as_ref()?.tx_queue_no_unfamiliar_locals.clone(), + FLAG flag_tx_queue_no_unfamiliar_locals: (bool) = false, or |c: &Config| c.mining.as_ref()?.tx_queue_no_unfamiliar_locals, "--tx-queue-no-unfamiliar-locals", "Local transactions sent through JSON-RPC (HTTP, WebSockets, etc) will be treated as 'external' if the sending account is unknown.", - FLAG flag_tx_queue_no_early_reject: (bool) = false, or |c: &Config| c.mining.as_ref()?.tx_queue_no_early_reject.clone(), + FLAG flag_tx_queue_no_early_reject: (bool) = false, or |c: &Config| c.mining.as_ref()?.tx_queue_no_early_reject, "--tx-queue-no-early-reject", "Disables transaction queue optimization to early reject transactions below minimal effective gas price. This allows local transactions to always enter the pool, despite it being full, but requires additional ecrecover on every transaction.", - FLAG flag_refuse_service_transactions: (bool) = false, or |c: &Config| c.mining.as_ref()?.refuse_service_transactions.clone(), + FLAG flag_refuse_service_transactions: (bool) = false, or |c: &Config| c.mining.as_ref()?.refuse_service_transactions, "--refuse-service-transactions", "Always refuse service transactions.", - FLAG flag_infinite_pending_block: (bool) = false, or |c: &Config| c.mining.as_ref()?.infinite_pending_block.clone(), + FLAG flag_infinite_pending_block: (bool) = false, or |c: &Config| c.mining.as_ref()?.infinite_pending_block, "--infinite-pending-block", "Pending block will be created with maximal possible gas limit and will execute all transactions in the queue. Note that such block is invalid and should never be attempted to be mined.", @@ -614,15 +614,15 @@ usage! { "--reseal-on-txs=[SET]", "Specify which transactions should force the node to reseal a block. SET is one of: none - never reseal on new transactions; own - reseal only on a new local transaction; ext - reseal only on a new external transaction; all - reseal on all new transactions.", - ARG arg_reseal_min_period: (u64) = 2000u64, or |c: &Config| c.mining.as_ref()?.reseal_min_period.clone(), + ARG arg_reseal_min_period: (u64) = 2000u64, or |c: &Config| c.mining.as_ref()?.reseal_min_period, "--reseal-min-period=[MS]", "Specify the minimum time between reseals from incoming transactions. MS is time measured in milliseconds.", - ARG arg_reseal_max_period: (u64) = 120000u64, or |c: &Config| c.mining.as_ref()?.reseal_max_period.clone(), + ARG arg_reseal_max_period: (u64) = 120000u64, or |c: &Config| c.mining.as_ref()?.reseal_max_period, "--reseal-max-period=[MS]", "Specify the maximum time since last block to enable force-sealing. MS is time measured in milliseconds.", - ARG arg_work_queue_size: (usize) = 20usize, or |c: &Config| c.mining.as_ref()?.work_queue_size.clone(), + ARG arg_work_queue_size: (usize) = 20usize, or |c: &Config| c.mining.as_ref()?.work_queue_size, "--work-queue-size=[ITEMS]", "Specify the number of historical work packages which are kept cached lest a solution is found for them later. High values take more memory but result in fewer unusable solutions.", @@ -650,15 +650,15 @@ usage! { "--gas-cap=[GAS]", "A cap on how large we will raise the gas limit per block due to transaction volume.", - ARG arg_tx_queue_mem_limit: (u32) = 4u32, or |c: &Config| c.mining.as_ref()?.tx_queue_mem_limit.clone(), + ARG arg_tx_queue_mem_limit: (u32) = 4u32, or |c: &Config| c.mining.as_ref()?.tx_queue_mem_limit, "--tx-queue-mem-limit=[MB]", "Maximum amount of memory that can be used by the transaction queue. Setting this parameter to 0 disables limiting.", - ARG arg_tx_queue_size: (usize) = 8_192usize, or |c: &Config| c.mining.as_ref()?.tx_queue_size.clone(), + ARG arg_tx_queue_size: (usize) = 8_192usize, or |c: &Config| c.mining.as_ref()?.tx_queue_size, "--tx-queue-size=[LIMIT]", "Maximum amount of transactions in the queue (waiting to be included in next block).", - ARG arg_tx_queue_per_sender: (Option) = None, or |c: &Config| c.mining.as_ref()?.tx_queue_per_sender.clone(), + ARG arg_tx_queue_per_sender: (Option) = None, or |c: &Config| c.mining.as_ref()?.tx_queue_per_sender, "--tx-queue-per-sender=[LIMIT]", "Maximum number of transactions per sender in the queue. By default it's 1% of the entire queue, but not less than 16.", @@ -674,11 +674,11 @@ usage! { "--stratum-interface=[IP]", "Interface address for Stratum server.", - ARG arg_stratum_port: (u16) = 8008u16, or |c: &Config| c.stratum.as_ref()?.port.clone(), + ARG arg_stratum_port: (u16) = 8008u16, or |c: &Config| c.stratum.as_ref()?.port, "--stratum-port=[PORT]", "Port for Stratum server to listen on.", - ARG arg_min_gas_price: (Option) = None, or |c: &Config| c.mining.as_ref()?.min_gas_price.clone(), + ARG arg_min_gas_price: (Option) = None, or |c: &Config| c.mining.as_ref()?.min_gas_price, "--min-gas-price=[STRING]", "Minimum amount of Wei per GAS to be paid for a transaction on top of base fee, to be accepted for mining. Overrides --usd-per-tx.", @@ -698,7 +698,7 @@ usage! { "--tx-gas-limit=[GAS]", "Apply a limit of GAS as the maximum amount of gas a single transaction may have for it to be mined.", - ARG arg_tx_time_limit: (Option) = None, or |c: &Config| c.mining.as_ref()?.tx_time_limit.clone(), + ARG arg_tx_time_limit: (Option) = None, or |c: &Config| c.mining.as_ref()?.tx_time_limit, "--tx-time-limit=[MS]", "Maximal time for processing single transaction. If enabled senders of transactions offending the limit will get other transactions penalized.", @@ -714,11 +714,11 @@ usage! { "--stratum-secret=[STRING]", "Secret for authorizing Stratum server for peers.", - ARG arg_max_round_blocks_to_import: (usize) = 1usize, or |c: &Config| c.mining.as_ref()?.max_round_blocks_to_import.clone(), + ARG arg_max_round_blocks_to_import: (usize) = 1usize, or |c: &Config| c.mining.as_ref()?.max_round_blocks_to_import, "--max-round-blocks-to-import=[S]", "Maximal number of blocks to import for each import round.", - ARG arg_new_transactions_stats_period: (u64) = 0u64, or |c: &Config| c.mining.as_ref()?.new_transactions_stats_period.clone(), + ARG arg_new_transactions_stats_period: (u64) = 0u64, or |c: &Config| c.mining.as_ref()?.new_transactions_stats_period, "--new-transactions-stats-period=[N]", "Specify number of blocks for which new transactions will be returned in a result of `parity_newTransactionsStats` RPC call. Setting this parameter to 0 will return only transactions imported during the current block. (default: 0)", @@ -728,7 +728,7 @@ usage! { "Executable will auto-restart if exiting with 69", ["Miscellaneous Options"] - FLAG flag_no_color: (bool) = false, or |c: &Config| c.misc.as_ref()?.color.map(|c| !c).clone(), + FLAG flag_no_color: (bool) = false, or |c: &Config| c.misc.as_ref()?.color.map(|c| !c), "--no-color", "Don't use terminal color codes in output.", @@ -748,12 +748,12 @@ usage! { "--log-file=[FILENAME]", "Specify a filename into which logging should be appended.", - ARG arg_shutdown_on_missing_block_import: (Option) = None, or |c: &Config| c.misc.as_ref()?.shutdown_on_missing_block_import.clone(), + ARG arg_shutdown_on_missing_block_import: (Option) = None, or |c: &Config| c.misc.as_ref()?.shutdown_on_missing_block_import, "--shutdown-on-missing-block-import=[STRING]", "Shuts down if no block has been imported for N seconds. Defaults to None. Set to None or 0 to disable this feature. This setting is only respected by the HBBFT Engine", ["Footprint Options"] - FLAG flag_scale_verifiers: (bool) = false, or |c: &Config| c.footprint.as_ref()?.scale_verifiers.clone(), + FLAG flag_scale_verifiers: (bool) = false, or |c: &Config| c.footprint.as_ref()?.scale_verifiers, "--scale-verifiers", "Automatically scale amount of verifier threads based on workload. Not guaranteed to be faster.", @@ -765,27 +765,27 @@ usage! { "--pruning=[METHOD]", "Configure pruning of the state/storage trie. METHOD may be one of auto, archive, fast: archive - keep all state trie data. No pruning. fast - maintain journal overlay. Fast but 50MB used. auto - use the method most recently synced or default to fast if none synced.", - ARG arg_pruning_history: (u64) = 64u64, or |c: &Config| c.footprint.as_ref()?.pruning_history.clone(), + ARG arg_pruning_history: (u64) = 64u64, or |c: &Config| c.footprint.as_ref()?.pruning_history, "--pruning-history=[NUM]", "Set a minimum number of recent states to keep in memory when pruning is active.", - ARG arg_pruning_memory: (usize) = 32usize, or |c: &Config| c.footprint.as_ref()?.pruning_memory.clone(), + ARG arg_pruning_memory: (usize) = 32usize, or |c: &Config| c.footprint.as_ref()?.pruning_memory, "--pruning-memory=[MB]", "The ideal amount of memory in megabytes to use to store recent states. As many states as possible will be kept within this limit, and at least --pruning-history states will always be kept.", - ARG arg_cache_size_db: (u32) = 128u32, or |c: &Config| c.footprint.as_ref()?.cache_size_db.clone(), + ARG arg_cache_size_db: (u32) = 128u32, or |c: &Config| c.footprint.as_ref()?.cache_size_db, "--cache-size-db=[MB]", "Override database cache size.", - ARG arg_cache_size_blocks: (u32) = 8u32, or |c: &Config| c.footprint.as_ref()?.cache_size_blocks.clone(), + ARG arg_cache_size_blocks: (u32) = 8u32, or |c: &Config| c.footprint.as_ref()?.cache_size_blocks, "--cache-size-blocks=[MB]", "Specify the preferred size of the blockchain cache in megabytes.", - ARG arg_cache_size_queue: (u32) = 40u32, or |c: &Config| c.footprint.as_ref()?.cache_size_queue.clone(), + ARG arg_cache_size_queue: (u32) = 40u32, or |c: &Config| c.footprint.as_ref()?.cache_size_queue, "--cache-size-queue=[MB]", "Specify the maximum size of memory to use for block queue.", - ARG arg_cache_size_state: (u32) = 25u32, or |c: &Config| c.footprint.as_ref()?.cache_size_state.clone(), + ARG arg_cache_size_state: (u32) = 25u32, or |c: &Config| c.footprint.as_ref()?.cache_size_state, "--cache-size-state=[MB]", "Specify the maximum size of memory to use for the state cache.", @@ -797,11 +797,11 @@ usage! { "--fat-db=[BOOL]", "Build appropriate information to allow enumeration of all accounts and storage keys. Doubles the size of the state database. BOOL may be one of on, off or auto.", - ARG arg_cache_size: (Option) = None, or |c: &Config| c.footprint.as_ref()?.cache_size.clone(), + ARG arg_cache_size: (Option) = None, or |c: &Config| c.footprint.as_ref()?.cache_size, "--cache-size=[MB]", "Set total amount of discretionary memory to use for the entire system, overrides other cache and queue options.", - ARG arg_num_verifiers: (Option) = None, or |c: &Config| c.footprint.as_ref()?.num_verifiers.clone(), + ARG arg_num_verifiers: (Option) = None, or |c: &Config| c.footprint.as_ref()?.num_verifiers, "--num-verifiers=[INT]", "Amount of verifier threads to use or to begin with, if verifier auto-scaling is enabled.", @@ -811,7 +811,7 @@ usage! { "Skip block seal check.", ["Snapshot Options"] - FLAG flag_enable_snapshotting: (bool) = false, or |c: &Config| c.snapshots.as_ref()?.enable.clone(), + FLAG flag_enable_snapshotting: (bool) = false, or |c: &Config| c.snapshots.as_ref()?.enable, "--enable-snapshotting", "Enable automated snapshots which usually occur once every 5000 blocks.", @@ -1059,10 +1059,10 @@ mod tests { #[test] fn should_accept_any_argument_order() { let args = Args::parse(&["openethereum", "--no-warp", "account", "list"]).unwrap(); - assert_eq!(args.flag_no_warp, true); + assert!(args.flag_no_warp); let args = Args::parse(&["openethereum", "account", "list", "--no-warp"]).unwrap(); - assert_eq!(args.flag_no_warp, true); + assert!(args.flag_no_warp); let args = Args::parse(&["openethereum", "--chain=dev", "account", "list"]).unwrap(); assert_eq!(args.arg_chain, "dev"); @@ -1083,13 +1083,13 @@ mod tests { #[test] fn should_parse_args_and_flags() { let args = Args::parse(&["openethereum", "--no-warp"]).unwrap(); - assert_eq!(args.flag_no_warp, true); + assert!(args.flag_no_warp); let args = Args::parse(&["openethereum", "--pruning", "archive"]).unwrap(); assert_eq!(args.arg_pruning, "archive"); let args = Args::parse(&["openethereum", "export", "state", "--no-storage"]).unwrap(); - assert_eq!(args.flag_export_state_no_storage, true); + assert!(args.flag_export_state_no_storage); let args = Args::parse(&["openethereum", "export", "state", "--min-balance", "123"]).unwrap(); diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index eb8543122..8e90dbc3f 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -146,7 +146,7 @@ impl Configuration { let mode = match self.args.arg_mode.as_ref() { "last" => None, mode => Some(to_mode( - &mode, + mode, self.args.arg_mode_timeout, self.args.arg_mode_alarm, )?), @@ -168,7 +168,7 @@ impl Configuration { let format = self.format()?; let metrics_conf = self.metrics_config()?; let keys_iterations = NonZeroU32::new(self.args.arg_keys_iterations) - .ok_or_else(|| "--keys-iterations must be non-zero")?; + .ok_or("--keys-iterations must be non-zero")?; let cmd = if self.args.flag_version { Cmd::Version @@ -182,23 +182,23 @@ impl Configuration { .accounts_config()? .password_files .first() - .map(|pwfile| PathBuf::from(pwfile)); + .map(PathBuf::from); Cmd::SignerSign { id: self.args.arg_signer_sign_id, - pwfile: pwfile, + pwfile, port: ws_conf.port, - authfile: authfile, + authfile, } } else if self.args.cmd_signer_reject { Cmd::SignerReject { id: self.args.arg_signer_reject_id, port: ws_conf.port, - authfile: authfile, + authfile, } } else if self.args.cmd_signer_list { Cmd::SignerList { port: ws_conf.port, - authfile: authfile, + authfile, } } else { unreachable!(); @@ -220,16 +220,16 @@ impl Configuration { })) } else if self.args.cmd_db && self.args.cmd_db_kill { Cmd::Blockchain(BlockchainCmd::Kill(KillBlockchain { - spec: spec, - dirs: dirs, - pruning: pruning, + spec, + dirs, + pruning, })) } else if self.args.cmd_account { let account_cmd = if self.args.cmd_account_new { let new_acc = NewAccount { iterations: keys_iterations, path: dirs.keys, - spec: spec, + spec, password_file: self .accounts_config()? .password_files @@ -240,7 +240,7 @@ impl Configuration { } else if self.args.cmd_account_list { let list_acc = ListAccounts { path: dirs.keys, - spec: spec, + spec, }; AccountCmd::List(list_acc) } else if self.args.cmd_account_import { @@ -251,7 +251,7 @@ impl Configuration { .expect("CLI argument is required; qed") .clone(), to: dirs.keys, - spec: spec, + spec, }; AccountCmd::Import(import_acc) } else { @@ -262,7 +262,7 @@ impl Configuration { let presale_cmd = ImportWallet { iterations: keys_iterations, path: dirs.keys, - spec: spec, + spec, wallet_path: self.args.arg_wallet_import_path.clone().unwrap(), password_file: self .accounts_config()? @@ -273,18 +273,18 @@ impl Configuration { Cmd::ImportPresaleWallet(presale_cmd) } else if self.args.cmd_import { let import_cmd = ImportBlockchain { - spec: spec, - cache_config: cache_config, - dirs: dirs, + spec, + cache_config, + dirs, file_path: self.args.arg_import_file.clone(), - format: format, - pruning: pruning, - pruning_history: pruning_history, + format, + pruning, + pruning_history, pruning_memory: self.args.arg_pruning_memory, - compaction: compaction, - tracing: tracing, - fat_db: fat_db, - vm_type: vm_type, + compaction, + tracing, + fat_db, + vm_type, check_seal: !self.args.flag_no_seal_check, with_color: logger_config.color, verifier_settings: self.verifier_settings(), @@ -294,17 +294,17 @@ impl Configuration { } else if self.args.cmd_export { if self.args.cmd_export_blocks { let export_cmd = ExportBlockchain { - spec: spec, - cache_config: cache_config, - dirs: dirs, + spec, + cache_config, + dirs, file_path: self.args.arg_export_blocks_file.clone(), - format: format, - pruning: pruning, - pruning_history: pruning_history, + format, + pruning, + pruning_history, pruning_memory: self.args.arg_pruning_memory, - compaction: compaction, - tracing: tracing, - fat_db: fat_db, + compaction, + tracing, + fat_db, from_block: to_block_id(&self.args.arg_export_blocks_from)?, to_block: to_block_id(&self.args.arg_export_blocks_to)?, check_seal: !self.args.flag_no_seal_check, @@ -313,17 +313,17 @@ impl Configuration { Cmd::Blockchain(BlockchainCmd::Export(export_cmd)) } else if self.args.cmd_export_state { let export_cmd = ExportState { - spec: spec, - cache_config: cache_config, - dirs: dirs, + spec, + cache_config, + dirs, file_path: self.args.arg_export_state_file.clone(), - format: format, - pruning: pruning, - pruning_history: pruning_history, + format, + pruning, + pruning_history, pruning_memory: self.args.arg_pruning_memory, - compaction: compaction, - tracing: tracing, - fat_db: fat_db, + compaction, + tracing, + fat_db, at: to_block_id(&self.args.arg_export_state_at)?, storage: !self.args.flag_export_state_no_storage, code: !self.args.flag_export_state_no_code, @@ -343,38 +343,38 @@ impl Configuration { } } else if self.args.cmd_snapshot { let snapshot_cmd = SnapshotCommand { - cache_config: cache_config, - dirs: dirs, - spec: spec, - pruning: pruning, - pruning_history: pruning_history, + cache_config, + dirs, + spec, + pruning, + pruning_history, pruning_memory: self.args.arg_pruning_memory, - tracing: tracing, - fat_db: fat_db, - compaction: compaction, + tracing, + fat_db, + compaction, file_path: self.args.arg_snapshot_file.clone(), kind: snapshot::Kind::Take, block_at: to_block_id(&self.args.arg_snapshot_at)?, max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import, - snapshot_conf: snapshot_conf, + snapshot_conf, }; Cmd::Snapshot(snapshot_cmd) } else if self.args.cmd_restore { let restore_cmd = SnapshotCommand { - cache_config: cache_config, - dirs: dirs, - spec: spec, - pruning: pruning, - pruning_history: pruning_history, + cache_config, + dirs, + spec, + pruning, + pruning_history, pruning_memory: self.args.arg_pruning_memory, - tracing: tracing, - fat_db: fat_db, - compaction: compaction, + tracing, + fat_db, + compaction, file_path: self.args.arg_restore_file.clone(), kind: snapshot::Kind::Restore, block_at: to_block_id("latest")?, // unimportant. max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import, - snapshot_conf: snapshot_conf, + snapshot_conf, }; Cmd::Snapshot(restore_cmd) } else { @@ -392,44 +392,44 @@ impl Configuration { let verifier_settings = self.verifier_settings(); let run_cmd = RunCmd { - cache_config: cache_config, - dirs: dirs, - spec: spec, - pruning: pruning, - pruning_history: pruning_history, + cache_config, + dirs, + spec, + pruning, + pruning_history, pruning_memory: self.args.arg_pruning_memory, - daemon: daemon, + daemon, logger_config: logger_config.clone(), miner_options: self.miner_options()?, gas_price_percentile: self.args.arg_gas_price_percentile, poll_lifetime: self.args.arg_poll_lifetime, - ws_conf: ws_conf, - snapshot_conf: snapshot_conf, - http_conf: http_conf, - ipc_conf: ipc_conf, - net_conf: net_conf, - network_id: network_id, + ws_conf, + snapshot_conf, + http_conf, + ipc_conf, + net_conf, + network_id, acc_conf: self.accounts_config()?, gas_pricer_conf: self.gas_pricer_config()?, miner_extras: self.miner_extras()?, stratum: self.stratum_options()?, allow_missing_blocks: self.args.flag_jsonrpc_allow_missing_blocks, - mode: mode, - tracing: tracing, - fat_db: fat_db, - compaction: compaction, - vm_type: vm_type, - warp_sync: warp_sync, + mode, + tracing, + fat_db, + compaction, + vm_type, + warp_sync, warp_barrier: self.args.arg_warp_barrier, experimental_rpcs, net_settings: self.network_settings()?, - secretstore_conf: secretstore_conf, + secretstore_conf, name: self.args.arg_identity, custom_bootnodes: self.args.arg_bootnodes.is_some(), check_seal: !self.args.flag_no_seal_check, download_old_blocks: !self.args.flag_no_ancient_blocks, new_transactions_stats_period: self.args.arg_new_transactions_stats_period, - verifier_settings: verifier_settings, + verifier_settings, no_persistent_txqueue: self.args.flag_no_persistent_txqueue, max_round_blocks_to_import: self.args.arg_max_round_blocks_to_import, metrics_conf, @@ -440,7 +440,7 @@ impl Configuration { Ok(Execute { logger: logger_config, - cmd: cmd, + cmd, }) } @@ -458,7 +458,7 @@ impl Configuration { engine_signer: self.engine_signer()?, work_notify: self.work_notify(), local_accounts: HashSet::from_iter( - to_addresses(&self.args.arg_tx_queue_locals)?.into_iter(), + to_addresses(&self.args.arg_tx_queue_locals)?, ), }; @@ -512,7 +512,7 @@ impl Configuration { } fn chain(&self) -> Result { - Ok(self.args.arg_chain.parse()?) + self.args.arg_chain.parse() } fn is_dev_chain(&self) -> Result { @@ -555,7 +555,7 @@ impl Configuration { fn accounts_config(&self) -> Result { let keys_iterations = NonZeroU32::new(self.args.arg_keys_iterations) - .ok_or_else(|| "--keys-iterations must be non-zero")?; + .ok_or("--keys-iterations must be non-zero")?; let cfg = AccountsConfig { iterations: keys_iterations, refresh_time: self.args.arg_accounts_refresh, @@ -700,7 +700,7 @@ impl Configuration { if "auto" == self.args.arg_usd_per_eth { Ok(GasPricerConfig::Calibrated { - usd_per_tx: usd_per_tx, + usd_per_tx, recalibration_period: to_duration(self.args.arg_price_update_period.as_str())?, api_endpoint: ETHERSCAN_ETH_PRICE_ENDPOINT.to_string(), }) @@ -718,7 +718,7 @@ impl Configuration { Ok(GasPricerConfig::Fixed(wei_per_gas)) } else { Ok(GasPricerConfig::Calibrated { - usd_per_tx: usd_per_tx, + usd_per_tx, recalibration_period: to_duration(self.args.arg_price_update_period.as_str())?, api_endpoint: self.args.arg_usd_per_eth.clone(), }) @@ -936,7 +936,7 @@ impl Configuration { }, processing_threads: self.args.arg_jsonrpc_threads, max_payload: match self.args.arg_jsonrpc_max_payload { - Some(max) if max > 0 => max as usize, + Some(max) if max > 0 => max, _ => 5usize, }, keep_alive: !self.args.flag_jsonrpc_no_keep_alive, @@ -1008,7 +1008,7 @@ impl Configuration { .args .arg_base_path .as_ref() - .map_or_else(|| default_data_path(), |s| s.clone()); + .map_or_else(default_data_path, |s| s.clone()); let data_path = replace_home("", &base_path); let is_using_base_path = self.args.arg_base_path.is_some(); // If base_path is set and db_path is not we default to base path subdir instead of LOCAL. @@ -1018,7 +1018,7 @@ impl Configuration { self.args .arg_db_path .as_ref() - .map_or(dir::CHAINS_PATH, |s| &s) + .map_or(dir::CHAINS_PATH, |s| s) }; let cache_path = if is_using_base_path { "$BASE/cache" @@ -1026,7 +1026,7 @@ impl Configuration { dir::CACHE_PATH }; - let db_path = replace_home_and_local(&data_path, &local_path, &base_db_path); + let db_path = replace_home_and_local(&data_path, &local_path, base_db_path); let cache_path = replace_home_and_local(&data_path, &local_path, cache_path); let keys_path = replace_home(&data_path, &self.args.arg_keys_path); let secretstore_path = replace_home(&data_path, &self.args.arg_secretstore_path); @@ -1090,7 +1090,7 @@ impl Configuration { #[cfg(feature = "accounts")] Some(ref s) if s.len() == 40 => Ok(Some(NodeSecretKey::KeyStore(s.parse() .map_err(|e| format!("Invalid secret store secret address: {}. Error: {:?}", s, e))?))), - Some(_) => Err(format!("Invalid secret store secret. Must be either existing account address, or hex-encoded private key")), + Some(_) => Err("Invalid secret store secret. Must be either existing account address, or hex-encoded private key".to_string()), None => Ok(None), } } @@ -1718,10 +1718,10 @@ mod tests { Cmd::Run(c) => { assert_eq!(c.net_conf.min_peers, 50); assert_eq!(c.net_conf.max_peers, 100); - assert_eq!(c.ipc_conf.enabled, false); - assert_eq!(c.miner_options.force_sealing, true); - assert_eq!(c.miner_options.reseal_on_external_tx, true); - assert_eq!(c.miner_options.reseal_on_own_tx, true); + assert!(!c.ipc_conf.enabled); + assert!(c.miner_options.force_sealing); + assert!(c.miner_options.reseal_on_external_tx); + assert!(c.miner_options.reseal_on_own_tx); assert_eq!( c.miner_options.reseal_min_period, Duration::from_millis(4000) diff --git a/bin/oe/db/rocksdb/blooms.rs b/bin/oe/db/rocksdb/blooms.rs index 06c8749d3..e08448fcd 100644 --- a/bin/oe/db/rocksdb/blooms.rs +++ b/bin/oe/db/rocksdb/blooms.rs @@ -41,9 +41,7 @@ pub fn migrate_blooms>(path: P, config: &DatabaseConfig) -> Resul .filter(|(key, _)| key.len() == 6) .take_while(|(key, _)| key[0] == 3u8 && key[1] == 0u8) .map(|(key, group)| { - let index = (key[2] as u64) << 24 - | (key[3] as u64) << 16 - | (key[4] as u64) << 8 + let index = ((key[2] as u64) << 24) | ((key[3] as u64) << 16) | ((key[4] as u64) << 8) | (key[5] as u64); let number = index * LOG_BLOOMS_ELEMENTS_PER_INDEX; @@ -65,10 +63,7 @@ pub fn migrate_blooms>(path: P, config: &DatabaseConfig) -> Resul .filter(|(key, _)| key.len() == 6) .take_while(|(key, _)| key[0] == 1u8 && key[1] == 0u8) .map(|(key, group)| { - let index = (key[2] as u64) - | (key[3] as u64) << 8 - | (key[4] as u64) << 16 - | (key[5] as u64) << 24; + let index = (key[2] as u64) | ((key[3] as u64) << 8) | ((key[4] as u64) << 16) | ((key[5] as u64) << 24); let number = index * LOG_BLOOMS_ELEMENTS_PER_INDEX; let blooms = rlp::decode_list::(&group); diff --git a/bin/oe/db/rocksdb/helpers.rs b/bin/oe/db/rocksdb/helpers.rs index e75f6efde..a8f355660 100644 --- a/bin/oe/db/rocksdb/helpers.rs +++ b/bin/oe/db/rocksdb/helpers.rs @@ -23,10 +23,10 @@ pub fn compaction_profile( profile: &DatabaseCompactionProfile, db_path: &Path, ) -> CompactionProfile { - match profile { - &DatabaseCompactionProfile::Auto => CompactionProfile::auto(db_path), - &DatabaseCompactionProfile::SSD => CompactionProfile::ssd(), - &DatabaseCompactionProfile::HDD => CompactionProfile::hdd(), + match *profile { + DatabaseCompactionProfile::Auto => CompactionProfile::auto(db_path), + DatabaseCompactionProfile::SSD => CompactionProfile::ssd(), + DatabaseCompactionProfile::HDD => CompactionProfile::hdd(), } } @@ -34,7 +34,7 @@ pub fn client_db_config(client_path: &Path, client_config: &ClientConfig) -> Dat let mut client_db_config = DatabaseConfig::with_columns(NUM_COLUMNS); client_db_config.memory_budget = client_config.db_cache_size; - client_db_config.compaction = compaction_profile(&client_config.db_compaction, &client_path); + client_db_config.compaction = compaction_profile(&client_config.db_compaction, client_path); client_db_config } diff --git a/bin/oe/db/rocksdb/migration.rs b/bin/oe/db/rocksdb/migration.rs index 441927aee..7e15895f5 100644 --- a/bin/oe/db/rocksdb/migration.rs +++ b/bin/oe/db/rocksdb/migration.rs @@ -55,7 +55,7 @@ const BLOOMS_DB_VERSION: u32 = 13; /// Defines how many items are migrated to the new version of database at once. const BATCH_SIZE: usize = 1024; /// Version file name. -const VERSION_FILE_NAME: &'static str = "db_version"; +const VERSION_FILE_NAME: &str = "db_version"; /// Migration related erorrs. #[derive(Debug)] @@ -175,12 +175,12 @@ fn migrate_database( return Ok(()); } - let backup_path = backup_database_path(&db_path); + let backup_path = backup_database_path(db_path); // remove the backup dir if it exists let _ = fs::remove_dir_all(&backup_path); // migrate old database to the new one - let temp_path = migrations.execute(&db_path, version)?; + let temp_path = migrations.execute(db_path, version)?; // completely in-place migration leads to the paths being equal. // in that case, no need to shuffle directories. @@ -189,12 +189,12 @@ fn migrate_database( } // create backup - fs::rename(&db_path, &backup_path)?; + fs::rename(db_path, &backup_path)?; // replace the old database with the new one - if let Err(err) = fs::rename(&temp_path, &db_path) { + if let Err(err) = fs::rename(&temp_path, db_path) { // if something went wrong, bring back backup - fs::rename(&backup_path, &db_path)?; + fs::rename(&backup_path, db_path)?; return Err(err.into()); } @@ -208,7 +208,7 @@ fn exists(path: &Path) -> bool { /// Migrates the database. pub fn migrate(path: &Path, compaction_profile: &DatabaseCompactionProfile) -> Result<(), Error> { - let compaction_profile = helpers::compaction_profile(&compaction_profile, path); + let compaction_profile = helpers::compaction_profile(compaction_profile, path); // read version file. let version = current_version(path)?; diff --git a/bin/oe/db/rocksdb/mod.rs b/bin/oe/db/rocksdb/mod.rs index 18052c3a5..a0556dad6 100644 --- a/bin/oe/db/rocksdb/mod.rs +++ b/bin/oe/db/rocksdb/mod.rs @@ -108,7 +108,7 @@ pub fn open_database( fs::create_dir_all(&blooms_path)?; fs::create_dir_all(&trace_blooms_path)?; - let db = Database::open(&config, client_path)?; + let db = Database::open(config, client_path)?; let db_with_metrics = ethcore_db::DatabaseWithMetrics::new(db); let db = AppDB { diff --git a/bin/oe/helpers.rs b/bin/oe/helpers.rs index 0b05cbb1d..e5e9ce040 100644 --- a/bin/oe/helpers.rs +++ b/bin/oe/helpers.rs @@ -331,7 +331,7 @@ pub fn execute_upgrades( /// Prompts user asking for password. pub fn password_prompt() -> Result { use rpassword::read_password; - const STDIN_ERROR: &'static str = "Unable to ask for password on non-interactive terminal."; + const STDIN_ERROR: &str = "Unable to ask for password on non-interactive terminal."; println!("Please note that password is NOT RECOVERABLE."); print!("Type password: "); @@ -355,9 +355,7 @@ pub fn password_prompt() -> Result { pub fn password_from_file(path: String) -> Result { let passwords = passwords_from_files(&[path])?; // use only first password from the file - passwords - .get(0) - .map(Password::clone) + passwords.first().cloned() .ok_or_else(|| "Password file seems to be empty.".to_owned()) } @@ -372,7 +370,7 @@ pub fn passwords_from_files(files: &[String]) -> Result, String> { .collect::>(); Ok(lines) }).collect::>, String>>(); - Ok(passwords?.into_iter().flat_map(|x| x).collect()) + Ok(passwords?.into_iter().flatten().collect()) } #[cfg(test)] @@ -403,7 +401,7 @@ mod tests { assert_eq!(to_duration("1second").unwrap(), Duration::from_secs(1)); assert_eq!(to_duration("2seconds").unwrap(), Duration::from_secs(2)); assert_eq!(to_duration("15seconds").unwrap(), Duration::from_secs(15)); - assert_eq!(to_duration("1minute").unwrap(), Duration::from_secs(1 * 60)); + assert_eq!(to_duration("1minute").unwrap(), Duration::from_secs(60)); assert_eq!( to_duration("2minutes").unwrap(), Duration::from_secs(2 * 60) @@ -419,7 +417,7 @@ mod tests { ); assert_eq!( to_duration("1hour").unwrap(), - Duration::from_secs(1 * 60 * 60) + Duration::from_secs(60 * 60) ); assert_eq!( to_duration("2hours").unwrap(), @@ -431,7 +429,7 @@ mod tests { ); assert_eq!( to_duration("1day").unwrap(), - Duration::from_secs(1 * 24 * 60 * 60) + Duration::from_secs(24 * 60 * 60) ); assert_eq!( to_duration("2days").unwrap(), diff --git a/bin/oe/informant.rs b/bin/oe/informant.rs index ae205f6fc..da580ca0e 100644 --- a/bin/oe/informant.rs +++ b/bin/oe/informant.rs @@ -206,10 +206,10 @@ impl Informant { ) -> Self { Informant { last_tick: RwLock::new(Instant::now()), - with_color: with_color, - target: target, - snapshot: snapshot, - rpc_stats: rpc_stats, + with_color, + target, + snapshot, + rpc_stats, last_import: Mutex::new(Instant::now()), skipped: AtomicUsize::new(0), skipped_txs: AtomicUsize::new(0), @@ -252,11 +252,10 @@ impl Informant { } = full_report; let rpc_stats = self.rpc_stats.as_ref(); - let snapshot_sync = sync_info.as_ref().map_or(false, |s| s.snapshot_sync) + let snapshot_sync = sync_info.as_ref().is_some_and(|s| s.snapshot_sync) && self .snapshot - .as_ref() - .map_or(false, |s| match s.restoration_status() { + .as_ref().is_some_and(|s| match s.restoration_status() { RestorationStatus::Ongoing { .. } | RestorationStatus::Initializing { .. } => { true } @@ -315,15 +314,13 @@ impl Informant { None => String::new(), }, match sync_info.as_ref() { - Some(ref sync_info) => format!("{}{}/{} peers", + Some(sync_info) => format!("{}{}/{} peers", match importing { - true => format!("{}", - if self.target.executes_transactions() { + true => (if self.target.executes_transactions() { paint(Green.bold(), format!("{:>8} ", format!("LI:#{}", sync_info.last_imported_block_number))) } else { String::new() - } - ), + }).to_string(), false => match sync_info.last_imported_ancient_number { Some(number) => format!("{} ", paint(Yellow.bold(), format!("{:>8}", format!("AB:#{}", number)))), None => String::new(), @@ -334,9 +331,9 @@ impl Informant { ), _ => String::new(), }, - cache_sizes.display(Blue.bold(), &paint), + cache_sizes.display(Blue.bold(), paint), match rpc_stats { - Some(ref rpc_stats) => format!( + Some(rpc_stats) => format!( "RPC: {} conn, {} req/s, {} µs", paint(Blue.bold(), format!("{:2}", rpc_stats.sessions())), paint(Blue.bold(), format!("{:4}", rpc_stats.requests_rate())), diff --git a/bin/oe/main.rs b/bin/oe/main.rs index f24557441..5e1f39e67 100644 --- a/bin/oe/main.rs +++ b/bin/oe/main.rs @@ -130,11 +130,8 @@ fn main() -> Result<(), i32> { } }); - match res_set_handler { - Err(err) => { - warn!("could not setup ctrl+c handler: {:?}", err) - } - _ => {} + if let Err(err) = res_set_handler { + warn!("could not setup ctrl+c handler: {:?}", err) } // so the client has started successfully @@ -146,7 +143,7 @@ fn main() -> Result<(), i32> { // Wait for signal let mut lock = exit.0.lock(); if !lock.should_exit() { - let _ = exit.1.wait(&mut lock); + exit.1.wait(&mut lock); } client.shutdown(); diff --git a/bin/oe/params.rs b/bin/oe/params.rs index af2747ab1..31b28ab1b 100644 --- a/bin/oe/params.rs +++ b/bin/oe/params.rs @@ -37,7 +37,9 @@ use parity_version::version_data; use crate::configuration; #[derive(Debug, PartialEq)] +#[derive(Default)] pub enum SpecType { + #[default] Foundation, Poanet, Xdai, @@ -58,11 +60,6 @@ pub enum SpecType { Custom(String), } -impl Default for SpecType { - fn default() -> Self { - SpecType::Foundation - } -} impl str::FromStr for SpecType { type Err = String; @@ -156,16 +153,13 @@ impl SpecType { } #[derive(Debug, PartialEq)] +#[derive(Default)] pub enum Pruning { Specific(Algorithm), + #[default] Auto, } -impl Default for Pruning { - fn default() -> Self { - Pruning::Auto - } -} impl str::FromStr for Pruning { type Err = String; @@ -215,8 +209,8 @@ impl str::FromStr for ResealPolicy { }; let reseal = ResealPolicy { - own: own, - external: external, + own, + external, }; Ok(reseal) @@ -276,8 +270,8 @@ impl GasPricerConfig { ref api_endpoint, } => GasPricer::new_calibrated(GasPriceCalibrator::new( GasPriceCalibratorOptions { - usd_per_tx: usd_per_tx, - recalibration_period: recalibration_period, + usd_per_tx, + recalibration_period, }, fetch, p, @@ -312,20 +306,17 @@ impl Default for MinerExtras { /// 3-value enum. #[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Default)] pub enum Switch { /// True. On, /// False. Off, /// Auto. + #[default] Auto, } -impl Default for Switch { - fn default() -> Self { - Switch::Auto - } -} impl str::FromStr for Switch { type Err = String; @@ -357,13 +348,13 @@ pub fn fatdb_switch_to_bool( user_defaults: &UserDefaults, _algorithm: Algorithm, ) -> Result { - let result = match (user_defaults.is_first_launch, switch, user_defaults.fat_db) { + + match (user_defaults.is_first_launch, switch, user_defaults.fat_db) { (false, Switch::On, false) => Err("FatDB resync required".into()), (_, Switch::On, _) => Ok(true), (_, Switch::Off, _) => Ok(false), (_, Switch::Auto, def) => Ok(def), - }; - result + } } pub fn mode_switch_to_bool( diff --git a/bin/oe/reserved_peer_management.rs b/bin/oe/reserved_peer_management.rs index d5abff2bf..ec46a03b5 100644 --- a/bin/oe/reserved_peer_management.rs +++ b/bin/oe/reserved_peer_management.rs @@ -43,18 +43,18 @@ impl ReservedPeersManagement for ReservedPeersWrapper { // this remove should never fail, because we check just before self.current_reserved_peers.remove(peer); } - return remove_result - .map_err(|_e| format!("remove_reserved_peer failed for peer: {peer}")); + remove_result + .map_err(|_e| format!("remove_reserved_peer failed for peer: {peer}")) } None => { warn!("ManageNetwork instance not available."); - return Err("ManageNetwork instance not available.".to_string()); + Err("ManageNetwork instance not available.".to_string()) } } } else { - return Err(format!( + Err(format!( "Cannot remove reserved Peer: Peer not reserved: {peer}" - )); + )) } } @@ -82,7 +82,7 @@ impl ReservedPeersManagement for ReservedPeersWrapper { } } - return disconnected; + disconnected } /// Returns the devp2p network endpoint IP and Port information that is used to communicate with other peers. diff --git a/bin/oe/rpc.rs b/bin/oe/rpc.rs index d4dd37c41..833d0ae58 100644 --- a/bin/oe/rpc.rs +++ b/bin/oe/rpc.rs @@ -33,7 +33,7 @@ pub use parity_rpc::{HttpServer, IpcServer}; //pub use parity_rpc::ws::Server as WsServer; pub use parity_rpc::ws::{ws, Server as WsServer}; -pub const DAPPS_DOMAIN: &'static str = "web3.site"; +pub const DAPPS_DOMAIN: &str = "web3.site"; #[derive(Debug, Clone, PartialEq)] pub struct HttpConfiguration { @@ -195,8 +195,8 @@ pub fn new_ws( allowed_origins, allowed_hosts, conf.max_connections, - rpc::WsExtractor::new(path.clone()), - rpc::WsExtractor::new(path.clone()), + rpc::WsExtractor::new(path), + rpc::WsExtractor::new(path), rpc::WsStats::new(deps.stats.clone()), conf.max_payload, ); @@ -275,7 +275,7 @@ pub fn new_ipc( // Windows pipe paths are not on the FS. if !cfg!(windows) { if let Some(dir) = path.parent() { - ::std::fs::create_dir_all(&dir).map_err(|err| { + ::std::fs::create_dir_all(dir).map_err(|err| { format!( "Unable to create IPC directory at {}: {}", dir.display(), @@ -314,7 +314,7 @@ fn with_domain( items.insert(host.to_string()); items.insert(host.replace("127.0.0.1", "localhost")); items.insert(format!("http://*.{}", domain)); //proxypac - if let Some(port) = extract_port(&*host) { + if let Some(port) = extract_port(&host) { items.insert(format!("http://*.{}:{}", domain, port)); } } diff --git a/bin/oe/rpc_apis.rs b/bin/oe/rpc_apis.rs index 50db479cb..77f327d57 100644 --- a/bin/oe/rpc_apis.rs +++ b/bin/oe/rpc_apis.rs @@ -100,8 +100,10 @@ impl FromStr for Api { } #[derive(Debug, Clone)] +#[derive(Default)] pub enum ApiSet { // Unsafe context (like jsonrpc over http) + #[default] UnsafeContext, // All possible APIs (safe context like token-protected WS interface) All, @@ -113,11 +115,6 @@ pub enum ApiSet { List(HashSet), } -impl Default for ApiSet { - fn default() -> Self { - ApiSet::UnsafeContext - } -} impl PartialEq for ApiSet { fn eq(&self, other: &Self) -> bool { @@ -265,7 +262,7 @@ impl FullDependencies { handler.extend_with(DebugClient::new(self.client.clone()).to_delegate()); } Api::Web3 => { - handler.extend_with(Web3Client::default().to_delegate()); + handler.extend_with(Web3Client.to_delegate()); } Api::Net => { handler.extend_with(NetClient::new(&self.sync).to_delegate()); @@ -411,7 +408,7 @@ impl FullDependencies { } Api::Traces => handler.extend_with(TracesClient::new(&self.client).to_delegate()), Api::Rpc => { - let modules = to_modules(&apis); + let modules = to_modules(apis); handler.extend_with(RpcClient::new(modules).to_delegate()); } Api::SecretStore => { diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 05222d701..749316224 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -166,7 +166,7 @@ impl ChainSyncing for SyncProviderWrapper { fn is_syncing(&self) -> bool { match self.sync_provider.upgrade() { Some(sync_arc) => { - return sync_arc.status().state != SyncState::Idle; + sync_arc.status().state != SyncState::Idle } // We also indicate the "syncing" state when the SyncProvider has already been destroyed. None => true, @@ -227,7 +227,7 @@ pub fn execute( // create dirs used by parity cmd.dirs.create_dirs( - cmd.acc_conf.unlocked_accounts.len() == 0, + cmd.acc_conf.unlocked_accounts.is_empty(), cmd.secretstore_conf.enabled, )?; @@ -486,7 +486,7 @@ pub fn execute( let (sync_provider, manage_network, chain_notify, priority_tasks, new_transaction_hashes) = modules::sync( sync_config, - net_conf.clone().into(), + net_conf.clone(), client.clone(), forks, snapshot_service.clone(), @@ -519,7 +519,7 @@ pub fn execute( { for hash in hashes { new_transaction_hashes - .send(hash.clone()) + .send(*hash) .expect("new_transaction_hashes receiving side is disconnected"); } let task = @@ -540,7 +540,7 @@ pub fn execute( let signer_service = Arc::new(signer::new_service(&cmd.ws_conf, &cmd.logger_config)); let deps_for_rpc_apis = Arc::new(rpc_apis::FullDependencies { - signer_service: signer_service, + signer_service, snapshot: snapshot_service.clone(), client: client.clone(), sync: sync_provider.clone(), diff --git a/bin/oe/secretstore.rs b/bin/oe/secretstore.rs index 207dab7a0..a64954c09 100644 --- a/bin/oe/secretstore.rs +++ b/bin/oe/secretstore.rs @@ -329,5 +329,5 @@ pub fn start( return Ok(None); } - KeyServer::new(conf, deps, executor).map(|s| Some(s)) + KeyServer::new(conf, deps, executor).map(Some) } diff --git a/bin/oe/signer.rs b/bin/oe/signer.rs index ff30c11f2..01ef4a5eb 100644 --- a/bin/oe/signer.rs +++ b/bin/oe/signer.rs @@ -24,7 +24,7 @@ use ansi_term::Colour::White; use ethcore_logger::Config as LogConfig; use parity_rpc; -pub const CODES_FILENAME: &'static str = "authcodes"; +pub const CODES_FILENAME: &str = "authcodes"; pub struct NewToken { pub token: String, @@ -91,7 +91,7 @@ fn generate_new_token(path: &Path, logger_config_color: bool) -> io::Result format!("{}", White.bold().paint(&code[..])), - false => format!("{}", &code[..]), + false => code[..].to_string(), } ); Ok(code) diff --git a/bin/oe/snapshot.rs b/bin/oe/snapshot.rs index 137e8c895..8dc1e9a22 100644 --- a/bin/oe/snapshot.rs +++ b/bin/oe/snapshot.rs @@ -320,7 +320,7 @@ impl SnapshotCommand { } }); - if let Err(e) = service.client().take_snapshot(writer, block_at, &*progress) { + if let Err(e) = service.client().take_snapshot(writer, block_at, &progress) { let _ = ::std::fs::remove_file(&file_path); return Err(format!( "Encountered fatal error while creating snapshot: {}", diff --git a/bin/oe/upgrade.rs b/bin/oe/upgrade.rs index e6f62fb65..da122a92c 100644 --- a/bin/oe/upgrade.rs +++ b/bin/oe/upgrade.rs @@ -42,7 +42,7 @@ impl From for Error { } } -const CURRENT_VERSION: &'static str = env!("CARGO_PKG_VERSION"); +const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[derive(Hash, PartialEq, Eq)] struct UpgradeKey { @@ -134,11 +134,11 @@ where } pub fn upgrade(db_path: &str) -> Result { - with_locked_version(db_path, |ver| upgrade_from_version(ver)) + with_locked_version(db_path, upgrade_from_version) } fn file_exists(path: &Path) -> bool { - match fs::metadata(&path) { + match fs::metadata(path) { Err(ref e) if e.kind() == io::ErrorKind::NotFound => false, _ => true, } @@ -146,12 +146,12 @@ fn file_exists(path: &Path) -> bool { #[cfg(any(test, feature = "accounts"))] pub fn upgrade_key_location(from: &PathBuf, to: &PathBuf) { - match fs::create_dir_all(&to).and_then(|()| fs::read_dir(from)) { + match fs::create_dir_all(to).and_then(|()| fs::read_dir(from)) { Ok(entries) => { let files: Vec<_> = entries .filter_map(|f| { f.ok().and_then(|f| { - if f.file_type().ok().map_or(false, |f| f.is_file()) { + if f.file_type().ok().is_some_and(|f| f.is_file()) { f.file_name().to_str().map(|s| s.to_owned()) } else { None @@ -191,11 +191,11 @@ pub fn upgrade_key_location(from: &PathBuf, to: &PathBuf) { } fn upgrade_dir_location(source: &PathBuf, dest: &PathBuf) { - if file_exists(&source) { - if !file_exists(&dest) { + if file_exists(source) { + if !file_exists(dest) { let mut parent = dest.clone(); parent.pop(); - if let Err(e) = fs::create_dir_all(&parent).and_then(|()| fs::rename(&source, &dest)) { + if let Err(e) = fs::create_dir_all(&parent).and_then(|()| fs::rename(source, dest)) { debug!("Skipped path {:?} -> {:?} :{:?}", source, dest, e); } else { info!( @@ -243,5 +243,5 @@ pub fn upgrade_data_paths(base_path: &str, dirs: &DatabaseDirectories, pruning: upgrade_dir_location(&dirs.legacy_version_path(pruning), &dirs.db_path(pruning)); upgrade_dir_location(&dirs.legacy_snapshot_path(), &dirs.snapshot_path()); upgrade_dir_location(&dirs.legacy_network_path(), &dirs.network_path()); - upgrade_user_defaults(&dirs); + upgrade_user_defaults(dirs); } diff --git a/bin/oe/user_defaults.rs b/bin/oe/user_defaults.rs index 95fa66a78..a6d5ccebd 100644 --- a/bin/oe/user_defaults.rs +++ b/bin/oe/user_defaults.rs @@ -41,9 +41,9 @@ impl From for Seconds { } } -impl Into for Seconds { - fn into(self) -> Duration { - self.0 +impl From for Duration { + fn from(val: Seconds) -> Self { + val.0 } } @@ -77,9 +77,9 @@ pub enum Mode { Offline, } -impl Into for Mode { - fn into(self) -> ClientMode { - match self { +impl From for ClientMode { + fn from(val: Mode) -> Self { + match val { Mode::Active => ClientMode::Active, Mode::Passive { timeout, alarm } => ClientMode::Passive(timeout.into(), alarm.into()), Mode::Dark { timeout } => ClientMode::Dark(timeout.into()), From cbf7967c223bab6206cd9df2ea18e993ede55df5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 1 Apr 2025 19:30:44 +0200 Subject: [PATCH 390/687] stripped warning --- bin/oe/helpers.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/oe/helpers.rs b/bin/oe/helpers.rs index e5e9ce040..5691b38ca 100644 --- a/bin/oe/helpers.rs +++ b/bin/oe/helpers.rs @@ -42,8 +42,8 @@ pub fn to_duration(s: &str) -> Result { } fn clean_0x(s: &str) -> &str { - if s.starts_with("0x") { - &s[2..] + if let Some(stripped) = s.strip_prefix("0x") { + stripped } else { s } From 257411deb2f8f06681fa8d43f48588dd777f163f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 2 Apr 2025 17:12:18 +0200 Subject: [PATCH 391/687] proc_macro2 & syn update for rlp-derive + :( cargo fmt --all -- --config imports_granularity=Crate --- Cargo.lock | 98 +++++++++---------- bin/oe/account_utils.rs | 4 +- bin/oe/configuration.rs | 4 +- bin/oe/db/rocksdb/blooms.rs | 9 +- bin/oe/helpers.rs | 9 +- bin/oe/informant.rs | 3 +- bin/oe/params.rs | 18 +--- bin/oe/presale.rs | 2 +- bin/oe/reserved_peer_management.rs | 6 +- bin/oe/rpc_apis.rs | 4 +- bin/oe/run.rs | 7 +- bin/oe/secretstore.rs | 7 +- .../accounts/ethstore/src/account/crypto.rs | 10 +- .../ethstore/src/account/safe_account.rs | 4 +- .../ethstore/src/accounts_dir/disk.rs | 7 +- .../ethstore/src/accounts_dir/memory.rs | 3 +- .../accounts/ethstore/src/accounts_dir/mod.rs | 3 +- .../ethstore/src/accounts_dir/vault.rs | 4 +- crates/accounts/ethstore/src/ethkey.rs | 2 +- crates/accounts/ethstore/src/ethstore.rs | 31 +++--- crates/accounts/ethstore/src/import.rs | 6 +- crates/accounts/ethstore/src/presale.rs | 3 +- crates/accounts/ethstore/src/secret_store.rs | 7 +- crates/concensus/miner/src/gas_pricer.rs | 2 +- .../miner/src/pool/local_transactions.rs | 2 +- crates/concensus/miner/src/pool/replace.rs | 2 +- crates/util/rlp-derive/Cargo.toml | 6 +- crates/util/rlp-derive/src/de.rs | 1 - crates/util/rlp-derive/src/en.rs | 7 +- crates/vm/builtin/src/lib.rs | 24 +++-- crates/vm/evm/src/interpreter/gasometer.rs | 8 +- crates/vm/evm/src/interpreter/mod.rs | 6 +- 32 files changed, 155 insertions(+), 154 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17640fff8..6e22e1b3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -799,8 +799,8 @@ checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3" dependencies = [ "fnv", "ident_case", - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "strsim 0.10.0", "syn 2.0.16", ] @@ -812,7 +812,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" dependencies = [ "darling_core", - "quote 1.0.27", + "quote 1.0.40", "syn 2.0.16", ] @@ -831,8 +831,8 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -842,8 +842,8 @@ version = "0.99.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "298998b1cf6b5b2c8a7b023dfd45821825ce3ba8a8af55c921a0e734e4653f76" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -1105,8 +1105,8 @@ version = "0.2.0" source = "git+https://github.com/matter-labs/eip1962.git?rev=ece6cbabc41948db4200e41f0bfdab7ab94c7af8#ece6cbabc41948db4200e41f0bfdab7ab94c7af8" dependencies = [ "byteorder", - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -1150,8 +1150,8 @@ source = "git+https://github.com/rimrakhimov/ethabi?branch=rimrakhimov%2Fremove- dependencies = [ "ethabi 11.0.0", "heck", - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -1841,8 +1841,8 @@ dependencies = [ "num-bigint 0.2.3", "num-integer", "num-traits 0.2.15", - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -2439,8 +2439,8 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef5550a42e3740a0e71f909d4c861056a284060af885ae7aa6242820f920d9d" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -2609,8 +2609,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2cc6ea7f785232d9ca8786a44e9fa698f92149dcdc1acc4aa1fc69c4993d79e" dependencies = [ "proc-macro-crate", - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -2894,8 +2894,8 @@ checksum = "56a7d287fd2ac3f75b11f19a1c8a874a7d55744bd91f7a1b3e7cf87d4343c36d" dependencies = [ "beef", "fnv", - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "regex-syntax", "syn 1.0.94", "utf8-ranges", @@ -3577,7 +3577,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f557c32c6d268a07c921471619c0295f5efad3a0e76d4f97a05c091a51d110b2" dependencies = [ - "proc-macro2 1.0.58", + "proc-macro2 1.0.94", "syn 1.0.94", "synstructure", ] @@ -3950,9 +3950,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.58" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa1fb82fc0c281dd9671101b66b771ebbe1eaf967b96ac8740dcba4b70005ca8" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" dependencies = [ "unicode-ident", ] @@ -4041,11 +4041,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.27" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ - "proc-macro2 1.0.58", + "proc-macro2 1.0.94", ] [[package]] @@ -4413,8 +4413,8 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -4431,10 +4431,10 @@ dependencies = [ name = "rlp_derive" version = "0.1.0" dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", + "proc-macro2 1.0.94", + "quote 1.0.40", "rlp", - "syn 0.15.26", + "syn 2.0.16", ] [[package]] @@ -4636,8 +4636,8 @@ version = "1.0.164" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 2.0.16", ] @@ -4658,8 +4658,8 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -4687,8 +4687,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "568577ff0ef47b879f736cd66740e022f3672788cdf002a05a4e609ea5a6fb15" dependencies = [ "darling", - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 2.0.16", ] @@ -4895,8 +4895,8 @@ version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a07e33e919ebcd69113d5be0e4d70c5707004ff45188910106854f38b960df4a" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "unicode-xid 0.2.0", ] @@ -4906,8 +4906,8 @@ version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "unicode-ident", ] @@ -4926,8 +4926,8 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "575be94ccb86e8da37efb894a87e2b660be299b41d8ef347f9d6d79fbe61b1ba" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", "unicode-xid 0.2.0", ] @@ -5015,8 +5015,8 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", ] @@ -5739,8 +5739,8 @@ dependencies = [ "bumpalo", "lazy_static", "log", - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", "wasm-bindgen-shared", ] @@ -5751,7 +5751,7 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" dependencies = [ - "quote 1.0.27", + "quote 1.0.40", "wasm-bindgen-macro-support", ] @@ -5761,8 +5761,8 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" dependencies = [ - "proc-macro2 1.0.58", - "quote 1.0.27", + "proc-macro2 1.0.94", + "quote 1.0.40", "syn 1.0.94", "wasm-bindgen-backend", "wasm-bindgen-shared", diff --git a/bin/oe/account_utils.rs b/bin/oe/account_utils.rs index fd1ae28d4..e93c12e68 100644 --- a/bin/oe/account_utils.rs +++ b/bin/oe/account_utils.rs @@ -230,8 +230,8 @@ mod accounts { match account_provider.insert_account(secret, &Password::from(String::new())) { Err(e) => warn!("Unable to add development account: {}", e), Ok(address) => { - let _ = account_provider - .set_account_name(address, "Development Account".into()); + let _ = + account_provider.set_account_name(address, "Development Account".into()); let _ = account_provider.set_account_meta( address, ::serde_json::to_string( diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 8e90dbc3f..df47cbb1f 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -457,9 +457,7 @@ impl Configuration { gas_range_target: (floor, ceil), engine_signer: self.engine_signer()?, work_notify: self.work_notify(), - local_accounts: HashSet::from_iter( - to_addresses(&self.args.arg_tx_queue_locals)?, - ), + local_accounts: HashSet::from_iter(to_addresses(&self.args.arg_tx_queue_locals)?), }; Ok(extras) diff --git a/bin/oe/db/rocksdb/blooms.rs b/bin/oe/db/rocksdb/blooms.rs index e08448fcd..e481fa195 100644 --- a/bin/oe/db/rocksdb/blooms.rs +++ b/bin/oe/db/rocksdb/blooms.rs @@ -41,7 +41,9 @@ pub fn migrate_blooms>(path: P, config: &DatabaseConfig) -> Resul .filter(|(key, _)| key.len() == 6) .take_while(|(key, _)| key[0] == 3u8 && key[1] == 0u8) .map(|(key, group)| { - let index = ((key[2] as u64) << 24) | ((key[3] as u64) << 16) | ((key[4] as u64) << 8) + let index = ((key[2] as u64) << 24) + | ((key[3] as u64) << 16) + | ((key[4] as u64) << 8) | (key[5] as u64); let number = index * LOG_BLOOMS_ELEMENTS_PER_INDEX; @@ -63,7 +65,10 @@ pub fn migrate_blooms>(path: P, config: &DatabaseConfig) -> Resul .filter(|(key, _)| key.len() == 6) .take_while(|(key, _)| key[0] == 1u8 && key[1] == 0u8) .map(|(key, group)| { - let index = (key[2] as u64) | ((key[3] as u64) << 8) | ((key[4] as u64) << 16) | ((key[5] as u64) << 24); + let index = (key[2] as u64) + | ((key[3] as u64) << 8) + | ((key[4] as u64) << 16) + | ((key[5] as u64) << 24); let number = index * LOG_BLOOMS_ELEMENTS_PER_INDEX; let blooms = rlp::decode_list::(&group); diff --git a/bin/oe/helpers.rs b/bin/oe/helpers.rs index 5691b38ca..3869a1a56 100644 --- a/bin/oe/helpers.rs +++ b/bin/oe/helpers.rs @@ -355,7 +355,9 @@ pub fn password_prompt() -> Result { pub fn password_from_file(path: String) -> Result { let passwords = passwords_from_files(&[path])?; // use only first password from the file - passwords.first().cloned() + passwords + .first() + .cloned() .ok_or_else(|| "Password file seems to be empty.".to_owned()) } @@ -415,10 +417,7 @@ mod tests { to_duration("daily").unwrap(), Duration::from_secs(24 * 60 * 60) ); - assert_eq!( - to_duration("1hour").unwrap(), - Duration::from_secs(60 * 60) - ); + assert_eq!(to_duration("1hour").unwrap(), Duration::from_secs(60 * 60)); assert_eq!( to_duration("2hours").unwrap(), Duration::from_secs(2 * 60 * 60) diff --git a/bin/oe/informant.rs b/bin/oe/informant.rs index da580ca0e..aabf3a8ff 100644 --- a/bin/oe/informant.rs +++ b/bin/oe/informant.rs @@ -255,7 +255,8 @@ impl Informant { let snapshot_sync = sync_info.as_ref().is_some_and(|s| s.snapshot_sync) && self .snapshot - .as_ref().is_some_and(|s| match s.restoration_status() { + .as_ref() + .is_some_and(|s| match s.restoration_status() { RestorationStatus::Ongoing { .. } | RestorationStatus::Initializing { .. } => { true } diff --git a/bin/oe/params.rs b/bin/oe/params.rs index 31b28ab1b..6ff18d15e 100644 --- a/bin/oe/params.rs +++ b/bin/oe/params.rs @@ -36,8 +36,7 @@ use parity_version::version_data; use crate::configuration; -#[derive(Debug, PartialEq)] -#[derive(Default)] +#[derive(Debug, PartialEq, Default)] pub enum SpecType { #[default] Foundation, @@ -60,7 +59,6 @@ pub enum SpecType { Custom(String), } - impl str::FromStr for SpecType { type Err = String; @@ -152,15 +150,13 @@ impl SpecType { } } -#[derive(Debug, PartialEq)] -#[derive(Default)] +#[derive(Debug, PartialEq, Default)] pub enum Pruning { Specific(Algorithm), #[default] Auto, } - impl str::FromStr for Pruning { type Err = String; @@ -208,10 +204,7 @@ impl str::FromStr for ResealPolicy { x => return Err(format!("Invalid reseal value: {}", x)), }; - let reseal = ResealPolicy { - own, - external, - }; + let reseal = ResealPolicy { own, external }; Ok(reseal) } @@ -305,8 +298,7 @@ impl Default for MinerExtras { } /// 3-value enum. -#[derive(Debug, Clone, Copy, PartialEq)] -#[derive(Default)] +#[derive(Debug, Clone, Copy, PartialEq, Default)] pub enum Switch { /// True. On, @@ -317,7 +309,6 @@ pub enum Switch { Auto, } - impl str::FromStr for Switch { type Err = String; @@ -348,7 +339,6 @@ pub fn fatdb_switch_to_bool( user_defaults: &UserDefaults, _algorithm: Algorithm, ) -> Result { - match (user_defaults.is_first_launch, switch, user_defaults.fat_db) { (false, Switch::On, false) => Err("FatDB resync required".into()), (_, Switch::On, _) => Ok(true), diff --git a/bin/oe/presale.rs b/bin/oe/presale.rs index 5fb83aa24..45190afae 100644 --- a/bin/oe/presale.rs +++ b/bin/oe/presale.rs @@ -15,10 +15,10 @@ // along with OpenEthereum. If not, see . use crate::{ + crypto::publickey, helpers::{password_from_file, password_prompt}, params::SpecType, }; -use crate::crypto::publickey; use ethkey::Password; use ethstore::PresaleWallet; diff --git a/bin/oe/reserved_peer_management.rs b/bin/oe/reserved_peer_management.rs index ec46a03b5..54b7ed3b8 100644 --- a/bin/oe/reserved_peer_management.rs +++ b/bin/oe/reserved_peer_management.rs @@ -100,13 +100,15 @@ impl ReservedPeersManagement for ReservedPeersWrapper { #[cfg(test)] mod tests { use super::*; - use crate::network::{NetworkContext, ProtocolId}; + use crate::{ + network::{NetworkContext, ProtocolId}, + sync::ManageNetwork, + }; use std::{ net::{Ipv4Addr, SocketAddrV4}, ops::RangeInclusive, sync::Arc, }; - use crate::sync::ManageNetwork; pub struct TestManageNetwork; diff --git a/bin/oe/rpc_apis.rs b/bin/oe/rpc_apis.rs index 77f327d57..86f4910f6 100644 --- a/bin/oe/rpc_apis.rs +++ b/bin/oe/rpc_apis.rs @@ -99,8 +99,7 @@ impl FromStr for Api { } } -#[derive(Debug, Clone)] -#[derive(Default)] +#[derive(Debug, Clone, Default)] pub enum ApiSet { // Unsafe context (like jsonrpc over http) #[default] @@ -115,7 +114,6 @@ pub enum ApiSet { List(HashSet), } - impl PartialEq for ApiSet { fn eq(&self, other: &Self) -> bool { self.list_apis() == other.list_apis() diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 749316224..df343f153 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -37,7 +37,7 @@ use crate::{ }, reserved_peer_management::ReservedPeersWrapper, rpc, rpc_apis, secretstore, signer, - sync::{self, SyncConfig, SyncProvider}, + sync::{self, SyncConfig, SyncProvider, SyncState}, user_defaults::UserDefaults, }; use ansi_term::Colour; @@ -59,7 +59,6 @@ use node_filter::NodeFilter; use parity_rpc::{informant, is_major_importing, NetworkSettings}; use parity_runtime::Runtime; use parity_version::version; -use crate::sync::SyncState; // How often we attempt to take a snapshot: only snapshot on blocknumbers that are multiples of this. const SNAPSHOT_PERIOD: u64 = 20000; @@ -165,9 +164,7 @@ impl ChainSyncing for SyncProviderWrapper { /// are we syncing in any means ? fn is_syncing(&self) -> bool { match self.sync_provider.upgrade() { - Some(sync_arc) => { - sync_arc.status().state != SyncState::Idle - } + Some(sync_arc) => sync_arc.status().state != SyncState::Idle, // We also indicate the "syncing" state when the SyncProvider has already been destroyed. None => true, } diff --git a/bin/oe/secretstore.rs b/bin/oe/secretstore.rs index a64954c09..7a78c46ef 100644 --- a/bin/oe/secretstore.rs +++ b/bin/oe/secretstore.rs @@ -14,8 +14,11 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::{account_utils::AccountProvider, sync::SyncProvider}; -use crate::crypto::publickey::{Public, Secret}; +use crate::{ + account_utils::AccountProvider, + crypto::publickey::{Public, Secret}, + sync::SyncProvider, +}; use dir::{default_data_path, helpers::replace_home}; use ethcore::{client::Client, miner::Miner}; use ethereum_types::Address; diff --git a/crates/accounts/ethstore/src/account/crypto.rs b/crates/accounts/ethstore/src/account/crypto.rs index 852a3ee7a..bb021fbbd 100644 --- a/crates/accounts/ethstore/src/account/crypto.rs +++ b/crates/accounts/ethstore/src/account/crypto.rs @@ -14,14 +14,16 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::account::{Aes128Ctr, Cipher, Kdf, Pbkdf2, Prf}; +use crate::{ + account::{Aes128Ctr, Cipher, Kdf, Pbkdf2, Prf}, + json, + random::Random, + Error, +}; use crypto::{self, publickey::Secret, Keccak256}; use ethkey::Password; -use crate::json; -use crate::random::Random; use smallvec::SmallVec; use std::{num::NonZeroU32, str}; -use crate::Error; /// Encrypted data #[derive(Debug, PartialEq, Clone)] diff --git a/crates/accounts/ethstore/src/account/safe_account.rs b/crates/accounts/ethstore/src/account/safe_account.rs index c5940a4f1..66fa807e3 100644 --- a/crates/accounts/ethstore/src/account/safe_account.rs +++ b/crates/accounts/ethstore/src/account/safe_account.rs @@ -15,15 +15,13 @@ // along with OpenEthereum. If not, see . use super::crypto::Crypto; -use crate::account::Version; +use crate::{account::Version, json, Error}; use crypto::{ self, publickey::{ecdh::agree, sign, Address, KeyPair, Message, Public, Secret, Signature}, }; use ethkey::Password; -use crate::json; use std::num::NonZeroU32; -use crate::Error; /// Account representation. #[derive(Debug, PartialEq, Clone)] diff --git a/crates/accounts/ethstore/src/accounts_dir/disk.rs b/crates/accounts/ethstore/src/accounts_dir/disk.rs index 42366a3b3..78346f715 100644 --- a/crates/accounts/ethstore/src/accounts_dir/disk.rs +++ b/crates/accounts/ethstore/src/accounts_dir/disk.rs @@ -18,8 +18,11 @@ use super::{ vault::{VaultDiskDirectory, VAULT_FILE_NAME}, KeyDirectory, VaultKey, VaultKeyDirectory, VaultKeyDirectoryProvider, }; +use crate::{ + json::{self, Uuid}, + Error, SafeAccount, +}; use ethkey::Password; -use crate::json::{self, Uuid}; use std::{ collections::HashMap, fs, io, @@ -27,8 +30,6 @@ use std::{ path::{Path, PathBuf}, }; use time; -use crate::Error; -use crate::SafeAccount; const IGNORED_FILES: &'static [&'static str] = &[ "thumbs.db", diff --git a/crates/accounts/ethstore/src/accounts_dir/memory.rs b/crates/accounts/ethstore/src/accounts_dir/memory.rs index 8d5234a95..c03ab5c3f 100644 --- a/crates/accounts/ethstore/src/accounts_dir/memory.rs +++ b/crates/accounts/ethstore/src/accounts_dir/memory.rs @@ -20,8 +20,7 @@ use parking_lot::RwLock; use std::collections::HashMap; use super::KeyDirectory; -use crate::Error; -use crate::SafeAccount; +use crate::{Error, SafeAccount}; /// Accounts in-memory storage. #[derive(Default)] diff --git a/crates/accounts/ethstore/src/accounts_dir/mod.rs b/crates/accounts/ethstore/src/accounts_dir/mod.rs index 2eff6f09e..d6e4337f3 100644 --- a/crates/accounts/ethstore/src/accounts_dir/mod.rs +++ b/crates/accounts/ethstore/src/accounts_dir/mod.rs @@ -16,10 +16,9 @@ //! Accounts Directory +use crate::{Error, SafeAccount}; use ethkey::Password; use std::{num::NonZeroU32, path::PathBuf}; -use crate::Error; -use crate::SafeAccount; mod disk; mod memory; diff --git a/crates/accounts/ethstore/src/accounts_dir/vault.rs b/crates/accounts/ethstore/src/accounts_dir/vault.rs index 17a330f19..b981bf00d 100644 --- a/crates/accounts/ethstore/src/accounts_dir/vault.rs +++ b/crates/accounts/ethstore/src/accounts_dir/vault.rs @@ -19,15 +19,13 @@ use super::{ disk::{self, DiskDirectory, KeyFileManager}, KeyDirectory, SetKeyError, VaultKey, VaultKeyDirectory, }; +use crate::{json, Error, SafeAccount}; use crypto::Keccak256; -use crate::json; use parking_lot::Mutex; use std::{ fs, io, path::{Path, PathBuf}, }; -use crate::Error; -use crate::SafeAccount; /// Name of vault metadata file pub const VAULT_FILE_NAME: &'static str = "vault.json"; diff --git a/crates/accounts/ethstore/src/ethkey.rs b/crates/accounts/ethstore/src/ethkey.rs index 0290412d7..3d8671aca 100644 --- a/crates/accounts/ethstore/src/ethkey.rs +++ b/crates/accounts/ethstore/src/ethkey.rs @@ -15,9 +15,9 @@ // along with OpenEthereum. If not, see . //! ethkey reexport to make documentation look pretty. +use crate::json; pub use _ethkey::*; pub use crypto::publickey::Address; -use crate::json; impl Into for Address { fn into(self) -> json::H160 { diff --git a/crates/accounts/ethstore/src/ethstore.rs b/crates/accounts/ethstore/src/ethstore.rs index 43a2b6420..9621a796e 100644 --- a/crates/accounts/ethstore/src/ethstore.rs +++ b/crates/accounts/ethstore/src/ethstore.rs @@ -22,22 +22,19 @@ use std::{ time::{Duration, Instant}, }; -use crate::account::SafeAccount; -use crate::accounts_dir::{KeyDirectory, SetKeyError, VaultKey, VaultKeyDirectory}; +use crate::{ + account::SafeAccount, + accounts_dir::{KeyDirectory, SetKeyError, VaultKey, VaultKeyDirectory}, + json::{self, OpaqueKeyFile, Uuid}, + presale::PresaleWallet, + random::Random, + Derivation, Error, OpaqueSecret, SecretStore, SecretVaultRef, SimpleSecretStore, + StoreAccountRef, +}; use crypto::publickey::{ self, Address, ExtendedKeyPair, KeyPair, Message, Public, Secret, Signature, }; use ethkey::Password; -use crate::json::{self, OpaqueKeyFile, Uuid}; -use crate::presale::PresaleWallet; -use crate::random::Random; -use crate::Derivation; -use crate::Error; -use crate::OpaqueSecret; -use crate::SecretStore; -use crate::SecretVaultRef; -use crate::SimpleSecretStore; -use crate::StoreAccountRef; lazy_static! { static ref KEY_ITERATIONS: NonZeroU32 = @@ -898,12 +895,14 @@ mod tests { use self::tempdir::TempDir; use super::{EthMultiStore, EthStore}; - use crate::accounts_dir::{KeyDirectory, MemoryDirectory, RootDiskDirectory}; + use crate::{ + accounts_dir::{KeyDirectory, MemoryDirectory, RootDiskDirectory}, + secret_store::{ + Derivation, SecretStore, SecretVaultRef, SimpleSecretStore, StoreAccountRef, + }, + }; use crypto::publickey::{Generator, KeyPair, Random}; use ethereum_types::H256; - use crate::secret_store::{ - Derivation, SecretStore, SecretVaultRef, SimpleSecretStore, StoreAccountRef, - }; fn keypair() -> KeyPair { Random.generate() diff --git a/crates/accounts/ethstore/src/import.rs b/crates/accounts/ethstore/src/import.rs index 5346950ec..ff199167f 100644 --- a/crates/accounts/ethstore/src/import.rs +++ b/crates/accounts/ethstore/src/import.rs @@ -16,9 +16,11 @@ use std::{collections::HashSet, fs, path::Path}; -use crate::accounts_dir::{DiskKeyFileManager, KeyDirectory, KeyFileManager}; +use crate::{ + accounts_dir::{DiskKeyFileManager, KeyDirectory, KeyFileManager}, + Error, +}; use crypto::publickey::Address; -use crate::Error; /// Import an account from a file. pub fn import_account(path: &Path, dst: &dyn KeyDirectory) -> Result { diff --git a/crates/accounts/ethstore/src/presale.rs b/crates/accounts/ethstore/src/presale.rs index 9cd731ed8..73118db22 100644 --- a/crates/accounts/ethstore/src/presale.rs +++ b/crates/accounts/ethstore/src/presale.rs @@ -14,15 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{json, Error}; use crypto::{ self, pbkdf2, publickey::{Address, KeyPair, Secret}, Keccak256, }; use ethkey::Password; -use crate::json; use std::{fs, num::NonZeroU32, path::Path}; -use crate::Error; /// Pre-sale wallet. pub struct PresaleWallet { diff --git a/crates/accounts/ethstore/src/secret_store.rs b/crates/accounts/ethstore/src/secret_store.rs index 7d712cc51..487635230 100644 --- a/crates/accounts/ethstore/src/secret_store.rs +++ b/crates/accounts/ethstore/src/secret_store.rs @@ -14,17 +14,18 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{ + json::{OpaqueKeyFile, Uuid}, + Error, OpaqueSecret, +}; use crypto::publickey::{Address, Message, Public, Secret, Signature}; use ethereum_types::H256; use ethkey::Password; -use crate::json::{OpaqueKeyFile, Uuid}; use std::{ cmp::Ordering, hash::{Hash, Hasher}, path::PathBuf, }; -use crate::Error; -use crate::OpaqueSecret; /// Key directory reference #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] diff --git a/crates/concensus/miner/src/gas_pricer.rs b/crates/concensus/miner/src/gas_pricer.rs index 330eb56f5..7cbc61df0 100644 --- a/crates/concensus/miner/src/gas_pricer.rs +++ b/crates/concensus/miner/src/gas_pricer.rs @@ -16,9 +16,9 @@ //! Auto-updates minimal gas price requirement. -use ethereum_types::U256; #[cfg(feature = "price-info")] use crate::gas_price_calibrator::GasPriceCalibrator; +use ethereum_types::U256; /// Struct to look after updating the acceptable gas price of a miner. #[derive(Debug, PartialEq)] diff --git a/crates/concensus/miner/src/pool/local_transactions.rs b/crates/concensus/miner/src/pool/local_transactions.rs index 7d510db6e..b028a247d 100644 --- a/crates/concensus/miner/src/pool/local_transactions.rs +++ b/crates/concensus/miner/src/pool/local_transactions.rs @@ -18,9 +18,9 @@ use std::{fmt, sync::Arc}; +use crate::pool::{ScoredTransaction, VerifiedTransaction as Transaction}; use ethereum_types::H256; use linked_hash_map::LinkedHashMap; -use crate::pool::{ScoredTransaction, VerifiedTransaction as Transaction}; use txpool::{self, VerifiedTransaction}; /// Status of local transaction. diff --git a/crates/concensus/miner/src/pool/replace.rs b/crates/concensus/miner/src/pool/replace.rs index 9b66762f6..edea5ff70 100644 --- a/crates/concensus/miner/src/pool/replace.rs +++ b/crates/concensus/miner/src/pool/replace.rs @@ -239,7 +239,6 @@ where mod tests { use super::*; - use crypto::publickey::{Generator, KeyPair, Random}; use crate::pool::{ scoring::*, tests::{ @@ -248,6 +247,7 @@ mod tests { }, PrioritizationStrategy, VerifiedTransaction, }; + use crypto::publickey::{Generator, KeyPair, Random}; use std::sync::Arc; use txpool::{scoring::Choice::*, ShouldReplace}; diff --git a/crates/util/rlp-derive/Cargo.toml b/crates/util/rlp-derive/Cargo.toml index d843d75a5..953c83fee 100644 --- a/crates/util/rlp-derive/Cargo.toml +++ b/crates/util/rlp-derive/Cargo.toml @@ -8,9 +8,9 @@ name = "rlp_derive" proc-macro = true [dependencies] -syn = "0.15" -quote = "0.6" -proc-macro2 = "0.4" +syn = "2.0" +quote = "1.0.40" +proc-macro2 = "1.0.40" [dev-dependencies] rlp = { version = "0.4.6" } diff --git a/crates/util/rlp-derive/src/de.rs b/crates/util/rlp-derive/src/de.rs index 484eb1d52..26678d416 100644 --- a/crates/util/rlp-derive/src/de.rs +++ b/crates/util/rlp-derive/src/de.rs @@ -146,7 +146,6 @@ fn decodable_field(index: usize, field: &syn::Field, quotes: ParseQuotes) -> Tok .segments .first() .expect("there must be at least 1 segment") - .value() .ident; if &ident.to_string() == "Vec" { if quotes.takes_index { diff --git a/crates/util/rlp-derive/src/en.rs b/crates/util/rlp-derive/src/en.rs index dd61a5ae9..b302c4f64 100644 --- a/crates/util/rlp-derive/src/en.rs +++ b/crates/util/rlp-derive/src/en.rs @@ -116,22 +116,21 @@ fn encodable_field(index: usize, field: &syn::Field) -> TokenStream { .segments .first() .expect("there must be at least 1 segment"); - let ident = &top_segment.value().ident; + let ident = &top_segment.ident; if &ident.to_string() == "Vec" { - let inner_ident = match top_segment.value().arguments { + let inner_ident = match top_segment.arguments { syn::PathArguments::AngleBracketed(ref angle) => { let ty = angle .args .first() .expect("Vec has only one angle bracketed type; qed"); - match **ty.value() { + match ty { syn::GenericArgument::Type(syn::Type::Path(ref path)) => { &path .path .segments .first() .expect("there must be at least 1 segment") - .value() .ident } _ => panic!("rlp_derive not supported"), diff --git a/crates/vm/builtin/src/lib.rs b/crates/vm/builtin/src/lib.rs index acd062f31..f0982dc0e 100644 --- a/crates/vm/builtin/src/lib.rs +++ b/crates/vm/builtin/src/lib.rs @@ -923,8 +923,6 @@ impl Implementation for Ripemd160 { fn modexp(mut base: BigUint, exp: Vec, modulus: BigUint) -> BigUint { const BITS_PER_DIGIT: usize = 8; - - // n^m % 0 || n^m % 1 if modulus <= BigUint::from(1 as usize) { return BigUint::from(0 as usize); @@ -935,7 +933,6 @@ fn modexp(mut base: BigUint, exp: Vec, modulus: BigUint) -> BigUint { // n^0 % m if exp.peek().is_none() { - return BigUint::from(1 as usize); } @@ -1529,29 +1526,40 @@ mod tests { fn modexp_func() { // n^0 % m == 1 - let mut base = BigUint::parse_bytes(b"12345", 10).unwrap(); let mut exp = BigUint::from(0 as usize); let mut modulus = BigUint::parse_bytes(b"789", 10).unwrap(); - assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::from(1 as usize)); + assert_eq!( + me(base, exp.to_bytes_be(), modulus), + BigUint::from(1 as usize) + ); // 0^n % m == 0 base = BigUint::from(0 as usize); exp = BigUint::parse_bytes(b"12345", 10).unwrap(); modulus = BigUint::parse_bytes(b"789", 10).unwrap(); - assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::from(0 as usize)); + assert_eq!( + me(base, exp.to_bytes_be(), modulus), + BigUint::from(0 as usize) + ); // n^m % 1 == 0 base = BigUint::parse_bytes(b"12345", 10).unwrap(); exp = BigUint::parse_bytes(b"789", 10).unwrap(); modulus = BigUint::from(1 as usize); - assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::from(0 as usize)); + assert_eq!( + me(base, exp.to_bytes_be(), modulus), + BigUint::from(0 as usize) + ); // if n % d == 0, then n^m % d == 0 base = BigUint::parse_bytes(b"12345", 10).unwrap(); exp = BigUint::parse_bytes(b"789", 10).unwrap(); modulus = BigUint::parse_bytes(b"15", 10).unwrap(); - assert_eq!(me(base, exp.to_bytes_be(), modulus), BigUint::from(0 as usize)); + assert_eq!( + me(base, exp.to_bytes_be(), modulus), + BigUint::from(0 as usize) + ); // others base = BigUint::parse_bytes(b"12345", 10).unwrap(); diff --git a/crates/vm/evm/src/interpreter/gasometer.rs b/crates/vm/evm/src/interpreter/gasometer.rs index 4fc46d53d..cfdb60cc4 100644 --- a/crates/vm/evm/src/interpreter/gasometer.rs +++ b/crates/vm/evm/src/interpreter/gasometer.rs @@ -19,9 +19,11 @@ use ethereum_types::{Address, BigEndianHash, U256}; use std::cmp; use super::stack::VecStack; -use crate::evm; -use crate::instructions::{self, Instruction, InstructionInfo}; -use crate::interpreter::stack::Stack; +use crate::{ + evm, + instructions::{self, Instruction, InstructionInfo}, + interpreter::stack::Stack, +}; use vm::{self, Schedule}; macro_rules! overflowing { diff --git a/crates/vm/evm/src/interpreter/mod.rs b/crates/vm/evm/src/interpreter/mod.rs index b7d7a3b39..f55c2ba6e 100644 --- a/crates/vm/evm/src/interpreter/mod.rs +++ b/crates/vm/evm/src/interpreter/mod.rs @@ -34,8 +34,10 @@ use vm::{ GasLeft, MessageCallResult, ParamsType, ReturnData, Schedule, TrapError, TrapKind, }; -use crate::evm::CostType; -use crate::instructions::{self, Instruction, InstructionInfo}; +use crate::{ + evm::CostType, + instructions::{self, Instruction, InstructionInfo}, +}; pub use self::shared_cache::SharedCache; use self::{ From b629fd6187c8e3077f2fd1b8fa33d856c5b9e1b1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 3 Apr 2025 13:48:17 +0200 Subject: [PATCH 392/687] rlp-derive update to 0.2 --- Cargo.lock | 41 ++++++++++++++-------------- crates/db/db/Cargo.toml | 2 +- crates/ethcore/Cargo.toml | 2 +- crates/ethcore/blockchain/Cargo.toml | 2 +- crates/ethcore/types/Cargo.toml | 2 +- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e22e1b3d..bd63ac44e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -509,7 +509,7 @@ dependencies = [ "parity-crypto", "parity-util-mem", "rlp", - "rlp_derive", + "rlp-derive 0.2.0", "rustc-hex 1.0.0", "serde", "serde_json", @@ -802,7 +802,7 @@ dependencies = [ "proc-macro2 1.0.94", "quote 1.0.40", "strsim 0.10.0", - "syn 2.0.16", + "syn 2.0.100", ] [[package]] @@ -813,7 +813,7 @@ checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" dependencies = [ "darling_core", "quote 1.0.40", - "syn 2.0.16", + "syn 2.0.100", ] [[package]] @@ -1270,8 +1270,8 @@ dependencies = [ "regex", "reth-util", "rlp", + "rlp-derive 0.2.0", "rlp_compress", - "rlp_derive", "rmp-serde", "rustc-hex 1.0.0", "scopeguard 1.1.0", @@ -1334,8 +1334,8 @@ dependencies = [ "rand 0.7.3", "rayon", "rlp", + "rlp-derive 0.2.0", "rlp_compress", - "rlp_derive", "rustc-hex 1.0.0", "stats", "tempdir", @@ -1392,7 +1392,7 @@ dependencies = [ "parity-util-mem", "parking_lot 0.11.1", "rlp", - "rlp_derive", + "rlp-derive 0.2.0", "stats", ] @@ -1606,7 +1606,7 @@ dependencies = [ "maplit", "parity-util-mem", "rlp", - "rlp-derive", + "rlp-derive 0.1.0", ] [[package]] @@ -4419,22 +4419,23 @@ dependencies = [ ] [[package]] -name = "rlp_compress" -version = "0.1.0" +name = "rlp-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "652db34deaaa57929e10ca18e5454a32cb0efc351ae80d320334bbf907b908b3" dependencies = [ - "elastic-array", - "lazy_static", - "rlp", + "proc-macro2 1.0.94", + "quote 1.0.40", + "syn 2.0.100", ] [[package]] -name = "rlp_derive" +name = "rlp_compress" version = "0.1.0" dependencies = [ - "proc-macro2 1.0.94", - "quote 1.0.40", + "elastic-array", + "lazy_static", "rlp", - "syn 2.0.16", ] [[package]] @@ -4638,7 +4639,7 @@ checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" dependencies = [ "proc-macro2 1.0.94", "quote 1.0.40", - "syn 2.0.16", + "syn 2.0.100", ] [[package]] @@ -4689,7 +4690,7 @@ dependencies = [ "darling", "proc-macro2 1.0.94", "quote 1.0.40", - "syn 2.0.16", + "syn 2.0.100", ] [[package]] @@ -4902,9 +4903,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.16" +version = "2.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" dependencies = [ "proc-macro2 1.0.94", "quote 1.0.40", diff --git a/crates/db/db/Cargo.toml b/crates/db/db/Cargo.toml index 95ebb5071..cf04a5706 100644 --- a/crates/db/db/Cargo.toml +++ b/crates/db/db/Cargo.toml @@ -16,5 +16,5 @@ kvdb-memorydb = "0.1" parity-util-mem = "0.7" parking_lot = "0.11.1" rlp = { version = "0.4.6" } -rlp_derive = { path = "../../util/rlp-derive" } +rlp-derive = { version = "0.2"} stats = { path = "../../util/stats" } \ No newline at end of file diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index f10b39a9f..7ec19370d 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -67,7 +67,7 @@ rayon = "1.1" regex = "1.3.9" rmp-serde = "1.1.0" rlp = { version = "0.4.6" } -rlp_derive = { path = "../util/rlp-derive" } +rlp-derive = { version = "0.2" } rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" diff --git a/crates/ethcore/blockchain/Cargo.toml b/crates/ethcore/blockchain/Cargo.toml index 7052b09b1..e0c8f44c7 100644 --- a/crates/ethcore/blockchain/Cargo.toml +++ b/crates/ethcore/blockchain/Cargo.toml @@ -25,7 +25,7 @@ rand = "0.7.3" rayon = "1.1" rlp = { version = "0.4.6" } rlp_compress = { path = "../../util/rlp-compress" } -rlp_derive = { path = "../../util/rlp-derive" } +rlp-derive = { version = "0.2" } triehash-ethereum = { version = "0.2", path = "../../util/triehash-ethereum" } stats = { path = "../../util/stats" } diff --git a/crates/ethcore/types/Cargo.toml b/crates/ethcore/types/Cargo.toml index e0c059a3e..cbfaf37da 100644 --- a/crates/ethcore/types/Cargo.toml +++ b/crates/ethcore/types/Cargo.toml @@ -16,7 +16,7 @@ parity-bytes = "0.1" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } parity-util-mem = "0.7" rlp = { version = "0.4.6" } -rlp_derive = { path = "../../util/rlp-derive" } +rlp-derive = { version = "0.2" } unexpected = { path = "../../util/unexpected" } serde = "1.0" serde_json = "1.0" From edf1f79aedd89e3d8021340171e65a608d25bf93 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 3 Apr 2025 13:54:35 +0200 Subject: [PATCH 393/687] test fixes for "use json::" --- crates/accounts/ethstore/src/json/key_file.rs | 2 +- crates/accounts/ethstore/src/json/presale.rs | 2 +- crates/accounts/ethstore/src/json/vault_file.rs | 2 +- crates/accounts/ethstore/src/json/vault_key_file.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/accounts/ethstore/src/json/key_file.rs b/crates/accounts/ethstore/src/json/key_file.rs index 9c2aec51e..00e9b9548 100644 --- a/crates/accounts/ethstore/src/json/key_file.rs +++ b/crates/accounts/ethstore/src/json/key_file.rs @@ -206,7 +206,7 @@ impl KeyFile { #[cfg(test)] mod tests { - use json::{Aes128Ctr, Cipher, Crypto, Kdf, KeyFile, Scrypt, Uuid, Version}; + use crate::json::{Aes128Ctr, Cipher, Crypto, Kdf, KeyFile, Scrypt, Uuid, Version}; use serde_json; use std::str::FromStr; diff --git a/crates/accounts/ethstore/src/json/presale.rs b/crates/accounts/ethstore/src/json/presale.rs index a2c9d6ce2..84b51f5b6 100644 --- a/crates/accounts/ethstore/src/json/presale.rs +++ b/crates/accounts/ethstore/src/json/presale.rs @@ -38,7 +38,7 @@ impl PresaleWallet { #[cfg(test)] mod tests { - use json::{PresaleWallet, H160}; + use crate::json::{PresaleWallet, H160}; use serde_json; use std::str::FromStr; diff --git a/crates/accounts/ethstore/src/json/vault_file.rs b/crates/accounts/ethstore/src/json/vault_file.rs index cd3de8e15..87f03d737 100644 --- a/crates/accounts/ethstore/src/json/vault_file.rs +++ b/crates/accounts/ethstore/src/json/vault_file.rs @@ -45,7 +45,7 @@ impl VaultFile { #[cfg(test)] mod test { - use json::{Aes128Ctr, Cipher, Crypto, Kdf, Pbkdf2, Prf, VaultFile}; + use crate::json::{Aes128Ctr, Cipher, Crypto, Kdf, Pbkdf2, Prf, VaultFile}; use serde_json; use std::num::NonZeroU32; diff --git a/crates/accounts/ethstore/src/json/vault_key_file.rs b/crates/accounts/ethstore/src/json/vault_key_file.rs index 47b53a290..f48d52a4a 100644 --- a/crates/accounts/ethstore/src/json/vault_key_file.rs +++ b/crates/accounts/ethstore/src/json/vault_key_file.rs @@ -117,7 +117,7 @@ impl VaultKeyMeta { #[cfg(test)] mod test { - use json::{ + use crate::json::{ insert_vault_name_to_json_meta, remove_vault_name_from_json_meta, Aes128Ctr, Cipher, Crypto, Kdf, Pbkdf2, Prf, VaultKeyFile, Version, }; From f1fc42ce94683efd8e61027135802e9026706b83 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 3 Apr 2025 13:57:43 +0200 Subject: [PATCH 394/687] use crate::Client; --- crates/concensus/miner/price-info/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/concensus/miner/price-info/src/lib.rs b/crates/concensus/miner/price-info/src/lib.rs index 7cb422724..9f7258c10 100644 --- a/crates/concensus/miner/price-info/src/lib.rs +++ b/crates/concensus/miner/price-info/src/lib.rs @@ -151,7 +151,7 @@ mod test { atomic::{AtomicBool, Ordering}, Arc, }; - use Client; + use crate::Client; fn price_info_ok(response: &str, executor: Executor) -> Client> { Client::new( From d7144556f640144d3cca3264419bcff07e871f99 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 3 Apr 2025 14:43:53 +0200 Subject: [PATCH 395/687] fixed most tests (use crate::) --- crates/concensus/miner/src/pool/local_transactions.rs | 2 +- crates/concensus/miner/src/pool/replace.rs | 6 +++--- crates/concensus/miner/src/pool/scoring.rs | 6 +++--- crates/vm/evm/src/interpreter/mod.rs | 4 ++-- crates/vm/evm/src/tests.rs | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/concensus/miner/src/pool/local_transactions.rs b/crates/concensus/miner/src/pool/local_transactions.rs index b028a247d..5c52972d3 100644 --- a/crates/concensus/miner/src/pool/local_transactions.rs +++ b/crates/concensus/miner/src/pool/local_transactions.rs @@ -259,7 +259,7 @@ mod tests { use txpool::Listener; use types::transaction; - use pool; + use crate::pool; #[test] fn should_add_transaction_as_pending() { diff --git a/crates/concensus/miner/src/pool/replace.rs b/crates/concensus/miner/src/pool/replace.rs index edea5ff70..67019b3c2 100644 --- a/crates/concensus/miner/src/pool/replace.rs +++ b/crates/concensus/miner/src/pool/replace.rs @@ -253,7 +253,7 @@ mod tests { fn local_tx_verified(tx: Tx, keypair: &KeyPair) -> VerifiedTransaction { let mut verified_tx = tx.unsigned().sign(keypair.secret(), None).verified(); - verified_tx.priority = ::pool::Priority::Local; + verified_tx.priority = crate::pool::Priority::Local; verified_tx } @@ -476,7 +476,7 @@ mod tests { ..Default::default() }; let mut verified_tx = tx.signed().verified(); - verified_tx.priority = ::pool::Priority::Local; + verified_tx.priority = crate::pool::Priority::Local; verified_tx }; let tx_local_high_gas = { @@ -486,7 +486,7 @@ mod tests { ..Default::default() }; let mut verified_tx = tx.signed().verified(); - verified_tx.priority = ::pool::Priority::Local; + verified_tx.priority = crate::pool::Priority::Local; verified_tx }; diff --git a/crates/concensus/miner/src/pool/scoring.rs b/crates/concensus/miner/src/pool/scoring.rs index 83e20e927..9f258ea03 100644 --- a/crates/concensus/miner/src/pool/scoring.rs +++ b/crates/concensus/miner/src/pool/scoring.rs @@ -200,9 +200,9 @@ mod tests { .map(|(i, tx)| { let mut verified = tx.verified(); verified.priority = match i { - 0 => ::pool::Priority::Local, - 1 => ::pool::Priority::Retracted, - _ => ::pool::Priority::Regular, + 0 => crate::pool::Priority::Local, + 1 => crate::pool::Priority::Retracted, + _ => crate::pool::Priority::Regular, }; txpool::Transaction { insertion_id: 0, diff --git a/crates/vm/evm/src/interpreter/mod.rs b/crates/vm/evm/src/interpreter/mod.rs index f55c2ba6e..e54523711 100644 --- a/crates/vm/evm/src/interpreter/mod.rs +++ b/crates/vm/evm/src/interpreter/mod.rs @@ -1546,7 +1546,7 @@ fn address_to_u256(value: Address) -> U256 { #[cfg(test)] mod tests { use ethereum_types::Address; - use factory::Factory; + use crate::factory::Factory; use rustc_hex::FromHex; use std::sync::Arc; use vm::{ @@ -1554,7 +1554,7 @@ mod tests { tests::{test_finalize, FakeExt}, ActionParams, ActionValue, Exec, }; - use vmtype::VMType; + use crate::vmtype::VMType; fn interpreter(params: ActionParams, ext: &dyn vm::Ext) -> Box { Factory::new(VMType::Interpreter, 1).create(params, ext.schedule(), ext.depth()) diff --git a/crates/vm/evm/src/tests.rs b/crates/vm/evm/src/tests.rs index b97294ea0..6bc4f5dc1 100644 --- a/crates/vm/evm/src/tests.rs +++ b/crates/vm/evm/src/tests.rs @@ -16,7 +16,7 @@ use super::interpreter::MAX_SUB_STACK_SIZE; use ethereum_types::{Address, H256, U256}; -use factory::Factory; +use crate::factory::Factory; use hex_literal::hex; use rustc_hex::FromHex; use std::{ @@ -31,7 +31,7 @@ use vm::{ tests::{test_finalize, FakeCall, FakeCallType, FakeExt}, ActionParams, ActionValue, Ext, }; -use vmtype::VMType; +use crate::vmtype::VMType; evm_test! {test_add: test_add_int} fn test_add(factory: super::Factory) { From a13c1b7dbe6db5001c9fac366e365abbce85d119 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 3 Apr 2025 14:52:46 +0200 Subject: [PATCH 396/687] defaulting to rust edition 2015 --- Cargo.toml | 1 + bin/ethkey/Cargo.toml | 1 + bin/ethstore/Cargo.toml | 1 + bin/evmbin/Cargo.toml | 1 + bin/oe/logger/Cargo.toml | 1 + crates/accounts/ethkey/Cargo.toml | 1 + crates/concensus/ethash/Cargo.toml | 1 + crates/concensus/miner/local-store/Cargo.toml | 1 + crates/concensus/miner/stratum/Cargo.toml | 1 + crates/concensus/miner/using-queue/Cargo.toml | 1 + crates/db/bloom/Cargo.toml | 1 + crates/db/journaldb/Cargo.toml | 1 + crates/db/memory-db/Cargo.toml | 1 + crates/db/migration-rocksdb/Cargo.toml | 1 + crates/ethcore/Cargo.toml | 1 + crates/ethcore/service/Cargo.toml | 1 + .../ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml | 1 + crates/ethcore/sync/Cargo.toml | 1 + crates/net/fake-fetch/Cargo.toml | 1 + crates/net/network-devp2p/Cargo.toml | 1 + crates/net/network/Cargo.toml | 1 + crates/net/node-filter/Cargo.toml | 1 + crates/rpc/Cargo.toml | 1 + crates/runtime/io/Cargo.toml | 1 + crates/runtime/runtime/Cargo.toml | 1 + crates/util/cli-signer/Cargo.toml | 1 + crates/util/cli-signer/rpc-client/Cargo.toml | 1 + crates/util/dir/Cargo.toml | 1 + crates/util/fastmap/Cargo.toml | 1 + crates/util/keccak-hasher/Cargo.toml | 1 + crates/util/len-caching-lock/Cargo.toml | 1 + crates/util/macros/Cargo.toml | 1 + crates/util/memory-cache/Cargo.toml | 1 + crates/util/panic-hook/Cargo.toml | 1 + crates/util/rlp-compress/Cargo.toml | 1 + crates/util/triehash-ethereum/Cargo.toml | 1 + crates/util/unexpected/Cargo.toml | 1 + crates/util/version/Cargo.toml | 1 + crates/vm/vm/Cargo.toml | 1 + crates/vm/wasm/Cargo.toml | 1 + 40 files changed, 40 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 371c7bfad..d6a9bd4bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ authors = [ "OpenEthereum developers", "Parity Technologies " ] +edition = "2015" [dependencies] blooms-db = { path = "crates/db/blooms-db" } diff --git a/bin/ethkey/Cargo.toml b/bin/ethkey/Cargo.toml index d5af93f26..8e05ce3eb 100644 --- a/bin/ethkey/Cargo.toml +++ b/bin/ethkey/Cargo.toml @@ -3,6 +3,7 @@ description = "Parity Ethereum Keys Generator CLI" name = "ethkey-cli" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] docopt = "1.0" diff --git a/bin/ethstore/Cargo.toml b/bin/ethstore/Cargo.toml index e03abc909..c82e9f685 100644 --- a/bin/ethstore/Cargo.toml +++ b/bin/ethstore/Cargo.toml @@ -3,6 +3,7 @@ description = "Parity Ethereum Key Management CLI" name = "ethstore-cli" version = "0.1.1" authors = ["Parity Technologies "] +edition = "2015" [dependencies] docopt = "1.0" diff --git a/bin/evmbin/Cargo.toml b/bin/evmbin/Cargo.toml index d6b896051..411914f9d 100644 --- a/bin/evmbin/Cargo.toml +++ b/bin/evmbin/Cargo.toml @@ -3,6 +3,7 @@ description = "Parity EVM Implementation" name = "evmbin" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [[bin]] name = "openethereum-evm" diff --git a/bin/oe/logger/Cargo.toml b/bin/oe/logger/Cargo.toml index 9c388dbbe..c8034f511 100644 --- a/bin/oe/logger/Cargo.toml +++ b/bin/oe/logger/Cargo.toml @@ -4,6 +4,7 @@ name = "ethcore-logger" version = "1.12.0" license = "GPL-3.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] log = "0.4" diff --git a/crates/accounts/ethkey/Cargo.toml b/crates/accounts/ethkey/Cargo.toml index 5b32bbaa2..af944ad02 100644 --- a/crates/accounts/ethkey/Cargo.toml +++ b/crates/accounts/ethkey/Cargo.toml @@ -3,6 +3,7 @@ description = "Parity Ethereum Keys Generator" name = "ethkey" version = "0.3.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] edit-distance = "2.0" diff --git a/crates/concensus/ethash/Cargo.toml b/crates/concensus/ethash/Cargo.toml index 448c14f49..b57d70852 100644 --- a/crates/concensus/ethash/Cargo.toml +++ b/crates/concensus/ethash/Cargo.toml @@ -3,6 +3,7 @@ description = "Parity Ethereum Ethash & ProgPoW Implementations" name = "ethash" version = "1.12.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] crunchy = "0.1.0" diff --git a/crates/concensus/miner/local-store/Cargo.toml b/crates/concensus/miner/local-store/Cargo.toml index 554ea9301..f02d65522 100644 --- a/crates/concensus/miner/local-store/Cargo.toml +++ b/crates/concensus/miner/local-store/Cargo.toml @@ -3,6 +3,7 @@ name = "parity-local-store" description = "Manages persistent local node data." version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] common-types = { path = "../../../ethcore/types" } diff --git a/crates/concensus/miner/stratum/Cargo.toml b/crates/concensus/miner/stratum/Cargo.toml index 44ba6a9a4..2ce6d926b 100644 --- a/crates/concensus/miner/stratum/Cargo.toml +++ b/crates/concensus/miner/stratum/Cargo.toml @@ -4,6 +4,7 @@ name = "ethcore-stratum" version = "1.12.0" license = "GPL-3.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/concensus/miner/using-queue/Cargo.toml b/crates/concensus/miner/using-queue/Cargo.toml index ac581a96d..e47d4c0d1 100644 --- a/crates/concensus/miner/using-queue/Cargo.toml +++ b/crates/concensus/miner/using-queue/Cargo.toml @@ -2,3 +2,4 @@ name = "using_queue" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" \ No newline at end of file diff --git a/crates/db/bloom/Cargo.toml b/crates/db/bloom/Cargo.toml index 8c366a852..08e37fef6 100644 --- a/crates/db/bloom/Cargo.toml +++ b/crates/db/bloom/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] description = "Journaling bloom filter" license = "GPL3" +edition = "2015" [lib] path = "src/lib.rs" diff --git a/crates/db/journaldb/Cargo.toml b/crates/db/journaldb/Cargo.toml index 5eb8d6760..50ec6d7ef 100644 --- a/crates/db/journaldb/Cargo.toml +++ b/crates/db/journaldb/Cargo.toml @@ -4,6 +4,7 @@ version = "0.2.0" authors = ["Parity Technologies "] description = "A `HashDB` which can manage a short-term journal potentially containing many forks of mutually exclusive actions" license = "GPL3" +edition = "2015" [dependencies] parity-bytes = "0.1" diff --git a/crates/db/memory-db/Cargo.toml b/crates/db/memory-db/Cargo.toml index 90c3cd895..3b98857dc 100644 --- a/crates/db/memory-db/Cargo.toml +++ b/crates/db/memory-db/Cargo.toml @@ -17,6 +17,7 @@ authors = ["Parity Technologies "] description = "In-memory implementation of hash-db, useful for tests" license = "Apache-2.0" repository = "https://github.com/paritytech/parity-common" +edition = "2015" [[bench]] name = "bench" diff --git a/crates/db/migration-rocksdb/Cargo.toml b/crates/db/migration-rocksdb/Cargo.toml index 025ed98cc..45e64efbc 100644 --- a/crates/db/migration-rocksdb/Cargo.toml +++ b/crates/db/migration-rocksdb/Cargo.toml @@ -2,6 +2,7 @@ name = "migration-rocksdb" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] log = "0.4" diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index 7ec19370d..e328ccea3 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "ethcore" version = "1.12.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] ansi_term = "0.10" diff --git a/crates/ethcore/service/Cargo.toml b/crates/ethcore/service/Cargo.toml index bab712483..9bcb96e23 100644 --- a/crates/ethcore/service/Cargo.toml +++ b/crates/ethcore/service/Cargo.toml @@ -3,6 +3,7 @@ description = "Parity Ethereum (EthCore) Client & Network Service Creation & Reg name = "ethcore-service" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] ansi_term = "0.10" diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml index b5a162b7e..1b2b00519 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml @@ -3,6 +3,7 @@ description = "parity config generator for hbbft validators" name = "hbbft_config_generator" version = "0.0.1" license = "GPL-3.0" +edition = "2015" authors = [ "David Forstenlechner ", "Thomas Haller " diff --git a/crates/ethcore/sync/Cargo.toml b/crates/ethcore/sync/Cargo.toml index cf181c95b..f687201d4 100644 --- a/crates/ethcore/sync/Cargo.toml +++ b/crates/ethcore/sync/Cargo.toml @@ -4,6 +4,7 @@ name = "ethcore-sync" version = "1.12.0" license = "GPL-3.0" authors = ["Parity Technologies "] +edition = "2015" [lib] diff --git a/crates/net/fake-fetch/Cargo.toml b/crates/net/fake-fetch/Cargo.toml index 870da27c8..163e9f6ae 100644 --- a/crates/net/fake-fetch/Cargo.toml +++ b/crates/net/fake-fetch/Cargo.toml @@ -4,6 +4,7 @@ name = "fake-fetch" version = "0.0.1" license = "GPL-3.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] fetch = { path = "../fetch" } diff --git a/crates/net/network-devp2p/Cargo.toml b/crates/net/network-devp2p/Cargo.toml index 0ec7e2e78..6d78a42c6 100644 --- a/crates/net/network-devp2p/Cargo.toml +++ b/crates/net/network-devp2p/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "ethcore-network-devp2p" version = "1.12.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] log = "0.4" diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index 19e583341..598ad2068 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "ethcore-network" version = "1.12.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] error-chain = { version = "0.12", default-features = false } diff --git a/crates/net/node-filter/Cargo.toml b/crates/net/node-filter/Cargo.toml index 5d2314632..8b3da79c1 100644 --- a/crates/net/node-filter/Cargo.toml +++ b/crates/net/node-filter/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "node-filter" version = "1.12.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] ethcore = { path = "../../ethcore"} diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index b019cd788..d400693b9 100644 --- a/crates/rpc/Cargo.toml +++ b/crates/rpc/Cargo.toml @@ -4,6 +4,7 @@ name = "parity-rpc" version = "1.12.0" license = "GPL-3.0" authors = ["Parity Technologies "] +edition = "2015" [lib] diff --git a/crates/runtime/io/Cargo.toml b/crates/runtime/io/Cargo.toml index a0d6a1aeb..2134caf04 100644 --- a/crates/runtime/io/Cargo.toml +++ b/crates/runtime/io/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "ethcore-io" version = "1.12.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] fnv = "1.0" diff --git a/crates/runtime/runtime/Cargo.toml b/crates/runtime/runtime/Cargo.toml index e537b2f4a..73b80950e 100644 --- a/crates/runtime/runtime/Cargo.toml +++ b/crates/runtime/runtime/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "parity-runtime" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] futures = "0.1" diff --git a/crates/util/cli-signer/Cargo.toml b/crates/util/cli-signer/Cargo.toml index a927870cc..4f22c1f32 100644 --- a/crates/util/cli-signer/Cargo.toml +++ b/crates/util/cli-signer/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "cli-signer" version = "1.4.0" authors = ["Parity "] +edition = "2015" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/cli-signer/rpc-client/Cargo.toml b/crates/util/cli-signer/rpc-client/Cargo.toml index dced024c6..ff162f21e 100644 --- a/crates/util/cli-signer/rpc-client/Cargo.toml +++ b/crates/util/cli-signer/rpc-client/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "parity-rpc-client" version = "1.4.0" authors = ["Parity "] +edition = "2015" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/dir/Cargo.toml b/crates/util/dir/Cargo.toml index 934fb0819..c6f8f3701 100644 --- a/crates/util/dir/Cargo.toml +++ b/crates/util/dir/Cargo.toml @@ -3,6 +3,7 @@ name = "dir" version = "0.1.2" authors = ["Parity Technologies "] license = "GPL3" +edition = "2015" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/fastmap/Cargo.toml b/crates/util/fastmap/Cargo.toml index ea6ce1306..c8e3c2aca 100644 --- a/crates/util/fastmap/Cargo.toml +++ b/crates/util/fastmap/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] description = "Specialized version of `HashMap` with H256 keys and fast hashing function." license = "GPL-3.0" +edition = "2015" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/keccak-hasher/Cargo.toml b/crates/util/keccak-hasher/Cargo.toml index ba3af0d3d..a11792dc7 100644 --- a/crates/util/keccak-hasher/Cargo.toml +++ b/crates/util/keccak-hasher/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.1" authors = ["Parity Technologies "] description = "Keccak-256 implementation of the Hasher trait" license = "GPL-3.0" +edition = "2015" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/len-caching-lock/Cargo.toml b/crates/util/len-caching-lock/Cargo.toml index 874485f25..a01af5447 100644 --- a/crates/util/len-caching-lock/Cargo.toml +++ b/crates/util/len-caching-lock/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "len-caching-lock" version = "0.1.1" authors = ["Parity Technologies "] +edition = "2015" [dependencies] parking_lot = "0.11.1" diff --git a/crates/util/macros/Cargo.toml b/crates/util/macros/Cargo.toml index fd6a130f3..658802119 100644 --- a/crates/util/macros/Cargo.toml +++ b/crates/util/macros/Cargo.toml @@ -2,3 +2,4 @@ name = "macros" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" \ No newline at end of file diff --git a/crates/util/memory-cache/Cargo.toml b/crates/util/memory-cache/Cargo.toml index 213772857..d5c7af121 100644 --- a/crates/util/memory-cache/Cargo.toml +++ b/crates/util/memory-cache/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] description = "An LRU-cache which operates on memory used" license = "GPL3" +edition = "2015" [dependencies] parity-util-mem = "0.7" diff --git a/crates/util/panic-hook/Cargo.toml b/crates/util/panic-hook/Cargo.toml index 82bb89719..b72a9bbe8 100644 --- a/crates/util/panic-hook/Cargo.toml +++ b/crates/util/panic-hook/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "panic_hook" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] backtrace = "0.3" \ No newline at end of file diff --git a/crates/util/rlp-compress/Cargo.toml b/crates/util/rlp-compress/Cargo.toml index e16c5b3de..4cefcfa66 100644 --- a/crates/util/rlp-compress/Cargo.toml +++ b/crates/util/rlp-compress/Cargo.toml @@ -2,6 +2,7 @@ name = "rlp_compress" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] rlp = { version = "0.4.6" } diff --git a/crates/util/triehash-ethereum/Cargo.toml b/crates/util/triehash-ethereum/Cargo.toml index 929baf1d2..4fb51f248 100644 --- a/crates/util/triehash-ethereum/Cargo.toml +++ b/crates/util/triehash-ethereum/Cargo.toml @@ -4,6 +4,7 @@ version = "0.2.0" authors = ["Parity Technologies "] description = "Trie-root helpers, ethereum style" license = "GPL-3.0" +edition = "2015" [dependencies] triehash = { version = "0.5.0" } diff --git a/crates/util/unexpected/Cargo.toml b/crates/util/unexpected/Cargo.toml index d5caeadee..1358581c6 100644 --- a/crates/util/unexpected/Cargo.toml +++ b/crates/util/unexpected/Cargo.toml @@ -2,3 +2,4 @@ name = "unexpected" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" \ No newline at end of file diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 22e62d161..551641e2c 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -8,6 +8,7 @@ authors = [ "Parity Technologies " ] build = "build.rs" +edition = "2015" [package.metadata] diff --git a/crates/vm/vm/Cargo.toml b/crates/vm/vm/Cargo.toml index ece0197c4..f2c056917 100644 --- a/crates/vm/vm/Cargo.toml +++ b/crates/vm/vm/Cargo.toml @@ -3,6 +3,7 @@ description = "Virtual Machines (VM) Support Library" name = "vm" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] parity-bytes = "0.1" diff --git a/crates/vm/wasm/Cargo.toml b/crates/vm/wasm/Cargo.toml index 2b1bafca2..9a9c53fec 100644 --- a/crates/vm/wasm/Cargo.toml +++ b/crates/vm/wasm/Cargo.toml @@ -3,6 +3,7 @@ description = "WASM Interpreter" name = "wasm" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2015" [dependencies] byteorder = "1.0" From fae85daba558391867e314832a574d76081929ee Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 3 Apr 2025 15:49:48 +0200 Subject: [PATCH 397/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/concensus/miner/price-info/src/lib.rs | 2 +- crates/vm/evm/src/interpreter/mod.rs | 3 +-- crates/vm/evm/src/tests.rs | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/concensus/miner/price-info/src/lib.rs b/crates/concensus/miner/price-info/src/lib.rs index 9f7258c10..17e166350 100644 --- a/crates/concensus/miner/price-info/src/lib.rs +++ b/crates/concensus/miner/price-info/src/lib.rs @@ -145,13 +145,13 @@ impl Client { #[cfg(test)] mod test { + use crate::Client; use fake_fetch::FakeFetch; use parity_runtime::{Executor, Runtime}; use std::sync::{ atomic::{AtomicBool, Ordering}, Arc, }; - use crate::Client; fn price_info_ok(response: &str, executor: Executor) -> Client> { Client::new( diff --git a/crates/vm/evm/src/interpreter/mod.rs b/crates/vm/evm/src/interpreter/mod.rs index e54523711..c9b43c9ff 100644 --- a/crates/vm/evm/src/interpreter/mod.rs +++ b/crates/vm/evm/src/interpreter/mod.rs @@ -1545,8 +1545,8 @@ fn address_to_u256(value: Address) -> U256 { #[cfg(test)] mod tests { + use crate::{factory::Factory, vmtype::VMType}; use ethereum_types::Address; - use crate::factory::Factory; use rustc_hex::FromHex; use std::sync::Arc; use vm::{ @@ -1554,7 +1554,6 @@ mod tests { tests::{test_finalize, FakeExt}, ActionParams, ActionValue, Exec, }; - use crate::vmtype::VMType; fn interpreter(params: ActionParams, ext: &dyn vm::Ext) -> Box { Factory::new(VMType::Interpreter, 1).create(params, ext.schedule(), ext.depth()) diff --git a/crates/vm/evm/src/tests.rs b/crates/vm/evm/src/tests.rs index 6bc4f5dc1..c27f75889 100644 --- a/crates/vm/evm/src/tests.rs +++ b/crates/vm/evm/src/tests.rs @@ -15,8 +15,8 @@ // along with OpenEthereum. If not, see . use super::interpreter::MAX_SUB_STACK_SIZE; +use crate::{factory::Factory, vmtype::VMType}; use ethereum_types::{Address, H256, U256}; -use crate::factory::Factory; use hex_literal::hex; use rustc_hex::FromHex; use std::{ @@ -31,7 +31,6 @@ use vm::{ tests::{test_finalize, FakeCall, FakeCallType, FakeExt}, ActionParams, ActionValue, Ext, }; -use crate::vmtype::VMType; evm_test! {test_add: test_add_int} fn test_add(factory: super::Factory) { From d6a39e0283f79e484742856a0e658562001f683a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 3 Apr 2025 15:51:02 +0200 Subject: [PATCH 398/687] pushed github workflows to rust 1.85 --- .github/workflows/build-test.yml | 2 +- .github/workflows/check.yml | 2 +- .github/workflows/compile-targets.yml | 2 +- .github/workflows/fmt.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 9230c644d..7a75b070a 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -15,7 +15,7 @@ jobs: - ubuntu-22.04 # - macos-latest toolchain: - - 1.75 + - 1.85 runs-on: ${{ matrix.platform }} steps: - name: Checkout sources diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 906baa03c..d5d88b6e4 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -18,7 +18,7 @@ jobs: - name: Install 1.59 toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.72 + toolchain: 1.85 profile: minimal override: true - name: Run cargo check 1/3 diff --git a/.github/workflows/compile-targets.yml b/.github/workflows/compile-targets.yml index 945b6a5b0..2eaf37372 100644 --- a/.github/workflows/compile-targets.yml +++ b/.github/workflows/compile-targets.yml @@ -18,7 +18,7 @@ jobs: - name: Install rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.75 + toolchain: 1.85 profile: minimal override: true diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml index 9c634a8b2..5700e82a9 100644 --- a/.github/workflows/fmt.yml +++ b/.github/workflows/fmt.yml @@ -11,7 +11,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.72 + toolchain: 1.85 override: true - run: rustup component add rustfmt - uses: actions-rs/cargo@v1 From be983b85d4a67e440a573872d7417241949272a4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Apr 2025 19:52:43 +0200 Subject: [PATCH 399/687] propagator now correctly analyses if a peer supports EIP 2464 transaction gossiping or not, and acts accordiantly. refactored required code parts. --- crates/ethcore/sync/src/api.rs | 6 +-- crates/ethcore/sync/src/chain/handler.rs | 2 +- crates/ethcore/sync/src/chain/propagator.rs | 28 ++++++----- crates/net/network-devp2p/src/host.rs | 2 +- crates/net/network-devp2p/src/session.rs | 46 ++++++++---------- crates/net/network/src/lib.rs | 54 ++++++++++++++++++++- 6 files changed, 91 insertions(+), 47 deletions(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 1177e05a7..bd911397f 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -318,12 +318,12 @@ impl SyncProvider for EthSync { Some(PeerInfo { id: session_info.id.map(|id| format!("{:x}", id)), - client_version: session_info.client_version, capabilities: session_info - .peer_capabilities - .into_iter() + .peer_capabilities() + .iter() .map(|c| c.to_string()) .collect(), + client_version: session_info.client_version, remote_address: session_info.remote_address, local_address: session_info.local_address, eth_info: peer_info, diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index e696aeea2..5f768807d 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -156,7 +156,7 @@ impl SyncHandler { pub fn on_peer_connected(sync: &mut ChainSync, io: &mut dyn SyncIo, peer: PeerId) { let peer_version = io.peer_version(peer); - trace!(target: "sync", "== Connected {}: {} protocol: {}", peer, peer_version, io.peer_session_info(peer).map_or(String::new(), |f| f.peer_capabilities.iter().map(|c| format!("{}-{}", c.protocol, c.version)).collect::>().join(" | "))); + trace!(target: "sync", "== Connected {}: {} protocol: {}", peer, peer_version, io.peer_session_info(peer).map_or(String::new(), |f| f.peer_capabilities().iter().map(|c| format!("{}-{}", c.protocol, c.version)).collect::>().join(" | "))); let whitelisted = peer_version.is_hbbft(); diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 2315fd6aa..5efe4ae34 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -235,18 +235,20 @@ impl ChainSync { let peer_info = self.peers.get_mut(&peer_id) .expect("peer_id is form peers; peers is result of select_peers_for_transactions; select_peers_for_transactions selects peers from self.peers; qed"); - // we would need to know the Session info of the peer in order to figure out if it is supporting hashes or not, - // what would require a lock. since atm this client is only compatible with other diamond-nodes, we can assume `true`here, - // in order to avoid the lock. (instead of: io.peer_session_info(peer_id)) + warn!(target: "sync", "peer_info.protocol_version: {:?}", peer_info.protocol_version); - //let is_hashes = peer_info.protocol_version >= ETH_PROTOCOL_VERSION_65.0; <-- this seems wrong, its comparing the xRLP version with the Peer Capability version - let is_hashes = true; + let mut id: Option = None; + let mut is_hashes = false; + + if let Some(session_info) = io.peer_session_info(peer_id) { + is_hashes = session_info.is_pooled_transactions_capable(); + id = session_info.id; + } // Send all transactions, if the peer doesn't know about anything if peer_info.last_sent_transactions.is_empty() { // update stats for hash in &all_transactions_hashes { - let id = io.peer_session_info(peer_id).and_then(|info| info.id); stats.propagated(hash, are_new, id, block_number); } peer_info.last_sent_transactions = all_transactions_hashes.clone(); @@ -312,7 +314,6 @@ impl ChainSync { }; // Update stats. - let id = io.peer_session_info(peer_id).and_then(|info| info.id); for hash in &to_send { stats.propagated(hash, are_new, id, block_number); } @@ -437,11 +438,6 @@ impl ChainSync { packet_id: SyncPacket, packet: Bytes, ) { - // if let Some(session) = sync.peer_session_info(peer_id) { - - // session.remote_address - // } - if let Err(e) = sync.send(peer_id, packet_id, packet) { debug!(target:"sync", "Error sending packet: {:?}", e); sync.disconnect_peer(peer_id); @@ -780,8 +776,14 @@ mod tests { assert_eq!(1, io.packets.len()); // 1 peer should receive the message assert_eq!(1, peer_count); + + // depending on ETH_PROTOCOL_VERSION_65.0, it sends here either TRANSACTION_PACK or NewPooledTransactionHashesPacket + // as for diamond Node // TRANSACTIONS_PACKET - assert_eq!(0x02, io.packets[0].packet_id); + assert!( + io.packets[0].packet_id == SyncPacket::NewPooledTransactionHashesPacket as u8 + || io.packets[0].packet_id == SyncPacket::TransactionsPacket as u8 + ); } #[test] diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 4532a3e33..b878a09c2 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -928,7 +928,7 @@ impl Host { let (min_peers, mut max_peers, reserved_only, self_id) = { let info = self.info.read(); let mut max_peers = info.config.max_peers; - for cap in &s.info.capabilities { + for cap in s.info.capabilities() { if let Some(num) = info.config.reserved_protocols.get(&cap.protocol) { diff --git a/crates/net/network-devp2p/src/session.rs b/crates/net/network-devp2p/src/session.rs index 80539be3d..2b83b008e 100644 --- a/crates/net/network-devp2p/src/session.rs +++ b/crates/net/network-devp2p/src/session.rs @@ -126,17 +126,8 @@ impl Session { Ok(Session { state: State::Handshake(handshake), had_hello: false, - info: SessionInfo { - id: id.cloned(), - client_version: ClientVersion::from(""), - protocol_version: 0, - capabilities: Vec::new(), - peer_capabilities: Vec::new(), - ping: None, - originated, - remote_address: "Handshake".to_owned(), - local_address: local_addr, - }, + + info: SessionInfo::new(id, local_addr, originated), ping_time: Instant::now(), pong_time: None, expired: false, @@ -257,7 +248,7 @@ impl Session { /// Checks if peer supports given capability pub fn have_capability(&self, protocol: ProtocolId) -> bool { self.info - .capabilities + .capabilities() .iter() .any(|c| c.protocol == protocol) } @@ -265,7 +256,7 @@ impl Session { /// Checks if peer supports given capability pub fn capability_version(&self, protocol: ProtocolId) -> Option { self.info - .capabilities + .capabilities() .iter() .filter_map(|c| { if c.protocol == protocol { @@ -320,7 +311,7 @@ impl Session { where Message: Send + Sync + Clone, { - if protocol.is_some() && (self.info.capabilities.is_empty() || !self.had_hello) { + if protocol.is_some() && (self.info.capabilities().is_empty() || !self.had_hello) { debug!(target: "network", "Sending to unconfirmed session {}, protocol: {:?}, packet: {}", self.token(), protocol.map(|p| str::from_utf8(&p.as_u64().to_ne_bytes()).unwrap_or("??").to_string()), packet_id); bail!(ErrorKind::BadProtocol); } @@ -330,14 +321,14 @@ impl Session { let mut i = 0usize; let pid = match protocol { Some(protocol) => { - while protocol != self.info.capabilities[i].protocol { + while protocol != self.info.capabilities()[i].protocol { i += 1; - if i == self.info.capabilities.len() { + if i == self.info.capabilities().len() { debug!(target: "network", "Unknown protocol: {:?}", protocol); return Ok(()); } } - self.info.capabilities[i].id_offset + packet_id + self.info.capabilities()[i].id_offset + packet_id } None => packet_id, }; @@ -455,19 +446,20 @@ impl Session { PACKET_PEERS => Ok(SessionData::None), PACKET_USER..=PACKET_LAST => { let mut i = 0usize; - while packet_id - >= self.info.capabilities[i].id_offset + self.info.capabilities[i].packet_count - { + let capabilities = self.info.capabilities(); + let mut capability = &capabilities[i]; + while packet_id >= capability.id_offset + capability.packet_count { i += 1; - if i == self.info.capabilities.len() { + if i == self.info.capabilities().len() { debug!(target: "network", "Unknown packet: {:?}", packet_id); return Ok(SessionData::Continue); } + capability = &capabilities[i]; } // map to protocol - let protocol = self.info.capabilities[i].protocol; - let protocol_packet_id = packet_id - self.info.capabilities[i].id_offset; + let protocol = capability.protocol; + let protocol_packet_id = packet_id - capability.id_offset; match *self .protocol_states @@ -475,7 +467,7 @@ impl Session { .or_insert_with(|| ProtocolState::Pending(Vec::new())) { ProtocolState::Connected => { - trace!(target: "network", "Packet {} mapped to {:?}:{}, i={}, capabilities={:?}", packet_id, protocol, protocol_packet_id, i, self.info.capabilities); + trace!(target: "network", "Packet {} mapped to {:?}:{}, i={}, capabilities={:?}", packet_id, protocol, protocol_packet_id, i, self.info.capabilities()); Ok(SessionData::Packet { data, protocol, @@ -579,9 +571,9 @@ impl Session { let protocol = ::std::cmp::min(protocol, host.protocol_version); self.info.protocol_version = protocol; self.info.client_version = client_version; - self.info.capabilities = caps; - self.info.peer_capabilities = peer_caps; - if self.info.capabilities.is_empty() { + self.info.set_capabilities(caps, peer_caps); + + if self.info.capabilities().is_empty() { trace!(target: "network", "No common capabilities with peer."); return Err(self.disconnect(io, DisconnectReason::UselessPeer)); } diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index 1082004a6..ec8042c46 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -116,9 +116,9 @@ pub struct SessionInfo { /// Peer RLPx protocol version pub protocol_version: u32, /// Session protocol capabilities - pub capabilities: Vec, + capabilities: Vec, /// Peer protocol capabilities - pub peer_capabilities: Vec, + peer_capabilities: Vec, /// Peer ping delay pub ping: Option, /// True if this session was originated by us. @@ -127,6 +127,56 @@ pub struct SessionInfo { pub remote_address: String, /// Local endpoint address of the session pub local_address: String, + + /// peer is capable of doing EIP 2464 transaction gossiping: https://eips.ethereum.org/EIPS/eip-2464 + is_pooled_transactions_capable: bool, +} + +impl SessionInfo { + /// new, SessionInfo that did not handshake yet. + pub fn new(id: Option<&NodeId>, local_addr: String, originated: bool) -> Self { + return Self { + id: id.cloned(), + client_version: ClientVersion::from(""), + protocol_version: 0, + capabilities: Vec::new(), + peer_capabilities: Vec::new(), + ping: None, + originated, + remote_address: "Handshake".to_owned(), + local_address: local_addr, + is_pooled_transactions_capable: false, // we don't know yet, we will know once we get the capabilities + }; + } + + /// on handshake, we get the peer id and the client version. + pub fn set_capabilities( + &mut self, + session_capabilities: Vec, + peer_capabilities: Vec, + ) { + self.capabilities = session_capabilities; + self.peer_capabilities = peer_capabilities; + + // ETH_PROTOCOL_VERSION_65 + self.is_pooled_transactions_capable = self + .capabilities + .iter() + .any(|x| x.protocol.low_u64() == 0x657468 /* hex for "eth" */ && x.version == 65); + } + + pub fn capabilities(&self) -> &Vec { + &self.capabilities + } + + pub fn peer_capabilities(&self) -> &Vec { + &self.peer_capabilities + } + + /// Returns if the peer is capable of doing EIP 2464 transaction gossiping: https://eips.ethereum.org/EIPS/eip-2464 + pub fn is_pooled_transactions_capable(&self) -> bool { + return self.is_pooled_transactions_capable; + } } #[derive(Debug, Clone, PartialEq, Eq)] From 5058c2df3759c6353e37f3b544244d87fcbcc1ae Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 5 Apr 2025 00:22:20 +0200 Subject: [PATCH 400/687] fixed warning: propagator now uses session capabilities, no ETH_PROTOCOL_VERSION_65 required anymore. --- crates/ethcore/sync/src/chain/propagator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 5efe4ae34..713274e89 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -34,7 +34,7 @@ use crate::chain::propagator_statistics::SyncPropagatorStatistics; use super::sync_packet::SyncPacket::{self, *}; use super::{ - random, ChainSync, ETH_PROTOCOL_VERSION_65, MAX_PEERS_PROPAGATION, MAX_PEER_LAG_PROPAGATION, + random, ChainSync, MAX_PEERS_PROPAGATION, MAX_PEER_LAG_PROPAGATION, MAX_TRANSACTION_PACKET_SIZE, MIN_PEERS_PROPAGATION, }; use ethcore_miner::pool::VerifiedTransaction; From 6ca250cc8a8ff3ae58b964e7c0753ae39385eaa4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 5 Apr 2025 00:22:46 +0200 Subject: [PATCH 401/687] fixed a bug where the size of the LRU PermissionCache was not respected. --- crates/ethcore/src/tx_filter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 29448ff8a..34f432798 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -64,7 +64,7 @@ pub struct PermissionCache { impl PermissionCache { pub fn new(size: usize) -> Self { PermissionCache { - cache: new_h256_fast_lru_map(NonZeroUsize::new(MAX_CACHE_SIZE).unwrap()), + cache: new_h256_fast_lru_map(NonZeroUsize::new(size).unwrap()), valid_block: H256::zero(), } } From 81e7d86f27371a5c645122107583e9df99b31b9c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 5 Apr 2025 19:02:12 +0200 Subject: [PATCH 402/687] fixed peer capability detection for is_pooled_transactions_capable --- crates/net/network/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index ec8042c46..d122fa888 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -160,7 +160,7 @@ impl SessionInfo { // ETH_PROTOCOL_VERSION_65 self.is_pooled_transactions_capable = self - .capabilities + .peer_capabilities .iter() .any(|x| x.protocol.low_u64() == 0x657468 /* hex for "eth" */ && x.version == 65); } From b47fb329b622182952db7910bf64f88c6eb5eb2a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 5 Apr 2025 19:09:37 +0200 Subject: [PATCH 403/687] refactored propagator: only encode the RLP for transaction or hashes that are needed. this improves performance of the critical single thread task in the sync io --- crates/ethcore/sync/src/chain/propagator.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 713274e89..4ce83e1b4 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -170,15 +170,7 @@ impl ChainSync { .iter() .map(|tx| tx.hash()) .collect::(); - let all_transactions_rlp = { - let mut packet = RlpStream::new_list(transactions.len()); - for tx in &transactions { - tx.rlp_append(&mut packet); - } - packet.out() - }; - let all_transactions_hashes_rlp = - rlp::encode_list(&all_transactions_hashes.iter().copied().collect::>()); + let block_number = io.chain().chain_info().best_block_number; @@ -255,9 +247,13 @@ impl ChainSync { let rlp = { if is_hashes { - all_transactions_hashes_rlp.clone() + rlp::encode_list(&all_transactions_hashes.iter().copied().collect::>()) } else { - all_transactions_rlp.clone() + let mut packet = RlpStream::new_list(transactions.len()); + for tx in &transactions { + tx.rlp_append(&mut packet); + } + packet.out() } }; send_packet( From 5ce544f27efd3390200484b4d61e8b6eb1b16f36 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 5 Apr 2025 20:21:10 +0200 Subject: [PATCH 404/687] promoted to warning: Disconnected from reserved peer peerID --- crates/ethcore/sync/src/api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index bd911397f..103a00eed 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -588,7 +588,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler { fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId) { trace_time!("sync::disconnected"); if io.is_reserved_peer(*peer) { - trace!(target: "sync", "Disconnected from reserved peer peerID: {} {}",peer, io.session_info(*peer).expect("").id.map_or("".to_string(), |f| format!("{:?}", f))); + warn!(target: "sync", "Disconnected from reserved peer peerID: {} {}",peer, io.session_info(*peer).expect("").id.map_or("".to_string(), |f| format!("{:?}", f))); } if io.subprotocol_name() != PAR_PROTOCOL { self.sync.write().on_peer_aborting( From 0f1b0b712dfdda0f6110172dff0dae35969566b3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 5 Apr 2025 20:42:19 +0200 Subject: [PATCH 405/687] simplified decision making if a transaction should be repooled --- crates/ethcore/sync/src/chain/mod.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 30cf45389..d537cfa8b 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -960,8 +960,9 @@ impl ChainSync { .copied() .collect(); } - Err(_unknown_tx) => { + Err(unknown_tx) => { // punish peer? + warn!(target: "sync", "Peer {} sent unknown transaction {}", peer_id, unknown_tx); } } @@ -1452,20 +1453,12 @@ impl ChainSync { if to_send.len() >= MAX_TRANSACTIONS_TO_REQUEST { break; } - // we should add it, - // - if it is not known to be fetched before - // - if the last fetch was more than 300ms ago. - let mut ask_this = true; - if let Some(t) = self + + if self .asking_pooled_transaction_overview .get_last_fetched(hash) + .map_or(false, |t| t.elapsed().as_millis() > 300) { - if t.elapsed().as_millis() < 300 { - ask_this = false; - } - } - - if ask_this { to_send.insert(hash.clone()); self.asking_pooled_transaction_overview .report_transaction_pooling(hash); From b2ea11a5b06ed59151459d5df74383ff561d6df4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 5 Apr 2025 20:42:45 +0200 Subject: [PATCH 406/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/sync/src/chain/propagator.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 4ce83e1b4..4fd11e9e3 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -170,7 +170,6 @@ impl ChainSync { .iter() .map(|tx| tx.hash()) .collect::(); - let block_number = io.chain().chain_info().best_block_number; @@ -247,13 +246,15 @@ impl ChainSync { let rlp = { if is_hashes { - rlp::encode_list(&all_transactions_hashes.iter().copied().collect::>()) + rlp::encode_list( + &all_transactions_hashes.iter().copied().collect::>(), + ) } else { let mut packet = RlpStream::new_list(transactions.len()); for tx in &transactions { tx.rlp_append(&mut packet); } - packet.out() + packet.out() } }; send_packet( From 0070c88de371ee85a4df597c03e58e84674f284c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 5 Apr 2025 20:43:43 +0200 Subject: [PATCH 407/687] on_peer_pooled_transactions() now does a reset_peer_asking(). This solves https://github.com/DMDcoin/diamond-node/issues/186 --- crates/ethcore/sync/src/chain/handler.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 5f768807d..ec5847682 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -873,7 +873,7 @@ impl SyncHandler { /// Called when peer sends us a list of pooled transactions pub fn on_peer_pooled_transactions( - sync: &ChainSync, + sync: &mut ChainSync, io: &mut dyn SyncIo, peer_id: PeerId, tx_rlp: &Rlp, @@ -904,6 +904,9 @@ impl SyncHandler { transactions.push(tx); } io.chain().queue_transactions(transactions, peer_id); + + sync.reset_peer_asking(peer_id, PeerAsking::PooledTransactions); + Ok(()) } From 4e22eb447f4d17bfd69c16966000d748f4aeef9c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Apr 2025 17:48:52 +0200 Subject: [PATCH 408/687] added CLI arg "logging" for hbbft_config_generator. --- .../hbbft/hbbft_config_generator/src/main.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 0718abbb3..4bcb53c21 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -115,6 +115,7 @@ fn to_toml( base_port: u16, base_rpc_port: u16, base_ws_port: u16, + logging: Option<&str>, ) -> Value { let mut parity = Map::new(); @@ -259,7 +260,8 @@ fn to_toml( misc.insert( "logging".into(), Value::String( - "txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace".into(), + logging.unwrap_or("txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace,sync=trace") + .into(), ), ); misc.insert("log_file".into(), Value::String("diamond-node.log".into())); @@ -416,6 +418,12 @@ fn main() { .required(false) .default_value("9540") .takes_value(true), + ).arg( + Arg::with_name("logging") + .long("log definition string") + .help("example: txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace,sync=trace") + .required(false) + .takes_value(true), ) .get_matches(); @@ -479,6 +487,8 @@ fn main() { let metrics_interface = matches.value_of("metrics_interface"); + let logging_string = matches.value_of("logging"); + assert!( num_nodes_total >= num_nodes_validators, "max_nodes must be greater than nodes" @@ -544,6 +554,7 @@ fn main() { port_base, port_base_rpc.unwrap(), port_base_ws.unwrap(), + logging_string, )) .expect("TOML string generation should succeed"); fs::write(file_name, toml_string).expect("Unable to write config file"); @@ -585,6 +596,7 @@ fn main() { port_base, port_base_rpc.unwrap(), port_base_ws.unwrap(), + logging_string, )) .expect("TOML string generation should succeed"); fs::write("rpc_node.toml", rpc_string).expect("Unable to write rpc config file"); From e49b72c67608c996cd47797424943475900ae672 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Apr 2025 19:12:23 +0200 Subject: [PATCH 409/687] logging cleanup (reducing log levels again) --- crates/ethcore/sync/src/chain/mod.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index d537cfa8b..2f76a3199 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1258,7 +1258,7 @@ impl ChainSync { let (peer_latest, peer_difficulty, peer_snapshot_number, peer_snapshot_hash) = { if let Some(peer) = self.peers.get_mut(&peer_id) { if peer.asking != PeerAsking::Nothing || !peer.can_sync() { - info!(target: "sync", "Skipping busy peer {} asking: {:?}", peer_id, peer.asking); + debug!(target: "sync", "Skipping busy peer {} asking: {:?}", peer_id, peer.asking); return; } ( @@ -1338,7 +1338,6 @@ impl ChainSync { }, SyncState::Idle | SyncState::Blocks | SyncState::NewBlocks => { - info!("doing sync"); if io.chain().queue_info().is_full() { self.pause_sync(); return; @@ -1365,7 +1364,7 @@ impl ChainSync { if force || equal_or_higher_difficulty { if ancient_block_fullness < 0.8 { if let Some(request) = self.old_blocks.as_mut().and_then(|d| d.request_blocks(peer_id, io, num_active_peers)) { - info!("requesting old blocks from: {}", peer_id); + debug!("requesting old blocks from: {}", peer_id); SyncRequester::request_blocks(self, io, peer_id, request, BlockSet::OldBlocks); return; } @@ -1418,7 +1417,8 @@ impl ChainSync { // if we got nothing to do, and the other peer is also at the same block, or is known to be just 1 behind, we are fetching unfetched pooled transactions. // there is some delay of the information what block they are on. - // communicate with this peer in any case if we are on the same block. + // communicate with this peer in any case if we are on the same block. + // more about: https://github.com/DMDcoin/diamond-node/issues/173 let communicate_with_peer = chain_info.best_block_hash == peer_latest; // on a distributed real network, 3 seconds is about they physical minimum. @@ -1445,6 +1445,9 @@ impl ChainSync { // and if we have nothing else to do, get the peer to give us at least some of announced but unfetched transactions let mut to_send = H256FastSet::default(); if let Some(peer) = self.peers.get_mut(&peer_id) { + + // info: this check should do nothing, if everything is tracked correctly, + if peer.asking_pooled_transactions.is_empty() { // todo: we might just request the same transactions from multiple peers here, at the same time. // we should keep track of how many replicas of a transaction we had requested. From 993cf800845451d8108b6dde35c395ba3c890efb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Apr 2025 19:42:43 +0200 Subject: [PATCH 410/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/sync/src/chain/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 2f76a3199..9148f8557 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1417,7 +1417,7 @@ impl ChainSync { // if we got nothing to do, and the other peer is also at the same block, or is known to be just 1 behind, we are fetching unfetched pooled transactions. // there is some delay of the information what block they are on. - // communicate with this peer in any case if we are on the same block. + // communicate with this peer in any case if we are on the same block. // more about: https://github.com/DMDcoin/diamond-node/issues/173 let communicate_with_peer = chain_info.best_block_hash == peer_latest; @@ -1445,9 +1445,8 @@ impl ChainSync { // and if we have nothing else to do, get the peer to give us at least some of announced but unfetched transactions let mut to_send = H256FastSet::default(); if let Some(peer) = self.peers.get_mut(&peer_id) { - // info: this check should do nothing, if everything is tracked correctly, - + if peer.asking_pooled_transactions.is_empty() { // todo: we might just request the same transactions from multiple peers here, at the same time. // we should keep track of how many replicas of a transaction we had requested. From 26d66dafd220a9707ba61b2f70e3cb335b7324ce Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Apr 2025 20:40:54 +0200 Subject: [PATCH 411/687] propagator: logging improvements. --- crates/ethcore/sync/src/chain/propagator.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 4fd11e9e3..a18e5b569 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -65,6 +65,9 @@ impl ChainSync { blocks: &[H256], peers: &[PeerId], ) -> usize { + if peers.len() == 0 { + return 0; + } trace!(target: "sync", "Sending NewBlocks to {:?}", peers); let sent = peers.len(); let mut send_packet = |io: &mut dyn SyncIo, rlp: Bytes| { @@ -100,6 +103,9 @@ impl ChainSync { io: &mut dyn SyncIo, peers: &[PeerId], ) -> usize { + if peers.len() == 0 { + return 0; + } trace!(target: "sync", "Sending NewHashes to {:?}", peers); let last_parent = *io.chain().best_block_header().parent_hash(); let best_block_hash = chain_info.best_block_hash; @@ -226,7 +232,6 @@ impl ChainSync { let peer_info = self.peers.get_mut(&peer_id) .expect("peer_id is form peers; peers is result of select_peers_for_transactions; select_peers_for_transactions selects peers from self.peers; qed"); - warn!(target: "sync", "peer_info.protocol_version: {:?}", peer_info.protocol_version); let mut id: Option = None; let mut is_hashes = false; @@ -234,6 +239,9 @@ impl ChainSync { if let Some(session_info) = io.peer_session_info(peer_id) { is_hashes = session_info.is_pooled_transactions_capable(); id = session_info.id; + } else { + warn!(target: "sync", "no peer session info available: could not detect if peer is capable of eip-2464 transaction gossiping"); + continue; } // Send all transactions, if the peer doesn't know about anything From ad02eb02397497297103f589e57dcc475ef98ebb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 10 Apr 2025 12:21:17 +0200 Subject: [PATCH 412/687] fixed bug where pooled transaction were not queried anymore + undone optimization https://github.com/DMDcoin/diamond-node/issues/173 because it did not lead to successfull service transaction propagation,. --- crates/ethcore/sync/src/chain/mod.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 9148f8557..e4eec5615 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1419,7 +1419,10 @@ impl ChainSync { // communicate with this peer in any case if we are on the same block. // more about: https://github.com/DMDcoin/diamond-node/issues/173 - let communicate_with_peer = chain_info.best_block_hash == peer_latest; + + //let communicate_with_peer = chain_info.best_block_hash == peer_latest; + + let communicate_with_peer = true; // on a distributed real network, 3 seconds is about they physical minimum. // therefore we "accept" other nodes to be 1 block behind - usually they are not! @@ -1459,7 +1462,7 @@ impl ChainSync { if self .asking_pooled_transaction_overview .get_last_fetched(hash) - .map_or(false, |t| t.elapsed().as_millis() > 300) + .map_or(true, |t| t.elapsed().as_millis() > 300) { to_send.insert(hash.clone()); self.asking_pooled_transaction_overview @@ -1467,10 +1470,19 @@ impl ChainSync { } } - peer.unfetched_pooled_transactions - .retain(|u| !to_send.contains(u)); - - peer.asking_pooled_transactions = to_send.clone(); + if !to_send.is_empty() { + peer.unfetched_pooled_transactions + .retain(|u| !to_send.contains(u)); + + // trace!( + // target: "sync", + // "Asking {} pooled transactions from peer {}: {:?}", + // to_send.len(), + // peer_id, + // to_send + // ); + peer.asking_pooled_transactions = to_send.clone(); + } } else { info!( "we are already asking from peer {}: {} transactions", From 0553b889522089f1c7c9b5da962be6eccb1fd564 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 10 Apr 2025 12:28:10 +0200 Subject: [PATCH 413/687] hint for https://github.com/DMDcoin/diamond-node/issues/196 --- crates/ethcore/sync/src/chain/handler.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index ec5847682..972a58525 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -861,6 +861,9 @@ impl SyncHandler { .as_val::() .map_err(|_| DownloaderImportError::Invalid)?; + // todo: what if the Transaction is not new, and already in the chain? + // see: https://github.com/DMDcoin/diamond-node/issues/196 + if io.chain().queued_transaction(hash).is_none() { sync.peers .get_mut(&peer_id) From 7b7bb8847fe49fc6c4ac12d8dde3c41916d298e5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 10 Apr 2025 12:28:49 +0200 Subject: [PATCH 414/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/sync/src/chain/mod.rs | 4 ++-- crates/ethcore/sync/src/chain/propagator.rs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index e4eec5615..dc3a7c9f7 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1419,9 +1419,9 @@ impl ChainSync { // communicate with this peer in any case if we are on the same block. // more about: https://github.com/DMDcoin/diamond-node/issues/173 - + //let communicate_with_peer = chain_info.best_block_hash == peer_latest; - + let communicate_with_peer = true; // on a distributed real network, 3 seconds is about they physical minimum. diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index a18e5b569..f8a6cf3fd 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -232,7 +232,6 @@ impl ChainSync { let peer_info = self.peers.get_mut(&peer_id) .expect("peer_id is form peers; peers is result of select_peers_for_transactions; select_peers_for_transactions selects peers from self.peers; qed"); - let mut id: Option = None; let mut is_hashes = false; From a3d15ba4ac6f5c532cf52470dc3d8bbca061b4f7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 10 Apr 2025 16:09:26 +0200 Subject: [PATCH 415/687] fixed warning for not read variable. --- crates/ethcore/sync/src/chain/propagator.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index f8a6cf3fd..13b4e2c3e 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -232,16 +232,12 @@ impl ChainSync { let peer_info = self.peers.get_mut(&peer_id) .expect("peer_id is form peers; peers is result of select_peers_for_transactions; select_peers_for_transactions selects peers from self.peers; qed"); - let mut id: Option = None; - let mut is_hashes = false; - - if let Some(session_info) = io.peer_session_info(peer_id) { - is_hashes = session_info.is_pooled_transactions_capable(); - id = session_info.id; + let (id, is_hashes) = if let Some(session_info) = io.peer_session_info(peer_id) { + (session_info.id, session_info.is_pooled_transactions_capable()) } else { warn!(target: "sync", "no peer session info available: could not detect if peer is capable of eip-2464 transaction gossiping"); continue; - } + }; // Send all transactions, if the peer doesn't know about anything if peer_info.last_sent_transactions.is_empty() { From 21a4ff566d9d965714526a64778bd045b5c5c0b7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 11 Apr 2025 23:51:55 +0200 Subject: [PATCH 416/687] NODE_SOFTWARE_NAME now defines the name of the node software - "diamond-node" --- bin/oe/cli/mod.rs | 64 +++++++++++++---------- bin/oe/configuration.rs | 109 +++++++++++++++++++++++----------------- bin/oe/lib.rs | 3 ++ 3 files changed, 102 insertions(+), 74 deletions(-) diff --git a/bin/oe/cli/mod.rs b/bin/oe/cli/mod.rs index fcb93eb82..8ab116f43 100644 --- a/bin/oe/cli/mod.rs +++ b/bin/oe/cli/mod.rs @@ -1053,52 +1053,59 @@ mod tests { Account, Args, ArgsError, Config, Footprint, Ipc, Metrics, Mining, Misc, Network, Operating, Rpc, SecretStore, Snapshots, Ws, }; + use crate::NODE_SOFTWARE_NAME; use clap::ErrorKind as ClapErrorKind; use toml; #[test] fn should_accept_any_argument_order() { - let args = Args::parse(&["openethereum", "--no-warp", "account", "list"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "--no-warp", "account", "list"]).unwrap(); assert!(args.flag_no_warp); - let args = Args::parse(&["openethereum", "account", "list", "--no-warp"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "account", "list", "--no-warp"]).unwrap(); assert!(args.flag_no_warp); - let args = Args::parse(&["openethereum", "--chain=dev", "account", "list"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "--chain=dev", "account", "list"]).unwrap(); assert_eq!(args.arg_chain, "dev"); - let args = Args::parse(&["openethereum", "account", "list", "--chain=dev"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "account", "list", "--chain=dev"]).unwrap(); assert_eq!(args.arg_chain, "dev"); } #[test] fn should_reject_invalid_values() { - let args = Args::parse(&["openethereum", "--jsonrpc-port=8545"]); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "--jsonrpc-port=8545"]); assert!(args.is_ok()); - let args = Args::parse(&["openethereum", "--jsonrpc-port=asd"]); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "--jsonrpc-port=asd"]); assert!(args.is_err()); } #[test] fn should_parse_args_and_flags() { - let args = Args::parse(&["openethereum", "--no-warp"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "--no-warp"]).unwrap(); assert!(args.flag_no_warp); - let args = Args::parse(&["openethereum", "--pruning", "archive"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "--pruning", "archive"]).unwrap(); assert_eq!(args.arg_pruning, "archive"); - let args = Args::parse(&["openethereum", "export", "state", "--no-storage"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "export", "state", "--no-storage"]).unwrap(); assert!(args.flag_export_state_no_storage); - let args = - Args::parse(&["openethereum", "export", "state", "--min-balance", "123"]).unwrap(); + let args = Args::parse(&[ + NODE_SOFTWARE_NAME, + "export", + "state", + "--min-balance", + "123", + ]) + .unwrap(); assert_eq!(args.arg_export_state_min_balance, Some("123".to_string())); } #[test] fn should_exit_gracefully_on_unknown_argument() { - let result = Args::parse(&["openethereum", "--please-exit-gracefully"]); + let result = Args::parse(&[NODE_SOFTWARE_NAME, "--please-exit-gracefully"]); assert!(match result { Err(ArgsError::Clap(ref clap_error)) if clap_error.kind == ClapErrorKind::UnknownArgument => @@ -1109,39 +1116,40 @@ mod tests { #[test] fn should_use_subcommand_arg_default() { - let args = Args::parse(&["openethereum", "export", "state", "--at", "123"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "export", "state", "--at", "123"]).unwrap(); assert_eq!(args.arg_export_state_at, "123"); assert_eq!(args.arg_snapshot_at, "latest"); - let args = Args::parse(&["openethereum", "snapshot", "--at", "123", "file.dump"]).unwrap(); + let args = + Args::parse(&[NODE_SOFTWARE_NAME, "snapshot", "--at", "123", "file.dump"]).unwrap(); assert_eq!(args.arg_snapshot_at, "123"); assert_eq!(args.arg_export_state_at, "latest"); - let args = Args::parse(&["openethereum", "export", "state"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "export", "state"]).unwrap(); assert_eq!(args.arg_snapshot_at, "latest"); assert_eq!(args.arg_export_state_at, "latest"); - let args = Args::parse(&["openethereum", "snapshot", "file.dump"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "snapshot", "file.dump"]).unwrap(); assert_eq!(args.arg_snapshot_at, "latest"); assert_eq!(args.arg_export_state_at, "latest"); } #[test] fn should_parse_multiple_values() { - let args = Args::parse(&["openethereum", "account", "import", "~/1", "~/2"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "account", "import", "~/1", "~/2"]).unwrap(); assert_eq!( args.arg_account_import_path, Some(vec!["~/1".to_owned(), "~/2".to_owned()]) ); - let args = Args::parse(&["openethereum", "account", "import", "~/1,ext"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "account", "import", "~/1,ext"]).unwrap(); assert_eq!( args.arg_account_import_path, Some(vec!["~/1,ext".to_owned()]) ); let args = Args::parse(&[ - "openethereum", + NODE_SOFTWARE_NAME, "--secretstore-nodes", "abc@127.0.0.1:3333,cde@10.10.10.10:4444", ]) @@ -1152,7 +1160,7 @@ mod tests { ); let args = Args::parse(&[ - "openethereum", + NODE_SOFTWARE_NAME, "--password", "~/.safe/1", "--password", @@ -1164,7 +1172,7 @@ mod tests { vec!["~/.safe/1".to_owned(), "~/.safe/2".to_owned()] ); - let args = Args::parse(&["openethereum", "--password", "~/.safe/1,~/.safe/2"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "--password", "~/.safe/1,~/.safe/2"]).unwrap(); assert_eq!( args.arg_password, vec!["~/.safe/1".to_owned(), "~/.safe/2".to_owned()] @@ -1173,7 +1181,7 @@ mod tests { #[test] fn should_parse_global_args_with_subcommand() { - let args = Args::parse(&["openethereum", "--chain", "dev", "account", "list"]).unwrap(); + let args = Args::parse(&[NODE_SOFTWARE_NAME, "--chain", "dev", "account", "list"]).unwrap(); assert_eq!(args.arg_chain, "dev".to_owned()); } @@ -1201,7 +1209,8 @@ mod tests { config.parity = Some(operating); // when - let args = Args::parse_with_config(&["openethereum", "--chain", "xyz"], config).unwrap(); + let args = + Args::parse_with_config(&[NODE_SOFTWARE_NAME, "--chain", "xyz"], config).unwrap(); // then assert_eq!(args.arg_chain, "xyz".to_owned()); @@ -1227,7 +1236,8 @@ mod tests { let config = toml::from_str(include_str!("./tests/config.full.toml")).unwrap(); // when - let args = Args::parse_with_config(&["openethereum", "--chain", "xyz"], config).unwrap(); + let args = + Args::parse_with_config(&[NODE_SOFTWARE_NAME, "--chain", "xyz"], config).unwrap(); // then assert_eq!( @@ -1656,7 +1666,7 @@ mod tests { #[test] fn should_not_accept_min_peers_bigger_than_max_peers() { - match Args::parse(&["openethereum", "--max-peers=39", "--min-peers=40"]) { + match Args::parse(&[NODE_SOFTWARE_NAME, "--max-peers=39", "--min-peers=40"]) { Err(ArgsError::PeerConfiguration) => (), _ => assert_eq!(false, true), } @@ -1664,7 +1674,7 @@ mod tests { #[test] fn should_accept_max_peers_equal_or_bigger_than_min_peers() { - Args::parse(&["openethereum", "--max-peers=40", "--min-peers=40"]).unwrap(); - Args::parse(&["openethereum", "--max-peers=100", "--min-peers=40"]).unwrap(); + Args::parse(&[NODE_SOFTWARE_NAME, "--max-peers=40", "--min-peers=40"]).unwrap(); + Args::parse(&[NODE_SOFTWARE_NAME, "--max-peers=100", "--min-peers=40"]).unwrap(); } } diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index df47cbb1f..5a94edeb3 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -1277,6 +1277,8 @@ mod tests { use super::*; + use crate::NODE_SOFTWARE_NAME; + lazy_static! { static ref ITERATIONS: NonZeroU32 = NonZeroU32::new(10240).expect("10240 > 0; qed"); } @@ -1289,14 +1291,14 @@ mod tests { #[test] fn test_command_version() { - let args = vec!["openethereum", "--version"]; + let args = vec![NODE_SOFTWARE_NAME, "--version"]; let conf = parse(&args); assert_eq!(conf.into_command().unwrap().cmd, Cmd::Version); } #[test] fn test_command_account_new() { - let args = vec!["openethereum", "account", "new"]; + let args = vec![NODE_SOFTWARE_NAME, "account", "new"]; let conf = parse(&args); assert_eq!( conf.into_command().unwrap().cmd, @@ -1311,7 +1313,7 @@ mod tests { #[test] fn test_command_account_list() { - let args = vec!["openethereum", "account", "list"]; + let args = vec![NODE_SOFTWARE_NAME, "account", "list"]; let conf = parse(&args); assert_eq!( conf.into_command().unwrap().cmd, @@ -1324,7 +1326,13 @@ mod tests { #[test] fn test_command_account_import() { - let args = vec!["openethereum", "account", "import", "my_dir", "another_dir"]; + let args = vec![ + NODE_SOFTWARE_NAME, + "account", + "import", + "my_dir", + "another_dir", + ]; let conf = parse(&args); assert_eq!( conf.into_command().unwrap().cmd, @@ -1339,7 +1347,7 @@ mod tests { #[test] fn test_command_wallet_import() { let args = vec![ - "openethereum", + NODE_SOFTWARE_NAME, "wallet", "import", "my_wallet.json", @@ -1361,7 +1369,7 @@ mod tests { #[test] fn test_command_blockchain_import() { - let args = vec!["openethereum", "import", "blockchain.json"]; + let args = vec![NODE_SOFTWARE_NAME, "import", "blockchain.json"]; let conf = parse(&args); assert_eq!( conf.into_command().unwrap().cmd, @@ -1388,7 +1396,7 @@ mod tests { #[test] fn test_command_blockchain_export() { - let args = vec!["openethereum", "export", "blocks", "blockchain.json"]; + let args = vec![NODE_SOFTWARE_NAME, "export", "blocks", "blockchain.json"]; let conf = parse(&args); assert_eq!( conf.into_command().unwrap().cmd, @@ -1414,7 +1422,7 @@ mod tests { #[test] fn test_command_state_export() { - let args = vec!["openethereum", "export", "state", "state.json"]; + let args = vec![NODE_SOFTWARE_NAME, "export", "state", "state.json"]; let conf = parse(&args); assert_eq!( conf.into_command().unwrap().cmd, @@ -1443,7 +1451,7 @@ mod tests { #[test] fn test_command_blockchain_export_with_custom_format() { let args = vec![ - "openethereum", + NODE_SOFTWARE_NAME, "export", "blocks", "--format", @@ -1475,7 +1483,7 @@ mod tests { #[test] fn test_command_signer_new_token() { - let args = vec!["openethereum", "signer", "new-token"]; + let args = vec![NODE_SOFTWARE_NAME, "signer", "new-token"]; let conf = parse(&args); let expected = Directories::default().signer; assert_eq!( @@ -1508,7 +1516,7 @@ mod tests { #[test] fn test_ws_max_connections() { - let args = vec!["openethereum", "--ws-max-connections", "1"]; + let args = vec![NODE_SOFTWARE_NAME, "--ws-max-connections", "1"]; let conf = parse(&args); assert_eq!( @@ -1580,7 +1588,7 @@ mod tests { // when let conf0 = parse(&["openethereum"]); - let conf2 = parse(&["openethereum", "--tx-queue-strategy", "gas_price"]); + let conf2 = parse(&[NODE_SOFTWARE_NAME, "--tx-queue-strategy", "gas_price"]); // then assert_eq!(conf0.miner_options().unwrap(), mining_options); @@ -1591,7 +1599,7 @@ mod tests { #[test] fn should_fail_on_force_reseal_and_reseal_min_period() { let conf = parse(&[ - "openethereum", + NODE_SOFTWARE_NAME, "--chain", "dev", "--force-sealing", @@ -1608,7 +1616,7 @@ mod tests { // when let conf = parse(&[ - "openethereum", + NODE_SOFTWARE_NAME, "--chain", "goerli", "--identity", @@ -1636,9 +1644,13 @@ mod tests { // when let conf0 = parse(&["openethereum"]); - let conf1 = parse(&["openethereum", "--jsonrpc-hosts", "none"]); - let conf2 = parse(&["openethereum", "--jsonrpc-hosts", "all"]); - let conf3 = parse(&["openethereum", "--jsonrpc-hosts", "parity.io,something.io"]); + let conf1 = parse(&[NODE_SOFTWARE_NAME, "--jsonrpc-hosts", "none"]); + let conf2 = parse(&[NODE_SOFTWARE_NAME, "--jsonrpc-hosts", "all"]); + let conf3 = parse(&[ + NODE_SOFTWARE_NAME, + "--jsonrpc-hosts", + "parity.io,something.io", + ]); // then assert_eq!(conf0.rpc_hosts(), Some(Vec::new())); @@ -1655,7 +1667,7 @@ mod tests { // given // when - let conf0 = parse(&["openethereum", "--ui-path=signer"]); + let conf0 = parse(&[NODE_SOFTWARE_NAME, "--ui-path=signer"]); // then assert_eq!(conf0.directories().signer, "signer".to_owned()); @@ -1670,7 +1682,7 @@ mod tests { .write_all(b" \n\t\n") .unwrap(); let args = vec![ - "openethereum", + NODE_SOFTWARE_NAME, "--reserved-peers", filename.to_str().unwrap(), ]; @@ -1684,7 +1696,7 @@ mod tests { let filename = tempdir.path().join("peers_comments"); File::create(&filename).unwrap().write_all(b"# Sample comment\nenode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@172.0.0.1:30303\n").unwrap(); let args = vec![ - "openethereum", + NODE_SOFTWARE_NAME, "--reserved-peers", filename.to_str().unwrap(), ]; @@ -1696,7 +1708,7 @@ mod tests { #[test] fn test_dev_preset() { - let args = vec!["openethereum", "--config", "dev"]; + let args = vec![NODE_SOFTWARE_NAME, "--config", "dev"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -1710,7 +1722,7 @@ mod tests { #[test] fn test_mining_preset() { - let args = vec!["openethereum", "--config", "mining"]; + let args = vec![NODE_SOFTWARE_NAME, "--config", "mining"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -1734,7 +1746,7 @@ mod tests { #[test] fn test_non_standard_ports_preset() { - let args = vec!["openethereum", "--config", "non-standard-ports"]; + let args = vec![NODE_SOFTWARE_NAME, "--config", "non-standard-ports"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -1747,7 +1759,7 @@ mod tests { #[test] fn test_insecure_preset() { - let args = vec!["openethereum", "--config", "insecure"]; + let args = vec![NODE_SOFTWARE_NAME, "--config", "insecure"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -1765,7 +1777,7 @@ mod tests { #[test] fn test_dev_insecure_preset() { - let args = vec!["openethereum", "--config", "dev-insecure"]; + let args = vec![NODE_SOFTWARE_NAME, "--config", "dev-insecure"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -1786,7 +1798,7 @@ mod tests { #[test] fn test_override_preset() { - let args = vec!["openethereum", "--config", "mining", "--min-peers=99"]; + let args = vec![NODE_SOFTWARE_NAME, "--config", "mining", "--min-peers=99"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -1798,7 +1810,7 @@ mod tests { #[test] fn test_identity_arg() { - let args = vec!["openethereum", "--identity", "Somebody"]; + let args = vec![NODE_SOFTWARE_NAME, "--identity", "Somebody"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -1817,9 +1829,9 @@ mod tests { // given // when - let conf0 = parse(&["openethereum", "--ports-shift", "1", "--stratum"]); + let conf0 = parse(&[NODE_SOFTWARE_NAME, "--ports-shift", "1", "--stratum"]); let conf1 = parse(&[ - "openethereum", + NODE_SOFTWARE_NAME, "--ports-shift", "1", "--jsonrpc-port", @@ -1848,7 +1860,7 @@ mod tests { #[test] fn should_resolve_external_nat_hosts() { // Ip works - let conf = parse(&["openethereum", "--nat", "extip:1.1.1.1"]); + let conf = parse(&[NODE_SOFTWARE_NAME, "--nat", "extip:1.1.1.1"]); assert_eq!( conf.net_addresses().unwrap().1.unwrap().ip().to_string(), "1.1.1.1" @@ -1856,7 +1868,7 @@ mod tests { assert_eq!(conf.net_addresses().unwrap().1.unwrap().port(), 30303); // Ip with port works, port is discarded - let conf = parse(&["openethereum", "--nat", "extip:192.168.1.1:123"]); + let conf = parse(&[NODE_SOFTWARE_NAME, "--nat", "extip:192.168.1.1:123"]); assert_eq!( conf.net_addresses().unwrap().1.unwrap().ip().to_string(), "192.168.1.1" @@ -1864,13 +1876,13 @@ mod tests { assert_eq!(conf.net_addresses().unwrap().1.unwrap().port(), 30303); // Hostname works - let conf = parse(&["openethereum", "--nat", "extip:ethereum.org"]); + let conf = parse(&[NODE_SOFTWARE_NAME, "--nat", "extip:ethereum.org"]); assert!(conf.net_addresses().unwrap().1.is_some()); assert_eq!(conf.net_addresses().unwrap().1.unwrap().port(), 30303); // Hostname works, garbage at the end is discarded let conf = parse(&[ - "openethereum", + NODE_SOFTWARE_NAME, "--nat", "extip:ethereum.org:whatever bla bla 123", ]); @@ -1878,7 +1890,7 @@ mod tests { assert_eq!(conf.net_addresses().unwrap().1.unwrap().port(), 30303); // Garbage is error - let conf = parse(&["openethereum", "--nat", "extip:blabla"]); + let conf = parse(&[NODE_SOFTWARE_NAME, "--nat", "extip:blabla"]); assert!(conf.net_addresses().is_err()); } @@ -1887,7 +1899,7 @@ mod tests { // given // when - let conf0 = parse(&["openethereum", "--unsafe-expose"]); + let conf0 = parse(&[NODE_SOFTWARE_NAME, "--unsafe-expose"]); // then assert_eq!(&conf0.network_settings().unwrap().rpc_interface, "0.0.0.0"); @@ -1905,16 +1917,16 @@ mod tests { #[test] fn allow_ips() { - let all = parse(&["openethereum", "--allow-ips", "all"]); - let private = parse(&["openethereum", "--allow-ips", "private"]); - let block_custom = parse(&["openethereum", "--allow-ips", "-10.0.0.0/8"]); + let all = parse(&[NODE_SOFTWARE_NAME, "--allow-ips", "all"]); + let private = parse(&[NODE_SOFTWARE_NAME, "--allow-ips", "private"]); + let block_custom = parse(&[NODE_SOFTWARE_NAME, "--allow-ips", "-10.0.0.0/8"]); let combo = parse(&[ - "openethereum", + NODE_SOFTWARE_NAME, "--allow-ips", "public 10.0.0.0/8 -1.0.0.0/8", ]); - let ipv6_custom_public = parse(&["openethereum", "--allow-ips", "public fc00::/7"]); - let ipv6_custom_private = parse(&["openethereum", "--allow-ips", "private -fc00::/7"]); + let ipv6_custom_public = parse(&[NODE_SOFTWARE_NAME, "--allow-ips", "public fc00::/7"]); + let ipv6_custom_private = parse(&[NODE_SOFTWARE_NAME, "--allow-ips", "private -fc00::/7"]); assert_eq!( all.ip_filter().unwrap(), @@ -1976,7 +1988,7 @@ mod tests { use std::path; let std = parse(&["openethereum"]); - let base = parse(&["openethereum", "--base-path", "/test"]); + let base = parse(&[NODE_SOFTWARE_NAME, "--base-path", "/test"]); let base_path = ::dir::default_data_path(); let local_path = ::dir::default_local_path(); @@ -1992,7 +2004,7 @@ mod tests { #[test] fn should_respect_only_max_peers_and_default() { - let args = vec!["openethereum", "--max-peers=50"]; + let args = vec![NODE_SOFTWARE_NAME, "--max-peers=50"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -2005,7 +2017,7 @@ mod tests { #[test] fn should_respect_only_max_peers_less_than_default() { - let args = vec!["openethereum", "--max-peers=5"]; + let args = vec![NODE_SOFTWARE_NAME, "--max-peers=5"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -2018,7 +2030,7 @@ mod tests { #[test] fn should_respect_only_min_peers_and_default() { - let args = vec!["openethereum", "--min-peers=5"]; + let args = vec![NODE_SOFTWARE_NAME, "--min-peers=5"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -2031,7 +2043,7 @@ mod tests { #[test] fn should_respect_only_min_peers_and_greater_than_default() { - let args = vec!["openethereum", "--min-peers=500"]; + let args = vec![NODE_SOFTWARE_NAME, "--min-peers=500"]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { @@ -2044,7 +2056,10 @@ mod tests { #[test] fn should_parse_shutdown_on_missing_block_import() { - let args = vec!["openethereum", "--shutdown-on-missing-block-import=1234"]; + let args = vec![ + NODE_SOFTWARE_NAME, + "--shutdown-on-missing-block-import=1234", + ]; let conf = Configuration::parse_cli(&args).unwrap(); match conf.into_command().unwrap().cmd { Cmd::Run(c) => { diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index 65f5388a6..8c5ae26ac 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -135,6 +135,9 @@ pub use parity_rpc::PubSubSession; #[global_allocator] static A: System = System; +/// The name of the node software. +pub const NODE_SOFTWARE_NAME: &str = "diamond-node"; + fn print_hash_of(maybe_file: Option) -> Result { if let Some(file) = maybe_file { let mut f = From 2711c2d8ed5b9008c33aac63d3a4a11d7939a259 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 12 Apr 2025 13:42:32 +0200 Subject: [PATCH 417/687] added "beta" branch to build pipeline --- .github/workflows/build-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 7a75b070a..c7e410da9 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -6,6 +6,7 @@ on: branches: - main - dev + - beta jobs: build-tests: name: Test and Build From 064949ff2f403aad67b4be9505a1ce649b280ee4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 12 Apr 2025 13:43:01 +0200 Subject: [PATCH 418/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/sync/src/chain/propagator.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 13b4e2c3e..e79e32c98 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -233,7 +233,10 @@ impl ChainSync { .expect("peer_id is form peers; peers is result of select_peers_for_transactions; select_peers_for_transactions selects peers from self.peers; qed"); let (id, is_hashes) = if let Some(session_info) = io.peer_session_info(peer_id) { - (session_info.id, session_info.is_pooled_transactions_capable()) + ( + session_info.id, + session_info.is_pooled_transactions_capable(), + ) } else { warn!(target: "sync", "no peer session info available: could not detect if peer is capable of eip-2464 transaction gossiping"); continue; From cd9d37e3194c8723680cddcc70478b0161edf72d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Apr 2025 00:47:08 +0200 Subject: [PATCH 419/687] diamond-node version: 3.3.5-hbbft-0.11.0-rc1 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd63ac44e..0201c6359 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -849,7 +849,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.10.0" +version = "3.3.5-hbbft-0.11.0-rc1" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3584,7 +3584,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.10.0" +version = "3.3.5-hbbft-0.11.0-rc1" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index d6a9bd4bf..5fbdd9c0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.10.0" +version = "3.3.5-hbbft-0.11.0-rc1" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 551641e2c..575574b83 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.10.0" +version = "3.3.5-hbbft-0.11.0-rc1" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 24035a53d9791d0ef058151b3f1dc9ae2c26ecdf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Apr 2025 00:49:13 +0200 Subject: [PATCH 420/687] log level adjustments for upcomming release --- crates/ethcore/sync/src/chain/mod.rs | 2 +- crates/ethcore/sync/src/chain/propagator.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index dc3a7c9f7..ee6209da1 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1247,7 +1247,7 @@ impl ChainSync { /// Find something to do for a peer. Called for a new peer or when a peer is done with its task. fn sync_peer(&mut self, io: &mut dyn SyncIo, peer_id: PeerId, force: bool) { - info!( + debug!( "sync_peer: {} force {} state: {:?}", peer_id, force, self.state ); diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index e79e32c98..f67627b5e 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -187,9 +187,8 @@ impl ChainSync { .retain_pending(&all_transactions_hashes); } - info!(target: "sync", "Propagating {} transactions to {} peers", transactions.len(), peers.len()); - - info!(target: "sync", "Propagating {:?}", all_transactions_hashes); + debug!(target: "sync", "Propagating {:?}", all_transactions_hashes); + trace!(target: "sync", "Propagating {} transactions to {} peers", transactions.len(), peers.len()); let send_packet = |io: &mut dyn SyncIo, stats: &mut SyncPropagatorStatistics, From 195c40b9317d62b51f03f84bb7a365a256101449 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Apr 2025 00:59:37 +0200 Subject: [PATCH 421/687] code cleanup, log level adjustments, passed "sync" topic to sync related tasks --- crates/ethcore/sync/src/chain/mod.rs | 48 +++++++--------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index ee6209da1..0d43a1413 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -107,6 +107,7 @@ use api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, ETH_PROTOCOL, PAR_PRO use block_sync::{BlockDownloader, DownloadAction}; use bytes::Bytes; use derive_more::Display; +use env_logger::Target; use ethcore::{ client::{BlockChainClient, BlockChainInfo, BlockId, BlockQueueInfo, BlockStatus}, snapshot::RestorationStatus, @@ -932,8 +933,8 @@ impl ChainSync { /// Updates transactions were received by a peer pub fn transactions_received(&mut self, txs: &[UnverifiedTransaction], peer_id: PeerId) { - info!(target: "sync", "Received {} transactions from peer {}", txs.len(), peer_id); - info!(target: "sync", "Received {:?}", txs.iter().map(|t| t.hash).map(|t| t.0).collect::>()); + debug!(target: "sync", "Received {} transactions from peer {}", txs.len(), peer_id); + trace!(target: "sync", "Received {:?}", txs.iter().map(|t| t.hash).map(|t| t.0).collect::>()); // Remove imported txs from all request queues let imported = txs.iter().map(|tx| tx.hash()).collect::(); @@ -1007,7 +1008,7 @@ impl ChainSync { // Reactivate peers only if some progress has been made // since the last sync round of if starting fresh. self.active_peers = self.peers.keys().cloned().collect(); - info!("resetting sync state to {:?}", self.state); + info!(target: "sync", "resetting sync state to {:?}", self.state); } /// Add a request for later processing @@ -1247,8 +1248,7 @@ impl ChainSync { /// Find something to do for a peer. Called for a new peer or when a peer is done with its task. fn sync_peer(&mut self, io: &mut dyn SyncIo, peer_id: PeerId, force: bool) { - debug!( - "sync_peer: {} force {} state: {:?}", + debug!(target: "sync", "sync_peer: {} force {} state: {:?}", peer_id, force, self.state ); if !self.active_peers.contains(&peer_id) { @@ -1288,37 +1288,13 @@ impl ChainSync { // the system get's stuck. let is_other_block = peer_latest != chain_info.best_block_hash; - if higher_difficulty && !is_other_block { - if peer_difficulty.is_some() { - // NetworkContext session_info - let session_info = io.peer_session_info(peer_id); - - match session_info { - Some(s) => { - //only warn if the other peer has provided a difficulty level. - warn!(target: "sync", "protected from hang. peer {}, did send wrong information ( td={:?}, our td={}) for blockhash latest={} {} originated by us: {}. client_version: {}, protocol version: {}", - peer_id, peer_difficulty, syncing_difficulty, peer_latest, s.remote_address, s.originated, s.client_version, s.protocol_version); - - // todo: temporary disabled peer deactivation. - // we are just returning now. - // will we see this problem in sequences now, but less disconnects ? - // io.disable_peer(peer_id); - // self.deactivate_peer(io, peer_id); - - return; - } - _ => {} - } - } - } - if self.old_blocks.is_some() { info!(target: "sync", "syncing old blocks from peer: {} ", peer_id); let session_info = io.peer_session_info(peer_id); match session_info { Some(s) => { - warn!(target: "sync", "old blocks peer: {} {} originated by us: {}", peer_id, s.remote_address, s.originated); + debug!(target: "sync", "old blocks peer: {} {} originated by us: {}", peer_id, s.remote_address, s.originated); } _ => {} } @@ -1364,20 +1340,19 @@ impl ChainSync { if force || equal_or_higher_difficulty { if ancient_block_fullness < 0.8 { if let Some(request) = self.old_blocks.as_mut().and_then(|d| d.request_blocks(peer_id, io, num_active_peers)) { - debug!("requesting old blocks from: {}", peer_id); + debug!(target:"sync", "requesting old blocks from: {}", peer_id); SyncRequester::request_blocks(self, io, peer_id, request, BlockSet::OldBlocks); return; } } } else { - trace!( + debug!( target: "sync", "peer {:?} is not suitable for requesting old blocks, syncing_difficulty={:?}, peer_difficulty={:?}", peer_id, syncing_difficulty, peer_difficulty ); - info!("deactivate_peer: {}", peer_id); self.deactivate_peer(io, peer_id); return; } @@ -1484,7 +1459,8 @@ impl ChainSync { peer.asking_pooled_transactions = to_send.clone(); } } else { - info!( + debug!( + target: "sync", "we are already asking from peer {}: {} transactions", peer_id, peer.asking_pooled_transactions.len() @@ -1493,7 +1469,7 @@ impl ChainSync { } if !to_send.is_empty() { - info!(target: "sync", "requesting {} pooled transactions from {}", to_send.len(), peer_id); + debug!(target: "sync", "requesting {} pooled transactions from {}", to_send.len(), peer_id); let bytes_sent = SyncRequester::request_pooled_transactions(self, io, peer_id, &to_send); self.statistics @@ -1502,7 +1478,7 @@ impl ChainSync { return; } } else { - info!(target: "sync", "Skipping peer {}, force={}, td={:?}, our td={}, blochhash={:?} our_blockhash={:?} state={:?}", peer_id, force, peer_difficulty, syncing_difficulty, peer_latest, chain_info.best_block_hash, self.state); + debug!(target: "sync", "Skipping peer {}, force={}, td={:?}, our td={}, blochhash={:?} our_blockhash={:?} state={:?}", peer_id, force, peer_difficulty, syncing_difficulty, peer_latest, chain_info.best_block_hash, self.state); } } } From fc576265d919a0a7302cdf2e1cd08d4f54dac735 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Apr 2025 01:05:36 +0200 Subject: [PATCH 422/687] unused import: env_logger::Target --- crates/ethcore/sync/src/chain/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 0d43a1413..d1fdb82ec 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -107,7 +107,6 @@ use api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, ETH_PROTOCOL, PAR_PRO use block_sync::{BlockDownloader, DownloadAction}; use bytes::Bytes; use derive_more::Display; -use env_logger::Target; use ethcore::{ client::{BlockChainClient, BlockChainInfo, BlockId, BlockQueueInfo, BlockStatus}, snapshot::RestorationStatus, From 2d5e1764fbdbff3ae22599d9600f24772aeaebd2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 16 Apr 2025 17:14:06 +0200 Subject: [PATCH 423/687] moved NODE_SOFTWARE_NAME to the parity crate. now also displaying NODE_SOFTWARE_NAME (diamond-node) in the CLI output. --- bin/oe/cli/mod.rs | 2 +- bin/oe/configuration.rs | 1 + bin/oe/lib.rs | 3 --- crates/util/version/src/lib.rs | 6 +++++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/oe/cli/mod.rs b/bin/oe/cli/mod.rs index 8ab116f43..3457f26a5 100644 --- a/bin/oe/cli/mod.rs +++ b/bin/oe/cli/mod.rs @@ -1053,8 +1053,8 @@ mod tests { Account, Args, ArgsError, Config, Footprint, Ipc, Metrics, Mining, Misc, Network, Operating, Rpc, SecretStore, Snapshots, Ws, }; - use crate::NODE_SOFTWARE_NAME; use clap::ErrorKind as ClapErrorKind; + use parity_version::NODE_SOFTWARE_NAME; use toml; #[test] diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 5a94edeb3..0267a0cf6 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -1268,6 +1268,7 @@ mod tests { use dir::Directories; use ethcore::{client::VMType, miner::MinerOptions}; use parity_rpc::NetworkSettings; + use parity_version::NODE_SOFTWARE_NAME; use tempdir::TempDir; use crate::network::{AllowIP, IpFilter}; diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index 8c5ae26ac..65f5388a6 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -135,9 +135,6 @@ pub use parity_rpc::PubSubSession; #[global_allocator] static A: System = System; -/// The name of the node software. -pub const NODE_SOFTWARE_NAME: &str = "diamond-node"; - fn print_hash_of(maybe_file: Option) -> Result { if let Some(file) = maybe_file { let mut f = diff --git a/crates/util/version/src/lib.rs b/crates/util/version/src/lib.rs index 93ff5091d..d3f9a6864 100644 --- a/crates/util/version/src/lib.rs +++ b/crates/util/version/src/lib.rs @@ -24,6 +24,9 @@ use bytes::Bytes; use rlp::RlpStream; use target_info::Target; +/// The name of the node software. +pub const NODE_SOFTWARE_NAME: &str = "diamond-node"; + mod vergen { #![allow(unused)] include!(concat!(env!("OUT_DIR"), "/version.rs")); @@ -55,7 +58,8 @@ pub fn version() -> String { let commit_date = vergen::commit_date().replace("-", ""); let date_dash = if commit_date.is_empty() { "" } else { "-" }; format!( - "OpenEthereum/v{}-{}{}{}{}{}/{}/rustc{}", + "{}/v{}-{}{}{}{}{}/{}/rustc{}", + NODE_SOFTWARE_NAME, env!("CARGO_PKG_VERSION"), THIS_TRACK, sha3_dash, From f532593464780412c5029afdd24a3060e1ac215c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Apr 2025 20:29:46 +0200 Subject: [PATCH 424/687] pumb diamond-node to rust edition 2024 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5fbdd9c0e..7ebc56b86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ authors = [ "OpenEthereum developers", "Parity Technologies " ] -edition = "2015" +edition = "2024" [dependencies] blooms-db = { path = "crates/db/blooms-db" } From 3e3aa7415b019111868a03e526522a9b3f6451b6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Apr 2025 20:30:57 +0200 Subject: [PATCH 425/687] chainspec pumb rust edition 2024 --- bin/chainspec/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/chainspec/Cargo.toml b/bin/chainspec/Cargo.toml index 59d8e69d1..ea58e7bd1 100644 --- a/bin/chainspec/Cargo.toml +++ b/bin/chainspec/Cargo.toml @@ -2,7 +2,7 @@ description = "Parity Ethereum Chain Specification" name = "chainspec" version = "0.1.0" -edition = "2018" +edition = "2024" authors = ["Marek Kotewicz "] [dependencies] From 7ba7cc341844bcd1c4008aa6277759b62b84dd64 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 19 Apr 2025 16:32:08 +0200 Subject: [PATCH 426/687] config -> config.toml --- .cargo/{config => config.toml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .cargo/{config => config.toml} (100%) diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml From 68b9f9348f32c1c41e1fda4fb88dac409799bc69 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 20 Apr 2025 22:45:57 +0200 Subject: [PATCH 427/687] WIP: first stack of rust edition 2025 upgrade --- bin/ethkey/Cargo.toml | 2 +- bin/ethstore/Cargo.toml | 2 +- bin/evmbin/Cargo.toml | 2 +- bin/oe/logger/Cargo.toml | 2 +- crates/accounts/ethkey/Cargo.toml | 2 +- crates/accounts/ethkey/src/brain.rs | 7 +++--- crates/accounts/ethkey/src/prefix.rs | 2 +- crates/concensus/ethash/Cargo.toml | 2 +- crates/concensus/ethash/src/cache.rs | 8 +++---- crates/concensus/ethash/src/compute.rs | 10 ++++---- crates/concensus/ethash/src/progpow.rs | 10 ++++---- crates/concensus/ethash/src/seed_compute.rs | 4 ++-- crates/concensus/miner/local-store/Cargo.toml | 2 +- crates/concensus/miner/stratum/Cargo.toml | 2 +- crates/concensus/miner/using-queue/Cargo.toml | 2 +- crates/db/bloom/Cargo.toml | 2 +- crates/db/journaldb/Cargo.toml | 2 +- crates/db/journaldb/src/archivedb.rs | 8 +++---- crates/db/journaldb/src/as_hash_db_impls.rs | 10 ++++---- crates/db/journaldb/src/earlymergedb.rs | 8 +++---- crates/db/journaldb/src/overlaydb.rs | 2 +- crates/db/journaldb/src/overlayrecentdb.rs | 8 +++---- crates/db/journaldb/src/refcounteddb.rs | 8 +++---- crates/db/memory-db/Cargo.toml | 2 +- crates/db/migration-rocksdb/Cargo.toml | 2 +- crates/ethcore/Cargo.toml | 2 +- crates/ethcore/service/Cargo.toml | 2 +- .../src/engines/authority_round/finality.rs | 2 +- .../src/engines/authority_round/randomness.rs | 2 +- .../hbbft/hbbft_config_generator/Cargo.toml | 2 +- crates/ethcore/sync/Cargo.toml | 2 +- crates/net/fake-fetch/Cargo.toml | 2 +- crates/net/network-devp2p/Cargo.toml | 2 +- crates/net/network-devp2p/src/connection.rs | 6 ++--- crates/net/network-devp2p/src/discovery.rs | 6 ++--- crates/net/network-devp2p/src/handshake.rs | 6 ++--- crates/net/network-devp2p/src/host.rs | 24 +++++++++---------- crates/net/network-devp2p/src/ip_utils.rs | 2 +- crates/net/network-devp2p/src/node_table.rs | 4 ++-- crates/net/network-devp2p/src/service.rs | 8 +++++-- crates/net/network-devp2p/src/session.rs | 10 ++++---- crates/net/network/Cargo.toml | 2 +- crates/net/network/src/error.rs | 2 +- crates/net/node-filter/Cargo.toml | 2 +- crates/rpc/Cargo.toml | 2 +- crates/runtime/io/Cargo.toml | 2 +- crates/runtime/io/src/service_mio.rs | 6 ++--- crates/runtime/io/src/worker.rs | 6 ++--- crates/runtime/runtime/Cargo.toml | 2 +- crates/util/cli-signer/Cargo.toml | 2 +- crates/util/cli-signer/rpc-client/Cargo.toml | 2 +- crates/util/dir/Cargo.toml | 2 +- crates/util/dir/src/helpers.rs | 2 +- crates/util/fastmap/Cargo.toml | 2 +- crates/util/keccak-hasher/Cargo.toml | 2 +- crates/util/len-caching-lock/Cargo.toml | 2 +- crates/util/len-caching-lock/src/mutex.rs | 2 +- crates/util/len-caching-lock/src/rwlock.rs | 2 +- crates/util/macros/Cargo.toml | 2 +- crates/util/memory-cache/Cargo.toml | 2 +- crates/util/panic-hook/Cargo.toml | 2 +- crates/util/rlp-compress/Cargo.toml | 2 +- crates/util/rlp-compress/src/common.rs | 2 +- crates/util/triehash-ethereum/Cargo.toml | 2 +- crates/util/unexpected/Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- crates/vm/vm/Cargo.toml | 2 +- crates/vm/vm/src/action_params.rs | 2 +- crates/vm/vm/src/error.rs | 6 ++--- crates/vm/vm/src/ext.rs | 10 ++++---- crates/vm/vm/src/tests.rs | 22 ++++++++--------- crates/vm/wasm/Cargo.toml | 2 +- crates/vm/wasm/src/runtime.rs | 2 +- 73 files changed, 151 insertions(+), 146 deletions(-) diff --git a/bin/ethkey/Cargo.toml b/bin/ethkey/Cargo.toml index 8e05ce3eb..709dd1397 100644 --- a/bin/ethkey/Cargo.toml +++ b/bin/ethkey/Cargo.toml @@ -3,7 +3,7 @@ description = "Parity Ethereum Keys Generator CLI" name = "ethkey-cli" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] docopt = "1.0" diff --git a/bin/ethstore/Cargo.toml b/bin/ethstore/Cargo.toml index c82e9f685..8b7b3336d 100644 --- a/bin/ethstore/Cargo.toml +++ b/bin/ethstore/Cargo.toml @@ -3,7 +3,7 @@ description = "Parity Ethereum Key Management CLI" name = "ethstore-cli" version = "0.1.1" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] docopt = "1.0" diff --git a/bin/evmbin/Cargo.toml b/bin/evmbin/Cargo.toml index 411914f9d..bd1f6ecf7 100644 --- a/bin/evmbin/Cargo.toml +++ b/bin/evmbin/Cargo.toml @@ -3,7 +3,7 @@ description = "Parity EVM Implementation" name = "evmbin" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [[bin]] name = "openethereum-evm" diff --git a/bin/oe/logger/Cargo.toml b/bin/oe/logger/Cargo.toml index c8034f511..3540446a6 100644 --- a/bin/oe/logger/Cargo.toml +++ b/bin/oe/logger/Cargo.toml @@ -4,7 +4,7 @@ name = "ethcore-logger" version = "1.12.0" license = "GPL-3.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] log = "0.4" diff --git a/crates/accounts/ethkey/Cargo.toml b/crates/accounts/ethkey/Cargo.toml index af944ad02..3b2d7d0ce 100644 --- a/crates/accounts/ethkey/Cargo.toml +++ b/crates/accounts/ethkey/Cargo.toml @@ -3,7 +3,7 @@ description = "Parity Ethereum Keys Generator" name = "ethkey" version = "0.3.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] edit-distance = "2.0" diff --git a/crates/accounts/ethkey/src/brain.rs b/crates/accounts/ethkey/src/brain.rs index 2cb6806fc..bcd64fc3c 100644 --- a/crates/accounts/ethkey/src/brain.rs +++ b/crates/accounts/ethkey/src/brain.rs @@ -18,8 +18,9 @@ use parity_crypto::{ publickey::{KeyPair, Secret}, Keccak256, }; -use parity_wordlist; +use crate::parity_wordlist; +use crate::WordlistError; /// Simple brainwallet. pub struct Brain(String); @@ -28,7 +29,7 @@ impl Brain { Brain(s) } - pub fn validate_phrase(phrase: &str, expected_words: usize) -> Result<(), ::WordlistError> { + pub fn validate_phrase(phrase: &str, expected_words: usize) -> Result<(), WordlistError> { parity_wordlist::validate_phrase(phrase, expected_words) } @@ -57,7 +58,7 @@ impl Brain { #[cfg(test)] mod tests { - use Brain; + use crate::Brain; #[test] fn test_brain() { diff --git a/crates/accounts/ethkey/src/prefix.rs b/crates/accounts/ethkey/src/prefix.rs index e037c41fe..4233ec8fc 100644 --- a/crates/accounts/ethkey/src/prefix.rs +++ b/crates/accounts/ethkey/src/prefix.rs @@ -41,7 +41,7 @@ impl Prefix { #[cfg(test)] mod tests { - use Prefix; + use crate::Prefix; #[test] fn prefix_generator() { diff --git a/crates/concensus/ethash/Cargo.toml b/crates/concensus/ethash/Cargo.toml index b57d70852..22b6ce977 100644 --- a/crates/concensus/ethash/Cargo.toml +++ b/crates/concensus/ethash/Cargo.toml @@ -3,7 +3,7 @@ description = "Parity Ethereum Ethash & ProgPoW Implementations" name = "ethash" version = "1.12.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] crunchy = "0.1.0" diff --git a/crates/concensus/ethash/src/cache.rs b/crates/concensus/ethash/src/cache.rs index 38b2b2de6..dfe399b70 100644 --- a/crates/concensus/ethash/src/cache.rs +++ b/crates/concensus/ethash/src/cache.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use compute::Light; +use crate::compute::Light; use either::Either; -use keccak::{keccak_512, H256}; +use crate::keccak::{keccak_512, H256}; use memmap::MmapMut; use parking_lot::Mutex; -use seed_compute::SeedHashCompute; +use crate::seed_compute::SeedHashCompute; -use shared::{epoch, get_cache_size, to_hex, Node, ETHASH_CACHE_ROUNDS, NODE_BYTES}; +use crate::shared::{epoch, get_cache_size, to_hex, Node, ETHASH_CACHE_ROUNDS, NODE_BYTES}; use std::{ borrow::Cow, diff --git a/crates/concensus/ethash/src/compute.rs b/crates/concensus/ethash/src/compute.rs index 00bbcd96d..ef786c86e 100644 --- a/crates/concensus/ethash/src/compute.rs +++ b/crates/concensus/ethash/src/compute.rs @@ -19,11 +19,11 @@ // TODO: fix endianess for big endian -use cache::{NodeCache, NodeCacheBuilder}; -use keccak::{keccak_256, keccak_512, H256}; -use progpow::{generate_cdag, keccak_f800_long, keccak_f800_short, progpow, CDag}; -use seed_compute::SeedHashCompute; -use shared::*; +use crate::cache::{NodeCache, NodeCacheBuilder}; +use crate::keccak::{keccak_256, keccak_512, H256}; +use crate::progpow::{generate_cdag, keccak_f800_long, keccak_f800_short, progpow, CDag}; +use crate::seed_compute::SeedHashCompute; +use crate::shared::*; use std::io; use std::{mem, path::Path}; diff --git a/crates/concensus/ethash/src/progpow.rs b/crates/concensus/ethash/src/progpow.rs index 131f90c2c..d729c64e2 100644 --- a/crates/concensus/ethash/src/progpow.rs +++ b/crates/concensus/ethash/src/progpow.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use compute::{calculate_dag_item, FNV_PRIME}; -use keccak::H256; -use shared::{get_data_size, Node, ETHASH_ACCESSES, ETHASH_MIX_BYTES}; +use crate::compute::{calculate_dag_item, FNV_PRIME}; +use crate::keccak::H256; +use crate::shared::{get_data_size, Node, ETHASH_ACCESSES, ETHASH_MIX_BYTES}; const PROGPOW_CACHE_BYTES: usize = 16 * 1024; const PROGPOW_CACHE_WORDS: usize = PROGPOW_CACHE_BYTES / 4; @@ -394,8 +394,8 @@ mod test { use tempdir::TempDir; use super::*; - use cache::{NodeCacheBuilder, OptimizeFor}; - use keccak::H256; + use crate::cache::{NodeCacheBuilder, OptimizeFor}; + use crate::keccak::H256; use rustc_hex::FromHex; use serde_json::{self, Value}; use std::collections::VecDeque; diff --git a/crates/concensus/ethash/src/seed_compute.rs b/crates/concensus/ethash/src/seed_compute.rs index 6ca9aba7e..f797f8068 100644 --- a/crates/concensus/ethash/src/seed_compute.rs +++ b/crates/concensus/ethash/src/seed_compute.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use keccak::{keccak_256, H256}; -use shared; +use crate::keccak::{keccak_256, H256}; +use crate::shared; use std::cell::Cell; diff --git a/crates/concensus/miner/local-store/Cargo.toml b/crates/concensus/miner/local-store/Cargo.toml index f02d65522..ee9137f81 100644 --- a/crates/concensus/miner/local-store/Cargo.toml +++ b/crates/concensus/miner/local-store/Cargo.toml @@ -3,7 +3,7 @@ name = "parity-local-store" description = "Manages persistent local node data." version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] common-types = { path = "../../../ethcore/types" } diff --git a/crates/concensus/miner/stratum/Cargo.toml b/crates/concensus/miner/stratum/Cargo.toml index 2ce6d926b..30d2811c8 100644 --- a/crates/concensus/miner/stratum/Cargo.toml +++ b/crates/concensus/miner/stratum/Cargo.toml @@ -4,7 +4,7 @@ name = "ethcore-stratum" version = "1.12.0" license = "GPL-3.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/concensus/miner/using-queue/Cargo.toml b/crates/concensus/miner/using-queue/Cargo.toml index e47d4c0d1..bfca910dd 100644 --- a/crates/concensus/miner/using-queue/Cargo.toml +++ b/crates/concensus/miner/using-queue/Cargo.toml @@ -2,4 +2,4 @@ name = "using_queue" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" \ No newline at end of file +edition = "2024" \ No newline at end of file diff --git a/crates/db/bloom/Cargo.toml b/crates/db/bloom/Cargo.toml index 08e37fef6..7527fd156 100644 --- a/crates/db/bloom/Cargo.toml +++ b/crates/db/bloom/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] description = "Journaling bloom filter" license = "GPL3" -edition = "2015" +edition = "2024" [lib] path = "src/lib.rs" diff --git a/crates/db/journaldb/Cargo.toml b/crates/db/journaldb/Cargo.toml index 50ec6d7ef..6824d82bd 100644 --- a/crates/db/journaldb/Cargo.toml +++ b/crates/db/journaldb/Cargo.toml @@ -4,7 +4,7 @@ version = "0.2.0" authors = ["Parity Technologies "] description = "A `HashDB` which can manage a short-term journal potentially containing many forks of mutually exclusive actions" license = "GPL3" -edition = "2015" +edition = "2024" [dependencies] parity-bytes = "0.1" diff --git a/crates/db/journaldb/src/archivedb.rs b/crates/db/journaldb/src/archivedb.rs index 65fbf2593..3b29ee625 100644 --- a/crates/db/journaldb/src/archivedb.rs +++ b/crates/db/journaldb/src/archivedb.rs @@ -31,8 +31,8 @@ use ethereum_types::H256; use hash_db::HashDB; use keccak_hasher::KeccakHasher; use rlp::{decode, encode}; -use traits::JournalDB; -use DB_PREFIX_LEN; +use crate::traits::JournalDB; +use crate::DB_PREFIX_LEN; /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay /// and latent-removal semantics. @@ -56,7 +56,7 @@ impl ArchiveDB { .expect("Low-level database error.") .map(|val| decode::(&val).expect("decoding db value failed")); ArchiveDB { - overlay: ::new_memory_db(), + overlay: crate::new_memory_db(), backing, latest_era, column, @@ -97,7 +97,7 @@ impl HashDB for ArchiveDB { } } -impl ::traits::KeyedHashDB for ArchiveDB { +impl crate::traits::KeyedHashDB for ArchiveDB { fn keys(&self) -> HashMap { let mut ret: HashMap = self .backing diff --git a/crates/db/journaldb/src/as_hash_db_impls.rs b/crates/db/journaldb/src/as_hash_db_impls.rs index d9eef2d5b..4f1668d0f 100644 --- a/crates/db/journaldb/src/as_hash_db_impls.rs +++ b/crates/db/journaldb/src/as_hash_db_impls.rs @@ -16,14 +16,14 @@ //! Impls of the `AsHashDB` upcast trait for all different variants of DB use crate::{AsKeyedHashDB, KeyedHashDB}; -use archivedb::ArchiveDB; -use earlymergedb::EarlyMergeDB; +use crate::archivedb::ArchiveDB; +use crate::earlymergedb::EarlyMergeDB; use hash_db::{AsHashDB, HashDB}; use keccak_hasher::KeccakHasher; use kvdb::DBValue; -use overlaydb::OverlayDB; -use overlayrecentdb::OverlayRecentDB; -use refcounteddb::RefCountedDB; +use crate::overlaydb::OverlayDB; +use crate::overlayrecentdb::OverlayRecentDB; +use crate::refcounteddb::RefCountedDB; impl AsHashDB for ArchiveDB { fn as_hash_db(&self) -> &dyn HashDB { diff --git a/crates/db/journaldb/src/earlymergedb.rs b/crates/db/journaldb/src/earlymergedb.rs index 80b6e07a4..0fe72cbbb 100644 --- a/crates/db/journaldb/src/earlymergedb.rs +++ b/crates/db/journaldb/src/earlymergedb.rs @@ -34,8 +34,8 @@ use memory_db::*; use parity_util_mem::MallocSizeOf; use parking_lot::RwLock; use rlp::{decode, encode}; -use util::{DatabaseKey, DatabaseValueRef, DatabaseValueView}; -use DB_PREFIX_LEN; +use crate::util::{DatabaseKey, DatabaseValueRef, DatabaseValueView}; +use crate::DB_PREFIX_LEN; #[derive(Debug, Clone, PartialEq, Eq, MallocSizeOf)] struct RefInfo { @@ -119,7 +119,7 @@ impl EarlyMergeDB { let (latest_era, refs) = EarlyMergeDB::read_refs(&*backing, col); let refs = Some(Arc::new(RwLock::new(refs))); EarlyMergeDB { - overlay: ::new_memory_db(), + overlay: crate::new_memory_db(), backing: backing, refs: refs, latest_era: latest_era, @@ -363,7 +363,7 @@ impl HashDB for EarlyMergeDB { } } -impl ::traits::KeyedHashDB for EarlyMergeDB { +impl crate::traits::KeyedHashDB for EarlyMergeDB { fn keys(&self) -> HashMap { let mut ret: HashMap = self .backing diff --git a/crates/db/journaldb/src/overlaydb.rs b/crates/db/journaldb/src/overlaydb.rs index c11db5a3b..3179c89ba 100644 --- a/crates/db/journaldb/src/overlaydb.rs +++ b/crates/db/journaldb/src/overlaydb.rs @@ -79,7 +79,7 @@ impl OverlayDB { /// Create a new instance of OverlayDB given a `backing` database. pub fn new(backing: Arc, col: Option) -> OverlayDB { OverlayDB { - overlay: ::new_memory_db(), + overlay: crate::new_memory_db(), backing: backing, column: col, } diff --git a/crates/db/journaldb/src/overlayrecentdb.rs b/crates/db/journaldb/src/overlayrecentdb.rs index 60c88957c..7d36f55f7 100644 --- a/crates/db/journaldb/src/overlayrecentdb.rs +++ b/crates/db/journaldb/src/overlayrecentdb.rs @@ -33,7 +33,7 @@ use memory_db::*; use parity_util_mem::MallocSizeOf; use parking_lot::RwLock; use rlp::{decode, encode, Decodable, DecoderError, Encodable, Rlp, RlpStream}; -use util::DatabaseKey; +use crate::util::DatabaseKey; /// Implementation of the `JournalDB` trait for a disk-backed database with a memory overlay /// and, possibly, latent-removal semantics. @@ -156,7 +156,7 @@ impl OverlayRecentDB { pub fn new(backing: Arc, col: Option) -> OverlayRecentDB { let journal_overlay = Arc::new(RwLock::new(OverlayRecentDB::read_overlay(&*backing, col))); OverlayRecentDB { - transaction_overlay: ::new_memory_db(), + transaction_overlay: crate::new_memory_db(), backing: backing, journal_overlay: journal_overlay, column: col, @@ -182,7 +182,7 @@ impl OverlayRecentDB { fn read_overlay(db: &dyn KeyValueDB, col: Option) -> JournalOverlay { let mut journal = HashMap::new(); - let mut overlay = ::new_memory_db(); + let mut overlay = crate::new_memory_db(); let mut count = 0; let mut latest_era = None; let mut earliest_era = None; @@ -256,7 +256,7 @@ fn to_short_key(key: &H256) -> H256 { k } -impl ::traits::KeyedHashDB for OverlayRecentDB { +impl crate::traits::KeyedHashDB for OverlayRecentDB { fn keys(&self) -> HashMap { let mut ret: HashMap = self .backing diff --git a/crates/db/journaldb/src/refcounteddb.rs b/crates/db/journaldb/src/refcounteddb.rs index 3ba75e717..2263e0b43 100644 --- a/crates/db/journaldb/src/refcounteddb.rs +++ b/crates/db/journaldb/src/refcounteddb.rs @@ -29,11 +29,11 @@ use ethereum_types::H256; use hash_db::HashDB; use keccak_hasher::KeccakHasher; use memory_db::MemoryDB; -use overlaydb::OverlayDB; +use crate::overlaydb::OverlayDB; use parity_util_mem::{allocators::new_malloc_size_ops, MallocSizeOf}; use rlp::{decode, encode}; -use util::{DatabaseKey, DatabaseValueRef, DatabaseValueView}; -use DB_PREFIX_LEN; +use crate::util::{DatabaseKey, DatabaseValueRef, DatabaseValueView}; +use crate::DB_PREFIX_LEN; /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay /// and latent-removal semantics. @@ -104,7 +104,7 @@ impl HashDB for RefCountedDB { } } -impl ::traits::KeyedHashDB for RefCountedDB { +impl crate::traits::KeyedHashDB for RefCountedDB { fn keys(&self) -> HashMap { self.forward.keys() } diff --git a/crates/db/memory-db/Cargo.toml b/crates/db/memory-db/Cargo.toml index 3b98857dc..f19e4248a 100644 --- a/crates/db/memory-db/Cargo.toml +++ b/crates/db/memory-db/Cargo.toml @@ -17,7 +17,7 @@ authors = ["Parity Technologies "] description = "In-memory implementation of hash-db, useful for tests" license = "Apache-2.0" repository = "https://github.com/paritytech/parity-common" -edition = "2015" +edition = "2024" [[bench]] name = "bench" diff --git a/crates/db/migration-rocksdb/Cargo.toml b/crates/db/migration-rocksdb/Cargo.toml index 45e64efbc..85c8b2980 100644 --- a/crates/db/migration-rocksdb/Cargo.toml +++ b/crates/db/migration-rocksdb/Cargo.toml @@ -2,7 +2,7 @@ name = "migration-rocksdb" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] log = "0.4" diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index e328ccea3..525ea4edd 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "ethcore" version = "1.12.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] ansi_term = "0.10" diff --git a/crates/ethcore/service/Cargo.toml b/crates/ethcore/service/Cargo.toml index 9bcb96e23..6d496afad 100644 --- a/crates/ethcore/service/Cargo.toml +++ b/crates/ethcore/service/Cargo.toml @@ -3,7 +3,7 @@ description = "Parity Ethereum (EthCore) Client & Network Service Creation & Reg name = "ethcore-service" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] ansi_term = "0.10" diff --git a/crates/ethcore/src/engines/authority_round/finality.rs b/crates/ethcore/src/engines/authority_round/finality.rs index cd7e9128d..e05d0a450 100644 --- a/crates/ethcore/src/engines/authority_round/finality.rs +++ b/crates/ethcore/src/engines/authority_round/finality.rs @@ -24,7 +24,7 @@ use std::collections::{ use ethereum_types::{Address, H256}; use types::BlockNumber; -use engines::validator_set::SimpleList; +use crate::engines::validator_set::SimpleList; /// Error indicating unknown validator. #[derive(Debug, PartialEq, Eq, Clone, Copy)] diff --git a/crates/ethcore/src/engines/authority_round/randomness.rs b/crates/ethcore/src/engines/authority_round/randomness.rs index 0113d8041..7a2fdefa9 100644 --- a/crates/ethcore/src/engines/authority_round/randomness.rs +++ b/crates/ethcore/src/engines/authority_round/randomness.rs @@ -213,7 +213,7 @@ impl RandomnessPhase { // Generate a new random number, but don't reveal it yet. Instead, we publish its hash to the // randomness contract, together with the number encrypted to ourselves. That way we will later be // able to decrypt and reveal it, and other parties are able to verify it against the hash. - let number: RandNumber = rng.gen(); + let number: RandNumber = rng gen(); let number_hash: Hash = keccak(number.0); let public = signer.public().ok_or(PhaseError::MissingPublicKey)?; let cipher = ecies::encrypt(&public, number_hash.as_bytes(), number.as_bytes())?; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml index 1b2b00519..286b561df 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml @@ -3,7 +3,7 @@ description = "parity config generator for hbbft validators" name = "hbbft_config_generator" version = "0.0.1" license = "GPL-3.0" -edition = "2015" +edition = "2024" authors = [ "David Forstenlechner ", "Thomas Haller " diff --git a/crates/ethcore/sync/Cargo.toml b/crates/ethcore/sync/Cargo.toml index f687201d4..84aff981f 100644 --- a/crates/ethcore/sync/Cargo.toml +++ b/crates/ethcore/sync/Cargo.toml @@ -4,7 +4,7 @@ name = "ethcore-sync" version = "1.12.0" license = "GPL-3.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [lib] diff --git a/crates/net/fake-fetch/Cargo.toml b/crates/net/fake-fetch/Cargo.toml index 163e9f6ae..cdf89a54f 100644 --- a/crates/net/fake-fetch/Cargo.toml +++ b/crates/net/fake-fetch/Cargo.toml @@ -4,7 +4,7 @@ name = "fake-fetch" version = "0.0.1" license = "GPL-3.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] fetch = { path = "../fetch" } diff --git a/crates/net/network-devp2p/Cargo.toml b/crates/net/network-devp2p/Cargo.toml index 6d78a42c6..b1c8bac47 100644 --- a/crates/net/network-devp2p/Cargo.toml +++ b/crates/net/network-devp2p/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "ethcore-network-devp2p" version = "1.12.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] log = "0.4" diff --git a/crates/net/network-devp2p/src/connection.rs b/crates/net/network-devp2p/src/connection.rs index 27211d900..f945d01d4 100644 --- a/crates/net/network-devp2p/src/connection.rs +++ b/crates/net/network-devp2p/src/connection.rs @@ -20,9 +20,9 @@ use crypto::{ publickey::Secret, }; use ethereum_types::{H128, H256, H512}; -use handshake::Handshake; +use crate::handshake::Handshake; use hash::{keccak, write_keccak}; -use io::{IoContext, StreamToken}; +use crate::io::{IoContext, StreamToken}; use mio::{ deprecated::{EventLoop, Handler, TryRead, TryWrite}, tcp::*, @@ -586,7 +586,7 @@ mod tests { }; use super::*; - use io::*; + use crate::io::*; use mio::Ready; use parity_bytes::Bytes; diff --git a/crates/net/network-devp2p/src/discovery.rs b/crates/net/network-devp2p/src/discovery.rs index d3d727ae4..8aaa5c140 100644 --- a/crates/net/network-devp2p/src/discovery.rs +++ b/crates/net/network-devp2p/src/discovery.rs @@ -19,7 +19,7 @@ use ethereum_types::{H256, H520}; use hash::keccak; use lru_cache::LruCache; use network::{Error, ErrorKind, IpFilter}; -use node_table::*; +use crate::node_table::*; use parity_bytes::Bytes; use rlp::{Rlp, RlpStream}; use std::{ @@ -29,7 +29,7 @@ use std::{ time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; -use PROTOCOL_VERSION; +use crate::PROTOCOL_VERSION; const ADDRESS_BYTES_SIZE: usize = 32; // Size of address type in bytes. const ADDRESS_BITS: usize = 8 * ADDRESS_BYTES_SIZE; // Denoted by n in [Kademlia]. @@ -982,7 +982,7 @@ where #[cfg(test)] mod tests { use super::*; - use node_table::{Node, NodeEndpoint, NodeId}; + use crate::node_table::{Node, NodeEndpoint, NodeId}; use std::net::{IpAddr, Ipv4Addr}; use crypto::publickey::{Generator, Random}; diff --git a/crates/net/network-devp2p/src/handshake.rs b/crates/net/network-devp2p/src/handshake.rs index c9379e50c..da3e83ac7 100644 --- a/crates/net/network-devp2p/src/handshake.rs +++ b/crates/net/network-devp2p/src/handshake.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use connection::Connection; +use crate::connection::Connection; use crypto::publickey::{ecdh, ecies, recover, sign, Generator, KeyPair, Public, Random, Secret}; use ethereum_types::{H256, H520}; -use host::HostInfo; +use crate::host::HostInfo; use io::{IoContext, StreamToken}; use mio::tcp::*; use network::{Error, ErrorKind}; -use node_table::NodeId; +use crate::node_table::NodeId; use parity_bytes::Bytes; use rand::{random, Rng}; use rlp::{Rlp, RlpStream}; diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index b878a09c2..9ef3ebb1a 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -17,7 +17,7 @@ use crypto::publickey::{Generator, KeyPair, Random, Secret}; use ethereum_types::H256; use hash::keccak; -use mio::{deprecated::EventLoop, tcp::*, udp::*, *}; +use crate::mio::{deprecated::EventLoop, tcp::*, udp::*, *}; use rlp::{Encodable, RlpStream}; use std::{ cmp::{max, min}, @@ -35,20 +35,20 @@ use std::{ time::Duration, }; -use discovery::{Discovery, NodeEntry, TableUpdates, MAX_DATAGRAM_SIZE}; -use io::*; -use ip_utils::{map_external_address, select_public_address}; +use crate::discovery::{Discovery, NodeEntry, TableUpdates, MAX_DATAGRAM_SIZE}; +use crate::io::*; +use crate::ip_utils::{map_external_address, select_public_address}; use network::{ client_version::ClientVersion, ConnectionDirection, ConnectionFilter, DisconnectReason, Error, ErrorKind, NetworkConfiguration, NetworkContext as NetworkContextTrait, NetworkIoMessage, NetworkProtocolHandler, NonReservedPeerMode, PacketId, PeerId, ProtocolId, SessionInfo, }; -use node_table::*; +use crate::node_table::*; use parity_path::restrict_permissions_owner; use parking_lot::{Mutex, RwLock}; -use session::{Session, SessionData}; +use crate::session::{Session, SessionData}; use stats::{PrometheusMetrics, PrometheusRegistry}; -use PROTOCOL_VERSION; +use crate::PROTOCOL_VERSION; type Slab = ::slab::Slab; @@ -183,7 +183,7 @@ impl<'s> NetworkContext<'s> { } impl<'s> NetworkContextTrait for NetworkContext<'s> { - fn send(&self, peer: PeerId, packet_id: PacketId, data: Vec) -> Result<(), Error> { + fn send(&self, peer: PeerId, packet_id: PacketId, data: Vec) -> std::result::Result<(), network::Error> { self.send_protocol(self.protocol, peer, packet_id, data) } @@ -193,7 +193,7 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { peer: PeerId, packet_id: PacketId, data: Vec, - ) -> Result<(), Error> { + ) -> std::result::Result<(), Error> { let session = self.resolve_session(peer); if let Some(session) = session { session @@ -219,7 +219,7 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { Ok(()) } - fn respond(&self, packet_id: PacketId, data: Vec) -> Result<(), Error> { + fn respond(&self, packet_id: PacketId, data: Vec) -> std::result::Result<(), network::Error> { assert!( self.session.is_some(), "Respond called without network context" @@ -246,7 +246,7 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { self.session.as_ref().map_or(false, |s| s.lock().expired()) } - fn register_timer(&self, token: TimerToken, delay: Duration) -> Result<(), Error> { + fn register_timer(&self, token: TimerToken, delay: Duration) -> std::result::Result<(), Error> { self.io .message(NetworkIoMessage::AddTimer { token, @@ -1366,7 +1366,7 @@ impl IoHandler for Host { } } - fn message(&self, io: &IoContext, message: &NetworkIoMessage) { + fn message(&self, io: &::io::IoContext, message: &NetworkIoMessage) { if self.stopping.load(AtomicOrdering::SeqCst) { return; } diff --git a/crates/net/network-devp2p/src/ip_utils.rs b/crates/net/network-devp2p/src/ip_utils.rs index 08d1ae085..f13b9a8b6 100644 --- a/crates/net/network-devp2p/src/ip_utils.rs +++ b/crates/net/network-devp2p/src/ip_utils.rs @@ -20,7 +20,7 @@ use igd::{search_gateway_from_timeout, PortMappingProtocol}; use ipnetwork::IpNetwork; -use node_table::NodeEndpoint; +use crate::node_table::NodeEndpoint; use std::{ io, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, diff --git a/crates/net/network-devp2p/src/node_table.rs b/crates/net/network-devp2p/src/node_table.rs index b4cf3fd4b..1deb66239 100644 --- a/crates/net/network-devp2p/src/node_table.rs +++ b/crates/net/network-devp2p/src/node_table.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use discovery::{NodeEntry, TableUpdates}; +use crate::discovery::{NodeEntry, TableUpdates}; use ethereum_types::H512; -use ip_utils::*; +use crate::ip_utils::*; use network::{AllowIP, Error, ErrorKind, IpFilter}; use rand::seq::SliceRandom; use rlp::{DecoderError, Rlp, RlpStream}; diff --git a/crates/net/network-devp2p/src/service.rs b/crates/net/network-devp2p/src/service.rs index cb7dc815e..16bcc8d53 100644 --- a/crates/net/network-devp2p/src/service.rs +++ b/crates/net/network-devp2p/src/service.rs @@ -15,9 +15,11 @@ // along with OpenEthereum. If not, see . use ansi_term::Colour; -use host::Host; + use io::*; -use network::{ + + +use crate::network::{ ConnectionFilter, Error, NetworkConfiguration, NetworkContext, NetworkIoMessage, NetworkProtocolHandler, NonReservedPeerMode, PeerId, ProtocolId, }; @@ -25,6 +27,8 @@ use parking_lot::RwLock; use stats::{PrometheusMetrics, PrometheusRegistry}; use std::{net::SocketAddr, ops::RangeInclusive, sync::Arc, time::Duration}; +use crate::host::Host; + struct HostHandler { public_url: RwLock>, } diff --git a/crates/net/network-devp2p/src/session.rs b/crates/net/network-devp2p/src/session.rs index 2b83b008e..5776ae41a 100644 --- a/crates/net/network-devp2p/src/session.rs +++ b/crates/net/network-devp2p/src/session.rs @@ -22,11 +22,11 @@ use std::{ time::{Duration, Instant}, }; -use connection::{Connection, EncryptedConnection, Packet, MAX_PAYLOAD_SIZE}; +use crate::connection::{Connection, EncryptedConnection, Packet, MAX_PAYLOAD_SIZE}; use ethereum_types::H256; -use handshake::Handshake; -use host::*; -use io::{IoContext, StreamToken}; +use crate::handshake::Handshake; +use crate::host::*; +use crate::io::{IoContext, StreamToken}; use mio::{ deprecated::{EventLoop, Handler}, tcp::*, @@ -36,7 +36,7 @@ use network::{ client_version::ClientVersion, DisconnectReason, Error, ErrorKind, PeerCapabilityInfo, ProtocolId, SessionCapabilityInfo, SessionInfo, }; -use node_table::NodeId; +use crate::node_table::NodeId; use rlp::{Rlp, RlpStream, EMPTY_LIST_RLP}; use snappy; diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index 598ad2068..efcab3c56 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "ethcore-network" version = "1.12.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] error-chain = { version = "0.12", default-features = false } diff --git a/crates/net/network/src/error.rs b/crates/net/network/src/error.rs index f37ebd6a8..0ab8839f3 100644 --- a/crates/net/network/src/error.rs +++ b/crates/net/network/src/error.rs @@ -19,7 +19,7 @@ #![allow(deprecated)] use crypto; -use io::IoError; +use crate::io::IoError; use libc::{EMFILE, ENFILE}; use rlp; use snappy; diff --git a/crates/net/node-filter/Cargo.toml b/crates/net/node-filter/Cargo.toml index 8b3da79c1..47283b597 100644 --- a/crates/net/node-filter/Cargo.toml +++ b/crates/net/node-filter/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "node-filter" version = "1.12.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] ethcore = { path = "../../ethcore"} diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index d400693b9..57a30e08a 100644 --- a/crates/rpc/Cargo.toml +++ b/crates/rpc/Cargo.toml @@ -4,7 +4,7 @@ name = "parity-rpc" version = "1.12.0" license = "GPL-3.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [lib] diff --git a/crates/runtime/io/Cargo.toml b/crates/runtime/io/Cargo.toml index 2134caf04..c7abe2895 100644 --- a/crates/runtime/io/Cargo.toml +++ b/crates/runtime/io/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "ethcore-io" version = "1.12.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] fnv = "1.0" diff --git a/crates/runtime/io/src/service_mio.rs b/crates/runtime/io/src/service_mio.rs index 32d2ea6dc..17c99d6c7 100644 --- a/crates/runtime/io/src/service_mio.rs +++ b/crates/runtime/io/src/service_mio.rs @@ -28,9 +28,9 @@ use std::{ thread::{self, JoinHandle}, time::Duration, }; -use worker::{Work, WorkType, Worker}; -use IoError; -use IoHandler; +use crate::worker::{Work, WorkType, Worker}; +use crate::IoError; +use crate::IoHandler; /// Timer ID pub type TimerToken = usize; diff --git a/crates/runtime/io/src/worker.rs b/crates/runtime/io/src/worker.rs index 8b04bee72..b5cf5cc90 100644 --- a/crates/runtime/io/src/worker.rs +++ b/crates/runtime/io/src/worker.rs @@ -16,7 +16,7 @@ use deque; use futures::future::{self, Loop}; -use service_mio::{HandlerId, IoChannel, IoContext}; +use crate::service_mio::{HandlerId, IoChannel, IoContext}; use std::{ sync::{ atomic::{AtomicBool, Ordering as AtomicOrdering}, @@ -25,8 +25,8 @@ use std::{ thread::{self, JoinHandle}, }; use tokio::{self}; -use IoHandler; -use LOCAL_STACK_SIZE; +use crate::IoHandler; +use crate::LOCAL_STACK_SIZE; use parking_lot::{Condvar, Mutex}; diff --git a/crates/runtime/runtime/Cargo.toml b/crates/runtime/runtime/Cargo.toml index 73b80950e..56f7991e5 100644 --- a/crates/runtime/runtime/Cargo.toml +++ b/crates/runtime/runtime/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "parity-runtime" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] futures = "0.1" diff --git a/crates/util/cli-signer/Cargo.toml b/crates/util/cli-signer/Cargo.toml index 4f22c1f32..653cf81a4 100644 --- a/crates/util/cli-signer/Cargo.toml +++ b/crates/util/cli-signer/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "cli-signer" version = "1.4.0" authors = ["Parity "] -edition = "2015" +edition = "2024" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/cli-signer/rpc-client/Cargo.toml b/crates/util/cli-signer/rpc-client/Cargo.toml index ff162f21e..0c8d7f936 100644 --- a/crates/util/cli-signer/rpc-client/Cargo.toml +++ b/crates/util/cli-signer/rpc-client/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "parity-rpc-client" version = "1.4.0" authors = ["Parity "] -edition = "2015" +edition = "2024" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/dir/Cargo.toml b/crates/util/dir/Cargo.toml index c6f8f3701..174314386 100644 --- a/crates/util/dir/Cargo.toml +++ b/crates/util/dir/Cargo.toml @@ -3,7 +3,7 @@ name = "dir" version = "0.1.2" authors = ["Parity Technologies "] license = "GPL3" -edition = "2015" +edition = "2024" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/dir/src/helpers.rs b/crates/util/dir/src/helpers.rs index 10f1b49f7..71abe9710 100644 --- a/crates/util/dir/src/helpers.rs +++ b/crates/util/dir/src/helpers.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . //! Directory helper functions -use home_dir; +use crate::home_dir; /// Replaces `$HOME` str with home directory path. pub fn replace_home(base: &str, arg: &str) -> String { diff --git a/crates/util/fastmap/Cargo.toml b/crates/util/fastmap/Cargo.toml index c8e3c2aca..bfad65649 100644 --- a/crates/util/fastmap/Cargo.toml +++ b/crates/util/fastmap/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] description = "Specialized version of `HashMap` with H256 keys and fast hashing function." license = "GPL-3.0" -edition = "2015" +edition = "2024" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/keccak-hasher/Cargo.toml b/crates/util/keccak-hasher/Cargo.toml index a11792dc7..3558e5634 100644 --- a/crates/util/keccak-hasher/Cargo.toml +++ b/crates/util/keccak-hasher/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.1" authors = ["Parity Technologies "] description = "Keccak-256 implementation of the Hasher trait" license = "GPL-3.0" -edition = "2015" +edition = "2024" [dependencies] ethereum-types = "0.9.2" diff --git a/crates/util/len-caching-lock/Cargo.toml b/crates/util/len-caching-lock/Cargo.toml index a01af5447..a01cc7547 100644 --- a/crates/util/len-caching-lock/Cargo.toml +++ b/crates/util/len-caching-lock/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "len-caching-lock" version = "0.1.1" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] parking_lot = "0.11.1" diff --git a/crates/util/len-caching-lock/src/mutex.rs b/crates/util/len-caching-lock/src/mutex.rs index 7aec80739..67290573f 100644 --- a/crates/util/len-caching-lock/src/mutex.rs +++ b/crates/util/len-caching-lock/src/mutex.rs @@ -21,7 +21,7 @@ use std::{ use parking_lot::{Mutex, MutexGuard}; -use Len; +use crate::Len; /// Can be used in place of a [`Mutex`](../../lock_api/struct.Mutex.html) where reading `T`'s `len()` without /// needing to lock, is advantageous. diff --git a/crates/util/len-caching-lock/src/rwlock.rs b/crates/util/len-caching-lock/src/rwlock.rs index 03551a26b..a88bf3d26 100644 --- a/crates/util/len-caching-lock/src/rwlock.rs +++ b/crates/util/len-caching-lock/src/rwlock.rs @@ -21,7 +21,7 @@ use std::{ use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; -use Len; +use crate::Len; /// Can be used in place of a [`RwLock`](../../lock_api/struct.RwLock.html) where /// reading `T`'s `len()` without needing to lock, is advantageous. diff --git a/crates/util/macros/Cargo.toml b/crates/util/macros/Cargo.toml index 658802119..202f78208 100644 --- a/crates/util/macros/Cargo.toml +++ b/crates/util/macros/Cargo.toml @@ -2,4 +2,4 @@ name = "macros" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" \ No newline at end of file +edition = "2024" \ No newline at end of file diff --git a/crates/util/memory-cache/Cargo.toml b/crates/util/memory-cache/Cargo.toml index d5c7af121..5594fe210 100644 --- a/crates/util/memory-cache/Cargo.toml +++ b/crates/util/memory-cache/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] description = "An LRU-cache which operates on memory used" license = "GPL3" -edition = "2015" +edition = "2024" [dependencies] parity-util-mem = "0.7" diff --git a/crates/util/panic-hook/Cargo.toml b/crates/util/panic-hook/Cargo.toml index b72a9bbe8..21525477d 100644 --- a/crates/util/panic-hook/Cargo.toml +++ b/crates/util/panic-hook/Cargo.toml @@ -5,7 +5,7 @@ license = "GPL-3.0" name = "panic_hook" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] backtrace = "0.3" \ No newline at end of file diff --git a/crates/util/rlp-compress/Cargo.toml b/crates/util/rlp-compress/Cargo.toml index 4cefcfa66..70c401bea 100644 --- a/crates/util/rlp-compress/Cargo.toml +++ b/crates/util/rlp-compress/Cargo.toml @@ -2,7 +2,7 @@ name = "rlp_compress" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] rlp = { version = "0.4.6" } diff --git a/crates/util/rlp-compress/src/common.rs b/crates/util/rlp-compress/src/common.rs index 846b66010..1aafb3f50 100644 --- a/crates/util/rlp-compress/src/common.rs +++ b/crates/util/rlp-compress/src/common.rs @@ -8,7 +8,7 @@ //! Contains RLPs used for compression. -use Swapper; +use crate::Swapper; lazy_static! { /// Swapper for snapshot compression. diff --git a/crates/util/triehash-ethereum/Cargo.toml b/crates/util/triehash-ethereum/Cargo.toml index 4fb51f248..020a3c1a2 100644 --- a/crates/util/triehash-ethereum/Cargo.toml +++ b/crates/util/triehash-ethereum/Cargo.toml @@ -4,7 +4,7 @@ version = "0.2.0" authors = ["Parity Technologies "] description = "Trie-root helpers, ethereum style" license = "GPL-3.0" -edition = "2015" +edition = "2024" [dependencies] triehash = { version = "0.5.0" } diff --git a/crates/util/unexpected/Cargo.toml b/crates/util/unexpected/Cargo.toml index 1358581c6..10ee84ead 100644 --- a/crates/util/unexpected/Cargo.toml +++ b/crates/util/unexpected/Cargo.toml @@ -2,4 +2,4 @@ name = "unexpected" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" \ No newline at end of file +edition = "2024" \ No newline at end of file diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 575574b83..9c8cee72e 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -8,7 +8,7 @@ authors = [ "Parity Technologies " ] build = "build.rs" -edition = "2015" +edition = "2024" [package.metadata] diff --git a/crates/vm/vm/Cargo.toml b/crates/vm/vm/Cargo.toml index f2c056917..6d39146c2 100644 --- a/crates/vm/vm/Cargo.toml +++ b/crates/vm/vm/Cargo.toml @@ -3,7 +3,7 @@ description = "Virtual Machines (VM) Support Library" name = "vm" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] parity-bytes = "0.1" diff --git a/crates/vm/vm/src/action_params.rs b/crates/vm/vm/src/action_params.rs index f2076e6e0..a6213949c 100644 --- a/crates/vm/vm/src/action_params.rs +++ b/crates/vm/vm/src/action_params.rs @@ -17,7 +17,7 @@ //! Evm input params. use super::access_list::AccessList; use bytes::Bytes; -use call_type::CallType; +use crate::call_type::CallType; use ethereum_types::{Address, H256, U256}; use ethjson; use hash::{keccak, KECCAK_EMPTY}; diff --git a/crates/vm/vm/src/error.rs b/crates/vm/vm/src/error.rs index bb1b8355f..f96a9a5f1 100644 --- a/crates/vm/vm/src/error.rs +++ b/crates/vm/vm/src/error.rs @@ -16,12 +16,12 @@ //! VM errors module -use action_params::ActionParams; +use crate::action_params::ActionParams; use ethereum_types::Address; use ethtrie; use std::fmt; -use ResumeCall; -use ResumeCreate; +use crate::ResumeCall; +use crate::ResumeCreate; #[derive(Debug)] pub enum TrapKind { diff --git a/crates/vm/vm/src/ext.rs b/crates/vm/vm/src/ext.rs index fccb42e78..24dcc5a86 100644 --- a/crates/vm/vm/src/ext.rs +++ b/crates/vm/vm/src/ext.rs @@ -17,12 +17,12 @@ //! Interface for Evm externalities. use bytes::Bytes; -use call_type::CallType; -use env_info::EnvInfo; -use error::{Result, TrapKind}; +use crate::call_type::CallType; +use crate::env_info::EnvInfo; +use crate::error::{Result, TrapKind}; use ethereum_types::{Address, H256, U256}; -use return_data::ReturnData; -use schedule::Schedule; +use crate::return_data::ReturnData; +use crate::schedule::Schedule; use std::sync::Arc; #[derive(Debug)] diff --git a/crates/vm/vm/src/tests.rs b/crates/vm/vm/src/tests.rs index 34336da13..2e220f5b7 100644 --- a/crates/vm/vm/src/tests.rs +++ b/crates/vm/vm/src/tests.rs @@ -21,19 +21,19 @@ use std::{ use crate::access_list::AccessList; use bytes::Bytes; -use error::TrapKind; +use crate::error::TrapKind; use ethereum_types::{Address, H256, U256}; use hash::keccak; -use CallType; -use ContractCreateResult; -use CreateContractAddress; -use EnvInfo; -use Ext; -use GasLeft; -use MessageCallResult; -use Result; -use ReturnData; -use Schedule; +use crate::CallType; +use crate::ContractCreateResult; +use crate::CreateContractAddress; +use crate::EnvInfo; +use crate::Ext; +use crate::GasLeft; +use crate::MessageCallResult; +use crate::Result; +use crate::ReturnData; +use crate::Schedule; pub struct FakeLogEntry { pub topics: Vec, diff --git a/crates/vm/wasm/Cargo.toml b/crates/vm/wasm/Cargo.toml index 9a9c53fec..075491dd5 100644 --- a/crates/vm/wasm/Cargo.toml +++ b/crates/vm/wasm/Cargo.toml @@ -3,7 +3,7 @@ description = "WASM Interpreter" name = "wasm" version = "0.1.0" authors = ["Parity Technologies "] -edition = "2015" +edition = "2024" [dependencies] byteorder = "1.0" diff --git a/crates/vm/wasm/src/runtime.rs b/crates/vm/wasm/src/runtime.rs index b4de3f77c..00bd69235 100644 --- a/crates/vm/wasm/src/runtime.rs +++ b/crates/vm/wasm/src/runtime.rs @@ -806,7 +806,7 @@ impl<'a> Runtime<'a> { mod ext_impl { - use env::ids::*; + use crate::env::ids::*; use wasmi::{Externals, RuntimeArgs, RuntimeValue, Trap}; macro_rules! void { From f73c70e00faee01f8c50d20cbbfa8236b30ac650 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 21 Apr 2025 17:23:25 +0200 Subject: [PATCH 428/687] next batch of rust edition 2025 changes --- crates/ethcore/src/block.rs | 6 ++--- crates/ethcore/src/client/ancient_import.rs | 2 +- crates/ethcore/src/client/client.rs | 8 +++---- crates/ethcore/src/client/evm_test_client.rs | 4 ++-- crates/ethcore/src/client/mod.rs | 4 ++-- crates/ethcore/src/client/test_client.rs | 6 ++--- crates/ethcore/src/client/traits.rs | 6 ++--- .../src/engines/authority_round/mod.rs | 2 +- crates/ethcore/src/error.rs | 2 +- crates/ethcore/src/ethereum/mod.rs | 2 +- crates/ethcore/src/executive.rs | 14 ++++++------ crates/ethcore/src/externalities.rs | 6 ++--- crates/ethcore/src/json_tests/executive.rs | 6 ++--- crates/ethcore/src/json_tests/transaction.rs | 2 +- crates/ethcore/src/lib.rs | 2 +- crates/ethcore/src/machine/impls.rs | 4 ++-- crates/ethcore/src/miner/miner.rs | 6 ++--- crates/ethcore/src/miner/mod.rs | 2 +- crates/ethcore/src/miner/pool_client.rs | 2 +- crates/ethcore/src/pod_account.rs | 2 +- crates/ethcore/src/pod_state.rs | 4 ++-- crates/ethcore/src/snapshot/tests/helpers.rs | 6 ++--- crates/ethcore/src/spec/spec.rs | 8 +++---- crates/ethcore/src/state/account.rs | 4 ++-- crates/ethcore/src/state/backend.rs | 2 +- crates/ethcore/src/state/mod.rs | 22 +++++++++---------- crates/ethcore/src/state_db.rs | 4 ++-- crates/ethcore/src/test_helpers.rs | 4 ++-- crates/ethcore/src/tests/client.rs | 4 ++-- crates/ethcore/src/tests/evm.rs | 4 ++-- 30 files changed, 75 insertions(+), 75 deletions(-) diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index 678b4eb24..d13f2e889 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -38,8 +38,8 @@ use ethereum_types::{Address, Bloom, H256, U256}; use engines::EthEngine; use error::{BlockError, Error}; -use factory::Factories; -use state::State; +use crate::factory::Factories; +use crate::state::State; use state_db::StateDB; use trace::Tracing; use triehash::ordered_trie_root; @@ -630,7 +630,7 @@ mod tests { use engines::EthEngine; use error::Error; use ethereum_types::Address; - use factory::Factories; + use crate::factory::Factories; use state_db::StateDB; use std::sync::Arc; use test_helpers::get_temp_state_db; diff --git a/crates/ethcore/src/client/ancient_import.rs b/crates/ethcore/src/client/ancient_import.rs index c5ff56aa3..7043b9e00 100644 --- a/crates/ethcore/src/client/ancient_import.rs +++ b/crates/ethcore/src/client/ancient_import.rs @@ -55,7 +55,7 @@ impl AncientVerifier { ) -> Result<(), ::error::Error> { // perform verification let verified = if let Some(ref cur_verifier) = *self.cur_verifier.read() { - match rng.gen::() <= HEAVY_VERIFY_RATE { + match rng.r#gen::() <= HEAVY_VERIFY_RATE { true => cur_verifier.verify_heavy(header)?, false => cur_verifier.verify_light(header)?, } diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 72f5eaba5..e7540b7bd 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -82,19 +82,19 @@ use error::{ BlockError, CallError, Error, Error as EthcoreError, ErrorKind as EthcoreErrorKind, EthcoreResult, ExecutionError, ImportErrorKind, QueueErrorKind, }; -use executive::{contract_address, Executed, Executive, TransactOptions}; -use factory::{Factories, VmFactory}; +use crate::executive::{contract_address, Executed, Executive, TransactOptions}; +use crate::factory::{Factories, VmFactory}; use io::IoChannel; use miner::{Miner, MinerService}; use snapshot::{self, io as snapshot_io, SnapshotClient}; use spec::Spec; -use state::{self, State}; +use crate::state::{self, State}; use state_db::StateDB; use stats::{PrometheusMetrics, PrometheusRegistry}; use trace::{ self, Database as TraceDatabase, ImportRequest as TraceImportRequest, LocalizedTrace, TraceDB, }; -use transaction_ext::Transaction; +use crate::transaction_ext::Transaction; use verification::{ self, queue::kind::{blocks::Unverified, BlockLike}, diff --git a/crates/ethcore/src/client/evm_test_client.rs b/crates/ethcore/src/client/evm_test_client.rs index 97c8d01b3..cc50f4319 100644 --- a/crates/ethcore/src/client/evm_test_client.rs +++ b/crates/ethcore/src/client/evm_test_client.rs @@ -21,8 +21,8 @@ use db; use ethereum_types::{H160, H256, U256}; use ethtrie; use evm::{FinalizationResult, VMType}; -use executive; -use factory::{self, Factories}; +use crate::executive; +use crate::factory::{self, Factories}; use journaldb; use kvdb::{self, KeyValueDB}; use pod_state; diff --git a/crates/ethcore/src/client/mod.rs b/crates/ethcore/src/client/mod.rs index cbe6a5df1..b526d0a05 100644 --- a/crates/ethcore/src/client/mod.rs +++ b/crates/ethcore/src/client/mod.rs @@ -44,14 +44,14 @@ pub use self::{ ScheduleInfo, SealedBlockImporter, StateClient, StateOrBlock, TransactionInfo, }, }; -pub use state::StateInfo; +pub use crate::state::StateInfo; pub use types::{ call_analytics::CallAnalytics, ids::*, pruning_info::PruningInfo, trace_filter::Filter as TraceFilter, }; -pub use executive::{Executed, Executive, TransactOptions}; +pub use crate::executive::{Executed, Executive, TransactOptions}; pub use vm::{EnvInfo, LastHashes}; pub use error::TransactionImportError; diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index df9a7dcd5..e76885ada 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -68,12 +68,12 @@ use client::{ }; use engines::EthEngine; use error::{Error, EthcoreResult}; -use executed::CallError; -use executive::Executed; +use crate::executed::CallError; +use crate::executive::Executed; use journaldb; use miner::{self, Miner, MinerService}; use spec::Spec; -use state::StateInfo; +use crate::state::StateInfo; use state_db::StateDB; use stats::{PrometheusMetrics, PrometheusRegistry}; use trace::LocalizedTrace; diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index c54036b91..5eb146355 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -54,9 +54,9 @@ use block::{ClosedBlock, OpenBlock, SealedBlock}; use client::Mode; use engines::EthEngine; use error::{Error, EthcoreResult}; -use executed::CallError; -use executive::Executed; -use state::StateInfo; +use crate::executed::CallError; +use crate::executive::Executed; +use crate::state::StateInfo; use trace::LocalizedTrace; use verification::queue::{kind::blocks::Unverified, QueueInfo as BlockQueueInfo}; diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index 8848dad19..429a7e324 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -3730,7 +3730,7 @@ mod tests { #[test] fn should_rewrite_bytecode_according_to_transitions() { - use state::StateInfo; + use crate::state::StateInfo; let tap = Arc::new(AccountProvider::transient_provider()); let addr1 = tap.insert_account(keccak("1").into(), &"1".into()).unwrap(); diff --git a/crates/ethcore/src/error.rs b/crates/ethcore/src/error.rs index 2a27c34b6..916b41386 100644 --- a/crates/ethcore/src/error.rs +++ b/crates/ethcore/src/error.rs @@ -33,7 +33,7 @@ use unexpected::{Mismatch, OutOfBounds}; use engines::EngineError; -pub use executed::{CallError, ExecutionError}; +pub use crate::executed::{CallError, ExecutionError}; #[derive(Debug, PartialEq, Clone, Eq)] /// Errors concerning block processing. diff --git a/crates/ethcore/src/ethereum/mod.rs b/crates/ethcore/src/ethereum/mod.rs index 3e8f49c55..0fc8d61b7 100644 --- a/crates/ethcore/src/ethereum/mod.rs +++ b/crates/ethcore/src/ethereum/mod.rs @@ -370,7 +370,7 @@ pub fn new_kovan_wasm_test_machine() -> EthereumMachine { mod tests { use super::*; use ethereum_types::{H160, H256, U256}; - use state::*; + use crate::state::*; use std::str::FromStr; use test_helpers::get_temp_state_db; use types::{view, views::BlockView}; diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index 8b0f0b42b..5dbe80bf2 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -18,16 +18,16 @@ use bytes::{Bytes, BytesRef}; use ethereum_types::{Address, H256, U256, U512}; use evm::{CallType, FinalizationResult, Finalize}; -use executed::ExecutionError; -pub use executed::{Executed, ExecutionResult}; -use externalities::*; -use factory::VmFactory; +use crate::executed::ExecutionError; +pub use crate::executed::{Executed, ExecutionResult}; +use crate::externalities::*; +use crate::factory::VmFactory; use hash::keccak; use machine::EthereumMachine as Machine; -use state::{Backend as StateBackend, CleanupMode, State, Substate}; +use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, convert::TryFrom, sync::Arc}; use trace::{self, Tracer, VMTracer}; -use transaction_ext::Transaction; +use crate::transaction_ext::Transaction; use types::transaction::{Action, SignedTransaction, TypedTransaction}; use vm::{ self, AccessList, ActionParams, ActionValue, CleanDustMode, CreateContractAddress, EnvInfo, @@ -1633,7 +1633,7 @@ mod tests { use evm::{Factory, VMType}; use machine::EthereumMachine; use rustc_hex::FromHex; - use state::{CleanupMode, Substate}; + use crate::state::{CleanupMode, Substate}; use std::{str::FromStr, sync::Arc}; use test_helpers::{get_temp_state, get_temp_state_with_factory}; use trace::{ diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index 052e4d88f..791996799 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -17,9 +17,9 @@ //! Transaction Execution environment. use bytes::Bytes; use ethereum_types::{Address, BigEndianHash, H256, U256}; -use executive::*; +use crate::executive::*; use machine::EthereumMachine as Machine; -use state::{Backend as StateBackend, CleanupMode, State, Substate}; +use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, sync::Arc}; use trace::{Tracer, VMTracer}; use types::transaction::UNSIGNED_SENDER; @@ -563,7 +563,7 @@ mod tests { use super::*; use ethereum_types::{Address, U256}; use evm::{CallType, EnvInfo, Ext}; - use state::{State, Substate}; + use crate::state::{State, Substate}; use std::str::FromStr; use test_helpers::get_temp_state; use trace::{NoopTracer, NoopVMTracer}; diff --git a/crates/ethcore/src/json_tests/executive.rs b/crates/ethcore/src/json_tests/executive.rs index ffd20e935..ac019f6d9 100644 --- a/crates/ethcore/src/json_tests/executive.rs +++ b/crates/ethcore/src/json_tests/executive.rs @@ -20,12 +20,12 @@ use ethereum_types::BigEndianHash; use ethjson; use ethtrie; use evm::Finalize; -use executive::*; -use externalities::*; +use crate::executive::*; +use crate::externalities::*; use hash::keccak; use machine::EthereumMachine as Machine; use rlp::RlpStream; -use state::{Backend as StateBackend, State, Substate}; +use crate::state::{Backend as StateBackend, State, Substate}; use std::{path::Path, sync::Arc}; use test_helpers::get_temp_state; use trace::{NoopTracer, NoopVMTracer, Tracer, VMTracer}; diff --git a/crates/ethcore/src/json_tests/transaction.rs b/crates/ethcore/src/json_tests/transaction.rs index 1d22bccb8..4d5a43c9b 100644 --- a/crates/ethcore/src/json_tests/transaction.rs +++ b/crates/ethcore/src/json_tests/transaction.rs @@ -18,7 +18,7 @@ use super::test_common::*; use client::EvmTestClient; use ethjson; use std::path::Path; -use transaction_ext::Transaction; +use crate::transaction_ext::Transaction; use types::{ header::Header, transaction::{TypedTransaction, UnverifiedTransaction}, diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index e6d2dcd68..3d961eb1e 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -149,5 +149,5 @@ pub mod test_helpers; mod tests; pub use evm::CreateContractAddress; -pub use executive::contract_address; +pub use crate::executive::contract_address; pub use trie::TrieSpec; diff --git a/crates/ethcore/src/machine/impls.rs b/crates/ethcore/src/machine/impls.rs index f1872879d..81c2a102c 100644 --- a/crates/ethcore/src/machine/impls.rs +++ b/crates/ethcore/src/machine/impls.rs @@ -41,9 +41,9 @@ use builtin::Builtin; use call_contract::CallContract; use client::BlockInfo; use error::Error; -use executive::Executive; +use crate::executive::Executive; use spec::CommonParams; -use state::{CleanupMode, Substate}; +use crate::state::{CleanupMode, Substate}; use trace::{NoopTracer, NoopVMTracer}; use tx_filter::TransactionFilter; diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 5d5419232..3f20b3680 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -64,10 +64,10 @@ use client::{ }; use engines::{EngineSigner, EthEngine, Seal, SealingState}; use error::{Error, ErrorKind}; -use executed::ExecutionError; -use executive::contract_address; +use crate::executed::ExecutionError; +use crate::executive::contract_address; use spec::Spec; -use state::State; +use crate::state::State; /// Different possible definitions for pending transaction set. #[derive(Debug, PartialEq)] diff --git a/crates/ethcore/src/miner/mod.rs b/crates/ethcore/src/miner/mod.rs index b6390e7db..c3eff6094 100644 --- a/crates/ethcore/src/miner/mod.rs +++ b/crates/ethcore/src/miner/mod.rs @@ -55,7 +55,7 @@ use client::{ SealedBlockImporter, }; use error::Error; -use state::StateInfo; +use crate::state::StateInfo; /// Provides methods to verify incoming external transactions pub trait TransactionVerifierClient: Send + Sync diff --git a/crates/ethcore/src/miner/pool_client.rs b/crates/ethcore/src/miner/pool_client.rs index 33eaa2d37..cc4327fc9 100644 --- a/crates/ethcore/src/miner/pool_client.rs +++ b/crates/ethcore/src/miner/pool_client.rs @@ -36,7 +36,7 @@ use miner::{ self, cache::{Cache, CachedClient}, }; -use transaction_ext::Transaction; +use crate::transaction_ext::Transaction; pub(crate) struct CachedNonceClient<'a, C: 'a> { cached_client: CachedClient<'a, C, Address, U256>, diff --git a/crates/ethcore/src/pod_account.rs b/crates/ethcore/src/pod_account.rs index 6187072db..f40320ba4 100644 --- a/crates/ethcore/src/pod_account.rs +++ b/crates/ethcore/src/pod_account.rs @@ -28,7 +28,7 @@ use kvdb::DBValue; use rlp::{self, RlpStream}; use rustc_hex::ToHex; use serde::Serializer; -use state::Account; +use crate::state::Account; use std::{collections::BTreeMap, fmt}; use trie::TrieFactory; use triehash::sec_trie_root; diff --git a/crates/ethcore/src/pod_state.rs b/crates/ethcore/src/pod_state.rs index c28797836..8d7b346ae 100644 --- a/crates/ethcore/src/pod_state.rs +++ b/crates/ethcore/src/pod_state.rs @@ -19,7 +19,7 @@ use ethereum_types::{Address, H256}; use ethjson; use itertools::Itertools; -use pod_account::{self, PodAccount}; +use crate::pod_account::{self, PodAccount}; use std::{collections::BTreeMap, fmt}; use triehash::sec_trie_root; use types::state_diff::StateDiff; @@ -104,7 +104,7 @@ pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff { mod test { use super::PodState; use ethereum_types::H160; - use pod_account::PodAccount; + use crate::pod_account::PodAccount; use std::collections::BTreeMap; use types::{account_diff::*, state_diff::*}; diff --git a/crates/ethcore/src/snapshot/tests/helpers.rs b/crates/ethcore/src/snapshot/tests/helpers.rs index 1bbc60961..a72be7816 100644 --- a/crates/ethcore/src/snapshot/tests/helpers.rs +++ b/crates/ethcore/src/snapshot/tests/helpers.rs @@ -99,9 +99,9 @@ impl StateProducer { let new_accs = rng.gen::() % 5; for _ in 0..new_accs { - let address_hash = H256(rng.gen()); - let balance: usize = rng.gen(); - let nonce: usize = rng.gen(); + let address_hash = H256(rng.r#gen()); + let balance: usize = rng.r#gen(); + let nonce: usize = rng.r#gen(); let acc = ::state::Account::new_basic(balance.into(), nonce.into()).rlp(); trie.insert(&address_hash[..], &acc).unwrap(); } diff --git a/crates/ethcore/src/spec/spec.rs b/crates/ethcore/src/spec/spec.rs index 94b062379..37f86cb7b 100644 --- a/crates/ethcore/src/spec/spec.rs +++ b/crates/ethcore/src/spec/spec.rs @@ -40,13 +40,13 @@ use engines::{ InstantSealParams, NullEngine, DEFAULT_BLOCKHASH_CONTRACT, }; use error::Error; -use executive::Executive; -use factory::Factories; +use crate::executive::Executive; +use crate::factory::Factories; use machine::EthereumMachine; use maplit::btreeset; use pod_state::PodState; use spec::{seal::Generic as GenericSeal, Genesis}; -use state::{backend::Basic as BasicBackend, Backend, State, Substate}; +use crate::state::{backend::Basic as BasicBackend, Backend, State, Substate}; use trace::{NoopTracer, NoopVMTracer}; pub use ethash::OptimizeFor; @@ -1237,7 +1237,7 @@ impl Spec { mod tests { use super::*; use ethereum_types::{H160, H256}; - use state::State; + use crate::state::State; use std::str::FromStr; use tempdir::TempDir; use test_helpers::get_temp_state_db; diff --git a/crates/ethcore/src/state/account.rs b/crates/ethcore/src/state/account.rs index e524285c5..425c64fca 100644 --- a/crates/ethcore/src/state/account.rs +++ b/crates/ethcore/src/state/account.rs @@ -17,7 +17,7 @@ //! Single account in the system. use bytes::{Bytes, ToPretty}; -use error::Error; +use crate::error::Error; use ethereum_types::{Address, BigEndianHash, H256, U256}; use ethtrie::{Result as TrieResult, SecTrieDB, TrieDB, TrieFactory}; use hash::{keccak, KECCAK_EMPTY, KECCAK_NULL_RLP}; @@ -25,7 +25,7 @@ use hash_db::HashDB; use keccak_hasher::KeccakHasher; use kvdb::DBValue; use lru_cache::LruCache; -use pod_account::*; +use crate::pod_account::*; use rlp::{encode, RlpStream}; use std::{ collections::{BTreeMap, HashMap}, diff --git a/crates/ethcore/src/state/backend.rs b/crates/ethcore/src/state/backend.rs index 53e8ee4a4..301aca962 100644 --- a/crates/ethcore/src/state/backend.rs +++ b/crates/ethcore/src/state/backend.rs @@ -33,7 +33,7 @@ use keccak_hasher::KeccakHasher; use kvdb::DBValue; use memory_db::MemoryDB; use parking_lot::Mutex; -use state::Account; +use crate::state::Account; /// State backend. See module docs for more details. pub trait Backend: Send { diff --git a/crates/ethcore/src/state/mod.rs b/crates/ethcore/src/state/mod.rs index 2617412c2..85e14538c 100644 --- a/crates/ethcore/src/state/mod.rs +++ b/crates/ethcore/src/state/mod.rs @@ -27,15 +27,15 @@ use std::{ sync::Arc, }; -use error::Error; -use executed::{Executed, ExecutionError}; -use executive::{Executive, TransactOptions}; -use factory::{Factories, VmFactory}; -use machine::EthereumMachine as Machine; -use pod_account::*; -use pod_state::{self, PodState}; -use state_db::StateDB; -use trace::{self, FlatTrace, VMTrace}; +use crate::error::Error; +use crate::executed::{Executed, ExecutionError}; +use crate::executive::{Executive, TransactOptions}; +use crate::factory::{Factories, VmFactory}; +use crate::machine::EthereumMachine as Machine; +use crate::pod_account::*; +use crate::pod_state::{self, PodState}; +use crate::state_db::StateDB; +use crate::trace::{self, FlatTrace, VMTrace}; use types::{ basic_account::BasicAccount, receipt::{LegacyReceipt, TransactionOutcome, TypedReceipt}, @@ -3357,7 +3357,7 @@ mod tests { #[test] fn should_trace_diff_suicided_accounts() { - use pod_account; + use crate::pod_account; let a = Address::from_low_u64_be(10); let db = get_temp_state_db(); @@ -3396,7 +3396,7 @@ mod tests { #[test] fn should_trace_diff_unmodified_storage() { - use pod_account; + use crate::pod_account; let a = Address::from_low_u64_be(10); let db = get_temp_state_db(); diff --git a/crates/ethcore/src/state_db.rs b/crates/ethcore/src/state_db.rs index 78942399d..a9975d4e8 100644 --- a/crates/ethcore/src/state_db.rs +++ b/crates/ethcore/src/state_db.rs @@ -32,7 +32,7 @@ use memory_cache::MemoryLruCache; use parking_lot::Mutex; use types::BlockNumber; -use state::{self, Account}; +use crate::state::{self, Account}; const STATE_CACHE_BLOCKS: usize = 12; @@ -447,7 +447,7 @@ unsafe impl Sync for SyncAccount {} mod tests { use ethereum_types::{Address, H256, U256}; use kvdb::DBTransaction; - use state::{Account, Backend}; + use crate::state::{Account, Backend}; use test_helpers::get_temp_state_db; #[test] diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index 4f07a47e6..050a9946c 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -49,10 +49,10 @@ use client::{ }; use engines::{EngineSigner, Seal}; use ethjson::crypto::publickey::{Public, Signature}; -use factory::Factories; +use crate::factory::Factories; use miner::Miner; use spec::Spec; -use state::*; +use crate::state::*; use state_db::StateDB; use verification::queue::kind::blocks::Unverified; diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index 29b7c30ff..6f9e9d18c 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -28,13 +28,13 @@ use client::{ use crypto::publickey::KeyPair; use ethereum; use ethereum_types::{Address, U256}; -use executive::{Executive, TransactOptions}; +use crate::executive::{Executive, TransactOptions}; use hash::keccak; use io::IoChannel; use miner::{Miner, MinerService, PendingOrdering}; use rustc_hex::ToHex; use spec::Spec; -use state::{self, CleanupMode, State, StateInfo}; +use crate::state::{self, CleanupMode, State, StateInfo}; use tempdir::TempDir; use test_helpers::{ self, generate_dummy_client, generate_dummy_client_with_data, get_bad_state_dummy_block, diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index b8e1f5c21..54ac6237a 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -17,9 +17,9 @@ //! Tests of EVM integration with transaction execution. use evm::{Factory, VMType}; -use executive::Executive; +use crate::executive::Executive; use hash::keccak; -use state::Substate; +use crate::state::Substate; use std::sync::Arc; use test_helpers::get_temp_state_with_factory; use trace::{NoopTracer, NoopVMTracer}; From 66cfb93df8f3ea1a8b6a43efc2a4d184f4d82373 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 21 Apr 2025 17:38:06 +0200 Subject: [PATCH 429/687] batch of rust 2025 changes --- crates/ethcore/service/src/service.rs | 2 +- crates/ethcore/src/block.rs | 4 ++-- crates/ethcore/src/client/ancient_import.rs | 6 ++--- crates/ethcore/src/client/chain_notify.rs | 2 +- crates/ethcore/src/client/client.rs | 22 +++++++++---------- crates/ethcore/src/client/config.rs | 2 +- crates/ethcore/src/client/evm_test_client.rs | 2 +- crates/ethcore/src/client/io_message.rs | 2 +- crates/ethcore/src/client/test_client.rs | 8 +++---- crates/ethcore/src/client/trace.rs | 2 +- crates/ethcore/src/client/traits.rs | 8 +++---- .../authority_round/block_gas_limit.rs | 2 +- .../src/engines/authority_round/mod.rs | 12 +++++----- .../src/engines/authority_round/randomness.rs | 2 +- .../src/engines/authority_round/util.rs | 2 +- crates/ethcore/src/engines/basic_authority.rs | 18 +++++++-------- crates/ethcore/src/engines/block_reward.rs | 8 +++---- .../ethcore/src/engines/clique/block_state.rs | 2 +- crates/ethcore/src/engines/clique/mod.rs | 8 +++---- crates/ethcore/src/engines/clique/tests.rs | 4 ++-- crates/ethcore/src/engines/clique/util.rs | 2 +- .../src/engines/hbbft/block_reward_hbbft.rs | 2 +- .../contracts/connectivity_tracker_hbbft.rs | 2 +- .../engines/hbbft/contracts/keygen_history.rs | 6 ++--- .../src/engines/hbbft/contracts/staking.rs | 6 ++--- .../engines/hbbft/contracts/validator_set.rs | 4 ++-- .../ethcore/src/engines/hbbft/contribution.rs | 2 +- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 10 ++++----- .../engines/hbbft/hbbft_message_memorium.rs | 2 +- .../ethcore/src/engines/hbbft/hbbft_state.rs | 4 ++-- .../src/engines/hbbft/keygen_transactions.rs | 4 ++-- .../engines/hbbft/test/hbbft_test_client.rs | 4 ++-- crates/ethcore/src/engines/hbbft/test/mod.rs | 2 +- .../engines/hbbft/test/network_simulator.rs | 2 +- .../src/engines/hbbft/utils/bound_contract.rs | 2 +- crates/ethcore/src/engines/instant_seal.rs | 10 ++++----- crates/ethcore/src/engines/mod.rs | 4 ++-- crates/ethcore/src/engines/null_engine.rs | 6 ++--- .../src/engines/validator_set/contract.rs | 6 ++--- .../ethcore/src/engines/validator_set/mod.rs | 4 ++-- .../src/engines/validator_set/multi.rs | 8 +++---- .../engines/validator_set/safe_contract.rs | 12 +++++----- .../src/engines/validator_set/simple_list.rs | 2 +- .../ethcore/src/engines/validator_set/test.rs | 2 +- crates/ethcore/src/error.rs | 2 +- crates/ethcore/src/ethereum/ethash.rs | 10 ++++----- crates/ethcore/src/ethereum/mod.rs | 2 +- crates/ethcore/src/executive.rs | 4 ++-- crates/ethcore/src/externalities.rs | 2 +- crates/ethcore/src/json_tests/chain.rs | 2 +- crates/ethcore/src/json_tests/executive.rs | 2 +- crates/ethcore/src/json_tests/state.rs | 2 +- crates/ethcore/src/json_tests/transaction.rs | 2 +- crates/ethcore/src/machine/impls.rs | 4 ++-- crates/ethcore/src/machine/traits.rs | 2 +- crates/ethcore/src/miner/miner.rs | 8 +++---- crates/ethcore/src/miner/mod.rs | 4 ++-- crates/ethcore/src/miner/pool_client.rs | 4 ++-- crates/ethcore/src/miner/stratum.rs | 2 +- .../src/snapshot/consensus/authority.rs | 8 +++---- crates/ethcore/src/snapshot/consensus/mod.rs | 4 ++-- crates/ethcore/src/snapshot/consensus/work.rs | 4 ++-- crates/ethcore/src/snapshot/mod.rs | 4 ++-- crates/ethcore/src/snapshot/service.rs | 8 +++---- crates/ethcore/src/snapshot/tests/helpers.rs | 6 ++--- .../src/snapshot/tests/proof_of_authority.rs | 2 +- .../src/snapshot/tests/proof_of_work.rs | 2 +- crates/ethcore/src/snapshot/tests/service.rs | 4 ++-- crates/ethcore/src/snapshot/watcher.rs | 4 ++-- crates/ethcore/src/spec/spec.rs | 4 ++-- crates/ethcore/src/state/mod.rs | 2 +- crates/ethcore/src/test_helpers.rs | 8 +++---- crates/ethcore/src/tests/blockchain.rs | 2 +- crates/ethcore/src/tests/client.rs | 4 ++-- crates/ethcore/src/tests/trace.rs | 4 ++-- crates/ethcore/src/trace/db.rs | 2 +- crates/ethcore/src/tx_filter.rs | 6 ++--- .../src/verification/canon_verifier.rs | 4 ++-- crates/ethcore/src/verification/mod.rs | 2 +- .../ethcore/src/verification/noop_verifier.rs | 4 ++-- crates/ethcore/src/verification/queue/kind.rs | 6 ++--- crates/ethcore/src/verification/queue/mod.rs | 6 ++--- .../ethcore/src/verification/verification.rs | 14 ++++++------ crates/ethcore/src/verification/verifier.rs | 4 ++-- crates/ethcore/sync/src/block_sync.rs | 2 +- crates/ethcore/sync/src/chain/handler.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 2 +- crates/ethcore/sync/src/chain/requester.rs | 2 +- crates/ethcore/sync/src/chain/supplier.rs | 2 +- crates/net/network/src/lib.rs | 2 +- crates/util/cli-signer/rpc-client/src/lib.rs | 2 +- .../rpc-client/src/signer_client.rs | 2 +- crates/util/cli-signer/src/lib.rs | 2 +- 93 files changed, 207 insertions(+), 207 deletions(-) diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index f4c046676..6a7b61566 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -22,7 +22,7 @@ use ansi_term::Colour; use io::{IoContext, IoError, IoHandler, IoService, TimerToken}; use stop_guard::StopGuard; -use blockchain::{BlockChainDB, BlockChainDBHandler}; +use crate::blockchain::{BlockChainDB, BlockChainDBHandler}; use ethcore::{ client::{ChainNotify, Client, ClientConfig, ClientIoMessage}, error::{Error as EthcoreError, ErrorKind}, diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index d13f2e889..0568f5c36 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -36,7 +36,7 @@ use std::{cmp, collections::HashSet, ops, sync::Arc}; use bytes::Bytes; use ethereum_types::{Address, Bloom, H256, U256}; -use engines::EthEngine; +use crate::engines::EthEngine; use error::{BlockError, Error}; use crate::factory::Factories; use crate::state::State; @@ -627,7 +627,7 @@ pub fn enact_verified( #[cfg(test)] mod tests { use super::*; - use engines::EthEngine; + use crate::engines::EthEngine; use error::Error; use ethereum_types::Address; use crate::factory::Factories; diff --git a/crates/ethcore/src/client/ancient_import.rs b/crates/ethcore/src/client/ancient_import.rs index 7043b9e00..04a864070 100644 --- a/crates/ethcore/src/client/ancient_import.rs +++ b/crates/ethcore/src/client/ancient_import.rs @@ -18,10 +18,10 @@ use std::sync::Arc; -use engines::{EpochVerifier, EthEngine}; -use machine::EthereumMachine; +use crate::engines::{EpochVerifier, EthEngine}; +use crate::machine::EthereumMachine; -use blockchain::BlockChain; +use crate::blockchain::BlockChain; use parking_lot::RwLock; use rand::Rng; use types::header::Header; diff --git a/crates/ethcore/src/client/chain_notify.rs b/crates/ethcore/src/client/chain_notify.rs index 53fde6719..0aa901025 100644 --- a/crates/ethcore/src/client/chain_notify.rs +++ b/crates/ethcore/src/client/chain_notify.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use blockchain::ImportRoute; +use crate::blockchain::ImportRoute; use bytes::Bytes; use ethereum_types::{H256, H512, U256}; use std::{collections::HashMap, time::Duration}; diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index e7540b7bd..070830473 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -27,7 +27,7 @@ use std::{ time::{Duration, Instant}, }; -use blockchain::{ +use crate::blockchain::{ BlockChain, BlockChainDB, BlockNumberKey, BlockProvider, BlockReceipts, ExtrasInsert, ImportRoute, TransactionAddress, TreeRoute, }; @@ -60,9 +60,9 @@ use types::{ use vm::{EnvInfo, LastHashes}; use ansi_term::Colour; -use block::{enact_verified, ClosedBlock, Drain, LockedBlock, OpenBlock, SealedBlock}; +use crate::block::{enact_verified, ClosedBlock, Drain, LockedBlock, OpenBlock, SealedBlock}; use call_contract::RegistryInfo; -use client::{ +use crate::client::{ ancient_import::AncientVerifier, bad_blocks, traits::{ChainSyncing, ForceUpdateSealing, ReservedPeersManagement, TransactionRequest}, @@ -74,7 +74,7 @@ use client::{ ScheduleInfo, SealedBlockImporter, StateClient, StateInfo, StateOrBlock, TraceFilter, TraceId, TransactionId, TransactionInfo, UncleId, }; -use engines::{ +use crate::engines::{ epoch::PendingTransition, EngineError, EpochTransition, EthEngine, ForkChoice, SealingState, MAX_UNCLE_AGE, }; @@ -102,7 +102,7 @@ use verification::{ }; use vm::Schedule; // re-export -pub use blockchain::CacheSize as BlockChainCacheSize; +pub use crate::blockchain::CacheSize as BlockChainCacheSize; use db::{keys::BlockDetails, Readable, Writable}; pub use reth_util::queue::ExecutionQueue; pub use types::{block_status::BlockStatus, blockchain_info::BlockChainInfo}; @@ -854,7 +854,7 @@ impl Importer { state_db: &StateDB, client: &Client, ) -> EthcoreResult> { - use engines::EpochChange; + use crate::engines::EpochChange; let hash = header.hash(); let auxiliary = ::machine::AuxiliaryData { @@ -864,7 +864,7 @@ impl Importer { match self.engine.signals_epoch_end(header, auxiliary) { EpochChange::Yes(proof) => { - use engines::Proof; + use crate::engines::Proof; let proof = match proof { Proof::Known(proof) => proof, @@ -2434,7 +2434,7 @@ impl BlockChainClient for Client { } fn transaction_receipt(&self, id: TransactionId) -> Option { - // NOTE Don't use block_receipts here for performance reasons + // NOTE Don't use crate::block_receipts here for performance reasons let address = self.transaction_address(id)?; let hash = address.block_hash; let chain = self.chain.read(); @@ -3785,14 +3785,14 @@ impl PrometheusMetrics for Client { #[cfg(test)] mod tests { - use blockchain::{BlockProvider, ExtrasInsert}; + use crate::blockchain::{BlockProvider, ExtrasInsert}; use ethereum_types::{H160, H256}; use spec::Spec; use test_helpers::generate_dummy_client_with_spec_and_data; #[test] fn should_not_cache_details_before_commit() { - use client::{BlockChainClient, ChainInfo}; + use crate::client::{BlockChainClient, ChainInfo}; use test_helpers::{generate_dummy_client, get_good_dummy_block_hash}; use kvdb::DBTransaction; @@ -3840,7 +3840,7 @@ mod tests { #[test] fn should_return_block_receipts() { - use client::{BlockChainClient, BlockId, TransactionId}; + use crate::client::{BlockChainClient, BlockId, TransactionId}; use test_helpers::generate_dummy_client_with_data; let client = generate_dummy_client_with_data(2, 2, &[1.into(), 1.into()]); diff --git a/crates/ethcore/src/client/config.rs b/crates/ethcore/src/client/config.rs index a023678c5..6a72f5e27 100644 --- a/crates/ethcore/src/client/config.rs +++ b/crates/ethcore/src/client/config.rs @@ -23,7 +23,7 @@ use journaldb; use snapshot::SnapshotConfiguration; use verification::{QueueConfig, VerifierType}; -pub use blockchain::Config as BlockChainConfig; +pub use crate::blockchain::Config as BlockChainConfig; pub use evm::VMType; pub use std::time::Duration; pub use trace::Config as TraceConfig; diff --git a/crates/ethcore/src/client/evm_test_client.rs b/crates/ethcore/src/client/evm_test_client.rs index cc50f4319..3de6c2fad 100644 --- a/crates/ethcore/src/client/evm_test_client.rs +++ b/crates/ethcore/src/client/evm_test_client.rs @@ -16,7 +16,7 @@ //! Simple Client used for EVM tests. -use client; +use crate::client; use db; use ethereum_types::{H160, H256, U256}; use ethtrie; diff --git a/crates/ethcore/src/client/io_message.rs b/crates/ethcore/src/client/io_message.rs index cd9c36cf0..7e425d48b 100644 --- a/crates/ethcore/src/client/io_message.rs +++ b/crates/ethcore/src/client/io_message.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use bytes::Bytes; -use client::Client; +use crate::client::Client; use ethereum_types::H256; use snapshot::ManifestData; use std::fmt; diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index e76885ada..af6c4cdd7 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -25,7 +25,7 @@ use std::{ }, }; -use blockchain::{BlockReceipts, TreeRoute}; +use crate::blockchain::{BlockReceipts, TreeRoute}; use bytes::Bytes; use crypto::publickey::{Generator, Random}; use db::{COL_STATE, NUM_COLUMNS}; @@ -56,9 +56,9 @@ use types::{ }; use vm::Schedule; -use block::{ClosedBlock, OpenBlock, SealedBlock}; +use crate::block::{ClosedBlock, OpenBlock, SealedBlock}; use call_contract::{CallContract, RegistryInfo}; -use client::{ +use crate::client::{ traits::{ForceUpdateSealing, TransactionRequest}, AccountData, BadBlocks, Balance, BlockChain, BlockChainClient, BlockChainInfo, BlockId, BlockInfo, BlockProducer, BlockStatus, BroadcastProposalBlock, Call, CallAnalytics, ChainInfo, @@ -66,7 +66,7 @@ use client::{ PrepareOpenBlock, ProvingBlockChainClient, ReopenBlock, ScheduleInfo, SealedBlockImporter, StateClient, StateOrBlock, TraceFilter, TraceId, TransactionId, TransactionInfo, UncleId, }; -use engines::EthEngine; +use crate::engines::EthEngine; use error::{Error, EthcoreResult}; use crate::executed::CallError; use crate::executive::Executed; diff --git a/crates/ethcore/src/client/trace.rs b/crates/ethcore/src/client/trace.rs index 2fae25f8d..6d60a5cf3 100644 --- a/crates/ethcore/src/client/trace.rs +++ b/crates/ethcore/src/client/trace.rs @@ -16,7 +16,7 @@ //! Bridge between Tracedb and Blockchain. -use blockchain::{BlockChain, BlockProvider, TransactionAddress}; +use crate::blockchain::{BlockChain, BlockProvider, TransactionAddress}; use ethereum_types::H256; use trace::DatabaseExtras as TraceDatabaseExtras; use types::BlockNumber; diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 5eb146355..2752ba899 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -22,7 +22,7 @@ use std::{ sync::Arc, }; -use blockchain::{BlockReceipts, TreeRoute}; +use crate::blockchain::{BlockReceipts, TreeRoute}; use bytes::Bytes; use call_contract::{CallContract, RegistryInfo}; use ethcore_miner::pool::VerifiedTransaction; @@ -50,9 +50,9 @@ use types::{ }; use vm::LastHashes; -use block::{ClosedBlock, OpenBlock, SealedBlock}; -use client::Mode; -use engines::EthEngine; +use crate::block::{ClosedBlock, OpenBlock, SealedBlock}; +use crate::client::Mode; +use crate::engines::EthEngine; use error::{Error, EthcoreResult}; use crate::executed::CallError; use crate::executive::Executed; diff --git a/crates/ethcore/src/engines/authority_round/block_gas_limit.rs b/crates/ethcore/src/engines/authority_round/block_gas_limit.rs index b4f98dc75..2e97d7625 100644 --- a/crates/ethcore/src/engines/authority_round/block_gas_limit.rs +++ b/crates/ethcore/src/engines/authority_round/block_gas_limit.rs @@ -16,7 +16,7 @@ //! A client interface for interacting with the block gas limit contract. -use client::{BlockChainClient, BlockId}; +use crate::client::{BlockChainClient, BlockId}; use types::header::Header; use ethabi::FunctionOutputDecoder; use ethabi_contract::use_contract; diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index 429a7e324..dfd7d2625 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -51,14 +51,14 @@ use super::{ validator_set::{new_validator_set_posdao, SimpleList, ValidatorSet}, EthEngine, }; -use block::*; +use crate::block::*; use bytes::Bytes; -use client::{ +use crate::client::{ traits::{ForceUpdateSealing, TransactionRequest}, EngineClient, }; use crypto::publickey::{self, Signature}; -use engines::{ +use crate::engines::{ block_reward, block_reward::{BlockRewardContract, RewardKind}, ConstructedVerifier, Engine, EngineError, Seal, SealingState, @@ -71,7 +71,7 @@ use hash::keccak; use io::{IoContext, IoHandler, IoService, TimerToken}; use itertools::{self, Itertools}; use lru_cache::LruCache; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use parking_lot::{Mutex, RwLock}; use rand::rngs::OsRng; use rlp::{encode, Decodable, DecoderError, Encodable, Rlp, RlpStream}; @@ -2386,9 +2386,9 @@ mod tests { AuthorityRoundParams, EmptyStep, SealedEmptyStep, StepDurationInfo, }; use accounts::AccountProvider; - use block::*; + use crate::block::*; use crypto::publickey::Signature; - use engines::{ + use crate::engines::{ block_reward::BlockRewardContract, validator_set::{SimpleList, TestSet}, Engine, EngineError, EngineSigner, EthEngine, Seal, diff --git a/crates/ethcore/src/engines/authority_round/randomness.rs b/crates/ethcore/src/engines/authority_round/randomness.rs index 7a2fdefa9..fef2d5ad6 100644 --- a/crates/ethcore/src/engines/authority_round/randomness.rs +++ b/crates/ethcore/src/engines/authority_round/randomness.rs @@ -72,7 +72,7 @@ use bytes::Bytes; use crypto::publickey::{ecies, Error as CryptoError}; use derive_more::Display; -use engines::signer::EngineSigner; +use crate::engines::signer::EngineSigner; use ethabi::Hash; use ethabi_contract::use_contract; use ethereum_types::{Address, H256, U256}; diff --git a/crates/ethcore/src/engines/authority_round/util.rs b/crates/ethcore/src/engines/authority_round/util.rs index 3b50a087f..3315f40fc 100644 --- a/crates/ethcore/src/engines/authority_round/util.rs +++ b/crates/ethcore/src/engines/authority_round/util.rs @@ -20,7 +20,7 @@ use std::fmt; -use client::{traits::EngineClient, BlockChainClient}; +use crate::client::{traits::EngineClient, BlockChainClient}; use ethabi::{self, FunctionOutputDecoder}; use ethabi_contract::use_contract; use ethereum_types::{Address, U256}; diff --git a/crates/ethcore/src/engines/basic_authority.rs b/crates/ethcore/src/engines/basic_authority.rs index 91add1a8b..9d8c1b8ac 100644 --- a/crates/ethcore/src/engines/basic_authority.rs +++ b/crates/ethcore/src/engines/basic_authority.rs @@ -17,14 +17,14 @@ //! A blockchain engine that supports a basic, non-BFT proof-of-authority. use super::validator_set::{new_validator_set, SimpleList, ValidatorSet}; -use block::*; -use client::EngineClient; +use crate::block::*; +use crate::client::EngineClient; use crypto::publickey::{self, Signature}; -use engines::{signer::EngineSigner, ConstructedVerifier, Engine, EngineError, Seal, SealingState}; -use error::{BlockError, Error}; +use crate::engines::{signer::EngineSigner, ConstructedVerifier, Engine, EngineError, Seal, SealingState}; +use crate::error::{BlockError, Error}; use ethereum_types::{H256, H520}; use ethjson; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use parking_lot::RwLock; use std::sync::Weak; use types::header::{ExtendedHeader, Header}; @@ -226,14 +226,14 @@ impl Engine for BasicAuthority { #[cfg(test)] mod tests { use accounts::AccountProvider; - use block::*; - use engines::{Seal, SealingState}; + use crate::block::*; + use crate::engines::{Seal, SealingState}; use ethereum_types::H520; use hash::keccak; - use spec::Spec; + use crate::spec::Spec; use std::sync::Arc; use tempdir::TempDir; - use test_helpers::get_temp_state_db; + use crate::test_helpers::get_temp_state_db; use types::header::Header; /// Create a new test chain spec with `BasicAuthority` consensus engine. diff --git a/crates/ethcore/src/engines/block_reward.rs b/crates/ethcore/src/engines/block_reward.rs index 90c05a8a7..d3792db86 100644 --- a/crates/ethcore/src/engines/block_reward.rs +++ b/crates/ethcore/src/engines/block_reward.rs @@ -21,10 +21,10 @@ use ethabi::{self, ParamType}; use ethereum_types::{Address, H160, U256}; use super::{SystemOrCodeCall, SystemOrCodeCallKind}; -use block::ExecutedBlock; +use crate::block::ExecutedBlock; use error::Error; use hash::keccak; -use machine::Machine; +use crate::machine::Machine; use std::sync::Arc; use trace::{self, ExecutiveTracer, Tracer, Tracing}; use types::BlockNumber; @@ -195,13 +195,13 @@ pub fn apply_block_rewards( #[cfg(test)] mod test { - use client::PrepareOpenBlock; + use crate::client::PrepareOpenBlock; use ethereum_types::{H160, U256}; use spec::Spec; use test_helpers::generate_dummy_client_with_spec; use super::{BlockRewardContract, RewardKind}; - use engines::SystemOrCodeCallKind; + use crate::engines::SystemOrCodeCallKind; use std::str::FromStr; #[test] diff --git a/crates/ethcore/src/engines/clique/block_state.rs b/crates/ethcore/src/engines/clique/block_state.rs index 53565693d..27ac9b760 100644 --- a/crates/ethcore/src/engines/clique/block_state.rs +++ b/crates/ethcore/src/engines/clique/block_state.rs @@ -20,7 +20,7 @@ use std::{ time::{Duration, SystemTime, UNIX_EPOCH}, }; -use engines::{ +use crate::engines::{ clique::{ util::{extract_signers, recover_creator}, VoteType, DIFF_INTURN, DIFF_NOTURN, NULL_AUTHOR, SIGNING_DELAY_NOTURN_MS, diff --git a/crates/ethcore/src/engines/clique/mod.rs b/crates/ethcore/src/engines/clique/mod.rs index c5107c117..a06b841d8 100644 --- a/crates/ethcore/src/engines/clique/mod.rs +++ b/crates/ethcore/src/engines/clique/mod.rs @@ -66,10 +66,10 @@ use std::{ }; use super::signer::EngineSigner; -use block::ExecutedBlock; -use client::{traits::ForceUpdateSealing, BlockId, EngineClient}; +use crate::block::ExecutedBlock; +use crate::client::{traits::ForceUpdateSealing, BlockId, EngineClient}; use crypto::publickey::Signature; -use engines::{ +use crate::engines::{ clique::util::{extract_signers, recover_creator}, Engine, EngineError, Seal, SealingState, }; @@ -78,7 +78,7 @@ use ethereum_types::{Address, H160, H256, H64, U256}; use hash::KECCAK_EMPTY_LIST_RLP; use itertools::Itertools; use lru_cache::LruCache; -use machine::{Call, EthereumMachine}; +use crate::machine::{Call, EthereumMachine}; use parking_lot::RwLock; use rand::Rng; use time_utils::CheckedSystemTime; diff --git a/crates/ethcore/src/engines/clique/tests.rs b/crates/ethcore/src/engines/clique/tests.rs index 22135731f..deeb83cea 100644 --- a/crates/ethcore/src/engines/clique/tests.rs +++ b/crates/ethcore/src/engines/clique/tests.rs @@ -17,9 +17,9 @@ //! Consensus tests for `PoA Clique Engine`, see http://eips.ethereum.org/EIPS/eip-225 for more information use super::*; -use block::*; +use crate::block::*; use crypto::publickey::{KeyPair, Secret}; -use engines::Engine; +use crate::engines::Engine; use error::{Error, ErrorKind}; use ethereum_types::{Address, H256}; use state_db::StateDB; diff --git a/crates/ethcore/src/engines/clique/util.rs b/crates/ethcore/src/engines/clique/util.rs index a5fd9f14a..17b92d505 100644 --- a/crates/ethcore/src/engines/clique/util.rs +++ b/crates/ethcore/src/engines/clique/util.rs @@ -17,7 +17,7 @@ use std::collections::BTreeSet; use crypto::publickey::{public_to_address, recover as ec_recover, Signature}; -use engines::{ +use crate::engines::{ clique::{ADDRESS_LENGTH, NULL_MIXHASH, NULL_NONCE, SIGNATURE_LENGTH, VANITY_LENGTH}, EngineError, }; diff --git a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs index 0b6021c3d..5d4d88b0e 100644 --- a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs @@ -17,7 +17,7 @@ //! Types for declaring block rewards and a client interface for interacting with a //! block reward contract. -use engines::{SystemOrCodeCall, SystemOrCodeCallKind}; +use crate::engines::{SystemOrCodeCall, SystemOrCodeCallKind}; use error::Error; use ethabi::FunctionOutputDecoder; use ethabi_contract::use_contract; diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index fce2bbf3c..83b73316a 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -1,4 +1,4 @@ -use client::EngineClient; +use crate::client::EngineClient; use ethereum_types::{Address, H256, U256}; use std::str::FromStr; use types::ids::BlockId; diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index 4746a3aa8..eeca45831 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -1,6 +1,6 @@ -use client::traits::EngineClient; +use crate::client::traits::EngineClient; use crypto::{self, publickey::Public}; -use engines::{ +use crate::engines::{ hbbft::{ contracts::validator_set::{get_validator_pubkeys, ValidatorType}, utils::bound_contract::{BoundContract, CallError}, @@ -267,7 +267,7 @@ pub fn initialize_synckeygen( mod tests { use super::*; use crypto::publickey::{KeyPair, Secret}; - use engines::signer::{from_keypair, EngineSigner}; + use crate::engines::signer::{from_keypair, EngineSigner}; use std::{collections::BTreeMap, sync::Arc}; #[test] diff --git a/crates/ethcore/src/engines/hbbft/contracts/staking.rs b/crates/ethcore/src/engines/hbbft/contracts/staking.rs index 2ab835aef..be30599e8 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/staking.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/staking.rs @@ -1,5 +1,5 @@ -use client::EngineClient; -use engines::hbbft::utils::bound_contract::{BoundContract, CallError}; +use crate::client::EngineClient; +use crate::engines::hbbft::utils::bound_contract::{BoundContract, CallError}; use ethereum_types::{Address, Public, U256}; use std::{ net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, @@ -116,7 +116,7 @@ pub fn get_pool_public_key( pub mod tests { use super::*; use crypto::publickey::{Generator, KeyPair, Public, Random}; - use engines::hbbft::test::hbbft_test_client::HbbftTestClient; + use crate::engines::hbbft::test::hbbft_test_client::HbbftTestClient; pub fn min_staking(client: &dyn EngineClient) -> Result { let c = BoundContract::bind(client, BlockId::Latest, *STAKING_CONTRACT_ADDRESS); diff --git a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs index 1ef64d4fc..d4d529db1 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs @@ -1,9 +1,9 @@ -use client::{ +use crate::client::{ traits::{EngineClient, TransactionRequest}, BlockChainClient, }; use crypto::publickey::Public; -use engines::hbbft::utils::bound_contract::{BoundContract, CallError}; +use crate::engines::hbbft::utils::bound_contract::{BoundContract, CallError}; use ethereum_types::{Address, U256}; use std::{collections::BTreeMap, net::SocketAddr, str::FromStr}; use types::{ids::BlockId, transaction::Error}; diff --git a/crates/ethcore/src/engines/hbbft/contribution.rs b/crates/ethcore/src/engines/hbbft/contribution.rs index 6954a23d9..98ce0de54 100644 --- a/crates/ethcore/src/engines/hbbft/contribution.rs +++ b/crates/ethcore/src/engines/hbbft/contribution.rs @@ -57,7 +57,7 @@ impl Contribution { #[cfg(test)] mod tests { use crypto::publickey::{Generator, Random}; - use engines::hbbft::test::create_transactions::create_transaction; + use crate::engines::hbbft::test::create_transactions::create_transaction; use ethereum_types::U256; use types::transaction::{SignedTransaction, TypedTransaction}; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index ca6bd4d19..2d66dff33 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -9,10 +9,10 @@ use crate::{ hbbft_peers_management::HbbftPeersManagement, }, }; -use block::ExecutedBlock; -use client::traits::{EngineClient, ForceUpdateSealing}; +use crate::block::ExecutedBlock; +use crate::client::traits::{EngineClient, ForceUpdateSealing}; use crypto::publickey::Signature; -use engines::{ +use crate::engines::{ default_system_or_code_call, signer::EngineSigner, Engine, EngineError, ForkChoice, Seal, SealingState, }; @@ -22,7 +22,7 @@ use ethjson::spec::HbbftParams; use hbbft::{NetworkInfo, Target}; use io::{IoContext, IoHandler, IoService, TimerToken}; use itertools::Itertools; -use machine::EthereumMachine; +use crate::machine::EthereumMachine; use parking_lot::{Mutex, RwLock}; use rlp; use rmp_serde; @@ -55,7 +55,7 @@ use super::{ sealing::{self, RlpSig, Sealing}, NodeId, }; -use engines::hbbft::{ +use crate::engines::hbbft::{ contracts::validator_set::{ get_validator_available_since, send_tx_announce_availability, staking_by_mining_address, }, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 61e34d83c..c53f39f15 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -12,7 +12,7 @@ use std::{ }; // use threshold_crypto::{SignatureShare}; -use engines::hbbft::{sealing, NodeId}; +use crate::engines::hbbft::{sealing, NodeId}; // use hbbft::honey_badger::Message; // use serde::{Deserialize, Serialize}; // use serde_json::{json, Result, Value}; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 152621791..4ed91b5dc 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -1,5 +1,5 @@ -use client::traits::EngineClient; -use engines::signer::EngineSigner; +use crate::client::traits::EngineClient; +use crate::engines::signer::EngineSigner; use ethcore_miner::pool::{PoolVerifiedTransaction, ScoredTransaction}; use ethereum_types::U256; use ethjson::spec::hbbft::HbbftNetworkFork; diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index b4f763e7d..8c7a4535c 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -1,5 +1,5 @@ -use client::traits::{EngineClient, TransactionRequest}; -use engines::{ +use crate::client::traits::{EngineClient, TransactionRequest}; +use crate::engines::{ hbbft::{ contracts::{ keygen_history::{ diff --git a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs index a2abb00d9..f53025b37 100644 --- a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs +++ b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs @@ -1,10 +1,10 @@ use super::create_transactions::{create_call, create_transaction, create_transfer}; -use client::{ +use crate::client::{ traits::{Balance, StateOrBlock}, BlockChainClient, ChainSyncing, Client, ImportExportBlocks, }; use crypto::publickey::{Generator, KeyPair, Random}; -use engines::signer::from_keypair; +use crate::engines::signer::from_keypair; use ethereum_types::{Address, U256}; use miner::{Miner, MinerService}; use parking_lot::RwLock; diff --git a/crates/ethcore/src/engines/hbbft/test/mod.rs b/crates/ethcore/src/engines/hbbft/test/mod.rs index 175f00e75..f22f6026c 100644 --- a/crates/ethcore/src/engines/hbbft/test/mod.rs +++ b/crates/ethcore/src/engines/hbbft/test/mod.rs @@ -9,7 +9,7 @@ use super::{ contribution::unix_now_secs, test::hbbft_test_client::{create_hbbft_client, create_hbbft_clients, HbbftTestClient}, }; -use client::traits::BlockInfo; +use crate::client::traits::BlockInfo; use crypto::publickey::{Generator, KeyPair, Random, Secret}; use ethereum_types::{Address, U256}; use std::str::FromStr; diff --git a/crates/ethcore/src/engines/hbbft/test/network_simulator.rs b/crates/ethcore/src/engines/hbbft/test/network_simulator.rs index afcd84ba7..c97b69ce9 100644 --- a/crates/ethcore/src/engines/hbbft/test/network_simulator.rs +++ b/crates/ethcore/src/engines/hbbft/test/network_simulator.rs @@ -1,4 +1,4 @@ -use engines::hbbft::test::hbbft_test_client::HbbftTestClient; +use crate::engines::hbbft::test::hbbft_test_client::HbbftTestClient; use parking_lot::RwLock; use std::collections::BTreeMap; diff --git a/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs b/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs index a62fa1b51..17f32232b 100644 --- a/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs +++ b/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs @@ -6,7 +6,7 @@ use std::fmt; -use client::EngineClient; +use crate::client::EngineClient; use ethabi; use ethereum_types::Address; use types::ids::BlockId; diff --git a/crates/ethcore/src/engines/instant_seal.rs b/crates/ethcore/src/engines/instant_seal.rs index 8410476d8..98a58007c 100644 --- a/crates/ethcore/src/engines/instant_seal.rs +++ b/crates/ethcore/src/engines/instant_seal.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use block::ExecutedBlock; -use engines::{Engine, Seal, SealingState}; -use machine::Machine; +use crate::block::ExecutedBlock; +use crate::engines::{Engine, Seal, SealingState}; +use crate::machine::Machine; use std::sync::atomic::{AtomicU64, Ordering}; use types::header::{ExtendedHeader, Header}; @@ -126,8 +126,8 @@ impl Engine for InstantSeal { #[cfg(test)] mod tests { - use block::*; - use engines::Seal; + use crate::block::*; + use crate::engines::Seal; use ethereum_types::{Address, H520}; use spec::Spec; use std::sync::Arc; diff --git a/crates/ethcore/src/engines/mod.rs b/crates/ethcore/src/engines/mod.rs index a21b9498a..2d257921d 100644 --- a/crates/ethcore/src/engines/mod.rs +++ b/crates/ethcore/src/engines/mod.rs @@ -60,11 +60,11 @@ use types::{ }; use vm::{ActionValue, CallType, CreateContractAddress, EnvInfo, Schedule}; -use block::ExecutedBlock; +use crate::block::ExecutedBlock; use bytes::Bytes; use crypto::publickey::Signature; use ethereum_types::{Address, H256, H512, H64, U256}; -use machine::{self, AuxiliaryData, AuxiliaryRequest, Machine}; +use crate::machine::{self, AuxiliaryData, AuxiliaryRequest, Machine}; use types::ancestry_action::AncestryAction; use unexpected::{Mismatch, OutOfBounds}; diff --git a/crates/ethcore/src/engines/null_engine.rs b/crates/ethcore/src/engines/null_engine.rs index f23e020d6..7885c1d9e 100644 --- a/crates/ethcore/src/engines/null_engine.rs +++ b/crates/ethcore/src/engines/null_engine.rs @@ -14,13 +14,13 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use block::ExecutedBlock; -use engines::{ +use crate::block::ExecutedBlock; +use crate::engines::{ block_reward::{self, RewardKind}, Engine, }; use ethereum_types::U256; -use machine::Machine; +use crate::machine::Machine; use types::{ ancestry_action::AncestryAction, header::{ExtendedHeader, Header}, diff --git a/crates/ethcore/src/engines/validator_set/contract.rs b/crates/ethcore/src/engines/validator_set/contract.rs index a4b781689..ae76df15b 100644 --- a/crates/ethcore/src/engines/validator_set/contract.rs +++ b/crates/ethcore/src/engines/validator_set/contract.rs @@ -20,11 +20,11 @@ use std::sync::Weak; use bytes::Bytes; use ethereum_types::{Address, H256, U256}; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use parking_lot::RwLock; use types::{header::Header, ids::BlockId, transaction, BlockNumber}; -use client::{traits::TransactionRequest, EngineClient}; +use crate::client::{traits::TransactionRequest, EngineClient}; use error::Error as EthcoreError; @@ -219,7 +219,7 @@ mod tests { use accounts::AccountProvider; use bytes::ToPretty; use call_contract::CallContract; - use client::{traits::TransactionRequest, BlockChainClient, BlockInfo, ChainInfo}; + use crate::client::{traits::TransactionRequest, BlockChainClient, BlockInfo, ChainInfo}; use ethabi::FunctionOutputDecoder; use ethereum_types::{Address, H520}; use hash::keccak; diff --git a/crates/ethcore/src/engines/validator_set/mod.rs b/crates/ethcore/src/engines/validator_set/mod.rs index c47e747f5..96c558b4c 100644 --- a/crates/ethcore/src/engines/validator_set/mod.rs +++ b/crates/ethcore/src/engines/validator_set/mod.rs @@ -28,10 +28,10 @@ use std::sync::Weak; use bytes::Bytes; use ethereum_types::{Address, H256}; use ethjson::spec::ValidatorSet as ValidatorSpec; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use types::{header::Header, ids::BlockId, BlockNumber}; -use client::EngineClient; +use crate::client::EngineClient; use error::Error as EthcoreError; diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index 29c7392f8..51c1e5afb 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -24,9 +24,9 @@ use parking_lot::RwLock; use types::{header::Header, ids::BlockId, BlockNumber}; use super::{SystemCall, ValidatorSet}; -use client::EngineClient; +use crate::client::EngineClient; use error::Error as EthcoreError; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use crate::machine::{AuxiliaryData, Call, EthereumMachine}; type BlockNumberLookup = Box Result + Send + Sync + 'static>; @@ -207,12 +207,12 @@ impl ValidatorSet for Multi { #[cfg(test)] mod tests { use accounts::AccountProvider; - use client::{ + use crate::client::{ traits::{ForceUpdateSealing, TransactionRequest}, BlockChainClient, BlockInfo, ChainInfo, ImportBlock, }; use crypto::publickey::Secret; - use engines::{validator_set::ValidatorSet, EpochChange}; + use crate::engines::{validator_set::ValidatorSet, EpochChange}; use ethereum_types::Address; use hash::keccak; use miner::{self, MinerService}; diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index 7d56ba5d8..eae32f579 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -36,8 +36,8 @@ use types::{ use unexpected::Mismatch; use super::{simple_list::SimpleList, SystemCall, ValidatorSet}; -use client::{traits::TransactionRequest, BlockChainClient, EngineClient}; -use machine::{AuxiliaryData, AuxiliaryRequest, Call, EthereumMachine}; +use crate::client::{traits::TransactionRequest, BlockChainClient, EngineClient}; +use crate::machine::{AuxiliaryData, AuxiliaryRequest, Call, EthereumMachine}; use_contract!(validator_set, "res/contracts/validator_set.json"); @@ -715,7 +715,7 @@ impl ReportQueue { mod tests { use super::{super::ValidatorSet, ValidatorSafeContract, EVENT_NAME_HASH}; use accounts::AccountProvider; - use client::{ + use crate::client::{ traits::{EngineClient, ForceUpdateSealing}, BlockInfo, ChainInfo, ImportBlock, }; @@ -856,8 +856,8 @@ mod tests { #[test] fn detects_bloom() { - use engines::EpochChange; - use machine::AuxiliaryRequest; + use crate::engines::EpochChange; + use crate::machine::AuxiliaryRequest; use types::{header::Header, log_entry::LogEntry}; let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); @@ -896,7 +896,7 @@ mod tests { #[test] fn initial_contract_is_signal() { - use engines::{EpochChange, Proof}; + use crate::engines::{EpochChange, Proof}; use types::header::Header; let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); diff --git a/crates/ethcore/src/engines/validator_set/simple_list.rs b/crates/ethcore/src/engines/validator_set/simple_list.rs index c608d68a0..6a044a1c2 100644 --- a/crates/ethcore/src/engines/validator_set/simple_list.rs +++ b/crates/ethcore/src/engines/validator_set/simple_list.rs @@ -21,7 +21,7 @@ use parity_util_mem::MallocSizeOf; use super::{SystemCall, ValidatorSet}; use bytes::Bytes; use error::Error as EthcoreError; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use types::{header::Header, BlockNumber}; /// Validator set containing a known set of addresses. diff --git a/crates/ethcore/src/engines/validator_set/test.rs b/crates/ethcore/src/engines/validator_set/test.rs index 88db87f75..1c6adce61 100644 --- a/crates/ethcore/src/engines/validator_set/test.rs +++ b/crates/ethcore/src/engines/validator_set/test.rs @@ -28,7 +28,7 @@ use types::{header::Header, BlockNumber}; use super::{SimpleList, SystemCall, ValidatorSet}; use error::Error as EthcoreError; -use machine::{AuxiliaryData, Call, EthereumMachine}; +use crate::machine::{AuxiliaryData, Call, EthereumMachine}; /// Set used for testing with a single validator. #[derive(Clone, MallocSizeOf)] diff --git a/crates/ethcore/src/error.rs b/crates/ethcore/src/error.rs index 916b41386..4a5bc0c58 100644 --- a/crates/ethcore/src/error.rs +++ b/crates/ethcore/src/error.rs @@ -31,7 +31,7 @@ use snapshot::Error as SnapshotError; use types::{transaction::Error as TransactionError, BlockNumber}; use unexpected::{Mismatch, OutOfBounds}; -use engines::EngineError; +use crate::engines::EngineError; pub use crate::executed::{CallError, ExecutionError}; diff --git a/crates/ethcore/src/ethereum/ethash.rs b/crates/ethcore/src/ethereum/ethash.rs index 1040d144f..8ecdc591d 100644 --- a/crates/ethcore/src/ethereum/ethash.rs +++ b/crates/ethcore/src/ethereum/ethash.rs @@ -31,15 +31,15 @@ use types::{ }; use unexpected::{Mismatch, OutOfBounds}; -use block::ExecutedBlock; -use engines::{ +use crate::block::ExecutedBlock; +use crate::engines::{ self, block_reward::{self, BlockRewardContract, RewardKind}, Engine, }; use error::{BlockError, Error}; use ethash::{self, quick_get_difficulty, slow_hash_block_number, EthashManager, OptimizeFor}; -use machine::EthereumMachine; +use crate::machine::EthereumMachine; /// Number of blocks in an ethash snapshot. // make dependent on difficulty incrment divisor? @@ -563,8 +563,8 @@ mod tests { super::{new_homestead_test_machine, new_mcip3_test, new_morden}, ecip1017_eras_block_reward, Ethash, EthashParams, }; - use block::*; - use engines::Engine; + use crate::block::*; + use crate::engines::Engine; use error::{BlockError, Error, ErrorKind}; use ethereum_types::{Address, H256, H64, U256}; use rlp; diff --git a/crates/ethcore/src/ethereum/mod.rs b/crates/ethcore/src/ethereum/mod.rs index 0fc8d61b7..815b9ea2c 100644 --- a/crates/ethcore/src/ethereum/mod.rs +++ b/crates/ethcore/src/ethereum/mod.rs @@ -29,7 +29,7 @@ pub mod public_key_to_address; pub use self::{denominations::*, ethash::Ethash}; use super::spec::*; -use machine::EthereumMachine; +use crate::machine::EthereumMachine; /// Load chain spec from `SpecParams` and JSON. pub fn load<'a, T: Into>>>(params: T, b: &[u8]) -> Spec { diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index 5dbe80bf2..b1d18c1c3 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -23,7 +23,7 @@ pub use crate::executed::{Executed, ExecutionResult}; use crate::externalities::*; use crate::factory::VmFactory; use hash::keccak; -use machine::EthereumMachine as Machine; +use crate::machine::EthereumMachine as Machine; use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, convert::TryFrom, sync::Arc}; use trace::{self, Tracer, VMTracer}; @@ -1631,7 +1631,7 @@ mod tests { use error::ExecutionError; use ethereum_types::{Address, BigEndianHash, H160, H256, U256, U512}; use evm::{Factory, VMType}; - use machine::EthereumMachine; + use crate::machine::EthereumMachine; use rustc_hex::FromHex; use crate::state::{CleanupMode, Substate}; use std::{str::FromStr, sync::Arc}; diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index 791996799..df25010f8 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -18,7 +18,7 @@ use bytes::Bytes; use ethereum_types::{Address, BigEndianHash, H256, U256}; use crate::executive::*; -use machine::EthereumMachine as Machine; +use crate::machine::EthereumMachine as Machine; use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, sync::Arc}; use trace::{Tracer, VMTracer}; diff --git a/crates/ethcore/src/json_tests/chain.rs b/crates/ethcore/src/json_tests/chain.rs index f4501d26c..7bbb55c20 100644 --- a/crates/ethcore/src/json_tests/chain.rs +++ b/crates/ethcore/src/json_tests/chain.rs @@ -17,7 +17,7 @@ use crate::exit::ShutdownManager; use super::HookType; -use client::{ +use crate::client::{ Balance, BlockChainClient, BlockId, ChainInfo, Client, ClientConfig, EvmTestClient, ImportBlock, Nonce, StateOrBlock, }; diff --git a/crates/ethcore/src/json_tests/executive.rs b/crates/ethcore/src/json_tests/executive.rs index ac019f6d9..71761968a 100644 --- a/crates/ethcore/src/json_tests/executive.rs +++ b/crates/ethcore/src/json_tests/executive.rs @@ -23,7 +23,7 @@ use evm::Finalize; use crate::executive::*; use crate::externalities::*; use hash::keccak; -use machine::EthereumMachine as Machine; +use crate::machine::EthereumMachine as Machine; use rlp::RlpStream; use crate::state::{Backend as StateBackend, State, Substate}; use std::{path::Path, sync::Arc}; diff --git a/crates/ethcore/src/json_tests/state.rs b/crates/ethcore/src/json_tests/state.rs index 445c60a0b..4c3f4a212 100644 --- a/crates/ethcore/src/json_tests/state.rs +++ b/crates/ethcore/src/json_tests/state.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use super::{test_common::*, HookType}; -use client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess}; +use crate::client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess}; use ethjson::{self, spec::ForkSpec}; use pod_state::PodState; use std::path::Path; diff --git a/crates/ethcore/src/json_tests/transaction.rs b/crates/ethcore/src/json_tests/transaction.rs index 4d5a43c9b..b9363ddb2 100644 --- a/crates/ethcore/src/json_tests/transaction.rs +++ b/crates/ethcore/src/json_tests/transaction.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use super::test_common::*; -use client::EvmTestClient; +use crate::client::EvmTestClient; use ethjson; use std::path::Path; use crate::transaction_ext::Transaction; diff --git a/crates/ethcore/src/machine/impls.rs b/crates/ethcore/src/machine/impls.rs index 81c2a102c..1d92390a2 100644 --- a/crates/ethcore/src/machine/impls.rs +++ b/crates/ethcore/src/machine/impls.rs @@ -36,10 +36,10 @@ use vm::{ Schedule, }; -use block::ExecutedBlock; +use crate::block::ExecutedBlock; use builtin::Builtin; use call_contract::CallContract; -use client::BlockInfo; +use crate::client::BlockInfo; use error::Error; use crate::executive::Executive; use spec::CommonParams; diff --git a/crates/ethcore/src/machine/traits.rs b/crates/ethcore/src/machine/traits.rs index 3f5f22b2e..9f08756a2 100644 --- a/crates/ethcore/src/machine/traits.rs +++ b/crates/ethcore/src/machine/traits.rs @@ -17,7 +17,7 @@ //! Generalization of a state machine for a consensus engine. //! This will define traits for the header, block, and state of a blockchain. -use block::ExecutedBlock; +use crate::block::ExecutedBlock; use ethereum_types::{Address, U256}; /// Generalization of types surrounding blockchain-suitable state machines. diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 3f20b3680..456faf3c7 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -56,13 +56,13 @@ use types::{ }; use using_queue::{GetAction, UsingQueue}; -use block::{ClosedBlock, OpenBlock, SealedBlock}; -use client::{ +use crate::block::{ClosedBlock, OpenBlock, SealedBlock}; +use crate::client::{ traits::{EngineClient, ForceUpdateSealing}, BlockChain, BlockId, BlockProducer, ChainInfo, ClientIoMessage, Nonce, SealedBlockImporter, TransactionId, TransactionInfo, }; -use engines::{EngineSigner, EthEngine, Seal, SealingState}; +use crate::engines::{EngineSigner, EthEngine, Seal, SealingState}; use error::{Error, ErrorKind}; use crate::executed::ExecutionError; use crate::executive::contract_address; @@ -1831,7 +1831,7 @@ mod tests { use rustc_hex::FromHex; use types::BlockNumber; - use client::{ChainInfo, EachBlockWith, ImportSealedBlock, TestBlockChainClient}; + use crate::client::{ChainInfo, EachBlockWith, ImportSealedBlock, TestBlockChainClient}; use miner::{MinerService, PendingOrdering}; use test_helpers::{ dummy_engine_signer_with_address, generate_dummy_client, generate_dummy_client_with_spec, diff --git a/crates/ethcore/src/miner/mod.rs b/crates/ethcore/src/miner/mod.rs index c3eff6094..6b4dacd6c 100644 --- a/crates/ethcore/src/miner/mod.rs +++ b/crates/ethcore/src/miner/mod.rs @@ -48,9 +48,9 @@ use types::{ BlockNumber, }; -use block::SealedBlock; +use crate::block::SealedBlock; use call_contract::{CallContract, RegistryInfo}; -use client::{ +use crate::client::{ traits::ForceUpdateSealing, AccountData, BlockChain, BlockProducer, Nonce, ScheduleInfo, SealedBlockImporter, }; diff --git a/crates/ethcore/src/miner/pool_client.rs b/crates/ethcore/src/miner/pool_client.rs index cc4327fc9..45bbe1f1d 100644 --- a/crates/ethcore/src/miner/pool_client.rs +++ b/crates/ethcore/src/miner/pool_client.rs @@ -29,8 +29,8 @@ use types::{ }; use call_contract::CallContract; -use client::{Balance, BlockId, BlockInfo, Nonce, TransactionId}; -use engines::EthEngine; +use crate::client::{Balance, BlockId, BlockInfo, Nonce, TransactionId}; +use crate::engines::EthEngine; use ethcore_miner::pool::client::BalanceClient; use miner::{ self, diff --git a/crates/ethcore/src/miner/stratum.rs b/crates/ethcore/src/miner/stratum.rs index 180be26cc..f5683f76b 100644 --- a/crates/ethcore/src/miner/stratum.rs +++ b/crates/ethcore/src/miner/stratum.rs @@ -22,7 +22,7 @@ use std::{ sync::{Arc, Weak}, }; -use client::{Client, ImportSealedBlock}; +use crate::client::{Client, ImportSealedBlock}; use ethash::{self, SeedHashCompute}; #[cfg(feature = "work-notify")] use ethcore_miner::work_notify::NotifyWork; diff --git a/crates/ethcore/src/snapshot/consensus/authority.rs b/crates/ethcore/src/snapshot/consensus/authority.rs index 07a84ff33..7706ea106 100644 --- a/crates/ethcore/src/snapshot/consensus/authority.rs +++ b/crates/ethcore/src/snapshot/consensus/authority.rs @@ -26,11 +26,11 @@ use std::sync::{ Arc, }; -use engines::{EpochTransition, EpochVerifier, EthEngine}; -use machine::EthereumMachine; +use crate::engines::{EpochTransition, EpochVerifier, EthEngine}; +use crate::machine::EthereumMachine; use snapshot::{Error, ManifestData, Progress}; -use blockchain::{BlockChain, BlockChainDB, BlockProvider}; +use crate::blockchain::{BlockChain, BlockChainDB, BlockProvider}; use bytes::Bytes; use db::KeyValueDB; use ethereum_types::{H256, U256}; @@ -199,7 +199,7 @@ impl ChunkRebuilder { transition_rlp: Rlp, engine: &dyn EthEngine, ) -> Result { - use engines::ConstructedVerifier; + use crate::engines::ConstructedVerifier; // decode. let header = diff --git a/crates/ethcore/src/snapshot/consensus/mod.rs b/crates/ethcore/src/snapshot/consensus/mod.rs index 44db5f724..546054de5 100644 --- a/crates/ethcore/src/snapshot/consensus/mod.rs +++ b/crates/ethcore/src/snapshot/consensus/mod.rs @@ -19,8 +19,8 @@ use std::sync::{atomic::AtomicBool, Arc}; -use blockchain::{BlockChain, BlockChainDB}; -use engines::EthEngine; +use crate::blockchain::{BlockChain, BlockChainDB}; +use crate::engines::EthEngine; use snapshot::{Error, ManifestData, Progress}; use types::BlockNumber; diff --git a/crates/ethcore/src/snapshot/consensus/work.rs b/crates/ethcore/src/snapshot/consensus/work.rs index 58a8525f3..948064a36 100644 --- a/crates/ethcore/src/snapshot/consensus/work.rs +++ b/crates/ethcore/src/snapshot/consensus/work.rs @@ -30,10 +30,10 @@ use std::{ }, }; -use blockchain::{BlockChain, BlockChainDB, BlockProvider}; +use crate::blockchain::{BlockChain, BlockChainDB, BlockProvider}; use bytes::Bytes; use db::KeyValueDB; -use engines::EthEngine; +use crate::engines::EthEngine; use ethereum_types::H256; use rand::rngs::OsRng; use rlp::{Rlp, RlpStream}; diff --git a/crates/ethcore/src/snapshot/mod.rs b/crates/ethcore/src/snapshot/mod.rs index 1cf466d1a..7dcab23b1 100644 --- a/crates/ethcore/src/snapshot/mod.rs +++ b/crates/ethcore/src/snapshot/mod.rs @@ -30,8 +30,8 @@ use std::{ }; use account_db::{AccountDB, AccountDBMut}; -use blockchain::{BlockChain, BlockProvider}; -use engines::EthEngine; +use crate::blockchain::{BlockChain, BlockProvider}; +use crate::engines::EthEngine; use types::{header::Header, ids::BlockId}; use bytes::Bytes; diff --git a/crates/ethcore/src/snapshot/service.rs b/crates/ethcore/src/snapshot/service.rs index 10519c06d..cfd159e77 100644 --- a/crates/ethcore/src/snapshot/service.rs +++ b/crates/ethcore/src/snapshot/service.rs @@ -34,9 +34,9 @@ use super::{ MAX_CHUNK_SIZE, }; -use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler}; -use client::{BlockChainClient, BlockInfo, ChainInfo, Client, ClientIoMessage}; -use engines::EthEngine; +use crate::blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler}; +use crate::client::{BlockChainClient, BlockInfo, ChainInfo, Client, ClientIoMessage}; +use crate::engines::EthEngine; use error::{Error, ErrorKind as SnapshotErrorKind}; use hash::keccak; use snapshot::Error as SnapshotError; @@ -1011,7 +1011,7 @@ impl Drop for Service { #[cfg(test)] mod tests { use super::*; - use client::ClientIoMessage; + use crate::client::ClientIoMessage; use io::IoService; use journaldb::Algorithm; use snapshot::{ManifestData, RestorationStatus, SnapshotService}; diff --git a/crates/ethcore/src/snapshot/tests/helpers.rs b/crates/ethcore/src/snapshot/tests/helpers.rs index a72be7816..bcbbbc1f3 100644 --- a/crates/ethcore/src/snapshot/tests/helpers.rs +++ b/crates/ethcore/src/snapshot/tests/helpers.rs @@ -23,9 +23,9 @@ use hash::KECCAK_NULL_RLP; use std::sync::Arc; use account_db::AccountDBMut; -use blockchain::{BlockChain, BlockChainDB}; -use client::{ChainInfo, Client}; -use engines::EthEngine; +use crate::blockchain::{BlockChain, BlockChainDB}; +use crate::client::{ChainInfo, Client}; +use crate::engines::EthEngine; use snapshot::{ io::{PackedReader, PackedWriter, SnapshotReader}, StateRebuilder, diff --git a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs index dc111a025..029d86ba5 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -19,7 +19,7 @@ use std::{cell::RefCell, str::FromStr, sync::Arc}; use accounts::AccountProvider; -use client::{BlockChainClient, ChainInfo, Client}; +use crate::client::{BlockChainClient, ChainInfo, Client}; use crypto::publickey::Secret; use snapshot::tests::helpers as snapshot_helpers; use spec::Spec; diff --git a/crates/ethcore/src/snapshot/tests/proof_of_work.rs b/crates/ethcore/src/snapshot/tests/proof_of_work.rs index 6a2dfac58..da7e6fb74 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_work.rs @@ -20,7 +20,7 @@ use error::{Error, ErrorKind}; use std::sync::atomic::AtomicBool; use tempdir::TempDir; -use blockchain::{ +use crate::blockchain::{ generator::{BlockBuilder, BlockGenerator}, BlockChain, ExtrasInsert, }; diff --git a/crates/ethcore/src/snapshot/tests/service.rs b/crates/ethcore/src/snapshot/tests/service.rs index 1a5b41227..72edea761 100644 --- a/crates/ethcore/src/snapshot/tests/service.rs +++ b/crates/ethcore/src/snapshot/tests/service.rs @@ -18,8 +18,8 @@ use std::{fs, sync::Arc}; -use blockchain::BlockProvider; -use client::{BlockInfo, Client, ClientConfig, ImportBlock}; +use crate::blockchain::BlockProvider; +use crate::client::{BlockInfo, Client, ClientConfig, ImportBlock}; use snapshot::{ chunk_secondary, chunk_state, io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, diff --git a/crates/ethcore/src/snapshot/watcher.rs b/crates/ethcore/src/snapshot/watcher.rs index 968d1e08c..b87d0c25a 100644 --- a/crates/ethcore/src/snapshot/watcher.rs +++ b/crates/ethcore/src/snapshot/watcher.rs @@ -16,7 +16,7 @@ //! Watcher for snapshot-related chain events. -use client::{BlockInfo, ChainNotify, Client, ClientIoMessage, NewBlocks}; +use crate::client::{BlockInfo, ChainNotify, Client, ClientIoMessage, NewBlocks}; use parking_lot::Mutex; use types::ids::BlockId; @@ -139,7 +139,7 @@ impl ChainNotify for Watcher { mod tests { use super::{Broadcast, Oracle, Watcher}; - use client::{ChainNotify, ChainRoute, NewBlocks}; + use crate::client::{ChainNotify, ChainRoute, NewBlocks}; use ethereum_types::{BigEndianHash, H256, U256}; diff --git a/crates/ethcore/src/spec/spec.rs b/crates/ethcore/src/spec/spec.rs index 37f86cb7b..1c8e7907a 100644 --- a/crates/ethcore/src/spec/spec.rs +++ b/crates/ethcore/src/spec/spec.rs @@ -35,14 +35,14 @@ use types::{header::Header, BlockNumber}; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; use builtin::Builtin; -use engines::{ +use crate::engines::{ AuthorityRound, BasicAuthority, Clique, EthEngine, HoneyBadgerBFT, InstantSeal, InstantSealParams, NullEngine, DEFAULT_BLOCKHASH_CONTRACT, }; use error::Error; use crate::executive::Executive; use crate::factory::Factories; -use machine::EthereumMachine; +use crate::machine::EthereumMachine; use maplit::btreeset; use pod_state::PodState; use spec::{seal::Generic as GenericSeal, Genesis}; diff --git a/crates/ethcore/src/state/mod.rs b/crates/ethcore/src/state/mod.rs index 85e14538c..ca125a166 100644 --- a/crates/ethcore/src/state/mod.rs +++ b/crates/ethcore/src/state/mod.rs @@ -1578,7 +1578,7 @@ mod tests { use ethereum_types::{Address, BigEndianHash, H256, U256}; use evm::CallType; use hash::{keccak, KECCAK_NULL_RLP}; - use machine::EthereumMachine; + use crate::machine::EthereumMachine; use rustc_hex::FromHex; use spec::*; use std::{str::FromStr, sync::Arc}; diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index 050a9946c..0a2443a4b 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -18,7 +18,7 @@ use std::{fs, io, path::Path, sync::Arc}; -use blockchain::{ +use crate::blockchain::{ BlockChain, BlockChainDB, BlockChainDBHandler, Config as BlockChainConfig, ExtrasInsert, }; use blooms_db; @@ -42,12 +42,12 @@ use types::{ BlockNumber, }; -use block::{Drain, OpenBlock}; -use client::{ +use crate::block::{Drain, OpenBlock}; +use crate::client::{ BlockInfo, ChainInfo, ChainMessageType, ChainNotify, Client, ClientConfig, ImportBlock, PrepareOpenBlock, }; -use engines::{EngineSigner, Seal}; +use crate::engines::{EngineSigner, Seal}; use ethjson::crypto::publickey::{Public, Signature}; use crate::factory::Factories; use miner::Miner; diff --git a/crates/ethcore/src/tests/blockchain.rs b/crates/ethcore/src/tests/blockchain.rs index 86a1475b1..aa5780a79 100644 --- a/crates/ethcore/src/tests/blockchain.rs +++ b/crates/ethcore/src/tests/blockchain.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use blockchain::BlockProvider; +use crate::blockchain::BlockProvider; use test_helpers::{ generate_dummy_blockchain, generate_dummy_blockchain_with_extra, diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index 6f9e9d18c..7c299b448 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -19,7 +19,7 @@ use std::{ sync::Arc, }; -use client::{ +use crate::client::{ traits::{ BlockChainClient, BlockChainReset, BlockInfo, ChainInfo, ImportBlock, ImportExportBlocks, }, @@ -434,7 +434,7 @@ fn does_not_propagate_delayed_transactions() { #[test] fn transaction_proof() { - use client::ProvingBlockChainClient; + use crate::client::ProvingBlockChainClient; let client = generate_dummy_client(0); let address = Address::random(); diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index 7aae884c7..292ea68ca 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -16,8 +16,8 @@ //! Client tests of tracing -use block::*; -use client::{BlockChainClient, Client, ClientConfig, *}; +use crate::block::*; +use crate::client::{BlockChainClient, Client, ClientConfig, *}; use crypto::publickey::KeyPair; use ethereum_types::{Address, U256}; use hash::keccak; diff --git a/crates/ethcore/src/trace/db.rs b/crates/ethcore/src/trace/db.rs index 33ca541f2..fba73e07c 100644 --- a/crates/ethcore/src/trace/db.rs +++ b/crates/ethcore/src/trace/db.rs @@ -17,7 +17,7 @@ //! Trace database. use std::{collections::HashMap, sync::Arc}; -use blockchain::BlockChainDB; +use crate::blockchain::BlockChainDB; use db::{self, cache_manager::CacheManager, CacheUpdatePolicy, Key, Readable, Writable}; use ethereum_types::{H256, H264}; use kvdb::DBTransaction; diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 34f432798..543cfe696 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -24,7 +24,7 @@ use fastmap::{new_h256_fast_lru_map, H256FastLruMap}; use lru_cache::LruCache; use call_contract::CallContract; -use client::{BlockId, BlockInfo}; +use crate::client::{BlockId, BlockInfo}; use hash::KECCAK_EMPTY; use parking_lot::Mutex; use spec::CommonParams; @@ -266,7 +266,7 @@ impl TransactionFilter { // we can cache every transaciton. permission_cache.insert(transaction.hash.clone(), permissions); } else { - trace!(target: "tx_filter", "did not add tx [{}] to permission cache, because block changed in the meantime.", transaction.hash); + trace!(target: "tx_filter", "did not add tx [{}] to permission cache, because crate::block changed in the meantime.", transaction.hash); } } @@ -280,7 +280,7 @@ mod test { use crate::exit::ShutdownManager; use super::TransactionFilter; - use client::{BlockChainClient, BlockId, Client, ClientConfig}; + use crate::client::{BlockChainClient, BlockId, Client, ClientConfig}; use crypto::publickey::{KeyPair, Secret}; use ethereum_types::{Address, U256}; use io::IoChannel; diff --git a/crates/ethcore/src/verification/canon_verifier.rs b/crates/ethcore/src/verification/canon_verifier.rs index a5089356e..8e9dc6cb6 100644 --- a/crates/ethcore/src/verification/canon_verifier.rs +++ b/crates/ethcore/src/verification/canon_verifier.rs @@ -18,8 +18,8 @@ use super::{verification, Verifier}; use call_contract::CallContract; -use client::BlockInfo; -use engines::EthEngine; +use crate::client::BlockInfo; +use crate::engines::EthEngine; use error::Error; use types::header::Header; diff --git a/crates/ethcore/src/verification/mod.rs b/crates/ethcore/src/verification/mod.rs index 3ee8f8503..ab65b062a 100644 --- a/crates/ethcore/src/verification/mod.rs +++ b/crates/ethcore/src/verification/mod.rs @@ -31,7 +31,7 @@ pub use self::{ }; use call_contract::CallContract; -use client::BlockInfo; +use crate::client::BlockInfo; /// Verifier type. #[derive(Debug, PartialEq, Clone)] diff --git a/crates/ethcore/src/verification/noop_verifier.rs b/crates/ethcore/src/verification/noop_verifier.rs index b4e1562ca..6451d7522 100644 --- a/crates/ethcore/src/verification/noop_verifier.rs +++ b/crates/ethcore/src/verification/noop_verifier.rs @@ -18,8 +18,8 @@ use super::{verification, Verifier}; use call_contract::CallContract; -use client::BlockInfo; -use engines::EthEngine; +use crate::client::BlockInfo; +use crate::engines::EthEngine; use error::Error; use types::header::Header; diff --git a/crates/ethcore/src/verification/queue/kind.rs b/crates/ethcore/src/verification/queue/kind.rs index a5b575452..6c2d3e324 100644 --- a/crates/ethcore/src/verification/queue/kind.rs +++ b/crates/ethcore/src/verification/queue/kind.rs @@ -16,7 +16,7 @@ //! Definition of valid items for the verification queue. -use engines::EthEngine; +use crate::engines::EthEngine; use error::Error; use ethereum_types::{H256, U256}; @@ -78,7 +78,7 @@ pub trait Kind: 'static + Sized + Send + Sync { pub mod blocks { use super::{BlockLike, Kind}; - use engines::EthEngine; + use crate::engines::EthEngine; use error::{BlockError, Error, ErrorKind}; use types::{ header::Header, @@ -213,7 +213,7 @@ pub mod blocks { pub mod headers { use super::{BlockLike, Kind}; - use engines::EthEngine; + use crate::engines::EthEngine; use error::Error; use types::header::Header; use verification::verify_header_params; diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index 61f128fcf..07215fa72 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -17,9 +17,9 @@ //! A queue of blocks. Sits between network or other I/O and the `BlockChain`. //! Sorts them ready for blockchain insertion. -use blockchain::BlockChain; -use client::ClientIoMessage; -use engines::EthEngine; +use crate::blockchain::BlockChain; +use crate::client::ClientIoMessage; +use crate::engines::EthEngine; use error::{BlockError, Error, ErrorKind, ImportErrorKind}; use ethereum_types::{H256, U256}; use io::*; diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index b1e7244bb..cdf3ff5e9 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -33,10 +33,10 @@ use rlp::Rlp; use triehash::ordered_trie_root; use unexpected::{Mismatch, OutOfBounds}; -use blockchain::*; +use crate::blockchain::*; use call_contract::CallContract; -use client::BlockInfo; -use engines::{EthEngine, MAX_UNCLE_AGE}; +use crate::client::BlockInfo; +use crate::engines::{EthEngine, MAX_UNCLE_AGE}; use error::{BlockError, Error}; use types::{header::Header, transaction::SignedTransaction, BlockNumber}; use verification::queue::kind::blocks::Unverified; @@ -540,9 +540,9 @@ fn verify_block_integrity(block: &Unverified) -> Result<(), Error> { mod tests { use super::*; - use blockchain::{BlockDetails, BlockReceipts, TransactionAddress}; + use crate::blockchain::{BlockDetails, BlockReceipts, TransactionAddress}; use crypto::publickey::{Generator, Random}; - use engines::EthEngine; + use crate::engines::EthEngine; use error::{BlockError::*, ErrorKind}; use ethereum_types::{Address, BloomRef, H256, U256}; use hash::keccak; @@ -1125,8 +1125,8 @@ mod tests { #[test] fn dust_protection() { use crypto::publickey::{Generator, Random}; - use engines::NullEngine; - use machine::EthereumMachine; + use crate::engines::NullEngine; + use crate::machine::EthereumMachine; use types::transaction::{Action, Transaction}; let mut params = CommonParams::default(); diff --git a/crates/ethcore/src/verification/verifier.rs b/crates/ethcore/src/verification/verifier.rs index c74af43e7..f06495b68 100644 --- a/crates/ethcore/src/verification/verifier.rs +++ b/crates/ethcore/src/verification/verifier.rs @@ -18,8 +18,8 @@ use super::verification; use call_contract::CallContract; -use client::BlockInfo; -use engines::EthEngine; +use crate::client::BlockInfo; +use crate::engines::EthEngine; use error::Error; use types::header::Header; diff --git a/crates/ethcore/sync/src/block_sync.rs b/crates/ethcore/sync/src/block_sync.rs index 7e1a3ccd1..6f366294d 100644 --- a/crates/ethcore/sync/src/block_sync.rs +++ b/crates/ethcore/sync/src/block_sync.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . // use std::backtrace::Backtrace; -use blocks::{BlockCollection, SyncBody, SyncHeader}; +use crate::blocks::{BlockCollection, SyncBody, SyncHeader}; use chain::BlockSet; use ethcore::{ client::{BlockId, BlockStatus}, diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 972a58525..470fb572f 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use api::{ETH_PROTOCOL, PAR_PROTOCOL}; -use block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction}; +use crate::block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction}; use bytes::Bytes; use enum_primitive::FromPrimitive; use ethcore::{ diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index d1fdb82ec..01ea97c81 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -104,7 +104,7 @@ use self::{ }; use super::{SyncConfig, WarpSync}; use api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, ETH_PROTOCOL, PAR_PROTOCOL}; -use block_sync::{BlockDownloader, DownloadAction}; +use crate::block_sync::{BlockDownloader, DownloadAction}; use bytes::Bytes; use derive_more::Display; use ethcore::{ diff --git a/crates/ethcore/sync/src/chain/requester.rs b/crates/ethcore/sync/src/chain/requester.rs index c8037efbd..0d49ed1bb 100644 --- a/crates/ethcore/sync/src/chain/requester.rs +++ b/crates/ethcore/sync/src/chain/requester.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use block_sync::BlockRequest; +use crate::block_sync::BlockRequest; use bytes::Bytes; use ethereum_types::H256; use fastmap::H256FastSet; diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index 7ff77de80..b04ee8bb3 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -511,7 +511,7 @@ impl SyncSupplier { #[cfg(test)] mod test { use super::{super::tests::*, *}; - use blocks::SyncHeader; + use crate::blocks::SyncHeader; use bytes::Bytes; use ethcore::{ client::{BlockChainClient, EachBlockWith, TestBlockChainClient}, diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index d122fa888..8282c2381 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -49,7 +49,7 @@ pub use connection_filter::{ConnectionDirection, ConnectionFilter}; pub use error::{DisconnectReason, Error, ErrorKind}; pub use io::TimerToken; -use client_version::ClientVersion; +use crate::client_version::ClientVersion; use crypto::publickey::Secret; use ethereum_types::{H512, U64}; use ipnetwork::{IpNetwork, IpNetworkError}; diff --git a/crates/util/cli-signer/rpc-client/src/lib.rs b/crates/util/cli-signer/rpc-client/src/lib.rs index 3f4b4d2d6..b22eeed47 100644 --- a/crates/util/cli-signer/rpc-client/src/lib.rs +++ b/crates/util/cli-signer/rpc-client/src/lib.rs @@ -41,7 +41,7 @@ pub type BoxFuture = Box + Send>; #[cfg(test)] mod tests { - use client::{Rpc, RpcError}; + use crate::client::{Rpc, RpcError}; use futures::Future; use rpc; use std::path::PathBuf; diff --git a/crates/util/cli-signer/rpc-client/src/signer_client.rs b/crates/util/cli-signer/rpc-client/src/signer_client.rs index 628394869..00befd375 100644 --- a/crates/util/cli-signer/rpc-client/src/signer_client.rs +++ b/crates/util/cli-signer/rpc-client/src/signer_client.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use client::{Rpc, RpcError}; +use crate::client::{Rpc, RpcError}; use ethereum_types::U256; use futures::Canceled; use rpc::signer::{ConfirmationRequest, TransactionCondition, TransactionModification}; diff --git a/crates/util/cli-signer/src/lib.rs b/crates/util/cli-signer/src/lib.rs index fbd1b62cb..71f060d22 100644 --- a/crates/util/cli-signer/src/lib.rs +++ b/crates/util/cli-signer/src/lib.rs @@ -21,7 +21,7 @@ extern crate rpassword; extern crate parity_rpc as rpc; extern crate parity_rpc_client as client; -use client::signer_client::SignerRpc; +use crate::client::signer_client::SignerRpc; use ethereum_types::U256; use rpc::signer::ConfirmationRequest; use std::{ From 94e07c1c72ac13fbafabca6355fd03881fcb4456 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Apr 2025 22:24:48 +0200 Subject: [PATCH 430/687] batch of rust 2025 changes --- crates/ethcore/src/engines/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/mod.rs b/crates/ethcore/src/engines/mod.rs index 2d257921d..657ff70af 100644 --- a/crates/ethcore/src/engines/mod.rs +++ b/crates/ethcore/src/engines/mod.rs @@ -50,9 +50,9 @@ use std::{ }; use builtin::Builtin; -use error::Error; -use snapshot::SnapshotComponents; -use spec::CommonParams; +use crate::error::Error; +use crate::snapshot::SnapshotComponents; +use crate::spec::CommonParams; use types::{ header::{ExtendedHeader, Header}, transaction::{self, SignedTransaction, UnverifiedTransaction}, @@ -360,7 +360,7 @@ pub trait Engine: Sync + Send { } /// Allow mutating the header during seal generation. Currently only used by Clique. - fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> { + fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), crate::error::Error> { Ok(()) } From 8e8f47f959ca4faaf9188ba2c2d508f8d58a3147 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 23 Apr 2025 11:23:13 +0200 Subject: [PATCH 431/687] batch of rust 2025 changes --- crates/concensus/miner/local-store/src/lib.rs | 2 +- crates/ethcore/service/src/error.rs | 2 +- crates/ethcore/service/src/service.rs | 2 +- crates/ethcore/src/block.rs | 12 ++++++------ crates/ethcore/src/client/bad_blocks.rs | 2 +- crates/ethcore/src/client/client.rs | 14 +++++++------- crates/ethcore/src/client/config.rs | 6 +++--- crates/ethcore/src/client/evm_test_client.rs | 4 ++-- crates/ethcore/src/client/io_message.rs | 2 +- crates/ethcore/src/client/mod.rs | 2 +- crates/ethcore/src/client/test_client.rs | 6 +++--- crates/ethcore/src/client/trace.rs | 2 +- crates/ethcore/src/client/traits.rs | 4 ++-- crates/ethcore/src/engines/authority_round/mod.rs | 4 ++-- .../src/engines/authority_round/randomness.rs | 2 +- crates/ethcore/src/engines/block_reward.rs | 4 ++-- crates/ethcore/src/engines/clique/mod.rs | 2 +- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- .../src/engines/hbbft/test/hbbft_test_client.rs | 2 +- crates/ethcore/src/engines/instant_seal.rs | 2 +- .../ethcore/src/engines/validator_set/contract.rs | 2 +- crates/ethcore/src/engines/validator_set/mod.rs | 2 +- crates/ethcore/src/engines/validator_set/multi.rs | 6 +++--- .../src/engines/validator_set/safe_contract.rs | 4 ++-- crates/ethcore/src/error.rs | 2 +- crates/ethcore/src/ethereum/ethash.rs | 2 +- crates/ethcore/src/executed.rs | 2 +- crates/ethcore/src/executive.rs | 4 ++-- crates/ethcore/src/externalities.rs | 4 ++-- crates/ethcore/src/factory.rs | 2 +- crates/ethcore/src/json_tests/chain.rs | 6 +++--- crates/ethcore/src/json_tests/difficulty.rs | 2 +- crates/ethcore/src/json_tests/executive.rs | 2 +- crates/ethcore/src/json_tests/local.rs | 2 +- crates/ethcore/src/json_tests/state.rs | 2 +- crates/ethcore/src/machine/impls.rs | 4 ++-- crates/ethcore/src/miner/miner.rs | 4 ++-- crates/ethcore/src/snapshot/account.rs | 8 ++++---- crates/ethcore/src/snapshot/consensus/authority.rs | 2 +- crates/ethcore/src/snapshot/consensus/mod.rs | 2 +- crates/ethcore/src/snapshot/consensus/work.rs | 12 ++++++------ crates/ethcore/src/snapshot/io.rs | 2 +- crates/ethcore/src/snapshot/mod.rs | 10 +++++----- crates/ethcore/src/snapshot/service.rs | 12 ++++++------ crates/ethcore/src/snapshot/tests/helpers.rs | 8 ++++---- .../src/snapshot/tests/proof_of_authority.rs | 4 ++-- crates/ethcore/src/snapshot/tests/proof_of_work.rs | 2 +- crates/ethcore/src/snapshot/tests/service.rs | 8 ++++---- crates/ethcore/src/snapshot/tests/state.rs | 4 ++-- crates/ethcore/src/snapshot/watcher.rs | 2 +- crates/ethcore/src/spec/genesis.rs | 2 +- crates/ethcore/src/spec/spec.rs | 4 ++-- crates/ethcore/src/state/account.rs | 2 +- crates/ethcore/src/state/mod.rs | 6 +++--- crates/ethcore/src/test_helpers.rs | 6 +++--- crates/ethcore/src/tests/client.rs | 6 +++--- crates/ethcore/src/tests/evm.rs | 2 +- crates/ethcore/src/tests/trace.rs | 8 ++++---- crates/ethcore/src/trace/db.rs | 4 ++-- crates/ethcore/src/trace/executive_tracer.rs | 2 +- crates/ethcore/src/trace/import.rs | 2 +- crates/ethcore/src/trace/noop_tracer.rs | 2 +- crates/ethcore/src/trace/types/filter.rs | 4 ++-- crates/ethcore/src/trace/types/flat.rs | 2 +- crates/ethcore/src/tx_filter.rs | 6 +++--- crates/ethcore/src/verification/queue/kind.rs | 4 ++-- crates/ethcore/src/verification/queue/mod.rs | 6 +++--- crates/ethcore/src/verification/verification.rs | 4 ++-- crates/ethcore/sync/src/api.rs | 2 +- crates/ethcore/sync/src/chain/handler.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 2 +- crates/ethcore/sync/src/tests/consensus.rs | 2 +- crates/ethcore/sync/src/tests/helpers.rs | 2 +- crates/ethcore/types/src/trace_filter.rs | 2 +- crates/net/network-devp2p/src/handshake.rs | 4 ++-- crates/net/network-devp2p/src/lib.rs | 2 +- crates/net/network-devp2p/src/service.rs | 2 +- crates/net/network-devp2p/tests/tests.rs | 2 +- crates/net/network/src/lib.rs | 2 +- crates/net/node-filter/src/lib.rs | 2 +- crates/rpc/src/v1/tests/eth.rs | 2 +- crates/runtime/io/src/service_non_mio.rs | 4 ++-- 82 files changed, 155 insertions(+), 155 deletions(-) diff --git a/crates/concensus/miner/local-store/src/lib.rs b/crates/concensus/miner/local-store/src/lib.rs index d1aee1065..120c9d570 100644 --- a/crates/concensus/miner/local-store/src/lib.rs +++ b/crates/concensus/miner/local-store/src/lib.rs @@ -19,7 +19,7 @@ use std::{fmt, sync::Arc, time::Duration}; use ethcore_db::KeyValueDB; -use io::IoHandler; +use crate::io::IoHandler; use types::transaction::{ Condition as TransactionCondition, PendingTransaction, SignedTransaction, TypedTransaction, UnverifiedTransaction, diff --git a/crates/ethcore/service/src/error.rs b/crates/ethcore/service/src/error.rs index 1c1840344..21692998b 100644 --- a/crates/ethcore/service/src/error.rs +++ b/crates/ethcore/service/src/error.rs @@ -19,7 +19,7 @@ #![allow(deprecated)] use ethcore; -use io; +use crate::io; error_chain! { foreign_links { diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index 6a7b61566..19a353812 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -19,7 +19,7 @@ use std::{path::Path, sync::Arc, time::Duration}; use ansi_term::Colour; -use io::{IoContext, IoError, IoHandler, IoService, TimerToken}; +use crate::io::{IoContext, IoError, IoHandler, IoService, TimerToken}; use stop_guard::StopGuard; use crate::blockchain::{BlockChainDB, BlockChainDBHandler}; diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index 0568f5c36..45e8decd8 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -41,10 +41,10 @@ use error::{BlockError, Error}; use crate::factory::Factories; use crate::state::State; use state_db::StateDB; -use trace::Tracing; +use crate::trace::Tracing; use triehash::ordered_trie_root; use unexpected::{Mismatch, OutOfBounds}; -use verification::PreverifiedBlock; +use crate::verification::PreverifiedBlock; use vm::{EnvInfo, LastHashes}; use hash::keccak; @@ -635,7 +635,7 @@ mod tests { use std::sync::Arc; use test_helpers::get_temp_state_db; use types::{header::Header, transaction::SignedTransaction, view, views::BlockView}; - use verification::queue::kind::blocks::Unverified; + use crate::verification::queue::kind::blocks::Unverified; use vm::LastHashes; /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header @@ -721,7 +721,7 @@ mod tests { #[test] fn open_block() { - use spec::*; + use crate::spec::*; let spec = Spec::new_test(); let genesis_header = spec.genesis_header(); let db = spec @@ -748,7 +748,7 @@ mod tests { #[test] fn enact_block() { - use spec::*; + use crate::spec::*; let spec = Spec::new_test(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); @@ -809,7 +809,7 @@ mod tests { #[test] fn enact_block_with_uncle() { - use spec::*; + use crate::spec::*; let spec = Spec::new_test(); let engine = &*spec.engine; let genesis_header = spec.genesis_header(); diff --git a/crates/ethcore/src/client/bad_blocks.rs b/crates/ethcore/src/client/bad_blocks.rs index c93852935..2701e2a1d 100644 --- a/crates/ethcore/src/client/bad_blocks.rs +++ b/crates/ethcore/src/client/bad_blocks.rs @@ -22,7 +22,7 @@ use itertools::Itertools; use memory_cache::MemoryLruCache; use parking_lot::RwLock; use types::BlockNumber; -use verification::queue::kind::blocks::Unverified; +use crate::verification::queue::kind::blocks::Unverified; /// Recently seen bad blocks. pub struct BadBlocks { diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 070830473..e31fb92c8 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -84,18 +84,18 @@ use error::{ }; use crate::executive::{contract_address, Executed, Executive, TransactOptions}; use crate::factory::{Factories, VmFactory}; -use io::IoChannel; +use crate::io::IoChannel; use miner::{Miner, MinerService}; -use snapshot::{self, io as snapshot_io, SnapshotClient}; -use spec::Spec; +use crate::snapshot::{self, io as snapshot_io, SnapshotClient}; +use crate::spec::Spec; use crate::state::{self, State}; use state_db::StateDB; use stats::{PrometheusMetrics, PrometheusRegistry}; -use trace::{ +use crate::trace::{ self, Database as TraceDatabase, ImportRequest as TraceImportRequest, LocalizedTrace, TraceDB, }; use crate::transaction_ext::Transaction; -use verification::{ +use crate::verification::{ self, queue::kind::{blocks::Unverified, BlockLike}, BlockQueue, PreverifiedBlock, Verifier, @@ -106,7 +106,7 @@ pub use crate::blockchain::CacheSize as BlockChainCacheSize; use db::{keys::BlockDetails, Readable, Writable}; pub use reth_util::queue::ExecutionQueue; pub use types::{block_status::BlockStatus, blockchain_info::BlockChainInfo}; -pub use verification::QueueInfo as BlockQueueInfo; +pub use crate::verification::QueueInfo as BlockQueueInfo; use crate::exit::ShutdownManager; use_contract!(registry, "res/contracts/registrar.json"); @@ -3787,7 +3787,7 @@ impl PrometheusMetrics for Client { mod tests { use crate::blockchain::{BlockProvider, ExtrasInsert}; use ethereum_types::{H160, H256}; - use spec::Spec; + use crate::spec::Spec; use test_helpers::generate_dummy_client_with_spec_and_data; #[test] diff --git a/crates/ethcore/src/client/config.rs b/crates/ethcore/src/client/config.rs index 6a72f5e27..ea4885b3f 100644 --- a/crates/ethcore/src/client/config.rs +++ b/crates/ethcore/src/client/config.rs @@ -20,13 +20,13 @@ use std::{ }; use journaldb; -use snapshot::SnapshotConfiguration; -use verification::{QueueConfig, VerifierType}; +use crate::snapshot::SnapshotConfiguration; +use crate::verification::{QueueConfig, VerifierType}; pub use crate::blockchain::Config as BlockChainConfig; pub use evm::VMType; pub use std::time::Duration; -pub use trace::Config as TraceConfig; +pub use crate::trace::Config as TraceConfig; /// Client state db compaction profile #[derive(Debug, PartialEq, Clone)] diff --git a/crates/ethcore/src/client/evm_test_client.rs b/crates/ethcore/src/client/evm_test_client.rs index 3de6c2fad..8a44980dc 100644 --- a/crates/ethcore/src/client/evm_test_client.rs +++ b/crates/ethcore/src/client/evm_test_client.rs @@ -26,11 +26,11 @@ use crate::factory::{self, Factories}; use journaldb; use kvdb::{self, KeyValueDB}; use pod_state; -use spec; +use crate::spec; use state; use state_db; use std::{fmt, sync::Arc}; -use trace; +use crate::trace; use trie; use types::{log_entry, receipt, transaction}; use vm::{self, ActionParams}; diff --git a/crates/ethcore/src/client/io_message.rs b/crates/ethcore/src/client/io_message.rs index 7e425d48b..82a633f9b 100644 --- a/crates/ethcore/src/client/io_message.rs +++ b/crates/ethcore/src/client/io_message.rs @@ -17,7 +17,7 @@ use bytes::Bytes; use crate::client::Client; use ethereum_types::H256; -use snapshot::ManifestData; +use crate::snapshot::ManifestData; use std::fmt; /// Message type for external and internal events diff --git a/crates/ethcore/src/client/mod.rs b/crates/ethcore/src/client/mod.rs index b526d0a05..9a18f2217 100644 --- a/crates/ethcore/src/client/mod.rs +++ b/crates/ethcore/src/client/mod.rs @@ -55,7 +55,7 @@ pub use crate::executive::{Executed, Executive, TransactOptions}; pub use vm::{EnvInfo, LastHashes}; pub use error::TransactionImportError; -pub use verification::VerifierType; +pub use crate::verification::VerifierType; pub mod traits; diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index af6c4cdd7..b8a99862d 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -72,12 +72,12 @@ use crate::executed::CallError; use crate::executive::Executed; use journaldb; use miner::{self, Miner, MinerService}; -use spec::Spec; +use crate::spec::Spec; use crate::state::StateInfo; use state_db::StateDB; use stats::{PrometheusMetrics, PrometheusRegistry}; -use trace::LocalizedTrace; -use verification::queue::{kind::blocks::Unverified, QueueInfo}; +use crate::trace::LocalizedTrace; +use crate::verification::queue::{kind::blocks::Unverified, QueueInfo}; use super::ReservedPeersManagement; diff --git a/crates/ethcore/src/client/trace.rs b/crates/ethcore/src/client/trace.rs index 6d60a5cf3..5a0833b8b 100644 --- a/crates/ethcore/src/client/trace.rs +++ b/crates/ethcore/src/client/trace.rs @@ -18,7 +18,7 @@ use crate::blockchain::{BlockChain, BlockProvider, TransactionAddress}; use ethereum_types::H256; -use trace::DatabaseExtras as TraceDatabaseExtras; +use crate::trace::DatabaseExtras as TraceDatabaseExtras; use types::BlockNumber; impl TraceDatabaseExtras for BlockChain { diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 2752ba899..d61406cdc 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -57,8 +57,8 @@ use error::{Error, EthcoreResult}; use crate::executed::CallError; use crate::executive::Executed; use crate::state::StateInfo; -use trace::LocalizedTrace; -use verification::queue::{kind::blocks::Unverified, QueueInfo as BlockQueueInfo}; +use crate::trace::LocalizedTrace; +use crate::verification::queue::{kind::blocks::Unverified, QueueInfo as BlockQueueInfo}; /// State information to be used during client query pub enum StateOrBlock { diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index dfd7d2625..3cb9c05c9 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -68,7 +68,7 @@ use ethereum_types::{Address, H256, H512, H520, U128, U256}; use ethjson::{self, uint::Uint}; use hash::keccak; -use io::{IoContext, IoHandler, IoService, TimerToken}; +use crate::io::{IoContext, IoHandler, IoService, TimerToken}; use itertools::{self, Itertools}; use lru_cache::LruCache; use crate::machine::{AuxiliaryData, Call, EthereumMachine}; @@ -2400,7 +2400,7 @@ mod tests { use hash::keccak; use miner::{Author, MinerService}; use rlp::encode; - use spec::Spec; + use crate::spec::Spec; use std::{ collections::BTreeMap, str::FromStr, diff --git a/crates/ethcore/src/engines/authority_round/randomness.rs b/crates/ethcore/src/engines/authority_round/randomness.rs index fef2d5ad6..2520b0f2b 100644 --- a/crates/ethcore/src/engines/authority_round/randomness.rs +++ b/crates/ethcore/src/engines/authority_round/randomness.rs @@ -213,7 +213,7 @@ impl RandomnessPhase { // Generate a new random number, but don't reveal it yet. Instead, we publish its hash to the // randomness contract, together with the number encrypted to ourselves. That way we will later be // able to decrypt and reveal it, and other parties are able to verify it against the hash. - let number: RandNumber = rng gen(); + let number: RandNumber = rng.r#gen(); let number_hash: Hash = keccak(number.0); let public = signer.public().ok_or(PhaseError::MissingPublicKey)?; let cipher = ecies::encrypt(&public, number_hash.as_bytes(), number.as_bytes())?; diff --git a/crates/ethcore/src/engines/block_reward.rs b/crates/ethcore/src/engines/block_reward.rs index d3792db86..f76ae0d39 100644 --- a/crates/ethcore/src/engines/block_reward.rs +++ b/crates/ethcore/src/engines/block_reward.rs @@ -26,7 +26,7 @@ use error::Error; use hash::keccak; use crate::machine::Machine; use std::sync::Arc; -use trace::{self, ExecutiveTracer, Tracer, Tracing}; +use crate::trace::{self, ExecutiveTracer, Tracer, Tracing}; use types::BlockNumber; use_contract!(block_reward_contract, "res/contracts/block_reward.json"); @@ -197,7 +197,7 @@ pub fn apply_block_rewards( mod test { use crate::client::PrepareOpenBlock; use ethereum_types::{H160, U256}; - use spec::Spec; + use crate::spec::Spec; use test_helpers::generate_dummy_client_with_spec; use super::{BlockRewardContract, RewardKind}; diff --git a/crates/ethcore/src/engines/clique/mod.rs b/crates/ethcore/src/engines/clique/mod.rs index a06b841d8..441f15b69 100644 --- a/crates/ethcore/src/engines/clique/mod.rs +++ b/crates/ethcore/src/engines/clique/mod.rs @@ -223,7 +223,7 @@ impl Clique { /// Note we need to `mock` the miner and it is introduced to test block verification to trigger new blocks /// to mainly test consensus edge cases pub fn with_test(epoch_length: u64, period: u64) -> Self { - use spec::Spec; + use crate::spec::Spec; Self { epoch_length, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 2d66dff33..74ed119eb 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -20,7 +20,7 @@ use error::{BlockError, Error}; use ethereum_types::{Address, Public, H256, H512, U256}; use ethjson::spec::HbbftParams; use hbbft::{NetworkInfo, Target}; -use io::{IoContext, IoHandler, IoService, TimerToken}; +use crate::io::{IoContext, IoHandler, IoService, TimerToken}; use itertools::Itertools; use crate::machine::EthereumMachine; use parking_lot::{Mutex, RwLock}; diff --git a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs index f53025b37..44f320d32 100644 --- a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs +++ b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs @@ -8,7 +8,7 @@ use crate::engines::signer::from_keypair; use ethereum_types::{Address, U256}; use miner::{Miner, MinerService}; use parking_lot::RwLock; -use spec::Spec; +use crate::spec::Spec; use std::{ops::Deref, sync::Arc}; use test_helpers::{generate_dummy_client_with_spec, TestNotify}; use types::{data_format::DataFormat, ids::BlockId}; diff --git a/crates/ethcore/src/engines/instant_seal.rs b/crates/ethcore/src/engines/instant_seal.rs index 98a58007c..4d831a835 100644 --- a/crates/ethcore/src/engines/instant_seal.rs +++ b/crates/ethcore/src/engines/instant_seal.rs @@ -129,7 +129,7 @@ mod tests { use crate::block::*; use crate::engines::Seal; use ethereum_types::{Address, H520}; - use spec::Spec; + use crate::spec::Spec; use std::sync::Arc; use test_helpers::get_temp_state_db; use types::header::Header; diff --git a/crates/ethcore/src/engines/validator_set/contract.rs b/crates/ethcore/src/engines/validator_set/contract.rs index ae76df15b..a9a46b053 100644 --- a/crates/ethcore/src/engines/validator_set/contract.rs +++ b/crates/ethcore/src/engines/validator_set/contract.rs @@ -226,7 +226,7 @@ mod tests { use miner::{self, MinerService}; use rlp::encode; use rustc_hex::FromHex; - use spec::Spec; + use crate::spec::Spec; use std::sync::Arc; use test_helpers::generate_dummy_client_with_spec; use types::{header::Header, ids::BlockId}; diff --git a/crates/ethcore/src/engines/validator_set/mod.rs b/crates/ethcore/src/engines/validator_set/mod.rs index 96c558b4c..fdd6bea7c 100644 --- a/crates/ethcore/src/engines/validator_set/mod.rs +++ b/crates/ethcore/src/engines/validator_set/mod.rs @@ -33,7 +33,7 @@ use types::{header::Header, ids::BlockId, BlockNumber}; use crate::client::EngineClient; -use error::Error as EthcoreError; +use crate::error::Error as EthcoreError; pub use self::simple_list::SimpleList; #[cfg(test)] diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index 51c1e5afb..22bf75d4b 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -25,7 +25,7 @@ use types::{header::Header, ids::BlockId, BlockNumber}; use super::{SystemCall, ValidatorSet}; use crate::client::EngineClient; -use error::Error as EthcoreError; +use crate::error::Error as EthcoreError; use crate::machine::{AuxiliaryData, Call, EthereumMachine}; type BlockNumberLookup = @@ -216,11 +216,11 @@ mod tests { use ethereum_types::Address; use hash::keccak; use miner::{self, MinerService}; - use spec::Spec; + use crate::spec::Spec; use std::{collections::BTreeMap, sync::Arc}; use test_helpers::generate_dummy_client_with_spec; use types::{header::Header, ids::BlockId}; - use verification::queue::kind::blocks::Unverified; + use crate::verification::queue::kind::blocks::Unverified; use super::Multi; diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index eae32f579..1dec1382b 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -724,14 +724,14 @@ mod tests { use hash::keccak; use miner::{self, MinerService}; use rustc_hex::FromHex; - use spec::Spec; + use crate::spec::Spec; use std::sync::Arc; use test_helpers::generate_dummy_client_with_spec; use types::{ ids::BlockId, transaction::{Action, Transaction, TypedTransaction}, }; - use verification::queue::kind::blocks::Unverified; + use crate::verification::queue::kind::blocks::Unverified; #[test] fn fetches_validators() { diff --git a/crates/ethcore/src/error.rs b/crates/ethcore/src/error.rs index 4a5bc0c58..74ca5c933 100644 --- a/crates/ethcore/src/error.rs +++ b/crates/ethcore/src/error.rs @@ -27,7 +27,7 @@ use ethereum_types::{Address, Bloom, H256, U256}; use ethtrie::TrieError; use rlp; use snappy::InvalidInput; -use snapshot::Error as SnapshotError; +use crate::snapshot::Error as SnapshotError; use types::{transaction::Error as TransactionError, BlockNumber}; use unexpected::{Mismatch, OutOfBounds}; diff --git a/crates/ethcore/src/ethereum/ethash.rs b/crates/ethcore/src/ethereum/ethash.rs index 8ecdc591d..81fa1c9da 100644 --- a/crates/ethcore/src/ethereum/ethash.rs +++ b/crates/ethcore/src/ethereum/ethash.rs @@ -568,7 +568,7 @@ mod tests { use error::{BlockError, Error, ErrorKind}; use ethereum_types::{Address, H256, H64, U256}; use rlp; - use spec::Spec; + use crate::spec::Spec; use std::{collections::BTreeMap, str::FromStr, sync::Arc}; use tempdir::TempDir; use test_helpers::get_temp_state_db; diff --git a/crates/ethcore/src/executed.rs b/crates/ethcore/src/executed.rs index 6e609f8e2..a4495999a 100644 --- a/crates/ethcore/src/executed.rs +++ b/crates/ethcore/src/executed.rs @@ -19,7 +19,7 @@ use bytes::Bytes; use ethereum_types::{Address, U256, U512}; use ethtrie; -use trace::{FlatTrace, VMTrace}; +use crate::trace::{FlatTrace, VMTrace}; use types::{log_entry::LogEntry, state_diff::StateDiff}; use vm; diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index b1d18c1c3..37aa4b0aa 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -26,7 +26,7 @@ use hash::keccak; use crate::machine::EthereumMachine as Machine; use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, convert::TryFrom, sync::Arc}; -use trace::{self, Tracer, VMTracer}; +use crate::trace::{self, Tracer, VMTracer}; use crate::transaction_ext::Transaction; use types::transaction::{Action, SignedTransaction, TypedTransaction}; use vm::{ @@ -1636,7 +1636,7 @@ mod tests { use crate::state::{CleanupMode, Substate}; use std::{str::FromStr, sync::Arc}; use test_helpers::{get_temp_state, get_temp_state_with_factory}; - use trace::{ + use crate::trace::{ trace, ExecutiveTracer, ExecutiveVMTracer, FlatTrace, MemoryDiff, NoopTracer, NoopVMTracer, StorageDiff, Tracer, VMExecutedOperation, VMOperation, VMTrace, VMTracer, }; diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index df25010f8..3c8c61aab 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -21,7 +21,7 @@ use crate::executive::*; use crate::machine::EthereumMachine as Machine; use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, sync::Arc}; -use trace::{Tracer, VMTracer}; +use crate::trace::{Tracer, VMTracer}; use types::transaction::UNSIGNED_SENDER; use vm::{ self, AccessList, ActionParams, ActionValue, CallType, ContractCreateResult, @@ -566,7 +566,7 @@ mod tests { use crate::state::{State, Substate}; use std::str::FromStr; use test_helpers::get_temp_state; - use trace::{NoopTracer, NoopVMTracer}; + use crate::trace::{NoopTracer, NoopVMTracer}; fn get_test_origin() -> OriginInfo { OriginInfo { diff --git a/crates/ethcore/src/factory.rs b/crates/ethcore/src/factory.rs index f89bce9ee..de946226c 100644 --- a/crates/ethcore/src/factory.rs +++ b/crates/ethcore/src/factory.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use account_db::Factory as AccountFactory; +use crate::account_db::Factory as AccountFactory; use ethtrie::RlpCodec; use evm::{Factory as EvmFactory, VMType}; use keccak_hasher::KeccakHasher; diff --git a/crates/ethcore/src/json_tests/chain.rs b/crates/ethcore/src/json_tests/chain.rs index 7bbb55c20..83189c8da 100644 --- a/crates/ethcore/src/json_tests/chain.rs +++ b/crates/ethcore/src/json_tests/chain.rs @@ -23,14 +23,14 @@ use crate::client::{ }; use ethereum_types::{H256, U256}; use ethjson; -use io::IoChannel; +use crate::io::IoChannel; use log::warn; use miner::Miner; use rustc_hex::ToHex; -use spec::Genesis; +use crate::spec::Genesis; use std::{path::Path, sync::Arc}; use test_helpers; -use verification::{queue::kind::blocks::Unverified, VerifierType}; +use crate::verification::{queue::kind::blocks::Unverified, VerifierType}; fn check_poststate( client: &Arc, diff --git a/crates/ethcore/src/json_tests/difficulty.rs b/crates/ethcore/src/json_tests/difficulty.rs index 60296e707..39a90499c 100644 --- a/crates/ethcore/src/json_tests/difficulty.rs +++ b/crates/ethcore/src/json_tests/difficulty.rs @@ -16,7 +16,7 @@ use ethereum_types::U256; use ethjson; -use spec::Spec; +use crate::spec::Spec; use std::path::Path; use types::header::Header; diff --git a/crates/ethcore/src/json_tests/executive.rs b/crates/ethcore/src/json_tests/executive.rs index 71761968a..b2ce2808d 100644 --- a/crates/ethcore/src/json_tests/executive.rs +++ b/crates/ethcore/src/json_tests/executive.rs @@ -28,7 +28,7 @@ use rlp::RlpStream; use crate::state::{Backend as StateBackend, State, Substate}; use std::{path::Path, sync::Arc}; use test_helpers::get_temp_state; -use trace::{NoopTracer, NoopVMTracer, Tracer, VMTracer}; +use crate::trace::{NoopTracer, NoopVMTracer, Tracer, VMTracer}; use vm::{ self, ActionParams, CallType, ContractCreateResult, CreateContractAddress, EnvInfo, Ext, MessageCallResult, ReturnData, Schedule, diff --git a/crates/ethcore/src/json_tests/local.rs b/crates/ethcore/src/json_tests/local.rs index bc20d32ae..65268d65f 100644 --- a/crates/ethcore/src/json_tests/local.rs +++ b/crates/ethcore/src/json_tests/local.rs @@ -8,7 +8,7 @@ use types::{ transaction::{TypedTransaction, TypedTxId, UnverifiedTransaction}, BlockNumber, }; -use verification::queue::kind::blocks::Unverified; +use crate::verification::queue::kind::blocks::Unverified; pub fn json_local_block_en_de_test( _test: ðjson::test::LocalTests, diff --git a/crates/ethcore/src/json_tests/state.rs b/crates/ethcore/src/json_tests/state.rs index 4c3f4a212..2fc00deea 100644 --- a/crates/ethcore/src/json_tests/state.rs +++ b/crates/ethcore/src/json_tests/state.rs @@ -19,7 +19,7 @@ use crate::client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess}; use ethjson::{self, spec::ForkSpec}; use pod_state::PodState; use std::path::Path; -use trace; +use crate::trace; use vm::EnvInfo; fn skip_test( diff --git a/crates/ethcore/src/machine/impls.rs b/crates/ethcore/src/machine/impls.rs index 1d92390a2..566abdb65 100644 --- a/crates/ethcore/src/machine/impls.rs +++ b/crates/ethcore/src/machine/impls.rs @@ -42,9 +42,9 @@ use call_contract::CallContract; use crate::client::BlockInfo; use error::Error; use crate::executive::Executive; -use spec::CommonParams; +use crate::spec::CommonParams; use crate::state::{CleanupMode, Substate}; -use trace::{NoopTracer, NoopVMTracer}; +use crate::trace::{NoopTracer, NoopVMTracer}; use tx_filter::TransactionFilter; /// Ethash-specific extensions. diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 456faf3c7..a9a29f554 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -37,7 +37,7 @@ use ethcore_miner::{ service_transaction_checker::ServiceTransactionChecker, }; use ethereum_types::{Address, H256, U256}; -use io::IoChannel; +use crate::io::IoChannel; use itertools::Itertools; use miner::{ self, @@ -66,7 +66,7 @@ use crate::engines::{EngineSigner, EthEngine, Seal, SealingState}; use error::{Error, ErrorKind}; use crate::executed::ExecutionError; use crate::executive::contract_address; -use spec::Spec; +use crate::spec::Spec; use crate::state::State; /// Different possible definitions for pending transaction set. diff --git a/crates/ethcore/src/snapshot/account.rs b/crates/ethcore/src/snapshot/account.rs index 7ce25e72c..dd3b004d1 100644 --- a/crates/ethcore/src/snapshot/account.rs +++ b/crates/ethcore/src/snapshot/account.rs @@ -16,14 +16,14 @@ //! Account state encoding and decoding -use account_db::{AccountDB, AccountDBMut}; +use crate::account_db::{AccountDB, AccountDBMut}; use bytes::Bytes; use ethereum_types::{H256, U256}; use ethtrie::{TrieDB, TrieDBMut}; use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP}; use hash_db::HashDB; use rlp::{Rlp, RlpStream}; -use snapshot::{Error, Progress}; +use crate::snapshot::{Error, Progress}; use std::{collections::HashSet, sync::atomic::Ordering}; use trie::{Trie, TrieMut}; use types::basic_account::BasicAccount; @@ -221,8 +221,8 @@ pub fn from_fat_rlp( #[cfg(test)] mod tests { - use account_db::{AccountDB, AccountDBMut}; - use snapshot::{tests::helpers::fill_storage, Progress}; + use crate::account_db::{AccountDB, AccountDBMut}; + use crate::snapshot::{tests::helpers::fill_storage, Progress}; use test_helpers::get_temp_state_db; use types::basic_account::BasicAccount; diff --git a/crates/ethcore/src/snapshot/consensus/authority.rs b/crates/ethcore/src/snapshot/consensus/authority.rs index 7706ea106..936ce0c2d 100644 --- a/crates/ethcore/src/snapshot/consensus/authority.rs +++ b/crates/ethcore/src/snapshot/consensus/authority.rs @@ -28,7 +28,7 @@ use std::sync::{ use crate::engines::{EpochTransition, EpochVerifier, EthEngine}; use crate::machine::EthereumMachine; -use snapshot::{Error, ManifestData, Progress}; +use crate::snapshot::{Error, ManifestData, Progress}; use crate::blockchain::{BlockChain, BlockChainDB, BlockProvider}; use bytes::Bytes; diff --git a/crates/ethcore/src/snapshot/consensus/mod.rs b/crates/ethcore/src/snapshot/consensus/mod.rs index 546054de5..5b71597ca 100644 --- a/crates/ethcore/src/snapshot/consensus/mod.rs +++ b/crates/ethcore/src/snapshot/consensus/mod.rs @@ -21,7 +21,7 @@ use std::sync::{atomic::AtomicBool, Arc}; use crate::blockchain::{BlockChain, BlockChainDB}; use crate::engines::EthEngine; -use snapshot::{Error, ManifestData, Progress}; +use crate::snapshot::{Error, ManifestData, Progress}; use types::BlockNumber; use ethereum_types::H256; diff --git a/crates/ethcore/src/snapshot/consensus/work.rs b/crates/ethcore/src/snapshot/consensus/work.rs index 948064a36..67b255a14 100644 --- a/crates/ethcore/src/snapshot/consensus/work.rs +++ b/crates/ethcore/src/snapshot/consensus/work.rs @@ -37,7 +37,7 @@ use crate::engines::EthEngine; use ethereum_types::H256; use rand::rngs::OsRng; use rlp::{Rlp, RlpStream}; -use snapshot::{block::AbridgedBlock, Error, ManifestData, Progress}; +use crate::snapshot::{block::AbridgedBlock, Error, ManifestData, Progress}; use types::{encoded, BlockNumber}; /// Snapshot creation and restoration for PoW chains. @@ -88,7 +88,7 @@ impl SnapshotComponents for PowSnapshot { chain: BlockChain, db: Arc, manifest: &ManifestData, - ) -> Result, ::error::Error> { + ) -> Result, crate::error::Error> { PowRebuilder::new( chain, db.key_value().clone(), @@ -99,10 +99,10 @@ impl SnapshotComponents for PowSnapshot { } fn min_supported_version(&self) -> u64 { - ::snapshot::MIN_SUPPORTED_STATE_CHUNK_VERSION + crate::snapshot::MIN_SUPPORTED_STATE_CHUNK_VERSION } fn current_version(&self) -> u64 { - ::snapshot::STATE_CHUNK_VERSION + crate::snapshot::STATE_CHUNK_VERSION } } @@ -267,9 +267,9 @@ impl Rebuilder for PowRebuilder { chunk: &[u8], engine: &dyn EthEngine, abort_flag: &AtomicBool, - ) -> Result<(), ::error::Error> { + ) -> Result<(), crate::error::Error> { use ethereum_types::U256; - use snapshot::verify_old_block; + use crate::snapshot::verify_old_block; use triehash::ordered_trie_root; let rlp = Rlp::new(chunk); diff --git a/crates/ethcore/src/snapshot/io.rs b/crates/ethcore/src/snapshot/io.rs index f1abb60be..b979c5942 100644 --- a/crates/ethcore/src/snapshot/io.rs +++ b/crates/ethcore/src/snapshot/io.rs @@ -340,7 +340,7 @@ mod tests { LooseReader, LooseWriter, PackedReader, PackedWriter, SnapshotReader, SnapshotWriter, SNAPSHOT_VERSION, }; - use snapshot::ManifestData; + use crate::snapshot::ManifestData; const STATE_CHUNKS: &'static [&'static [u8]] = &[b"dog", b"cat", b"hello world", b"hi", b"notarealchunk"]; diff --git a/crates/ethcore/src/snapshot/mod.rs b/crates/ethcore/src/snapshot/mod.rs index 7dcab23b1..de5efb6d4 100644 --- a/crates/ethcore/src/snapshot/mod.rs +++ b/crates/ethcore/src/snapshot/mod.rs @@ -29,7 +29,7 @@ use std::{ }, }; -use account_db::{AccountDB, AccountDBMut}; +use crate::account_db::{AccountDB, AccountDBMut}; use crate::blockchain::{BlockChain, BlockProvider}; use crate::engines::EthEngine; use types::{header::Header, ids::BlockId}; @@ -513,7 +513,7 @@ impl StateRebuilder { /// Finalize the restoration. Check for accounts missing code and make a dummy /// journal entry. /// Once all chunks have been fed, there should be nothing missing. - pub fn finalize(mut self, era: u64, id: H256) -> Result, ::error::Error> { + pub fn finalize(mut self, era: u64, id: H256) -> Result, crate::error::Error> { let missing = self.missing_code.keys().cloned().collect::>(); if !missing.is_empty() { return Err(Error::MissingCode(missing).into()); @@ -548,7 +548,7 @@ fn rebuild_accounts( known_code: &HashMap, known_storage_roots: &mut HashMap, abort_flag: &AtomicBool, -) -> Result { +) -> Result { let mut status = RebuiltStatus::default(); for (account_rlp, out) in account_fat_rlps.into_iter().zip(out_chunk.iter_mut()) { if !abort_flag.load(Ordering::SeqCst) { @@ -616,10 +616,10 @@ pub fn verify_old_block( engine: &dyn EthEngine, chain: &BlockChain, always: bool, -) -> Result<(), ::error::Error> { +) -> Result<(), crate::error::Error> { engine.verify_block_basic(header)?; - if always || rng.gen::() <= POW_VERIFY_RATE { + if always || rng.r#gen::() <= POW_VERIFY_RATE { engine.verify_block_unordered(header)?; match chain.block_header_data(header.parent_hash()) { Some(parent) => engine diff --git a/crates/ethcore/src/snapshot/service.rs b/crates/ethcore/src/snapshot/service.rs index cfd159e77..11e375498 100644 --- a/crates/ethcore/src/snapshot/service.rs +++ b/crates/ethcore/src/snapshot/service.rs @@ -37,12 +37,12 @@ use super::{ use crate::blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler}; use crate::client::{BlockChainClient, BlockInfo, ChainInfo, Client, ClientIoMessage}; use crate::engines::EthEngine; -use error::{Error, ErrorKind as SnapshotErrorKind}; +use crate::error::{Error, ErrorKind as SnapshotErrorKind}; use hash::keccak; -use snapshot::Error as SnapshotError; +use crate::snapshot::Error as SnapshotError; use types::ids::BlockId; -use io::IoChannel; +use crate::io::IoChannel; use bytes::Bytes; use ethereum_types::H256; @@ -1012,10 +1012,10 @@ impl Drop for Service { mod tests { use super::*; use crate::client::ClientIoMessage; - use io::IoService; + use crate::io::IoService; use journaldb::Algorithm; - use snapshot::{ManifestData, RestorationStatus, SnapshotService}; - use spec::Spec; + use crate::snapshot::{ManifestData, RestorationStatus, SnapshotService}; + use crate::spec::Spec; use tempdir::TempDir; use test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler}; diff --git a/crates/ethcore/src/snapshot/tests/helpers.rs b/crates/ethcore/src/snapshot/tests/helpers.rs index bcbbbc1f3..f5236810e 100644 --- a/crates/ethcore/src/snapshot/tests/helpers.rs +++ b/crates/ethcore/src/snapshot/tests/helpers.rs @@ -22,11 +22,11 @@ extern crate trie_standardmap; use hash::KECCAK_NULL_RLP; use std::sync::Arc; -use account_db::AccountDBMut; +use crate::account_db::AccountDBMut; use crate::blockchain::{BlockChain, BlockChainDB}; use crate::client::{ChainInfo, Client}; use crate::engines::EthEngine; -use snapshot::{ +use crate::snapshot::{ io::{PackedReader, PackedWriter, SnapshotReader}, StateRebuilder, }; @@ -71,7 +71,7 @@ impl StateProducer { let temp = trie .iter() .unwrap() // binding required due to complicated lifetime stuff - .filter(|_| rng.gen::() < ACCOUNT_CHURN) + .filter(|_| rng.r#gen::() < ACCOUNT_CHURN) .map(Result::unwrap) .map(|(k, v)| (H256::from_slice(&k), v.to_owned())) .collect(); @@ -96,7 +96,7 @@ impl StateProducer { } // add between 0 and 5 new accounts each tick. - let new_accs = rng.gen::() % 5; + let new_accs = rng.r#gen::() % 5; for _ in 0..new_accs { let address_hash = H256(rng.r#gen()); diff --git a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs index 029d86ba5..89f3e0bd7 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -21,8 +21,8 @@ use std::{cell::RefCell, str::FromStr, sync::Arc}; use accounts::AccountProvider; use crate::client::{BlockChainClient, ChainInfo, Client}; use crypto::publickey::Secret; -use snapshot::tests::helpers as snapshot_helpers; -use spec::Spec; +use crate::snapshot::tests::helpers as snapshot_helpers; +use crate::spec::Spec; use tempdir::TempDir; use test_helpers::generate_dummy_client_with_spec; use types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; diff --git a/crates/ethcore/src/snapshot/tests/proof_of_work.rs b/crates/ethcore/src/snapshot/tests/proof_of_work.rs index da7e6fb74..f4a656796 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_work.rs @@ -24,7 +24,7 @@ use crate::blockchain::{ generator::{BlockBuilder, BlockGenerator}, BlockChain, ExtrasInsert, }; -use snapshot::{ +use crate::snapshot::{ chunk_secondary, io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, Error as SnapshotError, Progress, SnapshotComponents, diff --git a/crates/ethcore/src/snapshot/tests/service.rs b/crates/ethcore/src/snapshot/tests/service.rs index 72edea761..8f3a0bfee 100644 --- a/crates/ethcore/src/snapshot/tests/service.rs +++ b/crates/ethcore/src/snapshot/tests/service.rs @@ -20,23 +20,23 @@ use std::{fs, sync::Arc}; use crate::blockchain::BlockProvider; use crate::client::{BlockInfo, Client, ClientConfig, ImportBlock}; -use snapshot::{ +use crate::snapshot::{ chunk_secondary, chunk_state, io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, service::{Service, ServiceParams}, ManifestData, Progress, RestorationStatus, SnapshotService, }; -use spec::Spec; +use crate::spec::Spec; use tempdir::TempDir; use test_helpers::{ generate_dummy_client_with_spec_and_data, new_db, new_temp_db, restoration_db_handler, }; use types::ids::BlockId; -use io::IoChannel; +use crate::io::IoChannel; use kvdb_rocksdb::DatabaseConfig; use parking_lot::Mutex; -use verification::queue::kind::blocks::Unverified; +use crate::verification::queue::kind::blocks::Unverified; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/snapshot/tests/state.rs b/crates/ethcore/src/snapshot/tests/state.rs index 39eb380c8..185bf0dfa 100644 --- a/crates/ethcore/src/snapshot/tests/state.rs +++ b/crates/ethcore/src/snapshot/tests/state.rs @@ -22,7 +22,7 @@ use hash::{keccak, KECCAK_NULL_RLP}; use std::sync::{atomic::AtomicBool, Arc}; use super::helpers::StateProducer; -use snapshot::{ +use crate::snapshot::{ account, chunk_state, io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, Error as SnapshotError, Progress, StateRebuilder, SNAPSHOT_SUBPARTS, @@ -128,7 +128,7 @@ fn get_code_from_prev_chunk() { use rlp::RlpStream; use std::collections::HashSet; - use account_db::{AccountDB, AccountDBMut}; + use crate::account_db::{AccountDB, AccountDBMut}; let code = b"this is definitely code"; let mut used_code = HashSet::new(); diff --git a/crates/ethcore/src/snapshot/watcher.rs b/crates/ethcore/src/snapshot/watcher.rs index b87d0c25a..8d09a9ef1 100644 --- a/crates/ethcore/src/snapshot/watcher.rs +++ b/crates/ethcore/src/snapshot/watcher.rs @@ -21,7 +21,7 @@ use parking_lot::Mutex; use types::ids::BlockId; use ethereum_types::H256; -use io::IoChannel; +use crate::io::IoChannel; use std::sync::Arc; diff --git a/crates/ethcore/src/spec/genesis.rs b/crates/ethcore/src/spec/genesis.rs index 127ffd531..301cd8fb1 100644 --- a/crates/ethcore/src/spec/genesis.rs +++ b/crates/ethcore/src/spec/genesis.rs @@ -17,7 +17,7 @@ use ethereum_types::{Address, H256, U256}; use ethjson; use hash::KECCAK_NULL_RLP; -use spec::seal::Seal; +use crate::spec::seal::Seal; /// Genesis components. pub struct Genesis { diff --git a/crates/ethcore/src/spec/spec.rs b/crates/ethcore/src/spec/spec.rs index 1c8e7907a..0ad98502a 100644 --- a/crates/ethcore/src/spec/spec.rs +++ b/crates/ethcore/src/spec/spec.rs @@ -45,9 +45,9 @@ use crate::factory::Factories; use crate::machine::EthereumMachine; use maplit::btreeset; use pod_state::PodState; -use spec::{seal::Generic as GenericSeal, Genesis}; +use crate::spec::{seal::Generic as GenericSeal, Genesis}; use crate::state::{backend::Basic as BasicBackend, Backend, State, Substate}; -use trace::{NoopTracer, NoopVMTracer}; +use crate::trace::{NoopTracer, NoopVMTracer}; pub use ethash::OptimizeFor; diff --git a/crates/ethcore/src/state/account.rs b/crates/ethcore/src/state/account.rs index 425c64fca..95273db99 100644 --- a/crates/ethcore/src/state/account.rs +++ b/crates/ethcore/src/state/account.rs @@ -689,7 +689,7 @@ impl fmt::Debug for Account { #[cfg(test)] mod tests { use super::*; - use account_db::*; + use crate::account_db::*; use bytes::Bytes; use ethereum_types::{Address, H256}; use journaldb::new_memory_db; diff --git a/crates/ethcore/src/state/mod.rs b/crates/ethcore/src/state/mod.rs index ca125a166..e46544978 100644 --- a/crates/ethcore/src/state/mod.rs +++ b/crates/ethcore/src/state/mod.rs @@ -203,7 +203,7 @@ pub fn check_proof( ) -> ProvedExecution { let backend = self::backend::ProofCheck::new(proof); let mut factories = Factories::default(); - factories.accountdb = ::account_db::Factory::Plain; + factories.accountdb = crate::account_db::Factory::Plain; let res = State::from_existing( backend, @@ -1580,10 +1580,10 @@ mod tests { use hash::{keccak, KECCAK_NULL_RLP}; use crate::machine::EthereumMachine; use rustc_hex::FromHex; - use spec::*; + use crate::spec::*; use std::{str::FromStr, sync::Arc}; use test_helpers::{get_temp_state, get_temp_state_db}; - use trace::{trace, FlatTrace, TraceError}; + use crate::trace::{trace, FlatTrace, TraceError}; use types::transaction::*; use vm::EnvInfo; diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index 0a2443a4b..2269af7a9 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -28,7 +28,7 @@ use db::KeyValueDB; use ethereum_types::{Address, H256, H512, U256}; use evm::Factory as EvmFactory; use hash::keccak; -use io::IoChannel; +use crate::io::IoChannel; use kvdb_rocksdb::{self, Database, DatabaseConfig}; use parking_lot::RwLock; use rlp::{self, RlpStream}; @@ -51,10 +51,10 @@ use crate::engines::{EngineSigner, Seal}; use ethjson::crypto::publickey::{Public, Signature}; use crate::factory::Factories; use miner::Miner; -use spec::Spec; +use crate::spec::Spec; use crate::state::*; use state_db::StateDB; -use verification::queue::kind::blocks::Unverified; +use crate::verification::queue::kind::blocks::Unverified; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index 7c299b448..c6ee7ae3a 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -30,10 +30,10 @@ use ethereum; use ethereum_types::{Address, U256}; use crate::executive::{Executive, TransactOptions}; use hash::keccak; -use io::IoChannel; +use crate::io::IoChannel; use miner::{Miner, MinerService, PendingOrdering}; use rustc_hex::ToHex; -use spec::Spec; +use crate::spec::Spec; use crate::state::{self, CleanupMode, State, StateInfo}; use tempdir::TempDir; use test_helpers::{ @@ -49,7 +49,7 @@ use types::{ view, views::BlockView, }; -use verification::queue::kind::blocks::Unverified; +use crate::verification::queue::kind::blocks::Unverified; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index 54ac6237a..46953d076 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -22,7 +22,7 @@ use hash::keccak; use crate::state::Substate; use std::sync::Arc; use test_helpers::get_temp_state_with_factory; -use trace::{NoopTracer, NoopVMTracer}; +use crate::trace::{NoopTracer, NoopVMTracer}; use types::transaction::SYSTEM_ADDRESS; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index 292ea68ca..4d562ab6c 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -21,19 +21,19 @@ use crate::client::{BlockChainClient, Client, ClientConfig, *}; use crypto::publickey::KeyPair; use ethereum_types::{Address, U256}; use hash::keccak; -use io::*; +use crate::io::*; use miner::Miner; -use spec::*; +use crate::spec::*; use std::{str::FromStr, sync::Arc}; use test_helpers::{self, get_temp_state_db}; -use trace::{trace::Action::Reward, LocalizedTrace, RewardType}; +use crate::trace::{trace::Action::Reward, LocalizedTrace, RewardType}; use types::{ header::Header, transaction::{Action, Transaction, TypedTransaction}, view, views::BlockView, }; -use verification::queue::kind::blocks::Unverified; +use crate::verification::queue::kind::blocks::Unverified; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/trace/db.rs b/crates/ethcore/src/trace/db.rs index fba73e07c..5ceb56d01 100644 --- a/crates/ethcore/src/trace/db.rs +++ b/crates/ethcore/src/trace/db.rs @@ -25,7 +25,7 @@ use parity_util_mem::MallocSizeOfExt; use parking_lot::RwLock; use types::BlockNumber; -use trace::{ +use crate::trace::{ flat::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}, Config, Database as TraceDatabase, DatabaseExtras, Filter, ImportRequest, LocalizedTrace, }; @@ -411,7 +411,7 @@ mod tests { use kvdb::DBTransaction; use std::{collections::HashMap, sync::Arc}; use test_helpers::new_db; - use trace::{ + use crate::trace::{ flat::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}, trace::{Action, Call, Res}, AddressesFilter, Config, Database as TraceDatabase, DatabaseExtras, Filter, ImportRequest, diff --git a/crates/ethcore/src/trace/executive_tracer.rs b/crates/ethcore/src/trace/executive_tracer.rs index 3cb7f2cd4..190f25e42 100644 --- a/crates/ethcore/src/trace/executive_tracer.rs +++ b/crates/ethcore/src/trace/executive_tracer.rs @@ -19,7 +19,7 @@ use ethereum_types::{Address, U256}; use log::{debug, warn}; use std::cmp::min; -use trace::{ +use crate::trace::{ trace::{ Action, Call, CallResult, Create, CreateResult, MemoryDiff, Res, Reward, RewardType, StorageDiff, Suicide, VMExecutedOperation, VMOperation, VMTrace, diff --git a/crates/ethcore/src/trace/import.rs b/crates/ethcore/src/trace/import.rs index aba9b2b09..6d13ff19a 100644 --- a/crates/ethcore/src/trace/import.rs +++ b/crates/ethcore/src/trace/import.rs @@ -18,7 +18,7 @@ use ethereum_types::H256; use types::BlockNumber; -use trace::FlatBlockTraces; +use crate::trace::FlatBlockTraces; /// Traces import request. pub struct ImportRequest { diff --git a/crates/ethcore/src/trace/noop_tracer.rs b/crates/ethcore/src/trace/noop_tracer.rs index 3944ecef8..64f71bc0f 100644 --- a/crates/ethcore/src/trace/noop_tracer.rs +++ b/crates/ethcore/src/trace/noop_tracer.rs @@ -17,7 +17,7 @@ //! Nonoperative tracer. use ethereum_types::{Address, U256}; -use trace::{ +use crate::trace::{ trace::{RewardType, VMTrace}, FlatTrace, Tracer, VMTracer, }; diff --git a/crates/ethcore/src/trace/types/filter.rs b/crates/ethcore/src/trace/types/filter.rs index fe1bbf291..30b9a9f65 100644 --- a/crates/ethcore/src/trace/types/filter.rs +++ b/crates/ethcore/src/trace/types/filter.rs @@ -19,7 +19,7 @@ use super::trace::{Action, Res}; use ethereum_types::{Address, Bloom, BloomInput}; use std::ops::Range; -use trace::flat::FlatTrace; +use crate::trace::flat::FlatTrace; /// Addresses filter. /// @@ -134,7 +134,7 @@ impl Filter { mod tests { use ethereum_types::{Address, Bloom, BloomInput}; use evm::CallType; - use trace::{ + use crate::trace::{ flat::FlatTrace, trace::{Action, Call, Create, CreateResult, Res, Reward, Suicide}, AddressesFilter, Filter, RewardType, TraceError, diff --git a/crates/ethcore/src/trace/types/flat.rs b/crates/ethcore/src/trace/types/flat.rs index a165e2e91..0c03541ac 100644 --- a/crates/ethcore/src/trace/types/flat.rs +++ b/crates/ethcore/src/trace/types/flat.rs @@ -128,7 +128,7 @@ mod tests { use super::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}; use evm::CallType; use rlp::*; - use trace::{ + use crate::trace::{ trace::{Action, Call, CallResult, Res, Reward, Suicide}, RewardType, }; diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 543cfe696..04bd3d98e 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -27,7 +27,7 @@ use call_contract::CallContract; use crate::client::{BlockId, BlockInfo}; use hash::KECCAK_EMPTY; use parking_lot::Mutex; -use spec::CommonParams; +use crate::spec::CommonParams; use types::{ transaction::{Action, SignedTransaction}, BlockNumber, @@ -283,9 +283,9 @@ mod test { use crate::client::{BlockChainClient, BlockId, Client, ClientConfig}; use crypto::publickey::{KeyPair, Secret}; use ethereum_types::{Address, U256}; - use io::IoChannel; + use crate::io::IoChannel; use miner::Miner; - use spec::Spec; + use crate::spec::Spec; use std::{str::FromStr, sync::Arc}; use tempdir::TempDir; use test_helpers; diff --git a/crates/ethcore/src/verification/queue/kind.rs b/crates/ethcore/src/verification/queue/kind.rs index 6c2d3e324..6ec9b3d0c 100644 --- a/crates/ethcore/src/verification/queue/kind.rs +++ b/crates/ethcore/src/verification/queue/kind.rs @@ -85,7 +85,7 @@ pub mod blocks { transaction::{TypedTransaction, UnverifiedTransaction}, BlockNumber, }; - use verification::{verify_block_basic, verify_block_unordered, PreverifiedBlock}; + use crate::verification::{verify_block_basic, verify_block_unordered, PreverifiedBlock}; use bytes::Bytes; use ethereum_types::{H256, U256}; @@ -216,7 +216,7 @@ pub mod headers { use crate::engines::EthEngine; use error::Error; use types::header::Header; - use verification::verify_header_params; + use crate::verification::verify_header_params; use ethereum_types::{H256, U256}; diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index 07215fa72..d96677bfd 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -22,7 +22,7 @@ use crate::client::ClientIoMessage; use crate::engines::EthEngine; use error::{BlockError, Error, ErrorKind, ImportErrorKind}; use ethereum_types::{H256, U256}; -use io::*; +use crate::io::*; use len_caching_lock::LenCachingMutex; use parity_util_mem::{MallocSizeOf, MallocSizeOfExt}; use parking_lot::{Condvar, Mutex, RwLock}; @@ -873,8 +873,8 @@ mod tests { use super::{kind::blocks::Unverified, BlockQueue, Config, State}; use bytes::Bytes; use error::*; - use io::*; - use spec::Spec; + use crate::io::*; + use crate::spec::Spec; use test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; use types::{view, views::BlockView, BlockNumber}; diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index cdf3ff5e9..9f28cef0b 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -39,7 +39,7 @@ use crate::client::BlockInfo; use crate::engines::{EthEngine, MAX_UNCLE_AGE}; use error::{BlockError, Error}; use types::{header::Header, transaction::SignedTransaction, BlockNumber}; -use verification::queue::kind::blocks::Unverified; +use crate::verification::queue::kind::blocks::Unverified; use time_utils::CheckedSystemTime; @@ -547,7 +547,7 @@ mod tests { use ethereum_types::{Address, BloomRef, H256, U256}; use hash::keccak; use rlp; - use spec::{CommonParams, Spec}; + use crate::spec::{CommonParams, Spec}; use std::{ collections::{BTreeMap, HashMap}, time::{SystemTime, UNIX_EPOCH}, diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 103a00eed..c71ddcdee 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -40,7 +40,7 @@ use ethcore::{ snapshot::SnapshotService, }; use ethereum_types::{H256, H512, U256, U64}; -use io::TimerToken; +use crate::io::TimerToken; use network::IpFilter; use parking_lot::{Mutex, RwLock}; use stats::{PrometheusMetrics, PrometheusRegistry}; diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 470fb572f..afafa0419 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -27,7 +27,7 @@ use ethereum_types::{H256, H512, U256}; use hash::keccak; use network::{client_version::ClientVersion, PeerId}; use rlp::Rlp; -use snapshot::ChunkType; +use crate::snapshot::ChunkType; use std::{cmp, mem, time::Instant}; use sync_io::SyncIo; use types::{block_status::BlockStatus, ids::BlockId, BlockNumber}; diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 01ea97c81..9d62955a3 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -118,7 +118,7 @@ use network::{self, client_version::ClientVersion, PeerId}; use parking_lot::{Mutex, RwLock, RwLockWriteGuard}; use rand::{seq::SliceRandom, Rng}; use rlp::{DecoderError, RlpStream}; -use snapshot::Snapshot; +use crate::snapshot::Snapshot; use stats::PrometheusMetrics; use std::{ cmp, diff --git a/crates/ethcore/sync/src/tests/consensus.rs b/crates/ethcore/sync/src/tests/consensus.rs index c9d441ed1..7c70b7e47 100644 --- a/crates/ethcore/sync/src/tests/consensus.rs +++ b/crates/ethcore/sync/src/tests/consensus.rs @@ -24,7 +24,7 @@ use ethcore::{ }; use ethereum_types::{Address, U256}; use hash::keccak; -use io::{IoChannel, IoHandler}; +use crate::io::{IoChannel, IoHandler}; use std::sync::Arc; use types::transaction::{Action, PendingTransaction, Transaction, TypedTransaction}; use SyncConfig; diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index b4a881a63..aec61a7e5 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -33,7 +33,7 @@ use ethcore::{ }; use ethereum_types::H256; -use io::{IoChannel, IoContext, IoHandler}; +use crate::io::{IoChannel, IoContext, IoHandler}; use network::{self, client_version::ClientVersion, PacketId, PeerId, ProtocolId, SessionInfo}; use parking_lot::RwLock; use std::{ diff --git a/crates/ethcore/types/src/trace_filter.rs b/crates/ethcore/types/src/trace_filter.rs index 66104acb4..eea0d2685 100644 --- a/crates/ethcore/types/src/trace_filter.rs +++ b/crates/ethcore/types/src/trace_filter.rs @@ -20,7 +20,7 @@ use crate::ids::BlockId; use ethereum_types::Address; use std::ops::Range; -/// Easy to use trace filter. +/// Easy to use crate::trace filter. pub struct Filter { /// Range of filtering. pub range: Range, diff --git a/crates/net/network-devp2p/src/handshake.rs b/crates/net/network-devp2p/src/handshake.rs index da3e83ac7..2cb0d58b4 100644 --- a/crates/net/network-devp2p/src/handshake.rs +++ b/crates/net/network-devp2p/src/handshake.rs @@ -18,7 +18,7 @@ use crate::connection::Connection; use crypto::publickey::{ecdh, ecies, recover, sign, Generator, KeyPair, Public, Random, Secret}; use ethereum_types::{H256, H520}; use crate::host::HostInfo; -use io::{IoContext, StreamToken}; +use crate::io::{IoContext, StreamToken}; use mio::tcp::*; use network::{Error, ErrorKind}; use crate::node_table::NodeId; @@ -383,7 +383,7 @@ mod test { use super::*; use crypto::publickey::Public; use ethereum_types::{H256, H512}; - use io::*; + use crate::io::*; use mio::tcp::TcpStream; use rustc_hex::FromHex; use std::str::FromStr; diff --git a/crates/net/network-devp2p/src/lib.rs b/crates/net/network-devp2p/src/lib.rs index 0072efc7b..e887b0361 100644 --- a/crates/net/network-devp2p/src/lib.rs +++ b/crates/net/network-devp2p/src/lib.rs @@ -117,7 +117,7 @@ pub use service::NetworkService; pub use connection::PAYLOAD_SOFT_LIMIT; -pub use io::TimerToken; +pub use crate::io::TimerToken; pub use node_table::{validate_node_url, NodeId}; const PROTOCOL_VERSION: u32 = 5; diff --git a/crates/net/network-devp2p/src/service.rs b/crates/net/network-devp2p/src/service.rs index 16bcc8d53..42c129b0f 100644 --- a/crates/net/network-devp2p/src/service.rs +++ b/crates/net/network-devp2p/src/service.rs @@ -16,7 +16,7 @@ use ansi_term::Colour; -use io::*; +use crate::io::*; use crate::network::{ diff --git a/crates/net/network-devp2p/tests/tests.rs b/crates/net/network-devp2p/tests/tests.rs index ea501ad31..a67b69ee3 100644 --- a/crates/net/network-devp2p/tests/tests.rs +++ b/crates/net/network-devp2p/tests/tests.rs @@ -27,7 +27,7 @@ use crypto::publickey::{Generator, Random}; use ethcore_network::*; use ethcore_network_devp2p::NetworkService; use ethereum_types::U64; -use io::TimerToken; +use crate::io::TimerToken; use parity_bytes::Bytes; use parking_lot::Mutex; use std::{ diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index 8282c2381..307747f71 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -47,7 +47,7 @@ mod error; pub use connection_filter::{ConnectionDirection, ConnectionFilter}; pub use error::{DisconnectReason, Error, ErrorKind}; -pub use io::TimerToken; +pub use crate::io::TimerToken; use crate::client_version::ClientVersion; use crypto::publickey::Secret; diff --git a/crates/net/node-filter/src/lib.rs b/crates/net/node-filter/src/lib.rs index d59f0ed6f..531f4a919 100644 --- a/crates/net/node-filter/src/lib.rs +++ b/crates/net/node-filter/src/lib.rs @@ -105,7 +105,7 @@ mod test { test_helpers, }; use ethereum_types::Address; - use io::IoChannel; + use crate::io::IoChannel; use network::{ConnectionDirection, ConnectionFilter, NodeId}; use std::{ str::FromStr, diff --git a/crates/rpc/src/v1/tests/eth.rs b/crates/rpc/src/v1/tests/eth.rs index 5fcc02f44..7c2b4e9fd 100644 --- a/crates/rpc/src/v1/tests/eth.rs +++ b/crates/rpc/src/v1/tests/eth.rs @@ -28,7 +28,7 @@ use ethcore::{ }; use ethereum_types::{Address, H256, U256}; use ethjson::{blockchain::BlockChain, spec::ForkSpec}; -use io::IoChannel; +use crate::io::IoChannel; use miner::external::ExternalMiner; use parity_runtime::Runtime; use parking_lot::Mutex; diff --git a/crates/runtime/io/src/service_non_mio.rs b/crates/runtime/io/src/service_non_mio.rs index 4d7651a5d..a6cb599ad 100644 --- a/crates/runtime/io/src/service_non_mio.rs +++ b/crates/runtime/io/src/service_non_mio.rs @@ -26,8 +26,8 @@ use std::{ }; use time::Duration as TimeDuration; use timer::{Guard as TimerGuard, Timer}; -use IoError; -use IoHandler; +use crate::ioError; +use crate::ioHandler; /// Timer ID pub type TimerToken = usize; From e50522b1b950ba136307005943ece9f2ec1e09c3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 23 Apr 2025 12:03:39 +0200 Subject: [PATCH 432/687] batch of rust 2025 changes --- bin/evmbin/src/info.rs | 2 +- crates/concensus/miner/local-store/src/lib.rs | 4 +- crates/concensus/miner/src/pool/client.rs | 2 +- crates/concensus/miner/src/pool/listener.rs | 2 +- .../miner/src/pool/local_transactions.rs | 2 +- crates/concensus/miner/src/pool/mod.rs | 2 +- crates/concensus/miner/src/pool/queue.rs | 2 +- crates/concensus/miner/src/pool/ready.rs | 2 +- .../concensus/miner/src/pool/tests/client.rs | 2 +- crates/concensus/miner/src/pool/tests/mod.rs | 2 +- crates/concensus/miner/src/pool/tests/tx.rs | 2 +- .../miner/src/pool/transaction_filter.rs | 2 +- crates/concensus/miner/src/pool/verifier.rs | 2 +- .../miner/src/service_transaction_checker.rs | 2 +- crates/ethcore/src/block.rs | 8 ++-- crates/ethcore/src/client/ancient_import.rs | 6 +-- crates/ethcore/src/client/bad_blocks.rs | 2 +- crates/ethcore/src/client/chain_notify.rs | 2 +- crates/ethcore/src/client/client.rs | 39 +++++++++---------- crates/ethcore/src/client/evm_test_client.rs | 4 +- crates/ethcore/src/client/mod.rs | 4 +- crates/ethcore/src/client/test_client.rs | 6 +-- crates/ethcore/src/client/trace.rs | 2 +- crates/ethcore/src/client/traits.rs | 4 +- .../authority_round/block_gas_limit.rs | 2 +- .../src/engines/authority_round/finality.rs | 4 +- .../src/engines/authority_round/mod.rs | 14 +++---- .../src/engines/authority_round/util.rs | 2 +- crates/ethcore/src/engines/basic_authority.rs | 4 +- crates/ethcore/src/engines/block_reward.rs | 4 +- .../ethcore/src/engines/clique/block_state.rs | 4 +- crates/ethcore/src/engines/clique/mod.rs | 4 +- crates/ethcore/src/engines/clique/util.rs | 4 +- .../src/engines/hbbft/block_reward_hbbft.rs | 2 +- .../contracts/connectivity_tracker_hbbft.rs | 2 +- .../engines/hbbft/contracts/keygen_history.rs | 2 +- .../src/engines/hbbft/contracts/permission.rs | 2 +- .../src/engines/hbbft/contracts/staking.rs | 2 +- .../engines/hbbft/contracts/validator_set.rs | 2 +- .../ethcore/src/engines/hbbft/contribution.rs | 4 +- .../hbbft/hbbft_early_epoch_end_manager.rs | 2 +- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 6 +-- .../src/engines/hbbft/hbbft_engine_cache.rs | 2 +- .../ethcore/src/engines/hbbft/hbbft_state.rs | 2 +- .../src/engines/hbbft/keygen_transactions.rs | 2 +- .../engines/hbbft/test/create_transactions.rs | 2 +- .../engines/hbbft/test/hbbft_test_client.rs | 2 +- crates/ethcore/src/engines/hbbft/test/mod.rs | 2 +- .../src/engines/hbbft/utils/bound_contract.rs | 2 +- .../hbbft/utils/transactions_shuffling.rs | 2 +- crates/ethcore/src/engines/instant_seal.rs | 4 +- crates/ethcore/src/engines/mod.rs | 14 +++---- crates/ethcore/src/engines/null_engine.rs | 2 +- .../src/engines/validator_set/contract.rs | 10 ++--- .../ethcore/src/engines/validator_set/mod.rs | 6 +-- .../src/engines/validator_set/multi.rs | 6 +-- .../engines/validator_set/safe_contract.rs | 22 +++++------ .../src/engines/validator_set/simple_list.rs | 6 +-- .../ethcore/src/engines/validator_set/test.rs | 4 +- crates/ethcore/src/error.rs | 2 +- crates/ethcore/src/ethereum/ethash.rs | 8 ++-- crates/ethcore/src/ethereum/mod.rs | 2 +- crates/ethcore/src/executed.rs | 2 +- crates/ethcore/src/executive.rs | 4 +- crates/ethcore/src/externalities.rs | 4 +- crates/ethcore/src/json_tests/difficulty.rs | 2 +- crates/ethcore/src/json_tests/local.rs | 2 +- crates/ethcore/src/json_tests/transaction.rs | 2 +- crates/ethcore/src/machine/impls.rs | 8 ++-- crates/ethcore/src/miner/miner.rs | 14 +++---- crates/ethcore/src/miner/mod.rs | 4 +- crates/ethcore/src/miner/pool_client.rs | 4 +- crates/ethcore/src/miner/stratum.rs | 2 +- crates/ethcore/src/pod_account.rs | 4 +- crates/ethcore/src/pod_state.rs | 4 +- crates/ethcore/src/snapshot/account.rs | 4 +- crates/ethcore/src/snapshot/block.rs | 4 +- .../src/snapshot/consensus/authority.rs | 12 +++--- crates/ethcore/src/snapshot/consensus/mod.rs | 8 ++-- crates/ethcore/src/snapshot/consensus/work.rs | 8 ++-- crates/ethcore/src/snapshot/error.rs | 2 +- crates/ethcore/src/snapshot/io.rs | 6 +-- crates/ethcore/src/snapshot/mod.rs | 6 +-- crates/ethcore/src/snapshot/service.rs | 12 +++--- crates/ethcore/src/snapshot/tests/helpers.rs | 6 +-- .../src/snapshot/tests/proof_of_authority.rs | 2 +- crates/ethcore/src/snapshot/tests/service.rs | 2 +- crates/ethcore/src/snapshot/tests/state.rs | 2 +- crates/ethcore/src/snapshot/watcher.rs | 2 +- crates/ethcore/src/spec/spec.rs | 14 +++---- crates/ethcore/src/state/account.rs | 2 +- crates/ethcore/src/state/mod.rs | 4 +- crates/ethcore/src/state/substate.rs | 4 +- crates/ethcore/src/state_db.rs | 2 +- crates/ethcore/src/test_helpers.rs | 2 +- crates/ethcore/src/tests/client.rs | 2 +- crates/ethcore/src/tests/evm.rs | 2 +- crates/ethcore/src/tests/trace.rs | 2 +- crates/ethcore/src/trace/db.rs | 4 +- crates/ethcore/src/trace/import.rs | 2 +- crates/ethcore/src/trace/mod.rs | 2 +- crates/ethcore/src/trace/types/localized.rs | 2 +- crates/ethcore/src/transaction_ext.rs | 2 +- crates/ethcore/src/tx_filter.rs | 4 +- .../src/verification/canon_verifier.rs | 4 +- .../ethcore/src/verification/noop_verifier.rs | 4 +- crates/ethcore/src/verification/queue/kind.rs | 10 ++--- crates/ethcore/src/verification/queue/mod.rs | 8 ++-- .../ethcore/src/verification/verification.rs | 8 ++-- crates/ethcore/src/verification/verifier.rs | 4 +- crates/ethcore/sync/src/api.rs | 2 +- crates/ethcore/sync/src/block_sync.rs | 4 +- crates/ethcore/sync/src/blocks.rs | 4 +- crates/ethcore/sync/src/chain/handler.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 4 +- crates/ethcore/sync/src/chain/propagator.rs | 4 +- crates/ethcore/sync/src/chain/requester.rs | 2 +- crates/ethcore/sync/src/chain/supplier.rs | 2 +- crates/ethcore/sync/src/sync_io.rs | 2 +- crates/ethcore/sync/src/tests/consensus.rs | 2 +- crates/ethcore/sync/src/tests/helpers.rs | 2 +- crates/ethcore/sync/src/tests/snapshot.rs | 2 +- crates/ethcore/sync/src/transactions_stats.rs | 2 +- crates/ethcore/types/src/views/block.rs | 2 +- crates/ethcore/types/src/views/body.rs | 2 +- crates/ethcore/types/src/views/header.rs | 2 +- crates/net/network-devp2p/src/lib.rs | 2 +- crates/rpc-common/src/lib.rs | 2 +- crates/rpc/src/v1/helpers/dispatch/full.rs | 2 +- crates/rpc/src/v1/helpers/dispatch/mod.rs | 2 +- .../v1/helpers/dispatch/prospective_signer.rs | 2 +- crates/rpc/src/v1/helpers/dispatch/signing.rs | 2 +- crates/rpc/src/v1/helpers/errors.rs | 2 +- crates/rpc/src/v1/helpers/fake_sign.rs | 2 +- crates/rpc/src/v1/helpers/poll_filter.rs | 2 +- crates/rpc/src/v1/impls/debug.rs | 2 +- crates/rpc/src/v1/impls/eth.rs | 4 +- crates/rpc/src/v1/impls/eth_filter.rs | 2 +- crates/rpc/src/v1/impls/eth_pubsub.rs | 2 +- crates/rpc/src/v1/impls/parity.rs | 2 +- crates/rpc/src/v1/impls/personal.rs | 2 +- crates/rpc/src/v1/impls/signer.rs | 2 +- crates/rpc/src/v1/impls/traces.rs | 2 +- crates/rpc/src/v1/tests/eth.rs | 2 +- .../rpc/src/v1/tests/helpers/miner_service.rs | 2 +- crates/rpc/src/v1/tests/mocked/eth.rs | 4 +- crates/rpc/src/v1/tests/mocked/eth_pubsub.rs | 2 +- crates/rpc/src/v1/tests/mocked/parity.rs | 6 +-- crates/rpc/src/v1/tests/mocked/parity_set.rs | 2 +- crates/rpc/src/v1/tests/mocked/personal.rs | 2 +- crates/rpc/src/v1/tests/mocked/signer.rs | 2 +- crates/rpc/src/v1/tests/mocked/signing.rs | 2 +- .../rpc/src/v1/tests/mocked/signing_unsafe.rs | 2 +- crates/rpc/src/v1/types/block.rs | 2 +- crates/rpc/src/v1/types/filter.rs | 4 +- crates/rpc/src/v1/types/log.rs | 2 +- crates/rpc/src/v1/types/receipt.rs | 4 +- crates/rpc/src/v1/types/trace.rs | 2 +- crates/rpc/src/v1/types/transaction.rs | 4 +- .../src/v1/types/transaction_access_list.rs | 2 +- .../rpc/src/v1/types/transaction_condition.rs | 2 +- 161 files changed, 309 insertions(+), 310 deletions(-) diff --git a/bin/evmbin/src/info.rs b/bin/evmbin/src/info.rs index 8dde90261..f34086f22 100644 --- a/bin/evmbin/src/info.rs +++ b/bin/evmbin/src/info.rs @@ -23,7 +23,7 @@ use ethcore::{ use ethereum_types::{H256, U256}; use ethjson; use std::time::{Duration, Instant}; -use types::transaction; +use crate::types::transaction; use vm::ActionParams; /// VM execution informant diff --git a/crates/concensus/miner/local-store/src/lib.rs b/crates/concensus/miner/local-store/src/lib.rs index 120c9d570..803d33726 100644 --- a/crates/concensus/miner/local-store/src/lib.rs +++ b/crates/concensus/miner/local-store/src/lib.rs @@ -20,7 +20,7 @@ use std::{fmt, sync::Arc, time::Duration}; use ethcore_db::KeyValueDB; use crate::io::IoHandler; -use types::transaction::{ +use crate::types::transaction::{ Condition as TransactionCondition, PendingTransaction, SignedTransaction, TypedTransaction, UnverifiedTransaction, }; @@ -241,7 +241,7 @@ mod tests { use ethkey::Brain; use std::sync::Arc; - use types::transaction::{Condition, PendingTransaction, Transaction, TypedTransaction}; + use crate::types::transaction::{Condition, PendingTransaction, Transaction, TypedTransaction}; // we want to test: round-trip of good transactions. // failure to roundtrip bad transactions (but that it doesn't panic) diff --git a/crates/concensus/miner/src/pool/client.rs b/crates/concensus/miner/src/pool/client.rs index c85f17f74..8d59ec1b1 100644 --- a/crates/concensus/miner/src/pool/client.rs +++ b/crates/concensus/miner/src/pool/client.rs @@ -23,7 +23,7 @@ use std::fmt; use ethereum_types::{H160 as Address, H256, U256}; -use types::transaction; +use crate::types::transaction; /// Account Details #[derive(Debug, Clone)] diff --git a/crates/concensus/miner/src/pool/listener.rs b/crates/concensus/miner/src/pool/listener.rs index 3f27e6a6b..cd34e47b5 100644 --- a/crates/concensus/miner/src/pool/listener.rs +++ b/crates/concensus/miner/src/pool/listener.rs @@ -127,7 +127,7 @@ mod tests { use ethereum_types::H160; use parking_lot::Mutex; use txpool::Listener; - use types::transaction; + use crate::types::transaction; #[test] fn should_notify_listeners() { diff --git a/crates/concensus/miner/src/pool/local_transactions.rs b/crates/concensus/miner/src/pool/local_transactions.rs index 5c52972d3..de69c5f4a 100644 --- a/crates/concensus/miner/src/pool/local_transactions.rs +++ b/crates/concensus/miner/src/pool/local_transactions.rs @@ -257,7 +257,7 @@ mod tests { use crypto::publickey::{Generator, Random}; use ethereum_types::U256; use txpool::Listener; - use types::transaction; + use crate::types::transaction; use crate::pool; diff --git a/crates/concensus/miner/src/pool/mod.rs b/crates/concensus/miner/src/pool/mod.rs index 4818aa59d..77e4fbfd7 100644 --- a/crates/concensus/miner/src/pool/mod.rs +++ b/crates/concensus/miner/src/pool/mod.rs @@ -19,7 +19,7 @@ use ethereum_types::{Address, H256, U256}; use parity_util_mem::MallocSizeOfExt; use txpool; -use types::transaction; +use crate::types::transaction; mod listener; mod queue; diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index 5651e0a8a..ba3ce8ba1 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -30,7 +30,7 @@ use self::scoring::ScoringEvent; use ethereum_types::{Address, H256, U256}; use parking_lot::RwLock; use txpool::{self, Verifier}; -use types::transaction; +use crate::types::transaction; use crate::pool::{ self, client, listener, diff --git a/crates/concensus/miner/src/pool/ready.rs b/crates/concensus/miner/src/pool/ready.rs index 86c3775f9..53b3e3f5f 100644 --- a/crates/concensus/miner/src/pool/ready.rs +++ b/crates/concensus/miner/src/pool/ready.rs @@ -42,7 +42,7 @@ use std::{cmp, collections::HashMap}; use ethereum_types::{H160 as Address, U256}; use txpool::{self, VerifiedTransaction as PoolVerifiedTransaction}; -use types::transaction; +use crate::types::transaction; use super::{client::NonceClient, VerifiedTransaction}; diff --git a/crates/concensus/miner/src/pool/tests/client.rs b/crates/concensus/miner/src/pool/tests/client.rs index e11adc4c4..fc8e8bb38 100644 --- a/crates/concensus/miner/src/pool/tests/client.rs +++ b/crates/concensus/miner/src/pool/tests/client.rs @@ -18,7 +18,7 @@ use std::sync::{atomic, Arc}; use ethereum_types::{Address, H256, U256}; use rlp::Rlp; -use types::transaction::{ +use crate::types::transaction::{ self, SignedTransaction, Transaction, TypedTransaction, UnverifiedTransaction, }; diff --git a/crates/concensus/miner/src/pool/tests/mod.rs b/crates/concensus/miner/src/pool/tests/mod.rs index a0ca385c5..a3fa41311 100644 --- a/crates/concensus/miner/src/pool/tests/mod.rs +++ b/crates/concensus/miner/src/pool/tests/mod.rs @@ -17,7 +17,7 @@ use ethereum_types::U256; use hash::KECCAK_EMPTY; use txpool; -use types::transaction::{self, PendingTransaction}; +use crate::types::transaction::{self, PendingTransaction}; use crate::pool::{ transaction_filter::TransactionFilter, verifier, PendingOrdering, PendingSettings, diff --git a/crates/concensus/miner/src/pool/tests/tx.rs b/crates/concensus/miner/src/pool/tests/tx.rs index fb17fd60b..a84b8e68c 100644 --- a/crates/concensus/miner/src/pool/tests/tx.rs +++ b/crates/concensus/miner/src/pool/tests/tx.rs @@ -17,7 +17,7 @@ use crypto::publickey::{Generator, Random}; use ethereum_types::{H256, U256}; use rustc_hex::FromHex; -use types::transaction::{ +use crate::types::transaction::{ self, AccessListTx, EIP1559TransactionTx, SignedTransaction, Transaction, TypedTransaction, UnverifiedTransaction, }; diff --git a/crates/concensus/miner/src/pool/transaction_filter.rs b/crates/concensus/miner/src/pool/transaction_filter.rs index 18ab966df..92a9d538f 100644 --- a/crates/concensus/miner/src/pool/transaction_filter.rs +++ b/crates/concensus/miner/src/pool/transaction_filter.rs @@ -21,7 +21,7 @@ use ethereum_types::{Address, U256}; use crate::pool::VerifiedTransaction; -use types::transaction::Action; +use crate::types::transaction::Action; #[allow(non_camel_case_types)] #[derive(Debug, Deserialize, Serialize)] diff --git a/crates/concensus/miner/src/pool/verifier.rs b/crates/concensus/miner/src/pool/verifier.rs index db56de9a3..cd74d2bb9 100644 --- a/crates/concensus/miner/src/pool/verifier.rs +++ b/crates/concensus/miner/src/pool/verifier.rs @@ -33,7 +33,7 @@ use std::{ use ethereum_types::{H256, U256}; use hash::KECCAK_EMPTY; use txpool; -use types::transaction; +use crate::types::transaction; use super::{ client::{Client, TransactionType}, diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index f8420c9f8..4f1721183 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -21,7 +21,7 @@ use ethabi::FunctionOutputDecoder; use ethereum_types::Address; use parking_lot::RwLock; use std::{collections::HashMap, mem, str::FromStr, sync::Arc}; -use types::{ids::BlockId, transaction::SignedTransaction}; +use crate::types::{ids::BlockId, transaction::SignedTransaction}; use_contract!( service_transaction, diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index 45e8decd8..f2668acd7 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -37,10 +37,10 @@ use bytes::Bytes; use ethereum_types::{Address, Bloom, H256, U256}; use crate::engines::EthEngine; -use error::{BlockError, Error}; +use crate::error::{BlockError, Error}; use crate::factory::Factories; use crate::state::State; -use state_db::StateDB; +use crate::state_db::StateDB; use crate::trace::Tracing; use triehash::ordered_trie_root; use unexpected::{Mismatch, OutOfBounds}; @@ -49,7 +49,7 @@ use vm::{EnvInfo, LastHashes}; use hash::keccak; use rlp::{encode_list, RlpStream}; -use types::{ +use crate::types::{ header::{ExtendedHeader, Header}, receipt::{TransactionOutcome, TypedReceipt}, transaction::{Error as TransactionError, SignedTransaction}, @@ -634,7 +634,7 @@ mod tests { use state_db::StateDB; use std::sync::Arc; use test_helpers::get_temp_state_db; - use types::{header::Header, transaction::SignedTransaction, view, views::BlockView}; + use crate::types::{header::Header, transaction::SignedTransaction, view, views::BlockView}; use crate::verification::queue::kind::blocks::Unverified; use vm::LastHashes; diff --git a/crates/ethcore/src/client/ancient_import.rs b/crates/ethcore/src/client/ancient_import.rs index 04a864070..fae039be9 100644 --- a/crates/ethcore/src/client/ancient_import.rs +++ b/crates/ethcore/src/client/ancient_import.rs @@ -24,7 +24,7 @@ use crate::machine::EthereumMachine; use crate::blockchain::BlockChain; use parking_lot::RwLock; use rand::Rng; -use types::header::Header; +use crate::types::header::Header; // do "heavy" verification on ~1/50 blocks, randomly sampled. const HEAVY_VERIFY_RATE: f32 = 0.02; @@ -52,7 +52,7 @@ impl AncientVerifier { rng: &mut R, header: &Header, chain: &BlockChain, - ) -> Result<(), ::error::Error> { + ) -> Result<(), crate::error::Error> { // perform verification let verified = if let Some(ref cur_verifier) = *self.cur_verifier.read() { match rng.r#gen::() <= HEAVY_VERIFY_RATE { @@ -93,7 +93,7 @@ impl AncientVerifier { &self, header: &Header, chain: &BlockChain, - ) -> Result>, ::error::Error> { + ) -> Result>, crate::error::Error> { trace!(target: "client", "Initializing ancient block restoration."); let current_epoch_data = chain .epoch_transitions() diff --git a/crates/ethcore/src/client/bad_blocks.rs b/crates/ethcore/src/client/bad_blocks.rs index 2701e2a1d..25cd47108 100644 --- a/crates/ethcore/src/client/bad_blocks.rs +++ b/crates/ethcore/src/client/bad_blocks.rs @@ -21,7 +21,7 @@ use ethereum_types::H256; use itertools::Itertools; use memory_cache::MemoryLruCache; use parking_lot::RwLock; -use types::BlockNumber; +use crate::types::BlockNumber; use crate::verification::queue::kind::blocks::Unverified; /// Recently seen bad blocks. diff --git a/crates/ethcore/src/client/chain_notify.rs b/crates/ethcore/src/client/chain_notify.rs index 0aa901025..513964d3c 100644 --- a/crates/ethcore/src/client/chain_notify.rs +++ b/crates/ethcore/src/client/chain_notify.rs @@ -18,7 +18,7 @@ use crate::blockchain::ImportRoute; use bytes::Bytes; use ethereum_types::{H256, H512, U256}; use std::{collections::HashMap, time::Duration}; -use types::transaction::UnverifiedTransaction; +use crate::types::transaction::UnverifiedTransaction; /// Messages to broadcast via chain pub enum ChainMessageType { diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index e31fb92c8..a986f967c 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -43,7 +43,7 @@ use rand::rngs::OsRng; use rlp::{PayloadInfo, Rlp}; use rustc_hex::FromHex; use trie::{Trie, TrieFactory, TrieSpec}; -use types::{ +use crate::types::{ ancestry_action::AncestryAction, data_format::DataFormat, encoded, @@ -78,18 +78,17 @@ use crate::engines::{ epoch::PendingTransition, EngineError, EpochTransition, EthEngine, ForkChoice, SealingState, MAX_UNCLE_AGE, }; -use error::{ +use crate::error::{ BlockError, CallError, Error, Error as EthcoreError, ErrorKind as EthcoreErrorKind, EthcoreResult, ExecutionError, ImportErrorKind, QueueErrorKind, }; use crate::executive::{contract_address, Executed, Executive, TransactOptions}; use crate::factory::{Factories, VmFactory}; use crate::io::IoChannel; -use miner::{Miner, MinerService}; use crate::snapshot::{self, io as snapshot_io, SnapshotClient}; use crate::spec::Spec; use crate::state::{self, State}; -use state_db::StateDB; +use crate::state_db::StateDB; use stats::{PrometheusMetrics, PrometheusRegistry}; use crate::trace::{ self, Database as TraceDatabase, ImportRequest as TraceImportRequest, LocalizedTrace, TraceDB, @@ -105,7 +104,7 @@ use vm::Schedule; pub use crate::blockchain::CacheSize as BlockChainCacheSize; use db::{keys::BlockDetails, Readable, Writable}; pub use reth_util::queue::ExecutionQueue; -pub use types::{block_status::BlockStatus, blockchain_info::BlockChainInfo}; +pub use crate::types::{block_status::BlockStatus, blockchain_info::BlockChainInfo}; pub use crate::verification::QueueInfo as BlockQueueInfo; use crate::exit::ShutdownManager; @@ -857,7 +856,7 @@ impl Importer { use crate::engines::EpochChange; let hash = header.hash(); - let auxiliary = ::machine::AuxiliaryData { + let auxiliary = crate::machine::AuxiliaryData { bytes: Some(block_bytes), receipts: Some(&receipts), }; @@ -882,7 +881,7 @@ impl Importer { let call = move |addr, data| { let mut state_db = state_db.boxed_clone(); - let backend = ::state::backend::Proving::new(state_db.as_hash_db_mut()); + let backend = crate::state::backend::Proving::new(state_db.as_hash_db_mut()); let transaction = client.contract_call_tx( BlockId::Hash(*header.parent_hash()), @@ -993,7 +992,7 @@ impl Client { miner: Arc, message_channel: IoChannel, shutdown: ShutdownManager, - ) -> Result, ::error::Error> { + ) -> Result, crate::error::Error> { let trie_spec = match config.fat_db { true => TrieSpec::Fat, false => TrieSpec::Secure, @@ -1323,7 +1322,7 @@ impl Client { // use a state-proving closure for the given block. fn with_proving_caller(&self, id: BlockId, with_call: F) -> T where - F: FnOnce(&::machine::Call) -> T, + F: FnOnce(&crate::machine::Call) -> T, { let call = |a, d| { let tx = self.contract_call_tx(id, a, d); @@ -1343,7 +1342,7 @@ impl Client { &self, mut state_db: StateDB, chain: &BlockChain, - ) -> Result<(), ::error::Error> { + ) -> Result<(), crate::error::Error> { let latest_era = match state_db.journal_db().latest_era() { Some(n) => n, None => return Ok(()), @@ -1701,7 +1700,7 @@ impl Client { } fn do_virtual_call( - machine: &::machine::EthereumMachine, + machine: &crate::machine::EthereumMachine, env_info: &EnvInfo, state: &mut State, t: &SignedTransaction, @@ -1710,7 +1709,7 @@ impl Client { fn call( state: &mut State, env_info: &EnvInfo, - machine: &::machine::EthereumMachine, + machine: &crate::machine::EthereumMachine, state_diff: bool, transaction: &SignedTransaction, options: TransactOptions, @@ -2054,7 +2053,7 @@ impl ImportBlock for Client { } impl StateClient for Client { - type State = State<::state_db::StateDB>; + type State = State; fn latest_state_and_header(&self) -> (Self::State, Header) { Client::latest_state_and_header(self) @@ -2072,7 +2071,7 @@ impl Drop for Client { } impl Call for Client { - type State = State<::state_db::StateDB>; + type State = State; fn call( &self, @@ -2775,7 +2774,7 @@ impl BlockChainClient for Client { }; self.importer .miner - .ready_transactions(self, max_len, ::miner::PendingOrdering::Priority) + .ready_transactions(self, max_len, crate::miner::PendingOrdering::Priority) } fn transaction(&self, tx_hash: &H256) -> Option> { @@ -3251,9 +3250,9 @@ impl BroadcastProposalBlock for Client { impl SealedBlockImporter for Client {} -impl ::miner::TransactionVerifierClient for Client {} +impl crate::miner::TransactionVerifierClient for Client {} -impl ::miner::BlockChainClient for Client {} +impl crate::miner::BlockChainClient for Client {} impl super::traits::EngineClient for Client { fn update_sealing(&self, force: ForceUpdateSealing) { @@ -3515,7 +3514,7 @@ impl ImportExportBlocks for Client { /// Returns `LocalizedReceipt` given `LocalizedTransaction` /// and a vector of receipts from given block up to transaction index. fn transaction_receipt( - machine: &::machine::EthereumMachine, + machine: &crate::machine::EthereumMachine, mut tx: LocalizedTransaction, receipt: TypedReceipt, prior_gas_used: U256, @@ -3804,7 +3803,7 @@ mod tests { thread, time::Duration, }; - use types::encoded; + use crate::types::encoded; let client = generate_dummy_client(0); let genesis = client.chain_info().best_block_hash; @@ -3869,7 +3868,7 @@ mod tests { use super::transaction_receipt; use crypto::publickey::KeyPair; use hash::keccak; - use types::{ + use crate::types::{ log_entry::{LocalizedLogEntry, LogEntry}, receipt::{LegacyReceipt, LocalizedReceipt, TransactionOutcome, TypedReceipt}, transaction::{Action, LocalizedTransaction, Transaction, TypedTransaction}, diff --git a/crates/ethcore/src/client/evm_test_client.rs b/crates/ethcore/src/client/evm_test_client.rs index 8a44980dc..503470e80 100644 --- a/crates/ethcore/src/client/evm_test_client.rs +++ b/crates/ethcore/src/client/evm_test_client.rs @@ -32,7 +32,7 @@ use state_db; use std::{fmt, sync::Arc}; use crate::trace; use trie; -use types::{log_entry, receipt, transaction}; +use crate::types::{log_entry, receipt, transaction}; use vm::{self, ActionParams}; /// EVM test Error. @@ -403,7 +403,7 @@ pub struct TransactErr { /// State root pub state_root: H256, /// Execution error - pub error: ::error::Error, + pub error: crate::error::Error, /// end state if needed pub end_state: Option, } diff --git a/crates/ethcore/src/client/mod.rs b/crates/ethcore/src/client/mod.rs index 9a18f2217..09f2327b6 100644 --- a/crates/ethcore/src/client/mod.rs +++ b/crates/ethcore/src/client/mod.rs @@ -46,7 +46,7 @@ pub use self::{ }; pub use crate::state::StateInfo; -pub use types::{ +pub use crate::types::{ call_analytics::CallAnalytics, ids::*, pruning_info::PruningInfo, trace_filter::Filter as TraceFilter, }; @@ -54,7 +54,7 @@ pub use types::{ pub use crate::executive::{Executed, Executive, TransactOptions}; pub use vm::{EnvInfo, LastHashes}; -pub use error::TransactionImportError; +pub use crate::error::TransactionImportError; pub use crate::verification::VerifierType; pub mod traits; diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index b8a99862d..fb21620e3 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -38,7 +38,7 @@ use kvdb::DBValue; use parking_lot::{Mutex, RwLock}; use rlp::RlpStream; use rustc_hex::FromHex; -use types::{ +use crate::types::{ basic_account::BasicAccount, encoded, filter::Filter, @@ -497,8 +497,8 @@ impl BroadcastProposalBlock for TestBlockChainClient { impl SealedBlockImporter for TestBlockChainClient {} -impl ::miner::TransactionVerifierClient for TestBlockChainClient {} -impl ::miner::BlockChainClient for TestBlockChainClient {} +impl crate::miner::TransactionVerifierClient for TestBlockChainClient {} +impl crate::miner::BlockChainClient for TestBlockChainClient {} impl Nonce for TestBlockChainClient { fn nonce(&self, address: &Address, id: BlockId) -> Option { diff --git a/crates/ethcore/src/client/trace.rs b/crates/ethcore/src/client/trace.rs index 5a0833b8b..6c5f3e05a 100644 --- a/crates/ethcore/src/client/trace.rs +++ b/crates/ethcore/src/client/trace.rs @@ -19,7 +19,7 @@ use crate::blockchain::{BlockChain, BlockProvider, TransactionAddress}; use ethereum_types::H256; use crate::trace::DatabaseExtras as TraceDatabaseExtras; -use types::BlockNumber; +use crate::types::BlockNumber; impl TraceDatabaseExtras for BlockChain { fn block_hash(&self, block_number: BlockNumber) -> Option { diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index d61406cdc..63c763a4d 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -31,7 +31,7 @@ use evm::Schedule; use itertools::Itertools; use kvdb::DBValue; use parking_lot::Mutex; -use types::{ +use crate::types::{ basic_account::BasicAccount, block_status::BlockStatus, blockchain_info::BlockChainInfo, @@ -53,7 +53,7 @@ use vm::LastHashes; use crate::block::{ClosedBlock, OpenBlock, SealedBlock}; use crate::client::Mode; use crate::engines::EthEngine; -use error::{Error, EthcoreResult}; +use crate::error::{Error, EthcoreResult}; use crate::executed::CallError; use crate::executive::Executed; use crate::state::StateInfo; diff --git a/crates/ethcore/src/engines/authority_round/block_gas_limit.rs b/crates/ethcore/src/engines/authority_round/block_gas_limit.rs index 2e97d7625..7bf3a6b49 100644 --- a/crates/ethcore/src/engines/authority_round/block_gas_limit.rs +++ b/crates/ethcore/src/engines/authority_round/block_gas_limit.rs @@ -17,7 +17,7 @@ //! A client interface for interacting with the block gas limit contract. use crate::client::{BlockChainClient, BlockId}; -use types::header::Header; +use crate::types::header::Header; use ethabi::FunctionOutputDecoder; use ethabi_contract::use_contract; use ethereum_types::{Address, U256}; diff --git a/crates/ethcore/src/engines/authority_round/finality.rs b/crates/ethcore/src/engines/authority_round/finality.rs index e05d0a450..f0d814f02 100644 --- a/crates/ethcore/src/engines/authority_round/finality.rs +++ b/crates/ethcore/src/engines/authority_round/finality.rs @@ -22,7 +22,7 @@ use std::collections::{ }; use ethereum_types::{Address, H256}; -use types::BlockNumber; +use crate::types::BlockNumber; use crate::engines::validator_set::SimpleList; @@ -193,7 +193,7 @@ impl RollingFinality { mod tests { use super::RollingFinality; use ethereum_types::{Address, H256}; - use types::BlockNumber; + use crate::types::BlockNumber; #[test] fn rejects_unknown_signers() { diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index 3cb9c05c9..5b3805c2f 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -63,7 +63,7 @@ use crate::engines::{ block_reward::{BlockRewardContract, RewardKind}, ConstructedVerifier, Engine, EngineError, Seal, SealingState, }; -use error::{BlockError, Error, ErrorKind}; +use crate::error::{BlockError, Error, ErrorKind}; use ethereum_types::{Address, H256, H512, H520, U128, U256}; use ethjson::{self, uint::Uint}; @@ -76,7 +76,7 @@ use parking_lot::{Mutex, RwLock}; use rand::rngs::OsRng; use rlp::{encode, Decodable, DecoderError, Encodable, Rlp, RlpStream}; use time_utils::CheckedSystemTime; -use types::{ +use crate::types::{ ancestry_action::AncestryAction, header::{ExtendedHeader, Header}, ids::BlockId, @@ -1879,7 +1879,7 @@ impl Engine for AuthorityRound { }; let parent = client - .block_header(::client::BlockId::Hash(*block.header.parent_hash())) + .block_header(crate::client::BlockId::Hash(*block.header.parent_hash())) .expect("hash is from parent; parent header must exist; qed") .decode(self.params().eip1559_transition)?; @@ -2393,12 +2393,12 @@ mod tests { validator_set::{SimpleList, TestSet}, Engine, EngineError, EngineSigner, EthEngine, Seal, }; - use error::{Error, ErrorKind}; + use crate::error::{Error, ErrorKind}; use ethabi_contract::use_contract; use ethereum_types::{Address, H256, H520, U256}; use ethjson; use hash::keccak; - use miner::{Author, MinerService}; + use crate::miner::{Author, MinerService}; use rlp::encode; use crate::spec::Spec; use std::{ @@ -2410,11 +2410,11 @@ mod tests { }, time::Duration, }; - use test_helpers::{ + use crate::test_helpers::{ generate_dummy_client_with_spec, generate_dummy_client_with_spec_and_data, get_temp_state_db, push_block_with_transactions_and_author, TestNotify, }; - use types::{ + use crate::types::{ header::Header, ids::BlockId, transaction::{Action, Transaction, TypedTransaction}, diff --git a/crates/ethcore/src/engines/authority_round/util.rs b/crates/ethcore/src/engines/authority_round/util.rs index 3315f40fc..218784d03 100644 --- a/crates/ethcore/src/engines/authority_round/util.rs +++ b/crates/ethcore/src/engines/authority_round/util.rs @@ -25,7 +25,7 @@ use ethabi::{self, FunctionOutputDecoder}; use ethabi_contract::use_contract; use ethereum_types::{Address, U256}; use log::{debug, error}; -use types::{header::Header, ids::BlockId}; +use crate::types::{header::Header, ids::BlockId}; /// A contract bound to a client and block number. /// diff --git a/crates/ethcore/src/engines/basic_authority.rs b/crates/ethcore/src/engines/basic_authority.rs index 9d8c1b8ac..884bd0f0b 100644 --- a/crates/ethcore/src/engines/basic_authority.rs +++ b/crates/ethcore/src/engines/basic_authority.rs @@ -27,7 +27,7 @@ use ethjson; use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use parking_lot::RwLock; use std::sync::Weak; -use types::header::{ExtendedHeader, Header}; +use crate::types::header::{ExtendedHeader, Header}; /// `BasicAuthority` params. #[derive(Debug, PartialEq)] @@ -234,7 +234,7 @@ mod tests { use std::sync::Arc; use tempdir::TempDir; use crate::test_helpers::get_temp_state_db; - use types::header::Header; + use crate::types::header::Header; /// Create a new test chain spec with `BasicAuthority` consensus engine. fn new_test_authority() -> Spec { diff --git a/crates/ethcore/src/engines/block_reward.rs b/crates/ethcore/src/engines/block_reward.rs index f76ae0d39..3093206f8 100644 --- a/crates/ethcore/src/engines/block_reward.rs +++ b/crates/ethcore/src/engines/block_reward.rs @@ -22,12 +22,12 @@ use ethereum_types::{Address, H160, U256}; use super::{SystemOrCodeCall, SystemOrCodeCallKind}; use crate::block::ExecutedBlock; -use error::Error; +use crate::error::Error; use hash::keccak; use crate::machine::Machine; use std::sync::Arc; use crate::trace::{self, ExecutiveTracer, Tracer, Tracing}; -use types::BlockNumber; +use crate::types::BlockNumber; use_contract!(block_reward_contract, "res/contracts/block_reward.json"); diff --git a/crates/ethcore/src/engines/clique/block_state.rs b/crates/ethcore/src/engines/clique/block_state.rs index 27ac9b760..778251fa3 100644 --- a/crates/ethcore/src/engines/clique/block_state.rs +++ b/crates/ethcore/src/engines/clique/block_state.rs @@ -27,11 +27,11 @@ use crate::engines::{ }, EngineError, }; -use error::{BlockError, Error}; +use crate::error::{BlockError, Error}; use ethereum_types::{Address, H64}; use rand::Rng; use time_utils::CheckedSystemTime; -use types::{header::Header, BlockNumber}; +use crate::types::{header::Header, BlockNumber}; use unexpected::Mismatch; /// Type that keeps track of the state for a given vote diff --git a/crates/ethcore/src/engines/clique/mod.rs b/crates/ethcore/src/engines/clique/mod.rs index 441f15b69..b4c2a143f 100644 --- a/crates/ethcore/src/engines/clique/mod.rs +++ b/crates/ethcore/src/engines/clique/mod.rs @@ -73,7 +73,7 @@ use crate::engines::{ clique::util::{extract_signers, recover_creator}, Engine, EngineError, Seal, SealingState, }; -use error::{BlockError, Error}; +use crate::error::{BlockError, Error}; use ethereum_types::{Address, H160, H256, H64, U256}; use hash::KECCAK_EMPTY_LIST_RLP; use itertools::Itertools; @@ -82,7 +82,7 @@ use crate::machine::{Call, EthereumMachine}; use parking_lot::RwLock; use rand::Rng; use time_utils::CheckedSystemTime; -use types::{ +use crate::types::{ header::{ExtendedHeader, Header}, BlockNumber, }; diff --git a/crates/ethcore/src/engines/clique/util.rs b/crates/ethcore/src/engines/clique/util.rs index 17b92d505..770a3aade 100644 --- a/crates/ethcore/src/engines/clique/util.rs +++ b/crates/ethcore/src/engines/clique/util.rs @@ -21,12 +21,12 @@ use crate::engines::{ clique::{ADDRESS_LENGTH, NULL_MIXHASH, NULL_NONCE, SIGNATURE_LENGTH, VANITY_LENGTH}, EngineError, }; -use error::Error; +use crate::error::Error; use ethereum_types::{Address, H160, H256}; use lru_cache::LruCache; use parking_lot::RwLock; use rlp::encode; -use types::header::Header; +use crate::types::header::Header; /// How many recovered signature to cache in the memory. pub const CREATOR_CACHE_NUM: usize = 4096; diff --git a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs index 5d4d88b0e..98d54202c 100644 --- a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs @@ -18,7 +18,7 @@ //! block reward contract. use crate::engines::{SystemOrCodeCall, SystemOrCodeCallKind}; -use error::Error; +use crate::error::Error; use ethabi::FunctionOutputDecoder; use ethabi_contract::use_contract; use ethereum_types::Address; diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index 83b73316a..fe63e6f15 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -1,7 +1,7 @@ use crate::client::EngineClient; use ethereum_types::{Address, H256, U256}; use std::str::FromStr; -use types::ids::BlockId; +use crate::types::ids::BlockId; use crate::{ client::{traits::TransactionRequest, BlockChainClient}, diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index eeca45831..c1284bfb9 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -20,7 +20,7 @@ use hbbft::{ use itertools::Itertools; use parking_lot::RwLock; use std::{collections::BTreeMap, str::FromStr, sync::Arc}; -use types::ids::BlockId; +use crate::types::ids::BlockId; use_contract!( key_history_contract, diff --git a/crates/ethcore/src/engines/hbbft/contracts/permission.rs b/crates/ethcore/src/engines/hbbft/contracts/permission.rs index 9e4ac713b..a6b8867d6 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/permission.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/permission.rs @@ -5,7 +5,7 @@ use crate::{ client::EngineClient, engines::hbbft::utils::bound_contract::{BoundContract, CallError}, }; -use types::ids::BlockId; +use crate::types::ids::BlockId; use_contract!(permission_contract, "res/contracts/permission_hbbft.json"); diff --git a/crates/ethcore/src/engines/hbbft/contracts/staking.rs b/crates/ethcore/src/engines/hbbft/contracts/staking.rs index be30599e8..a7fd2905a 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/staking.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/staking.rs @@ -5,7 +5,7 @@ use std::{ net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, str::FromStr, }; -use types::ids::BlockId; +use crate::types::ids::BlockId; use_contract!(staking_contract, "res/contracts/staking_contract.json"); diff --git a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs index d4d529db1..60af877bf 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs @@ -6,7 +6,7 @@ use crypto::publickey::Public; use crate::engines::hbbft::utils::bound_contract::{BoundContract, CallError}; use ethereum_types::{Address, U256}; use std::{collections::BTreeMap, net::SocketAddr, str::FromStr}; -use types::{ids::BlockId, transaction::Error}; +use crate::types::{ids::BlockId, transaction::Error}; use_contract!( validator_set_hbbft, diff --git a/crates/ethcore/src/engines/hbbft/contribution.rs b/crates/ethcore/src/engines/hbbft/contribution.rs index 98ce0de54..476f3f109 100644 --- a/crates/ethcore/src/engines/hbbft/contribution.rs +++ b/crates/ethcore/src/engines/hbbft/contribution.rs @@ -1,7 +1,7 @@ use rand::{self, distributions::Standard, Rng}; use rlp::RlpStream; use std::time::UNIX_EPOCH; -use types::transaction::SignedTransaction; +use crate::types::transaction::SignedTransaction; #[derive(Clone, Eq, PartialEq, Debug, Hash, Serialize, Deserialize)] pub(crate) struct Contribution { @@ -59,7 +59,7 @@ mod tests { use crypto::publickey::{Generator, Random}; use crate::engines::hbbft::test::create_transactions::create_transaction; use ethereum_types::U256; - use types::transaction::{SignedTransaction, TypedTransaction}; + use crate::types::transaction::{SignedTransaction, TypedTransaction}; #[test] fn test_contribution_serialization() { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index f27370207..105ea58a6 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -1,6 +1,6 @@ use ethereum_types::Address; use stats::PrometheusMetrics; -use types::ids::BlockId; +use crate::types::ids::BlockId; use crate::{ client::{BlockChainClient, EngineClient}, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 74ed119eb..6cd185fab 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -16,7 +16,7 @@ use crate::engines::{ default_system_or_code_call, signer::EngineSigner, Engine, EngineError, ForkChoice, Seal, SealingState, }; -use error::{BlockError, Error}; +use crate::error::{BlockError, Error}; use ethereum_types::{Address, Public, H256, H512, U256}; use ethjson::spec::HbbftParams; use hbbft::{NetworkInfo, Target}; @@ -36,7 +36,7 @@ use std::{ sync::{atomic::AtomicBool, Arc, Weak}, time::{Duration, Instant}, }; -use types::{ +use crate::types::{ header::{ExtendedHeader, Header}, ids::BlockId, transaction::{SignedTransaction, TypedTransaction}, @@ -1719,7 +1719,7 @@ mod tests { }; use rand; use std::sync::Arc; - use types::transaction::SignedTransaction; + use crate::types::transaction::SignedTransaction; #[test] fn test_single_contribution() { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs index 49f3c6f7f..7a5185f53 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs @@ -1,5 +1,5 @@ use crate::client::EngineClient; -use error::Error; +use crate::error::Error; use ethereum_types::Address; use parking_lot::Mutex; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 4ed91b5dc..35a8ef7c1 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -15,7 +15,7 @@ use std::{ sync::Arc, time::Duration, }; -use types::{header::Header, ids::BlockId}; +use crate::types::{header::Header, ids::BlockId}; use crate::engines::hbbft::contracts::permission::get_minimum_gas_from_permission_contract; diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 8c7a4535c..169559f22 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -20,7 +20,7 @@ use ethereum_types::{Address, U256}; use itertools::Itertools; use parking_lot::RwLock; use std::{collections::BTreeMap, sync::Arc}; -use types::ids::BlockId; +use crate::types::ids::BlockId; use crate::client::BlockChainClient; diff --git a/crates/ethcore/src/engines/hbbft/test/create_transactions.rs b/crates/ethcore/src/engines/hbbft/test/create_transactions.rs index 9e6375637..8a95b98e8 100644 --- a/crates/ethcore/src/engines/hbbft/test/create_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/test/create_transactions.rs @@ -1,6 +1,6 @@ use crypto::publickey::KeyPair; use ethereum_types::{Address, U256}; -use types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; +use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; pub fn create_transaction(keypair: &KeyPair, nonce: &U256) -> SignedTransaction { TypedTransaction::Legacy(Transaction { diff --git a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs index 44f320d32..1bc86f859 100644 --- a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs +++ b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs @@ -11,7 +11,7 @@ use parking_lot::RwLock; use crate::spec::Spec; use std::{ops::Deref, sync::Arc}; use test_helpers::{generate_dummy_client_with_spec, TestNotify}; -use types::{data_format::DataFormat, ids::BlockId}; +use crate::types::{data_format::DataFormat, ids::BlockId}; pub fn hbbft_spec() -> Spec { Spec::load( diff --git a/crates/ethcore/src/engines/hbbft/test/mod.rs b/crates/ethcore/src/engines/hbbft/test/mod.rs index f22f6026c..dcbbb1405 100644 --- a/crates/ethcore/src/engines/hbbft/test/mod.rs +++ b/crates/ethcore/src/engines/hbbft/test/mod.rs @@ -13,7 +13,7 @@ use crate::client::traits::BlockInfo; use crypto::publickey::{Generator, KeyPair, Random, Secret}; use ethereum_types::{Address, U256}; use std::str::FromStr; -use types::ids::BlockId; +use crate::types::ids::BlockId; pub mod create_transactions; pub mod hbbft_test_client; diff --git a/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs b/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs index 17f32232b..c301d623d 100644 --- a/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs +++ b/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs @@ -9,7 +9,7 @@ use std::fmt; use crate::client::EngineClient; use ethabi; use ethereum_types::Address; -use types::ids::BlockId; +use crate::types::ids::BlockId; /// A contract bound to a client and block number. /// diff --git a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs index 8d9a71c23..291fc3658 100644 --- a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs +++ b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs @@ -3,7 +3,7 @@ use ethereum_types::{Address, U256}; use std::collections::HashMap; -use types::transaction::SignedTransaction; +use crate::types::transaction::SignedTransaction; /// Combining an address with a random U256 seed using XOR, using big-endian byte ordering always. fn address_xor_u256(address: &Address, seed: U256) -> Address { diff --git a/crates/ethcore/src/engines/instant_seal.rs b/crates/ethcore/src/engines/instant_seal.rs index 4d831a835..eaeffd1e0 100644 --- a/crates/ethcore/src/engines/instant_seal.rs +++ b/crates/ethcore/src/engines/instant_seal.rs @@ -18,7 +18,7 @@ use crate::block::ExecutedBlock; use crate::engines::{Engine, Seal, SealingState}; use crate::machine::Machine; use std::sync::atomic::{AtomicU64, Ordering}; -use types::header::{ExtendedHeader, Header}; +use crate::types::header::{ExtendedHeader, Header}; /// `InstantSeal` params. #[derive(Default, Debug, PartialEq)] @@ -132,7 +132,7 @@ mod tests { use crate::spec::Spec; use std::sync::Arc; use test_helpers::get_temp_state_db; - use types::header::Header; + use crate::types::header::Header; #[test] fn instant_can_seal() { diff --git a/crates/ethcore/src/engines/mod.rs b/crates/ethcore/src/engines/mod.rs index 657ff70af..7f2a9bbc1 100644 --- a/crates/ethcore/src/engines/mod.rs +++ b/crates/ethcore/src/engines/mod.rs @@ -38,7 +38,7 @@ pub use self::{ }; // TODO [ToDr] Remove re-export (#10130) -pub use types::engines::{ +pub use crate::types::engines::{ epoch::{self, Transition as EpochTransition}, ForkChoice, }; @@ -53,7 +53,7 @@ use builtin::Builtin; use crate::error::Error; use crate::snapshot::SnapshotComponents; use crate::spec::CommonParams; -use types::{ +use crate::types::{ header::{ExtendedHeader, Header}, transaction::{self, SignedTransaction, UnverifiedTransaction}, BlockNumber, @@ -65,7 +65,7 @@ use bytes::Bytes; use crypto::publickey::Signature; use ethereum_types::{Address, H256, H512, H64, U256}; use crate::machine::{self, AuxiliaryData, AuxiliaryRequest, Machine}; -use types::ancestry_action::AncestryAction; +use crate::types::ancestry_action::AncestryAction; use unexpected::{Mismatch, OutOfBounds}; /// Default EIP-210 contract code. @@ -221,8 +221,8 @@ pub enum SystemOrCodeCallKind { /// Default SystemOrCodeCall implementation. pub fn default_system_or_code_call<'a>( - machine: &'a ::machine::EthereumMachine, - block: &'a mut ::block::ExecutedBlock, + machine: &'a crate::machine::EthereumMachine, + block: &'a mut crate::block::ExecutedBlock, ) -> impl FnMut(SystemOrCodeCallKind, Vec) -> Result, String> + 'a { move |to, data| { let result = match to { @@ -604,7 +604,7 @@ pub fn total_difficulty_fork_choice(new: &ExtendedHeader, best: &ExtendedHeader) // TODO: make this a _trait_ alias when those exist. // fortunately the effect is largely the same since engines are mostly used // via trait objects. -pub trait EthEngine: Engine<::machine::EthereumMachine> { +pub trait EthEngine: Engine { /// Get the general parameters of the chain. fn params(&self) -> &CommonParams { self.machine().params() @@ -718,7 +718,7 @@ pub trait EthEngine: Engine<::machine::EthereumMachine> { } // convenience wrappers for existing functions. -impl EthEngine for T where T: Engine<::machine::EthereumMachine> {} +impl EthEngine for T where T: Engine {} /// Verifier for all blocks within an epoch with self-contained state. pub trait EpochVerifier: Send + Sync { diff --git a/crates/ethcore/src/engines/null_engine.rs b/crates/ethcore/src/engines/null_engine.rs index 7885c1d9e..bd124d7de 100644 --- a/crates/ethcore/src/engines/null_engine.rs +++ b/crates/ethcore/src/engines/null_engine.rs @@ -21,7 +21,7 @@ use crate::engines::{ }; use ethereum_types::U256; use crate::machine::Machine; -use types::{ +use crate::types::{ ancestry_action::AncestryAction, header::{ExtendedHeader, Header}, BlockNumber, diff --git a/crates/ethcore/src/engines/validator_set/contract.rs b/crates/ethcore/src/engines/validator_set/contract.rs index a9a46b053..1d4dd32fe 100644 --- a/crates/ethcore/src/engines/validator_set/contract.rs +++ b/crates/ethcore/src/engines/validator_set/contract.rs @@ -22,11 +22,11 @@ use bytes::Bytes; use ethereum_types::{Address, H256, U256}; use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use parking_lot::RwLock; -use types::{header::Header, ids::BlockId, transaction, BlockNumber}; +use crate::types::{header::Header, ids::BlockId, transaction, BlockNumber}; use crate::client::{traits::TransactionRequest, EngineClient}; -use error::Error as EthcoreError; +use crate::error::Error as EthcoreError; use super::{safe_contract::ValidatorSafeContract, SimpleList, SystemCall, ValidatorSet}; @@ -146,7 +146,7 @@ impl ValidatorSet for ValidatorContract { first: bool, header: &Header, call: &mut SystemCall, - ) -> Result<(), ::error::Error> { + ) -> Result<(), crate::error::Error> { self.validators.on_epoch_begin(first, header, call) } @@ -173,7 +173,7 @@ impl ValidatorSet for ValidatorContract { machine: &EthereumMachine, number: BlockNumber, proof: &[u8], - ) -> Result<(SimpleList, Option), ::error::Error> { + ) -> Result<(SimpleList, Option), crate::error::Error> { self.validators.epoch_set(first, machine, number, proof) } @@ -229,7 +229,7 @@ mod tests { use crate::spec::Spec; use std::sync::Arc; use test_helpers::generate_dummy_client_with_spec; - use types::{header::Header, ids::BlockId}; + use crate::types::{header::Header, ids::BlockId}; #[test] fn fetches_validators() { diff --git a/crates/ethcore/src/engines/validator_set/mod.rs b/crates/ethcore/src/engines/validator_set/mod.rs index fdd6bea7c..a52114a5d 100644 --- a/crates/ethcore/src/engines/validator_set/mod.rs +++ b/crates/ethcore/src/engines/validator_set/mod.rs @@ -29,7 +29,7 @@ use bytes::Bytes; use ethereum_types::{Address, H256}; use ethjson::spec::ValidatorSet as ValidatorSpec; use crate::machine::{AuxiliaryData, Call, EthereumMachine}; -use types::{header::Header, ids::BlockId, BlockNumber}; +use crate::types::{header::Header, ids::BlockId, BlockNumber}; use crate::client::EngineClient; @@ -129,7 +129,7 @@ pub trait ValidatorSet: Send + Sync + 'static { _first: bool, _header: &Header, _call: &mut SystemCall, - ) -> Result<(), ::error::Error> { + ) -> Result<(), crate::error::Error> { Ok(()) } @@ -172,7 +172,7 @@ pub trait ValidatorSet: Send + Sync + 'static { machine: &EthereumMachine, number: BlockNumber, proof: &[u8], - ) -> Result<(SimpleList, Option), ::error::Error>; + ) -> Result<(SimpleList, Option), crate::error::Error>; /// Checks if a given address is a validator, with the given function /// for executing synchronous calls to contracts. diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index 22bf75d4b..b9dce65b7 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -21,7 +21,7 @@ use std::sync::Weak; use bytes::Bytes; use ethereum_types::{Address, H256}; use parking_lot::RwLock; -use types::{header::Header, ids::BlockId, BlockNumber}; +use crate::types::{header::Header, ids::BlockId, BlockNumber}; use super::{SystemCall, ValidatorSet}; use crate::client::EngineClient; @@ -149,7 +149,7 @@ impl ValidatorSet for Multi { machine: &EthereumMachine, number: BlockNumber, proof: &[u8], - ) -> Result<(super::SimpleList, Option), ::error::Error> { + ) -> Result<(super::SimpleList, Option), crate::error::Error> { let (set_block, set) = self.correct_set_by_number(number); let first = set_block == number; @@ -219,7 +219,7 @@ mod tests { use crate::spec::Spec; use std::{collections::BTreeMap, sync::Arc}; use test_helpers::generate_dummy_client_with_spec; - use types::{header::Header, ids::BlockId}; + use crate::types::{header::Header, ids::BlockId}; use crate::verification::queue::kind::blocks::Unverified; use super::Multi; diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index 1dec1382b..1718e696b 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -21,7 +21,7 @@ use std::{ }; use bytes::Bytes; -use error::{Error as EthcoreError, ErrorKind as EthcoreErrorKind}; +use crate::error::{Error as EthcoreError, ErrorKind as EthcoreErrorKind}; use ethabi::FunctionOutputDecoder; use ethereum_types::{Address, Bloom, H256, U256}; use hash::keccak; @@ -29,7 +29,7 @@ use kvdb::DBValue; use memory_cache::MemoryLruCache; use parking_lot::{Mutex, RwLock}; use rlp::{Rlp, RlpStream}; -use types::{ +use crate::types::{ header::Header, ids::BlockId, log_entry::LogEntry, receipt::TypedReceipt, transaction, BlockNumber, }; @@ -112,7 +112,7 @@ fn check_first_proof( old_header: Header, state_items: &[DBValue], ) -> Result, String> { - use types::transaction::{Action, Transaction, TypedTransaction}; + use crate::types::transaction::{Action, Transaction, TypedTransaction}; // TODO: match client contract_call_tx more cleanly without duplication. const PROVIDED_GAS: u64 = 50_000_000; @@ -168,7 +168,7 @@ fn check_first_proof( fn decode_first_proof( rlp: &Rlp, eip1559_transition: BlockNumber, -) -> Result<(Header, Vec), ::error::Error> { +) -> Result<(Header, Vec), crate::error::Error> { let header = Header::decode_rlp(&rlp.at(0)?, eip1559_transition)?; let state_items = rlp .at(1)? @@ -178,7 +178,7 @@ fn decode_first_proof( val.append_slice(x.data()?); Ok(val) }) - .collect::>()?; + .collect::>()?; Ok((header, state_items)) } @@ -196,7 +196,7 @@ fn encode_proof(header: &Header, receipts: &[TypedReceipt]) -> Bytes { fn decode_proof( rlp: &Rlp, eip1559_transition: BlockNumber, -) -> Result<(Header, Vec), ::error::Error> { +) -> Result<(Header, Vec), crate::error::Error> { Ok(( Header::decode_rlp(&rlp.at(0)?, eip1559_transition)?, TypedReceipt::decode_rlp_list(&rlp.at(1)?)?, @@ -494,7 +494,7 @@ impl ValidatorSet for ValidatorSafeContract { _first: bool, _header: &Header, caller: &mut SystemCall, - ) -> Result<(), ::error::Error> { + ) -> Result<(), crate::error::Error> { let data = validator_set::functions::finalize_change::encode_input(); caller(self.contract_address, data) .map(|_| ()) @@ -559,7 +559,7 @@ impl ValidatorSet for ValidatorSafeContract { machine: &EthereumMachine, _number: ::types::BlockNumber, proof: &[u8], - ) -> Result<(SimpleList, Option), ::error::Error> { + ) -> Result<(SimpleList, Option), crate::error::Error> { let rlp = Rlp::new(proof); if first { @@ -727,7 +727,7 @@ mod tests { use crate::spec::Spec; use std::sync::Arc; use test_helpers::generate_dummy_client_with_spec; - use types::{ + use crate::types::{ ids::BlockId, transaction::{Action, Transaction, TypedTransaction}, }; @@ -858,7 +858,7 @@ mod tests { fn detects_bloom() { use crate::engines::EpochChange; use crate::machine::AuxiliaryRequest; - use types::{header::Header, log_entry::LogEntry}; + use crate::types::{header::Header, log_entry::LogEntry}; let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); let engine = client.engine(); @@ -897,7 +897,7 @@ mod tests { #[test] fn initial_contract_is_signal() { use crate::engines::{EpochChange, Proof}; - use types::header::Header; + use crate::types::header::Header; let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); let engine = client.engine(); diff --git a/crates/ethcore/src/engines/validator_set/simple_list.rs b/crates/ethcore/src/engines/validator_set/simple_list.rs index 6a044a1c2..31cdcdba9 100644 --- a/crates/ethcore/src/engines/validator_set/simple_list.rs +++ b/crates/ethcore/src/engines/validator_set/simple_list.rs @@ -20,9 +20,9 @@ use parity_util_mem::MallocSizeOf; use super::{SystemCall, ValidatorSet}; use bytes::Bytes; -use error::Error as EthcoreError; +use crate::error::Error as EthcoreError; use crate::machine::{AuxiliaryData, Call, EthereumMachine}; -use types::{header::Header, BlockNumber}; +use crate::types::{header::Header, BlockNumber}; /// Validator set containing a known set of addresses. #[derive(Clone, Debug, PartialEq, Eq, Default, MallocSizeOf)] @@ -100,7 +100,7 @@ impl ValidatorSet for SimpleList { _: &EthereumMachine, _: BlockNumber, _: &[u8], - ) -> Result<(SimpleList, Option), ::error::Error> { + ) -> Result<(SimpleList, Option), crate::error::Error> { Ok((self.clone(), None)) } diff --git a/crates/ethcore/src/engines/validator_set/test.rs b/crates/ethcore/src/engines/validator_set/test.rs index 1c6adce61..8542b6a90 100644 --- a/crates/ethcore/src/engines/validator_set/test.rs +++ b/crates/ethcore/src/engines/validator_set/test.rs @@ -24,7 +24,7 @@ use std::sync::{ use bytes::Bytes; use ethereum_types::{Address, H256}; use parity_util_mem::MallocSizeOf; -use types::{header::Header, BlockNumber}; +use crate::types::{header::Header, BlockNumber}; use super::{SimpleList, SystemCall, ValidatorSet}; use error::Error as EthcoreError; @@ -109,7 +109,7 @@ impl ValidatorSet for TestSet { _: &EthereumMachine, _: BlockNumber, _: &[u8], - ) -> Result<(SimpleList, Option), ::error::Error> { + ) -> Result<(SimpleList, Option), crate::error::Error> { Ok((self.validator.clone(), None)) } diff --git a/crates/ethcore/src/error.rs b/crates/ethcore/src/error.rs index 74ca5c933..c9b52e104 100644 --- a/crates/ethcore/src/error.rs +++ b/crates/ethcore/src/error.rs @@ -28,7 +28,7 @@ use ethtrie::TrieError; use rlp; use snappy::InvalidInput; use crate::snapshot::Error as SnapshotError; -use types::{transaction::Error as TransactionError, BlockNumber}; +use crate::types::{transaction::Error as TransactionError, BlockNumber}; use unexpected::{Mismatch, OutOfBounds}; use crate::engines::EngineError; diff --git a/crates/ethcore/src/ethereum/ethash.rs b/crates/ethcore/src/ethereum/ethash.rs index 81fa1c9da..7e6003b3a 100644 --- a/crates/ethcore/src/ethereum/ethash.rs +++ b/crates/ethcore/src/ethereum/ethash.rs @@ -25,7 +25,7 @@ use ethereum_types::{H256, H64, U256}; use ethjson::{self, uint::Uint}; use hash::KECCAK_EMPTY_LIST_RLP; use rlp::Rlp; -use types::{ +use crate::types::{ header::{ExtendedHeader, Header}, BlockNumber, }; @@ -37,7 +37,7 @@ use crate::engines::{ block_reward::{self, BlockRewardContract, RewardKind}, Engine, }; -use error::{BlockError, Error}; +use crate::error::{BlockError, Error}; use ethash::{self, quick_get_difficulty, slow_hash_block_number, EthashManager, OptimizeFor}; use crate::machine::EthereumMachine; @@ -449,7 +449,7 @@ impl Engine for Arc { } fn snapshot_components(&self) -> Option> { - Some(Box::new(::snapshot::PowSnapshot::new( + Some(Box::new(crate::snapshot::PowSnapshot::new( SNAPSHOT_BLOCKS, MAX_SNAPSHOT_BLOCKS, ))) @@ -572,7 +572,7 @@ mod tests { use std::{collections::BTreeMap, str::FromStr, sync::Arc}; use tempdir::TempDir; use test_helpers::get_temp_state_db; - use types::header::Header; + use crate::types::header::Header; fn test_spec() -> Spec { let tempdir = TempDir::new("").unwrap(); diff --git a/crates/ethcore/src/ethereum/mod.rs b/crates/ethcore/src/ethereum/mod.rs index 815b9ea2c..019d98291 100644 --- a/crates/ethcore/src/ethereum/mod.rs +++ b/crates/ethcore/src/ethereum/mod.rs @@ -373,7 +373,7 @@ mod tests { use crate::state::*; use std::str::FromStr; use test_helpers::get_temp_state_db; - use types::{view, views::BlockView}; + use crate::types::{view, views::BlockView}; #[test] fn ensure_db_good() { diff --git a/crates/ethcore/src/executed.rs b/crates/ethcore/src/executed.rs index a4495999a..542bd1198 100644 --- a/crates/ethcore/src/executed.rs +++ b/crates/ethcore/src/executed.rs @@ -20,7 +20,7 @@ use bytes::Bytes; use ethereum_types::{Address, U256, U512}; use ethtrie; use crate::trace::{FlatTrace, VMTrace}; -use types::{log_entry::LogEntry, state_diff::StateDiff}; +use crate::types::{log_entry::LogEntry, state_diff::StateDiff}; use vm; use std::{error, fmt}; diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index 37aa4b0aa..38b855d05 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -28,7 +28,7 @@ use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, convert::TryFrom, sync::Arc}; use crate::trace::{self, Tracer, VMTracer}; use crate::transaction_ext::Transaction; -use types::transaction::{Action, SignedTransaction, TypedTransaction}; +use crate::types::transaction::{Action, SignedTransaction, TypedTransaction}; use vm::{ self, AccessList, ActionParams, ActionValue, CleanDustMode, CreateContractAddress, EnvInfo, ResumeCall, ResumeCreate, ReturnData, Schedule, TrapError, @@ -1640,7 +1640,7 @@ mod tests { trace, ExecutiveTracer, ExecutiveVMTracer, FlatTrace, MemoryDiff, NoopTracer, NoopVMTracer, StorageDiff, Tracer, VMExecutedOperation, VMOperation, VMTrace, VMTracer, }; - use types::transaction::{ + use crate::types::transaction::{ AccessListTx, Action, EIP1559TransactionTx, Transaction, TypedTransaction, }; use vm::{ActionParams, ActionValue, CallType, CreateContractAddress, EnvInfo}; diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index 3c8c61aab..3a50fd968 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -22,7 +22,7 @@ use crate::machine::EthereumMachine as Machine; use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, sync::Arc}; use crate::trace::{Tracer, VMTracer}; -use types::transaction::UNSIGNED_SENDER; +use crate::types::transaction::UNSIGNED_SENDER; use vm::{ self, AccessList, ActionParams, ActionValue, CallType, ContractCreateResult, CreateContractAddress, EnvInfo, Ext, MessageCallResult, ReturnData, Schedule, TrapKind, @@ -444,7 +444,7 @@ where } fn log(&mut self, topics: Vec, data: &[u8]) -> vm::Result<()> { - use types::log_entry::LogEntry; + use crate::types::log_entry::LogEntry; if self.static_flag { return Err(vm::Error::MutableCallInStaticContext); diff --git a/crates/ethcore/src/json_tests/difficulty.rs b/crates/ethcore/src/json_tests/difficulty.rs index 39a90499c..2b42e8a60 100644 --- a/crates/ethcore/src/json_tests/difficulty.rs +++ b/crates/ethcore/src/json_tests/difficulty.rs @@ -18,7 +18,7 @@ use ethereum_types::U256; use ethjson; use crate::spec::Spec; use std::path::Path; -use types::header::Header; +use crate::types::header::Header; use super::HookType; diff --git a/crates/ethcore/src/json_tests/local.rs b/crates/ethcore/src/json_tests/local.rs index 65268d65f..f6d0b3727 100644 --- a/crates/ethcore/src/json_tests/local.rs +++ b/crates/ethcore/src/json_tests/local.rs @@ -4,7 +4,7 @@ use ethjson::{self, blockchain::Block}; use log::warn; use rlp::RlpStream; use std::path::Path; -use types::{ +use crate::types::{ transaction::{TypedTransaction, TypedTxId, UnverifiedTransaction}, BlockNumber, }; diff --git a/crates/ethcore/src/json_tests/transaction.rs b/crates/ethcore/src/json_tests/transaction.rs index b9363ddb2..7b2c963b5 100644 --- a/crates/ethcore/src/json_tests/transaction.rs +++ b/crates/ethcore/src/json_tests/transaction.rs @@ -19,7 +19,7 @@ use crate::client::EvmTestClient; use ethjson; use std::path::Path; use crate::transaction_ext::Transaction; -use types::{ +use crate::types::{ header::Header, transaction::{TypedTransaction, UnverifiedTransaction}, }; diff --git a/crates/ethcore/src/machine/impls.rs b/crates/ethcore/src/machine/impls.rs index 566abdb65..b7d921bea 100644 --- a/crates/ethcore/src/machine/impls.rs +++ b/crates/ethcore/src/machine/impls.rs @@ -23,7 +23,7 @@ use std::{ }; use ethereum_types::{Address, H256, U256}; -use types::{ +use crate::types::{ header::Header, transaction::{ self, SignedTransaction, TypedTransaction, UnverifiedTransaction, SYSTEM_ADDRESS, @@ -40,12 +40,12 @@ use crate::block::ExecutedBlock; use builtin::Builtin; use call_contract::CallContract; use crate::client::BlockInfo; -use error::Error; +use crate::error::Error; use crate::executive::Executive; use crate::spec::CommonParams; use crate::state::{CleanupMode, Substate}; use crate::trace::{NoopTracer, NoopVMTracer}; -use tx_filter::TransactionFilter; +use crate::tx_filter::TransactionFilter; /// Ethash-specific extensions. #[derive(Debug, Clone)] @@ -207,7 +207,7 @@ impl EthereumMachine { let res = ex .call(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer) - .map_err(|e| ::engines::EngineError::FailedSystemCall(format!("{}", e)))?; + .map_err(|e| crate::engines::EngineError::FailedSystemCall(format!("{}", e)))?; let output = res.return_data.to_vec(); Ok(output) diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index a9a29f554..60b356b78 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -39,7 +39,7 @@ use ethcore_miner::{ use ethereum_types::{Address, H256, U256}; use crate::io::IoChannel; use itertools::Itertools; -use miner::{ +use crate::miner::{ self, cache::Cache, pool_client::{CachedNonceClient, PoolClient}, @@ -47,7 +47,7 @@ use miner::{ }; use parking_lot::{Mutex, RwLock}; use rayon::prelude::*; -use types::{ +use crate::types::{ block::Block, header::Header, receipt::RichReceipt, @@ -63,7 +63,7 @@ use crate::client::{ TransactionId, TransactionInfo, }; use crate::engines::{EngineSigner, EthEngine, Seal, SealingState}; -use error::{Error, ErrorKind}; +use crate::error::{Error, ErrorKind}; use crate::executed::ExecutionError; use crate::executive::contract_address; use crate::spec::Spec; @@ -1107,7 +1107,7 @@ impl Miner { const SEALING_TIMEOUT_IN_BLOCKS: u64 = 5; impl miner::MinerService for Miner { - type State = State<::state_db::StateDB>; + type State = State; fn authoring_params(&self) -> AuthoringParams { self.params.read().clone() @@ -1743,7 +1743,7 @@ impl miner::MinerService for Miner { let accounts = self.accounts.clone(); let service_transaction_checker = self.service_transaction_checker.clone(); - let cull = move |chain: &::client::Client| { + let cull = move |chain: &crate::client::Client| { let client = PoolClient::new( chain, &nonce_cache, @@ -1829,14 +1829,14 @@ mod tests { use crypto::publickey::{Generator, Random}; use hash::keccak; use rustc_hex::FromHex; - use types::BlockNumber; + use crate::types::BlockNumber; use crate::client::{ChainInfo, EachBlockWith, ImportSealedBlock, TestBlockChainClient}; use miner::{MinerService, PendingOrdering}; use test_helpers::{ dummy_engine_signer_with_address, generate_dummy_client, generate_dummy_client_with_spec, }; - use types::transaction::{Transaction, TypedTransaction}; + use crate::types::transaction::{Transaction, TypedTransaction}; #[test] fn should_prepare_block_to_seal() { diff --git a/crates/ethcore/src/miner/mod.rs b/crates/ethcore/src/miner/mod.rs index 6b4dacd6c..9e33e4fc1 100644 --- a/crates/ethcore/src/miner/mod.rs +++ b/crates/ethcore/src/miner/mod.rs @@ -40,7 +40,7 @@ use std::{ use bytes::Bytes; use ethcore_miner::pool::{local_transactions, QueueStatus, VerifiedTransaction}; use ethereum_types::{Address, H256, U256}; -use types::{ +use crate::types::{ block::Block, header::Header, receipt::RichReceipt, @@ -54,7 +54,7 @@ use crate::client::{ traits::ForceUpdateSealing, AccountData, BlockChain, BlockProducer, Nonce, ScheduleInfo, SealedBlockImporter, }; -use error::Error; +use crate::error::Error; use crate::state::StateInfo; /// Provides methods to verify incoming external transactions diff --git a/crates/ethcore/src/miner/pool_client.rs b/crates/ethcore/src/miner/pool_client.rs index 45bbe1f1d..59cc519bc 100644 --- a/crates/ethcore/src/miner/pool_client.rs +++ b/crates/ethcore/src/miner/pool_client.rs @@ -23,7 +23,7 @@ use ethcore_miner::{ service_transaction_checker::ServiceTransactionChecker, }; use ethereum_types::{Address, H256, U256}; -use types::{ +use crate::types::{ header::Header, transaction::{self, SignedTransaction, UnverifiedTransaction}, }; @@ -32,7 +32,7 @@ use call_contract::CallContract; use crate::client::{Balance, BlockId, BlockInfo, Nonce, TransactionId}; use crate::engines::EthEngine; use ethcore_miner::pool::client::BalanceClient; -use miner::{ +use crate::miner::{ self, cache::{Cache, CachedClient}, }; diff --git a/crates/ethcore/src/miner/stratum.rs b/crates/ethcore/src/miner/stratum.rs index f5683f76b..3205f423b 100644 --- a/crates/ethcore/src/miner/stratum.rs +++ b/crates/ethcore/src/miner/stratum.rs @@ -30,7 +30,7 @@ use ethcore_miner::work_notify::NotifyWork; use ethcore_stratum::PushWorkHandler; use ethcore_stratum::{Error as StratumServiceError, JobDispatcher, Stratum as StratumService}; use ethereum_types::{H256, H64, U256}; -use miner::{Miner, MinerService}; +use crate::miner::{Miner, MinerService}; use parking_lot::Mutex; use rlp::encode; diff --git a/crates/ethcore/src/pod_account.rs b/crates/ethcore/src/pod_account.rs index f40320ba4..3342104f0 100644 --- a/crates/ethcore/src/pod_account.rs +++ b/crates/ethcore/src/pod_account.rs @@ -32,7 +32,7 @@ use crate::state::Account; use std::{collections::BTreeMap, fmt}; use trie::TrieFactory; use triehash::sec_trie_root; -use types::account_diff::*; +use crate::types::account_diff::*; #[derive(Debug, Clone, PartialEq, Eq, Serialize)] /// An account, expressed as Plain-Old-Data (hence the name). @@ -219,7 +219,7 @@ mod test { use super::{diff_pod, PodAccount}; use ethereum_types::H256; use std::collections::BTreeMap; - use types::account_diff::*; + use crate::types::account_diff::*; #[test] fn existence() { diff --git a/crates/ethcore/src/pod_state.rs b/crates/ethcore/src/pod_state.rs index 8d7b346ae..b03bc6e1d 100644 --- a/crates/ethcore/src/pod_state.rs +++ b/crates/ethcore/src/pod_state.rs @@ -22,7 +22,7 @@ use itertools::Itertools; use crate::pod_account::{self, PodAccount}; use std::{collections::BTreeMap, fmt}; use triehash::sec_trie_root; -use types::state_diff::StateDiff; +use crate::types::state_diff::StateDiff; /// State of all accounts in the system expressed in Plain Old Data. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize)] @@ -106,7 +106,7 @@ mod test { use ethereum_types::H160; use crate::pod_account::PodAccount; use std::collections::BTreeMap; - use types::{account_diff::*, state_diff::*}; + use crate::types::{account_diff::*, state_diff::*}; #[test] fn create_delete() { diff --git a/crates/ethcore/src/snapshot/account.rs b/crates/ethcore/src/snapshot/account.rs index dd3b004d1..d76aba76f 100644 --- a/crates/ethcore/src/snapshot/account.rs +++ b/crates/ethcore/src/snapshot/account.rs @@ -26,7 +26,7 @@ use rlp::{Rlp, RlpStream}; use crate::snapshot::{Error, Progress}; use std::{collections::HashSet, sync::atomic::Ordering}; use trie::{Trie, TrieMut}; -use types::basic_account::BasicAccount; +use crate::types::basic_account::BasicAccount; // An empty account -- these were replaced with RLP null data for a space optimization in v1. const ACC_EMPTY: BasicAccount = BasicAccount { @@ -224,7 +224,7 @@ mod tests { use crate::account_db::{AccountDB, AccountDBMut}; use crate::snapshot::{tests::helpers::fill_storage, Progress}; use test_helpers::get_temp_state_db; - use types::basic_account::BasicAccount; + use crate::types::basic_account::BasicAccount; use ethereum_types::{Address, H256}; use hash::{keccak, KECCAK_EMPTY, KECCAK_NULL_RLP}; diff --git a/crates/ethcore/src/snapshot/block.rs b/crates/ethcore/src/snapshot/block.rs index 57004a756..03a45e922 100644 --- a/crates/ethcore/src/snapshot/block.rs +++ b/crates/ethcore/src/snapshot/block.rs @@ -21,7 +21,7 @@ use ethereum_types::{H256, U256}; use hash::keccak; use rlp::{DecoderError, Rlp, RlpStream}; use triehash::ordered_trie_root; -use types::{ +use crate::types::{ block::Block, header::Header, transaction::TypedTransaction, views::BlockView, BlockNumber, }; @@ -158,7 +158,7 @@ mod tests { use bytes::Bytes; use ethereum_types::{Address, H256, U256}; - use types::{ + use crate::types::{ block::Block, transaction::{Action, Transaction, TypedTransaction}, view, diff --git a/crates/ethcore/src/snapshot/consensus/authority.rs b/crates/ethcore/src/snapshot/consensus/authority.rs index 936ce0c2d..6a19c6045 100644 --- a/crates/ethcore/src/snapshot/consensus/authority.rs +++ b/crates/ethcore/src/snapshot/consensus/authority.rs @@ -36,7 +36,7 @@ use db::KeyValueDB; use ethereum_types::{H256, U256}; use itertools::{Itertools, Position}; use rlp::{Rlp, RlpStream}; -use types::{ +use crate::types::{ encoded, header::Header, ids::BlockId, receipt::TypedReceipt, transaction::TypedTransaction, BlockNumber, }; @@ -137,7 +137,7 @@ impl SnapshotComponents for PoaSnapshot { chain: BlockChain, db: Arc, manifest: &ManifestData, - ) -> Result, ::error::Error> { + ) -> Result, crate::error::Error> { Ok(Box::new(ChunkRebuilder { manifest: manifest.clone(), warp_target: None, @@ -198,7 +198,7 @@ impl ChunkRebuilder { last_verifier: &mut Option>>, transition_rlp: Rlp, engine: &dyn EthEngine, - ) -> Result { + ) -> Result { use crate::engines::ConstructedVerifier; // decode. @@ -260,7 +260,7 @@ impl Rebuilder for ChunkRebuilder { chunk: &[u8], engine: &dyn EthEngine, abort_flag: &AtomicBool, - ) -> Result<(), ::error::Error> { + ) -> Result<(), crate::error::Error> { let rlp = Rlp::new(chunk); let is_last_chunk: bool = rlp.val_at(0)?; let num_items = rlp.item_count()?; @@ -349,7 +349,7 @@ impl Rebuilder for ChunkRebuilder { } if is_last_chunk { - use types::block::Block; + use crate::types::block::Block; let last_rlp = rlp.at(num_items - 1)?; let block = Block { @@ -392,7 +392,7 @@ impl Rebuilder for ChunkRebuilder { Ok(()) } - fn finalize(&mut self, _engine: &dyn EthEngine) -> Result<(), ::error::Error> { + fn finalize(&mut self, _engine: &dyn EthEngine) -> Result<(), crate::error::Error> { if !self.had_genesis { return Err(Error::WrongChunkFormat("No genesis transition included.".into()).into()); } diff --git a/crates/ethcore/src/snapshot/consensus/mod.rs b/crates/ethcore/src/snapshot/consensus/mod.rs index 5b71597ca..6b591da99 100644 --- a/crates/ethcore/src/snapshot/consensus/mod.rs +++ b/crates/ethcore/src/snapshot/consensus/mod.rs @@ -22,7 +22,7 @@ use std::sync::{atomic::AtomicBool, Arc}; use crate::blockchain::{BlockChain, BlockChainDB}; use crate::engines::EthEngine; use crate::snapshot::{Error, ManifestData, Progress}; -use types::BlockNumber; +use crate::types::BlockNumber; use ethereum_types::H256; @@ -65,7 +65,7 @@ pub trait SnapshotComponents: Send { chain: BlockChain, db: Arc, manifest: &ManifestData, - ) -> Result, ::error::Error>; + ) -> Result, crate::error::Error>; /// Minimum supported snapshot version number. fn min_supported_version(&self) -> u64; @@ -85,12 +85,12 @@ pub trait Rebuilder: Send { chunk: &[u8], engine: &dyn EthEngine, abort_flag: &AtomicBool, - ) -> Result<(), ::error::Error>; + ) -> Result<(), crate::error::Error>; /// Finalize the restoration. Will be done after all chunks have been /// fed successfully. /// /// This should apply the necessary "glue" between chunks, /// and verify against the restored state. - fn finalize(&mut self, engine: &dyn EthEngine) -> Result<(), ::error::Error>; + fn finalize(&mut self, engine: &dyn EthEngine) -> Result<(), crate::error::Error>; } diff --git a/crates/ethcore/src/snapshot/consensus/work.rs b/crates/ethcore/src/snapshot/consensus/work.rs index 67b255a14..cdaa40440 100644 --- a/crates/ethcore/src/snapshot/consensus/work.rs +++ b/crates/ethcore/src/snapshot/consensus/work.rs @@ -38,7 +38,7 @@ use ethereum_types::H256; use rand::rngs::OsRng; use rlp::{Rlp, RlpStream}; use crate::snapshot::{block::AbridgedBlock, Error, ManifestData, Progress}; -use types::{encoded, BlockNumber}; +use crate::types::{encoded, BlockNumber}; /// Snapshot creation and restoration for PoW chains. /// This includes blocks from the head of the chain as a @@ -244,7 +244,7 @@ impl PowRebuilder { db: Arc, manifest: &ManifestData, snapshot_blocks: u64, - ) -> Result { + ) -> Result { Ok(PowRebuilder { chain: chain, db: db, @@ -372,7 +372,7 @@ impl Rebuilder for PowRebuilder { } /// Glue together any disconnected chunks and check that the chain is complete. - fn finalize(&mut self, _: &dyn EthEngine) -> Result<(), ::error::Error> { + fn finalize(&mut self, _: &dyn EthEngine) -> Result<(), crate::error::Error> { let mut batch = self.db.transaction(); for (first_num, first_hash) in self.disconnected.drain(..) { @@ -391,7 +391,7 @@ impl Rebuilder for PowRebuilder { self.chain.insert_epoch_transition( &mut batch, 0, - ::engines::EpochTransition { + crate::engines::EpochTransition { block_number: 0, block_hash: genesis_hash, proof: vec![], diff --git a/crates/ethcore/src/snapshot/error.rs b/crates/ethcore/src/snapshot/error.rs index 914f01d32..6670f5f95 100644 --- a/crates/ethcore/src/snapshot/error.rs +++ b/crates/ethcore/src/snapshot/error.rs @@ -18,7 +18,7 @@ use std::fmt; -use types::ids::BlockId; +use crate::types::ids::BlockId; use ethereum_types::H256; use ethtrie::TrieError; diff --git a/crates/ethcore/src/snapshot/io.rs b/crates/ethcore/src/snapshot/io.rs index b979c5942..420d8c273 100644 --- a/crates/ethcore/src/snapshot/io.rs +++ b/crates/ethcore/src/snapshot/io.rs @@ -207,7 +207,7 @@ impl PackedReader { /// Create a new `PackedReader` for the file at the given path. /// This will fail if any io errors are encountered or the file /// is not a valid packed snapshot. - pub fn new(path: &Path) -> Result, ::snapshot::error::Error> { + pub fn new(path: &Path) -> Result, crate::snapshot::error::Error> { let mut file = File::open(path)?; let file_len = file.metadata()?.len(); if file_len < 8 { @@ -246,7 +246,7 @@ impl PackedReader { }; if version > SNAPSHOT_VERSION { - return Err(::snapshot::error::Error::VersionNotSupported(version)); + return Err(crate::snapshot::error::Error::VersionNotSupported(version)); } let state: Vec = rlp.list_at(0 + start)?; @@ -302,7 +302,7 @@ pub struct LooseReader { impl LooseReader { /// Create a new `LooseReader` which will read the manifest and chunk data from /// the given directory. - pub fn new(mut dir: PathBuf) -> Result { + pub fn new(mut dir: PathBuf) -> Result { let mut manifest_buf = Vec::new(); dir.push("MANIFEST"); diff --git a/crates/ethcore/src/snapshot/mod.rs b/crates/ethcore/src/snapshot/mod.rs index de5efb6d4..71f7cd0b9 100644 --- a/crates/ethcore/src/snapshot/mod.rs +++ b/crates/ethcore/src/snapshot/mod.rs @@ -32,7 +32,7 @@ use std::{ use crate::account_db::{AccountDB, AccountDBMut}; use crate::blockchain::{BlockChain, BlockProvider}; use crate::engines::EthEngine; -use types::{header::Header, ids::BlockId}; +use crate::types::{header::Header, ids::BlockId}; use bytes::Bytes; use db::{DBValue, KeyValueDB}; @@ -60,7 +60,7 @@ pub use self::{ traits::SnapshotService, watcher::Watcher, }; -pub use types::{ +pub use crate::types::{ basic_account::BasicAccount, creation_status::CreationStatus, restoration_status::RestorationStatus, snapshot_manifest::ManifestData, }; @@ -447,7 +447,7 @@ impl StateRebuilder { } /// Feed an uncompressed state chunk into the rebuilder. - pub fn feed(&mut self, chunk: &[u8], flag: &AtomicBool) -> Result<(), ::error::Error> { + pub fn feed(&mut self, chunk: &[u8], flag: &AtomicBool) -> Result<(), crate::error::Error> { let rlp = Rlp::new(chunk); let mut pairs = Vec::with_capacity(rlp.item_count()?); diff --git a/crates/ethcore/src/snapshot/service.rs b/crates/ethcore/src/snapshot/service.rs index 11e375498..4703e7d13 100644 --- a/crates/ethcore/src/snapshot/service.rs +++ b/crates/ethcore/src/snapshot/service.rs @@ -40,7 +40,7 @@ use crate::engines::EthEngine; use crate::error::{Error, ErrorKind as SnapshotErrorKind}; use hash::keccak; use crate::snapshot::Error as SnapshotError; -use types::ids::BlockId; +use crate::types::ids::BlockId; use crate::io::IoChannel; @@ -126,7 +126,7 @@ impl Restoration { let components = params .engine .snapshot_components() - .ok_or_else(|| ::snapshot::Error::SnapshotsUnsupported)?; + .ok_or_else(|| crate::snapshot::Error::SnapshotsUnsupported)?; let secondary = components.rebuilder(chain, raw_db.clone(), &manifest)?; @@ -152,7 +152,7 @@ impl Restoration { let expected_len = snappy::decompressed_len(chunk)?; if expected_len > MAX_CHUNK_SIZE { trace!(target: "snapshot", "Discarding large chunk: {} vs {}", expected_len, MAX_CHUNK_SIZE); - return Err(::snapshot::Error::ChunkTooLarge.into()); + return Err(crate::snapshot::Error::ChunkTooLarge.into()); } let len = snappy::decompress_into(chunk, &mut self.snappy_buffer)?; @@ -180,7 +180,7 @@ impl Restoration { let expected_len = snappy::decompressed_len(chunk)?; if expected_len > MAX_CHUNK_SIZE { trace!(target: "snapshot", "Discarding large chunk: {} vs {}", expected_len, MAX_CHUNK_SIZE); - return Err(::snapshot::Error::ChunkTooLarge.into()); + return Err(crate::snapshot::Error::ChunkTooLarge.into()); } let len = snappy::decompress_into(chunk, &mut self.snappy_buffer)?; @@ -444,7 +444,7 @@ impl Service { let block = self .client .block(BlockId::Hash(parent_hash)) - .ok_or(::snapshot::error::Error::UnlinkedAncientBlockChain)?; + .ok_or(crate::snapshot::error::Error::UnlinkedAncientBlockChain)?; parent_hash = block.parent_hash(); let block_number = block.number(); @@ -490,7 +490,7 @@ impl Service { // We couldn't reach the targeted hash if parent_hash != target_hash { - return Err(::snapshot::error::Error::UnlinkedAncientBlockChain.into()); + return Err(crate::snapshot::error::Error::UnlinkedAncientBlockChain.into()); } // Update best ancient block in the Next Chain diff --git a/crates/ethcore/src/snapshot/tests/helpers.rs b/crates/ethcore/src/snapshot/tests/helpers.rs index f5236810e..f21ef7e7b 100644 --- a/crates/ethcore/src/snapshot/tests/helpers.rs +++ b/crates/ethcore/src/snapshot/tests/helpers.rs @@ -30,7 +30,7 @@ use crate::snapshot::{ io::{PackedReader, PackedWriter, SnapshotReader}, StateRebuilder, }; -use types::basic_account::BasicAccount; +use crate::types::basic_account::BasicAccount; use rand::Rng; use tempdir::TempDir; @@ -138,7 +138,7 @@ pub fn fill_storage(mut db: AccountDBMut, root: &mut H256, seed: &mut H256) { /// Take a snapshot from the given client into a temporary file. /// Return a snapshot reader for it. pub fn snap(client: &Client) -> (Box, TempDir) { - use types::ids::BlockId; + use crate::types::ids::BlockId; let tempdir = TempDir::new("").unwrap(); let path = tempdir.path().join("file"); @@ -162,7 +162,7 @@ pub fn restore( engine: &dyn EthEngine, reader: &dyn SnapshotReader, genesis: &[u8], -) -> Result<(), ::error::Error> { +) -> Result<(), crate::error::Error> { use std::sync::atomic::AtomicBool; let flag = AtomicBool::new(true); diff --git a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs index 89f3e0bd7..8d480b0c5 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -25,7 +25,7 @@ use crate::snapshot::tests::helpers as snapshot_helpers; use crate::spec::Spec; use tempdir::TempDir; use test_helpers::generate_dummy_client_with_spec; -use types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; +use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; use ethereum_types::Address; use test_helpers; diff --git a/crates/ethcore/src/snapshot/tests/service.rs b/crates/ethcore/src/snapshot/tests/service.rs index 8f3a0bfee..df7cb9697 100644 --- a/crates/ethcore/src/snapshot/tests/service.rs +++ b/crates/ethcore/src/snapshot/tests/service.rs @@ -31,7 +31,7 @@ use tempdir::TempDir; use test_helpers::{ generate_dummy_client_with_spec_and_data, new_db, new_temp_db, restoration_db_handler, }; -use types::ids::BlockId; +use crate::types::ids::BlockId; use crate::io::IoChannel; use kvdb_rocksdb::DatabaseConfig; diff --git a/crates/ethcore/src/snapshot/tests/state.rs b/crates/ethcore/src/snapshot/tests/state.rs index 185bf0dfa..d70210303 100644 --- a/crates/ethcore/src/snapshot/tests/state.rs +++ b/crates/ethcore/src/snapshot/tests/state.rs @@ -27,7 +27,7 @@ use crate::snapshot::{ io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, Error as SnapshotError, Progress, StateRebuilder, SNAPSHOT_SUBPARTS, }; -use types::basic_account::BasicAccount; +use crate::types::basic_account::BasicAccount; use error::{Error, ErrorKind}; diff --git a/crates/ethcore/src/snapshot/watcher.rs b/crates/ethcore/src/snapshot/watcher.rs index 8d09a9ef1..1a54e25b5 100644 --- a/crates/ethcore/src/snapshot/watcher.rs +++ b/crates/ethcore/src/snapshot/watcher.rs @@ -18,7 +18,7 @@ use crate::client::{BlockInfo, ChainNotify, Client, ClientIoMessage, NewBlocks}; use parking_lot::Mutex; -use types::ids::BlockId; +use crate::types::ids::BlockId; use ethereum_types::H256; use crate::io::IoChannel; diff --git a/crates/ethcore/src/spec/spec.rs b/crates/ethcore/src/spec/spec.rs index 0ad98502a..c645426a9 100644 --- a/crates/ethcore/src/spec/spec.rs +++ b/crates/ethcore/src/spec/spec.rs @@ -31,7 +31,7 @@ use hash::{keccak, KECCAK_NULL_RLP}; use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use rustc_hex::FromHex; -use types::{header::Header, BlockNumber}; +use crate::types::{header::Header, BlockNumber}; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; use builtin::Builtin; @@ -39,12 +39,12 @@ use crate::engines::{ AuthorityRound, BasicAuthority, Clique, EthEngine, HoneyBadgerBFT, InstantSeal, InstantSealParams, NullEngine, DEFAULT_BLOCKHASH_CONTRACT, }; -use error::Error; +use crate::error::Error; use crate::executive::Executive; use crate::factory::Factories; use crate::machine::EthereumMachine; use maplit::btreeset; -use pod_state::PodState; +use crate::pod_state::PodState; use crate::spec::{seal::Generic as GenericSeal, Genesis}; use crate::state::{backend::Basic as BasicBackend, Backend, State, Substate}; use crate::trace::{NoopTracer, NoopVMTracer}; @@ -791,7 +791,7 @@ impl Spec { } } - Arc::new(::ethereum::Ethash::new( + Arc::new(crate::ethereum::Ethash::new( spec_params.cache_dir, ethash.params.into(), machine, @@ -1061,7 +1061,7 @@ impl Spec { /// initialize genesis epoch data, using in-memory database for /// constructor. pub fn genesis_epoch_data(&self) -> Result, String> { - use types::transaction::{Action, Transaction, TypedTransaction}; + use crate::types::transaction::{Action, Transaction, TypedTransaction}; let genesis = self.genesis_header(); @@ -1099,7 +1099,7 @@ impl Spec { }) .fake_sign(from); - let res = ::state::prove_transaction_virtual( + let res = crate::state::prove_transaction_virtual( db.as_hash_db_mut(), *genesis.state_root(), &tx, @@ -1241,7 +1241,7 @@ mod tests { use std::str::FromStr; use tempdir::TempDir; use test_helpers::get_temp_state_db; - use types::{view, views::BlockView}; + use crate::types::{view, views::BlockView}; #[test] fn test_load_empty() { diff --git a/crates/ethcore/src/state/account.rs b/crates/ethcore/src/state/account.rs index 95273db99..380157082 100644 --- a/crates/ethcore/src/state/account.rs +++ b/crates/ethcore/src/state/account.rs @@ -33,7 +33,7 @@ use std::{ sync::Arc, }; use trie::{Recorder, Trie}; -use types::basic_account::BasicAccount; +use crate::types::basic_account::BasicAccount; use std::cell::{Cell, RefCell}; diff --git a/crates/ethcore/src/state/mod.rs b/crates/ethcore/src/state/mod.rs index e46544978..d6de6197c 100644 --- a/crates/ethcore/src/state/mod.rs +++ b/crates/ethcore/src/state/mod.rs @@ -36,7 +36,7 @@ use crate::pod_account::*; use crate::pod_state::{self, PodState}; use crate::state_db::StateDB; use crate::trace::{self, FlatTrace, VMTrace}; -use types::{ +use crate::types::{ basic_account::BasicAccount, receipt::{LegacyReceipt, TransactionOutcome, TypedReceipt}, state_diff::StateDiff, @@ -1584,7 +1584,7 @@ mod tests { use std::{str::FromStr, sync::Arc}; use test_helpers::{get_temp_state, get_temp_state_db}; use crate::trace::{trace, FlatTrace, TraceError}; - use types::transaction::*; + use crate::types::transaction::*; use vm::EnvInfo; fn secret() -> Secret { diff --git a/crates/ethcore/src/state/substate.rs b/crates/ethcore/src/state/substate.rs index a91dabbbe..3c61c4265 100644 --- a/crates/ethcore/src/state/substate.rs +++ b/crates/ethcore/src/state/substate.rs @@ -19,7 +19,7 @@ use super::CleanupMode; use ethereum_types::Address; use evm::{CleanDustMode, Schedule}; use std::collections::HashSet; -use types::log_entry::LogEntry; +use crate::types::log_entry::LogEntry; use vm::access_list::AccessList; /// State changes which should be applied in finalize, @@ -89,7 +89,7 @@ impl Substate { mod tests { use super::Substate; use ethereum_types::Address; - use types::log_entry::LogEntry; + use crate::types::log_entry::LogEntry; #[test] fn created() { diff --git a/crates/ethcore/src/state_db.rs b/crates/ethcore/src/state_db.rs index a9975d4e8..cd9ab1ff7 100644 --- a/crates/ethcore/src/state_db.rs +++ b/crates/ethcore/src/state_db.rs @@ -30,7 +30,7 @@ use kvdb::{DBTransaction, DBValue}; use lru_cache::LruCache; use memory_cache::MemoryLruCache; use parking_lot::Mutex; -use types::BlockNumber; +use crate::types::BlockNumber; use crate::state::{self, Account}; diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index 2269af7a9..b9bad211c 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -33,7 +33,7 @@ use kvdb_rocksdb::{self, Database, DatabaseConfig}; use parking_lot::RwLock; use rlp::{self, RlpStream}; use tempdir::TempDir; -use types::{ +use crate::types::{ encoded, header::Header, transaction::{Action, SignedTransaction, Transaction, TypedTransaction}, diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index c6ee7ae3a..a31dfb262 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -41,7 +41,7 @@ use test_helpers::{ get_good_dummy_block, get_good_dummy_block_seq, get_test_client_with_blocks, push_blocks_to_client, }; -use types::{ +use crate::types::{ data_format::DataFormat, filter::Filter, ids::BlockId, diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index 46953d076..3e698ca97 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -23,7 +23,7 @@ use crate::state::Substate; use std::sync::Arc; use test_helpers::get_temp_state_with_factory; use crate::trace::{NoopTracer, NoopVMTracer}; -use types::transaction::SYSTEM_ADDRESS; +use crate::types::transaction::SYSTEM_ADDRESS; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; use rustc_hex::FromHex; diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index 4d562ab6c..836fa1493 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -27,7 +27,7 @@ use crate::spec::*; use std::{str::FromStr, sync::Arc}; use test_helpers::{self, get_temp_state_db}; use crate::trace::{trace::Action::Reward, LocalizedTrace, RewardType}; -use types::{ +use crate::types::{ header::Header, transaction::{Action, Transaction, TypedTransaction}, view, diff --git a/crates/ethcore/src/trace/db.rs b/crates/ethcore/src/trace/db.rs index 5ceb56d01..5d1b7da04 100644 --- a/crates/ethcore/src/trace/db.rs +++ b/crates/ethcore/src/trace/db.rs @@ -23,7 +23,7 @@ use ethereum_types::{H256, H264}; use kvdb::DBTransaction; use parity_util_mem::MallocSizeOfExt; use parking_lot::RwLock; -use types::BlockNumber; +use crate::types::BlockNumber; use crate::trace::{ flat::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}, @@ -417,7 +417,7 @@ mod tests { AddressesFilter, Config, Database as TraceDatabase, DatabaseExtras, Filter, ImportRequest, LocalizedTrace, TraceDB, TraceError, }; - use types::BlockNumber; + use crate::types::BlockNumber; struct NoopExtras; diff --git a/crates/ethcore/src/trace/import.rs b/crates/ethcore/src/trace/import.rs index 6d13ff19a..dbe7362f9 100644 --- a/crates/ethcore/src/trace/import.rs +++ b/crates/ethcore/src/trace/import.rs @@ -16,7 +16,7 @@ //! Traces import request. use ethereum_types::H256; -use types::BlockNumber; +use crate::types::BlockNumber; use crate::trace::FlatBlockTraces; diff --git a/crates/ethcore/src/trace/mod.rs b/crates/ethcore/src/trace/mod.rs index 036a5245f..5163adda2 100644 --- a/crates/ethcore/src/trace/mod.rs +++ b/crates/ethcore/src/trace/mod.rs @@ -45,7 +45,7 @@ pub use self::types::{ use ethereum_types::{Address, H256, U256}; use kvdb::DBTransaction; -use types::BlockNumber; +use crate::types::BlockNumber; use vm::{ActionParams, Error as VmError}; /// This trait is used by executive to build traces. diff --git a/crates/ethcore/src/trace/types/localized.rs b/crates/ethcore/src/trace/types/localized.rs index 8392a33d7..35141c99b 100644 --- a/crates/ethcore/src/trace/types/localized.rs +++ b/crates/ethcore/src/trace/types/localized.rs @@ -18,7 +18,7 @@ use super::trace::{Action, Res}; use ethereum_types::H256; -use types::BlockNumber; +use crate::types::BlockNumber; /// Localized trace. #[derive(Debug, PartialEq, Clone)] diff --git a/crates/ethcore/src/transaction_ext.rs b/crates/ethcore/src/transaction_ext.rs index d86f09582..041b37349 100644 --- a/crates/ethcore/src/transaction_ext.rs +++ b/crates/ethcore/src/transaction_ext.rs @@ -17,7 +17,7 @@ //! Ethereum transaction use evm::Schedule; -use types::transaction::{self, Action}; +use crate::types::transaction::{self, Action}; /// Extends transaction with gas verification method. pub trait Transaction { diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 04bd3d98e..6a260db9d 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -28,7 +28,7 @@ use crate::client::{BlockId, BlockInfo}; use hash::KECCAK_EMPTY; use parking_lot::Mutex; use crate::spec::CommonParams; -use types::{ +use crate::types::{ transaction::{Action, SignedTransaction}, BlockNumber, }; @@ -289,7 +289,7 @@ mod test { use std::{str::FromStr, sync::Arc}; use tempdir::TempDir; use test_helpers; - use types::transaction::{ + use crate::types::transaction::{ AccessListTx, Action, EIP1559TransactionTx, Transaction, TypedTransaction, }; diff --git a/crates/ethcore/src/verification/canon_verifier.rs b/crates/ethcore/src/verification/canon_verifier.rs index 8e9dc6cb6..d3f5b667a 100644 --- a/crates/ethcore/src/verification/canon_verifier.rs +++ b/crates/ethcore/src/verification/canon_verifier.rs @@ -20,8 +20,8 @@ use super::{verification, Verifier}; use call_contract::CallContract; use crate::client::BlockInfo; use crate::engines::EthEngine; -use error::Error; -use types::header::Header; +use crate::error::Error; +use crate::types::header::Header; /// A canonial verifier -- this does full verification. pub struct CanonVerifier; diff --git a/crates/ethcore/src/verification/noop_verifier.rs b/crates/ethcore/src/verification/noop_verifier.rs index 6451d7522..8ec0d7f2e 100644 --- a/crates/ethcore/src/verification/noop_verifier.rs +++ b/crates/ethcore/src/verification/noop_verifier.rs @@ -20,8 +20,8 @@ use super::{verification, Verifier}; use call_contract::CallContract; use crate::client::BlockInfo; use crate::engines::EthEngine; -use error::Error; -use types::header::Header; +use crate::error::Error; +use crate::types::header::Header; /// A no-op verifier -- this will verify everything it's given immediately. #[allow(dead_code)] diff --git a/crates/ethcore/src/verification/queue/kind.rs b/crates/ethcore/src/verification/queue/kind.rs index 6ec9b3d0c..75f544e02 100644 --- a/crates/ethcore/src/verification/queue/kind.rs +++ b/crates/ethcore/src/verification/queue/kind.rs @@ -17,7 +17,7 @@ //! Definition of valid items for the verification queue. use crate::engines::EthEngine; -use error::Error; +use crate::error::Error; use ethereum_types::{H256, U256}; use parity_util_mem::MallocSizeOf; @@ -79,8 +79,8 @@ pub mod blocks { use super::{BlockLike, Kind}; use crate::engines::EthEngine; - use error::{BlockError, Error, ErrorKind}; - use types::{ + use crate::error::{BlockError, Error, ErrorKind}; + use crate::types::{ header::Header, transaction::{TypedTransaction, UnverifiedTransaction}, BlockNumber, @@ -214,8 +214,8 @@ pub mod headers { use super::{BlockLike, Kind}; use crate::engines::EthEngine; - use error::Error; - use types::header::Header; + use crate::error::Error; + use crate::types::header::Header; use crate::verification::verify_header_params; use ethereum_types::{H256, U256}; diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index d96677bfd..e12d5e3af 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -20,7 +20,7 @@ use crate::blockchain::BlockChain; use crate::client::ClientIoMessage; use crate::engines::EthEngine; -use error::{BlockError, Error, ErrorKind, ImportErrorKind}; +use crate::error::{BlockError, Error, ErrorKind, ImportErrorKind}; use ethereum_types::{H256, U256}; use crate::io::*; use len_caching_lock::LenCachingMutex; @@ -39,7 +39,7 @@ use std::{ use self::kind::{BlockLike, Kind}; -pub use types::verification_queue_info::VerificationQueueInfo as QueueInfo; +pub use crate::types::verification_queue_info::VerificationQueueInfo as QueueInfo; pub mod kind; @@ -126,7 +126,7 @@ pub enum Status { impl Into<::types::block_status::BlockStatus> for Status { fn into(self) -> ::types::block_status::BlockStatus { - use types::block_status::BlockStatus; + use crate::types::block_status::BlockStatus; match self { Status::Queued => BlockStatus::Queued, Status::Bad => BlockStatus::Bad, @@ -876,7 +876,7 @@ mod tests { use crate::io::*; use crate::spec::Spec; use test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; - use types::{view, views::BlockView, BlockNumber}; + use crate::types::{view, views::BlockView, BlockNumber}; // create a test block queue. // auto_scaling enables verifier adjustment. diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index 9f28cef0b..05f15ffc6 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -37,8 +37,8 @@ use crate::blockchain::*; use call_contract::CallContract; use crate::client::BlockInfo; use crate::engines::{EthEngine, MAX_UNCLE_AGE}; -use error::{BlockError, Error}; -use types::{header::Header, transaction::SignedTransaction, BlockNumber}; +use crate::error::{BlockError, Error}; +use crate::types::{header::Header, transaction::SignedTransaction, BlockNumber}; use crate::verification::queue::kind::blocks::Unverified; use time_utils::CheckedSystemTime; @@ -554,7 +554,7 @@ mod tests { }; use test_helpers::{create_test_block, create_test_block_with_data}; use triehash::ordered_trie_root; - use types::{ + use crate::types::{ encoded, log_entry::{LocalizedLogEntry, LogEntry}, transaction::{Action, SignedTransaction, Transaction, TypedTransaction}, @@ -1127,7 +1127,7 @@ mod tests { use crypto::publickey::{Generator, Random}; use crate::engines::NullEngine; use crate::machine::EthereumMachine; - use types::transaction::{Action, Transaction}; + use crate::types::transaction::{Action, Transaction}; let mut params = CommonParams::default(); params.dust_protection_transition = 0; diff --git a/crates/ethcore/src/verification/verifier.rs b/crates/ethcore/src/verification/verifier.rs index f06495b68..13aca31c1 100644 --- a/crates/ethcore/src/verification/verifier.rs +++ b/crates/ethcore/src/verification/verifier.rs @@ -20,8 +20,8 @@ use super::verification; use call_contract::CallContract; use crate::client::BlockInfo; use crate::engines::EthEngine; -use error::Error; -use types::header::Header; +use crate::error::Error; +use crate::types::header::Header; /// Should be used to verify blocks. pub trait Verifier: Send + Sync diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index c71ddcdee..48388e2d4 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -50,7 +50,7 @@ use std::{ str::FromStr, }; use sync_io::{NetSyncIo, SyncIo}; -use types::{ +use crate::types::{ creation_status::CreationStatus, restoration_status::RestorationStatus, transaction::UnverifiedTransaction, BlockNumber, }; diff --git a/crates/ethcore/sync/src/block_sync.rs b/crates/ethcore/sync/src/block_sync.rs index 6f366294d..335b44c10 100644 --- a/crates/ethcore/sync/src/block_sync.rs +++ b/crates/ethcore/sync/src/block_sync.rs @@ -33,7 +33,7 @@ use std::cmp; /// use std::collections::{BTreeMap, HashSet, VecDeque}; use sync_io::SyncIo; -use types::BlockNumber; +use crate::types::BlockNumber; const MAX_HEADERS_TO_REQUEST: usize = 128; const MAX_BODIES_TO_REQUEST_LARGE: usize = 128; @@ -804,7 +804,7 @@ mod tests { use rlp::{encode_list, RlpStream}; use tests::{helpers::TestIo, snapshot::TestSnapshotService}; use triehash_ethereum::ordered_trie_root; - use types::{ + use crate::types::{ header::Header as BlockHeader, transaction::{SignedTransaction, Transaction, TypedTransaction}, }; diff --git a/crates/ethcore/sync/src/blocks.rs b/crates/ethcore/sync/src/blocks.rs index 9c5d28f95..ad23435ac 100644 --- a/crates/ethcore/sync/src/blocks.rs +++ b/crates/ethcore/sync/src/blocks.rs @@ -23,7 +23,7 @@ use parity_util_mem::MallocSizeOf; use rlp::{DecoderError, Rlp, RlpStream}; use std::collections::{hash_map, BTreeMap, HashMap, HashSet}; use triehash_ethereum::ordered_trie_root; -use types::{ +use crate::types::{ header::Header as BlockHeader, transaction::{TypedTransaction, UnverifiedTransaction}, BlockNumber, @@ -626,7 +626,7 @@ mod test { verification::queue::kind::blocks::Unverified, }; use rlp::*; - use types::BlockNumber; + use crate::types::BlockNumber; fn is_empty(bc: &BlockCollection) -> bool { bc.heads.is_empty() diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index afafa0419..a297100a7 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -30,7 +30,7 @@ use rlp::Rlp; use crate::snapshot::ChunkType; use std::{cmp, mem, time::Instant}; use sync_io::SyncIo; -use types::{block_status::BlockStatus, ids::BlockId, BlockNumber}; +use crate::types::{block_status::BlockStatus, ids::BlockId, BlockNumber}; use super::{ request_id::strip_request_id, diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 9d62955a3..c1891ed68 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -128,7 +128,7 @@ use std::{ }; use sync_io::SyncIo; use transactions_stats::{Stats as TransactionStats, TransactionsStats}; -use types::{block_status, transaction::UnverifiedTransaction, BlockNumber}; +use crate::types::{block_status, transaction::UnverifiedTransaction, BlockNumber}; use self::{ handler::SyncHandler, @@ -1874,7 +1874,7 @@ pub mod tests { use rlp::{Rlp, RlpStream}; use std::collections::VecDeque; use tests::{helpers::TestIo, snapshot::TestSnapshotService}; - use types::header::Header; + use crate::types::header::Header; use SyncConfig; pub fn get_dummy_block(order: u32, parent_hash: H256) -> Bytes { diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index f67627b5e..11052add6 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -27,7 +27,7 @@ use network::{client_version::ClientCapabilities, PeerId}; use rand::RngCore; use rlp::RlpStream; use sync_io::SyncIo; -use types::{blockchain_info::BlockChainInfo, transaction::SignedTransaction, BlockNumber}; +use crate::types::{blockchain_info::BlockChainInfo, transaction::SignedTransaction, BlockNumber}; use crate::chain::propagator_statistics::SyncPropagatorStatistics; @@ -518,7 +518,7 @@ mod tests { use rlp::Rlp; use std::collections::VecDeque; use tests::{helpers::TestIo, snapshot::TestSnapshotService}; - use types::transaction::TypedTransaction; + use crate::types::transaction::TypedTransaction; use super::{ super::{tests::*, *}, diff --git a/crates/ethcore/sync/src/chain/requester.rs b/crates/ethcore/sync/src/chain/requester.rs index 0d49ed1bb..4b15d260a 100644 --- a/crates/ethcore/sync/src/chain/requester.rs +++ b/crates/ethcore/sync/src/chain/requester.rs @@ -22,7 +22,7 @@ use network::PeerId; use rlp::RlpStream; use std::time::Instant; use sync_io::SyncIo; -use types::BlockNumber; +use crate::types::BlockNumber; use super::{ request_id::generate_request_id, diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index b04ee8bb3..e32fde415 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -27,7 +27,7 @@ use network::{self, PeerId}; use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use std::cmp; -use types::{ids::BlockId, BlockNumber}; +use crate::types::{ids::BlockId, BlockNumber}; use sync_io::SyncIo; diff --git a/crates/ethcore/sync/src/sync_io.rs b/crates/ethcore/sync/src/sync_io.rs index fd811e469..3d7dde93e 100644 --- a/crates/ethcore/sync/src/sync_io.rs +++ b/crates/ethcore/sync/src/sync_io.rs @@ -22,7 +22,7 @@ use network::{ }; use parking_lot::RwLock; use std::collections::HashMap; -use types::BlockNumber; +use crate::types::BlockNumber; /// IO interface for the syncing handler. /// Provides peer connection management and an interface to the blockchain client. diff --git a/crates/ethcore/sync/src/tests/consensus.rs b/crates/ethcore/sync/src/tests/consensus.rs index 7c70b7e47..34d8dd919 100644 --- a/crates/ethcore/sync/src/tests/consensus.rs +++ b/crates/ethcore/sync/src/tests/consensus.rs @@ -26,7 +26,7 @@ use ethereum_types::{Address, U256}; use hash::keccak; use crate::io::{IoChannel, IoHandler}; use std::sync::Arc; -use types::transaction::{Action, PendingTransaction, Transaction, TypedTransaction}; +use crate::types::transaction::{Action, PendingTransaction, Transaction, TypedTransaction}; use SyncConfig; fn new_tx(secret: &Secret, nonce: U256, chain_id: u64) -> PendingTransaction { diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index aec61a7e5..667a0ee44 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -43,7 +43,7 @@ use std::{ use sync_io::SyncIo; use tests::snapshot::*; -use types::BlockNumber; +use crate::types::BlockNumber; use SyncConfig; pub trait FlushingBlockChainClient: BlockChainClient { diff --git a/crates/ethcore/sync/src/tests/snapshot.rs b/crates/ethcore/sync/src/tests/snapshot.rs index 9cc07c1b3..edd4096fd 100644 --- a/crates/ethcore/sync/src/tests/snapshot.rs +++ b/crates/ethcore/sync/src/tests/snapshot.rs @@ -24,7 +24,7 @@ use ethereum_types::H256; use hash::keccak; use parking_lot::Mutex; use std::{collections::HashMap, sync::Arc}; -use types::BlockNumber; +use crate::types::BlockNumber; use SyncConfig; use WarpSync; diff --git a/crates/ethcore/sync/src/transactions_stats.rs b/crates/ethcore/sync/src/transactions_stats.rs index 5b1b6f57c..ae5c65def 100644 --- a/crates/ethcore/sync/src/transactions_stats.rs +++ b/crates/ethcore/sync/src/transactions_stats.rs @@ -21,7 +21,7 @@ use std::{ collections::{HashMap, HashSet}, hash::BuildHasher, }; -use types::BlockNumber; +use crate::types::BlockNumber; type NodeId = H512; diff --git a/crates/ethcore/types/src/views/block.rs b/crates/ethcore/types/src/views/block.rs index 99994f057..0aceeaf43 100644 --- a/crates/ethcore/types/src/views/block.rs +++ b/crates/ethcore/types/src/views/block.rs @@ -44,7 +44,7 @@ impl<'a> BlockView<'a> { /// #[macro_use] /// extern crate common_types as types; /// - /// use types::views::{BlockView}; + /// use crate::types::views::{BlockView}; /// /// fn main() { /// let bytes : &[u8] = &[]; diff --git a/crates/ethcore/types/src/views/body.rs b/crates/ethcore/types/src/views/body.rs index 6772ccd6b..b7a1ee22d 100644 --- a/crates/ethcore/types/src/views/body.rs +++ b/crates/ethcore/types/src/views/body.rs @@ -42,7 +42,7 @@ impl<'a> BodyView<'a> { /// #[macro_use] /// extern crate common_types as types; /// - /// use types::views::{BodyView}; + /// use crate::types::views::{BodyView}; /// /// fn main() { /// let bytes : &[u8] = &[]; diff --git a/crates/ethcore/types/src/views/header.rs b/crates/ethcore/types/src/views/header.rs index 69f3175c7..b474def09 100644 --- a/crates/ethcore/types/src/views/header.rs +++ b/crates/ethcore/types/src/views/header.rs @@ -36,7 +36,7 @@ impl<'a> HeaderView<'a> { /// #[macro_use] /// extern crate common_types as types; /// - /// use types::views::{HeaderView}; + /// use crate::types::views::{HeaderView}; /// /// fn main() { /// let bytes : &[u8] = &[]; diff --git a/crates/net/network-devp2p/src/lib.rs b/crates/net/network-devp2p/src/lib.rs index e887b0361..8341c2b4c 100644 --- a/crates/net/network-devp2p/src/lib.rs +++ b/crates/net/network-devp2p/src/lib.rs @@ -26,7 +26,7 @@ //! use devp2p::NetworkService; //! use std::sync::Arc; //! use std::time::Duration; -//! use types::U64; +//! use crate::types::U64; //! //! struct MyHandler; //! diff --git a/crates/rpc-common/src/lib.rs b/crates/rpc-common/src/lib.rs index e14cfa337..5fe37a0db 100644 --- a/crates/rpc-common/src/lib.rs +++ b/crates/rpc-common/src/lib.rs @@ -16,4 +16,4 @@ mod types; -pub use types::bytes::Bytes; +pub use crate::types::bytes::Bytes; diff --git a/crates/rpc/src/v1/helpers/dispatch/full.rs b/crates/rpc/src/v1/helpers/dispatch/full.rs index 30daae085..8b26ea589 100644 --- a/crates/rpc/src/v1/helpers/dispatch/full.rs +++ b/crates/rpc/src/v1/helpers/dispatch/full.rs @@ -22,7 +22,7 @@ use ethcore::{ }; use ethereum_types::{Address, H256, U256}; use parking_lot::Mutex; -use types::transaction::{PendingTransaction, SignedTransaction}; +use crate::types::transaction::{PendingTransaction, SignedTransaction}; use jsonrpc_core::{ futures::{future, Future, IntoFuture}, diff --git a/crates/rpc/src/v1/helpers/dispatch/mod.rs b/crates/rpc/src/v1/helpers/dispatch/mod.rs index 34b77b04d..ac1950756 100644 --- a/crates/rpc/src/v1/helpers/dispatch/mod.rs +++ b/crates/rpc/src/v1/helpers/dispatch/mod.rs @@ -91,7 +91,7 @@ use ethcore::{client::BlockChainClient, miner::MinerService}; use ethereum_types::{Address, H256, H520, U256}; use ethkey::Password; use hash::keccak; -use types::{ +use crate::types::{ transaction::{PendingTransaction, SignedTransaction}, BlockNumber, }; diff --git a/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs b/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs index 8768ad641..4b61e3652 100644 --- a/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs +++ b/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs @@ -21,7 +21,7 @@ use jsonrpc_core::{ futures::{Async, Future, IntoFuture, Poll}, Error, Result, }; -use types::transaction::SignedTransaction; +use crate::types::transaction::SignedTransaction; use super::{Accounts, PostSign, SignWith, WithToken}; use v1::helpers::{errors, nonce, FilledTransactionRequest}; diff --git a/crates/rpc/src/v1/helpers/dispatch/signing.rs b/crates/rpc/src/v1/helpers/dispatch/signing.rs index 03f244ba7..4ab3345bf 100644 --- a/crates/rpc/src/v1/helpers/dispatch/signing.rs +++ b/crates/rpc/src/v1/helpers/dispatch/signing.rs @@ -21,7 +21,7 @@ use bytes::Bytes; use crypto::{publickey::Signature, DEFAULT_MAC}; use ethereum_types::{Address, H256, U256}; use jsonrpc_core::{Error, ErrorCode}; -use types::transaction::{ +use crate::types::transaction::{ AccessListTx, Action, EIP1559TransactionTx, SignedTransaction, Transaction, TypedTransaction, TypedTxId, }; diff --git a/crates/rpc/src/v1/helpers/errors.rs b/crates/rpc/src/v1/helpers/errors.rs index 94585e03c..8f98dc656 100644 --- a/crates/rpc/src/v1/helpers/errors.rs +++ b/crates/rpc/src/v1/helpers/errors.rs @@ -24,7 +24,7 @@ use ethcore::{ }; use jsonrpc_core::{Error, ErrorCode, Result as RpcResult, Value}; use rlp::DecoderError; -use types::{blockchain_info::BlockChainInfo, transaction::Error as TransactionError}; +use crate::types::{blockchain_info::BlockChainInfo, transaction::Error as TransactionError}; use v1::{impls::EthClientOptions, types::BlockNumber}; use vm::Error as VMError; diff --git a/crates/rpc/src/v1/helpers/fake_sign.rs b/crates/rpc/src/v1/helpers/fake_sign.rs index 70f4d6673..be6a2b6a2 100644 --- a/crates/rpc/src/v1/helpers/fake_sign.rs +++ b/crates/rpc/src/v1/helpers/fake_sign.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use std::cmp::min; -use types::transaction::{ +use crate::types::transaction::{ AccessListTx, Action, EIP1559TransactionTx, SignedTransaction, Transaction, TypedTransaction, TypedTxId, }; diff --git a/crates/rpc/src/v1/helpers/poll_filter.rs b/crates/rpc/src/v1/helpers/poll_filter.rs index 2c373399e..6b5379f17 100644 --- a/crates/rpc/src/v1/helpers/poll_filter.rs +++ b/crates/rpc/src/v1/helpers/poll_filter.rs @@ -22,7 +22,7 @@ use std::{ collections::{BTreeSet, HashSet, VecDeque}, sync::Arc, }; -use types::filter::Filter; +use crate::types::filter::Filter; use v1::types::Log; pub type BlockNumber = u64; diff --git a/crates/rpc/src/v1/impls/debug.rs b/crates/rpc/src/v1/impls/debug.rs index d2998d624..1d970e021 100644 --- a/crates/rpc/src/v1/impls/debug.rs +++ b/crates/rpc/src/v1/impls/debug.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use ethcore::client::BlockChainClient; -use types::{header::Header, transaction::LocalizedTransaction}; +use crate::types::{header::Header, transaction::LocalizedTransaction}; use jsonrpc_core::Result; use v1::{ diff --git a/crates/rpc/src/v1/impls/eth.rs b/crates/rpc/src/v1/impls/eth.rs index 23c60636e..a2e7563fd 100644 --- a/crates/rpc/src/v1/impls/eth.rs +++ b/crates/rpc/src/v1/impls/eth.rs @@ -37,7 +37,7 @@ use ethcore::{ use hash::keccak; use miner::external::ExternalMinerService; use sync::SyncProvider; -use types::{ +use crate::types::{ encoded, filter::Filter as EthcoreFilter, header::Header, @@ -562,7 +562,7 @@ fn check_known(client: &C, number: BlockNumber) -> Result<()> where C: BlockChainClient, { - use types::block_status::BlockStatus; + use crate::types::block_status::BlockStatus; let id = match number { BlockNumber::Pending => return Ok(()), diff --git a/crates/rpc/src/v1/impls/eth_filter.rs b/crates/rpc/src/v1/impls/eth_filter.rs index 417048a40..5df10fca1 100644 --- a/crates/rpc/src/v1/impls/eth_filter.rs +++ b/crates/rpc/src/v1/impls/eth_filter.rs @@ -27,7 +27,7 @@ use ethcore::{ }; use ethereum_types::{H256, U256}; use parking_lot::Mutex; -use types::filter::Filter as EthcoreFilter; +use crate::types::filter::Filter as EthcoreFilter; use jsonrpc_core::{ futures::{future, future::Either, Future}, diff --git a/crates/rpc/src/v1/impls/eth_pubsub.rs b/crates/rpc/src/v1/impls/eth_pubsub.rs index 3e042d933..f9f5952d2 100644 --- a/crates/rpc/src/v1/impls/eth_pubsub.rs +++ b/crates/rpc/src/v1/impls/eth_pubsub.rs @@ -44,7 +44,7 @@ use ethereum_types::H256; use parity_runtime::Executor; use parking_lot::RwLock; -use types::{encoded, filter::Filter as EthFilter}; +use crate::types::{encoded, filter::Filter as EthFilter}; type Client = Sink; diff --git a/crates/rpc/src/v1/impls/parity.rs b/crates/rpc/src/v1/impls/parity.rs index f03270fef..f12682d70 100644 --- a/crates/rpc/src/v1/impls/parity.rs +++ b/crates/rpc/src/v1/impls/parity.rs @@ -31,7 +31,7 @@ use ethstore::random_phrase; use jsonrpc_core::{futures::future, BoxFuture, Result}; use stats::PrometheusMetrics; use sync::{ManageNetwork, SyncProvider}; -use types::ids::BlockId; +use crate::types::ids::BlockId; use v1::{ helpers::{ self, diff --git a/crates/rpc/src/v1/impls/personal.rs b/crates/rpc/src/v1/impls/personal.rs index 0763443a9..05c023a52 100644 --- a/crates/rpc/src/v1/impls/personal.rs +++ b/crates/rpc/src/v1/impls/personal.rs @@ -22,7 +22,7 @@ use bytes::Bytes; use crypto::publickey::{public_to_address, recover, Signature}; use eip_712::{hash_structured_data, EIP712}; use ethereum_types::{Address, H160, H256, H520, U128}; -use types::transaction::{PendingTransaction, SignedTransaction}; +use crate::types::transaction::{PendingTransaction, SignedTransaction}; use jsonrpc_core::{ futures::{future, Future}, diff --git a/crates/rpc/src/v1/impls/signer.rs b/crates/rpc/src/v1/impls/signer.rs index 8d785f8ab..9098983d1 100644 --- a/crates/rpc/src/v1/impls/signer.rs +++ b/crates/rpc/src/v1/impls/signer.rs @@ -22,7 +22,7 @@ use crypto::publickey; use ethereum_types::{H520, U256}; use parity_runtime::Executor; use parking_lot::Mutex; -use types::transaction::{PendingTransaction, SignedTransaction, TypedTransaction}; +use crate::types::transaction::{PendingTransaction, SignedTransaction, TypedTransaction}; use jsonrpc_core::{ futures::{future, future::Either, Future, IntoFuture}, diff --git a/crates/rpc/src/v1/impls/traces.rs b/crates/rpc/src/v1/impls/traces.rs index c25ef7df0..4d499d8f1 100644 --- a/crates/rpc/src/v1/impls/traces.rs +++ b/crates/rpc/src/v1/impls/traces.rs @@ -23,7 +23,7 @@ use ethcore::client::{ TransactionId, }; use ethereum_types::H256; -use types::transaction::{SignedTransaction, TypedTransaction}; +use crate::types::transaction::{SignedTransaction, TypedTransaction}; use jsonrpc_core::Result; use v1::{ diff --git a/crates/rpc/src/v1/tests/eth.rs b/crates/rpc/src/v1/tests/eth.rs index 7c2b4e9fd..88f77b7ad 100644 --- a/crates/rpc/src/v1/tests/eth.rs +++ b/crates/rpc/src/v1/tests/eth.rs @@ -32,7 +32,7 @@ use crate::io::IoChannel; use miner::external::ExternalMiner; use parity_runtime::Runtime; use parking_lot::Mutex; -use types::ids::BlockId; +use crate::types::ids::BlockId; use jsonrpc_core::IoHandler; use v1::{ diff --git a/crates/rpc/src/v1/tests/helpers/miner_service.rs b/crates/rpc/src/v1/tests/helpers/miner_service.rs index 192e806f0..5abaaa3e8 100644 --- a/crates/rpc/src/v1/tests/helpers/miner_service.rs +++ b/crates/rpc/src/v1/tests/helpers/miner_service.rs @@ -39,7 +39,7 @@ use miner::pool::{ VerifiedTransaction, }; use parking_lot::{Mutex, RwLock}; -use types::{ +use crate::types::{ block::Block, header::Header, ids::BlockId, diff --git a/crates/rpc/src/v1/tests/mocked/eth.rs b/crates/rpc/src/v1/tests/mocked/eth.rs index f8d70097b..516e9d5a7 100644 --- a/crates/rpc/src/v1/tests/mocked/eth.rs +++ b/crates/rpc/src/v1/tests/mocked/eth.rs @@ -32,7 +32,7 @@ use parity_runtime::Runtime; use parking_lot::Mutex; use rustc_hex::{FromHex, ToHex}; use sync::SyncState; -use types::{ +use crate::types::{ ids::{BlockId, TransactionId}, log_entry::{LocalizedLogEntry, LogEntry}, receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome}, @@ -751,7 +751,7 @@ fn rpc_eth_transaction_count_by_number_pending() { #[test] fn rpc_eth_pending_transaction_by_hash() { use ethereum_types::H256; - use types::transaction::SignedTransaction; + use crate::types::transaction::SignedTransaction; let tester = EthTester::default(); { diff --git a/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs b/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs index e19768c27..3c5df6c87 100644 --- a/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs +++ b/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs @@ -116,7 +116,7 @@ fn should_subscribe_to_new_heads() { #[test] fn should_subscribe_to_logs() { use ethcore::client::BlockInfo; - use types::{ + use crate::types::{ ids::BlockId, log_entry::{LocalizedLogEntry, LogEntry}, }; diff --git a/crates/rpc/src/v1/tests/mocked/parity.rs b/crates/rpc/src/v1/tests/mocked/parity.rs index 861c9828f..a03095b25 100644 --- a/crates/rpc/src/v1/tests/mocked/parity.rs +++ b/crates/rpc/src/v1/tests/mocked/parity.rs @@ -21,7 +21,7 @@ use ethereum_types::{Address, BigEndianHash, Bloom, H256, U256}; use miner::pool::local_transactions::Status as LocalTransactionStatus; use std::{str::FromStr, sync::Arc}; use sync::ManageNetwork; -use types::{ +use crate::types::{ receipt::{LocalizedReceipt, TransactionOutcome}, transaction::TypedTxId, }; @@ -307,7 +307,7 @@ fn assert_txs_filtered(io: &IoHandler, filter: &str, expected: Vec #[test] fn rpc_parity_pending_transactions_with_filter() { - use types::transaction::{Action, Transaction, TypedTransaction}; + use crate::types::transaction::{Action, Transaction, TypedTransaction}; let deps = Dependencies::new(); let io = deps.default_client(); @@ -450,7 +450,7 @@ fn rpc_parity_transactions_stats() { #[test] fn rpc_parity_local_transactions() { - use types::transaction::{Transaction, TypedTransaction}; + use crate::types::transaction::{Transaction, TypedTransaction}; let deps = Dependencies::new(); let io = deps.default_client(); let tx = TypedTransaction::Legacy(Transaction { diff --git a/crates/rpc/src/v1/tests/mocked/parity_set.rs b/crates/rpc/src/v1/tests/mocked/parity_set.rs index d382644ac..45a2d5da0 100644 --- a/crates/rpc/src/v1/tests/mocked/parity_set.rs +++ b/crates/rpc/src/v1/tests/mocked/parity_set.rs @@ -178,7 +178,7 @@ fn rpc_parity_set_hash_content() { #[test] fn rpc_parity_remove_transaction() { - use types::transaction::{Action, Transaction, TypedTransaction}; + use crate::types::transaction::{Action, Transaction, TypedTransaction}; let miner = miner_service(); let client = client_service(); diff --git a/crates/rpc/src/v1/tests/mocked/personal.rs b/crates/rpc/src/v1/tests/mocked/personal.rs index eeaefed8f..4598e598e 100644 --- a/crates/rpc/src/v1/tests/mocked/personal.rs +++ b/crates/rpc/src/v1/tests/mocked/personal.rs @@ -25,7 +25,7 @@ use hash::keccak; use jsonrpc_core::IoHandler; use parity_runtime::Runtime; use parking_lot::Mutex; -use types::transaction::{Action, Transaction, TypedTransaction}; +use crate::types::transaction::{Action, Transaction, TypedTransaction}; use serde_json::to_value; use v1::{ diff --git a/crates/rpc/src/v1/tests/mocked/signer.rs b/crates/rpc/src/v1/tests/mocked/signer.rs index d35fdcde7..d05cb2eaa 100644 --- a/crates/rpc/src/v1/tests/mocked/signer.rs +++ b/crates/rpc/src/v1/tests/mocked/signer.rs @@ -22,7 +22,7 @@ use accounts::AccountProvider; use ethcore::client::TestBlockChainClient; use parity_runtime::Runtime; use parking_lot::Mutex; -use types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; +use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; use jsonrpc_core::IoHandler; use serde_json; diff --git a/crates/rpc/src/v1/tests/mocked/signing.rs b/crates/rpc/src/v1/tests/mocked/signing.rs index 64adfbf54..dae28d124 100644 --- a/crates/rpc/src/v1/tests/mocked/signing.rs +++ b/crates/rpc/src/v1/tests/mocked/signing.rs @@ -39,7 +39,7 @@ use ethereum_types::{Address, H256, H520, U256}; use parity_runtime::{Executor, Runtime}; use parking_lot::Mutex; use serde_json; -use types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; +use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; struct SigningTester { pub runtime: Runtime, diff --git a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs index b8ddbc603..f099b0ac7 100644 --- a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs +++ b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs @@ -21,7 +21,7 @@ use ethcore::client::TestBlockChainClient; use ethereum_types::{Address, U256}; use parity_runtime::Runtime; use parking_lot::Mutex; -use types::transaction::{Action, Transaction, TypedTransaction}; +use crate::types::transaction::{Action, Transaction, TypedTransaction}; use jsonrpc_core::IoHandler; use v1::{ diff --git a/crates/rpc/src/v1/types/block.rs b/crates/rpc/src/v1/types/block.rs index 0286e5272..b026000bd 100644 --- a/crates/rpc/src/v1/types/block.rs +++ b/crates/rpc/src/v1/types/block.rs @@ -18,7 +18,7 @@ use std::{collections::BTreeMap, ops::Deref}; use ethereum_types::{Bloom as H2048, H160, H256, U256}; use serde::{ser::Error, Serialize, Serializer}; -use types::{encoded::Header as EthHeader, BlockNumber}; +use crate::types::{encoded::Header as EthHeader, BlockNumber}; use v1::types::{Bytes, Transaction}; /// Block Transactions diff --git a/crates/rpc/src/v1/types/filter.rs b/crates/rpc/src/v1/types/filter.rs index 7e610e184..b7a056ea6 100644 --- a/crates/rpc/src/v1/types/filter.rs +++ b/crates/rpc/src/v1/types/filter.rs @@ -21,7 +21,7 @@ use serde::{ Deserialize, Deserializer, Serialize, Serializer, }; use serde_json::{from_value, Value}; -use types::{filter::Filter as EthFilter, ids::BlockId}; +use crate::types::{filter::Filter as EthFilter, ids::BlockId}; use v1::{ helpers::errors::invalid_params, @@ -177,7 +177,7 @@ mod tests { use ethereum_types::H256; use serde_json; use std::str::FromStr; - use types::{filter::Filter as EthFilter, ids::BlockId}; + use crate::types::{filter::Filter as EthFilter, ids::BlockId}; use v1::types::BlockNumber; #[test] diff --git a/crates/rpc/src/v1/types/log.rs b/crates/rpc/src/v1/types/log.rs index 72278ca5d..ec9a3266f 100644 --- a/crates/rpc/src/v1/types/log.rs +++ b/crates/rpc/src/v1/types/log.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use ethereum_types::{H160, H256, U256}; -use types::log_entry::{LocalizedLogEntry, LogEntry}; +use crate::types::log_entry::{LocalizedLogEntry, LogEntry}; use v1::types::Bytes; /// Log diff --git a/crates/rpc/src/v1/types/receipt.rs b/crates/rpc/src/v1/types/receipt.rs index b17f4fca7..c187d1b95 100644 --- a/crates/rpc/src/v1/types/receipt.rs +++ b/crates/rpc/src/v1/types/receipt.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use ethereum_types::{Bloom as H2048, H160, H256, U256, U64}; -use types::receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome, TypedReceipt}; +use crate::types::receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome, TypedReceipt}; use v1::types::Log; /// Receipt @@ -147,7 +147,7 @@ impl From for Receipt { mod tests { use ethereum_types::{Bloom, H256}; use serde_json; - use types::transaction::TypedTxId; + use crate::types::transaction::TypedTxId; use v1::types::{Log, Receipt}; #[test] diff --git a/crates/rpc/src/v1/types/trace.rs b/crates/rpc/src/v1/types/trace.rs index 7e055c542..89884fe65 100644 --- a/crates/rpc/src/v1/types/trace.rs +++ b/crates/rpc/src/v1/types/trace.rs @@ -23,7 +23,7 @@ use ethcore::{ }; use ethereum_types::{H160, H256, U256}; use serde::{ser::SerializeStruct, Serialize, Serializer}; -use types::{account_diff, state_diff}; +use crate::types::{account_diff, state_diff}; use vm; use v1::types::Bytes; diff --git a/crates/rpc/src/v1/types/transaction.rs b/crates/rpc/src/v1/types/transaction.rs index 85231b7f4..ebc330a23 100644 --- a/crates/rpc/src/v1/types/transaction.rs +++ b/crates/rpc/src/v1/types/transaction.rs @@ -20,7 +20,7 @@ use ethcore::{contract_address, CreateContractAddress}; use ethereum_types::{H160, H256, H512, U256, U64}; use miner; use serde::{ser::SerializeStruct, Serialize, Serializer}; -use types::transaction::{ +use crate::types::transaction::{ Action, LocalizedTransaction, PendingTransaction, SignedTransaction, TypedTransaction, TypedTxId, }; @@ -365,7 +365,7 @@ mod tests { use super::{LocalTransactionStatus, Transaction}; use ethereum_types::H256; use serde_json; - use types::transaction::TypedTxId; + use crate::types::transaction::TypedTxId; #[test] fn test_transaction_serialize() { diff --git a/crates/rpc/src/v1/types/transaction_access_list.rs b/crates/rpc/src/v1/types/transaction_access_list.rs index 810537e69..6dc7b7778 100644 --- a/crates/rpc/src/v1/types/transaction_access_list.rs +++ b/crates/rpc/src/v1/types/transaction_access_list.rs @@ -1,7 +1,7 @@ use ethereum_types::{H160, H256}; use serde::Serialize; use std::vec::Vec; -use types::transaction::AccessListItem as InnerAccessListItem; +use crate::types::transaction::AccessListItem as InnerAccessListItem; pub type AccessList = Vec; #[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)] diff --git a/crates/rpc/src/v1/types/transaction_condition.rs b/crates/rpc/src/v1/types/transaction_condition.rs index 55b1d613c..bf0c8759d 100644 --- a/crates/rpc/src/v1/types/transaction_condition.rs +++ b/crates/rpc/src/v1/types/transaction_condition.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use types::transaction; +use crate::types::transaction; /// Represents condition on minimum block number or block timestamp. #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] From d4ec6853ac12ed5c60611b8b842e1d38bcd4e502 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 23 Apr 2025 17:18:38 +0200 Subject: [PATCH 433/687] batch of rust 2025 changes --- crates/ethcore/src/client/client.rs | 4 +-- crates/ethcore/src/engines/block_reward.rs | 6 ++-- .../src/engines/hbbft/block_reward_hbbft.rs | 4 +-- .../src/engines/validator_set/contract.rs | 2 +- .../ethcore/src/engines/validator_set/mod.rs | 2 +- .../src/engines/validator_set/multi.rs | 2 +- .../engines/validator_set/safe_contract.rs | 32 +++++++++---------- .../src/engines/validator_set/simple_list.rs | 4 +-- .../ethcore/src/engines/validator_set/test.rs | 4 +-- crates/ethcore/src/executive.rs | 6 ++-- crates/ethcore/src/externalities.rs | 2 +- crates/ethcore/src/snapshot/tests/helpers.rs | 2 +- .../src/snapshot/tests/proof_of_work.rs | 2 +- crates/ethcore/src/state/account.rs | 4 +-- crates/ethcore/src/state/mod.rs | 2 +- crates/ethcore/src/test_helpers.rs | 4 +-- 16 files changed, 41 insertions(+), 41 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index a986f967c..1c8d2a49f 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -565,7 +565,7 @@ impl Importer { warn!(target: "client", "Service tx checker error: {:?}", e); bail!(e); } - Some(ref checker) => match checker.check(client, &t) { + Some(checker) => match checker.check(client, &t) { Ok(true) => {} Ok(false) => { let e = format!( @@ -3821,7 +3821,7 @@ mod tests { encoded::Block::new(new_block), Vec::new(), ExtrasInsert { - fork_choice: ::engines::ForkChoice::New, + fork_choice: crate::engines::ForkChoice::New, is_finalized: false, }, ); diff --git a/crates/ethcore/src/engines/block_reward.rs b/crates/ethcore/src/engines/block_reward.rs index 3093206f8..1f5e533dd 100644 --- a/crates/ethcore/src/engines/block_reward.rs +++ b/crates/ethcore/src/engines/block_reward.rs @@ -126,7 +126,7 @@ impl BlockRewardContract { let output = caller(self.kind.clone(), input) .map_err(Into::into) - .map_err(::engines::EngineError::FailedSystemCall)?; + .map_err(crate::engines::EngineError::FailedSystemCall)?; // since this is a non-constant call we can't use ethabi's function output // deserialization, sadness ensues. @@ -137,7 +137,7 @@ impl BlockRewardContract { let tokens = ethabi::decode(types, &output) .map_err(|err| err.to_string()) - .map_err(::engines::EngineError::FailedSystemCall)?; + .map_err(crate::engines::EngineError::FailedSystemCall)?; assert!(tokens.len() == 2); @@ -151,7 +151,7 @@ impl BlockRewardContract { .expect("type checked by ethabi::decode; qed"); if addresses.len() != rewards.len() { - return Err(::engines::EngineError::FailedSystemCall( + return Err(crate::engines::EngineError::FailedSystemCall( "invalid data returned by reward contract: both arrays must have the same size" .into(), ) diff --git a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs index 98d54202c..61e2cba4d 100644 --- a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs @@ -53,7 +53,7 @@ impl BlockRewardContract { let (input, decoder) = block_reward_contract::functions::reward::call(is_epoch_end); let output = caller(self.kind.clone(), input) .map_err(Into::into) - .map_err(::engines::EngineError::FailedSystemCall)?; + .map_err(crate::engines::EngineError::FailedSystemCall)?; match decoder.decode(&output) { Ok(_rewards_native) => {} @@ -67,6 +67,6 @@ impl BlockRewardContract { // let rewards_native = decoder // .decode(&output) // .map_err(|err| err.to_string()) - // .map_err(::engines::EngineError::FailedSystemCall)?; + // .map_err(crate::engines::EngineError::FailedSystemCall)?; } } diff --git a/crates/ethcore/src/engines/validator_set/contract.rs b/crates/ethcore/src/engines/validator_set/contract.rs index 1d4dd32fe..28a76454d 100644 --- a/crates/ethcore/src/engines/validator_set/contract.rs +++ b/crates/ethcore/src/engines/validator_set/contract.rs @@ -163,7 +163,7 @@ impl ValidatorSet for ValidatorContract { first: bool, header: &Header, aux: AuxiliaryData, - ) -> ::engines::EpochChange { + ) -> crate::engines::EpochChange { self.validators.signals_epoch_end(first, header, aux) } diff --git a/crates/ethcore/src/engines/validator_set/mod.rs b/crates/ethcore/src/engines/validator_set/mod.rs index a52114a5d..9dcd5673c 100644 --- a/crates/ethcore/src/engines/validator_set/mod.rs +++ b/crates/ethcore/src/engines/validator_set/mod.rs @@ -156,7 +156,7 @@ pub trait ValidatorSet: Send + Sync + 'static { first: bool, header: &Header, aux: AuxiliaryData, - ) -> ::engines::EpochChange; + ) -> crate::engines::EpochChange; /// Recover the validator set from the given proof, the block number, and /// whether this header is first in its set. diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index b9dce65b7..4b402cdb9 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -136,7 +136,7 @@ impl ValidatorSet for Multi { _first: bool, header: &Header, aux: AuxiliaryData, - ) -> ::engines::EpochChange { + ) -> crate::engines::EpochChange { let (set_block, set) = self.correct_set_by_number(header.number()); let first = set_block == header.number(); diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index 1718e696b..b390c0e26 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -64,7 +64,7 @@ struct StateProof { header: Header, } -impl ::engines::StateDependentProof for StateProof { +impl crate::engines::StateDependentProof for StateProof { fn generate_proof(&self, caller: &Call) -> Result, String> { prove_initial(self.contract_address, &self.header, caller) } @@ -148,7 +148,7 @@ fn check_first_proof( }) .fake_sign(from); - let res = ::state::check_proof( + let res = crate::state::check_proof( state_items, *old_header.state_root(), &tx, @@ -157,9 +157,9 @@ fn check_first_proof( ); match res { - ::state::ProvedExecution::BadProof => Err("Bad proof".into()), - ::state::ProvedExecution::Failed(e) => Err(format!("Failed call: {}", e)), - ::state::ProvedExecution::Complete(e) => { + crate::state::ProvedExecution::BadProof => Err("Bad proof".into()), + crate::state::ProvedExecution::Failed(e) => Err(format!("Failed call: {}", e)), + crate::state::ProvedExecution::Complete(e) => { decoder.decode(&e.output).map_err(|e| e.to_string()) } } @@ -409,7 +409,7 @@ impl ValidatorSet for ValidatorSafeContract { .decode(&x) .map_err(|x| format!("chain spec bug: could not decode: {:?}", x)) }) - .map_err(::engines::EngineError::FailedSystemCall)?; + .map_err(crate::engines::EngineError::FailedSystemCall)?; if !emit_initiate_change_callable { trace!(target: "engine", "New block #{} issued ― no need to call emitInitiateChange()", header.number()); } else { @@ -498,7 +498,7 @@ impl ValidatorSet for ValidatorSafeContract { let data = validator_set::functions::finalize_change::encode_input(); caller(self.contract_address, data) .map(|_| ()) - .map_err(::engines::EngineError::FailedSystemCall) + .map_err(crate::engines::EngineError::FailedSystemCall) .map_err(Into::into) } @@ -515,7 +515,7 @@ impl ValidatorSet for ValidatorSafeContract { first: bool, header: &Header, aux: AuxiliaryData, - ) -> ::engines::EpochChange { + ) -> crate::engines::EpochChange { let receipts = aux.receipts; // transition to the first block of a contract requires finality but has no log event. @@ -525,7 +525,7 @@ impl ValidatorSet for ValidatorSafeContract { contract_address: self.contract_address, header: header.clone(), }); - return ::engines::EpochChange::Yes(::engines::Proof::WithState(state_proof as Arc<_>)); + return crate::engines::EpochChange::Yes(crate::engines::Proof::WithState(state_proof as Arc<_>)); } // otherwise, we're checking for logs. @@ -533,21 +533,21 @@ impl ValidatorSet for ValidatorSafeContract { let header_bloom = header.log_bloom(); if &bloom & header_bloom != bloom { - return ::engines::EpochChange::No; + return crate::engines::EpochChange::No; } trace!(target: "engine", "detected epoch change event bloom"); match receipts { - None => ::engines::EpochChange::Unsure(AuxiliaryRequest::Receipts), + None => crate::engines::EpochChange::Unsure(AuxiliaryRequest::Receipts), Some(receipts) => match self.extract_from_event(bloom, header, receipts) { - None => ::engines::EpochChange::No, + None => crate::engines::EpochChange::No, Some(list) => { info!(target: "engine", "Signal for transition within contract. New list: {:?}", &*list); let proof = encode_proof(&header, receipts); - ::engines::EpochChange::Yes(::engines::Proof::Known(proof)) + crate::engines::EpochChange::Yes(crate::engines::Proof::Known(proof)) } }, } @@ -571,7 +571,7 @@ impl ValidatorSet for ValidatorSafeContract { let old_hash = old_header.hash(); let addresses = check_first_proof(machine, self.contract_address, old_header, &state_items) - .map_err(::engines::EngineError::InsufficientProof)?; + .map_err(crate::engines::EngineError::InsufficientProof)?; trace!(target: "engine", "extracted epoch set at #{}: {} addresses", number, addresses.len()); @@ -584,7 +584,7 @@ impl ValidatorSet for ValidatorSafeContract { // TODO: optimize? these were just decoded. let found_root = ::triehash::ordered_trie_root(receipts.iter().map(|r| r.encode())); if found_root != *old_header.receipts_root() { - return Err(::error::BlockError::InvalidReceiptsRoot(Mismatch { + return Err(crate::error::BlockError::InvalidReceiptsRoot(Mismatch { expected: *old_header.receipts_root(), found: found_root, }) @@ -595,7 +595,7 @@ impl ValidatorSet for ValidatorSafeContract { match self.extract_from_event(bloom, &old_header, &receipts) { Some(list) => Ok((list, Some(old_header.hash()))), - None => Err(::engines::EngineError::InsufficientProof( + None => Err(crate::engines::EngineError::InsufficientProof( "No log event in proof.".into(), ) .into()), diff --git a/crates/ethcore/src/engines/validator_set/simple_list.rs b/crates/ethcore/src/engines/validator_set/simple_list.rs index 31cdcdba9..265ac4590 100644 --- a/crates/ethcore/src/engines/validator_set/simple_list.rs +++ b/crates/ethcore/src/engines/validator_set/simple_list.rs @@ -90,8 +90,8 @@ impl ValidatorSet for SimpleList { _: bool, _: &Header, _: AuxiliaryData, - ) -> ::engines::EpochChange { - ::engines::EpochChange::No + ) -> crate::engines::EpochChange { + crate::engines::EpochChange::No } fn epoch_set( diff --git a/crates/ethcore/src/engines/validator_set/test.rs b/crates/ethcore/src/engines/validator_set/test.rs index 8542b6a90..ab77e894a 100644 --- a/crates/ethcore/src/engines/validator_set/test.rs +++ b/crates/ethcore/src/engines/validator_set/test.rs @@ -99,8 +99,8 @@ impl ValidatorSet for TestSet { _: bool, _: &Header, _: AuxiliaryData, - ) -> ::engines::EpochChange { - ::engines::EpochChange::No + ) -> crate::engines::EpochChange { + crate::engines::EpochChange::No } fn epoch_set( diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index 38b855d05..3d5956ca4 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -889,7 +889,7 @@ impl<'a> CallCreateExecutive<'a> { Some((_, exec)) => { let second_last = callstack.last_mut(); let parent_substate = match second_last { - Some((_, ref mut second_last)) => second_last.unconfirmed_substate().expect("Current stack value is created from second last item; second last item must be call or create; qed"), + Some((_, second_last)) => second_last.unconfirmed_substate().expect("Current stack value is created from second last item; second last item must be call or create; qed"), None => top_substate, }; @@ -926,7 +926,7 @@ impl<'a> CallCreateExecutive<'a> { let second_last = callstack.last_mut(); let parent_substate = match second_last { - Some((_, ref mut second_last)) => second_last.unconfirmed_substate().expect("Current stack value is created from second last item; second last item must be call or create; qed"), + Some((_, second_last)) => second_last.unconfirmed_substate().expect("Current stack value is created from second last item; second last item must be call or create; qed"), None => top_substate, }; @@ -958,7 +958,7 @@ impl<'a> CallCreateExecutive<'a> { let second_last = callstack.last_mut(); let parent_substate = match second_last { - Some((_, ref mut second_last)) => second_last.unconfirmed_substate().expect("Current stack value is created from second last item; second last item must be call or create; qed"), + Some((_, second_last)) => second_last.unconfirmed_substate().expect("Current stack value is created from second last item; second last item must be call or create; qed"), None => top_substate, }; diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index 3a50fd968..4cadf5ccb 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -214,7 +214,7 @@ where self.vm_tracer, ); let output = match &r { - Ok(ref r) => H256::from_slice(&r.return_data[..32]), + Ok(r) => H256::from_slice(&r.return_data[..32]), _ => H256::default(), }; trace!( diff --git a/crates/ethcore/src/snapshot/tests/helpers.rs b/crates/ethcore/src/snapshot/tests/helpers.rs index f21ef7e7b..3fef6ad23 100644 --- a/crates/ethcore/src/snapshot/tests/helpers.rs +++ b/crates/ethcore/src/snapshot/tests/helpers.rs @@ -102,7 +102,7 @@ impl StateProducer { let address_hash = H256(rng.r#gen()); let balance: usize = rng.r#gen(); let nonce: usize = rng.r#gen(); - let acc = ::state::Account::new_basic(balance.into(), nonce.into()).rlp(); + let acc = crate::state::Account::new_basic(balance.into(), nonce.into()).rlp(); trie.insert(&address_hash[..], &acc).unwrap(); } } diff --git a/crates/ethcore/src/snapshot/tests/proof_of_work.rs b/crates/ethcore/src/snapshot/tests/proof_of_work.rs index f4a656796..54d0f7438 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_work.rs @@ -66,7 +66,7 @@ fn chunk_and_restore(amount: u64) { block.encoded(), vec![], ExtrasInsert { - fork_choice: ::engines::ForkChoice::New, + fork_choice: crate::engines::ForkChoice::New, is_finalized: false, }, ); diff --git a/crates/ethcore/src/state/account.rs b/crates/ethcore/src/state/account.rs index 380157082..da6c09012 100644 --- a/crates/ethcore/src/state/account.rs +++ b/crates/ethcore/src/state/account.rs @@ -252,7 +252,7 @@ impl Account { return Ok(value); } match &self.original_storage_cache { - Some((ref original_storage_root, ref original_storage_cache)) => { + Some((original_storage_root, original_storage_cache)) => { Self::get_and_cache_storage( original_storage_root, &mut original_storage_cache.borrow_mut(), @@ -298,7 +298,7 @@ impl Account { /// Get cached original storage value after last state commitment. Returns `None` if the key is not in the cache. pub fn cached_original_storage_at(&self, key: &H256) -> Option { match &self.original_storage_cache { - Some((_, ref original_storage_cache)) => original_storage_cache + Some((_, original_storage_cache)) => original_storage_cache .borrow_mut() .get_mut(key) .map(|value| value.clone()), diff --git a/crates/ethcore/src/state/mod.rs b/crates/ethcore/src/state/mod.rs index d6de6197c..fbd8d9a9d 100644 --- a/crates/ethcore/src/state/mod.rs +++ b/crates/ethcore/src/state/mod.rs @@ -640,7 +640,7 @@ impl State { match checkpoint.get(address) { // The account exists at this checkpoint. Some(Some(AccountEntry { - account: Some(ref account), + account: Some(account), .. })) => { if let Some(value) = account.cached_storage_at(key) { diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index b9bad211c..3da2d918d 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -525,7 +525,7 @@ pub fn generate_dummy_blockchain(block_number: u32) -> BlockChain { encoded::Block::new(create_unverifiable_block(block_order, bc.best_block_hash())), vec![], ExtrasInsert { - fork_choice: ::engines::ForkChoice::New, + fork_choice: crate::engines::ForkChoice::New, is_finalized: false, }, ); @@ -557,7 +557,7 @@ pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> BlockChain { )), vec![], ExtrasInsert { - fork_choice: ::engines::ForkChoice::New, + fork_choice: crate::engines::ForkChoice::New, is_finalized: false, }, ); From ee7f6283ebb2779e4eafbd77a13bab11bbf51b19 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 27 Apr 2025 00:46:53 +0200 Subject: [PATCH 434/687] batch of rust 2025 changes --- crates/ethcore/src/client/client.rs | 8 ++++---- crates/ethcore/src/client/traits.rs | 2 +- crates/ethcore/src/engines/authority_round/mod.rs | 2 +- crates/ethcore/src/engines/null_engine.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 1c8d2a49f..a76e9e31e 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -27,10 +27,10 @@ use std::{ time::{Duration, Instant}, }; -use crate::blockchain::{ +use crate::{blockchain::{ BlockChain, BlockChainDB, BlockNumberKey, BlockProvider, BlockReceipts, ExtrasInsert, ImportRoute, TransactionAddress, TreeRoute, -}; +}, miner::Miner}; use bytes::{Bytes, ToPretty}; use call_contract::CallContract; use db::{DBTransaction, DBValue, KeyValueDB}; @@ -58,7 +58,7 @@ use crate::types::{ BlockNumber, }; use vm::{EnvInfo, LastHashes}; - +use crate::miner::MinerService; use ansi_term::Colour; use crate::block::{enact_verified, ClosedBlock, Drain, LockedBlock, OpenBlock, SealedBlock}; use call_contract::RegistryInfo; @@ -3292,7 +3292,7 @@ impl super::traits::EngineClient for Client { self.notify(|notify| notify.send(ChainMessageType::Consensus(message.clone()), node_id)); } - fn epoch_transition_for(&self, parent_hash: H256) -> Option<::engines::EpochTransition> { + fn epoch_transition_for(&self, parent_hash: H256) -> Option { self.chain.read().epoch_transition_for(parent_hash) } diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 63c763a4d..c3707523d 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -664,7 +664,7 @@ pub trait EngineClient: Sync + Send + ChainInfo { /// This will give the epoch that any children of this parent belong to. /// /// The block corresponding the the parent hash must be stored already. - fn epoch_transition_for(&self, parent_hash: H256) -> Option<::engines::EpochTransition>; + fn epoch_transition_for(&self, parent_hash: H256) -> Option; /// Attempt to cast the engine client to a full client. fn as_full_client(&self) -> Option<&dyn BlockChainClient>; diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index 5b3805c2f..c0b1a7fbb 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -2312,7 +2312,7 @@ impl Engine for AuthorityRound { if self.immediate_transitions { None } else { - Some(Box::new(::snapshot::PoaSnapshot)) + Some(Box::new(crate::snapshot::PoaSnapshot)) } } diff --git a/crates/ethcore/src/engines/null_engine.rs b/crates/ethcore/src/engines/null_engine.rs index bd124d7de..124535d08 100644 --- a/crates/ethcore/src/engines/null_engine.rs +++ b/crates/ethcore/src/engines/null_engine.rs @@ -118,7 +118,7 @@ impl Engine for NullEngine { } fn snapshot_components(&self) -> Option> { - Some(Box::new(::snapshot::PowSnapshot::new(10000, 10000))) + Some(Box::new(crate::snapshot::PowSnapshot::new(10000, 10000))) } fn fork_choice(&self, new: &ExtendedHeader, current: &ExtendedHeader) -> super::ForkChoice { diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index c1891ed68..ed3c3f097 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -475,7 +475,7 @@ impl ChainSyncApi { } /// Returns new transactions propagation statistics - pub fn new_transactions_stats(&self) -> BTreeMap { + pub fn new_transactions_stats(&self) -> BTreeMap { self.sync .read() .new_transactions_stats() @@ -530,7 +530,7 @@ impl ChainSyncApi { } // deadline to get the task from the queue - let deadline = Instant::now() + ::api::PRIORITY_TIMER_INTERVAL; + let deadline = Instant::now() + crate::api::PRIORITY_TIMER_INTERVAL; let mut work = || { let task = { let tasks = self.priority_tasks.try_lock_until(deadline)?; From 9c39a3db012ab67ca16b3035dc0adc850598c8d8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 27 Apr 2025 23:45:02 +0200 Subject: [PATCH 435/687] batch of rust 2025 changes --- crates/ethcore/sync/src/api.rs | 10 +++++----- crates/ethcore/sync/src/block_sync.rs | 4 ++-- crates/ethcore/sync/src/chain/handler.rs | 4 ++-- crates/ethcore/sync/src/chain/mod.rs | 8 ++++---- crates/ethcore/sync/src/chain/propagator.rs | 2 +- crates/ethcore/sync/src/chain/request_id.rs | 2 +- crates/ethcore/sync/src/chain/requester.rs | 2 +- crates/ethcore/sync/src/chain/supplier.rs | 4 ++-- crates/ethcore/sync/src/chain/sync_packet.rs | 2 +- crates/ethcore/sync/src/lib.rs | 4 ++-- crates/ethcore/sync/src/sync_io.rs | 2 +- crates/ethcore/sync/src/tests/chain.rs | 2 +- crates/ethcore/sync/src/tests/helpers.rs | 6 +++--- crates/ethcore/sync/src/transactions_stats.rs | 2 +- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 48388e2d4..6bdeb664e 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -30,26 +30,26 @@ use std::{ time::Duration, }; -use chain::{ +use crate::chain::{ fork_filter::ForkFilterApi, ChainSyncApi, SyncState, SyncStatus as EthSyncStatus, ETH_PROTOCOL_VERSION_63, ETH_PROTOCOL_VERSION_64, ETH_PROTOCOL_VERSION_65, ETH_PROTOCOL_VERSION_66, PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2, }; -use ethcore::{ +use crate::ethcore::{ client::{BlockChainClient, ChainMessageType, ChainNotify, NewBlocks}, snapshot::SnapshotService, }; use ethereum_types::{H256, H512, U256, U64}; use crate::io::TimerToken; -use network::IpFilter; +use crate::network::IpFilter; use parking_lot::{Mutex, RwLock}; -use stats::{PrometheusMetrics, PrometheusRegistry}; +use crate::stats::{PrometheusMetrics, PrometheusRegistry}; use std::{ net::{AddrParseError, SocketAddr}, str::FromStr, }; -use sync_io::{NetSyncIo, SyncIo}; +use crate::sync_io::{NetSyncIo, SyncIo}; use crate::types::{ creation_status::CreationStatus, restoration_status::RestorationStatus, transaction::UnverifiedTransaction, BlockNumber, diff --git a/crates/ethcore/sync/src/block_sync.rs b/crates/ethcore/sync/src/block_sync.rs index 335b44c10..f8aa9b508 100644 --- a/crates/ethcore/sync/src/block_sync.rs +++ b/crates/ethcore/sync/src/block_sync.rs @@ -16,7 +16,7 @@ // use std::backtrace::Backtrace; use crate::blocks::{BlockCollection, SyncBody, SyncHeader}; -use chain::BlockSet; +use crate::chain::BlockSet; use ethcore::{ client::{BlockId, BlockStatus}, error::{ @@ -32,7 +32,7 @@ use std::cmp; /// Blockchain downloader /// use std::collections::{BTreeMap, HashSet, VecDeque}; -use sync_io::SyncIo; +use crate::sync_io::SyncIo; use crate::types::BlockNumber; const MAX_HEADERS_TO_REQUEST: usize = 128; diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index a297100a7..9e161dbb2 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use api::{ETH_PROTOCOL, PAR_PROTOCOL}; +use crate::api::{ETH_PROTOCOL, PAR_PROTOCOL}; use crate::block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction}; use bytes::Bytes; use enum_primitive::FromPrimitive; @@ -29,7 +29,7 @@ use network::{client_version::ClientVersion, PeerId}; use rlp::Rlp; use crate::snapshot::ChunkType; use std::{cmp, mem, time::Instant}; -use sync_io::SyncIo; +use crate::sync_io::SyncIo; use crate::types::{block_status::BlockStatus, ids::BlockId, BlockNumber}; use super::{ diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index ed3c3f097..ed840defc 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -103,7 +103,7 @@ use self::{ propagator_statistics::SyncPropagatorStatistics, }; use super::{SyncConfig, WarpSync}; -use api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, ETH_PROTOCOL, PAR_PROTOCOL}; +use crate::api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, ETH_PROTOCOL, PAR_PROTOCOL}; use crate::block_sync::{BlockDownloader, DownloadAction}; use bytes::Bytes; use derive_more::Display; @@ -126,8 +126,8 @@ use std::{ sync::mpsc, time::{Duration, Instant}, }; -use sync_io::SyncIo; -use transactions_stats::{Stats as TransactionStats, TransactionsStats}; +use crate::sync_io::SyncIo; +use crate::transactions_stats::{Stats as TransactionStats, TransactionsStats}; use crate::types::{block_status, transaction::UnverifiedTransaction, BlockNumber}; use self::{ @@ -465,7 +465,7 @@ impl ChainSyncApi { } /// Returns pending transactions propagation statistics - pub fn pending_transactions_stats(&self) -> BTreeMap { + pub fn pending_transactions_stats(&self) -> BTreeMap { self.sync .read() .pending_transactions_stats() diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 11052add6..f50a058ef 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -26,7 +26,7 @@ use fastmap::H256FastSet; use network::{client_version::ClientCapabilities, PeerId}; use rand::RngCore; use rlp::RlpStream; -use sync_io::SyncIo; +use crate::sync_io::SyncIo; use crate::types::{blockchain_info::BlockChainInfo, transaction::SignedTransaction, BlockNumber}; use crate::chain::propagator_statistics::SyncPropagatorStatistics; diff --git a/crates/ethcore/sync/src/chain/request_id.rs b/crates/ethcore/sync/src/chain/request_id.rs index 29f24db8d..bbab579a5 100644 --- a/crates/ethcore/sync/src/chain/request_id.rs +++ b/crates/ethcore/sync/src/chain/request_id.rs @@ -1,5 +1,5 @@ use bytes::Bytes; -use chain::{ +use crate::chain::{ sync_packet::{PacketInfo, SyncPacket}, ChainSync, PeerInfo, }; diff --git a/crates/ethcore/sync/src/chain/requester.rs b/crates/ethcore/sync/src/chain/requester.rs index 4b15d260a..04b6d798e 100644 --- a/crates/ethcore/sync/src/chain/requester.rs +++ b/crates/ethcore/sync/src/chain/requester.rs @@ -21,7 +21,7 @@ use fastmap::H256FastSet; use network::PeerId; use rlp::RlpStream; use std::time::Instant; -use sync_io::SyncIo; +use crate::sync_io::SyncIo; use crate::types::BlockNumber; use super::{ diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index e32fde415..9330a81b9 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -29,7 +29,7 @@ use rlp::{Rlp, RlpStream}; use std::cmp; use crate::types::{ids::BlockId, BlockNumber}; -use sync_io::SyncIo; +use crate::sync_io::SyncIo; use super::{ request_id::{prepend_request_id, strip_request_id, RequestId}, @@ -40,7 +40,7 @@ use super::{ ChainSync, PacketProcessError, RlpResponseResult, SyncHandler, MAX_BODIES_TO_SEND, MAX_HEADERS_TO_SEND, MAX_RECEIPTS_HEADERS_TO_SEND, }; -use chain::MAX_NODE_DATA_TO_SEND; +use crate::chain::MAX_NODE_DATA_TO_SEND; use std::borrow::Borrow; /// The Chain Sync Supplier: answers requests from peers with available data diff --git a/crates/ethcore/sync/src/chain/sync_packet.rs b/crates/ethcore/sync/src/chain/sync_packet.rs index f8964040d..866ed02e8 100644 --- a/crates/ethcore/sync/src/chain/sync_packet.rs +++ b/crates/ethcore/sync/src/chain/sync_packet.rs @@ -24,7 +24,7 @@ #![allow(unused_doc_comments)] -use api::{ETH_PROTOCOL, PAR_PROTOCOL}; +use crate::api::{ETH_PROTOCOL, PAR_PROTOCOL}; use network::{PacketId, ProtocolId}; // An enum that defines all known packet ids in the context of diff --git a/crates/ethcore/sync/src/lib.rs b/crates/ethcore/sync/src/lib.rs index b288b8892..39832bae2 100644 --- a/crates/ethcore/sync/src/lib.rs +++ b/crates/ethcore/sync/src/lib.rs @@ -75,7 +75,7 @@ mod tests; mod api; -pub use api::*; -pub use chain::{SyncState, SyncStatus}; +pub use crate::api::*; +pub use crate::chain::{SyncState, SyncStatus}; pub use devp2p::validate_node_url; pub use network::{ConnectionDirection, ConnectionFilter, Error, ErrorKind, NonReservedPeerMode}; diff --git a/crates/ethcore/sync/src/sync_io.rs b/crates/ethcore/sync/src/sync_io.rs index 3d7dde93e..0c03f0809 100644 --- a/crates/ethcore/sync/src/sync_io.rs +++ b/crates/ethcore/sync/src/sync_io.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use bytes::Bytes; -use chain::sync_packet::{PacketInfo, SyncPacket}; +use crate::chain::sync_packet::{PacketInfo, SyncPacket}; use ethcore::{client::BlockChainClient, snapshot::SnapshotService}; use network::{ client_version::ClientVersion, Error, NetworkContext, PacketId, PeerId, ProtocolId, SessionInfo, diff --git a/crates/ethcore/sync/src/tests/chain.rs b/crates/ethcore/sync/src/tests/chain.rs index 3cc12729b..8bed806a0 100644 --- a/crates/ethcore/sync/src/tests/chain.rs +++ b/crates/ethcore/sync/src/tests/chain.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use super::helpers::*; -use chain::SyncState; +use crate::chain::SyncState; use ethcore::client::{ BlockChainClient, BlockId, BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient, }; diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index 667a0ee44..7c926ab6c 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use api::PAR_PROTOCOL; +use crate::api::PAR_PROTOCOL; use bytes::Bytes; -use chain::{ +use crate::chain::{ sync_packet::{PacketInfo, SyncPacket}, ChainSync, ForkFilterApi, SyncSupplier, ETH_PROTOCOL_VERSION_66, PAR_PROTOCOL_VERSION_2, }; @@ -40,7 +40,7 @@ use std::{ collections::{HashMap, HashSet, VecDeque}, sync::Arc, }; -use sync_io::SyncIo; +use crate::sync_io::SyncIo; use tests::snapshot::*; use crate::types::BlockNumber; diff --git a/crates/ethcore/sync/src/transactions_stats.rs b/crates/ethcore/sync/src/transactions_stats.rs index ae5c65def..ec4614172 100644 --- a/crates/ethcore/sync/src/transactions_stats.rs +++ b/crates/ethcore/sync/src/transactions_stats.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use api::TransactionStats; +use crate::api::TransactionStats; use ethereum_types::{H256, H512}; use fastmap::H256FastMap; use std::{ From 59ff48843b0d6c3048c5b3b2087c81d9e9c53f9d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Apr 2025 14:10:17 +0200 Subject: [PATCH 436/687] batch of rust 2025 changes, first compiling version --- crates/ethcore/service/src/service.rs | 2 +- crates/ethcore/sync/src/block_sync.rs | 2 +- crates/ethcore/sync/src/chain/handler.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 2 +- crates/ethcore/sync/src/chain/propagator.rs | 2 +- crates/ethcore/sync/src/chain/supplier.rs | 2 +- crates/ethcore/sync/src/tests/helpers.rs | 2 +- crates/rpc/src/lib.rs | 4 ++-- crates/rpc/src/tests/helpers.rs | 2 +- crates/rpc/src/tests/rpc.rs | 6 +++--- crates/rpc/src/tests/ws.rs | 4 ++-- crates/rpc/src/v1/extractors.rs | 4 ++-- crates/rpc/src/v1/helpers/dispatch/full.rs | 2 +- crates/rpc/src/v1/helpers/dispatch/mod.rs | 6 +++--- crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs | 2 +- crates/rpc/src/v1/helpers/dispatch/signing.rs | 2 +- crates/rpc/src/v1/helpers/eip191.rs | 2 +- crates/rpc/src/v1/helpers/errors.rs | 2 +- crates/rpc/src/v1/helpers/external_signer/oneshot.rs | 2 +- .../rpc/src/v1/helpers/external_signer/signing_queue.rs | 4 ++-- crates/rpc/src/v1/helpers/fake_sign.rs | 2 +- crates/rpc/src/v1/helpers/mod.rs | 2 +- crates/rpc/src/v1/helpers/poll_filter.rs | 4 ++-- crates/rpc/src/v1/helpers/poll_manager.rs | 2 +- crates/rpc/src/v1/helpers/requests.rs | 2 +- crates/rpc/src/v1/helpers/secretstore.rs | 2 +- crates/rpc/src/v1/helpers/signature.rs | 2 +- crates/rpc/src/v1/helpers/subscription_manager.rs | 2 +- crates/rpc/src/v1/helpers/work.rs | 2 +- crates/rpc/src/v1/impls/debug.rs | 2 +- crates/rpc/src/v1/impls/eth.rs | 4 ++-- crates/rpc/src/v1/impls/eth_filter.rs | 2 +- crates/rpc/src/v1/impls/eth_pubsub.rs | 2 +- crates/rpc/src/v1/impls/net.rs | 2 +- crates/rpc/src/v1/impls/parity.rs | 8 ++++---- crates/rpc/src/v1/impls/parity_accounts.rs | 2 +- crates/rpc/src/v1/impls/parity_set.rs | 6 +++--- crates/rpc/src/v1/impls/personal.rs | 2 +- crates/rpc/src/v1/impls/pubsub.rs | 2 +- crates/rpc/src/v1/impls/rpc.rs | 2 +- crates/rpc/src/v1/impls/secretstore.rs | 2 +- crates/rpc/src/v1/impls/signer.rs | 2 +- crates/rpc/src/v1/impls/signing.rs | 2 +- crates/rpc/src/v1/impls/signing_unsafe.rs | 2 +- crates/rpc/src/v1/impls/traces.rs | 2 +- crates/rpc/src/v1/impls/web3.rs | 2 +- crates/rpc/src/v1/metadata.rs | 2 +- crates/rpc/src/v1/tests/eth.rs | 2 +- crates/rpc/src/v1/tests/mocked/debug.rs | 2 +- crates/rpc/src/v1/tests/mocked/eth.rs | 2 +- crates/rpc/src/v1/tests/mocked/eth_pubsub.rs | 2 +- crates/rpc/src/v1/tests/mocked/net.rs | 2 +- crates/rpc/src/v1/tests/mocked/parity.rs | 2 +- crates/rpc/src/v1/tests/mocked/parity_accounts.rs | 2 +- crates/rpc/src/v1/tests/mocked/parity_set.rs | 4 ++-- crates/rpc/src/v1/tests/mocked/personal.rs | 2 +- crates/rpc/src/v1/tests/mocked/pubsub.rs | 2 +- crates/rpc/src/v1/tests/mocked/rpc.rs | 2 +- crates/rpc/src/v1/tests/mocked/secretstore.rs | 2 +- crates/rpc/src/v1/tests/mocked/signer.rs | 2 +- crates/rpc/src/v1/tests/mocked/signing.rs | 2 +- crates/rpc/src/v1/tests/mocked/signing_unsafe.rs | 2 +- crates/rpc/src/v1/tests/mocked/traces.rs | 2 +- crates/rpc/src/v1/tests/mocked/web3.rs | 2 +- crates/rpc/src/v1/traits/debug.rs | 2 +- crates/rpc/src/v1/traits/eth.rs | 2 +- crates/rpc/src/v1/traits/eth_pubsub.rs | 2 +- crates/rpc/src/v1/traits/eth_signing.rs | 2 +- crates/rpc/src/v1/traits/parity.rs | 4 ++-- crates/rpc/src/v1/traits/parity_accounts.rs | 2 +- crates/rpc/src/v1/traits/parity_set.rs | 2 +- crates/rpc/src/v1/traits/parity_signing.rs | 2 +- crates/rpc/src/v1/traits/personal.rs | 2 +- crates/rpc/src/v1/traits/secretstore.rs | 2 +- crates/rpc/src/v1/traits/signer.rs | 2 +- crates/rpc/src/v1/traits/traces.rs | 2 +- crates/rpc/src/v1/traits/web3.rs | 2 +- crates/rpc/src/v1/types/account_info.rs | 2 +- crates/rpc/src/v1/types/block.rs | 4 ++-- crates/rpc/src/v1/types/call_request.rs | 2 +- crates/rpc/src/v1/types/confirmations.rs | 4 ++-- crates/rpc/src/v1/types/eip191.rs | 2 +- crates/rpc/src/v1/types/fee_history.rs | 2 +- crates/rpc/src/v1/types/filter.rs | 4 ++-- crates/rpc/src/v1/types/log.rs | 4 ++-- crates/rpc/src/v1/types/pubsub.rs | 4 ++-- crates/rpc/src/v1/types/receipt.rs | 4 ++-- crates/rpc/src/v1/types/secretstore.rs | 2 +- crates/rpc/src/v1/types/trace.rs | 4 ++-- crates/rpc/src/v1/types/trace_filter.rs | 4 ++-- crates/rpc/src/v1/types/transaction.rs | 2 +- crates/rpc/src/v1/types/transaction_request.rs | 4 ++-- crates/util/cli-signer/rpc-client/src/client.rs | 4 ++-- crates/util/cli-signer/rpc-client/src/signer_client.rs | 2 +- 94 files changed, 121 insertions(+), 121 deletions(-) diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index 19a353812..af7d779f5 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -20,7 +20,7 @@ use std::{path::Path, sync::Arc, time::Duration}; use ansi_term::Colour; use crate::io::{IoContext, IoError, IoHandler, IoService, TimerToken}; -use stop_guard::StopGuard; +use crate::stop_guard::StopGuard; use crate::blockchain::{BlockChainDB, BlockChainDBHandler}; use ethcore::{ diff --git a/crates/ethcore/sync/src/block_sync.rs b/crates/ethcore/sync/src/block_sync.rs index f8aa9b508..30531e39c 100644 --- a/crates/ethcore/sync/src/block_sync.rs +++ b/crates/ethcore/sync/src/block_sync.rs @@ -802,7 +802,7 @@ mod tests { use hash::keccak; use parking_lot::RwLock; use rlp::{encode_list, RlpStream}; - use tests::{helpers::TestIo, snapshot::TestSnapshotService}; + use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; use triehash_ethereum::ordered_trie_root; use crate::types::{ header::Header as BlockHeader, diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 9e161dbb2..a6791c1ca 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -954,7 +954,7 @@ mod tests { use parking_lot::RwLock; use rlp::Rlp; use std::collections::VecDeque; - use tests::{helpers::TestIo, snapshot::TestSnapshotService}; + use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; use super::{ super::tests::{dummy_sync_with_peer, get_dummy_block, get_dummy_blocks, get_dummy_hashes}, diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index ed840defc..115bfbd0b 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1873,7 +1873,7 @@ pub mod tests { use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use std::collections::VecDeque; - use tests::{helpers::TestIo, snapshot::TestSnapshotService}; + use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; use crate::types::header::Header; use SyncConfig; diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index f50a058ef..773df6b30 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -517,7 +517,7 @@ mod tests { use parking_lot::RwLock; use rlp::Rlp; use std::collections::VecDeque; - use tests::{helpers::TestIo, snapshot::TestSnapshotService}; + use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; use crate::types::transaction::TypedTransaction; use super::{ diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index 9330a81b9..8e992feff 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -521,7 +521,7 @@ mod test { use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use std::{collections::VecDeque, str::FromStr}; - use tests::{helpers::TestIo, snapshot::TestSnapshotService}; + use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; #[test] fn return_block_headers() { diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index 7c926ab6c..792303a4d 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -41,7 +41,7 @@ use std::{ sync::Arc, }; use crate::sync_io::SyncIo; -use tests::snapshot::*; +use crate::tests::snapshot::*; use crate::types::BlockNumber; use SyncConfig; diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index 64eb4b9a6..296db0d00 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -134,8 +134,8 @@ pub use ipc::{ }; pub use jsonrpc_pubsub::Session as PubSubSession; -pub use authcodes::{AuthCodes, TimeProvider}; -pub use v1::{ +pub use crate::authcodes::{AuthCodes, TimeProvider}; +pub use crate::v1::{ block_import::{is_major_importing, is_major_importing_or_waiting}, dispatch, extractors::{RpcExtractor, WsDispatcher, WsExtractor, WsStats}, diff --git a/crates/rpc/src/tests/helpers.rs b/crates/rpc/src/tests/helpers.rs index 923b5a92c..92d940bf7 100644 --- a/crates/rpc/src/tests/helpers.rs +++ b/crates/rpc/src/tests/helpers.rs @@ -22,7 +22,7 @@ use tempdir::TempDir; use parity_runtime::{Runtime, TaskExecutor}; -use authcodes::AuthCodes; +use crate::authcodes::AuthCodes; /// Server with event loop pub struct Server { diff --git a/crates/rpc/src/tests/rpc.rs b/crates/rpc/src/tests/rpc.rs index 53935aa5a..4bbc337b0 100644 --- a/crates/rpc/src/tests/rpc.rs +++ b/crates/rpc/src/tests/rpc.rs @@ -21,10 +21,10 @@ use http::{self, hyper}; use rpc_servers::{HttpServer, MetaIoHandler}; #[cfg(any(test, feature = "test-helpers"))] -use tests::{helpers::Server, http_client}; +use crate::tests::{helpers::Server, http_client}; #[cfg(any(test, feature = "test-helpers"))] -use v1::{extractors, Metadata}; +use crate::v1::{extractors, Metadata}; #[cfg(any(test, feature = "test-helpers"))] fn serve(handler: Option>) -> Server { @@ -60,7 +60,7 @@ fn request(server: Server, request: &str) -> http_client::Response { mod tests { use super::{request, Server}; use jsonrpc_core::{MetaIoHandler, Value}; - use v1::Metadata; + use crate::v1::Metadata; fn serve() -> (Server<::HttpServer>, ::std::net::SocketAddr) { let mut io = MetaIoHandler::default(); diff --git a/crates/rpc/src/tests/ws.rs b/crates/rpc/src/tests/ws.rs index fb922df42..8640da9cb 100644 --- a/crates/rpc/src/tests/ws.rs +++ b/crates/rpc/src/tests/ws.rs @@ -21,11 +21,11 @@ use std::sync::Arc; use jsonrpc_core::MetaIoHandler; use ws; -use tests::{ +use crate::tests::{ helpers::{GuardedAuthCodes, Server}, http_client, }; -use v1::{extractors, informant}; +use crate::v1::{extractors, informant}; /// Setup a mock signer for tests pub fn serve() -> (Server, usize, GuardedAuthCodes) { diff --git a/crates/rpc/src/v1/extractors.rs b/crates/rpc/src/v1/extractors.rs index bd7bb05ff..61706a1f3 100644 --- a/crates/rpc/src/v1/extractors.rs +++ b/crates/rpc/src/v1/extractors.rs @@ -21,7 +21,7 @@ use std::{ sync::Arc, }; -use authcodes; +use crate::authcodes; use ethereum_types::H256; use http::hyper; use ipc; @@ -30,7 +30,7 @@ use jsonrpc_core::futures::future::Either; use jsonrpc_pubsub::Session; use ws; -use v1::{informant::RpcStats, Metadata, Origin}; +use crate::v1::{informant::RpcStats, Metadata, Origin}; /// Common HTTP & IPC metadata extractor. pub struct RpcExtractor; diff --git a/crates/rpc/src/v1/helpers/dispatch/full.rs b/crates/rpc/src/v1/helpers/dispatch/full.rs index 8b26ea589..c8ac43792 100644 --- a/crates/rpc/src/v1/helpers/dispatch/full.rs +++ b/crates/rpc/src/v1/helpers/dispatch/full.rs @@ -28,7 +28,7 @@ use jsonrpc_core::{ futures::{future, Future, IntoFuture}, BoxFuture, Result, }; -use v1::{ +use crate::v1::{ helpers::{errors, nonce, FilledTransactionRequest, TransactionRequest}, types::RichRawTransaction as RpcRichRawTransaction, }; diff --git a/crates/rpc/src/v1/helpers/dispatch/mod.rs b/crates/rpc/src/v1/helpers/dispatch/mod.rs index ac1950756..e27b25062 100644 --- a/crates/rpc/src/v1/helpers/dispatch/mod.rs +++ b/crates/rpc/src/v1/helpers/dispatch/mod.rs @@ -24,7 +24,7 @@ mod signing; #[cfg(not(any(test, feature = "accounts")))] mod signing { use super::*; - use v1::helpers::errors; + use crate::v1::helpers::errors; /// Dummy signer implementation #[derive(Debug, Clone)] @@ -81,7 +81,7 @@ mod signing { } pub use self::{full::FullDispatcher, signing::Signer}; -pub use v1::helpers::nonce::Reservations; +pub use crate::v1::helpers::nonce::Reservations; use std::{fmt::Debug, ops::Deref, sync::Arc}; @@ -100,7 +100,7 @@ use jsonrpc_core::{ futures::{future, Future, IntoFuture}, BoxFuture, Error, Result, }; -use v1::{ +use crate::v1::{ helpers::{ConfirmationPayload, FilledTransactionRequest, TransactionRequest}, types::{ Bytes as RpcBytes, ConfirmationPayload as RpcConfirmationPayload, ConfirmationResponse, diff --git a/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs b/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs index 4b61e3652..17ea408e8 100644 --- a/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs +++ b/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs @@ -24,7 +24,7 @@ use jsonrpc_core::{ use crate::types::transaction::SignedTransaction; use super::{Accounts, PostSign, SignWith, WithToken}; -use v1::helpers::{errors, nonce, FilledTransactionRequest}; +use crate::v1::helpers::{errors, nonce, FilledTransactionRequest}; #[derive(Debug, Clone, Copy)] enum ProspectiveSignerState { diff --git a/crates/rpc/src/v1/helpers/dispatch/signing.rs b/crates/rpc/src/v1/helpers/dispatch/signing.rs index 4ab3345bf..2cfdfe781 100644 --- a/crates/rpc/src/v1/helpers/dispatch/signing.rs +++ b/crates/rpc/src/v1/helpers/dispatch/signing.rs @@ -27,7 +27,7 @@ use crate::types::transaction::{ }; use jsonrpc_core::Result; -use v1::helpers::{errors, FilledTransactionRequest}; +use crate::v1::helpers::{errors, FilledTransactionRequest}; use super::{eth_data_hash, SignMessage, SignWith, WithToken}; diff --git a/crates/rpc/src/v1/helpers/eip191.rs b/crates/rpc/src/v1/helpers/eip191.rs index 044629a54..82ef7e9bd 100644 --- a/crates/rpc/src/v1/helpers/eip191.rs +++ b/crates/rpc/src/v1/helpers/eip191.rs @@ -21,7 +21,7 @@ use hash::keccak; use jsonrpc_core::Error; use serde_json::{from_value, Value}; use std::fmt::Display; -use v1::{ +use crate::v1::{ helpers::{dispatch::eth_data_hash, errors}, types::{Bytes, EIP191Version, PresignedTransaction}, }; diff --git a/crates/rpc/src/v1/helpers/errors.rs b/crates/rpc/src/v1/helpers/errors.rs index 8f98dc656..47048654d 100644 --- a/crates/rpc/src/v1/helpers/errors.rs +++ b/crates/rpc/src/v1/helpers/errors.rs @@ -25,7 +25,7 @@ use ethcore::{ use jsonrpc_core::{Error, ErrorCode, Result as RpcResult, Value}; use rlp::DecoderError; use crate::types::{blockchain_info::BlockChainInfo, transaction::Error as TransactionError}; -use v1::{impls::EthClientOptions, types::BlockNumber}; +use crate::v1::{impls::EthClientOptions, types::BlockNumber}; use vm::Error as VMError; mod codes { diff --git a/crates/rpc/src/v1/helpers/external_signer/oneshot.rs b/crates/rpc/src/v1/helpers/external_signer/oneshot.rs index 948951aad..adbda3faf 100644 --- a/crates/rpc/src/v1/helpers/external_signer/oneshot.rs +++ b/crates/rpc/src/v1/helpers/external_signer/oneshot.rs @@ -18,7 +18,7 @@ use jsonrpc_core::{ futures::{self, sync::oneshot, Future}, Error, }; -use v1::helpers::errors; +use crate::v1::helpers::errors; pub type Res = Result; diff --git a/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs b/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs index 23ddb4a2b..3691d50ad 100644 --- a/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs +++ b/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs @@ -19,7 +19,7 @@ use std::collections::BTreeMap; use super::oneshot; use ethereum_types::U256; use parking_lot::{Mutex, RwLock}; -use v1::{ +use crate::v1::{ helpers::{ errors, requests::{ConfirmationPayload, ConfirmationRequest}, @@ -246,7 +246,7 @@ mod test { use jsonrpc_core::futures::Future; use parking_lot::Mutex; use std::sync::Arc; - use v1::{ + use crate::v1::{ helpers::{ external_signer::{ConfirmationsQueue, QueueEvent, SigningQueue}, ConfirmationPayload, FilledTransactionRequest, diff --git a/crates/rpc/src/v1/helpers/fake_sign.rs b/crates/rpc/src/v1/helpers/fake_sign.rs index be6a2b6a2..9066cff77 100644 --- a/crates/rpc/src/v1/helpers/fake_sign.rs +++ b/crates/rpc/src/v1/helpers/fake_sign.rs @@ -22,7 +22,7 @@ use crate::types::transaction::{ use ethereum_types::U256; use jsonrpc_core::{Error, ErrorCode}; -use v1::helpers::CallRequest; +use crate::v1::helpers::CallRequest; pub fn sign_call(request: CallRequest) -> Result { let max_gas = U256::from(500_000_000); diff --git a/crates/rpc/src/v1/helpers/mod.rs b/crates/rpc/src/v1/helpers/mod.rs index a9f4d4f2e..5c16a907a 100644 --- a/crates/rpc/src/v1/helpers/mod.rs +++ b/crates/rpc/src/v1/helpers/mod.rs @@ -53,6 +53,6 @@ pub use self::{ work::submit_work_detail, }; -pub fn to_url(address: &Option<::Host>) -> Option { +pub fn to_url(address: &Option) -> Option { address.as_ref().map(|host| (**host).to_owned()) } diff --git a/crates/rpc/src/v1/helpers/poll_filter.rs b/crates/rpc/src/v1/helpers/poll_filter.rs index 6b5379f17..a20346223 100644 --- a/crates/rpc/src/v1/helpers/poll_filter.rs +++ b/crates/rpc/src/v1/helpers/poll_filter.rs @@ -23,7 +23,7 @@ use std::{ sync::Arc, }; use crate::types::filter::Filter; -use v1::types::Log; +use crate::v1::types::Log; pub type BlockNumber = u64; @@ -68,7 +68,7 @@ pub enum PollFilter { } impl PollFilter { - pub(in v1) const MAX_BLOCK_HISTORY_SIZE: usize = 32; + pub(in crate::v1) const MAX_BLOCK_HISTORY_SIZE: usize = 32; } /// Returns only last `n` logs diff --git a/crates/rpc/src/v1/helpers/poll_manager.rs b/crates/rpc/src/v1/helpers/poll_manager.rs index 044844035..4644ecdaf 100644 --- a/crates/rpc/src/v1/helpers/poll_manager.rs +++ b/crates/rpc/src/v1/helpers/poll_manager.rs @@ -85,7 +85,7 @@ where mod tests { use std::cell::Cell; use transient_hashmap::Timer; - use v1::helpers::PollManager; + use crate::v1::helpers::PollManager; struct TestTimer<'a> { time: &'a Cell, diff --git a/crates/rpc/src/v1/helpers/requests.rs b/crates/rpc/src/v1/helpers/requests.rs index e55644238..d85478194 100644 --- a/crates/rpc/src/v1/helpers/requests.rs +++ b/crates/rpc/src/v1/helpers/requests.rs @@ -17,7 +17,7 @@ use bytes::Bytes; use ethereum_types::{Address, H256, U256, U64}; -use v1::types::{AccessList, Origin, TransactionCondition}; +use crate::v1::types::{AccessList, Origin, TransactionCondition}; /// Transaction request coming from RPC #[derive(Debug, Clone, Default, Eq, PartialEq, Hash)] diff --git a/crates/rpc/src/v1/helpers/secretstore.rs b/crates/rpc/src/v1/helpers/secretstore.rs index 35df73247..3aa8b9f3f 100644 --- a/crates/rpc/src/v1/helpers/secretstore.rs +++ b/crates/rpc/src/v1/helpers/secretstore.rs @@ -21,7 +21,7 @@ use jsonrpc_core::Error; use rand::{rngs::OsRng, RngCore}; use std::collections::BTreeSet; use tiny_keccak::Keccak; -use v1::{helpers::errors, types::EncryptedDocumentKey}; +use crate::v1::{helpers::errors, types::EncryptedDocumentKey}; /// Initialization vector length. const INIT_VEC_LEN: usize = 16; diff --git a/crates/rpc/src/v1/helpers/signature.rs b/crates/rpc/src/v1/helpers/signature.rs index c7844aac3..4cb4541f1 100644 --- a/crates/rpc/src/v1/helpers/signature.rs +++ b/crates/rpc/src/v1/helpers/signature.rs @@ -18,7 +18,7 @@ use crypto::publickey::{public_to_address, recover, Signature}; use ethereum_types::{H256, U64}; use hash::keccak; use jsonrpc_core::Result; -use v1::{ +use crate::v1::{ helpers::{dispatch::eth_data_hash, errors}, types::{Bytes, RecoveredAccount}, }; diff --git a/crates/rpc/src/v1/helpers/subscription_manager.rs b/crates/rpc/src/v1/helpers/subscription_manager.rs index 5fa45ee7d..003bb32f6 100644 --- a/crates/rpc/src/v1/helpers/subscription_manager.rs +++ b/crates/rpc/src/v1/helpers/subscription_manager.rs @@ -33,7 +33,7 @@ use jsonrpc_core::{ }; use jsonrpc_pubsub::SubscriptionId; -use v1::{helpers::Subscribers, metadata::Metadata}; +use crate::v1::{helpers::Subscribers, metadata::Metadata}; #[derive(Debug)] struct Subscription { diff --git a/crates/rpc/src/v1/helpers/work.rs b/crates/rpc/src/v1/helpers/work.rs index 9f9bb5df3..c45ece7aa 100644 --- a/crates/rpc/src/v1/helpers/work.rs +++ b/crates/rpc/src/v1/helpers/work.rs @@ -22,7 +22,7 @@ use ethcore::miner::{BlockChainClient, MinerService}; use ethereum_types::{H256, H64}; use jsonrpc_core::Error; use rlp; -use v1::helpers::errors; +use crate::v1::helpers::errors; // Submit a POW work and return the block's hash pub fn submit_work_detail( diff --git a/crates/rpc/src/v1/impls/debug.rs b/crates/rpc/src/v1/impls/debug.rs index 1d970e021..d2aee9fea 100644 --- a/crates/rpc/src/v1/impls/debug.rs +++ b/crates/rpc/src/v1/impls/debug.rs @@ -22,7 +22,7 @@ use ethcore::client::BlockChainClient; use crate::types::{header::Header, transaction::LocalizedTransaction}; use jsonrpc_core::Result; -use v1::{ +use crate::v1::{ traits::Debug, types::{Block, BlockTransactions, Bytes, RichBlock, Transaction}, }; diff --git a/crates/rpc/src/v1/impls/eth.rs b/crates/rpc/src/v1/impls/eth.rs index a2e7563fd..e6e688e2d 100644 --- a/crates/rpc/src/v1/impls/eth.rs +++ b/crates/rpc/src/v1/impls/eth.rs @@ -35,7 +35,7 @@ use ethcore::{ snapshot::SnapshotService, }; use hash::keccak; -use miner::external::ExternalMinerService; +use crate::miner::external::ExternalMinerService; use sync::SyncProvider; use crate::types::{ encoded, @@ -47,7 +47,7 @@ use crate::types::{ use jsonrpc_core::{futures::future, BoxFuture, Result}; -use v1::{ +use crate::v1::{ helpers::{ self, block_import::is_major_importing, diff --git a/crates/rpc/src/v1/impls/eth_filter.rs b/crates/rpc/src/v1/impls/eth_filter.rs index 5df10fca1..0ba5cec63 100644 --- a/crates/rpc/src/v1/impls/eth_filter.rs +++ b/crates/rpc/src/v1/impls/eth_filter.rs @@ -33,7 +33,7 @@ use jsonrpc_core::{ futures::{future, future::Either, Future}, BoxFuture, Result, }; -use v1::{ +use crate::v1::{ helpers::{errors, limit_logs, PollFilter, PollManager, SyncPollFilter}, impls::eth::pending_logs, traits::EthFilter, diff --git a/crates/rpc/src/v1/impls/eth_pubsub.rs b/crates/rpc/src/v1/impls/eth_pubsub.rs index f9f5952d2..b895d870e 100644 --- a/crates/rpc/src/v1/impls/eth_pubsub.rs +++ b/crates/rpc/src/v1/impls/eth_pubsub.rs @@ -30,7 +30,7 @@ use jsonrpc_pubsub::{ SubscriptionId, }; -use v1::{ +use crate::v1::{ helpers::{errors, limit_logs, Subscribers}, metadata::Metadata, traits::EthPubSub, diff --git a/crates/rpc/src/v1/impls/net.rs b/crates/rpc/src/v1/impls/net.rs index 779c47773..c649f7b3a 100644 --- a/crates/rpc/src/v1/impls/net.rs +++ b/crates/rpc/src/v1/impls/net.rs @@ -18,7 +18,7 @@ use jsonrpc_core::Result; use std::sync::Arc; use sync::SyncProvider; -use v1::traits::Net; +use crate::v1::traits::Net; /// Net rpc implementation. pub struct NetClient { diff --git a/crates/rpc/src/v1/impls/parity.rs b/crates/rpc/src/v1/impls/parity.rs index f12682d70..4cb70b0ba 100644 --- a/crates/rpc/src/v1/impls/parity.rs +++ b/crates/rpc/src/v1/impls/parity.rs @@ -32,7 +32,7 @@ use jsonrpc_core::{futures::future, BoxFuture, Result}; use stats::PrometheusMetrics; use sync::{ManageNetwork, SyncProvider}; use crate::types::ids::BlockId; -use v1::{ +use crate::v1::{ helpers::{ self, block_import::is_major_importing, @@ -48,7 +48,7 @@ use v1::{ }, }; use version::version_data; -use Host; +use crate::Host; /// Parity implementation. pub struct ParityClient @@ -352,8 +352,8 @@ where Ok(ChainStatus { block_gap: gap }) } - fn node_kind(&self) -> Result<::v1::types::NodeKind> { - use v1::types::{Availability, Capability, NodeKind}; + fn node_kind(&self) -> Result { + use crate::v1::types::{Availability, Capability, NodeKind}; Ok(NodeKind { availability: Availability::Personal, diff --git a/crates/rpc/src/v1/impls/parity_accounts.rs b/crates/rpc/src/v1/impls/parity_accounts.rs index 151c3f12a..4e242047b 100644 --- a/crates/rpc/src/v1/impls/parity_accounts.rs +++ b/crates/rpc/src/v1/impls/parity_accounts.rs @@ -29,7 +29,7 @@ use ethereum_types::{Address, H160, H256, H520}; use ethkey::{Brain, Password}; use ethstore::KeyFile; use jsonrpc_core::Result; -use v1::{ +use crate::v1::{ helpers::{ deprecated::{self, DeprecationNotice}, errors, diff --git a/crates/rpc/src/v1/impls/parity_set.rs b/crates/rpc/src/v1/impls/parity_set.rs index 5e2b137ae..7da68f243 100644 --- a/crates/rpc/src/v1/impls/parity_set.rs +++ b/crates/rpc/src/v1/impls/parity_set.rs @@ -28,7 +28,7 @@ use hash::keccak_buffer; use sync::ManageNetwork; use jsonrpc_core::{futures::Future, BoxFuture, Result}; -use v1::{ +use crate::v1::{ helpers::errors, traits::ParitySet, types::{Bytes, Transaction}, @@ -37,8 +37,8 @@ use v1::{ #[cfg(any(test, feature = "accounts"))] pub mod accounts { use super::*; - use accounts::AccountProvider; - use v1::{ + use crate::accounts::AccountProvider; + use crate::v1::{ helpers::{deprecated::DeprecationNotice, engine_signer::EngineSigner}, traits::ParitySetAccounts, }; diff --git a/crates/rpc/src/v1/impls/personal.rs b/crates/rpc/src/v1/impls/personal.rs index 05c023a52..5750bddbf 100644 --- a/crates/rpc/src/v1/impls/personal.rs +++ b/crates/rpc/src/v1/impls/personal.rs @@ -29,7 +29,7 @@ use jsonrpc_core::{ types::Value, BoxFuture, Result, }; -use v1::{ +use crate::v1::{ helpers::{ deprecated::{self, DeprecationNotice}, dispatch::{self, eth_data_hash, Dispatcher, PostSign, SignWith, WithToken}, diff --git a/crates/rpc/src/v1/impls/pubsub.rs b/crates/rpc/src/v1/impls/pubsub.rs index 7d39d1c14..1c87d3b53 100644 --- a/crates/rpc/src/v1/impls/pubsub.rs +++ b/crates/rpc/src/v1/impls/pubsub.rs @@ -28,7 +28,7 @@ use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; use tokio_timer; use parity_runtime::Executor; -use v1::{helpers::GenericPollManager, metadata::Metadata, traits::PubSub}; +use crate::v1::{helpers::GenericPollManager, metadata::Metadata, traits::PubSub}; /// Parity PubSub implementation. pub struct PubSubClient> { diff --git a/crates/rpc/src/v1/impls/rpc.rs b/crates/rpc/src/v1/impls/rpc.rs index 521818620..a82d1bf79 100644 --- a/crates/rpc/src/v1/impls/rpc.rs +++ b/crates/rpc/src/v1/impls/rpc.rs @@ -17,7 +17,7 @@ //! RPC generic methods implementation. use jsonrpc_core::Result; use std::collections::BTreeMap; -use v1::traits::Rpc; +use crate::v1::traits::Rpc; /// RPC generic methods implementation. pub struct RpcClient { diff --git a/crates/rpc/src/v1/impls/secretstore.rs b/crates/rpc/src/v1/impls/secretstore.rs index 9c219e875..0172e75b2 100644 --- a/crates/rpc/src/v1/impls/secretstore.rs +++ b/crates/rpc/src/v1/impls/secretstore.rs @@ -24,7 +24,7 @@ use ethereum_types::{H160, H256, H512}; use ethkey::Password; use jsonrpc_core::Result; -use v1::{ +use crate::v1::{ helpers::{ errors, secretstore::{ diff --git a/crates/rpc/src/v1/impls/signer.rs b/crates/rpc/src/v1/impls/signer.rs index 9098983d1..f2180498d 100644 --- a/crates/rpc/src/v1/impls/signer.rs +++ b/crates/rpc/src/v1/impls/signer.rs @@ -32,7 +32,7 @@ use jsonrpc_pubsub::{ typed::{Sink, Subscriber}, SubscriptionId, }; -use v1::{ +use crate::v1::{ helpers::{ deprecated::{self, DeprecationNotice}, dispatch::{self, eth_data_hash, Dispatcher, WithToken}, diff --git a/crates/rpc/src/v1/impls/signing.rs b/crates/rpc/src/v1/impls/signing.rs index 3bb68910f..174c4d43a 100644 --- a/crates/rpc/src/v1/impls/signing.rs +++ b/crates/rpc/src/v1/impls/signing.rs @@ -27,7 +27,7 @@ use jsonrpc_core::{ BoxFuture, Error, Result, }; -use v1::{ +use crate::v1::{ helpers::{ deprecated::{self, DeprecationNotice}, dispatch::{self, Dispatcher}, diff --git a/crates/rpc/src/v1/impls/signing_unsafe.rs b/crates/rpc/src/v1/impls/signing_unsafe.rs index d515ef451..c82e324c9 100644 --- a/crates/rpc/src/v1/impls/signing_unsafe.rs +++ b/crates/rpc/src/v1/impls/signing_unsafe.rs @@ -23,7 +23,7 @@ use jsonrpc_core::{ futures::{future, Future}, BoxFuture, Result, }; -use v1::{ +use crate::v1::{ helpers::{ deprecated::{self, DeprecationNotice}, dispatch::{self, Dispatcher}, diff --git a/crates/rpc/src/v1/impls/traces.rs b/crates/rpc/src/v1/impls/traces.rs index 4d499d8f1..1e0fbd72f 100644 --- a/crates/rpc/src/v1/impls/traces.rs +++ b/crates/rpc/src/v1/impls/traces.rs @@ -26,7 +26,7 @@ use ethereum_types::H256; use crate::types::transaction::{SignedTransaction, TypedTransaction}; use jsonrpc_core::Result; -use v1::{ +use crate::v1::{ helpers::{errors, fake_sign}, traits::Traces, types::{ diff --git a/crates/rpc/src/v1/impls/web3.rs b/crates/rpc/src/v1/impls/web3.rs index 54d5059bc..a4abe41bf 100644 --- a/crates/rpc/src/v1/impls/web3.rs +++ b/crates/rpc/src/v1/impls/web3.rs @@ -18,7 +18,7 @@ use ethereum_types::H256; use hash::keccak; use jsonrpc_core::Result; -use v1::{traits::Web3, types::Bytes}; +use crate::v1::{traits::Web3, types::Bytes}; use version::version; /// Web3 rpc implementation. diff --git a/crates/rpc/src/v1/metadata.rs b/crates/rpc/src/v1/metadata.rs index 4e89a6c11..d969a1d39 100644 --- a/crates/rpc/src/v1/metadata.rs +++ b/crates/rpc/src/v1/metadata.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use jsonrpc_core; use jsonrpc_pubsub::{PubSubMetadata, Session}; -use v1::types::Origin; +use crate::v1::types::Origin; /// RPC methods metadata. #[derive(Clone, Default, Debug)] diff --git a/crates/rpc/src/v1/tests/eth.rs b/crates/rpc/src/v1/tests/eth.rs index 88f77b7ad..7f773f247 100644 --- a/crates/rpc/src/v1/tests/eth.rs +++ b/crates/rpc/src/v1/tests/eth.rs @@ -35,7 +35,7 @@ use parking_lot::Mutex; use crate::types::ids::BlockId; use jsonrpc_core::IoHandler; -use v1::{ +use crate::v1::{ helpers::{ dispatch::{self, FullDispatcher}, nonce, diff --git a/crates/rpc/src/v1/tests/mocked/debug.rs b/crates/rpc/src/v1/tests/mocked/debug.rs index ea2ef979e..4e0653de8 100644 --- a/crates/rpc/src/v1/tests/mocked/debug.rs +++ b/crates/rpc/src/v1/tests/mocked/debug.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use ethcore::client::TestBlockChainClient; use jsonrpc_core::IoHandler; -use v1::{Debug, DebugClient}; +use crate::v1::{Debug, DebugClient}; fn io() -> IoHandler { let client = Arc::new(TestBlockChainClient::new()); diff --git a/crates/rpc/src/v1/tests/mocked/eth.rs b/crates/rpc/src/v1/tests/mocked/eth.rs index 516e9d5a7..74167f177 100644 --- a/crates/rpc/src/v1/tests/mocked/eth.rs +++ b/crates/rpc/src/v1/tests/mocked/eth.rs @@ -40,7 +40,7 @@ use crate::types::{ }; use jsonrpc_core::IoHandler; -use v1::{ +use crate::v1::{ metadata::Metadata, tests::helpers::{Config, TestMinerService, TestSnapshotService, TestSyncProvider}, Eth, EthClient, EthClientOptions, EthFilter, EthFilterClient, diff --git a/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs b/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs index 3c5df6c87..a8a9f5bbe 100644 --- a/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs +++ b/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs @@ -24,7 +24,7 @@ use jsonrpc_pubsub::Session; use std::time::Duration; -use v1::{EthPubSub, EthPubSubClient, Metadata}; +use crate::v1::{EthPubSub, EthPubSubClient, Metadata}; use ethcore::client::{ ChainNotify, ChainRoute, ChainRouteType, EachBlockWith, NewBlocks, TestBlockChainClient, diff --git a/crates/rpc/src/v1/tests/mocked/net.rs b/crates/rpc/src/v1/tests/mocked/net.rs index 87450bd83..a100110a1 100644 --- a/crates/rpc/src/v1/tests/mocked/net.rs +++ b/crates/rpc/src/v1/tests/mocked/net.rs @@ -16,7 +16,7 @@ use jsonrpc_core::IoHandler; use std::sync::Arc; -use v1::{ +use crate::v1::{ tests::helpers::{Config, TestSyncProvider}, Net, NetClient, }; diff --git a/crates/rpc/src/v1/tests/mocked/parity.rs b/crates/rpc/src/v1/tests/mocked/parity.rs index a03095b25..83d7a2e3c 100644 --- a/crates/rpc/src/v1/tests/mocked/parity.rs +++ b/crates/rpc/src/v1/tests/mocked/parity.rs @@ -28,7 +28,7 @@ use crate::types::{ use super::manage_network::TestManageNetwork; use jsonrpc_core::IoHandler; -use v1::{ +use crate::v1::{ helpers::{external_signer::SignerService, NetworkSettings}, metadata::Metadata, tests::helpers::{Config, TestMinerService, TestSyncProvider}, diff --git a/crates/rpc/src/v1/tests/mocked/parity_accounts.rs b/crates/rpc/src/v1/tests/mocked/parity_accounts.rs index c154a577b..16f37129e 100644 --- a/crates/rpc/src/v1/tests/mocked/parity_accounts.rs +++ b/crates/rpc/src/v1/tests/mocked/parity_accounts.rs @@ -22,7 +22,7 @@ use ethstore::{accounts_dir::RootDiskDirectory, EthStore}; use tempdir::TempDir; use jsonrpc_core::IoHandler; -use v1::{ParityAccounts, ParityAccountsClient, ParityAccountsInfo}; +use crate::v1::{ParityAccounts, ParityAccountsClient, ParityAccountsInfo}; struct ParityAccountsTester { accounts: Arc, diff --git a/crates/rpc/src/v1/tests/mocked/parity_set.rs b/crates/rpc/src/v1/tests/mocked/parity_set.rs index 45a2d5da0..ca3a62ca8 100644 --- a/crates/rpc/src/v1/tests/mocked/parity_set.rs +++ b/crates/rpc/src/v1/tests/mocked/parity_set.rs @@ -23,7 +23,7 @@ use sync::ManageNetwork; use super::manage_network::TestManageNetwork; use jsonrpc_core::IoHandler; -use v1::{tests::helpers::TestMinerService, ParitySet, ParitySetClient}; +use crate::v1::{tests::helpers::TestMinerService, ParitySet, ParitySetClient}; use fake_fetch::FakeFetch; @@ -212,7 +212,7 @@ fn rpc_parity_remove_transaction() { fn rpc_parity_set_engine_signer() { use accounts::AccountProvider; use bytes::ToPretty; - use v1::{impls::ParitySetAccountsClient, traits::ParitySetAccounts}; + use crate::v1::{impls::ParitySetAccountsClient, traits::ParitySetAccounts}; let account_provider = Arc::new(AccountProvider::transient_provider()); account_provider diff --git a/crates/rpc/src/v1/tests/mocked/personal.rs b/crates/rpc/src/v1/tests/mocked/personal.rs index 4598e598e..b648021ba 100644 --- a/crates/rpc/src/v1/tests/mocked/personal.rs +++ b/crates/rpc/src/v1/tests/mocked/personal.rs @@ -28,7 +28,7 @@ use parking_lot::Mutex; use crate::types::transaction::{Action, Transaction, TypedTransaction}; use serde_json::to_value; -use v1::{ +use crate::v1::{ helpers::{ dispatch::{eth_data_hash, FullDispatcher}, eip191, nonce, diff --git a/crates/rpc/src/v1/tests/mocked/pubsub.rs b/crates/rpc/src/v1/tests/mocked/pubsub.rs index 5e05c254f..4b5fb4e31 100644 --- a/crates/rpc/src/v1/tests/mocked/pubsub.rs +++ b/crates/rpc/src/v1/tests/mocked/pubsub.rs @@ -24,7 +24,7 @@ use jsonrpc_core::{ use jsonrpc_pubsub::Session; use parity_runtime::Runtime; -use v1::{Metadata, PubSub, PubSubClient}; +use crate::v1::{Metadata, PubSub, PubSubClient}; fn rpc() -> MetaIoHandler { let mut io = MetaIoHandler::default(); diff --git a/crates/rpc/src/v1/tests/mocked/rpc.rs b/crates/rpc/src/v1/tests/mocked/rpc.rs index 6dc677c61..4e814e460 100644 --- a/crates/rpc/src/v1/tests/mocked/rpc.rs +++ b/crates/rpc/src/v1/tests/mocked/rpc.rs @@ -16,7 +16,7 @@ use jsonrpc_core::IoHandler; use std::collections::BTreeMap; -use v1::{Rpc, RpcClient}; +use crate::v1::{Rpc, RpcClient}; fn rpc_client() -> RpcClient { let mut modules = BTreeMap::new(); diff --git a/crates/rpc/src/v1/tests/mocked/secretstore.rs b/crates/rpc/src/v1/tests/mocked/secretstore.rs index 76dbbce50..04ae3a754 100644 --- a/crates/rpc/src/v1/tests/mocked/secretstore.rs +++ b/crates/rpc/src/v1/tests/mocked/secretstore.rs @@ -25,7 +25,7 @@ use ethereum_types::H256; use jsonrpc_core::{IoHandler, Success}; use serde_json; -use v1::{ +use crate::v1::{ helpers::secretstore::ordered_servers_keccak, metadata::Metadata, traits::secretstore::SecretStore, types::EncryptedDocumentKey, SecretStoreClient, }; diff --git a/crates/rpc/src/v1/tests/mocked/signer.rs b/crates/rpc/src/v1/tests/mocked/signer.rs index d05cb2eaa..4fa19e62f 100644 --- a/crates/rpc/src/v1/tests/mocked/signer.rs +++ b/crates/rpc/src/v1/tests/mocked/signer.rs @@ -26,7 +26,7 @@ use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTra use jsonrpc_core::IoHandler; use serde_json; -use v1::{ +use crate::v1::{ helpers::{ dispatch::{self, eth_data_hash, FullDispatcher}, external_signer::{SignerService, SigningQueue}, diff --git a/crates/rpc/src/v1/tests/mocked/signing.rs b/crates/rpc/src/v1/tests/mocked/signing.rs index dae28d124..035380522 100644 --- a/crates/rpc/src/v1/tests/mocked/signing.rs +++ b/crates/rpc/src/v1/tests/mocked/signing.rs @@ -17,7 +17,7 @@ use std::{str::FromStr, sync::Arc, thread, time::Duration}; use jsonrpc_core::{futures::Future, IoHandler, Success}; -use v1::{ +use crate::v1::{ helpers::{ dispatch, external_signer::{SignerService, SigningQueue}, diff --git a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs index f099b0ac7..7803b43bc 100644 --- a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs +++ b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs @@ -24,7 +24,7 @@ use parking_lot::Mutex; use crate::types::transaction::{Action, Transaction, TypedTransaction}; use jsonrpc_core::IoHandler; -use v1::{ +use crate::v1::{ helpers::{ dispatch::{self, FullDispatcher}, nonce, diff --git a/crates/rpc/src/v1/tests/mocked/traces.rs b/crates/rpc/src/v1/tests/mocked/traces.rs index f9363da5b..36c7ee5c8 100644 --- a/crates/rpc/src/v1/tests/mocked/traces.rs +++ b/crates/rpc/src/v1/tests/mocked/traces.rs @@ -29,7 +29,7 @@ use ethereum_types::{Address, H256}; use vm::CallType; use jsonrpc_core::IoHandler; -use v1::{tests::helpers::TestMinerService, Metadata, Traces, TracesClient}; +use crate::v1::{tests::helpers::TestMinerService, Metadata, Traces, TracesClient}; struct Tester { client: Arc, diff --git a/crates/rpc/src/v1/tests/mocked/web3.rs b/crates/rpc/src/v1/tests/mocked/web3.rs index 61158db3e..3960d7dc0 100644 --- a/crates/rpc/src/v1/tests/mocked/web3.rs +++ b/crates/rpc/src/v1/tests/mocked/web3.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use jsonrpc_core::IoHandler; -use v1::{Web3, Web3Client}; +use crate::v1::{Web3, Web3Client}; use version::version; #[test] diff --git a/crates/rpc/src/v1/traits/debug.rs b/crates/rpc/src/v1/traits/debug.rs index 98687c3d2..bfc766827 100644 --- a/crates/rpc/src/v1/traits/debug.rs +++ b/crates/rpc/src/v1/traits/debug.rs @@ -19,7 +19,7 @@ use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use v1::types::RichBlock; +use crate::v1::types::RichBlock; /// Debug RPC interface. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/eth.rs b/crates/rpc/src/v1/traits/eth.rs index 8c699d6a2..a4c346c81 100644 --- a/crates/rpc/src/v1/traits/eth.rs +++ b/crates/rpc/src/v1/traits/eth.rs @@ -19,7 +19,7 @@ use ethereum_types::{H160, H256, H64, U256, U64}; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use v1::types::{ +use crate::v1::types::{ BlockNumber, Bytes, CallRequest, EthAccount, EthFeeHistory, Filter, FilterChanges, Index, Log, Receipt, RichBlock, SyncStatus, Transaction, Work, }; diff --git a/crates/rpc/src/v1/traits/eth_pubsub.rs b/crates/rpc/src/v1/traits/eth_pubsub.rs index 06b9fa279..b5d394cae 100644 --- a/crates/rpc/src/v1/traits/eth_pubsub.rs +++ b/crates/rpc/src/v1/traits/eth_pubsub.rs @@ -20,7 +20,7 @@ use jsonrpc_core::Result; use jsonrpc_derive::rpc; use jsonrpc_pubsub::{typed, SubscriptionId}; -use v1::types::pubsub; +use crate::v1::types::pubsub; /// Eth PUB-SUB rpc interface. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/eth_signing.rs b/crates/rpc/src/v1/traits/eth_signing.rs index 1622fcb95..264cd29f2 100644 --- a/crates/rpc/src/v1/traits/eth_signing.rs +++ b/crates/rpc/src/v1/traits/eth_signing.rs @@ -20,7 +20,7 @@ use jsonrpc_core::BoxFuture; use jsonrpc_derive::rpc; use ethereum_types::{H160, H256, H520}; -use v1::types::{Bytes, RichRawTransaction, TransactionRequest}; +use crate::v1::types::{Bytes, RichRawTransaction, TransactionRequest}; /// Signing methods implementation relying on unlocked accounts. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/parity.rs b/crates/rpc/src/v1/traits/parity.rs index fc82206cf..2f32d03ac 100644 --- a/crates/rpc/src/v1/traits/parity.rs +++ b/crates/rpc/src/v1/traits/parity.rs @@ -23,7 +23,7 @@ use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; use ethcore::miner::TransactionFilter; -use v1::types::{ +use crate::v1::types::{ BlockNumber, Bytes, CallRequest, ChainStatus, Histogram, LocalTransactionStatus, Peers, Receipt, RecoveredAccount, RichHeader, RpcSettings, Transaction, TransactionStats, }; @@ -199,7 +199,7 @@ pub trait Parity { /// Get node kind info. #[rpc(name = "parity_nodeKind")] - fn node_kind(&self) -> Result<::v1::types::NodeKind>; + fn node_kind(&self) -> Result; /// Get block header. /// Same as `eth_getBlockByNumber` but without uncles and transactions. diff --git a/crates/rpc/src/v1/traits/parity_accounts.rs b/crates/rpc/src/v1/traits/parity_accounts.rs index d856f53e1..0ea8180ed 100644 --- a/crates/rpc/src/v1/traits/parity_accounts.rs +++ b/crates/rpc/src/v1/traits/parity_accounts.rs @@ -22,7 +22,7 @@ use ethkey::Password; use ethstore::KeyFile; use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use v1::types::{AccountInfo, DeriveHash, DeriveHierarchical, ExtAccountInfo}; +use crate::v1::types::{AccountInfo, DeriveHash, DeriveHierarchical, ExtAccountInfo}; /// Parity-specific read-only accounts rpc interface. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/parity_set.rs b/crates/rpc/src/v1/traits/parity_set.rs index fbaacb0ca..3f905b9f8 100644 --- a/crates/rpc/src/v1/traits/parity_set.rs +++ b/crates/rpc/src/v1/traits/parity_set.rs @@ -20,7 +20,7 @@ use ethereum_types::{H160, H256, U256}; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use v1::types::{Bytes, Transaction}; +use crate::v1::types::{Bytes, Transaction}; /// Parity-specific rpc interface for operations altering the account-related settings. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/parity_signing.rs b/crates/rpc/src/v1/traits/parity_signing.rs index 058c1536d..aa3a5a8a4 100644 --- a/crates/rpc/src/v1/traits/parity_signing.rs +++ b/crates/rpc/src/v1/traits/parity_signing.rs @@ -19,7 +19,7 @@ use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; use ethereum_types::{H160, U256}; -use v1::types::{Bytes, ConfirmationResponse, Either, TransactionRequest}; +use crate::v1::types::{Bytes, ConfirmationResponse, Either, TransactionRequest}; /// Signing methods implementation. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/personal.rs b/crates/rpc/src/v1/traits/personal.rs index b3b61ec55..7ddb968ac 100644 --- a/crates/rpc/src/v1/traits/personal.rs +++ b/crates/rpc/src/v1/traits/personal.rs @@ -19,7 +19,7 @@ use eip_712::EIP712; use ethereum_types::{H160, H256, H520, U128}; use jsonrpc_core::{types::Value, BoxFuture, Result}; use jsonrpc_derive::rpc; -use v1::types::{ +use crate::v1::types::{ Bytes, EIP191Version, RichRawTransaction as RpcRichRawTransaction, TransactionRequest, }; diff --git a/crates/rpc/src/v1/traits/secretstore.rs b/crates/rpc/src/v1/traits/secretstore.rs index b65efa0a1..6e746d822 100644 --- a/crates/rpc/src/v1/traits/secretstore.rs +++ b/crates/rpc/src/v1/traits/secretstore.rs @@ -22,7 +22,7 @@ use ethereum_types::{H160, H256, H512}; use ethkey::Password; use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use v1::types::{Bytes, EncryptedDocumentKey}; +use crate::v1::types::{Bytes, EncryptedDocumentKey}; /// Parity-specific rpc interface. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/signer.rs b/crates/rpc/src/v1/traits/signer.rs index d679c3413..eba32a550 100644 --- a/crates/rpc/src/v1/traits/signer.rs +++ b/crates/rpc/src/v1/traits/signer.rs @@ -21,7 +21,7 @@ use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; -use v1::types::{ +use crate::v1::types::{ Bytes, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken, TransactionModification, }; diff --git a/crates/rpc/src/v1/traits/traces.rs b/crates/rpc/src/v1/traits/traces.rs index db8dfa198..e214226d1 100644 --- a/crates/rpc/src/v1/traits/traces.rs +++ b/crates/rpc/src/v1/traits/traces.rs @@ -19,7 +19,7 @@ use ethereum_types::H256; use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use v1::types::{ +use crate::v1::types::{ BlockNumber, Bytes, CallRequest, Index, LocalizedTrace, TraceFilter, TraceOptions, TraceResults, TraceResultsWithTransactionHash, }; diff --git a/crates/rpc/src/v1/traits/web3.rs b/crates/rpc/src/v1/traits/web3.rs index a2323a26b..01d8329b4 100644 --- a/crates/rpc/src/v1/traits/web3.rs +++ b/crates/rpc/src/v1/traits/web3.rs @@ -19,7 +19,7 @@ use ethereum_types::H256; use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use v1::types::Bytes; +use crate::v1::types::Bytes; /// Web3 rpc interface. #[rpc(server)] diff --git a/crates/rpc/src/v1/types/account_info.rs b/crates/rpc/src/v1/types/account_info.rs index dd1eb612c..4739eed7b 100644 --- a/crates/rpc/src/v1/types/account_info.rs +++ b/crates/rpc/src/v1/types/account_info.rs @@ -17,7 +17,7 @@ //! Return types for RPC calls use ethereum_types::{Address, Public, H160, H256, U256}; -use v1::types::Bytes; +use crate::v1::types::Bytes; /// Account information. #[derive(Debug, Default, Clone, PartialEq, Serialize)] diff --git a/crates/rpc/src/v1/types/block.rs b/crates/rpc/src/v1/types/block.rs index b026000bd..eca91a181 100644 --- a/crates/rpc/src/v1/types/block.rs +++ b/crates/rpc/src/v1/types/block.rs @@ -19,7 +19,7 @@ use std::{collections::BTreeMap, ops::Deref}; use ethereum_types::{Bloom as H2048, H160, H256, U256}; use serde::{ser::Error, Serialize, Serializer}; use crate::types::{encoded::Header as EthHeader, BlockNumber}; -use v1::types::{Bytes, Transaction}; +use crate::v1::types::{Bytes, Transaction}; /// Block Transactions #[derive(Debug)] @@ -221,7 +221,7 @@ mod tests { use ethereum_types::{Bloom as H2048, H160, H256, H64, U256}; use serde_json; use std::collections::BTreeMap; - use v1::types::{Bytes, Transaction}; + use crate::v1::types::{Bytes, Transaction}; #[test] fn test_serialize_block_transactions() { diff --git a/crates/rpc/src/v1/types/call_request.rs b/crates/rpc/src/v1/types/call_request.rs index 296210642..b396e6af5 100644 --- a/crates/rpc/src/v1/types/call_request.rs +++ b/crates/rpc/src/v1/types/call_request.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use ethereum_types::{H160, U256, U64}; -use v1::{ +use crate::v1::{ helpers::CallRequest as Request, types::{AccessList, Bytes}, }; diff --git a/crates/rpc/src/v1/types/confirmations.rs b/crates/rpc/src/v1/types/confirmations.rs index 5471d8cc5..1acddf9b8 100644 --- a/crates/rpc/src/v1/types/confirmations.rs +++ b/crates/rpc/src/v1/types/confirmations.rs @@ -23,7 +23,7 @@ use std::fmt; use ethereum_types::{H160, H256, H520, U256}; use ethkey::Password; -use v1::{ +use crate::v1::{ helpers, types::{Bytes, Origin, RichRawTransaction, TransactionCondition, TransactionRequest}, }; @@ -305,7 +305,7 @@ mod tests { use ethereum_types::{Address, H256, U256}; use serde_json; use std::str::FromStr; - use v1::{helpers, types::TransactionCondition}; + use crate::v1::{helpers, types::TransactionCondition}; #[test] fn should_serialize_sign_confirmation() { diff --git a/crates/rpc/src/v1/types/eip191.rs b/crates/rpc/src/v1/types/eip191.rs index 6733cc778..3f31e089e 100644 --- a/crates/rpc/src/v1/types/eip191.rs +++ b/crates/rpc/src/v1/types/eip191.rs @@ -18,7 +18,7 @@ use ethereum_types::H160; use serde::{de, Deserialize, Deserializer}; -use v1::types::Bytes; +use crate::v1::types::Bytes; /// EIP-191 version specifier #[derive(Debug)] diff --git a/crates/rpc/src/v1/types/fee_history.rs b/crates/rpc/src/v1/types/fee_history.rs index 6c7eaf865..03f61e263 100644 --- a/crates/rpc/src/v1/types/fee_history.rs +++ b/crates/rpc/src/v1/types/fee_history.rs @@ -17,7 +17,7 @@ //! Return types for RPC calls use ethereum_types::U256; -use v1::types::BlockNumber; +use crate::v1::types::BlockNumber; /// Account information. #[derive(Debug, Default, Clone, PartialEq, Serialize)] diff --git a/crates/rpc/src/v1/types/filter.rs b/crates/rpc/src/v1/types/filter.rs index b7a056ea6..5c21f63ca 100644 --- a/crates/rpc/src/v1/types/filter.rs +++ b/crates/rpc/src/v1/types/filter.rs @@ -23,7 +23,7 @@ use serde::{ use serde_json::{from_value, Value}; use crate::types::{filter::Filter as EthFilter, ids::BlockId}; -use v1::{ +use crate::v1::{ helpers::errors::invalid_params, types::{BlockNumber, Log}, }; @@ -178,7 +178,7 @@ mod tests { use serde_json; use std::str::FromStr; use crate::types::{filter::Filter as EthFilter, ids::BlockId}; - use v1::types::BlockNumber; + use crate::v1::types::BlockNumber; #[test] fn topic_deserialization() { diff --git a/crates/rpc/src/v1/types/log.rs b/crates/rpc/src/v1/types/log.rs index ec9a3266f..f20064ff1 100644 --- a/crates/rpc/src/v1/types/log.rs +++ b/crates/rpc/src/v1/types/log.rs @@ -16,7 +16,7 @@ use ethereum_types::{H160, H256, U256}; use crate::types::log_entry::{LocalizedLogEntry, LogEntry}; -use v1::types::Bytes; +use crate::v1::types::Bytes; /// Log #[derive(Debug, Serialize, PartialEq, Eq, Hash, Clone)] @@ -89,7 +89,7 @@ mod tests { use ethereum_types::{H160, H256, U256}; use serde_json; use std::str::FromStr; - use v1::types::Log; + use crate::v1::types::Log; #[test] fn log_serialization() { diff --git a/crates/rpc/src/v1/types/pubsub.rs b/crates/rpc/src/v1/types/pubsub.rs index 17fa3b878..2f0ef1d0e 100644 --- a/crates/rpc/src/v1/types/pubsub.rs +++ b/crates/rpc/src/v1/types/pubsub.rs @@ -19,7 +19,7 @@ use ethereum_types::H256; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{from_value, Value}; -use v1::types::{Filter, Log, RichHeader}; +use crate::v1::types::{Filter, Log, RichHeader}; /// Subscription result. #[derive(Debug, Clone, PartialEq, Eq)] @@ -96,7 +96,7 @@ impl<'a> Deserialize<'a> for Params { mod tests { use super::{Kind, Params, Result}; use serde_json; - use v1::types::{filter::VariadicValue, Filter, Header, RichHeader}; + use crate::v1::types::{filter::VariadicValue, Filter, Header, RichHeader}; #[test] fn should_deserialize_kind() { diff --git a/crates/rpc/src/v1/types/receipt.rs b/crates/rpc/src/v1/types/receipt.rs index c187d1b95..9c6d8caa4 100644 --- a/crates/rpc/src/v1/types/receipt.rs +++ b/crates/rpc/src/v1/types/receipt.rs @@ -16,7 +16,7 @@ use ethereum_types::{Bloom as H2048, H160, H256, U256, U64}; use crate::types::receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome, TypedReceipt}; -use v1::types::Log; +use crate::v1::types::Log; /// Receipt #[derive(Debug, Serialize)] @@ -148,7 +148,7 @@ mod tests { use ethereum_types::{Bloom, H256}; use serde_json; use crate::types::transaction::TypedTxId; - use v1::types::{Log, Receipt}; + use crate::v1::types::{Log, Receipt}; #[test] fn receipt_serialization() { diff --git a/crates/rpc/src/v1/types/secretstore.rs b/crates/rpc/src/v1/types/secretstore.rs index bf77ca0a0..7ab011de9 100644 --- a/crates/rpc/src/v1/types/secretstore.rs +++ b/crates/rpc/src/v1/types/secretstore.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use ethereum_types::H512; -use v1::types::Bytes; +use crate::v1::types::Bytes; /// Encrypted document key. #[derive(Default, Debug, Serialize, PartialEq)] diff --git a/crates/rpc/src/v1/types/trace.rs b/crates/rpc/src/v1/types/trace.rs index 89884fe65..12682bc7a 100644 --- a/crates/rpc/src/v1/types/trace.rs +++ b/crates/rpc/src/v1/types/trace.rs @@ -26,7 +26,7 @@ use serde::{ser::SerializeStruct, Serialize, Serializer}; use crate::types::{account_diff, state_diff}; use vm; -use v1::types::Bytes; +use crate::v1::types::Bytes; #[derive(Debug, Serialize)] /// A diff of some chunk of memory. @@ -682,7 +682,7 @@ mod tests { use ethereum_types::{Address, H256}; use serde_json; use std::collections::BTreeMap; - use v1::types::Bytes; + use crate::v1::types::Bytes; #[test] fn should_serialize_trace_results() { diff --git a/crates/rpc/src/v1/types/trace_filter.rs b/crates/rpc/src/v1/types/trace_filter.rs index 7c61c78a3..a0c318aa0 100644 --- a/crates/rpc/src/v1/types/trace_filter.rs +++ b/crates/rpc/src/v1/types/trace_filter.rs @@ -18,7 +18,7 @@ use ethcore::{client, client::BlockId}; use ethereum_types::H160; -use v1::types::BlockNumber; +use crate::v1::types::BlockNumber; /// Trace filter #[derive(Debug, PartialEq, Deserialize)] @@ -71,7 +71,7 @@ impl Into for TraceFilter { mod tests { use ethereum_types::Address; use serde_json; - use v1::types::{BlockNumber, TraceFilter}; + use crate::v1::types::{BlockNumber, TraceFilter}; #[test] fn test_empty_trace_filter_deserialize() { diff --git a/crates/rpc/src/v1/types/transaction.rs b/crates/rpc/src/v1/types/transaction.rs index ebc330a23..92d8e2f13 100644 --- a/crates/rpc/src/v1/types/transaction.rs +++ b/crates/rpc/src/v1/types/transaction.rs @@ -24,7 +24,7 @@ use crate::types::transaction::{ Action, LocalizedTransaction, PendingTransaction, SignedTransaction, TypedTransaction, TypedTxId, }; -use v1::types::{AccessList, Bytes, TransactionCondition}; +use crate::v1::types::{AccessList, Bytes, TransactionCondition}; /// Transaction #[derive(Debug, Default, Clone, PartialEq, Serialize)] diff --git a/crates/rpc/src/v1/types/transaction_request.rs b/crates/rpc/src/v1/types/transaction_request.rs index 1f2493405..b37bdbbaa 100644 --- a/crates/rpc/src/v1/types/transaction_request.rs +++ b/crates/rpc/src/v1/types/transaction_request.rs @@ -18,7 +18,7 @@ use ansi_term::Colour; use ethereum_types::{H160, U256, U64}; -use v1::{ +use crate::v1::{ helpers, types::{AccessList, Bytes, TransactionCondition}, }; @@ -171,7 +171,7 @@ mod tests { use rustc_hex::FromHex; use serde_json; use std::str::FromStr; - use v1::types::TransactionCondition; + use crate::v1::types::TransactionCondition; #[test] fn transaction_request_deserialize() { diff --git a/crates/util/cli-signer/rpc-client/src/client.rs b/crates/util/cli-signer/rpc-client/src/client.rs index d27862036..9aa6f889e 100644 --- a/crates/util/cli-signer/rpc-client/src/client.rs +++ b/crates/util/cli-signer/rpc-client/src/client.rs @@ -30,7 +30,7 @@ use parking_lot::Mutex; use std::{fs::File, path::PathBuf}; use url::Url; -use ws::ws::{ +use crate::ws::ws::{ self, Error as WsError, ErrorKind as WsErrorKind, Handler, Handshake, Message, Request, Result as WsResult, Sender, }; @@ -46,7 +46,7 @@ use jsonrpc_core::{ Error as JsonRpcError, Id, Params, Version, }; -use BoxFuture; +use crate::BoxFuture; /// The actual websocket connection handler, passed into the /// event loop of ws-rs diff --git a/crates/util/cli-signer/rpc-client/src/signer_client.rs b/crates/util/cli-signer/rpc-client/src/signer_client.rs index 00befd375..8fca15a21 100644 --- a/crates/util/cli-signer/rpc-client/src/signer_client.rs +++ b/crates/util/cli-signer/rpc-client/src/signer_client.rs @@ -21,7 +21,7 @@ use rpc::signer::{ConfirmationRequest, TransactionCondition, TransactionModifica use serde; use serde_json::{to_value, Value as JsonValue}; use std::path::PathBuf; -use BoxFuture; +use crate::BoxFuture; pub struct SignerRpc { rpc: Rpc, From aa38a06a6d644aa355a584e427eb1a55b3f2c56c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Apr 2025 14:13:43 +0200 Subject: [PATCH 437/687] cargo fmt --all -- --config imports_granularity=Crate --- bin/ethkey/src/main.rs | 4 +- bin/ethstore/src/crack.rs | 2 +- bin/ethstore/src/main.rs | 4 +- bin/evmbin/benches/mod.rs | 4 +- bin/evmbin/src/info.rs | 5 +- bin/evmbin/src/main.rs | 2 +- bin/oe/account.rs | 2 +- bin/oe/account_utils.rs | 19 +- bin/oe/blockchain.rs | 23 +- bin/oe/cli/presets/mod.rs | 5 +- bin/oe/configuration.rs | 22 +- bin/oe/helpers.rs | 10 +- bin/oe/informant.rs | 6 +- bin/oe/lib.rs | 36 +- bin/oe/logger/src/lib.rs | 2 +- bin/oe/main.rs | 4 +- bin/oe/metrics.rs | 4 +- bin/oe/modules.rs | 2 +- bin/oe/params.rs | 2 +- bin/oe/presale.rs | 2 +- bin/oe/rpc.rs | 36 +- bin/oe/rpc_apis.rs | 2 +- bin/oe/run.rs | 12 +- bin/oe/snapshot.rs | 4 +- bin/oe/upgrade.rs | 4 +- bin/oe/user_defaults.rs | 2 +- crates/accounts/ethkey/src/brain.rs | 5 +- crates/concensus/ethash/benches/progpow.rs | 2 +- crates/concensus/ethash/src/cache.rs | 10 +- crates/concensus/ethash/src/compute.rs | 12 +- crates/concensus/ethash/src/keccak.rs | 4 +- crates/concensus/ethash/src/lib.rs | 2 +- crates/concensus/ethash/src/progpow.rs | 14 +- crates/concensus/ethash/src/seed_compute.rs | 6 +- crates/concensus/miner/local-store/src/lib.rs | 14 +- crates/concensus/miner/src/pool/client.rs | 2 +- crates/concensus/miner/src/pool/listener.rs | 2 +- .../miner/src/pool/local_transactions.rs | 2 +- crates/concensus/miner/src/pool/mod.rs | 2 +- crates/concensus/miner/src/pool/queue.rs | 2 +- crates/concensus/miner/src/pool/ready.rs | 2 +- .../concensus/miner/src/pool/tests/client.rs | 4 +- crates/concensus/miner/src/pool/tests/mod.rs | 2 +- crates/concensus/miner/src/pool/tests/tx.rs | 6 +- .../miner/src/pool/transaction_filter.rs | 3 +- crates/concensus/miner/src/pool/verifier.rs | 2 +- .../miner/src/service_transaction_checker.rs | 2 +- crates/concensus/miner/stratum/src/lib.rs | 9 +- crates/concensus/miner/using-queue/src/lib.rs | 6 +- crates/db/journaldb/src/archivedb.rs | 9 +- crates/db/journaldb/src/as_hash_db_impls.rs | 10 +- crates/db/journaldb/src/earlymergedb.rs | 10 +- crates/db/journaldb/src/overlaydb.rs | 4 +- crates/db/journaldb/src/overlayrecentdb.rs | 10 +- crates/db/journaldb/src/refcounteddb.rs | 14 +- crates/db/journaldb/src/traits.rs | 2 +- crates/db/memory-db/benches/bench.rs | 2 +- crates/db/memory-db/src/lib.rs | 2 +- crates/ethcore/benches/builtin.rs | 672 +++++++++--------- crates/ethcore/service/src/error.rs | 2 +- crates/ethcore/service/src/service.rs | 8 +- crates/ethcore/service/src/stop_guard.rs | 2 +- crates/ethcore/src/account_db.rs | 2 +- crates/ethcore/src/block.rs | 30 +- crates/ethcore/src/client/ancient_import.rs | 9 +- crates/ethcore/src/client/bad_blocks.rs | 3 +- crates/ethcore/src/client/chain_notify.rs | 3 +- crates/ethcore/src/client/client.rs | 169 ++--- crates/ethcore/src/client/config.rs | 9 +- crates/ethcore/src/client/evm_test_client.rs | 12 +- crates/ethcore/src/client/io_message.rs | 3 +- crates/ethcore/src/client/mod.rs | 3 +- crates/ethcore/src/client/test_client.rs | 78 +- crates/ethcore/src/client/trace.rs | 8 +- crates/ethcore/src/client/traits.rs | 58 +- .../src/engines/authority_round/finality.rs | 26 +- .../src/engines/authority_round/mod.rs | 113 +-- .../src/engines/authority_round/randomness.rs | 4 +- .../src/engines/authority_round/util.rs | 6 +- crates/ethcore/src/engines/basic_authority.rs | 28 +- crates/ethcore/src/engines/block_reward.rs | 25 +- .../ethcore/src/engines/clique/block_state.rs | 16 +- crates/ethcore/src/engines/clique/mod.rs | 56 +- crates/ethcore/src/engines/clique/tests.rs | 3 +- crates/ethcore/src/engines/clique/util.rs | 14 +- .../src/engines/hbbft/block_reward_hbbft.rs | 6 +- .../contracts/connectivity_tracker_hbbft.rs | 5 +- .../engines/hbbft/contracts/keygen_history.rs | 24 +- .../src/engines/hbbft/contracts/permission.rs | 2 +- .../src/engines/hbbft/contracts/staking.rs | 10 +- .../engines/hbbft/contracts/validator_set.rs | 12 +- .../ethcore/src/engines/hbbft/contribution.rs | 10 +- .../src/keygen_history_helpers.rs | 2 +- .../hbbft/hbbft_config_generator/src/main.rs | 7 +- .../hbbft/hbbft_early_epoch_end_manager.rs | 4 +- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 66 +- .../src/engines/hbbft/hbbft_engine_cache.rs | 3 +- .../engines/hbbft/hbbft_message_memorium.rs | 38 +- .../hbbft/hbbft_network_fork_manager.rs | 20 +- .../engines/hbbft/hbbft_peers_management.rs | 7 +- .../ethcore/src/engines/hbbft/hbbft_state.rs | 12 +- .../src/engines/hbbft/keygen_transactions.rs | 35 +- crates/ethcore/src/engines/hbbft/sealing.rs | 2 +- .../engines/hbbft/test/create_transactions.rs | 2 +- .../engines/hbbft/test/hbbft_test_client.rs | 16 +- crates/ethcore/src/engines/hbbft/test/mod.rs | 17 +- .../src/engines/hbbft/utils/bound_contract.rs | 3 +- .../hbbft/utils/transactions_shuffling.rs | 2 +- crates/ethcore/src/engines/instant_seal.rs | 15 +- crates/ethcore/src/engines/mod.rs | 30 +- crates/ethcore/src/engines/null_engine.rs | 22 +- crates/ethcore/src/engines/signer.rs | 2 +- .../src/engines/validator_set/contract.rs | 56 +- .../ethcore/src/engines/validator_set/mod.rs | 6 +- .../src/engines/validator_set/multi.rs | 28 +- .../engines/validator_set/safe_contract.rs | 90 ++- .../src/engines/validator_set/simple_list.rs | 8 +- .../ethcore/src/engines/validator_set/test.rs | 13 +- crates/ethcore/src/error.rs | 6 +- crates/ethcore/src/ethereum/ethash.rs | 36 +- crates/ethcore/src/ethereum/mod.rs | 6 +- crates/ethcore/src/executed.rs | 6 +- crates/ethcore/src/executive.rs | 330 +++++---- crates/ethcore/src/externalities.rs | 38 +- crates/ethcore/src/json_tests/chain.rs | 14 +- crates/ethcore/src/json_tests/difficulty.rs | 3 +- crates/ethcore/src/json_tests/executive.rs | 12 +- crates/ethcore/src/json_tests/local.rs | 12 +- crates/ethcore/src/json_tests/mod.rs | 2 +- crates/ethcore/src/json_tests/state.rs | 8 +- crates/ethcore/src/json_tests/transaction.rs | 14 +- crates/ethcore/src/lib.rs | 2 +- crates/ethcore/src/machine/impls.rs | 30 +- crates/ethcore/src/miner/miner.rs | 92 +-- crates/ethcore/src/miner/mod.rs | 26 +- crates/ethcore/src/miner/pool_client.rs | 24 +- crates/ethcore/src/miner/stratum.rs | 14 +- crates/ethcore/src/pod_account.rs | 7 +- crates/ethcore/src/pod_state.rs | 12 +- crates/ethcore/src/snapshot/account.rs | 20 +- crates/ethcore/src/snapshot/block.rs | 12 +- .../src/snapshot/consensus/authority.rs | 24 +- crates/ethcore/src/snapshot/consensus/mod.rs | 14 +- crates/ethcore/src/snapshot/consensus/work.rs | 16 +- crates/ethcore/src/snapshot/io.rs | 4 +- crates/ethcore/src/snapshot/mod.rs | 22 +- crates/ethcore/src/snapshot/service.rs | 50 +- crates/ethcore/src/snapshot/tests/helpers.rs | 18 +- .../src/snapshot/tests/proof_of_authority.rs | 10 +- .../src/snapshot/tests/proof_of_work.rs | 17 +- crates/ethcore/src/snapshot/tests/service.rs | 30 +- crates/ethcore/src/snapshot/tests/state.rs | 15 +- crates/ethcore/src/snapshot/watcher.rs | 8 +- crates/ethcore/src/spec/genesis.rs | 2 +- crates/ethcore/src/spec/seal.rs | 2 +- crates/ethcore/src/spec/spec.rs | 36 +- crates/ethcore/src/state/account.rs | 27 +- crates/ethcore/src/state/backend.rs | 2 +- crates/ethcore/src/state/mod.rs | 46 +- crates/ethcore/src/state/substate.rs | 4 +- crates/ethcore/src/state_db.rs | 9 +- crates/ethcore/src/test_helpers.rs | 43 +- crates/ethcore/src/tests/client.rs | 39 +- crates/ethcore/src/tests/evm.rs | 10 +- crates/ethcore/src/tests/trace.rs | 26 +- crates/ethcore/src/trace/db.rs | 23 +- crates/ethcore/src/trace/executive_tracer.rs | 23 +- crates/ethcore/src/trace/import.rs | 2 +- crates/ethcore/src/trace/mod.rs | 4 +- crates/ethcore/src/trace/noop_tracer.rs | 4 +- crates/ethcore/src/trace/types/filter.rs | 8 +- crates/ethcore/src/trace/types/flat.rs | 6 +- crates/ethcore/src/trace/types/localized.rs | 2 +- crates/ethcore/src/transaction_ext.rs | 2 +- crates/ethcore/src/tx_filter.rs | 84 ++- .../src/verification/canon_verifier.rs | 7 +- crates/ethcore/src/verification/mod.rs | 2 +- .../ethcore/src/verification/noop_verifier.rs | 7 +- crates/ethcore/src/verification/queue/kind.rs | 26 +- crates/ethcore/src/verification/queue/mod.rs | 24 +- .../ethcore/src/verification/verification.rs | 58 +- crates/ethcore/src/verification/verifier.rs | 5 +- crates/ethcore/sync/src/api.rs | 51 +- crates/ethcore/sync/src/block_sync.rs | 92 ++- crates/ethcore/sync/src/blocks.rs | 16 +- crates/ethcore/sync/src/chain/handler.rs | 22 +- crates/ethcore/sync/src/chain/mod.rs | 28 +- .../src/chain/pooled_transactions_overview.rs | 2 +- crates/ethcore/sync/src/chain/propagator.rs | 36 +- crates/ethcore/sync/src/chain/request_id.rs | 4 +- crates/ethcore/sync/src/chain/requester.rs | 4 +- crates/ethcore/sync/src/chain/supplier.rs | 14 +- crates/ethcore/sync/src/lib.rs | 6 +- crates/ethcore/sync/src/snapshot.rs | 8 +- crates/ethcore/sync/src/sync_io.rs | 8 +- crates/ethcore/sync/src/tests/chain.rs | 4 +- crates/ethcore/sync/src/tests/consensus.rs | 8 +- crates/ethcore/sync/src/tests/helpers.rs | 22 +- crates/ethcore/sync/src/tests/snapshot.rs | 6 +- crates/ethcore/sync/src/transactions_stats.rs | 3 +- crates/net/network-devp2p/src/connection.rs | 8 +- crates/net/network-devp2p/src/discovery.rs | 72 +- crates/net/network-devp2p/src/handshake.rs | 16 +- crates/net/network-devp2p/src/host.rs | 36 +- crates/net/network-devp2p/src/ip_utils.rs | 6 +- crates/net/network-devp2p/src/lib.rs | 2 +- crates/net/network-devp2p/src/node_table.rs | 90 ++- crates/net/network-devp2p/src/service.rs | 1 - crates/net/network-devp2p/src/session.rs | 18 +- crates/net/network-devp2p/tests/tests.rs | 4 +- crates/net/network/src/client_version.rs | 16 +- crates/net/network/src/error.rs | 2 +- crates/net/network/src/lib.rs | 2 +- crates/net/node-filter/src/lib.rs | 2 +- crates/rpc/src/authcodes.rs | 2 +- crates/rpc/src/lib.rs | 19 +- crates/rpc/src/tests/rpc.rs | 6 +- crates/rpc/src/tests/ws.rs | 10 +- crates/rpc/src/v1/extractors.rs | 12 +- crates/rpc/src/v1/helpers/dispatch/full.rs | 16 +- crates/rpc/src/v1/helpers/dispatch/mod.rs | 16 +- .../v1/helpers/dispatch/prospective_signer.rs | 6 +- crates/rpc/src/v1/helpers/dispatch/signing.rs | 14 +- crates/rpc/src/v1/helpers/eip191.rs | 12 +- crates/rpc/src/v1/helpers/errors.rs | 20 +- .../src/v1/helpers/external_signer/oneshot.rs | 4 +- .../helpers/external_signer/signing_queue.rs | 14 +- crates/rpc/src/v1/helpers/fake_sign.rs | 4 +- crates/rpc/src/v1/helpers/mod.rs | 2 +- crates/rpc/src/v1/helpers/nonce.rs | 5 +- crates/rpc/src/v1/helpers/poll_filter.rs | 3 +- crates/rpc/src/v1/helpers/poll_manager.rs | 2 +- crates/rpc/src/v1/helpers/requests.rs | 2 +- crates/rpc/src/v1/helpers/secretstore.rs | 6 +- crates/rpc/src/v1/helpers/signature.rs | 8 +- crates/rpc/src/v1/helpers/subscribers.rs | 2 +- .../src/v1/helpers/subscription_manager.rs | 9 +- crates/rpc/src/v1/helpers/work.rs | 4 +- crates/rpc/src/v1/impls/debug.rs | 4 +- crates/rpc/src/v1/impls/eth.rs | 63 +- crates/rpc/src/v1/impls/eth_filter.rs | 12 +- crates/rpc/src/v1/impls/eth_pubsub.rs | 8 +- crates/rpc/src/v1/impls/net.rs | 2 +- crates/rpc/src/v1/impls/parity.rs | 78 +- crates/rpc/src/v1/impls/parity_accounts.rs | 14 +- crates/rpc/src/v1/impls/parity_set.rs | 12 +- crates/rpc/src/v1/impls/personal.rs | 24 +- crates/rpc/src/v1/impls/pubsub.rs | 9 +- crates/rpc/src/v1/impls/rpc.rs | 2 +- crates/rpc/src/v1/impls/secretstore.rs | 6 +- crates/rpc/src/v1/impls/signer.rs | 22 +- crates/rpc/src/v1/impls/signing.rs | 2 +- crates/rpc/src/v1/impls/signing_unsafe.rs | 10 +- crates/rpc/src/v1/impls/traces.rs | 16 +- crates/rpc/src/v1/impls/web3.rs | 2 +- crates/rpc/src/v1/informant.rs | 2 +- crates/rpc/src/v1/mod.rs | 2 +- crates/rpc/src/v1/tests/eth.rs | 35 +- .../rpc/src/v1/tests/helpers/miner_service.rs | 26 +- crates/rpc/src/v1/tests/mocked/debug.rs | 2 +- crates/rpc/src/v1/tests/mocked/eth.rs | 18 +- crates/rpc/src/v1/tests/mocked/eth_pubsub.rs | 4 +- crates/rpc/src/v1/tests/mocked/net.rs | 6 +- crates/rpc/src/v1/tests/mocked/parity.rs | 14 +- .../src/v1/tests/mocked/parity_accounts.rs | 149 ++-- crates/rpc/src/v1/tests/mocked/parity_set.rs | 9 +- crates/rpc/src/v1/tests/mocked/personal.rs | 8 +- crates/rpc/src/v1/tests/mocked/pubsub.rs | 7 +- crates/rpc/src/v1/tests/mocked/rpc.rs | 2 +- crates/rpc/src/v1/tests/mocked/secretstore.rs | 29 +- crates/rpc/src/v1/tests/mocked/signer.rs | 13 +- crates/rpc/src/v1/tests/mocked/signing.rs | 104 +-- .../rpc/src/v1/tests/mocked/signing_unsafe.rs | 6 +- crates/rpc/src/v1/tests/mocked/traces.rs | 4 +- crates/rpc/src/v1/tests/mocked/web3.rs | 2 +- crates/rpc/src/v1/traits/eth.rs | 4 +- crates/rpc/src/v1/traits/eth_pubsub.rs | 2 +- crates/rpc/src/v1/traits/eth_signing.rs | 2 +- crates/rpc/src/v1/traits/parity.rs | 4 +- crates/rpc/src/v1/traits/parity_accounts.rs | 2 +- crates/rpc/src/v1/traits/parity_signing.rs | 2 +- crates/rpc/src/v1/traits/personal.rs | 8 +- crates/rpc/src/v1/traits/pubsub.rs | 2 +- crates/rpc/src/v1/traits/secretstore.rs | 2 +- crates/rpc/src/v1/traits/signer.rs | 2 +- crates/rpc/src/v1/traits/traces.rs | 8 +- crates/rpc/src/v1/types/account_info.rs | 2 +- crates/rpc/src/v1/types/block.rs | 14 +- crates/rpc/src/v1/types/block_number.rs | 2 +- crates/rpc/src/v1/types/call_request.rs | 2 +- crates/rpc/src/v1/types/confirmations.rs | 6 +- crates/rpc/src/v1/types/derivation.rs | 2 +- crates/rpc/src/v1/types/eip191.rs | 6 +- crates/rpc/src/v1/types/fee_history.rs | 2 +- crates/rpc/src/v1/types/filter.rs | 22 +- crates/rpc/src/v1/types/index.rs | 2 +- crates/rpc/src/v1/types/log.rs | 8 +- crates/rpc/src/v1/types/mod.rs | 2 +- crates/rpc/src/v1/types/pubsub.rs | 8 +- crates/rpc/src/v1/types/receipt.rs | 14 +- crates/rpc/src/v1/types/secretstore.rs | 2 +- crates/rpc/src/v1/types/trace.rs | 8 +- crates/rpc/src/v1/types/trace_filter.rs | 8 +- crates/rpc/src/v1/types/transaction.rs | 20 +- .../src/v1/types/transaction_access_list.rs | 2 +- .../rpc/src/v1/types/transaction_request.rs | 6 +- crates/runtime/io/src/lib.rs | 10 +- crates/runtime/io/src/service_mio.rs | 7 +- crates/runtime/io/src/service_non_mio.rs | 3 +- crates/runtime/io/src/worker.rs | 9 +- crates/runtime/runtime/src/lib.rs | 2 +- .../util/cli-signer/rpc-client/src/client.rs | 6 +- .../rpc-client/src/signer_client.rs | 8 +- crates/util/cli-signer/src/lib.rs | 2 +- crates/util/dir/src/lib.rs | 4 +- crates/util/rlp-compress/tests/compress.rs | 2 +- crates/util/version/build.rs | 2 +- crates/vm/vm/src/action_params.rs | 4 +- crates/vm/vm/src/error.rs | 4 +- crates/vm/vm/src/ext.rs | 12 +- crates/vm/vm/src/tests.rs | 16 +- crates/vm/wasm/src/env.rs | 6 +- 322 files changed, 3050 insertions(+), 2580 deletions(-) diff --git a/bin/ethkey/src/main.rs b/bin/ethkey/src/main.rs index 230351ef4..d8b7fab14 100644 --- a/bin/ethkey/src/main.rs +++ b/bin/ethkey/src/main.rs @@ -30,10 +30,10 @@ extern crate serde_derive; use std::{env, fmt, io, num::ParseIntError, process, sync}; use crypto::publickey::{ - sign, verify_address, verify_public, Error as EthkeyError, Generator, KeyPair, Random, + Error as EthkeyError, Generator, KeyPair, Random, sign, verify_address, verify_public, }; use docopt::Docopt; -use ethkey::{brain_recover, Brain, BrainPrefix, Prefix}; +use ethkey::{Brain, BrainPrefix, Prefix, brain_recover}; use rustc_hex::{FromHex, FromHexError}; const USAGE: &'static str = r#" diff --git a/bin/ethstore/src/crack.rs b/bin/ethstore/src/crack.rs index 04f6086a5..3d1fadd71 100644 --- a/bin/ethstore/src/crack.rs +++ b/bin/ethstore/src/crack.rs @@ -17,7 +17,7 @@ use parking_lot::Mutex; use std::{cmp, collections::VecDeque, sync::Arc, thread}; -use ethstore::{ethkey::Password, Error, PresaleWallet}; +use ethstore::{Error, PresaleWallet, ethkey::Password}; use num_cpus; pub fn run(passwords: VecDeque, wallet_path: &str) -> Result<(), Error> { diff --git a/bin/ethstore/src/main.rs b/bin/ethstore/src/main.rs index 6d275194e..439ec7f29 100644 --- a/bin/ethstore/src/main.rs +++ b/bin/ethstore/src/main.rs @@ -32,10 +32,10 @@ use std::{collections::VecDeque, env, fmt, fs, io::Read, process}; use docopt::Docopt; use ethstore::{ + EthStore, PresaleWallet, SecretStore, SecretVaultRef, SimpleSecretStore, StoreAccountRef, accounts_dir::{KeyDirectory, RootDiskDirectory}, ethkey::{Address, Password}, - import_accounts, EthStore, PresaleWallet, SecretStore, SecretVaultRef, SimpleSecretStore, - StoreAccountRef, + import_accounts, }; mod crack; diff --git a/bin/evmbin/benches/mod.rs b/bin/evmbin/benches/mod.rs index e02f1ea91..d7b6fb771 100644 --- a/bin/evmbin/benches/mod.rs +++ b/bin/evmbin/benches/mod.rs @@ -28,13 +28,13 @@ extern crate evm; extern crate rustc_hex; extern crate vm; -use criterion::{black_box, Criterion}; +use criterion::{Criterion, black_box}; use std::sync::Arc; use ethereum_types::U256; use evm::Factory; use rustc_hex::FromHex; -use vm::{tests::FakeExt, ActionParams, Ext}; +use vm::{ActionParams, Ext, tests::FakeExt}; criterion_group!( evmbin, diff --git a/bin/evmbin/src/info.rs b/bin/evmbin/src/info.rs index f34086f22..310097880 100644 --- a/bin/evmbin/src/info.rs +++ b/bin/evmbin/src/info.rs @@ -16,14 +16,15 @@ //! VM runner. +use crate::types::transaction; use ethcore::{ + TrieSpec, client::{self, EvmTestClient, EvmTestError, TransactErr, TransactSuccess}, - pod_state, spec, state, state_db, trace, TrieSpec, + pod_state, spec, state, state_db, trace, }; use ethereum_types::{H256, U256}; use ethjson; use std::time::{Duration, Instant}; -use crate::types::transaction; use vm::ActionParams; /// VM execution informant diff --git a/bin/evmbin/src/main.rs b/bin/evmbin/src/main.rs index 343f5118b..b5f9df147 100644 --- a/bin/evmbin/src/main.rs +++ b/bin/evmbin/src/main.rs @@ -44,7 +44,7 @@ extern crate tempdir; use bytes::Bytes; use docopt::Docopt; -use ethcore::{json_tests, spec, TrieSpec}; +use ethcore::{TrieSpec, json_tests, spec}; use ethereum_types::{Address, U256}; use ethjson::spec::ForkSpec; use evm::EnvInfo; diff --git a/bin/oe/account.rs b/bin/oe/account.rs index 0bd87cdbd..541013026 100644 --- a/bin/oe/account.rs +++ b/bin/oe/account.rs @@ -57,7 +57,7 @@ mod command { accounts::{AccountProvider, AccountProviderSettings}, helpers::{password_from_file, password_prompt}, }; - use ethstore::{accounts_dir::RootDiskDirectory, import_account, import_accounts, EthStore}; + use ethstore::{EthStore, accounts_dir::RootDiskDirectory, import_account, import_accounts}; use std::path::PathBuf; pub fn execute(cmd: AccountCmd) -> Result { diff --git a/bin/oe/account_utils.rs b/bin/oe/account_utils.rs index e93c12e68..d5da5afab 100644 --- a/bin/oe/account_utils.rs +++ b/bin/oe/account_utils.rs @@ -43,7 +43,9 @@ mod accounts { _cfg: AccountsConfig, _passwords: &[Password], ) -> Result { - warn!("Note: Your instance of OpenEthereum is running without account support. Some CLI options are ignored."); + warn!( + "Note: Your instance of OpenEthereum is running without account support. Some CLI options are ignored." + ); Ok(AccountProvider) } @@ -88,7 +90,7 @@ mod accounts { passwords: &[Password], ) -> Result { use crate::accounts::AccountProviderSettings; - use ethstore::{accounts_dir::RootDiskDirectory, EthStore}; + use ethstore::{EthStore, accounts_dir::RootDiskDirectory}; let path = dirs.keys_path(data_dir); upgrade_key_location(&dirs.legacy_keys_path(cfg.testnet), &path); @@ -105,8 +107,10 @@ mod accounts { | SpecType::Goerli | SpecType::Sokol | SpecType::Dev => vec![], - _ => vec![H160::from_str("00a329c0648769a73afac7f9381e08fb43dbea72") - .expect("the string is valid hex; qed")], + _ => vec![ + H160::from_str("00a329c0648769a73afac7f9381e08fb43dbea72") + .expect("the string is valid hex; qed"), + ], }, }; @@ -254,10 +258,13 @@ mod accounts { // Construct an error `String` with an adaptive hint on how to create an account. fn build_create_account_hint(spec: &SpecType, keys: &str) -> String { - format!("You can create an account via RPC, UI or `openethereum account new --chain {} --keys-path {}`.", spec, keys) + format!( + "You can create an account via RPC, UI or `openethereum account new --chain {} --keys-path {}`.", + spec, keys + ) } } pub use self::accounts::{ - accounts_list, miner_author, miner_local_accounts, prepare_account_provider, AccountProvider, + AccountProvider, accounts_list, miner_author, miner_local_accounts, prepare_account_provider, }; diff --git a/bin/oe/blockchain.rs b/bin/oe/blockchain.rs index cd82a102a..111d64235 100644 --- a/bin/oe/blockchain.rs +++ b/bin/oe/blockchain.rs @@ -20,10 +20,10 @@ use crate::{ bytes::ToPretty, cache::CacheConfig, db, - hash::{keccak, KECCAK_NULL_RLP}, + hash::{KECCAK_NULL_RLP, keccak}, helpers::{execute_upgrades, to_client_config}, informant::{FullNodeInformantData, Informant, MillisecondDuration}, - params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch}, + params::{Pruning, SpecType, Switch, fatdb_switch_to_bool, tracing_switch_to_bool}, types::data_format::DataFormat, user_defaults::UserDefaults, }; @@ -256,15 +256,16 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> { let report = client.report(); let ms = timer.elapsed().as_milliseconds(); - info!("Import completed in {} seconds, {} blocks, {} blk/s, {} transactions, {} tx/s, {} Mgas, {} Mgas/s", - ms / 1000, - report.blocks_imported, - (report.blocks_imported * 1000) as u64 / ms, - report.transactions_applied, - (report.transactions_applied * 1000) as u64 / ms, - report.gas_processed / 1_000_000, - (report.gas_processed / (ms * 1000)).low_u64(), - ); + info!( + "Import completed in {} seconds, {} blocks, {} blk/s, {} transactions, {} tx/s, {} Mgas, {} Mgas/s", + ms / 1000, + report.blocks_imported, + (report.blocks_imported * 1000) as u64 / ms, + report.transactions_applied, + (report.transactions_applied * 1000) as u64 / ms, + report.gas_processed / 1_000_000, + (report.gas_processed / (ms * 1000)).low_u64(), + ); Ok(()) } diff --git a/bin/oe/cli/presets/mod.rs b/bin/oe/cli/presets/mod.rs index 14a7bae12..4c362c3bb 100644 --- a/bin/oe/cli/presets/mod.rs +++ b/bin/oe/cli/presets/mod.rs @@ -23,6 +23,9 @@ pub fn preset_config_string(arg: &str) -> Result<&'static str, Error> { "non-standard-ports" => Ok(include_str!("./config.non-standard-ports.toml")), "insecure" => Ok(include_str!("./config.insecure.toml")), "dev-insecure" => Ok(include_str!("./config.dev-insecure.toml")), - _ => Err(Error::new(ErrorKind::InvalidInput, "Config doesn't match any presets [dev, mining, non-standard-ports, insecure, dev-insecure]")) + _ => Err(Error::new( + ErrorKind::InvalidInput, + "Config doesn't match any presets [dev, mining, non-standard-ports, insecure, dev-insecure]", + )), } } diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 0267a0cf6..63c05517f 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -20,14 +20,14 @@ use crate::{ hash::keccak, metrics::MetricsConfiguration, miner::pool, - sync::{self, validate_node_url, NetworkConfiguration}, + sync::{self, NetworkConfiguration, validate_node_url}, }; use ansi_term::Colour; use crate::crypto::publickey::{Public, Secret}; use ethcore::{ client::VMType, - miner::{stratum, MinerOptions}, + miner::{MinerOptions, stratum}, snapshot::SnapshotConfiguration, verification::queue::VerifierSettings, }; @@ -70,9 +70,8 @@ use crate::{ types::data_format::DataFormat, }; use dir::{ - self, default_data_path, default_local_path, + self, Directories, default_data_path, default_local_path, helpers::{replace_home, replace_home_and_local}, - Directories, }; use ethcore_logger::Config as LogConfig; use parity_rpc::NetworkSettings; @@ -757,13 +756,13 @@ impl Configuration { return Err(format!( "Failed to resolve hostname of a boot node: {}", line - )) + )); } Some(_) => { return Err(format!( "Invalid node address format given for a boot node: {}", line - )) + )); } } } @@ -801,7 +800,7 @@ impl Configuration { return Err(format!( "Invalid host given with `--nat extip:{}`", &self.args.arg_nat[6..] - )) + )); } } } else { @@ -1816,10 +1815,11 @@ mod tests { match conf.into_command().unwrap().cmd { Cmd::Run(c) => { assert_eq!(c.name, "Somebody"); - assert!(c - .net_conf - .client_version - .starts_with("OpenEthereum/Somebody/")); + assert!( + c.net_conf + .client_version + .starts_with("OpenEthereum/Somebody/") + ); } _ => panic!("Should be Cmd::Run"), } diff --git a/bin/oe/helpers.rs b/bin/oe/helpers.rs index 3869a1a56..786628d38 100644 --- a/bin/oe/helpers.rs +++ b/bin/oe/helpers.rs @@ -21,7 +21,7 @@ use crate::{ sync::{self, validate_node_url}, upgrade::{upgrade, upgrade_data_paths}, }; -use dir::{helpers::replace_home, DatabaseDirectories}; +use dir::{DatabaseDirectories, helpers::replace_home}; use ethcore::{ client::{BlockId, ClientConfig, DatabaseCompactionProfile, Mode, VMType, VerifierType}, miner::{Penalization, PendingSet}, @@ -591,9 +591,9 @@ but the first password is trimmed let res = join_set(Some(&test_set)).unwrap(); assert!( - res == "0x1111111111111111111111111111111111111111,0x0000000000000000000000000000000000000000" - || - res == "0x0000000000000000000000000000000000000000,0x1111111111111111111111111111111111111111" - ); + res == "0x1111111111111111111111111111111111111111,0x0000000000000000000000000000000000000000" + || res + == "0x0000000000000000000000000000000000000000,0x1111111111111111111111111111111111111111" + ); } } diff --git a/bin/oe/informant.rs b/bin/oe/informant.rs index aabf3a8ff..4ca3dbbd2 100644 --- a/bin/oe/informant.rs +++ b/bin/oe/informant.rs @@ -23,8 +23,8 @@ use self::ansi_term::{ use std::{ sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering}, Arc, + atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering}, }, time::{Duration, Instant}, }; @@ -40,9 +40,9 @@ use ethcore::{ BlockChainClient, BlockChainInfo, BlockId, BlockInfo, BlockQueueInfo, ChainInfo, ChainNotify, Client, ClientIoMessage, ClientReport, NewBlocks, }, - snapshot::{service::Service as SnapshotService, RestorationStatus, SnapshotService as SS}, + snapshot::{RestorationStatus, SnapshotService as SS, service::Service as SnapshotService}, }; -use number_prefix::{binary_prefix, Prefixed, Standalone}; +use number_prefix::{Prefixed, Standalone, binary_prefix}; use parity_rpc::{informant::RpcStats, is_major_importing_or_waiting}; use parking_lot::{Mutex, RwLock}; diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index 65f5388a6..fc2db1466 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -128,7 +128,7 @@ use std::alloc::System; pub use self::{configuration::Configuration, run::RunningClient}; pub use ethcore::exit::ShutdownManager; -pub use ethcore_logger::{setup_log, Config as LoggerConfig, RotatingLogger}; +pub use ethcore_logger::{Config as LoggerConfig, RotatingLogger, setup_log}; pub use parity_rpc::PubSubSession; #[cfg(feature = "memory_profiling")] @@ -157,23 +157,25 @@ fn run_deadlock_detection_thread() { let builder = std::thread::Builder::new().name("DeadlockDetection".to_string()); // Create a background thread which checks for deadlocks every 10s - let spawned = builder.spawn(move || loop { - thread::sleep(Duration::from_secs(10)); - let deadlocks = deadlock::check_deadlock(); - if deadlocks.is_empty() { - continue; - } + let spawned = builder.spawn(move || { + loop { + thread::sleep(Duration::from_secs(10)); + let deadlocks = deadlock::check_deadlock(); + if deadlocks.is_empty() { + continue; + } - warn!( - "{} {} detected", - deadlocks.len(), - Style::new().bold().paint("deadlock(s)") - ); - for (i, threads) in deadlocks.iter().enumerate() { - warn!("{} #{}", Style::new().bold().paint("Deadlock"), i); - for t in threads { - warn!("Thread Id {:#?}", t.thread_id()); - warn!("{:#?}", t.backtrace()); + warn!( + "{} {} detected", + deadlocks.len(), + Style::new().bold().paint("deadlock(s)") + ); + for (i, threads) in deadlocks.iter().enumerate() { + warn!("{} #{}", Style::new().bold().paint("Deadlock"), i); + for t in threads { + warn!("Thread Id {:#?}", t.thread_id()); + warn!("{:#?}", t.backtrace()); + } } } }); diff --git a/bin/oe/logger/src/lib.rs b/bin/oe/logger/src/lib.rs index 11465225a..2ae056bb6 100644 --- a/bin/oe/logger/src/lib.rs +++ b/bin/oe/logger/src/lib.rs @@ -41,7 +41,7 @@ use std::{ thread, }; -pub use rotating::{init_log, RotatingLogger}; +pub use rotating::{RotatingLogger, init_log}; #[derive(Debug, PartialEq, Clone)] pub struct Config { diff --git a/bin/oe/main.rs b/bin/oe/main.rs index 5e1f39e67..818a02f86 100644 --- a/bin/oe/main.rs +++ b/bin/oe/main.rs @@ -39,13 +39,13 @@ use std::{ io::Write, process::{self}, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, }; use ansi_term::Colour; -use diamond_node::{start, ExecutionAction, ShutdownManager}; +use diamond_node::{ExecutionAction, ShutdownManager, start}; use ethcore::exit::ExitStatus; use ethcore_logger::setup_log; use fdlimit::raise_fd_limit; diff --git a/bin/oe/metrics.rs b/bin/oe/metrics.rs index ae357d3a8..76b9c1c09 100644 --- a/bin/oe/metrics.rs +++ b/bin/oe/metrics.rs @@ -4,11 +4,11 @@ use crate::{futures::Future, rpc, rpc_apis}; use parking_lot::Mutex; -use hyper::{service::service_fn_ok, Body, Method, Request, Response, Server, StatusCode}; +use hyper::{Body, Method, Request, Response, Server, StatusCode, service::service_fn_ok}; use stats::{ - prometheus::{self, Encoder}, PrometheusMetrics, PrometheusRegistry, + prometheus::{self, Encoder}, }; #[derive(Debug, Clone, PartialEq)] diff --git a/bin/oe/modules.rs b/bin/oe/modules.rs index d88a8b51a..19bd21175 100644 --- a/bin/oe/modules.rs +++ b/bin/oe/modules.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use std::sync::{mpsc, Arc}; +use std::sync::{Arc, mpsc}; use crate::{ sync::{self, ConnectionFilter, NetworkConfiguration, Params, SyncConfig}, diff --git a/bin/oe/params.rs b/bin/oe/params.rs index 6ff18d15e..e3829d3d0 100644 --- a/bin/oe/params.rs +++ b/bin/oe/params.rs @@ -356,7 +356,7 @@ pub fn mode_switch_to_bool( #[cfg(test)] mod tests { - use super::{tracing_switch_to_bool, Pruning, ResealPolicy, SpecType, Switch}; + use super::{Pruning, ResealPolicy, SpecType, Switch, tracing_switch_to_bool}; use crate::user_defaults::UserDefaults; use journaldb::Algorithm; diff --git a/bin/oe/presale.rs b/bin/oe/presale.rs index 45190afae..188bbf89b 100644 --- a/bin/oe/presale.rs +++ b/bin/oe/presale.rs @@ -51,7 +51,7 @@ pub fn execute(cmd: ImportWallet) -> Result { pub fn import_account(cmd: &ImportWallet, kp: publickey::KeyPair, password: Password) { use crate::accounts::{AccountProvider, AccountProviderSettings}; - use ethstore::{accounts_dir::RootDiskDirectory, EthStore}; + use ethstore::{EthStore, accounts_dir::RootDiskDirectory}; let dir = Box::new(RootDiskDirectory::create(cmd.path.clone()).unwrap()); let secret_store = Box::new(EthStore::open_with_iterations(dir, cmd.iterations).unwrap()); diff --git a/bin/oe/rpc.rs b/bin/oe/rpc.rs index 833d0ae58..8f49aed80 100644 --- a/bin/oe/rpc.rs +++ b/bin/oe/rpc.rs @@ -23,15 +23,14 @@ use crate::{ use dir::{default_data_path, helpers::replace_home}; use jsonrpc_core::MetaIoHandler; use parity_rpc::{ - self as rpc, + self as rpc, DomainsValidation, Metadata, informant::{Middleware, RpcStats}, - DomainsValidation, Metadata, }; use parity_runtime::Executor; pub use parity_rpc::{HttpServer, IpcServer}; //pub use parity_rpc::ws::Server as WsServer; -pub use parity_rpc::ws::{ws, Server as WsServer}; +pub use parity_rpc::ws::{Server as WsServer, ws}; pub const DAPPS_DOMAIN: &str = "web3.site"; @@ -209,14 +208,16 @@ pub fn new_ws( // Err(e) => Err(format!("WebSockets error: {:?}", e)), // } match start_result { - Ok(server) => Ok(Some(server)), - Err(rpc::ws::Error::WsError(ws::Error { - kind: ws::ErrorKind::Io(ref err), .. - })) if err.kind() == io::ErrorKind::AddrInUse => Err( - format!("WebSockets address {} is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --ws-port and --ws-interface options.", url) - ), - Err(e) => Err(format!("WebSockets error: {:?}", e)), - } + Ok(server) => Ok(Some(server)), + Err(rpc::ws::Error::WsError(ws::Error { + kind: ws::ErrorKind::Io(ref err), + .. + })) if err.kind() == io::ErrorKind::AddrInUse => Err(format!( + "WebSockets address {} is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --ws-port and --ws-interface options.", + url + )), + Err(e) => Err(format!("WebSockets error: {:?}", e)), + } } pub fn new_http( @@ -253,12 +254,13 @@ pub fn new_http( ); match start_result { - Ok(server) => Ok(Some(server)), - Err(ref err) if err.kind() == io::ErrorKind::AddrInUse => Err( - format!("{} address {} is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --{}-port and --{}-interface options.", id, url, options, options) - ), - Err(e) => Err(format!("{} error: {:?}", id, e)), - } + Ok(server) => Ok(Some(server)), + Err(ref err) if err.kind() == io::ErrorKind::AddrInUse => Err(format!( + "{} address {} is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --{}-port and --{}-interface options.", + id, url, options, options + )), + Err(e) => Err(format!("{} error: {:?}", id, e)), + } } pub fn new_ipc( diff --git a/bin/oe/rpc_apis.rs b/bin/oe/rpc_apis.rs index 86f4910f6..5fb334749 100644 --- a/bin/oe/rpc_apis.rs +++ b/bin/oe/rpc_apis.rs @@ -33,9 +33,9 @@ use ethcore_logger::RotatingLogger; use fetch::Client as FetchClient; use jsonrpc_core::{self as core, MetaIoHandler}; use parity_rpc::{ + Host, Metadata, NetworkSettings, dispatch::FullDispatcher, informant::{ActivityNotifier, ClientNotifier}, - Host, Metadata, NetworkSettings, }; use parity_runtime::Executor; use parking_lot::Mutex; diff --git a/bin/oe/run.rs b/bin/oe/run.rs index df343f153..4fa79d06f 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -17,7 +17,7 @@ use std::{ any::Any, str::FromStr, - sync::{atomic, Arc, Weak}, + sync::{Arc, Weak, atomic}, thread, time::{Duration, Instant}, }; @@ -28,12 +28,12 @@ use crate::{ db, helpers::{execute_upgrades, passwords_from_files, to_client_config}, informant::{FullNodeInformantData, Informant}, - metrics::{start_prometheus_metrics, MetricsConfiguration}, + metrics::{MetricsConfiguration, start_prometheus_metrics}, miner::{external::ExternalMiner, work_notify::WorkPoster}, modules, params::{ - fatdb_switch_to_bool, mode_switch_to_bool, tracing_switch_to_bool, AccountsConfig, - GasPricerConfig, MinerExtras, Pruning, SpecType, Switch, + AccountsConfig, GasPricerConfig, MinerExtras, Pruning, SpecType, Switch, + fatdb_switch_to_bool, mode_switch_to_bool, tracing_switch_to_bool, }, reserved_peer_management::ReservedPeersWrapper, rpc, rpc_apis, secretstore, signer, @@ -47,7 +47,7 @@ use ethcore::{ BlockChainClient, BlockInfo, ChainSyncing, Client, DatabaseCompactionProfile, Mode, VMType, }, exit::ShutdownManager, - miner::{self, stratum, Miner, MinerOptions, MinerService}, + miner::{self, Miner, MinerOptions, MinerService, stratum}, snapshot::{self, SnapshotConfiguration}, verification::queue::VerifierSettings, }; @@ -56,7 +56,7 @@ use ethcore_service::ClientService; use ethereum_types::{H256, U64}; use journaldb::Algorithm; use node_filter::NodeFilter; -use parity_rpc::{informant, is_major_importing, NetworkSettings}; +use parity_rpc::{NetworkSettings, informant, is_major_importing}; use parity_runtime::Runtime; use parity_version::version; diff --git a/bin/oe/snapshot.rs b/bin/oe/snapshot.rs index 8dc1e9a22..9b970f705 100644 --- a/bin/oe/snapshot.rs +++ b/bin/oe/snapshot.rs @@ -28,9 +28,9 @@ use ethcore::{ exit::ShutdownManager, miner::Miner, snapshot::{ + Progress, RestorationStatus, SnapshotConfiguration, SnapshotService as SS, io::{PackedReader, PackedWriter, SnapshotReader}, service::Service as SnapshotService, - Progress, RestorationStatus, SnapshotConfiguration, SnapshotService as SS, }, }; use ethcore_service::ClientService; @@ -39,7 +39,7 @@ use crate::{ cache::CacheConfig, db, helpers::{execute_upgrades, to_client_config}, - params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch}, + params::{Pruning, SpecType, Switch, fatdb_switch_to_bool, tracing_switch_to_bool}, user_defaults::UserDefaults, }; use dir::Directories; diff --git a/bin/oe/upgrade.rs b/bin/oe/upgrade.rs index da122a92c..bc7e41335 100644 --- a/bin/oe/upgrade.rs +++ b/bin/oe/upgrade.rs @@ -16,12 +16,12 @@ //! Parity upgrade logic -use dir::{default_data_path, helpers::replace_home, home_dir, DatabaseDirectories}; +use dir::{DatabaseDirectories, default_data_path, helpers::replace_home, home_dir}; use journaldb::Algorithm; use semver::{SemVerError, Version}; use std::{ collections::*, - fs::{self, create_dir_all, File}, + fs::{self, File, create_dir_all}, io, io::{Read, Write}, path::{Path, PathBuf}, diff --git a/bin/oe/user_defaults.rs b/bin/oe/user_defaults.rs index a6d5ccebd..33b8362c3 100644 --- a/bin/oe/user_defaults.rs +++ b/bin/oe/user_defaults.rs @@ -127,7 +127,7 @@ impl UserDefaults { mod algorithm_serde { use journaldb::Algorithm; - use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; + use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error}; pub fn serialize(algorithm: &Algorithm, serializer: S) -> Result where diff --git a/crates/accounts/ethkey/src/brain.rs b/crates/accounts/ethkey/src/brain.rs index bcd64fc3c..d67980998 100644 --- a/crates/accounts/ethkey/src/brain.rs +++ b/crates/accounts/ethkey/src/brain.rs @@ -15,12 +15,11 @@ // along with OpenEthereum. If not, see . use parity_crypto::{ - publickey::{KeyPair, Secret}, Keccak256, + publickey::{KeyPair, Secret}, }; -use crate::parity_wordlist; -use crate::WordlistError; +use crate::{WordlistError, parity_wordlist}; /// Simple brainwallet. pub struct Brain(String); diff --git a/crates/concensus/ethash/benches/progpow.rs b/crates/concensus/ethash/benches/progpow.rs index 939818e7b..68fee0690 100644 --- a/crates/concensus/ethash/benches/progpow.rs +++ b/crates/concensus/ethash/benches/progpow.rs @@ -7,7 +7,7 @@ extern crate tempdir; use criterion::Criterion; use ethash::progpow; -use ethash::{compute::light_compute, NodeCacheBuilder, OptimizeFor}; +use ethash::{NodeCacheBuilder, OptimizeFor, compute::light_compute}; use rustc_hex::FromHex; use tempdir::TempDir; diff --git a/crates/concensus/ethash/src/cache.rs b/crates/concensus/ethash/src/cache.rs index dfe399b70..b71ef2910 100644 --- a/crates/concensus/ethash/src/cache.rs +++ b/crates/concensus/ethash/src/cache.rs @@ -14,14 +14,16 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::compute::Light; +use crate::{ + compute::Light, + keccak::{H256, keccak_512}, + seed_compute::SeedHashCompute, +}; use either::Either; -use crate::keccak::{keccak_512, H256}; use memmap::MmapMut; use parking_lot::Mutex; -use crate::seed_compute::SeedHashCompute; -use crate::shared::{epoch, get_cache_size, to_hex, Node, ETHASH_CACHE_ROUNDS, NODE_BYTES}; +use crate::shared::{ETHASH_CACHE_ROUNDS, NODE_BYTES, Node, epoch, get_cache_size, to_hex}; use std::{ borrow::Cow, diff --git a/crates/concensus/ethash/src/compute.rs b/crates/concensus/ethash/src/compute.rs index ef786c86e..067f96c69 100644 --- a/crates/concensus/ethash/src/compute.rs +++ b/crates/concensus/ethash/src/compute.rs @@ -19,11 +19,13 @@ // TODO: fix endianess for big endian -use crate::cache::{NodeCache, NodeCacheBuilder}; -use crate::keccak::{keccak_256, keccak_512, H256}; -use crate::progpow::{generate_cdag, keccak_f800_long, keccak_f800_short, progpow, CDag}; -use crate::seed_compute::SeedHashCompute; -use crate::shared::*; +use crate::{ + cache::{NodeCache, NodeCacheBuilder}, + keccak::{H256, keccak_256, keccak_512}, + progpow::{CDag, generate_cdag, keccak_f800_long, keccak_f800_short, progpow}, + seed_compute::SeedHashCompute, + shared::*, +}; use std::io; use std::{mem, path::Path}; diff --git a/crates/concensus/ethash/src/keccak.rs b/crates/concensus/ethash/src/keccak.rs index d3dbf1be9..66611562e 100644 --- a/crates/concensus/ethash/src/keccak.rs +++ b/crates/concensus/ethash/src/keccak.rs @@ -22,12 +22,12 @@ pub mod keccak_512 { use super::hash; pub use self::hash::{ - keccak512 as inplace, keccak512_range as inplace_range, keccak_512 as write, + keccak_512 as write, keccak512 as inplace, keccak512_range as inplace_range, }; } pub mod keccak_256 { use super::hash; - pub use self::hash::{keccak256 as inplace, keccak_256 as write}; + pub use self::hash::{keccak_256 as write, keccak256 as inplace}; } diff --git a/crates/concensus/ethash/src/lib.rs b/crates/concensus/ethash/src/lib.rs index 2232d2431..6af48700d 100644 --- a/crates/concensus/ethash/src/lib.rs +++ b/crates/concensus/ethash/src/lib.rs @@ -52,7 +52,7 @@ mod progpow; pub use cache::{NodeCacheBuilder, OptimizeFor}; use compute::Light; -pub use compute::{quick_get_difficulty, slow_hash_block_number, ProofOfWork}; +pub use compute::{ProofOfWork, quick_get_difficulty, slow_hash_block_number}; use ethereum_types::{BigEndianHash, U256, U512}; use keccak::H256; use parking_lot::Mutex; diff --git a/crates/concensus/ethash/src/progpow.rs b/crates/concensus/ethash/src/progpow.rs index d729c64e2..efce6b970 100644 --- a/crates/concensus/ethash/src/progpow.rs +++ b/crates/concensus/ethash/src/progpow.rs @@ -14,9 +14,11 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::compute::{calculate_dag_item, FNV_PRIME}; -use crate::keccak::H256; -use crate::shared::{get_data_size, Node, ETHASH_ACCESSES, ETHASH_MIX_BYTES}; +use crate::{ + compute::{FNV_PRIME, calculate_dag_item}, + keccak::H256, + shared::{ETHASH_ACCESSES, ETHASH_MIX_BYTES, Node, get_data_size}, +}; const PROGPOW_CACHE_BYTES: usize = 16 * 1024; const PROGPOW_CACHE_WORDS: usize = PROGPOW_CACHE_BYTES / 4; @@ -394,8 +396,10 @@ mod test { use tempdir::TempDir; use super::*; - use crate::cache::{NodeCacheBuilder, OptimizeFor}; - use crate::keccak::H256; + use crate::{ + cache::{NodeCacheBuilder, OptimizeFor}, + keccak::H256, + }; use rustc_hex::FromHex; use serde_json::{self, Value}; use std::collections::VecDeque; diff --git a/crates/concensus/ethash/src/seed_compute.rs b/crates/concensus/ethash/src/seed_compute.rs index f797f8068..95a6c436a 100644 --- a/crates/concensus/ethash/src/seed_compute.rs +++ b/crates/concensus/ethash/src/seed_compute.rs @@ -14,8 +14,10 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::keccak::{keccak_256, H256}; -use crate::shared; +use crate::{ + keccak::{H256, keccak_256}, + shared, +}; use std::cell::Cell; diff --git a/crates/concensus/miner/local-store/src/lib.rs b/crates/concensus/miner/local-store/src/lib.rs index 803d33726..78b8c53e2 100644 --- a/crates/concensus/miner/local-store/src/lib.rs +++ b/crates/concensus/miner/local-store/src/lib.rs @@ -18,12 +18,14 @@ use std::{fmt, sync::Arc, time::Duration}; -use ethcore_db::KeyValueDB; -use crate::io::IoHandler; -use crate::types::transaction::{ - Condition as TransactionCondition, PendingTransaction, SignedTransaction, TypedTransaction, - UnverifiedTransaction, +use crate::{ + io::IoHandler, + types::transaction::{ + Condition as TransactionCondition, PendingTransaction, SignedTransaction, TypedTransaction, + UnverifiedTransaction, + }, }; +use ethcore_db::KeyValueDB; extern crate common_types as types; extern crate ethcore_db; @@ -239,9 +241,9 @@ impl Drop for LocalDataStore { mod tests { use super::NodeInfo; + use crate::types::transaction::{Condition, PendingTransaction, Transaction, TypedTransaction}; use ethkey::Brain; use std::sync::Arc; - use crate::types::transaction::{Condition, PendingTransaction, Transaction, TypedTransaction}; // we want to test: round-trip of good transactions. // failure to roundtrip bad transactions (but that it doesn't panic) diff --git a/crates/concensus/miner/src/pool/client.rs b/crates/concensus/miner/src/pool/client.rs index 8d59ec1b1..8697bd703 100644 --- a/crates/concensus/miner/src/pool/client.rs +++ b/crates/concensus/miner/src/pool/client.rs @@ -22,8 +22,8 @@ use std::fmt; -use ethereum_types::{H160 as Address, H256, U256}; use crate::types::transaction; +use ethereum_types::{H160 as Address, H256, U256}; /// Account Details #[derive(Debug, Clone)] diff --git a/crates/concensus/miner/src/pool/listener.rs b/crates/concensus/miner/src/pool/listener.rs index cd34e47b5..6ed6fcf6b 100644 --- a/crates/concensus/miner/src/pool/listener.rs +++ b/crates/concensus/miner/src/pool/listener.rs @@ -124,10 +124,10 @@ impl txpool::Listener for Logger { #[cfg(test)] mod tests { use super::*; + use crate::types::transaction; use ethereum_types::H160; use parking_lot::Mutex; use txpool::Listener; - use crate::types::transaction; #[test] fn should_notify_listeners() { diff --git a/crates/concensus/miner/src/pool/local_transactions.rs b/crates/concensus/miner/src/pool/local_transactions.rs index de69c5f4a..f423a6cd1 100644 --- a/crates/concensus/miner/src/pool/local_transactions.rs +++ b/crates/concensus/miner/src/pool/local_transactions.rs @@ -254,10 +254,10 @@ impl txpool::Listener for LocalTransactionsList { #[cfg(test)] mod tests { use super::*; + use crate::types::transaction; use crypto::publickey::{Generator, Random}; use ethereum_types::U256; use txpool::Listener; - use crate::types::transaction; use crate::pool; diff --git a/crates/concensus/miner/src/pool/mod.rs b/crates/concensus/miner/src/pool/mod.rs index 77e4fbfd7..72cacdb4a 100644 --- a/crates/concensus/miner/src/pool/mod.rs +++ b/crates/concensus/miner/src/pool/mod.rs @@ -16,10 +16,10 @@ //! Transaction Pool +use crate::types::transaction; use ethereum_types::{Address, H256, U256}; use parity_util_mem::MallocSizeOfExt; use txpool; -use crate::types::transaction; mod listener; mod queue; diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index ba3ce8ba1..c0a9dd1b4 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -27,10 +27,10 @@ use std::{ }; use self::scoring::ScoringEvent; +use crate::types::transaction; use ethereum_types::{Address, H256, U256}; use parking_lot::RwLock; use txpool::{self, Verifier}; -use crate::types::transaction; use crate::pool::{ self, client, listener, diff --git a/crates/concensus/miner/src/pool/ready.rs b/crates/concensus/miner/src/pool/ready.rs index 53b3e3f5f..d833b2e5e 100644 --- a/crates/concensus/miner/src/pool/ready.rs +++ b/crates/concensus/miner/src/pool/ready.rs @@ -40,9 +40,9 @@ use std::{cmp, collections::HashMap}; +use crate::types::transaction; use ethereum_types::{H160 as Address, U256}; use txpool::{self, VerifiedTransaction as PoolVerifiedTransaction}; -use crate::types::transaction; use super::{client::NonceClient, VerifiedTransaction}; diff --git a/crates/concensus/miner/src/pool/tests/client.rs b/crates/concensus/miner/src/pool/tests/client.rs index fc8e8bb38..c24a2b942 100644 --- a/crates/concensus/miner/src/pool/tests/client.rs +++ b/crates/concensus/miner/src/pool/tests/client.rs @@ -16,11 +16,11 @@ use std::sync::{atomic, Arc}; -use ethereum_types::{Address, H256, U256}; -use rlp::Rlp; use crate::types::transaction::{ self, SignedTransaction, Transaction, TypedTransaction, UnverifiedTransaction, }; +use ethereum_types::{Address, H256, U256}; +use rlp::Rlp; use crate::pool::{self, client::AccountDetails}; diff --git a/crates/concensus/miner/src/pool/tests/mod.rs b/crates/concensus/miner/src/pool/tests/mod.rs index a3fa41311..cd1955e69 100644 --- a/crates/concensus/miner/src/pool/tests/mod.rs +++ b/crates/concensus/miner/src/pool/tests/mod.rs @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::types::transaction::{self, PendingTransaction}; use ethereum_types::U256; use hash::KECCAK_EMPTY; use txpool; -use crate::types::transaction::{self, PendingTransaction}; use crate::pool::{ transaction_filter::TransactionFilter, verifier, PendingOrdering, PendingSettings, diff --git a/crates/concensus/miner/src/pool/tests/tx.rs b/crates/concensus/miner/src/pool/tests/tx.rs index a84b8e68c..b129d249e 100644 --- a/crates/concensus/miner/src/pool/tests/tx.rs +++ b/crates/concensus/miner/src/pool/tests/tx.rs @@ -14,13 +14,13 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crypto::publickey::{Generator, Random}; -use ethereum_types::{H256, U256}; -use rustc_hex::FromHex; use crate::types::transaction::{ self, AccessListTx, EIP1559TransactionTx, SignedTransaction, Transaction, TypedTransaction, UnverifiedTransaction, }; +use crypto::publickey::{Generator, Random}; +use ethereum_types::{H256, U256}; +use rustc_hex::FromHex; use crate::pool::{verifier, VerifiedTransaction}; diff --git a/crates/concensus/miner/src/pool/transaction_filter.rs b/crates/concensus/miner/src/pool/transaction_filter.rs index 92a9d538f..338d6dad0 100644 --- a/crates/concensus/miner/src/pool/transaction_filter.rs +++ b/crates/concensus/miner/src/pool/transaction_filter.rs @@ -20,8 +20,7 @@ use ethereum_types::{Address, U256}; -use crate::pool::VerifiedTransaction; -use crate::types::transaction::Action; +use crate::{pool::VerifiedTransaction, types::transaction::Action}; #[allow(non_camel_case_types)] #[derive(Debug, Deserialize, Serialize)] diff --git a/crates/concensus/miner/src/pool/verifier.rs b/crates/concensus/miner/src/pool/verifier.rs index cd74d2bb9..7ca19bf43 100644 --- a/crates/concensus/miner/src/pool/verifier.rs +++ b/crates/concensus/miner/src/pool/verifier.rs @@ -30,10 +30,10 @@ use std::{ }, }; +use crate::types::transaction; use ethereum_types::{H256, U256}; use hash::KECCAK_EMPTY; use txpool; -use crate::types::transaction; use super::{ client::{Client, TransactionType}, diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index 4f1721183..23afc9609 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -16,12 +16,12 @@ //! A service transactions contract checker. +use crate::types::{ids::BlockId, transaction::SignedTransaction}; use call_contract::{CallContract, RegistryInfo}; use ethabi::FunctionOutputDecoder; use ethereum_types::Address; use parking_lot::RwLock; use std::{collections::HashMap, mem, str::FromStr, sync::Arc}; -use crate::types::{ids::BlockId, transaction::SignedTransaction}; use_contract!( service_transaction, diff --git a/crates/concensus/miner/stratum/src/lib.rs b/crates/concensus/miner/stratum/src/lib.rs index e1e79a548..01ea5df85 100644 --- a/crates/concensus/miner/stratum/src/lib.rs +++ b/crates/concensus/miner/stratum/src/lib.rs @@ -36,7 +36,7 @@ mod traits; pub use traits::{Error, JobDispatcher, PushWorkHandler, ServiceConfiguration}; -use jsonrpc_core::{to_value, Compatibility, IoDelegate, MetaIoHandler, Metadata, Params, Value}; +use jsonrpc_core::{Compatibility, IoDelegate, MetaIoHandler, Metadata, Params, Value, to_value}; use jsonrpc_tcp_server::{ Dispatcher, MetaExtractor, PushMessageError, RequestContext, Server as JsonRpcServer, ServerBuilder as JsonRpcServerBuilder, @@ -318,7 +318,7 @@ mod tests { sync::Arc, }; - use jsonrpc_core::futures::{future, Future}; + use jsonrpc_core::futures::{Future, future}; use tokio::{ io, net::TcpStream, @@ -504,8 +504,9 @@ mod tests { .expect("Response should be utf-8"); assert_eq!( - "{ \"id\": 17, \"method\": \"mining.notify\", \"params\": { \"00040008\", \"100500\" } }\n", - response); + "{ \"id\": 17, \"method\": \"mining.notify\", \"params\": { \"00040008\", \"100500\" } }\n", + response + ); } #[test] diff --git a/crates/concensus/miner/using-queue/src/lib.rs b/crates/concensus/miner/using-queue/src/lib.rs index 78ad91831..a4e77de1b 100644 --- a/crates/concensus/miner/using-queue/src/lib.rs +++ b/crates/concensus/miner/using-queue/src/lib.rs @@ -127,11 +127,7 @@ impl UsingQueue { { // a bit clumsy - TODO: think about a nicer way of expressing this. if let Some(ref x) = self.pending { - if predicate(x) { - Some(x.clone()) - } else { - None - } + if predicate(x) { Some(x.clone()) } else { None } } else { self.in_use .last() diff --git a/crates/db/journaldb/src/archivedb.rs b/crates/db/journaldb/src/archivedb.rs index 3b29ee625..9a3649c6d 100644 --- a/crates/db/journaldb/src/archivedb.rs +++ b/crates/db/journaldb/src/archivedb.rs @@ -17,22 +17,21 @@ //! Disk-backed `HashDB` implementation. use std::{ - collections::{hash_map::Entry, BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, hash_map::Entry}, io, sync::Arc, }; use super::{ - error_key_already_exists, error_negatively_reference_hash, memory_db::*, LATEST_ERA_KEY, + LATEST_ERA_KEY, error_key_already_exists, error_negatively_reference_hash, memory_db::*, }; +use crate::{DB_PREFIX_LEN, traits::JournalDB}; use bytes::Bytes; use ethcore_db::{DBTransaction, DBValue, KeyValueDB}; use ethereum_types::H256; use hash_db::HashDB; use keccak_hasher::KeccakHasher; use rlp::{decode, encode}; -use crate::traits::JournalDB; -use crate::DB_PREFIX_LEN; /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay /// and latent-removal semantics. @@ -228,10 +227,10 @@ impl JournalDB for ArchiveDB { mod tests { use super::*; + use JournalDB; use ethcore_db::InMemoryWithMetrics; use hash_db::HashDB; use keccak::keccak; - use JournalDB; #[test] fn insert_same_in_fork() { diff --git a/crates/db/journaldb/src/as_hash_db_impls.rs b/crates/db/journaldb/src/as_hash_db_impls.rs index 4f1668d0f..c426ecf5a 100644 --- a/crates/db/journaldb/src/as_hash_db_impls.rs +++ b/crates/db/journaldb/src/as_hash_db_impls.rs @@ -15,15 +15,13 @@ // along with OpenEthereum. If not, see . //! Impls of the `AsHashDB` upcast trait for all different variants of DB -use crate::{AsKeyedHashDB, KeyedHashDB}; -use crate::archivedb::ArchiveDB; -use crate::earlymergedb::EarlyMergeDB; +use crate::{ + AsKeyedHashDB, KeyedHashDB, archivedb::ArchiveDB, earlymergedb::EarlyMergeDB, + overlaydb::OverlayDB, overlayrecentdb::OverlayRecentDB, refcounteddb::RefCountedDB, +}; use hash_db::{AsHashDB, HashDB}; use keccak_hasher::KeccakHasher; use kvdb::DBValue; -use crate::overlaydb::OverlayDB; -use crate::overlayrecentdb::OverlayRecentDB; -use crate::refcounteddb::RefCountedDB; impl AsHashDB for ArchiveDB { fn as_hash_db(&self) -> &dyn HashDB { diff --git a/crates/db/journaldb/src/earlymergedb.rs b/crates/db/journaldb/src/earlymergedb.rs index 0fe72cbbb..43a7a1905 100644 --- a/crates/db/journaldb/src/earlymergedb.rs +++ b/crates/db/journaldb/src/earlymergedb.rs @@ -17,13 +17,17 @@ //! Disk-backed `HashDB` implementation. use std::{ - collections::{hash_map::Entry, BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, hash_map::Entry}, io, sync::Arc, }; use super::{ - error_key_already_exists, error_negatively_reference_hash, traits::JournalDB, LATEST_ERA_KEY, + LATEST_ERA_KEY, error_key_already_exists, error_negatively_reference_hash, traits::JournalDB, +}; +use crate::{ + DB_PREFIX_LEN, + util::{DatabaseKey, DatabaseValueRef, DatabaseValueView}, }; use bytes::Bytes; use ethcore_db::{DBTransaction, DBValue, KeyValueDB}; @@ -34,8 +38,6 @@ use memory_db::*; use parity_util_mem::MallocSizeOf; use parking_lot::RwLock; use rlp::{decode, encode}; -use crate::util::{DatabaseKey, DatabaseValueRef, DatabaseValueView}; -use crate::DB_PREFIX_LEN; #[derive(Debug, Clone, PartialEq, Eq, MallocSizeOf)] struct RefInfo { diff --git a/crates/db/journaldb/src/overlaydb.rs b/crates/db/journaldb/src/overlaydb.rs index 3179c89ba..3606ecd41 100644 --- a/crates/db/journaldb/src/overlaydb.rs +++ b/crates/db/journaldb/src/overlaydb.rs @@ -17,7 +17,7 @@ //! Disk-backed `HashDB` implementation. use std::{ - collections::{hash_map::Entry, HashMap}, + collections::{HashMap, hash_map::Entry}, io, sync::Arc, }; @@ -28,7 +28,7 @@ use ethereum_types::H256; use hash_db::HashDB; use keccak_hasher::KeccakHasher; use memory_db::*; -use rlp::{decode, encode, Decodable, DecoderError, Encodable, Rlp, RlpStream}; +use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream, decode, encode}; /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay. /// diff --git a/crates/db/journaldb/src/overlayrecentdb.rs b/crates/db/journaldb/src/overlayrecentdb.rs index 7d36f55f7..973c88acd 100644 --- a/crates/db/journaldb/src/overlayrecentdb.rs +++ b/crates/db/journaldb/src/overlayrecentdb.rs @@ -17,12 +17,13 @@ //! `JournalDB` over in-memory overlay use std::{ - collections::{hash_map::Entry, BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, hash_map::Entry}, io, sync::Arc, }; -use super::{error_negatively_reference_hash, JournalDB, DB_PREFIX_LEN, LATEST_ERA_KEY}; +use super::{DB_PREFIX_LEN, JournalDB, LATEST_ERA_KEY, error_negatively_reference_hash}; +use crate::util::DatabaseKey; use bytes::Bytes; use ethcore_db::{DBTransaction, DBValue, KeyValueDB}; use ethereum_types::H256; @@ -32,8 +33,7 @@ use keccak_hasher::KeccakHasher; use memory_db::*; use parity_util_mem::MallocSizeOf; use parking_lot::RwLock; -use rlp::{decode, encode, Decodable, DecoderError, Encodable, Rlp, RlpStream}; -use crate::util::DatabaseKey; +use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream, decode, encode}; /// Implementation of the `JournalDB` trait for a disk-backed database with a memory overlay /// and, possibly, latent-removal semantics. @@ -569,9 +569,9 @@ impl HashDB for OverlayRecentDB { mod tests { use super::*; + use JournalDB; use hash_db::HashDB; use keccak::keccak; - use JournalDB; fn new_db() -> OverlayRecentDB { let backing = Arc::new(ethcore_db::InMemoryWithMetrics::create(0)); diff --git a/crates/db/journaldb/src/refcounteddb.rs b/crates/db/journaldb/src/refcounteddb.rs index 2263e0b43..dd61c59a0 100644 --- a/crates/db/journaldb/src/refcounteddb.rs +++ b/crates/db/journaldb/src/refcounteddb.rs @@ -22,18 +22,20 @@ use std::{ sync::Arc, }; -use super::{traits::JournalDB, LATEST_ERA_KEY}; +use super::{LATEST_ERA_KEY, traits::JournalDB}; +use crate::{ + DB_PREFIX_LEN, + overlaydb::OverlayDB, + util::{DatabaseKey, DatabaseValueRef, DatabaseValueView}, +}; use bytes::Bytes; use ethcore_db::{DBTransaction, DBValue, KeyValueDB}; use ethereum_types::H256; use hash_db::HashDB; use keccak_hasher::KeccakHasher; use memory_db::MemoryDB; -use crate::overlaydb::OverlayDB; -use parity_util_mem::{allocators::new_malloc_size_ops, MallocSizeOf}; +use parity_util_mem::{MallocSizeOf, allocators::new_malloc_size_ops}; use rlp::{decode, encode}; -use crate::util::{DatabaseKey, DatabaseValueRef, DatabaseValueView}; -use crate::DB_PREFIX_LEN; /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay /// and latent-removal semantics. @@ -259,9 +261,9 @@ impl JournalDB for RefCountedDB { mod tests { use super::*; + use JournalDB; use hash_db::HashDB; use keccak::keccak; - use JournalDB; fn new_db() -> RefCountedDB { let backing = Arc::new(ethcore_db::InMemoryWithMetrics::create(0)); diff --git a/crates/db/journaldb/src/traits.rs b/crates/db/journaldb/src/traits.rs index 7e8edd815..6325f5ffd 100644 --- a/crates/db/journaldb/src/traits.rs +++ b/crates/db/journaldb/src/traits.rs @@ -70,7 +70,7 @@ pub trait JournalDB: KeyedHashDB { /// Mark a given block as canonical, indicating that competing blocks' states may be pruned out. fn mark_canonical(&mut self, batch: &mut DBTransaction, era: u64, id: &H256) - -> io::Result; + -> io::Result; /// Commit all queued insert and delete operations without affecting any journalling -- this requires that all insertions /// and deletions are indeed canonical and will likely lead to an invalid database if that assumption is violated. diff --git a/crates/db/memory-db/benches/bench.rs b/crates/db/memory-db/benches/bench.rs index a0212f435..83f73e85b 100644 --- a/crates/db/memory-db/benches/bench.rs +++ b/crates/db/memory-db/benches/bench.rs @@ -14,7 +14,7 @@ #[macro_use] extern crate criterion; -use criterion::{black_box, Criterion}; +use criterion::{Criterion, black_box}; criterion_group!( benches, instantiation, diff --git a/crates/db/memory-db/src/lib.rs b/crates/db/memory-db/src/lib.rs index 7baa58cab..87f93a640 100644 --- a/crates/db/memory-db/src/lib.rs +++ b/crates/db/memory-db/src/lib.rs @@ -23,7 +23,7 @@ extern crate keccak_hasher; use hash_db::{AsHashDB, AsPlainDB, HashDB, HashDBRef, Hasher as KeyHasher, PlainDB, PlainDBRef}; use parity_util_mem::MallocSizeOf; use std::{ - collections::{hash_map::Entry, HashMap}, + collections::{HashMap, hash_map::Entry}, hash, mem, }; diff --git a/crates/ethcore/benches/builtin.rs b/crates/ethcore/benches/builtin.rs index ffdce6242..2179bddaf 100644 --- a/crates/ethcore/benches/builtin.rs +++ b/crates/ethcore/benches/builtin.rs @@ -143,492 +143,492 @@ criterion_main!(builtin); fn ecrecover(b: &mut Criterion) { bench( - "ecrecover", - "0000000000000000000000000000000000000001", // ecrecover - "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", - "000000000000000000000000ceaccac640adf55b2028469bd36ba501f28b699d", - b, - ); + "ecrecover", + "0000000000000000000000000000000000000001", // ecrecover + "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", + "000000000000000000000000ceaccac640adf55b2028469bd36ba501f28b699d", + b, + ); } fn sha256(b: &mut Criterion) { bench( - "sha256", - "0000000000000000000000000000000000000002", // sha256 - "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", - "811c7003375852fabd0d362e40e68607a12bdabae61a7d068fe5fdd1dbbf2a5d", - b, - ); + "sha256", + "0000000000000000000000000000000000000002", // sha256 + "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", + "811c7003375852fabd0d362e40e68607a12bdabae61a7d068fe5fdd1dbbf2a5d", + b, + ); } fn ripemd(b: &mut Criterion) { bench( - "ripemd", - "0000000000000000000000000000000000000003", // ripemd - "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", - "0000000000000000000000009215b8d9882ff46f0dfde6684d78e831467f65e6", - b, - ); + "ripemd", + "0000000000000000000000000000000000000003", // ripemd + "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", + "0000000000000000000000009215b8d9882ff46f0dfde6684d78e831467f65e6", + b, + ); } fn identity(b: &mut Criterion) { bench( - "identity", - "0000000000000000000000000000000000000004", // identity - "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", - "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", - b, - ); + "identity", + "0000000000000000000000000000000000000004", // identity + "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", + "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", + b, + ); } fn modexp_eip_example1(b: &mut Criterion) { bench( - "modexp_eip_example1", - "0000000000000000000000000000000000000005", // modexp - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "modexp_eip_example1", + "0000000000000000000000000000000000000005", // modexp + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn modexp_eip_example2(b: &mut Criterion) { bench( - "modexp_eip_example2", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", - "0000000000000000000000000000000000000000000000000000000000000000", - b, - ); + "modexp_eip_example2", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", + "0000000000000000000000000000000000000000000000000000000000000000", + b, + ); } fn modexp_nagydani_1_square(b: &mut Criterion) { bench( - "modexp_nagydani_1_square", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb502fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b", - "60008f1614cc01dcfb6bfb09c625cf90b47d4468db81b5f8b7a39d42f332eab9b2da8f2d95311648a8f243f4bb13cfb3d8f7f2a3c014122ebb3ed41b02783adc", - b, - ); + "modexp_nagydani_1_square", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb502fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b", + "60008f1614cc01dcfb6bfb09c625cf90b47d4468db81b5f8b7a39d42f332eab9b2da8f2d95311648a8f243f4bb13cfb3d8f7f2a3c014122ebb3ed41b02783adc", + b, + ); } fn modexp_nagydani_1_qube(b: &mut Criterion) { bench( - "modexp_nagydani_1_qube", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb503fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b", - "4834a46ba565db27903b1c720c9d593e84e4cbd6ad2e64b31885d944f68cd801f92225a8961c952ddf2797fa4701b330c85c4b363798100b921a1a22a46a7fec", - b, - ); + "modexp_nagydani_1_qube", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb503fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b", + "4834a46ba565db27903b1c720c9d593e84e4cbd6ad2e64b31885d944f68cd801f92225a8961c952ddf2797fa4701b330c85c4b363798100b921a1a22a46a7fec", + b, + ); } fn modexp_nagydani_1_pow0x10001(b: &mut Criterion) { bench( - "modexp_nagydani_1_pow0x10001", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb5010001fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b", - "c36d804180c35d4426b57b50c5bfcca5c01856d104564cd513b461d3c8b8409128a5573e416d0ebe38f5f736766d9dc27143e4da981dfa4d67f7dc474cbee6d2", - b, - ); + "modexp_nagydani_1_pow0x10001", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb5010001fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b", + "c36d804180c35d4426b57b50c5bfcca5c01856d104564cd513b461d3c8b8409128a5573e416d0ebe38f5f736766d9dc27143e4da981dfa4d67f7dc474cbee6d2", + b, + ); } fn modexp_nagydani_2_square(b: &mut Criterion) { bench( - "modexp_nagydani_2_square", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf5102e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087", - "981dd99c3b113fae3e3eaa9435c0dc96779a23c12a53d1084b4f67b0b053a27560f627b873e3f16ad78f28c94f14b6392def26e4d8896c5e3c984e50fa0b3aa44f1da78b913187c6128baa9340b1e9c9a0fd02cb78885e72576da4a8f7e5a113e173a7a2889fde9d407bd9f06eb05bc8fc7b4229377a32941a02bf4edcc06d70", - b, - ); + "modexp_nagydani_2_square", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf5102e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087", + "981dd99c3b113fae3e3eaa9435c0dc96779a23c12a53d1084b4f67b0b053a27560f627b873e3f16ad78f28c94f14b6392def26e4d8896c5e3c984e50fa0b3aa44f1da78b913187c6128baa9340b1e9c9a0fd02cb78885e72576da4a8f7e5a113e173a7a2889fde9d407bd9f06eb05bc8fc7b4229377a32941a02bf4edcc06d70", + b, + ); } fn modexp_nagydani_2_qube(b: &mut Criterion) { bench( - "modexp_nagydani_2_qube", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf5103e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087", - "d89ceb68c32da4f6364978d62aaa40d7b09b59ec61eb3c0159c87ec3a91037f7dc6967594e530a69d049b64adfa39c8fa208ea970cfe4b7bcd359d345744405afe1cbf761647e32b3184c7fbe87cee8c6c7ff3b378faba6c68b83b6889cb40f1603ee68c56b4c03d48c595c826c041112dc941878f8c5be828154afd4a16311f", - b, - ); + "modexp_nagydani_2_qube", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf5103e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087", + "d89ceb68c32da4f6364978d62aaa40d7b09b59ec61eb3c0159c87ec3a91037f7dc6967594e530a69d049b64adfa39c8fa208ea970cfe4b7bcd359d345744405afe1cbf761647e32b3184c7fbe87cee8c6c7ff3b378faba6c68b83b6889cb40f1603ee68c56b4c03d48c595c826c041112dc941878f8c5be828154afd4a16311f", + b, + ); } fn modexp_nagydani_2_pow0x10001(b: &mut Criterion) { bench( - "modexp_nagydani_2_pow0x10001", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf51010001e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087", - "ad85e8ef13fd1dd46eae44af8b91ad1ccae5b7a1c92944f92a19f21b0b658139e0cabe9c1f679507c2de354bf2c91ebd965d1e633978a830d517d2f6f8dd5fd58065d58559de7e2334a878f8ec6992d9b9e77430d4764e863d77c0f87beede8f2f7f2ab2e7222f85cc9d98b8467f4bb72e87ef2882423ebdb6daf02dddac6db2", - b, - ); + "modexp_nagydani_2_pow0x10001", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf51010001e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087", + "ad85e8ef13fd1dd46eae44af8b91ad1ccae5b7a1c92944f92a19f21b0b658139e0cabe9c1f679507c2de354bf2c91ebd965d1e633978a830d517d2f6f8dd5fd58065d58559de7e2334a878f8ec6992d9b9e77430d4764e863d77c0f87beede8f2f7f2ab2e7222f85cc9d98b8467f4bb72e87ef2882423ebdb6daf02dddac6db2", + b, + ); } fn modexp_nagydani_3_square(b: &mut Criterion) { bench( - "modexp_nagydani_3_square", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb02d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d", - "affc7507ea6d84751ec6b3f0d7b99dbcc263f33330e450d1b3ff0bc3d0874320bf4edd57debd587306988157958cb3cfd369cc0c9c198706f635c9e0f15d047df5cb44d03e2727f26b083c4ad8485080e1293f171c1ed52aef5993a5815c35108e848c951cf1e334490b4a539a139e57b68f44fee583306f5b85ffa57206b3ee5660458858534e5386b9584af3c7f67806e84c189d695e5eb96e1272d06ec2df5dc5fabc6e94b793718c60c36be0a4d031fc84cd658aa72294b2e16fc240aef70cb9e591248e38bd49c5a554d1afa01f38dab72733092f7555334bbef6c8c430119840492380aa95fa025dcf699f0a39669d812b0c6946b6091e6e235337b6f8", - b, - ); + "modexp_nagydani_3_square", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb02d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d", + "affc7507ea6d84751ec6b3f0d7b99dbcc263f33330e450d1b3ff0bc3d0874320bf4edd57debd587306988157958cb3cfd369cc0c9c198706f635c9e0f15d047df5cb44d03e2727f26b083c4ad8485080e1293f171c1ed52aef5993a5815c35108e848c951cf1e334490b4a539a139e57b68f44fee583306f5b85ffa57206b3ee5660458858534e5386b9584af3c7f67806e84c189d695e5eb96e1272d06ec2df5dc5fabc6e94b793718c60c36be0a4d031fc84cd658aa72294b2e16fc240aef70cb9e591248e38bd49c5a554d1afa01f38dab72733092f7555334bbef6c8c430119840492380aa95fa025dcf699f0a39669d812b0c6946b6091e6e235337b6f8", + b, + ); } fn modexp_nagydani_3_qube(b: &mut Criterion) { bench( - "modexp_nagydani_3_qube", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb03d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d", - "1b280ecd6a6bf906b806d527c2a831e23b238f89da48449003a88ac3ac7150d6a5e9e6b3be4054c7da11dd1e470ec29a606f5115801b5bf53bc1900271d7c3ff3cd5ed790d1c219a9800437a689f2388ba1a11d68f6a8e5b74e9a3b1fac6ee85fc6afbac599f93c391f5dc82a759e3c6c0ab45ce3f5d25d9b0c1bf94cf701ea6466fc9a478dacc5754e593172b5111eeba88557048bceae401337cd4c1182ad9f700852bc8c99933a193f0b94cf1aedbefc48be3bc93ef5cb276d7c2d5462ac8bb0c8fe8923a1db2afe1c6b90d59c534994a6a633f0ead1d638fdc293486bb634ff2c8ec9e7297c04241a61c37e3ae95b11d53343d4ba2b4cc33d2cfa7eb705e", - b, - ); + "modexp_nagydani_3_qube", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb03d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d", + "1b280ecd6a6bf906b806d527c2a831e23b238f89da48449003a88ac3ac7150d6a5e9e6b3be4054c7da11dd1e470ec29a606f5115801b5bf53bc1900271d7c3ff3cd5ed790d1c219a9800437a689f2388ba1a11d68f6a8e5b74e9a3b1fac6ee85fc6afbac599f93c391f5dc82a759e3c6c0ab45ce3f5d25d9b0c1bf94cf701ea6466fc9a478dacc5754e593172b5111eeba88557048bceae401337cd4c1182ad9f700852bc8c99933a193f0b94cf1aedbefc48be3bc93ef5cb276d7c2d5462ac8bb0c8fe8923a1db2afe1c6b90d59c534994a6a633f0ead1d638fdc293486bb634ff2c8ec9e7297c04241a61c37e3ae95b11d53343d4ba2b4cc33d2cfa7eb705e", + b, + ); } fn modexp_nagydani_3_pow0x10001(b: &mut Criterion) { bench( - "modexp_nagydani_3_pow0x10001", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb010001d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d", - "37843d7c67920b5f177372fa56e2a09117df585f81df8b300fba245b1175f488c99476019857198ed459ed8d9799c377330e49f4180c4bf8e8f66240c64f65ede93d601f957b95b83efdee1e1bfde74169ff77002eaf078c71815a9220c80b2e3b3ff22c2f358111d816ebf83c2999026b6de50bfc711ff68705d2f40b753424aefc9f70f08d908b5a20276ad613b4ab4309a3ea72f0c17ea9df6b3367d44fb3acab11c333909e02e81ea2ed404a712d3ea96bba87461720e2d98723e7acd0520ac1a5212dbedcd8dc0c1abf61d4719e319ff4758a774790b8d463cdfe131d1b2dcfee52d002694e98e720cb6ae7ccea353bc503269ba35f0f63bf8d7b672a76", - b, - ); + "modexp_nagydani_3_pow0x10001", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb010001d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d", + "37843d7c67920b5f177372fa56e2a09117df585f81df8b300fba245b1175f488c99476019857198ed459ed8d9799c377330e49f4180c4bf8e8f66240c64f65ede93d601f957b95b83efdee1e1bfde74169ff77002eaf078c71815a9220c80b2e3b3ff22c2f358111d816ebf83c2999026b6de50bfc711ff68705d2f40b753424aefc9f70f08d908b5a20276ad613b4ab4309a3ea72f0c17ea9df6b3367d44fb3acab11c333909e02e81ea2ed404a712d3ea96bba87461720e2d98723e7acd0520ac1a5212dbedcd8dc0c1abf61d4719e319ff4758a774790b8d463cdfe131d1b2dcfee52d002694e98e720cb6ae7ccea353bc503269ba35f0f63bf8d7b672a76", + b, + ); } fn modexp_nagydani_4_square(b: &mut Criterion) { bench( - "modexp_nagydani_4_square", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b8102df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f", - "8a5aea5f50dcc03dc7a7a272b5aeebc040554dbc1ffe36753c4fc75f7ed5f6c2cc0de3a922bf96c78bf0643a73025ad21f45a4a5cadd717612c511ab2bff1190fe5f1ae05ba9f8fe3624de1de2a817da6072ddcdb933b50216811dbe6a9ca79d3a3c6b3a476b079fd0d05f04fb154e2dd3e5cb83b148a006f2bcbf0042efb2ae7b916ea81b27aac25c3bf9a8b6d35440062ad8eae34a83f3ffa2cc7b40346b62174a4422584f72f95316f6b2bee9ff232ba9739301c97c99a9ded26c45d72676eb856ad6ecc81d36a6de36d7f9dafafee11baa43a4b0d5e4ecffa7b9b7dcefd58c397dd373e6db4acd2b2c02717712e6289bed7c813b670c4a0c6735aa7f3b0f1ce556eae9fcc94b501b2c8781ba50a8c6220e8246371c3c7359fe4ef9da786ca7d98256754ca4e496be0a9174bedbecb384bdf470779186d6a833f068d2838a88d90ef3ad48ff963b67c39cc5a3ee123baf7bf3125f64e77af7f30e105d72c4b9b5b237ed251e4c122c6d8c1405e736299c3afd6db16a28c6a9cfa68241e53de4cd388271fe534a6a9b0dbea6171d170db1b89858468885d08fecbd54c8e471c3e25d48e97ba450b96d0d87e00ac732aaa0d3ce4309c1064bd8a4c0808a97e0143e43a24cfa847635125cd41c13e0574487963e9d725c01375db99c31da67b4cf65eff555f0c0ac416c727ff8d438ad7c42030551d68c2e7adda0abb1ca7c10", - b, - ); + "modexp_nagydani_4_square", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b8102df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f", + "8a5aea5f50dcc03dc7a7a272b5aeebc040554dbc1ffe36753c4fc75f7ed5f6c2cc0de3a922bf96c78bf0643a73025ad21f45a4a5cadd717612c511ab2bff1190fe5f1ae05ba9f8fe3624de1de2a817da6072ddcdb933b50216811dbe6a9ca79d3a3c6b3a476b079fd0d05f04fb154e2dd3e5cb83b148a006f2bcbf0042efb2ae7b916ea81b27aac25c3bf9a8b6d35440062ad8eae34a83f3ffa2cc7b40346b62174a4422584f72f95316f6b2bee9ff232ba9739301c97c99a9ded26c45d72676eb856ad6ecc81d36a6de36d7f9dafafee11baa43a4b0d5e4ecffa7b9b7dcefd58c397dd373e6db4acd2b2c02717712e6289bed7c813b670c4a0c6735aa7f3b0f1ce556eae9fcc94b501b2c8781ba50a8c6220e8246371c3c7359fe4ef9da786ca7d98256754ca4e496be0a9174bedbecb384bdf470779186d6a833f068d2838a88d90ef3ad48ff963b67c39cc5a3ee123baf7bf3125f64e77af7f30e105d72c4b9b5b237ed251e4c122c6d8c1405e736299c3afd6db16a28c6a9cfa68241e53de4cd388271fe534a6a9b0dbea6171d170db1b89858468885d08fecbd54c8e471c3e25d48e97ba450b96d0d87e00ac732aaa0d3ce4309c1064bd8a4c0808a97e0143e43a24cfa847635125cd41c13e0574487963e9d725c01375db99c31da67b4cf65eff555f0c0ac416c727ff8d438ad7c42030551d68c2e7adda0abb1ca7c10", + b, + ); } fn modexp_nagydani_4_qube(b: &mut Criterion) { bench( - "modexp_nagydani_4_qube", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b8103df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f", - "5a2664252aba2d6e19d9600da582cdd1f09d7a890ac48e6b8da15ae7c6ff1856fc67a841ac2314d283ffa3ca81a0ecf7c27d89ef91a5a893297928f5da0245c99645676b481b7e20a566ee6a4f2481942bee191deec5544600bb2441fd0fb19e2ee7d801ad8911c6b7750affec367a4b29a22942c0f5f4744a4e77a8b654da2a82571037099e9c6d930794efe5cdca73c7b6c0844e386bdca8ea01b3d7807146bb81365e2cdc6475f8c23e0ff84463126189dc9789f72bbce2e3d2d114d728a272f1345122de23df54c922ec7a16e5c2a8f84da8871482bd258c20a7c09bbcd64c7a96a51029bbfe848736a6ba7bf9d931a9b7de0bcaf3635034d4958b20ae9ab3a95a147b0421dd5f7ebff46c971010ebfc4adbbe0ad94d5498c853e7142c450d8c71de4b2f84edbf8acd2e16d00c8115b150b1c30e553dbb82635e781379fe2a56360420ff7e9f70cc64c00aba7e26ed13c7c19622865ae07248daced36416080f35f8cc157a857ed70ea4f347f17d1bee80fa038abd6e39b1ba06b97264388b21364f7c56e192d4b62d9b161405f32ab1e2594e86243e56fcf2cb30d21adef15b9940f91af681da24328c883d892670c6aa47940867a81830a82b82716895db810df1b834640abefb7db2092dd92912cb9a735175bc447be40a503cf22dfe565b4ed7a3293ca0dfd63a507430b323ee248ec82e843b673c97ad730728cebc", - b, - ); + "modexp_nagydani_4_qube", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b8103df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f", + "5a2664252aba2d6e19d9600da582cdd1f09d7a890ac48e6b8da15ae7c6ff1856fc67a841ac2314d283ffa3ca81a0ecf7c27d89ef91a5a893297928f5da0245c99645676b481b7e20a566ee6a4f2481942bee191deec5544600bb2441fd0fb19e2ee7d801ad8911c6b7750affec367a4b29a22942c0f5f4744a4e77a8b654da2a82571037099e9c6d930794efe5cdca73c7b6c0844e386bdca8ea01b3d7807146bb81365e2cdc6475f8c23e0ff84463126189dc9789f72bbce2e3d2d114d728a272f1345122de23df54c922ec7a16e5c2a8f84da8871482bd258c20a7c09bbcd64c7a96a51029bbfe848736a6ba7bf9d931a9b7de0bcaf3635034d4958b20ae9ab3a95a147b0421dd5f7ebff46c971010ebfc4adbbe0ad94d5498c853e7142c450d8c71de4b2f84edbf8acd2e16d00c8115b150b1c30e553dbb82635e781379fe2a56360420ff7e9f70cc64c00aba7e26ed13c7c19622865ae07248daced36416080f35f8cc157a857ed70ea4f347f17d1bee80fa038abd6e39b1ba06b97264388b21364f7c56e192d4b62d9b161405f32ab1e2594e86243e56fcf2cb30d21adef15b9940f91af681da24328c883d892670c6aa47940867a81830a82b82716895db810df1b834640abefb7db2092dd92912cb9a735175bc447be40a503cf22dfe565b4ed7a3293ca0dfd63a507430b323ee248ec82e843b673c97ad730728cebc", + b, + ); } fn modexp_nagydani_4_pow0x10001(b: &mut Criterion) { bench( - "modexp_nagydani_4_pow0x10001", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b81010001df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f", - "bed8b970c4a34849fc6926b08e40e20b21c15ed68d18f228904878d4370b56322d0da5789da0318768a374758e6375bfe4641fca5285ec7171828922160f48f5ca7efbfee4d5148612c38ad683ae4e3c3a053d2b7c098cf2b34f2cb19146eadd53c86b2d7ccf3d83b2c370bfb840913ee3879b1057a6b4e07e110b6bcd5e958bc71a14798c91d518cc70abee264b0d25a4110962a764b364ac0b0dd1ee8abc8426d775ec0f22b7e47b32576afaf1b5a48f64573ed1c5c29f50ab412188d9685307323d990802b81dacc06c6e05a1e901830ba9fcc67688dc29c5e27bde0a6e845ca925f5454b6fb3747edfaa2a5820838fb759eadf57f7cb5cec57fc213ddd8a4298fa079c3c0f472b07fb15aa6a7f0a3780bd296ff6a62e58ef443870b02260bd4fd2bbc98255674b8e1f1f9f8d33c7170b0ebbea4523b695911abbf26e41885344823bd0587115fdd83b721a4e8457a31c9a84b3d3520a07e0e35df7f48e5a9d534d0ec7feef1ff74de6a11e7f93eab95175b6ce22c68d78a642ad642837897ec11349205d8593ac19300207572c38d29ca5dfa03bc14cdbc32153c80e5cc3e739403d34c75915e49beb43094cc6dcafb3665b305ddec9286934ae66ec6b777ca528728c851318eb0f207b39f1caaf96db6eeead6b55ed08f451939314577d42bcc9f97c0b52d0234f88fd07e4c1d7780fdebc025cfffcb572cb27a8c33963", - b, - ); + "modexp_nagydani_4_pow0x10001", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b81010001df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f", + "bed8b970c4a34849fc6926b08e40e20b21c15ed68d18f228904878d4370b56322d0da5789da0318768a374758e6375bfe4641fca5285ec7171828922160f48f5ca7efbfee4d5148612c38ad683ae4e3c3a053d2b7c098cf2b34f2cb19146eadd53c86b2d7ccf3d83b2c370bfb840913ee3879b1057a6b4e07e110b6bcd5e958bc71a14798c91d518cc70abee264b0d25a4110962a764b364ac0b0dd1ee8abc8426d775ec0f22b7e47b32576afaf1b5a48f64573ed1c5c29f50ab412188d9685307323d990802b81dacc06c6e05a1e901830ba9fcc67688dc29c5e27bde0a6e845ca925f5454b6fb3747edfaa2a5820838fb759eadf57f7cb5cec57fc213ddd8a4298fa079c3c0f472b07fb15aa6a7f0a3780bd296ff6a62e58ef443870b02260bd4fd2bbc98255674b8e1f1f9f8d33c7170b0ebbea4523b695911abbf26e41885344823bd0587115fdd83b721a4e8457a31c9a84b3d3520a07e0e35df7f48e5a9d534d0ec7feef1ff74de6a11e7f93eab95175b6ce22c68d78a642ad642837897ec11349205d8593ac19300207572c38d29ca5dfa03bc14cdbc32153c80e5cc3e739403d34c75915e49beb43094cc6dcafb3665b305ddec9286934ae66ec6b777ca528728c851318eb0f207b39f1caaf96db6eeead6b55ed08f451939314577d42bcc9f97c0b52d0234f88fd07e4c1d7780fdebc025cfffcb572cb27a8c33963", + b, + ); } fn modexp_nagydani_5_square(b: &mut Criterion) { bench( - "modexp_nagydani_5_square", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf02e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad", - "d61fe4e3f32ac260915b5b03b78a86d11bfc41d973fce5b0cc59035cf8289a8a2e3878ea15fa46565b0d806e2f85b53873ea20ed653869b688adf83f3ef444535bf91598ff7e80f334fb782539b92f39f55310cc4b35349ab7b278346eda9bc37c0d8acd3557fae38197f412f8d9e57ce6a76b7205c23564cab06e5615be7c6f05c3d05ec690cba91da5e89d55b152ff8dd2157dc5458190025cf94b1ad98f7cbe64e9482faba95e6b33844afc640892872b44a9932096508f4a782a4805323808f23e54b6ff9b841dbfa87db3505ae4f687972c18ea0f0d0af89d36c1c2a5b14560c153c3fee406f5cf15cfd1c0bb45d767426d465f2f14c158495069d0c5955a00150707862ecaae30624ebacdd8ac33e4e6aab3ff90b6ba445a84689386b9e945d01823a65874444316e83767290fcff630d2477f49d5d8ffdd200e08ee1274270f86ed14c687895f6caf5ce528bd970c20d2408a9ba66216324c6a011ac4999098362dbd98a038129a2d40c8da6ab88318aa3046cb660327cc44236d9e5d2163bd0959062195c51ed93d0088b6f92051fc99050ece2538749165976233697ab4b610385366e5ce0b02ad6b61c168ecfbedcdf74278a38de340fd7a5fead8e588e294795f9b011e2e60377a89e25c90e145397cdeabc60fd32444a6b7642a611a83c464d8b8976666351b4865c37b02e6dc21dbcdf5f930341707b618cc0f03c3122646b3385c9df9f2ec730eec9d49e7dfc9153b6e6289da8c4f0ebea9ccc1b751948e3bb7171c9e4d57423b0eeeb79095c030cb52677b3f7e0b45c30f645391f3f9c957afa549c4e0b2465b03c67993cd200b1af01035962edbc4c9e89b31c82ac121987d6529dafdeef67a132dc04b6dc68e77f22862040b75e2ceb9ff16da0fca534e6db7bd12fa7b7f51b6c08c1e23dfcdb7acbd2da0b51c87ffbced065a612e9b1c8bba9b7e2d8d7a2f04fcc4aaf355b60d764879a76b5e16762d5f2f55d585d0c8e82df6940960cddfb72c91dfa71f6b4e1c6ca25dfc39a878e998a663c04fe29d5e83b9586d047b4d7ff70a9f0d44f127e7d741685ca75f11629128d916a0ffef4be586a30c4b70389cc746e84ebf177c01ee8a4511cfbb9d1ecf7f7b33c7dd8177896e10bbc82f838dcd6db7ac67de62bf46b6a640fb580c5d1d2708f3862e3d2b645d0d18e49ef088053e3a220adc0e033c2afcfe61c90e32151152eb3caaf746c5e377d541cafc6cbb0cc0fa48b5caf1728f2e1957f5addfc234f1a9d89e40d49356c9172d0561a695fce6dab1d412321bbf407f63766ffd7b6b3d79bcfa07991c5a9709849c1008689e3b47c50d613980bec239fb64185249d055b30375ccb4354d71fe4d05648fbf6c80634dfc3575f2f24abb714c1e4c95e8896763bf4316e954c7ad19e5780ab7a040ca6fb9271f90a8b22ae738daf6cb", - b, - ); + "modexp_nagydani_5_square", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf02e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad", + "d61fe4e3f32ac260915b5b03b78a86d11bfc41d973fce5b0cc59035cf8289a8a2e3878ea15fa46565b0d806e2f85b53873ea20ed653869b688adf83f3ef444535bf91598ff7e80f334fb782539b92f39f55310cc4b35349ab7b278346eda9bc37c0d8acd3557fae38197f412f8d9e57ce6a76b7205c23564cab06e5615be7c6f05c3d05ec690cba91da5e89d55b152ff8dd2157dc5458190025cf94b1ad98f7cbe64e9482faba95e6b33844afc640892872b44a9932096508f4a782a4805323808f23e54b6ff9b841dbfa87db3505ae4f687972c18ea0f0d0af89d36c1c2a5b14560c153c3fee406f5cf15cfd1c0bb45d767426d465f2f14c158495069d0c5955a00150707862ecaae30624ebacdd8ac33e4e6aab3ff90b6ba445a84689386b9e945d01823a65874444316e83767290fcff630d2477f49d5d8ffdd200e08ee1274270f86ed14c687895f6caf5ce528bd970c20d2408a9ba66216324c6a011ac4999098362dbd98a038129a2d40c8da6ab88318aa3046cb660327cc44236d9e5d2163bd0959062195c51ed93d0088b6f92051fc99050ece2538749165976233697ab4b610385366e5ce0b02ad6b61c168ecfbedcdf74278a38de340fd7a5fead8e588e294795f9b011e2e60377a89e25c90e145397cdeabc60fd32444a6b7642a611a83c464d8b8976666351b4865c37b02e6dc21dbcdf5f930341707b618cc0f03c3122646b3385c9df9f2ec730eec9d49e7dfc9153b6e6289da8c4f0ebea9ccc1b751948e3bb7171c9e4d57423b0eeeb79095c030cb52677b3f7e0b45c30f645391f3f9c957afa549c4e0b2465b03c67993cd200b1af01035962edbc4c9e89b31c82ac121987d6529dafdeef67a132dc04b6dc68e77f22862040b75e2ceb9ff16da0fca534e6db7bd12fa7b7f51b6c08c1e23dfcdb7acbd2da0b51c87ffbced065a612e9b1c8bba9b7e2d8d7a2f04fcc4aaf355b60d764879a76b5e16762d5f2f55d585d0c8e82df6940960cddfb72c91dfa71f6b4e1c6ca25dfc39a878e998a663c04fe29d5e83b9586d047b4d7ff70a9f0d44f127e7d741685ca75f11629128d916a0ffef4be586a30c4b70389cc746e84ebf177c01ee8a4511cfbb9d1ecf7f7b33c7dd8177896e10bbc82f838dcd6db7ac67de62bf46b6a640fb580c5d1d2708f3862e3d2b645d0d18e49ef088053e3a220adc0e033c2afcfe61c90e32151152eb3caaf746c5e377d541cafc6cbb0cc0fa48b5caf1728f2e1957f5addfc234f1a9d89e40d49356c9172d0561a695fce6dab1d412321bbf407f63766ffd7b6b3d79bcfa07991c5a9709849c1008689e3b47c50d613980bec239fb64185249d055b30375ccb4354d71fe4d05648fbf6c80634dfc3575f2f24abb714c1e4c95e8896763bf4316e954c7ad19e5780ab7a040ca6fb9271f90a8b22ae738daf6cb", + b, + ); } fn modexp_nagydani_5_qube(b: &mut Criterion) { bench( - "modexp_nagydani_5_qube", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf03e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad", - "5f9c70ec884926a89461056ad20ac4c30155e817f807e4d3f5bb743d789c83386762435c3627773fa77da5144451f2a8aad8adba88e0b669f5377c5e9bad70e45c86fe952b613f015a9953b8a5de5eaee4566acf98d41e327d93a35bd5cef4607d025e58951167957df4ff9b1627649d3943805472e5e293d3efb687cfd1e503faafeb2840a3e3b3f85d016051a58e1c9498aab72e63b748d834b31eb05d85dcde65e27834e266b85c75cc4ec0135135e0601cb93eeeb6e0010c8ceb65c4c319623c5e573a2c8c9fbbf7df68a930beb412d3f4dfd146175484f45d7afaa0d2e60684af9b34730f7c8438465ad3e1d0c3237336722f2aa51095bd5759f4b8ab4dda111b684aa3dac62a761722e7ae43495b7709933512c81c4e3c9133a51f7ce9f2b51fcec064f65779666960b4e45df3900f54311f5613e8012dd1b8efd359eda31a778264c72aa8bb419d862734d769076bce2810011989a45374e5c5d8729fec21427f0bf397eacbb4220f603cf463a4b0c94efd858ffd9768cd60d6ce68d755e0fbad007ce5c2223d70c7018345a102e4ab3c60a13a9e7794303156d4c2063e919f2153c13961fb324c80b240742f47773a7a8e25b3e3fb19b00ce839346c6eb3c732fbc6b888df0b1fe0a3d07b053a2e9402c267b2d62f794d8a2840526e3ade15ce2264496ccd7519571dfde47f7a4bb16292241c20b2be59f3f8fb4f6383f232d838c5a22d8c95b6834d9d2ca493f5a505ebe8899503b0e8f9b19e6e2dd81c1628b80016d02097e0134de51054c4e7674824d4d758760fc52377d2cad145e259aa2ffaf54139e1a66b1e0c1c191e32ac59474c6b526f5b3ba07d3e5ec286eddf531fcd5292869be58c9f22ef91026159f7cf9d05ef66b4299f4da48cc1635bf2243051d342d378a22c83390553e873713c0454ce5f3234397111ac3fe3207b86f0ed9fc025c81903e1748103692074f83824fda6341be4f95ff00b0a9a208c267e12fa01825054cc0513629bf3dbb56dc5b90d4316f87654a8be18227978ea0a8a522760cad620d0d14fd38920fb7321314062914275a5f99f677145a6979b156bd82ecd36f23f8e1273cc2759ecc0b2c69d94dad5211d1bed939dd87ed9e07b91d49713a6e16ade0a98aea789f04994e318e4ff2c8a188cd8d43aeb52c6daa3bc29b4af50ea82a247c5cd67b573b34cbadcc0a376d3bbd530d50367b42705d870f2e27a8197ef46070528bfe408360faa2ebb8bf76e9f388572842bcb119f4d84ee34ae31f5cc594f23705a49197b181fb78ed1ec99499c690f843a4d0cf2e226d118e9372271054fbabdcc5c92ae9fefaef0589cd0e722eaf30c1703ec4289c7fd81beaa8a455ccee5298e31e2080c10c366a6fcf56f7d13582ad0bcad037c612b710fc595b70fbefaaca23623b60c6c39b11beb8e5843b6b3dac60f", - b, - ); + "modexp_nagydani_5_qube", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf03e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad", + "5f9c70ec884926a89461056ad20ac4c30155e817f807e4d3f5bb743d789c83386762435c3627773fa77da5144451f2a8aad8adba88e0b669f5377c5e9bad70e45c86fe952b613f015a9953b8a5de5eaee4566acf98d41e327d93a35bd5cef4607d025e58951167957df4ff9b1627649d3943805472e5e293d3efb687cfd1e503faafeb2840a3e3b3f85d016051a58e1c9498aab72e63b748d834b31eb05d85dcde65e27834e266b85c75cc4ec0135135e0601cb93eeeb6e0010c8ceb65c4c319623c5e573a2c8c9fbbf7df68a930beb412d3f4dfd146175484f45d7afaa0d2e60684af9b34730f7c8438465ad3e1d0c3237336722f2aa51095bd5759f4b8ab4dda111b684aa3dac62a761722e7ae43495b7709933512c81c4e3c9133a51f7ce9f2b51fcec064f65779666960b4e45df3900f54311f5613e8012dd1b8efd359eda31a778264c72aa8bb419d862734d769076bce2810011989a45374e5c5d8729fec21427f0bf397eacbb4220f603cf463a4b0c94efd858ffd9768cd60d6ce68d755e0fbad007ce5c2223d70c7018345a102e4ab3c60a13a9e7794303156d4c2063e919f2153c13961fb324c80b240742f47773a7a8e25b3e3fb19b00ce839346c6eb3c732fbc6b888df0b1fe0a3d07b053a2e9402c267b2d62f794d8a2840526e3ade15ce2264496ccd7519571dfde47f7a4bb16292241c20b2be59f3f8fb4f6383f232d838c5a22d8c95b6834d9d2ca493f5a505ebe8899503b0e8f9b19e6e2dd81c1628b80016d02097e0134de51054c4e7674824d4d758760fc52377d2cad145e259aa2ffaf54139e1a66b1e0c1c191e32ac59474c6b526f5b3ba07d3e5ec286eddf531fcd5292869be58c9f22ef91026159f7cf9d05ef66b4299f4da48cc1635bf2243051d342d378a22c83390553e873713c0454ce5f3234397111ac3fe3207b86f0ed9fc025c81903e1748103692074f83824fda6341be4f95ff00b0a9a208c267e12fa01825054cc0513629bf3dbb56dc5b90d4316f87654a8be18227978ea0a8a522760cad620d0d14fd38920fb7321314062914275a5f99f677145a6979b156bd82ecd36f23f8e1273cc2759ecc0b2c69d94dad5211d1bed939dd87ed9e07b91d49713a6e16ade0a98aea789f04994e318e4ff2c8a188cd8d43aeb52c6daa3bc29b4af50ea82a247c5cd67b573b34cbadcc0a376d3bbd530d50367b42705d870f2e27a8197ef46070528bfe408360faa2ebb8bf76e9f388572842bcb119f4d84ee34ae31f5cc594f23705a49197b181fb78ed1ec99499c690f843a4d0cf2e226d118e9372271054fbabdcc5c92ae9fefaef0589cd0e722eaf30c1703ec4289c7fd81beaa8a455ccee5298e31e2080c10c366a6fcf56f7d13582ad0bcad037c612b710fc595b70fbefaaca23623b60c6c39b11beb8e5843b6b3dac60f", + b, + ); } fn modexp_nagydani_5_pow0x10001(b: &mut Criterion) { bench( - "modexp_nagydani_5_pow0x10001", - "0000000000000000000000000000000000000005", // modexp - "000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf010001e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad", - "5a0eb2bdf0ac1cae8e586689fa16cd4b07dfdedaec8a110ea1fdb059dd5253231b6132987598dfc6e11f86780428982d50cf68f67ae452622c3b336b537ef3298ca645e8f89ee39a26758206a5a3f6409afc709582f95274b57b71fae5c6b74619ae6f089a5393c5b79235d9caf699d23d88fb873f78379690ad8405e34c19f5257d596580c7a6a7206a3712825afe630c76b31cdb4a23e7f0632e10f14f4e282c81a66451a26f8df2a352b5b9f607a7198449d1b926e27036810368e691a74b91c61afa73d9d3b99453e7c8b50fd4f09c039a2f2feb5c419206694c31b92df1d9586140cb3417b38d0c503c7b508cc2ed12e813a1c795e9829eb39ee78eeaf360a169b491a1d4e419574e712402de9d48d54c1ae5e03739b7156615e8267e1fb0a897f067afd11fb33f6e24182d7aaaaa18fe5bc1982f20d6b871e5a398f0f6f718181d31ec225cfa9a0a70124ed9a70031bdf0c1c7829f708b6e17d50419ef361cf77d99c85f44607186c8d683106b8bd38a49b5d0fb503b397a83388c5678dcfcc737499d84512690701ed621a6f0172aecf037184ddf0f2453e4053024018e5ab2e30d6d5363b56e8b41509317c99042f517247474ab3abc848e00a07f69c254f46f2a05cf6ed84e5cc906a518fdcfdf2c61ce731f24c5264f1a25fc04934dc28aec112134dd523f70115074ca34e3807aa4cb925147f3a0ce152d323bd8c675ace446d0fd1ae30c4b57f0eb2c23884bc18f0964c0114796c5b6d080c3d89175665fbf63a6381a6a9da39ad070b645c8bb1779506da14439a9f5b5d481954764ea114fac688930bc68534d403cff4210673b6a6ff7ae416b7cd41404c3d3f282fcd193b86d0f54d0006c2a503b40d5c3930da980565b8f9630e9493a79d1c03e74e5f93ac8e4dc1a901ec5e3b3e57049124c7b72ea345aa359e782285d9e6a5c144a378111dd02c40855ff9c2be9b48425cb0b2fd62dc8678fd151121cf26a65e917d65d8e0dacfae108eb5508b601fb8ffa370be1f9a8b749a2d12eeab81f41079de87e2d777994fa4d28188c579ad327f9957fb7bdecec5c680844dd43cb57cf87aeb763c003e65011f73f8c63442df39a92b946a6bd968a1c1e4d5fa7d88476a68bd8e20e5b70a99259c7d3f85fb1b65cd2e93972e6264e74ebf289b8b6979b9b68a85cd5b360c1987f87235c3c845d62489e33acf85d53fa3561fe3a3aee18924588d9c6eba4edb7a4d106b31173e42929f6f0c48c80ce6a72d54eca7c0fe870068b7a7c89c63cdda593f5b32d3cb4ea8a32c39f00ab449155757172d66763ed9527019d6de6c9f2416aa6203f4d11c9ebee1e1d3845099e55504446448027212616167eb36035726daa7698b075286f5379cd3e93cb3e0cf4f9cb8d017facbb5550ed32d5ec5400ae57e47e2bf78d1eaeff9480cc765ceff39db500", - b, - ); + "modexp_nagydani_5_pow0x10001", + "0000000000000000000000000000000000000005", // modexp + "000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf010001e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad", + "5a0eb2bdf0ac1cae8e586689fa16cd4b07dfdedaec8a110ea1fdb059dd5253231b6132987598dfc6e11f86780428982d50cf68f67ae452622c3b336b537ef3298ca645e8f89ee39a26758206a5a3f6409afc709582f95274b57b71fae5c6b74619ae6f089a5393c5b79235d9caf699d23d88fb873f78379690ad8405e34c19f5257d596580c7a6a7206a3712825afe630c76b31cdb4a23e7f0632e10f14f4e282c81a66451a26f8df2a352b5b9f607a7198449d1b926e27036810368e691a74b91c61afa73d9d3b99453e7c8b50fd4f09c039a2f2feb5c419206694c31b92df1d9586140cb3417b38d0c503c7b508cc2ed12e813a1c795e9829eb39ee78eeaf360a169b491a1d4e419574e712402de9d48d54c1ae5e03739b7156615e8267e1fb0a897f067afd11fb33f6e24182d7aaaaa18fe5bc1982f20d6b871e5a398f0f6f718181d31ec225cfa9a0a70124ed9a70031bdf0c1c7829f708b6e17d50419ef361cf77d99c85f44607186c8d683106b8bd38a49b5d0fb503b397a83388c5678dcfcc737499d84512690701ed621a6f0172aecf037184ddf0f2453e4053024018e5ab2e30d6d5363b56e8b41509317c99042f517247474ab3abc848e00a07f69c254f46f2a05cf6ed84e5cc906a518fdcfdf2c61ce731f24c5264f1a25fc04934dc28aec112134dd523f70115074ca34e3807aa4cb925147f3a0ce152d323bd8c675ace446d0fd1ae30c4b57f0eb2c23884bc18f0964c0114796c5b6d080c3d89175665fbf63a6381a6a9da39ad070b645c8bb1779506da14439a9f5b5d481954764ea114fac688930bc68534d403cff4210673b6a6ff7ae416b7cd41404c3d3f282fcd193b86d0f54d0006c2a503b40d5c3930da980565b8f9630e9493a79d1c03e74e5f93ac8e4dc1a901ec5e3b3e57049124c7b72ea345aa359e782285d9e6a5c144a378111dd02c40855ff9c2be9b48425cb0b2fd62dc8678fd151121cf26a65e917d65d8e0dacfae108eb5508b601fb8ffa370be1f9a8b749a2d12eeab81f41079de87e2d777994fa4d28188c579ad327f9957fb7bdecec5c680844dd43cb57cf87aeb763c003e65011f73f8c63442df39a92b946a6bd968a1c1e4d5fa7d88476a68bd8e20e5b70a99259c7d3f85fb1b65cd2e93972e6264e74ebf289b8b6979b9b68a85cd5b360c1987f87235c3c845d62489e33acf85d53fa3561fe3a3aee18924588d9c6eba4edb7a4d106b31173e42929f6f0c48c80ce6a72d54eca7c0fe870068b7a7c89c63cdda593f5b32d3cb4ea8a32c39f00ab449155757172d66763ed9527019d6de6c9f2416aa6203f4d11c9ebee1e1d3845099e55504446448027212616167eb36035726daa7698b075286f5379cd3e93cb3e0cf4f9cb8d017facbb5550ed32d5ec5400ae57e47e2bf78d1eaeff9480cc765ceff39db500", + b, + ); } fn alt_bn128_add_chfast1(b: &mut Criterion) { bench( - "alt_bn128_add_chfast1", - "0000000000000000000000000000000000000006", // alt_bn128_add - "18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", - "2243525c5efd4b9c3d3c45ac0ca3fe4dd85e830a4ce6b65fa1eeaee202839703301d1d33be6da8e509df21cc35964723180eed7532537db9ae5e7d48f195c915", - b, - ); + "alt_bn128_add_chfast1", + "0000000000000000000000000000000000000006", // alt_bn128_add + "18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", + "2243525c5efd4b9c3d3c45ac0ca3fe4dd85e830a4ce6b65fa1eeaee202839703301d1d33be6da8e509df21cc35964723180eed7532537db9ae5e7d48f195c915", + b, + ); } fn alt_bn128_add_chfast2(b: &mut Criterion) { bench( - "alt_bn128_add_chfast2", - "0000000000000000000000000000000000000006", // alt_bn128_add - "2243525c5efd4b9c3d3c45ac0ca3fe4dd85e830a4ce6b65fa1eeaee202839703301d1d33be6da8e509df21cc35964723180eed7532537db9ae5e7d48f195c91518b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f37266", - "2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb204", - b, - ); + "alt_bn128_add_chfast2", + "0000000000000000000000000000000000000006", // alt_bn128_add + "2243525c5efd4b9c3d3c45ac0ca3fe4dd85e830a4ce6b65fa1eeaee202839703301d1d33be6da8e509df21cc35964723180eed7532537db9ae5e7d48f195c91518b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f37266", + "2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb204", + b, + ); } fn alt_bn128_add_cdetrio1(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio1", - "0000000000000000000000000000000000000006", // alt_bn128_add - "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - b, - ); + "alt_bn128_add_cdetrio1", + "0000000000000000000000000000000000000006", // alt_bn128_add + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + b, + ); } fn alt_bn128_add_cdetrio2(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio2", - "0000000000000000000000000000000000000006", // alt_bn128_add - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - b, - ); + "alt_bn128_add_cdetrio2", + "0000000000000000000000000000000000000006", // alt_bn128_add + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + b, + ); } fn alt_bn128_add_cdetrio3(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio3", - "0000000000000000000000000000000000000006", // alt_bn128_add - "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - b, - ); + "alt_bn128_add_cdetrio3", + "0000000000000000000000000000000000000006", // alt_bn128_add + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + b, + ); } fn alt_bn128_add_cdetrio4(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio4", - "0000000000000000000000000000000000000006", // alt_bn128_add - "", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - b, - ); + "alt_bn128_add_cdetrio4", + "0000000000000000000000000000000000000006", // alt_bn128_add + "", + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + b, + ); } fn alt_bn128_add_cdetrio5(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio5", - "0000000000000000000000000000000000000006", // alt_bn128_add - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - b, - ); + "alt_bn128_add_cdetrio5", + "0000000000000000000000000000000000000006", // alt_bn128_add + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + b, + ); } fn alt_bn128_add_cdetrio6(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio6", - "0000000000000000000000000000000000000006", // alt_bn128_add - "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", - b, - ); + "alt_bn128_add_cdetrio6", + "0000000000000000000000000000000000000006", // alt_bn128_add + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + b, + ); } fn alt_bn128_add_cdetrio7(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio7", - "0000000000000000000000000000000000000006", // alt_bn128_add - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", - b, - ); + "alt_bn128_add_cdetrio7", + "0000000000000000000000000000000000000006", // alt_bn128_add + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + b, + ); } fn alt_bn128_add_cdetrio8(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio8", - "0000000000000000000000000000000000000006", // alt_bn128_add - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", - b, - ); + "alt_bn128_add_cdetrio8", + "0000000000000000000000000000000000000006", // alt_bn128_add + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + b, + ); } fn alt_bn128_add_cdetrio9(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio9", - "0000000000000000000000000000000000000006", // alt_bn128_add - "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", - b, - ); + "alt_bn128_add_cdetrio9", + "0000000000000000000000000000000000000006", // alt_bn128_add + "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + b, + ); } fn alt_bn128_add_cdetrio10(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio10", - "0000000000000000000000000000000000000006", // alt_bn128_add - "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", - b, - ); + "alt_bn128_add_cdetrio10", + "0000000000000000000000000000000000000006", // alt_bn128_add + "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + b, + ); } fn alt_bn128_add_cdetrio11(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio11", - "0000000000000000000000000000000000000006", // alt_bn128_add - "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", - "030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4", - b, - ); + "alt_bn128_add_cdetrio11", + "0000000000000000000000000000000000000006", // alt_bn128_add + "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + "030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4", + b, + ); } fn alt_bn128_add_cdetrio12(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio12", - "0000000000000000000000000000000000000006", // alt_bn128_add - "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4", - b, - ); + "alt_bn128_add_cdetrio12", + "0000000000000000000000000000000000000006", // alt_bn128_add + "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4", + b, + ); } fn alt_bn128_add_cdetrio13(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio13", - "0000000000000000000000000000000000000006", // alt_bn128_add - "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98", - "15bf2bb17880144b5d1cd2b1f46eff9d617bffd1ca57c37fb5a49bd84e53cf66049c797f9ce0d17083deb32b5e36f2ea2a212ee036598dd7624c168993d1355f", - b, - ); + "alt_bn128_add_cdetrio13", + "0000000000000000000000000000000000000006", // alt_bn128_add + "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98", + "15bf2bb17880144b5d1cd2b1f46eff9d617bffd1ca57c37fb5a49bd84e53cf66049c797f9ce0d17083deb32b5e36f2ea2a212ee036598dd7624c168993d1355f", + b, + ); } fn alt_bn128_add_cdetrio14(b: &mut Criterion) { bench( - "alt_bn128_add_cdetrio14", - "0000000000000000000000000000000000000006", // alt_bn128_add - "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa92e83f8d734803fc370eba25ed1f6b8768bd6d83887b87165fc2434fe11a830cb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - b, - ); + "alt_bn128_add_cdetrio14", + "0000000000000000000000000000000000000006", // alt_bn128_add + "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa92e83f8d734803fc370eba25ed1f6b8768bd6d83887b87165fc2434fe11a830cb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + b, + ); } fn alt_bn128_mul_chfast1(b: &mut Criterion) { bench( - "alt_bn128_mul_chfast1", - "0000000000000000000000000000000000000007", // alt_bn128_mul - "2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c2", - "070a8d6a982153cae4be29d434e8faef8a47b274a053f5a4ee2a6c9c13c31e5c031b8ce914eba3a9ffb989f9cdd5b0f01943074bf4f0f315690ec3cec6981afc", - b, - ); + "alt_bn128_mul_chfast1", + "0000000000000000000000000000000000000007", // alt_bn128_mul + "2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c2", + "070a8d6a982153cae4be29d434e8faef8a47b274a053f5a4ee2a6c9c13c31e5c031b8ce914eba3a9ffb989f9cdd5b0f01943074bf4f0f315690ec3cec6981afc", + b, + ); } fn alt_bn128_mul_chfast2(b: &mut Criterion) { bench( - "alt_bn128_mul_chfast2", - "0000000000000000000000000000000000000007", // alt_bn128_mul - "070a8d6a982153cae4be29d434e8faef8a47b274a053f5a4ee2a6c9c13c31e5c031b8ce914eba3a9ffb989f9cdd5b0f01943074bf4f0f315690ec3cec6981afc30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd46", - "025a6f4181d2b4ea8b724290ffb40156eb0adb514c688556eb79cdea0752c2bb2eff3f31dea215f1eb86023a133a996eb6300b44da664d64251d05381bb8a02e", - b, - ); + "alt_bn128_mul_chfast2", + "0000000000000000000000000000000000000007", // alt_bn128_mul + "070a8d6a982153cae4be29d434e8faef8a47b274a053f5a4ee2a6c9c13c31e5c031b8ce914eba3a9ffb989f9cdd5b0f01943074bf4f0f315690ec3cec6981afc30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd46", + "025a6f4181d2b4ea8b724290ffb40156eb0adb514c688556eb79cdea0752c2bb2eff3f31dea215f1eb86023a133a996eb6300b44da664d64251d05381bb8a02e", + b, + ); } fn alt_bn128_mul_chfast3(b: &mut Criterion) { bench( - "alt_bn128_mul_chfast3", - "0000000000000000000000000000000000000007", // alt_bn128_mul - "025a6f4181d2b4ea8b724290ffb40156eb0adb514c688556eb79cdea0752c2bb2eff3f31dea215f1eb86023a133a996eb6300b44da664d64251d05381bb8a02e183227397098d014dc2822db40c0ac2ecbc0b548b438e5469e10460b6c3e7ea3", - "14789d0d4a730b354403b5fac948113739e276c23e0258d8596ee72f9cd9d3230af18a63153e0ec25ff9f2951dd3fa90ed0197bfef6e2a1a62b5095b9d2b4a27", - b, - ); + "alt_bn128_mul_chfast3", + "0000000000000000000000000000000000000007", // alt_bn128_mul + "025a6f4181d2b4ea8b724290ffb40156eb0adb514c688556eb79cdea0752c2bb2eff3f31dea215f1eb86023a133a996eb6300b44da664d64251d05381bb8a02e183227397098d014dc2822db40c0ac2ecbc0b548b438e5469e10460b6c3e7ea3", + "14789d0d4a730b354403b5fac948113739e276c23e0258d8596ee72f9cd9d3230af18a63153e0ec25ff9f2951dd3fa90ed0197bfef6e2a1a62b5095b9d2b4a27", + b, + ); } fn alt_bn128_mul_cdetrio1(b: &mut Criterion) { bench( - "alt_bn128_mul_cdetrio1", - "0000000000000000000000000000000000000007", // alt_bn128_mul - "1a87b0584ce92f4593d161480614f2989035225609f08058ccfa3d0f940febe31a2f3c951f6dadcc7ee9007dff81504b0fcd6d7cf59996efdc33d92bf7f9f8f6ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "2cde5879ba6f13c0b5aa4ef627f159a3347df9722efce88a9afbb20b763b4c411aa7e43076f6aee272755a7f9b84832e71559ba0d2e0b17d5f9f01755e5b0d11", - b, - ); + "alt_bn128_mul_cdetrio1", + "0000000000000000000000000000000000000007", // alt_bn128_mul + "1a87b0584ce92f4593d161480614f2989035225609f08058ccfa3d0f940febe31a2f3c951f6dadcc7ee9007dff81504b0fcd6d7cf59996efdc33d92bf7f9f8f6ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "2cde5879ba6f13c0b5aa4ef627f159a3347df9722efce88a9afbb20b763b4c411aa7e43076f6aee272755a7f9b84832e71559ba0d2e0b17d5f9f01755e5b0d11", + b, + ); } fn alt_bn128_mul_cdetrio6(b: &mut Criterion) { bench( - "alt_bn128_mul_cdetrio6", - "0000000000000000000000000000000000000007", // alt_bn128_mul - "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "29e587aadd7c06722aabba753017c093f70ba7eb1f1c0104ec0564e7e3e21f6022b1143f6a41008e7755c71c3d00b6b915d386de21783ef590486d8afa8453b1", - b, - ); + "alt_bn128_mul_cdetrio6", + "0000000000000000000000000000000000000007", // alt_bn128_mul + "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "29e587aadd7c06722aabba753017c093f70ba7eb1f1c0104ec0564e7e3e21f6022b1143f6a41008e7755c71c3d00b6b915d386de21783ef590486d8afa8453b1", + b, + ); } fn alt_bn128_mul_cdetrio11(b: &mut Criterion) { bench( - "alt_bn128_mul_cdetrio11", - "0000000000000000000000000000000000000007", // alt_bn128_mul - "039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "00a1a234d08efaa2616607e31eca1980128b00b415c845ff25bba3afcb81dc00242077290ed33906aeb8e42fd98c41bcb9057ba03421af3f2d08cfc441186024", - b, - ); + "alt_bn128_mul_cdetrio11", + "0000000000000000000000000000000000000007", // alt_bn128_mul + "039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "00a1a234d08efaa2616607e31eca1980128b00b415c845ff25bba3afcb81dc00242077290ed33906aeb8e42fd98c41bcb9057ba03421af3f2d08cfc441186024", + b, + ); } fn alt_bn128_pairing_jeff1(b: &mut Criterion) { bench( - "alt_bn128_pairing_jeff1", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_jeff1", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_jeff2(b: &mut Criterion) { bench( - "alt_bn128_pairing_jeff2", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "2eca0c7238bf16e83e7a1e6c5d49540685ff51380f309842a98561558019fc0203d3260361bb8451de5ff5ecd17f010ff22f5c31cdf184e9020b06fa5997db841213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f06967a1237ebfeca9aaae0d6d0bab8e28c198c5a339ef8a2407e31cdac516db922160fa257a5fd5b280642ff47b65eca77e626cb685c84fa6d3b6882a283ddd1198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_jeff2", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "2eca0c7238bf16e83e7a1e6c5d49540685ff51380f309842a98561558019fc0203d3260361bb8451de5ff5ecd17f010ff22f5c31cdf184e9020b06fa5997db841213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f06967a1237ebfeca9aaae0d6d0bab8e28c198c5a339ef8a2407e31cdac516db922160fa257a5fd5b280642ff47b65eca77e626cb685c84fa6d3b6882a283ddd1198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_jeff3(b: &mut Criterion) { bench( - "alt_bn128_pairing_jeff3", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "0f25929bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd216da2f5cb6be7a0aa72c440c53c9bbdfec6c36c7d515536431b3a865468acbba2e89718ad33c8bed92e210e81d1853435399a271913a6520736a4729cf0d51eb01a9e2ffa2e92599b68e44de5bcf354fa2642bd4f26b259daa6f7ce3ed57aeb314a9a87b789a58af499b314e13c3d65bede56c07ea2d418d6874857b70763713178fb49a2d6cd347dc58973ff49613a20757d0fcc22079f9abd10c3baee245901b9e027bd5cfc2cb5db82d4dc9677ac795ec500ecd47deee3b5da006d6d049b811d7511c78158de484232fc68daf8a45cf217d1c2fae693ff5871e8752d73b21198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_jeff3", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "0f25929bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd216da2f5cb6be7a0aa72c440c53c9bbdfec6c36c7d515536431b3a865468acbba2e89718ad33c8bed92e210e81d1853435399a271913a6520736a4729cf0d51eb01a9e2ffa2e92599b68e44de5bcf354fa2642bd4f26b259daa6f7ce3ed57aeb314a9a87b789a58af499b314e13c3d65bede56c07ea2d418d6874857b70763713178fb49a2d6cd347dc58973ff49613a20757d0fcc22079f9abd10c3baee245901b9e027bd5cfc2cb5db82d4dc9677ac795ec500ecd47deee3b5da006d6d049b811d7511c78158de484232fc68daf8a45cf217d1c2fae693ff5871e8752d73b21198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_jeff4(b: &mut Criterion) { bench( - "alt_bn128_pairing_jeff4", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "2f2ea0b3da1e8ef11914acf8b2e1b32d99df51f5f4f206fc6b947eae860eddb6068134ddb33dc888ef446b648d72338684d678d2eb2371c61a50734d78da4b7225f83c8b6ab9de74e7da488ef02645c5a16a6652c3c71a15dc37fe3a5dcb7cb122acdedd6308e3bb230d226d16a105295f523a8a02bfc5e8bd2da135ac4c245d065bbad92e7c4e31bf3757f1fe7362a63fbfee50e7dc68da116e67d600d9bf6806d302580dc0661002994e7cd3a7f224e7ddc27802777486bf80f40e4ca3cfdb186bac5188a98c45e6016873d107f5cd131f3a3e339d0375e58bd6219347b008122ae2b09e539e152ec5364e7e2204b03d11d3caa038bfc7cd499f8176aacbee1f39e4e4afc4bc74790a4a028aff2c3d2538731fb755edefd8cb48d6ea589b5e283f150794b6736f670d6a1033f9b46c6f5204f50813eb85c8dc4b59db1c5d39140d97ee4d2b36d99bc49974d18ecca3e7ad51011956051b464d9e27d46cc25e0764bb98575bd466d32db7b15f582b2d5c452b36aa394b789366e5e3ca5aabd415794ab061441e51d01e94640b7e3084a07e02c78cf3103c542bc5b298669f211b88da1679b0b64a63b7e0e7bfe52aae524f73a55be7fe70c7e9bfc94b4cf0da1213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_jeff4", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "2f2ea0b3da1e8ef11914acf8b2e1b32d99df51f5f4f206fc6b947eae860eddb6068134ddb33dc888ef446b648d72338684d678d2eb2371c61a50734d78da4b7225f83c8b6ab9de74e7da488ef02645c5a16a6652c3c71a15dc37fe3a5dcb7cb122acdedd6308e3bb230d226d16a105295f523a8a02bfc5e8bd2da135ac4c245d065bbad92e7c4e31bf3757f1fe7362a63fbfee50e7dc68da116e67d600d9bf6806d302580dc0661002994e7cd3a7f224e7ddc27802777486bf80f40e4ca3cfdb186bac5188a98c45e6016873d107f5cd131f3a3e339d0375e58bd6219347b008122ae2b09e539e152ec5364e7e2204b03d11d3caa038bfc7cd499f8176aacbee1f39e4e4afc4bc74790a4a028aff2c3d2538731fb755edefd8cb48d6ea589b5e283f150794b6736f670d6a1033f9b46c6f5204f50813eb85c8dc4b59db1c5d39140d97ee4d2b36d99bc49974d18ecca3e7ad51011956051b464d9e27d46cc25e0764bb98575bd466d32db7b15f582b2d5c452b36aa394b789366e5e3ca5aabd415794ab061441e51d01e94640b7e3084a07e02c78cf3103c542bc5b298669f211b88da1679b0b64a63b7e0e7bfe52aae524f73a55be7fe70c7e9bfc94b4cf0da1213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_jeff5(b: &mut Criterion) { bench( - "alt_bn128_pairing_jeff5", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "20a754d2071d4d53903e3b31a7e98ad6882d58aec240ef981fdf0a9d22c5926a29c853fcea789887315916bbeb89ca37edb355b4f980c9a12a94f30deeed30211213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f1abb4a25eb9379ae96c84fff9f0540abcfc0a0d11aeda02d4f37e4baf74cb0c11073b3ff2cdbb38755f8691ea59e9606696b3ff278acfc098fa8226470d03869217cee0a9ad79a4493b5253e2e4e3a39fc2df38419f230d341f60cb064a0ac290a3d76f140db8418ba512272381446eb73958670f00cf46f1d9e64cba057b53c26f64a8ec70387a13e41430ed3ee4a7db2059cc5fc13c067194bcc0cb49a98552fd72bd9edb657346127da132e5b82ab908f5816c826acb499e22f2412d1a2d70f25929bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd2198a1f162a73261f112401aa2db79c7dab1533c9935c77290a6ce3b191f2318d198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_jeff5", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "20a754d2071d4d53903e3b31a7e98ad6882d58aec240ef981fdf0a9d22c5926a29c853fcea789887315916bbeb89ca37edb355b4f980c9a12a94f30deeed30211213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f1abb4a25eb9379ae96c84fff9f0540abcfc0a0d11aeda02d4f37e4baf74cb0c11073b3ff2cdbb38755f8691ea59e9606696b3ff278acfc098fa8226470d03869217cee0a9ad79a4493b5253e2e4e3a39fc2df38419f230d341f60cb064a0ac290a3d76f140db8418ba512272381446eb73958670f00cf46f1d9e64cba057b53c26f64a8ec70387a13e41430ed3ee4a7db2059cc5fc13c067194bcc0cb49a98552fd72bd9edb657346127da132e5b82ab908f5816c826acb499e22f2412d1a2d70f25929bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd2198a1f162a73261f112401aa2db79c7dab1533c9935c77290a6ce3b191f2318d198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_jeff6(b: &mut Criterion) { bench( - "alt_bn128_pairing_jeff6", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c103188585e2364128fe25c70558f1560f4f9350baf3959e603cc91486e110936198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", - "0000000000000000000000000000000000000000000000000000000000000000", - b, - ); + "alt_bn128_pairing_jeff6", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c103188585e2364128fe25c70558f1560f4f9350baf3959e603cc91486e110936198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "0000000000000000000000000000000000000000000000000000000000000000", + b, + ); } fn alt_bn128_pairing_empty_data(b: &mut Criterion) { @@ -643,70 +643,70 @@ fn alt_bn128_pairing_empty_data(b: &mut Criterion) { fn alt_bn128_pairing_one_point(b: &mut Criterion) { bench( - "alt_bn128_pairing_one_point", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", - "0000000000000000000000000000000000000000000000000000000000000000", - b, - ); + "alt_bn128_pairing_one_point", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "0000000000000000000000000000000000000000000000000000000000000000", + b, + ); } fn alt_bn128_pairing_two_point_match_2(b: &mut Criterion) { bench( - "alt_bn128_pairing_two_point_match_2", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_two_point_match_2", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_two_point_match_3(b: &mut Criterion) { bench( - "alt_bn128_pairing_two_point_match_3", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_two_point_match_3", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_two_point_match_4(b: &mut Criterion) { bench( - "alt_bn128_pairing_two_point_match_4", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "105456a333e6d636854f987ea7bb713dfd0ae8371a72aea313ae0c32c0bf10160cf031d41b41557f3e7e3ba0c51bebe5da8e6ecd855ec50fc87efcdeac168bcc0476be093a6d2b4bbf907172049874af11e1b6267606e00804d3ff0037ec57fd3010c68cb50161b7d1d96bb71edfec9880171954e56871abf3d93cc94d745fa114c059d74e5b6c4ec14ae5864ebe23a71781d86c29fb8fb6cce94f70d3de7a2101b33461f39d9e887dbb100f170a2345dde3c07e256d1dfa2b657ba5cd030427000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000021a2c3013d2ea92e13c800cde68ef56a294b883f6ac35d25f587c09b1b3c635f7290158a80cd3d66530f74dc94c94adb88f5cdb481acca997b6e60071f08a115f2f997f3dbd66a7afe07fe7862ce239edba9e05c5afff7f8a1259c9733b2dfbb929d1691530ca701b4a106054688728c9972c8512e9789e9567aae23e302ccd75", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_two_point_match_4", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "105456a333e6d636854f987ea7bb713dfd0ae8371a72aea313ae0c32c0bf10160cf031d41b41557f3e7e3ba0c51bebe5da8e6ecd855ec50fc87efcdeac168bcc0476be093a6d2b4bbf907172049874af11e1b6267606e00804d3ff0037ec57fd3010c68cb50161b7d1d96bb71edfec9880171954e56871abf3d93cc94d745fa114c059d74e5b6c4ec14ae5864ebe23a71781d86c29fb8fb6cce94f70d3de7a2101b33461f39d9e887dbb100f170a2345dde3c07e256d1dfa2b657ba5cd030427000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000021a2c3013d2ea92e13c800cde68ef56a294b883f6ac35d25f587c09b1b3c635f7290158a80cd3d66530f74dc94c94adb88f5cdb481acca997b6e60071f08a115f2f997f3dbd66a7afe07fe7862ce239edba9e05c5afff7f8a1259c9733b2dfbb929d1691530ca701b4a106054688728c9972c8512e9789e9567aae23e302ccd75", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_ten_point_match_1(b: &mut Criterion) { bench( - "alt_bn128_pairing_ten_point_match_1", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_ten_point_match_1", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_ten_point_match_2(b: &mut Criterion) { bench( - "alt_bn128_pairing_ten_point_match_2", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_ten_point_match_2", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } fn alt_bn128_pairing_ten_point_match_3(b: &mut Criterion) { bench( - "alt_bn128_pairing_ten_point_match_3", - "0000000000000000000000000000000000000008", // alt_bn128_pairing - "105456a333e6d636854f987ea7bb713dfd0ae8371a72aea313ae0c32c0bf10160cf031d41b41557f3e7e3ba0c51bebe5da8e6ecd855ec50fc87efcdeac168bcc0476be093a6d2b4bbf907172049874af11e1b6267606e00804d3ff0037ec57fd3010c68cb50161b7d1d96bb71edfec9880171954e56871abf3d93cc94d745fa114c059d74e5b6c4ec14ae5864ebe23a71781d86c29fb8fb6cce94f70d3de7a2101b33461f39d9e887dbb100f170a2345dde3c07e256d1dfa2b657ba5cd030427000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000021a2c3013d2ea92e13c800cde68ef56a294b883f6ac35d25f587c09b1b3c635f7290158a80cd3d66530f74dc94c94adb88f5cdb481acca997b6e60071f08a115f2f997f3dbd66a7afe07fe7862ce239edba9e05c5afff7f8a1259c9733b2dfbb929d1691530ca701b4a106054688728c9972c8512e9789e9567aae23e302ccd75", - "0000000000000000000000000000000000000000000000000000000000000001", - b, - ); + "alt_bn128_pairing_ten_point_match_3", + "0000000000000000000000000000000000000008", // alt_bn128_pairing + "105456a333e6d636854f987ea7bb713dfd0ae8371a72aea313ae0c32c0bf10160cf031d41b41557f3e7e3ba0c51bebe5da8e6ecd855ec50fc87efcdeac168bcc0476be093a6d2b4bbf907172049874af11e1b6267606e00804d3ff0037ec57fd3010c68cb50161b7d1d96bb71edfec9880171954e56871abf3d93cc94d745fa114c059d74e5b6c4ec14ae5864ebe23a71781d86c29fb8fb6cce94f70d3de7a2101b33461f39d9e887dbb100f170a2345dde3c07e256d1dfa2b657ba5cd030427000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000021a2c3013d2ea92e13c800cde68ef56a294b883f6ac35d25f587c09b1b3c635f7290158a80cd3d66530f74dc94c94adb88f5cdb481acca997b6e60071f08a115f2f997f3dbd66a7afe07fe7862ce239edba9e05c5afff7f8a1259c9733b2dfbb929d1691530ca701b4a106054688728c9972c8512e9789e9567aae23e302ccd75", + "0000000000000000000000000000000000000000000000000000000000000001", + b, + ); } diff --git a/crates/ethcore/service/src/error.rs b/crates/ethcore/service/src/error.rs index 21692998b..be8f51db3 100644 --- a/crates/ethcore/service/src/error.rs +++ b/crates/ethcore/service/src/error.rs @@ -18,8 +18,8 @@ // https://github.com/openethereum/openethereum/issues/10302 #![allow(deprecated)] -use ethcore; use crate::io; +use ethcore; error_chain! { foreign_links { diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index af7d779f5..eef729d4d 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -18,9 +18,11 @@ use std::{path::Path, sync::Arc, time::Duration}; +use crate::{ + io::{IoContext, IoError, IoHandler, IoService, TimerToken}, + stop_guard::StopGuard, +}; use ansi_term::Colour; -use crate::io::{IoContext, IoError, IoHandler, IoService, TimerToken}; -use crate::stop_guard::StopGuard; use crate::blockchain::{BlockChainDB, BlockChainDBHandler}; use ethcore::{ @@ -29,8 +31,8 @@ use ethcore::{ exit::ShutdownManager, miner::Miner, snapshot::{ - service::{Service as SnapshotService, ServiceParams as SnapServiceParams}, Error as SnapshotError, RestorationStatus, SnapshotService as _SnapshotService, + service::{Service as SnapshotService, ServiceParams as SnapServiceParams}, }, spec::Spec, }; diff --git a/crates/ethcore/service/src/stop_guard.rs b/crates/ethcore/service/src/stop_guard.rs index ce662ea5d..18c91e074 100644 --- a/crates/ethcore/service/src/stop_guard.rs +++ b/crates/ethcore/service/src/stop_guard.rs @@ -16,7 +16,7 @@ //! Stop guard mod -use std::sync::{atomic::*, Arc}; +use std::sync::{Arc, atomic::*}; /// Stop guard that will set a stop flag on drop pub struct StopGuard { diff --git a/crates/ethcore/src/account_db.rs b/crates/ethcore/src/account_db.rs index b3e50b163..83b5f4861 100644 --- a/crates/ethcore/src/account_db.rs +++ b/crates/ethcore/src/account_db.rs @@ -16,7 +16,7 @@ //! DB backend wrapper for Account trie use ethereum_types::H256; -use hash::{keccak, KECCAK_NULL_RLP}; +use hash::{KECCAK_NULL_RLP, keccak}; use hash_db::{AsHashDB, HashDB}; use keccak_hasher::KeccakHasher; use kvdb::DBValue; diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index f2668acd7..28f2cb558 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -36,24 +36,26 @@ use std::{cmp, collections::HashSet, ops, sync::Arc}; use bytes::Bytes; use ethereum_types::{Address, Bloom, H256, U256}; -use crate::engines::EthEngine; -use crate::error::{BlockError, Error}; -use crate::factory::Factories; -use crate::state::State; -use crate::state_db::StateDB; -use crate::trace::Tracing; +use crate::{ + engines::EthEngine, + error::{BlockError, Error}, + factory::Factories, + state::State, + state_db::StateDB, + trace::Tracing, + verification::PreverifiedBlock, +}; use triehash::ordered_trie_root; use unexpected::{Mismatch, OutOfBounds}; -use crate::verification::PreverifiedBlock; use vm::{EnvInfo, LastHashes}; -use hash::keccak; -use rlp::{encode_list, RlpStream}; use crate::types::{ header::{ExtendedHeader, Header}, receipt::{TransactionOutcome, TypedReceipt}, transaction::{Error as TransactionError, SignedTransaction}, }; +use hash::keccak; +use rlp::{RlpStream, encode_list}; /// Block that is ready for transactions to be added. /// @@ -627,15 +629,17 @@ pub fn enact_verified( #[cfg(test)] mod tests { use super::*; - use crate::engines::EthEngine; + use crate::{ + engines::EthEngine, + factory::Factories, + types::{header::Header, transaction::SignedTransaction, view, views::BlockView}, + verification::queue::kind::blocks::Unverified, + }; use error::Error; use ethereum_types::Address; - use crate::factory::Factories; use state_db::StateDB; use std::sync::Arc; use test_helpers::get_temp_state_db; - use crate::types::{header::Header, transaction::SignedTransaction, view, views::BlockView}; - use crate::verification::queue::kind::blocks::Unverified; use vm::LastHashes; /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header diff --git a/crates/ethcore/src/client/ancient_import.rs b/crates/ethcore/src/client/ancient_import.rs index fae039be9..e5c2a4961 100644 --- a/crates/ethcore/src/client/ancient_import.rs +++ b/crates/ethcore/src/client/ancient_import.rs @@ -18,13 +18,14 @@ use std::sync::Arc; -use crate::engines::{EpochVerifier, EthEngine}; -use crate::machine::EthereumMachine; +use crate::{ + engines::{EpochVerifier, EthEngine}, + machine::EthereumMachine, +}; -use crate::blockchain::BlockChain; +use crate::{blockchain::BlockChain, types::header::Header}; use parking_lot::RwLock; use rand::Rng; -use crate::types::header::Header; // do "heavy" verification on ~1/50 blocks, randomly sampled. const HEAVY_VERIFY_RATE: f32 = 0.02; diff --git a/crates/ethcore/src/client/bad_blocks.rs b/crates/ethcore/src/client/bad_blocks.rs index 25cd47108..6863db91e 100644 --- a/crates/ethcore/src/client/bad_blocks.rs +++ b/crates/ethcore/src/client/bad_blocks.rs @@ -16,13 +16,12 @@ //! Stores recently seen bad blocks. +use crate::{types::BlockNumber, verification::queue::kind::blocks::Unverified}; use bytes::{Bytes, ToPretty}; use ethereum_types::H256; use itertools::Itertools; use memory_cache::MemoryLruCache; use parking_lot::RwLock; -use crate::types::BlockNumber; -use crate::verification::queue::kind::blocks::Unverified; /// Recently seen bad blocks. pub struct BadBlocks { diff --git a/crates/ethcore/src/client/chain_notify.rs b/crates/ethcore/src/client/chain_notify.rs index 513964d3c..257c91d13 100644 --- a/crates/ethcore/src/client/chain_notify.rs +++ b/crates/ethcore/src/client/chain_notify.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::blockchain::ImportRoute; +use crate::{blockchain::ImportRoute, types::transaction::UnverifiedTransaction}; use bytes::Bytes; use ethereum_types::{H256, H512, U256}; use std::{collections::HashMap, time::Duration}; -use crate::types::transaction::UnverifiedTransaction; /// Messages to broadcast via chain pub enum ChainMessageType { diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index a76e9e31e..c10b3f638 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -19,20 +19,75 @@ use std::{ collections::{BTreeMap, HashSet, VecDeque}, convert::TryFrom, io::{BufRead, BufReader}, - str::{from_utf8, FromStr}, + str::{FromStr, from_utf8}, sync::{ - atomic::{AtomicBool, AtomicI64, AtomicU64, Ordering as AtomicOrdering}, Arc, Weak, + atomic::{AtomicBool, AtomicI64, AtomicU64, Ordering as AtomicOrdering}, }, time::{Duration, Instant}, }; -use crate::{blockchain::{ - BlockChain, BlockChainDB, BlockNumberKey, BlockProvider, BlockReceipts, ExtrasInsert, - ImportRoute, TransactionAddress, TreeRoute, -}, miner::Miner}; +use crate::{ + block::{ClosedBlock, Drain, LockedBlock, OpenBlock, SealedBlock, enact_verified}, + blockchain::{ + BlockChain, BlockChainDB, BlockNumberKey, BlockProvider, BlockReceipts, ExtrasInsert, + ImportRoute, TransactionAddress, TreeRoute, + }, + client::{ + AccountData, BadBlocks, Balance, BlockChain as BlockChainTrait, BlockChainClient, + BlockChainReset, BlockId, BlockInfo, BlockProducer, BroadcastProposalBlock, Call, + CallAnalytics, ChainInfo, ChainMessageType, ChainNotify, ChainRoute, ClientConfig, + ClientIoMessage, EngineInfo, ImportBlock, ImportExportBlocks, ImportSealedBlock, IoClient, + Mode, NewBlocks, Nonce, PrepareOpenBlock, ProvingBlockChainClient, PruningInfo, + ReopenBlock, ScheduleInfo, SealedBlockImporter, StateClient, StateInfo, StateOrBlock, + TraceFilter, TraceId, TransactionId, TransactionInfo, UncleId, + ancient_import::AncientVerifier, + bad_blocks, + traits::{ChainSyncing, ForceUpdateSealing, ReservedPeersManagement, TransactionRequest}, + }, + engines::{ + EngineError, EpochTransition, EthEngine, ForkChoice, MAX_UNCLE_AGE, SealingState, + epoch::PendingTransition, + }, + error::{ + BlockError, CallError, Error, Error as EthcoreError, ErrorKind as EthcoreErrorKind, + EthcoreResult, ExecutionError, ImportErrorKind, QueueErrorKind, + }, + executive::{Executed, Executive, TransactOptions, contract_address}, + factory::{Factories, VmFactory}, + io::IoChannel, + miner::{Miner, MinerService}, + snapshot::{self, SnapshotClient, io as snapshot_io}, + spec::Spec, + state::{self, State}, + state_db::StateDB, + trace::{ + self, Database as TraceDatabase, ImportRequest as TraceImportRequest, LocalizedTrace, + TraceDB, + }, + transaction_ext::Transaction, + types::{ + BlockNumber, + ancestry_action::AncestryAction, + data_format::DataFormat, + encoded, + filter::Filter, + header::{ExtendedHeader, Header}, + log_entry::LocalizedLogEntry, + receipt::{LocalizedReceipt, TypedReceipt}, + transaction::{ + self, Action, LocalizedTransaction, SignedTransaction, TypedTransaction, + UnverifiedTransaction, + }, + }, + verification::{ + self, BlockQueue, PreverifiedBlock, Verifier, + queue::kind::{BlockLike, blocks::Unverified}, + }, +}; +use ansi_term::Colour; use bytes::{Bytes, ToPretty}; -use call_contract::CallContract; +use call_contract::{CallContract, RegistryInfo}; use db::{DBTransaction, DBValue, KeyValueDB}; use ethcore_miner::pool::VerifiedTransaction; use ethereum_types::{Address, H256, H264, H512, U256}; @@ -42,70 +97,17 @@ use parking_lot::{Mutex, RwLock}; use rand::rngs::OsRng; use rlp::{PayloadInfo, Rlp}; use rustc_hex::FromHex; -use trie::{Trie, TrieFactory, TrieSpec}; -use crate::types::{ - ancestry_action::AncestryAction, - data_format::DataFormat, - encoded, - filter::Filter, - header::{ExtendedHeader, Header}, - log_entry::LocalizedLogEntry, - receipt::{LocalizedReceipt, TypedReceipt}, - transaction::{ - self, Action, LocalizedTransaction, SignedTransaction, TypedTransaction, - UnverifiedTransaction, - }, - BlockNumber, -}; -use vm::{EnvInfo, LastHashes}; -use crate::miner::MinerService; -use ansi_term::Colour; -use crate::block::{enact_verified, ClosedBlock, Drain, LockedBlock, OpenBlock, SealedBlock}; -use call_contract::RegistryInfo; -use crate::client::{ - ancient_import::AncientVerifier, - bad_blocks, - traits::{ChainSyncing, ForceUpdateSealing, ReservedPeersManagement, TransactionRequest}, - AccountData, BadBlocks, Balance, BlockChain as BlockChainTrait, BlockChainClient, - BlockChainReset, BlockId, BlockInfo, BlockProducer, BroadcastProposalBlock, Call, - CallAnalytics, ChainInfo, ChainMessageType, ChainNotify, ChainRoute, ClientConfig, - ClientIoMessage, EngineInfo, ImportBlock, ImportExportBlocks, ImportSealedBlock, IoClient, - Mode, NewBlocks, Nonce, PrepareOpenBlock, ProvingBlockChainClient, PruningInfo, ReopenBlock, - ScheduleInfo, SealedBlockImporter, StateClient, StateInfo, StateOrBlock, TraceFilter, TraceId, - TransactionId, TransactionInfo, UncleId, -}; -use crate::engines::{ - epoch::PendingTransition, EngineError, EpochTransition, EthEngine, ForkChoice, SealingState, - MAX_UNCLE_AGE, -}; -use crate::error::{ - BlockError, CallError, Error, Error as EthcoreError, ErrorKind as EthcoreErrorKind, - EthcoreResult, ExecutionError, ImportErrorKind, QueueErrorKind, -}; -use crate::executive::{contract_address, Executed, Executive, TransactOptions}; -use crate::factory::{Factories, VmFactory}; -use crate::io::IoChannel; -use crate::snapshot::{self, io as snapshot_io, SnapshotClient}; -use crate::spec::Spec; -use crate::state::{self, State}; -use crate::state_db::StateDB; use stats::{PrometheusMetrics, PrometheusRegistry}; -use crate::trace::{ - self, Database as TraceDatabase, ImportRequest as TraceImportRequest, LocalizedTrace, TraceDB, -}; -use crate::transaction_ext::Transaction; -use crate::verification::{ - self, - queue::kind::{blocks::Unverified, BlockLike}, - BlockQueue, PreverifiedBlock, Verifier, -}; -use vm::Schedule; +use trie::{Trie, TrieFactory, TrieSpec}; +use vm::{EnvInfo, LastHashes, Schedule}; // re-export -pub use crate::blockchain::CacheSize as BlockChainCacheSize; -use db::{keys::BlockDetails, Readable, Writable}; +pub use crate::{ + blockchain::CacheSize as BlockChainCacheSize, + types::{block_status::BlockStatus, blockchain_info::BlockChainInfo}, + verification::QueueInfo as BlockQueueInfo, +}; +use db::{Readable, Writable, keys::BlockDetails}; pub use reth_util::queue::ExecutionQueue; -pub use crate::types::{block_status::BlockStatus, blockchain_info::BlockChainInfo}; -pub use crate::verification::QueueInfo as BlockQueueInfo; use crate::exit::ShutdownManager; use_contract!(registry, "res/contracts/registrar.json"); @@ -881,7 +883,8 @@ impl Importer { let call = move |addr, data| { let mut state_db = state_db.boxed_clone(); - let backend = crate::state::backend::Proving::new(state_db.as_hash_db_mut()); + let backend = + crate::state::backend::Proving::new(state_db.as_hash_db_mut()); let transaction = client.contract_call_tx( BlockId::Hash(*header.parent_hash()), @@ -1970,11 +1973,7 @@ impl RegistryInfo for Client { let value = decoder .decode(&self.call_contract(block, address, data).ok()?) .ok()?; - if value.is_zero() { - None - } else { - Some(value) - } + if value.is_zero() { None } else { Some(value) } } } @@ -2772,9 +2771,11 @@ impl BlockChainClient for Client { .as_u64() as usize, ) }; - self.importer - .miner - .ready_transactions(self, max_len, crate::miner::PendingOrdering::Priority) + self.importer.miner.ready_transactions( + self, + max_len, + crate::miner::PendingOrdering::Priority, + ) } fn transaction(&self, tx_hash: &H256) -> Option> { @@ -3784,9 +3785,11 @@ impl PrometheusMetrics for Client { #[cfg(test)] mod tests { - use crate::blockchain::{BlockProvider, ExtrasInsert}; + use crate::{ + blockchain::{BlockProvider, ExtrasInsert}, + spec::Spec, + }; use ethereum_types::{H160, H256}; - use crate::spec::Spec; use test_helpers::generate_dummy_client_with_spec_and_data; #[test] @@ -3794,16 +3797,16 @@ mod tests { use crate::client::{BlockChainClient, ChainInfo}; use test_helpers::{generate_dummy_client, get_good_dummy_block_hash}; + use crate::types::encoded; use kvdb::DBTransaction; use std::{ sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, thread, time::Duration, }; - use crate::types::encoded; let client = generate_dummy_client(0); let genesis = client.chain_info().best_block_hash; @@ -3866,13 +3869,13 @@ mod tests { #[test] fn should_return_correct_log_index() { use super::transaction_receipt; - use crypto::publickey::KeyPair; - use hash::keccak; use crate::types::{ log_entry::{LocalizedLogEntry, LogEntry}, receipt::{LegacyReceipt, LocalizedReceipt, TransactionOutcome, TypedReceipt}, transaction::{Action, LocalizedTransaction, Transaction, TypedTransaction}, }; + use crypto::publickey::KeyPair; + use hash::keccak; // given let key = KeyPair::from_secret_slice(keccak("test").as_bytes()).unwrap(); diff --git a/crates/ethcore/src/client/config.rs b/crates/ethcore/src/client/config.rs index ea4885b3f..26c305770 100644 --- a/crates/ethcore/src/client/config.rs +++ b/crates/ethcore/src/client/config.rs @@ -19,14 +19,15 @@ use std::{ str::FromStr, }; +use crate::{ + snapshot::SnapshotConfiguration, + verification::{QueueConfig, VerifierType}, +}; use journaldb; -use crate::snapshot::SnapshotConfiguration; -use crate::verification::{QueueConfig, VerifierType}; -pub use crate::blockchain::Config as BlockChainConfig; +pub use crate::{blockchain::Config as BlockChainConfig, trace::Config as TraceConfig}; pub use evm::VMType; pub use std::time::Duration; -pub use crate::trace::Config as TraceConfig; /// Client state db compaction profile #[derive(Debug, PartialEq, Clone)] diff --git a/crates/ethcore/src/client/evm_test_client.rs b/crates/ethcore/src/client/evm_test_client.rs index 503470e80..1a89cb508 100644 --- a/crates/ethcore/src/client/evm_test_client.rs +++ b/crates/ethcore/src/client/evm_test_client.rs @@ -16,23 +16,23 @@ //! Simple Client used for EVM tests. -use crate::client; +use crate::{ + client, executive, + factory::{self, Factories}, + spec, trace, + types::{log_entry, receipt, transaction}, +}; use db; use ethereum_types::{H160, H256, U256}; use ethtrie; use evm::{FinalizationResult, VMType}; -use crate::executive; -use crate::factory::{self, Factories}; use journaldb; use kvdb::{self, KeyValueDB}; use pod_state; -use crate::spec; use state; use state_db; use std::{fmt, sync::Arc}; -use crate::trace; use trie; -use crate::types::{log_entry, receipt, transaction}; use vm::{self, ActionParams}; /// EVM test Error. diff --git a/crates/ethcore/src/client/io_message.rs b/crates/ethcore/src/client/io_message.rs index 82a633f9b..c5e7961ed 100644 --- a/crates/ethcore/src/client/io_message.rs +++ b/crates/ethcore/src/client/io_message.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{client::Client, snapshot::ManifestData}; use bytes::Bytes; -use crate::client::Client; use ethereum_types::H256; -use crate::snapshot::ManifestData; use std::fmt; /// Message type for external and internal events diff --git a/crates/ethcore/src/client/mod.rs b/crates/ethcore/src/client/mod.rs index 09f2327b6..25e255fc3 100644 --- a/crates/ethcore/src/client/mod.rs +++ b/crates/ethcore/src/client/mod.rs @@ -54,8 +54,7 @@ pub use crate::types::{ pub use crate::executive::{Executed, Executive, TransactOptions}; pub use vm::{EnvInfo, LastHashes}; -pub use crate::error::TransactionImportError; -pub use crate::verification::VerifierType; +pub use crate::{error::TransactionImportError, verification::VerifierType}; pub mod traits; diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index fb21620e3..81dc931fe 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -20,12 +20,30 @@ use std::{ collections::{BTreeMap, HashMap}, str::FromStr, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrder}, Arc, + atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrder}, }, }; -use crate::blockchain::{BlockReceipts, TreeRoute}; +use crate::{ + blockchain::{BlockReceipts, TreeRoute}, + types::{ + BlockNumber, + basic_account::BasicAccount, + encoded, + filter::Filter, + header::Header, + log_entry::LocalizedLogEntry, + pruning_info::PruningInfo, + receipt::{LegacyReceipt, LocalizedReceipt, TransactionOutcome, TypedReceipt}, + transaction::{ + self, Action, LocalizedTransaction, SignedTransaction, Transaction, TypedTransaction, + TypedTxId, + }, + view, + views::BlockView, + }, +}; use bytes::Bytes; use crypto::publickey::{Generator, Random}; use db::{COL_STATE, NUM_COLUMNS}; @@ -38,46 +56,32 @@ use kvdb::DBValue; use parking_lot::{Mutex, RwLock}; use rlp::RlpStream; use rustc_hex::FromHex; -use crate::types::{ - basic_account::BasicAccount, - encoded, - filter::Filter, - header::Header, - log_entry::LocalizedLogEntry, - pruning_info::PruningInfo, - receipt::{LegacyReceipt, LocalizedReceipt, TransactionOutcome, TypedReceipt}, - transaction::{ - self, Action, LocalizedTransaction, SignedTransaction, Transaction, TypedTransaction, - TypedTxId, - }, - view, - views::BlockView, - BlockNumber, -}; use vm::Schedule; -use crate::block::{ClosedBlock, OpenBlock, SealedBlock}; -use call_contract::{CallContract, RegistryInfo}; -use crate::client::{ - traits::{ForceUpdateSealing, TransactionRequest}, - AccountData, BadBlocks, Balance, BlockChain, BlockChainClient, BlockChainInfo, BlockId, - BlockInfo, BlockProducer, BlockStatus, BroadcastProposalBlock, Call, CallAnalytics, ChainInfo, - EngineInfo, ImportBlock, ImportSealedBlock, IoClient, LastHashes, Mode, Nonce, - PrepareOpenBlock, ProvingBlockChainClient, ReopenBlock, ScheduleInfo, SealedBlockImporter, - StateClient, StateOrBlock, TraceFilter, TraceId, TransactionId, TransactionInfo, UncleId, +use crate::{ + block::{ClosedBlock, OpenBlock, SealedBlock}, + client::{ + AccountData, BadBlocks, Balance, BlockChain, BlockChainClient, BlockChainInfo, BlockId, + BlockInfo, BlockProducer, BlockStatus, BroadcastProposalBlock, Call, CallAnalytics, + ChainInfo, EngineInfo, ImportBlock, ImportSealedBlock, IoClient, LastHashes, Mode, Nonce, + PrepareOpenBlock, ProvingBlockChainClient, ReopenBlock, ScheduleInfo, SealedBlockImporter, + StateClient, StateOrBlock, TraceFilter, TraceId, TransactionId, TransactionInfo, UncleId, + traits::{ForceUpdateSealing, TransactionRequest}, + }, + engines::EthEngine, + executed::CallError, + executive::Executed, + spec::Spec, + state::StateInfo, + trace::LocalizedTrace, + verification::queue::{QueueInfo, kind::blocks::Unverified}, }; -use crate::engines::EthEngine; +use call_contract::{CallContract, RegistryInfo}; use error::{Error, EthcoreResult}; -use crate::executed::CallError; -use crate::executive::Executed; use journaldb; use miner::{self, Miner, MinerService}; -use crate::spec::Spec; -use crate::state::StateInfo; use state_db::StateDB; use stats::{PrometheusMetrics, PrometheusRegistry}; -use crate::trace::LocalizedTrace; -use crate::verification::queue::{kind::blocks::Unverified, QueueInfo}; use super::ReservedPeersManagement; @@ -954,11 +958,7 @@ impl BlockChainClient for TestBlockChainClient { blocks.push(hash.clone()); } } - if adding { - Vec::new() - } else { - blocks - } + if adding { Vec::new() } else { blocks } }, is_from_route_finalized: false, }) diff --git a/crates/ethcore/src/client/trace.rs b/crates/ethcore/src/client/trace.rs index 6c5f3e05a..04ce18e65 100644 --- a/crates/ethcore/src/client/trace.rs +++ b/crates/ethcore/src/client/trace.rs @@ -16,10 +16,12 @@ //! Bridge between Tracedb and Blockchain. -use crate::blockchain::{BlockChain, BlockProvider, TransactionAddress}; +use crate::{ + blockchain::{BlockChain, BlockProvider, TransactionAddress}, + trace::DatabaseExtras as TraceDatabaseExtras, + types::BlockNumber, +}; use ethereum_types::H256; -use crate::trace::DatabaseExtras as TraceDatabaseExtras; -use crate::types::BlockNumber; impl TraceDatabaseExtras for BlockChain { fn block_hash(&self, block_number: BlockNumber) -> Option { diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index c3707523d..369cf65af 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -22,7 +22,26 @@ use std::{ sync::Arc, }; -use crate::blockchain::{BlockReceipts, TreeRoute}; +use crate::{ + blockchain::{BlockReceipts, TreeRoute}, + types::{ + BlockNumber, + basic_account::BasicAccount, + block_status::BlockStatus, + blockchain_info::BlockChainInfo, + call_analytics::CallAnalytics, + data_format::DataFormat, + encoded, + filter::Filter, + header::Header, + ids::*, + log_entry::LocalizedLogEntry, + pruning_info::PruningInfo, + receipt::LocalizedReceipt, + trace_filter::Filter as TraceFilter, + transaction::{self, Action, LocalizedTransaction, SignedTransaction, TypedTxId}, + }, +}; use bytes::Bytes; use call_contract::{CallContract, RegistryInfo}; use ethcore_miner::pool::VerifiedTransaction; @@ -31,34 +50,19 @@ use evm::Schedule; use itertools::Itertools; use kvdb::DBValue; use parking_lot::Mutex; -use crate::types::{ - basic_account::BasicAccount, - block_status::BlockStatus, - blockchain_info::BlockChainInfo, - call_analytics::CallAnalytics, - data_format::DataFormat, - encoded, - filter::Filter, - header::Header, - ids::*, - log_entry::LocalizedLogEntry, - pruning_info::PruningInfo, - receipt::LocalizedReceipt, - trace_filter::Filter as TraceFilter, - transaction::{self, Action, LocalizedTransaction, SignedTransaction, TypedTxId}, - BlockNumber, -}; use vm::LastHashes; -use crate::block::{ClosedBlock, OpenBlock, SealedBlock}; -use crate::client::Mode; -use crate::engines::EthEngine; -use crate::error::{Error, EthcoreResult}; -use crate::executed::CallError; -use crate::executive::Executed; -use crate::state::StateInfo; -use crate::trace::LocalizedTrace; -use crate::verification::queue::{kind::blocks::Unverified, QueueInfo as BlockQueueInfo}; +use crate::{ + block::{ClosedBlock, OpenBlock, SealedBlock}, + client::Mode, + engines::EthEngine, + error::{Error, EthcoreResult}, + executed::CallError, + executive::Executed, + state::StateInfo, + trace::LocalizedTrace, + verification::queue::{QueueInfo as BlockQueueInfo, kind::blocks::Unverified}, +}; /// State information to be used during client query pub enum StateOrBlock { diff --git a/crates/ethcore/src/engines/authority_round/finality.rs b/crates/ethcore/src/engines/authority_round/finality.rs index f0d814f02..eace66ac1 100644 --- a/crates/ethcore/src/engines/authority_round/finality.rs +++ b/crates/ethcore/src/engines/authority_round/finality.rs @@ -17,12 +17,12 @@ //! Finality proof generation and checking. use std::collections::{ - hash_map::{Entry, HashMap}, VecDeque, + hash_map::{Entry, HashMap}, }; -use ethereum_types::{Address, H256}; use crate::types::BlockNumber; +use ethereum_types::{Address, H256}; use crate::engines::validator_set::SimpleList; @@ -182,7 +182,9 @@ impl RollingFinality { } } Entry::Vacant(_) => { - panic!("all hashes in `header` should have entries in `sign_count` for their signers; qed"); + panic!( + "all hashes in `header` should have entries in `sign_count` for their signers; qed" + ); } } } @@ -192,16 +194,18 @@ impl RollingFinality { #[cfg(test)] mod tests { use super::RollingFinality; - use ethereum_types::{Address, H256}; use crate::types::BlockNumber; + use ethereum_types::{Address, H256}; #[test] fn rejects_unknown_signers() { let signers = (0..3).map(|_| Address::random()).collect::>(); let mut finality = RollingFinality::blank(signers.clone(), BlockNumber::max_value()); - assert!(finality - .push_hash(H256::random(), 0, vec![signers[0], Address::random()]) - .is_err()); + assert!( + finality + .push_hash(H256::random(), 0, vec![signers[0], Address::random()]) + .is_err() + ); } #[test] @@ -287,9 +291,11 @@ mod tests { fn rejects_unknown_signers_2_3() { let signers = (0..3).map(|_| Address::random()).collect::>(); let mut finality = RollingFinality::blank(signers.clone(), 0); - assert!(finality - .push_hash(H256::random(), 0, vec![signers[0], Address::random()]) - .is_err()); + assert!( + finality + .push_hash(H256::random(), 0, vec![signers[0], Address::random()]) + .is_err() + ); } #[test] diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index c0b1a7fbb..65477a81f 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -38,8 +38,8 @@ use std::{ iter::{self, FromIterator}, ops::Deref, sync::{ - atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, Arc, Weak, + atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, }, time::{Duration, UNIX_EPOCH}, u64, @@ -47,42 +47,45 @@ use std::{ use self::finality::RollingFinality; use super::{ - signer::EngineSigner, - validator_set::{new_validator_set_posdao, SimpleList, ValidatorSet}, EthEngine, + signer::EngineSigner, + validator_set::{SimpleList, ValidatorSet, new_validator_set_posdao}, }; -use crate::block::*; -use bytes::Bytes; -use crate::client::{ - traits::{ForceUpdateSealing, TransactionRequest}, - EngineClient, +use crate::{ + block::*, + client::{ + EngineClient, + traits::{ForceUpdateSealing, TransactionRequest}, + }, + engines::{ + ConstructedVerifier, Engine, EngineError, Seal, SealingState, block_reward, + block_reward::{BlockRewardContract, RewardKind}, + }, + error::{BlockError, Error, ErrorKind}, }; +use bytes::Bytes; use crypto::publickey::{self, Signature}; -use crate::engines::{ - block_reward, - block_reward::{BlockRewardContract, RewardKind}, - ConstructedVerifier, Engine, EngineError, Seal, SealingState, -}; -use crate::error::{BlockError, Error, ErrorKind}; use ethereum_types::{Address, H256, H512, H520, U128, U256}; +use crate::{ + io::{IoContext, IoHandler, IoService, TimerToken}, + machine::{AuxiliaryData, Call, EthereumMachine}, + types::{ + BlockNumber, + ancestry_action::AncestryAction, + header::{ExtendedHeader, Header}, + ids::BlockId, + transaction::SignedTransaction, + }, +}; use ethjson::{self, uint::Uint}; use hash::keccak; -use crate::io::{IoContext, IoHandler, IoService, TimerToken}; use itertools::{self, Itertools}; use lru_cache::LruCache; -use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use parking_lot::{Mutex, RwLock}; use rand::rngs::OsRng; -use rlp::{encode, Decodable, DecoderError, Encodable, Rlp, RlpStream}; +use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream, encode}; use time_utils::CheckedSystemTime; -use crate::types::{ - ancestry_action::AncestryAction, - header::{ExtendedHeader, Header}, - ids::BlockId, - transaction::SignedTransaction, - BlockNumber, -}; use unexpected::{Mismatch, OutOfBounds}; //mod block_gas_limit as crate_block_gas_limit; @@ -1737,7 +1740,9 @@ impl Engine for AuthorityRound { // this is guarded against by `can_propose` unless the block was signed // on the same step (implies same key) and on a different node. if parent_step == step { - warn!("Attempted to seal block on the same step as parent. Is this authority sealing with more than one node?"); + warn!( + "Attempted to seal block on the same step as parent. Is this authority sealing with more than one node?" + ); return Seal::None; } @@ -2382,43 +2387,45 @@ fn next_step_time_duration(info: StepDurationInfo, time: u64) -> Option<(u64, u6 #[cfg(test)] mod tests { use super::{ - calculate_score, next_step_time_duration, util::BoundContract, AuthorityRound, - AuthorityRoundParams, EmptyStep, SealedEmptyStep, StepDurationInfo, + AuthorityRound, AuthorityRoundParams, EmptyStep, SealedEmptyStep, StepDurationInfo, + calculate_score, next_step_time_duration, util::BoundContract, + }; + use crate::{ + block::*, + engines::{ + Engine, EngineError, EngineSigner, EthEngine, Seal, + block_reward::BlockRewardContract, + validator_set::{SimpleList, TestSet}, + }, + error::{Error, ErrorKind}, + miner::{Author, MinerService}, + spec::Spec, + test_helpers::{ + TestNotify, generate_dummy_client_with_spec, generate_dummy_client_with_spec_and_data, + get_temp_state_db, push_block_with_transactions_and_author, + }, + types::{ + header::Header, + ids::BlockId, + transaction::{Action, Transaction, TypedTransaction}, + }, }; use accounts::AccountProvider; - use crate::block::*; use crypto::publickey::Signature; - use crate::engines::{ - block_reward::BlockRewardContract, - validator_set::{SimpleList, TestSet}, - Engine, EngineError, EngineSigner, EthEngine, Seal, - }; - use crate::error::{Error, ErrorKind}; use ethabi_contract::use_contract; use ethereum_types::{Address, H256, H520, U256}; use ethjson; use hash::keccak; - use crate::miner::{Author, MinerService}; use rlp::encode; - use crate::spec::Spec; use std::{ collections::BTreeMap, str::FromStr, sync::{ - atomic::{AtomicU64, AtomicUsize, Ordering as AtomicOrdering}, Arc, + atomic::{AtomicU64, AtomicUsize, Ordering as AtomicOrdering}, }, time::Duration, }; - use crate::test_helpers::{ - generate_dummy_client_with_spec, generate_dummy_client_with_spec_and_data, - get_temp_state_db, push_block_with_transactions_and_author, TestNotify, - }; - use crate::types::{ - header::Header, - ids::BlockId, - transaction::{Action, Transaction, TypedTransaction}, - }; fn aura(f: F) -> Arc where @@ -3489,16 +3496,18 @@ mod tests { engine.step(); assert!(bc.call_const(rand_contract::functions::is_reveal_phase::call())?); assert!(!bc.call_const(rand_contract::functions::sent_reveal::call(0, addr1))?); - assert!(bc - .call_const(rand_contract::functions::get_value::call())? - .is_zero()); + assert!( + bc.call_const(rand_contract::functions::get_value::call())? + .is_zero() + ); // ...so in the next step, we reveal our random value, and the contract's random value is not zero anymore. engine.step(); assert!(bc.call_const(rand_contract::functions::sent_reveal::call(0, addr1))?); - assert!(!bc - .call_const(rand_contract::functions::get_value::call())? - .is_zero()); + assert!( + !bc.call_const(rand_contract::functions::get_value::call())? + .is_zero() + ); Ok(()) } diff --git a/crates/ethcore/src/engines/authority_round/randomness.rs b/crates/ethcore/src/engines/authority_round/randomness.rs index 2520b0f2b..be0f0a7d2 100644 --- a/crates/ethcore/src/engines/authority_round/randomness.rs +++ b/crates/ethcore/src/engines/authority_round/randomness.rs @@ -69,10 +69,10 @@ //! A production implementation of a randomness contract can be found here: //! https://github.com/poanetwork/posdao-contracts/blob/4fddb108993d4962951717b49222327f3d94275b/contracts/RandomAuRa.sol +use crate::engines::signer::EngineSigner; use bytes::Bytes; -use crypto::publickey::{ecies, Error as CryptoError}; +use crypto::publickey::{Error as CryptoError, ecies}; use derive_more::Display; -use crate::engines::signer::EngineSigner; use ethabi::Hash; use ethabi_contract::use_contract; use ethereum_types::{Address, H256, U256}; diff --git a/crates/ethcore/src/engines/authority_round/util.rs b/crates/ethcore/src/engines/authority_round/util.rs index 218784d03..f03e4e2c4 100644 --- a/crates/ethcore/src/engines/authority_round/util.rs +++ b/crates/ethcore/src/engines/authority_round/util.rs @@ -20,12 +20,14 @@ use std::fmt; -use crate::client::{traits::EngineClient, BlockChainClient}; +use crate::{ + client::{BlockChainClient, traits::EngineClient}, + types::{header::Header, ids::BlockId}, +}; use ethabi::{self, FunctionOutputDecoder}; use ethabi_contract::use_contract; use ethereum_types::{Address, U256}; use log::{debug, error}; -use crate::types::{header::Header, ids::BlockId}; /// A contract bound to a client and block number. /// diff --git a/crates/ethcore/src/engines/basic_authority.rs b/crates/ethcore/src/engines/basic_authority.rs index 884bd0f0b..5994035c1 100644 --- a/crates/ethcore/src/engines/basic_authority.rs +++ b/crates/ethcore/src/engines/basic_authority.rs @@ -16,18 +16,20 @@ //! A blockchain engine that supports a basic, non-BFT proof-of-authority. -use super::validator_set::{new_validator_set, SimpleList, ValidatorSet}; -use crate::block::*; -use crate::client::EngineClient; +use super::validator_set::{SimpleList, ValidatorSet, new_validator_set}; +use crate::{ + block::*, + client::EngineClient, + engines::{ConstructedVerifier, Engine, EngineError, Seal, SealingState, signer::EngineSigner}, + error::{BlockError, Error}, + machine::{AuxiliaryData, Call, EthereumMachine}, + types::header::{ExtendedHeader, Header}, +}; use crypto::publickey::{self, Signature}; -use crate::engines::{signer::EngineSigner, ConstructedVerifier, Engine, EngineError, Seal, SealingState}; -use crate::error::{BlockError, Error}; use ethereum_types::{H256, H520}; use ethjson; -use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use parking_lot::RwLock; use std::sync::Weak; -use crate::types::header::{ExtendedHeader, Header}; /// `BasicAuthority` params. #[derive(Debug, PartialEq)] @@ -225,16 +227,18 @@ impl Engine for BasicAuthority { #[cfg(test)] mod tests { + use crate::{ + block::*, + engines::{Seal, SealingState}, + spec::Spec, + test_helpers::get_temp_state_db, + types::header::Header, + }; use accounts::AccountProvider; - use crate::block::*; - use crate::engines::{Seal, SealingState}; use ethereum_types::H520; use hash::keccak; - use crate::spec::Spec; use std::sync::Arc; use tempdir::TempDir; - use crate::test_helpers::get_temp_state_db; - use crate::types::header::Header; /// Create a new test chain spec with `BasicAuthority` consensus engine. fn new_test_authority() -> Spec { diff --git a/crates/ethcore/src/engines/block_reward.rs b/crates/ethcore/src/engines/block_reward.rs index 1f5e533dd..35f9cf2c0 100644 --- a/crates/ethcore/src/engines/block_reward.rs +++ b/crates/ethcore/src/engines/block_reward.rs @@ -21,13 +21,15 @@ use ethabi::{self, ParamType}; use ethereum_types::{Address, H160, U256}; use super::{SystemOrCodeCall, SystemOrCodeCallKind}; -use crate::block::ExecutedBlock; -use crate::error::Error; +use crate::{ + block::ExecutedBlock, + error::Error, + machine::Machine, + trace::{self, ExecutiveTracer, Tracer, Tracing}, + types::BlockNumber, +}; use hash::keccak; -use crate::machine::Machine; use std::sync::Arc; -use crate::trace::{self, ExecutiveTracer, Tracer, Tracing}; -use crate::types::BlockNumber; use_contract!(block_reward_contract, "res/contracts/block_reward.json"); @@ -195,9 +197,8 @@ pub fn apply_block_rewards( #[cfg(test)] mod test { - use crate::client::PrepareOpenBlock; + use crate::{client::PrepareOpenBlock, spec::Spec}; use ethereum_types::{H160, U256}; - use crate::spec::Spec; use test_helpers::generate_dummy_client_with_spec; use super::{BlockRewardContract, RewardKind}; @@ -237,10 +238,12 @@ mod test { }; // if no beneficiaries are given no rewards are attributed - assert!(block_reward_contract - .reward(&vec![], &mut call) - .unwrap() - .is_empty()); + assert!( + block_reward_contract + .reward(&vec![], &mut call) + .unwrap() + .is_empty() + ); // the contract rewards (1000 + kind) for each benefactor let beneficiaries = vec![ diff --git a/crates/ethcore/src/engines/clique/block_state.rs b/crates/ethcore/src/engines/clique/block_state.rs index 778251fa3..37f88706c 100644 --- a/crates/ethcore/src/engines/clique/block_state.rs +++ b/crates/ethcore/src/engines/clique/block_state.rs @@ -20,18 +20,20 @@ use std::{ time::{Duration, SystemTime, UNIX_EPOCH}, }; -use crate::engines::{ - clique::{ - util::{extract_signers, recover_creator}, - VoteType, DIFF_INTURN, DIFF_NOTURN, NULL_AUTHOR, SIGNING_DELAY_NOTURN_MS, +use crate::{ + engines::{ + EngineError, + clique::{ + DIFF_INTURN, DIFF_NOTURN, NULL_AUTHOR, SIGNING_DELAY_NOTURN_MS, VoteType, + util::{extract_signers, recover_creator}, + }, }, - EngineError, + error::{BlockError, Error}, + types::{BlockNumber, header::Header}, }; -use crate::error::{BlockError, Error}; use ethereum_types::{Address, H64}; use rand::Rng; use time_utils::CheckedSystemTime; -use crate::types::{header::Header, BlockNumber}; use unexpected::Mismatch; /// Type that keeps track of the state for a given vote diff --git a/crates/ethcore/src/engines/clique/mod.rs b/crates/ethcore/src/engines/clique/mod.rs index b4c2a143f..21aaa586c 100644 --- a/crates/ethcore/src/engines/clique/mod.rs +++ b/crates/ethcore/src/engines/clique/mod.rs @@ -66,26 +66,28 @@ use std::{ }; use super::signer::EngineSigner; -use crate::block::ExecutedBlock; -use crate::client::{traits::ForceUpdateSealing, BlockId, EngineClient}; -use crypto::publickey::Signature; -use crate::engines::{ - clique::util::{extract_signers, recover_creator}, - Engine, EngineError, Seal, SealingState, +use crate::{ + block::ExecutedBlock, + client::{BlockId, EngineClient, traits::ForceUpdateSealing}, + engines::{ + Engine, EngineError, Seal, SealingState, + clique::util::{extract_signers, recover_creator}, + }, + error::{BlockError, Error}, + machine::{Call, EthereumMachine}, + types::{ + BlockNumber, + header::{ExtendedHeader, Header}, + }, }; -use crate::error::{BlockError, Error}; -use ethereum_types::{Address, H160, H256, H64, U256}; +use crypto::publickey::Signature; +use ethereum_types::{Address, H64, H160, H256, U256}; use hash::KECCAK_EMPTY_LIST_RLP; use itertools::Itertools; use lru_cache::LruCache; -use crate::machine::{Call, EthereumMachine}; use parking_lot::RwLock; use rand::Rng; use time_utils::CheckedSystemTime; -use crate::types::{ - header::{ExtendedHeader, Header}, - BlockNumber, -}; use unexpected::{Mismatch, OutOfBounds}; use self::{block_state::CliqueBlockState, params::CliqueParams}; @@ -200,19 +202,21 @@ impl Clique { thread::Builder::new() .name("StepService".into()) - .spawn(move || loop { - let next_step_at = Instant::now() + SEALING_FREQ; - trace!(target: "miner", "StepService: triggering sealing"); - if let Some(eng) = weak_eng.upgrade() { - eng.step() - } else { - warn!(target: "shutdown", "StepService: engine is dropped; exiting."); - break; - } + .spawn(move || { + loop { + let next_step_at = Instant::now() + SEALING_FREQ; + trace!(target: "miner", "StepService: triggering sealing"); + if let Some(eng) = weak_eng.upgrade() { + eng.step() + } else { + warn!(target: "shutdown", "StepService: engine is dropped; exiting."); + break; + } - let now = Instant::now(); - if now < next_step_at { - thread::sleep(next_step_at - now); + let now = Instant::now(); + if now < next_step_at { + thread::sleep(next_step_at - now); + } } })?; Ok(engine) @@ -331,7 +335,7 @@ impl Clique { let last_checkpoint_header = match c.block_header(BlockId::Hash(last_checkpoint_hash)) { None => { - return Err(EngineError::CliqueMissingCheckpoint(last_checkpoint_hash))? + return Err(EngineError::CliqueMissingCheckpoint(last_checkpoint_hash))?; } Some(header) => header.decode(self.machine.params().eip1559_transition)?, }; diff --git a/crates/ethcore/src/engines/clique/tests.rs b/crates/ethcore/src/engines/clique/tests.rs index deeb83cea..c8152c9f3 100644 --- a/crates/ethcore/src/engines/clique/tests.rs +++ b/crates/ethcore/src/engines/clique/tests.rs @@ -17,9 +17,8 @@ //! Consensus tests for `PoA Clique Engine`, see http://eips.ethereum.org/EIPS/eip-225 for more information use super::*; -use crate::block::*; +use crate::{block::*, engines::Engine}; use crypto::publickey::{KeyPair, Secret}; -use crate::engines::Engine; use error::{Error, ErrorKind}; use ethereum_types::{Address, H256}; use state_db::StateDB; diff --git a/crates/ethcore/src/engines/clique/util.rs b/crates/ethcore/src/engines/clique/util.rs index 770a3aade..e59093e0e 100644 --- a/crates/ethcore/src/engines/clique/util.rs +++ b/crates/ethcore/src/engines/clique/util.rs @@ -16,17 +16,19 @@ use std::collections::BTreeSet; -use crypto::publickey::{public_to_address, recover as ec_recover, Signature}; -use crate::engines::{ - clique::{ADDRESS_LENGTH, NULL_MIXHASH, NULL_NONCE, SIGNATURE_LENGTH, VANITY_LENGTH}, - EngineError, +use crate::{ + engines::{ + EngineError, + clique::{ADDRESS_LENGTH, NULL_MIXHASH, NULL_NONCE, SIGNATURE_LENGTH, VANITY_LENGTH}, + }, + error::Error, + types::header::Header, }; -use crate::error::Error; +use crypto::publickey::{Signature, public_to_address, recover as ec_recover}; use ethereum_types::{Address, H160, H256}; use lru_cache::LruCache; use parking_lot::RwLock; use rlp::encode; -use crate::types::header::Header; /// How many recovered signature to cache in the memory. pub const CREATOR_CACHE_NUM: usize = 4096; diff --git a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs index 61e2cba4d..7c20d1e2e 100644 --- a/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs @@ -17,8 +17,10 @@ //! Types for declaring block rewards and a client interface for interacting with a //! block reward contract. -use crate::engines::{SystemOrCodeCall, SystemOrCodeCallKind}; -use crate::error::Error; +use crate::{ + engines::{SystemOrCodeCall, SystemOrCodeCallKind}, + error::Error, +}; use ethabi::FunctionOutputDecoder; use ethabi_contract::use_contract; use ethereum_types::Address; diff --git a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs index fe63e6f15..5212dcc96 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/connectivity_tracker_hbbft.rs @@ -1,10 +1,9 @@ -use crate::client::EngineClient; +use crate::{client::EngineClient, types::ids::BlockId}; use ethereum_types::{Address, H256, U256}; use std::str::FromStr; -use crate::types::ids::BlockId; use crate::{ - client::{traits::TransactionRequest, BlockChainClient}, + client::{BlockChainClient, traits::TransactionRequest}, engines::hbbft::utils::bound_contract::{BoundContract, CallError}, }; diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index c1284bfb9..f691ffabc 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -1,26 +1,28 @@ -use crate::client::traits::EngineClient; -use crypto::{self, publickey::Public}; -use crate::engines::{ - hbbft::{ - contracts::validator_set::{get_validator_pubkeys, ValidatorType}, - utils::bound_contract::{BoundContract, CallError}, - NodeId, +use crate::{ + client::traits::EngineClient, + engines::{ + hbbft::{ + NodeId, + contracts::validator_set::{ValidatorType, get_validator_pubkeys}, + utils::bound_contract::{BoundContract, CallError}, + }, + signer::EngineSigner, }, - signer::EngineSigner, + types::ids::BlockId, }; +use crypto::{self, publickey::Public}; use ethereum_types::{Address, H512, U256}; use hbbft::{ + NetworkInfo, crypto::{PublicKeySet, SecretKeyShare}, sync_key_gen::{ Ack, AckOutcome, Error, Part, PartOutcome, PubKeyMap, PublicKey, SecretKey, SyncKeyGen, }, util::max_faulty, - NetworkInfo, }; use itertools::Itertools; use parking_lot::RwLock; use std::{collections::BTreeMap, str::FromStr, sync::Arc}; -use crate::types::ids::BlockId; use_contract!( key_history_contract, @@ -266,8 +268,8 @@ pub fn initialize_synckeygen( #[cfg(test)] mod tests { use super::*; + use crate::engines::signer::{EngineSigner, from_keypair}; use crypto::publickey::{KeyPair, Secret}; - use crate::engines::signer::{from_keypair, EngineSigner}; use std::{collections::BTreeMap, sync::Arc}; #[test] diff --git a/crates/ethcore/src/engines/hbbft/contracts/permission.rs b/crates/ethcore/src/engines/hbbft/contracts/permission.rs index a6b8867d6..9323e64c4 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/permission.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/permission.rs @@ -4,8 +4,8 @@ use std::str::FromStr; use crate::{ client::EngineClient, engines::hbbft::utils::bound_contract::{BoundContract, CallError}, + types::ids::BlockId, }; -use crate::types::ids::BlockId; use_contract!(permission_contract, "res/contracts/permission_hbbft.json"); diff --git a/crates/ethcore/src/engines/hbbft/contracts/staking.rs b/crates/ethcore/src/engines/hbbft/contracts/staking.rs index a7fd2905a..84094ccc5 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/staking.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/staking.rs @@ -1,11 +1,13 @@ -use crate::client::EngineClient; -use crate::engines::hbbft::utils::bound_contract::{BoundContract, CallError}; +use crate::{ + client::EngineClient, + engines::hbbft::utils::bound_contract::{BoundContract, CallError}, + types::ids::BlockId, +}; use ethereum_types::{Address, Public, U256}; use std::{ net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, str::FromStr, }; -use crate::types::ids::BlockId; use_contract!(staking_contract, "res/contracts/staking_contract.json"); @@ -115,8 +117,8 @@ pub fn get_pool_public_key( #[cfg(test)] pub mod tests { use super::*; - use crypto::publickey::{Generator, KeyPair, Public, Random}; use crate::engines::hbbft::test::hbbft_test_client::HbbftTestClient; + use crypto::publickey::{Generator, KeyPair, Public, Random}; pub fn min_staking(client: &dyn EngineClient) -> Result { let c = BoundContract::bind(client, BlockId::Latest, *STAKING_CONTRACT_ADDRESS); diff --git a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs index 60af877bf..ceb97a700 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs @@ -1,12 +1,14 @@ -use crate::client::{ - traits::{EngineClient, TransactionRequest}, - BlockChainClient, +use crate::{ + client::{ + BlockChainClient, + traits::{EngineClient, TransactionRequest}, + }, + engines::hbbft::utils::bound_contract::{BoundContract, CallError}, + types::{ids::BlockId, transaction::Error}, }; use crypto::publickey::Public; -use crate::engines::hbbft::utils::bound_contract::{BoundContract, CallError}; use ethereum_types::{Address, U256}; use std::{collections::BTreeMap, net::SocketAddr, str::FromStr}; -use crate::types::{ids::BlockId, transaction::Error}; use_contract!( validator_set_hbbft, diff --git a/crates/ethcore/src/engines/hbbft/contribution.rs b/crates/ethcore/src/engines/hbbft/contribution.rs index 476f3f109..7863dbe7d 100644 --- a/crates/ethcore/src/engines/hbbft/contribution.rs +++ b/crates/ethcore/src/engines/hbbft/contribution.rs @@ -1,7 +1,7 @@ -use rand::{self, distributions::Standard, Rng}; +use crate::types::transaction::SignedTransaction; +use rand::{self, Rng, distributions::Standard}; use rlp::RlpStream; use std::time::UNIX_EPOCH; -use crate::types::transaction::SignedTransaction; #[derive(Clone, Eq, PartialEq, Debug, Hash, Serialize, Deserialize)] pub(crate) struct Contribution { @@ -56,10 +56,12 @@ impl Contribution { #[cfg(test)] mod tests { + use crate::{ + engines::hbbft::test::create_transactions::create_transaction, + types::transaction::{SignedTransaction, TypedTransaction}, + }; use crypto::publickey::{Generator, Random}; - use crate::engines::hbbft::test::create_transactions::create_transaction; use ethereum_types::U256; - use crate::types::transaction::{SignedTransaction, TypedTransaction}; #[test] fn test_contribution_serialization() { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs index dba6e142a..b6f6a9bf7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/keygen_history_helpers.rs @@ -2,7 +2,7 @@ use crate::Enode; use ethereum_types::H128; use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::sync_key_gen::{AckOutcome, Part, PartOutcome, PublicKey, SecretKey, SyncKeyGen}; -use parity_crypto::publickey::{public_to_address, Address, Public, Secret}; +use parity_crypto::publickey::{Address, Public, Secret, public_to_address}; use serde::{Deserialize, Serialize}; use serde_with::serde_as; use std::{collections::BTreeMap, sync::Arc}; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 4bcb53c21..bc41871d9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -22,7 +22,7 @@ use ethstore::{KeyFile, SafeAccount}; use keygen_history_helpers::{enodes_to_pub_keys, generate_keygens, key_sync_history_data}; use parity_crypto::publickey::{Address, Generator, KeyPair, Public, Random, Secret}; use std::{convert::TryInto, fmt::Write, fs, num::NonZeroU32, str::FromStr}; -use toml::{map::Map, Value}; +use toml::{Value, map::Map}; pub fn create_account() -> (Secret, Public, Address) { let acc = Random.generate(); @@ -494,7 +494,10 @@ fn main() { "max_nodes must be greater than nodes" ); - println!("generating config files for {} nodes in total, with the first {} nodes as initial validator", num_nodes_total, num_nodes_validators); + println!( + "generating config files for {} nodes in total, with the first {} nodes as initial validator", + num_nodes_total, num_nodes_validators + ); let config_type = value_t!(matches.value_of("configtype"), ConfigType).unwrap_or(ConfigType::PosdaoSetup); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs index 105ea58a6..224cc1ac2 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs @@ -1,6 +1,6 @@ +use crate::types::ids::BlockId; use ethereum_types::Address; use stats::PrometheusMetrics; -use crate::types::ids::BlockId; use crate::{ client::{BlockChainClient, EngineClient}, @@ -13,9 +13,9 @@ use std::{ }; use super::{ + NodeId, contracts::connectivity_tracker_hbbft::{is_connectivity_loss_reported, report_reconnect}, hbbft_message_memorium::HbbftMessageMemorium, - NodeId, }; pub(crate) struct HbbftEarlyEpochEndManager { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 6cd185fab..2583d166d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -3,26 +3,34 @@ use super::{ hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_engine_cache::HbbftEngineCache, }; use crate::{ - client::BlockChainClient, - engines::hbbft::{ - contracts::random_hbbft::set_current_seed_tx_raw, hbbft_message_memorium::BadSealReason, - hbbft_peers_management::HbbftPeersManagement, + block::ExecutedBlock, + client::{ + BlockChainClient, + traits::{EngineClient, ForceUpdateSealing}, + }, + engines::{ + Engine, EngineError, ForkChoice, Seal, SealingState, default_system_or_code_call, + hbbft::{ + contracts::random_hbbft::set_current_seed_tx_raw, + hbbft_message_memorium::BadSealReason, hbbft_peers_management::HbbftPeersManagement, + }, + signer::EngineSigner, + }, + error::{BlockError, Error}, + io::{IoContext, IoHandler, IoService, TimerToken}, + machine::EthereumMachine, + types::{ + BlockNumber, + header::{ExtendedHeader, Header}, + ids::BlockId, + transaction::{SignedTransaction, TypedTransaction}, }, }; -use crate::block::ExecutedBlock; -use crate::client::traits::{EngineClient, ForceUpdateSealing}; use crypto::publickey::Signature; -use crate::engines::{ - default_system_or_code_call, signer::EngineSigner, Engine, EngineError, ForkChoice, Seal, - SealingState, -}; -use crate::error::{BlockError, Error}; -use ethereum_types::{Address, Public, H256, H512, U256}; +use ethereum_types::{Address, H256, H512, Public, U256}; use ethjson::spec::HbbftParams; use hbbft::{NetworkInfo, Target}; -use crate::io::{IoContext, IoHandler, IoService, TimerToken}; use itertools::Itertools; -use crate::machine::EthereumMachine; use parking_lot::{Mutex, RwLock}; use rlp; use rmp_serde; @@ -33,27 +41,21 @@ use std::{ collections::BTreeMap, convert::TryFrom, ops::BitXor, - sync::{atomic::AtomicBool, Arc, Weak}, + sync::{Arc, Weak, atomic::AtomicBool}, time::{Duration, Instant}, }; -use crate::types::{ - header::{ExtendedHeader, Header}, - ids::BlockId, - transaction::{SignedTransaction, TypedTransaction}, - BlockNumber, -}; use super::{ + NodeId, contracts::{ keygen_history::{all_parts_acks_available, initialize_synckeygen}, staking::start_time_of_next_phase_transition, - validator_set::{get_pending_validators, is_pending_validator, ValidatorType}, + validator_set::{ValidatorType, get_pending_validators, is_pending_validator}, }, contribution::{unix_now_millis, unix_now_secs}, hbbft_state::{Batch, HbMessage, HbbftState, HoneyBadgerStep}, keygen_transactions::KeygenTransactionSender, sealing::{self, RlpSig, Sealing}, - NodeId, }; use crate::engines::hbbft::{ contracts::validator_set::{ @@ -227,7 +229,10 @@ impl TransitionHandler { } // lock the client and signal shutdown. - warn!("shutdown-on-missing-block-import: Detected stalled block import. no import for {duration_since_last_block_import}. last known import: {:?} now: {:?} Demanding shut down of hbbft engine.", last_known_block_import, now); + warn!( + "shutdown-on-missing-block-import: Detected stalled block import. no import for {duration_since_last_block_import}. last known import: {:?} now: {:?} Demanding shut down of hbbft engine.", + last_known_block_import, now + ); // if auto shutdown at missing block production (or import) is configured. // ... we need to check if enough time has passed since the last block was imported. @@ -235,7 +240,9 @@ impl TransitionHandler { if let Some(c) = weak.upgrade() { c.demand_shutdown(); } else { - error!("shutdown-on-missing-block-import: Error during Shutdown: could not upgrade weak reference."); + error!( + "shutdown-on-missing-block-import: Error during Shutdown: could not upgrade weak reference." + ); } } else { error!( @@ -1101,7 +1108,10 @@ impl HoneyBadgerBFT { } Err(call_error) => { error!(target: "engine", "unable to ask for corresponding staking address for given mining address: {:?}", call_error); - let message = format!("unable to ask for corresponding staking address for given mining address: {:?}", call_error); + let message = format!( + "unable to ask for corresponding staking address for given mining address: {:?}", + call_error + ); return Err(message.into()); } }; @@ -1711,15 +1721,15 @@ impl Engine for HoneyBadgerBFT { #[cfg(test)] mod tests { use super::super::{contribution::Contribution, test::create_transactions::create_transaction}; + use crate::types::transaction::SignedTransaction; use crypto::publickey::{Generator, Random}; use ethereum_types::U256; use hbbft::{ - honey_badger::{HoneyBadger, HoneyBadgerBuilder}, NetworkInfo, + honey_badger::{HoneyBadger, HoneyBadgerBuilder}, }; use rand; use std::sync::Arc; - use crate::types::transaction::SignedTransaction; #[test] fn test_single_contribution() { diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs index 7a5185f53..c8e2bf1f0 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine_cache.rs @@ -1,5 +1,4 @@ -use crate::client::EngineClient; -use crate::error::Error; +use crate::{client::EngineClient, error::Error}; use ethereum_types::Address; use parking_lot::Mutex; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index c53f39f15..de476a556 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -12,13 +12,13 @@ use std::{ }; // use threshold_crypto::{SignatureShare}; -use crate::engines::hbbft::{sealing, NodeId}; +use crate::engines::hbbft::{NodeId, sealing}; // use hbbft::honey_badger::Message; // use serde::{Deserialize, Serialize}; // use serde_json::{json, Result, Value}; use std::{ - fs::{self, create_dir_all, File}, + fs::{self, File, create_dir_all}, io::Write, path::PathBuf, }; @@ -199,9 +199,9 @@ impl NodeStakingEpochHistory { if block_num > last_message_faulty { self.last_message_faulty = block_num; } // else { - // this log entry is trigering often, probably there are more than 1 good messages able per block.// this log entry is trigering often, probably there are more than 1 good messages able per block. - // warn!(target: "hbbft_message_memorium", "add_message_event_faulty: event.block_num {block_num} <= last_message_faulty {last_message_faulty}"); - // } + // this log entry is trigering often, probably there are more than 1 good messages able per block.// this log entry is trigering often, probably there are more than 1 good messages able per block. + // warn!(target: "hbbft_message_memorium", "add_message_event_faulty: event.block_num {block_num} <= last_message_faulty {last_message_faulty}"); + // } self.num_faulty_messages += 1; } @@ -213,9 +213,9 @@ impl NodeStakingEpochHistory { if block_num > last_message_good { self.last_message_good = block_num; } // else { - // this log entry is trigering often, probably there are more than 1 good messages able per block. - // warn!(target: "hbbft_message_memorium", "add_message_event_good: ! event.block_num {block_num} > last_message_good {last_message_good}"); - // } + // this log entry is trigering often, probably there are more than 1 good messages able per block. + // warn!(target: "hbbft_message_memorium", "add_message_event_good: ! event.block_num {block_num} > last_message_good {last_message_good}"); + // } self.num_good_messages += 1; self.last_message_good_time = Instant::now(); } @@ -293,7 +293,9 @@ impl NodeStakingEpochHistory { // faulty messages let last_message_faulty = self.last_message_faulty; - return format!("{staking_epoch},{node_id},{total_sealing_messages},{total_good_sealing_messages},{total_late_sealing_messages},{total_error_sealing_messages},{last_good_sealing_message},{last_late_sealing_message},{last_error_sealing_message},{cumulative_lateness},{total_good_messages},{total_faulty_messages},{last_message_good},{last_message_faulty}\n"); + return format!( + "{staking_epoch},{node_id},{total_sealing_messages},{total_good_sealing_messages},{total_late_sealing_messages},{total_error_sealing_messages},{last_good_sealing_message},{last_late_sealing_message},{last_error_sealing_message},{cumulative_lateness},{total_good_messages},{total_faulty_messages},{last_message_good},{last_message_faulty}\n" + ); } // prometheus metrics @@ -638,13 +640,15 @@ impl HbbftMessageDispatcher { let builder = std::thread::Builder::new().name("MessageMemorial".to_string()); - match builder.spawn(move || loop { - // one loop cycle is very fast. - // so report_ function have their chance to aquire a write lock soon. - // and don't block the work thread for too long. - let work_result = arc_clone.write().work_message(); - if !work_result { - std::thread::sleep(std::time::Duration::from_millis(5000)); + match builder.spawn(move || { + loop { + // one loop cycle is very fast. + // so report_ function have their chance to aquire a write lock soon. + // and don't block the work thread for too long. + let work_result = arc_clone.write().work_message(); + if !work_result { + std::thread::sleep(std::time::Duration::from_millis(5000)); + } } }) { Ok(thread) => { @@ -1290,7 +1294,7 @@ impl PrometheusMetrics for HbbftMessageMemorium { #[cfg(test)] mod tests { - use crate::engines::hbbft::{hbbft_message_memorium::BadSealReason, NodeId}; + use crate::engines::hbbft::{NodeId, hbbft_message_memorium::BadSealReason}; use super::{HbbftMessageMemorium, MessageEventGood, SealEventBad}; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index d1f5912cf..c66ab214d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -6,15 +6,15 @@ use std::{ use ethereum_types::H512; use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::{ + NetworkInfo, sync_key_gen::{Ack, AckOutcome, Part, PartOutcome, SyncKeyGen}, util::max_faulty, - NetworkInfo, }; use parking_lot::RwLock; use crate::engines::{ - hbbft::contracts::keygen_history::{KeyPairWrapper, PublicWrapper}, EngineSigner, + hbbft::contracts::keygen_history::{KeyPairWrapper, PublicWrapper}, }; use super::NodeId; @@ -328,14 +328,18 @@ mod tests { let own_id = NodeId::default(); fork_manager.initialize(own_id, 8, vec![test_fork]); - assert!(fork_manager - .should_fork(9, 1, signer_lock.clone()) - .is_none()); + assert!( + fork_manager + .should_fork(9, 1, signer_lock.clone()) + .is_none() + ); let fork = fork_manager.should_fork(10, 1, signer_lock.clone()); assert!(fork.is_some()); assert!(fork.unwrap().num_nodes() == 2); - assert!(fork_manager - .should_fork(11, 1, signer_lock.clone()) - .is_none()); + assert!( + fork_manager + .should_fork(11, 1, signer_lock.clone()) + .is_none() + ); } } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 1c3882469..4c134fcde 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -9,7 +9,7 @@ use crate::{ ethereum::public_key_to_address::public_key_to_address, }; -use super::{contracts::staking::get_pool_public_key, NodeId}; +use super::{NodeId, contracts::staking::get_pool_public_key}; use bytes::ToPretty; use ethereum_types::Address; @@ -209,7 +209,10 @@ impl HbbftPeersManagement { } if validators_to_remove.len() > 0 { - info!("removing {} reserved peers, because they are neither a pending validator nor a current validator.", validators_to_remove.len()); + info!( + "removing {} reserved peers, because they are neither a pending validator nor a current validator.", + validators_to_remove.len() + ); let mut peers_management_guard = block_chain_client.reserved_peers_management().lock(); diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 35a8ef7c1..60a6bf028 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -1,12 +1,15 @@ -use crate::client::traits::EngineClient; -use crate::engines::signer::EngineSigner; +use crate::{ + client::traits::EngineClient, + engines::signer::EngineSigner, + types::{header::Header, ids::BlockId}, +}; use ethcore_miner::pool::{PoolVerifiedTransaction, ScoredTransaction}; use ethereum_types::U256; use ethjson::spec::hbbft::HbbftNetworkFork; use hbbft::{ + Epoched, NetworkInfo, crypto::{PublicKey, Signature}, honey_badger::{self, HoneyBadgerBuilder}, - Epoched, NetworkInfo, }; use parking_lot::{Mutex, RwLock}; use rand::seq::IteratorRandom; @@ -15,11 +18,11 @@ use std::{ sync::Arc, time::Duration, }; -use crate::types::{header::Header, ids::BlockId}; use crate::engines::hbbft::contracts::permission::get_minimum_gas_from_permission_contract; use super::{ + NodeId, contracts::{ keygen_history::{initialize_synckeygen, synckeygen_to_network_info}, staking::{get_posdao_epoch, get_posdao_epoch_start}, @@ -29,7 +32,6 @@ use super::{ hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_network_fork_manager::HbbftNetworkForkManager, hbbft_peers_management::HbbftPeersManagement, - NodeId, }; pub type HbMessage = honey_badger::Message; diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 169559f22..68740aca4 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -1,26 +1,29 @@ -use crate::client::traits::{EngineClient, TransactionRequest}; -use crate::engines::{ - hbbft::{ - contracts::{ - keygen_history::{ - engine_signer_to_synckeygen, get_current_key_gen_round, has_acks_of_address_data, - key_history_contract, part_of_address, PublicWrapper, KEYGEN_HISTORY_ADDRESS, - }, - staking::get_posdao_epoch, - validator_set::{ - get_pending_validator_key_generation_mode, get_validator_pubkeys, KeyGenMode, - ValidatorType, +use crate::{ + client::traits::{EngineClient, TransactionRequest}, + engines::{ + hbbft::{ + contracts::{ + keygen_history::{ + KEYGEN_HISTORY_ADDRESS, PublicWrapper, engine_signer_to_synckeygen, + get_current_key_gen_round, has_acks_of_address_data, key_history_contract, + part_of_address, + }, + staking::get_posdao_epoch, + validator_set::{ + KeyGenMode, ValidatorType, get_pending_validator_key_generation_mode, + get_validator_pubkeys, + }, }, + utils::bound_contract::CallError, }, - utils::bound_contract::CallError, + signer::EngineSigner, }, - signer::EngineSigner, + types::ids::BlockId, }; use ethereum_types::{Address, U256}; use itertools::Itertools; use parking_lot::RwLock; use std::{collections::BTreeMap, sync::Arc}; -use crate::types::ids::BlockId; use crate::client::BlockChainClient; @@ -180,7 +183,7 @@ impl KeygenTransactionSender { .map_err(|e| KeyGenError::CallError(e))? { ShouldSendKeyAnswer::NoNotThisKeyGenMode => { - return Err(KeyGenError::Unexpected) + return Err(KeyGenError::Unexpected); } ShouldSendKeyAnswer::NoWaiting => return Err(KeyGenError::Unexpected), ShouldSendKeyAnswer::Yes => { diff --git a/crates/ethcore/src/engines/hbbft/sealing.rs b/crates/ethcore/src/engines/hbbft/sealing.rs index 4eb78fc67..9a5ac0e36 100644 --- a/crates/ethcore/src/engines/hbbft/sealing.rs +++ b/crates/ethcore/src/engines/hbbft/sealing.rs @@ -1,5 +1,5 @@ use super::NodeId; -use hbbft::{crypto::Signature, threshold_sign::ThresholdSign, NetworkInfo}; +use hbbft::{NetworkInfo, crypto::Signature, threshold_sign::ThresholdSign}; use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream}; use std::{result, sync::Arc}; diff --git a/crates/ethcore/src/engines/hbbft/test/create_transactions.rs b/crates/ethcore/src/engines/hbbft/test/create_transactions.rs index 8a95b98e8..ca23fe882 100644 --- a/crates/ethcore/src/engines/hbbft/test/create_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/test/create_transactions.rs @@ -1,6 +1,6 @@ +use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; use crypto::publickey::KeyPair; use ethereum_types::{Address, U256}; -use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; pub fn create_transaction(keypair: &KeyPair, nonce: &U256) -> SignedTransaction { TypedTransaction::Legacy(Transaction { diff --git a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs index 1bc86f859..47bf4c67d 100644 --- a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs +++ b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs @@ -1,17 +1,19 @@ use super::create_transactions::{create_call, create_transaction, create_transfer}; -use crate::client::{ - traits::{Balance, StateOrBlock}, - BlockChainClient, ChainSyncing, Client, ImportExportBlocks, +use crate::{ + client::{ + BlockChainClient, ChainSyncing, Client, ImportExportBlocks, + traits::{Balance, StateOrBlock}, + }, + engines::signer::from_keypair, + spec::Spec, + types::{data_format::DataFormat, ids::BlockId}, }; use crypto::publickey::{Generator, KeyPair, Random}; -use crate::engines::signer::from_keypair; use ethereum_types::{Address, U256}; use miner::{Miner, MinerService}; use parking_lot::RwLock; -use crate::spec::Spec; use std::{ops::Deref, sync::Arc}; -use test_helpers::{generate_dummy_client_with_spec, TestNotify}; -use crate::types::{data_format::DataFormat, ids::BlockId}; +use test_helpers::{TestNotify, generate_dummy_client_with_spec}; pub fn hbbft_spec() -> Spec { Spec::load( diff --git a/crates/ethcore/src/engines/hbbft/test/mod.rs b/crates/ethcore/src/engines/hbbft/test/mod.rs index dcbbb1405..7a01ecd4e 100644 --- a/crates/ethcore/src/engines/hbbft/test/mod.rs +++ b/crates/ethcore/src/engines/hbbft/test/mod.rs @@ -7,13 +7,12 @@ use super::{ validator_set::{is_pending_validator, mining_by_staking_address}, }, contribution::unix_now_secs, - test::hbbft_test_client::{create_hbbft_client, create_hbbft_clients, HbbftTestClient}, + test::hbbft_test_client::{HbbftTestClient, create_hbbft_client, create_hbbft_clients}, }; -use crate::client::traits::BlockInfo; +use crate::{client::traits::BlockInfo, types::ids::BlockId}; use crypto::publickey::{Generator, KeyPair, Random, Secret}; use ethereum_types::{Address, U256}; use std::str::FromStr; -use crate::types::ids::BlockId; pub mod create_transactions; pub mod hbbft_test_client; @@ -135,8 +134,10 @@ fn test_epoch_transition() { assert!(genesis_transition_time.as_u64() < unix_now_secs()); // We should not be in the pending validator set at the genesis block. - assert!(!is_pending_validator(moc.client.as_ref(), &moc.address()) - .expect("is_pending_validator call must succeed")); + assert!( + !is_pending_validator(moc.client.as_ref(), &moc.address()) + .expect("is_pending_validator call must succeed") + ); // Fund the transactor. // Also triggers the creation of a block. @@ -149,8 +150,10 @@ fn test_epoch_transition() { assert_eq!(moc.client.chain().best_block_number(), 1); // Now we should be part of the pending validator set. - assert!(is_pending_validator(moc.client.as_ref(), &moc.address()) - .expect("Constant call must succeed")); + assert!( + is_pending_validator(moc.client.as_ref(), &moc.address()) + .expect("Constant call must succeed") + ); // Check if we are still in the first epoch. assert_eq!( diff --git a/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs b/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs index c301d623d..a0f4bc392 100644 --- a/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs +++ b/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs @@ -6,10 +6,9 @@ use std::fmt; -use crate::client::EngineClient; +use crate::{client::EngineClient, types::ids::BlockId}; use ethabi; use ethereum_types::Address; -use crate::types::ids::BlockId; /// A contract bound to a client and block number. /// diff --git a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs index 291fc3658..b1e04ed5e 100644 --- a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs +++ b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs @@ -1,9 +1,9 @@ // Warning: Part of the Consensus protocol, changes need to produce *exactly* the same result or // block verification will fail. Intentional breaking changes constitute a fork. +use crate::types::transaction::SignedTransaction; use ethereum_types::{Address, U256}; use std::collections::HashMap; -use crate::types::transaction::SignedTransaction; /// Combining an address with a random U256 seed using XOR, using big-endian byte ordering always. fn address_xor_u256(address: &Address, seed: U256) -> Address { diff --git a/crates/ethcore/src/engines/instant_seal.rs b/crates/ethcore/src/engines/instant_seal.rs index eaeffd1e0..efd38cfc7 100644 --- a/crates/ethcore/src/engines/instant_seal.rs +++ b/crates/ethcore/src/engines/instant_seal.rs @@ -14,11 +14,13 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::block::ExecutedBlock; -use crate::engines::{Engine, Seal, SealingState}; -use crate::machine::Machine; +use crate::{ + block::ExecutedBlock, + engines::{Engine, Seal, SealingState}, + machine::Machine, + types::header::{ExtendedHeader, Header}, +}; use std::sync::atomic::{AtomicU64, Ordering}; -use crate::types::header::{ExtendedHeader, Header}; /// `InstantSeal` params. #[derive(Default, Debug, PartialEq)] @@ -126,13 +128,10 @@ impl Engine for InstantSeal { #[cfg(test)] mod tests { - use crate::block::*; - use crate::engines::Seal; + use crate::{block::*, engines::Seal, spec::Spec, types::header::Header}; use ethereum_types::{Address, H520}; - use crate::spec::Spec; use std::sync::Arc; use test_helpers::get_temp_state_db; - use crate::types::header::Header; #[test] fn instant_can_seal() { diff --git a/crates/ethcore/src/engines/mod.rs b/crates/ethcore/src/engines/mod.rs index 7f2a9bbc1..994a830b2 100644 --- a/crates/ethcore/src/engines/mod.rs +++ b/crates/ethcore/src/engines/mod.rs @@ -39,8 +39,8 @@ pub use self::{ // TODO [ToDr] Remove re-export (#10130) pub use crate::types::engines::{ - epoch::{self, Transition as EpochTransition}, ForkChoice, + epoch::{self, Transition as EpochTransition}, }; use std::{ @@ -49,23 +49,27 @@ use std::{ sync::{Arc, Weak}, }; -use builtin::Builtin; -use crate::error::Error; -use crate::snapshot::SnapshotComponents; -use crate::spec::CommonParams; -use crate::types::{ - header::{ExtendedHeader, Header}, - transaction::{self, SignedTransaction, UnverifiedTransaction}, - BlockNumber, +use crate::{ + error::Error, + snapshot::SnapshotComponents, + spec::CommonParams, + types::{ + BlockNumber, + header::{ExtendedHeader, Header}, + transaction::{self, SignedTransaction, UnverifiedTransaction}, + }, }; +use builtin::Builtin; use vm::{ActionValue, CallType, CreateContractAddress, EnvInfo, Schedule}; -use crate::block::ExecutedBlock; +use crate::{ + block::ExecutedBlock, + machine::{self, AuxiliaryData, AuxiliaryRequest, Machine}, + types::ancestry_action::AncestryAction, +}; use bytes::Bytes; use crypto::publickey::Signature; -use ethereum_types::{Address, H256, H512, H64, U256}; -use crate::machine::{self, AuxiliaryData, AuxiliaryRequest, Machine}; -use crate::types::ancestry_action::AncestryAction; +use ethereum_types::{Address, H64, H256, H512, U256}; use unexpected::{Mismatch, OutOfBounds}; /// Default EIP-210 contract code. diff --git a/crates/ethcore/src/engines/null_engine.rs b/crates/ethcore/src/engines/null_engine.rs index 124535d08..02947241b 100644 --- a/crates/ethcore/src/engines/null_engine.rs +++ b/crates/ethcore/src/engines/null_engine.rs @@ -14,18 +14,20 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::block::ExecutedBlock; -use crate::engines::{ - block_reward::{self, RewardKind}, - Engine, +use crate::{ + block::ExecutedBlock, + engines::{ + Engine, + block_reward::{self, RewardKind}, + }, + machine::Machine, + types::{ + BlockNumber, + ancestry_action::AncestryAction, + header::{ExtendedHeader, Header}, + }, }; use ethereum_types::U256; -use crate::machine::Machine; -use crate::types::{ - ancestry_action::AncestryAction, - header::{ExtendedHeader, Header}, - BlockNumber, -}; /// Params for a null engine. #[derive(Clone, Default)] diff --git a/crates/ethcore/src/engines/signer.rs b/crates/ethcore/src/engines/signer.rs index c31eff3a7..2785d499c 100644 --- a/crates/ethcore/src/engines/signer.rs +++ b/crates/ethcore/src/engines/signer.rs @@ -16,7 +16,7 @@ //! A signer used by Engines which need to sign messages. -use crypto::publickey::{self, ecies, Error, Public, Signature}; +use crypto::publickey::{self, Error, Public, Signature, ecies}; use ethereum_types::{Address, H256}; //TODO dr diff --git a/crates/ethcore/src/engines/validator_set/contract.rs b/crates/ethcore/src/engines/validator_set/contract.rs index 28a76454d..c54cce570 100644 --- a/crates/ethcore/src/engines/validator_set/contract.rs +++ b/crates/ethcore/src/engines/validator_set/contract.rs @@ -18,17 +18,19 @@ /// It can also report validators for misbehaviour with two levels: `reportMalicious` and `reportBenign`. use std::sync::Weak; +use crate::{ + machine::{AuxiliaryData, Call, EthereumMachine}, + types::{BlockNumber, header::Header, ids::BlockId, transaction}, +}; use bytes::Bytes; use ethereum_types::{Address, H256, U256}; -use crate::machine::{AuxiliaryData, Call, EthereumMachine}; use parking_lot::RwLock; -use crate::types::{header::Header, ids::BlockId, transaction, BlockNumber}; -use crate::client::{traits::TransactionRequest, EngineClient}; +use crate::client::{EngineClient, traits::TransactionRequest}; use crate::error::Error as EthcoreError; -use super::{safe_contract::ValidatorSafeContract, SimpleList, SystemCall, ValidatorSet}; +use super::{SimpleList, SystemCall, ValidatorSet, safe_contract::ValidatorSafeContract}; use_contract!(validator_report, "res/contracts/validator_report.json"); @@ -216,20 +218,22 @@ impl ValidatorSet for ValidatorContract { #[cfg(test)] mod tests { use super::{super::ValidatorSet, ValidatorContract}; + use crate::{ + client::{BlockChainClient, BlockInfo, ChainInfo, traits::TransactionRequest}, + spec::Spec, + types::{header::Header, ids::BlockId}, + }; use accounts::AccountProvider; use bytes::ToPretty; use call_contract::CallContract; - use crate::client::{traits::TransactionRequest, BlockChainClient, BlockInfo, ChainInfo}; use ethabi::FunctionOutputDecoder; use ethereum_types::{Address, H520}; use hash::keccak; use miner::{self, MinerService}; use rlp::encode; use rustc_hex::FromHex; - use crate::spec::Spec; use std::sync::Arc; use test_helpers::generate_dummy_client_with_spec; - use crate::types::{header::Header, ids::BlockId}; #[test] fn fetches_validators() { @@ -238,18 +242,22 @@ mod tests { let vc = Arc::new(ValidatorContract::new(addr, None)); vc.register_client(Arc::downgrade(&client) as _); let last_hash = client.best_block_header().hash(); - assert!(vc.contains( - &last_hash, - &"7d577a597b2742b498cb5cf0c26cdcd726d39e6e" - .parse::
() - .unwrap() - )); - assert!(vc.contains( - &last_hash, - &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1" - .parse::
() - .unwrap() - )); + assert!( + vc.contains( + &last_hash, + &"7d577a597b2742b498cb5cf0c26cdcd726d39e6e" + .parse::
() + .unwrap() + ) + ); + assert!( + vc.contains( + &last_hash, + &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1" + .parse::
() + .unwrap() + ) + ); } #[test] @@ -310,10 +318,12 @@ mod tests { ); // Simulate a misbehaving validator by handling a double proposal. let header = client.best_block_header(); - assert!(client - .engine() - .verify_block_family(&header, &header) - .is_err()); + assert!( + client + .engine() + .verify_block_family(&header, &header) + .is_err() + ); // Seal a block. client.engine().step(); client.engine().step(); diff --git a/crates/ethcore/src/engines/validator_set/mod.rs b/crates/ethcore/src/engines/validator_set/mod.rs index 9dcd5673c..2a952fb2b 100644 --- a/crates/ethcore/src/engines/validator_set/mod.rs +++ b/crates/ethcore/src/engines/validator_set/mod.rs @@ -25,11 +25,13 @@ mod test; use std::sync::Weak; +use crate::{ + machine::{AuxiliaryData, Call, EthereumMachine}, + types::{BlockNumber, header::Header, ids::BlockId}, +}; use bytes::Bytes; use ethereum_types::{Address, H256}; use ethjson::spec::ValidatorSet as ValidatorSpec; -use crate::machine::{AuxiliaryData, Call, EthereumMachine}; -use crate::types::{header::Header, ids::BlockId, BlockNumber}; use crate::client::EngineClient; diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index 4b402cdb9..8aaadb25f 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -18,15 +18,17 @@ use std::collections::BTreeMap; use std::sync::Weak; +use crate::types::{BlockNumber, header::Header, ids::BlockId}; use bytes::Bytes; use ethereum_types::{Address, H256}; use parking_lot::RwLock; -use crate::types::{header::Header, ids::BlockId, BlockNumber}; use super::{SystemCall, ValidatorSet}; -use crate::client::EngineClient; -use crate::error::Error as EthcoreError; -use crate::machine::{AuxiliaryData, Call, EthereumMachine}; +use crate::{ + client::EngineClient, + error::Error as EthcoreError, + machine::{AuxiliaryData, Call, EthereumMachine}, +}; type BlockNumberLookup = Box Result + Send + Sync + 'static>; @@ -206,21 +208,23 @@ impl ValidatorSet for Multi { #[cfg(test)] mod tests { - use accounts::AccountProvider; - use crate::client::{ - traits::{ForceUpdateSealing, TransactionRequest}, - BlockChainClient, BlockInfo, ChainInfo, ImportBlock, + use crate::{ + client::{ + BlockChainClient, BlockInfo, ChainInfo, ImportBlock, + traits::{ForceUpdateSealing, TransactionRequest}, + }, + engines::{EpochChange, validator_set::ValidatorSet}, + spec::Spec, + types::{header::Header, ids::BlockId}, + verification::queue::kind::blocks::Unverified, }; + use accounts::AccountProvider; use crypto::publickey::Secret; - use crate::engines::{validator_set::ValidatorSet, EpochChange}; use ethereum_types::Address; use hash::keccak; use miner::{self, MinerService}; - use crate::spec::Spec; use std::{collections::BTreeMap, sync::Arc}; use test_helpers::generate_dummy_client_with_spec; - use crate::types::{header::Header, ids::BlockId}; - use crate::verification::queue::kind::blocks::Unverified; use super::Multi; diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index b390c0e26..3a5badafc 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -20,8 +20,14 @@ use std::{ sync::{Arc, Weak}, }; +use crate::{ + error::{Error as EthcoreError, ErrorKind as EthcoreErrorKind}, + types::{ + BlockNumber, header::Header, ids::BlockId, log_entry::LogEntry, receipt::TypedReceipt, + transaction, + }, +}; use bytes::Bytes; -use crate::error::{Error as EthcoreError, ErrorKind as EthcoreErrorKind}; use ethabi::FunctionOutputDecoder; use ethereum_types::{Address, Bloom, H256, U256}; use hash::keccak; @@ -29,15 +35,13 @@ use kvdb::DBValue; use memory_cache::MemoryLruCache; use parking_lot::{Mutex, RwLock}; use rlp::{Rlp, RlpStream}; -use crate::types::{ - header::Header, ids::BlockId, log_entry::LogEntry, receipt::TypedReceipt, transaction, - BlockNumber, -}; use unexpected::Mismatch; -use super::{simple_list::SimpleList, SystemCall, ValidatorSet}; -use crate::client::{traits::TransactionRequest, BlockChainClient, EngineClient}; -use crate::machine::{AuxiliaryData, AuxiliaryRequest, Call, EthereumMachine}; +use super::{SystemCall, ValidatorSet, simple_list::SimpleList}; +use crate::{ + client::{BlockChainClient, EngineClient, traits::TransactionRequest}, + machine::{AuxiliaryData, AuxiliaryRequest, Call, EthereumMachine}, +}; use_contract!(validator_set, "res/contracts/validator_set.json"); @@ -525,7 +529,9 @@ impl ValidatorSet for ValidatorSafeContract { contract_address: self.contract_address, header: header.clone(), }); - return crate::engines::EpochChange::Yes(crate::engines::Proof::WithState(state_proof as Arc<_>)); + return crate::engines::EpochChange::Yes(crate::engines::Proof::WithState( + state_proof as Arc<_>, + )); } // otherwise, we're checking for logs. @@ -713,25 +719,27 @@ impl ReportQueue { #[cfg(test)] mod tests { - use super::{super::ValidatorSet, ValidatorSafeContract, EVENT_NAME_HASH}; - use accounts::AccountProvider; - use crate::client::{ - traits::{EngineClient, ForceUpdateSealing}, - BlockInfo, ChainInfo, ImportBlock, + use super::{super::ValidatorSet, EVENT_NAME_HASH, ValidatorSafeContract}; + use crate::{ + client::{ + BlockInfo, ChainInfo, ImportBlock, + traits::{EngineClient, ForceUpdateSealing}, + }, + spec::Spec, + types::{ + ids::BlockId, + transaction::{Action, Transaction, TypedTransaction}, + }, + verification::queue::kind::blocks::Unverified, }; + use accounts::AccountProvider; use crypto::publickey::Secret; use ethereum_types::Address; use hash::keccak; use miner::{self, MinerService}; use rustc_hex::FromHex; - use crate::spec::Spec; use std::sync::Arc; use test_helpers::generate_dummy_client_with_spec; - use crate::types::{ - ids::BlockId, - transaction::{Action, Transaction, TypedTransaction}, - }; - use crate::verification::queue::kind::blocks::Unverified; #[test] fn fetches_validators() { @@ -740,18 +748,22 @@ mod tests { let vc = Arc::new(ValidatorSafeContract::new(addr, None)); vc.register_client(Arc::downgrade(&client) as _); let last_hash = client.best_block_header().hash(); - assert!(vc.contains( - &last_hash, - &"7d577a597b2742b498cb5cf0c26cdcd726d39e6e" - .parse::
() - .unwrap() - )); - assert!(vc.contains( - &last_hash, - &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1" - .parse::
() - .unwrap() - )); + assert!( + vc.contains( + &last_hash, + &"7d577a597b2742b498cb5cf0c26cdcd726d39e6e" + .parse::
() + .unwrap() + ) + ); + assert!( + vc.contains( + &last_hash, + &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1" + .parse::
() + .unwrap() + ) + ); } #[test] @@ -856,9 +868,11 @@ mod tests { #[test] fn detects_bloom() { - use crate::engines::EpochChange; - use crate::machine::AuxiliaryRequest; - use crate::types::{header::Header, log_entry::LogEntry}; + use crate::{ + engines::EpochChange, + machine::AuxiliaryRequest, + types::{header::Header, log_entry::LogEntry}, + }; let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); let engine = client.engine(); @@ -896,8 +910,10 @@ mod tests { #[test] fn initial_contract_is_signal() { - use crate::engines::{EpochChange, Proof}; - use crate::types::header::Header; + use crate::{ + engines::{EpochChange, Proof}, + types::header::Header, + }; let client = generate_dummy_client_with_spec(Spec::new_validator_safe_contract); let engine = client.engine(); diff --git a/crates/ethcore/src/engines/validator_set/simple_list.rs b/crates/ethcore/src/engines/validator_set/simple_list.rs index 265ac4590..3e32b910e 100644 --- a/crates/ethcore/src/engines/validator_set/simple_list.rs +++ b/crates/ethcore/src/engines/validator_set/simple_list.rs @@ -19,10 +19,12 @@ use ethereum_types::{Address, H256}; use parity_util_mem::MallocSizeOf; use super::{SystemCall, ValidatorSet}; +use crate::{ + error::Error as EthcoreError, + machine::{AuxiliaryData, Call, EthereumMachine}, + types::{BlockNumber, header::Header}, +}; use bytes::Bytes; -use crate::error::Error as EthcoreError; -use crate::machine::{AuxiliaryData, Call, EthereumMachine}; -use crate::types::{header::Header, BlockNumber}; /// Validator set containing a known set of addresses. #[derive(Clone, Debug, PartialEq, Eq, Default, MallocSizeOf)] diff --git a/crates/ethcore/src/engines/validator_set/test.rs b/crates/ethcore/src/engines/validator_set/test.rs index ab77e894a..b74c0c86e 100644 --- a/crates/ethcore/src/engines/validator_set/test.rs +++ b/crates/ethcore/src/engines/validator_set/test.rs @@ -17,18 +17,18 @@ /// Used for Engine testing. use std::str::FromStr; use std::sync::{ - atomic::{AtomicUsize, Ordering as AtomicOrdering}, Arc, + atomic::{AtomicUsize, Ordering as AtomicOrdering}, }; +use crate::types::{BlockNumber, header::Header}; use bytes::Bytes; use ethereum_types::{Address, H256}; use parity_util_mem::MallocSizeOf; -use crate::types::{header::Header, BlockNumber}; use super::{SimpleList, SystemCall, ValidatorSet}; -use error::Error as EthcoreError; use crate::machine::{AuxiliaryData, Call, EthereumMachine}; +use error::Error as EthcoreError; /// Set used for testing with a single validator. #[derive(Clone, MallocSizeOf)] @@ -47,10 +47,9 @@ impl Default for TestSet { impl TestSet { pub fn new(last_malicious: Arc, last_benign: Arc) -> Self { TestSet { - validator: SimpleList::new(vec![Address::from_str( - "7d577a597b2742b498cb5cf0c26cdcd726d39e6e", - ) - .unwrap()]), + validator: SimpleList::new(vec![ + Address::from_str("7d577a597b2742b498cb5cf0c26cdcd726d39e6e").unwrap(), + ]), last_malicious, last_benign, } diff --git a/crates/ethcore/src/error.rs b/crates/ethcore/src/error.rs index c9b52e104..6a84c3901 100644 --- a/crates/ethcore/src/error.rs +++ b/crates/ethcore/src/error.rs @@ -22,13 +22,15 @@ use std::{error, fmt, time::SystemTime}; +use crate::{ + snapshot::Error as SnapshotError, + types::{BlockNumber, transaction::Error as TransactionError}, +}; use crypto::publickey::Error as EthkeyError; use ethereum_types::{Address, Bloom, H256, U256}; use ethtrie::TrieError; use rlp; use snappy::InvalidInput; -use crate::snapshot::Error as SnapshotError; -use crate::types::{transaction::Error as TransactionError, BlockNumber}; use unexpected::{Mismatch, OutOfBounds}; use crate::engines::EngineError; diff --git a/crates/ethcore/src/ethereum/ethash.rs b/crates/ethcore/src/ethereum/ethash.rs index 7e6003b3a..e6bbed32f 100644 --- a/crates/ethcore/src/ethereum/ethash.rs +++ b/crates/ethcore/src/ethereum/ethash.rs @@ -21,25 +21,26 @@ use std::{ sync::Arc, }; -use ethereum_types::{H256, H64, U256}; -use ethjson::{self, uint::Uint}; -use hash::KECCAK_EMPTY_LIST_RLP; -use rlp::Rlp; use crate::types::{ - header::{ExtendedHeader, Header}, BlockNumber, + header::{ExtendedHeader, Header}, }; +use ethereum_types::{H64, H256, U256}; +use ethjson::{self, uint::Uint}; +use hash::KECCAK_EMPTY_LIST_RLP; +use rlp::Rlp; use unexpected::{Mismatch, OutOfBounds}; -use crate::block::ExecutedBlock; -use crate::engines::{ - self, - block_reward::{self, BlockRewardContract, RewardKind}, - Engine, +use crate::{ + block::ExecutedBlock, + engines::{ + self, Engine, + block_reward::{self, BlockRewardContract, RewardKind}, + }, + error::{BlockError, Error}, + machine::EthereumMachine, }; -use crate::error::{BlockError, Error}; -use ethash::{self, quick_get_difficulty, slow_hash_block_number, EthashManager, OptimizeFor}; -use crate::machine::EthereumMachine; +use ethash::{self, EthashManager, OptimizeFor, quick_get_difficulty, slow_hash_block_number}; /// Number of blocks in an ethash snapshot. // make dependent on difficulty incrment divisor? @@ -561,18 +562,15 @@ fn ecip1017_eras_block_reward(era_rounds: u64, mut reward: U256, block_number: u mod tests { use super::{ super::{new_homestead_test_machine, new_mcip3_test, new_morden}, - ecip1017_eras_block_reward, Ethash, EthashParams, + Ethash, EthashParams, ecip1017_eras_block_reward, }; - use crate::block::*; - use crate::engines::Engine; + use crate::{block::*, engines::Engine, spec::Spec, types::header::Header}; use error::{BlockError, Error, ErrorKind}; - use ethereum_types::{Address, H256, H64, U256}; + use ethereum_types::{Address, H64, H256, U256}; use rlp; - use crate::spec::Spec; use std::{collections::BTreeMap, str::FromStr, sync::Arc}; use tempdir::TempDir; use test_helpers::get_temp_state_db; - use crate::types::header::Header; fn test_spec() -> Spec { let tempdir = TempDir::new("").unwrap(); diff --git a/crates/ethcore/src/ethereum/mod.rs b/crates/ethcore/src/ethereum/mod.rs index 019d98291..640bd30b5 100644 --- a/crates/ethcore/src/ethereum/mod.rs +++ b/crates/ethcore/src/ethereum/mod.rs @@ -369,11 +369,13 @@ pub fn new_kovan_wasm_test_machine() -> EthereumMachine { #[cfg(test)] mod tests { use super::*; + use crate::{ + state::*, + types::{view, views::BlockView}, + }; use ethereum_types::{H160, H256, U256}; - use crate::state::*; use std::str::FromStr; use test_helpers::get_temp_state_db; - use crate::types::{view, views::BlockView}; #[test] fn ensure_db_good() { diff --git a/crates/ethcore/src/executed.rs b/crates/ethcore/src/executed.rs index 542bd1198..946fb22ed 100644 --- a/crates/ethcore/src/executed.rs +++ b/crates/ethcore/src/executed.rs @@ -16,11 +16,13 @@ //! Transaction execution format module. +use crate::{ + trace::{FlatTrace, VMTrace}, + types::{log_entry::LogEntry, state_diff::StateDiff}, +}; use bytes::Bytes; use ethereum_types::{Address, U256, U512}; use ethtrie; -use crate::trace::{FlatTrace, VMTrace}; -use crate::types::{log_entry::LogEntry, state_diff::StateDiff}; use vm; use std::{error, fmt}; diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index 3d5956ca4..589bc96a1 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -15,20 +15,22 @@ // along with OpenEthereum. If not, see . //! Transaction Execution environment. +pub use crate::executed::{Executed, ExecutionResult}; +use crate::{ + executed::ExecutionError, + externalities::*, + factory::VmFactory, + machine::EthereumMachine as Machine, + state::{Backend as StateBackend, CleanupMode, State, Substate}, + trace::{self, Tracer, VMTracer}, + transaction_ext::Transaction, + types::transaction::{Action, SignedTransaction, TypedTransaction}, +}; use bytes::{Bytes, BytesRef}; use ethereum_types::{Address, H256, U256, U512}; use evm::{CallType, FinalizationResult, Finalize}; -use crate::executed::ExecutionError; -pub use crate::executed::{Executed, ExecutionResult}; -use crate::externalities::*; -use crate::factory::VmFactory; use hash::keccak; -use crate::machine::EthereumMachine as Machine; -use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, convert::TryFrom, sync::Arc}; -use crate::trace::{self, Tracer, VMTracer}; -use crate::transaction_ext::Transaction; -use crate::types::transaction::{Action, SignedTransaction, TypedTransaction}; use vm::{ self, AccessList, ActionParams, ActionValue, CleanDustMode, CreateContractAddress, EnvInfo, ResumeCall, ResumeCreate, ReturnData, Schedule, TrapError, @@ -259,9 +261,7 @@ impl<'a> CallCreateExecutive<'a> { ) -> Self { trace!( "Executive::call(params={:?}) self.env_info={:?}, parent_static={}", - params, - info, - parent_static_flag + params, info, parent_static_flag ); let gas = params.gas; @@ -315,9 +315,7 @@ impl<'a> CallCreateExecutive<'a> { ) -> Self { trace!( "Executive::create(params={:?}) self.env_info={:?}, static={}", - params, - info, - static_flag + params, info, static_flag ); let gas = params.gas; @@ -884,135 +882,162 @@ impl<'a> CallCreateExecutive<'a> { let mut callstack: Vec<(Option
, CallCreateExecutive<'a>)> = Vec::new(); loop { match last_res { - None => { - match callstack.pop() { - Some((_, exec)) => { - let second_last = callstack.last_mut(); - let parent_substate = match second_last { + None => match callstack.pop() { + Some((_, exec)) => { + let second_last = callstack.last_mut(); + let parent_substate = match second_last { Some((_, second_last)) => second_last.unconfirmed_substate().expect("Current stack value is created from second last item; second last item must be call or create; qed"), None => top_substate, }; - last_res = Some((exec.is_create, exec.gas, exec.exec(state, parent_substate, tracer, vm_tracer))); - }, - None => panic!("When callstack only had one item and it was executed, this function would return; callstack never reaches zero item; qed"), - } - }, - Some((is_create, gas, Ok(val))) => { - let current = callstack.pop(); - - match current { - Some((address, mut exec)) => { - if is_create { - let address = address.expect("If the last executed status was from a create executive, then the destination address was pushed to the callstack; address is_some if it is_create; qed"); - - match val { - Ok(ref val) if val.apply_state => { - tracer.done_trace_create( - gas - val.gas_left, - &val.return_data, - address - ); - }, - Ok(_) => { - tracer.done_trace_failed(&vm::Error::Reverted); - }, - Err(ref err) => { - tracer.done_trace_failed(err); - }, - } - - vm_tracer.done_subtrace(); - - let second_last = callstack.last_mut(); - let parent_substate = match second_last { + last_res = Some(( + exec.is_create, + exec.gas, + exec.exec(state, parent_substate, tracer, vm_tracer), + )); + } + None => panic!( + "When callstack only had one item and it was executed, this function would return; callstack never reaches zero item; qed" + ), + }, + Some((is_create, gas, Ok(val))) => { + let current = callstack.pop(); + + match current { + Some((address, mut exec)) => { + if is_create { + let address = address.expect("If the last executed status was from a create executive, then the destination address was pushed to the callstack; address is_some if it is_create; qed"); + + match val { + Ok(ref val) if val.apply_state => { + tracer.done_trace_create( + gas - val.gas_left, + &val.return_data, + address, + ); + } + Ok(_) => { + tracer.done_trace_failed(&vm::Error::Reverted); + } + Err(ref err) => { + tracer.done_trace_failed(err); + } + } + + vm_tracer.done_subtrace(); + + let second_last = callstack.last_mut(); + let parent_substate = match second_last { Some((_, second_last)) => second_last.unconfirmed_substate().expect("Current stack value is created from second last item; second last item must be call or create; qed"), None => top_substate, }; - let contract_create_result = into_contract_create_result(val, &address, exec.unconfirmed_substate().expect("Executive is resumed from a create; it has an unconfirmed substate; qed")); - last_res = Some((exec.is_create, exec.gas, exec.resume_create( - contract_create_result, - state, - parent_substate, - tracer, - vm_tracer - ))); - } else { - match val { - Ok(ref val) if val.apply_state => { - tracer.done_trace_call( - gas - val.gas_left, - &val.return_data, - ); - }, - Ok(_) => { - tracer.done_trace_failed(&vm::Error::Reverted); - }, - Err(ref err) => { - tracer.done_trace_failed(err); - }, - } - - vm_tracer.done_subtrace(); - - let second_last = callstack.last_mut(); - let parent_substate = match second_last { + let contract_create_result = into_contract_create_result(val, &address, exec.unconfirmed_substate().expect("Executive is resumed from a create; it has an unconfirmed substate; qed")); + last_res = Some(( + exec.is_create, + exec.gas, + exec.resume_create( + contract_create_result, + state, + parent_substate, + tracer, + vm_tracer, + ), + )); + } else { + match val { + Ok(ref val) if val.apply_state => { + tracer + .done_trace_call(gas - val.gas_left, &val.return_data); + } + Ok(_) => { + tracer.done_trace_failed(&vm::Error::Reverted); + } + Err(ref err) => { + tracer.done_trace_failed(err); + } + } + + vm_tracer.done_subtrace(); + + let second_last = callstack.last_mut(); + let parent_substate = match second_last { Some((_, second_last)) => second_last.unconfirmed_substate().expect("Current stack value is created from second last item; second last item must be call or create; qed"), None => top_substate, }; - last_res = Some((exec.is_create, exec.gas, exec.resume_call( - into_message_call_result(val), - state, - parent_substate, - tracer, - vm_tracer - ))); - } - }, - None => return val, - } - }, - Some((_, _, Err(TrapError::Call(subparams, resume)))) => { - tracer.prepare_trace_call(&subparams, resume.depth + 1, resume.machine.builtin(&subparams.address, resume.info.number).is_some()); - vm_tracer.prepare_subtrace(subparams.code.as_ref().map_or_else(|| &[] as &[u8], |d| &*d as &[u8])); - - let sub_exec = CallCreateExecutive::new_call_raw( - subparams, - resume.info, - resume.machine, - resume.schedule, - resume.factory, - resume.depth + 1, - resume.stack_depth, - resume.static_flag, - ); - - callstack.push((None, resume)); - callstack.push((None, sub_exec)); - last_res = None; - }, - Some((_, _, Err(TrapError::Create(subparams, address, resume)))) => { - tracer.prepare_trace_create(&subparams); - vm_tracer.prepare_subtrace(subparams.code.as_ref().map_or_else(|| &[] as &[u8], |d| &*d as &[u8])); - - let sub_exec = CallCreateExecutive::new_create_raw( - subparams, - resume.info, - resume.machine, - resume.schedule, - resume.factory, - resume.depth + 1, - resume.stack_depth, - resume.static_flag - ); - - callstack.push((Some(address), resume)); - callstack.push((None, sub_exec)); - last_res = None; - }, - } + last_res = Some(( + exec.is_create, + exec.gas, + exec.resume_call( + into_message_call_result(val), + state, + parent_substate, + tracer, + vm_tracer, + ), + )); + } + } + None => return val, + } + } + Some((_, _, Err(TrapError::Call(subparams, resume)))) => { + tracer.prepare_trace_call( + &subparams, + resume.depth + 1, + resume + .machine + .builtin(&subparams.address, resume.info.number) + .is_some(), + ); + vm_tracer.prepare_subtrace( + subparams + .code + .as_ref() + .map_or_else(|| &[] as &[u8], |d| &*d as &[u8]), + ); + + let sub_exec = CallCreateExecutive::new_call_raw( + subparams, + resume.info, + resume.machine, + resume.schedule, + resume.factory, + resume.depth + 1, + resume.stack_depth, + resume.static_flag, + ); + + callstack.push((None, resume)); + callstack.push((None, sub_exec)); + last_res = None; + } + Some((_, _, Err(TrapError::Create(subparams, address, resume)))) => { + tracer.prepare_trace_create(&subparams); + vm_tracer.prepare_subtrace( + subparams + .code + .as_ref() + .map_or_else(|| &[] as &[u8], |d| &*d as &[u8]), + ); + + let sub_exec = CallCreateExecutive::new_create_raw( + subparams, + resume.info, + resume.machine, + resume.schedule, + resume.factory, + resume.depth + 1, + resume.stack_depth, + resume.static_flag, + ); + + callstack.push((Some(address), resume)); + callstack.push((None, sub_exec)); + last_res = None; + } + } } } } @@ -1531,22 +1556,31 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { let fees_value = fees_value.saturating_sub(burnt_fee); - trace!("exec::finalize: t.gas={}, sstore_refunds={}, suicide_refunds={}, refunds_bound={}, gas_left_prerefund={}, refunded={}, gas_left={}, gas_used={}, refund_value={}, fees_value={}\n", - t.tx().gas, sstore_refunds, suicide_refunds, refunds_bound, gas_left_prerefund, refunded, gas_left, gas_used, refund_value, fees_value); + trace!( + "exec::finalize: t.gas={}, sstore_refunds={}, suicide_refunds={}, refunds_bound={}, gas_left_prerefund={}, refunded={}, gas_left={}, gas_used={}, refund_value={}, fees_value={}\n", + t.tx().gas, + sstore_refunds, + suicide_refunds, + refunds_bound, + gas_left_prerefund, + refunded, + gas_left, + gas_used, + refund_value, + fees_value + ); let sender = t.sender(); trace!( "exec::finalize: Refunding refund_value={}, sender={}\n", - refund_value, - sender + refund_value, sender ); // Below: NoEmpty is safe since the sender must already be non-null to have sent this transaction self.state .add_balance(&sender, &refund_value, CleanupMode::NoEmpty)?; trace!( "exec::finalize: Compensating author: fees_value={}, author={}\n", - fees_value, - &self.info.author + fees_value, &self.info.author ); self.state.add_balance( &self.info.author, @@ -1627,22 +1661,24 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { #[allow(dead_code)] mod tests { use super::*; + use crate::{ + machine::EthereumMachine, + state::{CleanupMode, Substate}, + trace::{ + ExecutiveTracer, ExecutiveVMTracer, FlatTrace, MemoryDiff, NoopTracer, NoopVMTracer, + StorageDiff, Tracer, VMExecutedOperation, VMOperation, VMTrace, VMTracer, trace, + }, + types::transaction::{ + AccessListTx, Action, EIP1559TransactionTx, Transaction, TypedTransaction, + }, + }; use crypto::publickey::{Generator, Random}; use error::ExecutionError; use ethereum_types::{Address, BigEndianHash, H160, H256, U256, U512}; use evm::{Factory, VMType}; - use crate::machine::EthereumMachine; use rustc_hex::FromHex; - use crate::state::{CleanupMode, Substate}; use std::{str::FromStr, sync::Arc}; use test_helpers::{get_temp_state, get_temp_state_with_factory}; - use crate::trace::{ - trace, ExecutiveTracer, ExecutiveVMTracer, FlatTrace, MemoryDiff, NoopTracer, NoopVMTracer, - StorageDiff, Tracer, VMExecutedOperation, VMOperation, VMTrace, VMTracer, - }; - use crate::types::transaction::{ - AccessListTx, Action, EIP1559TransactionTx, Transaction, TypedTransaction, - }; use vm::{ActionParams, ActionValue, CallType, CreateContractAddress, EnvInfo}; fn make_frontier_machine(max_depth: usize) -> EthereumMachine { diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index 4cadf5ccb..390a1ef91 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -15,14 +15,16 @@ // along with OpenEthereum. If not, see . //! Transaction Execution environment. +use crate::{ + executive::*, + machine::EthereumMachine as Machine, + state::{Backend as StateBackend, CleanupMode, State, Substate}, + trace::{Tracer, VMTracer}, + types::transaction::UNSIGNED_SENDER, +}; use bytes::Bytes; use ethereum_types::{Address, BigEndianHash, H256, U256}; -use crate::executive::*; -use crate::machine::EthereumMachine as Machine; -use crate::state::{Backend as StateBackend, CleanupMode, State, Substate}; use std::{cmp, sync::Arc}; -use crate::trace::{Tracer, VMTracer}; -use crate::types::transaction::UNSIGNED_SENDER; use vm::{ self, AccessList, ActionParams, ActionValue, CallType, ContractCreateResult, CreateContractAddress, EnvInfo, Ext, MessageCallResult, ReturnData, Schedule, TrapKind, @@ -219,10 +221,7 @@ where }; trace!( "ext: blockhash contract({}) -> {:?}({}) self.env_info.number={}\n", - number, - r, - output, - self.env_info.number + number, r, output, self.env_info.number ); output } else { @@ -240,17 +239,14 @@ where let r = self.env_info.last_hashes[index as usize].clone(); trace!( "ext: blockhash({}) -> {} self.env_info.number={}\n", - number, - r, - self.env_info.number + number, r, self.env_info.number ); r } false => { trace!( "ext: blockhash({}) -> null self.env_info.number={}\n", - number, - self.env_info.number + number, self.env_info.number ); H256::zero() } @@ -561,12 +557,14 @@ where #[cfg(test)] mod tests { use super::*; + use crate::{ + state::{State, Substate}, + trace::{NoopTracer, NoopVMTracer}, + }; use ethereum_types::{Address, U256}; use evm::{CallType, EnvInfo, Ext}; - use crate::state::{State, Substate}; use std::str::FromStr; use test_helpers::get_temp_state; - use crate::trace::{NoopTracer, NoopVMTracer}; fn get_test_origin() -> OriginInfo { OriginInfo { @@ -769,10 +767,10 @@ mod tests { #[test] fn can_log() { let log_data = vec![120u8, 110u8]; - let log_topics = vec![H256::from_str( - "af0fa234a6af46afa23faf23bcbc1c1cb4bcb7bcbe7e7e7ee3ee2edddddddddd", - ) - .unwrap()]; + let log_topics = vec![ + H256::from_str("af0fa234a6af46afa23faf23bcbc1c1cb4bcb7bcbe7e7e7ee3ee2edddddddddd") + .unwrap(), + ]; let mut setup = TestSetup::new(); let state = &mut setup.state; diff --git a/crates/ethcore/src/json_tests/chain.rs b/crates/ethcore/src/json_tests/chain.rs index 83189c8da..bbdef6a4a 100644 --- a/crates/ethcore/src/json_tests/chain.rs +++ b/crates/ethcore/src/json_tests/chain.rs @@ -17,20 +17,22 @@ use crate::exit::ShutdownManager; use super::HookType; -use crate::client::{ - Balance, BlockChainClient, BlockId, ChainInfo, Client, ClientConfig, EvmTestClient, - ImportBlock, Nonce, StateOrBlock, +use crate::{ + client::{ + Balance, BlockChainClient, BlockId, ChainInfo, Client, ClientConfig, EvmTestClient, + ImportBlock, Nonce, StateOrBlock, + }, + io::IoChannel, + spec::Genesis, + verification::{VerifierType, queue::kind::blocks::Unverified}, }; use ethereum_types::{H256, U256}; use ethjson; -use crate::io::IoChannel; use log::warn; use miner::Miner; use rustc_hex::ToHex; -use crate::spec::Genesis; use std::{path::Path, sync::Arc}; use test_helpers; -use crate::verification::{queue::kind::blocks::Unverified, VerifierType}; fn check_poststate( client: &Arc, diff --git a/crates/ethcore/src/json_tests/difficulty.rs b/crates/ethcore/src/json_tests/difficulty.rs index 2b42e8a60..247a8bc02 100644 --- a/crates/ethcore/src/json_tests/difficulty.rs +++ b/crates/ethcore/src/json_tests/difficulty.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{spec::Spec, types::header::Header}; use ethereum_types::U256; use ethjson; -use crate::spec::Spec; use std::path::Path; -use crate::types::header::Header; use super::HookType; diff --git a/crates/ethcore/src/json_tests/executive.rs b/crates/ethcore/src/json_tests/executive.rs index b2ce2808d..ff94b2b73 100644 --- a/crates/ethcore/src/json_tests/executive.rs +++ b/crates/ethcore/src/json_tests/executive.rs @@ -15,20 +15,22 @@ // along with OpenEthereum. If not, see . use super::test_common::*; +use crate::{ + executive::*, + externalities::*, + machine::EthereumMachine as Machine, + state::{Backend as StateBackend, State, Substate}, + trace::{NoopTracer, NoopVMTracer, Tracer, VMTracer}, +}; use bytes::Bytes; use ethereum_types::BigEndianHash; use ethjson; use ethtrie; use evm::Finalize; -use crate::executive::*; -use crate::externalities::*; use hash::keccak; -use crate::machine::EthereumMachine as Machine; use rlp::RlpStream; -use crate::state::{Backend as StateBackend, State, Substate}; use std::{path::Path, sync::Arc}; use test_helpers::get_temp_state; -use crate::trace::{NoopTracer, NoopVMTracer, Tracer, VMTracer}; use vm::{ self, ActionParams, CallType, ContractCreateResult, CreateContractAddress, EnvInfo, Ext, MessageCallResult, ReturnData, Schedule, diff --git a/crates/ethcore/src/json_tests/local.rs b/crates/ethcore/src/json_tests/local.rs index f6d0b3727..e6f2a1f4b 100644 --- a/crates/ethcore/src/json_tests/local.rs +++ b/crates/ethcore/src/json_tests/local.rs @@ -1,14 +1,16 @@ use super::HookType; +use crate::{ + types::{ + BlockNumber, + transaction::{TypedTransaction, TypedTxId, UnverifiedTransaction}, + }, + verification::queue::kind::blocks::Unverified, +}; use ethereum_types::U256; use ethjson::{self, blockchain::Block}; use log::warn; use rlp::RlpStream; use std::path::Path; -use crate::types::{ - transaction::{TypedTransaction, TypedTxId, UnverifiedTransaction}, - BlockNumber, -}; -use crate::verification::queue::kind::blocks::Unverified; pub fn json_local_block_en_de_test( _test: ðjson::test::LocalTests, diff --git a/crates/ethcore/src/json_tests/mod.rs b/crates/ethcore/src/json_tests/mod.rs index 5cda1f28e..725e92cc9 100644 --- a/crates/ethcore/src/json_tests/mod.rs +++ b/crates/ethcore/src/json_tests/mod.rs @@ -30,5 +30,5 @@ pub mod runner; pub use self::{ executive::json_executive_test, - test_common::{debug_include_test, find_json_files_recursive, HookType}, + test_common::{HookType, debug_include_test, find_json_files_recursive}, }; diff --git a/crates/ethcore/src/json_tests/state.rs b/crates/ethcore/src/json_tests/state.rs index 2fc00deea..f46f17e52 100644 --- a/crates/ethcore/src/json_tests/state.rs +++ b/crates/ethcore/src/json_tests/state.rs @@ -14,12 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use super::{test_common::*, HookType}; -use crate::client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess}; +use super::{HookType, test_common::*}; +use crate::{ + client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess}, + trace, +}; use ethjson::{self, spec::ForkSpec}; use pod_state::PodState; use std::path::Path; -use crate::trace; use vm::EnvInfo; fn skip_test( diff --git a/crates/ethcore/src/json_tests/transaction.rs b/crates/ethcore/src/json_tests/transaction.rs index 7b2c963b5..e4e6b6755 100644 --- a/crates/ethcore/src/json_tests/transaction.rs +++ b/crates/ethcore/src/json_tests/transaction.rs @@ -15,14 +15,16 @@ // along with OpenEthereum. If not, see . use super::test_common::*; -use crate::client::EvmTestClient; +use crate::{ + client::EvmTestClient, + transaction_ext::Transaction, + types::{ + header::Header, + transaction::{TypedTransaction, UnverifiedTransaction}, + }, +}; use ethjson; use std::path::Path; -use crate::transaction_ext::Transaction; -use crate::types::{ - header::Header, - transaction::{TypedTransaction, UnverifiedTransaction}, -}; pub fn json_transaction_test( path: &Path, diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index 3d961eb1e..f3f6884c1 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -148,6 +148,6 @@ pub mod test_helpers; #[cfg(test)] mod tests; -pub use evm::CreateContractAddress; pub use crate::executive::contract_address; +pub use evm::CreateContractAddress; pub use trie::TrieSpec; diff --git a/crates/ethcore/src/machine/impls.rs b/crates/ethcore/src/machine/impls.rs index b7d921bea..cd3761ec5 100644 --- a/crates/ethcore/src/machine/impls.rs +++ b/crates/ethcore/src/machine/impls.rs @@ -22,30 +22,32 @@ use std::{ sync::Arc, }; -use ethereum_types::{Address, H256, U256}; use crate::types::{ + BlockNumber, header::Header, transaction::{ - self, SignedTransaction, TypedTransaction, UnverifiedTransaction, SYSTEM_ADDRESS, - UNSIGNED_SENDER, + self, SYSTEM_ADDRESS, SignedTransaction, TypedTransaction, UNSIGNED_SENDER, + UnverifiedTransaction, }, - BlockNumber, }; +use ethereum_types::{Address, H256, U256}; use vm::{ AccessList, ActionParams, ActionValue, CallType, CreateContractAddress, EnvInfo, ParamsType, Schedule, }; -use crate::block::ExecutedBlock; +use crate::{ + block::ExecutedBlock, + client::BlockInfo, + error::Error, + executive::Executive, + spec::CommonParams, + state::{CleanupMode, Substate}, + trace::{NoopTracer, NoopVMTracer}, + tx_filter::TransactionFilter, +}; use builtin::Builtin; use call_contract::CallContract; -use crate::client::BlockInfo; -use crate::error::Error; -use crate::executive::Executive; -use crate::spec::CommonParams; -use crate::state::{CleanupMode, Substate}; -use crate::trace::{NoopTracer, NoopVMTracer}; -use crate::tx_filter::TransactionFilter; /// Ethash-specific extensions. #[derive(Debug, Clone)] @@ -452,10 +454,10 @@ impl EthereumMachine { match tx.tx_type() { transaction::TypedTxId::AccessList if !schedule.eip2930 => { - return Err(transaction::Error::TransactionTypeNotEnabled) + return Err(transaction::Error::TransactionTypeNotEnabled); } transaction::TypedTxId::EIP1559Transaction if !schedule.eip1559 => { - return Err(transaction::Error::TransactionTypeNotEnabled) + return Err(transaction::Error::TransactionTypeNotEnabled); } _ => (), }; diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 60b356b78..be330f185 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -21,6 +21,21 @@ use std::{ time::{Duration, Instant}, }; +use crate::{ + io::IoChannel, + miner::{ + self, MinerService, + cache::Cache, + pool_client::{CachedNonceClient, PoolClient}, + }, + types::{ + BlockNumber, + block::Block, + header::Header, + receipt::RichReceipt, + transaction::{self, Action, PendingTransaction, SignedTransaction, UnverifiedTransaction}, + }, +}; use ansi_term::Colour; use bytes::Bytes; use call_contract::CallContract; @@ -30,44 +45,31 @@ use ethcore_miner::{ gas_pricer::GasPricer, local_accounts::LocalAccounts, pool::{ - self, - transaction_filter::{match_filter, TransactionFilter}, - PrioritizationStrategy, QueueStatus, TransactionQueue, VerifiedTransaction, + self, PrioritizationStrategy, QueueStatus, TransactionQueue, VerifiedTransaction, + transaction_filter::{TransactionFilter, match_filter}, }, service_transaction_checker::ServiceTransactionChecker, }; use ethereum_types::{Address, H256, U256}; -use crate::io::IoChannel; use itertools::Itertools; -use crate::miner::{ - self, - cache::Cache, - pool_client::{CachedNonceClient, PoolClient}, - MinerService, -}; use parking_lot::{Mutex, RwLock}; use rayon::prelude::*; -use crate::types::{ - block::Block, - header::Header, - receipt::RichReceipt, - transaction::{self, Action, PendingTransaction, SignedTransaction, UnverifiedTransaction}, - BlockNumber, -}; use using_queue::{GetAction, UsingQueue}; -use crate::block::{ClosedBlock, OpenBlock, SealedBlock}; -use crate::client::{ - traits::{EngineClient, ForceUpdateSealing}, - BlockChain, BlockId, BlockProducer, ChainInfo, ClientIoMessage, Nonce, SealedBlockImporter, - TransactionId, TransactionInfo, +use crate::{ + block::{ClosedBlock, OpenBlock, SealedBlock}, + client::{ + BlockChain, BlockId, BlockProducer, ChainInfo, ClientIoMessage, Nonce, SealedBlockImporter, + TransactionId, TransactionInfo, + traits::{EngineClient, ForceUpdateSealing}, + }, + engines::{EngineSigner, EthEngine, Seal, SealingState}, + error::{Error, ErrorKind}, + executed::ExecutionError, + executive::contract_address, + spec::Spec, + state::State, }; -use crate::engines::{EngineSigner, EthEngine, Seal, SealingState}; -use crate::error::{Error, ErrorKind}; -use crate::executed::ExecutionError; -use crate::executive::contract_address; -use crate::spec::Spec; -use crate::state::State; /// Different possible definitions for pending transaction set. #[derive(Debug, PartialEq)] @@ -1566,8 +1568,11 @@ impl miner::MinerService for Miner { // which should be on by default. if block.header.number() == 1 { if let Some(name) = self.engine.params().nonzero_bugfix_hard_fork() { - warn!("Your chain specification contains one or more hard forks which are required to be \ - on by default. Please remove these forks and start your chain again: {}.", name); + warn!( + "Your chain specification contains one or more hard forks which are required to be \ + on by default. Please remove these forks and start your chain again: {}.", + name + ); return; } } @@ -1825,18 +1830,20 @@ mod tests { use std::iter::FromIterator; use super::*; + use crate::types::BlockNumber; use accounts::AccountProvider; use crypto::publickey::{Generator, Random}; use hash::keccak; use rustc_hex::FromHex; - use crate::types::BlockNumber; - use crate::client::{ChainInfo, EachBlockWith, ImportSealedBlock, TestBlockChainClient}; + use crate::{ + client::{ChainInfo, EachBlockWith, ImportSealedBlock, TestBlockChainClient}, + types::transaction::{Transaction, TypedTransaction}, + }; use miner::{MinerService, PendingOrdering}; use test_helpers::{ dummy_engine_signer_with_address, generate_dummy_client, generate_dummy_client_with_spec, }; - use crate::types::transaction::{Transaction, TypedTransaction}; #[test] fn should_prepare_block_to_seal() { @@ -2267,13 +2274,18 @@ mod tests { assert!(miner.pending_block(0).is_none()); assert_eq!(client.chain_info().best_block_number, 3 as BlockNumber); - assert!(miner - .import_own_transaction( - &*client, - PendingTransaction::new(transaction_with_chain_id(spec.chain_id()).into(), None), - false - ) - .is_ok()); + assert!( + miner + .import_own_transaction( + &*client, + PendingTransaction::new( + transaction_with_chain_id(spec.chain_id()).into(), + None + ), + false + ) + .is_ok() + ); miner.update_sealing(&*client, ForceUpdateSealing::No); client.flush_queue(); diff --git a/crates/ethcore/src/miner/mod.rs b/crates/ethcore/src/miner/mod.rs index 9e33e4fc1..365924686 100644 --- a/crates/ethcore/src/miner/mod.rs +++ b/crates/ethcore/src/miner/mod.rs @@ -29,7 +29,7 @@ pub mod stratum; pub use self::miner::{Author, AuthoringParams, Miner, MinerOptions, Penalization, PendingSet}; pub use ethcore_miner::{ local_accounts::LocalAccounts, - pool::{transaction_filter::TransactionFilter, PendingOrdering}, + pool::{PendingOrdering, transaction_filter::TransactionFilter}, }; use std::{ @@ -37,25 +37,27 @@ use std::{ sync::Arc, }; -use bytes::Bytes; -use ethcore_miner::pool::{local_transactions, QueueStatus, VerifiedTransaction}; -use ethereum_types::{Address, H256, U256}; use crate::types::{ + BlockNumber, block::Block, header::Header, receipt::RichReceipt, transaction::{self, PendingTransaction, SignedTransaction, UnverifiedTransaction}, - BlockNumber, }; +use bytes::Bytes; +use ethcore_miner::pool::{QueueStatus, VerifiedTransaction, local_transactions}; +use ethereum_types::{Address, H256, U256}; -use crate::block::SealedBlock; -use call_contract::{CallContract, RegistryInfo}; -use crate::client::{ - traits::ForceUpdateSealing, AccountData, BlockChain, BlockProducer, Nonce, ScheduleInfo, - SealedBlockImporter, +use crate::{ + block::SealedBlock, + client::{ + AccountData, BlockChain, BlockProducer, Nonce, ScheduleInfo, SealedBlockImporter, + traits::ForceUpdateSealing, + }, + error::Error, + state::StateInfo, }; -use crate::error::Error; -use crate::state::StateInfo; +use call_contract::{CallContract, RegistryInfo}; /// Provides methods to verify incoming external transactions pub trait TransactionVerifierClient: Send + Sync diff --git a/crates/ethcore/src/miner/pool_client.rs b/crates/ethcore/src/miner/pool_client.rs index 59cc519bc..993efb155 100644 --- a/crates/ethcore/src/miner/pool_client.rs +++ b/crates/ethcore/src/miner/pool_client.rs @@ -18,25 +18,27 @@ use std::fmt; +use crate::types::{ + header::Header, + transaction::{self, SignedTransaction, UnverifiedTransaction}, +}; use ethcore_miner::{ local_accounts::LocalAccounts, pool, pool::client::NonceClient, service_transaction_checker::ServiceTransactionChecker, }; use ethereum_types::{Address, H256, U256}; -use crate::types::{ - header::Header, - transaction::{self, SignedTransaction, UnverifiedTransaction}, -}; +use crate::{ + client::{Balance, BlockId, BlockInfo, Nonce, TransactionId}, + engines::EthEngine, + miner::{ + self, + cache::{Cache, CachedClient}, + }, + transaction_ext::Transaction, +}; use call_contract::CallContract; -use crate::client::{Balance, BlockId, BlockInfo, Nonce, TransactionId}; -use crate::engines::EthEngine; use ethcore_miner::pool::client::BalanceClient; -use crate::miner::{ - self, - cache::{Cache, CachedClient}, -}; -use crate::transaction_ext::Transaction; pub(crate) struct CachedNonceClient<'a, C: 'a> { cached_client: CachedClient<'a, C, Address, U256>, diff --git a/crates/ethcore/src/miner/stratum.rs b/crates/ethcore/src/miner/stratum.rs index 3205f423b..b0090565d 100644 --- a/crates/ethcore/src/miner/stratum.rs +++ b/crates/ethcore/src/miner/stratum.rs @@ -22,15 +22,17 @@ use std::{ sync::{Arc, Weak}, }; -use crate::client::{Client, ImportSealedBlock}; +use crate::{ + client::{Client, ImportSealedBlock}, + miner::{Miner, MinerService}, +}; use ethash::{self, SeedHashCompute}; #[cfg(feature = "work-notify")] use ethcore_miner::work_notify::NotifyWork; #[cfg(feature = "work-notify")] use ethcore_stratum::PushWorkHandler; use ethcore_stratum::{Error as StratumServiceError, JobDispatcher, Stratum as StratumService}; -use ethereum_types::{H256, H64, U256}; -use crate::miner::{Miner, MinerService}; +use ethereum_types::{H64, H256, U256}; use parking_lot::Mutex; use rlp::encode; @@ -48,11 +50,7 @@ pub struct Options { } fn clean_0x(s: &str) -> &str { - if s.starts_with("0x") { - &s[2..] - } else { - s - } + if s.starts_with("0x") { &s[2..] } else { s } } struct SubmitPayload { diff --git a/crates/ethcore/src/pod_account.rs b/crates/ethcore/src/pod_account.rs index 3342104f0..a5f02ed72 100644 --- a/crates/ethcore/src/pod_account.rs +++ b/crates/ethcore/src/pod_account.rs @@ -16,6 +16,7 @@ //! Account system expressed in Plain Old Data. +use crate::{state::Account, types::account_diff::*}; use bytes::Bytes; use ethereum_types::{BigEndianHash, H256, U256}; use ethjson; @@ -28,11 +29,9 @@ use kvdb::DBValue; use rlp::{self, RlpStream}; use rustc_hex::ToHex; use serde::Serializer; -use crate::state::Account; use std::{collections::BTreeMap, fmt}; use trie::TrieFactory; use triehash::sec_trie_root; -use crate::types::account_diff::*; #[derive(Debug, Clone, PartialEq, Eq, Serialize)] /// An account, expressed as Plain-Old-Data (hence the name). @@ -216,10 +215,10 @@ pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option StateDiff { #[cfg(test)] mod test { use super::PodState; + use crate::{ + pod_account::PodAccount, + types::{account_diff::*, state_diff::*}, + }; use ethereum_types::H160; - use crate::pod_account::PodAccount; use std::collections::BTreeMap; - use crate::types::{account_diff::*, state_diff::*}; #[test] fn create_delete() { diff --git a/crates/ethcore/src/snapshot/account.rs b/crates/ethcore/src/snapshot/account.rs index d76aba76f..73fe5d59c 100644 --- a/crates/ethcore/src/snapshot/account.rs +++ b/crates/ethcore/src/snapshot/account.rs @@ -16,17 +16,19 @@ //! Account state encoding and decoding -use crate::account_db::{AccountDB, AccountDBMut}; +use crate::{ + account_db::{AccountDB, AccountDBMut}, + snapshot::{Error, Progress}, + types::basic_account::BasicAccount, +}; use bytes::Bytes; use ethereum_types::{H256, U256}; use ethtrie::{TrieDB, TrieDBMut}; use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP}; use hash_db::HashDB; use rlp::{Rlp, RlpStream}; -use crate::snapshot::{Error, Progress}; use std::{collections::HashSet, sync::atomic::Ordering}; use trie::{Trie, TrieMut}; -use crate::types::basic_account::BasicAccount; // An empty account -- these were replaced with RLP null data for a space optimization in v1. const ACC_EMPTY: BasicAccount = BasicAccount { @@ -221,20 +223,22 @@ pub fn from_fat_rlp( #[cfg(test)] mod tests { - use crate::account_db::{AccountDB, AccountDBMut}; - use crate::snapshot::{tests::helpers::fill_storage, Progress}; + use crate::{ + account_db::{AccountDB, AccountDBMut}, + snapshot::{Progress, tests::helpers::fill_storage}, + types::basic_account::BasicAccount, + }; use test_helpers::get_temp_state_db; - use crate::types::basic_account::BasicAccount; use ethereum_types::{Address, H256}; - use hash::{keccak, KECCAK_EMPTY, KECCAK_NULL_RLP}; + use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak}; use hash_db::HashDB; use kvdb::DBValue; use rlp::Rlp; use std::collections::HashSet; - use super::{from_fat_rlp, to_fat_rlps, ACC_EMPTY}; + use super::{ACC_EMPTY, from_fat_rlp, to_fat_rlps}; #[test] fn encoding_basic() { diff --git a/crates/ethcore/src/snapshot/block.rs b/crates/ethcore/src/snapshot/block.rs index 03a45e922..907ce2911 100644 --- a/crates/ethcore/src/snapshot/block.rs +++ b/crates/ethcore/src/snapshot/block.rs @@ -16,14 +16,14 @@ //! Block RLP compression. +use crate::types::{ + BlockNumber, block::Block, header::Header, transaction::TypedTransaction, views::BlockView, +}; use bytes::Bytes; use ethereum_types::{H256, U256}; use hash::keccak; use rlp::{DecoderError, Rlp, RlpStream}; use triehash::ordered_trie_root; -use crate::types::{ - block::Block, header::Header, transaction::TypedTransaction, views::BlockView, BlockNumber, -}; const HEADER_FIELDS: usize = 8; const BLOCK_FIELDS: usize = 2; @@ -156,15 +156,15 @@ impl AbridgedBlock { mod tests { use super::AbridgedBlock; - use bytes::Bytes; - use ethereum_types::{Address, H256, U256}; use crate::types::{ + BlockNumber, block::Block, transaction::{Action, Transaction, TypedTransaction}, view, views::BlockView, - BlockNumber, }; + use bytes::Bytes; + use ethereum_types::{Address, H256, U256}; fn encode_block(b: &Block) -> Bytes { b.rlp_bytes() diff --git a/crates/ethcore/src/snapshot/consensus/authority.rs b/crates/ethcore/src/snapshot/consensus/authority.rs index 6a19c6045..06b913043 100644 --- a/crates/ethcore/src/snapshot/consensus/authority.rs +++ b/crates/ethcore/src/snapshot/consensus/authority.rs @@ -22,24 +22,28 @@ use super::{ChunkSink, Rebuilder, SnapshotComponents}; use std::sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }; -use crate::engines::{EpochTransition, EpochVerifier, EthEngine}; -use crate::machine::EthereumMachine; -use crate::snapshot::{Error, ManifestData, Progress}; +use crate::{ + engines::{EpochTransition, EpochVerifier, EthEngine}, + machine::EthereumMachine, + snapshot::{Error, ManifestData, Progress}, +}; -use crate::blockchain::{BlockChain, BlockChainDB, BlockProvider}; +use crate::{ + blockchain::{BlockChain, BlockChainDB, BlockProvider}, + types::{ + BlockNumber, encoded, header::Header, ids::BlockId, receipt::TypedReceipt, + transaction::TypedTransaction, + }, +}; use bytes::Bytes; use db::KeyValueDB; use ethereum_types::{H256, U256}; use itertools::{Itertools, Position}; use rlp::{Rlp, RlpStream}; -use crate::types::{ - encoded, header::Header, ids::BlockId, receipt::TypedReceipt, transaction::TypedTransaction, - BlockNumber, -}; /// Snapshot creation and restoration for PoA chains. /// Chunk format: @@ -402,7 +406,7 @@ impl Rebuilder for ChunkRebuilder { None => { return Err( Error::WrongChunkFormat("Warp target block not included.".into()).into(), - ) + ); } }; diff --git a/crates/ethcore/src/snapshot/consensus/mod.rs b/crates/ethcore/src/snapshot/consensus/mod.rs index 6b591da99..481dbcc63 100644 --- a/crates/ethcore/src/snapshot/consensus/mod.rs +++ b/crates/ethcore/src/snapshot/consensus/mod.rs @@ -17,12 +17,14 @@ //! Secondary chunk creation and restoration, implementations for different consensus //! engines. -use std::sync::{atomic::AtomicBool, Arc}; - -use crate::blockchain::{BlockChain, BlockChainDB}; -use crate::engines::EthEngine; -use crate::snapshot::{Error, ManifestData, Progress}; -use crate::types::BlockNumber; +use std::sync::{Arc, atomic::AtomicBool}; + +use crate::{ + blockchain::{BlockChain, BlockChainDB}, + engines::EthEngine, + snapshot::{Error, ManifestData, Progress}, + types::BlockNumber, +}; use ethereum_types::H256; diff --git a/crates/ethcore/src/snapshot/consensus/work.rs b/crates/ethcore/src/snapshot/consensus/work.rs index cdaa40440..cb737aea7 100644 --- a/crates/ethcore/src/snapshot/consensus/work.rs +++ b/crates/ethcore/src/snapshot/consensus/work.rs @@ -25,20 +25,22 @@ use super::{ChunkSink, Rebuilder, SnapshotComponents}; use std::{ collections::VecDeque, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, }; -use crate::blockchain::{BlockChain, BlockChainDB, BlockProvider}; +use crate::{ + blockchain::{BlockChain, BlockChainDB, BlockProvider}, + engines::EthEngine, + snapshot::{Error, ManifestData, Progress, block::AbridgedBlock}, + types::{BlockNumber, encoded}, +}; use bytes::Bytes; use db::KeyValueDB; -use crate::engines::EthEngine; use ethereum_types::H256; use rand::rngs::OsRng; use rlp::{Rlp, RlpStream}; -use crate::snapshot::{block::AbridgedBlock, Error, ManifestData, Progress}; -use crate::types::{encoded, BlockNumber}; /// Snapshot creation and restoration for PoW chains. /// This includes blocks from the head of the chain as a @@ -88,7 +90,7 @@ impl SnapshotComponents for PowSnapshot { chain: BlockChain, db: Arc, manifest: &ManifestData, - ) -> Result, crate::error::Error> { + ) -> Result, crate::error::Error> { PowRebuilder::new( chain, db.key_value().clone(), @@ -268,8 +270,8 @@ impl Rebuilder for PowRebuilder { engine: &dyn EthEngine, abort_flag: &AtomicBool, ) -> Result<(), crate::error::Error> { - use ethereum_types::U256; use crate::snapshot::verify_old_block; + use ethereum_types::U256; use triehash::ordered_trie_root; let rlp = Rlp::new(chunk); diff --git a/crates/ethcore/src/snapshot/io.rs b/crates/ethcore/src/snapshot/io.rs index 420d8c273..62b63d0a3 100644 --- a/crates/ethcore/src/snapshot/io.rs +++ b/crates/ethcore/src/snapshot/io.rs @@ -337,8 +337,8 @@ mod tests { use tempdir::TempDir; use super::{ - LooseReader, LooseWriter, PackedReader, PackedWriter, SnapshotReader, SnapshotWriter, - SNAPSHOT_VERSION, + LooseReader, LooseWriter, PackedReader, PackedWriter, SNAPSHOT_VERSION, SnapshotReader, + SnapshotWriter, }; use crate::snapshot::ManifestData; diff --git a/crates/ethcore/src/snapshot/mod.rs b/crates/ethcore/src/snapshot/mod.rs index 71f7cd0b9..bb373fe63 100644 --- a/crates/ethcore/src/snapshot/mod.rs +++ b/crates/ethcore/src/snapshot/mod.rs @@ -19,20 +19,22 @@ //! Documentation of the format can be found at //! https://openethereum.github.io/Warp-Sync-Snapshot-Format -use hash::{keccak, KECCAK_EMPTY, KECCAK_NULL_RLP}; +use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak}; use std::{ cmp, collections::{HashMap, HashSet}, sync::{ - atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}, Arc, + atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}, }, }; -use crate::account_db::{AccountDB, AccountDBMut}; -use crate::blockchain::{BlockChain, BlockProvider}; -use crate::engines::EthEngine; -use crate::types::{header::Header, ids::BlockId}; +use crate::{ + account_db::{AccountDB, AccountDBMut}, + blockchain::{BlockChain, BlockProvider}, + engines::EthEngine, + types::{header::Header, ids::BlockId}, +}; use bytes::Bytes; use db::{DBValue, KeyValueDB}; @@ -50,7 +52,7 @@ use trie::{Trie, TrieMut}; use self::io::SnapshotWriter; use crossbeam_utils::thread; -use rand::{rngs::OsRng, Rng}; +use rand::{Rng, rngs::OsRng}; pub use self::error::Error; @@ -513,7 +515,11 @@ impl StateRebuilder { /// Finalize the restoration. Check for accounts missing code and make a dummy /// journal entry. /// Once all chunks have been fed, there should be nothing missing. - pub fn finalize(mut self, era: u64, id: H256) -> Result, crate::error::Error> { + pub fn finalize( + mut self, + era: u64, + id: H256, + ) -> Result, crate::error::Error> { let missing = self.missing_code.keys().cloned().collect::>(); if !missing.is_empty() { return Err(Error::MissingCode(missing).into()); diff --git a/crates/ethcore/src/snapshot/service.rs b/crates/ethcore/src/snapshot/service.rs index 4703e7d13..52f9f8dbf 100644 --- a/crates/ethcore/src/snapshot/service.rs +++ b/crates/ethcore/src/snapshot/service.rs @@ -23,24 +23,26 @@ use std::{ io::{self, ErrorKind, Read}, path::PathBuf, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, Arc, + atomic::{AtomicBool, AtomicUsize, Ordering}, }, }; use super::{ + CreationStatus, MAX_CHUNK_SIZE, ManifestData, Rebuilder, RestorationStatus, SnapshotService, + StateRebuilder, io::{LooseReader, LooseWriter, SnapshotReader, SnapshotWriter}, - CreationStatus, ManifestData, Rebuilder, RestorationStatus, SnapshotService, StateRebuilder, - MAX_CHUNK_SIZE, }; -use crate::blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler}; -use crate::client::{BlockChainClient, BlockInfo, ChainInfo, Client, ClientIoMessage}; -use crate::engines::EthEngine; -use crate::error::{Error, ErrorKind as SnapshotErrorKind}; +use crate::{ + blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler}, + client::{BlockChainClient, BlockInfo, ChainInfo, Client, ClientIoMessage}, + engines::EthEngine, + error::{Error, ErrorKind as SnapshotErrorKind}, + snapshot::Error as SnapshotError, + types::ids::BlockId, +}; use hash::keccak; -use crate::snapshot::Error as SnapshotError; -use crate::types::ids::BlockId; use crate::io::IoChannel; @@ -558,7 +560,9 @@ impl Service { if let Err(e) = res { if client.chain_info().best_block_number >= num + client.pruning_history() { // The state we were snapshotting was pruned before we could finish. - info!("Periodic snapshot failed: block state pruned. Run with a longer `--pruning-history` or with `--no-periodic-snapshot`"); + info!( + "Periodic snapshot failed: block state pruned. Run with a longer `--pruning-history` or with `--no-periodic-snapshot`" + ); return Err(e); } else { return Err(e); @@ -1011,11 +1015,13 @@ impl Drop for Service { #[cfg(test)] mod tests { use super::*; - use crate::client::ClientIoMessage; - use crate::io::IoService; + use crate::{ + client::ClientIoMessage, + io::IoService, + snapshot::{ManifestData, RestorationStatus, SnapshotService}, + spec::Spec, + }; use journaldb::Algorithm; - use crate::snapshot::{ManifestData, RestorationStatus, SnapshotService}; - use crate::spec::Spec; use tempdir::TempDir; use test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler}; @@ -1098,16 +1104,20 @@ mod tests { let definitely_bad_chunk = [1, 2, 3, 4, 5]; for hash in state_hashes { - assert!(restoration - .feed_state(hash, &definitely_bad_chunk, &flag) - .is_err()); + assert!( + restoration + .feed_state(hash, &definitely_bad_chunk, &flag) + .is_err() + ); assert!(!restoration.is_done()); } for hash in block_hashes { - assert!(restoration - .feed_blocks(hash, &definitely_bad_chunk, &*spec.engine, &flag) - .is_err()); + assert!( + restoration + .feed_blocks(hash, &definitely_bad_chunk, &*spec.engine, &flag) + .is_err() + ); assert!(!restoration.is_done()); } } diff --git a/crates/ethcore/src/snapshot/tests/helpers.rs b/crates/ethcore/src/snapshot/tests/helpers.rs index 3fef6ad23..aa7c3cc74 100644 --- a/crates/ethcore/src/snapshot/tests/helpers.rs +++ b/crates/ethcore/src/snapshot/tests/helpers.rs @@ -22,15 +22,17 @@ extern crate trie_standardmap; use hash::KECCAK_NULL_RLP; use std::sync::Arc; -use crate::account_db::AccountDBMut; -use crate::blockchain::{BlockChain, BlockChainDB}; -use crate::client::{ChainInfo, Client}; -use crate::engines::EthEngine; -use crate::snapshot::{ - io::{PackedReader, PackedWriter, SnapshotReader}, - StateRebuilder, +use crate::{ + account_db::AccountDBMut, + blockchain::{BlockChain, BlockChainDB}, + client::{ChainInfo, Client}, + engines::EthEngine, + snapshot::{ + StateRebuilder, + io::{PackedReader, PackedWriter, SnapshotReader}, + }, + types::basic_account::BasicAccount, }; -use crate::types::basic_account::BasicAccount; use rand::Rng; use tempdir::TempDir; diff --git a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs index 8d480b0c5..407b79073 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -18,14 +18,16 @@ use std::{cell::RefCell, str::FromStr, sync::Arc}; +use crate::{ + client::{BlockChainClient, ChainInfo, Client}, + snapshot::tests::helpers as snapshot_helpers, + spec::Spec, + types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}, +}; use accounts::AccountProvider; -use crate::client::{BlockChainClient, ChainInfo, Client}; use crypto::publickey::Secret; -use crate::snapshot::tests::helpers as snapshot_helpers; -use crate::spec::Spec; use tempdir::TempDir; use test_helpers::generate_dummy_client_with_spec; -use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; use ethereum_types::Address; use test_helpers; diff --git a/crates/ethcore/src/snapshot/tests/proof_of_work.rs b/crates/ethcore/src/snapshot/tests/proof_of_work.rs index 54d0f7438..b4ab5dd32 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_work.rs @@ -20,14 +20,15 @@ use error::{Error, ErrorKind}; use std::sync::atomic::AtomicBool; use tempdir::TempDir; -use crate::blockchain::{ - generator::{BlockBuilder, BlockGenerator}, - BlockChain, ExtrasInsert, -}; -use crate::snapshot::{ - chunk_secondary, - io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, - Error as SnapshotError, Progress, SnapshotComponents, +use crate::{ + blockchain::{ + BlockChain, ExtrasInsert, + generator::{BlockBuilder, BlockGenerator}, + }, + snapshot::{ + Error as SnapshotError, Progress, SnapshotComponents, chunk_secondary, + io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, + }, }; use kvdb::DBTransaction; diff --git a/crates/ethcore/src/snapshot/tests/service.rs b/crates/ethcore/src/snapshot/tests/service.rs index df7cb9697..25581ea05 100644 --- a/crates/ethcore/src/snapshot/tests/service.rs +++ b/crates/ethcore/src/snapshot/tests/service.rs @@ -18,25 +18,25 @@ use std::{fs, sync::Arc}; -use crate::blockchain::BlockProvider; -use crate::client::{BlockInfo, Client, ClientConfig, ImportBlock}; -use crate::snapshot::{ - chunk_secondary, chunk_state, - io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, - service::{Service, ServiceParams}, - ManifestData, Progress, RestorationStatus, SnapshotService, +use crate::{ + blockchain::BlockProvider, + client::{BlockInfo, Client, ClientConfig, ImportBlock}, + snapshot::{ + ManifestData, Progress, RestorationStatus, SnapshotService, chunk_secondary, chunk_state, + io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, + service::{Service, ServiceParams}, + }, + spec::Spec, + types::ids::BlockId, }; -use crate::spec::Spec; use tempdir::TempDir; use test_helpers::{ generate_dummy_client_with_spec_and_data, new_db, new_temp_db, restoration_db_handler, }; -use crate::types::ids::BlockId; -use crate::io::IoChannel; +use crate::{io::IoChannel, verification::queue::kind::blocks::Unverified}; use kvdb_rocksdb::DatabaseConfig; use parking_lot::Mutex; -use crate::verification::queue::kind::blocks::Unverified; use crate::exit::ShutdownManager; @@ -292,9 +292,11 @@ fn keep_ancient_blocks() { // Check that we have blocks in [NUM_BLOCKS - NUM_SNAPSHOT_BLOCKS + 1 ; NUM_BLOCKS] // but none before - assert!(client2 - .block(BlockId::Number(NUM_BLOCKS - NUM_SNAPSHOT_BLOCKS + 1)) - .is_some()); + assert!( + client2 + .block(BlockId::Number(NUM_BLOCKS - NUM_SNAPSHOT_BLOCKS + 1)) + .is_some() + ); assert!(client2.block(BlockId::Number(100)).is_none()); // Check that the first 50 blocks have been migrated diff --git a/crates/ethcore/src/snapshot/tests/state.rs b/crates/ethcore/src/snapshot/tests/state.rs index d70210303..e95974a87 100644 --- a/crates/ethcore/src/snapshot/tests/state.rs +++ b/crates/ethcore/src/snapshot/tests/state.rs @@ -18,16 +18,17 @@ extern crate rand_xorshift; -use hash::{keccak, KECCAK_NULL_RLP}; -use std::sync::{atomic::AtomicBool, Arc}; +use hash::{KECCAK_NULL_RLP, keccak}; +use std::sync::{Arc, atomic::AtomicBool}; use super::helpers::StateProducer; -use crate::snapshot::{ - account, chunk_state, - io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, - Error as SnapshotError, Progress, StateRebuilder, SNAPSHOT_SUBPARTS, +use crate::{ + snapshot::{ + Error as SnapshotError, Progress, SNAPSHOT_SUBPARTS, StateRebuilder, account, chunk_state, + io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}, + }, + types::basic_account::BasicAccount, }; -use crate::types::basic_account::BasicAccount; use error::{Error, ErrorKind}; diff --git a/crates/ethcore/src/snapshot/watcher.rs b/crates/ethcore/src/snapshot/watcher.rs index 1a54e25b5..e53d4ed5e 100644 --- a/crates/ethcore/src/snapshot/watcher.rs +++ b/crates/ethcore/src/snapshot/watcher.rs @@ -16,12 +16,14 @@ //! Watcher for snapshot-related chain events. -use crate::client::{BlockInfo, ChainNotify, Client, ClientIoMessage, NewBlocks}; +use crate::{ + client::{BlockInfo, ChainNotify, Client, ClientIoMessage, NewBlocks}, + types::ids::BlockId, +}; use parking_lot::Mutex; -use crate::types::ids::BlockId; -use ethereum_types::H256; use crate::io::IoChannel; +use ethereum_types::H256; use std::sync::Arc; diff --git a/crates/ethcore/src/spec/genesis.rs b/crates/ethcore/src/spec/genesis.rs index 301cd8fb1..8cc583b92 100644 --- a/crates/ethcore/src/spec/genesis.rs +++ b/crates/ethcore/src/spec/genesis.rs @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::spec::seal::Seal; use ethereum_types::{Address, H256, U256}; use ethjson; use hash::KECCAK_NULL_RLP; -use crate::spec::seal::Seal; /// Genesis components. pub struct Genesis { diff --git a/crates/ethcore/src/spec/seal.rs b/crates/ethcore/src/spec/seal.rs index 33d69b121..e45e97953 100644 --- a/crates/ethcore/src/spec/seal.rs +++ b/crates/ethcore/src/spec/seal.rs @@ -16,7 +16,7 @@ //! Spec seal. -use ethereum_types::{H256, H520, H64}; +use ethereum_types::{H64, H256, H520}; use ethjson; use rlp::RlpStream; diff --git a/crates/ethcore/src/spec/spec.rs b/crates/ethcore/src/spec/spec.rs index c645426a9..9c1630e11 100644 --- a/crates/ethcore/src/spec/spec.rs +++ b/crates/ethcore/src/spec/spec.rs @@ -24,30 +24,32 @@ use std::{ sync::Arc, }; +use crate::types::{BlockNumber, header::Header}; use bytes::Bytes; use ethereum_types::{Address, Bloom, H160, H256, U256}; use ethjson; -use hash::{keccak, KECCAK_NULL_RLP}; +use hash::{KECCAK_NULL_RLP, keccak}; use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use rustc_hex::FromHex; -use crate::types::{header::Header, BlockNumber}; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; -use builtin::Builtin; -use crate::engines::{ - AuthorityRound, BasicAuthority, Clique, EthEngine, HoneyBadgerBFT, InstantSeal, - InstantSealParams, NullEngine, DEFAULT_BLOCKHASH_CONTRACT, +use crate::{ + engines::{ + AuthorityRound, BasicAuthority, Clique, DEFAULT_BLOCKHASH_CONTRACT, EthEngine, + HoneyBadgerBFT, InstantSeal, InstantSealParams, NullEngine, + }, + error::Error, + executive::Executive, + factory::Factories, + machine::EthereumMachine, + pod_state::PodState, + spec::{Genesis, seal::Generic as GenericSeal}, + state::{Backend, State, Substate, backend::Basic as BasicBackend}, + trace::{NoopTracer, NoopVMTracer}, }; -use crate::error::Error; -use crate::executive::Executive; -use crate::factory::Factories; -use crate::machine::EthereumMachine; +use builtin::Builtin; use maplit::btreeset; -use crate::pod_state::PodState; -use crate::spec::{seal::Generic as GenericSeal, Genesis}; -use crate::state::{backend::Basic as BasicBackend, Backend, State, Substate}; -use crate::trace::{NoopTracer, NoopVMTracer}; pub use ethash::OptimizeFor; @@ -1236,12 +1238,14 @@ impl Spec { #[cfg(test)] mod tests { use super::*; + use crate::{ + state::State, + types::{view, views::BlockView}, + }; use ethereum_types::{H160, H256}; - use crate::state::State; use std::str::FromStr; use tempdir::TempDir; use test_helpers::get_temp_state_db; - use crate::types::{view, views::BlockView}; #[test] fn test_load_empty() { diff --git a/crates/ethcore/src/state/account.rs b/crates/ethcore/src/state/account.rs index da6c09012..b59f025bd 100644 --- a/crates/ethcore/src/state/account.rs +++ b/crates/ethcore/src/state/account.rs @@ -16,24 +16,22 @@ //! Single account in the system. +use crate::{error::Error, pod_account::*, types::basic_account::BasicAccount}; use bytes::{Bytes, ToPretty}; -use crate::error::Error; use ethereum_types::{Address, BigEndianHash, H256, U256}; use ethtrie::{Result as TrieResult, SecTrieDB, TrieDB, TrieFactory}; -use hash::{keccak, KECCAK_EMPTY, KECCAK_NULL_RLP}; +use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak}; use hash_db::HashDB; use keccak_hasher::KeccakHasher; use kvdb::DBValue; use lru_cache::LruCache; -use crate::pod_account::*; -use rlp::{encode, RlpStream}; +use rlp::{RlpStream, encode}; use std::{ collections::{BTreeMap, HashMap}, fmt, sync::Arc, }; use trie::{Recorder, Trie}; -use crate::types::basic_account::BasicAccount; use std::cell::{Cell, RefCell}; @@ -252,14 +250,12 @@ impl Account { return Ok(value); } match &self.original_storage_cache { - Some((original_storage_root, original_storage_cache)) => { - Self::get_and_cache_storage( - original_storage_root, - &mut original_storage_cache.borrow_mut(), - db, - key, - ) - } + Some((original_storage_root, original_storage_cache)) => Self::get_and_cache_storage( + original_storage_root, + &mut original_storage_cache.borrow_mut(), + db, + key, + ), None => Self::get_and_cache_storage( &self.storage_root, &mut self.storage_cache.borrow_mut(), @@ -844,7 +840,10 @@ mod tests { #[test] fn new_account() { let a = Account::new(69u8.into(), 0u8.into(), HashMap::new(), Bytes::new()); - assert_eq!(a.rlp().to_hex(), "f8448045a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"); + assert_eq!( + a.rlp().to_hex(), + "f8448045a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" + ); assert_eq!(*a.balance(), 69u8.into()); assert_eq!(*a.nonce(), 0u8.into()); assert_eq!(a.code_hash(), KECCAK_EMPTY); diff --git a/crates/ethcore/src/state/backend.rs b/crates/ethcore/src/state/backend.rs index 301aca962..ca790ddc8 100644 --- a/crates/ethcore/src/state/backend.rs +++ b/crates/ethcore/src/state/backend.rs @@ -26,6 +26,7 @@ use std::{ sync::Arc, }; +use crate::state::Account; use ethereum_types::{Address, H256}; use hash_db::{AsHashDB, HashDB}; use journaldb::AsKeyedHashDB; @@ -33,7 +34,6 @@ use keccak_hasher::KeccakHasher; use kvdb::DBValue; use memory_db::MemoryDB; use parking_lot::Mutex; -use crate::state::Account; /// State backend. See module docs for more details. pub trait Backend: Send { diff --git a/crates/ethcore/src/state/mod.rs b/crates/ethcore/src/state/mod.rs index fbd8d9a9d..51e9e1e75 100644 --- a/crates/ethcore/src/state/mod.rs +++ b/crates/ethcore/src/state/mod.rs @@ -22,25 +22,27 @@ use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP}; use std::{ cell::{RefCell, RefMut}, - collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap, HashSet}, + collections::{BTreeMap, BTreeSet, HashMap, HashSet, hash_map::Entry}, fmt, sync::Arc, }; -use crate::error::Error; -use crate::executed::{Executed, ExecutionError}; -use crate::executive::{Executive, TransactOptions}; -use crate::factory::{Factories, VmFactory}; -use crate::machine::EthereumMachine as Machine; -use crate::pod_account::*; -use crate::pod_state::{self, PodState}; -use crate::state_db::StateDB; -use crate::trace::{self, FlatTrace, VMTrace}; -use crate::types::{ - basic_account::BasicAccount, - receipt::{LegacyReceipt, TransactionOutcome, TypedReceipt}, - state_diff::StateDiff, - transaction::SignedTransaction, +use crate::{ + error::Error, + executed::{Executed, ExecutionError}, + executive::{Executive, TransactOptions}, + factory::{Factories, VmFactory}, + machine::EthereumMachine as Machine, + pod_account::*, + pod_state::{self, PodState}, + state_db::StateDB, + trace::{self, FlatTrace, VMTrace}, + types::{ + basic_account::BasicAccount, + receipt::{LegacyReceipt, TransactionOutcome, TypedReceipt}, + state_diff::StateDiff, + transaction::SignedTransaction, + }, }; use vm::EnvInfo; @@ -664,7 +666,7 @@ impl State { } // The account didn't exist at that point. Return empty value. Some(Some(AccountEntry { account: None, .. })) => { - return Ok(Some(H256::default())) + return Ok(Some(H256::default())); } // The value was not cached at that checkpoint, meaning it was not modified at all. Some(None) => { @@ -1574,17 +1576,19 @@ impl Clone for State { #[cfg(test)] mod tests { use super::*; + use crate::{ + machine::EthereumMachine, + spec::*, + trace::{FlatTrace, TraceError, trace}, + types::transaction::*, + }; use crypto::publickey::Secret; use ethereum_types::{Address, BigEndianHash, H256, U256}; use evm::CallType; - use hash::{keccak, KECCAK_NULL_RLP}; - use crate::machine::EthereumMachine; + use hash::{KECCAK_NULL_RLP, keccak}; use rustc_hex::FromHex; - use crate::spec::*; use std::{str::FromStr, sync::Arc}; use test_helpers::{get_temp_state, get_temp_state_db}; - use crate::trace::{trace, FlatTrace, TraceError}; - use crate::types::transaction::*; use vm::EnvInfo; fn secret() -> Secret { diff --git a/crates/ethcore/src/state/substate.rs b/crates/ethcore/src/state/substate.rs index 3c61c4265..441bbe76e 100644 --- a/crates/ethcore/src/state/substate.rs +++ b/crates/ethcore/src/state/substate.rs @@ -16,10 +16,10 @@ //! Execution environment substate. use super::CleanupMode; +use crate::types::log_entry::LogEntry; use ethereum_types::Address; use evm::{CleanDustMode, Schedule}; use std::collections::HashSet; -use crate::types::log_entry::LogEntry; use vm::access_list::AccessList; /// State changes which should be applied in finalize, @@ -88,8 +88,8 @@ impl Substate { #[cfg(test)] mod tests { use super::Substate; - use ethereum_types::Address; use crate::types::log_entry::LogEntry; + use ethereum_types::Address; #[test] fn created() { diff --git a/crates/ethcore/src/state_db.rs b/crates/ethcore/src/state_db.rs index cd9ab1ff7..01e7118ad 100644 --- a/crates/ethcore/src/state_db.rs +++ b/crates/ethcore/src/state_db.rs @@ -22,6 +22,7 @@ use std::{ sync::Arc, }; +use crate::types::BlockNumber; use ethereum_types::{Address, H256}; use hash_db::HashDB; use journaldb::JournalDB; @@ -30,7 +31,6 @@ use kvdb::{DBTransaction, DBValue}; use lru_cache::LruCache; use memory_cache::MemoryLruCache; use parking_lot::Mutex; -use crate::types::BlockNumber; use crate::state::{self, Account}; @@ -168,10 +168,7 @@ impl StateDB { pub fn sync_cache(&mut self, enacted: &[H256], retracted: &[H256], is_best: bool) { trace!( "sync_cache id = (#{:?}, {:?}), parent={:?}, best={}", - self.commit_number, - self.commit_hash, - self.parent_hash, - is_best + self.commit_number, self.commit_hash, self.parent_hash, is_best ); let mut cache = self.account_cache.lock(); let cache = &mut *cache; @@ -445,9 +442,9 @@ unsafe impl Sync for SyncAccount {} #[cfg(test)] mod tests { + use crate::state::{Account, Backend}; use ethereum_types::{Address, H256, U256}; use kvdb::DBTransaction; - use crate::state::{Account, Backend}; use test_helpers::get_temp_state_db; #[test] diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index 3da2d918d..8262f87d4 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -18,8 +18,18 @@ use std::{fs, io, path::Path, sync::Arc}; -use crate::blockchain::{ - BlockChain, BlockChainDB, BlockChainDBHandler, Config as BlockChainConfig, ExtrasInsert, +use crate::{ + blockchain::{ + BlockChain, BlockChainDB, BlockChainDBHandler, Config as BlockChainConfig, ExtrasInsert, + }, + io::IoChannel, + types::{ + BlockNumber, encoded, + header::Header, + transaction::{Action, SignedTransaction, Transaction, TypedTransaction}, + view, + views::BlockView, + }, }; use blooms_db; use bytes::Bytes; @@ -28,33 +38,26 @@ use db::KeyValueDB; use ethereum_types::{Address, H256, H512, U256}; use evm::Factory as EvmFactory; use hash::keccak; -use crate::io::IoChannel; use kvdb_rocksdb::{self, Database, DatabaseConfig}; use parking_lot::RwLock; use rlp::{self, RlpStream}; use tempdir::TempDir; -use crate::types::{ - encoded, - header::Header, - transaction::{Action, SignedTransaction, Transaction, TypedTransaction}, - view, - views::BlockView, - BlockNumber, -}; -use crate::block::{Drain, OpenBlock}; -use crate::client::{ - BlockInfo, ChainInfo, ChainMessageType, ChainNotify, Client, ClientConfig, ImportBlock, - PrepareOpenBlock, +use crate::{ + block::{Drain, OpenBlock}, + client::{ + BlockInfo, ChainInfo, ChainMessageType, ChainNotify, Client, ClientConfig, ImportBlock, + PrepareOpenBlock, + }, + engines::{EngineSigner, Seal}, + factory::Factories, + spec::Spec, + state::*, + verification::queue::kind::blocks::Unverified, }; -use crate::engines::{EngineSigner, Seal}; use ethjson::crypto::publickey::{Public, Signature}; -use crate::factory::Factories; use miner::Miner; -use crate::spec::Spec; -use crate::state::*; use state_db::StateDB; -use crate::verification::queue::kind::blocks::Unverified; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index a31dfb262..739b0c7de 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -15,41 +15,44 @@ // along with OpenEthereum. If not, see . use std::{ - str::{from_utf8, FromStr}, + str::{FromStr, from_utf8}, sync::Arc, }; -use crate::client::{ - traits::{ - BlockChainClient, BlockChainReset, BlockInfo, ChainInfo, ImportBlock, ImportExportBlocks, +use crate::{ + client::{ + Client, ClientConfig, ImportSealedBlock, PrepareOpenBlock, + traits::{ + BlockChainClient, BlockChainReset, BlockInfo, ChainInfo, ImportBlock, + ImportExportBlocks, + }, }, - Client, ClientConfig, ImportSealedBlock, PrepareOpenBlock, + executive::{Executive, TransactOptions}, + io::IoChannel, + spec::Spec, + state::{self, CleanupMode, State, StateInfo}, + types::{ + data_format::DataFormat, + filter::Filter, + ids::BlockId, + transaction::{Action, Condition, PendingTransaction, Transaction, TypedTransaction}, + view, + views::BlockView, + }, + verification::queue::kind::blocks::Unverified, }; use crypto::publickey::KeyPair; use ethereum; use ethereum_types::{Address, U256}; -use crate::executive::{Executive, TransactOptions}; use hash::keccak; -use crate::io::IoChannel; use miner::{Miner, MinerService, PendingOrdering}; use rustc_hex::ToHex; -use crate::spec::Spec; -use crate::state::{self, CleanupMode, State, StateInfo}; use tempdir::TempDir; use test_helpers::{ self, generate_dummy_client, generate_dummy_client_with_data, get_bad_state_dummy_block, get_good_dummy_block, get_good_dummy_block_seq, get_test_client_with_blocks, push_blocks_to_client, }; -use crate::types::{ - data_format::DataFormat, - filter::Filter, - ids::BlockId, - transaction::{Action, Condition, PendingTransaction, Transaction, TypedTransaction}, - view, - views::BlockView, -}; -use crate::verification::queue::kind::blocks::Unverified; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index 3e698ca97..6df5847f5 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -16,14 +16,16 @@ //! Tests of EVM integration with transaction execution. +use crate::{ + executive::Executive, + state::Substate, + trace::{NoopTracer, NoopVMTracer}, + types::transaction::SYSTEM_ADDRESS, +}; use evm::{Factory, VMType}; -use crate::executive::Executive; use hash::keccak; -use crate::state::Substate; use std::sync::Arc; use test_helpers::get_temp_state_with_factory; -use crate::trace::{NoopTracer, NoopVMTracer}; -use crate::types::transaction::SYSTEM_ADDRESS; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; use rustc_hex::FromHex; diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index 836fa1493..2fd18b63f 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -16,24 +16,26 @@ //! Client tests of tracing -use crate::block::*; -use crate::client::{BlockChainClient, Client, ClientConfig, *}; +use crate::{ + block::*, + client::{BlockChainClient, Client, ClientConfig, *}, + io::*, + spec::*, + trace::{LocalizedTrace, RewardType, trace::Action::Reward}, + types::{ + header::Header, + transaction::{Action, Transaction, TypedTransaction}, + view, + views::BlockView, + }, + verification::queue::kind::blocks::Unverified, +}; use crypto::publickey::KeyPair; use ethereum_types::{Address, U256}; use hash::keccak; -use crate::io::*; use miner::Miner; -use crate::spec::*; use std::{str::FromStr, sync::Arc}; use test_helpers::{self, get_temp_state_db}; -use crate::trace::{trace::Action::Reward, LocalizedTrace, RewardType}; -use crate::types::{ - header::Header, - transaction::{Action, Transaction, TypedTransaction}, - view, - views::BlockView, -}; -use crate::verification::queue::kind::blocks::Unverified; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/trace/db.rs b/crates/ethcore/src/trace/db.rs index 5d1b7da04..df08c87c9 100644 --- a/crates/ethcore/src/trace/db.rs +++ b/crates/ethcore/src/trace/db.rs @@ -17,17 +17,16 @@ //! Trace database. use std::{collections::HashMap, sync::Arc}; -use crate::blockchain::BlockChainDB; -use db::{self, cache_manager::CacheManager, CacheUpdatePolicy, Key, Readable, Writable}; +use crate::{blockchain::BlockChainDB, types::BlockNumber}; +use db::{self, CacheUpdatePolicy, Key, Readable, Writable, cache_manager::CacheManager}; use ethereum_types::{H256, H264}; use kvdb::DBTransaction; use parity_util_mem::MallocSizeOfExt; use parking_lot::RwLock; -use crate::types::BlockNumber; use crate::trace::{ - flat::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}, Config, Database as TraceDatabase, DatabaseExtras, Filter, ImportRequest, LocalizedTrace, + flat::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}, }; const TRACE_DB_VER: &'static [u8] = b"1.0"; @@ -406,18 +405,20 @@ where #[cfg(test)] mod tests { + use crate::{ + trace::{ + AddressesFilter, Config, Database as TraceDatabase, DatabaseExtras, Filter, + ImportRequest, LocalizedTrace, TraceDB, TraceError, + flat::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}, + trace::{Action, Call, Res}, + }, + types::BlockNumber, + }; use ethereum_types::{Address, H256, U256}; use evm::CallType; use kvdb::DBTransaction; use std::{collections::HashMap, sync::Arc}; use test_helpers::new_db; - use crate::trace::{ - flat::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}, - trace::{Action, Call, Res}, - AddressesFilter, Config, Database as TraceDatabase, DatabaseExtras, Filter, ImportRequest, - LocalizedTrace, TraceDB, TraceError, - }; - use crate::types::BlockNumber; struct NoopExtras; diff --git a/crates/ethcore/src/trace/executive_tracer.rs b/crates/ethcore/src/trace/executive_tracer.rs index 190f25e42..b8f791016 100644 --- a/crates/ethcore/src/trace/executive_tracer.rs +++ b/crates/ethcore/src/trace/executive_tracer.rs @@ -16,16 +16,16 @@ //! Simple executive tracer. -use ethereum_types::{Address, U256}; -use log::{debug, warn}; -use std::cmp::min; use crate::trace::{ + FlatTrace, Tracer, VMTracer, trace::{ Action, Call, CallResult, Create, CreateResult, MemoryDiff, Res, Reward, RewardType, StorageDiff, Suicide, VMExecutedOperation, VMOperation, VMTrace, }, - FlatTrace, Tracer, VMTracer, }; +use ethereum_types::{Address, U256}; +use log::{debug, warn}; +use std::cmp::min; use vm::{ActionParams, Error as VmError}; /// Simple executive tracer. Traces all calls and creates. Ignores delegatecalls. @@ -42,7 +42,10 @@ impl Tracer for ExecutiveTracer { type Output = FlatTrace; fn prepare_trace_call(&mut self, params: &ActionParams, depth: usize, is_builtin: bool) { - assert!(!self.skip_one, "skip_one is used only for builtin contracts that do not have subsequent calls; in prepare_trace_call it cannot be true; qed"); + assert!( + !self.skip_one, + "skip_one is used only for builtin contracts that do not have subsequent calls; in prepare_trace_call it cannot be true; qed" + ); if depth != 0 && is_builtin && params.value.value() == U256::zero() { self.skip_one = true; @@ -69,7 +72,10 @@ impl Tracer for ExecutiveTracer { } fn prepare_trace_create(&mut self, params: &ActionParams) { - assert!(!self.skip_one, "skip_one is used only for builtin contracts that do not have subsequent calls; in prepare_trace_create it cannot be true; qed"); + assert!( + !self.skip_one, + "skip_one is used only for builtin contracts that do not have subsequent calls; in prepare_trace_create it cannot be true; qed" + ); if let Some(parentlen) = self.sublen_stack.last_mut() { *parentlen += 1; @@ -113,7 +119,10 @@ impl Tracer for ExecutiveTracer { } fn done_trace_create(&mut self, gas_used: U256, code: &[u8], address: Address) { - assert!(!self.skip_one, "skip_one is only set with prepare_trace_call for builtin contracts with no subsequent calls; skip_one cannot be true after the same level prepare_trace_create; qed"); + assert!( + !self.skip_one, + "skip_one is only set with prepare_trace_call for builtin contracts with no subsequent calls; skip_one cannot be true after the same level prepare_trace_create; qed" + ); let vecindex = self.vecindex_stack.pop().expect("Executive invoked prepare_trace_create before this function; vecindex_stack is never empty; qed"); let sublen = self.sublen_stack.pop().expect("Executive invoked prepare_trace_create before this function; sublen_stack is never empty; qed"); diff --git a/crates/ethcore/src/trace/import.rs b/crates/ethcore/src/trace/import.rs index dbe7362f9..1c782f1ae 100644 --- a/crates/ethcore/src/trace/import.rs +++ b/crates/ethcore/src/trace/import.rs @@ -15,8 +15,8 @@ // along with OpenEthereum. If not, see . //! Traces import request. -use ethereum_types::H256; use crate::types::BlockNumber; +use ethereum_types::H256; use crate::trace::FlatBlockTraces; diff --git a/crates/ethcore/src/trace/mod.rs b/crates/ethcore/src/trace/mod.rs index 5163adda2..4ca7c2f54 100644 --- a/crates/ethcore/src/trace/mod.rs +++ b/crates/ethcore/src/trace/mod.rs @@ -33,6 +33,7 @@ pub use self::{ }; pub use self::types::{ + Tracing, error::Error as TraceError, filter, filter::{AddressesFilter, Filter}, @@ -40,12 +41,11 @@ pub use self::types::{ flat::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}, localized, trace, trace::{MemoryDiff, RewardType, StorageDiff, VMExecutedOperation, VMOperation, VMTrace}, - Tracing, }; +use crate::types::BlockNumber; use ethereum_types::{Address, H256, U256}; use kvdb::DBTransaction; -use crate::types::BlockNumber; use vm::{ActionParams, Error as VmError}; /// This trait is used by executive to build traces. diff --git a/crates/ethcore/src/trace/noop_tracer.rs b/crates/ethcore/src/trace/noop_tracer.rs index 64f71bc0f..c967f61d7 100644 --- a/crates/ethcore/src/trace/noop_tracer.rs +++ b/crates/ethcore/src/trace/noop_tracer.rs @@ -16,11 +16,11 @@ //! Nonoperative tracer. -use ethereum_types::{Address, U256}; use crate::trace::{ - trace::{RewardType, VMTrace}, FlatTrace, Tracer, VMTracer, + trace::{RewardType, VMTrace}, }; +use ethereum_types::{Address, U256}; use vm::{ActionParams, Error as VmError}; /// Nonoperative tracer. Does not trace anything. diff --git a/crates/ethcore/src/trace/types/filter.rs b/crates/ethcore/src/trace/types/filter.rs index 30b9a9f65..d8fe43928 100644 --- a/crates/ethcore/src/trace/types/filter.rs +++ b/crates/ethcore/src/trace/types/filter.rs @@ -17,9 +17,9 @@ //! Trace filters type definitions use super::trace::{Action, Res}; +use crate::trace::flat::FlatTrace; use ethereum_types::{Address, Bloom, BloomInput}; use std::ops::Range; -use crate::trace::flat::FlatTrace; /// Addresses filter. /// @@ -132,13 +132,13 @@ impl Filter { #[cfg(test)] mod tests { - use ethereum_types::{Address, Bloom, BloomInput}; - use evm::CallType; use crate::trace::{ + AddressesFilter, Filter, RewardType, TraceError, flat::FlatTrace, trace::{Action, Call, Create, CreateResult, Res, Reward, Suicide}, - AddressesFilter, Filter, RewardType, TraceError, }; + use ethereum_types::{Address, Bloom, BloomInput}; + use evm::CallType; #[test] fn empty_trace_filter_bloom_possibilities() { diff --git a/crates/ethcore/src/trace/types/flat.rs b/crates/ethcore/src/trace/types/flat.rs index 0c03541ac..0a6094052 100644 --- a/crates/ethcore/src/trace/types/flat.rs +++ b/crates/ethcore/src/trace/types/flat.rs @@ -126,12 +126,12 @@ impl Into> for FlatBlockTraces { #[cfg(test)] mod tests { use super::{FlatBlockTraces, FlatTrace, FlatTransactionTraces}; - use evm::CallType; - use rlp::*; use crate::trace::{ - trace::{Action, Call, CallResult, Res, Reward, Suicide}, RewardType, + trace::{Action, Call, CallResult, Res, Reward, Suicide}, }; + use evm::CallType; + use rlp::*; #[test] fn encode_flat_transaction_traces() { diff --git a/crates/ethcore/src/trace/types/localized.rs b/crates/ethcore/src/trace/types/localized.rs index 35141c99b..405e55819 100644 --- a/crates/ethcore/src/trace/types/localized.rs +++ b/crates/ethcore/src/trace/types/localized.rs @@ -17,8 +17,8 @@ //! Localized traces type definitions use super::trace::{Action, Res}; -use ethereum_types::H256; use crate::types::BlockNumber; +use ethereum_types::H256; /// Localized trace. #[derive(Debug, PartialEq, Clone)] diff --git a/crates/ethcore/src/transaction_ext.rs b/crates/ethcore/src/transaction_ext.rs index 041b37349..a9ac17918 100644 --- a/crates/ethcore/src/transaction_ext.rs +++ b/crates/ethcore/src/transaction_ext.rs @@ -16,8 +16,8 @@ //! Ethereum transaction -use evm::Schedule; use crate::types::transaction::{self, Action}; +use evm::Schedule; /// Extends transaction with gas verification method. pub trait Transaction { diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 6a260db9d..d4fa69a7d 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -20,18 +20,20 @@ use std::num::NonZeroUsize; use ethabi::FunctionOutputDecoder; use ethereum_types::{Address, H256, U256}; -use fastmap::{new_h256_fast_lru_map, H256FastLruMap}; +use fastmap::{H256FastLruMap, new_h256_fast_lru_map}; use lru_cache::LruCache; +use crate::{ + client::{BlockId, BlockInfo}, + spec::CommonParams, + types::{ + BlockNumber, + transaction::{Action, SignedTransaction}, + }, +}; use call_contract::CallContract; -use crate::client::{BlockId, BlockInfo}; use hash::KECCAK_EMPTY; use parking_lot::Mutex; -use crate::spec::CommonParams; -use crate::types::{ - transaction::{Action, SignedTransaction}, - BlockNumber, -}; use_contract!( transact_acl_deprecated, @@ -280,18 +282,20 @@ mod test { use crate::exit::ShutdownManager; use super::TransactionFilter; - use crate::client::{BlockChainClient, BlockId, Client, ClientConfig}; + use crate::{ + client::{BlockChainClient, BlockId, Client, ClientConfig}, + io::IoChannel, + spec::Spec, + types::transaction::{ + AccessListTx, Action, EIP1559TransactionTx, Transaction, TypedTransaction, + }, + }; use crypto::publickey::{KeyPair, Secret}; use ethereum_types::{Address, U256}; - use crate::io::IoChannel; use miner::Miner; - use crate::spec::Spec; use std::{str::FromStr, sync::Arc}; use tempdir::TempDir; use test_helpers; - use crate::types::transaction::{ - AccessListTx, Action, EIP1559TransactionTx, Transaction, TypedTransaction, - }; /// Contract code: https://gist.github.com/VladLupashevskyi/84f18eabb1e4afadf572cf92af3e7e7f #[test] @@ -485,14 +489,16 @@ mod test { &*client )); - assert!(!filter.transaction_allowed( - &genesis, - block_number, - &basic_tx_with_ether_and_to_key7 - .clone() - .sign(key5.secret(), None), - &*client - )); + assert!( + !filter.transaction_allowed( + &genesis, + block_number, + &basic_tx_with_ether_and_to_key7 + .clone() + .sign(key5.secret(), None), + &*client + ) + ); assert!(!filter.transaction_allowed( &genesis, block_number, @@ -505,28 +511,32 @@ mod test { &basic_tx.clone().sign(key6.secret(), None), &*client )); - assert!(filter.transaction_allowed( - &genesis, - block_number, - &basic_tx_with_ether_and_to_key7 - .clone() - .sign(key6.secret(), None), - &*client - )); + assert!( + filter.transaction_allowed( + &genesis, + block_number, + &basic_tx_with_ether_and_to_key7 + .clone() + .sign(key6.secret(), None), + &*client + ) + ); assert!(filter.transaction_allowed( &genesis, block_number, &basic_tx_to_key6.clone().sign(key7.secret(), None), &*client )); - assert!(!filter.transaction_allowed( - &genesis, - block_number, - &basic_tx_with_ether_and_to_key6 - .clone() - .sign(key7.secret(), None), - &*client - )); + assert!( + !filter.transaction_allowed( + &genesis, + block_number, + &basic_tx_with_ether_and_to_key6 + .clone() + .sign(key7.secret(), None), + &*client + ) + ); } /// Contract code: res/chainspec/test/contract_ver_3.sol diff --git a/crates/ethcore/src/verification/canon_verifier.rs b/crates/ethcore/src/verification/canon_verifier.rs index d3f5b667a..7ac220d3f 100644 --- a/crates/ethcore/src/verification/canon_verifier.rs +++ b/crates/ethcore/src/verification/canon_verifier.rs @@ -16,12 +16,9 @@ //! Canonical verifier. -use super::{verification, Verifier}; +use super::{Verifier, verification}; +use crate::{client::BlockInfo, engines::EthEngine, error::Error, types::header::Header}; use call_contract::CallContract; -use crate::client::BlockInfo; -use crate::engines::EthEngine; -use crate::error::Error; -use crate::types::header::Header; /// A canonial verifier -- this does full verification. pub struct CanonVerifier; diff --git a/crates/ethcore/src/verification/mod.rs b/crates/ethcore/src/verification/mod.rs index ab65b062a..9272067ed 100644 --- a/crates/ethcore/src/verification/mod.rs +++ b/crates/ethcore/src/verification/mod.rs @@ -30,8 +30,8 @@ pub use self::{ verifier::Verifier, }; -use call_contract::CallContract; use crate::client::BlockInfo; +use call_contract::CallContract; /// Verifier type. #[derive(Debug, PartialEq, Clone)] diff --git a/crates/ethcore/src/verification/noop_verifier.rs b/crates/ethcore/src/verification/noop_verifier.rs index 8ec0d7f2e..631fb6125 100644 --- a/crates/ethcore/src/verification/noop_verifier.rs +++ b/crates/ethcore/src/verification/noop_verifier.rs @@ -16,12 +16,9 @@ //! No-op verifier. -use super::{verification, Verifier}; +use super::{Verifier, verification}; +use crate::{client::BlockInfo, engines::EthEngine, error::Error, types::header::Header}; use call_contract::CallContract; -use crate::client::BlockInfo; -use crate::engines::EthEngine; -use crate::error::Error; -use crate::types::header::Header; /// A no-op verifier -- this will verify everything it's given immediately. #[allow(dead_code)] diff --git a/crates/ethcore/src/verification/queue/kind.rs b/crates/ethcore/src/verification/queue/kind.rs index 75f544e02..2edac39b1 100644 --- a/crates/ethcore/src/verification/queue/kind.rs +++ b/crates/ethcore/src/verification/queue/kind.rs @@ -16,8 +16,7 @@ //! Definition of valid items for the verification queue. -use crate::engines::EthEngine; -use crate::error::Error; +use crate::{engines::EthEngine, error::Error}; use ethereum_types::{H256, U256}; use parity_util_mem::MallocSizeOf; @@ -78,14 +77,16 @@ pub trait Kind: 'static + Sized + Send + Sync { pub mod blocks { use super::{BlockLike, Kind}; - use crate::engines::EthEngine; - use crate::error::{BlockError, Error, ErrorKind}; - use crate::types::{ - header::Header, - transaction::{TypedTransaction, UnverifiedTransaction}, - BlockNumber, + use crate::{ + engines::EthEngine, + error::{BlockError, Error, ErrorKind}, + types::{ + BlockNumber, + header::Header, + transaction::{TypedTransaction, UnverifiedTransaction}, + }, + verification::{PreverifiedBlock, verify_block_basic, verify_block_unordered}, }; - use crate::verification::{verify_block_basic, verify_block_unordered, PreverifiedBlock}; use bytes::Bytes; use ethereum_types::{H256, U256}; @@ -213,10 +214,9 @@ pub mod blocks { pub mod headers { use super::{BlockLike, Kind}; - use crate::engines::EthEngine; - use crate::error::Error; - use crate::types::header::Header; - use crate::verification::verify_header_params; + use crate::{ + engines::EthEngine, error::Error, types::header::Header, verification::verify_header_params, + }; use ethereum_types::{H256, U256}; diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index e12d5e3af..8a0eb7bb3 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -17,12 +17,14 @@ //! A queue of blocks. Sits between network or other I/O and the `BlockChain`. //! Sorts them ready for blockchain insertion. -use crate::blockchain::BlockChain; -use crate::client::ClientIoMessage; -use crate::engines::EthEngine; -use crate::error::{BlockError, Error, ErrorKind, ImportErrorKind}; +use crate::{ + blockchain::BlockChain, + client::ClientIoMessage, + engines::EthEngine, + error::{BlockError, Error, ErrorKind, ImportErrorKind}, + io::*, +}; use ethereum_types::{H256, U256}; -use crate::io::*; use len_caching_lock::LenCachingMutex; use parity_util_mem::{MallocSizeOf, MallocSizeOfExt}; use parking_lot::{Condvar, Mutex, RwLock}; @@ -31,8 +33,8 @@ use std::{ collections::{HashMap, HashSet, VecDeque}, iter::FromIterator, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering}, Arc, + atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering}, }, thread::{self, JoinHandle}, }; @@ -870,13 +872,15 @@ impl Drop for VerificationQueue { #[cfg(test)] mod tests { - use super::{kind::blocks::Unverified, BlockQueue, Config, State}; + use super::{BlockQueue, Config, State, kind::blocks::Unverified}; + use crate::{ + io::*, + spec::Spec, + types::{BlockNumber, view, views::BlockView}, + }; use bytes::Bytes; use error::*; - use crate::io::*; - use crate::spec::Spec; use test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; - use crate::types::{view, views::BlockView, BlockNumber}; // create a test block queue. // auto_scaling enables verifier adjustment. diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index 05f15ffc6..e0a81e479 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -33,13 +33,15 @@ use rlp::Rlp; use triehash::ordered_trie_root; use unexpected::{Mismatch, OutOfBounds}; -use crate::blockchain::*; +use crate::{ + blockchain::*, + client::BlockInfo, + engines::{EthEngine, MAX_UNCLE_AGE}, + error::{BlockError, Error}, + types::{BlockNumber, header::Header, transaction::SignedTransaction}, + verification::queue::kind::blocks::Unverified, +}; use call_contract::CallContract; -use crate::client::BlockInfo; -use crate::engines::{EthEngine, MAX_UNCLE_AGE}; -use crate::error::{BlockError, Error}; -use crate::types::{header::Header, transaction::SignedTransaction, BlockNumber}; -use crate::verification::queue::kind::blocks::Unverified; use time_utils::CheckedSystemTime; @@ -540,25 +542,27 @@ fn verify_block_integrity(block: &Unverified) -> Result<(), Error> { mod tests { use super::*; - use crate::blockchain::{BlockDetails, BlockReceipts, TransactionAddress}; + use crate::{ + blockchain::{BlockDetails, BlockReceipts, TransactionAddress}, + engines::EthEngine, + spec::{CommonParams, Spec}, + types::{ + encoded, + log_entry::{LocalizedLogEntry, LogEntry}, + transaction::{Action, SignedTransaction, Transaction, TypedTransaction}, + }, + }; use crypto::publickey::{Generator, Random}; - use crate::engines::EthEngine; use error::{BlockError::*, ErrorKind}; use ethereum_types::{Address, BloomRef, H256, U256}; use hash::keccak; use rlp; - use crate::spec::{CommonParams, Spec}; use std::{ collections::{BTreeMap, HashMap}, time::{SystemTime, UNIX_EPOCH}, }; use test_helpers::{create_test_block, create_test_block_with_data}; use triehash::ordered_trie_root; - use crate::types::{ - encoded, - log_entry::{LocalizedLogEntry, LogEntry}, - transaction::{Action, SignedTransaction, Transaction, TypedTransaction}, - }; fn check_ok(result: Result<(), Error>) { result.unwrap_or_else(|e| panic!("Block verification failed: {:?}", e)); @@ -892,10 +896,20 @@ mod tests { let mut bad_header = good.clone(); bad_header.set_transactions_root(eip86_transactions_root.clone()); bad_header.set_uncles_hash(good_uncles_hash.clone()); - match basic_test(&create_test_block_with_data(&bad_header, &eip86_transactions, &good_uncles), engine) { - Err(Error(ErrorKind::Transaction(ref e), _)) if e == &crypto::publickey::Error::InvalidSignature.into() => (), - e => panic!("Block verification failed.\nExpected: Transaction Error (Invalid Signature)\nGot: {:?}", e), - } + match basic_test( + &create_test_block_with_data(&bad_header, &eip86_transactions, &good_uncles), + engine, + ) { + Err(Error(ErrorKind::Transaction(ref e), _)) + if e == &crypto::publickey::Error::InvalidSignature.into() => + { + () + } + e => panic!( + "Block verification failed.\nExpected: Transaction Error (Invalid Signature)\nGot: {:?}", + e + ), + } let mut header = good.clone(); header.set_transactions_root(good_transactions_root.clone()); @@ -1124,10 +1138,12 @@ mod tests { #[test] fn dust_protection() { + use crate::{ + engines::NullEngine, + machine::EthereumMachine, + types::transaction::{Action, Transaction}, + }; use crypto::publickey::{Generator, Random}; - use crate::engines::NullEngine; - use crate::machine::EthereumMachine; - use crate::types::transaction::{Action, Transaction}; let mut params = CommonParams::default(); params.dust_protection_transition = 0; diff --git a/crates/ethcore/src/verification/verifier.rs b/crates/ethcore/src/verification/verifier.rs index 13aca31c1..7924598cc 100644 --- a/crates/ethcore/src/verification/verifier.rs +++ b/crates/ethcore/src/verification/verifier.rs @@ -17,11 +17,8 @@ //! A generic verifier trait. use super::verification; +use crate::{client::BlockInfo, engines::EthEngine, error::Error, types::header::Header}; use call_contract::CallContract; -use crate::client::BlockInfo; -use crate::engines::EthEngine; -use crate::error::Error; -use crate::types::header::Header; /// Should be used to verify blocks. pub trait Verifier: Send + Sync diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 6bdeb664e..0eacadd4e 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -18,42 +18,46 @@ use bytes::Bytes; use crypto::publickey::Secret; use devp2p::NetworkService; use network::{ - client_version::ClientVersion, ConnectionFilter, Error, ErrorKind, - NetworkConfiguration as BasicNetworkConfiguration, NetworkContext, NetworkProtocolHandler, - NodeId, NonReservedPeerMode, PeerId, ProtocolId, + ConnectionFilter, Error, ErrorKind, NetworkConfiguration as BasicNetworkConfiguration, + NetworkContext, NetworkProtocolHandler, NodeId, NonReservedPeerMode, PeerId, ProtocolId, + client_version::ClientVersion, }; use std::{ collections::{BTreeMap, BTreeSet, HashMap}, io, ops::RangeInclusive, - sync::{atomic, mpsc, Arc}, + sync::{Arc, atomic, mpsc}, time::Duration, }; -use crate::chain::{ - fork_filter::ForkFilterApi, ChainSyncApi, SyncState, SyncStatus as EthSyncStatus, - ETH_PROTOCOL_VERSION_63, ETH_PROTOCOL_VERSION_64, ETH_PROTOCOL_VERSION_65, - ETH_PROTOCOL_VERSION_66, PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2, -}; -use crate::ethcore::{ - client::{BlockChainClient, ChainMessageType, ChainNotify, NewBlocks}, - snapshot::SnapshotService, +use crate::{ + chain::{ + ChainSyncApi, ETH_PROTOCOL_VERSION_63, ETH_PROTOCOL_VERSION_64, ETH_PROTOCOL_VERSION_65, + ETH_PROTOCOL_VERSION_66, PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2, SyncState, + SyncStatus as EthSyncStatus, fork_filter::ForkFilterApi, + }, + ethcore::{ + client::{BlockChainClient, ChainMessageType, ChainNotify, NewBlocks}, + snapshot::SnapshotService, + }, + io::TimerToken, + network::IpFilter, + stats::{PrometheusMetrics, PrometheusRegistry}, }; -use ethereum_types::{H256, H512, U256, U64}; -use crate::io::TimerToken; -use crate::network::IpFilter; +use ethereum_types::{H256, H512, U64, U256}; use parking_lot::{Mutex, RwLock}; -use crate::stats::{PrometheusMetrics, PrometheusRegistry}; +use crate::{ + sync_io::{NetSyncIo, SyncIo}, + types::{ + BlockNumber, creation_status::CreationStatus, restoration_status::RestorationStatus, + transaction::UnverifiedTransaction, + }, +}; use std::{ net::{AddrParseError, SocketAddr}, str::FromStr, }; -use crate::sync_io::{NetSyncIo, SyncIo}; -use crate::types::{ - creation_status::CreationStatus, restoration_status::RestorationStatus, - transaction::UnverifiedTransaction, BlockNumber, -}; /// OpenEthereum sync protocol pub const PAR_PROTOCOL: ProtocolId = U64([0x706172]); // hexadecimal number of "par"; @@ -655,7 +659,10 @@ impl ChainNotify for EthSync { match self.network.start() { Err((err, listen_address)) => match err.into() { ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => { - warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", listen_address.expect("Listen address is not set.")) + warn!( + "Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", + listen_address.expect("Listen address is not set.") + ) } err => warn!("Error starting network: {}", err), }, diff --git a/crates/ethcore/sync/src/block_sync.rs b/crates/ethcore/sync/src/block_sync.rs index 30531e39c..292d949c9 100644 --- a/crates/ethcore/sync/src/block_sync.rs +++ b/crates/ethcore/sync/src/block_sync.rs @@ -15,8 +15,12 @@ // along with OpenEthereum. If not, see . // use std::backtrace::Backtrace; -use crate::blocks::{BlockCollection, SyncBody, SyncHeader}; -use crate::chain::BlockSet; +use crate::{ + blocks::{BlockCollection, SyncBody, SyncHeader}, + chain::BlockSet, + sync_io::SyncIo, + types::BlockNumber, +}; use ethcore::{ client::{BlockId, BlockStatus}, error::{ @@ -25,15 +29,13 @@ use ethcore::{ }, }; use ethereum_types::H256; -use network::{client_version::ClientCapabilities, PeerId}; +use network::{PeerId, client_version::ClientCapabilities}; use rlp::{self, Rlp}; use std::cmp; /// /// Blockchain downloader /// use std::collections::{BTreeMap, HashSet, VecDeque}; -use crate::sync_io::SyncIo; -use crate::types::BlockNumber; const MAX_HEADERS_TO_REQUEST: usize = 128; const MAX_BODIES_TO_REQUEST_LARGE: usize = 128; @@ -377,7 +379,10 @@ impl BlockDownloader { return Err(BlockDownloaderImportError::Invalid); } BlockSet::OldBlocks => { - trace_sync!(self, "Expected some useful headers for downloading OldBlocks. Try a different peer"); + trace_sync!( + self, + "Expected some useful headers for downloading OldBlocks. Try a different peer" + ); return Err(BlockDownloaderImportError::Useless); } _ => (), @@ -567,7 +572,10 @@ impl BlockDownloader { } else { let n = start - cmp::min(self.retract_step, start); if n == 0 { - info!("Header not found, bottom line reached, resetting, last imported: {}", self.last_imported_hash); + info!( + "Header not found, bottom line reached, resetting, last imported: {}", + self.last_imported_hash + ); info!(target: "sync", "Header not found: start: {} best: {} retract_step: {}, last_imported_hash: {}, oldest_reorg: {}", start, best, self.retract_step, self.last_imported_hash, oldest_reorg); self.reset_to_block(&best_hash, best); } else { @@ -797,17 +805,19 @@ where #[cfg(test)] mod tests { use super::*; + use crate::{ + tests::{helpers::TestIo, snapshot::TestSnapshotService}, + types::{ + header::Header as BlockHeader, + transaction::{SignedTransaction, Transaction, TypedTransaction}, + }, + }; use crypto::publickey::{Generator, Random}; use ethcore::{client::TestBlockChainClient, spec::Spec}; use hash::keccak; use parking_lot::RwLock; - use rlp::{encode_list, RlpStream}; - use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; + use rlp::{RlpStream, encode_list}; use triehash_ethereum::ordered_trie_root; - use crate::types::{ - header::Header as BlockHeader, - transaction::{SignedTransaction, Transaction, TypedTransaction}, - }; fn dummy_header(number: u64, parent_hash: H256) -> BlockHeader { let mut header = BlockHeader::new(); @@ -1063,33 +1073,39 @@ mod tests { // Only import the first three block headers. let rlp_data = encode_list(&headers[0..3]); let headers_rlp = Rlp::new(&rlp_data); - assert!(downloader - .import_headers(&mut io, &headers_rlp, headers[0].hash(), eip1559_transition) - .is_ok()); + assert!( + downloader + .import_headers(&mut io, &headers_rlp, headers[0].hash(), eip1559_transition) + .is_ok() + ); // Import first body successfully. let mut rlp_data = RlpStream::new_list(1); rlp_data.append_raw(&bodies[0], 1); let bodies_rlp = Rlp::new(rlp_data.as_raw()); - assert!(downloader - .import_bodies( - &bodies_rlp, - &[headers[0].hash(), headers[1].hash()], - eip1559_transition - ) - .is_ok()); + assert!( + downloader + .import_bodies( + &bodies_rlp, + &[headers[0].hash(), headers[1].hash()], + eip1559_transition + ) + .is_ok() + ); // Import second body successfully. let mut rlp_data = RlpStream::new_list(1); rlp_data.append_raw(&bodies[1], 1); let bodies_rlp = Rlp::new(rlp_data.as_raw()); - assert!(downloader - .import_bodies( - &bodies_rlp, - &[headers[0].hash(), headers[1].hash()], - eip1559_transition - ) - .is_ok()); + assert!( + downloader + .import_bodies( + &bodies_rlp, + &[headers[0].hash(), headers[1].hash()], + eip1559_transition + ) + .is_ok() + ); // Import unexpected third body. let mut rlp_data = RlpStream::new_list(1); @@ -1153,18 +1169,22 @@ mod tests { // Only import the first three block headers. let rlp_data = encode_list(&headers[0..3]); let headers_rlp = Rlp::new(&rlp_data); - assert!(downloader - .import_headers(&mut io, &headers_rlp, headers[0].hash(), eip1559_transition) - .is_ok()); + assert!( + downloader + .import_headers(&mut io, &headers_rlp, headers[0].hash(), eip1559_transition) + .is_ok() + ); // Import second and third receipts successfully. let mut rlp_data = RlpStream::new_list(2); rlp_data.append_raw(&receipts[1], 1); rlp_data.append_raw(&receipts[2], 1); let receipts_rlp = Rlp::new(rlp_data.as_raw()); - assert!(downloader - .import_receipts(&receipts_rlp, &[headers[1].hash(), headers[2].hash()]) - .is_ok()); + assert!( + downloader + .import_receipts(&receipts_rlp, &[headers[1].hash(), headers[2].hash()]) + .is_ok() + ); // Import unexpected fourth receipt. let mut rlp_data = RlpStream::new_list(1); diff --git a/crates/ethcore/sync/src/blocks.rs b/crates/ethcore/sync/src/blocks.rs index ad23435ac..847e4bad4 100644 --- a/crates/ethcore/sync/src/blocks.rs +++ b/crates/ethcore/sync/src/blocks.rs @@ -14,20 +14,20 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::types::{ + BlockNumber, + header::Header as BlockHeader, + transaction::{TypedTransaction, UnverifiedTransaction}, +}; use bytes::Bytes; use ethcore::verification::queue::kind::blocks::Unverified; use ethereum_types::H256; -use hash::{keccak, KECCAK_EMPTY_LIST_RLP, KECCAK_NULL_RLP}; +use hash::{KECCAK_EMPTY_LIST_RLP, KECCAK_NULL_RLP, keccak}; use network; use parity_util_mem::MallocSizeOf; use rlp::{DecoderError, Rlp, RlpStream}; -use std::collections::{hash_map, BTreeMap, HashMap, HashSet}; +use std::collections::{BTreeMap, HashMap, HashSet, hash_map}; use triehash_ethereum::ordered_trie_root; -use crate::types::{ - header::Header as BlockHeader, - transaction::{TypedTransaction, UnverifiedTransaction}, - BlockNumber, -}; malloc_size_of_is_0!(HeaderId); @@ -621,12 +621,12 @@ impl BlockCollection { #[cfg(test)] mod test { use super::{BlockCollection, SyncHeader}; + use crate::types::BlockNumber; use ethcore::{ client::{BlockChainClient, BlockId, EachBlockWith, TestBlockChainClient}, verification::queue::kind::blocks::Unverified, }; use rlp::*; - use crate::types::BlockNumber; fn is_empty(bc: &BlockCollection) -> bool { bc.heads.is_empty() diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index a6791c1ca..1c5484c49 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -14,8 +14,13 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::api::{ETH_PROTOCOL, PAR_PROTOCOL}; -use crate::block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction}; +use crate::{ + api::{ETH_PROTOCOL, PAR_PROTOCOL}, + block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction}, + snapshot::ChunkType, + sync_io::SyncIo, + types::{BlockNumber, block_status::BlockStatus, ids::BlockId}, +}; use bytes::Bytes; use enum_primitive::FromPrimitive; use ethcore::{ @@ -25,12 +30,9 @@ use ethcore::{ }; use ethereum_types::{H256, H512, U256}; use hash::keccak; -use network::{client_version::ClientVersion, PeerId}; +use network::{PeerId, client_version::ClientVersion}; use rlp::Rlp; -use crate::snapshot::ChunkType; use std::{cmp, mem, time::Instant}; -use crate::sync_io::SyncIo; -use crate::types::{block_status::BlockStatus, ids::BlockId, BlockNumber}; use super::{ request_id::strip_request_id, @@ -41,9 +43,9 @@ use super::{ }; use super::{ - BlockSet, ChainSync, ForkConfirmation, PacketProcessError, PeerAsking, PeerInfo, SyncRequester, - SyncState, ETH_PROTOCOL_VERSION_63, ETH_PROTOCOL_VERSION_64, ETH_PROTOCOL_VERSION_66, - MAX_NEW_BLOCK_AGE, MAX_NEW_HASHES, PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2, + BlockSet, ChainSync, ETH_PROTOCOL_VERSION_63, ETH_PROTOCOL_VERSION_64, ETH_PROTOCOL_VERSION_66, + ForkConfirmation, MAX_NEW_BLOCK_AGE, MAX_NEW_HASHES, PAR_PROTOCOL_VERSION_1, + PAR_PROTOCOL_VERSION_2, PacketProcessError, PeerAsking, PeerInfo, SyncRequester, SyncState, }; use network::client_version::ClientCapabilities; @@ -950,11 +952,11 @@ impl SyncHandler { #[cfg(test)] mod tests { + use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; use ethcore::client::{ChainInfo, EachBlockWith, TestBlockChainClient}; use parking_lot::RwLock; use rlp::Rlp; use std::collections::VecDeque; - use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; use super::{ super::tests::{dummy_sync_with_peer, get_dummy_block, get_dummy_blocks, get_dummy_hashes}, diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 115bfbd0b..b4162e06e 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -103,8 +103,14 @@ use self::{ propagator_statistics::SyncPropagatorStatistics, }; use super::{SyncConfig, WarpSync}; -use crate::api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, ETH_PROTOCOL, PAR_PROTOCOL}; -use crate::block_sync::{BlockDownloader, DownloadAction}; +use crate::{ + api::{ETH_PROTOCOL, EthProtocolInfo as PeerInfoDigest, PAR_PROTOCOL, PriorityTask}, + block_sync::{BlockDownloader, DownloadAction}, + snapshot::Snapshot, + sync_io::SyncIo, + transactions_stats::{Stats as TransactionStats, TransactionsStats}, + types::{BlockNumber, block_status, transaction::UnverifiedTransaction}, +}; use bytes::Bytes; use derive_more::Display; use ethcore::{ @@ -114,11 +120,10 @@ use ethcore::{ use ethereum_types::{H256, H512, U256}; use fastmap::{H256FastMap, H256FastSet}; use hash::keccak; -use network::{self, client_version::ClientVersion, PeerId}; +use network::{self, PeerId, client_version::ClientVersion}; use parking_lot::{Mutex, RwLock, RwLockWriteGuard}; -use rand::{seq::SliceRandom, Rng}; +use rand::{Rng, seq::SliceRandom}; use rlp::{DecoderError, RlpStream}; -use crate::snapshot::Snapshot; use stats::PrometheusMetrics; use std::{ cmp, @@ -126,9 +131,6 @@ use std::{ sync::mpsc, time::{Duration, Instant}, }; -use crate::sync_io::SyncIo; -use crate::transactions_stats::{Stats as TransactionStats, TransactionsStats}; -use crate::types::{block_status, transaction::UnverifiedTransaction, BlockNumber}; use self::{ handler::SyncHandler, @@ -1212,7 +1214,7 @@ impl ChainSync { ); peers.shuffle(&mut random::new()); // TODO (#646): sort by rating - // prefer peers with higher protocol version + // prefer peers with higher protocol version peers.sort_by(|&(_, ref v1), &(_, ref v2)| v1.cmp(v2)); @@ -1863,6 +1865,11 @@ impl PrometheusMetrics for ChainSync { #[cfg(test)] pub mod tests { use super::{PeerAsking, PeerInfo, *}; + use crate::{ + tests::{helpers::TestIo, snapshot::TestSnapshotService}, + types::header::Header, + }; + use SyncConfig; use bytes::Bytes; use ethcore::{ client::{BlockChainClient, BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient}, @@ -1873,9 +1880,6 @@ pub mod tests { use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use std::collections::VecDeque; - use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; - use crate::types::header::Header; - use SyncConfig; pub fn get_dummy_block(order: u32, parent_hash: H256) -> Bytes { let mut header = Header::new(); diff --git a/crates/ethcore/sync/src/chain/pooled_transactions_overview.rs b/crates/ethcore/sync/src/chain/pooled_transactions_overview.rs index 670c08c9c..2e95852c3 100644 --- a/crates/ethcore/sync/src/chain/pooled_transactions_overview.rs +++ b/crates/ethcore/sync/src/chain/pooled_transactions_overview.rs @@ -1,6 +1,6 @@ use std::{num::NonZeroUsize, time::Instant}; -use fastmap::{new_h256_fast_lru_map, H256FastLruMap}; +use fastmap::{H256FastLruMap, new_h256_fast_lru_map}; use hash::H256; /// memorizs currently pooled transactions, so they are not pooled to often from different hosts. diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 773df6b30..9c3968232 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -20,22 +20,24 @@ use std::{ time::{Duration, Instant}, }; +use crate::{ + sync_io::SyncIo, + types::{BlockNumber, blockchain_info::BlockChainInfo, transaction::SignedTransaction}, +}; use bytes::Bytes; use ethereum_types::H256; use fastmap::H256FastSet; -use network::{client_version::ClientCapabilities, PeerId}; +use network::{PeerId, client_version::ClientCapabilities}; use rand::RngCore; use rlp::RlpStream; -use crate::sync_io::SyncIo; -use crate::types::{blockchain_info::BlockChainInfo, transaction::SignedTransaction, BlockNumber}; use crate::chain::propagator_statistics::SyncPropagatorStatistics; use super::sync_packet::SyncPacket::{self, *}; use super::{ - random, ChainSync, MAX_PEERS_PROPAGATION, MAX_PEER_LAG_PROPAGATION, - MAX_TRANSACTION_PACKET_SIZE, MIN_PEERS_PROPAGATION, + ChainSync, MAX_PEER_LAG_PROPAGATION, MAX_PEERS_PROPAGATION, MAX_TRANSACTION_PACKET_SIZE, + MIN_PEERS_PROPAGATION, random, }; use ethcore_miner::pool::VerifiedTransaction; use std::sync::Arc; @@ -513,12 +515,14 @@ impl ChainSync { #[cfg(test)] mod tests { + use crate::{ + tests::{helpers::TestIo, snapshot::TestSnapshotService}, + types::transaction::TypedTransaction, + }; use ethcore::client::{BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient}; use parking_lot::RwLock; use rlp::Rlp; use std::collections::VecDeque; - use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; - use crate::types::transaction::TypedTransaction; use super::{ super::{tests::*, *}, @@ -927,14 +931,16 @@ mod tests { sync.propagate_ready_transactions(&mut io, || true); // peer#2 && peer#3 are receiving service transaction - assert!(io - .packets - .iter() - .any(|p| p.packet_id == 0x02 && p.recipient == 2)); // TRANSACTIONS_PACKET - assert!(io - .packets - .iter() - .any(|p| p.packet_id == 0x02 && p.recipient == 3)); // TRANSACTIONS_PACKET + assert!( + io.packets + .iter() + .any(|p| p.packet_id == 0x02 && p.recipient == 2) + ); // TRANSACTIONS_PACKET + assert!( + io.packets + .iter() + .any(|p| p.packet_id == 0x02 && p.recipient == 3) + ); // TRANSACTIONS_PACKET assert_eq!(io.packets.len(), 2); } diff --git a/crates/ethcore/sync/src/chain/request_id.rs b/crates/ethcore/sync/src/chain/request_id.rs index bbab579a5..3715213b2 100644 --- a/crates/ethcore/sync/src/chain/request_id.rs +++ b/crates/ethcore/sync/src/chain/request_id.rs @@ -1,8 +1,8 @@ -use bytes::Bytes; use crate::chain::{ - sync_packet::{PacketInfo, SyncPacket}, ChainSync, PeerInfo, + sync_packet::{PacketInfo, SyncPacket}, }; +use bytes::Bytes; use network::PeerId; use rlp::{DecoderError, Rlp, RlpStream}; diff --git a/crates/ethcore/sync/src/chain/requester.rs b/crates/ethcore/sync/src/chain/requester.rs index 04b6d798e..56333a963 100644 --- a/crates/ethcore/sync/src/chain/requester.rs +++ b/crates/ethcore/sync/src/chain/requester.rs @@ -14,15 +14,13 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::block_sync::BlockRequest; +use crate::{block_sync::BlockRequest, sync_io::SyncIo, types::BlockNumber}; use bytes::Bytes; use ethereum_types::H256; use fastmap::H256FastSet; use network::PeerId; use rlp::RlpStream; use std::time::Instant; -use crate::sync_io::SyncIo; -use crate::types::BlockNumber; use super::{ request_id::generate_request_id, diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index 8e992feff..5b195d30f 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -21,24 +21,24 @@ use devp2p::PAYLOAD_SOFT_LIMIT; #[cfg(test)] pub const PAYLOAD_SOFT_LIMIT: usize = 100_000; +use crate::types::{BlockNumber, ids::BlockId}; use enum_primitive::FromPrimitive; use ethereum_types::{H256, H512}; use network::{self, PeerId}; use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use std::cmp; -use crate::types::{ids::BlockId, BlockNumber}; use crate::sync_io::SyncIo; use super::{ - request_id::{prepend_request_id, strip_request_id, RequestId}, + request_id::{RequestId, prepend_request_id, strip_request_id}, sync_packet::{PacketInfo, SyncPacket, SyncPacket::*}, }; use super::{ - ChainSync, PacketProcessError, RlpResponseResult, SyncHandler, MAX_BODIES_TO_SEND, - MAX_HEADERS_TO_SEND, MAX_RECEIPTS_HEADERS_TO_SEND, + ChainSync, MAX_BODIES_TO_SEND, MAX_HEADERS_TO_SEND, MAX_RECEIPTS_HEADERS_TO_SEND, + PacketProcessError, RlpResponseResult, SyncHandler, }; use crate::chain::MAX_NODE_DATA_TO_SEND; use std::borrow::Borrow; @@ -511,7 +511,10 @@ impl SyncSupplier { #[cfg(test)] mod test { use super::{super::tests::*, *}; - use crate::blocks::SyncHeader; + use crate::{ + blocks::SyncHeader, + tests::{helpers::TestIo, snapshot::TestSnapshotService}, + }; use bytes::Bytes; use ethcore::{ client::{BlockChainClient, EachBlockWith, TestBlockChainClient}, @@ -521,7 +524,6 @@ mod test { use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use std::{collections::VecDeque, str::FromStr}; - use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; #[test] fn return_block_headers() { diff --git a/crates/ethcore/sync/src/lib.rs b/crates/ethcore/sync/src/lib.rs index 39832bae2..90aadc7f2 100644 --- a/crates/ethcore/sync/src/lib.rs +++ b/crates/ethcore/sync/src/lib.rs @@ -75,7 +75,9 @@ mod tests; mod api; -pub use crate::api::*; -pub use crate::chain::{SyncState, SyncStatus}; +pub use crate::{ + api::*, + chain::{SyncState, SyncStatus}, +}; pub use devp2p::validate_node_url; pub use network::{ConnectionDirection, ConnectionFilter, Error, ErrorKind, NonReservedPeerMode}; diff --git a/crates/ethcore/sync/src/snapshot.rs b/crates/ethcore/sync/src/snapshot.rs index b5f33081e..d614f2d62 100644 --- a/crates/ethcore/sync/src/snapshot.rs +++ b/crates/ethcore/sync/src/snapshot.rs @@ -226,9 +226,11 @@ mod test { let (manifest, mhash, state_chunks, block_chunks) = test_manifest(); snapshot.reset_to(&manifest, &mhash); assert_eq!(snapshot.done_chunks(), 0); - assert!(snapshot - .validate_chunk(&H256::random().as_bytes().to_vec()) - .is_err()); + assert!( + snapshot + .validate_chunk(&H256::random().as_bytes().to_vec()) + .is_err() + ); let requested: Vec = (0..40).map(|_| snapshot.needed_chunk().unwrap()).collect(); assert!(snapshot.needed_chunk().is_none()); diff --git a/crates/ethcore/sync/src/sync_io.rs b/crates/ethcore/sync/src/sync_io.rs index 0c03f0809..5c6a52985 100644 --- a/crates/ethcore/sync/src/sync_io.rs +++ b/crates/ethcore/sync/src/sync_io.rs @@ -14,15 +14,17 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{ + chain::sync_packet::{PacketInfo, SyncPacket}, + types::BlockNumber, +}; use bytes::Bytes; -use crate::chain::sync_packet::{PacketInfo, SyncPacket}; use ethcore::{client::BlockChainClient, snapshot::SnapshotService}; use network::{ - client_version::ClientVersion, Error, NetworkContext, PacketId, PeerId, ProtocolId, SessionInfo, + Error, NetworkContext, PacketId, PeerId, ProtocolId, SessionInfo, client_version::ClientVersion, }; use parking_lot::RwLock; use std::collections::HashMap; -use crate::types::BlockNumber; /// IO interface for the syncing handler. /// Provides peer connection management and an interface to the blockchain client. diff --git a/crates/ethcore/sync/src/tests/chain.rs b/crates/ethcore/sync/src/tests/chain.rs index 8bed806a0..c08c8ade3 100644 --- a/crates/ethcore/sync/src/tests/chain.rs +++ b/crates/ethcore/sync/src/tests/chain.rs @@ -16,12 +16,12 @@ use super::helpers::*; use crate::chain::SyncState; +use SyncConfig; +use WarpSync; use ethcore::client::{ BlockChainClient, BlockId, BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient, }; use std::sync::Arc; -use SyncConfig; -use WarpSync; #[test] fn two_peers() { diff --git a/crates/ethcore/sync/src/tests/consensus.rs b/crates/ethcore/sync/src/tests/consensus.rs index 34d8dd919..704b42da7 100644 --- a/crates/ethcore/sync/src/tests/consensus.rs +++ b/crates/ethcore/sync/src/tests/consensus.rs @@ -15,6 +15,11 @@ // along with OpenEthereum. If not, see . use super::helpers::*; +use crate::{ + io::{IoChannel, IoHandler}, + types::transaction::{Action, PendingTransaction, Transaction, TypedTransaction}, +}; +use SyncConfig; use crypto::publickey::{KeyPair, Secret}; use ethcore::{ client::{ChainInfo, ClientIoMessage}, @@ -24,10 +29,7 @@ use ethcore::{ }; use ethereum_types::{Address, U256}; use hash::keccak; -use crate::io::{IoChannel, IoHandler}; use std::sync::Arc; -use crate::types::transaction::{Action, PendingTransaction, Transaction, TypedTransaction}; -use SyncConfig; fn new_tx(secret: &Secret, nonce: U256, chain_id: u64) -> PendingTransaction { let signed = TypedTransaction::Legacy(Transaction { diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index 792303a4d..a50a69335 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -14,12 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::api::PAR_PROTOCOL; -use bytes::Bytes; -use crate::chain::{ - sync_packet::{PacketInfo, SyncPacket}, - ChainSync, ForkFilterApi, SyncSupplier, ETH_PROTOCOL_VERSION_66, PAR_PROTOCOL_VERSION_2, +use crate::{ + api::PAR_PROTOCOL, + chain::{ + ChainSync, ETH_PROTOCOL_VERSION_66, ForkFilterApi, PAR_PROTOCOL_VERSION_2, SyncSupplier, + sync_packet::{PacketInfo, SyncPacket}, + }, }; +use bytes::Bytes; use ethcore::{ client::{ BlockChainClient, ChainMessageType, ChainNotify, Client as EthcoreClient, ClientConfig, @@ -32,16 +34,18 @@ use ethcore::{ test_helpers, }; +use crate::{ + io::{IoChannel, IoContext, IoHandler}, + sync_io::SyncIo, + tests::snapshot::*, +}; use ethereum_types::H256; -use crate::io::{IoChannel, IoContext, IoHandler}; -use network::{self, client_version::ClientVersion, PacketId, PeerId, ProtocolId, SessionInfo}; +use network::{self, PacketId, PeerId, ProtocolId, SessionInfo, client_version::ClientVersion}; use parking_lot::RwLock; use std::{ collections::{HashMap, HashSet, VecDeque}, sync::Arc, }; -use crate::sync_io::SyncIo; -use crate::tests::snapshot::*; use crate::types::BlockNumber; use SyncConfig; diff --git a/crates/ethcore/sync/src/tests/snapshot.rs b/crates/ethcore/sync/src/tests/snapshot.rs index edd4096fd..d19ce7220 100644 --- a/crates/ethcore/sync/src/tests/snapshot.rs +++ b/crates/ethcore/sync/src/tests/snapshot.rs @@ -15,6 +15,9 @@ // along with OpenEthereum. If not, see . use super::helpers::*; +use crate::types::BlockNumber; +use SyncConfig; +use WarpSync; use bytes::Bytes; use ethcore::{ client::EachBlockWith, @@ -24,9 +27,6 @@ use ethereum_types::H256; use hash::keccak; use parking_lot::Mutex; use std::{collections::HashMap, sync::Arc}; -use crate::types::BlockNumber; -use SyncConfig; -use WarpSync; pub struct TestSnapshotService { manifest: Option, diff --git a/crates/ethcore/sync/src/transactions_stats.rs b/crates/ethcore/sync/src/transactions_stats.rs index ec4614172..a2c1578b3 100644 --- a/crates/ethcore/sync/src/transactions_stats.rs +++ b/crates/ethcore/sync/src/transactions_stats.rs @@ -14,14 +14,13 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::api::TransactionStats; +use crate::{api::TransactionStats, types::BlockNumber}; use ethereum_types::{H256, H512}; use fastmap::H256FastMap; use std::{ collections::{HashMap, HashSet}, hash::BuildHasher, }; -use crate::types::BlockNumber; type NodeId = H512; diff --git a/crates/net/network-devp2p/src/connection.rs b/crates/net/network-devp2p/src/connection.rs index f945d01d4..02c14ce64 100644 --- a/crates/net/network-devp2p/src/connection.rs +++ b/crates/net/network-devp2p/src/connection.rs @@ -14,19 +14,21 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{ + handshake::Handshake, + io::{IoContext, StreamToken}, +}; use bytes::{Buf, BufMut}; use crypto::{ aes::{AesCtr256, AesEcb256}, publickey::Secret, }; use ethereum_types::{H128, H256, H512}; -use crate::handshake::Handshake; use hash::{keccak, write_keccak}; -use crate::io::{IoContext, StreamToken}; use mio::{ + PollOpt, Ready, Token, deprecated::{EventLoop, Handler, TryRead, TryWrite}, tcp::*, - PollOpt, Ready, Token, }; use network::{Error, ErrorKind}; use parity_bytes::*; diff --git a/crates/net/network-devp2p/src/discovery.rs b/crates/net/network-devp2p/src/discovery.rs index 8aaa5c140..522c25694 100644 --- a/crates/net/network-devp2p/src/discovery.rs +++ b/crates/net/network-devp2p/src/discovery.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crypto::publickey::{recover, sign, KeyPair, Secret}; +use crate::node_table::*; +use crypto::publickey::{KeyPair, Secret, recover, sign}; use ethereum_types::{H256, H520}; use hash::keccak; use lru_cache::LruCache; use network::{Error, ErrorKind, IpFilter}; -use crate::node_table::*; use parity_bytes::Bytes; use rlp::{Rlp, RlpStream}; use std::{ - collections::{hash_map::Entry, HashMap, HashSet, VecDeque}, + collections::{HashMap, HashSet, VecDeque, hash_map::Entry}, default::Default, net::SocketAddr, time::{Duration, Instant, SystemTime, UNIX_EPOCH}, @@ -1234,39 +1234,39 @@ mod tests { udp_port: 40447, }; let node_ids_hex: [&str; 32] = [ - "22536fa57acc12c4993295cbc26fef4550513496712b301ad2283d356c8108521244a362e64e6d907a0d0b4e65526699c5ae3cfebfc680505fe3b33d50672835", - "22c482f42401546f8dd7ed6b1c0cad976da6630730f1116614579ccb084791a528ff2676bfe94434de80e5d7e479f1ea1d7737077da3bd5e69a0f3e5bf596091", - "234c73e3a8f6835a7f9a9d2a896bff4908d66d21d5433a2c37d94f1fa9a6ca17d02388f31013ff87e3ad86506e76bd1006b9cac3815974a2b47c8d4f2124697e", - "2a5aaf4e2046c521e890dc82313c6151a55078f045a7e3d259f168238d029271cdd9a0943468d45c1e36a34a8a6d4de4b0262e48d3c8cfdd4c2aab5df42926b9", - "341d8c94d9670461186cfc1f66d4246cb12384940e9f621ec8d6c216b5d037cde5f7a41b70474ca36ced4a4f2fe91c9dc5a24a128414672661f78e8611d54bfd", - "3d9fd01851f3ae1bfd06b48e89738f29f9a2b4dce3ab7864df4fccca55d1ac88044956ba47d0c4cb44a19924626a3a3aa5a4de8958365cb7385111ce7b929200", - "406d5507a7fbc194a495800ae8cf408093336febc24d03d6c63756f522274ab02146ceb1b0213291a9a1544680503837519f88f1e8677d921de62c82935b4e6c", - "4c537f00805f320616ee49c7bc36e1d7e52a04a782b0cc00fd3d6b77200b027cef5f875ed38f1167fef4b02d7bd49a661812301d9d680bb62297131204c035f9", - "4fc8e3fdbdd7acad82b283ac52c121b805f3b15ffcaa6b2ca67b9e375aa88e978951ffa3d03ee13be99f0ee987db0bbfc6a7ca02b175e9123d79826025b4089d", - "55b5042a6910bc908a0520966e8cbcc92ac299bdb7efbfbcf703df1506fa0f9b09c5eeb930080de848d2864cca71f885942852c51233db0ee46fe0447306d61f", - "5d24f28b350c4c37fc4dad7f418e029992c9e4ac356bb3d9a1356ba1076339863c05044d7ceba233c65779401f8a3b38fe67b6a592c1be4834dc869f7bb932eb", - "5f6edaf2f2ae3003f4b4ff90b8e71a717c832c71a634d96e77fe046f9a88adc8de5718ff3c47659aea4cead5376df5b731e1b6530e6b0999f56ad75d4dabd3f6", - "6214c04211efe91abd23d65e2dc8e711b06d4fb13dcfd65b691dc51f58455b2145f9b38f523b72a45a12705a28d389308a34455720d774c9b805326df42b5a63", - "69df92573ddbbce88b72a930843dbb70728b2a020e0cc4e8ba805dcf7f19297bfc5def4ca447e9e6ec66971be1815b8f49042720431f698b6a87a185d94fa6c8", - "72ffc23de007cf8b6f4a117f7427b532d05861c314344ffa265175f57ee45dae041a710a4dc74124dba1dabdc0f52dfd21e3154d1d4285aab529810c6161d623", - "80b567f279a9512f3a66ebd8f87a93acd4d50bf66f5eff6d04039c1f5838e37021e981539659b33e0644b243fc9671209a80cbef40d1bcf7c7117d353cb45532", - "9009dc9e3bf50595f84271f46d4c7a5ad6971f7d2ffce1905bfc40a407d34fc5e2dcebd92746eadcd2c5fa4d5aaccb0e01b542d506b361851df3f19e6bc629a3", - "95264f56e091efeba911003fd01eeb2c81f6fc4bb7b10c92e4c7bfaf460b7246d232e61ad8a223d74870981a84e15b2d5134c25d931cb860c6912b20a2d3ac01", - "96013a472a9f7ff9c5c76b5ca958f14ee510d826703aa41d4c88eac51d30d14229b9f19f6e0469c37aaa6d2136a978a4aaa38ca766f48e53e569f84e44252962", - "a513c988cf8480ad2992caa64e3fa059ce07efda260dfeefed78e1d41ea3f97844603b8a9737eb633086fd9ac2f201200cb656cda8a91bf6cc500d6039db6f53", - "ab3311f38e3641c8b3b1fd36dd7f94b148166e267258e840d29d1859537c74f202bd3342359b3623f96c23fa662d1b65182a898bf20343744b37cb265182e500", - "ac8f41dbd637891a08c9cf715c23577bdd431ba40231682a5a9ba7fd6cb6d66c04f63d6d65c7d9f8737e641e05fdbeede57138a174f0d55e7835575dd6cddd98", - "accdad251888d53e4e18efee1e0d749d050216b14896efb657e9c7b1b78dab82a5b6fb3234017aa19a2f50475d73960f352d308b2e0e841cbebaf418362a4f21", - "b138622208f74d2b8e8fc10bcd4cf3302685cd77d339280a939474b92be8b93e441c50709e25c82cc88a2a4207e9f2938912d60600226efe322b43c6ef5e7aef", - "b4f64e1fa6a5cd6198b2515bde63fbdabaf7e7a31dbaf5369babbda4b8cd0bf5025ac4b7d2d6e6e3bc76c890df585d28d4815e464c8792ef677df9206864a12b", - "c1136e08a27c93812ae2dd47201d9e81c82d1995001b88dba9eec700e1d3385dfaf7ae834226c3c90a138f1808cd10b5502f49ee774a2bc707f34bd7d160b7bd", - "c203ae9b5d1953b0ac462e66338800ec26982e2af54bd444fc8978973191633d4f483e31b28233c07bb99f34d57c680fa5f8e093e64f13b235005b7ab6e2d594", - "c2e1067c58a9948e773e0a3637d946e26d95762f89ec9d35e2ad84f770309d94168d4e112c78d62b60efc6216bc5d31475f24307b1b8e0fa8dcbb18a10cb85f5", - "d60ecb1a89e0d5aeff14c9a95da9f5492eb15871c53563b86b7c5ddf0da74b4c29e682fdd22aae2290e0b16ef4b6d707ef55396ca98f755c95b689cf65ce5f80", - "df5ad4ea6242929df86f2162d1cc62b0e0a6f0a03428a39dea98f6a689335b5ceaf1f0696c17b717b141aeb45a29108d95c3a7d2d1d0bb3441219504ae672917", - "e1268f5dd9552a11989df9d4953bb388e7466711b2bd9882a3ed4d0767a21f046c53c20f9a18d66bae1d6a5544492857ddecb0b5b4818bd4557be252ddd66c71", - "e626019dc0b50b9e254461f19d29e69a4669c5256134a6352c6c30d3bc55d201a5b43fc2e006556cfaf29765b683e807e03093798942826244e4ee9e47c75d3f", - ]; + "22536fa57acc12c4993295cbc26fef4550513496712b301ad2283d356c8108521244a362e64e6d907a0d0b4e65526699c5ae3cfebfc680505fe3b33d50672835", + "22c482f42401546f8dd7ed6b1c0cad976da6630730f1116614579ccb084791a528ff2676bfe94434de80e5d7e479f1ea1d7737077da3bd5e69a0f3e5bf596091", + "234c73e3a8f6835a7f9a9d2a896bff4908d66d21d5433a2c37d94f1fa9a6ca17d02388f31013ff87e3ad86506e76bd1006b9cac3815974a2b47c8d4f2124697e", + "2a5aaf4e2046c521e890dc82313c6151a55078f045a7e3d259f168238d029271cdd9a0943468d45c1e36a34a8a6d4de4b0262e48d3c8cfdd4c2aab5df42926b9", + "341d8c94d9670461186cfc1f66d4246cb12384940e9f621ec8d6c216b5d037cde5f7a41b70474ca36ced4a4f2fe91c9dc5a24a128414672661f78e8611d54bfd", + "3d9fd01851f3ae1bfd06b48e89738f29f9a2b4dce3ab7864df4fccca55d1ac88044956ba47d0c4cb44a19924626a3a3aa5a4de8958365cb7385111ce7b929200", + "406d5507a7fbc194a495800ae8cf408093336febc24d03d6c63756f522274ab02146ceb1b0213291a9a1544680503837519f88f1e8677d921de62c82935b4e6c", + "4c537f00805f320616ee49c7bc36e1d7e52a04a782b0cc00fd3d6b77200b027cef5f875ed38f1167fef4b02d7bd49a661812301d9d680bb62297131204c035f9", + "4fc8e3fdbdd7acad82b283ac52c121b805f3b15ffcaa6b2ca67b9e375aa88e978951ffa3d03ee13be99f0ee987db0bbfc6a7ca02b175e9123d79826025b4089d", + "55b5042a6910bc908a0520966e8cbcc92ac299bdb7efbfbcf703df1506fa0f9b09c5eeb930080de848d2864cca71f885942852c51233db0ee46fe0447306d61f", + "5d24f28b350c4c37fc4dad7f418e029992c9e4ac356bb3d9a1356ba1076339863c05044d7ceba233c65779401f8a3b38fe67b6a592c1be4834dc869f7bb932eb", + "5f6edaf2f2ae3003f4b4ff90b8e71a717c832c71a634d96e77fe046f9a88adc8de5718ff3c47659aea4cead5376df5b731e1b6530e6b0999f56ad75d4dabd3f6", + "6214c04211efe91abd23d65e2dc8e711b06d4fb13dcfd65b691dc51f58455b2145f9b38f523b72a45a12705a28d389308a34455720d774c9b805326df42b5a63", + "69df92573ddbbce88b72a930843dbb70728b2a020e0cc4e8ba805dcf7f19297bfc5def4ca447e9e6ec66971be1815b8f49042720431f698b6a87a185d94fa6c8", + "72ffc23de007cf8b6f4a117f7427b532d05861c314344ffa265175f57ee45dae041a710a4dc74124dba1dabdc0f52dfd21e3154d1d4285aab529810c6161d623", + "80b567f279a9512f3a66ebd8f87a93acd4d50bf66f5eff6d04039c1f5838e37021e981539659b33e0644b243fc9671209a80cbef40d1bcf7c7117d353cb45532", + "9009dc9e3bf50595f84271f46d4c7a5ad6971f7d2ffce1905bfc40a407d34fc5e2dcebd92746eadcd2c5fa4d5aaccb0e01b542d506b361851df3f19e6bc629a3", + "95264f56e091efeba911003fd01eeb2c81f6fc4bb7b10c92e4c7bfaf460b7246d232e61ad8a223d74870981a84e15b2d5134c25d931cb860c6912b20a2d3ac01", + "96013a472a9f7ff9c5c76b5ca958f14ee510d826703aa41d4c88eac51d30d14229b9f19f6e0469c37aaa6d2136a978a4aaa38ca766f48e53e569f84e44252962", + "a513c988cf8480ad2992caa64e3fa059ce07efda260dfeefed78e1d41ea3f97844603b8a9737eb633086fd9ac2f201200cb656cda8a91bf6cc500d6039db6f53", + "ab3311f38e3641c8b3b1fd36dd7f94b148166e267258e840d29d1859537c74f202bd3342359b3623f96c23fa662d1b65182a898bf20343744b37cb265182e500", + "ac8f41dbd637891a08c9cf715c23577bdd431ba40231682a5a9ba7fd6cb6d66c04f63d6d65c7d9f8737e641e05fdbeede57138a174f0d55e7835575dd6cddd98", + "accdad251888d53e4e18efee1e0d749d050216b14896efb657e9c7b1b78dab82a5b6fb3234017aa19a2f50475d73960f352d308b2e0e841cbebaf418362a4f21", + "b138622208f74d2b8e8fc10bcd4cf3302685cd77d339280a939474b92be8b93e441c50709e25c82cc88a2a4207e9f2938912d60600226efe322b43c6ef5e7aef", + "b4f64e1fa6a5cd6198b2515bde63fbdabaf7e7a31dbaf5369babbda4b8cd0bf5025ac4b7d2d6e6e3bc76c890df585d28d4815e464c8792ef677df9206864a12b", + "c1136e08a27c93812ae2dd47201d9e81c82d1995001b88dba9eec700e1d3385dfaf7ae834226c3c90a138f1808cd10b5502f49ee774a2bc707f34bd7d160b7bd", + "c203ae9b5d1953b0ac462e66338800ec26982e2af54bd444fc8978973191633d4f483e31b28233c07bb99f34d57c680fa5f8e093e64f13b235005b7ab6e2d594", + "c2e1067c58a9948e773e0a3637d946e26d95762f89ec9d35e2ad84f770309d94168d4e112c78d62b60efc6216bc5d31475f24307b1b8e0fa8dcbb18a10cb85f5", + "d60ecb1a89e0d5aeff14c9a95da9f5492eb15871c53563b86b7c5ddf0da74b4c29e682fdd22aae2290e0b16ef4b6d707ef55396ca98f755c95b689cf65ce5f80", + "df5ad4ea6242929df86f2162d1cc62b0e0a6f0a03428a39dea98f6a689335b5ceaf1f0696c17b717b141aeb45a29108d95c3a7d2d1d0bb3441219504ae672917", + "e1268f5dd9552a11989df9d4953bb388e7466711b2bd9882a3ed4d0767a21f046c53c20f9a18d66bae1d6a5544492857ddecb0b5b4818bd4557be252ddd66c71", + "e626019dc0b50b9e254461f19d29e69a4669c5256134a6352c6c30d3bc55d201a5b43fc2e006556cfaf29765b683e807e03093798942826244e4ee9e47c75d3f", + ]; let node_entries = node_ids_hex .iter() .map(|node_id_hex| NodeId::from_str(node_id_hex).unwrap()) diff --git a/crates/net/network-devp2p/src/handshake.rs b/crates/net/network-devp2p/src/handshake.rs index 2cb0d58b4..98bc38ed2 100644 --- a/crates/net/network-devp2p/src/handshake.rs +++ b/crates/net/network-devp2p/src/handshake.rs @@ -14,16 +14,18 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::connection::Connection; -use crypto::publickey::{ecdh, ecies, recover, sign, Generator, KeyPair, Public, Random, Secret}; +use crate::{ + connection::Connection, + host::HostInfo, + io::{IoContext, StreamToken}, + node_table::NodeId, +}; +use crypto::publickey::{Generator, KeyPair, Public, Random, Secret, ecdh, ecies, recover, sign}; use ethereum_types::{H256, H520}; -use crate::host::HostInfo; -use crate::io::{IoContext, StreamToken}; use mio::tcp::*; use network::{Error, ErrorKind}; -use crate::node_table::NodeId; use parity_bytes::Bytes; -use rand::{random, Rng}; +use rand::{Rng, random}; use rlp::{Rlp, RlpStream}; use std::time::Duration; @@ -381,9 +383,9 @@ impl Handshake { #[cfg(test)] mod test { use super::*; + use crate::io::*; use crypto::publickey::Public; use ethereum_types::{H256, H512}; - use crate::io::*; use mio::tcp::TcpStream; use rustc_hex::FromHex; use std::str::FromStr; diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 9ef3ebb1a..88d3098de 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::mio::{deprecated::EventLoop, tcp::*, udp::*, *}; use crypto::publickey::{Generator, KeyPair, Random, Secret}; use ethereum_types::H256; use hash::keccak; -use crate::mio::{deprecated::EventLoop, tcp::*, udp::*, *}; use rlp::{Encodable, RlpStream}; use std::{ cmp::{max, min}, @@ -29,26 +29,29 @@ use std::{ path::{Path, PathBuf}, str::FromStr, sync::{ - atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, Arc, + atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, }, time::Duration, }; -use crate::discovery::{Discovery, NodeEntry, TableUpdates, MAX_DATAGRAM_SIZE}; -use crate::io::*; -use crate::ip_utils::{map_external_address, select_public_address}; +use crate::{ + PROTOCOL_VERSION, + discovery::{Discovery, MAX_DATAGRAM_SIZE, NodeEntry, TableUpdates}, + io::*, + ip_utils::{map_external_address, select_public_address}, + node_table::*, + session::{Session, SessionData}, +}; use network::{ - client_version::ClientVersion, ConnectionDirection, ConnectionFilter, DisconnectReason, Error, - ErrorKind, NetworkConfiguration, NetworkContext as NetworkContextTrait, NetworkIoMessage, + ConnectionDirection, ConnectionFilter, DisconnectReason, Error, ErrorKind, + NetworkConfiguration, NetworkContext as NetworkContextTrait, NetworkIoMessage, NetworkProtocolHandler, NonReservedPeerMode, PacketId, PeerId, ProtocolId, SessionInfo, + client_version::ClientVersion, }; -use crate::node_table::*; use parity_path::restrict_permissions_owner; use parking_lot::{Mutex, RwLock}; -use crate::session::{Session, SessionData}; use stats::{PrometheusMetrics, PrometheusRegistry}; -use crate::PROTOCOL_VERSION; type Slab = ::slab::Slab; @@ -183,7 +186,12 @@ impl<'s> NetworkContext<'s> { } impl<'s> NetworkContextTrait for NetworkContext<'s> { - fn send(&self, peer: PeerId, packet_id: PacketId, data: Vec) -> std::result::Result<(), network::Error> { + fn send( + &self, + peer: PeerId, + packet_id: PacketId, + data: Vec, + ) -> std::result::Result<(), network::Error> { self.send_protocol(self.protocol, peer, packet_id, data) } @@ -219,7 +227,11 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { Ok(()) } - fn respond(&self, packet_id: PacketId, data: Vec) -> std::result::Result<(), network::Error> { + fn respond( + &self, + packet_id: PacketId, + data: Vec, + ) -> std::result::Result<(), network::Error> { assert!( self.session.is_some(), "Respond called without network context" diff --git a/crates/net/network-devp2p/src/ip_utils.rs b/crates/net/network-devp2p/src/ip_utils.rs index f13b9a8b6..c9a81462d 100644 --- a/crates/net/network-devp2p/src/ip_utils.rs +++ b/crates/net/network-devp2p/src/ip_utils.rs @@ -18,9 +18,9 @@ #![allow(unstable_name_collisions)] -use igd::{search_gateway_from_timeout, PortMappingProtocol}; -use ipnetwork::IpNetwork; use crate::node_table::NodeEndpoint; +use igd::{PortMappingProtocol, search_gateway_from_timeout}; +use ipnetwork::IpNetwork; use std::{ io, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, @@ -229,7 +229,7 @@ impl SocketAddrExt for IpAddr { #[cfg(not(any(windows, target_os = "android")))] mod getinterfaces { use libc::{ - freeifaddrs, getifaddrs, ifaddrs, sockaddr, sockaddr_in, sockaddr_in6, AF_INET, AF_INET6, + AF_INET, AF_INET6, freeifaddrs, getifaddrs, ifaddrs, sockaddr, sockaddr_in, sockaddr_in6, }; use std::{ io, mem, diff --git a/crates/net/network-devp2p/src/lib.rs b/crates/net/network-devp2p/src/lib.rs index 8341c2b4c..997b15e82 100644 --- a/crates/net/network-devp2p/src/lib.rs +++ b/crates/net/network-devp2p/src/lib.rs @@ -118,6 +118,6 @@ pub use service::NetworkService; pub use connection::PAYLOAD_SOFT_LIMIT; pub use crate::io::TimerToken; -pub use node_table::{validate_node_url, NodeId}; +pub use node_table::{NodeId, validate_node_url}; const PROTOCOL_VERSION: u32 = 5; diff --git a/crates/net/network-devp2p/src/node_table.rs b/crates/net/network-devp2p/src/node_table.rs index 1deb66239..fb2d0ec75 100644 --- a/crates/net/network-devp2p/src/node_table.rs +++ b/crates/net/network-devp2p/src/node_table.rs @@ -14,9 +14,11 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::discovery::{NodeEntry, TableUpdates}; +use crate::{ + discovery::{NodeEntry, TableUpdates}, + ip_utils::*, +}; use ethereum_types::H512; -use crate::ip_utils::*; use network::{AllowIP, Error, ErrorKind, IpFilter}; use rand::seq::SliceRandom; use rlp::{DecoderError, Rlp, RlpStream}; @@ -640,7 +642,9 @@ mod tests { #[test] fn node_parse() { assert!(validate_node_url("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@22.99.55.44:7770").is_none()); - let node = Node::from_str("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@22.99.55.44:7770"); + let node = Node::from_str( + "enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@22.99.55.44:7770", + ); assert!(node.is_ok()); let node = node.unwrap(); let v4 = match node.endpoint.address { @@ -755,15 +759,21 @@ mod tests { ], custom_block: vec![], }; - assert!(!NodeEndpoint::from_str("123.99.55.44:7770") - .unwrap() - .is_allowed(&filter)); - assert!(NodeEndpoint::from_str("10.0.0.1:7770") - .unwrap() - .is_allowed(&filter)); - assert!(NodeEndpoint::from_str("1.0.0.55:5550") - .unwrap() - .is_allowed(&filter)); + assert!( + !NodeEndpoint::from_str("123.99.55.44:7770") + .unwrap() + .is_allowed(&filter) + ); + assert!( + NodeEndpoint::from_str("10.0.0.1:7770") + .unwrap() + .is_allowed(&filter) + ); + assert!( + NodeEndpoint::from_str("1.0.0.55:5550") + .unwrap() + .is_allowed(&filter) + ); } #[test] @@ -776,15 +786,21 @@ mod tests { IpNetwork::from_str(&"1.0.0.0/8").unwrap(), ], }; - assert!(NodeEndpoint::from_str("123.99.55.44:7770") - .unwrap() - .is_allowed(&filter)); - assert!(!NodeEndpoint::from_str("10.0.0.1:7770") - .unwrap() - .is_allowed(&filter)); - assert!(!NodeEndpoint::from_str("1.0.0.55:5550") - .unwrap() - .is_allowed(&filter)); + assert!( + NodeEndpoint::from_str("123.99.55.44:7770") + .unwrap() + .is_allowed(&filter) + ); + assert!( + !NodeEndpoint::from_str("10.0.0.1:7770") + .unwrap() + .is_allowed(&filter) + ); + assert!( + !NodeEndpoint::from_str("1.0.0.55:5550") + .unwrap() + .is_allowed(&filter) + ); } #[test] @@ -794,12 +810,16 @@ mod tests { custom_allow: vec![IpNetwork::from_str(&"fc00::/8").unwrap()], custom_block: vec![], }; - assert!(NodeEndpoint::from_str("[fc00::]:5550") - .unwrap() - .is_allowed(&filter)); - assert!(!NodeEndpoint::from_str("[fd00::]:5550") - .unwrap() - .is_allowed(&filter)); + assert!( + NodeEndpoint::from_str("[fc00::]:5550") + .unwrap() + .is_allowed(&filter) + ); + assert!( + !NodeEndpoint::from_str("[fd00::]:5550") + .unwrap() + .is_allowed(&filter) + ); } #[test] @@ -809,11 +829,15 @@ mod tests { custom_allow: vec![], custom_block: vec![IpNetwork::from_str(&"fc00::/8").unwrap()], }; - assert!(!NodeEndpoint::from_str("[fc00::]:5550") - .unwrap() - .is_allowed(&filter)); - assert!(NodeEndpoint::from_str("[fd00::]:5550") - .unwrap() - .is_allowed(&filter)); + assert!( + !NodeEndpoint::from_str("[fc00::]:5550") + .unwrap() + .is_allowed(&filter) + ); + assert!( + NodeEndpoint::from_str("[fd00::]:5550") + .unwrap() + .is_allowed(&filter) + ); } } diff --git a/crates/net/network-devp2p/src/service.rs b/crates/net/network-devp2p/src/service.rs index 42c129b0f..d2dc26db0 100644 --- a/crates/net/network-devp2p/src/service.rs +++ b/crates/net/network-devp2p/src/service.rs @@ -18,7 +18,6 @@ use ansi_term::Colour; use crate::io::*; - use crate::network::{ ConnectionFilter, Error, NetworkConfiguration, NetworkContext, NetworkIoMessage, NetworkProtocolHandler, NonReservedPeerMode, PeerId, ProtocolId, diff --git a/crates/net/network-devp2p/src/session.rs b/crates/net/network-devp2p/src/session.rs index 5776ae41a..958d99e2e 100644 --- a/crates/net/network-devp2p/src/session.rs +++ b/crates/net/network-devp2p/src/session.rs @@ -22,22 +22,24 @@ use std::{ time::{Duration, Instant}, }; -use crate::connection::{Connection, EncryptedConnection, Packet, MAX_PAYLOAD_SIZE}; +use crate::{ + connection::{Connection, EncryptedConnection, MAX_PAYLOAD_SIZE, Packet}, + handshake::Handshake, + host::*, + io::{IoContext, StreamToken}, + node_table::NodeId, +}; use ethereum_types::H256; -use crate::handshake::Handshake; -use crate::host::*; -use crate::io::{IoContext, StreamToken}; use mio::{ deprecated::{EventLoop, Handler}, tcp::*, *, }; use network::{ - client_version::ClientVersion, DisconnectReason, Error, ErrorKind, PeerCapabilityInfo, - ProtocolId, SessionCapabilityInfo, SessionInfo, + DisconnectReason, Error, ErrorKind, PeerCapabilityInfo, ProtocolId, SessionCapabilityInfo, + SessionInfo, client_version::ClientVersion, }; -use crate::node_table::NodeId; -use rlp::{Rlp, RlpStream, EMPTY_LIST_RLP}; +use rlp::{EMPTY_LIST_RLP, Rlp, RlpStream}; use snappy; // Timeout must be less than (interval - 1). diff --git a/crates/net/network-devp2p/tests/tests.rs b/crates/net/network-devp2p/tests/tests.rs index a67b69ee3..d4bc0e374 100644 --- a/crates/net/network-devp2p/tests/tests.rs +++ b/crates/net/network-devp2p/tests/tests.rs @@ -23,17 +23,17 @@ extern crate parity_bytes; extern crate parity_crypto as crypto; extern crate parking_lot; +use crate::io::TimerToken; use crypto::publickey::{Generator, Random}; use ethcore_network::*; use ethcore_network_devp2p::NetworkService; use ethereum_types::U64; -use crate::io::TimerToken; use parity_bytes::Bytes; use parking_lot::Mutex; use std::{ sync::{ - atomic::{AtomicBool, Ordering as AtomicOrdering}, Arc, + atomic::{AtomicBool, Ordering as AtomicOrdering}, }, thread, time::*, diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index 1de0006df..a5f3e9e4e 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -391,8 +391,8 @@ pub mod tests { } #[test] - pub fn client_version_when_str_parity_long_format_and_valid_and_identity_multiple_tokens_then_all_fields_match( - ) { + pub fn client_version_when_str_parity_long_format_and_valid_and_identity_multiple_tokens_then_all_fields_match() + { let client_version_string = make_multitoken_identity_long_version_string(); if let ClientVersion::ParityClient(client_version) = @@ -434,8 +434,8 @@ pub mod tests { } #[test] - pub fn client_version_when_parity_format_and_invalid_then_equals_parity_unknown_client_version_string( - ) { + pub fn client_version_when_parity_format_and_invalid_then_equals_parity_unknown_client_version_string() + { // This is invalid because version has no leading 'v' let client_version_string = format!( "{}/{}/{}/{}", @@ -453,8 +453,8 @@ pub mod tests { } #[test] - pub fn client_version_when_parity_format_without_identity_and_missing_compiler_field_then_equals_parity_unknown_client_version_string( - ) { + pub fn client_version_when_parity_format_without_identity_and_missing_compiler_field_then_equals_parity_unknown_client_version_string() + { let client_version_string = format!( "{}/v{}/{}", CURRENT_CLIENT_ID_PREFIX, PARITY_CLIENT_SEMVER, PARITY_CLIENT_OS, @@ -468,8 +468,8 @@ pub mod tests { } #[test] - pub fn client_version_when_parity_format_with_identity_and_missing_compiler_field_then_equals_parity_unknown_client_version_string( - ) { + pub fn client_version_when_parity_format_with_identity_and_missing_compiler_field_then_equals_parity_unknown_client_version_string() + { let client_version_string = format!( "{}/{}/v{}/{}", CURRENT_CLIENT_ID_PREFIX, diff --git a/crates/net/network/src/error.rs b/crates/net/network/src/error.rs index 0ab8839f3..fff4dc42d 100644 --- a/crates/net/network/src/error.rs +++ b/crates/net/network/src/error.rs @@ -18,8 +18,8 @@ // https://github.com/openethereum/openethereum/issues/10302 #![allow(deprecated)] -use crypto; use crate::io::IoError; +use crypto; use libc::{EMFILE, ENFILE}; use rlp; use snappy; diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index 307747f71..cd116abe8 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -45,9 +45,9 @@ pub mod client_version; mod connection_filter; mod error; +pub use crate::io::TimerToken; pub use connection_filter::{ConnectionDirection, ConnectionFilter}; pub use error::{DisconnectReason, Error, ErrorKind}; -pub use crate::io::TimerToken; use crate::client_version::ClientVersion; use crypto::publickey::Secret; diff --git a/crates/net/node-filter/src/lib.rs b/crates/net/node-filter/src/lib.rs index 531f4a919..e08f8af3d 100644 --- a/crates/net/node-filter/src/lib.rs +++ b/crates/net/node-filter/src/lib.rs @@ -97,6 +97,7 @@ impl ConnectionFilter for NodeFilter { #[cfg(test)] mod test { use super::NodeFilter; + use crate::io::IoChannel; use ethcore::{ client::{BlockChainClient, Client, ClientConfig}, exit::ShutdownManager, @@ -105,7 +106,6 @@ mod test { test_helpers, }; use ethereum_types::Address; - use crate::io::IoChannel; use network::{ConnectionDirection, ConnectionFilter, NodeId}; use std::{ str::FromStr, diff --git a/crates/rpc/src/authcodes.rs b/crates/rpc/src/authcodes.rs index 97240cae6..e7713c382 100644 --- a/crates/rpc/src/authcodes.rs +++ b/crates/rpc/src/authcodes.rs @@ -25,7 +25,7 @@ use std::{ use ethereum_types::H256; use hash::keccak; use itertools::Itertools; -use rand::{distributions::Alphanumeric, rngs::OsRng, Rng}; +use rand::{Rng, distributions::Alphanumeric, rngs::OsRng}; /// Providing current time in seconds pub trait TimeProvider { diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index 296db0d00..4d2e2483c 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -126,20 +126,23 @@ pub mod v1; pub mod tests; pub use http::{ - cors::AccessControlAllowHeaders, hyper, AccessControlAllowOrigin, DomainsValidation, Host, - RequestMiddleware, RequestMiddlewareAction, + AccessControlAllowOrigin, DomainsValidation, Host, RequestMiddleware, RequestMiddlewareAction, + cors::AccessControlAllowHeaders, hyper, }; pub use ipc::{ MetaExtractor as IpcMetaExtractor, RequestContext as IpcRequestContext, Server as IpcServer, }; pub use jsonrpc_pubsub::Session as PubSubSession; -pub use crate::authcodes::{AuthCodes, TimeProvider}; -pub use crate::v1::{ - block_import::{is_major_importing, is_major_importing_or_waiting}, - dispatch, - extractors::{RpcExtractor, WsDispatcher, WsExtractor, WsStats}, - informant, signer, Metadata, NetworkSettings, Origin, +pub use crate::{ + authcodes::{AuthCodes, TimeProvider}, + v1::{ + Metadata, NetworkSettings, Origin, + block_import::{is_major_importing, is_major_importing_or_waiting}, + dispatch, + extractors::{RpcExtractor, WsDispatcher, WsExtractor, WsStats}, + informant, signer, + }, }; /// RPC HTTP Server instance diff --git a/crates/rpc/src/tests/rpc.rs b/crates/rpc/src/tests/rpc.rs index 4bbc337b0..3222cafee 100644 --- a/crates/rpc/src/tests/rpc.rs +++ b/crates/rpc/src/tests/rpc.rs @@ -24,7 +24,7 @@ use rpc_servers::{HttpServer, MetaIoHandler}; use crate::tests::{helpers::Server, http_client}; #[cfg(any(test, feature = "test-helpers"))] -use crate::v1::{extractors, Metadata}; +use crate::v1::{Metadata, extractors}; #[cfg(any(test, feature = "test-helpers"))] fn serve(handler: Option>) -> Server { @@ -58,9 +58,9 @@ fn request(server: Server, request: &str) -> http_client::Response { #[cfg(test)] mod tests { - use super::{request, Server}; - use jsonrpc_core::{MetaIoHandler, Value}; + use super::{Server, request}; use crate::v1::Metadata; + use jsonrpc_core::{MetaIoHandler, Value}; fn serve() -> (Server<::HttpServer>, ::std::net::SocketAddr) { let mut io = MetaIoHandler::default(); diff --git a/crates/rpc/src/tests/ws.rs b/crates/rpc/src/tests/ws.rs index 8640da9cb..f0a74c6bc 100644 --- a/crates/rpc/src/tests/ws.rs +++ b/crates/rpc/src/tests/ws.rs @@ -21,11 +21,13 @@ use std::sync::Arc; use jsonrpc_core::MetaIoHandler; use ws; -use crate::tests::{ - helpers::{GuardedAuthCodes, Server}, - http_client, +use crate::{ + tests::{ + helpers::{GuardedAuthCodes, Server}, + http_client, + }, + v1::{extractors, informant}, }; -use crate::v1::{extractors, informant}; /// Setup a mock signer for tests pub fn serve() -> (Server, usize, GuardedAuthCodes) { diff --git a/crates/rpc/src/v1/extractors.rs b/crates/rpc/src/v1/extractors.rs index 61706a1f3..68350c491 100644 --- a/crates/rpc/src/v1/extractors.rs +++ b/crates/rpc/src/v1/extractors.rs @@ -30,7 +30,7 @@ use jsonrpc_core::futures::future::Either; use jsonrpc_pubsub::Session; use ws; -use crate::v1::{informant::RpcStats, Metadata, Origin}; +use crate::v1::{Metadata, Origin, informant::RpcStats}; /// Common HTTP & IPC metadata extractor. pub struct RpcExtractor; @@ -184,11 +184,7 @@ fn auth_token_hash(codes_path: &Path, protocol: &str, save_file: bool) -> Option } } - if res { - Some(auth) - } else { - None - } + if res { Some(auth) } else { None } }); } @@ -261,11 +257,11 @@ impl> core::Middleware for WsDispatcher< #[cfg(test)] mod tests { use super::RpcExtractor; + use Origin; use http::{ - hyper::{Body, Request}, MetaExtractor, + hyper::{Body, Request}, }; - use Origin; #[test] fn should_extract_rpc_origin() { diff --git a/crates/rpc/src/v1/helpers/dispatch/full.rs b/crates/rpc/src/v1/helpers/dispatch/full.rs index c8ac43792..516e6d40a 100644 --- a/crates/rpc/src/v1/helpers/dispatch/full.rs +++ b/crates/rpc/src/v1/helpers/dispatch/full.rs @@ -16,26 +16,26 @@ use std::sync::Arc; +use crate::types::transaction::{PendingTransaction, SignedTransaction}; use ethcore::{ client::BlockChainClient, miner::{self, MinerService}, }; use ethereum_types::{Address, H256, U256}; use parking_lot::Mutex; -use crate::types::transaction::{PendingTransaction, SignedTransaction}; -use jsonrpc_core::{ - futures::{future, Future, IntoFuture}, - BoxFuture, Result, -}; use crate::v1::{ - helpers::{errors, nonce, FilledTransactionRequest, TransactionRequest}, + helpers::{FilledTransactionRequest, TransactionRequest, errors, nonce}, types::RichRawTransaction as RpcRichRawTransaction, }; +use jsonrpc_core::{ + BoxFuture, Result, + futures::{Future, IntoFuture, future}, +}; use super::{ - default_gas_price, prospective_signer::ProspectiveSigner, Accounts, Dispatcher, PostSign, - SignWith, + Accounts, Dispatcher, PostSign, SignWith, default_gas_price, + prospective_signer::ProspectiveSigner, }; /// A dispatcher which uses references to a client and miner in order to sign diff --git a/crates/rpc/src/v1/helpers/dispatch/mod.rs b/crates/rpc/src/v1/helpers/dispatch/mod.rs index e27b25062..7f7a01807 100644 --- a/crates/rpc/src/v1/helpers/dispatch/mod.rs +++ b/crates/rpc/src/v1/helpers/dispatch/mod.rs @@ -85,21 +85,17 @@ pub use crate::v1::helpers::nonce::Reservations; use std::{fmt::Debug, ops::Deref, sync::Arc}; +use crate::types::{ + BlockNumber, + transaction::{PendingTransaction, SignedTransaction}, +}; use bytes::Bytes; use crypto::publickey::Signature; use ethcore::{client::BlockChainClient, miner::MinerService}; use ethereum_types::{Address, H256, H520, U256}; use ethkey::Password; use hash::keccak; -use crate::types::{ - transaction::{PendingTransaction, SignedTransaction}, - BlockNumber, -}; -use jsonrpc_core::{ - futures::{future, Future, IntoFuture}, - BoxFuture, Error, Result, -}; use crate::v1::{ helpers::{ConfirmationPayload, FilledTransactionRequest, TransactionRequest}, types::{ @@ -108,6 +104,10 @@ use crate::v1::{ EthSignRequest as RpcEthSignRequest, RichRawTransaction as RpcRichRawTransaction, }, }; +use jsonrpc_core::{ + BoxFuture, Error, Result, + futures::{Future, IntoFuture, future}, +}; /// Has the capability to dispatch, sign, and decrypt. /// diff --git a/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs b/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs index 17ea408e8..7bb57da1c 100644 --- a/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs +++ b/crates/rpc/src/v1/helpers/dispatch/prospective_signer.rs @@ -16,15 +16,15 @@ use std::sync::Arc; +use crate::types::transaction::SignedTransaction; use ethereum_types::U256; use jsonrpc_core::{ - futures::{Async, Future, IntoFuture, Poll}, Error, Result, + futures::{Async, Future, IntoFuture, Poll}, }; -use crate::types::transaction::SignedTransaction; use super::{Accounts, PostSign, SignWith, WithToken}; -use crate::v1::helpers::{errors, nonce, FilledTransactionRequest}; +use crate::v1::helpers::{FilledTransactionRequest, errors, nonce}; #[derive(Debug, Clone, Copy)] enum ProspectiveSignerState { diff --git a/crates/rpc/src/v1/helpers/dispatch/signing.rs b/crates/rpc/src/v1/helpers/dispatch/signing.rs index 2cfdfe781..e69be7c08 100644 --- a/crates/rpc/src/v1/helpers/dispatch/signing.rs +++ b/crates/rpc/src/v1/helpers/dispatch/signing.rs @@ -16,20 +16,20 @@ use std::sync::Arc; -use accounts::AccountProvider; -use bytes::Bytes; -use crypto::{publickey::Signature, DEFAULT_MAC}; -use ethereum_types::{Address, H256, U256}; -use jsonrpc_core::{Error, ErrorCode}; use crate::types::transaction::{ AccessListTx, Action, EIP1559TransactionTx, SignedTransaction, Transaction, TypedTransaction, TypedTxId, }; +use accounts::AccountProvider; +use bytes::Bytes; +use crypto::{DEFAULT_MAC, publickey::Signature}; +use ethereum_types::{Address, H256, U256}; +use jsonrpc_core::{Error, ErrorCode}; +use crate::v1::helpers::{FilledTransactionRequest, errors}; use jsonrpc_core::Result; -use crate::v1::helpers::{errors, FilledTransactionRequest}; -use super::{eth_data_hash, SignMessage, SignWith, WithToken}; +use super::{SignMessage, SignWith, WithToken, eth_data_hash}; /// Account-aware signer pub struct Signer { diff --git a/crates/rpc/src/v1/helpers/eip191.rs b/crates/rpc/src/v1/helpers/eip191.rs index 82ef7e9bd..00365b6e5 100644 --- a/crates/rpc/src/v1/helpers/eip191.rs +++ b/crates/rpc/src/v1/helpers/eip191.rs @@ -15,16 +15,16 @@ // along with OpenEthereum. If not, see . //! EIP-191 compliant decoding + hashing -use eip_712::{hash_structured_data, EIP712}; -use ethereum_types::H256; -use hash::keccak; -use jsonrpc_core::Error; -use serde_json::{from_value, Value}; -use std::fmt::Display; use crate::v1::{ helpers::{dispatch::eth_data_hash, errors}, types::{Bytes, EIP191Version, PresignedTransaction}, }; +use eip_712::{EIP712, hash_structured_data}; +use ethereum_types::H256; +use hash::keccak; +use jsonrpc_core::Error; +use serde_json::{Value, from_value}; +use std::fmt::Display; /// deserializes and hashes the message depending on the version specifier pub fn hash_message(version: EIP191Version, message: Value) -> Result { diff --git a/crates/rpc/src/v1/helpers/errors.rs b/crates/rpc/src/v1/helpers/errors.rs index 47048654d..d67b4d809 100644 --- a/crates/rpc/src/v1/helpers/errors.rs +++ b/crates/rpc/src/v1/helpers/errors.rs @@ -18,14 +18,16 @@ use std::fmt; +use crate::{ + types::{blockchain_info::BlockChainInfo, transaction::Error as TransactionError}, + v1::{impls::EthClientOptions, types::BlockNumber}, +}; use ethcore::{ client::{BlockChainClient, BlockId}, error::{CallError, Error as EthcoreError, ErrorKind}, }; use jsonrpc_core::{Error, ErrorCode, Result as RpcResult, Value}; use rlp::DecoderError; -use crate::types::{blockchain_info::BlockChainInfo, transaction::Error as TransactionError}; -use crate::v1::{impls::EthClientOptions, types::BlockNumber}; use vm::Error as VMError; mod codes { @@ -532,10 +534,16 @@ pub fn require_experimental(allow_experimental_rpcs: bool, eip: &str) -> Result< Ok(()) } else { Err(Error { - code: ErrorCode::ServerError(codes::EXPERIMENTAL_RPC), - message: format!("This method is not part of the official RPC API yet (EIP-{}). Run with `--jsonrpc-experimental` to enable it.", eip), - data: Some(Value::String(format!("See EIP: https://eips.ethereum.org/EIPS/eip-{}", eip))), - }) + code: ErrorCode::ServerError(codes::EXPERIMENTAL_RPC), + message: format!( + "This method is not part of the official RPC API yet (EIP-{}). Run with `--jsonrpc-experimental` to enable it.", + eip + ), + data: Some(Value::String(format!( + "See EIP: https://eips.ethereum.org/EIPS/eip-{}", + eip + ))), + }) } } diff --git a/crates/rpc/src/v1/helpers/external_signer/oneshot.rs b/crates/rpc/src/v1/helpers/external_signer/oneshot.rs index adbda3faf..f3a975ae0 100644 --- a/crates/rpc/src/v1/helpers/external_signer/oneshot.rs +++ b/crates/rpc/src/v1/helpers/external_signer/oneshot.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::v1::helpers::errors; use jsonrpc_core::{ - futures::{self, sync::oneshot, Future}, Error, + futures::{self, Future, sync::oneshot}, }; -use crate::v1::helpers::errors; pub type Res = Result; diff --git a/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs b/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs index 3691d50ad..bb86a0f9d 100644 --- a/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs +++ b/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs @@ -17,8 +17,6 @@ use std::collections::BTreeMap; use super::oneshot; -use ethereum_types::U256; -use parking_lot::{Mutex, RwLock}; use crate::v1::{ helpers::{ errors, @@ -26,6 +24,8 @@ use crate::v1::{ }, types::{ConfirmationResponse, Origin}, }; +use ethereum_types::U256; +use parking_lot::{Mutex, RwLock}; use jsonrpc_core::Error; @@ -242,17 +242,17 @@ impl SigningQueue for ConfirmationsQueue { #[cfg(test)] mod test { - use ethereum_types::{Address, H256, U256}; - use jsonrpc_core::futures::Future; - use parking_lot::Mutex; - use std::sync::Arc; use crate::v1::{ helpers::{ - external_signer::{ConfirmationsQueue, QueueEvent, SigningQueue}, ConfirmationPayload, FilledTransactionRequest, + external_signer::{ConfirmationsQueue, QueueEvent, SigningQueue}, }, types::ConfirmationResponse, }; + use ethereum_types::{Address, H256, U256}; + use jsonrpc_core::futures::Future; + use parking_lot::Mutex; + use std::sync::Arc; fn request() -> ConfirmationPayload { ConfirmationPayload::SendTransaction(FilledTransactionRequest { diff --git a/crates/rpc/src/v1/helpers/fake_sign.rs b/crates/rpc/src/v1/helpers/fake_sign.rs index 9066cff77..58f6fd7e0 100644 --- a/crates/rpc/src/v1/helpers/fake_sign.rs +++ b/crates/rpc/src/v1/helpers/fake_sign.rs @@ -14,15 +14,15 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use std::cmp::min; use crate::types::transaction::{ AccessListTx, Action, EIP1559TransactionTx, SignedTransaction, Transaction, TypedTransaction, TypedTxId, }; +use std::cmp::min; +use crate::v1::helpers::CallRequest; use ethereum_types::U256; use jsonrpc_core::{Error, ErrorCode}; -use crate::v1::helpers::CallRequest; pub fn sign_call(request: CallRequest) -> Result { let max_gas = U256::from(500_000_000); diff --git a/crates/rpc/src/v1/helpers/mod.rs b/crates/rpc/src/v1/helpers/mod.rs index 5c16a907a..5091e18df 100644 --- a/crates/rpc/src/v1/helpers/mod.rs +++ b/crates/rpc/src/v1/helpers/mod.rs @@ -41,7 +41,7 @@ mod work; pub use self::{ network_settings::NetworkSettings, - poll_filter::{limit_logs, PollFilter, SyncPollFilter}, + poll_filter::{PollFilter, SyncPollFilter, limit_logs}, poll_manager::PollManager, requests::{ CallRequest, ConfirmationPayload, ConfirmationRequest, FilledTransactionRequest, diff --git a/crates/rpc/src/v1/helpers/nonce.rs b/crates/rpc/src/v1/helpers/nonce.rs index 47d937029..a7ccbe401 100644 --- a/crates/rpc/src/v1/helpers/nonce.rs +++ b/crates/rpc/src/v1/helpers/nonce.rs @@ -19,14 +19,13 @@ use std::{ collections::HashMap, mem, sync::{ - atomic, + Arc, atomic, atomic::{AtomicBool, AtomicUsize}, - Arc, }, }; use ethereum_types::{Address, U256}; -use futures::{future, future::Either, sync::oneshot, Async, Future, Poll}; +use futures::{Async, Future, Poll, future, future::Either, sync::oneshot}; use parity_runtime::Executor; /// Manages currently reserved and prospective nonces diff --git a/crates/rpc/src/v1/helpers/poll_filter.rs b/crates/rpc/src/v1/helpers/poll_filter.rs index a20346223..5db6f128e 100644 --- a/crates/rpc/src/v1/helpers/poll_filter.rs +++ b/crates/rpc/src/v1/helpers/poll_filter.rs @@ -16,14 +16,13 @@ //! Helper type with all filter state data. +use crate::{types::filter::Filter, v1::types::Log}; use ethereum_types::H256; use parking_lot::Mutex; use std::{ collections::{BTreeSet, HashSet, VecDeque}, sync::Arc, }; -use crate::types::filter::Filter; -use crate::v1::types::Log; pub type BlockNumber = u64; diff --git a/crates/rpc/src/v1/helpers/poll_manager.rs b/crates/rpc/src/v1/helpers/poll_manager.rs index 4644ecdaf..46983a913 100644 --- a/crates/rpc/src/v1/helpers/poll_manager.rs +++ b/crates/rpc/src/v1/helpers/poll_manager.rs @@ -83,9 +83,9 @@ where #[cfg(test)] mod tests { + use crate::v1::helpers::PollManager; use std::cell::Cell; use transient_hashmap::Timer; - use crate::v1::helpers::PollManager; struct TestTimer<'a> { time: &'a Cell, diff --git a/crates/rpc/src/v1/helpers/requests.rs b/crates/rpc/src/v1/helpers/requests.rs index d85478194..ca84ae371 100644 --- a/crates/rpc/src/v1/helpers/requests.rs +++ b/crates/rpc/src/v1/helpers/requests.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . use bytes::Bytes; -use ethereum_types::{Address, H256, U256, U64}; +use ethereum_types::{Address, H256, U64, U256}; use crate::v1::types::{AccessList, Origin, TransactionCondition}; diff --git a/crates/rpc/src/v1/helpers/secretstore.rs b/crates/rpc/src/v1/helpers/secretstore.rs index 3aa8b9f3f..f29171583 100644 --- a/crates/rpc/src/v1/helpers/secretstore.rs +++ b/crates/rpc/src/v1/helpers/secretstore.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::v1::{helpers::errors, types::EncryptedDocumentKey}; use bytes::Bytes; -use crypto::publickey::{self, ec_math_utils, Generator, Public, Random, Secret}; +use crypto::publickey::{self, Generator, Public, Random, Secret, ec_math_utils}; use ethereum_types::{H256, H512}; use jsonrpc_core::Error; -use rand::{rngs::OsRng, RngCore}; +use rand::{RngCore, rngs::OsRng}; use std::collections::BTreeSet; use tiny_keccak::Keccak; -use crate::v1::{helpers::errors, types::EncryptedDocumentKey}; /// Initialization vector length. const INIT_VEC_LEN: usize = 16; diff --git a/crates/rpc/src/v1/helpers/signature.rs b/crates/rpc/src/v1/helpers/signature.rs index 4cb4541f1..83fe5fa2b 100644 --- a/crates/rpc/src/v1/helpers/signature.rs +++ b/crates/rpc/src/v1/helpers/signature.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crypto::publickey::{public_to_address, recover, Signature}; -use ethereum_types::{H256, U64}; -use hash::keccak; -use jsonrpc_core::Result; use crate::v1::{ helpers::{dispatch::eth_data_hash, errors}, types::{Bytes, RecoveredAccount}, }; +use crypto::publickey::{Signature, public_to_address, recover}; +use ethereum_types::{H256, U64}; +use hash::keccak; +use jsonrpc_core::Result; /// helper method for parity_verifySignature pub fn verify_signature( diff --git a/crates/rpc/src/v1/helpers/subscribers.rs b/crates/rpc/src/v1/helpers/subscribers.rs index 2dac203a4..1ec424f4a 100644 --- a/crates/rpc/src/v1/helpers/subscribers.rs +++ b/crates/rpc/src/v1/helpers/subscribers.rs @@ -18,8 +18,8 @@ use ethereum_types::H64; use jsonrpc_pubsub::{ - typed::{Sink, Subscriber}, SubscriptionId, + typed::{Sink, Subscriber}, }; use std::{collections::HashMap, ops, str}; diff --git a/crates/rpc/src/v1/helpers/subscription_manager.rs b/crates/rpc/src/v1/helpers/subscription_manager.rs index 003bb32f6..88dc894cd 100644 --- a/crates/rpc/src/v1/helpers/subscription_manager.rs +++ b/crates/rpc/src/v1/helpers/subscription_manager.rs @@ -18,18 +18,17 @@ use parking_lot::Mutex; use std::sync::{ - atomic::{self, AtomicBool}, Arc, + atomic::{self, AtomicBool}, }; use jsonrpc_core::{ - self as core, + self as core, MetaIoHandler, futures::{ + Future, Sink, future::{self, Either}, sync::mpsc, - Future, Sink, }, - MetaIoHandler, }; use jsonrpc_pubsub::SubscriptionId; @@ -160,8 +159,8 @@ mod tests { use http::tokio::runtime::Runtime; use jsonrpc_core::{ - futures::{Future, Stream}, MetaIoHandler, NoopMiddleware, Params, Value, + futures::{Future, Stream}, }; use jsonrpc_pubsub::SubscriptionId; diff --git a/crates/rpc/src/v1/helpers/work.rs b/crates/rpc/src/v1/helpers/work.rs index c45ece7aa..6a0eeeb96 100644 --- a/crates/rpc/src/v1/helpers/work.rs +++ b/crates/rpc/src/v1/helpers/work.rs @@ -18,11 +18,11 @@ use std::sync::Arc; +use crate::v1::helpers::errors; use ethcore::miner::{BlockChainClient, MinerService}; -use ethereum_types::{H256, H64}; +use ethereum_types::{H64, H256}; use jsonrpc_core::Error; use rlp; -use crate::v1::helpers::errors; // Submit a POW work and return the block's hash pub fn submit_work_detail( diff --git a/crates/rpc/src/v1/impls/debug.rs b/crates/rpc/src/v1/impls/debug.rs index d2aee9fea..1425b26d9 100644 --- a/crates/rpc/src/v1/impls/debug.rs +++ b/crates/rpc/src/v1/impls/debug.rs @@ -18,14 +18,14 @@ use std::sync::Arc; -use ethcore::client::BlockChainClient; use crate::types::{header::Header, transaction::LocalizedTransaction}; +use ethcore::client::BlockChainClient; -use jsonrpc_core::Result; use crate::v1::{ traits::Debug, types::{Block, BlockTransactions, Bytes, RichBlock, Transaction}, }; +use jsonrpc_core::Result; /// Debug rpc implementation. pub struct DebugClient { diff --git a/crates/rpc/src/v1/impls/eth.rs b/crates/rpc/src/v1/impls/eth.rs index e6e688e2d..7c219cbbc 100644 --- a/crates/rpc/src/v1/impls/eth.rs +++ b/crates/rpc/src/v1/impls/eth.rs @@ -22,9 +22,18 @@ use std::{ time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; -use ethereum_types::{Address, BigEndianHash, H160, H256, H64, U256, U64}; +use ethereum_types::{Address, BigEndianHash, H64, H160, H256, U64, U256}; use parking_lot::Mutex; +use crate::{ + miner::external::ExternalMinerService, + types::{ + BlockNumber as EthBlockNumber, encoded, + filter::Filter as EthcoreFilter, + header::Header, + transaction::{LocalizedTransaction, SignedTransaction, TypedTransaction}, + }, +}; use ethash::{self, SeedHashCompute}; use ethcore::{ client::{ @@ -35,31 +44,23 @@ use ethcore::{ snapshot::SnapshotService, }; use hash::keccak; -use crate::miner::external::ExternalMinerService; use sync::SyncProvider; -use crate::types::{ - encoded, - filter::Filter as EthcoreFilter, - header::Header, - transaction::{LocalizedTransaction, SignedTransaction, TypedTransaction}, - BlockNumber as EthBlockNumber, -}; -use jsonrpc_core::{futures::future, BoxFuture, Result}; +use jsonrpc_core::{BoxFuture, Result, futures::future}; use crate::v1::{ helpers::{ self, block_import::is_major_importing, deprecated::{self, DeprecationNotice}, - dispatch::{default_gas_price, default_max_priority_fee_per_gas, FullDispatcher}, + dispatch::{FullDispatcher, default_gas_price, default_max_priority_fee_per_gas}, errors, fake_sign, limit_logs, }, traits::Eth, types::{ - block_number_to_id, Block, BlockNumber, BlockTransactions, Bytes, CallRequest, EthAccount, - EthFeeHistory, Filter, Index, Log, Receipt, RichBlock, StorageProof, SyncInfo, SyncStatus, - Transaction, Work, + Block, BlockNumber, BlockTransactions, Bytes, CallRequest, EthAccount, EthFeeHistory, + Filter, Index, Log, Receipt, RichBlock, StorageProof, SyncInfo, SyncStatus, Transaction, + Work, block_number_to_id, }, }; @@ -234,7 +235,9 @@ where ) } None => { - warn!("`Pending` is deprecated and may be removed in future versions. Falling back to `Latest`"); + warn!( + "`Pending` is deprecated and may be removed in future versions. Falling back to `Latest`" + ); client_query(BlockId::Latest) } } @@ -1365,13 +1368,14 @@ where }; let state = try_bf!(self.client.state_at(id).ok_or_else(errors::state_pruned)); - let header = try_bf!(self - .client - .block_header(id) - .ok_or_else(errors::state_pruned) - .and_then(|h| h - .decode(self.client.engine().params().eip1559_transition) - .map_err(errors::decode))); + let header = try_bf!( + self.client + .block_header(id) + .ok_or_else(errors::state_pruned) + .and_then(|h| h + .decode(self.client.engine().params().eip1559_transition) + .map_err(errors::decode)) + ); (state, header) }; @@ -1408,13 +1412,14 @@ where }; let state = try_bf!(self.client.state_at(id).ok_or_else(errors::state_pruned)); - let header = try_bf!(self - .client - .block_header(id) - .ok_or_else(errors::state_pruned) - .and_then(|h| h - .decode(self.client.engine().params().eip1559_transition) - .map_err(errors::decode))); + let header = try_bf!( + self.client + .block_header(id) + .ok_or_else(errors::state_pruned) + .and_then(|h| h + .decode(self.client.engine().params().eip1559_transition) + .map_err(errors::decode)) + ); (state, header) }; diff --git a/crates/rpc/src/v1/impls/eth_filter.rs b/crates/rpc/src/v1/impls/eth_filter.rs index 0ba5cec63..4f673b587 100644 --- a/crates/rpc/src/v1/impls/eth_filter.rs +++ b/crates/rpc/src/v1/impls/eth_filter.rs @@ -21,24 +21,24 @@ use std::{ sync::Arc, }; +use crate::types::filter::Filter as EthcoreFilter; use ethcore::{ client::{BlockChainClient, BlockId}, miner::{self, MinerService}, }; use ethereum_types::{H256, U256}; use parking_lot::Mutex; -use crate::types::filter::Filter as EthcoreFilter; -use jsonrpc_core::{ - futures::{future, future::Either, Future}, - BoxFuture, Result, -}; use crate::v1::{ - helpers::{errors, limit_logs, PollFilter, PollManager, SyncPollFilter}, + helpers::{PollFilter, PollManager, SyncPollFilter, errors, limit_logs}, impls::eth::pending_logs, traits::EthFilter, types::{BlockNumber, Filter, FilterChanges, Index, Log}, }; +use jsonrpc_core::{ + BoxFuture, Result, + futures::{Future, future, future::Either}, +}; /// Something which provides data that can be filtered over. pub trait Filterable { diff --git a/crates/rpc/src/v1/impls/eth_pubsub.rs b/crates/rpc/src/v1/impls/eth_pubsub.rs index b895d870e..6a32a56cf 100644 --- a/crates/rpc/src/v1/impls/eth_pubsub.rs +++ b/crates/rpc/src/v1/impls/eth_pubsub.rs @@ -22,19 +22,19 @@ use std::{ }; use jsonrpc_core::{ - futures::{self, Future, IntoFuture}, Error, Result, + futures::{self, Future, IntoFuture}, }; use jsonrpc_pubsub::{ - typed::{Sink, Subscriber}, SubscriptionId, + typed::{Sink, Subscriber}, }; use crate::v1::{ - helpers::{errors, limit_logs, Subscribers}, + helpers::{Subscribers, errors, limit_logs}, metadata::Metadata, traits::EthPubSub, - types::{pubsub, Header, Log, RichHeader}, + types::{Header, Log, RichHeader, pubsub}, }; use ethcore::client::{ diff --git a/crates/rpc/src/v1/impls/net.rs b/crates/rpc/src/v1/impls/net.rs index c649f7b3a..39e5ff381 100644 --- a/crates/rpc/src/v1/impls/net.rs +++ b/crates/rpc/src/v1/impls/net.rs @@ -15,10 +15,10 @@ // along with OpenEthereum. If not, see . //! Net rpc implementation. +use crate::v1::traits::Net; use jsonrpc_core::Result; use std::sync::Arc; use sync::SyncProvider; -use crate::v1::traits::Net; /// Net rpc implementation. pub struct NetClient { diff --git a/crates/rpc/src/v1/impls/parity.rs b/crates/rpc/src/v1/impls/parity.rs index 4cb70b0ba..5f27ac1f3 100644 --- a/crates/rpc/src/v1/impls/parity.rs +++ b/crates/rpc/src/v1/impls/parity.rs @@ -17,7 +17,26 @@ //! Parity-specific rpc implementation. use std::{collections::BTreeMap, str::FromStr, sync::Arc}; -use crypto::{publickey::ecies, DEFAULT_MAC}; +use crate::{ + Host, + types::ids::BlockId, + v1::{ + helpers::{ + self, NetworkSettings, + block_import::is_major_importing, + errors, + external_signer::{SignerService, SigningQueue}, + fake_sign, verify_signature, + }, + traits::Parity, + types::{ + BlockNumber, Bytes, CallRequest, ChainStatus, Header, Histogram, + LocalTransactionStatus, Peers, Receipt, RecoveredAccount, RichHeader, RpcSettings, + Transaction, TransactionStats, block_number_to_id, + }, + }, +}; +use crypto::{DEFAULT_MAC, publickey::ecies}; use ethcore::{ client::{BlockChainClient, Call, EngineInfo, StateClient}, miner::{self, MinerService, TransactionFilter}, @@ -25,30 +44,13 @@ use ethcore::{ state::StateInfo, }; use ethcore_logger::RotatingLogger; -use ethereum_types::{Address, H160, H256, H512, H64, U256, U64}; +use ethereum_types::{Address, H64, H160, H256, H512, U64, U256}; use ethkey::Brain; use ethstore::random_phrase; -use jsonrpc_core::{futures::future, BoxFuture, Result}; +use jsonrpc_core::{BoxFuture, Result, futures::future}; use stats::PrometheusMetrics; use sync::{ManageNetwork, SyncProvider}; -use crate::types::ids::BlockId; -use crate::v1::{ - helpers::{ - self, - block_import::is_major_importing, - errors, - external_signer::{SignerService, SigningQueue}, - fake_sign, verify_signature, NetworkSettings, - }, - traits::Parity, - types::{ - block_number_to_id, BlockNumber, Bytes, CallRequest, ChainStatus, Header, Histogram, - LocalTransactionStatus, Peers, Receipt, RecoveredAccount, RichHeader, RpcSettings, - Transaction, TransactionStats, - }, -}; use version::version_data; -use crate::Host; /// Parity implementation. pub struct ParityClient @@ -367,10 +369,11 @@ where let (header, extra) = if number == BlockNumber::Pending { let info = self.client.chain_info(); - let header = try_bf!(self - .miner - .pending_block_header(info.best_block_number) - .ok_or_else(errors::unknown_block)); + let header = try_bf!( + self.miner + .pending_block_header(info.best_block_number) + .ok_or_else(errors::unknown_block) + ); (header.encoded(), None) } else { @@ -382,10 +385,11 @@ where BlockNumber::Pending => unreachable!(), // Already covered }; - let header = try_bf!(self - .client - .block_header(id) - .ok_or_else(errors::unknown_block)); + let header = try_bf!( + self.client + .block_header(id) + .ok_or_else(errors::unknown_block) + ); let info = self.client.block_extra_info(id).expect(EXTRA_INFO_PROOF); (header, Some(info)) @@ -403,10 +407,11 @@ where let id = match number { BlockNumber::Pending => { let info = self.client.chain_info(); - let receipts = try_bf!(self - .miner - .pending_receipts(info.best_block_number) - .ok_or_else(errors::unknown_block)); + let receipts = try_bf!( + self.miner + .pending_receipts(info.best_block_number) + .ok_or_else(errors::unknown_block) + ); return Box::new(future::ok(receipts.into_iter().map(Into::into).collect())); } BlockNumber::Hash { hash, .. } => BlockId::Hash(hash), @@ -414,10 +419,11 @@ where BlockNumber::Earliest => BlockId::Earliest, BlockNumber::Latest => BlockId::Latest, }; - let receipts = try_bf!(self - .client - .localized_block_receipts(id) - .ok_or_else(errors::unknown_block)); + let receipts = try_bf!( + self.client + .localized_block_receipts(id) + .ok_or_else(errors::unknown_block) + ); Box::new(future::ok(receipts.into_iter().map(Into::into).collect())) } diff --git a/crates/rpc/src/v1/impls/parity_accounts.rs b/crates/rpc/src/v1/impls/parity_accounts.rs index 4e242047b..e9deefc4e 100644 --- a/crates/rpc/src/v1/impls/parity_accounts.rs +++ b/crates/rpc/src/v1/impls/parity_accounts.rs @@ -17,18 +17,12 @@ //! Account management (personal) rpc implementation use std::{ collections::{ - btree_map::{BTreeMap, Entry}, HashSet, + btree_map::{BTreeMap, Entry}, }, sync::Arc, }; -use accounts::AccountProvider; -use crypto::publickey::Secret; -use ethereum_types::{Address, H160, H256, H520}; -use ethkey::{Brain, Password}; -use ethstore::KeyFile; -use jsonrpc_core::Result; use crate::v1::{ helpers::{ deprecated::{self, DeprecationNotice}, @@ -37,6 +31,12 @@ use crate::v1::{ traits::{ParityAccounts, ParityAccountsInfo}, types::{AccountInfo, Derive, DeriveHash, DeriveHierarchical, ExtAccountInfo}, }; +use accounts::AccountProvider; +use crypto::publickey::Secret; +use ethereum_types::{Address, H160, H256, H520}; +use ethkey::{Brain, Password}; +use ethstore::KeyFile; +use jsonrpc_core::Result; /// Account management (personal) rpc implementation. pub struct ParityAccountsClient { diff --git a/crates/rpc/src/v1/impls/parity_set.rs b/crates/rpc/src/v1/impls/parity_set.rs index 7da68f243..083ef61bd 100644 --- a/crates/rpc/src/v1/impls/parity_set.rs +++ b/crates/rpc/src/v1/impls/parity_set.rs @@ -27,20 +27,22 @@ use fetch::{self, Fetch}; use hash::keccak_buffer; use sync::ManageNetwork; -use jsonrpc_core::{futures::Future, BoxFuture, Result}; use crate::v1::{ helpers::errors, traits::ParitySet, types::{Bytes, Transaction}, }; +use jsonrpc_core::{BoxFuture, Result, futures::Future}; #[cfg(any(test, feature = "accounts"))] pub mod accounts { use super::*; - use crate::accounts::AccountProvider; - use crate::v1::{ - helpers::{deprecated::DeprecationNotice, engine_signer::EngineSigner}, - traits::ParitySetAccounts, + use crate::{ + accounts::AccountProvider, + v1::{ + helpers::{deprecated::DeprecationNotice, engine_signer::EngineSigner}, + traits::ParitySetAccounts, + }, }; /// Parity-specific account-touching RPC interfaces. diff --git a/crates/rpc/src/v1/impls/personal.rs b/crates/rpc/src/v1/impls/personal.rs index 5750bddbf..970adb975 100644 --- a/crates/rpc/src/v1/impls/personal.rs +++ b/crates/rpc/src/v1/impls/personal.rs @@ -17,22 +17,17 @@ //! Account management (personal) rpc implementation use std::sync::Arc; +use crate::types::transaction::{PendingTransaction, SignedTransaction}; use accounts::AccountProvider; use bytes::Bytes; -use crypto::publickey::{public_to_address, recover, Signature}; -use eip_712::{hash_structured_data, EIP712}; +use crypto::publickey::{Signature, public_to_address, recover}; +use eip_712::{EIP712, hash_structured_data}; use ethereum_types::{Address, H160, H256, H520, U128}; -use crate::types::transaction::{PendingTransaction, SignedTransaction}; -use jsonrpc_core::{ - futures::{future, Future}, - types::Value, - BoxFuture, Result, -}; use crate::v1::{ helpers::{ deprecated::{self, DeprecationNotice}, - dispatch::{self, eth_data_hash, Dispatcher, PostSign, SignWith, WithToken}, + dispatch::{self, Dispatcher, PostSign, SignWith, WithToken, eth_data_hash}, eip191, errors, }, metadata::Metadata, @@ -43,6 +38,11 @@ use crate::v1::{ RichRawTransaction as RpcRichRawTransaction, TransactionRequest, }, }; +use jsonrpc_core::{ + BoxFuture, Result, + futures::{Future, future}, + types::Value, +}; /// Account management (personal) rpc implementation. pub struct PersonalClient { @@ -162,7 +162,7 @@ impl Personal for PersonalClient { return Err(errors::unsupported( "Time-unlocking is not supported when permanent unlock is disabled.", Some("Use personal_sendTransaction instead."), - )) + )); } }; match r { @@ -342,7 +342,9 @@ impl Personal for PersonalClient { "personal_signAndSendTransaction", Some("use personal_sendTransaction instead."), ); - warn!("Using deprecated personal_signAndSendTransaction, use personal_sendTransaction instead."); + warn!( + "Using deprecated personal_signAndSendTransaction, use personal_sendTransaction instead." + ); self.send_transaction(meta, request, password) } } diff --git a/crates/rpc/src/v1/impls/pubsub.rs b/crates/rpc/src/v1/impls/pubsub.rs index 1c87d3b53..064bd382e 100644 --- a/crates/rpc/src/v1/impls/pubsub.rs +++ b/crates/rpc/src/v1/impls/pubsub.rs @@ -20,15 +20,14 @@ use parking_lot::RwLock; use std::{sync::Arc, time::Duration}; use jsonrpc_core::{ - self as core, - futures::{future, Future, Sink, Stream}, - MetaIoHandler, Result, + self as core, MetaIoHandler, Result, + futures::{Future, Sink, Stream, future}, }; -use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; +use jsonrpc_pubsub::{SubscriptionId, typed::Subscriber}; use tokio_timer; -use parity_runtime::Executor; use crate::v1::{helpers::GenericPollManager, metadata::Metadata, traits::PubSub}; +use parity_runtime::Executor; /// Parity PubSub implementation. pub struct PubSubClient> { diff --git a/crates/rpc/src/v1/impls/rpc.rs b/crates/rpc/src/v1/impls/rpc.rs index a82d1bf79..2c2ffc1a4 100644 --- a/crates/rpc/src/v1/impls/rpc.rs +++ b/crates/rpc/src/v1/impls/rpc.rs @@ -15,9 +15,9 @@ // along with OpenEthereum. If not, see . //! RPC generic methods implementation. +use crate::v1::traits::Rpc; use jsonrpc_core::Result; use std::collections::BTreeMap; -use crate::v1::traits::Rpc; /// RPC generic methods implementation. pub struct RpcClient { diff --git a/crates/rpc/src/v1/impls/secretstore.rs b/crates/rpc/src/v1/impls/secretstore.rs index 0172e75b2..fd57acf69 100644 --- a/crates/rpc/src/v1/impls/secretstore.rs +++ b/crates/rpc/src/v1/impls/secretstore.rs @@ -19,11 +19,9 @@ use std::{collections::BTreeSet, sync::Arc}; use accounts::AccountProvider; -use crypto::{publickey::Secret, DEFAULT_MAC}; +use crypto::{DEFAULT_MAC, publickey::Secret}; use ethereum_types::{H160, H256, H512}; -use ethkey::Password; -use jsonrpc_core::Result; use crate::v1::{ helpers::{ errors, @@ -35,6 +33,8 @@ use crate::v1::{ traits::SecretStore, types::{Bytes, EncryptedDocumentKey}, }; +use ethkey::Password; +use jsonrpc_core::Result; /// Parity implementation. pub struct SecretStoreClient { diff --git a/crates/rpc/src/v1/impls/signer.rs b/crates/rpc/src/v1/impls/signer.rs index f2180498d..b605f0a78 100644 --- a/crates/rpc/src/v1/impls/signer.rs +++ b/crates/rpc/src/v1/impls/signer.rs @@ -18,27 +18,19 @@ use std::sync::Arc; +use crate::types::transaction::{PendingTransaction, SignedTransaction, TypedTransaction}; use crypto::publickey; use ethereum_types::{H520, U256}; use parity_runtime::Executor; use parking_lot::Mutex; -use crate::types::transaction::{PendingTransaction, SignedTransaction, TypedTransaction}; -use jsonrpc_core::{ - futures::{future, future::Either, Future, IntoFuture}, - BoxFuture, Error, Result, -}; -use jsonrpc_pubsub::{ - typed::{Sink, Subscriber}, - SubscriptionId, -}; use crate::v1::{ helpers::{ + ConfirmationPayload, FilledTransactionRequest, Subscribers, deprecated::{self, DeprecationNotice}, - dispatch::{self, eth_data_hash, Dispatcher, WithToken}, + dispatch::{self, Dispatcher, WithToken, eth_data_hash}, errors, external_signer::{SignerService, SigningQueue}, - ConfirmationPayload, FilledTransactionRequest, Subscribers, }, metadata::Metadata, traits::Signer, @@ -47,6 +39,14 @@ use crate::v1::{ TransactionModification, }, }; +use jsonrpc_core::{ + BoxFuture, Error, Result, + futures::{Future, IntoFuture, future, future::Either}, +}; +use jsonrpc_pubsub::{ + SubscriptionId, + typed::{Sink, Subscriber}, +}; /// Transactions confirmation (personal) rpc implementation. pub struct SignerClient { diff --git a/crates/rpc/src/v1/impls/signing.rs b/crates/rpc/src/v1/impls/signing.rs index 174c4d43a..b79bd6e1d 100644 --- a/crates/rpc/src/v1/impls/signing.rs +++ b/crates/rpc/src/v1/impls/signing.rs @@ -23,8 +23,8 @@ use transient_hashmap::TransientHashMap; use ethereum_types::{H160, H256, H520, U256}; use jsonrpc_core::{ - futures::{future, future::Either, Async, Future, Poll}, BoxFuture, Error, Result, + futures::{Async, Future, Poll, future, future::Either}, }; use crate::v1::{ diff --git a/crates/rpc/src/v1/impls/signing_unsafe.rs b/crates/rpc/src/v1/impls/signing_unsafe.rs index c82e324c9..a68704e4c 100644 --- a/crates/rpc/src/v1/impls/signing_unsafe.rs +++ b/crates/rpc/src/v1/impls/signing_unsafe.rs @@ -18,11 +18,6 @@ use std::sync::Arc; -use ethereum_types::{Address, H160, H256, H520, U256}; -use jsonrpc_core::{ - futures::{future, Future}, - BoxFuture, Result, -}; use crate::v1::{ helpers::{ deprecated::{self, DeprecationNotice}, @@ -37,6 +32,11 @@ use crate::v1::{ RichRawTransaction as RpcRichRawTransaction, TransactionRequest as RpcTransactionRequest, }, }; +use ethereum_types::{Address, H160, H256, H520, U256}; +use jsonrpc_core::{ + BoxFuture, Result, + futures::{Future, future}, +}; /// Implementation of functions that require signing when no trusted signer is used. pub struct SigningUnsafeClient { diff --git a/crates/rpc/src/v1/impls/traces.rs b/crates/rpc/src/v1/impls/traces.rs index 1e0fbd72f..f0e67cdfe 100644 --- a/crates/rpc/src/v1/impls/traces.rs +++ b/crates/rpc/src/v1/impls/traces.rs @@ -18,22 +18,22 @@ use std::sync::Arc; +use crate::types::transaction::{SignedTransaction, TypedTransaction}; use ethcore::client::{ BlockChainClient, BlockId, Call, CallAnalytics, EngineInfo, StateClient, StateInfo, TraceId, TransactionId, }; use ethereum_types::H256; -use crate::types::transaction::{SignedTransaction, TypedTransaction}; -use jsonrpc_core::Result; use crate::v1::{ helpers::{errors, fake_sign}, traits::Traces, types::{ - block_number_to_id, BlockNumber, Bytes, CallRequest, Index, LocalizedTrace, TraceFilter, - TraceOptions, TraceResults, TraceResultsWithTransactionHash, + BlockNumber, Bytes, CallRequest, Index, LocalizedTrace, TraceFilter, TraceOptions, + TraceResults, TraceResultsWithTransactionHash, block_number_to_id, }, }; +use jsonrpc_core::Result; fn to_call_analytics(flags: TraceOptions) -> CallAnalytics { CallAnalytics { @@ -118,7 +118,7 @@ where return Err(errors::invalid_params( "`BlockNumber::Pending` is not supported", (), - )) + )); } }; @@ -167,7 +167,7 @@ where return Err(errors::invalid_params( "`BlockNumber::Pending` is not supported", (), - )) + )); } }; @@ -211,7 +211,7 @@ where return Err(errors::invalid_params( "`BlockNumber::Pending` is not supported", (), - )) + )); } }; @@ -263,7 +263,7 @@ where return Err(errors::invalid_params( "`BlockNumber::Pending` is not supported", (), - )) + )); } }; diff --git a/crates/rpc/src/v1/impls/web3.rs b/crates/rpc/src/v1/impls/web3.rs index a4abe41bf..eacd1a99e 100644 --- a/crates/rpc/src/v1/impls/web3.rs +++ b/crates/rpc/src/v1/impls/web3.rs @@ -15,10 +15,10 @@ // along with OpenEthereum. If not, see . //! Web3 rpc implementation. +use crate::v1::{traits::Web3, types::Bytes}; use ethereum_types::H256; use hash::keccak; use jsonrpc_core::Result; -use crate::v1::{traits::Web3, types::Bytes}; use version::version; /// Web3 rpc implementation. diff --git a/crates/rpc/src/v1/informant.rs b/crates/rpc/src/v1/informant.rs index 7e64dc756..67175080b 100644 --- a/crates/rpc/src/v1/informant.rs +++ b/crates/rpc/src/v1/informant.rs @@ -24,8 +24,8 @@ use parking_lot::RwLock; use std::{ fmt, sync::{ - atomic::{self, AtomicUsize}, Arc, + atomic::{self, AtomicUsize}, }, time, }; diff --git a/crates/rpc/src/v1/mod.rs b/crates/rpc/src/v1/mod.rs index fe4357c15..09077b110 100644 --- a/crates/rpc/src/v1/mod.rs +++ b/crates/rpc/src/v1/mod.rs @@ -43,7 +43,7 @@ pub mod traits; pub use self::{ extractors::{RpcExtractor, WsDispatcher, WsExtractor, WsStats}, - helpers::{block_import, dispatch, NetworkSettings}, + helpers::{NetworkSettings, block_import, dispatch}, impls::*, metadata::Metadata, traits::{ diff --git a/crates/rpc/src/v1/tests/eth.rs b/crates/rpc/src/v1/tests/eth.rs index 7f773f247..1bb03da6f 100644 --- a/crates/rpc/src/v1/tests/eth.rs +++ b/crates/rpc/src/v1/tests/eth.rs @@ -17,6 +17,7 @@ //! rpc integration tests. use std::{env, sync::Arc}; +use crate::{io::IoChannel, types::ids::BlockId}; use accounts::AccountProvider; use ethcore::{ client::{BlockChainClient, ChainInfo, Client, ClientConfig, EvmTestClient, ImportBlock}, @@ -24,17 +25,14 @@ use ethcore::{ miner::Miner, spec::{Genesis, Spec}, test_helpers, - verification::{queue::kind::blocks::Unverified, VerifierType}, + verification::{VerifierType, queue::kind::blocks::Unverified}, }; use ethereum_types::{Address, H256, U256}; use ethjson::{blockchain::BlockChain, spec::ForkSpec}; -use crate::io::IoChannel; use miner::external::ExternalMiner; use parity_runtime::Runtime; use parking_lot::Mutex; -use crate::types::ids::BlockId; -use jsonrpc_core::IoHandler; use crate::v1::{ helpers::{ dispatch::{self, FullDispatcher}, @@ -45,6 +43,7 @@ use crate::v1::{ tests::helpers::{Config, TestSnapshotService, TestSyncProvider}, traits::{Eth, EthSigning}, }; +use jsonrpc_core::IoHandler; fn account_provider() -> Arc { Arc::new(AccountProvider::transient_provider()) @@ -226,12 +225,14 @@ fn eth_get_proof() { }"#; let res_latest = r#","address":"0xaaaf5374fce5edbc8e2a8697c15331677e6ebaaa","balance":"0x9","codeHash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","nonce":"0x0","storageHash":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","storageProof":[]},"id":1}"#.to_owned(); - assert!(tester - .handler - .handle_request_sync(req_latest) - .unwrap() - .to_string() - .ends_with(res_latest.as_str())); + assert!( + tester + .handler + .handle_request_sync(req_latest) + .unwrap() + .to_string() + .ends_with(res_latest.as_str()) + ); // non-existant account let req_new_acc = r#"{ @@ -242,12 +243,14 @@ fn eth_get_proof() { }"#; let res_new_acc = r#","address":"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","balance":"0x0","codeHash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","nonce":"0x0","storageHash":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","storageProof":[]},"id":3}"#.to_owned(); - assert!(tester - .handler - .handle_request_sync(req_new_acc) - .unwrap() - .to_string() - .ends_with(res_new_acc.as_str())); + assert!( + tester + .handler + .handle_request_sync(req_new_acc) + .unwrap() + .to_string() + .ends_with(res_new_acc.as_str()) + ); } #[test] diff --git a/crates/rpc/src/v1/tests/helpers/miner_service.rs b/crates/rpc/src/v1/tests/helpers/miner_service.rs index 5abaaa3e8..a229118e0 100644 --- a/crates/rpc/src/v1/tests/helpers/miner_service.rs +++ b/crates/rpc/src/v1/tests/helpers/miner_service.rs @@ -21,32 +21,32 @@ use std::{ sync::Arc, }; +use crate::types::{ + BlockNumber, + block::Block, + header::Header, + ids::BlockId, + receipt::RichReceipt, + transaction::{self, PendingTransaction, SignedTransaction, UnverifiedTransaction}, +}; use bytes::Bytes; use call_contract::CallContract; use ethcore::{ block::SealedBlock, client::{ - test_client::TestState, traits::ForceUpdateSealing, BlockChain, EngineInfo, Nonce, - PrepareOpenBlock, StateClient, + BlockChain, EngineInfo, Nonce, PrepareOpenBlock, StateClient, test_client::TestState, + traits::ForceUpdateSealing, }, - engines::{signer::EngineSigner, EthEngine}, + engines::{EthEngine, signer::EngineSigner}, error::Error, miner::{self, AuthoringParams, MinerService, TransactionFilter}, }; use ethereum_types::{Address, H256, U256}; use miner::pool::{ - local_transactions::Status as LocalTransactionStatus, verifier, QueueStatus, - VerifiedTransaction, + QueueStatus, VerifiedTransaction, local_transactions::Status as LocalTransactionStatus, + verifier, }; use parking_lot::{Mutex, RwLock}; -use crate::types::{ - block::Block, - header::Header, - ids::BlockId, - receipt::RichReceipt, - transaction::{self, PendingTransaction, SignedTransaction, UnverifiedTransaction}, - BlockNumber, -}; /// Test miner service. pub struct TestMinerService { diff --git a/crates/rpc/src/v1/tests/mocked/debug.rs b/crates/rpc/src/v1/tests/mocked/debug.rs index 4e0653de8..2f1726e99 100644 --- a/crates/rpc/src/v1/tests/mocked/debug.rs +++ b/crates/rpc/src/v1/tests/mocked/debug.rs @@ -18,8 +18,8 @@ use std::sync::Arc; use ethcore::client::TestBlockChainClient; -use jsonrpc_core::IoHandler; use crate::v1::{Debug, DebugClient}; +use jsonrpc_core::IoHandler; fn io() -> IoHandler { let client = Arc::new(TestBlockChainClient::new()); diff --git a/crates/rpc/src/v1/tests/mocked/eth.rs b/crates/rpc/src/v1/tests/mocked/eth.rs index 74167f177..4ed588e60 100644 --- a/crates/rpc/src/v1/tests/mocked/eth.rs +++ b/crates/rpc/src/v1/tests/mocked/eth.rs @@ -21,6 +21,12 @@ use std::{ time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; +use crate::types::{ + ids::{BlockId, TransactionId}, + log_entry::{LocalizedLogEntry, LogEntry}, + receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome}, + transaction::{Action, Transaction, TypedTransaction, TypedTxId}, +}; use accounts::AccountProvider; use ethcore::{ client::{BlockChainClient, EachBlockWith, EvmTestClient, Executed, TestBlockChainClient}, @@ -32,19 +38,13 @@ use parity_runtime::Runtime; use parking_lot::Mutex; use rustc_hex::{FromHex, ToHex}; use sync::SyncState; -use crate::types::{ - ids::{BlockId, TransactionId}, - log_entry::{LocalizedLogEntry, LogEntry}, - receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome}, - transaction::{Action, Transaction, TypedTransaction, TypedTxId}, -}; -use jsonrpc_core::IoHandler; use crate::v1::{ + Eth, EthClient, EthClientOptions, EthFilter, EthFilterClient, metadata::Metadata, tests::helpers::{Config, TestMinerService, TestSnapshotService, TestSyncProvider}, - Eth, EthClient, EthClientOptions, EthFilter, EthFilterClient, }; +use jsonrpc_core::IoHandler; fn blockchain_client() -> Arc { let client = TestBlockChainClient::new(); @@ -750,8 +750,8 @@ fn rpc_eth_transaction_count_by_number_pending() { #[test] fn rpc_eth_pending_transaction_by_hash() { - use ethereum_types::H256; use crate::types::transaction::SignedTransaction; + use ethereum_types::H256; let tester = EthTester::default(); { diff --git a/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs b/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs index a8a9f5bbe..71585b1d7 100644 --- a/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs +++ b/crates/rpc/src/v1/tests/mocked/eth_pubsub.rs @@ -17,8 +17,8 @@ use std::sync::Arc; use jsonrpc_core::{ - futures::{self, Future, Stream}, MetaIoHandler, + futures::{self, Future, Stream}, }; use jsonrpc_pubsub::Session; @@ -115,11 +115,11 @@ fn should_subscribe_to_new_heads() { #[test] fn should_subscribe_to_logs() { - use ethcore::client::BlockInfo; use crate::types::{ ids::BlockId, log_entry::{LocalizedLogEntry, LogEntry}, }; + use ethcore::client::BlockInfo; // given let el = Runtime::with_thread_count(1); diff --git a/crates/rpc/src/v1/tests/mocked/net.rs b/crates/rpc/src/v1/tests/mocked/net.rs index a100110a1..e38f0cd2e 100644 --- a/crates/rpc/src/v1/tests/mocked/net.rs +++ b/crates/rpc/src/v1/tests/mocked/net.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use jsonrpc_core::IoHandler; -use std::sync::Arc; use crate::v1::{ - tests::helpers::{Config, TestSyncProvider}, Net, NetClient, + tests::helpers::{Config, TestSyncProvider}, }; +use jsonrpc_core::IoHandler; +use std::sync::Arc; fn sync_provider() -> Arc { Arc::new(TestSyncProvider::new(Config { diff --git a/crates/rpc/src/v1/tests/mocked/parity.rs b/crates/rpc/src/v1/tests/mocked/parity.rs index 83d7a2e3c..9e8ed186d 100644 --- a/crates/rpc/src/v1/tests/mocked/parity.rs +++ b/crates/rpc/src/v1/tests/mocked/parity.rs @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::types::{ + receipt::{LocalizedReceipt, TransactionOutcome}, + transaction::TypedTxId, +}; use crypto::publickey::{Generator, Random}; use ethcore::client::{Executed, TestBlockChainClient, TransactionId}; use ethcore_logger::RotatingLogger; @@ -21,20 +25,16 @@ use ethereum_types::{Address, BigEndianHash, Bloom, H256, U256}; use miner::pool::local_transactions::Status as LocalTransactionStatus; use std::{str::FromStr, sync::Arc}; use sync::ManageNetwork; -use crate::types::{ - receipt::{LocalizedReceipt, TransactionOutcome}, - transaction::TypedTxId, -}; use super::manage_network::TestManageNetwork; -use jsonrpc_core::IoHandler; use crate::v1::{ - helpers::{external_signer::SignerService, NetworkSettings}, + Parity, ParityClient, + helpers::{NetworkSettings, external_signer::SignerService}, metadata::Metadata, tests::helpers::{Config, TestMinerService, TestSyncProvider}, - Parity, ParityClient, }; use Host; +use jsonrpc_core::IoHandler; pub type TestParityClient = ParityClient; diff --git a/crates/rpc/src/v1/tests/mocked/parity_accounts.rs b/crates/rpc/src/v1/tests/mocked/parity_accounts.rs index 16f37129e..0cb55aa41 100644 --- a/crates/rpc/src/v1/tests/mocked/parity_accounts.rs +++ b/crates/rpc/src/v1/tests/mocked/parity_accounts.rs @@ -18,11 +18,11 @@ use std::{str::FromStr, sync::Arc}; use accounts::{AccountProvider, AccountProviderSettings}; use ethereum_types::Address; -use ethstore::{accounts_dir::RootDiskDirectory, EthStore}; +use ethstore::{EthStore, accounts_dir::RootDiskDirectory}; use tempdir::TempDir; -use jsonrpc_core::IoHandler; use crate::v1::{ParityAccounts, ParityAccountsClient, ParityAccountsInfo}; +use jsonrpc_core::IoHandler; struct ParityAccountsTester { accounts: Arc, @@ -154,7 +154,10 @@ fn should_be_able_to_get_account_info() { let request = r#"{"jsonrpc": "2.0", "method": "parity_allAccountsInfo", "params": [], "id": 1}"#; let res = tester.io.handle_request_sync(request); - let response = format!("{{\"jsonrpc\":\"2.0\",\"result\":{{\"0x{:x}\":{{\"meta\":\"{{foo: 69}}\",\"name\":\"Test\",\"uuid\":\"{}\"}}}},\"id\":1}}", address, uuid); + let response = format!( + "{{\"jsonrpc\":\"2.0\",\"result\":{{\"0x{:x}\":{{\"meta\":\"{{foo: 69}}\",\"name\":\"Test\",\"uuid\":\"{}\"}}}},\"id\":1}}", + address, uuid + ); assert_eq!(res, Some(response)); } @@ -188,7 +191,10 @@ fn should_be_able_to_set_name() { let request = r#"{"jsonrpc": "2.0", "method": "parity_allAccountsInfo", "params": [], "id": 1}"#; let res = tester.io.handle_request_sync(request); - let response = format!("{{\"jsonrpc\":\"2.0\",\"result\":{{\"0x{:x}\":{{\"meta\":\"{{}}\",\"name\":\"Test\",\"uuid\":\"{}\"}}}},\"id\":1}}", address, uuid); + let response = format!( + "{{\"jsonrpc\":\"2.0\",\"result\":{{\"0x{:x}\":{{\"meta\":\"{{}}\",\"name\":\"Test\",\"uuid\":\"{}\"}}}},\"id\":1}}", + address, uuid + ); assert_eq!(res, Some(response)); } @@ -222,7 +228,10 @@ fn should_be_able_to_set_meta() { let request = r#"{"jsonrpc": "2.0", "method": "parity_allAccountsInfo", "params": [], "id": 1}"#; let res = tester.io.handle_request_sync(request); - let response = format!("{{\"jsonrpc\":\"2.0\",\"result\":{{\"0x{:x}\":{{\"meta\":\"{{foo: 69}}\",\"name\":\"\",\"uuid\":\"{}\"}}}},\"id\":1}}", address, uuid); + let response = format!( + "{{\"jsonrpc\":\"2.0\",\"result\":{{\"0x{:x}\":{{\"meta\":\"{{foo: 69}}\",\"name\":\"\",\"uuid\":\"{}\"}}}},\"id\":1}}", + address, uuid + ); assert_eq!(res, Some(response)); } @@ -297,10 +306,12 @@ fn rpc_parity_new_vault() { Some(response.to_owned()) ); assert!(tester.accounts.close_vault("vault1").is_ok()); - assert!(tester - .accounts - .open_vault("vault1", &"password1".into()) - .is_ok()); + assert!( + tester + .accounts + .open_vault("vault1", &"password1".into()) + .is_ok() + ); } #[test] @@ -308,10 +319,12 @@ fn rpc_parity_open_vault() { let tempdir = TempDir::new("").unwrap(); let tester = setup_with_vaults_support(tempdir.path().to_str().unwrap()); - assert!(tester - .accounts - .create_vault("vault1", &"password1".into()) - .is_ok()); + assert!( + tester + .accounts + .create_vault("vault1", &"password1".into()) + .is_ok() + ); assert!(tester.accounts.close_vault("vault1").is_ok()); let request = r#"{"jsonrpc": "2.0", "method": "parity_openVault", "params":["vault1", "password1"], "id": 1}"#; @@ -328,10 +341,12 @@ fn rpc_parity_close_vault() { let tempdir = TempDir::new("").unwrap(); let tester = setup_with_vaults_support(tempdir.path().to_str().unwrap()); - assert!(tester - .accounts - .create_vault("vault1", &"password1".into()) - .is_ok()); + assert!( + tester + .accounts + .create_vault("vault1", &"password1".into()) + .is_ok() + ); let request = r#"{"jsonrpc": "2.0", "method": "parity_closeVault", "params":["vault1"], "id": 1}"#; @@ -348,10 +363,12 @@ fn rpc_parity_change_vault_password() { let tempdir = TempDir::new("").unwrap(); let tester = setup_with_vaults_support(tempdir.path().to_str().unwrap()); - assert!(tester - .accounts - .create_vault("vault1", &"password1".into()) - .is_ok()); + assert!( + tester + .accounts + .create_vault("vault1", &"password1".into()) + .is_ok() + ); let request = r#"{"jsonrpc": "2.0", "method": "parity_changeVaultPassword", "params":["vault1", "password2"], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; @@ -371,10 +388,12 @@ fn rpc_parity_change_vault() { .accounts .new_account_and_public(&"root_password".into()) .unwrap(); - assert!(tester - .accounts - .create_vault("vault1", &"password1".into()) - .is_ok()); + assert!( + tester + .accounts + .create_vault("vault1", &"password1".into()) + .is_ok() + ); let request = format!( r#"{{"jsonrpc": "2.0", "method": "parity_changeVault", "params":["0x{:x}", "vault1"], "id": 1}}"#, @@ -403,10 +422,12 @@ fn rpc_parity_vault_adds_vault_field_to_acount_meta() { .unwrap() .uuid .unwrap(); - assert!(tester - .accounts - .create_vault("vault1", &"password1".into()) - .is_ok()); + assert!( + tester + .accounts + .create_vault("vault1", &"password1".into()) + .is_ok() + ); assert!(tester.accounts.change_vault(address1, "vault1").is_ok()); let request = r#"{"jsonrpc": "2.0", "method": "parity_allAccountsInfo", "params":[], "id": 1}"#; @@ -440,14 +461,18 @@ fn rpc_parity_list_vaults() { let tempdir = TempDir::new("").unwrap(); let tester = setup_with_vaults_support(tempdir.path().to_str().unwrap()); - assert!(tester - .accounts - .create_vault("vault1", &"password1".into()) - .is_ok()); - assert!(tester - .accounts - .create_vault("vault2", &"password2".into()) - .is_ok()); + assert!( + tester + .accounts + .create_vault("vault1", &"password1".into()) + .is_ok() + ); + assert!( + tester + .accounts + .create_vault("vault2", &"password2".into()) + .is_ok() + ); let request = r#"{"jsonrpc": "2.0", "method": "parity_listVaults", "params":[], "id": 1}"#; let response1 = r#"{"jsonrpc":"2.0","result":["vault1","vault2"],"id":1}"#; @@ -465,18 +490,24 @@ fn rpc_parity_list_opened_vaults() { let tempdir = TempDir::new("").unwrap(); let tester = setup_with_vaults_support(tempdir.path().to_str().unwrap()); - assert!(tester - .accounts - .create_vault("vault1", &"password1".into()) - .is_ok()); - assert!(tester - .accounts - .create_vault("vault2", &"password2".into()) - .is_ok()); - assert!(tester - .accounts - .create_vault("vault3", &"password3".into()) - .is_ok()); + assert!( + tester + .accounts + .create_vault("vault1", &"password1".into()) + .is_ok() + ); + assert!( + tester + .accounts + .create_vault("vault2", &"password2".into()) + .is_ok() + ); + assert!( + tester + .accounts + .create_vault("vault3", &"password3".into()) + .is_ok() + ); assert!(tester.accounts.close_vault("vault2").is_ok()); let request = @@ -496,10 +527,12 @@ fn rpc_parity_get_set_vault_meta() { let tempdir = TempDir::new("").unwrap(); let tester = setup_with_vaults_support(tempdir.path().to_str().unwrap()); - assert!(tester - .accounts - .create_vault("vault1", &"password1".into()) - .is_ok()); + assert!( + tester + .accounts + .create_vault("vault1", &"password1".into()) + .is_ok() + ); // when no meta set let request = @@ -512,10 +545,12 @@ fn rpc_parity_get_set_vault_meta() { ); // when meta set - assert!(tester - .accounts - .set_vault_meta("vault1", "vault1_meta") - .is_ok()); + assert!( + tester + .accounts + .set_vault_meta("vault1", "vault1_meta") + .is_ok() + ); let request = r#"{"jsonrpc": "2.0", "method": "parity_getVaultMeta", "params":["vault1"], "id": 1}"#; diff --git a/crates/rpc/src/v1/tests/mocked/parity_set.rs b/crates/rpc/src/v1/tests/mocked/parity_set.rs index ca3a62ca8..a320ed334 100644 --- a/crates/rpc/src/v1/tests/mocked/parity_set.rs +++ b/crates/rpc/src/v1/tests/mocked/parity_set.rs @@ -22,8 +22,8 @@ use ethcore::{client::TestBlockChainClient, miner::MinerService}; use sync::ManageNetwork; use super::manage_network::TestManageNetwork; +use crate::v1::{ParitySet, ParitySetClient, tests::helpers::TestMinerService}; use jsonrpc_core::IoHandler; -use crate::v1::{tests::helpers::TestMinerService, ParitySet, ParitySetClient}; use fake_fetch::FakeFetch; @@ -210,9 +210,9 @@ fn rpc_parity_remove_transaction() { #[test] fn rpc_parity_set_engine_signer() { + use crate::v1::{impls::ParitySetAccountsClient, traits::ParitySetAccounts}; use accounts::AccountProvider; use bytes::ToPretty; - use crate::v1::{impls::ParitySetAccountsClient, traits::ParitySetAccounts}; let account_provider = Arc::new(AccountProvider::transient_provider()); account_provider @@ -239,5 +239,8 @@ fn rpc_parity_set_engine_signer() { .sign(::hash::keccak("x")) .unwrap() .to_vec(); - assert_eq!(&format!("{}", signature.pretty()), "6f46069ded2154af6e806706e4f7f6fd310ac45f3c6dccb85f11c0059ee20a09245df0a0008bb84a10882b1298284bc93058e7bc5938ea728e77620061687a6401"); + assert_eq!( + &format!("{}", signature.pretty()), + "6f46069ded2154af6e806706e4f7f6fd310ac45f3c6dccb85f11c0059ee20a09245df0a0008bb84a10882b1298284bc93058e7bc5938ea728e77620061687a6401" + ); } diff --git a/crates/rpc/src/v1/tests/mocked/personal.rs b/crates/rpc/src/v1/tests/mocked/personal.rs index b648021ba..ec91f4609 100644 --- a/crates/rpc/src/v1/tests/mocked/personal.rs +++ b/crates/rpc/src/v1/tests/mocked/personal.rs @@ -16,6 +16,7 @@ use std::{str::FromStr, sync::Arc}; +use crate::types::transaction::{Action, Transaction, TypedTransaction}; use accounts::AccountProvider; use bytes::ToPretty; use crypto::publickey::Secret; @@ -25,18 +26,17 @@ use hash::keccak; use jsonrpc_core::IoHandler; use parity_runtime::Runtime; use parking_lot::Mutex; -use crate::types::transaction::{Action, Transaction, TypedTransaction}; -use serde_json::to_value; use crate::v1::{ + Metadata, Personal, PersonalClient, helpers::{ - dispatch::{eth_data_hash, FullDispatcher}, + dispatch::{FullDispatcher, eth_data_hash}, eip191, nonce, }, tests::helpers::TestMinerService, types::{EIP191Version, PresignedTransaction}, - Metadata, Personal, PersonalClient, }; +use serde_json::to_value; struct PersonalTester { _runtime: Runtime, diff --git a/crates/rpc/src/v1/tests/mocked/pubsub.rs b/crates/rpc/src/v1/tests/mocked/pubsub.rs index 4b5fb4e31..bde1b13b4 100644 --- a/crates/rpc/src/v1/tests/mocked/pubsub.rs +++ b/crates/rpc/src/v1/tests/mocked/pubsub.rs @@ -14,17 +14,16 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use std::sync::{atomic, Arc}; +use std::sync::{Arc, atomic}; use jsonrpc_core::{ - self as core, + self as core, MetaIoHandler, futures::{self, Future, Stream}, - MetaIoHandler, }; use jsonrpc_pubsub::Session; -use parity_runtime::Runtime; use crate::v1::{Metadata, PubSub, PubSubClient}; +use parity_runtime::Runtime; fn rpc() -> MetaIoHandler { let mut io = MetaIoHandler::default(); diff --git a/crates/rpc/src/v1/tests/mocked/rpc.rs b/crates/rpc/src/v1/tests/mocked/rpc.rs index 4e814e460..c609a2bf5 100644 --- a/crates/rpc/src/v1/tests/mocked/rpc.rs +++ b/crates/rpc/src/v1/tests/mocked/rpc.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::v1::{Rpc, RpcClient}; use jsonrpc_core::IoHandler; use std::collections::BTreeMap; -use crate::v1::{Rpc, RpcClient}; fn rpc_client() -> RpcClient { let mut modules = BTreeMap::new(); diff --git a/crates/rpc/src/v1/tests/mocked/secretstore.rs b/crates/rpc/src/v1/tests/mocked/secretstore.rs index 04ae3a754..f92b9e2f5 100644 --- a/crates/rpc/src/v1/tests/mocked/secretstore.rs +++ b/crates/rpc/src/v1/tests/mocked/secretstore.rs @@ -18,17 +18,17 @@ use std::sync::Arc; use accounts::AccountProvider; use crypto::{ - publickey::{verify_public, KeyPair, Signature}, DEFAULT_MAC, + publickey::{KeyPair, Signature, verify_public}, }; use ethereum_types::H256; -use jsonrpc_core::{IoHandler, Success}; -use serde_json; use crate::v1::{ - helpers::secretstore::ordered_servers_keccak, metadata::Metadata, - traits::secretstore::SecretStore, types::EncryptedDocumentKey, SecretStoreClient, + SecretStoreClient, helpers::secretstore::ordered_servers_keccak, metadata::Metadata, + traits::secretstore::SecretStore, types::EncryptedDocumentKey, }; +use jsonrpc_core::{IoHandler, Success}; +use serde_json; struct Dependencies { pub accounts: Arc, @@ -195,13 +195,14 @@ fn rpc_secretstore_generate_document_key() { serde_json::from_str(&generation_response).unwrap(); // the only thing we can check is that 'encrypted_key' can be decrypted by passed account - assert!(deps - .accounts - .decrypt( - "00dfE63B22312ab4329aD0d28CaD8Af987A01932".parse().unwrap(), - Some("password".into()), - &DEFAULT_MAC, - &generation_response.encrypted_key.0 - ) - .is_ok()); + assert!( + deps.accounts + .decrypt( + "00dfE63B22312ab4329aD0d28CaD8Af987A01932".parse().unwrap(), + Some("password".into()), + &DEFAULT_MAC, + &generation_response.encrypted_key.0 + ) + .is_ok() + ); } diff --git a/crates/rpc/src/v1/tests/mocked/signer.rs b/crates/rpc/src/v1/tests/mocked/signer.rs index 4fa19e62f..835d1c041 100644 --- a/crates/rpc/src/v1/tests/mocked/signer.rs +++ b/crates/rpc/src/v1/tests/mocked/signer.rs @@ -18,25 +18,26 @@ use bytes::ToPretty; use ethereum_types::{Address, H520, U256}; use std::{str::FromStr, sync::Arc}; +use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; use accounts::AccountProvider; use ethcore::client::TestBlockChainClient; use parity_runtime::Runtime; use parking_lot::Mutex; -use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; -use jsonrpc_core::IoHandler; -use serde_json; use crate::v1::{ + Origin, Signer, SignerClient, helpers::{ - dispatch::{self, eth_data_hash, FullDispatcher}, + ConfirmationPayload, FilledTransactionRequest, + dispatch::{self, FullDispatcher, eth_data_hash}, external_signer::{SignerService, SigningQueue}, - nonce, ConfirmationPayload, FilledTransactionRequest, + nonce, }, metadata::Metadata, tests::helpers::TestMinerService, types::Bytes as RpcBytes, - Origin, Signer, SignerClient, }; +use jsonrpc_core::IoHandler; +use serde_json; struct SignerTester { _runtime: Runtime, diff --git a/crates/rpc/src/v1/tests/mocked/signing.rs b/crates/rpc/src/v1/tests/mocked/signing.rs index 035380522..4bda77396 100644 --- a/crates/rpc/src/v1/tests/mocked/signing.rs +++ b/crates/rpc/src/v1/tests/mocked/signing.rs @@ -16,7 +16,6 @@ use std::{str::FromStr, sync::Arc, thread, time::Duration}; -use jsonrpc_core::{futures::Future, IoHandler, Success}; use crate::v1::{ helpers::{ dispatch, @@ -29,8 +28,12 @@ use crate::v1::{ traits::{EthSigning, Parity, ParitySigning}, types::{ConfirmationResponse, RichRawTransaction}, }; +use jsonrpc_core::{IoHandler, Success, futures::Future}; -use crate::dispatch::FullDispatcher; +use crate::{ + dispatch::FullDispatcher, + types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}, +}; use accounts::AccountProvider; use bytes::ToPretty; use crypto::publickey::{Generator, Random, Secret}; @@ -39,7 +42,6 @@ use ethereum_types::{Address, H256, H520, U256}; use parity_runtime::{Executor, Runtime}; use parking_lot::Mutex; use serde_json; -use crate::types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}; struct SigningTester { pub runtime: Runtime, @@ -152,17 +154,19 @@ fn should_add_sign_to_queue() { // the future must be polled at least once before request is queued. let signer = tester.signer.clone(); - ::std::thread::spawn(move || loop { - if signer.requests().len() == 1 { - // respond - let sender = signer.take(&1.into()).unwrap(); - signer.request_confirmed( - sender, - Ok(ConfirmationResponse::Signature(H520::from_low_u64_be(0))), - ); - break; + ::std::thread::spawn(move || { + loop { + if signer.requests().len() == 1 { + // respond + let sender = signer.take(&1.into()).unwrap(); + signer.request_confirmed( + sender, + Ok(ConfirmationResponse::Signature(H520::from_low_u64_be(0))), + ); + break; + } + ::std::thread::sleep(Duration::from_millis(100)) } - ::std::thread::sleep(Duration::from_millis(100)) }); let res = promise.wait().unwrap(); @@ -343,19 +347,21 @@ fn should_add_transaction_to_queue() { // the future must be polled at least once before request is queued. let signer = tester.signer.clone(); - ::std::thread::spawn(move || loop { - if signer.requests().len() == 1 { - // respond - let sender = signer.take(&1.into()).unwrap(); - signer.request_confirmed( - sender, - Ok(ConfirmationResponse::SendTransaction( - H256::from_low_u64_be(0), - )), - ); - break; + ::std::thread::spawn(move || { + loop { + if signer.requests().len() == 1 { + // respond + let sender = signer.take(&1.into()).unwrap(); + signer.request_confirmed( + sender, + Ok(ConfirmationResponse::SendTransaction( + H256::from_low_u64_be(0), + )), + ); + break; + } + ::std::thread::sleep(Duration::from_millis(100)) } - ::std::thread::sleep(Duration::from_millis(100)) }); let res = promise.wait().unwrap(); @@ -439,19 +445,21 @@ fn should_add_sign_transaction_to_the_queue() { // the future must be polled at least once before request is queued. let signer = tester.signer.clone(); - ::std::thread::spawn(move || loop { - if signer.requests().len() == 1 { - // respond - let sender = signer.take(&1.into()).unwrap(); - signer.request_confirmed( - sender, - Ok(ConfirmationResponse::SignTransaction( - RichRawTransaction::from_signed(t.into()), - )), - ); - break; + ::std::thread::spawn(move || { + loop { + if signer.requests().len() == 1 { + // respond + let sender = signer.take(&1.into()).unwrap(); + signer.request_confirmed( + sender, + Ok(ConfirmationResponse::SignTransaction( + RichRawTransaction::from_signed(t.into()), + )), + ); + break; + } + ::std::thread::sleep(Duration::from_millis(100)) } - ::std::thread::sleep(Duration::from_millis(100)) }); let res = promise.wait().unwrap(); @@ -580,17 +588,19 @@ fn should_add_decryption_to_the_queue() { // the future must be polled at least once before request is queued. let signer = tester.signer.clone(); - ::std::thread::spawn(move || loop { - if signer.requests().len() == 1 { - // respond - let sender = signer.take(&1.into()).unwrap(); - signer.request_confirmed( - sender, - Ok(ConfirmationResponse::Decrypt(vec![0x1, 0x2].into())), - ); - break; + ::std::thread::spawn(move || { + loop { + if signer.requests().len() == 1 { + // respond + let sender = signer.take(&1.into()).unwrap(); + signer.request_confirmed( + sender, + Ok(ConfirmationResponse::Decrypt(vec![0x1, 0x2].into())), + ); + break; + } + ::std::thread::sleep(Duration::from_millis(10)) } - ::std::thread::sleep(Duration::from_millis(10)) }); // check response: will deadlock if unsuccessful. diff --git a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs index 7803b43bc..3ab1c71b7 100644 --- a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs +++ b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs @@ -16,23 +16,23 @@ use std::{str::FromStr, sync::Arc}; +use crate::types::transaction::{Action, Transaction, TypedTransaction}; use accounts::AccountProvider; use ethcore::client::TestBlockChainClient; use ethereum_types::{Address, U256}; use parity_runtime::Runtime; use parking_lot::Mutex; -use crate::types::transaction::{Action, Transaction, TypedTransaction}; -use jsonrpc_core::IoHandler; use crate::v1::{ + EthClientOptions, EthSigning, SigningUnsafeClient, helpers::{ dispatch::{self, FullDispatcher}, nonce, }, metadata::Metadata, tests::helpers::TestMinerService, - EthClientOptions, EthSigning, SigningUnsafeClient, }; +use jsonrpc_core::IoHandler; fn blockchain_client() -> Arc { let client = TestBlockChainClient::new(); diff --git a/crates/rpc/src/v1/tests/mocked/traces.rs b/crates/rpc/src/v1/tests/mocked/traces.rs index 36c7ee5c8..e84628a90 100644 --- a/crates/rpc/src/v1/tests/mocked/traces.rs +++ b/crates/rpc/src/v1/tests/mocked/traces.rs @@ -20,16 +20,16 @@ use ethcore::{ client::TestBlockChainClient, executed::{CallError, Executed}, trace::{ - trace::{Action, Call, Res}, LocalizedTrace, + trace::{Action, Call, Res}, }, }; use ethereum_types::{Address, H256}; use vm::CallType; +use crate::v1::{Metadata, Traces, TracesClient, tests::helpers::TestMinerService}; use jsonrpc_core::IoHandler; -use crate::v1::{tests::helpers::TestMinerService, Metadata, Traces, TracesClient}; struct Tester { client: Arc, diff --git a/crates/rpc/src/v1/tests/mocked/web3.rs b/crates/rpc/src/v1/tests/mocked/web3.rs index 3960d7dc0..0c448b572 100644 --- a/crates/rpc/src/v1/tests/mocked/web3.rs +++ b/crates/rpc/src/v1/tests/mocked/web3.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use jsonrpc_core::IoHandler; use crate::v1::{Web3, Web3Client}; +use jsonrpc_core::IoHandler; use version::version; #[test] diff --git a/crates/rpc/src/v1/traits/eth.rs b/crates/rpc/src/v1/traits/eth.rs index a4c346c81..bf5515330 100644 --- a/crates/rpc/src/v1/traits/eth.rs +++ b/crates/rpc/src/v1/traits/eth.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . //! Eth rpc interface. -use ethereum_types::{H160, H256, H64, U256, U64}; +use ethereum_types::{H64, H160, H256, U64, U256}; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; @@ -64,7 +64,7 @@ pub trait Eth { /// Returns transaction fee history. #[rpc(name = "eth_feeHistory")] fn fee_history(&self, _: U256, _: BlockNumber, _: Option>) - -> BoxFuture; + -> BoxFuture; /// Returns accounts list. #[rpc(name = "eth_accounts")] diff --git a/crates/rpc/src/v1/traits/eth_pubsub.rs b/crates/rpc/src/v1/traits/eth_pubsub.rs index b5d394cae..bbb65ec72 100644 --- a/crates/rpc/src/v1/traits/eth_pubsub.rs +++ b/crates/rpc/src/v1/traits/eth_pubsub.rs @@ -18,7 +18,7 @@ use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use jsonrpc_pubsub::{typed, SubscriptionId}; +use jsonrpc_pubsub::{SubscriptionId, typed}; use crate::v1::types::pubsub; diff --git a/crates/rpc/src/v1/traits/eth_signing.rs b/crates/rpc/src/v1/traits/eth_signing.rs index 264cd29f2..4c1a077f6 100644 --- a/crates/rpc/src/v1/traits/eth_signing.rs +++ b/crates/rpc/src/v1/traits/eth_signing.rs @@ -19,8 +19,8 @@ use jsonrpc_core::BoxFuture; use jsonrpc_derive::rpc; -use ethereum_types::{H160, H256, H520}; use crate::v1::types::{Bytes, RichRawTransaction, TransactionRequest}; +use ethereum_types::{H160, H256, H520}; /// Signing methods implementation relying on unlocked accounts. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/parity.rs b/crates/rpc/src/v1/traits/parity.rs index 2f32d03ac..3d895599d 100644 --- a/crates/rpc/src/v1/traits/parity.rs +++ b/crates/rpc/src/v1/traits/parity.rs @@ -18,15 +18,15 @@ use std::collections::BTreeMap; -use ethereum_types::{H160, H256, H512, H64, U256, U64}; +use ethereum_types::{H64, H160, H256, H512, U64, U256}; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use ethcore::miner::TransactionFilter; use crate::v1::types::{ BlockNumber, Bytes, CallRequest, ChainStatus, Histogram, LocalTransactionStatus, Peers, Receipt, RecoveredAccount, RichHeader, RpcSettings, Transaction, TransactionStats, }; +use ethcore::miner::TransactionFilter; /// Parity-specific rpc interface. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/parity_accounts.rs b/crates/rpc/src/v1/traits/parity_accounts.rs index 0ea8180ed..5f4ebf374 100644 --- a/crates/rpc/src/v1/traits/parity_accounts.rs +++ b/crates/rpc/src/v1/traits/parity_accounts.rs @@ -17,12 +17,12 @@ //! Parity Accounts-related rpc interface. use std::collections::BTreeMap; +use crate::v1::types::{AccountInfo, DeriveHash, DeriveHierarchical, ExtAccountInfo}; use ethereum_types::{H160, H256, H520}; use ethkey::Password; use ethstore::KeyFile; use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use crate::v1::types::{AccountInfo, DeriveHash, DeriveHierarchical, ExtAccountInfo}; /// Parity-specific read-only accounts rpc interface. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/parity_signing.rs b/crates/rpc/src/v1/traits/parity_signing.rs index aa3a5a8a4..7838bc8a8 100644 --- a/crates/rpc/src/v1/traits/parity_signing.rs +++ b/crates/rpc/src/v1/traits/parity_signing.rs @@ -18,8 +18,8 @@ use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use ethereum_types::{H160, U256}; use crate::v1::types::{Bytes, ConfirmationResponse, Either, TransactionRequest}; +use ethereum_types::{H160, U256}; /// Signing methods implementation. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/personal.rs b/crates/rpc/src/v1/traits/personal.rs index 7ddb968ac..91795f882 100644 --- a/crates/rpc/src/v1/traits/personal.rs +++ b/crates/rpc/src/v1/traits/personal.rs @@ -15,13 +15,13 @@ // along with OpenEthereum. If not, see . //! Personal rpc interface. -use eip_712::EIP712; -use ethereum_types::{H160, H256, H520, U128}; -use jsonrpc_core::{types::Value, BoxFuture, Result}; -use jsonrpc_derive::rpc; use crate::v1::types::{ Bytes, EIP191Version, RichRawTransaction as RpcRichRawTransaction, TransactionRequest, }; +use eip_712::EIP712; +use ethereum_types::{H160, H256, H520, U128}; +use jsonrpc_core::{BoxFuture, Result, types::Value}; +use jsonrpc_derive::rpc; /// Personal rpc interface. Safe (read-only) functions. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/pubsub.rs b/crates/rpc/src/v1/traits/pubsub.rs index 429b11565..8d0356ab1 100644 --- a/crates/rpc/src/v1/traits/pubsub.rs +++ b/crates/rpc/src/v1/traits/pubsub.rs @@ -18,7 +18,7 @@ use jsonrpc_core::{Params, Result, Value}; use jsonrpc_derive::rpc; -use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; +use jsonrpc_pubsub::{SubscriptionId, typed::Subscriber}; /// Parity-specific PUB-SUB rpc interface. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/secretstore.rs b/crates/rpc/src/v1/traits/secretstore.rs index 6e746d822..f6e0401fe 100644 --- a/crates/rpc/src/v1/traits/secretstore.rs +++ b/crates/rpc/src/v1/traits/secretstore.rs @@ -18,11 +18,11 @@ use std::collections::BTreeSet; +use crate::v1::types::{Bytes, EncryptedDocumentKey}; use ethereum_types::{H160, H256, H512}; use ethkey::Password; use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use crate::v1::types::{Bytes, EncryptedDocumentKey}; /// Parity-specific rpc interface. #[rpc(server)] diff --git a/crates/rpc/src/v1/traits/signer.rs b/crates/rpc/src/v1/traits/signer.rs index eba32a550..b3dbdf99c 100644 --- a/crates/rpc/src/v1/traits/signer.rs +++ b/crates/rpc/src/v1/traits/signer.rs @@ -19,7 +19,7 @@ use ethereum_types::U256; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; +use jsonrpc_pubsub::{SubscriptionId, typed::Subscriber}; use crate::v1::types::{ Bytes, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken, diff --git a/crates/rpc/src/v1/traits/traces.rs b/crates/rpc/src/v1/traits/traces.rs index e214226d1..67b8053c4 100644 --- a/crates/rpc/src/v1/traits/traces.rs +++ b/crates/rpc/src/v1/traits/traces.rs @@ -16,13 +16,13 @@ //! Traces specific rpc interface. -use ethereum_types::H256; -use jsonrpc_core::Result; -use jsonrpc_derive::rpc; use crate::v1::types::{ BlockNumber, Bytes, CallRequest, Index, LocalizedTrace, TraceFilter, TraceOptions, TraceResults, TraceResultsWithTransactionHash, }; +use ethereum_types::H256; +use jsonrpc_core::Result; +use jsonrpc_derive::rpc; /// Traces specific rpc interface. #[rpc(server)] @@ -46,7 +46,7 @@ pub trait Traces { /// Executes the given call and returns a number of possible traces for it. #[rpc(name = "trace_call")] fn call(&self, _: CallRequest, _: TraceOptions, _: Option) - -> Result; + -> Result; /// Executes all given calls and returns a number of possible traces for each of it. #[rpc(name = "trace_callMany")] diff --git a/crates/rpc/src/v1/types/account_info.rs b/crates/rpc/src/v1/types/account_info.rs index 4739eed7b..c8a8d6cb5 100644 --- a/crates/rpc/src/v1/types/account_info.rs +++ b/crates/rpc/src/v1/types/account_info.rs @@ -16,8 +16,8 @@ //! Return types for RPC calls -use ethereum_types::{Address, Public, H160, H256, U256}; use crate::v1::types::Bytes; +use ethereum_types::{Address, H160, H256, Public, U256}; /// Account information. #[derive(Debug, Default, Clone, PartialEq, Serialize)] diff --git a/crates/rpc/src/v1/types/block.rs b/crates/rpc/src/v1/types/block.rs index eca91a181..a84b2e8ee 100644 --- a/crates/rpc/src/v1/types/block.rs +++ b/crates/rpc/src/v1/types/block.rs @@ -16,10 +16,12 @@ use std::{collections::BTreeMap, ops::Deref}; +use crate::{ + types::{BlockNumber, encoded::Header as EthHeader}, + v1::types::{Bytes, Transaction}, +}; use ethereum_types::{Bloom as H2048, H160, H256, U256}; -use serde::{ser::Error, Serialize, Serializer}; -use crate::types::{encoded::Header as EthHeader, BlockNumber}; -use crate::v1::types::{Bytes, Transaction}; +use serde::{Serialize, Serializer, ser::Error}; /// Block Transactions #[derive(Debug)] @@ -199,7 +201,7 @@ impl Serialize for Rich { where S: Serializer, { - use serde_json::{to_value, Value}; + use serde_json::{Value, to_value}; let serialized = (to_value(&self.inner), to_value(&self.extra_info)); if let (Ok(Value::Object(mut value)), Ok(Value::Object(extras))) = serialized { @@ -218,10 +220,10 @@ impl Serialize for Rich { #[cfg(test)] mod tests { use super::{Block, BlockTransactions, Header, RichBlock, RichHeader}; - use ethereum_types::{Bloom as H2048, H160, H256, H64, U256}; + use crate::v1::types::{Bytes, Transaction}; + use ethereum_types::{Bloom as H2048, H64, H160, H256, U256}; use serde_json; use std::collections::BTreeMap; - use crate::v1::types::{Bytes, Transaction}; #[test] fn test_serialize_block_transactions() { diff --git a/crates/rpc/src/v1/types/block_number.rs b/crates/rpc/src/v1/types/block_number.rs index 6ac3afb57..a18445935 100644 --- a/crates/rpc/src/v1/types/block_number.rs +++ b/crates/rpc/src/v1/types/block_number.rs @@ -17,8 +17,8 @@ use ethcore::client::BlockId; use hash::H256; use serde::{ - de::{Error, MapAccess, Visitor}, Deserialize, Deserializer, Serialize, Serializer, + de::{Error, MapAccess, Visitor}, }; use std::fmt; diff --git a/crates/rpc/src/v1/types/call_request.rs b/crates/rpc/src/v1/types/call_request.rs index b396e6af5..498c9b6b1 100644 --- a/crates/rpc/src/v1/types/call_request.rs +++ b/crates/rpc/src/v1/types/call_request.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use ethereum_types::{H160, U256, U64}; use crate::v1::{ helpers::CallRequest as Request, types::{AccessList, Bytes}, }; +use ethereum_types::{H160, U64, U256}; /// Call request #[derive(Debug, Default, PartialEq, Deserialize)] diff --git a/crates/rpc/src/v1/types/confirmations.rs b/crates/rpc/src/v1/types/confirmations.rs index 1acddf9b8..96904763e 100644 --- a/crates/rpc/src/v1/types/confirmations.rs +++ b/crates/rpc/src/v1/types/confirmations.rs @@ -21,12 +21,12 @@ use bytes::ToPretty; use serde::{Serialize, Serializer}; use std::fmt; -use ethereum_types::{H160, H256, H520, U256}; -use ethkey::Password; use crate::v1::{ helpers, types::{Bytes, Origin, RichRawTransaction, TransactionCondition, TransactionRequest}, }; +use ethereum_types::{H160, H256, H520, U256}; +use ethkey::Password; /// Confirmation waiting in a queue #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] @@ -302,10 +302,10 @@ where #[cfg(test)] mod tests { use super::*; + use crate::v1::{helpers, types::TransactionCondition}; use ethereum_types::{Address, H256, U256}; use serde_json; use std::str::FromStr; - use crate::v1::{helpers, types::TransactionCondition}; #[test] fn should_serialize_sign_confirmation() { diff --git a/crates/rpc/src/v1/types/derivation.rs b/crates/rpc/src/v1/types/derivation.rs index c1f634040..6b68631be 100644 --- a/crates/rpc/src/v1/types/derivation.rs +++ b/crates/rpc/src/v1/types/derivation.rs @@ -15,8 +15,8 @@ // along with OpenEthereum. If not, see . use serde::{ - de::{Error, Visitor}, Deserialize, Deserializer, + de::{Error, Visitor}, }; use std::fmt; diff --git a/crates/rpc/src/v1/types/eip191.rs b/crates/rpc/src/v1/types/eip191.rs index 3f31e089e..cfa9b60f9 100644 --- a/crates/rpc/src/v1/types/eip191.rs +++ b/crates/rpc/src/v1/types/eip191.rs @@ -16,9 +16,9 @@ //! EIP-191 specific types -use ethereum_types::H160; -use serde::{de, Deserialize, Deserializer}; use crate::v1::types::Bytes; +use ethereum_types::H160; +use serde::{Deserialize, Deserializer, de}; /// EIP-191 version specifier #[derive(Debug)] @@ -55,7 +55,7 @@ impl<'de> Deserialize<'de> for EIP191Version { return Err(de::Error::custom(format!( "Invalid byte version '{}'", other - ))) + ))); } }; Ok(byte_version) diff --git a/crates/rpc/src/v1/types/fee_history.rs b/crates/rpc/src/v1/types/fee_history.rs index 03f61e263..4e4db27b3 100644 --- a/crates/rpc/src/v1/types/fee_history.rs +++ b/crates/rpc/src/v1/types/fee_history.rs @@ -16,8 +16,8 @@ //! Return types for RPC calls -use ethereum_types::U256; use crate::v1::types::BlockNumber; +use ethereum_types::U256; /// Account information. #[derive(Debug, Default, Clone, PartialEq, Serialize)] diff --git a/crates/rpc/src/v1/types/filter.rs b/crates/rpc/src/v1/types/filter.rs index 5c21f63ca..fa77e8610 100644 --- a/crates/rpc/src/v1/types/filter.rs +++ b/crates/rpc/src/v1/types/filter.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::types::{filter::Filter as EthFilter, ids::BlockId}; use ethereum_types::{H160, H256}; use jsonrpc_core::Error as RpcError; use serde::{ - de::{DeserializeOwned, Error}, Deserialize, Deserializer, Serialize, Serializer, + de::{DeserializeOwned, Error}, }; -use serde_json::{from_value, Value}; -use crate::types::{filter::Filter as EthFilter, ids::BlockId}; +use serde_json::{Value, from_value}; use crate::v1::{ helpers::errors::invalid_params, @@ -174,11 +174,13 @@ impl Serialize for FilterChanges { #[cfg(test)] mod tests { use super::{Filter, Topic, VariadicValue}; + use crate::{ + types::{filter::Filter as EthFilter, ids::BlockId}, + v1::types::BlockNumber, + }; use ethereum_types::H256; use serde_json; use std::str::FromStr; - use crate::types::{filter::Filter as EthFilter, ids::BlockId}; - use crate::v1::types::BlockNumber; #[test] fn topic_deserialization() { @@ -257,10 +259,12 @@ mod tests { address: Some(vec![]), topics: vec![ None, - Some(vec![H256::from_str( - "000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b" - ) - .unwrap()]), + Some(vec![ + H256::from_str( + "000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b" + ) + .unwrap() + ]), None, None, ], diff --git a/crates/rpc/src/v1/types/index.rs b/crates/rpc/src/v1/types/index.rs index 9c25b7b61..2a890a8cb 100644 --- a/crates/rpc/src/v1/types/index.rs +++ b/crates/rpc/src/v1/types/index.rs @@ -15,8 +15,8 @@ // along with OpenEthereum. If not, see . use serde::{ - de::{Error, Visitor}, Deserialize, Deserializer, + de::{Error, Visitor}, }; use std::fmt; diff --git a/crates/rpc/src/v1/types/log.rs b/crates/rpc/src/v1/types/log.rs index f20064ff1..3ebc5ef9b 100644 --- a/crates/rpc/src/v1/types/log.rs +++ b/crates/rpc/src/v1/types/log.rs @@ -14,9 +14,11 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{ + types::log_entry::{LocalizedLogEntry, LogEntry}, + v1::types::Bytes, +}; use ethereum_types::{H160, H256, U256}; -use crate::types::log_entry::{LocalizedLogEntry, LogEntry}; -use crate::v1::types::Bytes; /// Log #[derive(Debug, Serialize, PartialEq, Eq, Hash, Clone)] @@ -86,10 +88,10 @@ impl From for Log { #[cfg(test)] mod tests { + use crate::v1::types::Log; use ethereum_types::{H160, H256, U256}; use serde_json; use std::str::FromStr; - use crate::v1::types::Log; #[test] fn log_serialization() { diff --git a/crates/rpc/src/v1/types/mod.rs b/crates/rpc/src/v1/types/mod.rs index de7478bba..7be2e544d 100644 --- a/crates/rpc/src/v1/types/mod.rs +++ b/crates/rpc/src/v1/types/mod.rs @@ -21,7 +21,7 @@ pub use rpc_common::Bytes; pub use self::{ account_info::{AccountInfo, EthAccount, ExtAccountInfo, RecoveredAccount, StorageProof}, block::{Block, BlockTransactions, Header, RichBlock, RichHeader}, - block_number::{block_number_to_id, BlockNumber}, + block_number::{BlockNumber, block_number_to_id}, call_request::CallRequest, confirmations::{ ConfirmationPayload, ConfirmationRequest, ConfirmationResponse, diff --git a/crates/rpc/src/v1/types/pubsub.rs b/crates/rpc/src/v1/types/pubsub.rs index 2f0ef1d0e..aa403d5a5 100644 --- a/crates/rpc/src/v1/types/pubsub.rs +++ b/crates/rpc/src/v1/types/pubsub.rs @@ -16,10 +16,10 @@ //! Pub-Sub types. -use ethereum_types::H256; -use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; -use serde_json::{from_value, Value}; use crate::v1::types::{Filter, Log, RichHeader}; +use ethereum_types::H256; +use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error}; +use serde_json::{Value, from_value}; /// Subscription result. #[derive(Debug, Clone, PartialEq, Eq)] @@ -95,8 +95,8 @@ impl<'a> Deserialize<'a> for Params { #[cfg(test)] mod tests { use super::{Kind, Params, Result}; + use crate::v1::types::{Filter, Header, RichHeader, filter::VariadicValue}; use serde_json; - use crate::v1::types::{filter::VariadicValue, Filter, Header, RichHeader}; #[test] fn should_deserialize_kind() { diff --git a/crates/rpc/src/v1/types/receipt.rs b/crates/rpc/src/v1/types/receipt.rs index 9c6d8caa4..1afeb1e95 100644 --- a/crates/rpc/src/v1/types/receipt.rs +++ b/crates/rpc/src/v1/types/receipt.rs @@ -14,9 +14,11 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use ethereum_types::{Bloom as H2048, H160, H256, U256, U64}; -use crate::types::receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome, TypedReceipt}; -use crate::v1::types::Log; +use crate::{ + types::receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome, TypedReceipt}, + v1::types::Log, +}; +use ethereum_types::{Bloom as H2048, H160, H256, U64, U256}; /// Receipt #[derive(Debug, Serialize)] @@ -145,10 +147,12 @@ impl From for Receipt { #[cfg(test)] mod tests { + use crate::{ + types::transaction::TypedTxId, + v1::types::{Log, Receipt}, + }; use ethereum_types::{Bloom, H256}; use serde_json; - use crate::types::transaction::TypedTxId; - use crate::v1::types::{Log, Receipt}; #[test] fn receipt_serialization() { diff --git a/crates/rpc/src/v1/types/secretstore.rs b/crates/rpc/src/v1/types/secretstore.rs index 7ab011de9..a5a738537 100644 --- a/crates/rpc/src/v1/types/secretstore.rs +++ b/crates/rpc/src/v1/types/secretstore.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use ethereum_types::H512; use crate::v1::types::Bytes; +use ethereum_types::H512; /// Encrypted document key. #[derive(Default, Debug, Serialize, PartialEq)] diff --git a/crates/rpc/src/v1/types/trace.rs b/crates/rpc/src/v1/types/trace.rs index 12682bc7a..38a131aab 100644 --- a/crates/rpc/src/v1/types/trace.rs +++ b/crates/rpc/src/v1/types/trace.rs @@ -16,14 +16,14 @@ use std::collections::BTreeMap; +use crate::types::{account_diff, state_diff}; use ethcore::{ client::Executed, trace as et, - trace::{trace, FlatTrace, LocalizedTrace as EthLocalizedTrace, TraceError}, + trace::{FlatTrace, LocalizedTrace as EthLocalizedTrace, TraceError, trace}, }; use ethereum_types::{H160, H256, U256}; -use serde::{ser::SerializeStruct, Serialize, Serializer}; -use crate::types::{account_diff, state_diff}; +use serde::{Serialize, Serializer, ser::SerializeStruct}; use vm; use crate::v1::types::Bytes; @@ -678,11 +678,11 @@ impl From<(H256, Executed)> for TraceResultsWithTransactionHash { #[cfg(test)] mod tests { use super::*; + use crate::v1::types::Bytes; use ethcore::trace::TraceError; use ethereum_types::{Address, H256}; use serde_json; use std::collections::BTreeMap; - use crate::v1::types::Bytes; #[test] fn should_serialize_trace_results() { diff --git a/crates/rpc/src/v1/types/trace_filter.rs b/crates/rpc/src/v1/types/trace_filter.rs index a0c318aa0..4c8699d17 100644 --- a/crates/rpc/src/v1/types/trace_filter.rs +++ b/crates/rpc/src/v1/types/trace_filter.rs @@ -16,9 +16,9 @@ //! Trace filter deserialization. +use crate::v1::types::BlockNumber; use ethcore::{client, client::BlockId}; use ethereum_types::H160; -use crate::v1::types::BlockNumber; /// Trace filter #[derive(Debug, PartialEq, Deserialize)] @@ -47,7 +47,9 @@ impl Into for TraceFilter { BlockNumber::Earliest => BlockId::Earliest, BlockNumber::Latest => BlockId::Latest, BlockNumber::Pending => { - warn!("Pending traces are not supported and might be removed in future versions. Falling back to Latest"); + warn!( + "Pending traces are not supported and might be removed in future versions. Falling back to Latest" + ); BlockId::Latest } }; @@ -69,9 +71,9 @@ impl Into for TraceFilter { #[cfg(test)] mod tests { + use crate::v1::types::{BlockNumber, TraceFilter}; use ethereum_types::Address; use serde_json; - use crate::v1::types::{BlockNumber, TraceFilter}; #[test] fn test_empty_trace_filter_deserialize() { diff --git a/crates/rpc/src/v1/types/transaction.rs b/crates/rpc/src/v1/types/transaction.rs index 92d8e2f13..d70c9c868 100644 --- a/crates/rpc/src/v1/types/transaction.rs +++ b/crates/rpc/src/v1/types/transaction.rs @@ -16,15 +16,17 @@ use std::sync::Arc; -use ethcore::{contract_address, CreateContractAddress}; -use ethereum_types::{H160, H256, H512, U256, U64}; -use miner; -use serde::{ser::SerializeStruct, Serialize, Serializer}; -use crate::types::transaction::{ - Action, LocalizedTransaction, PendingTransaction, SignedTransaction, TypedTransaction, - TypedTxId, +use crate::{ + types::transaction::{ + Action, LocalizedTransaction, PendingTransaction, SignedTransaction, TypedTransaction, + TypedTxId, + }, + v1::types::{AccessList, Bytes, TransactionCondition}, }; -use crate::v1::types::{AccessList, Bytes, TransactionCondition}; +use ethcore::{CreateContractAddress, contract_address}; +use ethereum_types::{H160, H256, H512, U64, U256}; +use miner; +use serde::{Serialize, Serializer, ser::SerializeStruct}; /// Transaction #[derive(Debug, Default, Clone, PartialEq, Serialize)] @@ -363,9 +365,9 @@ mod tests { use crate::v1::types::transaction_access_list::AccessListItem; use super::{LocalTransactionStatus, Transaction}; + use crate::types::transaction::TypedTxId; use ethereum_types::H256; use serde_json; - use crate::types::transaction::TypedTxId; #[test] fn test_transaction_serialize() { diff --git a/crates/rpc/src/v1/types/transaction_access_list.rs b/crates/rpc/src/v1/types/transaction_access_list.rs index 6dc7b7778..0746888a8 100644 --- a/crates/rpc/src/v1/types/transaction_access_list.rs +++ b/crates/rpc/src/v1/types/transaction_access_list.rs @@ -1,7 +1,7 @@ +use crate::types::transaction::AccessListItem as InnerAccessListItem; use ethereum_types::{H160, H256}; use serde::Serialize; use std::vec::Vec; -use crate::types::transaction::AccessListItem as InnerAccessListItem; pub type AccessList = Vec; #[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)] diff --git a/crates/rpc/src/v1/types/transaction_request.rs b/crates/rpc/src/v1/types/transaction_request.rs index b37bdbbaa..96df20b5f 100644 --- a/crates/rpc/src/v1/types/transaction_request.rs +++ b/crates/rpc/src/v1/types/transaction_request.rs @@ -16,12 +16,12 @@ //! `TransactionRequest` type -use ansi_term::Colour; -use ethereum_types::{H160, U256, U64}; use crate::v1::{ helpers, types::{AccessList, Bytes, TransactionCondition}, }; +use ansi_term::Colour; +use ethereum_types::{H160, U64, U256}; use std::fmt; @@ -167,11 +167,11 @@ impl Into for TransactionRequest { #[cfg(test)] mod tests { use super::*; + use crate::v1::types::TransactionCondition; use ethereum_types::{H160, U256}; use rustc_hex::FromHex; use serde_json; use std::str::FromStr; - use crate::v1::types::TransactionCondition; #[test] fn transaction_request_deserialize() { diff --git a/crates/runtime/io/src/lib.rs b/crates/runtime/io/src/lib.rs index 455a26a31..d36fbeecb 100644 --- a/crates/runtime/io/src/lib.rs +++ b/crates/runtime/io/src/lib.rs @@ -90,10 +90,10 @@ mod service_non_mio; #[cfg(feature = "mio")] mod worker; -#[cfg(feature = "mio")] -use mio::deprecated::{EventLoop, NotifyError}; #[cfg(feature = "mio")] use mio::Token; +#[cfg(feature = "mio")] +use mio::deprecated::{EventLoop, NotifyError}; use std::{cell::Cell, error, fmt}; thread_local! { @@ -202,16 +202,16 @@ where #[cfg(feature = "mio")] pub use service_mio::{ - IoChannel, IoContext, IoManager, IoService, StreamToken, TimerToken, TOKENS_PER_HANDLER, + IoChannel, IoContext, IoManager, IoService, StreamToken, TOKENS_PER_HANDLER, TimerToken, }; #[cfg(not(feature = "mio"))] -pub use service_non_mio::{IoChannel, IoContext, IoService, TimerToken, TOKENS_PER_HANDLER}; +pub use service_non_mio::{IoChannel, IoContext, IoService, TOKENS_PER_HANDLER, TimerToken}; #[cfg(test)] mod tests { use super::*; use std::{ - sync::{atomic, Arc}, + sync::{Arc, atomic}, thread, time::Duration, }; diff --git a/crates/runtime/io/src/service_mio.rs b/crates/runtime/io/src/service_mio.rs index 17c99d6c7..7adcfe87c 100644 --- a/crates/runtime/io/src/service_mio.rs +++ b/crates/runtime/io/src/service_mio.rs @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{ + IoError, IoHandler, + worker::{Work, WorkType, Worker}, +}; use deque; use mio::{ deprecated::{EventLoop, EventLoopBuilder, Handler, Sender}, @@ -28,9 +32,6 @@ use std::{ thread::{self, JoinHandle}, time::Duration, }; -use crate::worker::{Work, WorkType, Worker}; -use crate::IoError; -use crate::IoHandler; /// Timer ID pub type TimerToken = usize; diff --git a/crates/runtime/io/src/service_non_mio.rs b/crates/runtime/io/src/service_non_mio.rs index a6cb599ad..6712a2e0f 100644 --- a/crates/runtime/io/src/service_non_mio.rs +++ b/crates/runtime/io/src/service_non_mio.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{ioError, ioHandler}; use deque; use fnv::FnvHashMap; use num_cpus; @@ -26,8 +27,6 @@ use std::{ }; use time::Duration as TimeDuration; use timer::{Guard as TimerGuard, Timer}; -use crate::ioError; -use crate::ioHandler; /// Timer ID pub type TimerToken = usize; diff --git a/crates/runtime/io/src/worker.rs b/crates/runtime/io/src/worker.rs index b5cf5cc90..99f176b3a 100644 --- a/crates/runtime/io/src/worker.rs +++ b/crates/runtime/io/src/worker.rs @@ -14,19 +14,20 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{ + IoHandler, LOCAL_STACK_SIZE, + service_mio::{HandlerId, IoChannel, IoContext}, +}; use deque; use futures::future::{self, Loop}; -use crate::service_mio::{HandlerId, IoChannel, IoContext}; use std::{ sync::{ - atomic::{AtomicBool, Ordering as AtomicOrdering}, Arc, + atomic::{AtomicBool, Ordering as AtomicOrdering}, }, thread::{self, JoinHandle}, }; use tokio::{self}; -use crate::IoHandler; -use crate::LOCAL_STACK_SIZE; use parking_lot::{Condvar, Mutex}; diff --git a/crates/runtime/runtime/src/lib.rs b/crates/runtime/runtime/src/lib.rs index e8ea5ec3b..04f0981b0 100644 --- a/crates/runtime/runtime/src/lib.rs +++ b/crates/runtime/runtime/src/lib.rs @@ -19,7 +19,7 @@ pub extern crate futures; pub extern crate tokio; -use futures::{future, Future, IntoFuture}; +use futures::{Future, IntoFuture, future}; use std::{ fmt, sync::mpsc, diff --git a/crates/util/cli-signer/rpc-client/src/client.rs b/crates/util/cli-signer/rpc-client/src/client.rs index 9aa6f889e..9465cee77 100644 --- a/crates/util/cli-signer/rpc-client/src/client.rs +++ b/crates/util/cli-signer/rpc-client/src/client.rs @@ -19,8 +19,8 @@ use std::{ fmt::{Debug, Error as FmtError, Formatter}, io::{BufRead, BufReader}, sync::{ - atomic::{AtomicUsize, Ordering}, Arc, + atomic::{AtomicUsize, Ordering}, }, thread, time, }; @@ -38,12 +38,12 @@ use crate::ws::ws::{ use serde::de::DeserializeOwned; use serde_json::{self as json, Error as JsonError, Value as JsonValue}; -use futures::{done, oneshot, Canceled, Complete, Future}; +use futures::{Canceled, Complete, Future, done, oneshot}; use jsonrpc_core::{ + Error as JsonRpcError, Id, Params, Version, request::MethodCall, response::{Failure, Output, Success}, - Error as JsonRpcError, Id, Params, Version, }; use crate::BoxFuture; diff --git a/crates/util/cli-signer/rpc-client/src/signer_client.rs b/crates/util/cli-signer/rpc-client/src/signer_client.rs index 8fca15a21..4dca446b7 100644 --- a/crates/util/cli-signer/rpc-client/src/signer_client.rs +++ b/crates/util/cli-signer/rpc-client/src/signer_client.rs @@ -14,14 +14,16 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::client::{Rpc, RpcError}; +use crate::{ + BoxFuture, + client::{Rpc, RpcError}, +}; use ethereum_types::U256; use futures::Canceled; use rpc::signer::{ConfirmationRequest, TransactionCondition, TransactionModification}; use serde; -use serde_json::{to_value, Value as JsonValue}; +use serde_json::{Value as JsonValue, to_value}; use std::path::PathBuf; -use crate::BoxFuture; pub struct SignerRpc { rpc: Rpc, diff --git a/crates/util/cli-signer/src/lib.rs b/crates/util/cli-signer/src/lib.rs index 71f060d22..1f22538d8 100644 --- a/crates/util/cli-signer/src/lib.rs +++ b/crates/util/cli-signer/src/lib.rs @@ -26,7 +26,7 @@ use ethereum_types::U256; use rpc::signer::ConfirmationRequest; use std::{ fs::File, - io::{stdin, stdout, BufRead, BufReader, Write}, + io::{BufRead, BufReader, Write, stdin, stdout}, path::PathBuf, }; diff --git a/crates/util/dir/src/lib.rs b/crates/util/dir/src/lib.rs index f105014b4..1eb0a6d74 100644 --- a/crates/util/dir/src/lib.rs +++ b/crates/util/dir/src/lib.rs @@ -43,8 +43,8 @@ extern crate home; extern crate journaldb; pub mod helpers; -use app_dirs::{data_root, get_app_root, AppDataType, AppInfo}; -use ethereum_types::{H256, H64}; +use app_dirs::{AppDataType, AppInfo, data_root, get_app_root}; +use ethereum_types::{H64, H256}; use helpers::{replace_home, replace_home_and_local}; use journaldb::Algorithm; use std::{ diff --git a/crates/util/rlp-compress/tests/compress.rs b/crates/util/rlp-compress/tests/compress.rs index 9f901a8e8..44f126f30 100644 --- a/crates/util/rlp-compress/tests/compress.rs +++ b/crates/util/rlp-compress/tests/compress.rs @@ -17,7 +17,7 @@ extern crate rlp_compress; use rlp_compress::{ - blocks_swapper, compress, decompress, snapshot_swapper, Compressor, Decompressor, Swapper, + Compressor, Decompressor, Swapper, blocks_swapper, compress, decompress, snapshot_swapper, }; #[test] diff --git a/crates/util/version/build.rs b/crates/util/version/build.rs index 91beb954f..832d84a9e 100644 --- a/crates/util/version/build.rs +++ b/crates/util/version/build.rs @@ -19,7 +19,7 @@ extern crate toml; extern crate vergen; use std::{env, fs::File, io::Write, path::Path}; -use vergen::{vergen, OutputFns}; +use vergen::{OutputFns, vergen}; const ERROR_MSG: &'static str = "Failed to generate metadata files"; diff --git a/crates/vm/vm/src/action_params.rs b/crates/vm/vm/src/action_params.rs index a6213949c..3b408070e 100644 --- a/crates/vm/vm/src/action_params.rs +++ b/crates/vm/vm/src/action_params.rs @@ -16,11 +16,11 @@ //! Evm input params. use super::access_list::AccessList; -use bytes::Bytes; use crate::call_type::CallType; +use bytes::Bytes; use ethereum_types::{Address, H256, U256}; use ethjson; -use hash::{keccak, KECCAK_EMPTY}; +use hash::{KECCAK_EMPTY, keccak}; use std::sync::Arc; diff --git a/crates/vm/vm/src/error.rs b/crates/vm/vm/src/error.rs index f96a9a5f1..50b0bee8b 100644 --- a/crates/vm/vm/src/error.rs +++ b/crates/vm/vm/src/error.rs @@ -16,12 +16,10 @@ //! VM errors module -use crate::action_params::ActionParams; +use crate::{ResumeCall, ResumeCreate, action_params::ActionParams}; use ethereum_types::Address; use ethtrie; use std::fmt; -use crate::ResumeCall; -use crate::ResumeCreate; #[derive(Debug)] pub enum TrapKind { diff --git a/crates/vm/vm/src/ext.rs b/crates/vm/vm/src/ext.rs index 24dcc5a86..25a6da7ca 100644 --- a/crates/vm/vm/src/ext.rs +++ b/crates/vm/vm/src/ext.rs @@ -16,13 +16,15 @@ //! Interface for Evm externalities. +use crate::{ + call_type::CallType, + env_info::EnvInfo, + error::{Result, TrapKind}, + return_data::ReturnData, + schedule::Schedule, +}; use bytes::Bytes; -use crate::call_type::CallType; -use crate::env_info::EnvInfo; -use crate::error::{Result, TrapKind}; use ethereum_types::{Address, H256, U256}; -use crate::return_data::ReturnData; -use crate::schedule::Schedule; use std::sync::Arc; #[derive(Debug)] diff --git a/crates/vm/vm/src/tests.rs b/crates/vm/vm/src/tests.rs index 2e220f5b7..4b224c097 100644 --- a/crates/vm/vm/src/tests.rs +++ b/crates/vm/vm/src/tests.rs @@ -19,21 +19,13 @@ use std::{ sync::Arc, }; -use crate::access_list::AccessList; +use crate::{ + CallType, ContractCreateResult, CreateContractAddress, EnvInfo, Ext, GasLeft, + MessageCallResult, Result, ReturnData, Schedule, access_list::AccessList, error::TrapKind, +}; use bytes::Bytes; -use crate::error::TrapKind; use ethereum_types::{Address, H256, U256}; use hash::keccak; -use crate::CallType; -use crate::ContractCreateResult; -use crate::CreateContractAddress; -use crate::EnvInfo; -use crate::Ext; -use crate::GasLeft; -use crate::MessageCallResult; -use crate::Result; -use crate::ReturnData; -use crate::Schedule; pub struct FakeLogEntry { pub topics: Vec, diff --git a/crates/vm/wasm/src/env.rs b/crates/vm/wasm/src/env.rs index ba51305c5..b009f118a 100644 --- a/crates/vm/wasm/src/env.rs +++ b/crates/vm/wasm/src/env.rs @@ -19,8 +19,8 @@ use std::cell::RefCell; use vm::WasmCosts; use wasmi::{ - self, memory_units, Error, FuncInstance, FuncRef, MemoryDescriptor, MemoryInstance, MemoryRef, - Signature, + self, Error, FuncInstance, FuncRef, MemoryDescriptor, MemoryInstance, MemoryRef, Signature, + memory_units, }; /// Internal ids all functions runtime supports. This is just a glue for wasmi interpreter @@ -210,7 +210,7 @@ impl wasmi::ModuleImportResolver for ImportResolver { return Err(wasmi::Error::Instantiation(format!( "Export {} not found", field_name - ))) + ))); } }; From 1fea038dbd0551ef48ebf72525b3c6dba4bee28e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Apr 2025 14:28:37 +0200 Subject: [PATCH 438/687] fixed use crate::NODE_SOFTWARE_NAME; --- bin/oe/configuration.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 63c05517f..470273b2d 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -1277,8 +1277,6 @@ mod tests { use super::*; - use crate::NODE_SOFTWARE_NAME; - lazy_static! { static ref ITERATIONS: NonZeroU32 = NonZeroU32::new(10240).expect("10240 > 0; qed"); } From 621f1523bbe5a5625e89092c5b97d0aa968f0a42 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Apr 2025 15:02:03 +0200 Subject: [PATCH 439/687] batch of rust 2025 changes for tests target. --- bin/ethstore/src/main.rs | 4 +++- crates/ethcore/src/block.rs | 2 +- crates/ethcore/src/client/evm_test_client.rs | 12 ++++++------ crates/ethcore/src/client/test_client.rs | 8 ++++---- crates/ethcore/src/engines/clique/tests.rs | 2 +- .../src/engines/hbbft/test/hbbft_test_client.rs | 2 +- crates/ethcore/src/engines/validator_set/contract.rs | 2 +- crates/ethcore/src/engines/validator_set/multi.rs | 2 +- .../src/engines/validator_set/safe_contract.rs | 2 +- crates/ethcore/src/externalities.rs | 2 +- crates/ethcore/src/json_tests/chain.rs | 4 ++-- crates/ethcore/src/json_tests/executive.rs | 4 ++-- crates/ethcore/src/json_tests/state.rs | 2 +- crates/ethcore/src/json_tests/transaction.rs | 2 +- crates/ethcore/src/miner/miner.rs | 2 +- .../ethcore/src/snapshot/tests/proof_of_authority.rs | 2 +- crates/ethcore/src/test_helpers.rs | 8 ++++---- crates/ethcore/src/tests/client.rs | 2 +- crates/ethcore/src/tests/trace.rs | 2 +- crates/ethcore/src/tx_filter.rs | 2 +- crates/rpc/src/v1/tests/eth.rs | 2 +- crates/rpc/src/v1/tests/helpers/miner_service.rs | 2 +- crates/rpc/src/v1/tests/mocked/eth.rs | 2 +- crates/rpc/src/v1/tests/mocked/parity.rs | 2 +- crates/rpc/src/v1/types/transaction.rs | 4 ++-- 25 files changed, 41 insertions(+), 39 deletions(-) diff --git a/bin/ethstore/src/main.rs b/bin/ethstore/src/main.rs index 439ec7f29..4542f6911 100644 --- a/bin/ethstore/src/main.rs +++ b/bin/ethstore/src/main.rs @@ -150,7 +150,9 @@ impl fmt::Display for Error { fn main() { panic_hook::set_abort(); if env::var("RUST_LOG").is_err() { - env::set_var("RUST_LOG", "warn") + unsafe { + env::set_var("RUST_LOG", "warn") + } } env_logger::try_init().expect("Logger initialized only once."); diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index 28f2cb558..361fb7cb3 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -637,7 +637,7 @@ mod tests { }; use error::Error; use ethereum_types::Address; - use state_db::StateDB; + use crate::state_db::StateDB; use std::sync::Arc; use test_helpers::get_temp_state_db; use vm::LastHashes; diff --git a/crates/ethcore/src/client/evm_test_client.rs b/crates/ethcore/src/client/evm_test_client.rs index 1a89cb508..3f07a558d 100644 --- a/crates/ethcore/src/client/evm_test_client.rs +++ b/crates/ethcore/src/client/evm_test_client.rs @@ -28,9 +28,9 @@ use ethtrie; use evm::{FinalizationResult, VMType}; use journaldb; use kvdb::{self, KeyValueDB}; -use pod_state; -use state; -use state_db; +use crate::pod_state; +use crate::state; +use crate::state_db; use std::{fmt, sync::Arc}; use trie; use vm::{self, ActionParams}; @@ -43,12 +43,12 @@ pub enum EvmTestError { /// EVM error. Evm(vm::Error), /// Initialization error. - ClientError(::error::Error), + ClientError(crate::error::Error), /// Post-condition failure, PostCondition(String), } -impl> From for EvmTestError { +impl> From for EvmTestError { fn from(err: E) -> Self { EvmTestError::ClientError(err.into()) } @@ -67,7 +67,7 @@ impl fmt::Display for EvmTestError { } } -use ethereum::{self}; +use crate::ethereum::{self}; use ethjson::spec::ForkSpec; /// Simplified, single-block EVM test client. diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index 81dc931fe..128ca329b 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -77,10 +77,10 @@ use crate::{ verification::queue::{QueueInfo, kind::blocks::Unverified}, }; use call_contract::{CallContract, RegistryInfo}; -use error::{Error, EthcoreResult}; +use crate::error::{Error, EthcoreResult}; use journaldb; -use miner::{self, Miner, MinerService}; -use state_db::StateDB; +use crate::miner::{self, Miner, MinerService}; +use crate::state_db::StateDB; use stats::{PrometheusMetrics, PrometheusRegistry}; use super::ReservedPeersManagement; @@ -1222,7 +1222,7 @@ impl super::traits::EngineClient for TestBlockChainClient { // TODO: allow test to intercept the message to relay it to other test clients } - fn epoch_transition_for(&self, _block_hash: H256) -> Option<::engines::EpochTransition> { + fn epoch_transition_for(&self, _block_hash: H256) -> Option { None } diff --git a/crates/ethcore/src/engines/clique/tests.rs b/crates/ethcore/src/engines/clique/tests.rs index c8152c9f3..b25b7a5cc 100644 --- a/crates/ethcore/src/engines/clique/tests.rs +++ b/crates/ethcore/src/engines/clique/tests.rs @@ -21,7 +21,7 @@ use crate::{block::*, engines::Engine}; use crypto::publickey::{KeyPair, Secret}; use error::{Error, ErrorKind}; use ethereum_types::{Address, H256}; -use state_db::StateDB; +use crate::state_db::StateDB; use test_helpers::get_temp_state_db; use std::{collections::HashMap, sync::Arc}; diff --git a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs index 47bf4c67d..a963033ce 100644 --- a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs +++ b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs @@ -10,7 +10,7 @@ use crate::{ }; use crypto::publickey::{Generator, KeyPair, Random}; use ethereum_types::{Address, U256}; -use miner::{Miner, MinerService}; +use crate::miner::{Miner, MinerService}; use parking_lot::RwLock; use std::{ops::Deref, sync::Arc}; use test_helpers::{TestNotify, generate_dummy_client_with_spec}; diff --git a/crates/ethcore/src/engines/validator_set/contract.rs b/crates/ethcore/src/engines/validator_set/contract.rs index c54cce570..7f97b40c8 100644 --- a/crates/ethcore/src/engines/validator_set/contract.rs +++ b/crates/ethcore/src/engines/validator_set/contract.rs @@ -229,7 +229,7 @@ mod tests { use ethabi::FunctionOutputDecoder; use ethereum_types::{Address, H520}; use hash::keccak; - use miner::{self, MinerService}; + use crate::miner::{self, MinerService}; use rlp::encode; use rustc_hex::FromHex; use std::sync::Arc; diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index 8aaadb25f..8ff8b9f3a 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -222,7 +222,7 @@ mod tests { use crypto::publickey::Secret; use ethereum_types::Address; use hash::keccak; - use miner::{self, MinerService}; + use crate::miner::{self, MinerService}; use std::{collections::BTreeMap, sync::Arc}; use test_helpers::generate_dummy_client_with_spec; diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index 3a5badafc..39690e329 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -736,7 +736,7 @@ mod tests { use crypto::publickey::Secret; use ethereum_types::Address; use hash::keccak; - use miner::{self, MinerService}; + use crate::miner::{self, MinerService}; use rustc_hex::FromHex; use std::sync::Arc; use test_helpers::generate_dummy_client_with_spec; diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index 390a1ef91..9169cb088 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -589,7 +589,7 @@ mod tests { } struct TestSetup { - state: State<::state_db::StateDB>, + state: State, machine: ::machine::EthereumMachine, schedule: Schedule, sub_state: Substate, diff --git a/crates/ethcore/src/json_tests/chain.rs b/crates/ethcore/src/json_tests/chain.rs index bbdef6a4a..ece19caaa 100644 --- a/crates/ethcore/src/json_tests/chain.rs +++ b/crates/ethcore/src/json_tests/chain.rs @@ -29,10 +29,10 @@ use crate::{ use ethereum_types::{H256, U256}; use ethjson; use log::warn; -use miner::Miner; +use crate::miner::Miner; use rustc_hex::ToHex; use std::{path::Path, sync::Arc}; -use test_helpers; +use crate::test_helpers; fn check_poststate( client: &Arc, diff --git a/crates/ethcore/src/json_tests/executive.rs b/crates/ethcore/src/json_tests/executive.rs index ff94b2b73..358629ab3 100644 --- a/crates/ethcore/src/json_tests/executive.rs +++ b/crates/ethcore/src/json_tests/executive.rs @@ -30,7 +30,7 @@ use evm::Finalize; use hash::keccak; use rlp::RlpStream; use std::{path::Path, sync::Arc}; -use test_helpers::get_temp_state; +use crate::test_helpers::get_temp_state; use vm::{ self, ActionParams, CallType, ContractCreateResult, CreateContractAddress, EnvInfo, Ext, MessageCallResult, ReturnData, Schedule, @@ -313,7 +313,7 @@ pub fn json_executive_test( state.populate_from(From::from(vm.pre_state.clone())); let info: EnvInfo = From::from(vm.env); let machine = { - let mut machine = ::ethereum::new_frontier_test_machine(); + let mut machine = crate::ethereum::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = 1)); machine }; diff --git a/crates/ethcore/src/json_tests/state.rs b/crates/ethcore/src/json_tests/state.rs index f46f17e52..56a6cb66b 100644 --- a/crates/ethcore/src/json_tests/state.rs +++ b/crates/ethcore/src/json_tests/state.rs @@ -20,7 +20,7 @@ use crate::{ trace, }; use ethjson::{self, spec::ForkSpec}; -use pod_state::PodState; +use crate::pod_state::PodState; use std::path::Path; use vm::EnvInfo; diff --git a/crates/ethcore/src/json_tests/transaction.rs b/crates/ethcore/src/json_tests/transaction.rs index e4e6b6755..426b955f2 100644 --- a/crates/ethcore/src/json_tests/transaction.rs +++ b/crates/ethcore/src/json_tests/transaction.rs @@ -70,7 +70,7 @@ pub fn json_transaction_test( let rlp: Vec = test.rlp.clone().into(); let res = TypedTransaction::decode(&rlp) - .map_err(::error::Error::from) + .map_err(crate::error::Error::from) .and_then(|t: UnverifiedTransaction| { let mut header: Header = Default::default(); // Use high enough number to activate all required features. diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index be330f185..251ffa767 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -1840,7 +1840,7 @@ mod tests { client::{ChainInfo, EachBlockWith, ImportSealedBlock, TestBlockChainClient}, types::transaction::{Transaction, TypedTransaction}, }; - use miner::{MinerService, PendingOrdering}; + use crate::miner::{MinerService, PendingOrdering}; use test_helpers::{ dummy_engine_signer_with_address, generate_dummy_client, generate_dummy_client_with_spec, }; diff --git a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs index 407b79073..58a554452 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -106,7 +106,7 @@ fn make_chain( { // push a block with given number, signed by one of the signers, with given transactions. let push_block = |signers: &[Address], n, txs: Vec| { - use miner::{self, MinerService}; + use crate::miner::{self, MinerService}; let idx = n as usize % signers.len(); trace!(target: "snapshot", "Pushing block #{}, {} txs, author={}", diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index 8262f87d4..2ce578e94 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -56,8 +56,8 @@ use crate::{ verification::queue::kind::blocks::Unverified, }; use ethjson::crypto::publickey::{Public, Signature}; -use miner::Miner; -use state_db::StateDB; +use crate::miner::Miner; +use crate::state_db::StateDB; use crate::exit::ShutdownManager; @@ -583,13 +583,13 @@ pub fn generate_dummy_empty_blockchain() -> BlockChain { } /// Returns temp state -pub fn get_temp_state() -> State<::state_db::StateDB> { +pub fn get_temp_state() -> State { let journal_db = get_temp_state_db(); State::new(journal_db, U256::from(0), Default::default()) } /// Returns temp state using coresponding factory -pub fn get_temp_state_with_factory(factory: EvmFactory) -> State<::state_db::StateDB> { +pub fn get_temp_state_with_factory(factory: EvmFactory) -> State { let journal_db = get_temp_state_db(); let mut factories = Factories::default(); factories.vm = factory.into(); diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index 739b0c7de..37949f146 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -45,7 +45,7 @@ use crypto::publickey::KeyPair; use ethereum; use ethereum_types::{Address, U256}; use hash::keccak; -use miner::{Miner, MinerService, PendingOrdering}; +use crate::miner::{Miner, MinerService, PendingOrdering}; use rustc_hex::ToHex; use tempdir::TempDir; use test_helpers::{ diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index 2fd18b63f..fc5d76a42 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -33,7 +33,7 @@ use crate::{ use crypto::publickey::KeyPair; use ethereum_types::{Address, U256}; use hash::keccak; -use miner::Miner; +use crate::miner::Miner; use std::{str::FromStr, sync::Arc}; use test_helpers::{self, get_temp_state_db}; diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index d4fa69a7d..6b11d4938 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -292,7 +292,7 @@ mod test { }; use crypto::publickey::{KeyPair, Secret}; use ethereum_types::{Address, U256}; - use miner::Miner; + use crate::miner::Miner; use std::{str::FromStr, sync::Arc}; use tempdir::TempDir; use test_helpers; diff --git a/crates/rpc/src/v1/tests/eth.rs b/crates/rpc/src/v1/tests/eth.rs index 1bb03da6f..1a1a985a3 100644 --- a/crates/rpc/src/v1/tests/eth.rs +++ b/crates/rpc/src/v1/tests/eth.rs @@ -29,7 +29,7 @@ use ethcore::{ }; use ethereum_types::{Address, H256, U256}; use ethjson::{blockchain::BlockChain, spec::ForkSpec}; -use miner::external::ExternalMiner; +use crate::miner::external::ExternalMiner; use parity_runtime::Runtime; use parking_lot::Mutex; diff --git a/crates/rpc/src/v1/tests/helpers/miner_service.rs b/crates/rpc/src/v1/tests/helpers/miner_service.rs index a229118e0..dc5517584 100644 --- a/crates/rpc/src/v1/tests/helpers/miner_service.rs +++ b/crates/rpc/src/v1/tests/helpers/miner_service.rs @@ -42,7 +42,7 @@ use ethcore::{ miner::{self, AuthoringParams, MinerService, TransactionFilter}, }; use ethereum_types::{Address, H256, U256}; -use miner::pool::{ +use crate::miner::pool::{ QueueStatus, VerifiedTransaction, local_transactions::Status as LocalTransactionStatus, verifier, }; diff --git a/crates/rpc/src/v1/tests/mocked/eth.rs b/crates/rpc/src/v1/tests/mocked/eth.rs index 4ed588e60..7cd36f9c2 100644 --- a/crates/rpc/src/v1/tests/mocked/eth.rs +++ b/crates/rpc/src/v1/tests/mocked/eth.rs @@ -33,7 +33,7 @@ use ethcore::{ miner::{self, MinerService}, }; use ethereum_types::{Address, Bloom, H160, H256, U256}; -use miner::external::ExternalMiner; +use crate::miner::external::ExternalMiner; use parity_runtime::Runtime; use parking_lot::Mutex; use rustc_hex::{FromHex, ToHex}; diff --git a/crates/rpc/src/v1/tests/mocked/parity.rs b/crates/rpc/src/v1/tests/mocked/parity.rs index 9e8ed186d..48be233e8 100644 --- a/crates/rpc/src/v1/tests/mocked/parity.rs +++ b/crates/rpc/src/v1/tests/mocked/parity.rs @@ -22,7 +22,7 @@ use crypto::publickey::{Generator, Random}; use ethcore::client::{Executed, TestBlockChainClient, TransactionId}; use ethcore_logger::RotatingLogger; use ethereum_types::{Address, BigEndianHash, Bloom, H256, U256}; -use miner::pool::local_transactions::Status as LocalTransactionStatus; +use crate::miner::pool::local_transactions::Status as LocalTransactionStatus; use std::{str::FromStr, sync::Arc}; use sync::ManageNetwork; diff --git a/crates/rpc/src/v1/types/transaction.rs b/crates/rpc/src/v1/types/transaction.rs index d70c9c868..53cd1dd80 100644 --- a/crates/rpc/src/v1/types/transaction.rs +++ b/crates/rpc/src/v1/types/transaction.rs @@ -25,7 +25,7 @@ use crate::{ }; use ethcore::{CreateContractAddress, contract_address}; use ethereum_types::{H160, H256, H512, U64, U256}; -use miner; +use crate::miner; use serde::{Serialize, Serializer, ser::SerializeStruct}; /// Transaction @@ -342,7 +342,7 @@ impl LocalTransactionStatus { let convert = |tx: Arc| { Transaction::from_signed(tx.signed().clone()) }; - use miner::pool::local_transactions::Status::*; + use crate::miner::pool::local_transactions::Status::*; match s { Pending(_) => LocalTransactionStatus::Pending, Mined(tx) => LocalTransactionStatus::Mined(convert(tx)), From 75eb76f7b81c68b8dc5e9eda308b70e8f4c60ace Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Apr 2025 15:09:17 +0200 Subject: [PATCH 440/687] batch of rust 2025 changes for tests target. --- bin/evmbin/src/display/json.rs | 4 ++-- bin/evmbin/src/display/simple.rs | 4 ++-- bin/evmbin/src/display/std_json.rs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/evmbin/src/display/json.rs b/bin/evmbin/src/display/json.rs index 08658abf0..ac63f6d08 100644 --- a/bin/evmbin/src/display/json.rs +++ b/bin/evmbin/src/display/json.rs @@ -20,10 +20,10 @@ use std::{collections::HashMap, mem}; use super::config::Config; use bytes::ToPretty; -use display; +use crate::display; use ethcore::trace; use ethereum_types::{BigEndianHash, H256, U256}; -use info as vm; +use crate::info as vm; /// JSON formatting informant. #[derive(Default)] diff --git a/bin/evmbin/src/display/simple.rs b/bin/evmbin/src/display/simple.rs index 76043d54e..338e39355 100644 --- a/bin/evmbin/src/display/simple.rs +++ b/bin/evmbin/src/display/simple.rs @@ -20,8 +20,8 @@ use super::config::Config; use bytes::ToPretty; use ethcore::trace; -use display; -use info as vm; +use crate::display; +use crate::info as vm; /// Simple formatting informant. #[derive(Default)] diff --git a/bin/evmbin/src/display/std_json.rs b/bin/evmbin/src/display/std_json.rs index 4114f719c..fc5891245 100644 --- a/bin/evmbin/src/display/std_json.rs +++ b/bin/evmbin/src/display/std_json.rs @@ -20,10 +20,10 @@ use std::{collections::HashMap, io}; use super::config::Config; use bytes::ToPretty; -use display; +use crate::display; use ethcore::{pod_state, trace}; use ethereum_types::{BigEndianHash, H256, U256}; -use info as vm; +use crate::info as vm; pub trait Writer: io::Write + Send + Sized { fn clone(&self) -> Self; @@ -132,7 +132,7 @@ impl Informant { root: H256, end_state: &Option, ) { - if let Some(ref end_state) = end_state { + if let Some(end_state) = end_state { let dump_data = json!({ "root": root, "accounts": end_state, From 9a629366cb58d65f45a00d85c8ea1f5992d2382d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 28 Apr 2025 15:14:16 +0200 Subject: [PATCH 441/687] batch of rust 2025 changes for tests target. --- bin/evmbin/src/display/std_json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/evmbin/src/display/std_json.rs b/bin/evmbin/src/display/std_json.rs index fc5891245..aabe0dca1 100644 --- a/bin/evmbin/src/display/std_json.rs +++ b/bin/evmbin/src/display/std_json.rs @@ -165,7 +165,7 @@ impl vm::Informant for Informant { } fn finish( result: vm::RunResult<::Output>, - (ref mut trace_sink, ref mut out_sink, _): &mut Self::Sink, + ( trace_sink, out_sink, _): &mut Self::Sink, ) { match result { Ok(success) => { From b4d752d305eed5e401c087b013789d56e5daf70d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Apr 2025 14:09:17 +0200 Subject: [PATCH 442/687] cargo fmt --all -- --config imports_granularity=Crate --- bin/ethstore/src/main.rs | 4 +--- bin/evmbin/src/display/json.rs | 3 +-- bin/evmbin/src/display/simple.rs | 3 +-- bin/evmbin/src/display/std_json.rs | 5 ++-- crates/ethcore/src/block.rs | 2 +- crates/ethcore/src/client/evm_test_client.rs | 5 +--- crates/ethcore/src/client/test_client.rs | 6 ++--- crates/ethcore/src/engines/clique/mod.rs | 15 ++++++------ crates/ethcore/src/engines/clique/tests.rs | 3 +-- .../engines/hbbft/test/hbbft_test_client.rs | 2 +- .../src/engines/validator_set/contract.rs | 2 +- .../src/engines/validator_set/multi.rs | 2 +- .../engines/validator_set/safe_contract.rs | 2 +- crates/ethcore/src/json_tests/chain.rs | 4 ++-- crates/ethcore/src/json_tests/executive.rs | 2 +- crates/ethcore/src/json_tests/state.rs | 2 +- crates/ethcore/src/miner/miner.rs | 2 +- crates/ethcore/src/test_helpers.rs | 4 ++-- crates/ethcore/src/tests/client.rs | 2 +- crates/ethcore/src/tests/trace.rs | 2 +- crates/ethcore/src/tx_filter.rs | 2 +- crates/rpc/src/v1/tests/eth.rs | 3 +-- .../rpc/src/v1/tests/helpers/miner_service.rs | 24 ++++++++++--------- crates/rpc/src/v1/tests/mocked/eth.rs | 14 ++++++----- crates/rpc/src/v1/tests/mocked/parity.rs | 10 ++++---- crates/rpc/src/v1/types/transaction.rs | 2 +- 26 files changed, 62 insertions(+), 65 deletions(-) diff --git a/bin/ethstore/src/main.rs b/bin/ethstore/src/main.rs index 4542f6911..247411185 100644 --- a/bin/ethstore/src/main.rs +++ b/bin/ethstore/src/main.rs @@ -150,9 +150,7 @@ impl fmt::Display for Error { fn main() { panic_hook::set_abort(); if env::var("RUST_LOG").is_err() { - unsafe { - env::set_var("RUST_LOG", "warn") - } + unsafe { env::set_var("RUST_LOG", "warn") } } env_logger::try_init().expect("Logger initialized only once."); diff --git a/bin/evmbin/src/display/json.rs b/bin/evmbin/src/display/json.rs index ac63f6d08..c0b68e21f 100644 --- a/bin/evmbin/src/display/json.rs +++ b/bin/evmbin/src/display/json.rs @@ -19,11 +19,10 @@ use std::{collections::HashMap, mem}; use super::config::Config; +use crate::{display, info as vm}; use bytes::ToPretty; -use crate::display; use ethcore::trace; use ethereum_types::{BigEndianHash, H256, U256}; -use crate::info as vm; /// JSON formatting informant. #[derive(Default)] diff --git a/bin/evmbin/src/display/simple.rs b/bin/evmbin/src/display/simple.rs index 338e39355..acd30773d 100644 --- a/bin/evmbin/src/display/simple.rs +++ b/bin/evmbin/src/display/simple.rs @@ -20,8 +20,7 @@ use super::config::Config; use bytes::ToPretty; use ethcore::trace; -use crate::display; -use crate::info as vm; +use crate::{display, info as vm}; /// Simple formatting informant. #[derive(Default)] diff --git a/bin/evmbin/src/display/std_json.rs b/bin/evmbin/src/display/std_json.rs index aabe0dca1..4d46cdee7 100644 --- a/bin/evmbin/src/display/std_json.rs +++ b/bin/evmbin/src/display/std_json.rs @@ -19,11 +19,10 @@ use std::{collections::HashMap, io}; use super::config::Config; +use crate::{display, info as vm}; use bytes::ToPretty; -use crate::display; use ethcore::{pod_state, trace}; use ethereum_types::{BigEndianHash, H256, U256}; -use crate::info as vm; pub trait Writer: io::Write + Send + Sized { fn clone(&self) -> Self; @@ -165,7 +164,7 @@ impl vm::Informant for Informant { } fn finish( result: vm::RunResult<::Output>, - ( trace_sink, out_sink, _): &mut Self::Sink, + (trace_sink, out_sink, _): &mut Self::Sink, ) { match result { Ok(success) => { diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index 361fb7cb3..a03c947fa 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -632,12 +632,12 @@ mod tests { use crate::{ engines::EthEngine, factory::Factories, + state_db::StateDB, types::{header::Header, transaction::SignedTransaction, view, views::BlockView}, verification::queue::kind::blocks::Unverified, }; use error::Error; use ethereum_types::Address; - use crate::state_db::StateDB; use std::sync::Arc; use test_helpers::get_temp_state_db; use vm::LastHashes; diff --git a/crates/ethcore/src/client/evm_test_client.rs b/crates/ethcore/src/client/evm_test_client.rs index 3f07a558d..2edea9965 100644 --- a/crates/ethcore/src/client/evm_test_client.rs +++ b/crates/ethcore/src/client/evm_test_client.rs @@ -19,7 +19,7 @@ use crate::{ client, executive, factory::{self, Factories}, - spec, trace, + pod_state, spec, state, state_db, trace, types::{log_entry, receipt, transaction}, }; use db; @@ -28,9 +28,6 @@ use ethtrie; use evm::{FinalizationResult, VMType}; use journaldb; use kvdb::{self, KeyValueDB}; -use crate::pod_state; -use crate::state; -use crate::state_db; use std::{fmt, sync::Arc}; use trie; use vm::{self, ActionParams}; diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index 128ca329b..4143ede4e 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -69,18 +69,18 @@ use crate::{ traits::{ForceUpdateSealing, TransactionRequest}, }, engines::EthEngine, + error::{Error, EthcoreResult}, executed::CallError, executive::Executed, + miner::{self, Miner, MinerService}, spec::Spec, state::StateInfo, + state_db::StateDB, trace::LocalizedTrace, verification::queue::{QueueInfo, kind::blocks::Unverified}, }; use call_contract::{CallContract, RegistryInfo}; -use crate::error::{Error, EthcoreResult}; use journaldb; -use crate::miner::{self, Miner, MinerService}; -use crate::state_db::StateDB; use stats::{PrometheusMetrics, PrometheusRegistry}; use super::ReservedPeersManagement; diff --git a/crates/ethcore/src/engines/clique/mod.rs b/crates/ethcore/src/engines/clique/mod.rs index 21aaa586c..d5f03291b 100644 --- a/crates/ethcore/src/engines/clique/mod.rs +++ b/crates/ethcore/src/engines/clique/mod.rs @@ -332,13 +332,14 @@ impl Clique { .expect("chain has at least one element; qed") .parent_hash(); - let last_checkpoint_header = - match c.block_header(BlockId::Hash(last_checkpoint_hash)) { - None => { - return Err(EngineError::CliqueMissingCheckpoint(last_checkpoint_hash))?; - } - Some(header) => header.decode(self.machine.params().eip1559_transition)?, - }; + let last_checkpoint_header = match c + .block_header(BlockId::Hash(last_checkpoint_hash)) + { + None => { + return Err(EngineError::CliqueMissingCheckpoint(last_checkpoint_hash))?; + } + Some(header) => header.decode(self.machine.params().eip1559_transition)?, + }; let last_checkpoint_state = match block_state_by_hash.get_mut(&last_checkpoint_hash) { diff --git a/crates/ethcore/src/engines/clique/tests.rs b/crates/ethcore/src/engines/clique/tests.rs index b25b7a5cc..a9c837920 100644 --- a/crates/ethcore/src/engines/clique/tests.rs +++ b/crates/ethcore/src/engines/clique/tests.rs @@ -17,11 +17,10 @@ //! Consensus tests for `PoA Clique Engine`, see http://eips.ethereum.org/EIPS/eip-225 for more information use super::*; -use crate::{block::*, engines::Engine}; +use crate::{block::*, engines::Engine, state_db::StateDB}; use crypto::publickey::{KeyPair, Secret}; use error::{Error, ErrorKind}; use ethereum_types::{Address, H256}; -use crate::state_db::StateDB; use test_helpers::get_temp_state_db; use std::{collections::HashMap, sync::Arc}; diff --git a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs index a963033ce..9d95a7c50 100644 --- a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs +++ b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs @@ -5,12 +5,12 @@ use crate::{ traits::{Balance, StateOrBlock}, }, engines::signer::from_keypair, + miner::{Miner, MinerService}, spec::Spec, types::{data_format::DataFormat, ids::BlockId}, }; use crypto::publickey::{Generator, KeyPair, Random}; use ethereum_types::{Address, U256}; -use crate::miner::{Miner, MinerService}; use parking_lot::RwLock; use std::{ops::Deref, sync::Arc}; use test_helpers::{TestNotify, generate_dummy_client_with_spec}; diff --git a/crates/ethcore/src/engines/validator_set/contract.rs b/crates/ethcore/src/engines/validator_set/contract.rs index 7f97b40c8..01787be1e 100644 --- a/crates/ethcore/src/engines/validator_set/contract.rs +++ b/crates/ethcore/src/engines/validator_set/contract.rs @@ -220,6 +220,7 @@ mod tests { use super::{super::ValidatorSet, ValidatorContract}; use crate::{ client::{BlockChainClient, BlockInfo, ChainInfo, traits::TransactionRequest}, + miner::{self, MinerService}, spec::Spec, types::{header::Header, ids::BlockId}, }; @@ -229,7 +230,6 @@ mod tests { use ethabi::FunctionOutputDecoder; use ethereum_types::{Address, H520}; use hash::keccak; - use crate::miner::{self, MinerService}; use rlp::encode; use rustc_hex::FromHex; use std::sync::Arc; diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index 8ff8b9f3a..ccc730a47 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -214,6 +214,7 @@ mod tests { traits::{ForceUpdateSealing, TransactionRequest}, }, engines::{EpochChange, validator_set::ValidatorSet}, + miner::{self, MinerService}, spec::Spec, types::{header::Header, ids::BlockId}, verification::queue::kind::blocks::Unverified, @@ -222,7 +223,6 @@ mod tests { use crypto::publickey::Secret; use ethereum_types::Address; use hash::keccak; - use crate::miner::{self, MinerService}; use std::{collections::BTreeMap, sync::Arc}; use test_helpers::generate_dummy_client_with_spec; diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index 39690e329..56a433273 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -725,6 +725,7 @@ mod tests { BlockInfo, ChainInfo, ImportBlock, traits::{EngineClient, ForceUpdateSealing}, }, + miner::{self, MinerService}, spec::Spec, types::{ ids::BlockId, @@ -736,7 +737,6 @@ mod tests { use crypto::publickey::Secret; use ethereum_types::Address; use hash::keccak; - use crate::miner::{self, MinerService}; use rustc_hex::FromHex; use std::sync::Arc; use test_helpers::generate_dummy_client_with_spec; diff --git a/crates/ethcore/src/json_tests/chain.rs b/crates/ethcore/src/json_tests/chain.rs index ece19caaa..ec8481f31 100644 --- a/crates/ethcore/src/json_tests/chain.rs +++ b/crates/ethcore/src/json_tests/chain.rs @@ -23,16 +23,16 @@ use crate::{ ImportBlock, Nonce, StateOrBlock, }, io::IoChannel, + miner::Miner, spec::Genesis, + test_helpers, verification::{VerifierType, queue::kind::blocks::Unverified}, }; use ethereum_types::{H256, U256}; use ethjson; use log::warn; -use crate::miner::Miner; use rustc_hex::ToHex; use std::{path::Path, sync::Arc}; -use crate::test_helpers; fn check_poststate( client: &Arc, diff --git a/crates/ethcore/src/json_tests/executive.rs b/crates/ethcore/src/json_tests/executive.rs index 358629ab3..4b5540f7e 100644 --- a/crates/ethcore/src/json_tests/executive.rs +++ b/crates/ethcore/src/json_tests/executive.rs @@ -20,6 +20,7 @@ use crate::{ externalities::*, machine::EthereumMachine as Machine, state::{Backend as StateBackend, State, Substate}, + test_helpers::get_temp_state, trace::{NoopTracer, NoopVMTracer, Tracer, VMTracer}, }; use bytes::Bytes; @@ -30,7 +31,6 @@ use evm::Finalize; use hash::keccak; use rlp::RlpStream; use std::{path::Path, sync::Arc}; -use crate::test_helpers::get_temp_state; use vm::{ self, ActionParams, CallType, ContractCreateResult, CreateContractAddress, EnvInfo, Ext, MessageCallResult, ReturnData, Schedule, diff --git a/crates/ethcore/src/json_tests/state.rs b/crates/ethcore/src/json_tests/state.rs index 56a6cb66b..8fb25313d 100644 --- a/crates/ethcore/src/json_tests/state.rs +++ b/crates/ethcore/src/json_tests/state.rs @@ -17,10 +17,10 @@ use super::{HookType, test_common::*}; use crate::{ client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess}, + pod_state::PodState, trace, }; use ethjson::{self, spec::ForkSpec}; -use crate::pod_state::PodState; use std::path::Path; use vm::EnvInfo; diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 251ffa767..8d1e81268 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -1838,9 +1838,9 @@ mod tests { use crate::{ client::{ChainInfo, EachBlockWith, ImportSealedBlock, TestBlockChainClient}, + miner::{MinerService, PendingOrdering}, types::transaction::{Transaction, TypedTransaction}, }; - use crate::miner::{MinerService, PendingOrdering}; use test_helpers::{ dummy_engine_signer_with_address, generate_dummy_client, generate_dummy_client_with_spec, }; diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index 2ce578e94..9e86a3f07 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -51,13 +51,13 @@ use crate::{ }, engines::{EngineSigner, Seal}, factory::Factories, + miner::Miner, spec::Spec, state::*, + state_db::StateDB, verification::queue::kind::blocks::Unverified, }; use ethjson::crypto::publickey::{Public, Signature}; -use crate::miner::Miner; -use crate::state_db::StateDB; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index 37949f146..b92f0b871 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -29,6 +29,7 @@ use crate::{ }, executive::{Executive, TransactOptions}, io::IoChannel, + miner::{Miner, MinerService, PendingOrdering}, spec::Spec, state::{self, CleanupMode, State, StateInfo}, types::{ @@ -45,7 +46,6 @@ use crypto::publickey::KeyPair; use ethereum; use ethereum_types::{Address, U256}; use hash::keccak; -use crate::miner::{Miner, MinerService, PendingOrdering}; use rustc_hex::ToHex; use tempdir::TempDir; use test_helpers::{ diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index fc5d76a42..63a6dac6a 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -20,6 +20,7 @@ use crate::{ block::*, client::{BlockChainClient, Client, ClientConfig, *}, io::*, + miner::Miner, spec::*, trace::{LocalizedTrace, RewardType, trace::Action::Reward}, types::{ @@ -33,7 +34,6 @@ use crate::{ use crypto::publickey::KeyPair; use ethereum_types::{Address, U256}; use hash::keccak; -use crate::miner::Miner; use std::{str::FromStr, sync::Arc}; use test_helpers::{self, get_temp_state_db}; diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 6b11d4938..ca3341b46 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -285,6 +285,7 @@ mod test { use crate::{ client::{BlockChainClient, BlockId, Client, ClientConfig}, io::IoChannel, + miner::Miner, spec::Spec, types::transaction::{ AccessListTx, Action, EIP1559TransactionTx, Transaction, TypedTransaction, @@ -292,7 +293,6 @@ mod test { }; use crypto::publickey::{KeyPair, Secret}; use ethereum_types::{Address, U256}; - use crate::miner::Miner; use std::{str::FromStr, sync::Arc}; use tempdir::TempDir; use test_helpers; diff --git a/crates/rpc/src/v1/tests/eth.rs b/crates/rpc/src/v1/tests/eth.rs index 1a1a985a3..0edff735a 100644 --- a/crates/rpc/src/v1/tests/eth.rs +++ b/crates/rpc/src/v1/tests/eth.rs @@ -17,7 +17,7 @@ //! rpc integration tests. use std::{env, sync::Arc}; -use crate::{io::IoChannel, types::ids::BlockId}; +use crate::{io::IoChannel, miner::external::ExternalMiner, types::ids::BlockId}; use accounts::AccountProvider; use ethcore::{ client::{BlockChainClient, ChainInfo, Client, ClientConfig, EvmTestClient, ImportBlock}, @@ -29,7 +29,6 @@ use ethcore::{ }; use ethereum_types::{Address, H256, U256}; use ethjson::{blockchain::BlockChain, spec::ForkSpec}; -use crate::miner::external::ExternalMiner; use parity_runtime::Runtime; use parking_lot::Mutex; diff --git a/crates/rpc/src/v1/tests/helpers/miner_service.rs b/crates/rpc/src/v1/tests/helpers/miner_service.rs index dc5517584..891c9e3b3 100644 --- a/crates/rpc/src/v1/tests/helpers/miner_service.rs +++ b/crates/rpc/src/v1/tests/helpers/miner_service.rs @@ -21,13 +21,19 @@ use std::{ sync::Arc, }; -use crate::types::{ - BlockNumber, - block::Block, - header::Header, - ids::BlockId, - receipt::RichReceipt, - transaction::{self, PendingTransaction, SignedTransaction, UnverifiedTransaction}, +use crate::{ + miner::pool::{ + QueueStatus, VerifiedTransaction, local_transactions::Status as LocalTransactionStatus, + verifier, + }, + types::{ + BlockNumber, + block::Block, + header::Header, + ids::BlockId, + receipt::RichReceipt, + transaction::{self, PendingTransaction, SignedTransaction, UnverifiedTransaction}, + }, }; use bytes::Bytes; use call_contract::CallContract; @@ -42,10 +48,6 @@ use ethcore::{ miner::{self, AuthoringParams, MinerService, TransactionFilter}, }; use ethereum_types::{Address, H256, U256}; -use crate::miner::pool::{ - QueueStatus, VerifiedTransaction, local_transactions::Status as LocalTransactionStatus, - verifier, -}; use parking_lot::{Mutex, RwLock}; /// Test miner service. diff --git a/crates/rpc/src/v1/tests/mocked/eth.rs b/crates/rpc/src/v1/tests/mocked/eth.rs index 7cd36f9c2..f7968b936 100644 --- a/crates/rpc/src/v1/tests/mocked/eth.rs +++ b/crates/rpc/src/v1/tests/mocked/eth.rs @@ -21,11 +21,14 @@ use std::{ time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; -use crate::types::{ - ids::{BlockId, TransactionId}, - log_entry::{LocalizedLogEntry, LogEntry}, - receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome}, - transaction::{Action, Transaction, TypedTransaction, TypedTxId}, +use crate::{ + miner::external::ExternalMiner, + types::{ + ids::{BlockId, TransactionId}, + log_entry::{LocalizedLogEntry, LogEntry}, + receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome}, + transaction::{Action, Transaction, TypedTransaction, TypedTxId}, + }, }; use accounts::AccountProvider; use ethcore::{ @@ -33,7 +36,6 @@ use ethcore::{ miner::{self, MinerService}, }; use ethereum_types::{Address, Bloom, H160, H256, U256}; -use crate::miner::external::ExternalMiner; use parity_runtime::Runtime; use parking_lot::Mutex; use rustc_hex::{FromHex, ToHex}; diff --git a/crates/rpc/src/v1/tests/mocked/parity.rs b/crates/rpc/src/v1/tests/mocked/parity.rs index 48be233e8..cd26e1f38 100644 --- a/crates/rpc/src/v1/tests/mocked/parity.rs +++ b/crates/rpc/src/v1/tests/mocked/parity.rs @@ -14,15 +14,17 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::types::{ - receipt::{LocalizedReceipt, TransactionOutcome}, - transaction::TypedTxId, +use crate::{ + miner::pool::local_transactions::Status as LocalTransactionStatus, + types::{ + receipt::{LocalizedReceipt, TransactionOutcome}, + transaction::TypedTxId, + }, }; use crypto::publickey::{Generator, Random}; use ethcore::client::{Executed, TestBlockChainClient, TransactionId}; use ethcore_logger::RotatingLogger; use ethereum_types::{Address, BigEndianHash, Bloom, H256, U256}; -use crate::miner::pool::local_transactions::Status as LocalTransactionStatus; use std::{str::FromStr, sync::Arc}; use sync::ManageNetwork; diff --git a/crates/rpc/src/v1/types/transaction.rs b/crates/rpc/src/v1/types/transaction.rs index 53cd1dd80..ca4a983d7 100644 --- a/crates/rpc/src/v1/types/transaction.rs +++ b/crates/rpc/src/v1/types/transaction.rs @@ -17,6 +17,7 @@ use std::sync::Arc; use crate::{ + miner, types::transaction::{ Action, LocalizedTransaction, PendingTransaction, SignedTransaction, TypedTransaction, TypedTxId, @@ -25,7 +26,6 @@ use crate::{ }; use ethcore::{CreateContractAddress, contract_address}; use ethereum_types::{H160, H256, H512, U64, U256}; -use crate::miner; use serde::{Serialize, Serializer, ser::SerializeStruct}; /// Transaction From cb3fa987a8cb55a23fdc1effc2ebae80a95eac11 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Apr 2025 14:12:59 +0200 Subject: [PATCH 443/687] fixed IoError and IoHandler imports for Non-Mio --- crates/runtime/io/src/service_non_mio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/runtime/io/src/service_non_mio.rs b/crates/runtime/io/src/service_non_mio.rs index 6712a2e0f..d09b71d46 100644 --- a/crates/runtime/io/src/service_non_mio.rs +++ b/crates/runtime/io/src/service_non_mio.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::{ioError, ioHandler}; +use crate::{IoError, IoHandler}; use deque; use fnv::FnvHashMap; use num_cpus; From 8263f9e11be312597d4d598e3368267f915d61f2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Apr 2025 16:46:12 +0200 Subject: [PATCH 444/687] fixed imports for benchmarks (cargo check --locked --all --benches --verbose) --- crates/ethcore/src/externalities.rs | 2 +- crates/ethcore/src/tests/client.rs | 4 ++-- crates/ethcore/src/tests/evm.rs | 2 +- crates/ethcore/src/verification/queue/mod.rs | 4 ++-- crates/ethcore/src/verification/verification.rs | 4 ++-- crates/rpc/src/tests/rpc.rs | 2 +- crates/rpc/src/v1/extractors.rs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index 9169cb088..3a1da6d20 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -604,7 +604,7 @@ mod tests { impl TestSetup { fn new() -> Self { - let machine = ::spec::Spec::new_test_machine(); + let machine = crate::spec::Spec::new_test_machine(); let env_info = get_test_env_info(); let schedule = machine.schedule(env_info.number); TestSetup { diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index b92f0b871..e4d30268f 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -479,8 +479,8 @@ fn transaction_proof() { .1; let backend = state::backend::ProofCheck::new(&proof); - let mut factories = ::factory::Factories::default(); - factories.accountdb = ::account_db::Factory::Plain; // raw state values, no mangled keys. + let mut factories = crate::factory::Factories::default(); + factories.accountdb = crate::account_db::Factory::Plain; // raw state values, no mangled keys. let root = *client.best_block_header().state_root(); let machine = test_spec.engine.machine(); diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index 6df5847f5..ecc55254d 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -40,7 +40,7 @@ fn test_blockhash_eip210(factory: Factory) { let test_blockhash_contract = "73fffffffffffffffffffffffffffffffffffffffe33141561007a57600143036020526000356101006020510755600061010060205107141561005057600035610100610100602051050761010001555b6000620100006020510714156100755760003561010062010000602051050761020001555b61014a565b4360003512151561009057600060405260206040f35b610100600035430312156100b357610100600035075460605260206060f3610149565b62010000600035430312156100d157600061010060003507146100d4565b60005b156100f6576101006101006000350507610100015460805260206080f3610148565b630100000060003543031215610116576000620100006000350714610119565b60005b1561013c57610100620100006000350507610200015460a052602060a0f3610147565b600060c052602060c0f35b5b5b5b5b"; let blockhash_contract_code = Arc::new(test_blockhash_contract.from_hex().unwrap()); let blockhash_contract_code_hash = keccak(blockhash_contract_code.as_ref()); - let machine = ::ethereum::new_eip210_test_machine(); + let machine = crate::ethereum::new_eip210_test_machine(); let mut env_info = EnvInfo::default(); // populate state with 256 last hashes diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index 8a0eb7bb3..ac8520a7c 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -879,8 +879,8 @@ mod tests { types::{BlockNumber, view, views::BlockView}, }; use bytes::Bytes; - use error::*; - use test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; + use crate::error::*; + use crate::test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; // create a test block queue. // auto_scaling enables verifier adjustment. diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index e0a81e479..b256fc050 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -553,7 +553,7 @@ mod tests { }, }; use crypto::publickey::{Generator, Random}; - use error::{BlockError::*, ErrorKind}; + use crate::error::{BlockError::*, ErrorKind}; use ethereum_types::{Address, BloomRef, H256, U256}; use hash::keccak; use rlp; @@ -561,7 +561,7 @@ mod tests { collections::{BTreeMap, HashMap}, time::{SystemTime, UNIX_EPOCH}, }; - use test_helpers::{create_test_block, create_test_block_with_data}; + use crate::test_helpers::{create_test_block, create_test_block_with_data}; use triehash::ordered_trie_root; fn check_ok(result: Result<(), Error>) { diff --git a/crates/rpc/src/tests/rpc.rs b/crates/rpc/src/tests/rpc.rs index 3222cafee..4183c1632 100644 --- a/crates/rpc/src/tests/rpc.rs +++ b/crates/rpc/src/tests/rpc.rs @@ -62,7 +62,7 @@ mod tests { use crate::v1::Metadata; use jsonrpc_core::{MetaIoHandler, Value}; - fn serve() -> (Server<::HttpServer>, ::std::net::SocketAddr) { + fn serve() -> (Server, ::std::net::SocketAddr) { let mut io = MetaIoHandler::default(); io.add_method_with_meta("hello", |_, meta: Metadata| { Ok(Value::String(format!("{}", meta.origin))) diff --git a/crates/rpc/src/v1/extractors.rs b/crates/rpc/src/v1/extractors.rs index 68350c491..166931504 100644 --- a/crates/rpc/src/v1/extractors.rs +++ b/crates/rpc/src/v1/extractors.rs @@ -257,7 +257,7 @@ impl> core::Middleware for WsDispatcher< #[cfg(test)] mod tests { use super::RpcExtractor; - use Origin; + use crate::Origin; use http::{ MetaExtractor, hyper::{Body, Request}, From e267f70040c2828d6bb8839f5a7c8310991c9142 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 6 May 2025 22:15:37 +0200 Subject: [PATCH 445/687] ethkey fix --- crates/accounts/ethkey/src/brain_prefix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/accounts/ethkey/src/brain_prefix.rs b/crates/accounts/ethkey/src/brain_prefix.rs index 819dce564..d7226eabc 100644 --- a/crates/accounts/ethkey/src/brain_prefix.rs +++ b/crates/accounts/ethkey/src/brain_prefix.rs @@ -56,7 +56,7 @@ impl BrainPrefix { #[cfg(test)] mod tests { - use BrainPrefix; + use crate::BrainPrefix; #[test] fn prefix_generator() { From 61b9208429acb5ff03d9f062ee2e8b96723c2478 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 6 May 2025 22:17:29 +0200 Subject: [PATCH 446/687] tet fixes rust 2025 --- crates/ethcore/src/block.rs | 2 +- crates/ethcore/src/client/client.rs | 6 +++--- crates/ethcore/src/engines/block_reward.rs | 2 +- crates/ethcore/src/engines/clique/tests.rs | 2 +- crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs | 2 +- crates/ethcore/src/engines/instant_seal.rs | 2 +- crates/ethcore/src/engines/validator_set/contract.rs | 2 +- crates/ethcore/src/engines/validator_set/multi.rs | 2 +- crates/ethcore/src/engines/validator_set/safe_contract.rs | 2 +- crates/ethcore/src/ethereum/ethash.rs | 2 +- crates/ethcore/src/ethereum/mod.rs | 2 +- crates/ethcore/src/executive.rs | 2 +- crates/ethcore/src/externalities.rs | 2 +- crates/ethcore/src/miner/miner.rs | 2 +- crates/ethcore/src/snapshot/account.rs | 2 +- crates/ethcore/src/snapshot/service.rs | 2 +- crates/ethcore/src/snapshot/tests/proof_of_authority.rs | 4 ++-- crates/ethcore/src/snapshot/tests/proof_of_work.rs | 2 +- crates/ethcore/src/snapshot/tests/service.rs | 2 +- crates/ethcore/src/spec/spec.rs | 2 +- crates/ethcore/src/state/mod.rs | 2 +- crates/ethcore/src/state_db.rs | 2 +- crates/ethcore/src/tests/blockchain.rs | 2 +- crates/ethcore/src/tests/client.rs | 2 +- crates/ethcore/src/tests/evm.rs | 2 +- crates/ethcore/src/tests/trace.rs | 2 +- crates/ethcore/src/trace/db.rs | 2 +- crates/ethcore/src/tx_filter.rs | 2 +- crates/ethcore/src/verification/queue/mod.rs | 2 +- crates/ethcore/src/verification/verification.rs | 2 +- 30 files changed, 33 insertions(+), 33 deletions(-) diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index a03c947fa..0d81bee14 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -639,7 +639,7 @@ mod tests { use error::Error; use ethereum_types::Address; use std::sync::Arc; - use test_helpers::get_temp_state_db; + use crate::test_helpers::get_temp_state_db; use vm::LastHashes; /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index c10b3f638..cf3fd2efb 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -3790,12 +3790,12 @@ mod tests { spec::Spec, }; use ethereum_types::{H160, H256}; - use test_helpers::generate_dummy_client_with_spec_and_data; + use crate::test_helpers::generate_dummy_client_with_spec_and_data; #[test] fn should_not_cache_details_before_commit() { use crate::client::{BlockChainClient, ChainInfo}; - use test_helpers::{generate_dummy_client, get_good_dummy_block_hash}; + use crate::test_helpers::{generate_dummy_client, get_good_dummy_block_hash}; use crate::types::encoded; use kvdb::DBTransaction; @@ -3843,7 +3843,7 @@ mod tests { #[test] fn should_return_block_receipts() { use crate::client::{BlockChainClient, BlockId, TransactionId}; - use test_helpers::generate_dummy_client_with_data; + use crate::test_helpers::generate_dummy_client_with_data; let client = generate_dummy_client_with_data(2, 2, &[1.into(), 1.into()]); let receipts = client.localized_block_receipts(BlockId::Latest).unwrap(); diff --git a/crates/ethcore/src/engines/block_reward.rs b/crates/ethcore/src/engines/block_reward.rs index 35f9cf2c0..c96f8a2f4 100644 --- a/crates/ethcore/src/engines/block_reward.rs +++ b/crates/ethcore/src/engines/block_reward.rs @@ -199,7 +199,7 @@ pub fn apply_block_rewards( mod test { use crate::{client::PrepareOpenBlock, spec::Spec}; use ethereum_types::{H160, U256}; - use test_helpers::generate_dummy_client_with_spec; + use crate::test_helpers::generate_dummy_client_with_spec; use super::{BlockRewardContract, RewardKind}; use crate::engines::SystemOrCodeCallKind; diff --git a/crates/ethcore/src/engines/clique/tests.rs b/crates/ethcore/src/engines/clique/tests.rs index a9c837920..aa394162f 100644 --- a/crates/ethcore/src/engines/clique/tests.rs +++ b/crates/ethcore/src/engines/clique/tests.rs @@ -21,7 +21,7 @@ use crate::{block::*, engines::Engine, state_db::StateDB}; use crypto::publickey::{KeyPair, Secret}; use error::{Error, ErrorKind}; use ethereum_types::{Address, H256}; -use test_helpers::get_temp_state_db; +use crate::test_helpers::get_temp_state_db; use std::{collections::HashMap, sync::Arc}; diff --git a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs index 9d95a7c50..b0d7c2e92 100644 --- a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs +++ b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs @@ -13,7 +13,7 @@ use crypto::publickey::{Generator, KeyPair, Random}; use ethereum_types::{Address, U256}; use parking_lot::RwLock; use std::{ops::Deref, sync::Arc}; -use test_helpers::{TestNotify, generate_dummy_client_with_spec}; +use crate::test_helpers::{TestNotify, generate_dummy_client_with_spec}; pub fn hbbft_spec() -> Spec { Spec::load( diff --git a/crates/ethcore/src/engines/instant_seal.rs b/crates/ethcore/src/engines/instant_seal.rs index efd38cfc7..6ac747831 100644 --- a/crates/ethcore/src/engines/instant_seal.rs +++ b/crates/ethcore/src/engines/instant_seal.rs @@ -131,7 +131,7 @@ mod tests { use crate::{block::*, engines::Seal, spec::Spec, types::header::Header}; use ethereum_types::{Address, H520}; use std::sync::Arc; - use test_helpers::get_temp_state_db; + use crate::test_helpers::get_temp_state_db; #[test] fn instant_can_seal() { diff --git a/crates/ethcore/src/engines/validator_set/contract.rs b/crates/ethcore/src/engines/validator_set/contract.rs index 01787be1e..6d5f430f0 100644 --- a/crates/ethcore/src/engines/validator_set/contract.rs +++ b/crates/ethcore/src/engines/validator_set/contract.rs @@ -233,7 +233,7 @@ mod tests { use rlp::encode; use rustc_hex::FromHex; use std::sync::Arc; - use test_helpers::generate_dummy_client_with_spec; + use crate::test_helpers::generate_dummy_client_with_spec; #[test] fn fetches_validators() { diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index ccc730a47..1314f5fb4 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -224,7 +224,7 @@ mod tests { use ethereum_types::Address; use hash::keccak; use std::{collections::BTreeMap, sync::Arc}; - use test_helpers::generate_dummy_client_with_spec; + use crate::test_helpers::generate_dummy_client_with_spec; use super::Multi; diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index 56a433273..411f71af9 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -739,7 +739,7 @@ mod tests { use hash::keccak; use rustc_hex::FromHex; use std::sync::Arc; - use test_helpers::generate_dummy_client_with_spec; + use crate::test_helpers::generate_dummy_client_with_spec; #[test] fn fetches_validators() { diff --git a/crates/ethcore/src/ethereum/ethash.rs b/crates/ethcore/src/ethereum/ethash.rs index e6bbed32f..d73629274 100644 --- a/crates/ethcore/src/ethereum/ethash.rs +++ b/crates/ethcore/src/ethereum/ethash.rs @@ -570,7 +570,7 @@ mod tests { use rlp; use std::{collections::BTreeMap, str::FromStr, sync::Arc}; use tempdir::TempDir; - use test_helpers::get_temp_state_db; + use crate::test_helpers::get_temp_state_db; fn test_spec() -> Spec { let tempdir = TempDir::new("").unwrap(); diff --git a/crates/ethcore/src/ethereum/mod.rs b/crates/ethcore/src/ethereum/mod.rs index 640bd30b5..45b1837dc 100644 --- a/crates/ethcore/src/ethereum/mod.rs +++ b/crates/ethcore/src/ethereum/mod.rs @@ -375,7 +375,7 @@ mod tests { }; use ethereum_types::{H160, H256, U256}; use std::str::FromStr; - use test_helpers::get_temp_state_db; + use crate::test_helpers::get_temp_state_db; #[test] fn ensure_db_good() { diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index 589bc96a1..b1d21d62f 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -1678,7 +1678,7 @@ mod tests { use evm::{Factory, VMType}; use rustc_hex::FromHex; use std::{str::FromStr, sync::Arc}; - use test_helpers::{get_temp_state, get_temp_state_with_factory}; + use crate::test_helpers::{get_temp_state, get_temp_state_with_factory}; use vm::{ActionParams, ActionValue, CallType, CreateContractAddress, EnvInfo}; fn make_frontier_machine(max_depth: usize) -> EthereumMachine { diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index 9169cb088..a1ba8a1d4 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -564,7 +564,7 @@ mod tests { use ethereum_types::{Address, U256}; use evm::{CallType, EnvInfo, Ext}; use std::str::FromStr; - use test_helpers::get_temp_state; + use crate::test_helpers::get_temp_state; fn get_test_origin() -> OriginInfo { OriginInfo { diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 8d1e81268..484890126 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -1841,7 +1841,7 @@ mod tests { miner::{MinerService, PendingOrdering}, types::transaction::{Transaction, TypedTransaction}, }; - use test_helpers::{ + use crate::test_helpers::{ dummy_engine_signer_with_address, generate_dummy_client, generate_dummy_client_with_spec, }; diff --git a/crates/ethcore/src/snapshot/account.rs b/crates/ethcore/src/snapshot/account.rs index 73fe5d59c..f4f169edf 100644 --- a/crates/ethcore/src/snapshot/account.rs +++ b/crates/ethcore/src/snapshot/account.rs @@ -228,7 +228,7 @@ mod tests { snapshot::{Progress, tests::helpers::fill_storage}, types::basic_account::BasicAccount, }; - use test_helpers::get_temp_state_db; + use crate::test_helpers::get_temp_state_db; use ethereum_types::{Address, H256}; use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak}; diff --git a/crates/ethcore/src/snapshot/service.rs b/crates/ethcore/src/snapshot/service.rs index 52f9f8dbf..d710320e2 100644 --- a/crates/ethcore/src/snapshot/service.rs +++ b/crates/ethcore/src/snapshot/service.rs @@ -1023,7 +1023,7 @@ mod tests { }; use journaldb::Algorithm; use tempdir::TempDir; - use test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler}; + use crate::test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler}; #[test] fn sends_async_messages() { diff --git a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs index 58a554452..41de9cbf8 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -27,10 +27,10 @@ use crate::{ use accounts::AccountProvider; use crypto::publickey::Secret; use tempdir::TempDir; -use test_helpers::generate_dummy_client_with_spec; +use crate::test_helpers::generate_dummy_client_with_spec; use ethereum_types::Address; -use test_helpers; +use crate::test_helpers; use_contract!(test_validator_set, "res/contracts/test_validator_set.json"); diff --git a/crates/ethcore/src/snapshot/tests/proof_of_work.rs b/crates/ethcore/src/snapshot/tests/proof_of_work.rs index b4ab5dd32..a9d23e726 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_work.rs @@ -34,7 +34,7 @@ use crate::{ use kvdb::DBTransaction; use parking_lot::Mutex; use snappy; -use test_helpers; +use crate::test_helpers; const SNAPSHOT_MODE: ::snapshot::PowSnapshot = ::snapshot::PowSnapshot { blocks: 30000, diff --git a/crates/ethcore/src/snapshot/tests/service.rs b/crates/ethcore/src/snapshot/tests/service.rs index 25581ea05..e086291d6 100644 --- a/crates/ethcore/src/snapshot/tests/service.rs +++ b/crates/ethcore/src/snapshot/tests/service.rs @@ -30,7 +30,7 @@ use crate::{ types::ids::BlockId, }; use tempdir::TempDir; -use test_helpers::{ +use crate::test_helpers::{ generate_dummy_client_with_spec_and_data, new_db, new_temp_db, restoration_db_handler, }; diff --git a/crates/ethcore/src/spec/spec.rs b/crates/ethcore/src/spec/spec.rs index 9c1630e11..6556f679e 100644 --- a/crates/ethcore/src/spec/spec.rs +++ b/crates/ethcore/src/spec/spec.rs @@ -1245,7 +1245,7 @@ mod tests { use ethereum_types::{H160, H256}; use std::str::FromStr; use tempdir::TempDir; - use test_helpers::get_temp_state_db; + use crate::test_helpers::get_temp_state_db; #[test] fn test_load_empty() { diff --git a/crates/ethcore/src/state/mod.rs b/crates/ethcore/src/state/mod.rs index 51e9e1e75..ddbbb4942 100644 --- a/crates/ethcore/src/state/mod.rs +++ b/crates/ethcore/src/state/mod.rs @@ -1588,7 +1588,7 @@ mod tests { use hash::{KECCAK_NULL_RLP, keccak}; use rustc_hex::FromHex; use std::{str::FromStr, sync::Arc}; - use test_helpers::{get_temp_state, get_temp_state_db}; + use crate::test_helpers::{get_temp_state, get_temp_state_db}; use vm::EnvInfo; fn secret() -> Secret { diff --git a/crates/ethcore/src/state_db.rs b/crates/ethcore/src/state_db.rs index 01e7118ad..545d65eeb 100644 --- a/crates/ethcore/src/state_db.rs +++ b/crates/ethcore/src/state_db.rs @@ -445,7 +445,7 @@ mod tests { use crate::state::{Account, Backend}; use ethereum_types::{Address, H256, U256}; use kvdb::DBTransaction; - use test_helpers::get_temp_state_db; + use crate::test_helpers::get_temp_state_db; #[test] fn state_db_smoke() { diff --git a/crates/ethcore/src/tests/blockchain.rs b/crates/ethcore/src/tests/blockchain.rs index aa5780a79..98a605d7c 100644 --- a/crates/ethcore/src/tests/blockchain.rs +++ b/crates/ethcore/src/tests/blockchain.rs @@ -16,7 +16,7 @@ use crate::blockchain::BlockProvider; -use test_helpers::{ +use crate::test_helpers::{ generate_dummy_blockchain, generate_dummy_blockchain_with_extra, generate_dummy_empty_blockchain, }; diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index b92f0b871..56cd69186 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -48,7 +48,7 @@ use ethereum_types::{Address, U256}; use hash::keccak; use rustc_hex::ToHex; use tempdir::TempDir; -use test_helpers::{ +use crate::test_helpers::{ self, generate_dummy_client, generate_dummy_client_with_data, get_bad_state_dummy_block, get_good_dummy_block, get_good_dummy_block_seq, get_test_client_with_blocks, push_blocks_to_client, diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index 6df5847f5..061dff2f7 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -25,7 +25,7 @@ use crate::{ use evm::{Factory, VMType}; use hash::keccak; use std::sync::Arc; -use test_helpers::get_temp_state_with_factory; +use crate::test_helpers::get_temp_state_with_factory; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; use rustc_hex::FromHex; diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index 63a6dac6a..3c6f665a7 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -35,7 +35,7 @@ use crypto::publickey::KeyPair; use ethereum_types::{Address, U256}; use hash::keccak; use std::{str::FromStr, sync::Arc}; -use test_helpers::{self, get_temp_state_db}; +use crate::test_helpers::{self, get_temp_state_db}; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/trace/db.rs b/crates/ethcore/src/trace/db.rs index df08c87c9..97ea51908 100644 --- a/crates/ethcore/src/trace/db.rs +++ b/crates/ethcore/src/trace/db.rs @@ -418,7 +418,7 @@ mod tests { use evm::CallType; use kvdb::DBTransaction; use std::{collections::HashMap, sync::Arc}; - use test_helpers::new_db; + use crate::test_helpers::new_db; struct NoopExtras; diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index ca3341b46..a4d3aa8b4 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -295,7 +295,7 @@ mod test { use ethereum_types::{Address, U256}; use std::{str::FromStr, sync::Arc}; use tempdir::TempDir; - use test_helpers; + use crate::test_helpers; /// Contract code: https://gist.github.com/VladLupashevskyi/84f18eabb1e4afadf572cf92af3e7e7f #[test] diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index 8a0eb7bb3..b9f56e756 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -880,7 +880,7 @@ mod tests { }; use bytes::Bytes; use error::*; - use test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; + use crate::test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; // create a test block queue. // auto_scaling enables verifier adjustment. diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index e0a81e479..972153f41 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -561,7 +561,7 @@ mod tests { collections::{BTreeMap, HashMap}, time::{SystemTime, UNIX_EPOCH}, }; - use test_helpers::{create_test_block, create_test_block_with_data}; + use crate::test_helpers::{create_test_block, create_test_block_with_data}; use triehash::ordered_trie_root; fn check_ok(result: Result<(), Error>) { From 79377ad3cf0b010c3ebe6c7848246c07df8c2efa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 6 May 2025 22:19:18 +0200 Subject: [PATCH 447/687] rust 2025 - crate::error --- crates/ethcore/service/src/lib.rs | 2 +- crates/ethcore/src/block.rs | 2 +- crates/ethcore/src/engines/clique/tests.rs | 2 +- crates/ethcore/src/engines/validator_set/test.rs | 2 +- crates/ethcore/src/ethereum/ethash.rs | 2 +- crates/ethcore/src/executive.rs | 2 +- crates/ethcore/src/snapshot/tests/proof_of_work.rs | 2 +- crates/ethcore/src/snapshot/tests/state.rs | 2 +- crates/ethcore/src/verification/queue/mod.rs | 2 +- crates/ethcore/src/verification/verification.rs | 2 +- crates/net/network/src/lib.rs | 2 +- crates/vm/vm/src/lib.rs | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/ethcore/service/src/lib.rs b/crates/ethcore/service/src/lib.rs index 289ded738..07b617991 100644 --- a/crates/ethcore/service/src/lib.rs +++ b/crates/ethcore/service/src/lib.rs @@ -41,5 +41,5 @@ mod stop_guard; #[cfg(test)] extern crate kvdb_rocksdb; -pub use error::{Error, ErrorKind}; +pub use crate::error::{Error, ErrorKind}; pub use service::ClientService; diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index 0d81bee14..f86493700 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -636,7 +636,7 @@ mod tests { types::{header::Header, transaction::SignedTransaction, view, views::BlockView}, verification::queue::kind::blocks::Unverified, }; - use error::Error; + use crate::error::Error; use ethereum_types::Address; use std::sync::Arc; use crate::test_helpers::get_temp_state_db; diff --git a/crates/ethcore/src/engines/clique/tests.rs b/crates/ethcore/src/engines/clique/tests.rs index aa394162f..c07d0c726 100644 --- a/crates/ethcore/src/engines/clique/tests.rs +++ b/crates/ethcore/src/engines/clique/tests.rs @@ -19,7 +19,7 @@ use super::*; use crate::{block::*, engines::Engine, state_db::StateDB}; use crypto::publickey::{KeyPair, Secret}; -use error::{Error, ErrorKind}; +use crate::error::{Error, ErrorKind}; use ethereum_types::{Address, H256}; use crate::test_helpers::get_temp_state_db; diff --git a/crates/ethcore/src/engines/validator_set/test.rs b/crates/ethcore/src/engines/validator_set/test.rs index b74c0c86e..585817a0d 100644 --- a/crates/ethcore/src/engines/validator_set/test.rs +++ b/crates/ethcore/src/engines/validator_set/test.rs @@ -28,7 +28,7 @@ use parity_util_mem::MallocSizeOf; use super::{SimpleList, SystemCall, ValidatorSet}; use crate::machine::{AuxiliaryData, Call, EthereumMachine}; -use error::Error as EthcoreError; +use crate::error::Error as EthcoreError; /// Set used for testing with a single validator. #[derive(Clone, MallocSizeOf)] diff --git a/crates/ethcore/src/ethereum/ethash.rs b/crates/ethcore/src/ethereum/ethash.rs index d73629274..6bfb26497 100644 --- a/crates/ethcore/src/ethereum/ethash.rs +++ b/crates/ethcore/src/ethereum/ethash.rs @@ -565,7 +565,7 @@ mod tests { Ethash, EthashParams, ecip1017_eras_block_reward, }; use crate::{block::*, engines::Engine, spec::Spec, types::header::Header}; - use error::{BlockError, Error, ErrorKind}; + use crate::error::{BlockError, Error, ErrorKind}; use ethereum_types::{Address, H64, H256, U256}; use rlp; use std::{collections::BTreeMap, str::FromStr, sync::Arc}; diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index b1d21d62f..218fee702 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -1673,7 +1673,7 @@ mod tests { }, }; use crypto::publickey::{Generator, Random}; - use error::ExecutionError; + use crate::error::ExecutionError; use ethereum_types::{Address, BigEndianHash, H160, H256, U256, U512}; use evm::{Factory, VMType}; use rustc_hex::FromHex; diff --git a/crates/ethcore/src/snapshot/tests/proof_of_work.rs b/crates/ethcore/src/snapshot/tests/proof_of_work.rs index a9d23e726..653b6d12f 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_work.rs @@ -16,7 +16,7 @@ //! PoW block chunker and rebuilder tests. -use error::{Error, ErrorKind}; +use crate::error::{Error, ErrorKind}; use std::sync::atomic::AtomicBool; use tempdir::TempDir; diff --git a/crates/ethcore/src/snapshot/tests/state.rs b/crates/ethcore/src/snapshot/tests/state.rs index e95974a87..0d10723ca 100644 --- a/crates/ethcore/src/snapshot/tests/state.rs +++ b/crates/ethcore/src/snapshot/tests/state.rs @@ -30,7 +30,7 @@ use crate::{ types::basic_account::BasicAccount, }; -use error::{Error, ErrorKind}; +use crate::error::{Error, ErrorKind}; use self::rand_xorshift::XorShiftRng; use ethereum_types::H256; diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index b9f56e756..ac8520a7c 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -879,7 +879,7 @@ mod tests { types::{BlockNumber, view, views::BlockView}, }; use bytes::Bytes; - use error::*; + use crate::error::*; use crate::test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; // create a test block queue. diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index 972153f41..b256fc050 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -553,7 +553,7 @@ mod tests { }, }; use crypto::publickey::{Generator, Random}; - use error::{BlockError::*, ErrorKind}; + use crate::error::{BlockError::*, ErrorKind}; use ethereum_types::{Address, BloomRef, H256, U256}; use hash::keccak; use rlp; diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index cd116abe8..493385dc5 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -47,7 +47,7 @@ mod error; pub use crate::io::TimerToken; pub use connection_filter::{ConnectionDirection, ConnectionFilter}; -pub use error::{DisconnectReason, Error, ErrorKind}; +pub use crate::error::{DisconnectReason, Error, ErrorKind}; use crate::client_version::ClientVersion; use crypto::publickey::Secret; diff --git a/crates/vm/vm/src/lib.rs b/crates/vm/vm/src/lib.rs index f662921c7..f3438a97c 100644 --- a/crates/vm/vm/src/lib.rs +++ b/crates/vm/vm/src/lib.rs @@ -38,7 +38,7 @@ pub use access_list::AccessList; pub use action_params::{ActionParams, ActionValue, ParamsType}; pub use call_type::CallType; pub use env_info::{EnvInfo, LastHashes}; -pub use error::{Error, ExecTrapError, ExecTrapResult, Result, TrapError, TrapKind, TrapResult}; +pub use crate::error::{Error, ExecTrapError, ExecTrapResult, Result, TrapError, TrapKind, TrapResult}; pub use ext::{ContractCreateResult, CreateContractAddress, Ext, MessageCallResult}; pub use return_data::{GasLeft, ReturnData}; pub use schedule::{CleanDustMode, Schedule, WasmCosts}; From dd7a44e24dfc4ffc62c71ce190bc6de114ce94a8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 May 2025 10:18:25 +0200 Subject: [PATCH 448/687] batch of rust 2025 changes for tests target. --- crates/ethcore/src/tests/client.rs | 2 +- crates/ethcore/sync/src/chain/fork_filter.rs | 4 ++-- crates/ethcore/sync/src/chain/supplier.rs | 2 +- crates/ethcore/types/src/filter.rs | 10 +++++----- crates/rpc/src/tests/rpc.rs | 4 ++-- crates/rpc/src/v1/extractors.rs | 2 +- crates/rpc/src/v1/tests/mocked/parity.rs | 2 +- crates/util/dir/src/lib.rs | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index 56cd69186..3169773e2 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -43,7 +43,7 @@ use crate::{ verification::queue::kind::blocks::Unverified, }; use crypto::publickey::KeyPair; -use ethereum; +use crate::ethereum; use ethereum_types::{Address, U256}; use hash::keccak; use rustc_hex::ToHex; diff --git a/crates/ethcore/sync/src/chain/fork_filter.rs b/crates/ethcore/sync/src/chain/fork_filter.rs index c72c06efd..94939d8f2 100644 --- a/crates/ethcore/sync/src/chain/fork_filter.rs +++ b/crates/ethcore/sync/src/chain/fork_filter.rs @@ -2,10 +2,10 @@ //! to support Ethereum network protocol, version 64 and above. // Re-export ethereum-forkid crate contents here. -pub use ethereum_forkid::{BlockNumber, ForkId, RejectReason}; +pub use crate::ethereum_forkid::{BlockNumber, ForkId, RejectReason}; use ethcore::client::ChainInfo; -use ethereum_forkid::ForkFilter; +use crate::ethereum_forkid::ForkFilter; /// Wrapper around fork filter that provides integration with `ForkFilter`. pub struct ForkFilterApi { diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index 5b195d30f..f11553638 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -545,7 +545,7 @@ mod test { rlp.out() } fn to_header_vec( - rlp: ::chain::RlpResponseResult, + rlp: crate::chain::RlpResponseResult, eip1559_transition: BlockNumber, ) -> Vec { Rlp::new(&rlp.unwrap().unwrap().1.out()) diff --git a/crates/ethcore/types/src/filter.rs b/crates/ethcore/types/src/filter.rs index 5415b447f..8ecedb0bb 100644 --- a/crates/ethcore/types/src/filter.rs +++ b/crates/ethcore/types/src/filter.rs @@ -67,17 +67,17 @@ impl Clone for Filter { impl Filter { /// Returns combinations of each address and topic. pub fn bloom_possibilities(&self) -> Vec { - let blooms = match self.address { - Some(ref addresses) if !addresses.is_empty() => addresses + let blooms = match &self.address { + Some(addresses) if !addresses.is_empty() => addresses .iter() - .map(|ref address| Bloom::from(BloomInput::Raw(address.as_bytes()))) + .map(|address| Bloom::from(BloomInput::Raw(address.as_bytes()))) .collect(), _ => vec![Bloom::default()], }; - self.topics.iter().fold(blooms, |bs, topic| match *topic { + self.topics.iter().fold(blooms, |bs, topic| match topic { None => bs, - Some(ref topics) => bs + Some(topics) => bs .into_iter() .flat_map(|bloom| { topics diff --git a/crates/rpc/src/tests/rpc.rs b/crates/rpc/src/tests/rpc.rs index 3222cafee..c787f416b 100644 --- a/crates/rpc/src/tests/rpc.rs +++ b/crates/rpc/src/tests/rpc.rs @@ -61,8 +61,8 @@ mod tests { use super::{Server, request}; use crate::v1::Metadata; use jsonrpc_core::{MetaIoHandler, Value}; - - fn serve() -> (Server<::HttpServer>, ::std::net::SocketAddr) { + + fn serve() -> (Server, ::std::net::SocketAddr) { let mut io = MetaIoHandler::default(); io.add_method_with_meta("hello", |_, meta: Metadata| { Ok(Value::String(format!("{}", meta.origin))) diff --git a/crates/rpc/src/v1/extractors.rs b/crates/rpc/src/v1/extractors.rs index 68350c491..166931504 100644 --- a/crates/rpc/src/v1/extractors.rs +++ b/crates/rpc/src/v1/extractors.rs @@ -257,7 +257,7 @@ impl> core::Middleware for WsDispatcher< #[cfg(test)] mod tests { use super::RpcExtractor; - use Origin; + use crate::Origin; use http::{ MetaExtractor, hyper::{Body, Request}, diff --git a/crates/rpc/src/v1/tests/mocked/parity.rs b/crates/rpc/src/v1/tests/mocked/parity.rs index cd26e1f38..45eb9df4f 100644 --- a/crates/rpc/src/v1/tests/mocked/parity.rs +++ b/crates/rpc/src/v1/tests/mocked/parity.rs @@ -35,7 +35,7 @@ use crate::v1::{ metadata::Metadata, tests::helpers::{Config, TestMinerService, TestSyncProvider}, }; -use Host; +use crate::Host; use jsonrpc_core::IoHandler; pub type TestParityClient = ParityClient; diff --git a/crates/util/dir/src/lib.rs b/crates/util/dir/src/lib.rs index 1eb0a6d74..e972321d6 100644 --- a/crates/util/dir/src/lib.rs +++ b/crates/util/dir/src/lib.rs @@ -45,7 +45,7 @@ extern crate journaldb; pub mod helpers; use app_dirs::{AppDataType, AppInfo, data_root, get_app_root}; use ethereum_types::{H64, H256}; -use helpers::{replace_home, replace_home_and_local}; +use crate::helpers::{replace_home, replace_home_and_local}; use journaldb::Algorithm; use std::{ fs, @@ -335,7 +335,7 @@ mod platform { #[cfg(test)] mod tests { use super::Directories; - use helpers::{replace_home, replace_home_and_local}; + use crate::helpers::{replace_home, replace_home_and_local}; #[test] fn test_default_directories() { From 3e5433ddd3e0b043f5804d9b0c2e4cff18bee840 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 May 2025 10:35:08 +0200 Subject: [PATCH 449/687] batch of rust 2025 changes for tests target. --- bin/evmbin/src/display/json.rs | 2 +- bin/evmbin/src/display/std_json.rs | 2 +- bin/evmbin/src/info.rs | 2 +- crates/ethcore/src/engines/authority_round/mod.rs | 2 +- crates/ethcore/src/engines/clique/tests.rs | 3 ++- crates/ethcore/src/externalities.rs | 2 +- crates/ethcore/src/snapshot/tests/proof_of_work.rs | 4 ++-- crates/ethcore/src/tests/client.rs | 4 ++-- crates/ethcore/src/tests/evm.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 2 +- crates/ethcore/sync/src/tests/chain.rs | 4 ++-- crates/ethcore/sync/src/tests/consensus.rs | 2 +- crates/ethcore/sync/src/tests/helpers.rs | 2 +- crates/ethcore/sync/src/tests/snapshot.rs | 4 ++-- 14 files changed, 19 insertions(+), 18 deletions(-) diff --git a/bin/evmbin/src/display/json.rs b/bin/evmbin/src/display/json.rs index c0b68e21f..4a6bd1037 100644 --- a/bin/evmbin/src/display/json.rs +++ b/bin/evmbin/src/display/json.rs @@ -271,7 +271,7 @@ impl trace::VMTracer for Informant { #[cfg(test)] mod tests { use super::*; - use info::tests::run_test; + use crate::info::tests::run_test; use serde_json; #[derive(Serialize, Deserialize, Debug, PartialEq)] diff --git a/bin/evmbin/src/display/std_json.rs b/bin/evmbin/src/display/std_json.rs index 4d46cdee7..1c569695b 100644 --- a/bin/evmbin/src/display/std_json.rs +++ b/bin/evmbin/src/display/std_json.rs @@ -289,7 +289,7 @@ impl trace::VMTracer for Informant { #[cfg(test)] pub mod tests { use super::*; - use info::tests::run_test; + use crate::info::tests::run_test; use std::sync::{Arc, Mutex}; #[derive(Debug, Clone, Default)] diff --git a/bin/evmbin/src/info.rs b/bin/evmbin/src/info.rs index 310097880..4aa3a836a 100644 --- a/bin/evmbin/src/info.rs +++ b/bin/evmbin/src/info.rs @@ -289,7 +289,7 @@ pub mod tests { #[test] fn should_call_account_from_spec() { - use display::{config::Config, std_json::tests::informant}; + use crate::display::{config::Config, std_json::tests::informant}; let (inf, res) = informant(Config::default()); let mut params = ActionParams::default(); diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index 65477a81f..6b03b106a 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -2456,7 +2456,7 @@ mod tests { f(&mut params); // create engine - let mut c_params = ::spec::CommonParams::default(); + let mut c_params = crate::spec::CommonParams::default(); c_params.gas_limit_bound_divisor = 5.into(); let machine = ::machine::EthereumMachine::regular(c_params, Default::default()); AuthorityRound::new(params, machine).unwrap() diff --git a/crates/ethcore/src/engines/clique/tests.rs b/crates/ethcore/src/engines/clique/tests.rs index c07d0c726..75213dbf4 100644 --- a/crates/ethcore/src/engines/clique/tests.rs +++ b/crates/ethcore/src/engines/clique/tests.rs @@ -330,7 +330,8 @@ fn one_signer_dropping_itself() { 'A', ) .unwrap(); - let signers = tester.clique_signers(&vote.hash()); + let hash = vote.hash(); + let signers = tester.clique_signers(&hash); assert!(signers.count() == 0); } diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index a1ba8a1d4..ec49e8448 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -604,7 +604,7 @@ mod tests { impl TestSetup { fn new() -> Self { - let machine = ::spec::Spec::new_test_machine(); + let machine = crate::spec::Spec::new_test_machine(); let env_info = get_test_env_info(); let schedule = machine.schedule(env_info.number); TestSetup { diff --git a/crates/ethcore/src/snapshot/tests/proof_of_work.rs b/crates/ethcore/src/snapshot/tests/proof_of_work.rs index 653b6d12f..786f307b5 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_work.rs @@ -47,7 +47,7 @@ fn chunk_and_restore(amount: u64) { let generator = BlockGenerator::new(vec![rest]); let genesis = genesis.last(); - let engine = ::spec::Spec::new_test().engine; + let engine = crate::spec::Spec::new_test().engine; let tempdir = TempDir::new("").unwrap(); let snapshot_path = tempdir.path().join("SNAP"); @@ -161,7 +161,7 @@ fn checks_flag() { let chunk = stream.out(); let db = test_helpers::new_db(); - let engine = ::spec::Spec::new_test().engine; + let engine = crate::spec::Spec::new_test().engine; let chain = BlockChain::new( Default::default(), genesis.last().encoded().raw(), diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index 3169773e2..dcaa3b8f3 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -479,8 +479,8 @@ fn transaction_proof() { .1; let backend = state::backend::ProofCheck::new(&proof); - let mut factories = ::factory::Factories::default(); - factories.accountdb = ::account_db::Factory::Plain; // raw state values, no mangled keys. + let mut factories = crate::factory::Factories::default(); + factories.accountdb = crate::account_db::Factory::Plain; // raw state values, no mangled keys. let root = *client.best_block_header().state_root(); let machine = test_spec.engine.machine(); diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index 061dff2f7..024e012aa 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -40,7 +40,7 @@ fn test_blockhash_eip210(factory: Factory) { let test_blockhash_contract = "73fffffffffffffffffffffffffffffffffffffffe33141561007a57600143036020526000356101006020510755600061010060205107141561005057600035610100610100602051050761010001555b6000620100006020510714156100755760003561010062010000602051050761020001555b61014a565b4360003512151561009057600060405260206040f35b610100600035430312156100b357610100600035075460605260206060f3610149565b62010000600035430312156100d157600061010060003507146100d4565b60005b156100f6576101006101006000350507610100015460805260206080f3610148565b630100000060003543031215610116576000620100006000350714610119565b60005b1561013c57610100620100006000350507610200015460a052602060a0f3610147565b600060c052602060c0f35b5b5b5b5b"; let blockhash_contract_code = Arc::new(test_blockhash_contract.from_hex().unwrap()); let blockhash_contract_code_hash = keccak(blockhash_contract_code.as_ref()); - let machine = ::ethereum::new_eip210_test_machine(); + let machine = crate::ethereum::new_eip210_test_machine(); let mut env_info = EnvInfo::default(); // populate state with 256 last hashes diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index b4162e06e..8b87bf215 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1869,7 +1869,7 @@ pub mod tests { tests::{helpers::TestIo, snapshot::TestSnapshotService}, types::header::Header, }; - use SyncConfig; + use crate::SyncConfig; use bytes::Bytes; use ethcore::{ client::{BlockChainClient, BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient}, diff --git a/crates/ethcore/sync/src/tests/chain.rs b/crates/ethcore/sync/src/tests/chain.rs index c08c8ade3..f3d451ffa 100644 --- a/crates/ethcore/sync/src/tests/chain.rs +++ b/crates/ethcore/sync/src/tests/chain.rs @@ -16,8 +16,8 @@ use super::helpers::*; use crate::chain::SyncState; -use SyncConfig; -use WarpSync; +use crate::SyncConfig; +use crate::WarpSync; use ethcore::client::{ BlockChainClient, BlockId, BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient, }; diff --git a/crates/ethcore/sync/src/tests/consensus.rs b/crates/ethcore/sync/src/tests/consensus.rs index 704b42da7..0171cc69a 100644 --- a/crates/ethcore/sync/src/tests/consensus.rs +++ b/crates/ethcore/sync/src/tests/consensus.rs @@ -19,7 +19,7 @@ use crate::{ io::{IoChannel, IoHandler}, types::transaction::{Action, PendingTransaction, Transaction, TypedTransaction}, }; -use SyncConfig; +use crate::SyncConfig; use crypto::publickey::{KeyPair, Secret}; use ethcore::{ client::{ChainInfo, ClientIoMessage}, diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index a50a69335..6812046fd 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -48,7 +48,7 @@ use std::{ }; use crate::types::BlockNumber; -use SyncConfig; +use crate::SyncConfig; pub trait FlushingBlockChainClient: BlockChainClient { fn flush(&self) {} diff --git a/crates/ethcore/sync/src/tests/snapshot.rs b/crates/ethcore/sync/src/tests/snapshot.rs index d19ce7220..ee760d212 100644 --- a/crates/ethcore/sync/src/tests/snapshot.rs +++ b/crates/ethcore/sync/src/tests/snapshot.rs @@ -16,8 +16,8 @@ use super::helpers::*; use crate::types::BlockNumber; -use SyncConfig; -use WarpSync; +use crate::SyncConfig; +use crate::WarpSync; use bytes::Bytes; use ethcore::{ client::EachBlockWith, From aedd4760a01359ac590b2e6790f6c528eb0dd339 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 May 2025 10:53:34 +0200 Subject: [PATCH 450/687] fixed all code for "cargo check --locked --all --benches --verbose" --- crates/ethcore/src/client/client.rs | 2 +- crates/ethcore/src/engines/authority_round/mod.rs | 2 +- crates/ethcore/src/engines/validator_set/multi.rs | 10 +++++----- crates/ethcore/src/executive.rs | 14 +++++++------- crates/ethcore/src/externalities.rs | 2 +- crates/ethcore/src/machine/impls.rs | 2 +- crates/ethcore/src/snapshot/tests/proof_of_work.rs | 6 +++--- crates/ethcore/src/snapshot/tests/service.rs | 8 ++++---- crates/ethcore/src/snapshot/tests/state.rs | 4 ++-- crates/ethcore/src/state/mod.rs | 2 +- crates/ethcore/src/verification/verification.rs | 2 +- crates/rpc/src/v1/tests/mocked/parity.rs | 2 +- 12 files changed, 28 insertions(+), 28 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index cf3fd2efb..2ce86d2f5 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -3880,7 +3880,7 @@ mod tests { // given let key = KeyPair::from_secret_slice(keccak("test").as_bytes()).unwrap(); let secret = key.secret(); - let machine = ::ethereum::new_frontier_test_machine(); + let machine = crate::ethereum::new_frontier_test_machine(); let block_number = 1; let block_hash = H256::from_low_u64_be(5); diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index 6b03b106a..997fbe405 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -2458,7 +2458,7 @@ mod tests { // create engine let mut c_params = crate::spec::CommonParams::default(); c_params.gas_limit_bound_divisor = 5.into(); - let machine = ::machine::EthereumMachine::regular(c_params, Default::default()); + let machine = crate::machine::EthereumMachine::regular(c_params, Default::default()); AuthorityRound::new(params, machine).unwrap() } diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index 1314f5fb4..f49efeb0b 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -253,12 +253,12 @@ mod tests { Default::default(), )) .unwrap(); - ::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); + crate::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); assert_eq!(client.chain_info().best_block_number, 0); // Right signer for the first block. let signer = Box::new((tap.clone(), v0, "".into())); client.miner().set_author(miner::Author::Sealer(signer)); - ::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); + crate::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); assert_eq!(client.chain_info().best_block_number, 1); // This time v0 is wrong. client @@ -267,11 +267,11 @@ mod tests { Default::default(), )) .unwrap(); - ::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); + crate::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); assert_eq!(client.chain_info().best_block_number, 1); let signer = Box::new((tap.clone(), v1, "".into())); client.miner().set_author(miner::Author::Sealer(signer)); - ::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); + crate::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); assert_eq!(client.chain_info().best_block_number, 2); // v1 is still good. client @@ -280,7 +280,7 @@ mod tests { Default::default(), )) .unwrap(); - ::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); + crate::client::EngineClient::update_sealing(&*client, ForceUpdateSealing::No); assert_eq!(client.chain_info().best_block_number, 3); // Check syncing. diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index 218fee702..f09b71339 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -1682,19 +1682,19 @@ mod tests { use vm::{ActionParams, ActionValue, CallType, CreateContractAddress, EnvInfo}; fn make_frontier_machine(max_depth: usize) -> EthereumMachine { - let mut machine = ::ethereum::new_frontier_test_machine(); + let mut machine = crate::ethereum::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } fn make_byzantium_machine(max_depth: usize) -> EthereumMachine { - let mut machine = ::ethereum::new_byzantium_test_machine(); + let mut machine = crate::ethereum::new_byzantium_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } fn make_london_machine(max_depth: usize) -> EthereumMachine { - let mut machine = ::ethereum::new_london_test_machine(); + let mut machine = crate::ethereum::new_london_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } @@ -2088,7 +2088,7 @@ mod tests { .add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty) .unwrap(); let info = EnvInfo::default(); - let machine = ::ethereum::new_byzantium_test_machine(); + let machine = crate::ethereum::new_byzantium_test_machine(); let schedule = machine.schedule(info.number); let mut substate = Substate::new(); let mut tracer = ExecutiveTracer::default(); @@ -2988,7 +2988,7 @@ mod tests { params.code = Some(Arc::new(code)); params.value = ActionValue::Transfer(U256::zero()); let info = EnvInfo::default(); - let machine = ::ethereum::new_byzantium_test_machine(); + let machine = crate::ethereum::new_byzantium_test_machine(); let schedule = machine.schedule(info.number); let mut substate = Substate::new(); @@ -3050,7 +3050,7 @@ mod tests { .unwrap(); let info = EnvInfo::default(); - let machine = ::ethereum::new_constantinople_test_machine(); + let machine = crate::ethereum::new_constantinople_test_machine(); let schedule = machine.schedule(info.number); assert_eq!( @@ -3141,7 +3141,7 @@ mod tests { info.number = 100; // Network with wasm activated at block 10 - let machine = ::ethereum::new_kovan_wasm_test_machine(); + let machine = crate::ethereum::new_kovan_wasm_test_machine(); let mut output = [0u8; 20]; let FinalizationResult { diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index ec49e8448..10f57fd46 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -590,7 +590,7 @@ mod tests { struct TestSetup { state: State, - machine: ::machine::EthereumMachine, + machine: crate::machine::EthereumMachine, schedule: Schedule, sub_state: Substate, env_info: EnvInfo, diff --git a/crates/ethcore/src/machine/impls.rs b/crates/ethcore/src/machine/impls.rs index cd3761ec5..50329c87a 100644 --- a/crates/ethcore/src/machine/impls.rs +++ b/crates/ethcore/src/machine/impls.rs @@ -600,7 +600,7 @@ mod tests { let rlp = "ea80843b9aca0083015f90948921ebb5f79e9e3920abe571004d0b1d5119c154865af3107a400080038080"; let transaction: UnverifiedTransaction = TypedTransaction::decode(&::rustc_hex::FromHex::from_hex(rlp).unwrap()).unwrap(); - let spec = ::ethereum::new_ropsten_test(); + let spec = crate::ethereum::new_ropsten_test(); let ethparams = get_default_ethash_extensions(); let machine = EthereumMachine::with_ethash_extensions( diff --git a/crates/ethcore/src/snapshot/tests/proof_of_work.rs b/crates/ethcore/src/snapshot/tests/proof_of_work.rs index 786f307b5..bf06e27ab 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_work.rs @@ -36,7 +36,7 @@ use parking_lot::Mutex; use snappy; use crate::test_helpers; -const SNAPSHOT_MODE: ::snapshot::PowSnapshot = ::snapshot::PowSnapshot { +const SNAPSHOT_MODE: crate::snapshot::PowSnapshot = crate::snapshot::PowSnapshot { blocks: 30000, max_restore_blocks: 30000, }; @@ -89,7 +89,7 @@ fn chunk_and_restore(amount: u64) { ) .unwrap(); - let manifest = ::snapshot::ManifestData { + let manifest = crate::snapshot::ManifestData { version: 2, state_hashes: Vec::new(), block_hashes: block_hashes, @@ -169,7 +169,7 @@ fn checks_flag() { engine.params().eip1559_transition, ); - let manifest = ::snapshot::ManifestData { + let manifest = crate::snapshot::ManifestData { version: 2, state_hashes: Vec::new(), block_hashes: Vec::new(), diff --git a/crates/ethcore/src/snapshot/tests/service.rs b/crates/ethcore/src/snapshot/tests/service.rs index e086291d6..360ffc68f 100644 --- a/crates/ethcore/src/snapshot/tests/service.rs +++ b/crates/ethcore/src/snapshot/tests/service.rs @@ -69,7 +69,7 @@ fn restored_is_equivalent() { Default::default(), &spec, blockchain_db, - Arc::new(::miner::Miner::new_for_tests(&spec, None)), + Arc::new(crate::miner::Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), ShutdownManager::null(), ) @@ -173,7 +173,7 @@ fn keep_ancient_blocks() { // Test variables const NUM_BLOCKS: u64 = 500; const NUM_SNAPSHOT_BLOCKS: u64 = 300; - const SNAPSHOT_MODE: ::snapshot::PowSnapshot = ::snapshot::PowSnapshot { + const SNAPSHOT_MODE: crate::snapshot::PowSnapshot = crate::snapshot::PowSnapshot { blocks: NUM_SNAPSHOT_BLOCKS, max_restore_blocks: NUM_SNAPSHOT_BLOCKS, }; @@ -233,7 +233,7 @@ fn keep_ancient_blocks() { ClientConfig::default(), &spec, client_db, - Arc::new(::miner::Miner::new_for_tests(&spec, None)), + Arc::new(crate::miner::Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), ShutdownManager::null(), ) @@ -322,7 +322,7 @@ fn recover_aborted_recovery() { Default::default(), &spec, client_db, - Arc::new(::miner::Miner::new_for_tests(&spec, None)), + Arc::new(crate::miner::Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), ShutdownManager::null(), ) diff --git a/crates/ethcore/src/snapshot/tests/state.rs b/crates/ethcore/src/snapshot/tests/state.rs index 0d10723ca..57fe40f76 100644 --- a/crates/ethcore/src/snapshot/tests/state.rs +++ b/crates/ethcore/src/snapshot/tests/state.rs @@ -76,7 +76,7 @@ fn snap_and_restore() { writer .into_inner() - .finish(::snapshot::ManifestData { + .finish(crate::snapshot::ManifestData { version: 2, state_hashes: state_hashes, block_hashes: Vec::new(), @@ -215,7 +215,7 @@ fn checks_flag() { writer .into_inner() - .finish(::snapshot::ManifestData { + .finish(crate::snapshot::ManifestData { version: 2, state_hashes, block_hashes: Vec::new(), diff --git a/crates/ethcore/src/state/mod.rs b/crates/ethcore/src/state/mod.rs index ddbbb4942..f54200cf2 100644 --- a/crates/ethcore/src/state/mod.rs +++ b/crates/ethcore/src/state/mod.rs @@ -1596,7 +1596,7 @@ mod tests { } fn make_frontier_machine(max_depth: usize) -> EthereumMachine { - let mut machine = ::ethereum::new_frontier_test_machine(); + let mut machine = crate::ethereum::new_frontier_test_machine(); machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = max_depth)); machine } diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index b256fc050..eef2cb020 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -735,7 +735,7 @@ mod tests { // additions that need access to state (tx filter in specific) // no existing tests need access to test, so having this not function // is fine. - let client = ::client::TestBlockChainClient::default(); + let client = crate::client::TestBlockChainClient::default(); let parent = bc .block_header_data(header.parent_hash()) .ok_or(BlockError::UnknownParent(*header.parent_hash()))? diff --git a/crates/rpc/src/v1/tests/mocked/parity.rs b/crates/rpc/src/v1/tests/mocked/parity.rs index 45eb9df4f..6717c87e6 100644 --- a/crates/rpc/src/v1/tests/mocked/parity.rs +++ b/crates/rpc/src/v1/tests/mocked/parity.rs @@ -464,7 +464,7 @@ fn rpc_parity_local_transactions() { nonce: 0.into(), }) .fake_sign(Address::from_low_u64_be(3)); - let tx = Arc::new(::miner::pool::VerifiedTransaction::from_pending_block_transaction(tx)); + let tx = Arc::new(crate::miner::pool::VerifiedTransaction::from_pending_block_transaction(tx)); deps.miner.local_transactions.lock().insert( H256::from_low_u64_be(10), LocalTransactionStatus::Pending(tx.clone()), From f2d1a3d23615d0d7c6a60d99ebd6af547c78fa67 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 May 2025 11:15:19 +0200 Subject: [PATCH 451/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/block.rs | 4 ++-- crates/ethcore/src/client/client.rs | 14 +++++++++----- crates/ethcore/src/engines/block_reward.rs | 5 +++-- crates/ethcore/src/engines/clique/tests.rs | 12 ++++++++---- .../src/engines/hbbft/test/hbbft_test_client.rs | 2 +- crates/ethcore/src/engines/instant_seal.rs | 5 +++-- .../ethcore/src/engines/validator_set/contract.rs | 2 +- crates/ethcore/src/engines/validator_set/multi.rs | 2 +- .../src/engines/validator_set/safe_contract.rs | 2 +- crates/ethcore/src/engines/validator_set/test.rs | 6 ++++-- crates/ethcore/src/ethereum/ethash.rs | 11 ++++++++--- crates/ethcore/src/ethereum/mod.rs | 2 +- crates/ethcore/src/executive.rs | 4 ++-- crates/ethcore/src/externalities.rs | 2 +- crates/ethcore/src/miner/miner.rs | 7 ++++--- crates/ethcore/src/snapshot/account.rs | 2 +- crates/ethcore/src/snapshot/service.rs | 2 +- .../src/snapshot/tests/proof_of_authority.rs | 4 ++-- crates/ethcore/src/snapshot/tests/proof_of_work.rs | 2 +- crates/ethcore/src/snapshot/tests/service.rs | 6 +++--- crates/ethcore/src/spec/spec.rs | 2 +- crates/ethcore/src/state/mod.rs | 2 +- crates/ethcore/src/state_db.rs | 6 ++++-- crates/ethcore/src/tests/client.rs | 12 ++++++------ crates/ethcore/src/tests/evm.rs | 2 +- crates/ethcore/src/tests/trace.rs | 2 +- crates/ethcore/src/trace/db.rs | 2 +- crates/ethcore/src/tx_filter.rs | 2 +- crates/ethcore/src/verification/queue/mod.rs | 4 ++-- crates/ethcore/src/verification/verification.rs | 4 ++-- crates/ethcore/sync/src/chain/fork_filter.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 2 +- crates/ethcore/sync/src/tests/chain.rs | 4 +--- crates/ethcore/sync/src/tests/consensus.rs | 2 +- crates/ethcore/sync/src/tests/helpers.rs | 3 +-- crates/ethcore/sync/src/tests/snapshot.rs | 4 +--- crates/net/network/src/lib.rs | 6 ++++-- crates/rpc/src/tests/rpc.rs | 2 +- crates/rpc/src/v1/tests/mocked/parity.rs | 14 ++++++++------ crates/util/dir/src/lib.rs | 2 +- crates/vm/vm/src/lib.rs | 4 +++- 41 files changed, 100 insertions(+), 79 deletions(-) diff --git a/crates/ethcore/src/block.rs b/crates/ethcore/src/block.rs index f86493700..e20819b9a 100644 --- a/crates/ethcore/src/block.rs +++ b/crates/ethcore/src/block.rs @@ -631,15 +631,15 @@ mod tests { use super::*; use crate::{ engines::EthEngine, + error::Error, factory::Factories, state_db::StateDB, + test_helpers::get_temp_state_db, types::{header::Header, transaction::SignedTransaction, view, views::BlockView}, verification::queue::kind::blocks::Unverified, }; - use crate::error::Error; use ethereum_types::Address; use std::sync::Arc; - use crate::test_helpers::get_temp_state_db; use vm::LastHashes; /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 2ce86d2f5..f820c37bf 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -3788,14 +3788,16 @@ mod tests { use crate::{ blockchain::{BlockProvider, ExtrasInsert}, spec::Spec, + test_helpers::generate_dummy_client_with_spec_and_data, }; use ethereum_types::{H160, H256}; - use crate::test_helpers::generate_dummy_client_with_spec_and_data; #[test] fn should_not_cache_details_before_commit() { - use crate::client::{BlockChainClient, ChainInfo}; - use crate::test_helpers::{generate_dummy_client, get_good_dummy_block_hash}; + use crate::{ + client::{BlockChainClient, ChainInfo}, + test_helpers::{generate_dummy_client, get_good_dummy_block_hash}, + }; use crate::types::encoded; use kvdb::DBTransaction; @@ -3842,8 +3844,10 @@ mod tests { #[test] fn should_return_block_receipts() { - use crate::client::{BlockChainClient, BlockId, TransactionId}; - use crate::test_helpers::generate_dummy_client_with_data; + use crate::{ + client::{BlockChainClient, BlockId, TransactionId}, + test_helpers::generate_dummy_client_with_data, + }; let client = generate_dummy_client_with_data(2, 2, &[1.into(), 1.into()]); let receipts = client.localized_block_receipts(BlockId::Latest).unwrap(); diff --git a/crates/ethcore/src/engines/block_reward.rs b/crates/ethcore/src/engines/block_reward.rs index c96f8a2f4..241780279 100644 --- a/crates/ethcore/src/engines/block_reward.rs +++ b/crates/ethcore/src/engines/block_reward.rs @@ -197,9 +197,10 @@ pub fn apply_block_rewards( #[cfg(test)] mod test { - use crate::{client::PrepareOpenBlock, spec::Spec}; + use crate::{ + client::PrepareOpenBlock, spec::Spec, test_helpers::generate_dummy_client_with_spec, + }; use ethereum_types::{H160, U256}; - use crate::test_helpers::generate_dummy_client_with_spec; use super::{BlockRewardContract, RewardKind}; use crate::engines::SystemOrCodeCallKind; diff --git a/crates/ethcore/src/engines/clique/tests.rs b/crates/ethcore/src/engines/clique/tests.rs index 75213dbf4..1ecd8f176 100644 --- a/crates/ethcore/src/engines/clique/tests.rs +++ b/crates/ethcore/src/engines/clique/tests.rs @@ -17,11 +17,15 @@ //! Consensus tests for `PoA Clique Engine`, see http://eips.ethereum.org/EIPS/eip-225 for more information use super::*; -use crate::{block::*, engines::Engine, state_db::StateDB}; +use crate::{ + block::*, + engines::Engine, + error::{Error, ErrorKind}, + state_db::StateDB, + test_helpers::get_temp_state_db, +}; use crypto::publickey::{KeyPair, Secret}; -use crate::error::{Error, ErrorKind}; use ethereum_types::{Address, H256}; -use crate::test_helpers::get_temp_state_db; use std::{collections::HashMap, sync::Arc}; @@ -330,7 +334,7 @@ fn one_signer_dropping_itself() { 'A', ) .unwrap(); - let hash = vote.hash(); + let hash = vote.hash(); let signers = tester.clique_signers(&hash); assert!(signers.count() == 0); } diff --git a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs index b0d7c2e92..aef36d06c 100644 --- a/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs +++ b/crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs @@ -7,13 +7,13 @@ use crate::{ engines::signer::from_keypair, miner::{Miner, MinerService}, spec::Spec, + test_helpers::{TestNotify, generate_dummy_client_with_spec}, types::{data_format::DataFormat, ids::BlockId}, }; use crypto::publickey::{Generator, KeyPair, Random}; use ethereum_types::{Address, U256}; use parking_lot::RwLock; use std::{ops::Deref, sync::Arc}; -use crate::test_helpers::{TestNotify, generate_dummy_client_with_spec}; pub fn hbbft_spec() -> Spec { Spec::load( diff --git a/crates/ethcore/src/engines/instant_seal.rs b/crates/ethcore/src/engines/instant_seal.rs index 6ac747831..80213ad14 100644 --- a/crates/ethcore/src/engines/instant_seal.rs +++ b/crates/ethcore/src/engines/instant_seal.rs @@ -128,10 +128,11 @@ impl Engine for InstantSeal { #[cfg(test)] mod tests { - use crate::{block::*, engines::Seal, spec::Spec, types::header::Header}; + use crate::{ + block::*, engines::Seal, spec::Spec, test_helpers::get_temp_state_db, types::header::Header, + }; use ethereum_types::{Address, H520}; use std::sync::Arc; - use crate::test_helpers::get_temp_state_db; #[test] fn instant_can_seal() { diff --git a/crates/ethcore/src/engines/validator_set/contract.rs b/crates/ethcore/src/engines/validator_set/contract.rs index 6d5f430f0..5fadc8320 100644 --- a/crates/ethcore/src/engines/validator_set/contract.rs +++ b/crates/ethcore/src/engines/validator_set/contract.rs @@ -222,6 +222,7 @@ mod tests { client::{BlockChainClient, BlockInfo, ChainInfo, traits::TransactionRequest}, miner::{self, MinerService}, spec::Spec, + test_helpers::generate_dummy_client_with_spec, types::{header::Header, ids::BlockId}, }; use accounts::AccountProvider; @@ -233,7 +234,6 @@ mod tests { use rlp::encode; use rustc_hex::FromHex; use std::sync::Arc; - use crate::test_helpers::generate_dummy_client_with_spec; #[test] fn fetches_validators() { diff --git a/crates/ethcore/src/engines/validator_set/multi.rs b/crates/ethcore/src/engines/validator_set/multi.rs index f49efeb0b..2a643af48 100644 --- a/crates/ethcore/src/engines/validator_set/multi.rs +++ b/crates/ethcore/src/engines/validator_set/multi.rs @@ -216,6 +216,7 @@ mod tests { engines::{EpochChange, validator_set::ValidatorSet}, miner::{self, MinerService}, spec::Spec, + test_helpers::generate_dummy_client_with_spec, types::{header::Header, ids::BlockId}, verification::queue::kind::blocks::Unverified, }; @@ -224,7 +225,6 @@ mod tests { use ethereum_types::Address; use hash::keccak; use std::{collections::BTreeMap, sync::Arc}; - use crate::test_helpers::generate_dummy_client_with_spec; use super::Multi; diff --git a/crates/ethcore/src/engines/validator_set/safe_contract.rs b/crates/ethcore/src/engines/validator_set/safe_contract.rs index 411f71af9..1d97cd2b1 100644 --- a/crates/ethcore/src/engines/validator_set/safe_contract.rs +++ b/crates/ethcore/src/engines/validator_set/safe_contract.rs @@ -727,6 +727,7 @@ mod tests { }, miner::{self, MinerService}, spec::Spec, + test_helpers::generate_dummy_client_with_spec, types::{ ids::BlockId, transaction::{Action, Transaction, TypedTransaction}, @@ -739,7 +740,6 @@ mod tests { use hash::keccak; use rustc_hex::FromHex; use std::sync::Arc; - use crate::test_helpers::generate_dummy_client_with_spec; #[test] fn fetches_validators() { diff --git a/crates/ethcore/src/engines/validator_set/test.rs b/crates/ethcore/src/engines/validator_set/test.rs index 585817a0d..748345ab9 100644 --- a/crates/ethcore/src/engines/validator_set/test.rs +++ b/crates/ethcore/src/engines/validator_set/test.rs @@ -27,8 +27,10 @@ use ethereum_types::{Address, H256}; use parity_util_mem::MallocSizeOf; use super::{SimpleList, SystemCall, ValidatorSet}; -use crate::machine::{AuxiliaryData, Call, EthereumMachine}; -use crate::error::Error as EthcoreError; +use crate::{ + error::Error as EthcoreError, + machine::{AuxiliaryData, Call, EthereumMachine}, +}; /// Set used for testing with a single validator. #[derive(Clone, MallocSizeOf)] diff --git a/crates/ethcore/src/ethereum/ethash.rs b/crates/ethcore/src/ethereum/ethash.rs index 6bfb26497..ee185c452 100644 --- a/crates/ethcore/src/ethereum/ethash.rs +++ b/crates/ethcore/src/ethereum/ethash.rs @@ -564,13 +564,18 @@ mod tests { super::{new_homestead_test_machine, new_mcip3_test, new_morden}, Ethash, EthashParams, ecip1017_eras_block_reward, }; - use crate::{block::*, engines::Engine, spec::Spec, types::header::Header}; - use crate::error::{BlockError, Error, ErrorKind}; + use crate::{ + block::*, + engines::Engine, + error::{BlockError, Error, ErrorKind}, + spec::Spec, + test_helpers::get_temp_state_db, + types::header::Header, + }; use ethereum_types::{Address, H64, H256, U256}; use rlp; use std::{collections::BTreeMap, str::FromStr, sync::Arc}; use tempdir::TempDir; - use crate::test_helpers::get_temp_state_db; fn test_spec() -> Spec { let tempdir = TempDir::new("").unwrap(); diff --git a/crates/ethcore/src/ethereum/mod.rs b/crates/ethcore/src/ethereum/mod.rs index 45b1837dc..cfebc56fb 100644 --- a/crates/ethcore/src/ethereum/mod.rs +++ b/crates/ethcore/src/ethereum/mod.rs @@ -371,11 +371,11 @@ mod tests { use super::*; use crate::{ state::*, + test_helpers::get_temp_state_db, types::{view, views::BlockView}, }; use ethereum_types::{H160, H256, U256}; use std::str::FromStr; - use crate::test_helpers::get_temp_state_db; #[test] fn ensure_db_good() { diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index f09b71339..163b53cd0 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -1662,8 +1662,10 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { mod tests { use super::*; use crate::{ + error::ExecutionError, machine::EthereumMachine, state::{CleanupMode, Substate}, + test_helpers::{get_temp_state, get_temp_state_with_factory}, trace::{ ExecutiveTracer, ExecutiveVMTracer, FlatTrace, MemoryDiff, NoopTracer, NoopVMTracer, StorageDiff, Tracer, VMExecutedOperation, VMOperation, VMTrace, VMTracer, trace, @@ -1673,12 +1675,10 @@ mod tests { }, }; use crypto::publickey::{Generator, Random}; - use crate::error::ExecutionError; use ethereum_types::{Address, BigEndianHash, H160, H256, U256, U512}; use evm::{Factory, VMType}; use rustc_hex::FromHex; use std::{str::FromStr, sync::Arc}; - use crate::test_helpers::{get_temp_state, get_temp_state_with_factory}; use vm::{ActionParams, ActionValue, CallType, CreateContractAddress, EnvInfo}; fn make_frontier_machine(max_depth: usize) -> EthereumMachine { diff --git a/crates/ethcore/src/externalities.rs b/crates/ethcore/src/externalities.rs index 10f57fd46..1a4e3e81c 100644 --- a/crates/ethcore/src/externalities.rs +++ b/crates/ethcore/src/externalities.rs @@ -559,12 +559,12 @@ mod tests { use super::*; use crate::{ state::{State, Substate}, + test_helpers::get_temp_state, trace::{NoopTracer, NoopVMTracer}, }; use ethereum_types::{Address, U256}; use evm::{CallType, EnvInfo, Ext}; use std::str::FromStr; - use crate::test_helpers::get_temp_state; fn get_test_origin() -> OriginInfo { OriginInfo { diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 484890126..77e3e4624 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -1839,11 +1839,12 @@ mod tests { use crate::{ client::{ChainInfo, EachBlockWith, ImportSealedBlock, TestBlockChainClient}, miner::{MinerService, PendingOrdering}, + test_helpers::{ + dummy_engine_signer_with_address, generate_dummy_client, + generate_dummy_client_with_spec, + }, types::transaction::{Transaction, TypedTransaction}, }; - use crate::test_helpers::{ - dummy_engine_signer_with_address, generate_dummy_client, generate_dummy_client_with_spec, - }; #[test] fn should_prepare_block_to_seal() { diff --git a/crates/ethcore/src/snapshot/account.rs b/crates/ethcore/src/snapshot/account.rs index f4f169edf..680afebbf 100644 --- a/crates/ethcore/src/snapshot/account.rs +++ b/crates/ethcore/src/snapshot/account.rs @@ -226,9 +226,9 @@ mod tests { use crate::{ account_db::{AccountDB, AccountDBMut}, snapshot::{Progress, tests::helpers::fill_storage}, + test_helpers::get_temp_state_db, types::basic_account::BasicAccount, }; - use crate::test_helpers::get_temp_state_db; use ethereum_types::{Address, H256}; use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak}; diff --git a/crates/ethcore/src/snapshot/service.rs b/crates/ethcore/src/snapshot/service.rs index d710320e2..144190913 100644 --- a/crates/ethcore/src/snapshot/service.rs +++ b/crates/ethcore/src/snapshot/service.rs @@ -1020,10 +1020,10 @@ mod tests { io::IoService, snapshot::{ManifestData, RestorationStatus, SnapshotService}, spec::Spec, + test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler}, }; use journaldb::Algorithm; use tempdir::TempDir; - use crate::test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler}; #[test] fn sends_async_messages() { diff --git a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs index 41de9cbf8..68061e10c 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -22,15 +22,15 @@ use crate::{ client::{BlockChainClient, ChainInfo, Client}, snapshot::tests::helpers as snapshot_helpers, spec::Spec, + test_helpers::generate_dummy_client_with_spec, types::transaction::{Action, SignedTransaction, Transaction, TypedTransaction}, }; use accounts::AccountProvider; use crypto::publickey::Secret; use tempdir::TempDir; -use crate::test_helpers::generate_dummy_client_with_spec; -use ethereum_types::Address; use crate::test_helpers; +use ethereum_types::Address; use_contract!(test_validator_set, "res/contracts/test_validator_set.json"); diff --git a/crates/ethcore/src/snapshot/tests/proof_of_work.rs b/crates/ethcore/src/snapshot/tests/proof_of_work.rs index bf06e27ab..532b63262 100644 --- a/crates/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/crates/ethcore/src/snapshot/tests/proof_of_work.rs @@ -31,10 +31,10 @@ use crate::{ }, }; +use crate::test_helpers; use kvdb::DBTransaction; use parking_lot::Mutex; use snappy; -use crate::test_helpers; const SNAPSHOT_MODE: crate::snapshot::PowSnapshot = crate::snapshot::PowSnapshot { blocks: 30000, diff --git a/crates/ethcore/src/snapshot/tests/service.rs b/crates/ethcore/src/snapshot/tests/service.rs index 360ffc68f..a412bb037 100644 --- a/crates/ethcore/src/snapshot/tests/service.rs +++ b/crates/ethcore/src/snapshot/tests/service.rs @@ -27,12 +27,12 @@ use crate::{ service::{Service, ServiceParams}, }, spec::Spec, + test_helpers::{ + generate_dummy_client_with_spec_and_data, new_db, new_temp_db, restoration_db_handler, + }, types::ids::BlockId, }; use tempdir::TempDir; -use crate::test_helpers::{ - generate_dummy_client_with_spec_and_data, new_db, new_temp_db, restoration_db_handler, -}; use crate::{io::IoChannel, verification::queue::kind::blocks::Unverified}; use kvdb_rocksdb::DatabaseConfig; diff --git a/crates/ethcore/src/spec/spec.rs b/crates/ethcore/src/spec/spec.rs index 6556f679e..a8b7cdb5d 100644 --- a/crates/ethcore/src/spec/spec.rs +++ b/crates/ethcore/src/spec/spec.rs @@ -1240,12 +1240,12 @@ mod tests { use super::*; use crate::{ state::State, + test_helpers::get_temp_state_db, types::{view, views::BlockView}, }; use ethereum_types::{H160, H256}; use std::str::FromStr; use tempdir::TempDir; - use crate::test_helpers::get_temp_state_db; #[test] fn test_load_empty() { diff --git a/crates/ethcore/src/state/mod.rs b/crates/ethcore/src/state/mod.rs index f54200cf2..9ed08bcd2 100644 --- a/crates/ethcore/src/state/mod.rs +++ b/crates/ethcore/src/state/mod.rs @@ -1579,6 +1579,7 @@ mod tests { use crate::{ machine::EthereumMachine, spec::*, + test_helpers::{get_temp_state, get_temp_state_db}, trace::{FlatTrace, TraceError, trace}, types::transaction::*, }; @@ -1588,7 +1589,6 @@ mod tests { use hash::{KECCAK_NULL_RLP, keccak}; use rustc_hex::FromHex; use std::{str::FromStr, sync::Arc}; - use crate::test_helpers::{get_temp_state, get_temp_state_db}; use vm::EnvInfo; fn secret() -> Secret { diff --git a/crates/ethcore/src/state_db.rs b/crates/ethcore/src/state_db.rs index 545d65eeb..8365fc2c7 100644 --- a/crates/ethcore/src/state_db.rs +++ b/crates/ethcore/src/state_db.rs @@ -442,10 +442,12 @@ unsafe impl Sync for SyncAccount {} #[cfg(test)] mod tests { - use crate::state::{Account, Backend}; + use crate::{ + state::{Account, Backend}, + test_helpers::get_temp_state_db, + }; use ethereum_types::{Address, H256, U256}; use kvdb::DBTransaction; - use crate::test_helpers::get_temp_state_db; #[test] fn state_db_smoke() { diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index dcaa3b8f3..9c80ccf5f 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -27,11 +27,17 @@ use crate::{ ImportExportBlocks, }, }, + ethereum, executive::{Executive, TransactOptions}, io::IoChannel, miner::{Miner, MinerService, PendingOrdering}, spec::Spec, state::{self, CleanupMode, State, StateInfo}, + test_helpers::{ + self, generate_dummy_client, generate_dummy_client_with_data, get_bad_state_dummy_block, + get_good_dummy_block, get_good_dummy_block_seq, get_test_client_with_blocks, + push_blocks_to_client, + }, types::{ data_format::DataFormat, filter::Filter, @@ -43,16 +49,10 @@ use crate::{ verification::queue::kind::blocks::Unverified, }; use crypto::publickey::KeyPair; -use crate::ethereum; use ethereum_types::{Address, U256}; use hash::keccak; use rustc_hex::ToHex; use tempdir::TempDir; -use crate::test_helpers::{ - self, generate_dummy_client, generate_dummy_client_with_data, get_bad_state_dummy_block, - get_good_dummy_block, get_good_dummy_block_seq, get_test_client_with_blocks, - push_blocks_to_client, -}; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index 024e012aa..936f27f04 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -19,13 +19,13 @@ use crate::{ executive::Executive, state::Substate, + test_helpers::get_temp_state_with_factory, trace::{NoopTracer, NoopVMTracer}, types::transaction::SYSTEM_ADDRESS, }; use evm::{Factory, VMType}; use hash::keccak; use std::sync::Arc; -use crate::test_helpers::get_temp_state_with_factory; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; use rustc_hex::FromHex; diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index 3c6f665a7..36ca5a39d 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -22,6 +22,7 @@ use crate::{ io::*, miner::Miner, spec::*, + test_helpers::{self, get_temp_state_db}, trace::{LocalizedTrace, RewardType, trace::Action::Reward}, types::{ header::Header, @@ -35,7 +36,6 @@ use crypto::publickey::KeyPair; use ethereum_types::{Address, U256}; use hash::keccak; use std::{str::FromStr, sync::Arc}; -use crate::test_helpers::{self, get_temp_state_db}; use crate::exit::ShutdownManager; diff --git a/crates/ethcore/src/trace/db.rs b/crates/ethcore/src/trace/db.rs index 97ea51908..af14692c3 100644 --- a/crates/ethcore/src/trace/db.rs +++ b/crates/ethcore/src/trace/db.rs @@ -406,6 +406,7 @@ where #[cfg(test)] mod tests { use crate::{ + test_helpers::new_db, trace::{ AddressesFilter, Config, Database as TraceDatabase, DatabaseExtras, Filter, ImportRequest, LocalizedTrace, TraceDB, TraceError, @@ -418,7 +419,6 @@ mod tests { use evm::CallType; use kvdb::DBTransaction; use std::{collections::HashMap, sync::Arc}; - use crate::test_helpers::new_db; struct NoopExtras; diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index a4d3aa8b4..3684ed68a 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -287,6 +287,7 @@ mod test { io::IoChannel, miner::Miner, spec::Spec, + test_helpers, types::transaction::{ AccessListTx, Action, EIP1559TransactionTx, Transaction, TypedTransaction, }, @@ -295,7 +296,6 @@ mod test { use ethereum_types::{Address, U256}; use std::{str::FromStr, sync::Arc}; use tempdir::TempDir; - use crate::test_helpers; /// Contract code: https://gist.github.com/VladLupashevskyi/84f18eabb1e4afadf572cf92af3e7e7f #[test] diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index ac8520a7c..a3271aa4f 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -874,13 +874,13 @@ impl Drop for VerificationQueue { mod tests { use super::{BlockQueue, Config, State, kind::blocks::Unverified}; use crate::{ + error::*, io::*, spec::Spec, + test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}, types::{BlockNumber, view, views::BlockView}, }; use bytes::Bytes; - use crate::error::*; - use crate::test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; // create a test block queue. // auto_scaling enables verifier adjustment. diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index eef2cb020..f1fa29957 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -545,7 +545,9 @@ mod tests { use crate::{ blockchain::{BlockDetails, BlockReceipts, TransactionAddress}, engines::EthEngine, + error::{BlockError::*, ErrorKind}, spec::{CommonParams, Spec}, + test_helpers::{create_test_block, create_test_block_with_data}, types::{ encoded, log_entry::{LocalizedLogEntry, LogEntry}, @@ -553,7 +555,6 @@ mod tests { }, }; use crypto::publickey::{Generator, Random}; - use crate::error::{BlockError::*, ErrorKind}; use ethereum_types::{Address, BloomRef, H256, U256}; use hash::keccak; use rlp; @@ -561,7 +562,6 @@ mod tests { collections::{BTreeMap, HashMap}, time::{SystemTime, UNIX_EPOCH}, }; - use crate::test_helpers::{create_test_block, create_test_block_with_data}; use triehash::ordered_trie_root; fn check_ok(result: Result<(), Error>) { diff --git a/crates/ethcore/sync/src/chain/fork_filter.rs b/crates/ethcore/sync/src/chain/fork_filter.rs index 94939d8f2..4f5de69f6 100644 --- a/crates/ethcore/sync/src/chain/fork_filter.rs +++ b/crates/ethcore/sync/src/chain/fork_filter.rs @@ -4,8 +4,8 @@ // Re-export ethereum-forkid crate contents here. pub use crate::ethereum_forkid::{BlockNumber, ForkId, RejectReason}; -use ethcore::client::ChainInfo; use crate::ethereum_forkid::ForkFilter; +use ethcore::client::ChainInfo; /// Wrapper around fork filter that provides integration with `ForkFilter`. pub struct ForkFilterApi { diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 8b87bf215..b5cc48ed4 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1866,10 +1866,10 @@ impl PrometheusMetrics for ChainSync { pub mod tests { use super::{PeerAsking, PeerInfo, *}; use crate::{ + SyncConfig, tests::{helpers::TestIo, snapshot::TestSnapshotService}, types::header::Header, }; - use crate::SyncConfig; use bytes::Bytes; use ethcore::{ client::{BlockChainClient, BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient}, diff --git a/crates/ethcore/sync/src/tests/chain.rs b/crates/ethcore/sync/src/tests/chain.rs index f3d451ffa..1cf318567 100644 --- a/crates/ethcore/sync/src/tests/chain.rs +++ b/crates/ethcore/sync/src/tests/chain.rs @@ -15,9 +15,7 @@ // along with OpenEthereum. If not, see . use super::helpers::*; -use crate::chain::SyncState; -use crate::SyncConfig; -use crate::WarpSync; +use crate::{SyncConfig, WarpSync, chain::SyncState}; use ethcore::client::{ BlockChainClient, BlockId, BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient, }; diff --git a/crates/ethcore/sync/src/tests/consensus.rs b/crates/ethcore/sync/src/tests/consensus.rs index 0171cc69a..ff4493046 100644 --- a/crates/ethcore/sync/src/tests/consensus.rs +++ b/crates/ethcore/sync/src/tests/consensus.rs @@ -16,10 +16,10 @@ use super::helpers::*; use crate::{ + SyncConfig, io::{IoChannel, IoHandler}, types::transaction::{Action, PendingTransaction, Transaction, TypedTransaction}, }; -use crate::SyncConfig; use crypto::publickey::{KeyPair, Secret}; use ethcore::{ client::{ChainInfo, ClientIoMessage}, diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index 6812046fd..2ec2a4895 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -47,8 +47,7 @@ use std::{ sync::Arc, }; -use crate::types::BlockNumber; -use crate::SyncConfig; +use crate::{SyncConfig, types::BlockNumber}; pub trait FlushingBlockChainClient: BlockChainClient { fn flush(&self) {} diff --git a/crates/ethcore/sync/src/tests/snapshot.rs b/crates/ethcore/sync/src/tests/snapshot.rs index ee760d212..baae4ea9e 100644 --- a/crates/ethcore/sync/src/tests/snapshot.rs +++ b/crates/ethcore/sync/src/tests/snapshot.rs @@ -15,9 +15,7 @@ // along with OpenEthereum. If not, see . use super::helpers::*; -use crate::types::BlockNumber; -use crate::SyncConfig; -use crate::WarpSync; +use crate::{SyncConfig, WarpSync, types::BlockNumber}; use bytes::Bytes; use ethcore::{ client::EachBlockWith, diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index 493385dc5..2a9cbdc14 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -45,9 +45,11 @@ pub mod client_version; mod connection_filter; mod error; -pub use crate::io::TimerToken; +pub use crate::{ + error::{DisconnectReason, Error, ErrorKind}, + io::TimerToken, +}; pub use connection_filter::{ConnectionDirection, ConnectionFilter}; -pub use crate::error::{DisconnectReason, Error, ErrorKind}; use crate::client_version::ClientVersion; use crypto::publickey::Secret; diff --git a/crates/rpc/src/tests/rpc.rs b/crates/rpc/src/tests/rpc.rs index c787f416b..4183c1632 100644 --- a/crates/rpc/src/tests/rpc.rs +++ b/crates/rpc/src/tests/rpc.rs @@ -61,7 +61,7 @@ mod tests { use super::{Server, request}; use crate::v1::Metadata; use jsonrpc_core::{MetaIoHandler, Value}; - + fn serve() -> (Server, ::std::net::SocketAddr) { let mut io = MetaIoHandler::default(); io.add_method_with_meta("hello", |_, meta: Metadata| { diff --git a/crates/rpc/src/v1/tests/mocked/parity.rs b/crates/rpc/src/v1/tests/mocked/parity.rs index 6717c87e6..203425ce3 100644 --- a/crates/rpc/src/v1/tests/mocked/parity.rs +++ b/crates/rpc/src/v1/tests/mocked/parity.rs @@ -29,13 +29,15 @@ use std::{str::FromStr, sync::Arc}; use sync::ManageNetwork; use super::manage_network::TestManageNetwork; -use crate::v1::{ - Parity, ParityClient, - helpers::{NetworkSettings, external_signer::SignerService}, - metadata::Metadata, - tests::helpers::{Config, TestMinerService, TestSyncProvider}, +use crate::{ + Host, + v1::{ + Parity, ParityClient, + helpers::{NetworkSettings, external_signer::SignerService}, + metadata::Metadata, + tests::helpers::{Config, TestMinerService, TestSyncProvider}, + }, }; -use crate::Host; use jsonrpc_core::IoHandler; pub type TestParityClient = ParityClient; diff --git a/crates/util/dir/src/lib.rs b/crates/util/dir/src/lib.rs index e972321d6..8535dbf4b 100644 --- a/crates/util/dir/src/lib.rs +++ b/crates/util/dir/src/lib.rs @@ -43,9 +43,9 @@ extern crate home; extern crate journaldb; pub mod helpers; +use crate::helpers::{replace_home, replace_home_and_local}; use app_dirs::{AppDataType, AppInfo, data_root, get_app_root}; use ethereum_types::{H64, H256}; -use crate::helpers::{replace_home, replace_home_and_local}; use journaldb::Algorithm; use std::{ fs, diff --git a/crates/vm/vm/src/lib.rs b/crates/vm/vm/src/lib.rs index f3438a97c..0d2c7aee5 100644 --- a/crates/vm/vm/src/lib.rs +++ b/crates/vm/vm/src/lib.rs @@ -34,11 +34,13 @@ pub mod schedule; pub mod tests; +pub use crate::error::{ + Error, ExecTrapError, ExecTrapResult, Result, TrapError, TrapKind, TrapResult, +}; pub use access_list::AccessList; pub use action_params::{ActionParams, ActionValue, ParamsType}; pub use call_type::CallType; pub use env_info::{EnvInfo, LastHashes}; -pub use crate::error::{Error, ExecTrapError, ExecTrapResult, Result, TrapError, TrapKind, TrapResult}; pub use ext::{ContractCreateResult, CreateContractAddress, Ext, MessageCallResult}; pub use return_data::{GasLeft, ReturnData}; pub use schedule::{CleanDustMode, Schedule, WasmCosts}; From 9c664788b99aedef4c20aa6d1162c34af6335029 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 May 2025 13:34:11 +0200 Subject: [PATCH 452/687] fixed test_identity_arg test --- bin/oe/configuration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 470273b2d..641a59190 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -1816,7 +1816,7 @@ mod tests { assert!( c.net_conf .client_version - .starts_with("OpenEthereum/Somebody/") + .starts_with("diamond-node/Somebody/") ); } _ => panic!("Should be Cmd::Run"), From f342ad0460b0e37057d1f27d4f8c483c435caf13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20M=C3=BCller?= Date: Wed, 7 May 2025 18:56:03 +0300 Subject: [PATCH 453/687] fix: dependency broken build --- Cargo.lock | 8 +++----- Cargo.toml | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0201c6359..80e12854d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3398,8 +3398,7 @@ dependencies = [ [[package]] name = "parity-rocksdb" version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d17caf6640e24b70242f3f48615e3f0764f98871e8c7aea25584e29833eb5a8" +source = "git+https://github.com/DMDcoin/rust-rocksdb.git#412b49ac7d87c20360fbbdfdda79d22f542f280d" dependencies = [ "libc", "local-encoding", @@ -3408,9 +3407,8 @@ dependencies = [ [[package]] name = "parity-rocksdb-sys" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9581e6b8c63f3808500638372ee56faaaffb57c4d349974bff591606b94d5f57" +version = "0.5.7" +source = "git+https://github.com/DMDcoin/rust-rocksdb.git#412b49ac7d87c20360fbbdfdda79d22f542f280d" dependencies = [ "cmake", "libc", diff --git a/Cargo.toml b/Cargo.toml index 5fbdd9c0e..420114c58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,6 +80,10 @@ net2 = "0.2.38" # ethcore-secretstore = { path = "crates/util/secret-store", optional = true } +[patch.crates-io] +# patch parity-rocksdb-sys package +parity-rocksdb = { git = 'https://github.com/DMDcoin/rust-rocksdb.git' } + [build-dependencies] rustc_version = "0.2" From 8bf470a4a6fac7821fc8d991deec083d6245dabf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 11 May 2025 21:29:32 +0200 Subject: [PATCH 454/687] fixed problem where diamond-node clients did not connect to each other, because of Node Software Name. --- crates/net/network/Cargo.toml | 1 + crates/net/network/src/client_version.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index efcab3c56..0793b51e3 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -10,6 +10,7 @@ edition = "2024" [dependencies] error-chain = { version = "0.12", default-features = false } parity-crypto = { version = "0.6.2", features = [ "publickey"] } +parity-version = { path = "../../../crates/util/version" } ethcore-io = { path = "../../runtime/io" } ethereum-types = "0.9.2" ethkey = { path = "../../../crates/accounts/ethkey" } diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index a5f3e9e4e..18514e7a5 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -179,6 +179,7 @@ impl ClientCapabilities for ClientVersion { fn is_parity(client_id: &str) -> bool { client_id.starts_with(LEGACY_CLIENT_ID_PREFIX) || client_id.starts_with(CURRENT_CLIENT_ID_PREFIX) + || client_id.starts_with(parity_version::NODE_SOFTWARE_NAME) } fn is_nethermind(client_id: &str) -> bool { From ce04af6212bb24c254e17c620ec5ce4463157af1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 11 May 2025 21:29:58 +0200 Subject: [PATCH 455/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/verification/queue/mod.rs | 4 ++-- crates/ethcore/src/verification/verification.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index ac8520a7c..a3271aa4f 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -874,13 +874,13 @@ impl Drop for VerificationQueue { mod tests { use super::{BlockQueue, Config, State, kind::blocks::Unverified}; use crate::{ + error::*, io::*, spec::Spec, + test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}, types::{BlockNumber, view, views::BlockView}, }; use bytes::Bytes; - use crate::error::*; - use crate::test_helpers::{get_good_dummy_block, get_good_dummy_block_seq}; // create a test block queue. // auto_scaling enables verifier adjustment. diff --git a/crates/ethcore/src/verification/verification.rs b/crates/ethcore/src/verification/verification.rs index b256fc050..768e72053 100644 --- a/crates/ethcore/src/verification/verification.rs +++ b/crates/ethcore/src/verification/verification.rs @@ -545,7 +545,9 @@ mod tests { use crate::{ blockchain::{BlockDetails, BlockReceipts, TransactionAddress}, engines::EthEngine, + error::{BlockError::*, ErrorKind}, spec::{CommonParams, Spec}, + test_helpers::{create_test_block, create_test_block_with_data}, types::{ encoded, log_entry::{LocalizedLogEntry, LogEntry}, @@ -553,7 +555,6 @@ mod tests { }, }; use crypto::publickey::{Generator, Random}; - use crate::error::{BlockError::*, ErrorKind}; use ethereum_types::{Address, BloomRef, H256, U256}; use hash::keccak; use rlp; @@ -561,7 +562,6 @@ mod tests { collections::{BTreeMap, HashMap}, time::{SystemTime, UNIX_EPOCH}, }; - use crate::test_helpers::{create_test_block, create_test_block_with_data}; use triehash::ordered_trie_root; fn check_ok(result: Result<(), Error>) { From 23814c48caca5f83e04eb0321317c7138c7e2e4d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 11 May 2025 21:30:11 +0200 Subject: [PATCH 456/687] Cargo.lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 0201c6359..88bf1f221 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1478,6 +1478,7 @@ dependencies = [ "libc", "parity-crypto", "parity-snappy", + "parity-version", "rlp", "semver", "serde", From 0a0df269600ebd8385ff97001b6fec621259ee2f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 13 May 2025 14:35:54 +0200 Subject: [PATCH 457/687] default.nix --- default.nix | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 default.nix diff --git a/default.nix b/default.nix new file mode 100644 index 000000000..c30ae919c --- /dev/null +++ b/default.nix @@ -0,0 +1,7 @@ +{ pkgs ? import {} }: + pkgs.mkShell { + # nativeBuildInputs is usually what you want -- tools you need to run + nativeBuildInputs = with pkgs.buildPackages; [ + gcc + ]; +} \ No newline at end of file From c8f1fa3c30cb4213eff4b40defbed52bcd5053be Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 13 May 2025 21:17:09 +0200 Subject: [PATCH 458/687] unusued crate warning --- crates/ethcore/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index f3f6884c1..dea8101a7 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -18,7 +18,6 @@ //! Ethcore library -extern crate ansi_term; extern crate common_types as types; extern crate crossbeam_utils; extern crate derive_more; From 28b20084a6b37881935c0ccd581ed217b42e37da Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 15 May 2025 15:07:54 +0200 Subject: [PATCH 459/687] adjust devp2p log levels --- crates/ethcore/sync/src/chain/handler.rs | 2 +- crates/ethcore/sync/src/chain/requester.rs | 2 +- crates/ethcore/sync/src/chain/supplier.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 1c5484c49..94fe1a6ef 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -896,7 +896,7 @@ impl SyncHandler { trace!(target: "sync", "{} Peer sent us more transactions than was supposed to", peer_id); return Err(DownloaderImportError::Invalid); } - info!(target: "sync", "{:02} -> PooledTransactions ({} entries)", peer_id, item_count); + debug!(target: "sync", "{:02} -> PooledTransactions ({} entries)", peer_id, item_count); let mut transactions = Vec::with_capacity(item_count); for i in 0..item_count { let rlp = tx_rlp.at(i)?; diff --git a/crates/ethcore/sync/src/chain/requester.rs b/crates/ethcore/sync/src/chain/requester.rs index 56333a963..1e229f8e5 100644 --- a/crates/ethcore/sync/src/chain/requester.rs +++ b/crates/ethcore/sync/src/chain/requester.rs @@ -113,7 +113,7 @@ impl SyncRequester { peer_id: PeerId, hashes: &H256FastSet, ) -> usize { - info!(target: "sync", "{} <- GetPooledTransactions: {:?}", peer_id, hashes); + debug!(target: "sync", "{} <- GetPooledTransactions: {:?}", peer_id, hashes); let mut rlp = RlpStream::new_list(hashes.len()); for h in hashes { rlp.append(h); diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index f11553638..89d4e8995 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -331,7 +331,7 @@ impl SyncSupplier { } rlp.finalize_unbounded_list(); - info!(target: "sync", "{} -> GetPooledTransactions: returned {} entries. Not found: {}. parse errors: {}", peer_id, added, not_found, parse_errors); + debug!(target: "sync", "{} -> GetPooledTransactions: returned {} entries. Not found: {}. parse errors: {}", peer_id, added, not_found, parse_errors); Ok(Some((PooledTransactionsPacket, rlp))) } From 5fcc1ef7dc84caf93e76855f325cc5f17272bc81 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 May 2025 22:23:26 +0200 Subject: [PATCH 460/687] warnings --- crates/concensus/miner/src/pool/queue.rs | 3 ++- crates/concensus/miner/src/service_transaction_checker.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index c0a9dd1b4..a35c7c956 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -786,12 +786,13 @@ impl TransactionQueue { (pool.listener_mut().1).0.add(f); } - /// Check if pending set is cached. + /// Check if pending set is cached. (enforced) #[cfg(test)] pub fn is_enforced_pending_cached(&self) -> bool { self.cached_enforced_pending.read().pending.is_some() } + /// Check if pending set is cached. (non-enforced) #[cfg(test)] pub fn is_non_enforced_pending_cached(&self) -> bool { self.cached_non_enforced_pending.read().pending.is_some() diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index 23afc9609..d2a2697e3 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -21,7 +21,7 @@ use call_contract::{CallContract, RegistryInfo}; use ethabi::FunctionOutputDecoder; use ethereum_types::Address; use parking_lot::RwLock; -use std::{collections::HashMap, mem, str::FromStr, sync::Arc}; +use std::{collections::HashMap, str::FromStr, sync::Arc}; use_contract!( service_transaction, From fa2db667451571e95728f935cb3101b8f2d2d757 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 May 2025 22:30:50 +0200 Subject: [PATCH 461/687] passing LogConfig to Execute Commands --- bin/oe/configuration.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 641a59190..20cee98a5 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -109,7 +109,9 @@ pub enum Cmd { } pub struct Execute { - pub logger: LogConfig, + // pub logger: LogConfig, + + /// executed command. pub cmd: Cmd, } @@ -438,7 +440,7 @@ impl Configuration { }; Ok(Execute { - logger: logger_config, + // logger: logger_config, cmd, }) } From b612cd89fde20cb2129794dc8f28d28023582afc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 May 2025 22:31:02 +0200 Subject: [PATCH 462/687] fixed warnings for unsafe blocks. --- crates/concensus/ethash/src/cache.rs | 53 ++++++++++++++------------ crates/concensus/ethash/src/compute.rs | 5 ++- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/crates/concensus/ethash/src/cache.rs b/crates/concensus/ethash/src/cache.rs index b71ef2910..7cf10546d 100644 --- a/crates/concensus/ethash/src/cache.rs +++ b/crates/concensus/ethash/src/cache.rs @@ -320,39 +320,42 @@ impl AsRef<[Node]> for NodeCache { // out. It counts as a read and causes all writes afterwards to be elided. Yes, really. I know, I // want to refactor this to use less `unsafe` as much as the next rustacean. unsafe fn initialize_memory(memory: *mut Node, num_nodes: usize, ident: &H256) { - // We use raw pointers here, see above - let dst = slice::from_raw_parts_mut(memory as *mut u8, NODE_BYTES); + unsafe { + // We use raw pointers here, see above + let dst = slice::from_raw_parts_mut(memory as *mut u8, NODE_BYTES); - debug_assert_eq!(ident.len(), 32); - keccak_512::write(&ident[..], dst); + debug_assert_eq!(ident.len(), 32); + keccak_512::write(&ident[..], dst); - for i in 1..num_nodes { - // We use raw pointers here, see above - let dst = slice::from_raw_parts_mut(memory.offset(i as _) as *mut u8, NODE_BYTES); - let src = slice::from_raw_parts(memory.offset(i as isize - 1) as *mut u8, NODE_BYTES); - keccak_512::write(src, dst); - } + for i in 1..num_nodes { + // We use raw pointers here, see above + let dst = slice::from_raw_parts_mut(memory.offset(i as _) as *mut u8, NODE_BYTES); + let src = slice::from_raw_parts(memory.offset(i as isize - 1) as *mut u8, NODE_BYTES); + keccak_512::write(src, dst); + } - // Now this is initialized, we can treat it as a slice. - let nodes: &mut [Node] = slice::from_raw_parts_mut(memory, num_nodes); + // Now this is initialized, we can treat it as a slice. + let nodes: &mut [Node] = slice::from_raw_parts_mut(memory, num_nodes); - for _ in 0..ETHASH_CACHE_ROUNDS { - for i in 0..num_nodes { - let data_idx = (num_nodes - 1 + i) % num_nodes; - let idx = nodes.get_unchecked_mut(i).as_words()[0] as usize % num_nodes; + for _ in 0..ETHASH_CACHE_ROUNDS { + for i in 0..num_nodes { + let data_idx = (num_nodes - 1 + i) % num_nodes; + let idx = nodes.get_unchecked_mut(i).as_words()[0] as usize % num_nodes; - let data = { - let mut data: Node = nodes.get_unchecked(data_idx).clone(); - let rhs: &Node = nodes.get_unchecked(idx); + let data = { + let mut data: Node = nodes.get_unchecked(data_idx).clone(); + let rhs: &Node = nodes.get_unchecked(idx); - for (a, b) in data.as_dwords_mut().iter_mut().zip(rhs.as_dwords()) { - *a ^= *b; - } + for (a, b) in data.as_dwords_mut().iter_mut().zip(rhs.as_dwords()) { + *a ^= *b; + } - data - }; + data + }; - keccak_512::write(&data.bytes, &mut nodes.get_unchecked_mut(i).bytes); + keccak_512::write(&data.bytes, &mut nodes.get_unchecked_mut(i).bytes); + } } + } } diff --git a/crates/concensus/ethash/src/compute.rs b/crates/concensus/ethash/src/compute.rs index 067f96c69..218a105b9 100644 --- a/crates/concensus/ethash/src/compute.rs +++ b/crates/concensus/ethash/src/compute.rs @@ -182,7 +182,10 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64) use std::mem; debug_assert_eq!(val.len() * mem::size_of::(), $n * mem::size_of::()); - &mut *(val.as_mut_ptr() as *mut [U; $n]) + unsafe { + &mut *(val.as_mut_ptr() as *mut [U; $n]) + } + } make_const_array($value) From b9dff0e22cf04fc86969a3b326dba9aeea4ec577 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 May 2025 22:35:04 +0200 Subject: [PATCH 463/687] cargo fmt --all -- --config imports_granularity=Crate --- bin/oe/configuration.rs | 1 - crates/concensus/ethash/src/cache.rs | 1 - crates/concensus/ethash/src/compute.rs | 5 +---- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 20cee98a5..e6be6c2b5 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -110,7 +110,6 @@ pub enum Cmd { pub struct Execute { // pub logger: LogConfig, - /// executed command. pub cmd: Cmd, } diff --git a/crates/concensus/ethash/src/cache.rs b/crates/concensus/ethash/src/cache.rs index 7cf10546d..bcb087f0f 100644 --- a/crates/concensus/ethash/src/cache.rs +++ b/crates/concensus/ethash/src/cache.rs @@ -356,6 +356,5 @@ unsafe fn initialize_memory(memory: *mut Node, num_nodes: usize, ident: &H256) { keccak_512::write(&data.bytes, &mut nodes.get_unchecked_mut(i).bytes); } } - } } diff --git a/crates/concensus/ethash/src/compute.rs b/crates/concensus/ethash/src/compute.rs index 218a105b9..761f4ada9 100644 --- a/crates/concensus/ethash/src/compute.rs +++ b/crates/concensus/ethash/src/compute.rs @@ -182,10 +182,7 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64) use std::mem; debug_assert_eq!(val.len() * mem::size_of::(), $n * mem::size_of::()); - unsafe { - &mut *(val.as_mut_ptr() as *mut [U; $n]) - } - + unsafe { &mut *(val.as_mut_ptr() as *mut [U; $n]) } } make_const_array($value) From 9d121fe04aef6de085753b9cc9b5af9be4fe4299 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 May 2025 22:44:19 +0200 Subject: [PATCH 464/687] Add devP2PTests feature for propagator.rs tests --- crates/ethcore/sync/Cargo.toml | 3 +++ crates/ethcore/sync/src/chain/propagator.rs | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/crates/ethcore/sync/Cargo.toml b/crates/ethcore/sync/Cargo.toml index 84aff981f..441e3dcc7 100644 --- a/crates/ethcore/sync/Cargo.toml +++ b/crates/ethcore/sync/Cargo.toml @@ -47,3 +47,6 @@ ethcore = { path = "..", features = ["test-helpers"] } ethcore-io = { path = "../../runtime/io", features = ["mio"] } kvdb-memorydb = "0.1" rustc-hex = "1.0" + +[features] +devP2PTests = [] \ No newline at end of file diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 9c3968232..aa26783e1 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -634,6 +634,7 @@ mod tests { assert_eq!(0x07, io.packets[0].packet_id); } + #[cfg(feature = "devP2PTests")] #[test] fn propagates_ready_transactions() { let mut client = TestBlockChainClient::new(); @@ -661,6 +662,7 @@ mod tests { assert_eq!(0x02, io.packets[0].packet_id); } + #[cfg(feature = "devP2PTests")] #[test] fn propagates_ready_transactions_to_subset_of_peers() { let mut client = TestBlockChainClient::new(); @@ -679,6 +681,7 @@ mod tests { assert_eq!(8, peer_count); } + #[cfg(feature = "devP2PTests")] #[test] fn propagates_new_transactions_to_all_peers() { let (new_transaction_hashes_tx, new_transaction_hashes_rx) = crossbeam_channel::unbounded(); @@ -699,6 +702,7 @@ mod tests { assert_eq!(25, peer_count); } + #[cfg(feature = "devP2PTests")] #[test] fn propagates_new_transactions() { let (new_transaction_hashes_tx, new_transaction_hashes_rx) = crossbeam_channel::unbounded(); @@ -733,6 +737,7 @@ mod tests { assert_eq!(0x02, io.packets[0].packet_id); } + #[cfg(feature = "devP2PTests")] #[test] fn does_not_propagate_ready_transactions_after_new_block() { let mut client = TestBlockChainClient::new(); @@ -756,6 +761,7 @@ mod tests { assert_eq!(0x02, io.packets[0].packet_id); } + #[cfg(feature = "devP2PTests")] #[test] fn does_not_propagate_new_transactions_after_new_block() { let (new_transaction_hashes_tx, new_transaction_hashes_rx) = crossbeam_channel::unbounded(); @@ -819,6 +825,7 @@ mod tests { assert_eq!(0, peer_count_new2); } + #[cfg(feature = "devP2PTests")] #[test] fn propagates_transactions_without_alternating() { let mut client = TestBlockChainClient::new(); @@ -855,6 +862,7 @@ mod tests { assert_eq!(0x02, queue.read()[1].packet_id); } + #[cfg(feature = "devP2PTests")] #[test] fn should_maintain_transactions_propagation_stats() { let (new_transaction_hashes_tx, new_transaction_hashes_rx) = crossbeam_channel::unbounded(); @@ -905,6 +913,7 @@ mod tests { ); } + #[cfg(feature = "devP2PTests")] #[test] fn should_propagate_service_transaction_to_selected_peers_only() { let mut client = TestBlockChainClient::new(); @@ -944,6 +953,7 @@ mod tests { assert_eq!(io.packets.len(), 2); } + #[cfg(feature = "devP2PTests")] #[test] fn should_propagate_service_transaction_is_sent_as_separate_message() { let mut client = TestBlockChainClient::new(); @@ -991,6 +1001,7 @@ mod tests { assert!(sent_transactions.iter().any(|tx| tx.hash() == tx2_hash)); } + #[cfg(feature = "devP2PTests")] #[test] fn should_propagate_transactions_with_max_fee_per_gas_lower_than_base_fee() { let (new_transaction_hashes_tx, new_transaction_hashes_rx) = crossbeam_channel::unbounded(); From c284f1f91bfb2d29a07a64ef30d1d9ad2b9bb586 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 May 2025 23:26:59 +0200 Subject: [PATCH 465/687] Update import statements to use 'use' for num_cpus crate. --- bin/ethstore/src/main.rs | 2 +- bin/oe/lib.rs | 2 +- crates/ethcore/src/lib.rs | 2 +- crates/runtime/io/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/ethstore/src/main.rs b/bin/ethstore/src/main.rs index 247411185..223e1518c 100644 --- a/bin/ethstore/src/main.rs +++ b/bin/ethstore/src/main.rs @@ -17,7 +17,7 @@ extern crate dir; extern crate docopt; extern crate ethstore; -extern crate num_cpus; +use num_cpus; extern crate panic_hook; extern crate parking_lot; extern crate rustc_hex; diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index fc2db1466..ee1d53939 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -25,7 +25,7 @@ extern crate atty; extern crate dir; extern crate futures; extern crate jsonrpc_core; -extern crate num_cpus; +use num_cpus; extern crate number_prefix; extern crate parking_lot; extern crate regex; diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index dea8101a7..b663e1fcb 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -44,7 +44,7 @@ extern crate lru_cache; extern crate maplit; extern crate memory_cache; extern crate memory_db; -extern crate num_cpus; +use num_cpus; extern crate parity_bytes as bytes; extern crate parity_crypto as crypto; extern crate parity_snappy as snappy; diff --git a/crates/runtime/io/src/lib.rs b/crates/runtime/io/src/lib.rs index d36fbeecb..f51ba8ebf 100644 --- a/crates/runtime/io/src/lib.rs +++ b/crates/runtime/io/src/lib.rs @@ -76,7 +76,7 @@ extern crate log as rlog; extern crate crossbeam_deque as deque; extern crate fnv; extern crate futures; -extern crate num_cpus; +use num_cpus; extern crate parking_lot; extern crate slab; extern crate time; From 5a6d6b3ee3602a1e23715e69878edabaf7ddbbf3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 May 2025 23:32:15 +0200 Subject: [PATCH 466/687] Remove unused imports across multiple files --- bin/oe/cli/mod.rs | 2 +- bin/oe/configuration.rs | 1 - bin/oe/db/rocksdb/blooms.rs | 1 - bin/oe/db/rocksdb/mod.rs | 1 - bin/oe/informant.rs | 1 - bin/oe/lib.rs | 1 - bin/oe/signer.rs | 1 - 7 files changed, 1 insertion(+), 7 deletions(-) diff --git a/bin/oe/cli/mod.rs b/bin/oe/cli/mod.rs index 3457f26a5..ec50f3a52 100644 --- a/bin/oe/cli/mod.rs +++ b/bin/oe/cli/mod.rs @@ -1055,7 +1055,7 @@ mod tests { }; use clap::ErrorKind as ClapErrorKind; use parity_version::NODE_SOFTWARE_NAME; - use toml; + #[test] fn should_accept_any_argument_order() { diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index e6be6c2b5..8110076a2 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -33,7 +33,6 @@ use ethcore::{ }; use ethereum_types::{Address, H256, U256}; -use num_cpus; use parity_version::{version, version_data}; use std::{ cmp, diff --git a/bin/oe/db/rocksdb/blooms.rs b/bin/oe/db/rocksdb/blooms.rs index e481fa195..ad5e39765 100644 --- a/bin/oe/db/rocksdb/blooms.rs +++ b/bin/oe/db/rocksdb/blooms.rs @@ -19,7 +19,6 @@ use super::{kvdb_rocksdb::DatabaseConfig, open_database}; use ethcore::error::Error; use ethereum_types::Bloom; -use rlp; use std::path::Path; const LOG_BLOOMS_ELEMENTS_PER_INDEX: u64 = 16; diff --git a/bin/oe/db/rocksdb/mod.rs b/bin/oe/db/rocksdb/mod.rs index a0556dad6..1c59fdbf3 100644 --- a/bin/oe/db/rocksdb/mod.rs +++ b/bin/oe/db/rocksdb/mod.rs @@ -22,7 +22,6 @@ use self::{ ethcore_blockchain::{BlockChainDB, BlockChainDBHandler}, kvdb_rocksdb::{Database, DatabaseConfig}, }; -use blooms_db; use ethcore::client::ClientConfig; use ethcore_db::KeyValueDB; use stats::PrometheusMetrics; diff --git a/bin/oe/informant.rs b/bin/oe/informant.rs index 4ca3dbbd2..2c57b0a87 100644 --- a/bin/oe/informant.rs +++ b/bin/oe/informant.rs @@ -34,7 +34,6 @@ use crate::{ sync::{ManageNetwork, SyncProvider}, types::BlockNumber, }; -use atty; use ethcore::{ client::{ BlockChainClient, BlockChainInfo, BlockId, BlockInfo, BlockQueueInfo, ChainInfo, diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index ee1d53939..baa14a7f5 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -25,7 +25,6 @@ extern crate atty; extern crate dir; extern crate futures; extern crate jsonrpc_core; -use num_cpus; extern crate number_prefix; extern crate parking_lot; extern crate regex; diff --git a/bin/oe/signer.rs b/bin/oe/signer.rs index 01ef4a5eb..34bf7a004 100644 --- a/bin/oe/signer.rs +++ b/bin/oe/signer.rs @@ -22,7 +22,6 @@ use std::{ use crate::{path::restrict_permissions_owner, rpc, rpc_apis}; use ansi_term::Colour::White; use ethcore_logger::Config as LogConfig; -use parity_rpc; pub const CODES_FILENAME: &str = "authcodes"; From cc934266314aba29f68bae69b927156ad70fdf41 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 May 2025 23:41:42 +0200 Subject: [PATCH 467/687] Update imports to use 'use' instead of 'extern crate' for ethereum_types. --- bin/chainspec/src/main.rs | 2 +- bin/evmbin/benches/mod.rs | 2 +- bin/evmbin/src/main.rs | 4 ++-- bin/oe/lib.rs | 2 +- crates/accounts/ethstore/src/lib.rs | 2 +- crates/accounts/ethstore/tests/api.rs | 2 +- crates/concensus/ethash/src/lib.rs | 2 +- crates/concensus/miner/src/lib.rs | 2 +- crates/concensus/miner/stratum/src/lib.rs | 2 +- crates/db/journaldb/src/lib.rs | 2 +- crates/db/patricia-trie-ethereum/src/lib.rs | 6 +++--- crates/ethcore/benches/builtin.rs | 2 +- crates/ethcore/service/src/lib.rs | 2 +- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 4 ++-- crates/ethcore/src/lib.rs | 8 ++++---- crates/ethcore/sync/src/lib.rs | 4 ++-- crates/net/network-devp2p/src/lib.rs | 4 ++-- crates/net/network-devp2p/tests/tests.rs | 2 +- crates/net/network/src/client_version.rs | 1 + crates/net/network/src/lib.rs | 2 +- crates/net/node-filter/src/lib.rs | 2 +- crates/rpc/src/lib.rs | 4 ++-- crates/util/cli-signer/rpc-client/src/lib.rs | 2 +- crates/util/cli-signer/src/lib.rs | 2 +- crates/util/dir/src/lib.rs | 2 +- crates/util/fastmap/src/lib.rs | 2 +- crates/util/keccak-hasher/src/lib.rs | 2 +- crates/util/triehash-ethereum/src/lib.rs | 2 +- crates/vm/evm/benches/basic.rs | 2 +- crates/vm/evm/src/lib.rs | 2 +- crates/vm/vm/src/lib.rs | 4 ++-- crates/vm/wasm/src/lib.rs | 2 +- 32 files changed, 43 insertions(+), 42 deletions(-) diff --git a/bin/chainspec/src/main.rs b/bin/chainspec/src/main.rs index 4928a99b5..0c5a885ca 100644 --- a/bin/chainspec/src/main.rs +++ b/bin/chainspec/src/main.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -extern crate ethjson; +use ethjson; extern crate serde_json; use ethjson::spec::Spec; diff --git a/bin/evmbin/benches/mod.rs b/bin/evmbin/benches/mod.rs index d7b6fb771..d1dec68bb 100644 --- a/bin/evmbin/benches/mod.rs +++ b/bin/evmbin/benches/mod.rs @@ -23,7 +23,7 @@ #[macro_use] extern crate criterion; extern crate ethcore; -extern crate ethereum_types; +use ethereum_types; extern crate evm; extern crate rustc_hex; extern crate vm; diff --git a/bin/evmbin/src/main.rs b/bin/evmbin/src/main.rs index b5f9df147..ee323691c 100644 --- a/bin/evmbin/src/main.rs +++ b/bin/evmbin/src/main.rs @@ -20,7 +20,7 @@ extern crate common_types as types; extern crate ethcore; -extern crate ethjson; +use ethjson; extern crate rustc_hex; extern crate serde; #[macro_use] @@ -29,7 +29,7 @@ extern crate serde_derive; extern crate serde_json; extern crate docopt; extern crate env_logger; -extern crate ethereum_types; +use ethereum_types; extern crate evm; extern crate panic_hook; extern crate parity_bytes as bytes; diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index baa14a7f5..54e7e5004 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -50,7 +50,7 @@ extern crate ethcore_miner as miner; extern crate ethcore_network as network; extern crate ethcore_service; extern crate ethcore_sync as sync; -extern crate ethereum_types; +use ethereum_types; extern crate ethkey; extern crate ethstore; extern crate fetch; diff --git a/crates/accounts/ethstore/src/lib.rs b/crates/accounts/ethstore/src/lib.rs index 5abfdf2ae..a68c04df8 100644 --- a/crates/accounts/ethstore/src/lib.rs +++ b/crates/accounts/ethstore/src/lib.rs @@ -29,7 +29,7 @@ extern crate smallvec; extern crate tempdir; extern crate time; -extern crate ethereum_types; +use ethereum_types; extern crate ethkey as _ethkey; extern crate parity_crypto as crypto; extern crate parity_wordlist; diff --git a/crates/accounts/ethstore/tests/api.rs b/crates/accounts/ethstore/tests/api.rs index 1eb2fa7f0..fde95be71 100644 --- a/crates/accounts/ethstore/tests/api.rs +++ b/crates/accounts/ethstore/tests/api.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -extern crate ethereum_types; +use ethereum_types; extern crate ethstore; extern crate parity_crypto as crypto; extern crate rand; diff --git a/crates/concensus/ethash/src/lib.rs b/crates/concensus/ethash/src/lib.rs index 6af48700d..6b695f9e6 100644 --- a/crates/concensus/ethash/src/lib.rs +++ b/crates/concensus/ethash/src/lib.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . extern crate either; -extern crate ethereum_types; +use ethereum_types; extern crate memmap; extern crate parking_lot; extern crate primal; diff --git a/crates/concensus/miner/src/lib.rs b/crates/concensus/miner/src/lib.rs index 062da7f37..73cd5ad9a 100644 --- a/crates/concensus/miner/src/lib.rs +++ b/crates/concensus/miner/src/lib.rs @@ -24,7 +24,7 @@ extern crate common_types as types; extern crate ethabi; extern crate ethabi_derive; extern crate ethcore_call_contract as call_contract; -extern crate ethereum_types; +use ethereum_types; extern crate futures; extern crate keccak_hash as hash; extern crate linked_hash_map; diff --git a/crates/concensus/miner/stratum/src/lib.rs b/crates/concensus/miner/stratum/src/lib.rs index 01ea5df85..ccf5c33a4 100644 --- a/crates/concensus/miner/stratum/src/lib.rs +++ b/crates/concensus/miner/stratum/src/lib.rs @@ -16,7 +16,7 @@ //! Stratum protocol implementation for parity ethereum/bitcoin clients -extern crate ethereum_types; +use ethereum_types; extern crate jsonrpc_core; extern crate jsonrpc_tcp_server; extern crate keccak_hash as hash; diff --git a/crates/db/journaldb/src/lib.rs b/crates/db/journaldb/src/lib.rs index 4ac6da48c..a00a7519b 100644 --- a/crates/db/journaldb/src/lib.rs +++ b/crates/db/journaldb/src/lib.rs @@ -20,7 +20,7 @@ extern crate log; extern crate ethcore_db; -extern crate ethereum_types; +use ethereum_types; extern crate fastmap; extern crate hash_db; extern crate keccak_hasher; diff --git a/crates/db/patricia-trie-ethereum/src/lib.rs b/crates/db/patricia-trie-ethereum/src/lib.rs index d6828ee70..59cade7a9 100644 --- a/crates/db/patricia-trie-ethereum/src/lib.rs +++ b/crates/db/patricia-trie-ethereum/src/lib.rs @@ -17,7 +17,7 @@ //! Façade crate for `patricia_trie` for Ethereum specific impls extern crate elastic_array; -extern crate ethereum_types; +use ethereum_types; extern crate hash_db; extern crate keccak_hasher; extern crate parity_bytes; @@ -47,7 +47,7 @@ pub type RlpCodec = RlpNodeCodec; /// extern crate hash_db; /// extern crate keccak_hasher; /// extern crate memory_db; -/// extern crate ethereum_types; +/// use ethereum_types; /// extern crate elastic_array; /// extern crate journaldb; /// @@ -92,7 +92,7 @@ pub type FatDB<'db> = trie::FatDB<'db, KeccakHasher, RlpCodec>; /// extern crate keccak_hash; /// extern crate keccak_hasher; /// extern crate memory_db; -/// extern crate ethereum_types; +/// use ethereum_types; /// extern crate elastic_array; /// extern crate journaldb; /// diff --git a/crates/ethcore/benches/builtin.rs b/crates/ethcore/benches/builtin.rs index 2179bddaf..9c5123511 100644 --- a/crates/ethcore/benches/builtin.rs +++ b/crates/ethcore/benches/builtin.rs @@ -21,7 +21,7 @@ extern crate criterion; extern crate lazy_static; extern crate ethcore; extern crate ethcore_builtin; -extern crate ethereum_types; +use ethereum_types; extern crate parity_bytes as bytes; extern crate rustc_hex; diff --git a/crates/ethcore/service/src/lib.rs b/crates/ethcore/service/src/lib.rs index 07b617991..5d115ddc0 100644 --- a/crates/ethcore/service/src/lib.rs +++ b/crates/ethcore/service/src/lib.rs @@ -19,7 +19,7 @@ extern crate ethcore; extern crate ethcore_blockchain as blockchain; extern crate ethcore_io as io; extern crate ethcore_sync as sync; -extern crate ethereum_types; +use ethereum_types; extern crate kvdb; #[macro_use] diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index bc41871d9..26632d409 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -2,8 +2,8 @@ extern crate bincode; #[macro_use] extern crate clap; extern crate ethcore; -extern crate ethereum_types; -extern crate ethjson; +use ethereum_types; +use ethjson; extern crate ethkey; extern crate ethstore; extern crate hbbft; diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index b663e1fcb..56500c100 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -19,7 +19,7 @@ //! Ethcore library extern crate common_types as types; -extern crate crossbeam_utils; +use crossbeam_utils; extern crate derive_more; extern crate ethabi; extern crate ethash; @@ -28,9 +28,9 @@ extern crate ethcore_builtin as builtin; extern crate ethcore_call_contract as call_contract; extern crate ethcore_db as db; extern crate ethcore_io as io; -extern crate ethcore_miner; -extern crate ethereum_types; -extern crate ethjson; +use ethcore_miner; +use ethereum_types; +use ethjson; extern crate fastmap; extern crate hash_db; extern crate hbbft; diff --git a/crates/ethcore/sync/src/lib.rs b/crates/ethcore/sync/src/lib.rs index 90aadc7f2..9ca487902 100644 --- a/crates/ethcore/sync/src/lib.rs +++ b/crates/ethcore/sync/src/lib.rs @@ -28,7 +28,7 @@ extern crate ethcore_io as io; extern crate ethcore_network as network; extern crate ethcore_network_devp2p as devp2p; extern crate ethereum_forkid; -extern crate ethereum_types; +use ethereum_types; extern crate ethkey; extern crate ethstore; extern crate fastmap; @@ -61,7 +61,7 @@ extern crate macros; extern crate log; #[macro_use] extern crate trace_time; -extern crate ethcore_miner; +use ethcore_miner; mod block_sync; mod blocks; diff --git a/crates/net/network-devp2p/src/lib.rs b/crates/net/network-devp2p/src/lib.rs index 997b15e82..2eef18ac5 100644 --- a/crates/net/network-devp2p/src/lib.rs +++ b/crates/net/network-devp2p/src/lib.rs @@ -21,7 +21,7 @@ //! ```rust //! extern crate ethcore_network as net; //! extern crate ethcore_network_devp2p as devp2p; -//! extern crate ethereum_types as types; +//! use ethereum_types as types; //! use net::*; //! use devp2p::NetworkService; //! use std::sync::Arc; @@ -66,7 +66,7 @@ extern crate ansi_term; //TODO: remove this extern crate bytes; extern crate ethcore_io as io; extern crate ethcore_network as network; -extern crate ethereum_types; +use ethereum_types; extern crate ethkey; extern crate igd; extern crate ipnetwork; diff --git a/crates/net/network-devp2p/tests/tests.rs b/crates/net/network-devp2p/tests/tests.rs index d4bc0e374..52533b50b 100644 --- a/crates/net/network-devp2p/tests/tests.rs +++ b/crates/net/network-devp2p/tests/tests.rs @@ -18,7 +18,7 @@ extern crate env_logger; extern crate ethcore_io as io; extern crate ethcore_network; extern crate ethcore_network_devp2p; -extern crate ethereum_types; +use ethereum_types; extern crate parity_bytes; extern crate parity_crypto as crypto; extern crate parking_lot; diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index 18514e7a5..d3eac082d 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -282,6 +282,7 @@ fn get_number_from_version(version: &str) -> Option<&str> { None } + #[cfg(test)] pub mod tests { use super::*; diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index 2a9cbdc14..38f621dc7 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -17,7 +17,7 @@ #![recursion_limit = "128"] extern crate ethcore_io as io; -extern crate ethereum_types; +use ethereum_types; extern crate ethkey; extern crate ipnetwork; extern crate libc; diff --git a/crates/net/node-filter/src/lib.rs b/crates/net/node-filter/src/lib.rs index e08f8af3d..94a5a45d0 100644 --- a/crates/net/node-filter/src/lib.rs +++ b/crates/net/node-filter/src/lib.rs @@ -20,7 +20,7 @@ extern crate ethabi; extern crate ethcore; extern crate ethcore_network as network; extern crate ethcore_network_devp2p as devp2p; -extern crate ethereum_types; +use ethereum_types; extern crate lru_cache; extern crate parking_lot; diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index 4d2e2483c..e492063db 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -65,7 +65,7 @@ extern crate ethcore_logger; extern crate ethcore_miner as miner; extern crate ethcore_network as network; extern crate ethcore_sync as sync; -extern crate ethereum_types; +use ethereum_types; extern crate ethkey; extern crate ethstore; extern crate fetch; @@ -90,7 +90,7 @@ extern crate log; extern crate serde_derive; #[cfg(test)] -extern crate ethjson; +use ethjson; #[cfg(test)] #[macro_use] diff --git a/crates/util/cli-signer/rpc-client/src/lib.rs b/crates/util/cli-signer/rpc-client/src/lib.rs index b22eeed47..1ef4f7e09 100644 --- a/crates/util/cli-signer/rpc-client/src/lib.rs +++ b/crates/util/cli-signer/rpc-client/src/lib.rs @@ -17,7 +17,7 @@ pub mod client; pub mod signer_client; -extern crate ethereum_types; +use ethereum_types; extern crate futures; extern crate jsonrpc_core; extern crate jsonrpc_ws_server as ws; diff --git a/crates/util/cli-signer/src/lib.rs b/crates/util/cli-signer/src/lib.rs index 1f22538d8..ad909d660 100644 --- a/crates/util/cli-signer/src/lib.rs +++ b/crates/util/cli-signer/src/lib.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -extern crate ethereum_types; +use ethereum_types; extern crate futures; extern crate rpassword; diff --git a/crates/util/dir/src/lib.rs b/crates/util/dir/src/lib.rs index 8535dbf4b..247fc365a 100644 --- a/crates/util/dir/src/lib.rs +++ b/crates/util/dir/src/lib.rs @@ -38,7 +38,7 @@ /// Unix: $BASE/openethereum/ /// extern crate app_dirs; -extern crate ethereum_types; +use ethereum_types; extern crate home; extern crate journaldb; diff --git a/crates/util/fastmap/src/lib.rs b/crates/util/fastmap/src/lib.rs index 30c5be92a..76e394a47 100644 --- a/crates/util/fastmap/src/lib.rs +++ b/crates/util/fastmap/src/lib.rs @@ -16,7 +16,7 @@ //! Provides a `H256FastMap` type with H256 keys and fast hashing function. -extern crate ethereum_types; +use ethereum_types; extern crate lru; extern crate plain_hasher; diff --git a/crates/util/keccak-hasher/src/lib.rs b/crates/util/keccak-hasher/src/lib.rs index 727181b35..d9a0bb198 100644 --- a/crates/util/keccak-hasher/src/lib.rs +++ b/crates/util/keccak-hasher/src/lib.rs @@ -15,7 +15,7 @@ // along with OpenEthereum. If not, see . //! Hasher implementation for the Keccak-256 hash -extern crate ethereum_types; +use ethereum_types; extern crate hash_db; extern crate plain_hasher; extern crate tiny_keccak; diff --git a/crates/util/triehash-ethereum/src/lib.rs b/crates/util/triehash-ethereum/src/lib.rs index 029f59f79..31a42cc53 100644 --- a/crates/util/triehash-ethereum/src/lib.rs +++ b/crates/util/triehash-ethereum/src/lib.rs @@ -16,7 +16,7 @@ //! Generates Keccak-flavoured trie roots. -extern crate ethereum_types; +use ethereum_types; extern crate keccak_hasher; extern crate triehash; diff --git a/crates/vm/evm/benches/basic.rs b/crates/vm/evm/benches/basic.rs index d6659f608..7f0e8fa13 100644 --- a/crates/vm/evm/benches/basic.rs +++ b/crates/vm/evm/benches/basic.rs @@ -19,7 +19,7 @@ #[macro_use] extern crate criterion; extern crate bit_set; -extern crate ethereum_types; +use ethereum_types; extern crate evm; extern crate keccak_hash as hash; extern crate memory_cache; diff --git a/crates/vm/evm/src/lib.rs b/crates/vm/evm/src/lib.rs index 66431fa3d..59dd6d0a6 100644 --- a/crates/vm/evm/src/lib.rs +++ b/crates/vm/evm/src/lib.rs @@ -18,7 +18,7 @@ extern crate bit_set; extern crate ethcore_builtin as builtin; -extern crate ethereum_types; +use ethereum_types; extern crate keccak_hash as hash; extern crate memory_cache; extern crate num_bigint; diff --git a/crates/vm/vm/src/lib.rs b/crates/vm/vm/src/lib.rs index 0d2c7aee5..a273dc8d7 100644 --- a/crates/vm/vm/src/lib.rs +++ b/crates/vm/vm/src/lib.rs @@ -16,8 +16,8 @@ //! Virtual machines support library -extern crate ethereum_types; -extern crate ethjson; +use ethereum_types; +use ethjson; extern crate keccak_hash as hash; extern crate parity_bytes as bytes; extern crate patricia_trie_ethereum as ethtrie; diff --git a/crates/vm/wasm/src/lib.rs b/crates/vm/wasm/src/lib.rs index 9601d53cd..f868a56b0 100644 --- a/crates/vm/wasm/src/lib.rs +++ b/crates/vm/wasm/src/lib.rs @@ -17,7 +17,7 @@ //! Wasm Interpreter extern crate byteorder; -extern crate ethereum_types; +use ethereum_types; #[macro_use] extern crate log; extern crate libc; From 80906d2c4b01d510dbc0d22affc270b525dd33de Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 17 May 2025 23:47:54 +0200 Subject: [PATCH 468/687] cargo fmt --all -- --config imports_granularity=Crate --- bin/oe/cli/mod.rs | 1 - crates/net/network/src/client_version.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/bin/oe/cli/mod.rs b/bin/oe/cli/mod.rs index ec50f3a52..c28b91c8c 100644 --- a/bin/oe/cli/mod.rs +++ b/bin/oe/cli/mod.rs @@ -1055,7 +1055,6 @@ mod tests { }; use clap::ErrorKind as ClapErrorKind; use parity_version::NODE_SOFTWARE_NAME; - #[test] fn should_accept_any_argument_order() { diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index d3eac082d..18514e7a5 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -282,7 +282,6 @@ fn get_number_from_version(version: &str) -> Option<&str> { None } - #[cfg(test)] pub mod tests { use super::*; From a5580f6cd8e3e71be81dd3d50fbaca1b60d7e9a2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 18 May 2025 09:53:42 +0200 Subject: [PATCH 469/687] further "extern crate" to "use" conversions --- bin/evmbin/benches/mod.rs | 4 ++-- bin/evmbin/src/main.rs | 4 ++-- crates/ethcore/src/lib.rs | 10 +++++----- crates/rpc/src/lib.rs | 2 +- crates/vm/evm/benches/basic.rs | 4 ++-- crates/vm/evm/src/lib.rs | 2 +- crates/vm/wasm/src/lib.rs | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bin/evmbin/benches/mod.rs b/bin/evmbin/benches/mod.rs index d1dec68bb..c8938c62b 100644 --- a/bin/evmbin/benches/mod.rs +++ b/bin/evmbin/benches/mod.rs @@ -24,9 +24,9 @@ extern crate criterion; extern crate ethcore; use ethereum_types; -extern crate evm; +use evm; extern crate rustc_hex; -extern crate vm; +use vm; use criterion::{Criterion, black_box}; use std::sync::Arc; diff --git a/bin/evmbin/src/main.rs b/bin/evmbin/src/main.rs index ee323691c..ac922ff8f 100644 --- a/bin/evmbin/src/main.rs +++ b/bin/evmbin/src/main.rs @@ -30,10 +30,10 @@ extern crate serde_json; extern crate docopt; extern crate env_logger; use ethereum_types; -extern crate evm; +use evm; extern crate panic_hook; extern crate parity_bytes as bytes; -extern crate vm; +use vm; #[cfg(test)] #[macro_use] diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index 56500c100..3ce593c7f 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -64,9 +64,9 @@ extern crate tiny_keccak; extern crate trie_db as trie; extern crate triehash_ethereum as triehash; extern crate unexpected; -extern crate using_queue; -extern crate vm; -extern crate wasm; +use using_queue; +use vm; +use wasm; #[cfg(any(test, feature = "blooms-db"))] extern crate blooms_db; @@ -75,7 +75,7 @@ extern crate env_logger; #[cfg(test)] extern crate ethcore_accounts as accounts; #[cfg(feature = "stratum")] -extern crate ethcore_stratum; +use ethcore_stratum; #[cfg(feature = "json-tests")] extern crate globset; #[cfg(any(test, feature = "kvdb-rocksdb"))] @@ -107,7 +107,7 @@ extern crate trace_time; extern crate serde_derive; #[cfg_attr(test, macro_use)] -extern crate evm; +use evm; #[cfg(all(test, feature = "price-info"))] extern crate fetch; diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index e492063db..dfa0a6338 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -76,7 +76,7 @@ extern crate parity_runtime; extern crate parity_version as version; extern crate rlp; extern crate stats; -extern crate vm; +use vm; #[cfg(any(test, feature = "ethcore-accounts"))] extern crate ethcore_accounts as accounts; diff --git a/crates/vm/evm/benches/basic.rs b/crates/vm/evm/benches/basic.rs index 7f0e8fa13..0d7cac880 100644 --- a/crates/vm/evm/benches/basic.rs +++ b/crates/vm/evm/benches/basic.rs @@ -20,13 +20,13 @@ extern crate criterion; extern crate bit_set; use ethereum_types; -extern crate evm; +use evm; extern crate keccak_hash as hash; extern crate memory_cache; extern crate parity_bytes as bytes; extern crate parking_lot; extern crate rustc_hex; -extern crate vm; +use vm; use bytes::Bytes; use criterion::{black_box, Bencher, Criterion}; diff --git a/crates/vm/evm/src/lib.rs b/crates/vm/evm/src/lib.rs index 59dd6d0a6..cd0019ab3 100644 --- a/crates/vm/evm/src/lib.rs +++ b/crates/vm/evm/src/lib.rs @@ -25,7 +25,7 @@ extern crate num_bigint; extern crate parity_bytes as bytes; extern crate parity_util_mem; extern crate parking_lot; -extern crate vm; +use vm; #[macro_use] extern crate lazy_static; diff --git a/crates/vm/wasm/src/lib.rs b/crates/vm/wasm/src/lib.rs index f868a56b0..7742eddfa 100644 --- a/crates/vm/wasm/src/lib.rs +++ b/crates/vm/wasm/src/lib.rs @@ -23,7 +23,7 @@ extern crate log; extern crate libc; extern crate parity_wasm; extern crate pwasm_utils as wasm_utils; -extern crate vm; +use vm; extern crate wasmi; #[cfg(test)] From 6f8a6958cd666bb2a6e97e7479dbb3e4e7a701c5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 18 May 2025 10:04:13 +0200 Subject: [PATCH 470/687] fixed extern crate and uses with cargo fix --lib -p ethcore --- crates/ethcore/src/lib.rs | 43 +++++++-------------------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index 3ce593c7f..63f7b81bf 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -19,54 +19,25 @@ //! Ethcore library extern crate common_types as types; -use crossbeam_utils; -extern crate derive_more; -extern crate ethabi; -extern crate ethash; +use ethabi; +use ethash; extern crate ethcore_blockchain as blockchain; extern crate ethcore_builtin as builtin; extern crate ethcore_call_contract as call_contract; extern crate ethcore_db as db; extern crate ethcore_io as io; -use ethcore_miner; -use ethereum_types; -use ethjson; -extern crate fastmap; -extern crate hash_db; -extern crate hbbft; -extern crate itertools; -extern crate journaldb; +use itertools; +use journaldb; extern crate keccak_hash as hash; -extern crate keccak_hasher; -extern crate kvdb; -extern crate len_caching_lock; -extern crate lru_cache; -extern crate maplit; -extern crate memory_cache; -extern crate memory_db; -use num_cpus; extern crate parity_bytes as bytes; extern crate parity_crypto as crypto; extern crate parity_snappy as snappy; -extern crate parity_util_mem; -extern crate parking_lot; extern crate patricia_trie_ethereum as ethtrie; -extern crate rand; -extern crate rayon; -extern crate reth_util; -extern crate rlp; -extern crate rmp_serde; -extern crate rustc_hex; -extern crate serde; -extern crate stats; -extern crate time_utils; -extern crate tiny_keccak; +use rand; +use rlp; +use rmp_serde; extern crate trie_db as trie; extern crate triehash_ethereum as triehash; -extern crate unexpected; -use using_queue; -use vm; -use wasm; #[cfg(any(test, feature = "blooms-db"))] extern crate blooms_db; From c5981a7985bb58b5761884e3cbfe8b876289d21a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 18 May 2025 21:58:44 +0200 Subject: [PATCH 471/687] version update: 0.11.0-rc2 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 88bf1f221..eb8ac18b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -849,7 +849,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.0-rc1" +version = "3.3.5-hbbft-0.11.0-rc2" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3585,7 +3585,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.0-rc1" +version = "3.3.5-hbbft-0.11.0-rc2" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 7ebc56b86..762fd2dc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.0-rc1" +version = "3.3.5-hbbft-0.11.0-rc2" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 9c8cee72e..6e7ed6190 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.0-rc1" +version = "3.3.5-hbbft-0.11.0-rc2" authors = [ "bit.diamonds developers", "OpenEthereum developers", From d827f317765e593e66a35bced0008c0f8decc7ac Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 18 May 2025 22:11:53 +0200 Subject: [PATCH 472/687] cleanup imports --- crates/accounts/ethstore/src/lib.rs | 1 - crates/concensus/miner/src/lib.rs | 1 - crates/ethcore/service/src/lib.rs | 1 - crates/ethcore/sync/src/chain/mod.rs | 2 +- crates/ethcore/sync/src/lib.rs | 2 -- crates/net/network-devp2p/src/lib.rs | 1 - crates/rpc/src/lib.rs | 37 +++++--------------- crates/rpc/src/v1/types/mod.rs | 4 +-- crates/runtime/io/src/lib.rs | 1 - crates/util/cli-signer/rpc-client/src/lib.rs | 1 - crates/vm/evm/src/lib.rs | 1 - crates/vm/vm/src/lib.rs | 2 -- 12 files changed, 12 insertions(+), 42 deletions(-) diff --git a/crates/accounts/ethstore/src/lib.rs b/crates/accounts/ethstore/src/lib.rs index a68c04df8..ebe5b0ec1 100644 --- a/crates/accounts/ethstore/src/lib.rs +++ b/crates/accounts/ethstore/src/lib.rs @@ -29,7 +29,6 @@ extern crate smallvec; extern crate tempdir; extern crate time; -use ethereum_types; extern crate ethkey as _ethkey; extern crate parity_crypto as crypto; extern crate parity_wordlist; diff --git a/crates/concensus/miner/src/lib.rs b/crates/concensus/miner/src/lib.rs index 73cd5ad9a..ac408ccb7 100644 --- a/crates/concensus/miner/src/lib.rs +++ b/crates/concensus/miner/src/lib.rs @@ -24,7 +24,6 @@ extern crate common_types as types; extern crate ethabi; extern crate ethabi_derive; extern crate ethcore_call_contract as call_contract; -use ethereum_types; extern crate futures; extern crate keccak_hash as hash; extern crate linked_hash_map; diff --git a/crates/ethcore/service/src/lib.rs b/crates/ethcore/service/src/lib.rs index 5d115ddc0..56941eb5c 100644 --- a/crates/ethcore/service/src/lib.rs +++ b/crates/ethcore/service/src/lib.rs @@ -19,7 +19,6 @@ extern crate ethcore; extern crate ethcore_blockchain as blockchain; extern crate ethcore_io as io; extern crate ethcore_sync as sync; -use ethereum_types; extern crate kvdb; #[macro_use] diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index b5cc48ed4..a876cbc7d 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -109,7 +109,7 @@ use crate::{ snapshot::Snapshot, sync_io::SyncIo, transactions_stats::{Stats as TransactionStats, TransactionsStats}, - types::{BlockNumber, block_status, transaction::UnverifiedTransaction}, + types::{BlockNumber, transaction::UnverifiedTransaction}, }; use bytes::Bytes; use derive_more::Display; diff --git a/crates/ethcore/sync/src/lib.rs b/crates/ethcore/sync/src/lib.rs index 9ca487902..78a8cc804 100644 --- a/crates/ethcore/sync/src/lib.rs +++ b/crates/ethcore/sync/src/lib.rs @@ -28,7 +28,6 @@ extern crate ethcore_io as io; extern crate ethcore_network as network; extern crate ethcore_network_devp2p as devp2p; extern crate ethereum_forkid; -use ethereum_types; extern crate ethkey; extern crate ethstore; extern crate fastmap; @@ -61,7 +60,6 @@ extern crate macros; extern crate log; #[macro_use] extern crate trace_time; -use ethcore_miner; mod block_sync; mod blocks; diff --git a/crates/net/network-devp2p/src/lib.rs b/crates/net/network-devp2p/src/lib.rs index 2eef18ac5..2a96a5850 100644 --- a/crates/net/network-devp2p/src/lib.rs +++ b/crates/net/network-devp2p/src/lib.rs @@ -66,7 +66,6 @@ extern crate ansi_term; //TODO: remove this extern crate bytes; extern crate ethcore_io as io; extern crate ethcore_network as network; -use ethereum_types; extern crate ethkey; extern crate igd; extern crate ipnetwork; diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index dfa0a6338..6f84f7a1b 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -40,43 +40,26 @@ #[macro_use] extern crate futures; -extern crate ansi_term; -extern crate itertools; -extern crate order_stat; -extern crate parking_lot; -extern crate rand; -extern crate rustc_hex; -extern crate serde; -extern crate serde_json; -extern crate tokio_timer; -extern crate transient_hashmap; - -extern crate jsonrpc_core; -extern crate jsonrpc_derive; +use order_stat; +use tokio_timer; + +use jsonrpc_core; extern crate jsonrpc_http_server as http; extern crate jsonrpc_ipc_server as ipc; -extern crate jsonrpc_pubsub; +use jsonrpc_pubsub; extern crate common_types as types; -extern crate eip_712; -extern crate ethash; -extern crate ethcore; -extern crate ethcore_logger; +use ethash; extern crate ethcore_miner as miner; extern crate ethcore_network as network; extern crate ethcore_sync as sync; -use ethereum_types; -extern crate ethkey; -extern crate ethstore; -extern crate fetch; +use fetch; extern crate keccak_hash as hash; extern crate parity_bytes as bytes; extern crate parity_crypto as crypto; -extern crate parity_runtime; +use parity_runtime; extern crate parity_version as version; -extern crate rlp; -extern crate stats; -use vm; +use rlp; #[cfg(any(test, feature = "ethcore-accounts"))] extern crate ethcore_accounts as accounts; @@ -110,12 +93,10 @@ extern crate ethcore_io as io; extern crate ethcore_call_contract as call_contract; // #[cfg(test)] -extern crate tempdir; #[cfg(test)] extern crate rpc_servers; -extern crate rpc_common; pub extern crate jsonrpc_ws_server as ws; diff --git a/crates/rpc/src/v1/types/mod.rs b/crates/rpc/src/v1/types/mod.rs index 7be2e544d..721d15db7 100644 --- a/crates/rpc/src/v1/types/mod.rs +++ b/crates/rpc/src/v1/types/mod.rs @@ -28,8 +28,8 @@ pub use self::{ ConfirmationResponseWithToken, DecryptRequest, EIP191SignRequest, Either, EthSignRequest, TransactionModification, }, - derivation::{Derive, DeriveHash, DeriveHierarchical}, - eip191::{EIP191Version, PresignedTransaction}, + derivation::{DeriveHash, DeriveHierarchical}, + eip191::EIP191Version, fee_history::EthFeeHistory, filter::{Filter, FilterChanges}, histogram::Histogram, diff --git a/crates/runtime/io/src/lib.rs b/crates/runtime/io/src/lib.rs index f51ba8ebf..7afa28b06 100644 --- a/crates/runtime/io/src/lib.rs +++ b/crates/runtime/io/src/lib.rs @@ -76,7 +76,6 @@ extern crate log as rlog; extern crate crossbeam_deque as deque; extern crate fnv; extern crate futures; -use num_cpus; extern crate parking_lot; extern crate slab; extern crate time; diff --git a/crates/util/cli-signer/rpc-client/src/lib.rs b/crates/util/cli-signer/rpc-client/src/lib.rs index 1ef4f7e09..8cb66112c 100644 --- a/crates/util/cli-signer/rpc-client/src/lib.rs +++ b/crates/util/cli-signer/rpc-client/src/lib.rs @@ -17,7 +17,6 @@ pub mod client; pub mod signer_client; -use ethereum_types; extern crate futures; extern crate jsonrpc_core; extern crate jsonrpc_ws_server as ws; diff --git a/crates/vm/evm/src/lib.rs b/crates/vm/evm/src/lib.rs index cd0019ab3..0d0dc2f83 100644 --- a/crates/vm/evm/src/lib.rs +++ b/crates/vm/evm/src/lib.rs @@ -18,7 +18,6 @@ extern crate bit_set; extern crate ethcore_builtin as builtin; -use ethereum_types; extern crate keccak_hash as hash; extern crate memory_cache; extern crate num_bigint; diff --git a/crates/vm/vm/src/lib.rs b/crates/vm/vm/src/lib.rs index a273dc8d7..5a17f647c 100644 --- a/crates/vm/vm/src/lib.rs +++ b/crates/vm/vm/src/lib.rs @@ -16,8 +16,6 @@ //! Virtual machines support library -use ethereum_types; -use ethjson; extern crate keccak_hash as hash; extern crate parity_bytes as bytes; extern crate patricia_trie_ethereum as ethtrie; From 564e9d315898908e8f16e6ecbd70a1a86fb02295 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 18 May 2025 22:13:18 +0200 Subject: [PATCH 473/687] import fixes in ethcore --- crates/ethcore/src/lib.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index 63f7b81bf..852bc196e 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -19,23 +19,16 @@ //! Ethcore library extern crate common_types as types; -use ethabi; -use ethash; extern crate ethcore_blockchain as blockchain; extern crate ethcore_builtin as builtin; extern crate ethcore_call_contract as call_contract; extern crate ethcore_db as db; extern crate ethcore_io as io; -use itertools; -use journaldb; extern crate keccak_hash as hash; extern crate parity_bytes as bytes; extern crate parity_crypto as crypto; extern crate parity_snappy as snappy; extern crate patricia_trie_ethereum as ethtrie; -use rand; -use rlp; -use rmp_serde; extern crate trie_db as trie; extern crate triehash_ethereum as triehash; From 2071f6b149ab0157e1caf4765b70f776dcbd7e39 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 18 May 2025 22:27:48 +0200 Subject: [PATCH 474/687] fix: Add PresignedTransaction and Derive to types module --- crates/rpc/src/v1/mod.rs | 1 + crates/rpc/src/v1/types/mod.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/rpc/src/v1/mod.rs b/crates/rpc/src/v1/mod.rs index 09077b110..b4af8e115 100644 --- a/crates/rpc/src/v1/mod.rs +++ b/crates/rpc/src/v1/mod.rs @@ -34,6 +34,7 @@ mod helpers; mod impls; #[cfg(test)] mod tests; + mod types; pub mod extractors; diff --git a/crates/rpc/src/v1/types/mod.rs b/crates/rpc/src/v1/types/mod.rs index 721d15db7..e0ddaf599 100644 --- a/crates/rpc/src/v1/types/mod.rs +++ b/crates/rpc/src/v1/types/mod.rs @@ -28,8 +28,9 @@ pub use self::{ ConfirmationResponseWithToken, DecryptRequest, EIP191SignRequest, Either, EthSignRequest, TransactionModification, }, - derivation::{DeriveHash, DeriveHierarchical}, + derivation::{Derive, DeriveHash, DeriveHierarchical}, eip191::EIP191Version, + eip191::PresignedTransaction, fee_history::EthFeeHistory, filter::{Filter, FilterChanges}, histogram::Histogram, From 5ec90c499f22cc25a9789fa67905d90e1eb04ec8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 18 May 2025 22:31:13 +0200 Subject: [PATCH 475/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/rpc/src/lib.rs | 1 - crates/rpc/src/v1/types/mod.rs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index 6f84f7a1b..3becca72a 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -97,7 +97,6 @@ extern crate ethcore_call_contract as call_contract; #[cfg(test)] extern crate rpc_servers; - pub extern crate jsonrpc_ws_server as ws; mod authcodes; diff --git a/crates/rpc/src/v1/types/mod.rs b/crates/rpc/src/v1/types/mod.rs index e0ddaf599..7be2e544d 100644 --- a/crates/rpc/src/v1/types/mod.rs +++ b/crates/rpc/src/v1/types/mod.rs @@ -29,8 +29,7 @@ pub use self::{ TransactionModification, }, derivation::{Derive, DeriveHash, DeriveHierarchical}, - eip191::EIP191Version, - eip191::PresignedTransaction, + eip191::{EIP191Version, PresignedTransaction}, fee_history::EthFeeHistory, filter::{Filter, FilterChanges}, histogram::Histogram, From 90d7e138607fcd70b49f2e155d66455611499f86 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 May 2025 11:28:11 +0200 Subject: [PATCH 476/687] fixed missing evm_test imports for tests --- crates/ethcore/src/executive.rs | 2 +- crates/ethcore/src/tests/evm.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index 163b53cd0..0e32ada48 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -1676,7 +1676,7 @@ mod tests { }; use crypto::publickey::{Generator, Random}; use ethereum_types::{Address, BigEndianHash, H160, H256, U256, U512}; - use evm::{Factory, VMType}; + use evm::{evm_test, evm_test_ignore, Factory, VMType}; use rustc_hex::FromHex; use std::{str::FromStr, sync::Arc}; use vm::{ActionParams, ActionValue, CallType, CreateContractAddress, EnvInfo}; diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index 936f27f04..1bd9599be 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -23,7 +23,7 @@ use crate::{ trace::{NoopTracer, NoopVMTracer}, types::transaction::SYSTEM_ADDRESS, }; -use evm::{Factory, VMType}; +use evm::{evm_test, Factory, VMType}; use hash::keccak; use std::sync::Arc; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; From 225c6c0568e64a1245204895f6d0cd5f0a5d8cea Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 19 May 2025 11:30:38 +0200 Subject: [PATCH 477/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/executive.rs | 2 +- crates/ethcore/src/tests/evm.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/executive.rs b/crates/ethcore/src/executive.rs index 0e32ada48..a948b6c99 100644 --- a/crates/ethcore/src/executive.rs +++ b/crates/ethcore/src/executive.rs @@ -1676,7 +1676,7 @@ mod tests { }; use crypto::publickey::{Generator, Random}; use ethereum_types::{Address, BigEndianHash, H160, H256, U256, U512}; - use evm::{evm_test, evm_test_ignore, Factory, VMType}; + use evm::{Factory, VMType, evm_test, evm_test_ignore}; use rustc_hex::FromHex; use std::{str::FromStr, sync::Arc}; use vm::{ActionParams, ActionValue, CallType, CreateContractAddress, EnvInfo}; diff --git a/crates/ethcore/src/tests/evm.rs b/crates/ethcore/src/tests/evm.rs index 1bd9599be..5498888c8 100644 --- a/crates/ethcore/src/tests/evm.rs +++ b/crates/ethcore/src/tests/evm.rs @@ -23,7 +23,7 @@ use crate::{ trace::{NoopTracer, NoopVMTracer}, types::transaction::SYSTEM_ADDRESS, }; -use evm::{evm_test, Factory, VMType}; +use evm::{Factory, VMType, evm_test}; use hash::keccak; use std::sync::Arc; use vm::{AccessList, ActionParams, ActionValue, CallType, EnvInfo, ParamsType}; From 30b3f4c3ecfd4dfd574822dc25648fc641dd4548 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 May 2025 10:46:07 +0200 Subject: [PATCH 478/687] forward compatibility with diamond-node. --- crates/net/network/src/client_version.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index 1de0006df..a95f580bb 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -179,6 +179,7 @@ impl ClientCapabilities for ClientVersion { fn is_parity(client_id: &str) -> bool { client_id.starts_with(LEGACY_CLIENT_ID_PREFIX) || client_id.starts_with(CURRENT_CLIENT_ID_PREFIX) + || client_id.starts_with("diamond-node") // forward compatibilitiy for realease 0.11.x } fn is_nethermind(client_id: &str) -> bool { From 290f3ec08be3427d79462c99bc4b04d3c818a1c1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 May 2025 10:56:43 +0200 Subject: [PATCH 479/687] added logging for trying to send on an expired message. --- crates/net/network-devp2p/src/session.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/net/network-devp2p/src/session.rs b/crates/net/network-devp2p/src/session.rs index 80539be3d..b95f9de64 100644 --- a/crates/net/network-devp2p/src/session.rs +++ b/crates/net/network-devp2p/src/session.rs @@ -325,6 +325,7 @@ impl Session { bail!(ErrorKind::BadProtocol); } if self.expired() { + debug!(target: "network", "Unable to send to expired session"); return Err(ErrorKind::Expired.into()); } let mut i = 0usize; From 37448f45a8e0c474b70ca5b2261c138ab4dd6b89 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 May 2025 11:02:57 +0200 Subject: [PATCH 480/687] Experimental Fix for https://github.com/DMDcoin/diamond-node/issues/209 increased constants for Sending and receiving: MAX_PAYLOAD_SIZE: 256 MB PAYLOAD_SOFT_LIMIT: 64 MB RECEIVE_PAYLOAD: 60 Secs --- crates/net/network-devp2p/src/connection.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/net/network-devp2p/src/connection.rs b/crates/net/network-devp2p/src/connection.rs index 27211d900..739861c4f 100644 --- a/crates/net/network-devp2p/src/connection.rs +++ b/crates/net/network-devp2p/src/connection.rs @@ -41,12 +41,12 @@ use std::{ use tiny_keccak::Keccak; const ENCRYPTED_HEADER_LEN: usize = 32; -const RECEIVE_PAYLOAD: Duration = Duration::from_secs(30); -pub const MAX_PAYLOAD_SIZE: usize = (1 << 24) - 1; +const RECEIVE_PAYLOAD: Duration = Duration::from_secs(60); +pub const MAX_PAYLOAD_SIZE: usize = (1 << 28) - 1; /// Network responses should try not to go over this limit. /// This should be lower than MAX_PAYLOAD_SIZE -pub const PAYLOAD_SOFT_LIMIT: usize = (1 << 22) - 1; +pub const PAYLOAD_SOFT_LIMIT: usize = (1 << 26) - 1; pub trait GenericSocket: Read + Write {} From b402693ce7e1323e0f25f7291eb7e172a439dbf2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 May 2025 19:05:50 +0200 Subject: [PATCH 481/687] improved logging on host duplicates and timeout handling --- crates/net/network-devp2p/src/host.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 4532a3e33..a49a0139f 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -1027,12 +1027,22 @@ impl Host { let handlers = self.handlers.read(); if !ready_data.is_empty() { - let duplicate = self.sessions.read().iter().any(|e| { - let session = e.lock(); - session.token() != token && session.info.id == ready_id - }); - if duplicate { - trace!(target: "network", "Rejected duplicate connection: {}", token); + let duplicates: Vec = self + .sessions + .read() + .iter() + .filter_map(|e| { + let session = e.lock(); + if session.token() != token && session.info.id == ready_id { + return Some(session.token()); + } else { + return None; + } + }) + .collect(); + + if duplicates.len() > 0 { + trace!(target: "network", "Rejected duplicate connection for {:?}: token: {} other connections: {:?}", ready_id, token, duplicates); session .lock() .disconnect(io, DisconnectReason::DuplicatePeer); @@ -1309,7 +1319,10 @@ impl IoHandler for Host { } match token { IDLE => self.maintain_network(io), - FIRST_SESSION..=LAST_SESSION => self.connection_timeout(token, io), + FIRST_SESSION..=LAST_SESSION => { + trace!(target: "network", "Timeout from Host impl: {}", token); + self.connection_timeout(token, io); + } DISCOVERY_REFRESH => { // Run the _slow_ discovery if enough peers are connected if !self.has_enough_peers() { From 03b1e04ac8271f0ff1fe2ae014b0bee865405a24 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 May 2025 19:06:20 +0200 Subject: [PATCH 482/687] receive payload timeout is 60 secs now. --- crates/net/network-devp2p/src/connection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/net/network-devp2p/src/connection.rs b/crates/net/network-devp2p/src/connection.rs index 739861c4f..e564f521c 100644 --- a/crates/net/network-devp2p/src/connection.rs +++ b/crates/net/network-devp2p/src/connection.rs @@ -41,7 +41,7 @@ use std::{ use tiny_keccak::Keccak; const ENCRYPTED_HEADER_LEN: usize = 32; -const RECEIVE_PAYLOAD: Duration = Duration::from_secs(60); +const RECEIVE_PAYLOAD: Duration = Duration::from_secs(600); pub const MAX_PAYLOAD_SIZE: usize = (1 << 28) - 1; /// Network responses should try not to go over this limit. From 2256ef11c35a8c9ef5aa91dbfc8fda999bf65f8a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 May 2025 19:10:17 +0200 Subject: [PATCH 483/687] supplier: trace sync if a block could not get found. --- crates/ethcore/sync/src/chain/supplier.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index d51d9e2a2..b3049efa8 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -22,6 +22,7 @@ use devp2p::PAYLOAD_SOFT_LIMIT; pub const PAYLOAD_SOFT_LIMIT: usize = 100_000; use enum_primitive::FromPrimitive; +use ethcore::trace; use ethereum_types::{H256, H512}; use network::{self, PeerId}; use parking_lot::RwLock; @@ -252,7 +253,11 @@ impl SyncSupplier { } number } - None => return Ok(Some((BlockHeadersPacket, RlpStream::new_list(0)))), //no such header, return nothing + None => { + trace!(target: "sync", "{} -> GetBlockHeaders: no such header {}", peer_id, hash); + //no such header, return nothing + return Ok(Some((BlockHeadersPacket, RlpStream::new_list(0)))); + } } } else { let number = r.val_at::(0)?; From e31004b45c0032638f2c14f80980078203b5853e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 May 2025 20:01:08 +0200 Subject: [PATCH 484/687] experimental: Only download 1 block at maximum. also print the foreign address in the trace print. --- crates/ethcore/sync/src/block_sync.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/sync/src/block_sync.rs b/crates/ethcore/sync/src/block_sync.rs index 7e1a3ccd1..faefa773b 100644 --- a/crates/ethcore/sync/src/block_sync.rs +++ b/crates/ethcore/sync/src/block_sync.rs @@ -602,6 +602,7 @@ impl BlockDownloader { self.retract_step = 1; } } + self.last_round_start = self.last_imported_block; self.last_round_start_hash = self.last_imported_hash; self.imported_this_round = None; @@ -648,9 +649,9 @@ impl BlockDownloader { .blocks .needed_bodies(number_of_bodies_to_request, false); - trace!(target: "sync", "Downloading blocks from Peer {} sync with better chain. needed Bodies: {}, download receipts: {}", peer_id, needed_bodies.len(),self.download_receipts); - if !needed_bodies.is_empty() { + needed_bodies.truncate(1); + trace!(target: "sync", "Downloading blocks from PeerID {} : {}. needed Bodies: {}, download receipts: {}, first body: {}", peer_id, peerID.map_or("unknown", |p| &p.remote_address), needed_bodies.len(),self.download_receipts, needed_bodies[0]); return Some(BlockRequest::Bodies { hashes: needed_bodies, }); @@ -660,6 +661,7 @@ impl BlockDownloader { let needed_receipts = self.blocks.needed_receipts(MAX_RECEPITS_TO_REQUEST, false); if !needed_receipts.is_empty() { + trace!(target: "sync", "Downloading receipts from Peer {}. needed receipts: {}, first receipt: {}", peer_id, needed_receipts.len(), needed_receipts[0]); return Some(BlockRequest::Receipts { hashes: needed_receipts, }); From 9e79795778488f490ed7510aa6c272649055d284 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 May 2025 20:25:26 +0200 Subject: [PATCH 485/687] fixed compile error --- crates/ethcore/sync/src/block_sync.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/sync/src/block_sync.rs b/crates/ethcore/sync/src/block_sync.rs index faefa773b..f5e0f5ffe 100644 --- a/crates/ethcore/sync/src/block_sync.rs +++ b/crates/ethcore/sync/src/block_sync.rs @@ -639,19 +639,20 @@ impl BlockDownloader { // check to see if we need to download any block bodies first let client_version = io.peer_version(peer_id); - let number_of_bodies_to_request = if client_version.can_handle_large_requests() { - MAX_BODIES_TO_REQUEST_LARGE - } else { - MAX_BODIES_TO_REQUEST_SMALL - }; + // let number_of_bodies_to_request = if client_version.can_handle_large_requests() { + // MAX_BODIES_TO_REQUEST_LARGE + // } else { + // MAX_BODIES_TO_REQUEST_SMALL + // }; + + let number_of_bodies_to_request = 1; let needed_bodies = self .blocks .needed_bodies(number_of_bodies_to_request, false); if !needed_bodies.is_empty() { - needed_bodies.truncate(1); - trace!(target: "sync", "Downloading blocks from PeerID {} : {}. needed Bodies: {}, download receipts: {}, first body: {}", peer_id, peerID.map_or("unknown", |p| &p.remote_address), needed_bodies.len(),self.download_receipts, needed_bodies[0]); + trace!(target: "sync", "Downloading blocks from PeerID {} : {}. needed Bodies: {}, download receipts: {}, first body: {}", peer_id, io.peer_session_info(peer_id).map_or("unknown".to_string(), |p| p.remote_address.clone()), needed_bodies.len(),self.download_receipts, needed_bodies[0]); return Some(BlockRequest::Bodies { hashes: needed_bodies, }); From d6472cedf7015cab74a88f6668e9c9b37db6529e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 May 2025 20:27:55 +0200 Subject: [PATCH 486/687] fixed warning --- crates/ethcore/sync/src/block_sync.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ethcore/sync/src/block_sync.rs b/crates/ethcore/sync/src/block_sync.rs index f5e0f5ffe..2b2b9fb20 100644 --- a/crates/ethcore/sync/src/block_sync.rs +++ b/crates/ethcore/sync/src/block_sync.rs @@ -637,7 +637,6 @@ impl BlockDownloader { } State::Blocks => { // check to see if we need to download any block bodies first - let client_version = io.peer_version(peer_id); // let number_of_bodies_to_request = if client_version.can_handle_large_requests() { // MAX_BODIES_TO_REQUEST_LARGE From a808d359dd0fe6acb73b84dde28be0c403a12159 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 21 May 2025 11:55:05 +0200 Subject: [PATCH 487/687] Release Nodes for 3.3.5-hbbft-0.10.1 --- CHANGELOG.md | 5 +++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 983bddefe..c19f91fcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ +## Diamond Node Software 3.3.5-hbbft-0.10.1 + +- Emergency fix to improve blockimports: only one block at a time is now requested throught the devp2p block sync protocol. https://github.com/DMDcoin/diamond-node/issues/209 + + ## Diamond Node Software 3.3.5-hbbft-0.10.0 - Bonus Score finalization diff --git a/Cargo.lock b/Cargo.lock index cf5542252..94d2ab728 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -843,7 +843,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.10.0" +version = "3.3.5-hbbft-0.10.1-rc1" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3575,7 +3575,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.10.0" +version = "3.3.5-hbbft-0.10.1-rc1" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 17792a291..29e6df324 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.10.0" +version = "3.3.5-hbbft-0.10.1-rc1" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 22e62d161..a8cea8b62 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.10.0" +version = "3.3.5-hbbft-0.10.1-rc1" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 260dbb147363669c30ba31fb1839a2562c1f6cc7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 21 May 2025 14:14:26 +0200 Subject: [PATCH 488/687] specified rust version. --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 235c00c63..42a54e848 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ authors = [ "Parity Technologies " ] edition = "2024" +rust-version = "1.85" [dependencies] blooms-db = { path = "crates/db/blooms-db" } From 6c15e444b57297ddf9ac40b032222aa6bb848fbb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 21 May 2025 14:15:26 +0200 Subject: [PATCH 489/687] Changelogs for 3.3.5-hbbft-0.11.0 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c19f91fcd..f2dcc4e6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ +## Diamond Node Software 3.3.5-hbbft-0.11.0 + +- Fixed: Compile error on newer Linux Versions https://github.com/DMDcoin/diamond-node/issues/145 +- rust update to 1.85 and rust edition 2024 https://github.com/DMDcoin/diamond-node/issues/191 +- updated dependencies https://github.com/DMDcoin/diamond-node/issues/107 +- Fixed: Service Transaction not allowed: https://github.com/DMDcoin/diamond-node/issues/185 +- reduced network usage: https://github.com/DMDcoin/diamond-node/issues/163 +- additional prometheus counter and gauges, most of them for analysing https://github.com/DMDcoin/diamond-node/issues/163 +- Improved transaction propagation for clients that are syncing https://github.com/DMDcoin/diamond-node/issues/173 + ## Diamond Node Software 3.3.5-hbbft-0.10.1 - Emergency fix to improve blockimports: only one block at a time is now requested throught the devp2p block sync protocol. https://github.com/DMDcoin/diamond-node/issues/209 From f82c682cf12b300d387dba01ca3658563748abd4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 21 May 2025 14:56:50 +0200 Subject: [PATCH 490/687] Unit tests for latest changes to reduce the maximum number of blocks requested to 1. --- crates/ethcore/sync/src/tests/chain.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/tests/chain.rs b/crates/ethcore/sync/src/tests/chain.rs index 3cc12729b..5447dffc1 100644 --- a/crates/ethcore/sync/src/tests/chain.rs +++ b/crates/ethcore/sync/src/tests/chain.rs @@ -67,7 +67,8 @@ fn takes_few_steps() { net.peer(1).chain.add_blocks(100, EachBlockWith::Uncle); net.peer(2).chain.add_blocks(100, EachBlockWith::Uncle); let total_steps = net.sync(); - assert!(total_steps < 20); + // hotfix for https://github.com/DMDcoin/diamond-node/issues/209 increased the number of steps required to sync. + assert!(total_steps <= 100); } #[test] From 5c1ae72ca4de02f1248c16c1fa4f21d82acf71b7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 21 May 2025 16:04:36 +0200 Subject: [PATCH 491/687] fixed test: takes_few_steps() --- crates/ethcore/sync/src/tests/chain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/tests/chain.rs b/crates/ethcore/sync/src/tests/chain.rs index 5447dffc1..f99b3261a 100644 --- a/crates/ethcore/sync/src/tests/chain.rs +++ b/crates/ethcore/sync/src/tests/chain.rs @@ -68,7 +68,7 @@ fn takes_few_steps() { net.peer(2).chain.add_blocks(100, EachBlockWith::Uncle); let total_steps = net.sync(); // hotfix for https://github.com/DMDcoin/diamond-node/issues/209 increased the number of steps required to sync. - assert!(total_steps <= 100); + assert!(total_steps <= 110); } #[test] From 84aeab5575d617f16a6e3780dae221f1183fe116 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 22 May 2025 11:52:49 +0200 Subject: [PATCH 492/687] adjusted log level for import_external_transactions. --- crates/ethcore/src/miner/miner.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 77e3e4624..96de8eaac 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -1208,8 +1208,8 @@ impl miner::MinerService for Miner { chain: &C, transactions: Vec, ) -> Vec> { - trace!(target: "external_tx", "Importing external transactions"); - info!( + debug!(target: "external_tx", "Importing external transactions"); + trace!(target: "external_tx", "import_external_transactions {:?}", transactions.iter().map(|f| f.hash).collect_vec() ); From 29dcf63351fa50db76f649366b4b95ab21681a2f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 22 May 2025 12:47:31 +0200 Subject: [PATCH 493/687] lowed logging level for Peer {} sent unknown transaction. --- crates/ethcore/sync/src/chain/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index a876cbc7d..9f07546eb 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -964,7 +964,7 @@ impl ChainSync { } Err(unknown_tx) => { // punish peer? - warn!(target: "sync", "Peer {} sent unknown transaction {}", peer_id, unknown_tx); + debug!(target: "sync", "Peer {} sent unknown transaction {}", peer_id, unknown_tx); } } From 9c5bd171d08057869d4f58b83d4574d3983d76fa Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Mon, 26 May 2025 14:41:23 +0200 Subject: [PATCH 494/687] Using the DMDcoin forks of hbbft and threshold_crypto instead of my private forks --- Cargo.lock | 6 +++--- crates/ethcore/Cargo.toml | 4 ++-- .../src/engines/hbbft/hbbft_config_generator/Cargo.toml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 306d3942a..7fa294734 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2125,7 +2125,7 @@ dependencies = [ [[package]] name = "hbbft" version = "0.1.1" -source = "git+https://github.com/dforsten/hbbft?rev=f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd#f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" +source = "git+https://github.com/DMDcoin/hbbft.git?rev=4edcd5cf5f370e6862d6d84d7ae4f05c0eb88074#4edcd5cf5f370e6862d6d84d7ae4f05c0eb88074" dependencies = [ "bincode", "byteorder", @@ -2168,7 +2168,7 @@ dependencies = [ [[package]] name = "hbbft_testing" version = "0.1.0" -source = "git+https://github.com/dforsten/hbbft?rev=f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd#f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" +source = "git+https://github.com/DMDcoin/hbbft.git?rev=4edcd5cf5f370e6862d6d84d7ae4f05c0eb88074#4edcd5cf5f370e6862d6d84d7ae4f05c0eb88074" dependencies = [ "hbbft", "integer-sqrt", @@ -5052,7 +5052,7 @@ dependencies = [ [[package]] name = "threshold_crypto" version = "0.4.0" -source = "git+https://github.com/dforsten/threshold_crypto?rev=776dd301a82036abf6fca60d574197e93e15810e#776dd301a82036abf6fca60d574197e93e15810e" +source = "git+https://github.com/DMDcoin/threshold_crypto.git?rev=5b582c420cf93b75078654ac3df6ec297bfe0371#5b582c420cf93b75078654ac3df6ec297bfe0371" dependencies = [ "byteorder", "ff", diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index 525ea4edd..1d40bf589 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -35,8 +35,8 @@ ethkey = { path = "../accounts/ethkey" } evm = { path = "../vm/evm" } globset = "0.4" hash-db = "0.11.0" -hbbft = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" } -hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" } +hbbft = { git = "https://github.com/DMDcoin/hbbft.git", rev = "4edcd5cf5f370e6862d6d84d7ae4f05c0eb88074" } +hbbft_testing = { git = "https://github.com/DMDcoin/hbbft.git", rev = "4edcd5cf5f370e6862d6d84d7ae4f05c0eb88074" } hex_fmt = "0.3.0" itertools = "0.5" journaldb = { path = "../db/journaldb" } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml index 286b561df..b4b7aa084 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/Cargo.toml @@ -17,8 +17,8 @@ ethjson = { path = "../../../../../ethjson" } ethereum-types = "0.9.2" ethkey = { path = "../../../../../accounts/ethkey" } ethstore = { path = "../../../../../accounts/ethstore"} -hbbft = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" } -hbbft_testing = { git = "https://github.com/dforsten/hbbft", rev = "f1d4c1d6f0714b7f267f84aaafa54c8d572c63bd" } +hbbft = { git = "https://github.com/DMDcoin/hbbft.git", rev = "4edcd5cf5f370e6862d6d84d7ae4f05c0eb88074" } +hbbft_testing = { git = "https://github.com/DMDcoin/hbbft.git", rev = "4edcd5cf5f370e6862d6d84d7ae4f05c0eb88074" } parity-crypto = { version = "0.6.2", features = ["publickey"] } rand = "0.7.3" rustc-hex = "2.1.0" From 7e08cab2300441ce426e5e3ef9fb3c9aa6ea7f86 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 29 May 2025 00:07:32 +0200 Subject: [PATCH 495/687] cargo fix --lib -p parity-rpc --- crates/rpc/src/lib.rs | 7 ------- crates/rpc/src/v1/types/mod.rs | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index 3becca72a..6a56f0556 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -40,26 +40,19 @@ #[macro_use] extern crate futures; -use order_stat; -use tokio_timer; -use jsonrpc_core; extern crate jsonrpc_http_server as http; extern crate jsonrpc_ipc_server as ipc; use jsonrpc_pubsub; extern crate common_types as types; -use ethash; extern crate ethcore_miner as miner; extern crate ethcore_network as network; extern crate ethcore_sync as sync; -use fetch; extern crate keccak_hash as hash; extern crate parity_bytes as bytes; extern crate parity_crypto as crypto; -use parity_runtime; extern crate parity_version as version; -use rlp; #[cfg(any(test, feature = "ethcore-accounts"))] extern crate ethcore_accounts as accounts; diff --git a/crates/rpc/src/v1/types/mod.rs b/crates/rpc/src/v1/types/mod.rs index 7be2e544d..721d15db7 100644 --- a/crates/rpc/src/v1/types/mod.rs +++ b/crates/rpc/src/v1/types/mod.rs @@ -28,8 +28,8 @@ pub use self::{ ConfirmationResponseWithToken, DecryptRequest, EIP191SignRequest, Either, EthSignRequest, TransactionModification, }, - derivation::{Derive, DeriveHash, DeriveHierarchical}, - eip191::{EIP191Version, PresignedTransaction}, + derivation::{DeriveHash, DeriveHierarchical}, + eip191::EIP191Version, fee_history::EthFeeHistory, filter::{Filter, FilterChanges}, histogram::Histogram, From 099a396c25bf0b002f92caf67a682beaf36ffdce Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 29 May 2025 10:28:59 +0200 Subject: [PATCH 496/687] fixed errors created by cargo fix --- crates/rpc/src/lib.rs | 1 - crates/rpc/src/v1/types/mod.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index 6a56f0556..6533b4315 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -40,7 +40,6 @@ #[macro_use] extern crate futures; - extern crate jsonrpc_http_server as http; extern crate jsonrpc_ipc_server as ipc; use jsonrpc_pubsub; diff --git a/crates/rpc/src/v1/types/mod.rs b/crates/rpc/src/v1/types/mod.rs index 721d15db7..7be2e544d 100644 --- a/crates/rpc/src/v1/types/mod.rs +++ b/crates/rpc/src/v1/types/mod.rs @@ -28,8 +28,8 @@ pub use self::{ ConfirmationResponseWithToken, DecryptRequest, EIP191SignRequest, Either, EthSignRequest, TransactionModification, }, - derivation::{DeriveHash, DeriveHierarchical}, - eip191::EIP191Version, + derivation::{Derive, DeriveHash, DeriveHierarchical}, + eip191::{EIP191Version, PresignedTransaction}, fee_history::EthFeeHistory, filter::{Filter, FilterChanges}, histogram::Histogram, From 6b624f1c7605889cd6d088f219064c7459522b12 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 29 May 2025 16:05:47 +0200 Subject: [PATCH 497/687] Zero warnings in diamond-node code --- bin/oe/rpc_apis.rs | 1 + bin/oe/secretstore.rs | 3 ++ bin/oe/signer.rs | 2 -- crates/concensus/ethash/src/shared.rs | 14 +++----- crates/ethcore/blockchain/src/blockchain.rs | 2 +- crates/ethcore/src/client/client.rs | 2 ++ crates/ethcore/src/client/test_client.rs | 1 + .../src/engines/authority_round/mod.rs | 4 +-- .../src/engines/authority_round/util.rs | 2 ++ crates/ethcore/src/engines/clique/mod.rs | 8 +++++ .../engines/hbbft/hbbft_peers_management.rs | 1 + .../src/engines/hbbft/keygen_transactions.rs | 1 + .../src/engines/hbbft/utils/bound_contract.rs | 2 ++ .../hbbft/utils/transactions_shuffling.rs | 3 +- crates/ethcore/src/engines/signer.rs | 2 +- crates/ethcore/src/lib.rs | 10 +----- crates/ethcore/src/miner/stratum.rs | 4 +++ crates/ethcore/src/snapshot/tests/helpers.rs | 2 +- crates/ethcore/src/snapshot/tests/state.rs | 2 +- crates/ethcore/sync/src/block_sync.rs | 4 +-- crates/ethcore/sync/src/chain/supplier.rs | 1 - crates/net/network-devp2p/src/connection.rs | 6 +--- crates/net/network-devp2p/src/node_table.rs | 7 ++-- crates/rpc/src/lib.rs | 36 ++++++++----------- .../helpers/external_signer/signing_queue.rs | 1 + crates/rpc/src/v1/types/derivation.rs | 1 + crates/util/panic-hook/src/lib.rs | 4 +-- crates/vm/evm/src/factory.rs | 1 - crates/vm/wasm/src/lib.rs | 1 - crates/vm/wasm/src/runtime.rs | 1 - 30 files changed, 62 insertions(+), 67 deletions(-) diff --git a/bin/oe/rpc_apis.rs b/bin/oe/rpc_apis.rs index 5fb334749..a024714e5 100644 --- a/bin/oe/rpc_apis.rs +++ b/bin/oe/rpc_apis.rs @@ -214,6 +214,7 @@ pub struct FullDependencies { pub client: Arc, pub snapshot: Arc, pub sync: Arc, + #[allow(dead_code)] pub net: Arc, pub accounts: Arc, pub miner: Arc, diff --git a/bin/oe/secretstore.rs b/bin/oe/secretstore.rs index 7a78c46ef..c000e5cf8 100644 --- a/bin/oe/secretstore.rs +++ b/bin/oe/secretstore.rs @@ -87,6 +87,9 @@ pub struct Configuration { } /// Secret store dependencies +/// TODO: The compiler complains that none of the struct members are ever used +/// Remove this struct and all its dependencies +#[allow(dead_code)] pub struct Dependencies<'a> { /// Blockchain client. pub client: Arc, diff --git a/bin/oe/signer.rs b/bin/oe/signer.rs index 34bf7a004..0630a3d22 100644 --- a/bin/oe/signer.rs +++ b/bin/oe/signer.rs @@ -26,7 +26,6 @@ use ethcore_logger::Config as LogConfig; pub const CODES_FILENAME: &str = "authcodes"; pub struct NewToken { - pub token: String, pub message: String, } @@ -69,7 +68,6 @@ pub fn generate_token_and_url( }; Ok(NewToken { - token: code.clone(), message: format!( r#" Generated token: diff --git a/crates/concensus/ethash/src/shared.rs b/crates/concensus/ethash/src/shared.rs index 4bbd16f5e..f09ed9048 100644 --- a/crates/concensus/ethash/src/shared.rs +++ b/crates/concensus/ethash/src/shared.rs @@ -70,10 +70,6 @@ pub type NodeBytes = [u8; NODE_BYTES]; pub type NodeWords = [u32; NODE_WORDS]; pub type NodeDwords = [u64; NODE_DWORDS]; -unsafe trait AsBigAsUsize: Sized { - const _DUMMY: [(); 0]; -} - macro_rules! static_assert_size_eq { (@inner $a:ty, $b:ty, $($rest:ty),*) => { fn first() { @@ -85,11 +81,11 @@ macro_rules! static_assert_size_eq { } }; (@inner $a:ty, $b:ty) => { - unsafe impl AsBigAsUsize for $a { - #[allow(dead_code)] - const _DUMMY: [(); 0] = - [(); (::std::mem::size_of::<$a>() - ::std::mem::size_of::<$b>())]; - } + // Use const assertion instead of trait implementation + const _: () = assert!( + ::std::mem::size_of::<$a>() == ::std::mem::size_of::<$b>(), + concat!("Size mismatch between ", stringify!($a), " and ", stringify!($b)) + ); }; ($($rest:ty),*) => { static_assert_size_eq!(size_eq: $($rest),*); diff --git a/crates/ethcore/blockchain/src/blockchain.rs b/crates/ethcore/blockchain/src/blockchain.rs index 548cb6478..3176f4950 100644 --- a/crates/ethcore/blockchain/src/blockchain.rs +++ b/crates/ethcore/blockchain/src/blockchain.rs @@ -1573,7 +1573,7 @@ impl BlockChain { } /// Iterator that lists `first` and then all of `first`'s ancestors, by extended header. - pub fn ancestry_with_metadata_iter<'a>(&'a self, first: H256) -> AncestryWithMetadataIter { + pub fn ancestry_with_metadata_iter<'a>(&'a self, first: H256) -> AncestryWithMetadataIter<'a> { AncestryWithMetadataIter { current: if self.is_known(&first) { first diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index f820c37bf..2cd51abe2 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -1416,11 +1416,13 @@ impl Client { self.importer.miner.clone() } + /// Provides read-only access to the `state_db` instance. #[cfg(test)] pub fn state_db(&self) -> ::parking_lot::RwLockReadGuard { self.state_db.read() } + /// Retrieves a cloned instance of the blockchain. #[cfg(test)] pub fn chain(&self) -> Arc { self.chain.read().clone() diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index 4143ede4e..01ae7e4bf 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -426,6 +426,7 @@ impl TestBlockChainClient { self.disabled.load(AtomicOrder::SeqCst) } + /// Sets the producer for new transaction hashes. pub fn set_new_transaction_hashes_producer( &self, new_transaction_hashes: crossbeam_channel::Sender, diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index 997fbe405..9672f8049 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -1093,8 +1093,8 @@ impl AuthorityRound { // fetch correct validator set for epoch at header, taking into account // finality of previous transitions. - fn epoch_set<'a>( - &'a self, + fn epoch_set( + &self, header: &Header, ) -> Result<(CowLike, BlockNumber), Error> { Ok(if self.immediate_transitions { diff --git a/crates/ethcore/src/engines/authority_round/util.rs b/crates/ethcore/src/engines/authority_round/util.rs index f03e4e2c4..d9fb03960 100644 --- a/crates/ethcore/src/engines/authority_round/util.rs +++ b/crates/ethcore/src/engines/authority_round/util.rs @@ -44,8 +44,10 @@ pub struct BoundContract<'a> { #[derive(Debug)] pub enum CallError { /// The call itself failed. + #[allow(dead_code)] CallFailed(String), /// Decoding the return value failed or the decoded value was a failure. + #[allow(dead_code)] DecodeFailed(ethabi::Error), /// The passed in client reference could not be upgraded to a `BlockchainClient`. NotFullClient, diff --git a/crates/ethcore/src/engines/clique/mod.rs b/crates/ethcore/src/engines/clique/mod.rs index d5f03291b..04e024e05 100644 --- a/crates/ethcore/src/engines/clique/mod.rs +++ b/crates/ethcore/src/engines/clique/mod.rs @@ -173,12 +173,20 @@ pub struct Clique { #[cfg(test)] /// Test version of `CliqueEngine` to make all fields public pub struct Clique { + /// Number of blocks that make up an epoch in the Clique consensus algorithm. + /// At each epoch transition, signers/validators can be added or removed. pub epoch_length: u64, + /// The period between blocks in seconds pub period: u64, + /// The Ethereum machine implementation pub machine: EthereumMachine, + /// Reference to the engine client pub client: RwLock>>, + /// Cache of block states indexed by block hash pub block_state_by_hash: RwLock>, + /// Current set of proposals for adding/removing validators pub proposals: RwLock>, + /// Optional engine signer pub signer: RwLock>>, } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 4c134fcde..13836ecb1 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -306,6 +306,7 @@ impl HbbftPeersManagement { /// because those should be current validators by now. /// Make sure to connect to the new current validators, /// before disconnecting from the pending validators. + #[allow(dead_code)] pub fn disconnect_pending_validators( &mut self, client: &dyn BlockChainClient, diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 68740aca4..c4ace544e 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -46,6 +46,7 @@ pub enum KeyGenError { NoSigner, NoFullClient, NoPartToWrite, + #[allow(dead_code)] CallError(CallError), Unexpected, } diff --git a/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs b/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs index a0f4bc392..ff9f2acbe 100644 --- a/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs +++ b/crates/ethcore/src/engines/hbbft/utils/bound_contract.rs @@ -25,8 +25,10 @@ pub struct BoundContract<'a> { #[derive(Debug)] pub enum CallError { /// The call itself failed. + #[allow(dead_code)] CallFailed(String), /// Decoding the return value failed or the decoded value was a failure. + #[allow(dead_code)] DecodeFailed(ethabi::Error), /// The passed in client reference could not be upgraded to a `BlockchainClient`. NotFullClient, diff --git a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs index b1e04ed5e..4ad52feae 100644 --- a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs +++ b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs @@ -25,6 +25,7 @@ fn address_xor_u256(address: &Address, seed: U256) -> Address { } /// The list of transactions is expected to be free of duplicates. +#[allow(dead_code)] fn deterministic_transactions_shuffling( transactions: Vec, seed: U256, @@ -88,8 +89,8 @@ fn deterministic_transactions_shuffling( #[cfg(test)] mod tests { use super::*; - // Convert to bytes in big-endian order. + // Convert to bytes in big-endian order. fn u64_to_bytes_be(n: u64) -> [u8; N] { // Make sure the array is large enough to hold 8 bytes. assert!(N >= 8, "Target array size must be at least 8 bytes"); diff --git a/crates/ethcore/src/engines/signer.rs b/crates/ethcore/src/engines/signer.rs index 2785d499c..0f0d3e3a7 100644 --- a/crates/ethcore/src/engines/signer.rs +++ b/crates/ethcore/src/engines/signer.rs @@ -63,7 +63,7 @@ impl EngineSigner for Signer { #[cfg(test)] mod test_signer { - extern crate ethkey; + use ethkey; use std::sync::Arc; diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index 852bc196e..e2aadb51c 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -34,20 +34,12 @@ extern crate triehash_ethereum as triehash; #[cfg(any(test, feature = "blooms-db"))] extern crate blooms_db; -#[cfg(any(test, feature = "env_logger"))] -extern crate env_logger; #[cfg(test)] extern crate ethcore_accounts as accounts; -#[cfg(feature = "stratum")] -use ethcore_stratum; #[cfg(feature = "json-tests")] extern crate globset; #[cfg(any(test, feature = "kvdb-rocksdb"))] extern crate kvdb_rocksdb; -#[cfg(test)] -extern crate rlp_compress; -#[cfg(any(test, feature = "tempdir"))] -extern crate tempdir; #[cfg(feature = "json-tests")] extern crate tempfile; #[cfg(feature = "json-tests")] @@ -70,7 +62,7 @@ extern crate trace_time; #[macro_use] extern crate serde_derive; -#[cfg_attr(test, macro_use)] +#[cfg(test)] use evm; #[cfg(all(test, feature = "price-info"))] diff --git a/crates/ethcore/src/miner/stratum.rs b/crates/ethcore/src/miner/stratum.rs index b0090565d..f27e0754d 100644 --- a/crates/ethcore/src/miner/stratum.rs +++ b/crates/ethcore/src/miner/stratum.rs @@ -99,9 +99,13 @@ impl SubmitPayload { #[derive(Debug)] enum PayloadError { + #[allow(dead_code)] ArgumentsAmountUnexpected(usize), + #[allow(dead_code)] InvalidNonce(String), + #[allow(dead_code)] InvalidPowHash(String), + #[allow(dead_code)] InvalidMixHash(String), } diff --git a/crates/ethcore/src/snapshot/tests/helpers.rs b/crates/ethcore/src/snapshot/tests/helpers.rs index aa7c3cc74..fb504d8a6 100644 --- a/crates/ethcore/src/snapshot/tests/helpers.rs +++ b/crates/ethcore/src/snapshot/tests/helpers.rs @@ -17,7 +17,7 @@ //! Snapshot test helpers. These are used to build blockchains and state tries //! which can be queried before and after a full snapshot/restore cycle. -extern crate trie_standardmap; +use trie_standardmap; use hash::KECCAK_NULL_RLP; use std::sync::Arc; diff --git a/crates/ethcore/src/snapshot/tests/state.rs b/crates/ethcore/src/snapshot/tests/state.rs index 57fe40f76..9fec345e9 100644 --- a/crates/ethcore/src/snapshot/tests/state.rs +++ b/crates/ethcore/src/snapshot/tests/state.rs @@ -16,7 +16,7 @@ //! State snapshotting tests. -extern crate rand_xorshift; +use rand_xorshift; use hash::{KECCAK_NULL_RLP, keccak}; use std::sync::{Arc, atomic::AtomicBool}; diff --git a/crates/ethcore/sync/src/block_sync.rs b/crates/ethcore/sync/src/block_sync.rs index 5566f8279..732a1f702 100644 --- a/crates/ethcore/sync/src/block_sync.rs +++ b/crates/ethcore/sync/src/block_sync.rs @@ -29,7 +29,7 @@ use ethcore::{ }, }; use ethereum_types::H256; -use network::{PeerId, client_version::ClientCapabilities}; +use network::PeerId; use rlp::{self, Rlp}; use std::cmp; /// @@ -38,8 +38,6 @@ use std::cmp; use std::collections::{BTreeMap, HashSet, VecDeque}; const MAX_HEADERS_TO_REQUEST: usize = 128; -const MAX_BODIES_TO_REQUEST_LARGE: usize = 128; -const MAX_BODIES_TO_REQUEST_SMALL: usize = 32; // Size request for parity clients prior to 2.4.0 const MAX_RECEPITS_TO_REQUEST: usize = 256; const SUBCHAIN_SIZE: u64 = 256; const MAX_ROUND_PARENTS: usize = 16; diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index 2cea479af..ee74734d8 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -23,7 +23,6 @@ pub const PAYLOAD_SOFT_LIMIT: usize = 100_000; use crate::types::{BlockNumber, ids::BlockId}; use enum_primitive::FromPrimitive; -use ethcore::trace; use ethereum_types::{H256, H512}; use network::{self, PeerId}; use parking_lot::RwLock; diff --git a/crates/net/network-devp2p/src/connection.rs b/crates/net/network-devp2p/src/connection.rs index 921dc968d..c268f97fc 100644 --- a/crates/net/network-devp2p/src/connection.rs +++ b/crates/net/network-devp2p/src/connection.rs @@ -306,7 +306,6 @@ pub enum WriteStatus { /// `RLPx` packet pub struct Packet { - pub protocol: u16, pub data: Bytes, } @@ -517,10 +516,7 @@ impl EncryptedConnection { self.decoder .decrypt(&mut payload[..self.payload_len + padding])?; payload.truncate(self.payload_len); - Ok(Packet { - protocol: self.protocol_id, - data: payload, - }) + Ok(Packet { data: payload }) } /// Update MAC after reading or writing any data. diff --git a/crates/net/network-devp2p/src/node_table.rs b/crates/net/network-devp2p/src/node_table.rs index fb2d0ec75..d01fbaf1a 100644 --- a/crates/net/network-devp2p/src/node_table.rs +++ b/crates/net/network-devp2p/src/node_table.rs @@ -111,7 +111,8 @@ impl NodeEndpoint { rlp.append(&(&a.ip().octets()[..])); } SocketAddr::V6(a) => unsafe { - let o: *const u8 = a.ip().segments().as_ptr() as *const u8; + let segments = a.ip().segments(); + let o: *const u8 = segments.as_ptr() as *const u8; rlp.append(&slice::from_raw_parts(o, 16)); }, }; @@ -167,7 +168,6 @@ impl Display for NodeEndpoint { #[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum PeerType { _Required, - Optional, } /// A type for representing an interaction (contact) with a node at a given time @@ -211,7 +211,6 @@ impl NodeContact { pub struct Node { pub id: NodeId, pub endpoint: NodeEndpoint, - pub peer_type: PeerType, pub last_contact: Option, } @@ -220,7 +219,6 @@ impl Node { Node { id, endpoint, - peer_type: PeerType::Optional, last_contact: None, } } @@ -256,7 +254,6 @@ impl FromStr for Node { Ok(Node { id, endpoint, - peer_type: PeerType::Optional, last_contact: None, }) } diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index 6533b4315..6ce82f3fc 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -17,25 +17,22 @@ //! OpenEthereum JSON-RPC Servers (WS, HTTP, IPC). #![warn(missing_docs, unused_extern_crates)] -#![cfg_attr(feature = "cargo-clippy", warn(clippy::all, clippy::pedantic))] -#![cfg_attr( - feature = "cargo-clippy", - allow( - // things are often more readable this way - clippy::cast_lossless, - clippy::module_name_repetitions, - clippy::single_match_else, - clippy::type_complexity, - clippy::use_self, - // not practical - clippy::match_bool, - clippy::needless_pass_by_value, - clippy::similar_names, - // don't require markdown syntax for docs - clippy::doc_markdown, - ), - warn(clippy::indexing_slicing) +#![warn(clippy::all, clippy::pedantic)] +#![allow( + // things are often more readable this way + clippy::cast_lossless, + clippy::module_name_repetitions, + clippy::single_match_else, + clippy::type_complexity, + clippy::use_self, + // not practical + clippy::match_bool, + clippy::needless_pass_by_value, + clippy::similar_names, + // don't require markdown syntax for docs + clippy::doc_markdown, )] +#![warn(clippy::indexing_slicing)] #[macro_use] extern crate futures; @@ -56,9 +53,6 @@ extern crate parity_version as version; #[cfg(any(test, feature = "ethcore-accounts"))] extern crate ethcore_accounts as accounts; -#[cfg(any(test, feature = "ethcore-accounts"))] -extern crate tiny_keccak; - #[macro_use] extern crate log; #[macro_use] diff --git a/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs b/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs index bb86a0f9d..ce09b59fa 100644 --- a/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs +++ b/crates/rpc/src/v1/helpers/external_signer/signing_queue.rs @@ -88,6 +88,7 @@ pub trait SigningQueue: Send + Sync { fn len(&self) -> usize; /// Returns true if there are no requests awaiting confirmation. + #[allow(dead_code)] fn is_empty(&self) -> bool; } diff --git a/crates/rpc/src/v1/types/derivation.rs b/crates/rpc/src/v1/types/derivation.rs index 6b68631be..c89f3ab46 100644 --- a/crates/rpc/src/v1/types/derivation.rs +++ b/crates/rpc/src/v1/types/derivation.rs @@ -75,6 +75,7 @@ impl From for Derive { #[cfg(any(test, feature = "accounts"))] #[derive(Debug)] pub enum ConvertError { + #[allow(dead_code)] IndexOverlfow(u64), } diff --git a/crates/util/panic-hook/src/lib.rs b/crates/util/panic-hook/src/lib.rs index ca23bb0f4..1d1ad414b 100644 --- a/crates/util/panic-hook/src/lib.rs +++ b/crates/util/panic-hook/src/lib.rs @@ -20,7 +20,7 @@ extern crate backtrace; use backtrace::Backtrace; use std::{ - panic::{self, PanicInfo}, + panic::{self, PanicHookInfo}, process, thread, }; @@ -54,7 +54,7 @@ This is a bug. Please report it at: https://github.com/dmdcoin/diamond-node/issues/new "; -fn gen_panic_msg(info: &PanicInfo) -> String { +fn gen_panic_msg(info: &PanicHookInfo) -> String { let location = info.location(); let file = location.as_ref().map(|l| l.file()).unwrap_or(""); let line = location.as_ref().map(|l| l.line()).unwrap_or(0); diff --git a/crates/vm/evm/src/factory.rs b/crates/vm/evm/src/factory.rs index 9fa1e7082..fc353a317 100644 --- a/crates/vm/evm/src/factory.rs +++ b/crates/vm/evm/src/factory.rs @@ -105,7 +105,6 @@ macro_rules! evm_test_ignore( ($name_test: ident: $name_int: ident) => { #[test] #[ignore] - #[cfg(feature = "ignored-tests")] fn $name_int() { $name_test(Factory::new(VMType::Interpreter, 1024 * 32)); } diff --git a/crates/vm/wasm/src/lib.rs b/crates/vm/wasm/src/lib.rs index 7742eddfa..a0770db82 100644 --- a/crates/vm/wasm/src/lib.rs +++ b/crates/vm/wasm/src/lib.rs @@ -132,7 +132,6 @@ impl WasmInterpreter { address: self.params.address, sender: self.params.sender, origin: self.params.origin, - code_address: self.params.code_address, value: self.params.value.value(), }, ); diff --git a/crates/vm/wasm/src/runtime.rs b/crates/vm/wasm/src/runtime.rs index 00bd69235..01b684ad0 100644 --- a/crates/vm/wasm/src/runtime.rs +++ b/crates/vm/wasm/src/runtime.rs @@ -26,7 +26,6 @@ pub struct RuntimeContext { pub address: Address, pub sender: Address, pub origin: Address, - pub code_address: Address, pub value: U256, } From 78904f7a248c062e7d4490ac9354a66e6fcf3d23 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Fri, 30 May 2025 15:02:14 +0200 Subject: [PATCH 498/687] Fixed all warnings reported by cargo check Eliminated redundant check workflow steps using no default features --- .github/workflows/check.yml | 26 ++--------------- bin/ethstore/src/main.rs | 1 - bin/evmbin/src/display/std_json.rs | 12 -------- bin/evmbin/src/main.rs | 1 - crates/db/memory-db/benches/bench.rs | 2 +- .../hbbft/hbbft_config_generator/src/main.rs | 2 -- crates/ethcore/src/lib.rs | 12 -------- crates/ethcore/sync/src/chain/propagator.rs | 3 -- crates/ethcore/sync/src/tests/mod.rs | 5 +--- crates/ethcore/sync/src/tests/rpc.rs | 29 ------------------- crates/net/network/src/client_version.rs | 2 -- crates/rpc/src/lib.rs | 11 ------- crates/rpc/src/v1/helpers/subscribers.rs | 3 +- crates/rpc/src/v1/tests/mocked/eth.rs | 1 + .../rpc/src/v1/tests/mocked/manage_network.rs | 2 +- crates/rpc/src/v1/tests/mocked/signing.rs | 2 ++ .../rpc/src/v1/tests/mocked/signing_unsafe.rs | 2 ++ crates/transaction-pool/src/tests/mod.rs | 1 + 18 files changed, 12 insertions(+), 105 deletions(-) delete mode 100644 crates/ethcore/sync/src/tests/rpc.rs diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d5d88b6e4..966d534a6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -21,30 +21,8 @@ jobs: toolchain: 1.85 profile: minimal override: true - - name: Run cargo check 1/3 + - name: Run cargo check uses: actions-rs/cargo@v1 with: command: check - args: --locked --no-default-features --verbose - - name: Run cargo check 2/3 - uses: actions-rs/cargo@v1 - with: - command: check - args: --locked --manifest-path crates/runtime/io/Cargo.toml --no-default-features --verbose - - name: Run cargo check 3/3 - uses: actions-rs/cargo@v1 - with: - command: check - args: --locked --manifest-path crates/runtime/io/Cargo.toml --features "mio" --verbose - - name: Run cargo check evmbin - uses: actions-rs/cargo@v1 - with: - command: check - args: --locked -p evmbin --verbose - - name: Run cargo check benches - uses: actions-rs/cargo@v1 - with: - command: check - args: --locked --all --benches --verbose - - name: Run validate chainspecs - run: ./scripts/actions/validate-chainspecs.sh + args: --locked --all --benches --verbose --tests diff --git a/bin/ethstore/src/main.rs b/bin/ethstore/src/main.rs index 223e1518c..117be943d 100644 --- a/bin/ethstore/src/main.rs +++ b/bin/ethstore/src/main.rs @@ -17,7 +17,6 @@ extern crate dir; extern crate docopt; extern crate ethstore; -use num_cpus; extern crate panic_hook; extern crate parking_lot; extern crate rustc_hex; diff --git a/bin/evmbin/src/display/std_json.rs b/bin/evmbin/src/display/std_json.rs index 1c569695b..06a08c03b 100644 --- a/bin/evmbin/src/display/std_json.rs +++ b/bin/evmbin/src/display/std_json.rs @@ -26,27 +26,18 @@ use ethereum_types::{BigEndianHash, H256, U256}; pub trait Writer: io::Write + Send + Sized { fn clone(&self) -> Self; - fn default() -> Self; } impl Writer for io::Stdout { fn clone(&self) -> Self { io::stdout() } - - fn default() -> Self { - io::stdout() - } } impl Writer for io::Stderr { fn clone(&self) -> Self { io::stderr() } - - fn default() -> Self { - io::stderr() - } } /// JSON formatting informant. @@ -299,9 +290,6 @@ pub mod tests { fn clone(&self) -> Self { Clone::clone(self) } - fn default() -> Self { - Default::default() - } } impl io::Write for TestWriter { diff --git a/bin/evmbin/src/main.rs b/bin/evmbin/src/main.rs index ac922ff8f..a4e0db760 100644 --- a/bin/evmbin/src/main.rs +++ b/bin/evmbin/src/main.rs @@ -336,7 +336,6 @@ fn run_call(args: Args, informant: T) { #[derive(Debug, Deserialize)] struct Args { - cmd_stats: bool, cmd_state_test: bool, cmd_stats_jsontests_vm: bool, arg_file: Option, diff --git a/crates/db/memory-db/benches/bench.rs b/crates/db/memory-db/benches/bench.rs index 83f73e85b..769ff118d 100644 --- a/crates/db/memory-db/benches/bench.rs +++ b/crates/db/memory-db/benches/bench.rs @@ -44,7 +44,7 @@ fn instantiation(b: &mut Criterion) { fn compare_to_null_embedded_in_struct(b: &mut Criterion) { struct X { a_hash: ::Out, - }; + } let x = X { a_hash: KeccakHasher::hash(&[0u8][..]), }; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 26632d409..5b41a7f63 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -2,8 +2,6 @@ extern crate bincode; #[macro_use] extern crate clap; extern crate ethcore; -use ethereum_types; -use ethjson; extern crate ethkey; extern crate ethstore; extern crate hbbft; diff --git a/crates/ethcore/src/lib.rs b/crates/ethcore/src/lib.rs index e2aadb51c..a453c4324 100644 --- a/crates/ethcore/src/lib.rs +++ b/crates/ethcore/src/lib.rs @@ -36,14 +36,8 @@ extern crate triehash_ethereum as triehash; extern crate blooms_db; #[cfg(test)] extern crate ethcore_accounts as accounts; -#[cfg(feature = "json-tests")] -extern crate globset; #[cfg(any(test, feature = "kvdb-rocksdb"))] extern crate kvdb_rocksdb; -#[cfg(feature = "json-tests")] -extern crate tempfile; -#[cfg(feature = "json-tests")] -extern crate walkdir; #[macro_use] extern crate ethabi_contract; @@ -65,12 +59,6 @@ extern crate serde_derive; #[cfg(test)] use evm; -#[cfg(all(test, feature = "price-info"))] -extern crate fetch; - -#[cfg(all(test, feature = "price-info"))] -extern crate parity_runtime; - pub mod block; pub mod client; pub mod engines; diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index aa26783e1..cefc56098 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -517,18 +517,15 @@ impl ChainSync { mod tests { use crate::{ tests::{helpers::TestIo, snapshot::TestSnapshotService}, - types::transaction::TypedTransaction, }; use ethcore::client::{BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient}; use parking_lot::RwLock; - use rlp::Rlp; use std::collections::VecDeque; use super::{ super::{tests::*, *}, *, }; - use ethcore::ethereum::new_london_test; #[test] fn sends_new_hashes_to_lagging_peer() { diff --git a/crates/ethcore/sync/src/tests/mod.rs b/crates/ethcore/sync/src/tests/mod.rs index cc6d4b357..061e98773 100644 --- a/crates/ethcore/sync/src/tests/mod.rs +++ b/crates/ethcore/sync/src/tests/mod.rs @@ -17,7 +17,4 @@ mod chain; mod consensus; pub mod helpers; -pub mod snapshot; - -#[cfg(feature = "ipc")] -mod rpc; +pub mod snapshot; \ No newline at end of file diff --git a/crates/ethcore/sync/src/tests/rpc.rs b/crates/ethcore/sync/src/tests/rpc.rs deleted file mode 100644 index fd3b1e044..000000000 --- a/crates/ethcore/sync/src/tests/rpc.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015-2020 Parity Technologies (UK) Ltd. -// This file is part of OpenEthereum. - -// OpenEthereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// OpenEthereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with OpenEthereum. If not, see . - -use super::super::NetworkConfiguration; -use ipc::binary::{deserialize, serialize}; -use network::NetworkConfiguration as BasicNetworkConfiguration; -use std::convert::From; - -#[test] -fn network_settings_serialize() { - let net_cfg = NetworkConfiguration::from(BasicNetworkConfiguration::new_local()); - let serialized = serialize(&net_cfg).unwrap(); - let deserialized = deserialize::(&serialized).unwrap(); - - assert_eq!(net_cfg.udp_port, deserialized.udp_port); -} diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index 18514e7a5..c944ed86d 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -#![warn(missing_docs)] - //! Parse ethereum client ID strings and provide querying functionality use semver::{Identifier, Version}; diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index 6ce82f3fc..278f13851 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -58,9 +58,6 @@ extern crate log; #[macro_use] extern crate serde_derive; -#[cfg(test)] -use ethjson; - #[cfg(test)] #[macro_use] extern crate pretty_assertions; @@ -69,20 +66,12 @@ extern crate pretty_assertions; #[macro_use] extern crate macros; -#[cfg(test)] -extern crate fake_fetch; - #[cfg(test)] extern crate ethcore_io as io; #[cfg(test)] extern crate ethcore_call_contract as call_contract; -// #[cfg(test)] - -#[cfg(test)] -extern crate rpc_servers; - pub extern crate jsonrpc_ws_server as ws; mod authcodes; diff --git a/crates/rpc/src/v1/helpers/subscribers.rs b/crates/rpc/src/v1/helpers/subscribers.rs index 1ec424f4a..7cef814f2 100644 --- a/crates/rpc/src/v1/helpers/subscribers.rs +++ b/crates/rpc/src/v1/helpers/subscribers.rs @@ -54,8 +54,7 @@ mod random { #[cfg(test)] mod random { - extern crate rand_xorshift; - use self::rand_xorshift::XorShiftRng; + use rand_xorshift::XorShiftRng; use rand::SeedableRng; const RNG_SEED: [u8; 16] = [0u8; 16]; pub type Rng = XorShiftRng; diff --git a/crates/rpc/src/v1/tests/mocked/eth.rs b/crates/rpc/src/v1/tests/mocked/eth.rs index f7968b936..737d73ce6 100644 --- a/crates/rpc/src/v1/tests/mocked/eth.rs +++ b/crates/rpc/src/v1/tests/mocked/eth.rs @@ -79,6 +79,7 @@ fn snapshot_service() -> Arc { } struct EthTester { + #[allow(dead_code)] pub runtime: Runtime, pub client: Arc, pub sync: Arc, diff --git a/crates/rpc/src/v1/tests/mocked/manage_network.rs b/crates/rpc/src/v1/tests/mocked/manage_network.rs index e032979ea..346d9e8ee 100644 --- a/crates/rpc/src/v1/tests/mocked/manage_network.rs +++ b/crates/rpc/src/v1/tests/mocked/manage_network.rs @@ -21,7 +21,7 @@ use std::{ }; use sync::ManageNetwork; -extern crate ethcore_network; +use ethcore_network; pub struct TestManageNetwork; diff --git a/crates/rpc/src/v1/tests/mocked/signing.rs b/crates/rpc/src/v1/tests/mocked/signing.rs index 4bda77396..2ca444abc 100644 --- a/crates/rpc/src/v1/tests/mocked/signing.rs +++ b/crates/rpc/src/v1/tests/mocked/signing.rs @@ -44,8 +44,10 @@ use parking_lot::Mutex; use serde_json; struct SigningTester { + #[allow(dead_code)] pub runtime: Runtime, pub signer: Arc, + #[allow(dead_code)] pub client: Arc, pub miner: Arc, pub accounts: Arc, diff --git a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs index 3ab1c71b7..02f9e2488 100644 --- a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs +++ b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs @@ -48,7 +48,9 @@ fn miner_service() -> Arc { } struct EthTester { + #[allow(dead_code)] pub runtime: Runtime, + #[allow(dead_code)] pub client: Arc, pub accounts_provider: Arc, pub miner: Arc, diff --git a/crates/transaction-pool/src/tests/mod.rs b/crates/transaction-pool/src/tests/mod.rs index 3e1d87c6a..87b6f9c44 100644 --- a/crates/transaction-pool/src/tests/mod.rs +++ b/crates/transaction-pool/src/tests/mod.rs @@ -60,6 +60,7 @@ pub type SharedTransaction = Arc; type TestPool = Pool; impl TestPool { + /// Creates a new instance with a specified maximum count limit. pub fn with_limit(max_count: usize) -> Self { Self::with_options(Options { max_count, From c1986527b22a7a5234a2c79fb5d99e4691348553 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Fri, 30 May 2025 15:04:56 +0200 Subject: [PATCH 499/687] cargo fmt fixes --- crates/ethcore/sync/src/chain/propagator.rs | 4 +--- crates/ethcore/sync/src/tests/mod.rs | 2 +- crates/rpc/src/v1/helpers/subscribers.rs | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index cefc56098..efa090f70 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -515,9 +515,7 @@ impl ChainSync { #[cfg(test)] mod tests { - use crate::{ - tests::{helpers::TestIo, snapshot::TestSnapshotService}, - }; + use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService}; use ethcore::client::{BlockInfo, ChainInfo, EachBlockWith, TestBlockChainClient}; use parking_lot::RwLock; use std::collections::VecDeque; diff --git a/crates/ethcore/sync/src/tests/mod.rs b/crates/ethcore/sync/src/tests/mod.rs index 061e98773..99ae3cc39 100644 --- a/crates/ethcore/sync/src/tests/mod.rs +++ b/crates/ethcore/sync/src/tests/mod.rs @@ -17,4 +17,4 @@ mod chain; mod consensus; pub mod helpers; -pub mod snapshot; \ No newline at end of file +pub mod snapshot; diff --git a/crates/rpc/src/v1/helpers/subscribers.rs b/crates/rpc/src/v1/helpers/subscribers.rs index 7cef814f2..283b55504 100644 --- a/crates/rpc/src/v1/helpers/subscribers.rs +++ b/crates/rpc/src/v1/helpers/subscribers.rs @@ -54,8 +54,8 @@ mod random { #[cfg(test)] mod random { - use rand_xorshift::XorShiftRng; use rand::SeedableRng; + use rand_xorshift::XorShiftRng; const RNG_SEED: [u8; 16] = [0u8; 16]; pub type Rng = XorShiftRng; pub fn new() -> Rng { From ecca07b322316821beaf71fabdaee94dc9f84aaf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 3 Jun 2025 20:45:32 +0200 Subject: [PATCH 500/687] SyncState caching implementation: https://github.com/DMDcoin/diamond-node/issues/223 --- crates/ethcore/sync/src/chain/mod.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 9f07546eb..4a6f6343d 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -428,6 +428,8 @@ pub struct ChainSyncApi { priority_tasks: Mutex>, /// The rest of sync data sync: RwLock, + /// last known sync state. + last_known_sync_status: Mutex, } impl ChainSyncApi { @@ -439,14 +441,14 @@ impl ChainSyncApi { priority_tasks: mpsc::Receiver, new_transaction_hashes: crossbeam_channel::Receiver, ) -> Self { + let sync = ChainSync::new(config, chain, fork_filter, new_transaction_hashes); + + let last_known_sync_status = sync.status(); + ChainSyncApi { - sync: RwLock::new(ChainSync::new( - config, - chain, - fork_filter, - new_transaction_hashes, - )), + sync: RwLock::new(sync), priority_tasks: Mutex::new(priority_tasks), + last_known_sync_status: Mutex::new(last_known_sync_status), } } @@ -461,9 +463,17 @@ impl ChainSyncApi { ids.iter().map(|id| sync.peer_info(id)).collect() } - /// Returns synchonization status + /// Returns best known synchonization status pub fn status(&self) -> SyncStatus { - self.sync.read().status() + if let Some(sync) = self.sync.try_read_for(Duration::from_millis(50)) { + let status = sync.status(); + *self.last_known_sync_status.lock() = status.clone(); + return status; + } + + // we return that last known sync status here, in cases we could not get the most recent information. + // see also: https://github.com/DMDcoin/diamond-node/issues/223 + return self.last_known_sync_status.lock().clone(); } /// Returns pending transactions propagation statistics From 711f72ed770bc245899214553ca7be54b280d0db Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 3 Jun 2025 21:29:44 +0200 Subject: [PATCH 501/687] release 0.11.1 --- CHANGELOG.md | 3 +++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2dcc4e6c..b02764151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ +## Diamond Node Software 3.3.5-hbbft-0.11.1 + +- caching of SyncStatus to prevent deadlocks https://github.com/DMDcoin/diamond-node/issues/223 ## Diamond Node Software 3.3.5-hbbft-0.11.0 diff --git a/Cargo.lock b/Cargo.lock index 306d3942a..5a26a3cb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -849,7 +849,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.0-rc3" +version = "3.3.5-hbbft-0.11.1" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3583,7 +3583,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.0-rc3" +version = "3.3.5-hbbft-0.11.1" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 42a54e848..eaf62cac7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.0-rc3" +version = "3.3.5-hbbft-0.11.1" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index eae5ca8ef..09c6af133 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.0-rc3" +version = "3.3.5-hbbft-0.11.1" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 4e9d9d945da2af034c3a42fe2729a351f1ff1df3 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 5 Jun 2025 17:33:57 +0200 Subject: [PATCH 502/687] Re-added chainspec tests --- .github/workflows/check.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 966d534a6..249fb15bd 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -26,3 +26,7 @@ jobs: with: command: check args: --locked --all --benches --verbose --tests + - name: Run validate chainspecs + run: ./scripts/actions/validate-chainspecs.sh + args: --locked --all --benches --verbose --tests + From b83b926059df616c68ece9d7f3bf59983d728ac9 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Thu, 5 Jun 2025 17:54:57 +0200 Subject: [PATCH 503/687] Re-added mio io and evmbin checks --- .github/workflows/check.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 249fb15bd..f619b05ed 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -26,6 +26,16 @@ jobs: with: command: check args: --locked --all --benches --verbose --tests + - name: Run cargo check mio io + uses: actions-rs/cargo@v1 + with: + command: check + args: --locked --manifest-path crates/runtime/io/Cargo.toml --features "mio" --verbose + - name: Run cargo check evmbin + uses: actions-rs/cargo@v1 + with: + command: check + args: --locked -p evmbin --verbose - name: Run validate chainspecs run: ./scripts/actions/validate-chainspecs.sh args: --locked --all --benches --verbose --tests From 05984b60b0103e2f900a080db200dd5ea144181d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 11 Jun 2025 21:25:06 +0200 Subject: [PATCH 504/687] panic information is now also in STDOUT available --- bin/oe/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/oe/main.rs b/bin/oe/main.rs index 818a02f86..c3d84b0ca 100644 --- a/bin/oe/main.rs +++ b/bin/oe/main.rs @@ -110,7 +110,7 @@ fn main() -> Result<(), i32> { let e = exit.clone(); let exiting = exiting.clone(); move |panic_msg| { - warn!("Panic occured, see stderr for details"); + warn!("Panic occured! {}", panic_msg); eprintln!("{}", panic_msg); if !exiting.swap(true, Ordering::SeqCst) { *e.0.lock() = ExitStatus::new_panicking(); From 7fef57aba73874e1cd43fef697af136e2cfeb8ac Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 11 Jun 2025 21:35:09 +0200 Subject: [PATCH 505/687] transaction propagation time consumption is now in us vs ms --- crates/ethcore/sync/src/chain/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 4a6f6343d..242c3349e 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -556,9 +556,9 @@ impl ChainSyncApi { // since we already have everything let's use a different deadline // to do the rest of the job now, so that previous work is not wasted. let deadline = Instant::now() + PRIORITY_TASK_DEADLINE; - let as_ms = move |prev| { + let as_us = move |prev| { let dur: Duration = Instant::now() - prev; - dur.as_secs() * 1_000 + dur.subsec_millis() as u64 + dur.as_micros() }; match task { // NOTE We can't simply use existing methods, @@ -583,14 +583,14 @@ impl ChainSyncApi { } } } - debug!(target: "sync", "Finished block propagation, took {}ms", as_ms(started)); + debug!(target: "sync", "Finished block propagation, took {} us", as_us(started)); } PriorityTask::PropagateTransactions(time, _) => { let hashes = sync.new_transaction_hashes(None); sync.propagate_new_transactions(io, hashes, || { check_deadline(deadline).is_some() }); - debug!(target: "sync", "Finished transaction propagation, took {}ms", as_ms(time)); + debug!(target: "sync", "Finished transaction propagation, took {} us", as_us(time)); } } @@ -945,7 +945,9 @@ impl ChainSync { /// Updates transactions were received by a peer pub fn transactions_received(&mut self, txs: &[UnverifiedTransaction], peer_id: PeerId) { debug!(target: "sync", "Received {} transactions from peer {}", txs.len(), peer_id); - trace!(target: "sync", "Received {:?}", txs.iter().map(|t| t.hash).map(|t| t.0).collect::>()); + if !txs.is_empty() { + trace!(target: "sync", "Received {:?}", txs.iter().map(|t| t.hash).map(|t| t.0).collect::>()); + } // Remove imported txs from all request queues let imported = txs.iter().map(|tx| tx.hash()).collect::(); From 5e2cdc15594a17043f30b6da76f976231c6ec856 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 11 Jun 2025 21:39:13 +0200 Subject: [PATCH 506/687] hbbft peers are now managed by an IOChannel, using the message dispatcher pattern, this helps reducing lock stacks. Known Issue: Nonce Calculation does not work anymore. --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 145 +++++----------- .../src/engines/hbbft/hbbft_peers_handler.rs | 159 ++++++++++++++++++ .../engines/hbbft/hbbft_peers_management.rs | 3 + .../ethcore/src/engines/hbbft/hbbft_state.rs | 33 ++-- crates/ethcore/src/engines/hbbft/mod.rs | 1 + crates/ethcore/sync/src/chain/propagator.rs | 3 + 6 files changed, 217 insertions(+), 127 deletions(-) create mode 100644 crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 2583d166d..685e0fd2c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1,6 +1,8 @@ use super::{ block_reward_hbbft::BlockRewardContract, - hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_engine_cache::HbbftEngineCache, + hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, + hbbft_engine_cache::HbbftEngineCache, + hbbft_peers_handler::{self, HbbftConnectToPeersMessage, HbbftPeersHandler}, }; use crate::{ block::ExecutedBlock, @@ -79,6 +81,7 @@ enum Message { /// The Honey Badger BFT Engine. pub struct HoneyBadgerBFT { transition_service: IoService<()>, + hbbft_peers_service: IoService, client: Arc>>>, signer: Arc>>>, machine: EthereumMachine, @@ -91,7 +94,7 @@ pub struct HoneyBadgerBFT { keygen_transaction_sender: RwLock, has_sent_availability_tx: AtomicBool, has_connected_to_validator_set: AtomicBool, - peers_management: Mutex, + //peers_management: Mutex, current_minimum_gas_price: Mutex>, early_epoch_manager: Mutex>, hbbft_engine_cache: Mutex, @@ -275,6 +278,9 @@ impl IoHandler<()> for TransitionHandler { io.register_timer(ENGINE_VALIDATOR_CANDIDATE_ACTIONS, Duration::from_secs(30)) .unwrap_or_else(|e| warn!(target: "consensus", "ENGINE_VALIDATOR_CANDIDATE_ACTIONS Timer failed: {}.", e)); + + // io.channel() + // io.register_stream() } fn timeout(&self, io: &IoContext<()>, timer: TimerToken) { @@ -419,6 +425,9 @@ impl HoneyBadgerBFT { let engine = Arc::new(HoneyBadgerBFT { transition_service: IoService::<()>::start("Hbbft")?, + hbbft_peers_service: IoService::::start( + "peers_management", + )?, client: Arc::new(RwLock::new(None)), signer: Arc::new(RwLock::new(None)), machine, @@ -442,7 +451,6 @@ impl HoneyBadgerBFT { keygen_transaction_sender: RwLock::new(KeygenTransactionSender::new()), has_sent_availability_tx: AtomicBool::new(false), has_connected_to_validator_set: AtomicBool::new(false), - peers_management: Mutex::new(HbbftPeersManagement::new()), current_minimum_gas_price: Mutex::new(None), early_epoch_manager: Mutex::new(None), hbbft_engine_cache: Mutex::new(HbbftEngineCache::new()), @@ -459,6 +467,12 @@ impl HoneyBadgerBFT { .transition_service .register_handler(Arc::new(handler))?; } + + let peers_handler = HbbftPeersHandler::new(engine.client.clone()); + engine + .hbbft_peers_service + .register_handler(Arc::new(peers_handler))?; + Ok(engine) } @@ -921,16 +935,6 @@ impl HoneyBadgerBFT { } } - fn should_handle_internet_address_announcements(&self, client: &dyn BlockChainClient) -> bool { - // this will just called in the next hbbft validator node events again. - // if we don't get a lock, we will just a little be late with announcing our internet address. - if let Some(peers) = self.peers_management.try_lock() { - return peers.should_announce_own_internet_address(client); - } - - false - } - /// early epoch ends /// https://github.com/DMDcoin/diamond-node/issues/87 fn handle_early_epoch_end( @@ -987,7 +991,7 @@ impl HoneyBadgerBFT { // some actions are required for hbbft nodes. // this functions figures out what kind of actions are required and executes them. // this will lock the client and some deeper layers. - fn do_validator_engine_actions(&self) -> Result<(), String> { + fn do_validator_engine_actions(&self) -> Result<(), Error> { // here we need to differentiate the different engine functions, // that requre different levels of access to the client. debug!(target: "engine", "do_validator_engine_actions."); @@ -1030,8 +1034,6 @@ impl HoneyBadgerBFT { let should_handle_availability_announcements = self.should_handle_availability_announcements(); - let should_handle_internet_address_announcements = - self.should_handle_internet_address_announcements(block_chain_client); let should_connect_to_validator_set = self.should_connect_to_validator_set(); let mut should_handle_early_epoch_end = false; @@ -1066,9 +1068,12 @@ impl HoneyBadgerBFT { }; } // drop lock for hbbft_state + self.hbbft_peers_service.send_message( + HbbftConnectToPeersMessage::AnnounceOwnInternetAddress(mining_address), + )?; + // if we do not have to do anything, we can return early. if !(should_handle_availability_announcements - || should_handle_internet_address_announcements || should_connect_to_validator_set || should_handle_early_epoch_end) { @@ -1084,64 +1089,10 @@ impl HoneyBadgerBFT { ); } - // since get latest nonce respects the pending transactions, - // we don't have to take care of sending 2 transactions at once. - if should_handle_internet_address_announcements { - // TODO: - // staking by mining address could be cached. - // but it COULD also get changed in the contracts, during the time the node is running. - // most likely since a Node can get staked, and than it becomes a mining address. - // a good solution for this is not to do this expensive operation that fequently. - let staking_address = match staking_by_mining_address( - engine_client, - &mining_address, - ) { - Ok(staking_address) => { - if staking_address.is_zero() { - //TODO: here some fine handling can improve performance. - //with this implementation every node (validator or not) - //needs to query this state every block. - //trace!(target: "engine", "availability handling not a validator"); - return Ok(()); - } - staking_address - } - Err(call_error) => { - error!(target: "engine", "unable to ask for corresponding staking address for given mining address: {:?}", call_error); - let message = format!( - "unable to ask for corresponding staking address for given mining address: {:?}", - call_error - ); - return Err(message.into()); - } - }; - - if let Some(mut peers_management) = self - .peers_management - .try_lock_for(Duration::from_millis(100)) - { - if let Err(error) = peers_management.announce_own_internet_address( - block_chain_client, - engine_client, - &mining_address, - &staking_address, - ) { - error!(target: "engine", "Error trying to announce own internet address: {:?}", error); - } - } - } - - // TODO: There or more trigger reasons now to access the state. if should_connect_to_validator_set { - if let Some(mut peers_management) = self - .peers_management - .try_lock_for(Duration::from_millis(100)) - { - // connecting to current validators. - peers_management.connect_to_current_validators(&validator_set, &client_arc); - self.has_connected_to_validator_set - .store(true, Ordering::SeqCst); - } + self.hbbft_peers_service.send_message( + HbbftConnectToPeersMessage::ConnectToCurrentPeers(validator_set.clone()), + )?; } if should_handle_early_epoch_end { @@ -1217,30 +1168,10 @@ impl HoneyBadgerBFT { if let Ok(is_pending) = is_pending_validator(&*client, &signer.address()) { trace!(target: "engine", "is_pending_validator: {}", is_pending); if is_pending { - // we are a pending validator, so we need to connect to other pending validators. - // so we start already the required communication channels. - // but this is NOT Mission critical, - // we will connect to the validators when we are in the validator set anyway. - // so we won't lock and wait forever to be able to do this. - if let Some(mut peers_management) = self - .peers_management - .try_lock_for(Duration::from_millis(50)) - { - // problem: this get's called every block, not only when validators become pending. - match peers_management - .connect_to_pending_validators(&client, &validators) - { - Ok(value) => { - if value > 0 { - debug!(target: "engine", "added to additional {:?} reserved peers, because they are pending validators.", value); - } - } - Err(err) => { - warn!(target: "engine", "Error connecting to other pending validators: {:?}", err); - } - } - } else { - warn!(target: "engine", "Could not connect to other pending validators, peers management lock not acquird within time."); + if let Err(err) = self.hbbft_peers_service.send_message( + HbbftConnectToPeersMessage::ConnectToPendingPeers(validators), + ) { + error!(target: "engine", "Error connecting to pending peers: {:?}", err); } let _err = self @@ -1383,7 +1314,7 @@ impl Engine for HoneyBadgerBFT { match state.update_honeybadger( client, &self.signer, - &self.peers_management, + &self.hbbft_peers_service, &self.early_epoch_manager, &self.current_minimum_gas_price, BlockId::Latest, @@ -1405,10 +1336,14 @@ impl Engine for HoneyBadgerBFT { fn set_signer(&self, signer: Option>) { if let Some(engine_signer) = signer.as_ref() { - // this is importamt, we really have to get that lock here. - self.peers_management - .lock() - .set_validator_address(engine_signer.address()); + if let Err(err) = + self.hbbft_peers_service + .send_message(HbbftConnectToPeersMessage::SetSignerAddress( + engine_signer.address(), + )) + { + error!(target: "engine", "Error setting signer address in hbbft peers service: {:?}", err); + } } *self.signer.write() = signer; @@ -1425,7 +1360,7 @@ impl Engine for HoneyBadgerBFT { if let None = self.hbbft_state.write().update_honeybadger( client, &self.signer, - &self.peers_management, + &self.hbbft_peers_service, &self.early_epoch_manager, &self.current_minimum_gas_price, BlockId::Latest, @@ -1647,7 +1582,7 @@ impl Engine for HoneyBadgerBFT { match state.update_honeybadger( client.clone(), &self.signer, - &self.peers_management, + &self.hbbft_peers_service, &self.early_epoch_manager, &self.current_minimum_gas_price, BlockId::Hash(block_hash.clone()), diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs new file mode 100644 index 000000000..cb64966cf --- /dev/null +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs @@ -0,0 +1,159 @@ +use std::sync::{Arc, Weak}; + +use ethereum_types::Address; +use io::IoHandler; +use parking_lot::{Mutex, RwLock}; + +use crate::{client::EngineClient, engines::EngineError, error::Error}; + +use super::{ + NodeId, contracts::validator_set::staking_by_mining_address, + hbbft_peers_management::HbbftPeersManagement, +}; + +pub enum HbbftConnectToPeersMessage { + SetSignerAddress(Address), + ConnectToPendingPeers(Vec
), + ConnectToCurrentPeers(Vec), + AnnounceOwnInternetAddress(Address), + DisconnectAllValidators, +} + +/// IOChannel Wrapper for doing the HbbftPeersManagement asynconous. +pub struct HbbftPeersHandler { + peers_management: Mutex, + client: Arc>>>, +} + +impl HbbftPeersHandler { + pub fn new(client: Arc>>>) -> Self { + Self { + peers_management: Mutex::new(HbbftPeersManagement::new()), + client, + } + } + + fn client_arc(&self) -> Option> { + self.client.read().as_ref().and_then(Weak::upgrade) + } + + fn announce_own_internet_address(&self, mining_address: &Address) -> Result<(), Error> { + info!(target: "engine", "trying to Announce own internet address for mining address: {:?}", mining_address); + + let engine_client = self.client_arc().ok_or(EngineError::RequiresClient)?; + + // TODO: + // staking by mining address could be cached. + // but it COULD also get changed in the contracts, during the time the node is running. + // most likely since a Node can get staked, and than it becomes a mining address. + // a good solution for this is not to do this expensive operation that fequently. + let staking_address = match staking_by_mining_address( + engine_client.as_ref(), + &mining_address, + ) { + Ok(staking_address) => { + if staking_address.is_zero() { + //TODO: here some fine handling can improve performance. + //with this implementation every node (validator or not) + //needs to query this state every block. + //trace!(target: "engine", "availability handling not a validator"); + return Ok(()); + } + staking_address + } + Err(call_error) => { + let message = format!( + "unable to ask for corresponding staking address for given mining address: {:?}", + call_error + ); + error!(target: "engine", "{:?}", message); + + return Err(EngineError::SystemCallResultInvalid(message).into()); + } + }; + + let block_chain_client = engine_client + .as_full_client() + .ok_or("BlockchainClient required")?; + + if let Err(error) = self.peers_management.lock().announce_own_internet_address( + block_chain_client, + engine_client.as_ref(), + &mining_address, + &staking_address, + ) { + error!(target: "engine", "Error trying to announce own internet address: {:?}", error); + } + + info!(target: "engine", "Success: trying to announce own internet address for mining address: {:?}", mining_address); + + return Ok(()); + } +} + +impl IoHandler for HbbftPeersHandler { + fn message( + &self, + _io: &io::IoContext, + message: &HbbftConnectToPeersMessage, + ) { + // we can savely lock the whole peers_management here, because this handler is the only one that locks that data. + + // working peers management is a nice to have, but it is not worth a deadlock. + + if let Some(client_arc) = self.client_arc() { + match message { + HbbftConnectToPeersMessage::ConnectToPendingPeers(peers) => { + match self + .peers_management + .lock() + .connect_to_pending_validators(&client_arc, peers) + { + Ok(value) => { + if value > 0 { + debug!(target: "engine", "Added {:?} reserved peers because they are pending validators.", value); + } + } + Err(err) => { + warn!(target: "engine", "Error connecting to other pending validators: {:?}", err); + } + } + } + HbbftConnectToPeersMessage::ConnectToCurrentPeers(validator_set) => { + // connecting to current validators. + self.peers_management + .lock() + .connect_to_current_validators(validator_set, &client_arc); + } + + HbbftConnectToPeersMessage::AnnounceOwnInternetAddress(mining_address) => { + if let Err(error) = self.announce_own_internet_address(mining_address) { + error!(target: "engine", "Error announcing own internet address: {:?}", error); + } + } + + HbbftConnectToPeersMessage::SetSignerAddress(signer_address) => { + self.peers_management + .lock() + .set_validator_address(signer_address.clone()); + } + + HbbftConnectToPeersMessage::DisconnectAllValidators => { + self.peers_management + .lock() + .disconnect_all_validators(&client_arc); + } + } + } + } +} + +// fn do_keygen_peers_management( +// client: Arc, +// validators: Vec
, +// peers_management: &Mutex, +// ) { +// parity_runtime::tokio::spawn(async move { + +// }); +// } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 13836ecb1..b10a76e23 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -365,6 +365,9 @@ impl HbbftPeersManagement { mining_address: &Address, staking_address: &Address, ) -> Result<(), String> { + if !self.should_announce_own_internet_address(block_chain_client) { + return Ok(()); + } // updates the nodes internet address if the information on the blockchain is outdated. // check if the stored internet address differs from our. diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 60a6bf028..73aee7902 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -11,6 +11,7 @@ use hbbft::{ crypto::{PublicKey, Signature}, honey_badger::{self, HoneyBadgerBuilder}, }; +use io::IoService; use parking_lot::{Mutex, RwLock}; use rand::seq::IteratorRandom; use std::{ @@ -31,6 +32,7 @@ use super::{ contribution::Contribution, hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_network_fork_manager::HbbftNetworkForkManager, + hbbft_peers_handler::HbbftConnectToPeersMessage, hbbft_peers_management::HbbftPeersManagement, }; @@ -94,7 +96,7 @@ impl HbbftState { &mut self, client: Arc, signer: &Arc>>>, - peers_management_mutex: &Mutex, + peers_service: &IoService, early_epoch_end_manager_mutex: &Mutex>, current_minimum_gas_price: &Mutex>, block_id: BlockId, @@ -211,12 +213,9 @@ impl HbbftState { if sks.is_none() { info!(target: "engine", "We are not part of the HoneyBadger validator set - running as regular node."); - // we can disconnect the peers here. - if let Some(mut peers_management) = - peers_management_mutex.try_lock_for(std::time::Duration::from_millis(50)) - { - peers_management.disconnect_all_validators(&client); - } + peers_service + .send_message(HbbftConnectToPeersMessage::DisconnectAllValidators) + .ok()?; return Some(()); } @@ -226,21 +225,11 @@ impl HbbftState { info!(target: "engine", "HoneyBadger Algorithm initialized! Running as validator node."); - // this is importent, but we should not risk deadlocks... - // maybe we should refactor this to a message Queue system, and pass a "connect_to_current_validators" message - if let Some(mut peers_management) = - peers_management_mutex.try_lock_for(std::time::Duration::from_millis(250)) - { - peers_management.connect_to_current_validators(&self.get_validator_set(), &client); - } else { - // maybe we should work with signals that signals that connect_to_current_validators should happen - // instead of trying to achieve a lock here. - // in this case: - // if Node A cannot acquire the lock, but Node B can, then Node B connects to Node A, - // and we are find. - // if both nodes cannot acquire the lock, then we are busted. - warn!(target: "engine", "could not acquire to connect to current validators on switching to new validator set for staking epoch {}.", self.current_posdao_epoch); - } + peers_service + .send_message(HbbftConnectToPeersMessage::ConnectToCurrentPeers( + self.get_validator_set(), + )) + .ok()?; let allowed_devp2p_warmup_time = Duration::from_secs(1200); diff --git a/crates/ethcore/src/engines/hbbft/mod.rs b/crates/ethcore/src/engines/hbbft/mod.rs index df1ce7459..0dec8b4ea 100644 --- a/crates/ethcore/src/engines/hbbft/mod.rs +++ b/crates/ethcore/src/engines/hbbft/mod.rs @@ -6,6 +6,7 @@ mod hbbft_engine; mod hbbft_engine_cache; mod hbbft_message_memorium; mod hbbft_network_fork_manager; +mod hbbft_peers_handler; mod hbbft_peers_management; mod hbbft_state; mod keygen_transactions; diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index efa090f70..74e5c1bb1 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -361,6 +361,9 @@ impl ChainSync { trace!(target: "sync", "Sent latest {} blocks and {} hashes to peers.", blocks, hashes); } } else { + // todo: on HBBFT we do not need to send the new sealed blocks to all validators, because + // they can create them themselves by the Consensus engine. + // t_nb 11.4.3 self.propagate_blocks(&chain_info, io, sealed, &peers); // t_nb 11.4.2 From 9fcc69ae7064264ea0d68bdbf845d402cb535959 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 12 Jun 2025 17:38:31 +0200 Subject: [PATCH 507/687] - Availability announcments are now also handled by the hbbft handler. - IOChannels now require the user the specify the worker threads - removed the extensive lock on the client --- crates/ethcore/service/src/service.rs | 2 +- crates/ethcore/src/client/client.rs | 7 +- crates/ethcore/src/client/test_client.rs | 10 +- crates/ethcore/src/client/traits.rs | 3 +- .../src/engines/authority_round/mod.rs | 2 +- .../engines/hbbft/contracts/validator_set.rs | 26 ++- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 201 +++++++--------- .../src/engines/hbbft/hbbft_peers_handler.rs | 219 ++++++++++++++---- .../ethcore/src/engines/hbbft/hbbft_state.rs | 1 - .../src/engines/hbbft/keygen_transactions.rs | 7 +- crates/ethcore/src/snapshot/service.rs | 2 +- crates/net/network-devp2p/src/service.rs | 2 +- crates/runtime/io/src/lib.rs | 6 +- crates/runtime/io/src/service_mio.rs | 9 +- crates/runtime/io/src/service_non_mio.rs | 7 +- 15 files changed, 305 insertions(+), 199 deletions(-) diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index eef729d4d..62f18d3ec 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -60,7 +60,7 @@ impl ClientService { miner: Arc, shutdown: ShutdownManager, ) -> Result { - let io_service = IoService::::start("Client")?; + let io_service = IoService::::start("Client", 4)?; info!( "Configured for {} using {} engine", diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 2cd51abe2..f514f21f8 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -2917,11 +2917,16 @@ impl BlockChainClient for Client { .import_own_transaction(self, signed.into(), false) } - fn transact_silently(&self, tx_request: TransactionRequest) -> Result<(), transaction::Error> { + fn transact_silently( + &self, + tx_request: TransactionRequest, + ) -> Result { let signed = self.create_transaction(tx_request)?; + let tx_hash = signed.hash(); self.importer .miner .import_own_transaction(self, signed.into(), true) + .map(|_| tx_hash) } fn is_major_syncing(&self) -> bool { diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index 01ae7e4bf..863e82305 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -1106,9 +1106,15 @@ impl BlockChainClient for TestBlockChainClient { .import_own_transaction(self, signed.into(), false) } - fn transact_silently(&self, tx_request: TransactionRequest) -> Result<(), transaction::Error> { + fn transact_silently( + &self, + tx_request: TransactionRequest, + ) -> Result { let signed = self.create_transaction(tx_request)?; - self.miner.import_own_transaction(self, signed.into(), true) + let hash = signed.hash(); + self.miner + .import_own_transaction(self, signed.into(), true) + .map(|_| hash) } fn is_major_syncing(&self) -> bool { diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 369cf65af..bac0e344c 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -529,7 +529,8 @@ pub trait BlockChainClient: /// Same as transact(), but just adding the transaction to the queue, without calling back into the engine. /// Used by engines to queue transactions without causing deadlocks due to re-entrant calls. - fn transact_silently(&self, tx_request: TransactionRequest) -> Result<(), transaction::Error>; + fn transact_silently(&self, tx_request: TransactionRequest) + -> Result; /// Returns true if the chain is currently syncing in major states. fn is_major_syncing(&self) -> bool; diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index 9672f8049..e251edcc4 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -1046,7 +1046,7 @@ impl AuthorityRound { step.calibrate(); let engine = Arc::new(AuthorityRound { - transition_service: IoService::<()>::start("AuRa")?, + transition_service: IoService::<()>::start("AuRa", 4)?, step: Arc::new(PermissionedStep { inner: step, can_propose: AtomicBool::new(true), diff --git a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs index ceb97a700..59632cea9 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs @@ -155,7 +155,7 @@ pub fn set_validator_internet_address( .gas(U256::from(100_000)) .nonce(nonce); - info!(target:"consensus", "set_validator_internet_address: ip: {} nonce: {}", socket_addr, nonce); + info!(target:"consensus", "set_validator_internet_address: ip: {} with nonce: {}", socket_addr, nonce); full_client.transact_silently(transaction)?; Ok(()) } @@ -168,17 +168,18 @@ pub fn send_tx_announce_availability( // we need to get the real latest nonce. //let nonce_from_full_client = full_client.nonce(address,BlockId::Latest); - let mut nonce = full_client.next_nonce(&address); + let nonce = full_client.next_nonce(&address); - match full_client.nonce(address, BlockId::Latest) { - Some(new_nonce) => { - if new_nonce != nonce { - info!(target:"consensus", "got better nonce for announce availability: {} => {}", nonce, new_nonce); - nonce = new_nonce; - } - } - None => {} - } + // match full_client.nonce(address, BlockId::Latest) { + // Some(current_nonce) => { + + // if new_nonce != nonce { + // info!(target:"consensus", "got better nonce for announce availability: {} => {}", nonce, new_nonce); + // nonce = new_nonce; + // } + // } + // None => {} + // } match full_client.block_number(BlockId::Latest) { Some(block_number) => match full_client.block_hash(BlockId::Number(block_number)) { @@ -196,7 +197,8 @@ pub fn send_tx_announce_availability( .nonce(nonce); info!(target:"consensus", "sending announce availability with nonce: {}", nonce); - full_client.transact_silently(transaction)?; + let hash = full_client.transact_silently(transaction)?; + info!(target:"consensus", "sending announce availability with nonce: {} hash: {}", nonce, hash); return Ok(()); } }, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 685e0fd2c..5c45c01da 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -92,7 +92,7 @@ pub struct HoneyBadgerBFT { message_counter: Mutex, random_numbers: RwLock>, keygen_transaction_sender: RwLock, - has_sent_availability_tx: AtomicBool, + has_connected_to_validator_set: AtomicBool, //peers_management: Mutex, current_minimum_gas_price: Mutex>, @@ -260,6 +260,70 @@ impl TransitionHandler { warn!(target: "consensus", "shutdown-on-missing-block-import: Could not read current block number."); } } + + fn handle_engine(&self, io: &IoContext<()>) -> Result<(), Error> { + let client = self + .client + .read() + .as_ref() + .ok_or(EngineError::RequiresClient)? + .upgrade() + .ok_or(EngineError::RequiresClient)?; + + // trace!(target: "consensus", "Honey Badger IoHandler timeout called"); + // The block may be complete, but not have been ready to seal - trigger a new seal attempt. + // TODO: In theory, that should not happen. The seal is ready exactly when the sealing entry is `Complete`. + // if let Some(ref weak) = *self.client.read() { + // if let Some(c) = weak.upgrade() { + // c.update_sealing(ForceUpdateSealing::No); + // shutdown_on_missing_block_import_config = + // c.config_shutdown_on_missing_block_import(); + // } + // } + + client.update_sealing(ForceUpdateSealing::No); + let shutdown_on_missing_block_import_config = + client.config_shutdown_on_missing_block_import(); + + // Periodically allow messages received for future epochs to be processed. + self.engine.replay_cached_messages(); + + self.handle_shutdown_on_missing_block_import(shutdown_on_missing_block_import_config); + + let timer_duration = self.min_block_time_remaining(client.clone()); + + // If the minimum block time has passed we are ready to trigger new blocks. + if timer_duration == Duration::from_secs(0) { + // Always create blocks if we are in the keygen phase. + self.engine.start_hbbft_epoch_if_next_phase(); + + // If the maximum block time has been reached we trigger a new block in any case. + if self.max_block_time_remaining(client.clone()) == Duration::from_secs(0) { + self.engine.start_hbbft_epoch(client); + } + + // Transactions may have been submitted during creation of the last block, trigger the + // creation of a new block if the transaction threshold has been reached. + self.engine.start_hbbft_epoch_if_ready(); + + // Set timer duration to the default period (1s) + timer_duration = DEFAULT_DURATION; + } + + // The duration should be at least 1ms and at most self.engine.params.minimum_block_time + timer_duration = max(timer_duration, Duration::from_millis(1)); + timer_duration = min( + timer_duration, + Duration::from_secs(self.engine.params.minimum_block_time), + ); + + io.register_timer_once(ENGINE_TIMEOUT_TOKEN, timer_duration) + .unwrap_or_else( + |e| warn!(target: "consensus", "Failed to restart consensus step timer: {}.", e), + ); + + Ok(()) + } } impl IoHandler<()> for TransitionHandler { @@ -285,61 +349,9 @@ impl IoHandler<()> for TransitionHandler { fn timeout(&self, io: &IoContext<()>, timer: TimerToken) { if timer == ENGINE_TIMEOUT_TOKEN { - let mut shutdown_on_missing_block_import_config: Option = None; - - // trace!(target: "consensus", "Honey Badger IoHandler timeout called"); - // The block may be complete, but not have been ready to seal - trigger a new seal attempt. - // TODO: In theory, that should not happen. The seal is ready exactly when the sealing entry is `Complete`. - if let Some(ref weak) = *self.client.read() { - if let Some(c) = weak.upgrade() { - c.update_sealing(ForceUpdateSealing::No); - shutdown_on_missing_block_import_config = - c.config_shutdown_on_missing_block_import(); - } - } - - // Periodically allow messages received for future epochs to be processed. - self.engine.replay_cached_messages(); - - self.handle_shutdown_on_missing_block_import(shutdown_on_missing_block_import_config); - - // The client may not be registered yet on startup, we set the default duration. - let mut timer_duration = DEFAULT_DURATION; - if let Some(ref weak) = *self.client.read() { - if let Some(c) = weak.upgrade() { - timer_duration = self.min_block_time_remaining(c.clone()); - - // If the minimum block time has passed we are ready to trigger new blocks. - if timer_duration == Duration::from_secs(0) { - // Always create blocks if we are in the keygen phase. - self.engine.start_hbbft_epoch_if_next_phase(); - - // If the maximum block time has been reached we trigger a new block in any case. - if self.max_block_time_remaining(c.clone()) == Duration::from_secs(0) { - self.engine.start_hbbft_epoch(c); - } - - // Transactions may have been submitted during creation of the last block, trigger the - // creation of a new block if the transaction threshold has been reached. - self.engine.start_hbbft_epoch_if_ready(); - - // Set timer duration to the default period (1s) - timer_duration = DEFAULT_DURATION; - } - - // The duration should be at least 1ms and at most self.engine.params.minimum_block_time - timer_duration = max(timer_duration, Duration::from_millis(1)); - timer_duration = min( - timer_duration, - Duration::from_secs(self.engine.params.minimum_block_time), - ); - } + if let Err(err) = self.handle_engine(io) { + error!(target: "consensus", "Error in Honey Badger Engine timeout handler: {:?}", err); } - - io.register_timer_once(ENGINE_TIMEOUT_TOKEN, timer_duration) - .unwrap_or_else( - |e| warn!(target: "consensus", "Failed to restart consensus step timer: {}.", e), - ); } else if timer == ENGINE_SHUTDOWN { // we do not run this on the first occurence, // the first occurence could mean that the client is not fully set up @@ -424,9 +436,10 @@ impl HoneyBadgerBFT { let is_unit_test = params.is_unit_test.unwrap_or(false); let engine = Arc::new(HoneyBadgerBFT { - transition_service: IoService::<()>::start("Hbbft")?, + transition_service: IoService::<()>::start("Hbbft", 4)?, hbbft_peers_service: IoService::::start( "peers_management", + 1, )?, client: Arc::new(RwLock::new(None)), signer: Arc::new(RwLock::new(None)), @@ -449,7 +462,7 @@ impl HoneyBadgerBFT { message_counter: Mutex::new(0), random_numbers: RwLock::new(BTreeMap::new()), keygen_transaction_sender: RwLock::new(KeygenTransactionSender::new()), - has_sent_availability_tx: AtomicBool::new(false), + has_connected_to_validator_set: AtomicBool::new(false), current_minimum_gas_price: Mutex::new(None), early_epoch_manager: Mutex::new(None), @@ -893,48 +906,10 @@ impl HoneyBadgerBFT { Some(()) } - fn should_handle_availability_announcements(&self) -> bool { - !self.has_sent_availability_tx.load(Ordering::SeqCst) - } - fn should_connect_to_validator_set(&self) -> bool { !self.has_connected_to_validator_set.load(Ordering::SeqCst) } - fn handle_availability_announcements( - &self, - engine_client: &dyn EngineClient, - block_chain_client: &dyn BlockChainClient, - mining_address: &Address, - ) { - // handles the announcements of the availability of other peers as blockchain transactions - - // let engine_client = client.deref(); - - match get_validator_available_since(engine_client, &mining_address) { - Ok(s) => { - if s.is_zero() { - //debug!(target: "engine", "sending announce availability transaction"); - info!(target: "engine", "sending announce availability transaction"); - match send_tx_announce_availability(block_chain_client, &mining_address) { - Ok(()) => {} - Err(call_error) => { - error!(target: "engine", "CallError during announce availability. {:?}", call_error); - } - } - } - - // we store "HAS_SENT" if we SEND, - // or if we are already marked as available. - self.has_sent_availability_tx.store(true, Ordering::SeqCst); - //return Ok(()); - } - Err(e) => { - error!(target: "engine", "Error trying to send availability check: {:?}", e); - } - } - } - /// early epoch ends /// https://github.com/DMDcoin/diamond-node/issues/87 fn handle_early_epoch_end( @@ -1032,9 +1007,6 @@ impl HoneyBadgerBFT { } }; - let should_handle_availability_announcements = - self.should_handle_availability_announcements(); - let should_connect_to_validator_set = self.should_connect_to_validator_set(); let mut should_handle_early_epoch_end = false; @@ -1068,26 +1040,17 @@ impl HoneyBadgerBFT { }; } // drop lock for hbbft_state - self.hbbft_peers_service.send_message( - HbbftConnectToPeersMessage::AnnounceOwnInternetAddress(mining_address), - )?; + self.hbbft_peers_service + .send_message(HbbftConnectToPeersMessage::AnnounceOwnInternetAddress)?; // if we do not have to do anything, we can return early. - if !(should_handle_availability_announcements - || should_connect_to_validator_set - || should_handle_early_epoch_end) - { + if !(should_connect_to_validator_set || should_handle_early_epoch_end) { return Ok(()); } - // if we are not a potential validator, we already have already returned here. - if should_handle_availability_announcements { - self.handle_availability_announcements( - engine_client, - block_chain_client, - &mining_address, - ); - } + self.hbbft_peers_service + .channel() + .send(HbbftConnectToPeersMessage::AnnounceAvailability)?; if should_connect_to_validator_set { self.hbbft_peers_service.send_message( @@ -1336,14 +1299,16 @@ impl Engine for HoneyBadgerBFT { fn set_signer(&self, signer: Option>) { if let Some(engine_signer) = signer.as_ref() { - if let Err(err) = - self.hbbft_peers_service - .send_message(HbbftConnectToPeersMessage::SetSignerAddress( - engine_signer.address(), - )) + let signer_address = engine_signer.address(); + info!(target: "engine", "set_signer: {:?}", signer_address); + if let Err(err) = self + .hbbft_peers_service + .send_message(HbbftConnectToPeersMessage::SetSignerAddress(signer_address)) { error!(target: "engine", "Error setting signer address in hbbft peers service: {:?}", err); } + } else { + info!(target: "engine", "set_signer: signer is None, not setting signer address in hbbft peers service."); } *self.signer.write() = signer; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs index cb64966cf..c53d0640f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs @@ -1,21 +1,31 @@ -use std::sync::{Arc, Weak}; +use std::sync::{ + Arc, Weak, + atomic::{AtomicBool, Ordering}, +}; use ethereum_types::Address; use io::IoHandler; use parking_lot::{Mutex, RwLock}; -use crate::{client::EngineClient, engines::EngineError, error::Error}; +use crate::{ + client::EngineClient, + engines::{EngineError, hbbft::contracts::validator_set::send_tx_announce_availability}, + error::Error, +}; use super::{ - NodeId, contracts::validator_set::staking_by_mining_address, + NodeId, + contracts::validator_set::{get_validator_available_since, staking_by_mining_address}, hbbft_peers_management::HbbftPeersManagement, }; +#[derive(Debug)] pub enum HbbftConnectToPeersMessage { SetSignerAddress(Address), ConnectToPendingPeers(Vec
), ConnectToCurrentPeers(Vec), - AnnounceOwnInternetAddress(Address), + AnnounceOwnInternetAddress, + AnnounceAvailability, DisconnectAllValidators, } @@ -23,24 +33,104 @@ pub enum HbbftConnectToPeersMessage { pub struct HbbftPeersHandler { peers_management: Mutex, client: Arc>>>, + has_sent_availability_tx: AtomicBool, + mining_address: Mutex
, } impl HbbftPeersHandler { pub fn new(client: Arc>>>) -> Self { + // let c = client.read().expect("Client lock is poisoned").upgrade().expect(""); + + // let fullClient = c.as_full_client().expect("Client is not a full client"); + + info!(target: "engine", "Creating HbbftPeersHandler"); + Self { peers_management: Mutex::new(HbbftPeersManagement::new()), client, + has_sent_availability_tx: AtomicBool::new(false), + mining_address: Mutex::new(Address::zero()), // Initialize with zero address, can be set later } } - fn client_arc(&self) -> Option> { - self.client.read().as_ref().and_then(Weak::upgrade) + fn client_arc(&self) -> Result, Error> { + return self + .client + .read() + .as_ref() + .and_then(Weak::upgrade) + .ok_or(EngineError::RequiresClient.into()); + } + + fn get_mining_address(&self) -> Address { + // Lock the mutex to safely access the mining address + return self.mining_address.lock().clone(); + } + + fn announce_availability(&self) -> Result<(), Error> { + if self.has_sent_availability_tx.load(Ordering::SeqCst) { + return Ok(()); + } + + let mining_address = self.get_mining_address(); + + if mining_address.is_zero() { + error!(target: "engine", "Mining address is zero, cannot announce availability."); + return Err( + EngineError::SystemCallResultInvalid("Mining address is zero".to_string()).into(), + ); + } + + let engine_client = self.client_arc()?; + + let block_chain_client = engine_client + .as_full_client() + .ok_or("BlockchainClient required")?; + + match get_validator_available_since(engine_client.as_ref(), &mining_address) { + Ok(s) => { + if s.is_zero() { + //debug!(target: "engine", "sending announce availability transaction"); + info!(target: "engine", "sending announce availability transaction"); + match send_tx_announce_availability(block_chain_client, &mining_address) { + Ok(()) => {} + Err(call_error) => { + error!(target: "engine", "CallError during announce availability. {:?}", call_error); + return Err(EngineError::SystemCallResultInvalid( + "CallError during announce availability".to_string(), + ) + .into()); + } + } + } + + // we store "HAS_SENT" if we SEND, + // or if we are already marked as available. + self.has_sent_availability_tx.store(true, Ordering::SeqCst); + //return Ok(()); + return Ok(()); + } + Err(e) => { + error!(target: "engine", "Error trying to send availability check: {:?}", e); + return Err(EngineError::SystemCallResultInvalid( + "Error trying to send availability check".to_string(), + ) + .into()); + } + } } - fn announce_own_internet_address(&self, mining_address: &Address) -> Result<(), Error> { - info!(target: "engine", "trying to Announce own internet address for mining address: {:?}", mining_address); + fn announce_own_internet_address(&self) -> Result<(), Error> { + let mining_address = self.get_mining_address(); - let engine_client = self.client_arc().ok_or(EngineError::RequiresClient)?; + if mining_address.is_zero() { + error!(target: "engine", "Mining address is zero, will not announce own internet address."); + return Err( + EngineError::SystemCallResultInvalid("Mining address is zero".to_string()).into(), + ); + } + + let engine_client = self.client_arc()?; // TODO: // staking by mining address could be cached. @@ -89,60 +179,89 @@ impl HbbftPeersHandler { return Ok(()); } -} -impl IoHandler for HbbftPeersHandler { - fn message( - &self, - _io: &io::IoContext, - message: &HbbftConnectToPeersMessage, - ) { + fn handle_message(&self, message: &HbbftConnectToPeersMessage) -> Result<(), Error> { // we can savely lock the whole peers_management here, because this handler is the only one that locks that data. // working peers management is a nice to have, but it is not worth a deadlock. - if let Some(client_arc) = self.client_arc() { - match message { - HbbftConnectToPeersMessage::ConnectToPendingPeers(peers) => { - match self - .peers_management - .lock() - .connect_to_pending_validators(&client_arc, peers) - { - Ok(value) => { - if value > 0 { - debug!(target: "engine", "Added {:?} reserved peers because they are pending validators.", value); - } - } - Err(err) => { - warn!(target: "engine", "Error connecting to other pending validators: {:?}", err); + match message { + HbbftConnectToPeersMessage::ConnectToPendingPeers(peers) => { + match self + .peers_management + .lock() + .connect_to_pending_validators(&self.client_arc()?, peers) + { + Ok(value) => { + if value > 0 { + debug!(target: "engine", "Added {:?} reserved peers because they are pending validators.", value); } + return Ok(()); } - } - HbbftConnectToPeersMessage::ConnectToCurrentPeers(validator_set) => { - // connecting to current validators. - self.peers_management - .lock() - .connect_to_current_validators(validator_set, &client_arc); - } - - HbbftConnectToPeersMessage::AnnounceOwnInternetAddress(mining_address) => { - if let Err(error) = self.announce_own_internet_address(mining_address) { - error!(target: "engine", "Error announcing own internet address: {:?}", error); + Err(err) => { + return Err(format!( + "Error connecting to other pending validators: {:?}", + err + ) + .into()); } } + } + HbbftConnectToPeersMessage::ConnectToCurrentPeers(validator_set) => { + // connecting to current validators. + self.peers_management + .lock() + .connect_to_current_validators(validator_set, &self.client_arc()?); + return Ok(()); + } - HbbftConnectToPeersMessage::SetSignerAddress(signer_address) => { - self.peers_management - .lock() - .set_validator_address(signer_address.clone()); + HbbftConnectToPeersMessage::AnnounceOwnInternetAddress => { + if let Err(error) = self.announce_own_internet_address() { + bail!("Error announcing own internet address: {:?}", error); } + return Ok(()); + } + + HbbftConnectToPeersMessage::SetSignerAddress(signer_address) => { + info!(target: "engine", "Setting signer address to: {:?}", signer_address); + *self.mining_address.lock() = signer_address.clone(); + + self.peers_management + .lock() + .set_validator_address(signer_address.clone()); + return Ok(()); + } - HbbftConnectToPeersMessage::DisconnectAllValidators => { - self.peers_management - .lock() - .disconnect_all_validators(&client_arc); + HbbftConnectToPeersMessage::DisconnectAllValidators => { + self.peers_management + .lock() + .disconnect_all_validators(&self.client_arc()?); + return Ok(()); + } + + HbbftConnectToPeersMessage::AnnounceAvailability => { + if let Err(error) = self.announce_availability() { + bail!("Error announcing availability: {:?}", error); } + return Ok(()); + } + } + } +} + +impl IoHandler for HbbftPeersHandler { + fn message( + &self, + _io: &io::IoContext, + message: &HbbftConnectToPeersMessage, + ) { + info!(target: "engine", "Hbbft Queue received message: {:?}", message); + match self.handle_message(message) { + Ok(_) => { + info!(target: "engine", "Hbbft Queue successfully worked message {:?}", message); + } + Err(e) => { + error!(target: "engine", "Error handling HbbftConnectToPeersMessage: {:?} {:?}", message, e); } } } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 73aee7902..2a678f4a1 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -33,7 +33,6 @@ use super::{ hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_network_fork_manager::HbbftNetworkForkManager, hbbft_peers_handler::HbbftConnectToPeersMessage, - hbbft_peers_management::HbbftPeersManagement, }; pub type HbMessage = honey_badger::Message; diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index c4ace544e..6c4e3c051 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -309,9 +309,10 @@ impl KeygenTransactionSender { .nonce(full_client.nonce(&address, BlockId::Latest).unwrap()) .gas_price(U256::from(10000000000u64)); debug!(target: "engine", "sending acks with nonce: {}", acks_transaction.nonce.unwrap()); - full_client + let hash = full_client .transact_silently(acks_transaction) .map_err(|_| CallError::ReturnValueInvalid)?; + debug!(target: "engine", "sending acks tx: {}", hash); } _ => {} } @@ -343,12 +344,14 @@ fn send_part_transaction( .gas(U256::from(gas)) .nonce(nonce) .gas_price(U256::from(10000000000u64)); - full_client + let hash = full_client .transact_silently(part_transaction) .map_err(|e| { warn!(target:"engine", "could not transact_silently: {:?}", e); CallError::ReturnValueInvalid })?; + debug!(target: "engine", "sending part tx: {}", hash); + return Ok(nonce); } diff --git a/crates/ethcore/src/snapshot/service.rs b/crates/ethcore/src/snapshot/service.rs index 144190913..095cb3aa2 100644 --- a/crates/ethcore/src/snapshot/service.rs +++ b/crates/ethcore/src/snapshot/service.rs @@ -1030,7 +1030,7 @@ mod tests { let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; let client = generate_dummy_client_with_spec_and_data(Spec::new_null, 400, 5, &gas_prices, false); - let service = IoService::::start("Test").unwrap(); + let service = IoService::::start("Test", 4).unwrap(); let spec = Spec::new_test(); let tempdir = TempDir::new("").unwrap(); diff --git a/crates/net/network-devp2p/src/service.rs b/crates/net/network-devp2p/src/service.rs index d2dc26db0..644cd83ca 100644 --- a/crates/net/network-devp2p/src/service.rs +++ b/crates/net/network-devp2p/src/service.rs @@ -64,7 +64,7 @@ impl NetworkService { let host_handler = Arc::new(HostHandler { public_url: RwLock::new(None), }); - let io_service = IoService::::start("devp2p")?; + let io_service = IoService::::start("devp2p", 4)?; Ok(NetworkService { io_service, diff --git a/crates/runtime/io/src/lib.rs b/crates/runtime/io/src/lib.rs index 7afa28b06..2344c8092 100644 --- a/crates/runtime/io/src/lib.rs +++ b/crates/runtime/io/src/lib.rs @@ -239,7 +239,7 @@ mod tests { let handler = Arc::new(MyHandler(atomic::AtomicBool::new(false))); let service = - IoService::::start("Test").expect("Error creating network service"); + IoService::::start("Test", 4).expect("Error creating network service"); service.register_handler(handler.clone()).unwrap(); service.send_message(MyMessage { data: 5 }).unwrap(); @@ -270,7 +270,7 @@ mod tests { let handler = Arc::new(MyHandler(atomic::AtomicBool::new(false))); let service = - IoService::::start("Test").expect("Error creating network service"); + IoService::::start("Test", 4).expect("Error creating network service"); service.register_handler(handler.clone()).unwrap(); thread::sleep(Duration::from_secs(2)); @@ -298,7 +298,7 @@ mod tests { let handler = Arc::new(MyHandler(atomic::AtomicUsize::new(0))); let service = - IoService::::start("Test").expect("Error creating network service"); + IoService::::start("Test", 4).expect("Error creating network service"); service.register_handler(handler.clone()).unwrap(); thread::sleep(Duration::from_secs(2)); diff --git a/crates/runtime/io/src/service_mio.rs b/crates/runtime/io/src/service_mio.rs index 7adcfe87c..ee7a726a9 100644 --- a/crates/runtime/io/src/service_mio.rs +++ b/crates/runtime/io/src/service_mio.rs @@ -214,10 +214,10 @@ where symbolic_name: &str, event_loop: &mut EventLoop>, handlers: Arc>>>>, + num_workers: i32, ) -> Result<(), IoError> { let worker = deque::Worker::new_fifo(); let stealer = worker.stealer(); - let num_workers = 4; let work_ready_mutex = Arc::new(Mutex::new(())); let work_ready = Arc::new(Condvar::new()); let workers = (0..num_workers) @@ -537,7 +537,10 @@ where Message: Send + Sync + 'static, { /// Starts IO event loop - pub fn start(symbolic_name: &'static str) -> Result, IoError> { + pub fn start( + symbolic_name: &'static str, + num_workers: i32, + ) -> Result, IoError> { let mut config = EventLoopBuilder::new(); config.messages_per_tick(1024); let mut event_loop = config.build().expect("Error creating event loop"); @@ -545,7 +548,7 @@ where let handlers = Arc::new(RwLock::new(Slab::with_capacity(MAX_HANDLERS))); let h = handlers.clone(); let thread = thread::spawn(move || { - IoManager::::start(symbolic_name, &mut event_loop, h) + IoManager::::start(symbolic_name, &mut event_loop, h, num_workers) .expect("Error starting IO service"); }); Ok(IoService { diff --git a/crates/runtime/io/src/service_non_mio.rs b/crates/runtime/io/src/service_non_mio.rs index d09b71d46..29ae3dfb5 100644 --- a/crates/runtime/io/src/service_non_mio.rs +++ b/crates/runtime/io/src/service_non_mio.rs @@ -266,7 +266,10 @@ where Message: Send + Sync + 'static, { /// Starts IO event loop - pub fn start(_symbolic_name: &'static str) -> Result, IoError> { + pub fn start( + _symbolic_name: &'static str, + num_threads: i32, + ) -> Result, IoError> { // This minimal implementation of IoService does have named Workers // like the mio-dependent one does, so _symbolic_name is ignored. let tx = deque::Worker::new_fifo(); @@ -280,7 +283,7 @@ where channel: Mutex::new(Some(tx)), }); - let thread_joins = (0..num_cpus::get()) + let thread_joins = (0..num_threads) .map(|_| { let rx = rx.clone(); let shared = shared.clone(); From bb2d71fb672f677afda85c89c2a492c92276393a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 12 Jun 2025 17:54:25 +0200 Subject: [PATCH 508/687] fixed timer duration warning --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 5c45c01da..1750c4545 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -290,7 +290,7 @@ impl TransitionHandler { self.handle_shutdown_on_missing_block_import(shutdown_on_missing_block_import_config); - let timer_duration = self.min_block_time_remaining(client.clone()); + let mut timer_duration = self.min_block_time_remaining(client.clone()); // If the minimum block time has passed we are ready to trigger new blocks. if timer_duration == Duration::from_secs(0) { From d036b2b69af76b4320f0476f76b71a70930ad390 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 05:34:12 +0200 Subject: [PATCH 509/687] warning cleanup --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 1750c4545..fc60977b4 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -2,7 +2,7 @@ use super::{ block_reward_hbbft::BlockRewardContract, hbbft_early_epoch_end_manager::HbbftEarlyEpochEndManager, hbbft_engine_cache::HbbftEngineCache, - hbbft_peers_handler::{self, HbbftConnectToPeersMessage, HbbftPeersHandler}, + hbbft_peers_handler::{HbbftConnectToPeersMessage, HbbftPeersHandler}, }; use crate::{ block::ExecutedBlock, @@ -14,7 +14,7 @@ use crate::{ Engine, EngineError, ForkChoice, Seal, SealingState, default_system_or_code_call, hbbft::{ contracts::random_hbbft::set_current_seed_tx_raw, - hbbft_message_memorium::BadSealReason, hbbft_peers_management::HbbftPeersManagement, + hbbft_message_memorium::BadSealReason, }, signer::EngineSigner, }, @@ -59,12 +59,7 @@ use super::{ keygen_transactions::KeygenTransactionSender, sealing::{self, RlpSig, Sealing}, }; -use crate::engines::hbbft::{ - contracts::validator_set::{ - get_validator_available_since, send_tx_announce_availability, staking_by_mining_address, - }, - hbbft_message_memorium::HbbftMessageDispatcher, -}; +use crate::engines::hbbft::hbbft_message_memorium::HbbftMessageDispatcher; use std::{ops::Deref, sync::atomic::Ordering}; type TargetedMessage = hbbft::TargetedMessage; From 333fa151847eec760ccc3dc61718e31e253ac1d2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 06:27:02 +0200 Subject: [PATCH 510/687] updated docs to API changes --- crates/runtime/io/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/runtime/io/src/lib.rs b/crates/runtime/io/src/lib.rs index 2344c8092..842286665 100644 --- a/crates/runtime/io/src/lib.rs +++ b/crates/runtime/io/src/lib.rs @@ -46,7 +46,7 @@ //! } //! //! fn main () { -//! let mut service = IoService::::start("name").expect("Error creating network service"); +//! let mut service = IoService::::start("name", 4).expect("Error creating network service"); //! service.register_handler(Arc::new(MyHandler)).unwrap(); //! //! // Wait for quit condition From 764e2faa8f188b0192d8117f6dfcb7a705a59fe5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 06:42:29 +0200 Subject: [PATCH 511/687] removed num_cpus from service_non_mio --- Cargo.lock | 1 - crates/runtime/io/Cargo.toml | 1 - crates/runtime/io/src/service_non_mio.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fa294734..12c694361 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1405,7 +1405,6 @@ dependencies = [ "futures", "log", "mio", - "num_cpus", "parking_lot 0.11.1", "slab 0.4.2", "time 0.1.45", diff --git a/crates/runtime/io/Cargo.toml b/crates/runtime/io/Cargo.toml index c7abe2895..600b46635 100644 --- a/crates/runtime/io/Cargo.toml +++ b/crates/runtime/io/Cargo.toml @@ -14,7 +14,6 @@ crossbeam-deque = "0.7.4" parking_lot = "0.11.1" log = "0.4" slab = "0.4" -num_cpus = "1.8" timer = "0.2" time = "0.1" tokio = "0.1" diff --git a/crates/runtime/io/src/service_non_mio.rs b/crates/runtime/io/src/service_non_mio.rs index 29ae3dfb5..c61b79fde 100644 --- a/crates/runtime/io/src/service_non_mio.rs +++ b/crates/runtime/io/src/service_non_mio.rs @@ -17,7 +17,6 @@ use crate::{IoError, IoHandler}; use deque; use fnv::FnvHashMap; -use num_cpus; use parking_lot::{Mutex, RwLock}; use slab::Slab; use std::{ From 4565c0bb476ed1eb527e4f2c5892d9c17936ac24 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 06:42:54 +0200 Subject: [PATCH 512/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index fc60977b4..1a5c9e29e 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -13,8 +13,7 @@ use crate::{ engines::{ Engine, EngineError, ForkChoice, Seal, SealingState, default_system_or_code_call, hbbft::{ - contracts::random_hbbft::set_current_seed_tx_raw, - hbbft_message_memorium::BadSealReason, + contracts::random_hbbft::set_current_seed_tx_raw, hbbft_message_memorium::BadSealReason, }, signer::EngineSigner, }, From 9ddf0146cc00c7369ade5684f2cfa117c472b58c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 07:16:32 +0200 Subject: [PATCH 513/687] cleanup --- .../src/engines/hbbft/hbbft_peers_handler.rs | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs index c53d0640f..1535a09f4 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs @@ -29,7 +29,7 @@ pub enum HbbftConnectToPeersMessage { DisconnectAllValidators, } -/// IOChannel Wrapper for doing the HbbftPeersManagement asynconous. +/// IOChannel handler for doing hbbft peers management and hbbft service transactions async. pub struct HbbftPeersHandler { peers_management: Mutex, client: Arc>>>, @@ -39,12 +39,6 @@ pub struct HbbftPeersHandler { impl HbbftPeersHandler { pub fn new(client: Arc>>>) -> Self { - // let c = client.read().expect("Client lock is poisoned").upgrade().expect(""); - - // let fullClient = c.as_full_client().expect("Client is not a full client"); - - info!(target: "engine", "Creating HbbftPeersHandler"); - Self { peers_management: Mutex::new(HbbftPeersManagement::new()), client, @@ -181,9 +175,6 @@ impl HbbftPeersHandler { } fn handle_message(&self, message: &HbbftConnectToPeersMessage) -> Result<(), Error> { - // we can savely lock the whole peers_management here, because this handler is the only one that locks that data. - - // working peers management is a nice to have, but it is not worth a deadlock. match message { HbbftConnectToPeersMessage::ConnectToPendingPeers(peers) => { @@ -255,7 +246,6 @@ impl IoHandler for HbbftPeersHandler { _io: &io::IoContext, message: &HbbftConnectToPeersMessage, ) { - info!(target: "engine", "Hbbft Queue received message: {:?}", message); match self.handle_message(message) { Ok(_) => { info!(target: "engine", "Hbbft Queue successfully worked message {:?}", message); @@ -265,14 +255,4 @@ impl IoHandler for HbbftPeersHandler { } } } -} - -// fn do_keygen_peers_management( -// client: Arc, -// validators: Vec
, -// peers_management: &Mutex, -// ) { -// parity_runtime::tokio::spawn(async move { - -// }); -// } +} \ No newline at end of file From 492d598eba99cda4c1ca79ef7210aac82dc36832 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 07:21:26 +0200 Subject: [PATCH 514/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs index 1535a09f4..d128c7b28 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs @@ -175,7 +175,6 @@ impl HbbftPeersHandler { } fn handle_message(&self, message: &HbbftConnectToPeersMessage) -> Result<(), Error> { - match message { HbbftConnectToPeersMessage::ConnectToPendingPeers(peers) => { match self @@ -255,4 +254,4 @@ impl IoHandler for HbbftPeersHandler { } } } -} \ No newline at end of file +} From b62d68222bac1d4bd175164aab1ce7be1e424189 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 09:11:55 +0200 Subject: [PATCH 515/687] On detecting a deadlock, we are shutting down the Node Software now if the feature "shutdown-on-deadlock" is defined, and is activated as a default feature for now. Shutdowns are now timed to take a maximum of 60 seconds, instead of 300 seconds. https://github.com/DMDcoin/diamond-node/issues/231 Code Infrastructure changes: ShutdownManager is now hosted as an Arc. --- Cargo.toml | 3 ++- bin/oe/blockchain.rs | 10 +++++----- bin/oe/lib.rs | 20 +++++++++++++++++--- bin/oe/run.rs | 6 +++--- bin/oe/snapshot.rs | 2 +- crates/ethcore/service/src/service.rs | 2 +- crates/ethcore/src/client/client.rs | 4 ++-- 7 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 42a54e848..bfb0ae836 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,7 +99,7 @@ lazy_static = "1.2.0" winapi = { version = "0.3.4", features = ["winsock2", "winuser", "shellapi"] } [features] -default = ["accounts"] +default = ["shutdown-on-deadlock", "accounts"] accounts = ["ethcore-accounts", "parity-rpc/accounts"] miner-debug = ["ethcore/miner-debug"] json-tests = ["ethcore/json-tests"] @@ -118,6 +118,7 @@ deadlock_detection = ["parking_lot/deadlock_detection"] # and `massif-visualizer` for visualization memory_profiling = [] secretstore = [] +shutdown-on-deadlock = ["deadlock_detection"] [lib] path = "bin/oe/lib.rs" diff --git a/bin/oe/blockchain.rs b/bin/oe/blockchain.rs index 111d64235..bc2065911 100644 --- a/bin/oe/blockchain.rs +++ b/bin/oe/blockchain.rs @@ -214,7 +214,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> { // TODO [ToDr] don't use test miner here // (actually don't require miner at all) Arc::new(Miner::new_for_tests(&spec, None)), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .map_err(|e| format!("Client service error: {:?}", e))?; @@ -282,7 +282,7 @@ fn start_client( require_fat_db: bool, max_round_blocks_to_import: usize, shutdown_on_missing_block_import: Option, - shutdown: ShutdownManager, + shutdown: Arc, ) -> Result { // load spec file let spec = spec.spec(&dirs.cache)?; @@ -376,7 +376,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result<(), String> { false, cmd.max_round_blocks_to_import, None, - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), )?; let client = service.client(); @@ -407,7 +407,7 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> { true, cmd.max_round_blocks_to_import, None, - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), )?; let client = service.client(); @@ -527,7 +527,7 @@ fn execute_reset(cmd: ResetBlockchain) -> Result<(), String> { false, 0, None, - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), )?; let client = service.client(); diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index 54e7e5004..d6dcbb660 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -146,7 +146,18 @@ fn print_hash_of(maybe_file: Option) -> Result { } #[cfg(feature = "deadlock_detection")] -fn run_deadlock_detection_thread() { +#[cfg(feature = "shutdown-on-deadlock")] +fn on_deadlock_detected(shutdown: &Arc) { + warn!("Deadlock detected, trying to shutdown the node software"); + shutdown.demand_shutdown(); +} + +#[cfg(feature = "deadlock_detection")] +#[cfg(not(feature = "shutdown-on-deadlock"))] +fn on_deadlock_detected(_: &Arc) {} + +#[cfg(feature = "deadlock_detection")] +fn run_deadlock_detection_thread(shutdown: Arc) { use ansi_term::Style; use parking_lot::deadlock; use std::{thread, time::Duration}; @@ -176,6 +187,7 @@ fn run_deadlock_detection_thread() { warn!("{:#?}", t.backtrace()); } } + on_deadlock_detected(&shutdown); } }); @@ -206,12 +218,14 @@ fn execute( logger: Arc, shutdown: ShutdownManager, ) -> Result { + let shutdown_arc = Arc::new(shutdown); + #[cfg(feature = "deadlock_detection")] - run_deadlock_detection_thread(); + run_deadlock_detection_thread(shutdown_arc.clone()); match command.cmd { Cmd::Run(run_cmd) => { - let outcome = run::execute(run_cmd, logger, shutdown)?; + let outcome = run::execute(run_cmd, logger, shutdown_arc)?; Ok(ExecutionAction::Running(outcome)) } Cmd::Version => Ok(ExecutionAction::Instant(Some(Args::print_version()))), diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 4fa79d06f..3a8ae6b6d 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -177,7 +177,7 @@ impl ChainSyncing for SyncProviderWrapper { pub fn execute( cmd: RunCmd, logger: Arc, - shutdown: ShutdownManager, + shutdown: Arc, ) -> Result { // load spec let spec = cmd.spec.spec(&cmd.dirs.cache)?; @@ -755,8 +755,8 @@ fn print_running_environment(data_dir: &str, dirs: &Directories, db_dirs: &Datab fn wait_for_drop(w: Weak) { const SLEEP_DURATION: Duration = Duration::from_secs(1); - const WARN_TIMEOUT: Duration = Duration::from_secs(60); - const MAX_TIMEOUT: Duration = Duration::from_secs(300); + const WARN_TIMEOUT: Duration = Duration::from_secs(30); + const MAX_TIMEOUT: Duration = Duration::from_secs(60); let instant = Instant::now(); let mut warned = false; diff --git a/bin/oe/snapshot.rs b/bin/oe/snapshot.rs index 9b970f705..e56f34cca 100644 --- a/bin/oe/snapshot.rs +++ b/bin/oe/snapshot.rs @@ -241,7 +241,7 @@ impl SnapshotCommand { // TODO [ToDr] don't use test miner here // (actually don't require miner at all) Arc::new(Miner::new_for_tests(&spec, None)), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .map_err(|e| format!("Client service error: {:?}", e))?; diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index 62f18d3ec..8ca197288 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -58,7 +58,7 @@ impl ClientService { restoration_db_handler: Box, _ipc_path: &Path, miner: Arc, - shutdown: ShutdownManager, + shutdown: Arc, ) -> Result { let io_service = IoService::::start("Client", 4)?; diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index f514f21f8..d72be8e09 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -304,7 +304,7 @@ pub struct Client { importer: Importer, - shutdown: ShutdownManager, + shutdown: Arc, statistics: ClientStatistics, } @@ -994,7 +994,7 @@ impl Client { db: Arc, miner: Arc, message_channel: IoChannel, - shutdown: ShutdownManager, + shutdown: Arc, ) -> Result, crate::error::Error> { let trie_spec = match config.fat_db { true => TrieSpec::Fat, From b4627a080103eef9c087669804a96f66f123fc59 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 10:01:40 +0200 Subject: [PATCH 516/687] spawning an addtional thread that does the shutdown in cases the shutdown routine is unable to finish all work, for example because of deadlocks. --- bin/oe/run.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 3a8ae6b6d..691a813d3 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -710,6 +710,24 @@ impl RunningClient { keep_alive, } => { info!("Finishing work, please wait..."); + + // this is a backup thread that exits the process after 90 seconds, + // in case the shutdown routine does not finish in time. + std::thread::Builder::new() + .name("diamond-node-force-quit".to_string()) + .spawn(move || { + // we make a force quit if after 90 seconds, if this shutdown routine + std::thread::sleep(Duration::from_secs(30)); + warn!(target: "shutdown", "shutdown not happened within 30 seconds, waiting for 60 seconds before force exiting the process."); + std::thread::sleep(Duration::from_secs(50)); + warn!(target: "shutdown", "force exit in 10 seconds."); + std::thread::sleep(Duration::from_secs(10)); + warn!(target: "shutdown", "force exiting now."); + std::process::exit(1); + // Wait for the shutdown manager to finish + }) + .expect("Failed to spawn Force shutdown thread"); + // Create a weak reference to the client so that we can wait on shutdown // until it is dropped let weak_client = Arc::downgrade(&client); From e8345cb7f048970186a80871e922d865f8eb686d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 10:28:16 +0200 Subject: [PATCH 517/687] fixed tests: reference for client changed to Arc --- crates/ethcore/service/src/service.rs | 2 +- crates/ethcore/src/json_tests/chain.rs | 2 +- crates/ethcore/src/snapshot/tests/service.rs | 6 +++--- crates/ethcore/src/test_helpers.rs | 4 ++-- crates/ethcore/src/tests/client.rs | 12 ++++++------ crates/ethcore/src/tests/trace.rs | 2 +- crates/ethcore/src/tx_filter.rs | 10 +++++----- crates/ethcore/sync/src/tests/helpers.rs | 2 +- crates/net/node-filter/src/lib.rs | 2 +- crates/rpc/src/v1/tests/eth.rs | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index 8ca197288..175f1157c 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -274,7 +274,7 @@ mod tests { restoration_db_handler, tempdir.path(), Arc::new(Miner::new_for_tests(&spec, None)), - ShutdownManager::null(), + Arc(ShutdownManager::null()), ); assert!(service.is_ok()); drop(service.unwrap()); diff --git a/crates/ethcore/src/json_tests/chain.rs b/crates/ethcore/src/json_tests/chain.rs index ec8481f31..fc18f7f8d 100644 --- a/crates/ethcore/src/json_tests/chain.rs +++ b/crates/ethcore/src/json_tests/chain.rs @@ -203,7 +203,7 @@ pub fn json_chain_test( db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .expect("Failed to instantiate a new Client"); diff --git a/crates/ethcore/src/snapshot/tests/service.rs b/crates/ethcore/src/snapshot/tests/service.rs index a412bb037..fb277a5fe 100644 --- a/crates/ethcore/src/snapshot/tests/service.rs +++ b/crates/ethcore/src/snapshot/tests/service.rs @@ -71,7 +71,7 @@ fn restored_is_equivalent() { blockchain_db, Arc::new(crate::miner::Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); @@ -235,7 +235,7 @@ fn keep_ancient_blocks() { client_db, Arc::new(crate::miner::Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); @@ -324,7 +324,7 @@ fn recover_aborted_recovery() { client_db, Arc::new(crate::miner::Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let service_params = ServiceParams { diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index 9e86a3f07..a191fd411 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -169,7 +169,7 @@ where client_db, Arc::new(miner), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let test_engine = &*test_spec.engine; @@ -377,7 +377,7 @@ pub fn get_test_client_with_blocks(blocks: Vec) -> Arc { client_db, Arc::new(Miner::new_for_tests(&test_spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); diff --git a/crates/ethcore/src/tests/client.rs b/crates/ethcore/src/tests/client.rs index 9c80ccf5f..2e15c2cd2 100644 --- a/crates/ethcore/src/tests/client.rs +++ b/crates/ethcore/src/tests/client.rs @@ -67,7 +67,7 @@ fn imports_from_empty() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); client.import_verified_blocks(); @@ -86,7 +86,7 @@ fn should_return_registrar() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let params = client.additional_params(); @@ -107,7 +107,7 @@ fn imports_good_block() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let good_block = get_good_dummy_block(); @@ -135,7 +135,7 @@ fn query_none_block() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let non_existant = client.block_header(BlockId::Number(188)); @@ -338,7 +338,7 @@ fn change_history_size() { db.clone(), Arc::new(Miner::new_for_tests(&test_spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); @@ -371,7 +371,7 @@ fn change_history_size() { db, Arc::new(Miner::new_for_tests(&test_spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); assert_eq!(client.state().balance(&address).unwrap(), 100.into()); diff --git a/crates/ethcore/src/tests/trace.rs b/crates/ethcore/src/tests/trace.rs index 36ca5a39d..d18526252 100644 --- a/crates/ethcore/src/tests/trace.rs +++ b/crates/ethcore/src/tests/trace.rs @@ -54,7 +54,7 @@ fn can_trace_block_and_uncle_reward() { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); diff --git a/crates/ethcore/src/tx_filter.rs b/crates/ethcore/src/tx_filter.rs index 3684ed68a..69a116b27 100644 --- a/crates/ethcore/src/tx_filter.rs +++ b/crates/ethcore/src/tx_filter.rs @@ -312,7 +312,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let key1 = KeyPair::from_secret( @@ -554,7 +554,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let key1 = KeyPair::from_secret( @@ -623,7 +623,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let key1 = KeyPair::from_secret( @@ -692,7 +692,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let key1 = KeyPair::from_secret( @@ -764,7 +764,7 @@ mod test { db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let key1 = KeyPair::from_secret( diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index 2ec2a4895..a6040f65f 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -451,7 +451,7 @@ impl TestNet> { test_helpers::new_db(), miner.clone(), channel.clone(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); diff --git a/crates/net/node-filter/src/lib.rs b/crates/net/node-filter/src/lib.rs index 94a5a45d0..cd2b55110 100644 --- a/crates/net/node-filter/src/lib.rs +++ b/crates/net/node-filter/src/lib.rs @@ -128,7 +128,7 @@ mod test { client_db, Arc::new(Miner::new_for_tests(&spec, None)), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let filter = NodeFilter::new( diff --git a/crates/rpc/src/v1/tests/eth.rs b/crates/rpc/src/v1/tests/eth.rs index 0edff735a..5bd05dd7f 100644 --- a/crates/rpc/src/v1/tests/eth.rs +++ b/crates/rpc/src/v1/tests/eth.rs @@ -129,7 +129,7 @@ impl EthTester { test_helpers::new_db(), miner_service.clone(), IoChannel::disconnected(), - ShutdownManager::null(), + Arc::new(ShutdownManager::null()), ) .unwrap(); let sync_provider = sync_provider(); From 76c17ebf56aba539bb633491b199284c96fe01f6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 10:40:15 +0200 Subject: [PATCH 518/687] fixed "it_can_be_started" test --- crates/ethcore/service/src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/service/src/service.rs b/crates/ethcore/service/src/service.rs index 175f1157c..9885ea874 100644 --- a/crates/ethcore/service/src/service.rs +++ b/crates/ethcore/service/src/service.rs @@ -274,7 +274,7 @@ mod tests { restoration_db_handler, tempdir.path(), Arc::new(Miner::new_for_tests(&spec, None)), - Arc(ShutdownManager::null()), + Arc::new(ShutdownManager::null()), ); assert!(service.is_ok()); drop(service.unwrap()); From 1f496db1031ac306aeecfa1f7194aeee50434930 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Jun 2025 11:48:16 +0200 Subject: [PATCH 519/687] release 0.11.2 --- CHANGELOG.md | 4 ++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b02764151..6c264c914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Diamond Node Software 3.3.5-hbbft-0.11.2 + +- [shutdown on deadlock](https://github.com/DMDcoin/diamond-node/issues/231) +- [deadlock possibility in reserved peers management](https://github.com/DMDcoin/diamond-node/issues/229) ## Diamond Node Software 3.3.5-hbbft-0.11.1 diff --git a/Cargo.lock b/Cargo.lock index ac8b26f16..cc8122fd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -849,7 +849,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.1" +version = "3.3.5-hbbft-0.11.2-rc1" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3582,7 +3582,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.1" +version = "3.3.5-hbbft-0.11.2-rc1" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 89da8793e..e87a637bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.1" +version = "3.3.5-hbbft-0.11.2-rc1" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 09c6af133..92ed8cf60 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.1" +version = "3.3.5-hbbft-0.11.2-rc1" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 9225b09b5c7f946c13ac917592c8a84691c15c01 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jun 2025 14:55:44 +0200 Subject: [PATCH 520/687] reduced log level of announce internet address transactions --- crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs index d128c7b28..7183d38ba 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs @@ -115,6 +115,12 @@ impl HbbftPeersHandler { } fn announce_own_internet_address(&self) -> Result<(), Error> { + + // todo: + // if the network is unable to process this transaction, + // we are keeping to announce out internet address. + + let mining_address = self.get_mining_address(); if mining_address.is_zero() { @@ -169,7 +175,7 @@ impl HbbftPeersHandler { error!(target: "engine", "Error trying to announce own internet address: {:?}", error); } - info!(target: "engine", "Success: trying to announce own internet address for mining address: {:?}", mining_address); + trace!(target: "engine", "Success: trying to announce own internet address for mining address: {:?}", mining_address); return Ok(()); } From 024dcd4a2c7b9e9fde0d6d7119f03adfd70dad87 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jun 2025 15:18:50 +0200 Subject: [PATCH 521/687] reduced log level of IOHandler for Hbbft Messages --- crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs index 7183d38ba..5105d2585 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs @@ -120,7 +120,7 @@ impl HbbftPeersHandler { // if the network is unable to process this transaction, // we are keeping to announce out internet address. - + let mining_address = self.get_mining_address(); if mining_address.is_zero() { @@ -253,7 +253,7 @@ impl IoHandler for HbbftPeersHandler { ) { match self.handle_message(message) { Ok(_) => { - info!(target: "engine", "Hbbft Queue successfully worked message {:?}", message); + trace!(target: "engine", "Hbbft Queue successfully worked message {:?}", message); } Err(e) => { error!(target: "engine", "Error handling HbbftConnectToPeersMessage: {:?} {:?}", message, e); From dacd88e3288578f40a95a118354def252d4bcf91 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jun 2025 17:08:10 +0200 Subject: [PATCH 522/687] v0.11.2 RC2 - improved logging levels --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc8122fd6..0091c23da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -849,7 +849,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.2-rc1" +version = "3.3.5-hbbft-0.11.2-rc2" dependencies = [ "ansi_term 0.10.2", "atty", diff --git a/Cargo.toml b/Cargo.toml index e87a637bb..355cb51ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.2-rc1" +version = "3.3.5-hbbft-0.11.2-rc2" license = "GPL-3.0" authors = [ "bit.diamonds developers", From c469e1608a114fcbc6db2af2d63520dcd07604a3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 15 Jun 2025 17:33:52 +0200 Subject: [PATCH 523/687] chanoglog formatting --- CHANGELOG.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c264c914..561161902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,17 +5,17 @@ ## Diamond Node Software 3.3.5-hbbft-0.11.1 -- caching of SyncStatus to prevent deadlocks https://github.com/DMDcoin/diamond-node/issues/223 +- [caching of SyncStatus to prevent deadlocks](https://github.com/DMDcoin/diamond-node/issues/223) ## Diamond Node Software 3.3.5-hbbft-0.11.0 -- Fixed: Compile error on newer Linux Versions https://github.com/DMDcoin/diamond-node/issues/145 -- rust update to 1.85 and rust edition 2024 https://github.com/DMDcoin/diamond-node/issues/191 -- updated dependencies https://github.com/DMDcoin/diamond-node/issues/107 -- Fixed: Service Transaction not allowed: https://github.com/DMDcoin/diamond-node/issues/185 -- reduced network usage: https://github.com/DMDcoin/diamond-node/issues/163 -- additional prometheus counter and gauges, most of them for analysing https://github.com/DMDcoin/diamond-node/issues/163 -- Improved transaction propagation for clients that are syncing https://github.com/DMDcoin/diamond-node/issues/173 +- [Fixed: Compile error on newer Linux Versions](https://github.com/DMDcoin/diamond-node/issues/145) +- [rust update to 1.85 and rust edition 2024](https://github.com/DMDcoin/diamond-node/issues/191) +- [updated dependencies](https://github.com/DMDcoin/diamond-node/issues/107) +- [Fixed: Service Transaction not allowed:](https://github.com/DMDcoin/diamond-node/issues/185) +- [reduced network usage:](https://github.com/DMDcoin/diamond-node/issues/163) +- [additional prometheus counter and gauges, most of them for analysing](https://github.com/DMDcoin/diamond-node/issues/163) +- [Improved transaction propagation for clients that are syncing](https://github.com/DMDcoin/diamond-node/issues/173) ## Diamond Node Software 3.3.5-hbbft-0.10.1 From 653b4805cadc47a3e9cdb7f5e726a329617a59cc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Jun 2025 09:57:02 +0200 Subject: [PATCH 524/687] logging improvements --- crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs | 4 +++- crates/net/network-devp2p/src/host.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index b10a76e23..42beb4555 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -157,7 +157,9 @@ impl HbbftPeersManagement { validator_set: &Vec, client_arc: &Arc, ) { - info!(target: "Engine", "adding current validators as reserved peers: {}", validator_set.len()); + if validator_set.len() > 0 { + info!(target: "Engine", "adding current validators as reserved peers: {}", validator_set.len()); + } // todo: iterate over NodeIds, extract the address // we do not need to connect to ourself. // figure out the IP and port from the contracts diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index c0f639417..c503d4bb1 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -970,7 +970,7 @@ impl Host { { if !reserved_nodes.contains(&id) { // only proceed if the connecting peer is reserved. - trace!(target: "network", "Disconnecting non-reserved peer {:?}", id); + trace!(target: "network", "Disconnecting non-reserved peer {:?} (TooManyPeers)", id); s.disconnect(io, DisconnectReason::TooManyPeers); kill = true; break; From 9d65d27e255c87916d289bb95c41ae4b8e4b28d3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Jun 2025 10:36:42 +0200 Subject: [PATCH 525/687] hbbft peers handler: do not announce availability if the chain is syncing. --- crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs index 5105d2585..e847b077f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs @@ -81,6 +81,11 @@ impl HbbftPeersHandler { .as_full_client() .ok_or("BlockchainClient required")?; + + if block_chain_client.is_major_syncing() { + return Ok(()); + } + match get_validator_available_since(engine_client.as_ref(), &mining_address) { Ok(s) => { if s.is_zero() { From c7b5555357379e7405e77ae55999b2b38be2cd20 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Jun 2025 15:40:35 +0200 Subject: [PATCH 526/687] improved reserved peers management logging. --- .../ethcore/src/engines/hbbft/hbbft_peers_management.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 42beb4555..3bc7b5ba3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -158,7 +158,7 @@ impl HbbftPeersManagement { client_arc: &Arc, ) { if validator_set.len() > 0 { - info!(target: "Engine", "adding current validators as reserved peers: {}", validator_set.len()); + debug!(target: "Engine", "adding current validators as reserved peers. potential {}", validator_set.len()); } // todo: iterate over NodeIds, extract the address // we do not need to connect to ourself. @@ -189,7 +189,7 @@ impl HbbftPeersManagement { // validators_to_remove let mut current_validator_connections: Vec = Vec::new(); - + let mut validators_to_connect : Vec = Vec::new(); for node in validator_set.iter() { let address = public_key_to_address(&node.0); @@ -204,6 +204,7 @@ impl HbbftPeersManagement { self.connect_to_validator(client, block_chain_client, &address) { validators_to_remove.remove(&connection.mining_address); + validators_to_connect.push(connection.clone()); current_validator_connections.push(connection); } else { warn!(target: "Engine", "could not add current validator to reserved peers: {}", address); @@ -245,6 +246,10 @@ impl HbbftPeersManagement { // and we have disconnected all previous validators that are not current validators anymore. // so we now can set the information of collected validators. + if validators_to_connect.len() > 0 { + info!(target: "Engine", "added {} current validators as reserved peers.", validators_to_connect.len()); + } + self.connected_current_validators = current_validator_connections; } From f021975dc04a15082198d79c1e3b23b3f55fb1d9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Jun 2025 15:56:08 +0200 Subject: [PATCH 527/687] improved logging of adding reserved peers. --- .../ethcore/src/engines/hbbft/hbbft_peers_management.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 3bc7b5ba3..3db59e6f9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -189,7 +189,7 @@ impl HbbftPeersManagement { // validators_to_remove let mut current_validator_connections: Vec = Vec::new(); - let mut validators_to_connect : Vec = Vec::new(); + let mut validators_to_connect_count = 0; for node in validator_set.iter() { let address = public_key_to_address(&node.0); @@ -204,7 +204,7 @@ impl HbbftPeersManagement { self.connect_to_validator(client, block_chain_client, &address) { validators_to_remove.remove(&connection.mining_address); - validators_to_connect.push(connection.clone()); + validators_to_connect_count += 1; current_validator_connections.push(connection); } else { warn!(target: "Engine", "could not add current validator to reserved peers: {}", address); @@ -246,8 +246,8 @@ impl HbbftPeersManagement { // and we have disconnected all previous validators that are not current validators anymore. // so we now can set the information of collected validators. - if validators_to_connect.len() > 0 { - info!(target: "Engine", "added {} current validators as reserved peers.", validators_to_connect.len()); + if validators_to_connect_count > 0 { + info!(target: "Engine", "added {} current validators as reserved peers.", validators_to_connect_count); } self.connected_current_validators = current_validator_connections; From 4cd9ba893fa24f31f1132af2bc32410bad028c92 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 07:54:04 +0200 Subject: [PATCH 528/687] parking_lot update --- Cargo.lock | 250 ++++++++++++------- Cargo.toml | 2 +- bin/ethstore/Cargo.toml | 2 +- bin/oe/logger/Cargo.toml | 2 +- crates/accounts/Cargo.toml | 2 +- crates/accounts/ethstore/Cargo.toml | 2 +- crates/concensus/ethash/Cargo.toml | 2 +- crates/concensus/miner/Cargo.toml | 2 +- crates/concensus/miner/price-info/Cargo.toml | 2 +- crates/concensus/miner/stratum/Cargo.toml | 2 +- crates/db/blooms-db/Cargo.toml | 2 +- crates/db/db/Cargo.toml | 2 +- crates/db/journaldb/Cargo.toml | 2 +- crates/ethcore/Cargo.toml | 2 +- crates/ethcore/blockchain/Cargo.toml | 2 +- crates/ethcore/sync/Cargo.toml | 2 +- crates/net/network-devp2p/Cargo.toml | 2 +- crates/net/node-filter/Cargo.toml | 2 +- crates/rpc/Cargo.toml | 2 +- crates/runtime/io/Cargo.toml | 2 +- crates/util/cli-signer/rpc-client/Cargo.toml | 2 +- crates/util/len-caching-lock/Cargo.toml | 2 +- crates/vm/evm/Cargo.toml | 2 +- 23 files changed, 180 insertions(+), 114 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0091c23da..2f62a59bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,18 +4,18 @@ version = 4 [[package]] name = "addr2line" -version = "0.14.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "adler32" @@ -110,7 +110,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -158,7 +158,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" dependencies = [ "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -175,9 +175,9 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" [[package]] name = "backtrace" -version = "0.3.56" +version = "0.3.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc" +checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" dependencies = [ "addr2line", "cfg-if 1.0.0", @@ -185,6 +185,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", + "windows-targets 0.52.6", ] [[package]] @@ -326,7 +327,7 @@ dependencies = [ "byteorder", "criterion 0.3.0", "ethbloom 0.9.2", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "tempdir", "tiny-keccak 1.5.0", ] @@ -449,7 +450,7 @@ dependencies = [ "serde", "time 0.1.45", "wasm-bindgen", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -778,7 +779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b37feaa84e6861e00a1f5e5aa8da3ee56d605c9992d33e082786754828e20865" dependencies = [ "nix", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -905,7 +906,7 @@ dependencies = [ "parity-rpc", "parity-runtime", "parity-version", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "pretty_assertions", "prometheus", "regex", @@ -922,7 +923,7 @@ dependencies = [ "term_size", "textwrap 0.9.0", "toml 0.4.10", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -1166,7 +1167,7 @@ dependencies = [ "keccak-hash", "log", "memmap", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "primal", "rustc-hex 1.0.0", "serde_json", @@ -1261,7 +1262,7 @@ dependencies = [ "parity-runtime", "parity-snappy", "parity-util-mem", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "patricia-trie-ethereum", "rand 0.6.5", "rand 0.7.3", @@ -1304,7 +1305,7 @@ dependencies = [ "ethstore", "log", "parity-crypto", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "serde", "serde_derive", "serde_json", @@ -1330,7 +1331,7 @@ dependencies = [ "parity-bytes", "parity-crypto", "parity-util-mem", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "rand 0.7.3", "rayon", "rlp", @@ -1390,7 +1391,7 @@ dependencies = [ "kvdb-memorydb", "kvdb-rocksdb", "parity-util-mem", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "rlp", "rlp-derive 0.2.0", "stats", @@ -1405,7 +1406,7 @@ dependencies = [ "futures", "log", "mio", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "slab 0.4.2", "time 0.1.45", "timer", @@ -1422,7 +1423,7 @@ dependencies = [ "env_logger 0.5.13", "lazy_static", "log", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "regex", "time 0.1.45", ] @@ -1451,7 +1452,7 @@ dependencies = [ "parity-crypto", "parity-runtime", "parity-util-mem", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "price-info", "rlp", "rustc-hex 1.0.0", @@ -1508,7 +1509,7 @@ dependencies = [ "parity-crypto", "parity-path", "parity-snappy", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "rand 0.7.3", "rlp", "rustc-hex 1.0.0", @@ -1550,7 +1551,7 @@ dependencies = [ "jsonrpc-tcp-server", "keccak-hash", "log", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "tokio", "tokio-io", ] @@ -1584,7 +1585,7 @@ dependencies = [ "parity-bytes", "parity-crypto", "parity-util-mem", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "primitive-types 0.7.2", "rand 0.7.3", "rand_xorshift 0.2.0", @@ -1702,7 +1703,7 @@ dependencies = [ "matches", "parity-crypto", "parity-wordlist", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "rand 0.7.3", "rustc-hex 1.0.0", "serde", @@ -1723,7 +1724,7 @@ dependencies = [ "ethstore", "num_cpus", "panic_hook", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "rustc-hex 1.0.0", "serde", "serde_derive", @@ -1746,7 +1747,7 @@ dependencies = [ "num-bigint 0.4.3", "parity-bytes", "parity-util-mem", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "rustc-hex 1.0.0", "vm", ] @@ -1913,7 +1914,7 @@ dependencies = [ "lazy_static", "libc", "libloading", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -1996,9 +1997,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.23.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "globset" @@ -2184,7 +2185,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -2253,7 +2254,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29302b90cfa76231a757a887d1e3153331a63c7f80b6c75f86366334cbe70708" dependencies = [ "scopeguard 0.3.3", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -2263,7 +2264,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3753954f7bd71f0e671afb8b5a992d1724cf43b7f95a563cd4a0bde94659ca8" dependencies = [ "scopeguard 1.1.0", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -2576,7 +2577,7 @@ dependencies = [ "memory-db 0.11.0", "parity-bytes", "parity-util-mem", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "rlp", ] @@ -2804,14 +2805,14 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" name = "len-caching-lock" version = "0.1.1" dependencies = [ - "parking_lot 0.11.1", + "parking_lot 0.11.2", ] [[package]] name = "libc" -version = "0.2.126" +version = "0.2.173" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb" [[package]] name = "libloading" @@ -2820,7 +2821,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" dependencies = [ "cc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -2977,7 +2978,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" dependencies = [ "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3040,12 +3041,11 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.4.4" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" dependencies = [ - "adler", - "autocfg 1.0.0", + "adler2", ] [[package]] @@ -3088,7 +3088,7 @@ dependencies = [ "log", "mio", "miow 0.3.7", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3120,7 +3120,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3137,7 +3137,7 @@ checksum = "74d0df99cfcd2530b2e694f6e17e7f37b8e26bb23983ac530c0c97408837c631" dependencies = [ "cfg-if 0.1.10", "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3166,7 +3166,7 @@ dependencies = [ "kvdb-memorydb", "log", "lru-cache", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "tempdir", ] @@ -3246,9 +3246,12 @@ dependencies = [ [[package]] name = "object" -version = "0.23.0" +version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] [[package]] name = "oe-rpc-common" @@ -3456,7 +3459,7 @@ dependencies = [ "parity-crypto", "parity-runtime", "parity-version", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "pretty_assertions", "rand 0.7.3", "rand_xorshift 0.2.0", @@ -3486,7 +3489,7 @@ dependencies = [ "log", "matches", "parity-rpc", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "serde", "serde_json", "url 2.1.0", @@ -3548,7 +3551,7 @@ dependencies = [ "tokio", "tokio-named-pipes", "tokio-uds", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3566,7 +3569,7 @@ dependencies = [ "parking_lot 0.10.2", "primitive-types 0.7.2", "smallvec 1.6.1", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3662,13 +3665,13 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api 0.4.6", - "parking_lot_core 0.8.3", + "parking_lot_core 0.8.6", ] [[package]] @@ -3691,7 +3694,7 @@ dependencies = [ "rand 0.5.6", "rustc_version", "smallvec 0.6.14", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3706,7 +3709,7 @@ dependencies = [ "redox_syscall 0.1.56", "rustc_version", "smallvec 0.6.14", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3720,14 +3723,14 @@ dependencies = [ "libc", "redox_syscall 0.1.56", "smallvec 1.6.1", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "parking_lot_core" -version = "0.8.3" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" dependencies = [ "backtrace", "cfg-if 1.0.0", @@ -3737,7 +3740,7 @@ dependencies = [ "redox_syscall 0.2.16", "smallvec 1.6.1", "thread-id", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -3845,7 +3848,7 @@ dependencies = [ "futures", "log", "parity-runtime", - "parking_lot 0.11.1", + "parking_lot 0.11.2", "serde_json", ] @@ -4062,7 +4065,7 @@ dependencies = [ "libc", "rand_core 0.3.1", "rdrand", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -4075,7 +4078,7 @@ dependencies = [ "fuchsia-cprng", "libc", "rand_core 0.3.1", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -4094,7 +4097,7 @@ dependencies = [ "rand_os 0.1.3", "rand_pcg", "rand_xorshift 0.1.1", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -4199,7 +4202,7 @@ checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" dependencies = [ "libc", "rand_core 0.4.2", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -4213,7 +4216,7 @@ dependencies = [ "libc", "rand_core 0.4.2", "rdrand", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -4363,7 +4366,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -4382,7 +4385,7 @@ dependencies = [ "libc", "spin", "untrusted", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -4478,9 +4481,9 @@ checksum = "1601f32bc5858aae3cbfa1c645c96c4d820cc5c16be0194f089560c00b6eb625" [[package]] name = "rustc-demangle" -version = "0.1.16" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" [[package]] name = "rustc-hex" @@ -4958,7 +4961,7 @@ dependencies = [ "rand 0.7.3", "redox_syscall 0.1.56", "remove_dir_all", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5021,13 +5024,12 @@ dependencies = [ [[package]] name = "thread-id" -version = "3.3.0" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1" +checksum = "cfe8f25bbdd100db7e1d34acf7fd2dc59c4bf8f7483f505eaa7d4f12f76cc0ea" dependencies = [ "libc", - "redox_syscall 0.1.56", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5075,7 +5077,7 @@ checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5677,7 +5679,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" dependencies = [ "same-file", - "winapi 0.3.8", + "winapi 0.3.9", "winapi-util", ] @@ -5813,9 +5815,9 @@ checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", @@ -5839,7 +5841,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -5854,7 +5856,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", "winapi-util", ] @@ -5864,7 +5866,7 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", ] [[package]] @@ -5873,13 +5875,29 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -5888,42 +5906,90 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 355cb51ed..9f915b3d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ number_prefix = "0.2" rpassword = "1.0" semver = "0.9" ansi_term = "0.10" -parking_lot = "0.11.1" +parking_lot = "0.11.2" crossbeam-channel = "0.5.2" regex = "1.0" atty = "0.2.8" diff --git a/bin/ethstore/Cargo.toml b/bin/ethstore/Cargo.toml index 8b7b3336d..9ae107799 100644 --- a/bin/ethstore/Cargo.toml +++ b/bin/ethstore/Cargo.toml @@ -12,7 +12,7 @@ num_cpus = "1.6" rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" -parking_lot = "0.11.1" +parking_lot = "0.11.2" ethstore = { path = "../../crates/accounts/ethstore" } dir = { path = '../../crates/util/dir' } panic_hook = { path = "../../crates/util/panic-hook" } diff --git a/bin/oe/logger/Cargo.toml b/bin/oe/logger/Cargo.toml index 3540446a6..5f1acf49f 100644 --- a/bin/oe/logger/Cargo.toml +++ b/bin/oe/logger/Cargo.toml @@ -13,6 +13,6 @@ atty = "0.2" lazy_static = "1.0" regex = "1.0" time = "0.1" -parking_lot = "0.11.1" +parking_lot = "0.11.2" arrayvec = "0.7" ansi_term = "0.10" diff --git a/crates/accounts/Cargo.toml b/crates/accounts/Cargo.toml index ae560b6a8..62ae4c72e 100644 --- a/crates/accounts/Cargo.toml +++ b/crates/accounts/Cargo.toml @@ -13,7 +13,7 @@ ethkey = { path = "ethkey" } ethstore = { path = "ethstore" } log = "0.4" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } -parking_lot = "0.11.1" +parking_lot = "0.11.2" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/crates/accounts/ethstore/Cargo.toml b/crates/accounts/ethstore/Cargo.toml index 2cb224048..4bdbcc5ca 100644 --- a/crates/accounts/ethstore/Cargo.toml +++ b/crates/accounts/ethstore/Cargo.toml @@ -16,7 +16,7 @@ serde_derive = "1.0" rustc-hex = "1.0" time = "0.1.34" itertools = "0.5" -parking_lot = "0.11.1" +parking_lot = "0.11.2" parity-crypto = { version = "0.6.2", features = [ "publickey"] } ethereum-types = "0.9.2" smallvec = "0.6.14" diff --git a/crates/concensus/ethash/Cargo.toml b/crates/concensus/ethash/Cargo.toml index 22b6ce977..1f058c153 100644 --- a/crates/concensus/ethash/Cargo.toml +++ b/crates/concensus/ethash/Cargo.toml @@ -13,7 +13,7 @@ keccak-hash = "0.5.0" tiny-keccak = "2.0.2" log = "0.4" memmap = "0.6" -parking_lot = "0.11.1" +parking_lot = "0.11.2" primal = "0.2.3" [dev-dependencies] diff --git a/crates/concensus/miner/Cargo.toml b/crates/concensus/miner/Cargo.toml index d5c9b13d9..64ddaf049 100644 --- a/crates/concensus/miner/Cargo.toml +++ b/crates/concensus/miner/Cargo.toml @@ -30,7 +30,7 @@ log = "0.4" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } parity-runtime = { path = "../../runtime/runtime" } parity-util-mem = "0.7" -parking_lot = "0.11.1" +parking_lot = "0.11.2" price-info = { path = "./price-info", optional = true } rlp = { version = "0.4.6" } serde = { version = "1.0", features = ["derive"] } diff --git a/crates/concensus/miner/price-info/Cargo.toml b/crates/concensus/miner/price-info/Cargo.toml index 7ed267791..e4e1b549e 100644 --- a/crates/concensus/miner/price-info/Cargo.toml +++ b/crates/concensus/miner/price-info/Cargo.toml @@ -15,5 +15,5 @@ log = "0.4" serde_json = "1.0" [dev-dependencies] -parking_lot = "0.11.1" +parking_lot = "0.11.2" fake-fetch = { path = "../../../net/fake-fetch" } diff --git a/crates/concensus/miner/stratum/Cargo.toml b/crates/concensus/miner/stratum/Cargo.toml index 30d2811c8..7197a7944 100644 --- a/crates/concensus/miner/stratum/Cargo.toml +++ b/crates/concensus/miner/stratum/Cargo.toml @@ -12,7 +12,7 @@ keccak-hash = "0.5.0" jsonrpc-core = "15.0.0" jsonrpc-tcp-server = "15.0.0" log = "0.4" -parking_lot = "0.11.1" +parking_lot = "0.11.2" [dev-dependencies] env_logger = "0.5" diff --git a/crates/db/blooms-db/Cargo.toml b/crates/db/blooms-db/Cargo.toml index 55aa8b005..61132a5c0 100644 --- a/crates/db/blooms-db/Cargo.toml +++ b/crates/db/blooms-db/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] byteorder = "1.2" ethbloom = "0.9.1" -parking_lot = "0.11.1" +parking_lot = "0.11.2" tiny-keccak = "1.4" [dev-dependencies] diff --git a/crates/db/db/Cargo.toml b/crates/db/db/Cargo.toml index cf04a5706..8f1317aec 100644 --- a/crates/db/db/Cargo.toml +++ b/crates/db/db/Cargo.toml @@ -14,7 +14,7 @@ kvdb = "0.1" kvdb-rocksdb = "0.1.3" kvdb-memorydb = "0.1" parity-util-mem = "0.7" -parking_lot = "0.11.1" +parking_lot = "0.11.2" rlp = { version = "0.4.6" } rlp-derive = { version = "0.2"} stats = { path = "../../util/stats" } \ No newline at end of file diff --git a/crates/db/journaldb/Cargo.toml b/crates/db/journaldb/Cargo.toml index 6824d82bd..d34c8e9d9 100644 --- a/crates/db/journaldb/Cargo.toml +++ b/crates/db/journaldb/Cargo.toml @@ -16,7 +16,7 @@ kvdb = "0.1" log = "0.4" memory-db = { path = "../memory-db" } parity-util-mem = "0.7" -parking_lot = "0.11.1" +parking_lot = "0.11.2" fastmap = { path = "../../util/fastmap" } rlp = { version = "0.4.6" } diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index 1d40bf589..1e3e1eeb0 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -58,7 +58,7 @@ parity-bytes = "0.1" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } parity-snappy = "0.1" parity-util-mem = "0.7" -parking_lot = "0.11.1" +parking_lot = "0.11.2" trie-db = "0.11.0" patricia-trie-ethereum = { path = "../db/patricia-trie-ethereum" } rand_065 = { package = "rand", version = "0.6.5" } diff --git a/crates/ethcore/blockchain/Cargo.toml b/crates/ethcore/blockchain/Cargo.toml index e0c8f44c7..35855c784 100644 --- a/crates/ethcore/blockchain/Cargo.toml +++ b/crates/ethcore/blockchain/Cargo.toml @@ -20,7 +20,7 @@ log = "0.4" parity-bytes = "0.1" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } parity-util-mem = "0.7" -parking_lot = "0.11.1" +parking_lot = "0.11.2" rand = "0.7.3" rayon = "1.1" rlp = { version = "0.4.6" } diff --git a/crates/ethcore/sync/Cargo.toml b/crates/ethcore/sync/Cargo.toml index 441e3dcc7..28d49a144 100644 --- a/crates/ethcore/sync/Cargo.toml +++ b/crates/ethcore/sync/Cargo.toml @@ -32,7 +32,7 @@ macros = { path = "../../util/macros" } parity-bytes = "0.1" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } parity-util-mem = "0.7" -parking_lot = "0.11.1" +parking_lot = "0.11.2" rand = "0.7.3" rand_xorshift = "0.2.0" rlp = { version = "0.4.6" } diff --git a/crates/net/network-devp2p/Cargo.toml b/crates/net/network-devp2p/Cargo.toml index b1c8bac47..5b6ec72bf 100644 --- a/crates/net/network-devp2p/Cargo.toml +++ b/crates/net/network-devp2p/Cargo.toml @@ -16,7 +16,7 @@ tiny-keccak = "1.4" slab = "0.2" igd = "0.8" libc = "0.2.7" -parking_lot = "0.11.1" +parking_lot = "0.11.2" ansi_term = "0.10" rustc-hex = "1.0" ethcore-io = { path = "../../runtime/io", features = ["mio"] } diff --git a/crates/net/node-filter/Cargo.toml b/crates/net/node-filter/Cargo.toml index 47283b597..75d487c89 100644 --- a/crates/net/node-filter/Cargo.toml +++ b/crates/net/node-filter/Cargo.toml @@ -13,7 +13,7 @@ ethcore-network = { path = "../network" } ethcore-network-devp2p = { path = "../network-devp2p" } ethereum-types = "0.9.2" log = "0.4" -parking_lot = "0.11.1" +parking_lot = "0.11.2" ethabi = "12.0.0" ethabi-derive = { git = 'https://github.com/rimrakhimov/ethabi', branch = 'rimrakhimov/remove-syn-export-span' } ethabi-contract = "16.0.0" diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index 57a30e08a..9ea77af78 100644 --- a/crates/rpc/Cargo.toml +++ b/crates/rpc/Cargo.toml @@ -13,7 +13,7 @@ ansi_term = "0.10" futures = "0.1.6" log = "0.4" order-stat = "0.1" -parking_lot = "0.11.1" +parking_lot = "0.11.2" rand = "0.7.3" rand_xorshift = "0.2.0" rustc-hex = "1.0" diff --git a/crates/runtime/io/Cargo.toml b/crates/runtime/io/Cargo.toml index 600b46635..29d0a96f9 100644 --- a/crates/runtime/io/Cargo.toml +++ b/crates/runtime/io/Cargo.toml @@ -11,7 +11,7 @@ edition = "2024" fnv = "1.0" mio = { version = "0.6.8", optional = true } crossbeam-deque = "0.7.4" -parking_lot = "0.11.1" +parking_lot = "0.11.2" log = "0.4" slab = "0.4" timer = "0.2" diff --git a/crates/util/cli-signer/rpc-client/Cargo.toml b/crates/util/cli-signer/rpc-client/Cargo.toml index 0c8d7f936..ff0cdb848 100644 --- a/crates/util/cli-signer/rpc-client/Cargo.toml +++ b/crates/util/cli-signer/rpc-client/Cargo.toml @@ -15,7 +15,7 @@ serde = "1.0" serde_json = "1.0" url = "2" matches = "0.1" -parking_lot = "0.11.1" +parking_lot = "0.11.2" jsonrpc-core = "15.0.0" jsonrpc-ws-server = "15.0.0" parity-rpc = { path = "../../../rpc" } diff --git a/crates/util/len-caching-lock/Cargo.toml b/crates/util/len-caching-lock/Cargo.toml index a01cc7547..0647e6867 100644 --- a/crates/util/len-caching-lock/Cargo.toml +++ b/crates/util/len-caching-lock/Cargo.toml @@ -8,4 +8,4 @@ authors = ["Parity Technologies "] edition = "2024" [dependencies] -parking_lot = "0.11.1" +parking_lot = "0.11.2" diff --git a/crates/vm/evm/Cargo.toml b/crates/vm/evm/Cargo.toml index 78354e8ad..4aff92d94 100644 --- a/crates/vm/evm/Cargo.toml +++ b/crates/vm/evm/Cargo.toml @@ -14,7 +14,7 @@ log = "0.4" vm = { path = "../vm" } keccak-hash = "0.5.0" parity-util-mem = "0.7" -parking_lot = "0.11.1" +parking_lot = "0.11.2" memory-cache = { path = "../../util/memory-cache" } ethcore-builtin = { path = "../builtin" } num-bigint = "0.4" From fa4eb8874c545044c3dd9c662f13a9b5f08a689d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 09:00:22 +0200 Subject: [PATCH 529/687] TransactionQueue.find() has now inverted lookup logic, cached_enforced_pending and cached_non_enforced_pending are now queried before self.pool, since pool is locked more often. --- crates/concensus/miner/src/pool/queue.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index a35c7c956..88f5b8e9c 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -466,6 +466,7 @@ impl TransactionQueue { // Double check after acquiring write lock let mut cached_pending = cached.write(); + if let Some(pending) = cached_pending.pending(block_number, current_timestamp, nonce_cap.as_ref(), max_len) { @@ -668,11 +669,11 @@ impl TransactionQueue { /// Given transaction hash looks up that transaction in the pool /// and returns a shared pointer to it or `None` if it's not present. pub fn find(&self, hash: &H256) -> Option> { - self.pool + self.cached_enforced_pending .read() .find(hash) - .or(self.cached_enforced_pending.read().find(hash)) .or(self.cached_non_enforced_pending.read().find(hash)) + .or(self.pool.read().find(hash)) } /// Remove a set of transactions from the pool. From de726a732dceee627985f5ef48790ab7c427cb0c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 12:44:18 +0200 Subject: [PATCH 530/687] reduced locking time for reserved peers in Host Session Management, by cloning that info. --- crates/net/network-devp2p/src/host.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index c503d4bb1..e28ac77f7 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -1063,7 +1063,7 @@ impl Host { return; } for p in ready_data { - let reserved = self.reserved_nodes.read(); + let reserved = self.reserved_nodes.read().clone(); if let Some(h) = handlers.get(&p) { h.connected( &NetworkContext::new( @@ -1084,7 +1084,7 @@ impl Host { } for (p, packet_id, data) in packet_data { - let reserved = self.reserved_nodes.read(); + let reserved = self.reserved_nodes.read().clone(); if let Some(h) = handlers.get(&p) { h.read( &NetworkContext::new( From dd7f889bb9179adfa4c810696eda557f25bdacad Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 12:54:07 +0200 Subject: [PATCH 531/687] changed supplier and handler for pooled transactions to not require a readlock. It is now behaving as such the transactions is not known, for both scenarious, on_peer_new_pooled_transaction_hashes && return_pooled_transactions --- bin/oe/lib.rs | 4 ++-- crates/concensus/miner/src/pool/queue.rs | 12 ++++++++++++ crates/ethcore/src/client/client.rs | 4 ++++ crates/ethcore/src/client/traits.rs | 4 ++++ crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 ++ .../ethcore/src/engines/hbbft/hbbft_peers_handler.rs | 3 --- crates/ethcore/src/miner/miner.rs | 4 ++++ crates/ethcore/src/miner/mod.rs | 4 ++++ crates/ethcore/sync/src/chain/handler.rs | 4 +++- crates/ethcore/sync/src/chain/supplier.rs | 5 ++++- 10 files changed, 39 insertions(+), 7 deletions(-) diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index d6dcbb660..6be25db33 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -166,7 +166,7 @@ fn run_deadlock_detection_thread(shutdown: Arc) { let builder = std::thread::Builder::new().name("DeadlockDetection".to_string()); - // Create a background thread which checks for deadlocks every 10s + // Create a background thread which checks for deadlocks let spawned = builder.spawn(move || { loop { thread::sleep(Duration::from_secs(10)); @@ -208,7 +208,7 @@ pub enum ExecutionAction { Instant(Option), /// The client has started running and must be shut down manually by calling `shutdown`. - /// + /// /// If you don't call `shutdown()`, execution will continue in the background. Running(RunningClient), } diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index 88f5b8e9c..7f48b42f5 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -676,6 +676,18 @@ impl TransactionQueue { .or(self.pool.read().find(hash)) } + /// Retrieve a transaction from the pool, if the pool is readable. + /// + /// Given transaction hash looks up that transaction in the pool + /// and returns a shared pointer to it or `None` if it's not present, or a readlock could not get acquired. + pub fn find_if_readable(&self, hash: &H256) -> Option> { + self.cached_enforced_pending + .try_read()? + .find(hash) + .or(self.cached_non_enforced_pending.try_read()?.find(hash)) + .or(self.pool.try_read()?.find(hash)) + } + /// Remove a set of transactions from the pool. /// /// Given an iterator of transaction hashes diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index d72be8e09..786a6657d 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -2426,6 +2426,10 @@ impl BlockChainClient for Client { self.importer.miner.transaction(&hash) } + fn queued_transaction_if_readable(&self, hash: &H256) -> Option> { + self.importer.miner.transaction_if_readable(&hash) + } + fn uncle(&self, id: UncleId) -> Option { let index = id.position; self.block_body(id.block) diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index bac0e344c..d65a80b7f 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -353,6 +353,10 @@ pub trait BlockChainClient: /// Get pool transaction with a given hash. fn queued_transaction(&self, hash: H256) -> Option>; + /// see queued_transactions(&self). + /// Get pool transaction with a given hash, but returns NONE fast, if if cannot acquire a readlock fast. + fn queued_transaction_if_readable(&self, hash: &H256) -> Option>; + /// Get uncle with given id. fn uncle(&self, id: UncleId) -> Option; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 1a5c9e29e..0f5cd21c7 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -827,6 +827,8 @@ impl HoneyBadgerBFT { if let Some(block_header) = client.block_header(BlockId::Latest) { let target_min_timestamp = block_header.timestamp() + self.params.minimum_block_time; let now = unix_now_secs(); + // we could implement a cheaper way to get the number of queued transaction, that does not require this intensive locking. + // see: https://github.com/DMDcoin/diamond-node/issues/237 let queue_length = client.queued_transactions().len(); (self.params.minimum_block_time == 0 || target_min_timestamp <= now) && queue_length >= self.params.transaction_queue_size_trigger diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs index e847b077f..c5e609d3c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs @@ -81,7 +81,6 @@ impl HbbftPeersHandler { .as_full_client() .ok_or("BlockchainClient required")?; - if block_chain_client.is_major_syncing() { return Ok(()); } @@ -120,12 +119,10 @@ impl HbbftPeersHandler { } fn announce_own_internet_address(&self) -> Result<(), Error> { - // todo: // if the network is unable to process this transaction, // we are keeping to announce out internet address. - let mining_address = self.get_mining_address(); if mining_address.is_zero() { diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 96de8eaac..484aec14e 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -1468,6 +1468,10 @@ impl miner::MinerService for Miner { return result; } + fn transaction_if_readable(&self, hash: &H256) -> Option> { + self.transaction_queue.find_if_readable(hash) + } + fn remove_transaction(&self, hash: &H256) -> Option> { self.transaction_queue .remove(::std::iter::once(hash), false) diff --git a/crates/ethcore/src/miner/mod.rs b/crates/ethcore/src/miner/mod.rs index 365924686..e63c3566f 100644 --- a/crates/ethcore/src/miner/mod.rs +++ b/crates/ethcore/src/miner/mod.rs @@ -199,6 +199,10 @@ pub trait MinerService: Send + Sync { /// Query transaction from the pool given it's hash. fn transaction(&self, hash: &H256) -> Option>; + /// Query transaction from the pool given it's hash, without blocking. + /// Might return "None" in cases when the lock could not get acquired. + fn transaction_if_readable(&self, hash: &H256) -> Option>; + /// Returns next valid nonce for given address. /// /// This includes nonces of all transactions from this address in the pending queue diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 94fe1a6ef..0a6a8784b 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -866,7 +866,9 @@ impl SyncHandler { // todo: what if the Transaction is not new, and already in the chain? // see: https://github.com/DMDcoin/diamond-node/issues/196 - if io.chain().queued_transaction(hash).is_none() { + // if we cant read the pool here, we are asuming we dont know the transaction yet. + // in the worst case we are refetching a transaction that we already have. + if io.chain().queued_transaction_if_readable(&hash).is_none() { sync.peers .get_mut(&peer_id) .map(|peer| peer.unfetched_pooled_transactions.insert(hash)); diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index ee74734d8..e098d8f94 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -320,7 +320,10 @@ impl SyncSupplier { if let Ok(hash) = v.as_val::() { // io.chain().transaction(hash) - if let Some(tx) = io.chain().queued_transaction(hash) { + // we do not lock here, if we cannot access the memory at this point in time, + // we will just skip this transaction, otherwise the other peer might wait to long, resulting in a timeout. + // also this solved a potential deadlock situation: + if let Some(tx) = io.chain().queued_transaction_if_readable(&hash) { tx.signed().rlp_append(&mut rlp); added += 1; if rlp.len() > PAYLOAD_SOFT_LIMIT { From 8a34bbc0b4e8d7c04565f06aa342324ee51d4511 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 12:59:10 +0200 Subject: [PATCH 532/687] refactored function name: queued_transaction_if_readable to transaction_if_readable --- crates/ethcore/src/client/client.rs | 2 +- crates/ethcore/src/client/test_client.rs | 4 ++++ crates/ethcore/src/client/traits.rs | 8 ++++---- crates/ethcore/sync/src/chain/handler.rs | 2 +- crates/ethcore/sync/src/chain/supplier.rs | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 786a6657d..7e5d8f460 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -2426,7 +2426,7 @@ impl BlockChainClient for Client { self.importer.miner.transaction(&hash) } - fn queued_transaction_if_readable(&self, hash: &H256) -> Option> { + fn transaction_if_readable(&self, hash: &H256) -> Option> { self.importer.miner.transaction_if_readable(&hash) } diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index 863e82305..10995668a 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -1160,6 +1160,10 @@ impl BlockChainClient for TestBlockChainClient { self.miner.transaction(tx_hash) } + fn transaction_if_readable(&self, hash: &H256) -> Option> { + self.miner.transaction_if_readable(hash) + } + /// Returns the devp2p network endpoint IP and Port information that is used to communicate with other peers. fn reserved_peers_management(&self) -> &Mutex>> { diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index d65a80b7f..43a59a3e3 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -353,10 +353,6 @@ pub trait BlockChainClient: /// Get pool transaction with a given hash. fn queued_transaction(&self, hash: H256) -> Option>; - /// see queued_transactions(&self). - /// Get pool transaction with a given hash, but returns NONE fast, if if cannot acquire a readlock fast. - fn queued_transaction_if_readable(&self, hash: &H256) -> Option>; - /// Get uncle with given id. fn uncle(&self, id: UncleId) -> Option; @@ -427,6 +423,10 @@ pub trait BlockChainClient: /// Get verified transaction with specified transaction hash. fn transaction(&self, tx_hash: &H256) -> Option>; + /// see queued_transactions(&self). + /// Get pool transaction with a given hash, but returns NONE fast, if if cannot acquire a readlock fast. + fn transaction_if_readable(&self, hash: &H256) -> Option>; + /// Sorted list of transaction gas prices from at least last sample_size blocks. fn gas_price_corpus(&self, sample_size: usize) -> ::stats::Corpus { let mut h = self.chain_info().best_block_hash; diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 0a6a8784b..d93c924f8 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -868,7 +868,7 @@ impl SyncHandler { // if we cant read the pool here, we are asuming we dont know the transaction yet. // in the worst case we are refetching a transaction that we already have. - if io.chain().queued_transaction_if_readable(&hash).is_none() { + if io.chain().transaction_if_readable(&hash).is_none() { sync.peers .get_mut(&peer_id) .map(|peer| peer.unfetched_pooled_transactions.insert(hash)); diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index e098d8f94..5ab702b98 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -323,7 +323,7 @@ impl SyncSupplier { // we do not lock here, if we cannot access the memory at this point in time, // we will just skip this transaction, otherwise the other peer might wait to long, resulting in a timeout. // also this solved a potential deadlock situation: - if let Some(tx) = io.chain().queued_transaction_if_readable(&hash) { + if let Some(tx) = io.chain().transaction_if_readable(&hash) { tx.signed().rlp_append(&mut rlp); added += 1; if rlp.len() > PAYLOAD_SOFT_LIMIT { From 2da2e2e9cfcd745308bc8ed0eb6686c2efea14d4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 13:16:42 +0200 Subject: [PATCH 533/687] test miner service implementation of latest changes --- crates/rpc/src/v1/tests/helpers/miner_service.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/rpc/src/v1/tests/helpers/miner_service.rs b/crates/rpc/src/v1/tests/helpers/miner_service.rs index 891c9e3b3..99a0fb564 100644 --- a/crates/rpc/src/v1/tests/helpers/miner_service.rs +++ b/crates/rpc/src/v1/tests/helpers/miner_service.rs @@ -254,6 +254,14 @@ impl MinerService for TestMinerService { .map(|tx| Arc::new(VerifiedTransaction::from_pending_block_transaction(tx))) } + fn transaction_if_readable(&self, hash: &H256) -> Option> { + self.pending_transactions + .try_lock()? + .get(hash) + .cloned() + .map(|tx| Arc::new(VerifiedTransaction::from_pending_block_transaction(tx))) + } + fn remove_transaction(&self, hash: &H256) -> Option> { self.pending_transactions .lock() @@ -401,4 +409,6 @@ impl MinerService for TestMinerService { } } } + + } From b2eff695b6e4c0b792b83250a320f02b6c08bba2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 13:17:06 +0200 Subject: [PATCH 534/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/rpc/src/v1/tests/helpers/miner_service.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/rpc/src/v1/tests/helpers/miner_service.rs b/crates/rpc/src/v1/tests/helpers/miner_service.rs index 99a0fb564..b9b1177fb 100644 --- a/crates/rpc/src/v1/tests/helpers/miner_service.rs +++ b/crates/rpc/src/v1/tests/helpers/miner_service.rs @@ -409,6 +409,4 @@ impl MinerService for TestMinerService { } } } - - } From da44be4caf7328796444500fc76b0ae0c36da3cb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 14:02:58 +0200 Subject: [PATCH 535/687] pump version 3.3.5-hbbft-0.11.3 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f62a59bd..ce9efa946 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.2-rc2" +version = "3.3.5-hbbft-0.11.3" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3585,7 +3585,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.2-rc1" +version = "3.3.5-hbbft-0.11.3" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 9f915b3d9..9ba2aa076 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.2-rc2" +version = "3.3.5-hbbft-0.11.3" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 92ed8cf60..f90e7c806 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.2-rc1" +version = "3.3.5-hbbft-0.11.3" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 5358e53c92110ed6a3d597ed65b3d01fe1b620bb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 14:03:34 +0200 Subject: [PATCH 536/687] Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 561161902..a6f204a93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Diamond Node Software 3.3.5-hbbft-0.11.3 + +- [deadlocks in transaction pools](https://github.com/DMDcoin/diamond-node/issues/236) + ## Diamond Node Software 3.3.5-hbbft-0.11.2 - [shutdown on deadlock](https://github.com/DMDcoin/diamond-node/issues/231) From 6bada08531ca228964d5007f70c6daefa84b66c6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 19:05:15 +0200 Subject: [PATCH 537/687] parking_lot = "0.12" --- Cargo.lock | 92 ++++++-------------- Cargo.toml | 2 +- bin/ethstore/Cargo.toml | 2 +- bin/oe/logger/Cargo.toml | 2 +- crates/accounts/Cargo.toml | 2 +- crates/accounts/ethstore/Cargo.toml | 2 +- crates/concensus/ethash/Cargo.toml | 2 +- crates/concensus/miner/Cargo.toml | 2 +- crates/concensus/miner/price-info/Cargo.toml | 2 +- crates/concensus/miner/stratum/Cargo.toml | 2 +- crates/db/blooms-db/Cargo.toml | 2 +- crates/db/db/Cargo.toml | 2 +- crates/db/journaldb/Cargo.toml | 2 +- crates/ethcore/Cargo.toml | 2 +- crates/ethcore/blockchain/Cargo.toml | 2 +- crates/ethcore/sync/Cargo.toml | 2 +- crates/net/network-devp2p/Cargo.toml | 2 +- crates/net/node-filter/Cargo.toml | 2 +- crates/rpc/Cargo.toml | 2 +- crates/runtime/io/Cargo.toml | 2 +- crates/util/cli-signer/rpc-client/Cargo.toml | 2 +- crates/util/len-caching-lock/Cargo.toml | 2 +- crates/vm/evm/Cargo.toml | 2 +- 23 files changed, 51 insertions(+), 85 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce9efa946..3956243cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -327,7 +327,7 @@ dependencies = [ "byteorder", "criterion 0.3.0", "ethbloom 0.9.2", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "tempdir", "tiny-keccak 1.5.0", ] @@ -906,7 +906,7 @@ dependencies = [ "parity-rpc", "parity-runtime", "parity-version", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "pretty_assertions", "prometheus", "regex", @@ -1167,7 +1167,7 @@ dependencies = [ "keccak-hash", "log", "memmap", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "primal", "rustc-hex 1.0.0", "serde_json", @@ -1262,7 +1262,7 @@ dependencies = [ "parity-runtime", "parity-snappy", "parity-util-mem", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "patricia-trie-ethereum", "rand 0.6.5", "rand 0.7.3", @@ -1305,7 +1305,7 @@ dependencies = [ "ethstore", "log", "parity-crypto", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "serde", "serde_derive", "serde_json", @@ -1331,7 +1331,7 @@ dependencies = [ "parity-bytes", "parity-crypto", "parity-util-mem", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "rand 0.7.3", "rayon", "rlp", @@ -1391,7 +1391,7 @@ dependencies = [ "kvdb-memorydb", "kvdb-rocksdb", "parity-util-mem", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "rlp", "rlp-derive 0.2.0", "stats", @@ -1406,7 +1406,7 @@ dependencies = [ "futures", "log", "mio", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "slab 0.4.2", "time 0.1.45", "timer", @@ -1423,7 +1423,7 @@ dependencies = [ "env_logger 0.5.13", "lazy_static", "log", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "regex", "time 0.1.45", ] @@ -1452,7 +1452,7 @@ dependencies = [ "parity-crypto", "parity-runtime", "parity-util-mem", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "price-info", "rlp", "rustc-hex 1.0.0", @@ -1509,7 +1509,7 @@ dependencies = [ "parity-crypto", "parity-path", "parity-snappy", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "rand 0.7.3", "rlp", "rustc-hex 1.0.0", @@ -1551,7 +1551,7 @@ dependencies = [ "jsonrpc-tcp-server", "keccak-hash", "log", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "tokio", "tokio-io", ] @@ -1585,7 +1585,7 @@ dependencies = [ "parity-bytes", "parity-crypto", "parity-util-mem", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "primitive-types 0.7.2", "rand 0.7.3", "rand_xorshift 0.2.0", @@ -1703,7 +1703,7 @@ dependencies = [ "matches", "parity-crypto", "parity-wordlist", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "rand 0.7.3", "rustc-hex 1.0.0", "serde", @@ -1724,7 +1724,7 @@ dependencies = [ "ethstore", "num_cpus", "panic_hook", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "rustc-hex 1.0.0", "serde", "serde_derive", @@ -1747,7 +1747,7 @@ dependencies = [ "num-bigint 0.4.3", "parity-bytes", "parity-util-mem", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "rustc-hex 1.0.0", "vm", ] @@ -1889,9 +1889,9 @@ dependencies = [ [[package]] name = "fixedbitset" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "fnv" @@ -2482,15 +2482,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0175f63815ce00183bf755155ad0cb48c65226c5d17a724e369c25418d2b7699" -[[package]] -name = "instant" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "integer-sqrt" version = "0.1.5" @@ -2577,7 +2568,7 @@ dependencies = [ "memory-db 0.11.0", "parity-bytes", "parity-util-mem", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "rlp", ] @@ -2805,7 +2796,7 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" name = "len-caching-lock" version = "0.1.1" dependencies = [ - "parking_lot 0.11.2", + "parking_lot 0.12.1", ] [[package]] @@ -3166,7 +3157,7 @@ dependencies = [ "kvdb-memorydb", "log", "lru-cache", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "tempdir", ] @@ -3459,7 +3450,7 @@ dependencies = [ "parity-crypto", "parity-runtime", "parity-version", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "pretty_assertions", "rand 0.7.3", "rand_xorshift 0.2.0", @@ -3489,7 +3480,7 @@ dependencies = [ "log", "matches", "parity-rpc", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "serde", "serde_json", "url 2.1.0", @@ -3663,17 +3654,6 @@ dependencies = [ "parking_lot_core 0.7.2", ] -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api 0.4.6", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -3728,31 +3708,17 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "backtrace", "cfg-if 1.0.0", - "instant", "libc", "petgraph", "redox_syscall 0.2.16", "smallvec 1.6.1", "thread-id", - "winapi 0.3.9", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall 0.2.16", - "smallvec 1.6.1", "windows-sys", ] @@ -3807,12 +3773,12 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "petgraph" -version = "0.5.1" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 1.9.3", + "indexmap 2.2.2", ] [[package]] @@ -3848,7 +3814,7 @@ dependencies = [ "futures", "log", "parity-runtime", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "serde_json", ] diff --git a/Cargo.toml b/Cargo.toml index 9ba2aa076..f994cfe50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ number_prefix = "0.2" rpassword = "1.0" semver = "0.9" ansi_term = "0.10" -parking_lot = "0.11.2" +parking_lot = "0.12" crossbeam-channel = "0.5.2" regex = "1.0" atty = "0.2.8" diff --git a/bin/ethstore/Cargo.toml b/bin/ethstore/Cargo.toml index 9ae107799..b13564ecc 100644 --- a/bin/ethstore/Cargo.toml +++ b/bin/ethstore/Cargo.toml @@ -12,7 +12,7 @@ num_cpus = "1.6" rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" -parking_lot = "0.11.2" +parking_lot = "0.12" ethstore = { path = "../../crates/accounts/ethstore" } dir = { path = '../../crates/util/dir' } panic_hook = { path = "../../crates/util/panic-hook" } diff --git a/bin/oe/logger/Cargo.toml b/bin/oe/logger/Cargo.toml index 5f1acf49f..3772996f5 100644 --- a/bin/oe/logger/Cargo.toml +++ b/bin/oe/logger/Cargo.toml @@ -13,6 +13,6 @@ atty = "0.2" lazy_static = "1.0" regex = "1.0" time = "0.1" -parking_lot = "0.11.2" +parking_lot = "0.12" arrayvec = "0.7" ansi_term = "0.10" diff --git a/crates/accounts/Cargo.toml b/crates/accounts/Cargo.toml index 62ae4c72e..4a94992f0 100644 --- a/crates/accounts/Cargo.toml +++ b/crates/accounts/Cargo.toml @@ -13,7 +13,7 @@ ethkey = { path = "ethkey" } ethstore = { path = "ethstore" } log = "0.4" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } -parking_lot = "0.11.2" +parking_lot = "0.12" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/crates/accounts/ethstore/Cargo.toml b/crates/accounts/ethstore/Cargo.toml index 4bdbcc5ca..d526be59d 100644 --- a/crates/accounts/ethstore/Cargo.toml +++ b/crates/accounts/ethstore/Cargo.toml @@ -16,7 +16,7 @@ serde_derive = "1.0" rustc-hex = "1.0" time = "0.1.34" itertools = "0.5" -parking_lot = "0.11.2" +parking_lot = "0.12" parity-crypto = { version = "0.6.2", features = [ "publickey"] } ethereum-types = "0.9.2" smallvec = "0.6.14" diff --git a/crates/concensus/ethash/Cargo.toml b/crates/concensus/ethash/Cargo.toml index 1f058c153..e3a1ff054 100644 --- a/crates/concensus/ethash/Cargo.toml +++ b/crates/concensus/ethash/Cargo.toml @@ -13,7 +13,7 @@ keccak-hash = "0.5.0" tiny-keccak = "2.0.2" log = "0.4" memmap = "0.6" -parking_lot = "0.11.2" +parking_lot = "0.12" primal = "0.2.3" [dev-dependencies] diff --git a/crates/concensus/miner/Cargo.toml b/crates/concensus/miner/Cargo.toml index 64ddaf049..00bb5461c 100644 --- a/crates/concensus/miner/Cargo.toml +++ b/crates/concensus/miner/Cargo.toml @@ -30,7 +30,7 @@ log = "0.4" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } parity-runtime = { path = "../../runtime/runtime" } parity-util-mem = "0.7" -parking_lot = "0.11.2" +parking_lot = "0.12" price-info = { path = "./price-info", optional = true } rlp = { version = "0.4.6" } serde = { version = "1.0", features = ["derive"] } diff --git a/crates/concensus/miner/price-info/Cargo.toml b/crates/concensus/miner/price-info/Cargo.toml index e4e1b549e..8af227ded 100644 --- a/crates/concensus/miner/price-info/Cargo.toml +++ b/crates/concensus/miner/price-info/Cargo.toml @@ -15,5 +15,5 @@ log = "0.4" serde_json = "1.0" [dev-dependencies] -parking_lot = "0.11.2" +parking_lot = "0.12" fake-fetch = { path = "../../../net/fake-fetch" } diff --git a/crates/concensus/miner/stratum/Cargo.toml b/crates/concensus/miner/stratum/Cargo.toml index 7197a7944..b36d587d9 100644 --- a/crates/concensus/miner/stratum/Cargo.toml +++ b/crates/concensus/miner/stratum/Cargo.toml @@ -12,7 +12,7 @@ keccak-hash = "0.5.0" jsonrpc-core = "15.0.0" jsonrpc-tcp-server = "15.0.0" log = "0.4" -parking_lot = "0.11.2" +parking_lot = "0.12" [dev-dependencies] env_logger = "0.5" diff --git a/crates/db/blooms-db/Cargo.toml b/crates/db/blooms-db/Cargo.toml index 61132a5c0..3d8eccf42 100644 --- a/crates/db/blooms-db/Cargo.toml +++ b/crates/db/blooms-db/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] byteorder = "1.2" ethbloom = "0.9.1" -parking_lot = "0.11.2" +parking_lot = "0.12" tiny-keccak = "1.4" [dev-dependencies] diff --git a/crates/db/db/Cargo.toml b/crates/db/db/Cargo.toml index 8f1317aec..3ee1c0fb3 100644 --- a/crates/db/db/Cargo.toml +++ b/crates/db/db/Cargo.toml @@ -14,7 +14,7 @@ kvdb = "0.1" kvdb-rocksdb = "0.1.3" kvdb-memorydb = "0.1" parity-util-mem = "0.7" -parking_lot = "0.11.2" +parking_lot = "0.12" rlp = { version = "0.4.6" } rlp-derive = { version = "0.2"} stats = { path = "../../util/stats" } \ No newline at end of file diff --git a/crates/db/journaldb/Cargo.toml b/crates/db/journaldb/Cargo.toml index d34c8e9d9..f13fa9cb3 100644 --- a/crates/db/journaldb/Cargo.toml +++ b/crates/db/journaldb/Cargo.toml @@ -16,7 +16,7 @@ kvdb = "0.1" log = "0.4" memory-db = { path = "../memory-db" } parity-util-mem = "0.7" -parking_lot = "0.11.2" +parking_lot = "0.12" fastmap = { path = "../../util/fastmap" } rlp = { version = "0.4.6" } diff --git a/crates/ethcore/Cargo.toml b/crates/ethcore/Cargo.toml index 1e3e1eeb0..f7cfcd6fb 100644 --- a/crates/ethcore/Cargo.toml +++ b/crates/ethcore/Cargo.toml @@ -58,7 +58,7 @@ parity-bytes = "0.1" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } parity-snappy = "0.1" parity-util-mem = "0.7" -parking_lot = "0.11.2" +parking_lot = "0.12" trie-db = "0.11.0" patricia-trie-ethereum = { path = "../db/patricia-trie-ethereum" } rand_065 = { package = "rand", version = "0.6.5" } diff --git a/crates/ethcore/blockchain/Cargo.toml b/crates/ethcore/blockchain/Cargo.toml index 35855c784..f9eec5ec5 100644 --- a/crates/ethcore/blockchain/Cargo.toml +++ b/crates/ethcore/blockchain/Cargo.toml @@ -20,7 +20,7 @@ log = "0.4" parity-bytes = "0.1" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } parity-util-mem = "0.7" -parking_lot = "0.11.2" +parking_lot = "0.12" rand = "0.7.3" rayon = "1.1" rlp = { version = "0.4.6" } diff --git a/crates/ethcore/sync/Cargo.toml b/crates/ethcore/sync/Cargo.toml index 28d49a144..3fff084c8 100644 --- a/crates/ethcore/sync/Cargo.toml +++ b/crates/ethcore/sync/Cargo.toml @@ -32,7 +32,7 @@ macros = { path = "../../util/macros" } parity-bytes = "0.1" parity-crypto = { version = "0.6.2", features = [ "publickey" ] } parity-util-mem = "0.7" -parking_lot = "0.11.2" +parking_lot = "0.12" rand = "0.7.3" rand_xorshift = "0.2.0" rlp = { version = "0.4.6" } diff --git a/crates/net/network-devp2p/Cargo.toml b/crates/net/network-devp2p/Cargo.toml index 5b6ec72bf..2691952bd 100644 --- a/crates/net/network-devp2p/Cargo.toml +++ b/crates/net/network-devp2p/Cargo.toml @@ -16,7 +16,7 @@ tiny-keccak = "1.4" slab = "0.2" igd = "0.8" libc = "0.2.7" -parking_lot = "0.11.2" +parking_lot = "0.12" ansi_term = "0.10" rustc-hex = "1.0" ethcore-io = { path = "../../runtime/io", features = ["mio"] } diff --git a/crates/net/node-filter/Cargo.toml b/crates/net/node-filter/Cargo.toml index 75d487c89..3d65751f0 100644 --- a/crates/net/node-filter/Cargo.toml +++ b/crates/net/node-filter/Cargo.toml @@ -13,7 +13,7 @@ ethcore-network = { path = "../network" } ethcore-network-devp2p = { path = "../network-devp2p" } ethereum-types = "0.9.2" log = "0.4" -parking_lot = "0.11.2" +parking_lot = "0.12" ethabi = "12.0.0" ethabi-derive = { git = 'https://github.com/rimrakhimov/ethabi', branch = 'rimrakhimov/remove-syn-export-span' } ethabi-contract = "16.0.0" diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index 9ea77af78..b3cb4bd87 100644 --- a/crates/rpc/Cargo.toml +++ b/crates/rpc/Cargo.toml @@ -13,7 +13,7 @@ ansi_term = "0.10" futures = "0.1.6" log = "0.4" order-stat = "0.1" -parking_lot = "0.11.2" +parking_lot = "0.12" rand = "0.7.3" rand_xorshift = "0.2.0" rustc-hex = "1.0" diff --git a/crates/runtime/io/Cargo.toml b/crates/runtime/io/Cargo.toml index 29d0a96f9..537316828 100644 --- a/crates/runtime/io/Cargo.toml +++ b/crates/runtime/io/Cargo.toml @@ -11,7 +11,7 @@ edition = "2024" fnv = "1.0" mio = { version = "0.6.8", optional = true } crossbeam-deque = "0.7.4" -parking_lot = "0.11.2" +parking_lot = "0.12" log = "0.4" slab = "0.4" timer = "0.2" diff --git a/crates/util/cli-signer/rpc-client/Cargo.toml b/crates/util/cli-signer/rpc-client/Cargo.toml index ff0cdb848..504d34fdf 100644 --- a/crates/util/cli-signer/rpc-client/Cargo.toml +++ b/crates/util/cli-signer/rpc-client/Cargo.toml @@ -15,7 +15,7 @@ serde = "1.0" serde_json = "1.0" url = "2" matches = "0.1" -parking_lot = "0.11.2" +parking_lot = "0.12" jsonrpc-core = "15.0.0" jsonrpc-ws-server = "15.0.0" parity-rpc = { path = "../../../rpc" } diff --git a/crates/util/len-caching-lock/Cargo.toml b/crates/util/len-caching-lock/Cargo.toml index 0647e6867..fb838a728 100644 --- a/crates/util/len-caching-lock/Cargo.toml +++ b/crates/util/len-caching-lock/Cargo.toml @@ -8,4 +8,4 @@ authors = ["Parity Technologies "] edition = "2024" [dependencies] -parking_lot = "0.11.2" +parking_lot = "0.12" diff --git a/crates/vm/evm/Cargo.toml b/crates/vm/evm/Cargo.toml index 4aff92d94..baaa0cf4b 100644 --- a/crates/vm/evm/Cargo.toml +++ b/crates/vm/evm/Cargo.toml @@ -14,7 +14,7 @@ log = "0.4" vm = { path = "../vm" } keccak-hash = "0.5.0" parity-util-mem = "0.7" -parking_lot = "0.11.2" +parking_lot = "0.12" memory-cache = { path = "../../util/memory-cache" } ethcore-builtin = { path = "../builtin" } num-bigint = "0.4" From d831a73b1dda897c7de91e6dfdd75f0d45449f66 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 19:30:39 +0200 Subject: [PATCH 538/687] log level updates --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 0f5cd21c7..6ce46cf2c 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -965,7 +965,7 @@ impl HoneyBadgerBFT { fn do_validator_engine_actions(&self) -> Result<(), Error> { // here we need to differentiate the different engine functions, // that requre different levels of access to the client. - debug!(target: "engine", "do_validator_engine_actions."); + trace!(target: "engine", "do_validator_engine_actions."); match self.client_arc() { Some(client_arc) => { if self.is_syncing(&client_arc) { @@ -1031,7 +1031,7 @@ impl HoneyBadgerBFT { } None => { // maybe improve here, to return with a result, that triggers a retry soon. - warn!(target: "engine", "Unable to do_validator_engine_actions: Could not acquire read lock for hbbft state. Unable to decide about early epoch end."); + info!(target: "engine", "Unable to do_validator_engine_actions: Could not acquire read lock for hbbft state. Unable to decide about early epoch end. retrying soon."); } }; } // drop lock for hbbft_state From 975221a70e1fded577ab9a72ed749b7c44c98b91 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 17 Jun 2025 19:35:05 +0200 Subject: [PATCH 539/687] adjusted log levels --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- crates/ethcore/sync/src/chain/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 6ce46cf2c..4d7768e95 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -382,7 +382,7 @@ impl IoHandler<()> for TransitionHandler { let is_staked = self.engine.is_staked(); if is_staked { - debug!(target: "consensus", "We are staked!"); + trace!(target: "consensus", "We are staked!"); let is_available = self.engine.is_available(); if !is_available { warn!(target: "consensus", "Initiating Shutdown: Honey Badger Consensus detected that this Node has been flagged as unavailable, while it should be available."); diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 242c3349e..626456ead 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1021,7 +1021,7 @@ impl ChainSync { // Reactivate peers only if some progress has been made // since the last sync round of if starting fresh. self.active_peers = self.peers.keys().cloned().collect(); - info!(target: "sync", "resetting sync state to {:?}", self.state); + debug!(target: "sync", "resetting sync state to {:?}", self.state); } /// Add a request for later processing From 0ba06a05ab8056488e435f23d9175012cc6fd55c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 18 Jun 2025 21:27:52 +0200 Subject: [PATCH 540/687] Introduced the concept of the deadline stopwatch and deadline based locking strategies. DevP2P uses now this strategy to access data from the transaction queue, with a deadline of 200ms for retrieving transactions (supplier) and 1000ms for planning transaction retrieval. https://github.com/DMDcoin/diamond-node/issues/236 --- Cargo.lock | 1 + crates/concensus/miner/src/pool/queue.rs | 20 +++++++-- crates/ethcore/src/client/client.rs | 10 ++++- crates/ethcore/src/client/test_client.rs | 9 ++++- crates/ethcore/src/client/traits.rs | 7 +++- crates/ethcore/src/miner/miner.rs | 9 ++++- crates/ethcore/src/miner/mod.rs | 7 +++- crates/ethcore/sync/Cargo.toml | 1 + crates/ethcore/sync/src/chain/handler.rs | 23 ++++++++++- crates/ethcore/sync/src/chain/supplier.rs | 14 ++++++- crates/util/time-utils/src/lib.rs | 49 ++++++++++++++++++++++- 11 files changed, 133 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3956243cf..19e8509aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1592,6 +1592,7 @@ dependencies = [ "rlp", "rustc-hex 1.0.0", "stats", + "time-utils", "trace-time", "triehash-ethereum", ] diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index 7f48b42f5..ddea78e91 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -24,6 +24,7 @@ use std::{ atomic::{self, AtomicUsize}, Arc, }, + time::Duration, }; use self::scoring::ScoringEvent; @@ -680,12 +681,23 @@ impl TransactionQueue { /// /// Given transaction hash looks up that transaction in the pool /// and returns a shared pointer to it or `None` if it's not present, or a readlock could not get acquired. - pub fn find_if_readable(&self, hash: &H256) -> Option> { + pub fn find_if_readable( + &self, + hash: &H256, + max_lock_duration: &Duration, + ) -> Option> { + let splitted_duration = max_lock_duration.div_f32(3.0); self.cached_enforced_pending - .try_read()? + .try_read_for(splitted_duration.clone())? .find(hash) - .or(self.cached_non_enforced_pending.try_read()?.find(hash)) - .or(self.pool.try_read()?.find(hash)) + .or(self + .cached_non_enforced_pending + .try_read_for(splitted_duration.clone())? + .find(hash)) + .or(self + .pool + .try_read_for(splitted_duration.clone())? + .find(hash)) } /// Remove a set of transactions from the pool. diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 7e5d8f460..c67dd07f3 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -2426,8 +2426,14 @@ impl BlockChainClient for Client { self.importer.miner.transaction(&hash) } - fn transaction_if_readable(&self, hash: &H256) -> Option> { - self.importer.miner.transaction_if_readable(&hash) + fn transaction_if_readable( + &self, + hash: &H256, + max_lock_duration: &Duration, + ) -> Option> { + self.importer + .miner + .transaction_if_readable(&hash, max_lock_duration) } fn uncle(&self, id: UncleId) -> Option { diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index 10995668a..d884f78e2 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -23,6 +23,7 @@ use std::{ Arc, atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrder}, }, + time::Duration, }; use crate::{ @@ -1160,8 +1161,12 @@ impl BlockChainClient for TestBlockChainClient { self.miner.transaction(tx_hash) } - fn transaction_if_readable(&self, hash: &H256) -> Option> { - self.miner.transaction_if_readable(hash) + fn transaction_if_readable( + &self, + hash: &H256, + max_lock_duration: &Duration, + ) -> Option> { + self.miner.transaction_if_readable(hash, max_lock_duration) } /// Returns the devp2p network endpoint IP and Port information that is used to communicate with other peers. diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 43a59a3e3..6d5fefd88 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -20,6 +20,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, net::SocketAddr, sync::Arc, + time::Duration, }; use crate::{ @@ -425,7 +426,11 @@ pub trait BlockChainClient: /// see queued_transactions(&self). /// Get pool transaction with a given hash, but returns NONE fast, if if cannot acquire a readlock fast. - fn transaction_if_readable(&self, hash: &H256) -> Option>; + fn transaction_if_readable( + &self, + hash: &H256, + max_lock_duration: &Duration, + ) -> Option>; /// Sorted list of transaction gas prices from at least last sample_size blocks. fn gas_price_corpus(&self, sample_size: usize) -> ::stats::Corpus { diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 484aec14e..70f794e04 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -1468,8 +1468,13 @@ impl miner::MinerService for Miner { return result; } - fn transaction_if_readable(&self, hash: &H256) -> Option> { - self.transaction_queue.find_if_readable(hash) + fn transaction_if_readable( + &self, + hash: &H256, + max_lock_duration: &Duration, + ) -> Option> { + self.transaction_queue + .find_if_readable(hash, max_lock_duration) } fn remove_transaction(&self, hash: &H256) -> Option> { diff --git a/crates/ethcore/src/miner/mod.rs b/crates/ethcore/src/miner/mod.rs index e63c3566f..cd0365f15 100644 --- a/crates/ethcore/src/miner/mod.rs +++ b/crates/ethcore/src/miner/mod.rs @@ -35,6 +35,7 @@ pub use ethcore_miner::{ use std::{ collections::{BTreeMap, BTreeSet}, sync::Arc, + time::Duration, }; use crate::types::{ @@ -201,7 +202,11 @@ pub trait MinerService: Send + Sync { /// Query transaction from the pool given it's hash, without blocking. /// Might return "None" in cases when the lock could not get acquired. - fn transaction_if_readable(&self, hash: &H256) -> Option>; + fn transaction_if_readable( + &self, + hash: &H256, + max_lock_duration: &Duration, + ) -> Option>; /// Returns next valid nonce for given address. /// diff --git a/crates/ethcore/sync/Cargo.toml b/crates/ethcore/sync/Cargo.toml index 3fff084c8..a9b558538 100644 --- a/crates/ethcore/sync/Cargo.toml +++ b/crates/ethcore/sync/Cargo.toml @@ -38,6 +38,7 @@ rand_xorshift = "0.2.0" rlp = { version = "0.4.6" } trace-time = "0.1" triehash-ethereum = {version = "0.2", path = "../../util/triehash-ethereum" } +time-utils = { path = "../../util/time-utils" } stats = { path = "../../util/stats" } crossbeam-channel = "0.5.2" diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index d93c924f8..64e77dd80 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -32,7 +32,11 @@ use ethereum_types::{H256, H512, U256}; use hash::keccak; use network::{PeerId, client_version::ClientVersion}; use rlp::Rlp; -use std::{cmp, mem, time::Instant}; +use std::{ + cmp, mem, + time::{Duration, Instant}, +}; +use time_utils::DeadlineStopwatch; use super::{ request_id::strip_request_id, @@ -858,6 +862,11 @@ impl SyncHandler { peer_id: PeerId, tx_rlp: &Rlp, ) -> Result<(), DownloaderImportError> { + // those P2P operations must not take forever, a better , configurable but balanced timeout managment would be nice to have. + let max_duration = Duration::from_millis(500); + + let deadline = DeadlineStopwatch::new(max_duration); + for item in tx_rlp { let hash = item .as_val::() @@ -868,7 +877,17 @@ impl SyncHandler { // if we cant read the pool here, we are asuming we dont know the transaction yet. // in the worst case we are refetching a transaction that we already have. - if io.chain().transaction_if_readable(&hash).is_none() { + + if deadline.is_expired() { + // we did run out of time to finish this opation, but thats Ok. + return Ok(()); + } + + if io + .chain() + .transaction_if_readable(&hash, &deadline.time_left()) + .is_none() + { sync.peers .get_mut(&peer_id) .map(|peer| peer.unfetched_pooled_transactions.insert(hash)); diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index 5ab702b98..e77bfd974 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -18,6 +18,7 @@ use bytes::Bytes; #[cfg(not(test))] use devp2p::PAYLOAD_SOFT_LIMIT; +use time_utils::DeadlineStopwatch; #[cfg(test)] pub const PAYLOAD_SOFT_LIMIT: usize = 100_000; @@ -27,7 +28,7 @@ use ethereum_types::{H256, H512}; use network::{self, PeerId}; use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; -use std::cmp; +use std::{cmp, time::Duration}; use crate::sync_io::SyncIo; @@ -316,14 +317,23 @@ impl SyncSupplier { rlp.begin_unbounded_list(); let mut not_found = 0; let mut parse_errors = 0; + + let deadline = DeadlineStopwatch::new(Duration::from_millis(200)); for v in r { if let Ok(hash) = v.as_val::() { // io.chain().transaction(hash) + if !deadline.should_continue() { + break; + } + // we do not lock here, if we cannot access the memory at this point in time, // we will just skip this transaction, otherwise the other peer might wait to long, resulting in a timeout. // also this solved a potential deadlock situation: - if let Some(tx) = io.chain().transaction_if_readable(&hash) { + if let Some(tx) = io + .chain() + .transaction_if_readable(&hash, &deadline.time_left()) + { tx.signed().rlp_append(&mut rlp); added += 1; if rlp.len() > PAYLOAD_SOFT_LIMIT { diff --git a/crates/util/time-utils/src/lib.rs b/crates/util/time-utils/src/lib.rs index c413df7ee..6dc15b906 100644 --- a/crates/util/time-utils/src/lib.rs +++ b/crates/util/time-utils/src/lib.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; /// Temporary trait for `checked operations` on SystemTime until these are available in the standard library pub trait CheckedSystemTime { @@ -49,6 +49,53 @@ impl CheckedSystemTime for SystemTime { } } +/// a DeadlineStopwatch helps to handle deadlines in a more convenient way. +pub struct DeadlineStopwatch { + started: Instant, + max_duration: Duration, +} + +impl DeadlineStopwatch { + pub fn new(max_duration: Duration) -> Self { + Self { + started: Instant::now(), + max_duration, + } + } + + pub fn elapsed(&self) -> Duration { + self.started.elapsed() + } + + pub fn started(&self) -> &Instant { + &self.started + } + + pub fn end_time(&self) -> Instant { + self.started + self.max_duration + } + + pub fn should_continue(&self) -> bool { + self.elapsed() < self.max_duration + } + + pub fn time_left(&self) -> Duration { + let elapsed = self.elapsed(); + + if elapsed >= self.max_duration { + Duration::from_secs(0) + } else if let Some(time_left) = self.max_duration.checked_sub(elapsed) { + time_left + } else { + Duration::from_secs(0) + } + } + + pub fn is_expired(&self) -> bool { + self.elapsed() >= self.max_duration + } +} + #[cfg(test)] mod tests { #[test] From 53430bd8269c3791ebf0608cfefd5d04680db8f9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 20 Jun 2025 08:00:09 +0200 Subject: [PATCH 541/687] TestMinerService fix for new timeout handling. --- crates/rpc/src/v1/tests/helpers/miner_service.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rpc/src/v1/tests/helpers/miner_service.rs b/crates/rpc/src/v1/tests/helpers/miner_service.rs index b9b1177fb..981ed9b35 100644 --- a/crates/rpc/src/v1/tests/helpers/miner_service.rs +++ b/crates/rpc/src/v1/tests/helpers/miner_service.rs @@ -18,7 +18,7 @@ use std::{ collections::{BTreeMap, BTreeSet, HashMap}, - sync::Arc, + sync::Arc, time::Duration, }; use crate::{ @@ -254,9 +254,9 @@ impl MinerService for TestMinerService { .map(|tx| Arc::new(VerifiedTransaction::from_pending_block_transaction(tx))) } - fn transaction_if_readable(&self, hash: &H256) -> Option> { + fn transaction_if_readable(&self, hash: &H256, max_duration: &Duration) -> Option> { self.pending_transactions - .try_lock()? + .try_lock_for(*max_duration)? .get(hash) .cloned() .map(|tx| Arc::new(VerifiedTransaction::from_pending_block_transaction(tx))) From ecb0009290e86ca4f297f9506b034b54f540673c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 20 Jun 2025 08:10:32 +0200 Subject: [PATCH 542/687] log infos for devP2P infos that could not get processed. --- crates/ethcore/sync/src/chain/handler.rs | 1 + crates/ethcore/sync/src/chain/supplier.rs | 3 ++- crates/rpc/src/v1/tests/helpers/miner_service.rs | 9 +++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index 64e77dd80..ee2e1ffa3 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -879,6 +879,7 @@ impl SyncHandler { // in the worst case we are refetching a transaction that we already have. if deadline.is_expired() { + debug!(target: "sync", "{}: deadline reached while processing pooled transactions", peer_id); // we did run out of time to finish this opation, but thats Ok. return Ok(()); } diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index e77bfd974..01e90205c 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -323,7 +323,8 @@ impl SyncSupplier { if let Ok(hash) = v.as_val::() { // io.chain().transaction(hash) - if !deadline.should_continue() { + if deadline.is_expired() { + debug!(target: "sync", "{} -> GetPooledTransactions: deadline reached, only returning partial result to ", peer_id); break; } diff --git a/crates/rpc/src/v1/tests/helpers/miner_service.rs b/crates/rpc/src/v1/tests/helpers/miner_service.rs index 981ed9b35..3a60429e2 100644 --- a/crates/rpc/src/v1/tests/helpers/miner_service.rs +++ b/crates/rpc/src/v1/tests/helpers/miner_service.rs @@ -18,7 +18,8 @@ use std::{ collections::{BTreeMap, BTreeSet, HashMap}, - sync::Arc, time::Duration, + sync::Arc, + time::Duration, }; use crate::{ @@ -254,7 +255,11 @@ impl MinerService for TestMinerService { .map(|tx| Arc::new(VerifiedTransaction::from_pending_block_transaction(tx))) } - fn transaction_if_readable(&self, hash: &H256, max_duration: &Duration) -> Option> { + fn transaction_if_readable( + &self, + hash: &H256, + max_duration: &Duration, + ) -> Option> { self.pending_transactions .try_lock_for(*max_duration)? .get(hash) From f6c401ee3e5feda1888450686648db5b0ec39290 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 20 Jun 2025 09:02:14 +0200 Subject: [PATCH 543/687] release 0.11.4 --- CHANGELOG.md | 3 +++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6f204a93..98e0752d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## Diamond Node Software 3.3.5-hbbft-0.11.4 +- [Balanced lock approach for solving the lock problems in devp2p](https://github.com/DMDcoin/diamond-node/issues/236) + ## Diamond Node Software 3.3.5-hbbft-0.11.3 - [deadlocks in transaction pools](https://github.com/DMDcoin/diamond-node/issues/236) diff --git a/Cargo.lock b/Cargo.lock index 19e8509aa..4c58bd093 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.3" +version = "3.3.5-hbbft-0.11.4" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3577,7 +3577,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.3" +version = "3.3.5-hbbft-0.11.4" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index f994cfe50..e3091b85c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.3" +version = "3.3.5-hbbft-0.11.4" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index f90e7c806..fd68e8a7e 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.3" +version = "3.3.5-hbbft-0.11.4" authors = [ "bit.diamonds developers", "OpenEthereum developers", From e1110d5d511c8265e2849d3cdf3ff5363bb31725 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 21 Jun 2025 09:59:26 +0200 Subject: [PATCH 544/687] diamond front running resistance: applying the transaction shuffeling for https://github.com/DMDcoin/diamond-node/issues/89 --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 5 ++++- crates/ethcore/src/engines/hbbft/utils/mod.rs | 2 +- .../src/engines/hbbft/utils/transactions_shuffling.rs | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 4d7768e95..d5eeb1a3d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -503,7 +503,7 @@ impl HoneyBadgerBFT { trace!(target: "consensus", "Batch received for epoch {}, creating new Block.", batch.epoch); // Decode and de-duplicate transactions - let batch_txns: Vec<_> = batch + let mut batch_txns: Vec<_> = batch .contributions .iter() .flat_map(|(_, c)| &c.transactions) @@ -564,6 +564,9 @@ impl HoneyBadgerBFT { .write() .insert(batch.epoch, random_number); + // Shuffelin transactions deterministically based on the random number. + batch_txns = crate::engines::hbbft::utils::transactions_shuffling::deterministic_transactions_shuffling(batch_txns, random_number); + if let Some(header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) { let block_num = header.number(); let hash = header.bare_hash(); diff --git a/crates/ethcore/src/engines/hbbft/utils/mod.rs b/crates/ethcore/src/engines/hbbft/utils/mod.rs index c545c13df..61e8abfc8 100644 --- a/crates/ethcore/src/engines/hbbft/utils/mod.rs +++ b/crates/ethcore/src/engines/hbbft/utils/mod.rs @@ -1,2 +1,2 @@ pub mod bound_contract; -mod transactions_shuffling; +pub mod transactions_shuffling; diff --git a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs index 4ad52feae..f12be4f20 100644 --- a/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs +++ b/crates/ethcore/src/engines/hbbft/utils/transactions_shuffling.rs @@ -25,8 +25,7 @@ fn address_xor_u256(address: &Address, seed: U256) -> Address { } /// The list of transactions is expected to be free of duplicates. -#[allow(dead_code)] -fn deterministic_transactions_shuffling( +pub fn deterministic_transactions_shuffling( transactions: Vec, seed: U256, ) -> Vec { From 3794a1d1b378efa71c29537bfe5815220b0d158a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 29 Jun 2025 19:02:11 +0200 Subject: [PATCH 545/687] improved performance by removing useless copy of bytes send to consensus peers. --- crates/ethcore/sync/src/chain/propagator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 74e5c1bb1..4688b1714 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -409,7 +409,7 @@ impl ChainSync { peer_id: usize, ) { self.statistics.log_consensus(peer_id, packet.len()); - ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); + ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet); } fn select_peers_for_transactions(&self, filter: F, are_new: bool) -> Vec From 10351eb91dbae631f6dcb426cc0eaba74ccf76ed Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 30 Jun 2025 10:55:54 +0200 Subject: [PATCH 546/687] - errors in sending messages now require to be handled. - failed messages are now readded to the send cache. - in non critical paths of the consesus, those errors are ignored, like it has been the case all the time. --- crates/ethcore/sync/src/api.rs | 36 +++++++++++- crates/ethcore/sync/src/chain/mod.rs | 8 ++- crates/ethcore/sync/src/chain/propagator.rs | 62 ++++++++++++++------- 3 files changed, 81 insertions(+), 25 deletions(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 0eacadd4e..de5c18c83 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -511,17 +511,39 @@ impl SyncProtocolHandler { node_id: &NodeId, peer_id: PeerId, ) { + // now since we are connected, lets send any cached messages if let Some(vec_msg) = self.message_cache.write().remove(&Some(*node_id)) { trace!(target: "consensus", "Cached Messages: Trying to send cached messages to {:?}", node_id); + + let mut failed_messages: Vec = Vec::new(); + for msg in vec_msg { match msg { - ChainMessageType::Consensus(message) => self + ChainMessageType::Consensus(message) => { + let send_consensus_result = self .sync .write() - .send_consensus_packet(sync_io, message, peer_id), + .send_consensus_packet(sync_io, message.clone(), peer_id); + + match send_consensus_result { + Ok(_) => {}, + Err(e) => { + info!(target: "consensus", "Error sending cached consensus message to peer (re-adding) {:?}: {:?}", peer_id, e); + failed_messages.push(ChainMessageType::Consensus(message)); + }, + } + } } } + + if !failed_messages.is_empty() { + // If we failed to send some messages, cache them for later + let mut lock = self.message_cache.write(); + lock.entry(Some(*node_id)).or_default().extend(failed_messages); + } else { + trace!(target: "consensus", "Cached Messages: Successfully sent all cached messages to {:?}", node_id); + } } } } @@ -742,7 +764,15 @@ impl ChainNotify for EthSync { &self.eth_handler.overlay); match message_type { - ChainMessageType::Consensus(message) => self.eth_handler.sync.write().send_consensus_packet(&mut sync_io, message, my_peer_id), + ChainMessageType::Consensus(message) => { + let send_result = self.eth_handler.sync.write().send_consensus_packet(&mut sync_io, message.clone(), my_peer_id); + if let Err(e) = send_result { + info!(target: "consensus", "Error sending consensus message to peer - caching message {:?}: {:?}", my_peer_id, e); + // If we failed to send the message, cache it for later + let mut lock = self.eth_handler.message_cache.write(); + lock.entry(node_id.clone()).or_default().push(ChainMessageType::Consensus(message)); + } + }, } }); } diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 626456ead..5cdf15ca6 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -577,9 +577,11 @@ impl ChainSyncApi { for peers in sync.get_peers(&chain_info, PeerState::SameBlock).chunks(10) { check_deadline(deadline)?; for peer in peers { - ChainSync::send_packet(io, *peer, NewBlockPacket, rlp.clone()); - if let Some(ref mut peer) = sync.peers.get_mut(peer) { - peer.latest_hash = hash; + let send_result = ChainSync::send_packet(io, *peer, NewBlockPacket, rlp.clone()); + if send_result.is_ok() { + if let Some(ref mut peer) = sync.peers.get_mut(peer) { + peer.latest_hash = hash; + } } } } diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 4688b1714..081d3cd37 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -27,7 +27,7 @@ use crate::{ use bytes::Bytes; use ethereum_types::H256; use fastmap::H256FastSet; -use network::{PeerId, client_version::ClientCapabilities}; +use network::{client_version::ClientCapabilities, Error, PeerId}; use rand::RngCore; use rlp::RlpStream; @@ -77,10 +77,12 @@ impl ChainSync { self.statistics .log_propagated_block(io, *peer_id, blocks.len(), rlp.len()); - ChainSync::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); + let send_result = ChainSync::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); - if let Some(ref mut peer) = self.peers.get_mut(peer_id) { - peer.latest_hash = chain_info.best_block_hash.clone(); + if send_result.is_ok() { + if let Some(ref mut peer) = self.peers.get_mut(peer_id) { + peer.latest_hash = chain_info.best_block_hash.clone(); + } } } }; @@ -122,7 +124,7 @@ impl ChainSync { if let Some(ref mut peer) = self.peers.get_mut(peer_id) { peer.latest_hash = best_block_hash; } - ChainSync::send_packet(io, *peer_id, NewBlockHashesPacket, rlp.clone()); + let _ = ChainSync::send_packet(io, *peer_id, NewBlockHashesPacket, rlp.clone()); } sent } @@ -200,13 +202,8 @@ impl ChainSync { rlp: Bytes| { let size = rlp.len(); - if is_hashes { - stats.log_propagated_hashes(sent, size); - } else { - stats.log_propagated_transactions(sent, size); - } - ChainSync::send_packet( + let send_result = ChainSync::send_packet( io, peer_id, if is_hashes { @@ -216,7 +213,18 @@ impl ChainSync { }, rlp, ); - trace!(target: "sync", "{:02} <- {} ({} entries; {} bytes)", peer_id, if is_hashes { "NewPooledTransactionHashes" } else { "Transactions" }, sent, size); + + + + if send_result.is_ok() { + if is_hashes { + stats.log_propagated_hashes(sent, size); + } else { + stats.log_propagated_transactions(sent, size); + } + trace!(target: "sync", "{:02} <- {} ({} entries; {} bytes)", peer_id, if is_hashes { "NewPooledTransactionHashes" } else { "Transactions" }, sent, size); + } + }; let mut sent_to_peers = HashSet::new(); @@ -385,7 +393,7 @@ impl ChainSync { // more about: https://github.com/DMDcoin/diamond-node/issues/61 let rlp = ChainSync::create_block_rlp(block, io.chain().chain_info().total_difficulty); for peer_id in &peers { - ChainSync::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); + let _ = ChainSync::send_packet(io, *peer_id, NewBlockPacket, rlp.clone()); } } } @@ -398,7 +406,11 @@ impl ChainSync { self.statistics .log_consensus_broadcast(lucky_peers.len(), packet.len()); for peer_id in lucky_peers { - ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); + let send_result = ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); + + if let Err(e) = send_result { + info!(target: "sync", "Error broadcast consensus packet to peer {}: {:?}", peer_id, e); + } } } @@ -407,9 +419,18 @@ impl ChainSync { io: &mut dyn SyncIo, packet: Bytes, peer_id: usize, - ) { - self.statistics.log_consensus(peer_id, packet.len()); - ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet); + ) -> Result<(), Error> { + let packet_len = packet.len(); + let send_result = ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); + match &send_result { + Ok(_) => { + self.statistics.log_consensus(peer_id, packet_len); + }, + Err(e) => { + warn!(target: "sync", "Error sending consensus packet to peer {}: {:?}", peer_id, e); + }, + } + return send_result; } fn select_peers_for_transactions(&self, filter: F, are_new: bool) -> Vec @@ -444,11 +465,14 @@ impl ChainSync { peer_id: PeerId, packet_id: SyncPacket, packet: Bytes, - ) { - if let Err(e) = sync.send(peer_id, packet_id, packet) { + ) -> Result<(), Error> { + let result = sync.send(peer_id, packet_id, packet); + if let Err(e) = &result { debug!(target:"sync", "Error sending packet: {:?}", e); sync.disconnect_peer(peer_id); } + + return result; } /// propagates new transactions to all peers From 5a91d267b59e065a9e8695f092e6b2c83b2d02a0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 30 Jun 2025 14:46:33 +0200 Subject: [PATCH 547/687] Consensus messages are now targeted at NodeIDs (H512) instead of the internally used peer_id, to make sure that they are sent to the correct peer. https://github.com/DMDcoin/diamond-node/issues/248 --- crates/ethcore/src/client/chain_notify.rs | 2 +- crates/ethcore/src/client/client.rs | 4 +- crates/ethcore/src/test_helpers.rs | 6 +- crates/ethcore/sync/src/api.rs | 59 ++++++------------- crates/ethcore/sync/src/chain/mod.rs | 3 +- crates/ethcore/sync/src/chain/propagator.rs | 40 ++++++++----- .../sync/src/chain/propagator_statistics.rs | 2 +- crates/ethcore/sync/src/sync_io.rs | 8 +++ crates/ethcore/sync/src/tests/helpers.rs | 4 ++ crates/net/network-devp2p/src/host.rs | 9 ++- crates/net/network/src/lib.rs | 6 +- 11 files changed, 75 insertions(+), 68 deletions(-) diff --git a/crates/ethcore/src/client/chain_notify.rs b/crates/ethcore/src/client/chain_notify.rs index 257c91d13..030c00875 100644 --- a/crates/ethcore/src/client/chain_notify.rs +++ b/crates/ethcore/src/client/chain_notify.rs @@ -184,7 +184,7 @@ pub trait ChainNotify: Send + Sync { } /// fires when chain sends a message to a specific peer - fn send(&self, _message_type: ChainMessageType, _node_id: Option) { + fn send(&self, _message_type: ChainMessageType, _node_id: &H512) { // does nothing by default } diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index c67dd07f3..5597f8e65 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -3307,7 +3307,9 @@ impl super::traits::EngineClient for Client { .sent_consensus_messages_bytes .fetch_add(message.len() as u64, std::sync::atomic::Ordering::Relaxed); - self.notify(|notify| notify.send(ChainMessageType::Consensus(message.clone()), node_id)); + if let Some(n) = node_id { + self.notify(|notify| notify.send(ChainMessageType::Consensus(message.clone()), &n)); + } } fn epoch_transition_for(&self, parent_hash: H256) -> Option { diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index a191fd411..b6c349904 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -695,11 +695,13 @@ impl ChainNotify for TestNotify { self.messages.write().push(data); } - fn send(&self, message: ChainMessageType, node_id: Option) { + fn send(&self, message: ChainMessageType, node_id: &H512) { let data = match message { ChainMessageType::Consensus(data) => data, }; - self.targeted_messages.write().push((data, node_id)); + self.targeted_messages + .write() + .push((data, Some(node_id.clone()))); } } diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index de5c18c83..6715e6cfe 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -494,24 +494,18 @@ impl SyncProtocolHandler { let mut sync_io = NetSyncIo::new(nc, &*self.chain, &*self.snapshot_service, &self.overlay); for node_id in pub_keys.iter() { - if let Some(peer_id) = nc.node_id_to_peer_id(*node_id) { + if let Some(peer_id) = nc.node_id_to_peer_id(node_id) { let found_peers = self.sync.peer_info(&[peer_id]); if let Some(peer_info) = found_peers.first() { if let Some(_) = peer_info { - self.send_cached_consensus_messages_for(&mut sync_io, node_id, peer_id); + self.send_cached_consensus_messages_for(&mut sync_io, node_id); } } } } } - fn send_cached_consensus_messages_for( - &self, - sync_io: &mut dyn SyncIo, - node_id: &NodeId, - peer_id: PeerId, - ) { - + fn send_cached_consensus_messages_for(&self, sync_io: &mut dyn SyncIo, node_id: &NodeId) { // now since we are connected, lets send any cached messages if let Some(vec_msg) = self.message_cache.write().remove(&Some(*node_id)) { trace!(target: "consensus", "Cached Messages: Trying to send cached messages to {:?}", node_id); @@ -521,17 +515,18 @@ impl SyncProtocolHandler { for msg in vec_msg { match msg { ChainMessageType::Consensus(message) => { - let send_consensus_result = self - .sync - .write() - .send_consensus_packet(sync_io, message.clone(), peer_id); + let send_consensus_result = self.sync.write().send_consensus_packet( + sync_io, + message.clone(), + node_id, + ); match send_consensus_result { - Ok(_) => {}, + Ok(_) => {} Err(e) => { - info!(target: "consensus", "Error sending cached consensus message to peer (re-adding) {:?}: {:?}", peer_id, e); + info!(target: "consensus", "Error sending cached consensus message to peer (re-adding) {:?}: {:?}", node_id, e); failed_messages.push(ChainMessageType::Consensus(message)); - }, + } } } } @@ -540,7 +535,9 @@ impl SyncProtocolHandler { if !failed_messages.is_empty() { // If we failed to send some messages, cache them for later let mut lock = self.message_cache.write(); - lock.entry(Some(*node_id)).or_default().extend(failed_messages); + lock.entry(Some(*node_id)) + .or_default() + .extend(failed_messages); } else { trace!(target: "consensus", "Cached Messages: Successfully sent all cached messages to {:?}", node_id); } @@ -736,28 +733,8 @@ impl ChainNotify for EthSync { }); } - fn send(&self, message_type: ChainMessageType, node_id: Option) { + fn send(&self, message_type: ChainMessageType, node_id: &H512) { self.network.with_context(PAR_PROTOCOL, |context| { - let peer_ids = self.network.connected_peers(); - let target_peer_id = peer_ids.into_iter().find(|p| { - match context.session_info(*p){ - Some(session_info) => { - session_info.id == node_id - }, - None => { warn!(target:"sync", "No session exists for peerId {:?} Node: {:?}", p, node_id); false}, - } - }); - - let my_peer_id = match target_peer_id { - None => { - trace!(target: "consensus", "Cached Messages: peer {:?} not connected, caching message...", node_id); - let mut lock = self.eth_handler.message_cache.write(); - lock.entry(node_id.clone()).or_default().push(message_type); - return; - } - Some(n) => n, - }; - let mut sync_io = NetSyncIo::new(context, &*self.eth_handler.chain, &*self.eth_handler.snapshot_service, @@ -765,12 +742,12 @@ impl ChainNotify for EthSync { match message_type { ChainMessageType::Consensus(message) => { - let send_result = self.eth_handler.sync.write().send_consensus_packet(&mut sync_io, message.clone(), my_peer_id); + let send_result = self.eth_handler.sync.write().send_consensus_packet(&mut sync_io, message.clone(), node_id); if let Err(e) = send_result { - info!(target: "consensus", "Error sending consensus message to peer - caching message {:?}: {:?}", my_peer_id, e); + info!(target: "consensus", "Error sending consensus message to peer - caching message {:?}: {:?}", node_id, e); // If we failed to send the message, cache it for later let mut lock = self.eth_handler.message_cache.write(); - lock.entry(node_id.clone()).or_default().push(ChainMessageType::Consensus(message)); + lock.entry(Some(node_id.clone())).or_default().push(ChainMessageType::Consensus(message)); } }, } diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index 5cdf15ca6..fe0dcebbe 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -577,7 +577,8 @@ impl ChainSyncApi { for peers in sync.get_peers(&chain_info, PeerState::SameBlock).chunks(10) { check_deadline(deadline)?; for peer in peers { - let send_result = ChainSync::send_packet(io, *peer, NewBlockPacket, rlp.clone()); + let send_result = + ChainSync::send_packet(io, *peer, NewBlockPacket, rlp.clone()); if send_result.is_ok() { if let Some(ref mut peer) = sync.peers.get_mut(peer) { peer.latest_hash = hash; diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 081d3cd37..25e7b16cf 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -25,9 +25,9 @@ use crate::{ types::{BlockNumber, blockchain_info::BlockChainInfo, transaction::SignedTransaction}, }; use bytes::Bytes; -use ethereum_types::H256; +use ethereum_types::{H256, H512}; use fastmap::H256FastSet; -use network::{client_version::ClientCapabilities, Error, PeerId}; +use network::{Error, PeerId, client_version::ClientCapabilities}; use rand::RngCore; use rlp::RlpStream; @@ -202,7 +202,6 @@ impl ChainSync { rlp: Bytes| { let size = rlp.len(); - let send_result = ChainSync::send_packet( io, peer_id, @@ -214,17 +213,14 @@ impl ChainSync { rlp, ); - - if send_result.is_ok() { if is_hashes { stats.log_propagated_hashes(sent, size); } else { stats.log_propagated_transactions(sent, size); - } + } trace!(target: "sync", "{:02} <- {} ({} entries; {} bytes)", peer_id, if is_hashes { "NewPooledTransactionHashes" } else { "Transactions" }, sent, size); } - }; let mut sent_to_peers = HashSet::new(); @@ -403,32 +399,46 @@ impl ChainSync { let lucky_peers = ChainSync::select_random_peers(&self.get_consensus_peers()); trace!(target: "sync", "Sending consensus packet to {:?}", lucky_peers); - self.statistics - .log_consensus_broadcast(lucky_peers.len(), packet.len()); + let mut num_sent_messages = 0; for peer_id in lucky_peers { - let send_result = ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); + let send_result = + ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); if let Err(e) = send_result { info!(target: "sync", "Error broadcast consensus packet to peer {}: {:?}", peer_id, e); + } else { + num_sent_messages += 1; } } + + self.statistics + .log_consensus_broadcast(num_sent_messages, packet.len()); } + /// Sends a packet to a specific peer. + /// The caller has to take care about Errors, and reshedule if an error occurs. pub(crate) fn send_consensus_packet( &mut self, io: &mut dyn SyncIo, packet: Bytes, - peer_id: usize, + peer: &H512, ) -> Result<(), Error> { + let peer_id = match io.node_id_to_peer_id(peer) { + Some(id) => id, + None => { + warn!(target: "sync", "Peer with node id {} not found in peers list.", peer); + return Err("No Session for Peer".into()); + } + }; let packet_len = packet.len(); let send_result = ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); match &send_result { Ok(_) => { - self.statistics.log_consensus(peer_id, packet_len); - }, + self.statistics.log_consensus(packet_len); + } Err(e) => { warn!(target: "sync", "Error sending consensus packet to peer {}: {:?}", peer_id, e); - }, + } } return send_result; } @@ -467,7 +477,7 @@ impl ChainSync { packet: Bytes, ) -> Result<(), Error> { let result = sync.send(peer_id, packet_id, packet); - if let Err(e) = &result { + if let Err(e) = &result { debug!(target:"sync", "Error sending packet: {:?}", e); sync.disconnect_peer(peer_id); } diff --git a/crates/ethcore/sync/src/chain/propagator_statistics.rs b/crates/ethcore/sync/src/chain/propagator_statistics.rs index da66e63d5..06274584b 100644 --- a/crates/ethcore/sync/src/chain/propagator_statistics.rs +++ b/crates/ethcore/sync/src/chain/propagator_statistics.rs @@ -79,7 +79,7 @@ impl SyncPropagatorStatistics { } } - pub(crate) fn log_consensus(&mut self, _peer_id: usize, bytelen: usize) { + pub(crate) fn log_consensus(&mut self, bytelen: usize) { if self.logging_enabled { self.consensus_bytes += bytelen as i64; self.consensus_packages += 1; diff --git a/crates/ethcore/sync/src/sync_io.rs b/crates/ethcore/sync/src/sync_io.rs index 5c6a52985..b6382b40f 100644 --- a/crates/ethcore/sync/src/sync_io.rs +++ b/crates/ethcore/sync/src/sync_io.rs @@ -20,6 +20,7 @@ use crate::{ }; use bytes::Bytes; use ethcore::{client::BlockChainClient, snapshot::SnapshotService}; +use ethereum_types::H512; use network::{ Error, NetworkContext, PacketId, PeerId, ProtocolId, SessionInfo, client_version::ClientVersion, }; @@ -58,6 +59,9 @@ pub trait SyncIo { fn is_expired(&self) -> bool; /// Return sync overlay fn chain_overlay(&self) -> &RwLock>; + + /// Returns the peer ID for a given node id, if a corresponding peer exists. + fn node_id_to_peer_id(&self, node_id: &H512) -> Option; } /// Wraps `NetworkContext` and the blockchain client @@ -132,4 +136,8 @@ impl<'s> SyncIo for NetSyncIo<'s> { fn peer_version(&self, peer_id: PeerId) -> ClientVersion { self.network.peer_client_version(peer_id) } + + fn node_id_to_peer_id(&self, node_id: &H512) -> Option { + self.network.node_id_to_peer_id(node_id) + } } diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index a6040f65f..aee9124e8 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -181,6 +181,10 @@ where fn chain_overlay(&self) -> &RwLock> { &self.overlay } + + fn node_id_to_peer_id(&self, node_id: ðereum_types::H512) -> Option { + return Some(node_id.to_low_u64_le() as PeerId); + } } /// Mock for emulution of async run of new blocks diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index e28ac77f7..c2b4cb968 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -296,14 +296,17 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { .unwrap_or(false) } - fn node_id_to_peer_id(&self, node_id: NodeId) -> Option { + fn node_id_to_peer_id(&self, node_id: &NodeId) -> Option { let sessions = self.sessions.read(); let sessions = &*sessions; for i in (0..MAX_SESSIONS).map(|x| x + FIRST_SESSION) { if let Some(session) = sessions.get(i) { - if session.lock().info.id == Some(node_id) { - return Some(i); + let session_node_id_o = session.lock().info.id; + if let Some(session_node_id) = session_node_id_o { + if session_node_id == *node_id { + return Some(i); + } } } } diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index 38f621dc7..2f0f47d04 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -368,7 +368,7 @@ pub trait NetworkContext { fn is_reserved_peer(&self, peer: PeerId) -> bool; /// Returns the peer ID for a given node id, if a corresponding peer exists. - fn node_id_to_peer_id(&self, node_id: NodeId) -> Option; + fn node_id_to_peer_id(&self, node_id: &NodeId) -> Option; } impl<'a, T> NetworkContext for &'a T @@ -429,8 +429,8 @@ where (**self).is_reserved_peer(peer) } - fn node_id_to_peer_id(&self, node_id: NodeId) -> Option { - (**self).node_id_to_peer_id(node_id) + fn node_id_to_peer_id(&self, node_id: &NodeId) -> Option { + (**self).node_id_to_peer_id(&node_id) } } From ee56b0a516f0cd5980c3fe8b67c17c29301be91e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 30 Jun 2025 14:50:15 +0200 Subject: [PATCH 548/687] change log and version update --- CHANGELOG.md | 3 +++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98e0752d0..1bf37e96f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## Diamond Node Software 3.3.5-hbbft-0.11.5 +- [Improved reliability of Hbbft targeted message delivery](https://github.com/DMDcoin/diamond-node/issues/248) + ## Diamond Node Software 3.3.5-hbbft-0.11.4 - [Balanced lock approach for solving the lock problems in devp2p](https://github.com/DMDcoin/diamond-node/issues/236) diff --git a/Cargo.lock b/Cargo.lock index 4c58bd093..a380c6ece 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.4" +version = "3.3.5-hbbft-0.11.5" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3577,7 +3577,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.4" +version = "3.3.5-hbbft-0.11.5" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index e3091b85c..269794c1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.4" +version = "3.3.5-hbbft-0.11.5" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index fd68e8a7e..00d318a46 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.4" +version = "3.3.5-hbbft-0.11.5" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 0cb882f76955196cc311332bb70a2605f92b8900 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 2 Jul 2025 16:44:10 +0200 Subject: [PATCH 549/687] WIP: changing to BTree instead of Slab for session management. --- crates/net/network-devp2p/src/host.rs | 44 ++++++++++++++------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index c2b4cb968..5b6327de8 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -21,7 +21,7 @@ use hash::keccak; use rlp::{Encodable, RlpStream}; use std::{ cmp::{max, min}, - collections::{HashMap, HashSet}, + collections::{BTreeSet, HashMap, HashSet}, fs, io::{self, Read, Write}, net::{Ipv4Addr, SocketAddr, SocketAddrV4}, @@ -29,8 +29,7 @@ use std::{ path::{Path, PathBuf}, str::FromStr, sync::{ - Arc, - atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, + atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, Arc }, time::Duration, }; @@ -108,7 +107,7 @@ impl Encodable for CapabilityInfo { pub struct NetworkContext<'s> { io: &'s IoContext, protocol: ProtocolId, - sessions: Arc>>, + sessions: Arc>>, session: Option, session_id: Option, reserved_peers: &'s HashSet, @@ -161,7 +160,7 @@ impl<'s> NetworkContext<'s> { io: &'s IoContext, protocol: ProtocolId, session: Option, - sessions: Arc>>, + sessions: Arc>>, reserved_peers: &'s HashSet, statistics: &'s NetworkingStatistics, ) -> NetworkContext<'s> { @@ -180,7 +179,7 @@ impl<'s> NetworkContext<'s> { fn resolve_session(&self, peer: PeerId) -> Option { match self.session_id { Some(id) if id == peer => self.session.clone(), - _ => self.sessions.read().get(peer).cloned(), + _ => self.sessions.read().get(&peer).cloned(), } } } @@ -366,7 +365,7 @@ pub struct Host { pub info: RwLock, udp_socket: Mutex>, tcp_listener: Mutex, - sessions: Arc>>, + sessions: Arc>>, discovery: Mutex>>, nodes: RwLock, handlers: RwLock>>, @@ -575,7 +574,7 @@ impl Host { let mut peers = Vec::with_capacity(sessions.count()); for i in (0..MAX_SESSIONS).map(|x| x + FIRST_SESSION) { - if sessions.get(i).is_some() { + if sessions.get(&i).is_some() { peers.push(i); } } @@ -703,13 +702,13 @@ impl Host { self.sessions .read() .iter() - .any(|e| e.lock().id() == Some(id)) + .any(|e| e.1.lock().id() == Some(id)) } fn keep_alive(&self, io: &IoContext) { let mut to_kill = Vec::new(); for e in self.sessions.read().iter() { - let mut s = e.lock(); + let mut s = e.1.lock(); if !s.keep_alive(io) { s.disconnect(io, DisconnectReason::PingTimeout); to_kill.push(s.token()); @@ -847,6 +846,9 @@ impl Host { let nonce = self.info.write().next_nonce(); let mut sessions = self.sessions.write(); + // we can add now the new session. + // if no NodeID is provided, we use the smalles used number. + let token = sessions.insert_with_opt(|token| { trace!(target: "network", "{}: Initiating session {:?}", token, id); match Session::new(io, socket, token, id, &nonce, &self.info.read()) { @@ -886,7 +888,7 @@ impl Host { } fn session_writable(&self, token: StreamToken, io: &IoContext) { - let session = { self.sessions.read().get(token).cloned() }; + let session = { self.sessions.read().get(&token).cloned() }; if let Some(session) = session { let mut s = session.lock(); @@ -909,7 +911,7 @@ impl Host { let mut ready_data: Vec = Vec::new(); let mut packet_data: Vec<(ProtocolId, PacketId, Vec)> = Vec::new(); let mut kill = false; - let session = { self.sessions.read().get(token).cloned() }; + let session = { self.sessions.read().get(&token).cloned() }; let mut ready_id = None; if let Some(session) = session.clone() { { @@ -1047,7 +1049,7 @@ impl Host { .read() .iter() .filter_map(|e| { - let session = e.lock(); + let session = e.1.lock(); if session.token() != token && session.info.id == ready_id { return Some(session.token()); } else { @@ -1183,7 +1185,7 @@ impl Host { let mut expired_session = None; if let FIRST_SESSION..=LAST_SESSION = token { let sessions = self.sessions.read(); - if let Some(session) = sessions.get(token).cloned() { + if let Some(session) = sessions.get(&token).cloned() { expired_session = Some(session.clone()); let mut s = session.lock(); if !s.expired() { @@ -1232,7 +1234,7 @@ impl Host { { let sessions = self.sessions.read(); for c in sessions.iter() { - let s = c.lock(); + let s = c.1.lock(); if let Some(id) = s.id() { if node_changes.removed.contains(id) { to_remove.push(s.token()); @@ -1447,7 +1449,7 @@ impl IoHandler for Host { .unwrap_or_else(|e| debug!("Error registering timer {}: {:?}", token, e)); } NetworkIoMessage::Disconnect(ref peer) => { - let session = { self.sessions.read().get(*peer).cloned() }; + let session = { self.sessions.read().get(&*peer).cloned() }; if let Some(session) = session { session .lock() @@ -1457,7 +1459,7 @@ impl IoHandler for Host { self.kill_connection(*peer, io, false); } NetworkIoMessage::DisablePeer(ref peer) => { - let session = { self.sessions.read().get(*peer).cloned() }; + let session = { self.sessions.read().get(&*peer).cloned() }; if let Some(session) = session { session .lock() @@ -1486,7 +1488,7 @@ impl IoHandler for Host { ) { match stream { FIRST_SESSION..=LAST_SESSION => { - let session = { self.sessions.read().get(stream).cloned() }; + let session = { self.sessions.read().get(&stream).cloned() }; if let Some(session) = session { session .lock() @@ -1522,13 +1524,13 @@ impl IoHandler for Host { match stream { FIRST_SESSION..=LAST_SESSION => { let mut connections = self.sessions.write(); - if let Some(connection) = connections.get(stream).cloned() { + if let Some(connection) = connections.get(&stream).cloned() { let c = connection.lock(); if c.expired() { // make sure it is the same connection that the event was generated for c.deregister_socket(event_loop) .expect("Error deregistering socket"); - connections.remove(stream); + connections.remove(&stream); } } } @@ -1545,7 +1547,7 @@ impl IoHandler for Host { ) { match stream { FIRST_SESSION..=LAST_SESSION => { - let connection = { self.sessions.read().get(stream).cloned() }; + let connection = { self.sessions.read().get(&&stream).cloned() }; if let Some(connection) = connection { connection .lock() From 97ac7b1bdd5c55273748302e261eb5ba444cd00d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 2 Jul 2025 22:26:16 +0200 Subject: [PATCH 550/687] fixed more errors --- crates/net/network-devp2p/src/host.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 5b6327de8..48f3796df 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -107,7 +107,7 @@ impl Encodable for CapabilityInfo { pub struct NetworkContext<'s> { io: &'s IoContext, protocol: ProtocolId, - sessions: Arc>>, + sessions: Arc>>, session: Option, session_id: Option, reserved_peers: &'s HashSet, @@ -299,8 +299,10 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { let sessions = self.sessions.read(); let sessions = &*sessions; + // todo: + // we can do deterministic lookup here ?! for i in (0..MAX_SESSIONS).map(|x| x + FIRST_SESSION) { - if let Some(session) = sessions.get(i) { + if let Some(session) = sessions.get(&i) { let session_node_id_o = session.lock().info.id; if let Some(session_node_id) = session_node_id_o { if session_node_id == *node_id { @@ -514,7 +516,7 @@ impl Host { let reserved: HashSet = self.reserved_nodes.read().clone(); let mut to_kill = Vec::new(); for e in self.sessions.read().iter() { - let mut s = e.lock(); + let mut s = e.1.lock(); { let id = s.id(); if id.map_or(false, |id| reserved.contains(id)) { @@ -556,7 +558,7 @@ impl Host { self.stopping.store(true, AtomicOrdering::SeqCst); let mut to_kill = Vec::new(); for e in self.sessions.read().iter() { - let mut s = e.lock(); + let mut s = e.1.lock(); s.disconnect(io, DisconnectReason::ClientQuit); to_kill.push(s.token()); } @@ -660,7 +662,7 @@ impl Host { self.sessions .read() .iter() - .any(|e| e.lock().info.id == Some(*id)) + .any(|e| e.1.lock().info.id == Some(*id)) } // returns (handshakes, egress, ingress) From 5cc55f37ad23ecb44ea7662ba5bf7e4a14a48654 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 2 Jul 2025 22:58:47 +0200 Subject: [PATCH 551/687] gather a read lock instead of a copy for session reading. (reverted previouse change) --- crates/net/network-devp2p/src/host.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index c2b4cb968..cf62550e2 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -512,7 +512,7 @@ impl Host { drop(info); if let NonReservedPeerMode::Deny = mode { // disconnect all non-reserved peers here. - let reserved: HashSet = self.reserved_nodes.read().clone(); + let reserved = self.reserved_nodes.read(); let mut to_kill = Vec::new(); for e in self.sessions.read().iter() { let mut s = e.lock(); @@ -1087,7 +1087,7 @@ impl Host { } for (p, packet_id, data) in packet_data { - let reserved = self.reserved_nodes.read().clone(); + let reserved = self.reserved_nodes.read(); if let Some(h) = handlers.get(&p) { h.read( &NetworkContext::new( From 5819d052b8622b5104a602f45c10e27d59cbd7e9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 3 Jul 2025 23:02:29 +0200 Subject: [PATCH 552/687] WIP: new session management. --- crates/net/network-devp2p/src/host.rs | 137 +++++++++++++++++--------- 1 file changed, 91 insertions(+), 46 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 48f3796df..49b4d5891 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -19,9 +19,10 @@ use crypto::publickey::{Generator, KeyPair, Random, Secret}; use ethereum_types::H256; use hash::keccak; use rlp::{Encodable, RlpStream}; +use slab::Index; use std::{ - cmp::{max, min}, - collections::{BTreeSet, HashMap, HashSet}, + cmp::{max, min, Ordering}, + collections::{BTreeMap, HashMap, HashSet}, fs, io::{self, Read, Write}, net::{Ipv4Addr, SocketAddr, SocketAddrV4}, @@ -29,7 +30,7 @@ use std::{ path::{Path, PathBuf}, str::FromStr, sync::{ - atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, Arc + atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering as AtomicOrdering}, Arc }, time::Duration, }; @@ -49,7 +50,7 @@ use network::{ client_version::ClientVersion, }; use parity_path::restrict_permissions_owner; -use parking_lot::{Mutex, RwLock}; +use parking_lot::{lock_api::RwLockReadGuard, Mutex, RwLock}; use stats::{PrometheusMetrics, PrometheusRegistry}; type Slab = ::slab::Slab; @@ -360,6 +361,45 @@ struct ProtocolTimer { pub token: TimerToken, // Handler level token } + + +struct SessionContainer { + sessions: Arc>>, + node_id_to_session: BTreeMap, + sessions_tokens: Mutex, // Used to generate new session tokens +} + +impl SessionContainer { + + pub fn new() -> Self { + SessionContainer { + sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), + node_id_to_session: BTreeMap::new(), + sessions_tokens: Mutex::new(0), + } + } + + /// Returns a reference to the sessions map. + pub fn sessions(&self) -> &Arc>> { + &self.sessions + } + + /// gets the next token ID and store this information + fn next_token_id(&self) -> usize { + let lock = self.sessions_tokens.lock(); + + let next_id = 0; + // if (lock.as_usize() > usize::MAX - 1) { + + // } + //let sessions = self.sessions.read(); + + + todo!("Implement next_token_id logic"); + + } +} + /// Root IO handler. Manages protocol handlers, IO timers and network connections. /// /// NOTE: must keep the lock in order of: reserved_nodes (rwlock) -> session (mutex, from sessions) @@ -367,7 +407,7 @@ pub struct Host { pub info: RwLock, udp_socket: Mutex>, tcp_listener: Mutex, - sessions: Arc>>, + sessions: SessionContainer, discovery: Mutex>>, nodes: RwLock, handlers: RwLock>>, @@ -437,10 +477,7 @@ impl Host { discovery: Mutex::new(None), udp_socket: Mutex::new(None), tcp_listener: Mutex::new(tcp_listener), - sessions: Arc::new(RwLock::new(Slab::new_starting_at( - FIRST_SESSION, - MAX_SESSIONS, - ))), + sessions: SessionContainer::new(), nodes: RwLock::new(NodeTable::new(path)), handlers: RwLock::new(HashMap::new()), timers: RwLock::new(HashMap::new()), @@ -515,7 +552,7 @@ impl Host { // disconnect all non-reserved peers here. let reserved: HashSet = self.reserved_nodes.read().clone(); let mut to_kill = Vec::new(); - for e in self.sessions.read().iter() { + for e in self.sessions.sessions.read().iter() { let mut s = e.1.lock(); { let id = s.id(); @@ -557,7 +594,7 @@ impl Host { pub fn stop(&self, io: &IoContext) { self.stopping.store(true, AtomicOrdering::SeqCst); let mut to_kill = Vec::new(); - for e in self.sessions.read().iter() { + for e in self.sessions.sessions.read().iter() { let mut s = e.1.lock(); s.disconnect(io, DisconnectReason::ClientQuit); to_kill.push(s.token()); @@ -571,10 +608,10 @@ impl Host { /// Get all connected peers. pub fn connected_peers(&self) -> Vec { - let sessions = self.sessions.read(); + let sessions = self.sessions.sessions.read(); let sessions = &*sessions; - let mut peers = Vec::with_capacity(sessions.count()); + let mut peers = Vec::with_capacity(sessions.len()); for i in (0..MAX_SESSIONS).map(|x| x + FIRST_SESSION) { if sessions.get(&i).is_some() { peers.push(i); @@ -659,7 +696,7 @@ impl Host { } fn have_session(&self, id: &NodeId) -> bool { - self.sessions + self.sessions.sessions .read() .iter() .any(|e| e.1.lock().info.id == Some(*id)) @@ -670,8 +707,8 @@ impl Host { let mut handshakes = 0; let mut egress = 0; let mut ingress = 0; - for s in self.sessions.read().iter() { - match s.try_lock() { + for s in self.sessions.sessions.read().iter() { + match s.1.try_lock() { Some(ref s) if s.is_ready() && s.info.originated => egress += 1, Some(ref s) if s.is_ready() && !s.info.originated => ingress += 1, _ => handshakes += 1, @@ -686,9 +723,9 @@ impl Host { let mut egress = 0; let mut ingress = 0; - if let Some(lock) = self.sessions.try_read_for(lock_duration) { + if let Some(lock) = self.sessions.sessions.try_read_for(lock_duration) { for s in lock.iter() { - match s.try_lock() { + match s.1.try_lock() { Some(ref s) if s.is_ready() && s.info.originated => egress += 1, Some(ref s) if s.is_ready() && !s.info.originated => ingress += 1, _ => handshakes += 1, @@ -701,7 +738,8 @@ impl Host { } fn connecting_to(&self, id: &NodeId) -> bool { - self.sessions + // todo: we can use the mapping here for faster access. + self.sessions.sessions .read() .iter() .any(|e| e.1.lock().id() == Some(id)) @@ -709,7 +747,7 @@ impl Host { fn keep_alive(&self, io: &IoContext) { let mut to_kill = Vec::new(); - for e in self.sessions.read().iter() { + for e in self.sessions.sessions.read().iter() { let mut s = e.1.lock(); if !s.keep_alive(io) { s.disconnect(io, DisconnectReason::PingTimeout); @@ -846,21 +884,26 @@ impl Host { io: &IoContext, ) -> Result<(), Error> { let nonce = self.info.write().next_nonce(); - let mut sessions = self.sessions.write(); + let mut sessions = self.sessions.sessions.write(); + + // even a try without success will give a new token. + let token = self.session.next_token_id(); // we can add now the new session. // if no NodeID is provided, we use the smalles used number. - let token = sessions.insert_with_opt(|token| { - trace!(target: "network", "{}: Initiating session {:?}", token, id); - match Session::new(io, socket, token, id, &nonce, &self.info.read()) { - Ok(s) => Some(Arc::new(Mutex::new(s))), - Err(e) => { - debug!(target: "network", "Session create error: {:?}", e); - None - } + let existing = sessions.get(&token); + + + + trace!(target: "network", "{}: Initiating session {:?}", token, id); + let session = match Session::new(io, socket, token, id, &nonce, &self.info.read()) { + Ok(s) => Some(Arc::new(Mutex::new(s))), + Err(e) => { + debug!(target: "network", "Session create error: {:?}", e); + None } - }); + }; match token { Some(t) => io.register_stream(t).map(|_| ()).map_err(Into::into), @@ -890,7 +933,7 @@ impl Host { } fn session_writable(&self, token: StreamToken, io: &IoContext) { - let session = { self.sessions.read().get(&token).cloned() }; + let session = { self.sessions.sessions.read().get(&token).cloned() }; if let Some(session) = session { let mut s = session.lock(); @@ -913,7 +956,7 @@ impl Host { let mut ready_data: Vec = Vec::new(); let mut packet_data: Vec<(ProtocolId, PacketId, Vec)> = Vec::new(); let mut kill = false; - let session = { self.sessions.read().get(&token).cloned() }; + let session = { self.sessions.sessions.read().get(&token).cloned() }; let mut ready_id = None; if let Some(session) = session.clone() { { @@ -1047,6 +1090,7 @@ impl Host { let handlers = self.handlers.read(); if !ready_data.is_empty() { let duplicates: Vec = self + .sessions .sessions .read() .iter() @@ -1077,7 +1121,7 @@ impl Host { io, p, Some(session.clone()), - self.sessions.clone(), + self.sessions.sessions.clone(), &reserved, &self.statistics, ), @@ -1098,7 +1142,7 @@ impl Host { io, p, Some(session.clone()), - self.sessions.clone(), + self.sessions.sessions.clone(), &reserved, &self.statistics, ), @@ -1186,7 +1230,7 @@ impl Host { let mut deregister = false; let mut expired_session = None; if let FIRST_SESSION..=LAST_SESSION = token { - let sessions = self.sessions.read(); + let sessions = self.sessions.sessions.read(); if let Some(session) = sessions.get(&token).cloned() { expired_session = Some(session.clone()); let mut s = session.lock(); @@ -1217,7 +1261,7 @@ impl Host { io, p, expired_session.clone(), - self.sessions.clone(), + self.sessions.sessions.clone(), &reserved, &self.statistics, ), @@ -1234,7 +1278,7 @@ impl Host { fn update_nodes(&self, _io: &IoContext, node_changes: TableUpdates) { let mut to_remove: Vec = Vec::new(); { - let sessions = self.sessions.read(); + let sessions = self.sessions.sessions.read(); for c in sessions.iter() { let s = c.1.lock(); if let Some(id) = s.id() { @@ -1261,7 +1305,7 @@ impl Host { io, protocol, None, - self.sessions.clone(), + self.sessions.sessions.clone(), &reserved, &self.statistics, ); @@ -1283,12 +1327,13 @@ impl Host { io, protocol, None, - self.sessions.clone(), + self.sessions.sessions.clone(), &reserved, &self.statistics, ); action(&context) } + } impl IoHandler for Host { @@ -1383,7 +1428,7 @@ impl IoHandler for Host { io, timer.protocol, None, - self.sessions.clone(), + self.sessions.sessions.clone(), &reserved, &self.statistics, ), @@ -1414,7 +1459,7 @@ impl IoHandler for Host { io, *protocol, None, - self.sessions.clone(), + self.sessions.sessions.clone(), &reserved, &self.statistics, )); @@ -1451,7 +1496,7 @@ impl IoHandler for Host { .unwrap_or_else(|e| debug!("Error registering timer {}: {:?}", token, e)); } NetworkIoMessage::Disconnect(ref peer) => { - let session = { self.sessions.read().get(&*peer).cloned() }; + let session = { self.sessions.sessions.read().get(&*peer).cloned() }; if let Some(session) = session { session .lock() @@ -1461,7 +1506,7 @@ impl IoHandler for Host { self.kill_connection(*peer, io, false); } NetworkIoMessage::DisablePeer(ref peer) => { - let session = { self.sessions.read().get(&*peer).cloned() }; + let session = { self.sessions.sessions.read().get(&*peer).cloned() }; if let Some(session) = session { session .lock() @@ -1490,7 +1535,7 @@ impl IoHandler for Host { ) { match stream { FIRST_SESSION..=LAST_SESSION => { - let session = { self.sessions.read().get(&stream).cloned() }; + let session = { self.sessions.sessions.read().get(&stream).cloned() }; if let Some(session) = session { session .lock() @@ -1525,7 +1570,7 @@ impl IoHandler for Host { ) { match stream { FIRST_SESSION..=LAST_SESSION => { - let mut connections = self.sessions.write(); + let mut connections = self.sessions.sessions.write(); if let Some(connection) = connections.get(&stream).cloned() { let c = connection.lock(); if c.expired() { @@ -1549,7 +1594,7 @@ impl IoHandler for Host { ) { match stream { FIRST_SESSION..=LAST_SESSION => { - let connection = { self.sessions.read().get(&&stream).cloned() }; + let connection = { self.sessions.sessions.read().get(&&stream).cloned() }; if let Some(connection) = connection { connection .lock() From 86a2db0b1ac92cb7bb2e55318b291d33a8662b50 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Jul 2025 17:14:43 +0200 Subject: [PATCH 553/687] new error types for Networking --- crates/net/network/src/error.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/net/network/src/error.rs b/crates/net/network/src/error.rs index fff4dc42d..63b0b6a06 100644 --- a/crates/net/network/src/error.rs +++ b/crates/net/network/src/error.rs @@ -160,6 +160,18 @@ error_chain! { display("Too many open files on system. Consider closing some processes/release some file handlers or increas the system-wide resource limits and restart openethereum."), } + #[doc = "A connection to the specified nodeId already exists."] + AlreadyExists { + description("A connection to the specified nodeId already exists."), + display("A connection to the specified nodeId already exists."), + } + + #[doc = "A connection to the specified NodeId exists, but there is a missmatch in the host cache."] + HostCacheInconsistency { + description("A connection to the specified nodeId already exists."), + display("A connection to the specified NodeId exists, but there is a missmatch in the host cache."), + } + #[doc = "An unknown IO error occurred."] Io(err: io::Error) { description("IO Error"), From 38ca972ae0b08658d87782963c41fe3ad5f2d4b0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Jul 2025 19:15:51 +0200 Subject: [PATCH 554/687] WIP first Logic part for new peer ID mapping --- crates/net/network-devp2p/src/host.rs | 161 ++++++++++++++++++++------ 1 file changed, 128 insertions(+), 33 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 49b4d5891..85c713cf3 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -19,9 +19,8 @@ use crypto::publickey::{Generator, KeyPair, Random, Secret}; use ethereum_types::H256; use hash::keccak; use rlp::{Encodable, RlpStream}; -use slab::Index; use std::{ - cmp::{max, min, Ordering}, + cmp::{max, min}, collections::{BTreeMap, HashMap, HashSet}, fs, io::{self, Read, Write}, @@ -30,7 +29,7 @@ use std::{ path::{Path, PathBuf}, str::FromStr, sync::{ - atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering as AtomicOrdering}, Arc + atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, Arc }, time::Duration, }; @@ -365,7 +364,7 @@ struct ProtocolTimer { struct SessionContainer { sessions: Arc>>, - node_id_to_session: BTreeMap, + node_id_to_session: Mutex>, sessions_tokens: Mutex, // Used to generate new session tokens } @@ -374,7 +373,7 @@ impl SessionContainer { pub fn new() -> Self { SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), - node_id_to_session: BTreeMap::new(), + node_id_to_session: Mutex::new(BTreeMap::new()), sessions_tokens: Mutex::new(0), } } @@ -385,7 +384,9 @@ impl SessionContainer { } /// gets the next token ID and store this information - fn next_token_id(&self) -> usize { + fn create_token_id(&self, tokens: &BTreeMap) -> usize { + + tokens.len let lock = self.sessions_tokens.lock(); let next_id = 0; @@ -398,6 +399,125 @@ impl SessionContainer { todo!("Implement next_token_id logic"); } + + + /// Creates a new session and adds it to the session container. + /// returns the token ID of the new session, or an Error if not successful. + fn create_connection(&self, socket: TcpStream, id: Option<ðereum_types::H512>, io: &IoContext, nonce: &H256, host: &HostInfo) -> Result { + + + // make sure noone else is trying to modify the sessions at the same time. + // creating a connection is a very rare event. + + // always lock the node_id_to_session first, then the sessions. + let mut node_ids = self.node_id_to_session.lock(); + let mut sessions = self.sessions.write(); + + + // even a try without success will give a new token. + //let token = self.create_token_id(&id); + // we can add now the new session. + // if no NodeID is provided, we use the smalles used number. + + if let Some(node_id) = id { + + // check if there is already a connection for the given node id. + if let Some(existing_peer_id) = node_ids.get(node_id) { + + if let Some(existing_session_mutex) = sessions.get(existing_peer_id) { + let session = existing_session_mutex.lock(); + if let Some(id_from_session) = &session.info.id { + if session.info.id == Some(*node_id) { + // we got already got a session for the specified node. + // maybe the old session is already scheduled for getting deleted. + if session.expired() { + // if the session is expired, we will just create n new session for this node. + let new_session = Session::new(io, socket, existing_peer_id.clone(), id, nonce, host); + match new_session { + Ok(session) => { + let old_session = sessions.insert(*existing_peer_id, Arc::new(Mutex::new(session))); + // node_ids does not need to get updated, since it uses the same value. + + // in this context, the stream might already be unregistered ?! + // we can just register the stream again. + if let Err(err) = io.register_stream(*existing_peer_id) { + // todo: research this topic, watch out for this message, + // maybe we can keep track of stream registrations as well somehow. + debug!(target: "network", "Failed to register stream for token: {} : {}", existing_peer_id, err); + } + + debug!(target: "network", "Created new session for node id: {}", node_id); + return Ok(*existing_peer_id); + }, + Err(e) => { + error!(target: "network", "Failed to create session for node id: {}", node_id); + return Err(e); + } + } + } else { + // this might happen if 2 nodes try to connect to each other at the same time. + debug!(target: "network", "Session already exists for node id: {}", node_id); + return Err(ErrorKind::AlreadyExists.into()); + } + + } else { + error!(target: "network", "host cache inconsistency: Session node id missmatch. expected: {} is {}.", existing_peer_id, id_from_session); + return Err(ErrorKind::HostCacheInconsistency.into()); + } + } else { + error!(target: "network", "host cache inconsistency: Session has no Node_id defined where it should for {}", existing_peer_id); + return Err(ErrorKind::HostCacheInconsistency.into()); + } + } else { + // we have a node id, but there is no session for it (anymore) + + match Session::new(io, socket, existing_peer_id.clone(), id, nonce, host) { + Ok(new_session) => { + + }, + Err(err) => { + + } + } + error!(target: "network", "host cache inconsistency: Session does not exist for node id: {}", node_id); + return Err(ErrorKind::HostCacheInconsistency.into()); + } + } else { + // this should be the most common scenario. + // we have a new node id, we were either never connected to, or we forgot about it. + + let next_free_token = self.get_next_free_token(); + + } + } else { + // we dont know the NodeID. + let address = socket.peer_addr().map_or("unknown".to_string(), |a| a.to_string()); + debug!(target: "network", "No NodeID found for peer: {}", address); + } + // if we dont know a NodeID + // debug!(target: "network", "Session create error: {:?}", e); + + + let existing = sessions.get(&token); + + + trace!(target: "network", "{}: Initiating session {:?}", token, id); + let session = match Session::new(io, socket, token, id, &nonce, &self.info.read()) { + Ok(s) => Some(Arc::new(Mutex::new(s))), + Err(e) => { + debug!(target: "network", "Session create error: {:?}", e); + None + } + }; + + match token { + Some(t) => io.register_stream(t).map(|_| ()).map_err(Into::into), + None => { + debug!(target: "network", "Max sessions reached"); + Ok(()) + } + } + } } /// Root IO handler. Manages protocol handlers, IO timers and network connections. @@ -883,35 +1003,10 @@ impl Host { id: Option<&NodeId>, io: &IoContext, ) -> Result<(), Error> { - let nonce = self.info.write().next_nonce(); - let mut sessions = self.sessions.sessions.write(); - - - // even a try without success will give a new token. - let token = self.session.next_token_id(); - // we can add now the new session. - // if no NodeID is provided, we use the smalles used number. - let existing = sessions.get(&token); - - - - trace!(target: "network", "{}: Initiating session {:?}", token, id); - let session = match Session::new(io, socket, token, id, &nonce, &self.info.read()) { - Ok(s) => Some(Arc::new(Mutex::new(s))), - Err(e) => { - debug!(target: "network", "Session create error: {:?}", e); - None - } - }; + let nonce = self.info.write().next_nonce(); + self.sessions.create_connection(socket, id, io, nonce) - match token { - Some(t) => io.register_stream(t).map(|_| ()).map_err(Into::into), - None => { - debug!(target: "network", "Max sessions reached"); - Ok(()) - } - } } fn accept(&self, io: &IoContext) { From 8247352d2d04ec4edf30d44467d430520602c2ba Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Jul 2025 20:30:14 +0200 Subject: [PATCH 555/687] further implementation of session container. --- crates/net/network-devp2p/src/host.rs | 87 ++++++++++++--------------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 85c713cf3..96a81ecd9 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -31,7 +31,7 @@ use std::{ sync::{ atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, Arc }, - time::Duration, + time::{Duration, Instant}, }; use crate::{ @@ -49,7 +49,7 @@ use network::{ client_version::ClientVersion, }; use parity_path::restrict_permissions_owner; -use parking_lot::{lock_api::RwLockReadGuard, Mutex, RwLock}; +use parking_lot::{lock_api::{RwLockReadGuard, RwLockUpgradableReadGuard}, Mutex, RwLock}; use stats::{PrometheusMetrics, PrometheusRegistry}; type Slab = ::slab::Slab; @@ -364,8 +364,8 @@ struct ProtocolTimer { struct SessionContainer { sessions: Arc>>, - node_id_to_session: Mutex>, - sessions_tokens: Mutex, // Used to generate new session tokens + node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. + sessions_token_max: Mutex, // Used to generate new session tokens } impl SessionContainer { @@ -374,7 +374,7 @@ impl SessionContainer { SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), node_id_to_session: Mutex::new(BTreeMap::new()), - sessions_tokens: Mutex::new(0), + sessions_token_max: Mutex::new(0), } } @@ -384,20 +384,17 @@ impl SessionContainer { } /// gets the next token ID and store this information - fn create_token_id(&self, tokens: &BTreeMap) -> usize { + fn create_token_id(&self, node_id: &NodeId, tokens: &mut BTreeMap) -> usize { - tokens.len - let lock = self.sessions_tokens.lock(); - - let next_id = 0; - // if (lock.as_usize() > usize::MAX - 1) { - - // } - //let sessions = self.sessions.read(); - - - todo!("Implement next_token_id logic"); - + let mut session_token_max = self.sessions_token_max.lock(); + let next_id = session_token_max.clone(); + + *session_token_max += 1; + if let Some(old) = tokens.insert(node_id.clone(), next_id) { + warn!(target: "network", "Node ID {} already exists with token {}, overwriting with {}", node_id, old, next_id); + } + + return next_id; } @@ -412,12 +409,6 @@ impl SessionContainer { // always lock the node_id_to_session first, then the sessions. let mut node_ids = self.node_id_to_session.lock(); let mut sessions = self.sessions.write(); - - - // even a try without success will give a new token. - //let token = self.create_token_id(&id); - // we can add now the new session. - // if no NodeID is provided, we use the smalles used number. if let Some(node_id) = id { @@ -435,7 +426,8 @@ impl SessionContainer { let new_session = Session::new(io, socket, existing_peer_id.clone(), id, nonce, host); match new_session { Ok(session) => { - let old_session = sessions.insert(*existing_peer_id, Arc::new(Mutex::new(session))); + //let mut session_write = RwLockUpgradableReadGuard::upgrade(sessions); + let _old_session = sessions.insert(*existing_peer_id, Arc::new(Mutex::new(session))); // node_ids does not need to get updated, since it uses the same value. // in this context, the stream might already be unregistered ?! @@ -486,37 +478,38 @@ impl SessionContainer { // this should be the most common scenario. // we have a new node id, we were either never connected to, or we forgot about it. - let next_free_token = self.get_next_free_token(); + let next_free_token = self.create_token_id(&node_id, &mut node_ids); + let new_session = Session::new(io, socket, next_free_token.clone(), id, nonce, host); + // the token is already registerd. + match new_session { + Ok(session) => { + let session = Arc::new(Mutex::new(session)); + sessions.insert(next_free_token, session.clone()); + // register the stream for the new session. + if let Err(err) = io.register_stream(next_free_token) { + debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); + } + node_ids.insert(node_id.clone(), next_free_token); + trace!(target: "network", "Created new session for node id: {}", node_id); + return Ok(next_free_token); + }, + Err(e) => { + error!(target: "network", "Failed to create session for node id: {}", node_id); + return Err(e); + } + } } } else { // we dont know the NodeID. let address = socket.peer_addr().map_or("unknown".to_string(), |a| a.to_string()); debug!(target: "network", "No NodeID found for peer: {}", address); + return Err("connection to Nodes is only possible with Nodes that can provide a NodeID".into()); } // if we dont know a NodeID // debug!(target: "network", "Session create error: {:?}", e); - let existing = sessions.get(&token); - - - trace!(target: "network", "{}: Initiating session {:?}", token, id); - let session = match Session::new(io, socket, token, id, &nonce, &self.info.read()) { - Ok(s) => Some(Arc::new(Mutex::new(s))), - Err(e) => { - debug!(target: "network", "Session create error: {:?}", e); - None - } - }; - - match token { - Some(t) => io.register_stream(t).map(|_| ()).map_err(Into::into), - None => { - debug!(target: "network", "Max sessions reached"); - Ok(()) - } - } } } @@ -1002,10 +995,10 @@ impl Host { socket: TcpStream, id: Option<&NodeId>, io: &IoContext, - ) -> Result<(), Error> { + ) -> Result { let nonce = self.info.write().next_nonce(); - self.sessions.create_connection(socket, id, io, nonce) + self.sessions.create_connection(socket, id, io, &nonce, &self.info.read()) } From 585e16a3573c1d0dfc29850eb6c163f50666c3e0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Jul 2025 20:45:41 +0200 Subject: [PATCH 556/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/net/network-devp2p/src/host.rs | 111 ++++++++++++++------------ 1 file changed, 62 insertions(+), 49 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 96a81ecd9..febd766e9 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -29,7 +29,8 @@ use std::{ path::{Path, PathBuf}, str::FromStr, sync::{ - atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, Arc + Arc, + atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, }, time::{Duration, Instant}, }; @@ -49,7 +50,10 @@ use network::{ client_version::ClientVersion, }; use parity_path::restrict_permissions_owner; -use parking_lot::{lock_api::{RwLockReadGuard, RwLockUpgradableReadGuard}, Mutex, RwLock}; +use parking_lot::{ + Mutex, RwLock, + lock_api::{RwLockReadGuard, RwLockUpgradableReadGuard}, +}; use stats::{PrometheusMetrics, PrometheusRegistry}; type Slab = ::slab::Slab; @@ -360,16 +364,13 @@ struct ProtocolTimer { pub token: TimerToken, // Handler level token } - - struct SessionContainer { sessions: Arc>>, - node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. + node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. sessions_token_max: Mutex, // Used to generate new session tokens } impl SessionContainer { - pub fn new() -> Self { SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), @@ -383,39 +384,44 @@ impl SessionContainer { &self.sessions } - /// gets the next token ID and store this information - fn create_token_id(&self, node_id: &NodeId, tokens: &mut BTreeMap) -> usize { - - let mut session_token_max = self.sessions_token_max.lock(); + /// gets the next token ID and store this information + fn create_token_id( + &self, + node_id: &NodeId, + tokens: &mut BTreeMap, + ) -> usize { + let mut session_token_max = self.sessions_token_max.lock(); let next_id = session_token_max.clone(); - + *session_token_max += 1; if let Some(old) = tokens.insert(node_id.clone(), next_id) { warn!(target: "network", "Node ID {} already exists with token {}, overwriting with {}", node_id, old, next_id); } - + return next_id; } - /// Creates a new session and adds it to the session container. /// returns the token ID of the new session, or an Error if not successful. - fn create_connection(&self, socket: TcpStream, id: Option<ðereum_types::H512>, io: &IoContext, nonce: &H256, host: &HostInfo) -> Result { - - + fn create_connection( + &self, + socket: TcpStream, + id: Option<ðereum_types::H512>, + io: &IoContext, + nonce: &H256, + host: &HostInfo, + ) -> Result { // make sure noone else is trying to modify the sessions at the same time. - // creating a connection is a very rare event. - + // creating a connection is a very rare event. + // always lock the node_id_to_session first, then the sessions. let mut node_ids = self.node_id_to_session.lock(); let mut sessions = self.sessions.write(); - + if let Some(node_id) = id { - // check if there is already a connection for the given node id. if let Some(existing_peer_id) = node_ids.get(node_id) { - - if let Some(existing_session_mutex) = sessions.get(existing_peer_id) { + if let Some(existing_session_mutex) = sessions.get(existing_peer_id) { let session = existing_session_mutex.lock(); if let Some(id_from_session) = &session.info.id { if session.info.id == Some(*node_id) { @@ -423,24 +429,34 @@ impl SessionContainer { // maybe the old session is already scheduled for getting deleted. if session.expired() { // if the session is expired, we will just create n new session for this node. - let new_session = Session::new(io, socket, existing_peer_id.clone(), id, nonce, host); + let new_session = Session::new( + io, + socket, + existing_peer_id.clone(), + id, + nonce, + host, + ); match new_session { Ok(session) => { //let mut session_write = RwLockUpgradableReadGuard::upgrade(sessions); - let _old_session = sessions.insert(*existing_peer_id, Arc::new(Mutex::new(session))); + let _old_session = sessions.insert( + *existing_peer_id, + Arc::new(Mutex::new(session)), + ); // node_ids does not need to get updated, since it uses the same value. // in this context, the stream might already be unregistered ?! // we can just register the stream again. - if let Err(err) = io.register_stream(*existing_peer_id) { - // todo: research this topic, watch out for this message, + if let Err(err) = io.register_stream(*existing_peer_id) { + // todo: research this topic, watch out for this message, // maybe we can keep track of stream registrations as well somehow. debug!(target: "network", "Failed to register stream for token: {} : {}", existing_peer_id, err); } debug!(target: "network", "Created new session for node id: {}", node_id); return Ok(*existing_peer_id); - }, + } Err(e) => { error!(target: "network", "Failed to create session for node id: {}", node_id); return Err(e); @@ -451,11 +467,10 @@ impl SessionContainer { debug!(target: "network", "Session already exists for node id: {}", node_id); return Err(ErrorKind::AlreadyExists.into()); } - } else { error!(target: "network", "host cache inconsistency: Session node id missmatch. expected: {} is {}.", existing_peer_id, id_from_session); - return Err(ErrorKind::HostCacheInconsistency.into()); - } + return Err(ErrorKind::HostCacheInconsistency.into()); + } } else { error!(target: "network", "host cache inconsistency: Session has no Node_id defined where it should for {}", existing_peer_id); return Err(ErrorKind::HostCacheInconsistency.into()); @@ -464,12 +479,8 @@ impl SessionContainer { // we have a node id, but there is no session for it (anymore) match Session::new(io, socket, existing_peer_id.clone(), id, nonce, host) { - Ok(new_session) => { - - }, - Err(err) => { - - } + Ok(new_session) => {} + Err(err) => {} } error!(target: "network", "host cache inconsistency: Session does not exist for node id: {}", node_id); return Err(ErrorKind::HostCacheInconsistency.into()); @@ -479,7 +490,8 @@ impl SessionContainer { // we have a new node id, we were either never connected to, or we forgot about it. let next_free_token = self.create_token_id(&node_id, &mut node_ids); - let new_session = Session::new(io, socket, next_free_token.clone(), id, nonce, host); + let new_session = + Session::new(io, socket, next_free_token.clone(), id, nonce, host); // the token is already registerd. match new_session { Ok(session) => { @@ -492,24 +504,25 @@ impl SessionContainer { node_ids.insert(node_id.clone(), next_free_token); trace!(target: "network", "Created new session for node id: {}", node_id); return Ok(next_free_token); - }, + } Err(e) => { error!(target: "network", "Failed to create session for node id: {}", node_id); return Err(e); } } - } } else { // we dont know the NodeID. - let address = socket.peer_addr().map_or("unknown".to_string(), |a| a.to_string()); + let address = socket + .peer_addr() + .map_or("unknown".to_string(), |a| a.to_string()); debug!(target: "network", "No NodeID found for peer: {}", address); - return Err("connection to Nodes is only possible with Nodes that can provide a NodeID".into()); + return Err( + "connection to Nodes is only possible with Nodes that can provide a NodeID".into(), + ); } // if we dont know a NodeID // debug!(target: "network", "Session create error: {:?}", e); - - } } @@ -809,7 +822,8 @@ impl Host { } fn have_session(&self, id: &NodeId) -> bool { - self.sessions.sessions + self.sessions + .sessions .read() .iter() .any(|e| e.1.lock().info.id == Some(*id)) @@ -852,7 +866,8 @@ impl Host { fn connecting_to(&self, id: &NodeId) -> bool { // todo: we can use the mapping here for faster access. - self.sessions.sessions + self.sessions + .sessions .read() .iter() .any(|e| e.1.lock().id() == Some(id)) @@ -996,10 +1011,9 @@ impl Host { id: Option<&NodeId>, io: &IoContext, ) -> Result { - let nonce = self.info.write().next_nonce(); - self.sessions.create_connection(socket, id, io, &nonce, &self.info.read()) - + self.sessions + .create_connection(socket, id, io, &nonce, &self.info.read()) } fn accept(&self, io: &IoContext) { @@ -1421,7 +1435,6 @@ impl Host { ); action(&context) } - } impl IoHandler for Host { From f23efc93893162d27c1b295d4e7623aa86a33bea Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Jul 2025 06:51:26 +0200 Subject: [PATCH 557/687] alignment of token ids. system streams go now before the user session streams. Todo: - respect track max number of connections for generating new peer_id - use new lookup strategy instead of iterating over nodes. --- crates/net/network-devp2p/src/host.rs | 188 ++++++++++++++------------ 1 file changed, 105 insertions(+), 83 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index febd766e9..fd0808d1e 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -63,18 +63,18 @@ const MAX_HANDSHAKES: usize = 1024; const DEFAULT_PORT: u16 = 30303; +const SYS_TIMER: TimerToken = 0; // StreamToken/TimerToken -const TCP_ACCEPT: StreamToken = SYS_TIMER + 1; -const IDLE: TimerToken = SYS_TIMER + 2; -const DISCOVERY: StreamToken = SYS_TIMER + 3; -const DISCOVERY_REFRESH: TimerToken = SYS_TIMER + 4; -const FAST_DISCOVERY_REFRESH: TimerToken = SYS_TIMER + 5; -const DISCOVERY_ROUND: TimerToken = SYS_TIMER + 6; -const NODE_TABLE: TimerToken = SYS_TIMER + 7; -const FIRST_SESSION: StreamToken = 0; -const LAST_SESSION: StreamToken = FIRST_SESSION + MAX_SESSIONS - 1; -const USER_TIMER: TimerToken = LAST_SESSION + 256; -const SYS_TIMER: TimerToken = LAST_SESSION + 1; +const TCP_ACCEPT: StreamToken = 1; +const IDLE: TimerToken = 2; +const DISCOVERY: StreamToken = 3; +const DISCOVERY_REFRESH: TimerToken = 4; +const FAST_DISCOVERY_REFRESH: TimerToken = 5; +const DISCOVERY_ROUND: TimerToken = 6; +const NODE_TABLE: TimerToken = 7; +const USER_TIMER: TimerToken = 8; + +const FIRST_SESSION: StreamToken = 9; // Timeouts // for IDLE TimerToken @@ -366,6 +366,8 @@ struct ProtocolTimer { struct SessionContainer { sessions: Arc>>, + expired_sessions: Arc>>, + discovery_session: Arc>>, node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. sessions_token_max: Mutex, // Used to generate new session tokens } @@ -374,8 +376,10 @@ impl SessionContainer { pub fn new() -> Self { SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), + expired_sessions: Arc::new(RwLock::new(Vec::new())), node_id_to_session: Mutex::new(BTreeMap::new()), sessions_token_max: Mutex::new(0), + discovery_session: Arc::new(RwLock::new(None)), } } @@ -415,65 +419,77 @@ impl SessionContainer { // creating a connection is a very rare event. // always lock the node_id_to_session first, then the sessions. + let mut expired_session = self.expired_sessions.write(); let mut node_ids = self.node_id_to_session.lock(); let mut sessions = self.sessions.write(); + if let Some(node_id) = id { // check if there is already a connection for the given node id. if let Some(existing_peer_id) = node_ids.get(node_id) { - if let Some(existing_session_mutex) = sessions.get(existing_peer_id) { - let session = existing_session_mutex.lock(); - if let Some(id_from_session) = &session.info.id { - if session.info.id == Some(*node_id) { - // we got already got a session for the specified node. - // maybe the old session is already scheduled for getting deleted. - if session.expired() { - // if the session is expired, we will just create n new session for this node. - let new_session = Session::new( - io, - socket, - existing_peer_id.clone(), - id, - nonce, - host, - ); - match new_session { - Ok(session) => { - //let mut session_write = RwLockUpgradableReadGuard::upgrade(sessions); - let _old_session = sessions.insert( - *existing_peer_id, - Arc::new(Mutex::new(session)), - ); - // node_ids does not need to get updated, since it uses the same value. - - // in this context, the stream might already be unregistered ?! - // we can just register the stream again. - if let Err(err) = io.register_stream(*existing_peer_id) { - // todo: research this topic, watch out for this message, - // maybe we can keep track of stream registrations as well somehow. - debug!(target: "network", "Failed to register stream for token: {} : {}", existing_peer_id, err); - } - - debug!(target: "network", "Created new session for node id: {}", node_id); - return Ok(*existing_peer_id); - } - Err(e) => { - error!(target: "network", "Failed to create session for node id: {}", node_id); - return Err(e); - } - } + let existing_session_mutex_o = sessions.get(existing_peer_id).clone(); + + if let Some(existing_session_mutex) = existing_session_mutex_o { + let session_expired = { + let session = existing_session_mutex.lock(); + if let Some(id_from_session) = &session.info.id { + if session.info.id == Some(*node_id) { + // we got already got a session for the specified node. + // maybe the old session is already scheduled for getting deleted. + session.expired() } else { - // this might happen if 2 nodes try to connect to each other at the same time. - debug!(target: "network", "Session already exists for node id: {}", node_id); - return Err(ErrorKind::AlreadyExists.into()); + error!(target: "network", "host cache inconsistency: Session node id missmatch. expected: {} is {}.", existing_peer_id, id_from_session); + return Err(ErrorKind::HostCacheInconsistency.into()); } } else { - error!(target: "network", "host cache inconsistency: Session node id missmatch. expected: {} is {}.", existing_peer_id, id_from_session); + error!(target: "network", "host cache inconsistency: Session has no Node_id defined where it should for {}", existing_peer_id); return Err(ErrorKind::HostCacheInconsistency.into()); } + }; // session guard is dropped here + + if session_expired { + // if the session is expired, we will just create n new session for this node. + let new_session = + Session::new(io, socket, existing_peer_id.clone(), id, nonce, host); + match new_session { + Ok(session) => { + let new_session_arc = Arc::new(Mutex::new(session)); + let old_session_o = + sessions.insert(*existing_peer_id, new_session_arc); + + match old_session_o { + Some(old) => { + // we remember the expired session, so it can get closed and cleaned up in a nice way later. + expired_session.push(old); + }, + None => { + // we have a cache missmatch. + // but the only thing is missing is a clean ending of the old session. + // nothing mission critical. + error!(target: "network", "host cache inconsistency: Session for node id {} was not found in sessions map, but it should be there.", node_id); + }, + } + + // in this context, the stream might already be unregistered ?! + // we can just register the stream again. + if let Err(err) = io.register_stream(*existing_peer_id) { + // todo: research this topic, watch out for this message, + // maybe we can keep track of stream registrations as well somehow. + debug!(target: "network", "Failed to register stream for token: {} : {}", existing_peer_id, err); + } + + debug!(target: "network", "Created new session for node id: {}", node_id); + return Ok(*existing_peer_id); + } + Err(e) => { + error!(target: "network", "Failed to create session for node id: {}", node_id); + return Err(e); + } + } } else { - error!(target: "network", "host cache inconsistency: Session has no Node_id defined where it should for {}", existing_peer_id); - return Err(ErrorKind::HostCacheInconsistency.into()); + // this might happen if 2 nodes try to connect to each other at the same time. + debug!(target: "network", "Session already exists for node id: {}", node_id); + return Err(ErrorKind::AlreadyExists.into()); } } else { // we have a node id, but there is no session for it (anymore) @@ -524,6 +540,15 @@ impl SessionContainer { // if we dont know a NodeID // debug!(target: "network", "Session create error: {:?}", e); } + + fn get_session_for(&self, id: &NodeId) -> Option { + + self.node_id_to_session.lock().get(id).map_or(None, |peer_id| { + let sessions = self.sessions.read(); + sessions.get(peer_id).cloned() + }) + + } } /// Root IO handler. Manages protocol handlers, IO timers and network connections. @@ -822,11 +847,8 @@ impl Host { } fn have_session(&self, id: &NodeId) -> bool { - self.sessions - .sessions - .read() - .iter() - .any(|e| e.1.lock().info.id == Some(*id)) + + self.sessions.get_session_for(id).is_some() } // returns (handshakes, egress, ingress) @@ -1331,7 +1353,7 @@ impl Host { let mut failure_id = None; let mut deregister = false; let mut expired_session = None; - if let FIRST_SESSION..=LAST_SESSION = token { + if token >= FIRST_SESSION { let sessions = self.sessions.sessions.read(); if let Some(session) = sessions.get(&token).cloned() { expired_session = Some(session.clone()); @@ -1449,10 +1471,11 @@ impl IoHandler for Host { fn stream_hup(&self, io: &IoContext, stream: StreamToken) { trace!(target: "network", "Hup: {}", stream); - match stream { - FIRST_SESSION..=LAST_SESSION => self.connection_closed(stream, io), - _ => warn!(target: "network", "Unexpected hup"), - }; + if stream >= FIRST_SESSION { + self.connection_closed(stream, io) + } else { + warn!(target: "network", "Unexpected hup for session {}", stream); + } } fn stream_readable(&self, io: &IoContext, stream: StreamToken) { @@ -1460,7 +1483,7 @@ impl IoHandler for Host { return; } match stream { - FIRST_SESSION..=LAST_SESSION => self.session_readable(stream, io), + FIRST_SESSION.. => self.session_readable(stream, io), DISCOVERY => self.discovery_readable(io), TCP_ACCEPT => self.accept(io), _ => panic!("Received unknown readable token"), @@ -1472,7 +1495,7 @@ impl IoHandler for Host { return; } match stream { - FIRST_SESSION..=LAST_SESSION => self.session_writable(stream, io), + FIRST_SESSION.. => self.session_writable(stream, io), DISCOVERY => self.discovery_writable(io), _ => panic!("Received unknown writable token"), } @@ -1484,7 +1507,7 @@ impl IoHandler for Host { } match token { IDLE => self.maintain_network(io), - FIRST_SESSION..=LAST_SESSION => { + FIRST_SESSION.. => { trace!(target: "network", "Timeout from Host impl: {}", token); self.connection_timeout(token, io); } @@ -1635,7 +1658,7 @@ impl IoHandler for Host { event_loop: &mut EventLoop>, ) { match stream { - FIRST_SESSION..=LAST_SESSION => { + FIRST_SESSION.. => { let session = { self.sessions.sessions.read().get(&stream).cloned() }; if let Some(session) = session { session @@ -1670,7 +1693,7 @@ impl IoHandler for Host { event_loop: &mut EventLoop>, ) { match stream { - FIRST_SESSION..=LAST_SESSION => { + FIRST_SESSION.. => { let mut connections = self.sessions.sessions.write(); if let Some(connection) = connections.get(&stream).cloned() { let c = connection.lock(); @@ -1694,15 +1717,6 @@ impl IoHandler for Host { event_loop: &mut EventLoop>, ) { match stream { - FIRST_SESSION..=LAST_SESSION => { - let connection = { self.sessions.sessions.read().get(&&stream).cloned() }; - if let Some(connection) = connection { - connection - .lock() - .update_socket(reg, event_loop) - .expect("Error updating socket"); - } - } DISCOVERY => match ( self.udp_socket.lock().as_ref(), self.discovery.lock().as_ref(), @@ -1727,7 +1741,15 @@ impl IoHandler for Host { PollOpt::edge(), ) .expect("Error reregistering stream"), - _ => warn!("Unexpected stream update"), + _ => { + let connection = { self.sessions.sessions.read().get(&&stream).cloned() }; + if let Some(connection) = connection { + connection + .lock() + .update_socket(reg, event_loop) + .expect("Error updating socket"); + } + }, } } } From 77e591f95f279f681d77407f6485001440cda6c2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Jul 2025 07:54:28 +0200 Subject: [PATCH 558/687] reusing peer_ids for Node IDs --- crates/net/network-devp2p/src/host.rs | 30 ++++++++++++--------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index fd0808d1e..c7fa0dd72 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -52,18 +52,16 @@ use network::{ use parity_path::restrict_permissions_owner; use parking_lot::{ Mutex, RwLock, - lock_api::{RwLockReadGuard, RwLockUpgradableReadGuard}, }; use stats::{PrometheusMetrics, PrometheusRegistry}; -type Slab = ::slab::Slab; const MAX_SESSIONS: usize = 2048 + MAX_HANDSHAKES; const MAX_HANDSHAKES: usize = 1024; const DEFAULT_PORT: u16 = 30303; -const SYS_TIMER: TimerToken = 0; +//const SYS_TIMER: TimerToken = 0; // StreamToken/TimerToken const TCP_ACCEPT: StreamToken = 1; const IDLE: TimerToken = 2; @@ -367,7 +365,6 @@ struct ProtocolTimer { struct SessionContainer { sessions: Arc>>, expired_sessions: Arc>>, - discovery_session: Arc>>, node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. sessions_token_max: Mutex, // Used to generate new session tokens } @@ -378,16 +375,10 @@ impl SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), expired_sessions: Arc::new(RwLock::new(Vec::new())), node_id_to_session: Mutex::new(BTreeMap::new()), - sessions_token_max: Mutex::new(0), - discovery_session: Arc::new(RwLock::new(None)), + sessions_token_max: Mutex::new(0) } } - /// Returns a reference to the sessions map. - pub fn sessions(&self) -> &Arc>> { - &self.sessions - } - /// gets the next token ID and store this information fn create_token_id( &self, @@ -398,6 +389,7 @@ impl SessionContainer { let next_id = session_token_max.clone(); *session_token_max += 1; + if let Some(old) = tokens.insert(node_id.clone(), next_id) { warn!(target: "network", "Node ID {} already exists with token {}, overwriting with {}", node_id, old, next_id); } @@ -422,7 +414,6 @@ impl SessionContainer { let mut expired_session = self.expired_sessions.write(); let mut node_ids = self.node_id_to_session.lock(); let mut sessions = self.sessions.write(); - if let Some(node_id) = id { // check if there is already a connection for the given node id. @@ -492,14 +483,19 @@ impl SessionContainer { return Err(ErrorKind::AlreadyExists.into()); } } else { + debug!(target: "network", "reusing peer ID {} for node: {}", existing_peer_id, node_id); // we have a node id, but there is no session for it (anymore) - + // we reuse that peer_id, so other in flight actions are pointing to the same node again. match Session::new(io, socket, existing_peer_id.clone(), id, nonce, host) { - Ok(new_session) => {} - Err(err) => {} + Ok(new_session) => { + sessions.insert(existing_peer_id.clone(), Arc::new(Mutex::new(new_session))); + return Ok(existing_peer_id.clone()); + } + Err(err) => { + debug!(target: "network", "reusing peer ID {} for node: {}, but could not create session", existing_peer_id, node_id); + return Err(err); + } } - error!(target: "network", "host cache inconsistency: Session does not exist for node id: {}", node_id); - return Err(ErrorKind::HostCacheInconsistency.into()); } } else { // this should be the most common scenario. From ad811b1f87e204d81cbc2555d0e37cea61d75e9a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Jul 2025 07:57:11 +0200 Subject: [PATCH 559/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/net/network-devp2p/src/host.rs | 38 +++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index c7fa0dd72..36ce80c4a 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -50,12 +50,9 @@ use network::{ client_version::ClientVersion, }; use parity_path::restrict_permissions_owner; -use parking_lot::{ - Mutex, RwLock, -}; +use parking_lot::{Mutex, RwLock}; use stats::{PrometheusMetrics, PrometheusRegistry}; - const MAX_SESSIONS: usize = 2048 + MAX_HANDSHAKES; const MAX_HANDSHAKES: usize = 1024; @@ -375,7 +372,7 @@ impl SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), expired_sessions: Arc::new(RwLock::new(Vec::new())), node_id_to_session: Mutex::new(BTreeMap::new()), - sessions_token_max: Mutex::new(0) + sessions_token_max: Mutex::new(0), } } @@ -447,20 +444,20 @@ impl SessionContainer { let new_session_arc = Arc::new(Mutex::new(session)); let old_session_o = sessions.insert(*existing_peer_id, new_session_arc); - + match old_session_o { Some(old) => { // we remember the expired session, so it can get closed and cleaned up in a nice way later. expired_session.push(old); - }, + } None => { // we have a cache missmatch. // but the only thing is missing is a clean ending of the old session. // nothing mission critical. error!(target: "network", "host cache inconsistency: Session for node id {} was not found in sessions map, but it should be there.", node_id); - }, + } } - + // in this context, the stream might already be unregistered ?! // we can just register the stream again. if let Err(err) = io.register_stream(*existing_peer_id) { @@ -488,7 +485,10 @@ impl SessionContainer { // we reuse that peer_id, so other in flight actions are pointing to the same node again. match Session::new(io, socket, existing_peer_id.clone(), id, nonce, host) { Ok(new_session) => { - sessions.insert(existing_peer_id.clone(), Arc::new(Mutex::new(new_session))); + sessions.insert( + existing_peer_id.clone(), + Arc::new(Mutex::new(new_session)), + ); return Ok(existing_peer_id.clone()); } Err(err) => { @@ -536,14 +536,15 @@ impl SessionContainer { // if we dont know a NodeID // debug!(target: "network", "Session create error: {:?}", e); } - + fn get_session_for(&self, id: &NodeId) -> Option { - - self.node_id_to_session.lock().get(id).map_or(None, |peer_id| { - let sessions = self.sessions.read(); - sessions.get(peer_id).cloned() - }) - + self.node_id_to_session + .lock() + .get(id) + .map_or(None, |peer_id| { + let sessions = self.sessions.read(); + sessions.get(peer_id).cloned() + }) } } @@ -843,7 +844,6 @@ impl Host { } fn have_session(&self, id: &NodeId) -> bool { - self.sessions.get_session_for(id).is_some() } @@ -1745,7 +1745,7 @@ impl IoHandler for Host { .update_socket(reg, event_loop) .expect("Error updating socket"); } - }, + } } } } From 4e6b29cb977a8d5fd42214ca84ee81b139724e82 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Jul 2025 13:11:47 +0200 Subject: [PATCH 560/687] Network Context has now a SessionContainer instead of the sessions collections --- crates/net/network-devp2p/src/host.rs | 98 ++++++++++++++++++--------- crates/net/network/src/error.rs | 6 ++ 2 files changed, 71 insertions(+), 33 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 36ce80c4a..1f725255e 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -106,7 +106,7 @@ impl Encodable for CapabilityInfo { pub struct NetworkContext<'s> { io: &'s IoContext, protocol: ProtocolId, - sessions: Arc>>, + sessions: &'s SessionContainer, session: Option, session_id: Option, reserved_peers: &'s HashSet, @@ -159,7 +159,7 @@ impl<'s> NetworkContext<'s> { io: &'s IoContext, protocol: ProtocolId, session: Option, - sessions: Arc>>, + sessions: &'s SessionContainer, reserved_peers: &'s HashSet, statistics: &'s NetworkingStatistics, ) -> NetworkContext<'s> { @@ -178,7 +178,7 @@ impl<'s> NetworkContext<'s> { fn resolve_session(&self, peer: PeerId) -> Option { match self.session_id { Some(id) if id == peer => self.session.clone(), - _ => self.sessions.read().get(&peer).cloned(), + _ => self.sessions.sessions.read().get(&peer).cloned(), } } } @@ -295,22 +295,7 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { } fn node_id_to_peer_id(&self, node_id: &NodeId) -> Option { - let sessions = self.sessions.read(); - let sessions = &*sessions; - - // todo: - // we can do deterministic lookup here ?! - for i in (0..MAX_SESSIONS).map(|x| x + FIRST_SESSION) { - if let Some(session) = sessions.get(&i) { - let session_node_id_o = session.lock().info.id; - if let Some(session_node_id) = session_node_id_o { - if session_node_id == *node_id { - return Some(i); - } - } - } - } - None + self.sessions.node_id_to_peer_id(node_id, true) } } @@ -372,7 +357,7 @@ impl SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), expired_sessions: Arc::new(RwLock::new(Vec::new())), node_id_to_session: Mutex::new(BTreeMap::new()), - sessions_token_max: Mutex::new(0), + sessions_token_max: Mutex::new(FIRST_SESSION), } } @@ -387,6 +372,10 @@ impl SessionContainer { *session_token_max += 1; + // if we run out of token ids, + // we need to recycle Ids that are not used anymore. + + if let Some(old) = tokens.insert(node_id.clone(), next_id) { warn!(target: "network", "Node ID {} already exists with token {}, overwriting with {}", node_id, old, next_id); } @@ -412,6 +401,10 @@ impl SessionContainer { let mut node_ids = self.node_id_to_session.lock(); let mut sessions = self.sessions.write(); + if sessions.len() >= MAX_SESSIONS { + return Err( ErrorKind::TooManyConnections.into()); + } + if let Some(node_id) = id { // check if there is already a connection for the given node id. if let Some(existing_peer_id) = node_ids.get(node_id) { @@ -436,10 +429,13 @@ impl SessionContainer { }; // session guard is dropped here if session_expired { + + debug!(target: "network", "Creating new session for expired {} token: {} node id: {:?}", socket_address_to_string(&socket), existing_peer_id, id); // if the session is expired, we will just create n new session for this node. let new_session = Session::new(io, socket, existing_peer_id.clone(), id, nonce, host); match new_session { + Ok(session) => { let new_session_arc = Arc::new(Mutex::new(session)); let old_session_o = @@ -466,7 +462,7 @@ impl SessionContainer { debug!(target: "network", "Failed to register stream for token: {} : {}", existing_peer_id, err); } - debug!(target: "network", "Created new session for node id: {}", node_id); + return Ok(*existing_peer_id); } Err(e) => { @@ -489,6 +485,9 @@ impl SessionContainer { existing_peer_id.clone(), Arc::new(Mutex::new(new_session)), ); + if let Err(err) = io.register_stream(existing_peer_id.clone()) { + warn!(target: "network", "Failed to register stream for reused token: {} : {}", existing_peer_id, err); + } return Ok(existing_peer_id.clone()); } Err(err) => { @@ -502,6 +501,7 @@ impl SessionContainer { // we have a new node id, we were either never connected to, or we forgot about it. let next_free_token = self.create_token_id(&node_id, &mut node_ids); + trace!(target: "network", "Creating new session {} for new node id:{} with token {}", socket_address_to_string(&socket), node_id, next_free_token); let new_session = Session::new(io, socket, next_free_token.clone(), id, nonce, host); // the token is already registerd. @@ -514,7 +514,7 @@ impl SessionContainer { debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); } node_ids.insert(node_id.clone(), next_free_token); - trace!(target: "network", "Created new session for node id: {}", node_id); + return Ok(next_free_token); } Err(e) => { @@ -524,11 +524,9 @@ impl SessionContainer { } } } else { + // we dont know the NodeID. - let address = socket - .peer_addr() - .map_or("unknown".to_string(), |a| a.to_string()); - debug!(target: "network", "No NodeID found for peer: {}", address); + trace!(target: "network", "No NodeID found for peer: {}", socket_address_to_string(&socket)); return Err( "connection to Nodes is only possible with Nodes that can provide a NodeID".into(), ); @@ -546,6 +544,37 @@ impl SessionContainer { sessions.get(peer_id).cloned() }) } + + fn node_id_to_peer_id(&self, node_id: &NodeId, only_available_sessions: bool) -> Option { + + self.node_id_to_session + .lock() + .get(node_id) + .map_or(None, |peer_id| { + if !only_available_sessions { + return Some(*peer_id); + } + let sessions = self.sessions.read(); + + // we can do additional checks: + // we could ensure that the Node ID matches. + // we could also read the flag and check if it is not marked for + // getting disconnected. + + if sessions.contains_key(peer_id) { + return Some(*peer_id); + } + + return None; + }) + } +} + +fn socket_address_to_string(socket: &TcpStream) -> String { + + socket + .peer_addr() + .map_or("unknown".to_string(), |a| a.to_string()) } /// Root IO handler. Manages protocol handlers, IO timers and network connections. @@ -1241,7 +1270,7 @@ impl Host { io, p, Some(session.clone()), - self.sessions.sessions.clone(), + &self.sessions, &reserved, &self.statistics, ), @@ -1262,7 +1291,7 @@ impl Host { io, p, Some(session.clone()), - self.sessions.sessions.clone(), + &self.sessions, &reserved, &self.statistics, ), @@ -1366,6 +1395,8 @@ impl Host { failure_id = s.id().cloned(); } deregister = remote || s.done(); + } else { + trace!(target: "network", "Session not found for token: {}", token); } } if let Some(id) = failure_id { @@ -1381,7 +1412,7 @@ impl Host { io, p, expired_session.clone(), - self.sessions.sessions.clone(), + &self.sessions, &reserved, &self.statistics, ), @@ -1425,7 +1456,7 @@ impl Host { io, protocol, None, - self.sessions.sessions.clone(), + &self.sessions, &reserved, &self.statistics, ); @@ -1447,7 +1478,7 @@ impl Host { io, protocol, None, - self.sessions.sessions.clone(), + &self.sessions, &reserved, &self.statistics, ); @@ -1548,7 +1579,7 @@ impl IoHandler for Host { io, timer.protocol, None, - self.sessions.sessions.clone(), + &self.sessions, &reserved, &self.statistics, ), @@ -1579,7 +1610,7 @@ impl IoHandler for Host { io, *protocol, None, - self.sessions.sessions.clone(), + &self.sessions, &reserved, &self.statistics, )); @@ -1653,6 +1684,7 @@ impl IoHandler for Host { reg: Token, event_loop: &mut EventLoop>, ) { + trace!(target: "network", "register_stream {}", stream); match stream { FIRST_SESSION.. => { let session = { self.sessions.sessions.read().get(&stream).cloned() }; diff --git a/crates/net/network/src/error.rs b/crates/net/network/src/error.rs index 63b0b6a06..50e880019 100644 --- a/crates/net/network/src/error.rs +++ b/crates/net/network/src/error.rs @@ -166,6 +166,12 @@ error_chain! { display("A connection to the specified nodeId already exists."), } + #[doc = "Reached maximum connections"] + TooManyConnections { + description("The maximum number of connections has been reached."), + display("The hardcoded maximum number of connections has been reached on this host."), + } + #[doc = "A connection to the specified NodeId exists, but there is a missmatch in the host cache."] HostCacheInconsistency { description("A connection to the specified nodeId already exists."), From 7b044726e60c4a7aaba56e0bc3bbb40285a7d963 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Jul 2025 19:24:25 +0200 Subject: [PATCH 561/687] defaulting to network debug info now for configuring debug log clients. --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index 5b41a7f63..e4e7c8e0f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -258,7 +258,7 @@ fn to_toml( misc.insert( "logging".into(), Value::String( - logging.unwrap_or("txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace,sync=trace") + logging.unwrap_or("txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace,sync=trace,network=trace") .into(), ), ); @@ -419,7 +419,7 @@ fn main() { ).arg( Arg::with_name("logging") .long("log definition string") - .help("example: txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace,sync=trace") + .help("example: txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace,sync=trace,network=trace") .required(false) .takes_value(true), ) From 2dcd2d0ae6f8bae437591588c5ae0807d37d5ca9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Jul 2025 19:25:20 +0200 Subject: [PATCH 562/687] reactivated trace logging for transaction asking. --- crates/ethcore/sync/src/chain/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/ethcore/sync/src/chain/mod.rs b/crates/ethcore/sync/src/chain/mod.rs index fe0dcebbe..3a204b3c1 100644 --- a/crates/ethcore/sync/src/chain/mod.rs +++ b/crates/ethcore/sync/src/chain/mod.rs @@ -1465,13 +1465,13 @@ impl ChainSync { peer.unfetched_pooled_transactions .retain(|u| !to_send.contains(u)); - // trace!( - // target: "sync", - // "Asking {} pooled transactions from peer {}: {:?}", - // to_send.len(), - // peer_id, - // to_send - // ); + trace!( + target: "sync", + "Asking {} pooled transactions from peer {}: {:?}", + to_send.len(), + peer_id, + to_send + ); peer.asking_pooled_transactions = to_send.clone(); } } else { From 86a3c8fd49370ebbeff9df506de4da496acbae37 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Jul 2025 19:26:37 +0200 Subject: [PATCH 563/687] NodeTable now has a function for a retrival of information that requires less overhead and locks: `pub fn nodes_filtered(&self, max_count: usize, ip_filter: &IpFilter, filter: F) -> Vec ` --- crates/net/network-devp2p/src/node_table.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/net/network-devp2p/src/node_table.rs b/crates/net/network-devp2p/src/node_table.rs index d01fbaf1a..808cb8657 100644 --- a/crates/net/network-devp2p/src/node_table.rs +++ b/crates/net/network-devp2p/src/node_table.rs @@ -374,6 +374,20 @@ impl NodeTable { .collect() } + /// Returns node ids sorted by failure percentage, for nodes with the same failure percentage the absolute number of + /// failures is considered. + pub fn nodes_filtered(&self, max_count: usize, ip_filter: &IpFilter, filter: F) -> Vec + where + F: Fn(&Node) -> bool { + self.ordered_entries() + .iter() + .filter(|n| n.endpoint.is_allowed(&ip_filter)) + .filter(|n| filter(n)) + .take(max_count) + .map(|n| n.id) + .collect() + } + /// Ordered list of all entries by failure percentage, for nodes with the same failure percentage the absolute /// number of failures is considered. pub fn entries(&self) -> Vec { From 2103e0ec077379838d4844d4b14c7b7a7dd9ecfe Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 7 Jul 2025 19:29:15 +0200 Subject: [PATCH 564/687] reworked connect_peers() to massivly reduce the count of Locks, and also removed nested locks. --- crates/net/network-devp2p/src/host.rs | 180 +++++++++++++++----------- 1 file changed, 108 insertions(+), 72 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 1f725255e..f9793f091 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -372,10 +372,9 @@ impl SessionContainer { *session_token_max += 1; - // if we run out of token ids, + // TODO: if we run out of token ids, // we need to recycle Ids that are not used anymore. - if let Some(old) = tokens.insert(node_id.clone(), next_id) { warn!(target: "network", "Node ID {} already exists with token {}, overwriting with {}", node_id, old, next_id); } @@ -383,6 +382,18 @@ impl SessionContainer { return next_id; } + fn create_token_id_for_handshake(&self) -> usize { + let mut session_token_max = self.sessions_token_max.lock(); + let next_id = session_token_max.clone(); + + *session_token_max += 1; + + // TODO: if we run out of token ids, + // we need to recycle Ids that are not used anymore. + + return next_id; + } + /// Creates a new session and adds it to the session container. /// returns the token ID of the new session, or an Error if not successful. fn create_connection( @@ -398,11 +409,11 @@ impl SessionContainer { // always lock the node_id_to_session first, then the sessions. let mut expired_session = self.expired_sessions.write(); - let mut node_ids = self.node_id_to_session.lock(); let mut sessions = self.sessions.write(); + let mut node_ids = self.node_id_to_session.lock(); if sessions.len() >= MAX_SESSIONS { - return Err( ErrorKind::TooManyConnections.into()); + return Err(ErrorKind::TooManyConnections.into()); } if let Some(node_id) = id { @@ -429,13 +440,11 @@ impl SessionContainer { }; // session guard is dropped here if session_expired { - debug!(target: "network", "Creating new session for expired {} token: {} node id: {:?}", socket_address_to_string(&socket), existing_peer_id, id); // if the session is expired, we will just create n new session for this node. let new_session = Session::new(io, socket, existing_peer_id.clone(), id, nonce, host); match new_session { - Ok(session) => { let new_session_arc = Arc::new(Mutex::new(session)); let old_session_o = @@ -462,7 +471,6 @@ impl SessionContainer { debug!(target: "network", "Failed to register stream for token: {} : {}", existing_peer_id, err); } - return Ok(*existing_peer_id); } Err(e) => { @@ -514,7 +522,7 @@ impl SessionContainer { debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); } node_ids.insert(node_id.clone(), next_free_token); - + return Ok(next_free_token); } Err(e) => { @@ -524,12 +532,31 @@ impl SessionContainer { } } } else { + let next_free_token = self.create_token_id_for_handshake(); + + trace!(target: "network", "creating session for handshaking peer: {} token: {}", socket_address_to_string(&socket), next_free_token); + // we dont know the NodeID, + // we still need a session to do the handshake. + + let new_session = Session::new(io, socket, next_free_token.clone(), id, nonce, host); + // the token is already registerd. + match new_session { + Ok(session) => { + let session = Arc::new(Mutex::new(session)); + sessions.insert(next_free_token, session.clone()); + // register the stream for the new session. + if let Err(err) = io.register_stream(next_free_token) { + debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); + } + //node_ids.insert(node_id.clone(), next_free_token); - // we dont know the NodeID. - trace!(target: "network", "No NodeID found for peer: {}", socket_address_to_string(&socket)); - return Err( - "connection to Nodes is only possible with Nodes that can provide a NodeID".into(), - ); + return Ok(next_free_token); + } + Err(e) => { + error!(target: "network", "Failed to create handshake session for: {}", next_free_token); + return Err(e); + } + } } // if we dont know a NodeID // debug!(target: "network", "Session create error: {:?}", e); @@ -544,9 +571,8 @@ impl SessionContainer { sessions.get(peer_id).cloned() }) } - - fn node_id_to_peer_id(&self, node_id: &NodeId, only_available_sessions: bool) -> Option { + fn node_id_to_peer_id(&self, node_id: &NodeId, only_available_sessions: bool) -> Option { self.node_id_to_session .lock() .get(node_id) @@ -555,7 +581,7 @@ impl SessionContainer { return Some(*peer_id); } let sessions = self.sessions.read(); - + // we can do additional checks: // we could ensure that the Node ID matches. // we could also read the flag and check if it is not marked for @@ -568,13 +594,35 @@ impl SessionContainer { return None; }) } + + fn register_finalized_handshake(&self, token: usize, id: Option<ðereum_types::H512>) { + let node_id = match id { + Some(id) => id.clone(), + None => { + error!(target: "network", "Tried to register finalized handshake without node id"); + // we have no node id, so we can not register it. + return; + } + }; + + // register this session. + if let Some(old) = self.node_id_to_session.lock().insert(node_id, token) { + // in scenarios where we did have registered the session to this node, + // the token id wont change. + // but still we need a lock to node_id_to_session anyway. + if old != token { + debug!(target: "network", "handshake completed: changed primary session for node id {} from {} to {}", node_id, token, old); + } + } else { + debug!(target: "network", "handshake completed: node id {} registered primary session token {}", node_id, token); + } + } } fn socket_address_to_string(socket: &TcpStream) -> String { - socket - .peer_addr() - .map_or("unknown".to_string(), |a| a.to_string()) + .peer_addr() + .map_or("unknown".to_string(), |a| a.to_string()) } /// Root IO handler. Manages protocol handlers, IO timers and network connections. @@ -789,10 +837,10 @@ impl Host { let sessions = &*sessions; let mut peers = Vec::with_capacity(sessions.len()); - for i in (0..MAX_SESSIONS).map(|x| x + FIRST_SESSION) { - if sessions.get(&i).is_some() { - peers.push(i); - } + + + for peer_id in sessions.keys() { + peers.push(peer_id.clone()); } peers } @@ -911,15 +959,6 @@ impl Host { return None; } - fn connecting_to(&self, id: &NodeId) -> bool { - // todo: we can use the mapping here for faster access. - self.sessions - .sessions - .read() - .iter() - .any(|e| e.1.lock().id() == Some(id)) - } - fn keep_alive(&self, io: &IoContext) { let mut to_kill = Vec::new(); for e in self.sessions.sessions.read().iter() { @@ -948,7 +987,8 @@ impl Host { } fn connect_peers(&self, io: &IoContext) { - let (min_peers, mut pin, max_handshakes, allow_ips, self_id) = { + + let (min_peers, pin, max_handshakes, allow_ips, self_id) = { let info = self.info.read(); if info.capabilities.is_empty() { return; @@ -963,55 +1003,51 @@ impl Host { *info.id(), ) }; + + let (mut handshake_count, egress_count, ingress_count) = self.session_count(); + // we clone the reserved nodes, to avoid deadlocks and reduce locking time. + let unconnected_reserved_nodes: Vec = self.reserved_nodes.read().clone().into_iter().filter(|f| !self.have_session(f)).collect(); - let (handshake_count, egress_count, ingress_count) = self.session_count(); - let reserved_nodes = self.reserved_nodes.read(); - if egress_count + ingress_count >= min_peers as usize + reserved_nodes.len() { - // check if all pinned nodes are connected. - if reserved_nodes - .iter() - .all(|n| self.have_session(n) && self.connecting_to(n)) - { - return; - } + // reserved peers are already findable in the SessionContainer, even they are handshaking. + // so we wont trigger a second handshake here. + + let mut started: usize = 0; - // if not, only attempt connect to reserved peers - pin = true; + for reserved in &unconnected_reserved_nodes { + self.connect_peer(reserved, io); + started += 1; + handshake_count += 1; } - // allow 16 slots for incoming connections - if handshake_count >= max_handshakes { + if (pin) { return; } - // iterate over all nodes, reserved ones coming first. - // if we are pinned to only reserved nodes, ignore all others. - let nodes = reserved_nodes.iter().cloned().chain(if !pin { - self.nodes.read().nodes(&allow_ips) - } else { - Vec::new() - }); + if handshake_count >= max_handshakes { + return; + } let max_handshakes_per_round = max_handshakes / 2; - let mut started: usize = 0; - for id in nodes - .filter(|id| { - !self.have_session(id) - && !self.connecting_to(id) - && *id != self_id - && self.filter.as_ref().map_or(true, |f| { - f.connection_allowed(&self_id, &id, ConnectionDirection::Outbound) - }) + + // ip filter: + //.nodes(&allow_ips)) + let number_of_connects_to_make = max_handshakes_per_round.min(max_handshakes - handshake_count); + + // now connect to nodes from the node table. + for id in self.nodes.read().nodes_filtered(number_of_connects_to_make, + &allow_ips, + |n: &Node| { + n.id != self_id + && self.filter.as_ref().map_or(true, |f| { + f.connection_allowed(&self_id, &n.id, ConnectionDirection::Outbound)}) + && !self.have_session(&n.id) }) - .take(min( - max_handshakes_per_round, - max_handshakes - handshake_count, - )) { self.connect_peer(&id, io); started += 1; } - debug!(target: "network", "Connecting peers: {} sessions, {} pending + {} started", egress_count + ingress_count, handshake_count, started); + + debug!(target: "network", "Connecting peers: {} sessions, {} handshakes {} started", egress_count + ingress_count, handshake_count, started); } fn connect_peer(&self, id: &NodeId, io: &IoContext) { @@ -1019,10 +1055,6 @@ impl Host { trace!(target: "network", "Aborted connect. Node already connected."); return; } - if self.connecting_to(id) { - trace!(target: "network", "Aborted connect. Node already connecting."); - return; - } let socket = { let address = { @@ -1136,6 +1168,7 @@ impl Host { let (_, egress_count, ingress_count) = self.session_count(); let reserved_nodes = self.reserved_nodes.read(); let mut s = session.lock(); + self.sessions.register_finalized_handshake(token, s.id()); let (min_peers, mut max_peers, reserved_only, self_id) = { let info = self.info.read(); let mut max_peers = info.config.max_peers; @@ -1379,6 +1412,9 @@ impl Host { let mut deregister = false; let mut expired_session = None; if token >= FIRST_SESSION { + // we can shorten the session read lock here, if this causes a deadlock. + // on the other hand it is good, so not that many sessions manipulations can take place + // at the same time. let sessions = self.sessions.sessions.read(); if let Some(session) = sessions.get(&token).cloned() { expired_session = Some(session.clone()); From d1a7937b0b43dc5f4bb18b9b97dba2cc37f008f7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 8 Jul 2025 11:40:51 +0200 Subject: [PATCH 565/687] Rewritten connect_peers() to be - faster - easier to understand - holding locks for less time - doing less stacked locks SessionContainer: ABBA Locks solved by fixing the order of locks. --- crates/net/network-devp2p/src/host.rs | 30 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index f9793f091..8d531a3a8 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -409,8 +409,8 @@ impl SessionContainer { // always lock the node_id_to_session first, then the sessions. let mut expired_session = self.expired_sessions.write(); - let mut sessions = self.sessions.write(); let mut node_ids = self.node_id_to_session.lock(); + let mut sessions = self.sessions.write(); if sessions.len() >= MAX_SESSIONS { return Err(ErrorKind::TooManyConnections.into()); @@ -566,9 +566,10 @@ impl SessionContainer { self.node_id_to_session .lock() .get(id) + .cloned() .map_or(None, |peer_id| { let sessions = self.sessions.read(); - sessions.get(peer_id).cloned() + sessions.get(&peer_id).cloned() }) } @@ -921,6 +922,7 @@ impl Host { } fn have_session(&self, id: &NodeId) -> bool { + //self.sessions.have_session(id) self.sessions.get_session_for(id).is_some() } @@ -1006,7 +1008,8 @@ impl Host { let (mut handshake_count, egress_count, ingress_count) = self.session_count(); // we clone the reserved nodes, to avoid deadlocks and reduce locking time. - let unconnected_reserved_nodes: Vec = self.reserved_nodes.read().clone().into_iter().filter(|f| !self.have_session(f)).collect(); + let reserved_nodes = Arc::new(self.reserved_nodes.read().clone()); + let unconnected_reserved_nodes: Vec = reserved_nodes.as_ref().into_iter().filter(|f| !self.have_session(f)).cloned().collect(); // reserved peers are already findable in the SessionContainer, even they are handshaking. // so we wont trigger a second handshake here. @@ -1019,7 +1022,7 @@ impl Host { handshake_count += 1; } - if (pin) { + if pin { return; } @@ -1031,17 +1034,20 @@ impl Host { // ip filter: //.nodes(&allow_ips)) - let number_of_connects_to_make = max_handshakes_per_round.min(max_handshakes - handshake_count); + let number_of_connects_to_make = (min_peers as usize).min(max_handshakes_per_round.min(max_handshakes - handshake_count)); - // now connect to nodes from the node table. - for id in self.nodes.read().nodes_filtered(number_of_connects_to_make, + let nodes_to_connect = self.nodes.read().nodes_filtered(number_of_connects_to_make, &allow_ips, - |n: &Node| { + |n: &Node| { n.id != self_id + && !&reserved_nodes.contains(&n.id) && self.filter.as_ref().map_or(true, |f| { f.connection_allowed(&self_id, &n.id, ConnectionDirection::Outbound)}) - && !self.have_session(&n.id) - }) + && !self.have_session(&n.id) // alternative strategy: we might also get an list of active connections, instead of locking here to figure out if we have a session or not. + }); + + // now connect to nodes from the node table. + for id in nodes_to_connect { self.connect_peer(&id, io); started += 1; @@ -1166,7 +1172,7 @@ impl Host { } Ok(SessionData::Ready) => { let (_, egress_count, ingress_count) = self.session_count(); - let reserved_nodes = self.reserved_nodes.read(); + let mut s = session.lock(); self.sessions.register_finalized_handshake(token, s.id()); let (min_peers, mut max_peers, reserved_only, self_id) = { @@ -1200,7 +1206,7 @@ impl Host { || (s.info.originated && egress_count > min_peers) || (!s.info.originated && ingress_count > max_ingress) { - if !reserved_nodes.contains(&id) { + if !self.reserved_nodes.read().contains(&id) { // only proceed if the connecting peer is reserved. trace!(target: "network", "Disconnecting non-reserved peer {:?} (TooManyPeers)", id); s.disconnect(io, DisconnectReason::TooManyPeers); From d095f4309c91eddc40fb78d0ff235676df4d2be7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 8 Jul 2025 11:41:57 +0200 Subject: [PATCH 566/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/net/network-devp2p/src/host.rs | 51 +++++++++++---------- crates/net/network-devp2p/src/node_table.rs | 10 +++- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 8d531a3a8..238a69ad1 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -595,7 +595,7 @@ impl SessionContainer { return None; }) } - + fn register_finalized_handshake(&self, token: usize, id: Option<ðereum_types::H512>) { let node_id = match id { Some(id) => id.clone(), @@ -608,7 +608,7 @@ impl SessionContainer { // register this session. if let Some(old) = self.node_id_to_session.lock().insert(node_id, token) { - // in scenarios where we did have registered the session to this node, + // in scenarios where we did have registered the session to this node, // the token id wont change. // but still we need a lock to node_id_to_session anyway. if old != token { @@ -839,7 +839,6 @@ impl Host { let mut peers = Vec::with_capacity(sessions.len()); - for peer_id in sessions.keys() { peers.push(peer_id.clone()); } @@ -989,7 +988,6 @@ impl Host { } fn connect_peers(&self, io: &IoContext) { - let (min_peers, pin, max_handshakes, allow_ips, self_id) = { let info = self.info.read(); if info.capabilities.is_empty() { @@ -1005,15 +1003,20 @@ impl Host { *info.id(), ) }; - + let (mut handshake_count, egress_count, ingress_count) = self.session_count(); // we clone the reserved nodes, to avoid deadlocks and reduce locking time. - let reserved_nodes = Arc::new(self.reserved_nodes.read().clone()); - let unconnected_reserved_nodes: Vec = reserved_nodes.as_ref().into_iter().filter(|f| !self.have_session(f)).cloned().collect(); + let reserved_nodes = Arc::new(self.reserved_nodes.read().clone()); + let unconnected_reserved_nodes: Vec = reserved_nodes + .as_ref() + .into_iter() + .filter(|f| !self.have_session(f)) + .cloned() + .collect(); // reserved peers are already findable in the SessionContainer, even they are handshaking. // so we wont trigger a second handshake here. - + let mut started: usize = 0; for reserved in &unconnected_reserved_nodes { @@ -1034,21 +1037,23 @@ impl Host { // ip filter: //.nodes(&allow_ips)) - let number_of_connects_to_make = (min_peers as usize).min(max_handshakes_per_round.min(max_handshakes - handshake_count)); - - let nodes_to_connect = self.nodes.read().nodes_filtered(number_of_connects_to_make, - &allow_ips, - |n: &Node| { - n.id != self_id - && !&reserved_nodes.contains(&n.id) - && self.filter.as_ref().map_or(true, |f| { - f.connection_allowed(&self_id, &n.id, ConnectionDirection::Outbound)}) - && !self.have_session(&n.id) // alternative strategy: we might also get an list of active connections, instead of locking here to figure out if we have a session or not. - }); + let number_of_connects_to_make = (min_peers as usize) + .min(max_handshakes_per_round.min(max_handshakes - handshake_count)); + + let nodes_to_connect = + self.nodes + .read() + .nodes_filtered(number_of_connects_to_make, &allow_ips, |n: &Node| { + n.id != self_id + && !&reserved_nodes.contains(&n.id) + && self.filter.as_ref().map_or(true, |f| { + f.connection_allowed(&self_id, &n.id, ConnectionDirection::Outbound) + }) + && !self.have_session(&n.id) // alternative strategy: we might also get an list of active connections, instead of locking here to figure out if we have a session or not. + }); // now connect to nodes from the node table. - for id in nodes_to_connect - { + for id in nodes_to_connect { self.connect_peer(&id, io); started += 1; } @@ -1172,7 +1177,7 @@ impl Host { } Ok(SessionData::Ready) => { let (_, egress_count, ingress_count) = self.session_count(); - + let mut s = session.lock(); self.sessions.register_finalized_handshake(token, s.id()); let (min_peers, mut max_peers, reserved_only, self_id) = { @@ -1419,7 +1424,7 @@ impl Host { let mut expired_session = None; if token >= FIRST_SESSION { // we can shorten the session read lock here, if this causes a deadlock. - // on the other hand it is good, so not that many sessions manipulations can take place + // on the other hand it is good, so not that many sessions manipulations can take place // at the same time. let sessions = self.sessions.sessions.read(); if let Some(session) = sessions.get(&token).cloned() { diff --git a/crates/net/network-devp2p/src/node_table.rs b/crates/net/network-devp2p/src/node_table.rs index 808cb8657..f3f1118ed 100644 --- a/crates/net/network-devp2p/src/node_table.rs +++ b/crates/net/network-devp2p/src/node_table.rs @@ -376,9 +376,15 @@ impl NodeTable { /// Returns node ids sorted by failure percentage, for nodes with the same failure percentage the absolute number of /// failures is considered. - pub fn nodes_filtered(&self, max_count: usize, ip_filter: &IpFilter, filter: F) -> Vec + pub fn nodes_filtered( + &self, + max_count: usize, + ip_filter: &IpFilter, + filter: F, + ) -> Vec where - F: Fn(&Node) -> bool { + F: Fn(&Node) -> bool, + { self.ordered_entries() .iter() .filter(|n| n.endpoint.is_allowed(&ip_filter)) From 524adcb6a212fdb1f1f429a7682207263ad751d5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 8 Jul 2025 16:04:45 +0200 Subject: [PATCH 567/687] reduced "Error in Honey Badger Engine timeout handler: " log level to trace --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 4d7768e95..00884b4a1 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -344,7 +344,7 @@ impl IoHandler<()> for TransitionHandler { fn timeout(&self, io: &IoContext<()>, timer: TimerToken) { if timer == ENGINE_TIMEOUT_TOKEN { if let Err(err) = self.handle_engine(io) { - error!(target: "consensus", "Error in Honey Badger Engine timeout handler: {:?}", err); + trace!(target: "consensus", "Error in Honey Badger Engine timeout handler: {:?}", err); } } else if timer == ENGINE_SHUTDOWN { // we do not run this on the first occurence, From 4c8960f614d0ab63da9e020c5f3a016a07c51902 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 11 Jul 2025 23:55:38 +0200 Subject: [PATCH 568/687] logs --- crates/ethcore/sync/src/api.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 6715e6cfe..83c4f9ec5 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -562,6 +562,7 @@ impl PrometheusMetrics for SyncProtocolHandler { impl NetworkProtocolHandler for SyncProtocolHandler { fn initialize(&self, io: &dyn NetworkContext) { + trace!(target: "sync", "Initializing sync protocol handler for subprotocol: {}", io.subprotocol_name()); if io.subprotocol_name() != PAR_PROTOCOL { io.register_timer(PEERS_TIMER, Duration::from_millis(700)) .expect("Error registering peers timer"); @@ -595,7 +596,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler { trace_time!("sync::connected"); let node_id = io.session_info(*peer).unwrap().id; if io.is_reserved_peer(*peer) { - trace!(target: "sync", "Connected to reserved peer {:?}", node_id); + trace!(target: "sync", "Connected to reserved peer {node_id:?} {peer}" ); } // If warp protocol is supported only allow warp handshake let warp_protocol = io.protocol_version(PAR_PROTOCOL, *peer).unwrap_or(0) != 0; @@ -611,7 +612,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler { fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId) { trace_time!("sync::disconnected"); if io.is_reserved_peer(*peer) { - warn!(target: "sync", "Disconnected from reserved peer peerID: {} {}",peer, io.session_info(*peer).expect("").id.map_or("".to_string(), |f| format!("{:?}", f))); + warn!(target: "sync", "Disconnected from reserved peer peerID: {} protocol: {} peer: {}",peer , io.subprotocol_name(), io.session_info(*peer).expect("").id.map_or("".to_string(), |f| format!("{:?}", f))); } if io.subprotocol_name() != PAR_PROTOCOL { self.sync.write().on_peer_aborting( @@ -623,6 +624,10 @@ impl NetworkProtocolHandler for SyncProtocolHandler { fn timeout(&self, nc: &dyn NetworkContext, timer: TimerToken) { trace_time!("sync::timeout"); + + trace!(target: "sync", "Timer {} triggered.", timer); + // timer 2: + // Timer 0 triggered. let mut io = NetSyncIo::new(nc, &*self.chain, &*self.snapshot_service, &self.overlay); match timer { PEERS_TIMER => self.sync.write().maintain_peers(&mut io), From adfa55a0dd4b6a2e8a01f07ab10d98bf8519392d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 11 Jul 2025 23:57:06 +0200 Subject: [PATCH 569/687] session nonce --- crates/net/network-devp2p/src/session.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/net/network-devp2p/src/session.rs b/crates/net/network-devp2p/src/session.rs index 9fc687916..fe0f4d005 100644 --- a/crates/net/network-devp2p/src/session.rs +++ b/crates/net/network-devp2p/src/session.rs @@ -62,6 +62,8 @@ enum ProtocolState { pub struct Session { /// Shared session information pub info: SessionInfo, + + /// Session ready flag. Set after successful Hello packet exchange had_hello: bool, /// Session is no longer active flag. @@ -142,6 +144,7 @@ impl Session { &mut self, io: &IoContext, host: &HostInfo, + session_uid: H256 ) -> Result<(), Error> where Message: Send + Sync + Clone, @@ -153,6 +156,7 @@ impl Session { } else { panic!("Unexpected state"); }; + self.info.session_uid = Some(session_uid); self.state = State::Session(connection); self.write_hello(io, host)?; Ok(()) @@ -207,13 +211,16 @@ impl Session { if self.expired() { return Ok(SessionData::None); } - let mut create_session = false; + let mut create_session_with_uid: Option = None; let mut packet_data = None; match self.state { State::Handshake(ref mut h) => { h.readable(io, host)?; if h.done() { - create_session = true; + // the Nonce Id is a unique ID shared on both endpoints + // it can be used to order sessions for example duplicate removal, + // so both Nodes can use the same algorithm to decide wich connection to keep. + create_session_with_uid = Some(h.nonce ^ h.remote_nonce); } } State::Session(ref mut c) => match c.readable(io)? { @@ -224,8 +231,8 @@ impl Session { if let Some(data) = packet_data { return Ok(self.read_packet(io, &data, host)?); } - if create_session { - self.complete_handshake(io, host)?; + if let Some(session_uid) = create_session_with_uid { + self.complete_handshake(io, host, session_uid)?; io.update_registration(self.token()) .unwrap_or_else(|e| debug!(target: "network", "Token registration error: {:?}", e)); } @@ -570,7 +577,7 @@ impl Session { offset += caps[i].packet_count; i += 1; } - debug!(target: "network", "Hello: {} v{} {} {:?}", client_version, protocol, id, caps); + debug!(target: "network", "Hello: {} {} v{} {} {:?}", self.token(), client_version, protocol, id, caps); let protocol = ::std::cmp::min(protocol, host.protocol_version); self.info.protocol_version = protocol; self.info.client_version = client_version; @@ -617,6 +624,8 @@ impl Session { where Message: Send + Sync + Clone, { + + if let State::Session(_) = self.state { let mut rlp = RlpStream::new(); rlp.begin_list(1); @@ -625,6 +634,8 @@ impl Session { .ok(); } ErrorKind::Disconnect(reason).into() + + } fn send(&mut self, io: &IoContext, data: &[u8]) -> Result<(), Error> From b5abdb60543463f4f7e58881a3e2098a0677b9dc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 11 Jul 2025 23:57:32 +0200 Subject: [PATCH 570/687] double connections --- crates/net/network-devp2p/src/host.rs | 149 +++++++++++++++++++++++--- 1 file changed, 137 insertions(+), 12 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 238a69ad1..36aedad8e 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -257,6 +257,7 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { } fn register_timer(&self, token: TimerToken, delay: Duration) -> std::result::Result<(), Error> { + trace!(target: "network", "Registering timer: {:?} for protocol: {} with delay {}", token, self.protocol, delay.as_millis()); self.io .message(NetworkIoMessage::AddTimer { token, @@ -563,6 +564,7 @@ impl SessionContainer { } fn get_session_for(&self, id: &NodeId) -> Option { + self.node_id_to_session .lock() .get(id) @@ -618,6 +620,93 @@ impl SessionContainer { debug!(target: "network", "handshake completed: node id {} registered primary session token {}", node_id, token); } } + + // handles duplicated sessions and desides wich one to be deleted. a duplicated session if it exists in a deterministic way, so both sides agree on the same session to keep. + // returns if this session is marked for deletion, and not being accepted by the SessionContainer. + // see: https://github.com/DMDcoin/diamond-node/issues/252 + fn should_delete_duplicate_session(&self, session: &SharedSession) -> Option { + + let mut node_id = NodeId::zero(); + let mut peer_id = PeerId::default(); + let mut uid: H256 = H256::zero(); + + { + let lock = session.lock(); + peer_id = lock.token().clone(); + + node_id = match lock.id() { + Some(id) => id.clone(), + None => { + trace!(target: "network", "Tried to delete duplicate session without node id"); + return None; // we have no node id, so we can not delete it. + } + }; + + uid = match lock.info.session_uid { + Some(u) => u.clone(), + None => { + trace!(target: "network", "Tried to delete duplicate session without session uid"); + return None; // we have no session uid, so we can not delete it. + }, + }; + }; + + if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { + if existing_peer_id != peer_id { + + // there may be an active session for this peer id. + let existing_session = self.get_session_for(&node_id); + if let Some(existing_session_mutex) = existing_session { + let existing_lock = existing_session_mutex.lock(); + if existing_lock.expired() { + // other session is already about to get deleted. + trace!(target:"network", "existing peer session {existing_peer_id} is already about to get deleted."); + return None; + } + if let Some(existing_uid) = existing_lock.info.session_uid { + // the highest RNG wins. + if existing_uid.lt(&uid) { + // we keep the existing session, and delete the new one. + trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} for {node_id}, deleting this session"); + // we savely mark this connection to get killed softly. + return Some(peer_id); + } else { + trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} for {node_id}, deleting duplicated session"); + // and delete the existing one. + return Some(existing_peer_id); + } + } + } + + trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} {node_id}"); + return Some(existing_peer_id); + } + } + + return None; + } + + // makes a shallow search if there is already a session for that connection + fn is_duplicate(&self, session: &SharedSession) -> bool { + + + let (id, token) = { + let lock = session.lock(); + (lock.id().cloned(), lock.token().clone()) + }; + + if let Some(node_id) = id { + + if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { + if existing_peer_id != token { + trace!(target: "network", "Session {token} has a duplicate :{existing_peer_id} {node_id}"); + return true; + } + } + } // else we dont have enough information to make a decision. + + return false; + } } fn socket_address_to_string(socket: &TcpStream) -> String { @@ -922,7 +1011,13 @@ impl Host { fn have_session(&self, id: &NodeId) -> bool { //self.sessions.have_session(id) - self.sessions.get_session_for(id).is_some() + let result = self.sessions.get_session_for(id).is_some(); + + if !result { + trace!(target: "network", "no session found for {id}"); + } + + return result; } // returns (handshakes, egress, ingress) @@ -1005,6 +1100,10 @@ impl Host { }; let (mut handshake_count, egress_count, ingress_count) = self.session_count(); + + trace!(target: "network", "initial handshake count: {handshake_count}"); + + // we clone the reserved nodes, to avoid deadlocks and reduce locking time. let reserved_nodes = Arc::new(self.reserved_nodes.read().clone()); let unconnected_reserved_nodes: Vec = reserved_nodes @@ -1020,6 +1119,7 @@ impl Host { let mut started: usize = 0; for reserved in &unconnected_reserved_nodes { + trace!(target: "network", "connect_peer because it is unconnected reserved peer: {reserved}"); self.connect_peer(reserved, io); started += 1; handshake_count += 1; @@ -1052,6 +1152,8 @@ impl Host { && !self.have_session(&n.id) // alternative strategy: we might also get an list of active connections, instead of locking here to figure out if we have a session or not. }); + trace!(target: "network", "reserved nodes: {:?} nodes_to_connect: {:?}", reserved_nodes, nodes_to_connect); + // now connect to nodes from the node table. for id in nodes_to_connect { self.connect_peer(&id, io); @@ -1147,7 +1249,7 @@ impl Host { fn session_readable(&self, token: StreamToken, io: &IoContext) { let mut ready_data: Vec = Vec::new(); let mut packet_data: Vec<(ProtocolId, PacketId, Vec)> = Vec::new(); - let mut kill = false; + let mut kill : Option = None; let session = { self.sessions.sessions.read().get(&token).cloned() }; let mut ready_id = None; if let Some(session) = session.clone() { @@ -1172,14 +1274,25 @@ impl Host { } _ => {} } - kill = true; + kill = Some(token); break; } Ok(SessionData::Ready) => { let (_, egress_count, ingress_count) = self.session_count(); + //if self.sessions.is_duplicate(&session) { + + kill = self.sessions.should_delete_duplicate_session(&session); + + if let Some(session_to_kill) = kill { + if session_to_kill == token { + // if its our session wich gets to be killed, we can skip the next setup steps. + break; + } + } + let mut s = session.lock(); - self.sessions.register_finalized_handshake(token, s.id()); + // self.sessions.register_finalized_handshake(token, s.id()); let (min_peers, mut max_peers, reserved_only, self_id) = { let info = self.info.read(); let mut max_peers = info.config.max_peers; @@ -1215,7 +1328,7 @@ impl Host { // only proceed if the connecting peer is reserved. trace!(target: "network", "Disconnecting non-reserved peer {:?} (TooManyPeers)", id); s.disconnect(io, DisconnectReason::TooManyPeers); - kill = true; + kill = Some(token); break; } } @@ -1225,7 +1338,7 @@ impl Host { }) { trace!(target: "network", "Inbound connection not allowed for {:?}", id); s.disconnect(io, DisconnectReason::UnexpectedIdentity); - kill = true; + kill = Some(token); break; } @@ -1276,10 +1389,14 @@ impl Host { } } - if kill { - self.kill_connection(token, io, true); + if let Some(peer_to_kill) = kill { + self.kill_connection(peer_to_kill, io, true); } + // todo: because of new duplicated session detection logic, + // https://github.com/DMDcoin/diamond-node/issues/252 + // this code should realisticly not be able to find duplicate sessions. + let handlers = self.handlers.read(); if !ready_data.is_empty() { let duplicates: Vec = self @@ -1289,7 +1406,7 @@ impl Host { .iter() .filter_map(|e| { let session = e.1.lock(); - if session.token() != token && session.info.id == ready_id { + if session.token() != token && session.info.id == ready_id && !session.expired(){ return Some(session.token()); } else { return None; @@ -1414,10 +1531,14 @@ impl Host { fn connection_timeout(&self, token: StreamToken, io: &IoContext) { trace!(target: "network", "Connection timeout: {}", token); - self.kill_connection(token, io, true) + self.kill_connection(token, io, true); } fn kill_connection(&self, token: StreamToken, io: &IoContext, remote: bool) { + self.kill_connection_with_failure(token, io, remote, true); + } + + fn kill_connection_with_failure(&self, token: StreamToken, io: &IoContext, remote: bool, as_failure: bool) { let mut to_disconnect: Vec = Vec::new(); let mut failure_id = None; let mut deregister = false; @@ -1431,15 +1552,18 @@ impl Host { expired_session = Some(session.clone()); let mut s = session.lock(); if !s.expired() { + if as_failure { + failure_id = s.id().cloned(); + } if s.is_ready() { for (p, _) in self.handlers.read().iter() { if s.have_capability(*p) { - to_disconnect.push(*p); + to_disconnect.push(p.clone()); } } } + s.set_expired(); - failure_id = s.id().cloned(); } deregister = remote || s.done(); } else { @@ -1676,6 +1800,7 @@ impl IoHandler for Host { ref delay, ref token, } => { + trace!(target: "network", "Adding timer for protocol: {:?}, delay: {:?}, token: {}", protocol, delay.as_millis(), token); let handler_token = { let mut timer_counter = self.timer_counter.write(); let counter = &mut *timer_counter; From ac0c9059a00b2bb9b195744f84c6674532ad568d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 12 Jul 2025 16:24:50 +0200 Subject: [PATCH 571/687] handshake: logging peer_id. --- crates/net/network-devp2p/src/handshake.rs | 4 ++-- crates/net/network-devp2p/src/session.rs | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/net/network-devp2p/src/handshake.rs b/crates/net/network-devp2p/src/handshake.rs index 98bc38ed2..dd6b3c0dd 100644 --- a/crates/net/network-devp2p/src/handshake.rs +++ b/crates/net/network-devp2p/src/handshake.rs @@ -241,7 +241,7 @@ impl Handshake { where Message: Send + Clone + Sync + 'static, { - trace!(target: "network", "Received EIP8 handshake auth from {:?}", self.connection.remote_addr_str()); + trace!(target: "network", "{} Received EIP8 handshake auth from {:?}", self.connection.token, self.connection.remote_addr_str()); self.auth_cipher.extend_from_slice(data); let auth = ecies::decrypt(secret, &self.auth_cipher[0..2], &self.auth_cipher[2..])?; let rlp = Rlp::new(&auth); @@ -290,7 +290,7 @@ impl Handshake { } fn read_ack_eip8(&mut self, secret: &Secret, data: &[u8]) -> Result<(), Error> { - trace!(target: "network", "Received EIP8 handshake auth from {:?}", self.connection.remote_addr_str()); + trace!(target: "network", "{} Received EIP8 handshake auth from {:?}",self.connection.token, self.connection.remote_addr_str()); self.ack_cipher.extend_from_slice(data); let ack = ecies::decrypt(secret, &self.ack_cipher[0..2], &self.ack_cipher[2..])?; let rlp = Rlp::new(&ack); diff --git a/crates/net/network-devp2p/src/session.rs b/crates/net/network-devp2p/src/session.rs index fe0f4d005..c0752849a 100644 --- a/crates/net/network-devp2p/src/session.rs +++ b/crates/net/network-devp2p/src/session.rs @@ -63,7 +63,6 @@ pub struct Session { /// Shared session information pub info: SessionInfo, - /// Session ready flag. Set after successful Hello packet exchange had_hello: bool, /// Session is no longer active flag. @@ -144,7 +143,7 @@ impl Session { &mut self, io: &IoContext, host: &HostInfo, - session_uid: H256 + session_uid: H256, ) -> Result<(), Error> where Message: Send + Sync + Clone, @@ -624,8 +623,6 @@ impl Session { where Message: Send + Sync + Clone, { - - if let State::Session(_) = self.state { let mut rlp = RlpStream::new(); rlp.begin_list(1); @@ -634,8 +631,6 @@ impl Session { .ok(); } ErrorKind::Disconnect(reason).into() - - } fn send(&mut self, io: &IoContext, data: &[u8]) -> Result<(), Error> From 3e28e1d3c3882f00cf20eb36202325676dec87c2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 13 Jul 2025 12:01:25 +0200 Subject: [PATCH 572/687] session UID for SessionInfo --- crates/net/network/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index 2f0f47d04..fbdcbca1c 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -17,7 +17,7 @@ #![recursion_limit = "128"] extern crate ethcore_io as io; -use ethereum_types; +use ethereum_types::{self, H256}; extern crate ethkey; extern crate ipnetwork; extern crate libc; @@ -130,6 +130,10 @@ pub struct SessionInfo { /// Local endpoint address of the session pub local_address: String, + /// A unique identifier that is the same on both sessions endpoints after the handshake is completed. + /// it is the XOR of the Nonces for the handshake that initialized this Session. + pub session_uid: Option, + /// peer is capable of doing EIP 2464 transaction gossiping: https://eips.ethereum.org/EIPS/eip-2464 is_pooled_transactions_capable: bool, } @@ -148,6 +152,7 @@ impl SessionInfo { remote_address: "Handshake".to_owned(), local_address: local_addr, is_pooled_transactions_capable: false, // we don't know yet, we will know once we get the capabilities + session_uid: None, // session-uid is set after the handshake has completed. }; } From 6068bf831d5309cdc8ccbe093f4e92061b3015b1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 13 Jul 2025 12:03:49 +0200 Subject: [PATCH 573/687] registering finalization of handshakes. further info and cleanup --- crates/ethcore/sync/src/chain/propagator.rs | 4 ++ crates/net/network-devp2p/src/host.rs | 55 ++++++++++++--------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 25e7b16cf..ac3606de1 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -131,6 +131,8 @@ impl ChainSync { /// propagates new transactions to all peers pub(crate) fn propagate_new_ready_transactions(&mut self, io: &mut dyn SyncIo) { + debug!(target: "sync", "propagate_new_ready_transactions"); + let deadline = Instant::now() + Duration::from_millis(500); self.propagate_ready_transactions(io, || { @@ -497,6 +499,8 @@ impl ChainSync { F: FnMut() -> bool, G: Fn(&dyn SyncIo) -> Vec>, { + trace!(target:"sync", "propagate_transactions"); + // Early out if nobody to send to. if self.peers.is_empty() { return 0; diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 36aedad8e..a3787672d 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -564,7 +564,6 @@ impl SessionContainer { } fn get_session_for(&self, id: &NodeId) -> Option { - self.node_id_to_session .lock() .get(id) @@ -623,21 +622,21 @@ impl SessionContainer { // handles duplicated sessions and desides wich one to be deleted. a duplicated session if it exists in a deterministic way, so both sides agree on the same session to keep. // returns if this session is marked for deletion, and not being accepted by the SessionContainer. - // see: https://github.com/DMDcoin/diamond-node/issues/252 + // see: https://github.com/DMDcoin/diamond-node/issues/252 fn should_delete_duplicate_session(&self, session: &SharedSession) -> Option { - let mut node_id = NodeId::zero(); let mut peer_id = PeerId::default(); let mut uid: H256 = H256::zero(); - { + { let lock = session.lock(); peer_id = lock.token().clone(); node_id = match lock.id() { Some(id) => id.clone(), None => { - trace!(target: "network", "Tried to delete duplicate session without node id"); + // based on the control flow of the software, this should never happen. + warn!(target: "network", "Tried to delete duplicate session without node id"); return None; // we have no node id, so we can not delete it. } }; @@ -645,15 +644,15 @@ impl SessionContainer { uid = match lock.info.session_uid { Some(u) => u.clone(), None => { - trace!(target: "network", "Tried to delete duplicate session without session uid"); + // based on the control flow of the software, this should never happen. + warn!(target: "network", "Tried to delete duplicate session without session uid"); return None; // we have no session uid, so we can not delete it. - }, - }; + } + }; }; if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { if existing_peer_id != peer_id { - // there may be an active session for this peer id. let existing_session = self.get_session_for(&node_id); if let Some(existing_session_mutex) = existing_session { @@ -676,27 +675,29 @@ impl SessionContainer { return Some(existing_peer_id); } } + } else { + trace!(target: "network", "No session active for {node_id} with peer id {existing_peer_id}"); + // todo: make sure the mapping is rewritten. } trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} {node_id}"); return Some(existing_peer_id); } + } else { + trace!(target: "network", "No session known for {node_id}"); } return None; } - + // makes a shallow search if there is already a session for that connection fn is_duplicate(&self, session: &SharedSession) -> bool { - - - let (id, token) = { + let (id, token) = { let lock = session.lock(); - (lock.id().cloned(), lock.token().clone()) + (lock.id().cloned(), lock.token().clone()) }; - - if let Some(node_id) = id { + if let Some(node_id) = id { if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { if existing_peer_id != token { trace!(target: "network", "Session {token} has a duplicate :{existing_peer_id} {node_id}"); @@ -1103,16 +1104,16 @@ impl Host { trace!(target: "network", "initial handshake count: {handshake_count}"); - // we clone the reserved nodes, to avoid deadlocks and reduce locking time. let reserved_nodes = Arc::new(self.reserved_nodes.read().clone()); let unconnected_reserved_nodes: Vec = reserved_nodes .as_ref() .into_iter() - .filter(|f| !self.have_session(f)) + .filter(|f| !self.have_session(f) && f.ne(&&self_id)) .cloned() .collect(); + // reserved peers are already findable in the SessionContainer, even they are handshaking. // so we wont trigger a second handshake here. @@ -1249,7 +1250,7 @@ impl Host { fn session_readable(&self, token: StreamToken, io: &IoContext) { let mut ready_data: Vec = Vec::new(); let mut packet_data: Vec<(ProtocolId, PacketId, Vec)> = Vec::new(); - let mut kill : Option = None; + let mut kill: Option = None; let session = { self.sessions.sessions.read().get(&token).cloned() }; let mut ready_id = None; if let Some(session) = session.clone() { @@ -1291,8 +1292,9 @@ impl Host { } } + let mut s = session.lock(); - // self.sessions.register_finalized_handshake(token, s.id()); + self.sessions.register_finalized_handshake(token, s.id()); let (min_peers, mut max_peers, reserved_only, self_id) = { let info = self.info.read(); let mut max_peers = info.config.max_peers; @@ -1406,7 +1408,10 @@ impl Host { .iter() .filter_map(|e| { let session = e.1.lock(); - if session.token() != token && session.info.id == ready_id && !session.expired(){ + if session.token() != token + && session.info.id == ready_id + && !session.expired() + { return Some(session.token()); } else { return None; @@ -1538,7 +1543,13 @@ impl Host { self.kill_connection_with_failure(token, io, remote, true); } - fn kill_connection_with_failure(&self, token: StreamToken, io: &IoContext, remote: bool, as_failure: bool) { + fn kill_connection_with_failure( + &self, + token: StreamToken, + io: &IoContext, + remote: bool, + as_failure: bool, + ) { let mut to_disconnect: Vec = Vec::new(); let mut failure_id = None; let mut deregister = false; From f21001f6bf699fd29fe12a96ea4716b9c8d94842 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 13 Jul 2025 12:04:26 +0200 Subject: [PATCH 574/687] fixed whispaces --- crates/net/network-devp2p/src/host.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index a3787672d..c1369292e 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -1113,7 +1113,6 @@ impl Host { .cloned() .collect(); - // reserved peers are already findable in the SessionContainer, even they are handshaking. // so we wont trigger a second handshake here. @@ -1292,7 +1291,6 @@ impl Host { } } - let mut s = session.lock(); self.sessions.register_finalized_handshake(token, s.id()); let (min_peers, mut max_peers, reserved_only, self_id) = { From d5cc8d86fa9c55ed86c67a948038eca80478b619 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Jul 2025 17:20:04 +0200 Subject: [PATCH 575/687] refactoring: moved session container to session_container.rs. --- Cargo.lock | 1 + crates/net/network-devp2p/Cargo.toml | 1 + crates/net/network-devp2p/src/host.rs | 441 +----------------- crates/net/network-devp2p/src/lib.rs | 1 + .../network-devp2p/src/session_container.rs | 428 +++++++++++++++++ 5 files changed, 456 insertions(+), 416 deletions(-) create mode 100644 crates/net/network-devp2p/src/session_container.rs diff --git a/Cargo.lock b/Cargo.lock index a380c6ece..bfa9d8420 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,6 +1519,7 @@ dependencies = [ "slab 0.2.0", "stats", "tempdir", + "time-utils", "tiny-keccak 1.5.0", ] diff --git a/crates/net/network-devp2p/Cargo.toml b/crates/net/network-devp2p/Cargo.toml index 2691952bd..241d318c8 100644 --- a/crates/net/network-devp2p/Cargo.toml +++ b/crates/net/network-devp2p/Cargo.toml @@ -36,6 +36,7 @@ serde_derive = "1.0" error-chain = { version = "0.12", default-features = false } lru-cache = "0.1" stats = { path = "../../util/stats" } +time-utils = { path = "../../util/time-utils" } [dev-dependencies] env_logger = "0.5" diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index c1369292e..3f25519bc 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -14,14 +14,17 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use crate::mio::{deprecated::EventLoop, tcp::*, udp::*, *}; +use crate::{ + mio::{deprecated::EventLoop, tcp::*, udp::*, *}, + session_container::{SessionContainer, SharedSession}, +}; use crypto::publickey::{Generator, KeyPair, Random, Secret}; use ethereum_types::H256; use hash::keccak; use rlp::{Encodable, RlpStream}; use std::{ cmp::{max, min}, - collections::{BTreeMap, HashMap, HashSet}, + collections::{HashMap, HashSet}, fs, io::{self, Read, Write}, net::{Ipv4Addr, SocketAddr, SocketAddrV4}, @@ -32,7 +35,7 @@ use std::{ Arc, atomic::{AtomicBool, AtomicU64, Ordering as AtomicOrdering}, }, - time::{Duration, Instant}, + time::Duration, }; use crate::{ @@ -41,7 +44,7 @@ use crate::{ io::*, ip_utils::{map_external_address, select_public_address}, node_table::*, - session::{Session, SessionData}, + session::SessionData, }; use network::{ ConnectionDirection, ConnectionFilter, DisconnectReason, Error, ErrorKind, @@ -178,7 +181,7 @@ impl<'s> NetworkContext<'s> { fn resolve_session(&self, peer: PeerId) -> Option { match self.session_id { Some(id) if id == peer => self.session.clone(), - _ => self.sessions.sessions.read().get(&peer).cloned(), + _ => self.sessions.read().get(&peer).cloned(), } } } @@ -337,385 +340,12 @@ impl HostInfo { } } -type SharedSession = Arc>; - #[derive(Copy, Clone)] struct ProtocolTimer { pub protocol: ProtocolId, pub token: TimerToken, // Handler level token } -struct SessionContainer { - sessions: Arc>>, - expired_sessions: Arc>>, - node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. - sessions_token_max: Mutex, // Used to generate new session tokens -} - -impl SessionContainer { - pub fn new() -> Self { - SessionContainer { - sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), - expired_sessions: Arc::new(RwLock::new(Vec::new())), - node_id_to_session: Mutex::new(BTreeMap::new()), - sessions_token_max: Mutex::new(FIRST_SESSION), - } - } - - /// gets the next token ID and store this information - fn create_token_id( - &self, - node_id: &NodeId, - tokens: &mut BTreeMap, - ) -> usize { - let mut session_token_max = self.sessions_token_max.lock(); - let next_id = session_token_max.clone(); - - *session_token_max += 1; - - // TODO: if we run out of token ids, - // we need to recycle Ids that are not used anymore. - - if let Some(old) = tokens.insert(node_id.clone(), next_id) { - warn!(target: "network", "Node ID {} already exists with token {}, overwriting with {}", node_id, old, next_id); - } - - return next_id; - } - - fn create_token_id_for_handshake(&self) -> usize { - let mut session_token_max = self.sessions_token_max.lock(); - let next_id = session_token_max.clone(); - - *session_token_max += 1; - - // TODO: if we run out of token ids, - // we need to recycle Ids that are not used anymore. - - return next_id; - } - - /// Creates a new session and adds it to the session container. - /// returns the token ID of the new session, or an Error if not successful. - fn create_connection( - &self, - socket: TcpStream, - id: Option<ðereum_types::H512>, - io: &IoContext, - nonce: &H256, - host: &HostInfo, - ) -> Result { - // make sure noone else is trying to modify the sessions at the same time. - // creating a connection is a very rare event. - - // always lock the node_id_to_session first, then the sessions. - let mut expired_session = self.expired_sessions.write(); - let mut node_ids = self.node_id_to_session.lock(); - let mut sessions = self.sessions.write(); - - if sessions.len() >= MAX_SESSIONS { - return Err(ErrorKind::TooManyConnections.into()); - } - - if let Some(node_id) = id { - // check if there is already a connection for the given node id. - if let Some(existing_peer_id) = node_ids.get(node_id) { - let existing_session_mutex_o = sessions.get(existing_peer_id).clone(); - - if let Some(existing_session_mutex) = existing_session_mutex_o { - let session_expired = { - let session = existing_session_mutex.lock(); - if let Some(id_from_session) = &session.info.id { - if session.info.id == Some(*node_id) { - // we got already got a session for the specified node. - // maybe the old session is already scheduled for getting deleted. - session.expired() - } else { - error!(target: "network", "host cache inconsistency: Session node id missmatch. expected: {} is {}.", existing_peer_id, id_from_session); - return Err(ErrorKind::HostCacheInconsistency.into()); - } - } else { - error!(target: "network", "host cache inconsistency: Session has no Node_id defined where it should for {}", existing_peer_id); - return Err(ErrorKind::HostCacheInconsistency.into()); - } - }; // session guard is dropped here - - if session_expired { - debug!(target: "network", "Creating new session for expired {} token: {} node id: {:?}", socket_address_to_string(&socket), existing_peer_id, id); - // if the session is expired, we will just create n new session for this node. - let new_session = - Session::new(io, socket, existing_peer_id.clone(), id, nonce, host); - match new_session { - Ok(session) => { - let new_session_arc = Arc::new(Mutex::new(session)); - let old_session_o = - sessions.insert(*existing_peer_id, new_session_arc); - - match old_session_o { - Some(old) => { - // we remember the expired session, so it can get closed and cleaned up in a nice way later. - expired_session.push(old); - } - None => { - // we have a cache missmatch. - // but the only thing is missing is a clean ending of the old session. - // nothing mission critical. - error!(target: "network", "host cache inconsistency: Session for node id {} was not found in sessions map, but it should be there.", node_id); - } - } - - // in this context, the stream might already be unregistered ?! - // we can just register the stream again. - if let Err(err) = io.register_stream(*existing_peer_id) { - // todo: research this topic, watch out for this message, - // maybe we can keep track of stream registrations as well somehow. - debug!(target: "network", "Failed to register stream for token: {} : {}", existing_peer_id, err); - } - - return Ok(*existing_peer_id); - } - Err(e) => { - error!(target: "network", "Failed to create session for node id: {}", node_id); - return Err(e); - } - } - } else { - // this might happen if 2 nodes try to connect to each other at the same time. - debug!(target: "network", "Session already exists for node id: {}", node_id); - return Err(ErrorKind::AlreadyExists.into()); - } - } else { - debug!(target: "network", "reusing peer ID {} for node: {}", existing_peer_id, node_id); - // we have a node id, but there is no session for it (anymore) - // we reuse that peer_id, so other in flight actions are pointing to the same node again. - match Session::new(io, socket, existing_peer_id.clone(), id, nonce, host) { - Ok(new_session) => { - sessions.insert( - existing_peer_id.clone(), - Arc::new(Mutex::new(new_session)), - ); - if let Err(err) = io.register_stream(existing_peer_id.clone()) { - warn!(target: "network", "Failed to register stream for reused token: {} : {}", existing_peer_id, err); - } - return Ok(existing_peer_id.clone()); - } - Err(err) => { - debug!(target: "network", "reusing peer ID {} for node: {}, but could not create session", existing_peer_id, node_id); - return Err(err); - } - } - } - } else { - // this should be the most common scenario. - // we have a new node id, we were either never connected to, or we forgot about it. - - let next_free_token = self.create_token_id(&node_id, &mut node_ids); - trace!(target: "network", "Creating new session {} for new node id:{} with token {}", socket_address_to_string(&socket), node_id, next_free_token); - let new_session = - Session::new(io, socket, next_free_token.clone(), id, nonce, host); - // the token is already registerd. - match new_session { - Ok(session) => { - let session = Arc::new(Mutex::new(session)); - sessions.insert(next_free_token, session.clone()); - // register the stream for the new session. - if let Err(err) = io.register_stream(next_free_token) { - debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); - } - node_ids.insert(node_id.clone(), next_free_token); - - return Ok(next_free_token); - } - Err(e) => { - error!(target: "network", "Failed to create session for node id: {}", node_id); - return Err(e); - } - } - } - } else { - let next_free_token = self.create_token_id_for_handshake(); - - trace!(target: "network", "creating session for handshaking peer: {} token: {}", socket_address_to_string(&socket), next_free_token); - // we dont know the NodeID, - // we still need a session to do the handshake. - - let new_session = Session::new(io, socket, next_free_token.clone(), id, nonce, host); - // the token is already registerd. - match new_session { - Ok(session) => { - let session = Arc::new(Mutex::new(session)); - sessions.insert(next_free_token, session.clone()); - // register the stream for the new session. - if let Err(err) = io.register_stream(next_free_token) { - debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); - } - //node_ids.insert(node_id.clone(), next_free_token); - - return Ok(next_free_token); - } - Err(e) => { - error!(target: "network", "Failed to create handshake session for: {}", next_free_token); - return Err(e); - } - } - } - // if we dont know a NodeID - // debug!(target: "network", "Session create error: {:?}", e); - } - - fn get_session_for(&self, id: &NodeId) -> Option { - self.node_id_to_session - .lock() - .get(id) - .cloned() - .map_or(None, |peer_id| { - let sessions = self.sessions.read(); - sessions.get(&peer_id).cloned() - }) - } - - fn node_id_to_peer_id(&self, node_id: &NodeId, only_available_sessions: bool) -> Option { - self.node_id_to_session - .lock() - .get(node_id) - .map_or(None, |peer_id| { - if !only_available_sessions { - return Some(*peer_id); - } - let sessions = self.sessions.read(); - - // we can do additional checks: - // we could ensure that the Node ID matches. - // we could also read the flag and check if it is not marked for - // getting disconnected. - - if sessions.contains_key(peer_id) { - return Some(*peer_id); - } - - return None; - }) - } - - fn register_finalized_handshake(&self, token: usize, id: Option<ðereum_types::H512>) { - let node_id = match id { - Some(id) => id.clone(), - None => { - error!(target: "network", "Tried to register finalized handshake without node id"); - // we have no node id, so we can not register it. - return; - } - }; - - // register this session. - if let Some(old) = self.node_id_to_session.lock().insert(node_id, token) { - // in scenarios where we did have registered the session to this node, - // the token id wont change. - // but still we need a lock to node_id_to_session anyway. - if old != token { - debug!(target: "network", "handshake completed: changed primary session for node id {} from {} to {}", node_id, token, old); - } - } else { - debug!(target: "network", "handshake completed: node id {} registered primary session token {}", node_id, token); - } - } - - // handles duplicated sessions and desides wich one to be deleted. a duplicated session if it exists in a deterministic way, so both sides agree on the same session to keep. - // returns if this session is marked for deletion, and not being accepted by the SessionContainer. - // see: https://github.com/DMDcoin/diamond-node/issues/252 - fn should_delete_duplicate_session(&self, session: &SharedSession) -> Option { - let mut node_id = NodeId::zero(); - let mut peer_id = PeerId::default(); - let mut uid: H256 = H256::zero(); - - { - let lock = session.lock(); - peer_id = lock.token().clone(); - - node_id = match lock.id() { - Some(id) => id.clone(), - None => { - // based on the control flow of the software, this should never happen. - warn!(target: "network", "Tried to delete duplicate session without node id"); - return None; // we have no node id, so we can not delete it. - } - }; - - uid = match lock.info.session_uid { - Some(u) => u.clone(), - None => { - // based on the control flow of the software, this should never happen. - warn!(target: "network", "Tried to delete duplicate session without session uid"); - return None; // we have no session uid, so we can not delete it. - } - }; - }; - - if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { - if existing_peer_id != peer_id { - // there may be an active session for this peer id. - let existing_session = self.get_session_for(&node_id); - if let Some(existing_session_mutex) = existing_session { - let existing_lock = existing_session_mutex.lock(); - if existing_lock.expired() { - // other session is already about to get deleted. - trace!(target:"network", "existing peer session {existing_peer_id} is already about to get deleted."); - return None; - } - if let Some(existing_uid) = existing_lock.info.session_uid { - // the highest RNG wins. - if existing_uid.lt(&uid) { - // we keep the existing session, and delete the new one. - trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} for {node_id}, deleting this session"); - // we savely mark this connection to get killed softly. - return Some(peer_id); - } else { - trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} for {node_id}, deleting duplicated session"); - // and delete the existing one. - return Some(existing_peer_id); - } - } - } else { - trace!(target: "network", "No session active for {node_id} with peer id {existing_peer_id}"); - // todo: make sure the mapping is rewritten. - } - - trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} {node_id}"); - return Some(existing_peer_id); - } - } else { - trace!(target: "network", "No session known for {node_id}"); - } - - return None; - } - - // makes a shallow search if there is already a session for that connection - fn is_duplicate(&self, session: &SharedSession) -> bool { - let (id, token) = { - let lock = session.lock(); - (lock.id().cloned(), lock.token().clone()) - }; - - if let Some(node_id) = id { - if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { - if existing_peer_id != token { - trace!(target: "network", "Session {token} has a duplicate :{existing_peer_id} {node_id}"); - return true; - } - } - } // else we dont have enough information to make a decision. - - return false; - } -} - -fn socket_address_to_string(socket: &TcpStream) -> String { - socket - .peer_addr() - .map_or("unknown".to_string(), |a| a.to_string()) -} - /// Root IO handler. Manages protocol handlers, IO timers and network connections. /// /// NOTE: must keep the lock in order of: reserved_nodes (rwlock) -> session (mutex, from sessions) @@ -793,7 +423,7 @@ impl Host { discovery: Mutex::new(None), udp_socket: Mutex::new(None), tcp_listener: Mutex::new(tcp_listener), - sessions: SessionContainer::new(), + sessions: SessionContainer::new(FIRST_SESSION, MAX_SESSIONS), nodes: RwLock::new(NodeTable::new(path)), handlers: RwLock::new(HashMap::new()), timers: RwLock::new(HashMap::new()), @@ -868,7 +498,7 @@ impl Host { // disconnect all non-reserved peers here. let reserved: HashSet = self.reserved_nodes.read().clone(); let mut to_kill = Vec::new(); - for e in self.sessions.sessions.read().iter() { + for e in self.sessions.read().iter() { let mut s = e.1.lock(); { let id = s.id(); @@ -910,7 +540,7 @@ impl Host { pub fn stop(&self, io: &IoContext) { self.stopping.store(true, AtomicOrdering::SeqCst); let mut to_kill = Vec::new(); - for e in self.sessions.sessions.read().iter() { + for e in self.sessions.read().iter() { let mut s = e.1.lock(); s.disconnect(io, DisconnectReason::ClientQuit); to_kill.push(s.token()); @@ -924,7 +554,7 @@ impl Host { /// Get all connected peers. pub fn connected_peers(&self) -> Vec { - let sessions = self.sessions.sessions.read(); + let sessions = self.sessions.read(); let sessions = &*sessions; let mut peers = Vec::with_capacity(sessions.len()); @@ -1026,7 +656,7 @@ impl Host { let mut handshakes = 0; let mut egress = 0; let mut ingress = 0; - for s in self.sessions.sessions.read().iter() { + for s in self.sessions.read().iter() { match s.1.try_lock() { Some(ref s) if s.is_ready() && s.info.originated => egress += 1, Some(ref s) if s.is_ready() && !s.info.originated => ingress += 1, @@ -1036,29 +666,9 @@ impl Host { (handshakes, egress, ingress) } - // like session count, but does not block if read can not be achieved. - fn session_count_try(&self, lock_duration: Duration) -> Option<(usize, usize, usize)> { - let mut handshakes = 0; - let mut egress = 0; - let mut ingress = 0; - - if let Some(lock) = self.sessions.sessions.try_read_for(lock_duration) { - for s in lock.iter() { - match s.1.try_lock() { - Some(ref s) if s.is_ready() && s.info.originated => egress += 1, - Some(ref s) if s.is_ready() && !s.info.originated => ingress += 1, - _ => handshakes += 1, - } - } - return Some((handshakes, egress, ingress)); - } - - return None; - } - fn keep_alive(&self, io: &IoContext) { let mut to_kill = Vec::new(); - for e in self.sessions.sessions.read().iter() { + for e in self.sessions.read().iter() { let mut s = e.1.lock(); if !s.keep_alive(io) { s.disconnect(io, DisconnectReason::PingTimeout); @@ -1227,7 +837,7 @@ impl Host { } fn session_writable(&self, token: StreamToken, io: &IoContext) { - let session = { self.sessions.sessions.read().get(&token).cloned() }; + let session = { self.sessions.read().get(&token).cloned() }; if let Some(session) = session { let mut s = session.lock(); @@ -1250,7 +860,7 @@ impl Host { let mut ready_data: Vec = Vec::new(); let mut packet_data: Vec<(ProtocolId, PacketId, Vec)> = Vec::new(); let mut kill: Option = None; - let session = { self.sessions.sessions.read().get(&token).cloned() }; + let session = { self.sessions.read().get(&token).cloned() }; let mut ready_id = None; if let Some(session) = session.clone() { { @@ -1400,7 +1010,6 @@ impl Host { let handlers = self.handlers.read(); if !ready_data.is_empty() { let duplicates: Vec = self - .sessions .sessions .read() .iter() @@ -1556,7 +1165,7 @@ impl Host { // we can shorten the session read lock here, if this causes a deadlock. // on the other hand it is good, so not that many sessions manipulations can take place // at the same time. - let sessions = self.sessions.sessions.read(); + let sessions = self.sessions.read(); if let Some(session) = sessions.get(&token).cloned() { expired_session = Some(session.clone()); let mut s = session.lock(); @@ -1609,7 +1218,7 @@ impl Host { fn update_nodes(&self, _io: &IoContext, node_changes: TableUpdates) { let mut to_remove: Vec = Vec::new(); { - let sessions = self.sessions.sessions.read(); + let sessions = self.sessions.read(); for c in sessions.iter() { let s = c.1.lock(); if let Some(id) = s.id() { @@ -1828,7 +1437,7 @@ impl IoHandler for Host { .unwrap_or_else(|e| debug!("Error registering timer {}: {:?}", token, e)); } NetworkIoMessage::Disconnect(ref peer) => { - let session = { self.sessions.sessions.read().get(&*peer).cloned() }; + let session = { self.sessions.read().get(&*peer).cloned() }; if let Some(session) = session { session .lock() @@ -1838,7 +1447,7 @@ impl IoHandler for Host { self.kill_connection(*peer, io, false); } NetworkIoMessage::DisablePeer(ref peer) => { - let session = { self.sessions.sessions.read().get(&*peer).cloned() }; + let session = { self.sessions.read().get(&*peer).cloned() }; if let Some(session) = session { session .lock() @@ -1868,7 +1477,7 @@ impl IoHandler for Host { trace!(target: "network", "register_stream {}", stream); match stream { FIRST_SESSION.. => { - let session = { self.sessions.sessions.read().get(&stream).cloned() }; + let session = { self.sessions.read().get(&stream).cloned() }; if let Some(session) = session { session .lock() @@ -1903,7 +1512,7 @@ impl IoHandler for Host { ) { match stream { FIRST_SESSION.. => { - let mut connections = self.sessions.sessions.write(); + let mut connections = self.sessions.write(); if let Some(connection) = connections.get(&stream).cloned() { let c = connection.lock(); if c.expired() { @@ -1951,7 +1560,7 @@ impl IoHandler for Host { ) .expect("Error reregistering stream"), _ => { - let connection = { self.sessions.sessions.read().get(&&stream).cloned() }; + let connection = { self.sessions.read().get(&&stream).cloned() }; if let Some(connection) = connection { connection .lock() @@ -1965,10 +1574,10 @@ impl IoHandler for Host { impl PrometheusMetrics for Host { fn prometheus_metrics(&self, r: &mut PrometheusRegistry) { - let lockdur = Duration::from_millis(20); + let lockdur = Duration::from_millis(50); if let Some((handshakes, egress, ingress)) = - self.session_count_try(Duration::from_millis(20)) + self.sessions.session_count_try(Duration::from_millis(20)) { r.register_gauge("p2p_ingress", "count", ingress as i64); r.register_gauge("p2p_egress", "count", egress as i64); diff --git a/crates/net/network-devp2p/src/lib.rs b/crates/net/network-devp2p/src/lib.rs index 2a96a5850..d454a02c3 100644 --- a/crates/net/network-devp2p/src/lib.rs +++ b/crates/net/network-devp2p/src/lib.rs @@ -110,6 +110,7 @@ mod ip_utils; mod node_table; mod service; mod session; +mod session_container; pub use host::NetworkContext; pub use service::NetworkService; diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs new file mode 100644 index 000000000..2e41f8c83 --- /dev/null +++ b/crates/net/network-devp2p/src/session_container.rs @@ -0,0 +1,428 @@ +use crate::host::HostInfo; +use ethereum_types::H256; +use mio::net::TcpStream; +use std::{collections::BTreeMap, sync::Arc, time::Duration}; + +use crate::{io::*, node_table::*, session::Session}; +use network::{Error, ErrorKind, NetworkIoMessage, PeerId}; +use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard}; + +pub type SharedSession = Arc>; + +fn socket_address_to_string(socket: &TcpStream) -> String { + socket + .peer_addr() + .map_or("unknown".to_string(), |a| a.to_string()) +} + +pub struct SessionContainer { + max_sessions: usize, + sessions: Arc>>, + expired_sessions: Arc>>, + node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. + sessions_token_max: Mutex, // Used to generate new session tokens +} + +impl SessionContainer { + pub fn new(first_session_token: usize, max_sessions: usize) -> Self { + SessionContainer { + sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), + expired_sessions: Arc::new(RwLock::new(Vec::new())), + node_id_to_session: Mutex::new(BTreeMap::new()), + sessions_token_max: Mutex::new(first_session_token), + max_sessions, + } + } + + /// Returns a Read guard to the sessions. + pub fn read(&self) -> RwLockReadGuard> { + self.sessions.read() + } + + pub fn write(&self) -> RwLockWriteGuard> { + self.sessions.write() + } + + /// gets the next token ID and store this information + fn create_token_id( + &self, + node_id: &NodeId, + tokens: &mut BTreeMap, + ) -> usize { + let mut session_token_max = self.sessions_token_max.lock(); + let next_id = session_token_max.clone(); + + *session_token_max += 1; + + // TODO: if we run out of token ids, + // we need to recycle Ids that are not used anymore. + + if let Some(old) = tokens.insert(node_id.clone(), next_id) { + warn!(target: "network", "Node ID {} already exists with token {}, overwriting with {}", node_id, old, next_id); + } + + return next_id; + } + + fn create_token_id_for_handshake(&self) -> usize { + let mut session_token_max = self.sessions_token_max.lock(); + let next_id = session_token_max.clone(); + + *session_token_max += 1; + + // TODO: if we run out of token ids, + // we need to recycle Ids that are not used anymore. + + return next_id; + } + + // like session count, but does not block if read can not be achieved. + pub fn session_count_try(&self, lock_duration: Duration) -> Option<(usize, usize, usize)> { + let mut handshakes = 0; + let mut egress = 0; + let mut ingress = 0; + + let deadline = time_utils::DeadlineStopwatch::new(lock_duration); + + if let Some(lock) = self.sessions.try_read_for(deadline.time_left()) { + for s in lock.iter() { + match s.1.try_lock_for(deadline.time_left()) { + Some(ref s) => { + if s.is_ready() { + if s.info.originated { + egress += 1 + } else { + ingress += 1; + } + } else { + handshakes += 1; + } + } + + None => return None, + } + } + return Some((handshakes, egress, ingress)); + } + + return None; + } + + /// Creates a new session and adds it to the session container. + /// returns the token ID of the new session, or an Error if not successful. + pub fn create_connection( + &self, + socket: TcpStream, + id: Option<ðereum_types::H512>, + io: &IoContext, + nonce: &H256, + host: &HostInfo, + ) -> Result { + // make sure noone else is trying to modify the sessions at the same time. + // creating a connection is a very rare event. + + // always lock the node_id_to_session first, then the sessions. + let mut expired_session = self.expired_sessions.write(); + let mut node_ids = self.node_id_to_session.lock(); + let mut sessions = self.sessions.write(); + + if sessions.len() >= self.max_sessions { + return Err(ErrorKind::TooManyConnections.into()); + } + + if let Some(node_id) = id { + // check if there is already a connection for the given node id. + if let Some(existing_peer_id) = node_ids.get(node_id) { + let existing_session_mutex_o = sessions.get(existing_peer_id).clone(); + + if let Some(existing_session_mutex) = existing_session_mutex_o { + let session_expired = { + let session = existing_session_mutex.lock(); + if let Some(id_from_session) = &session.info.id { + if session.info.id == Some(*node_id) { + // we got already got a session for the specified node. + // maybe the old session is already scheduled for getting deleted. + session.expired() + } else { + error!(target: "network", "host cache inconsistency: Session node id missmatch. expected: {} is {}.", existing_peer_id, id_from_session); + return Err(ErrorKind::HostCacheInconsistency.into()); + } + } else { + error!(target: "network", "host cache inconsistency: Session has no Node_id defined where it should for {}", existing_peer_id); + return Err(ErrorKind::HostCacheInconsistency.into()); + } + }; // session guard is dropped here + + if session_expired { + debug!(target: "network", "Creating new session for expired {} token: {} node id: {:?}", socket_address_to_string(&socket), existing_peer_id, id); + // if the session is expired, we will just create n new session for this node. + let new_session = + Session::new(io, socket, existing_peer_id.clone(), id, nonce, host); + match new_session { + Ok(session) => { + let new_session_arc = Arc::new(Mutex::new(session)); + let old_session_o = + sessions.insert(*existing_peer_id, new_session_arc); + + match old_session_o { + Some(old) => { + // we remember the expired session, so it can get closed and cleaned up in a nice way later. + expired_session.push(old); + } + None => { + // we have a cache missmatch. + // but the only thing is missing is a clean ending of the old session. + // nothing mission critical. + error!(target: "network", "host cache inconsistency: Session for node id {} was not found in sessions map, but it should be there.", node_id); + } + } + + // in this context, the stream might already be unregistered ?! + // we can just register the stream again. + if let Err(err) = io.register_stream(*existing_peer_id) { + // todo: research this topic, watch out for this message, + // maybe we can keep track of stream registrations as well somehow. + debug!(target: "network", "Failed to register stream for token: {} : {}", existing_peer_id, err); + } + + return Ok(*existing_peer_id); + } + Err(e) => { + error!(target: "network", "Failed to create session for node id: {}", node_id); + return Err(e); + } + } + } else { + // this might happen if 2 nodes try to connect to each other at the same time. + debug!(target: "network", "Session already exists for node id: {}", node_id); + return Err(ErrorKind::AlreadyExists.into()); + } + } else { + debug!(target: "network", "reusing peer ID {} for node: {}", existing_peer_id, node_id); + // we have a node id, but there is no session for it (anymore) + // we reuse that peer_id, so other in flight actions are pointing to the same node again. + match Session::new(io, socket, existing_peer_id.clone(), id, nonce, host) { + Ok(new_session) => { + sessions.insert( + existing_peer_id.clone(), + Arc::new(Mutex::new(new_session)), + ); + if let Err(err) = io.register_stream(existing_peer_id.clone()) { + warn!(target: "network", "Failed to register stream for reused token: {} : {}", existing_peer_id, err); + } + return Ok(existing_peer_id.clone()); + } + Err(err) => { + debug!(target: "network", "reusing peer ID {} for node: {}, but could not create session", existing_peer_id, node_id); + return Err(err); + } + } + } + } else { + // this should be the most common scenario. + // we have a new node id, we were either never connected to, or we forgot about it. + + let next_free_token = self.create_token_id(&node_id, &mut node_ids); + trace!(target: "network", "Creating new session {} for new node id:{} with token {}", socket_address_to_string(&socket), node_id, next_free_token); + let new_session = + Session::new(io, socket, next_free_token.clone(), id, nonce, host); + // the token is already registerd. + match new_session { + Ok(session) => { + let session = Arc::new(Mutex::new(session)); + sessions.insert(next_free_token, session.clone()); + // register the stream for the new session. + if let Err(err) = io.register_stream(next_free_token) { + debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); + } + node_ids.insert(node_id.clone(), next_free_token); + + return Ok(next_free_token); + } + Err(e) => { + error!(target: "network", "Failed to create session for node id: {}", node_id); + return Err(e); + } + } + } + } else { + let next_free_token = self.create_token_id_for_handshake(); + + trace!(target: "network", "creating session for handshaking peer: {} token: {}", socket_address_to_string(&socket), next_free_token); + // we dont know the NodeID, + // we still need a session to do the handshake. + + let new_session = Session::new(io, socket, next_free_token.clone(), id, nonce, host); + // the token is already registerd. + match new_session { + Ok(session) => { + let session = Arc::new(Mutex::new(session)); + sessions.insert(next_free_token, session.clone()); + // register the stream for the new session. + if let Err(err) = io.register_stream(next_free_token) { + debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); + } + //node_ids.insert(node_id.clone(), next_free_token); + + return Ok(next_free_token); + } + Err(e) => { + error!(target: "network", "Failed to create handshake session for: {}", next_free_token); + return Err(e); + } + } + } + // if we dont know a NodeID + // debug!(target: "network", "Session create error: {:?}", e); + } + + pub fn get_session_for(&self, id: &NodeId) -> Option { + self.node_id_to_session + .lock() + .get(id) + .cloned() + .map_or(None, |peer_id| { + let sessions = self.sessions.read(); + sessions.get(&peer_id).cloned() + }) + } + + pub fn node_id_to_peer_id( + &self, + node_id: &NodeId, + only_available_sessions: bool, + ) -> Option { + self.node_id_to_session + .lock() + .get(node_id) + .map_or(None, |peer_id| { + if !only_available_sessions { + return Some(*peer_id); + } + let sessions = self.sessions.read(); + + // we can do additional checks: + // we could ensure that the Node ID matches. + // we could also read the flag and check if it is not marked for + // getting disconnected. + + if sessions.contains_key(peer_id) { + return Some(*peer_id); + } + + return None; + }) + } + + pub fn register_finalized_handshake(&self, token: usize, id: Option<ðereum_types::H512>) { + let node_id = match id { + Some(id) => id.clone(), + None => { + error!(target: "network", "Tried to register finalized handshake without node id"); + // we have no node id, so we can not register it. + return; + } + }; + + // register this session. + if let Some(old) = self.node_id_to_session.lock().insert(node_id, token) { + // in scenarios where we did have registered the session to this node, + // the token id wont change. + // but still we need a lock to node_id_to_session anyway. + if old != token { + debug!(target: "network", "handshake completed: changed primary session for node id {} from {} to {}", node_id, token, old); + } + } else { + debug!(target: "network", "handshake completed: node id {} registered primary session token {}", node_id, token); + } + } + + // handles duplicated sessions and desides wich one to be deleted. a duplicated session if it exists in a deterministic way, so both sides agree on the same session to keep. + // returns if this session is marked for deletion, and not being accepted by the SessionContainer. + // see: https://github.com/DMDcoin/diamond-node/issues/252 + pub fn should_delete_duplicate_session(&self, session: &SharedSession) -> Option { + let mut node_id = NodeId::zero(); + let mut peer_id = PeerId::default(); + let mut uid: H256 = H256::zero(); + + { + let lock = session.lock(); + peer_id = lock.token().clone(); + + node_id = match lock.id() { + Some(id) => id.clone(), + None => { + // based on the control flow of the software, this should never happen. + warn!(target: "network", "Tried to delete duplicate session without node id"); + return None; // we have no node id, so we can not delete it. + } + }; + + uid = match lock.info.session_uid { + Some(u) => u.clone(), + None => { + // based on the control flow of the software, this should never happen. + warn!(target: "network", "Tried to delete duplicate session without session uid"); + return None; // we have no session uid, so we can not delete it. + } + }; + }; + + if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { + if existing_peer_id != peer_id { + // there may be an active session for this peer id. + let existing_session = self.get_session_for(&node_id); + if let Some(existing_session_mutex) = existing_session { + let existing_lock = existing_session_mutex.lock(); + if existing_lock.expired() { + // other session is already about to get deleted. + trace!(target:"network", "existing peer session {existing_peer_id} is already about to get deleted."); + return None; + } + if let Some(existing_uid) = existing_lock.info.session_uid { + // the highest RNG wins. + if existing_uid.lt(&uid) { + // we keep the existing session, and delete the new one. + trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} for {node_id}, deleting this session"); + // we savely mark this connection to get killed softly. + return Some(peer_id); + } else { + trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} for {node_id}, deleting duplicated session"); + // and delete the existing one. + return Some(existing_peer_id); + } + } + } else { + trace!(target: "network", "No session active for {node_id} with peer id {existing_peer_id}"); + // todo: make sure the mapping is rewritten. + } + + trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} {node_id}"); + return Some(existing_peer_id); + } + } else { + trace!(target: "network", "No session known for {node_id}"); + } + + return None; + } + + // makes a shallow search if there is already a session for that connection + fn is_duplicate(&self, session: &SharedSession) -> bool { + let (id, token) = { + let lock = session.lock(); + (lock.id().cloned(), lock.token().clone()) + }; + + if let Some(node_id) = id { + if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { + if existing_peer_id != token { + trace!(target: "network", "Session {token} has a duplicate :{existing_peer_id} {node_id}"); + return true; + } + } + } // else we dont have enough information to make a decision. + + return false; + } +} From 809d80d621ed47dcf01ba762d94defccad0089e6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Jul 2025 17:41:56 +0200 Subject: [PATCH 576/687] session container warning fixes --- crates/net/network-devp2p/src/session_container.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 2e41f8c83..f7c1cb749 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -341,15 +341,13 @@ impl SessionContainer { // returns if this session is marked for deletion, and not being accepted by the SessionContainer. // see: https://github.com/DMDcoin/diamond-node/issues/252 pub fn should_delete_duplicate_session(&self, session: &SharedSession) -> Option { - let mut node_id = NodeId::zero(); - let mut peer_id = PeerId::default(); - let mut uid: H256 = H256::zero(); + let (node_id, peer_id, uid) = { let lock = session.lock(); - peer_id = lock.token().clone(); + let peer_id = lock.token().clone(); - node_id = match lock.id() { + let node_id = match lock.id() { Some(id) => id.clone(), None => { // based on the control flow of the software, this should never happen. @@ -358,7 +356,7 @@ impl SessionContainer { } }; - uid = match lock.info.session_uid { + let uid = match lock.info.session_uid { Some(u) => u.clone(), None => { // based on the control flow of the software, this should never happen. @@ -366,6 +364,8 @@ impl SessionContainer { return None; // we have no session uid, so we can not delete it. } }; + + (node_id, peer_id, uid) }; if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { From e9f669573031f144e1162c620f1ad4c1322542db Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 14 Jul 2025 17:43:18 +0200 Subject: [PATCH 577/687] removed is_duplicate from session container --- .../network-devp2p/src/session_container.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index f7c1cb749..d3f57a0ec 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -406,23 +406,4 @@ impl SessionContainer { return None; } - - // makes a shallow search if there is already a session for that connection - fn is_duplicate(&self, session: &SharedSession) -> bool { - let (id, token) = { - let lock = session.lock(); - (lock.id().cloned(), lock.token().clone()) - }; - - if let Some(node_id) = id { - if let Some(existing_peer_id) = self.node_id_to_peer_id(&node_id, true) { - if existing_peer_id != token { - trace!(target: "network", "Session {token} has a duplicate :{existing_peer_id} {node_id}"); - return true; - } - } - } // else we dont have enough information to make a decision. - - return false; - } } From f7107e930b0581a89906af52531c3a84bb92836d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 15 Jul 2025 14:37:21 +0200 Subject: [PATCH 578/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/net/network-devp2p/src/session_container.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index d3f57a0ec..c49973d9e 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -341,9 +341,7 @@ impl SessionContainer { // returns if this session is marked for deletion, and not being accepted by the SessionContainer. // see: https://github.com/DMDcoin/diamond-node/issues/252 pub fn should_delete_duplicate_session(&self, session: &SharedSession) -> Option { - - let (node_id, peer_id, uid) = - { + let (node_id, peer_id, uid) = { let lock = session.lock(); let peer_id = lock.token().clone(); From b58cf0a635b0e40f446e15f476ce34179c2f85bc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jul 2025 14:53:45 +0200 Subject: [PATCH 579/687] io trace logging for dev builds by default. --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index e4e7c8e0f..ffe79c932 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -258,7 +258,7 @@ fn to_toml( misc.insert( "logging".into(), Value::String( - logging.unwrap_or("txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace,sync=trace,network=trace") + logging.unwrap_or("txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace,sync=trace,network=trace,io=trace") .into(), ), ); From ed45cf2d823e962e1fb81b11e68b05e15fa178d1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jul 2025 14:56:30 +0200 Subject: [PATCH 580/687] improved Error handling for Notify Error. --- crates/runtime/io/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/runtime/io/src/lib.rs b/crates/runtime/io/src/lib.rs index 842286665..0c155b2d0 100644 --- a/crates/runtime/io/src/lib.rs +++ b/crates/runtime/io/src/lib.rs @@ -141,10 +141,10 @@ impl From>> for IoError where Message: Send, { - fn from(_err: NotifyError>) -> IoError { + fn from(err: NotifyError>) -> IoError { IoError::Mio(::std::io::Error::new( ::std::io::ErrorKind::ConnectionAborted, - "Network IO notification error", + format!("Network IO notification error {}", err), )) } } From ee436fd908294c70e50df8148baf0a52a3ca0a21 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jul 2025 14:57:34 +0200 Subject: [PATCH 581/687] Improved Error Handling for mio cases: missing Timer, missing Handler --- crates/runtime/io/src/service_mio.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/runtime/io/src/service_mio.rs b/crates/runtime/io/src/service_mio.rs index ee7a726a9..caaa2d688 100644 --- a/crates/runtime/io/src/service_mio.rs +++ b/crates/runtime/io/src/service_mio.rs @@ -305,7 +305,11 @@ where handler_id: handler_index, }); self.work_ready.notify_all(); + } else { + debug!(target: "io", "No timer available for token {}. handlerID {handler_index}, subtoken {token_id}", token.0); } + } else { + debug!(target: "io", "No handler for token {} registererd. handlerID {handler_index}, subtoken {token_id}", token.0); } } @@ -346,6 +350,7 @@ where delay, once, } => { + trace!(target: "io", "Registering timer: handler_id={}, token={}, delay={:?}, once={}", handler_id, token, delay, once); let timer_id = token + handler_id * TOKENS_PER_HANDLER; let timeout = event_loop .timeout(Token(timer_id), delay) From 75a1a8dd59b3ab6f9564e5c8e06a099763f2d815 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jul 2025 14:59:51 +0200 Subject: [PATCH 582/687] New Timer & Peer IDs for Host: Id: 1 - 7: Host Systems. id: 8 - 99: User Timers (Hope thats enough) Id: 100+ : DevP2P Session Peers --- crates/net/network-devp2p/src/host.rs | 54 +++++++++++++++---- .../network-devp2p/src/session_container.rs | 15 +++--- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index af309716a..395971f09 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -70,9 +70,23 @@ const DISCOVERY_REFRESH: TimerToken = 4; const FAST_DISCOVERY_REFRESH: TimerToken = 5; const DISCOVERY_ROUND: TimerToken = 6; const NODE_TABLE: TimerToken = 7; -const USER_TIMER: TimerToken = 8; -const FIRST_SESSION: StreamToken = 9; +// Maximum count of peer mappings we remember. each node ID takes 64 bytes for nodeID, 8 bytes for peer id, and probabyl 3 * 8 bytes for internals. = about 100 bytes per entry.) +// 10000 elements should take about 1 MB of memory. +const MAX_NODE_TO_PEER_MAPPINGS: usize = 10000; + +// the user timers are a collection of timers that are registered by the protocol handlers. +// therefore comming from other modules. +// to be not in conflict with the token ID system, we choose a very +// high number for the user timers, +// that is realisticly unreachable by the peer stream tokens, +// but still have enough number space for user timers. +const FIRST_USER_TIMER: TimerToken = 8; +const MAX_USER_TIMERS: TimerToken = 91; +const LAST_USER_TIMER: TimerToken = FIRST_USER_TIMER + MAX_USER_TIMERS; + +const FIRST_SESSION: StreamToken = LAST_USER_TIMER + 1; +const LAST_SESSION: StreamToken = StreamToken::MAX; // Timeouts // for IDLE TimerToken @@ -423,11 +437,11 @@ impl Host { discovery: Mutex::new(None), udp_socket: Mutex::new(None), tcp_listener: Mutex::new(tcp_listener), - sessions: SessionContainer::new(FIRST_SESSION, MAX_SESSIONS), + sessions: SessionContainer::new(FIRST_SESSION, MAX_SESSIONS, MAX_NODE_TO_PEER_MAPPINGS), nodes: RwLock::new(NodeTable::new(path)), handlers: RwLock::new(HashMap::new()), timers: RwLock::new(HashMap::new()), - timer_counter: RwLock::new(USER_TIMER), + timer_counter: RwLock::new(FIRST_USER_TIMER), reserved_nodes: RwLock::new(HashSet::new()), stopping: AtomicBool::new(false), filter, @@ -1299,7 +1313,7 @@ impl IoHandler for Host { return; } match stream { - FIRST_SESSION.. => self.session_readable(stream, io), + FIRST_SESSION..LAST_SESSION => self.session_readable(stream, io), DISCOVERY => self.discovery_readable(io), TCP_ACCEPT => self.accept(io), _ => panic!("Received unknown readable token"), @@ -1311,22 +1325,20 @@ impl IoHandler for Host { return; } match stream { - FIRST_SESSION.. => self.session_writable(stream, io), + FIRST_SESSION..=LAST_SESSION => self.session_writable(stream, io), DISCOVERY => self.discovery_writable(io), _ => panic!("Received unknown writable token"), } } fn timeout(&self, io: &IoContext, token: TimerToken) { + trace!(target: "network", "HOST timout: {}", token); if self.stopping.load(AtomicOrdering::SeqCst) { return; } match token { IDLE => self.maintain_network(io), - FIRST_SESSION.. => { - trace!(target: "network", "Timeout from Host impl: {}", token); - self.connection_timeout(token, io); - } + DISCOVERY_REFRESH => { // Run the _slow_ discovery if enough peers are connected if !self.has_enough_peers() { @@ -1356,7 +1368,7 @@ impl IoHandler for Host { nodes.clear_useless(); nodes.save(); } - _ => match self.timers.read().get(&token).cloned() { + FIRST_USER_TIMER..=LAST_USER_TIMER => match self.timers.read().get(&token).cloned() { Some(timer) => match self.handlers.read().get(&timer.protocol).cloned() { None => { warn!(target: "network", "No handler found for protocol: {:?}", timer.protocol) @@ -1380,6 +1392,13 @@ impl IoHandler for Host { warn!("Unknown timer token: {}", token); } // timer is not registerd through us }, + FIRST_SESSION..=LAST_SESSION => { + trace!(target: "network", "Timeout from Host impl: {}", token); + self.connection_timeout(token, io); + } + _ => { + warn!(target: "network", "HOST: Unknown timer token tick: {}", token); + } } } @@ -1419,6 +1438,12 @@ impl IoHandler for Host { ref token, } => { trace!(target: "network", "Adding timer for protocol: {:?}, delay: {:?}, token: {}", protocol, delay.as_millis(), token); + + if token >= &MAX_USER_TIMERS { + warn!(target: "network", "Tried to register timer with token {} which is larger than MAX_USER_TIMERS {}", token, MAX_USER_TIMERS); + return; + } + let handler_token = { let mut timer_counter = self.timer_counter.write(); let counter = &mut *timer_counter; @@ -1426,6 +1451,11 @@ impl IoHandler for Host { *counter += 1; handler_token }; + + if handler_token > LAST_USER_TIMER { + warn!(target: "network", "Tried to register timer witch Index {token} what would be over the boundaries of usertimers: {LAST_USER_TIMER}"); + return; + } self.timers.write().insert( handler_token, ProtocolTimer { @@ -1433,6 +1463,8 @@ impl IoHandler for Host { token: *token, }, ); + + trace!(target: "network", "Registering handler_token {} token {} for protocol {:?} with delay {:?}", handler_token, token, protocol, delay); io.register_timer(handler_token, *delay) .unwrap_or_else(|e| debug!("Error registering timer {}: {:?}", token, e)); } diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index c49973d9e..5598e25ab 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -1,5 +1,6 @@ use crate::host::HostInfo; use ethereum_types::H256; +use lru_cache::LruCache; use mio::net::TcpStream; use std::{collections::BTreeMap, sync::Arc, time::Duration}; @@ -19,16 +20,16 @@ pub struct SessionContainer { max_sessions: usize, sessions: Arc>>, expired_sessions: Arc>>, - node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. + node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. sessions_token_max: Mutex, // Used to generate new session tokens } impl SessionContainer { - pub fn new(first_session_token: usize, max_sessions: usize) -> Self { + pub fn new(first_session_token: usize, max_sessions: usize, max_node_mappings: usize) -> Self { SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), expired_sessions: Arc::new(RwLock::new(Vec::new())), - node_id_to_session: Mutex::new(BTreeMap::new()), + node_id_to_session: Mutex::new(LruCache::new(max_node_mappings)), sessions_token_max: Mutex::new(first_session_token), max_sessions, } @@ -47,7 +48,7 @@ impl SessionContainer { fn create_token_id( &self, node_id: &NodeId, - tokens: &mut BTreeMap, + tokens: &mut LruCache, ) -> usize { let mut session_token_max = self.sessions_token_max.lock(); let next_id = session_token_max.clone(); @@ -132,7 +133,7 @@ impl SessionContainer { if let Some(node_id) = id { // check if there is already a connection for the given node id. - if let Some(existing_peer_id) = node_ids.get(node_id) { + if let Some(existing_peer_id) = node_ids.get_mut(node_id) { let existing_session_mutex_o = sessions.get(existing_peer_id).clone(); if let Some(existing_session_mutex) = existing_session_mutex_o { @@ -279,7 +280,7 @@ impl SessionContainer { pub fn get_session_for(&self, id: &NodeId) -> Option { self.node_id_to_session .lock() - .get(id) + .get_mut(id) .cloned() .map_or(None, |peer_id| { let sessions = self.sessions.read(); @@ -294,7 +295,7 @@ impl SessionContainer { ) -> Option { self.node_id_to_session .lock() - .get(node_id) + .get_mut(node_id) .map_or(None, |peer_id| { if !only_available_sessions { return Some(*peer_id); From 1de13bb7eb78b31bf75eda5aa98f631f15d30948 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jul 2025 15:47:29 +0200 Subject: [PATCH 583/687] fixed possible integer underflow in calc_cumulative_lateness_gap --- .../engines/hbbft/hbbft_message_memorium.rs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index de476a556..89c4e4cde 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -110,18 +110,27 @@ impl NodeStakingEpochHistory { || self.last_good_sealing_message + 1 < block_num || self.last_error_sealing_message + 1 < block_num { - let difference = block_num - - 1 - - u64::max( + + let latest_message = + u64::max( + u64::max( u64::max( - u64::max( - self.last_late_sealing_message, - staking_epoch_start_block_num, - ), - self.last_good_sealing_message, + self.last_late_sealing_message, + staking_epoch_start_block_num, ), - self.last_error_sealing_message, - ); + self.last_good_sealing_message, + ), + self.last_error_sealing_message, + ); + + if (latest_message + 1) > block_num { + return 0; + } + + let difference = block_num + - 1 + - latest_message; + return (difference * (difference + 1)) / 2; } return 0; From f1ddfb8e7411f82b6e7c70377e4bad5d4c3c7904 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jul 2025 15:50:54 +0200 Subject: [PATCH 584/687] architecture improvement: SessionContainer does not allow to obtain a write lock. The last reason that required a Write lock was deregistering a stream for a session and removing that Session from the Session list. --- crates/net/network-devp2p/src/host.rs | 11 +---------- .../network-devp2p/src/session_container.rs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 395971f09..a1fb34805 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -1544,16 +1544,7 @@ impl IoHandler for Host { ) { match stream { FIRST_SESSION.. => { - let mut connections = self.sessions.write(); - if let Some(connection) = connections.get(&stream).cloned() { - let c = connection.lock(); - if c.expired() { - // make sure it is the same connection that the event was generated for - c.deregister_socket(event_loop) - .expect("Error deregistering socket"); - connections.remove(&stream); - } - } + self.sessions.deregister_session_stream(stream, event_loop); } DISCOVERY => (), _ => warn!("Unexpected stream deregistration"), diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 5598e25ab..0769806a4 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -40,10 +40,6 @@ impl SessionContainer { self.sessions.read() } - pub fn write(&self) -> RwLockWriteGuard> { - self.sessions.write() - } - /// gets the next token ID and store this information fn create_token_id( &self, @@ -405,4 +401,18 @@ impl SessionContainer { return None; } + + pub(crate) fn deregister_session_stream(&self, stream: usize, event_loop: &mut mio::deprecated::EventLoop) { + + let mut connections = self.sessions.write(); + if let Some(connection) = connections.get(&stream).cloned() { + let c = connection.lock(); + if c.expired() { + // make sure it is the same connection that the event was generated for + c.deregister_socket(event_loop) + .expect("Error deregistering socket"); + connections.remove(&stream); + } + } + } } From 7ef89c20ec7b230bf6e9c56da5a2e1b7d773fb64 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jul 2025 15:52:14 +0200 Subject: [PATCH 585/687] cargo fmt --all -- --config imports_granularity=Crate --- .../ethcore/src/engines/hbbft/hbbft_message_memorium.rs | 8 ++------ crates/net/network-devp2p/src/session_container.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs index 89c4e4cde..235b13a48 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs @@ -110,9 +110,7 @@ impl NodeStakingEpochHistory { || self.last_good_sealing_message + 1 < block_num || self.last_error_sealing_message + 1 < block_num { - - let latest_message = - u64::max( + let latest_message = u64::max( u64::max( u64::max( self.last_late_sealing_message, @@ -127,9 +125,7 @@ impl NodeStakingEpochHistory { return 0; } - let difference = block_num - - 1 - - latest_message; + let difference = block_num - 1 - latest_message; return (difference * (difference + 1)) / 2; } diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 0769806a4..02d07547b 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -401,9 +401,12 @@ impl SessionContainer { return None; } - - pub(crate) fn deregister_session_stream(&self, stream: usize, event_loop: &mut mio::deprecated::EventLoop) { - + + pub(crate) fn deregister_session_stream( + &self, + stream: usize, + event_loop: &mut mio::deprecated::EventLoop, + ) { let mut connections = self.sessions.write(); if let Some(connection) = connections.get(&stream).cloned() { let c = connection.lock(); From fb482342dd9010ca185ffb79bba11bd7bcfdbe2c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jul 2025 16:04:40 +0200 Subject: [PATCH 586/687] logging: parse errors: -> unparsable --- crates/ethcore/sync/src/chain/supplier.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/supplier.rs b/crates/ethcore/sync/src/chain/supplier.rs index 01e90205c..288cdd84a 100644 --- a/crates/ethcore/sync/src/chain/supplier.rs +++ b/crates/ethcore/sync/src/chain/supplier.rs @@ -349,7 +349,7 @@ impl SyncSupplier { } rlp.finalize_unbounded_list(); - debug!(target: "sync", "{} -> GetPooledTransactions: returned {} entries. Not found: {}. parse errors: {}", peer_id, added, not_found, parse_errors); + debug!(target: "sync", "{} -> GetPooledTransactions: returned {} entries. Not found: {}. unparsable {}", peer_id, added, not_found, parse_errors); Ok(Some((PooledTransactionsPacket, rlp))) } From d82bc0a405f529a214dc8c6f989e2e8a539df2da Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jul 2025 16:26:20 +0200 Subject: [PATCH 587/687] unused import --- crates/net/network-devp2p/src/session_container.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 02d07547b..af3b8d3ca 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -6,7 +6,7 @@ use std::{collections::BTreeMap, sync::Arc, time::Duration}; use crate::{io::*, node_table::*, session::Session}; use network::{Error, ErrorKind, NetworkIoMessage, PeerId}; -use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard}; +use parking_lot::{Mutex, RwLock, RwLockReadGuard}; pub type SharedSession = Arc>; From 2f3f77b3737450ead7714d204e0937d6582adf55 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jul 2025 15:59:24 +0200 Subject: [PATCH 588/687] handler_index typo --- crates/runtime/io/src/service_mio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/runtime/io/src/service_mio.rs b/crates/runtime/io/src/service_mio.rs index caaa2d688..7b5d1af90 100644 --- a/crates/runtime/io/src/service_mio.rs +++ b/crates/runtime/io/src/service_mio.rs @@ -306,10 +306,10 @@ where }); self.work_ready.notify_all(); } else { - debug!(target: "io", "No timer available for token {}. handlerID {handler_index}, subtoken {token_id}", token.0); + debug!(target: "io", "No timer available for token {}. handler_index {handler_index}, subtoken {token_id}", token.0); } } else { - debug!(target: "io", "No handler for token {} registererd. handlerID {handler_index}, subtoken {token_id}", token.0); + debug!(target: "io", "No handler for token {} registererd. handler_index {handler_index}, subtoken {token_id}", token.0); } } From 8230f2ca06c77db54d1e0e612a8cdf5f0c3c1931 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jul 2025 16:02:59 +0200 Subject: [PATCH 589/687] various typos in comments --- crates/ethcore/sync/src/chain/propagator.rs | 2 +- crates/net/network-devp2p/src/session_container.rs | 6 +++--- crates/net/network/src/error.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index ac3606de1..14661cbf2 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -385,7 +385,7 @@ impl ChainSync { let peers = self.get_consensus_peers(); trace!(target: "sync", "Sending proposed blocks to {:?}", peers); for block in proposed { - // todo: sometimes we get at the receiving end blocks, with missmatching total difficulty, + // todo: sometimes we get at the receiving end blocks, with mismatching total difficulty, // so we ignore those blocks on import. // might that be the case if we are sending more than 1 block here ? // more about: https://github.com/DMDcoin/diamond-node/issues/61 diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index af3b8d3ca..81a67d103 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -141,7 +141,7 @@ impl SessionContainer { // maybe the old session is already scheduled for getting deleted. session.expired() } else { - error!(target: "network", "host cache inconsistency: Session node id missmatch. expected: {} is {}.", existing_peer_id, id_from_session); + error!(target: "network", "host cache inconsistency: Session node id mismatch. expected: {} is {}.", existing_peer_id, id_from_session); return Err(ErrorKind::HostCacheInconsistency.into()); } } else { @@ -167,9 +167,9 @@ impl SessionContainer { expired_session.push(old); } None => { - // we have a cache missmatch. + // we have a cache mismatch. // but the only thing is missing is a clean ending of the old session. - // nothing mission critical. + // nothing mission-critical. error!(target: "network", "host cache inconsistency: Session for node id {} was not found in sessions map, but it should be there.", node_id); } } diff --git a/crates/net/network/src/error.rs b/crates/net/network/src/error.rs index 50e880019..b46076316 100644 --- a/crates/net/network/src/error.rs +++ b/crates/net/network/src/error.rs @@ -172,10 +172,10 @@ error_chain! { display("The hardcoded maximum number of connections has been reached on this host."), } - #[doc = "A connection to the specified NodeId exists, but there is a missmatch in the host cache."] + #[doc = "A connection to the specified NodeId exists, but there is a mismatch in the host cache."] HostCacheInconsistency { description("A connection to the specified nodeId already exists."), - display("A connection to the specified NodeId exists, but there is a missmatch in the host cache."), + display("A connection to the specified NodeId exists, but there is a mismatch in the host cache."), } #[doc = "An unknown IO error occurred."] From 72f675b16cc4691c86afd5ee0799d6b379ad88ec Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 23 Jul 2025 17:59:22 +0200 Subject: [PATCH 590/687] Separate Handshakes and Encrypted Connections. Handshakes use now Slot 100 - 199, while encrypted connections start with slot 200. WIP checkin, still needs some fixes. --- crates/ethcore/sync/src/api.rs | 3 - crates/net/network-devp2p/src/handshake.rs | 1 + crates/net/network-devp2p/src/host.rs | 145 +++++++++---- crates/net/network-devp2p/src/session.rs | 10 + .../network-devp2p/src/session_container.rs | 194 ++++++++++++++---- 5 files changed, 277 insertions(+), 76 deletions(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 83c4f9ec5..fcdb0b4aa 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -625,9 +625,6 @@ impl NetworkProtocolHandler for SyncProtocolHandler { fn timeout(&self, nc: &dyn NetworkContext, timer: TimerToken) { trace_time!("sync::timeout"); - trace!(target: "sync", "Timer {} triggered.", timer); - // timer 2: - // Timer 0 triggered. let mut io = NetSyncIo::new(nc, &*self.chain, &*self.snapshot_service, &self.overlay); match timer { PEERS_TIMER => self.sync.write().maintain_peers(&mut io), diff --git a/crates/net/network-devp2p/src/handshake.rs b/crates/net/network-devp2p/src/handshake.rs index dd6b3c0dd..5ec866109 100644 --- a/crates/net/network-devp2p/src/handshake.rs +++ b/crates/net/network-devp2p/src/handshake.rs @@ -273,6 +273,7 @@ impl Handshake { self.remote_ephemeral = Public::from_slice(&ack[0..64]); self.remote_nonce = H256::from_slice(&ack[64..(64 + 32)]); self.state = HandshakeState::StartSession; + trace!(target: "network", "handshake completed for from {:?}", self.connection.remote_addr_str()); } Err(_) => { // Try to interpret as EIP-8 packet diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index a1fb34805..0dc81fb84 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -16,6 +16,7 @@ use crate::{ mio::{deprecated::EventLoop, tcp::*, udp::*, *}, + session, session_container::{SessionContainer, SharedSession}, }; use crypto::publickey::{Generator, KeyPair, Random, Secret}; @@ -57,7 +58,7 @@ use parking_lot::{Mutex, RwLock}; use stats::{PrometheusMetrics, PrometheusRegistry}; const MAX_SESSIONS: usize = 2048 + MAX_HANDSHAKES; -const MAX_HANDSHAKES: usize = 1024; +const MAX_HANDSHAKES: usize = 99; const DEFAULT_PORT: u16 = 30303; @@ -85,7 +86,9 @@ const FIRST_USER_TIMER: TimerToken = 8; const MAX_USER_TIMERS: TimerToken = 91; const LAST_USER_TIMER: TimerToken = FIRST_USER_TIMER + MAX_USER_TIMERS; -const FIRST_SESSION: StreamToken = LAST_USER_TIMER + 1; +const FIRST_HANDSHAKE: StreamToken = LAST_USER_TIMER + 1; +const LAST_HANDSHAKE: StreamToken = FIRST_HANDSHAKE + MAX_HANDSHAKES; +const FIRST_SESSION: StreamToken = FIRST_HANDSHAKE + MAX_HANDSHAKES + 1; const LAST_SESSION: StreamToken = StreamToken::MAX; // Timeouts @@ -195,7 +198,13 @@ impl<'s> NetworkContext<'s> { fn resolve_session(&self, peer: PeerId) -> Option { match self.session_id { Some(id) if id == peer => self.session.clone(), - _ => self.sessions.read().get(&peer).cloned(), + _ => { + if peer >= FIRST_SESSION { + self.sessions.get_session(peer) + } else { + self.sessions.get_session(peer) + } + } } } } @@ -367,6 +376,7 @@ pub struct Host { pub info: RwLock, udp_socket: Mutex>, tcp_listener: Mutex, + handshake_lock: Mutex<()>, sessions: SessionContainer, discovery: Mutex>>, nodes: RwLock, @@ -437,7 +447,13 @@ impl Host { discovery: Mutex::new(None), udp_socket: Mutex::new(None), tcp_listener: Mutex::new(tcp_listener), - sessions: SessionContainer::new(FIRST_SESSION, MAX_SESSIONS, MAX_NODE_TO_PEER_MAPPINGS), + sessions: SessionContainer::new( + FIRST_HANDSHAKE, + MAX_SESSIONS, + MAX_NODE_TO_PEER_MAPPINGS, + MAX_HANDSHAKES, + ), + handshake_lock: Mutex::new(()), nodes: RwLock::new(NodeTable::new(path)), handlers: RwLock::new(HashMap::new()), timers: RwLock::new(HashMap::new()), @@ -559,6 +575,13 @@ impl Host { s.disconnect(io, DisconnectReason::ClientQuit); to_kill.push(s.token()); } + + for e in self.sessions.read_handshakes().iter() { + let mut s = e.1.lock(); + s.disconnect(io, DisconnectReason::ClientQuit); + to_kill.push(s.token()); + } + for p in to_kill { trace!(target: "network", "Disconnecting on shutdown: {}", p); self.kill_connection(p, io, true); @@ -667,17 +690,7 @@ impl Host { // returns (handshakes, egress, ingress) fn session_count(&self) -> (usize, usize, usize) { - let mut handshakes = 0; - let mut egress = 0; - let mut ingress = 0; - for s in self.sessions.read().iter() { - match s.1.try_lock() { - Some(ref s) if s.is_ready() && s.info.originated => egress += 1, - Some(ref s) if s.is_ready() && !s.info.originated => ingress += 1, - _ => handshakes += 1, - } - } - (handshakes, egress, ingress) + self.sessions.session_count() } fn keep_alive(&self, io: &IoContext) { @@ -708,6 +721,9 @@ impl Host { } fn connect_peers(&self, io: &IoContext) { + // dont connect to peers, while we are processing handshakes. + let _handshake_lock = self.handshake_lock.lock(); + let (min_peers, pin, max_handshakes, allow_ips, self_id) = { let info = self.info.read(); if info.capabilities.is_empty() { @@ -850,17 +866,17 @@ impl Host { } } - fn session_writable(&self, token: StreamToken, io: &IoContext) { - let session = { self.sessions.read().get(&token).cloned() }; - + fn session_writable(&self, session: Option, io: &IoContext) { if let Some(session) = session { let mut s = session.lock(); if let Err(e) = s.writable(io, &self.info.read()) { - trace!(target: "network", "Session write error: {}: {:?}", token, e); + trace!(target: "network", "Session write error: {}: {:?}", s.token(), e); } if s.done() { - io.deregister_stream(token) + io.deregister_stream(s.token()) .unwrap_or_else(|e| debug!("Error deregistering stream: {:?}", e)); + } else { + trace!(target: "network", "Session writable not done: {}", s.token()); } } } @@ -870,13 +886,14 @@ impl Host { self.kill_connection(token, io, true); } - fn session_readable(&self, token: StreamToken, io: &IoContext) { + fn session_readable(&self, session: Option, io: &IoContext) { let mut ready_data: Vec = Vec::new(); let mut packet_data: Vec<(ProtocolId, PacketId, Vec)> = Vec::new(); let mut kill: Option = None; - let session = { self.sessions.read().get(&token).cloned() }; let mut ready_id = None; - if let Some(session) = session.clone() { + if let Some(session) = session { + let token = session.lock().token(); + trace!(target: "network", "Session readable called: {}", token); { loop { let session_result = session.lock().readable(io, &self.info.read()); @@ -902,6 +919,9 @@ impl Host { break; } Ok(SessionData::Ready) => { + // we allow only one Handshake to be handlet at a time. + let _handshake_lock = self.handshake_lock.lock(); + let (_, egress_count, ingress_count) = self.session_count(); //if self.sessions.is_duplicate(&session) { @@ -911,12 +931,13 @@ impl Host { if let Some(session_to_kill) = kill { if session_to_kill == token { // if its our session wich gets to be killed, we can skip the next setup steps. + trace!(target: "network", "not registering session {session_to_kill}"); break; } } let mut s = session.lock(); - self.sessions.register_finalized_handshake(token, s.id()); + let (min_peers, mut max_peers, reserved_only, self_id) = { let info = self.info.read(); let mut max_peers = info.config.max_peers; @@ -968,6 +989,19 @@ impl Host { ready_id = Some(id); + let new_token = match self + .sessions + .register_finalized_handshake(&mut s, io) + { + Ok(t) => t, + Err(e) => { + warn!(target: "network", "Unable to finalize handshake for token {token} reason: {e}"); + break; + } + }; + + trace!(target: "network", "upgraded handshake to regular session for token: {} -> {}", token, new_token); + // Add it to the node table if !s.info.originated { if let Ok(address) = s.remote_addr() { @@ -1088,6 +1122,8 @@ impl Host { ); } } + } else { + trace!(target: "network", "Session not found"); } } @@ -1175,12 +1211,19 @@ impl Host { let mut failure_id = None; let mut deregister = false; let mut expired_session = None; - if token >= FIRST_SESSION { + if token >= FIRST_HANDSHAKE { + trace!(target: "network", "Killing connection: {}", token); + let session_o = if token >= FIRST_SESSION { + self.sessions.get_session(token) + } else { + self.sessions.get_handshake(token) + }; + // we can shorten the session read lock here, if this causes a deadlock. // on the other hand it is good, so not that many sessions manipulations can take place // at the same time. - let sessions = self.sessions.read(); - if let Some(session) = sessions.get(&token).cloned() { + + if let Some(session) = session_o { expired_session = Some(session.clone()); let mut s = session.lock(); if !s.expired() { @@ -1287,6 +1330,16 @@ impl Host { ); action(&context) } + + fn get_session_or_handshake(&self, token: StreamToken) -> Option { + if token >= FIRST_HANDSHAKE && token <= LAST_HANDSHAKE { + return self.sessions.get_handshake(token); + } else if token >= FIRST_SESSION && token <= LAST_SESSION { + return self.sessions.get_session(token); + } + warn!(target: "network", "get_session_or_handshake called with unexpected token: {}", token); + return None; + } } impl IoHandler for Host { @@ -1301,7 +1354,7 @@ impl IoHandler for Host { fn stream_hup(&self, io: &IoContext, stream: StreamToken) { trace!(target: "network", "Hup: {}", stream); - if stream >= FIRST_SESSION { + if stream >= FIRST_HANDSHAKE { self.connection_closed(stream, io) } else { warn!(target: "network", "Unexpected hup for session {}", stream); @@ -1313,7 +1366,12 @@ impl IoHandler for Host { return; } match stream { - FIRST_SESSION..LAST_SESSION => self.session_readable(stream, io), + FIRST_HANDSHAKE..=LAST_HANDSHAKE => { + self.session_readable(self.sessions.get_handshake(stream), io) + } + FIRST_SESSION..=LAST_SESSION => { + self.session_readable(self.sessions.get_session(stream), io) + } DISCOVERY => self.discovery_readable(io), TCP_ACCEPT => self.accept(io), _ => panic!("Received unknown readable token"), @@ -1325,14 +1383,18 @@ impl IoHandler for Host { return; } match stream { - FIRST_SESSION..=LAST_SESSION => self.session_writable(stream, io), + FIRST_HANDSHAKE..=LAST_HANDSHAKE => { + self.session_writable(self.sessions.get_handshake(stream), io) + } + FIRST_SESSION..=LAST_SESSION => { + self.session_writable(self.sessions.get_session(stream), io) + } DISCOVERY => self.discovery_writable(io), _ => panic!("Received unknown writable token"), } } fn timeout(&self, io: &IoContext, token: TimerToken) { - trace!(target: "network", "HOST timout: {}", token); if self.stopping.load(AtomicOrdering::SeqCst) { return; } @@ -1392,7 +1454,7 @@ impl IoHandler for Host { warn!("Unknown timer token: {}", token); } // timer is not registerd through us }, - FIRST_SESSION..=LAST_SESSION => { + FIRST_HANDSHAKE..=LAST_SESSION => { trace!(target: "network", "Timeout from Host impl: {}", token); self.connection_timeout(token, io); } @@ -1469,7 +1531,7 @@ impl IoHandler for Host { .unwrap_or_else(|e| debug!("Error registering timer {}: {:?}", token, e)); } NetworkIoMessage::Disconnect(ref peer) => { - let session = { self.sessions.read().get(&*peer).cloned() }; + let session = self.get_session_or_handshake(peer.clone()); if let Some(session) = session { session .lock() @@ -1479,7 +1541,7 @@ impl IoHandler for Host { self.kill_connection(*peer, io, false); } NetworkIoMessage::DisablePeer(ref peer) => { - let session = { self.sessions.read().get(&*peer).cloned() }; + let session = self.get_session_or_handshake(peer.clone()); if let Some(session) = session { session .lock() @@ -1508,8 +1570,17 @@ impl IoHandler for Host { ) { trace!(target: "network", "register_stream {}", stream); match stream { + FIRST_HANDSHAKE..=LAST_HANDSHAKE => { + let session = { self.sessions.get_handshake(stream) }; + if let Some(session) = session { + session + .lock() + .register_socket(reg, event_loop) + .expect("Error registering socket"); + } + } FIRST_SESSION.. => { - let session = { self.sessions.read().get(&stream).cloned() }; + let session = { self.sessions.get_session(stream) }; if let Some(session) = session { session .lock() @@ -1543,7 +1614,7 @@ impl IoHandler for Host { event_loop: &mut EventLoop>, ) { match stream { - FIRST_SESSION.. => { + FIRST_HANDSHAKE.. => { self.sessions.deregister_session_stream(stream, event_loop); } DISCOVERY => (), @@ -1583,7 +1654,7 @@ impl IoHandler for Host { ) .expect("Error reregistering stream"), _ => { - let connection = { self.sessions.read().get(&&stream).cloned() }; + let connection = self.get_session_or_handshake(stream); if let Some(connection) = connection { connection .lock() diff --git a/crates/net/network-devp2p/src/session.rs b/crates/net/network-devp2p/src/session.rs index c0752849a..47f131f36 100644 --- a/crates/net/network-devp2p/src/session.rs +++ b/crates/net/network-devp2p/src/session.rs @@ -645,4 +645,14 @@ impl Session { } Ok(()) } + + pub(crate) fn update_token_id(&mut self, token: StreamToken) -> Result<(), Error> { + match self.state { + State::Handshake(ref _h) => return Err(ErrorKind::HostCacheInconsistency.into()), + State::Session(ref mut s) => { + s.connection.token = token; + return Ok(()); + } + } + } } diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 81a67d103..1f7b26f05 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -18,20 +18,36 @@ fn socket_address_to_string(socket: &TcpStream) -> String { pub struct SessionContainer { max_sessions: usize, + max_handshakes: usize, // New field to limit concurrent handshakes + first_handshake: usize, + last_handshake: usize, + // the handshake cursor is a improvement to find new available handshake slots. it defines the next starting search position. + current_handshake_cursor: Mutex, sessions: Arc>>, + handshakes: Arc>>, // Separate map for handshakes expired_sessions: Arc>>, node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. - sessions_token_max: Mutex, // Used to generate new session tokens + sessions_token_max: Mutex, // curent last used token for regular sessions. } impl SessionContainer { - pub fn new(first_session_token: usize, max_sessions: usize, max_node_mappings: usize) -> Self { + pub fn new( + first_handshake_token: usize, + max_sessions: usize, + max_node_mappings: usize, + max_handshakes: usize, + ) -> Self { SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), + handshakes: Arc::new(RwLock::new(std::collections::BTreeMap::new())), + current_handshake_cursor: Mutex::new(first_handshake_token), + first_handshake: first_handshake_token, + last_handshake: first_handshake_token + max_handshakes, expired_sessions: Arc::new(RwLock::new(Vec::new())), node_id_to_session: Mutex::new(LruCache::new(max_node_mappings)), - sessions_token_max: Mutex::new(first_session_token), + sessions_token_max: Mutex::new(first_handshake_token + max_handshakes + 1), // Renamed from first_session_token max_sessions, + max_handshakes, } } @@ -40,6 +56,11 @@ impl SessionContainer { self.sessions.read() } + /// Returns a Read guard to the sessions. + pub fn read_handshakes(&self) -> RwLockReadGuard> { + self.handshakes.read() + } + /// gets the next token ID and store this information fn create_token_id( &self, @@ -61,21 +82,54 @@ impl SessionContainer { return next_id; } - fn create_token_id_for_handshake(&self) -> usize { - let mut session_token_max = self.sessions_token_max.lock(); - let next_id = session_token_max.clone(); + fn create_token_id_for_handshake( + &self, + handshakes: &std::collections::BTreeMap, + ) -> Result { + let mut cursor_lock = self.current_handshake_cursor.lock(); + let start_cursor = *cursor_lock; - *session_token_max += 1; + for _ in 0..self.max_handshakes { + let current_token = *cursor_lock; + *cursor_lock = if current_token + 1 < self.last_handshake { + current_token + 1 + } else { + self.first_handshake + }; - // TODO: if we run out of token ids, - // we need to recycle Ids that are not used anymore. + if !handshakes.contains_key(¤t_token) { + // Found an available token + return Ok(current_token); + } - return next_id; + if *cursor_lock == start_cursor { + // We've looped through all possible handshake tokens and found none free. + break; + } + } + + // If we reach here, it means no available handshake token was found. + Err(ErrorKind::TooManyConnections.into()) + } + + pub(crate) fn session_count(&self) -> (usize, usize, usize) { + let mut egress = 0; + let mut ingress = 0; + + // we avoid an intensive read lock on the sessions, and take a snapshot of current sessions. + for s in self.sessions.read().clone().iter() { + match s.1.lock() { + ref s if s.is_ready() && s.info.originated => egress += 1, + ref s if s.is_ready() && !s.info.originated => ingress += 1, + _ => {} + } + } + + (self.handshakes.read().len(), egress, ingress) } // like session count, but does not block if read can not be achieved. pub fn session_count_try(&self, lock_duration: Duration) -> Option<(usize, usize, usize)> { - let mut handshakes = 0; let mut egress = 0; let mut ingress = 0; @@ -91,18 +145,20 @@ impl SessionContainer { } else { ingress += 1; } - } else { - handshakes += 1; } } - None => return None, } } - return Some((handshakes, egress, ingress)); + } else { + return None; } - return None; + if let Some(lock) = self.handshakes.try_read_for(deadline.time_left()) { + return Some((lock.len(), egress, ingress)); + } else { + return None; + } } /// Creates a new session and adds it to the session container. @@ -115,13 +171,11 @@ impl SessionContainer { nonce: &H256, host: &HostInfo, ) -> Result { - // make sure noone else is trying to modify the sessions at the same time. - // creating a connection is a very rare event. - // always lock the node_id_to_session first, then the sessions. let mut expired_session = self.expired_sessions.write(); let mut node_ids = self.node_id_to_session.lock(); let mut sessions = self.sessions.write(); + let mut handshakes = self.handshakes.write(); if sessions.len() >= self.max_sessions { return Err(ErrorKind::TooManyConnections.into()); @@ -243,7 +297,12 @@ impl SessionContainer { } } } else { - let next_free_token = self.create_token_id_for_handshake(); + // Handle ingress handshakes separately + if handshakes.len() >= self.max_handshakes { + return Err(ErrorKind::TooManyConnections.into()); // Treat as too many handshakes + } + + let next_free_token = self.create_token_id_for_handshake(&mut handshakes)?; trace!(target: "network", "creating session for handshaking peer: {} token: {}", socket_address_to_string(&socket), next_free_token); // we dont know the NodeID, @@ -254,13 +313,11 @@ impl SessionContainer { match new_session { Ok(session) => { let session = Arc::new(Mutex::new(session)); - sessions.insert(next_free_token, session.clone()); + handshakes.insert(next_free_token, session.clone()); // Insert into handshakes map // register the stream for the new session. if let Err(err) = io.register_stream(next_free_token) { debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); } - //node_ids.insert(node_id.clone(), next_free_token); - return Ok(next_free_token); } Err(e) => { @@ -269,8 +326,6 @@ impl SessionContainer { } } } - // if we dont know a NodeID - // debug!(target: "network", "Session create error: {:?}", e); } pub fn get_session_for(&self, id: &NodeId) -> Option { @@ -311,26 +366,74 @@ impl SessionContainer { }) } - pub fn register_finalized_handshake(&self, token: usize, id: Option<ðereum_types::H512>) { + // This method will now handle both registration and promotion if applicable + pub fn register_finalized_handshake( + &self, + session: &mut Session, + io: &IoContext, + ) -> Result { + let token = session.token(); + let id = session.id(); + + trace!(target: "network", "register_finalized_handshake for token: {} with id: {:?}", token,id); let node_id = match id { Some(id) => id.clone(), None => { error!(target: "network", "Tried to register finalized handshake without node id"); - // we have no node id, so we can not register it. - return; + // We have no Node ID, so we can't promote it to a full session mapped by Node ID. + // This might indicate an error state, or a handshake that failed to yield a Node ID. + // For now, we'll just log and return. + return Err(ErrorKind::HostCacheInconsistency.into()); } }; - // register this session. - if let Some(old) = self.node_id_to_session.lock().insert(node_id, token) { - // in scenarios where we did have registered the session to this node, - // the token id wont change. - // but still we need a lock to node_id_to_session anyway. - if old != token { - debug!(target: "network", "handshake completed: changed primary session for node id {} from {} to {}", node_id, token, old); + let mut node_ids_lock = self.node_id_to_session.lock(); + let mut sessions_lock = self.sessions.write(); + let mut handshakes_lock = self.handshakes.write(); + + // 1. Try to promote from handshakes map + if let Some(handshake_session) = handshakes_lock.remove(&token) { + // Check session limit before promoting + if sessions_lock.len() >= self.max_sessions { + error!(target: "network", "Failed to promote handshake {}: too many active sessions.", token); + // The handshake session is removed from 'handshakes_lock' but not added to 'sessions_lock'. + // This session will effectively be dropped, and eventually cleaned up by `deregister_session_stream`. + return Err(ErrorKind::TooManyConnections.into()); + } + + // switch the session token here, + let upgraded_token = self.create_token_id(&node_id, &mut node_ids_lock); + + io.deregister_stream(token)?; + io.register_stream(upgraded_token.clone())?; + session.update_token_id(upgraded_token)?; + + // Move to the sessions map + sessions_lock.insert(upgraded_token, handshake_session.clone()); + + // Register/update the NodeId to session token mapping + if let Some(old_token) = node_ids_lock.insert(node_id.clone(), upgraded_token) { + if old_token != token { + debug!(target: "network", "Handshake completed: changed primary session for node id {} from {} to {}", node_id, old_token, upgraded_token); + } + } else { + debug!(target: "network", "Handshake completed: node id {} registered primary session token {}", node_id, upgraded_token); } + return Ok(upgraded_token); } else { - debug!(target: "network", "handshake completed: node id {} registered primary session token {}", node_id, token); + return Err(ErrorKind::HostCacheInconsistency.into()); + // // 2. If not found in handshakes, it might be an existing session being re-registered + // // (e.g., an outgoing connection where the Node ID was known from the start) + // if let Some(old_token) = node_ids_lock.insert(node_id, token) { + // // in scenarios where we did have registered the session to this node, + // // the token id wont change. + // // but still we need a lock to node_id_to_session anyway. + // if old_token != token { + // debug!(target: "network", "Node ID {} already existed with token {}, overwriting with {}", node_id, old_token, token); + // } + // } else { + // debug!(target: "network", "Node ID {} registered primary session token {}", node_id, token); + // } } } @@ -417,5 +520,24 @@ impl SessionContainer { connections.remove(&stream); } } + // Also check the handshakes map for deregistration + let mut handshakes = self.handshakes.write(); + if let Some(connection) = handshakes.get(&stream).cloned() { + let c = connection.lock(); + if c.expired() { + c.deregister_socket(event_loop) + .expect("Error deregistering socket"); + handshakes.remove(&stream); + } + } + } + + pub(crate) fn get_handshake(&self, stream: usize) -> Option { + trace!(target: "network", "get_handshake for stream: {}. total handshakes: {}", stream, self.handshakes.read().len() ); + self.handshakes.read().get(&stream).cloned() + } + + pub(crate) fn get_session(&self, stream: usize) -> Option { + self.sessions.read().get(&stream).cloned() } } From 3783ff94a8deae26de27ee2e8e19049b66628f53 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 24 Jul 2025 09:16:24 +0200 Subject: [PATCH 591/687] improved session handling and improve error messaging in NetworkProtocolHandler and Host implementations. --- crates/ethcore/sync/src/api.rs | 5 +- crates/net/network-devp2p/src/host.rs | 13 +- .../network-devp2p/src/session_container.rs | 205 +++++------------- 3 files changed, 67 insertions(+), 156 deletions(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index fcdb0b4aa..aefcd3075 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -594,7 +594,10 @@ impl NetworkProtocolHandler for SyncProtocolHandler { fn connected(&self, io: &dyn NetworkContext, peer: &PeerId) { trace_time!("sync::connected"); - let node_id = io.session_info(*peer).unwrap().id; + let node_id = io + .session_info(*peer) + .expect(format!("peer not found: {peer}").as_str()) + .id; if io.is_reserved_peer(*peer) { trace!(target: "sync", "Connected to reserved peer {node_id:?} {peer}" ); } diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 0dc81fb84..b53db607b 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -202,7 +202,7 @@ impl<'s> NetworkContext<'s> { if peer >= FIRST_SESSION { self.sessions.get_session(peer) } else { - self.sessions.get_session(peer) + self.sessions.get_handshake(peer) } } } @@ -845,7 +845,7 @@ impl Host { ) -> Result { let nonce = self.info.write().next_nonce(); self.sessions - .create_connection(socket, id, io, &nonce, &self.info.read()) + .create_handshake_connection(socket, id, io, &nonce, &self.info.read()) } fn accept(&self, io: &IoContext) { @@ -875,8 +875,6 @@ impl Host { if s.done() { io.deregister_stream(s.token()) .unwrap_or_else(|e| debug!("Error deregistering stream: {:?}", e)); - } else { - trace!(target: "network", "Session writable not done: {}", s.token()); } } } @@ -892,7 +890,7 @@ impl Host { let mut kill: Option = None; let mut ready_id = None; if let Some(session) = session { - let token = session.lock().token(); + let mut token = session.lock().token(); trace!(target: "network", "Session readable called: {}", token); { loop { @@ -1002,6 +1000,8 @@ impl Host { trace!(target: "network", "upgraded handshake to regular session for token: {} -> {}", token, new_token); + token = new_token; + // Add it to the node table if !s.info.originated { if let Ok(address) = s.remote_addr() { @@ -1083,8 +1083,9 @@ impl Host { self.kill_connection(token, io, false); return; } + + let reserved = self.reserved_nodes.read().clone(); for p in ready_data { - let reserved = self.reserved_nodes.read().clone(); if let Some(h) = handlers.get(&p) { h.connected( &NetworkContext::new( diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 1f7b26f05..04532ab85 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -16,6 +16,8 @@ fn socket_address_to_string(socket: &TcpStream) -> String { .map_or("unknown".to_string(), |a| a.to_string()) } +/// SessionContainer manages handshakes, and their upgrade to regular encrypted sessions. +/// It has high performance lookup capabilities for NodeIDs by using a hashmap, instead of linear locking iteration of sessions. pub struct SessionContainer { max_sessions: usize, max_handshakes: usize, // New field to limit concurrent handshakes @@ -25,7 +27,6 @@ pub struct SessionContainer { current_handshake_cursor: Mutex, sessions: Arc>>, handshakes: Arc>>, // Separate map for handshakes - expired_sessions: Arc>>, node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. sessions_token_max: Mutex, // curent last used token for regular sessions. } @@ -43,7 +44,6 @@ impl SessionContainer { current_handshake_cursor: Mutex::new(first_handshake_token), first_handshake: first_handshake_token, last_handshake: first_handshake_token + max_handshakes, - expired_sessions: Arc::new(RwLock::new(Vec::new())), node_id_to_session: Mutex::new(LruCache::new(max_node_mappings)), sessions_token_max: Mutex::new(first_handshake_token + max_handshakes + 1), // Renamed from first_session_token max_sessions, @@ -163,7 +163,7 @@ impl SessionContainer { /// Creates a new session and adds it to the session container. /// returns the token ID of the new session, or an Error if not successful. - pub fn create_connection( + pub fn create_handshake_connection( &self, socket: TcpStream, id: Option<ðereum_types::H512>, @@ -171,159 +171,65 @@ impl SessionContainer { nonce: &H256, host: &HostInfo, ) -> Result { - // always lock the node_id_to_session first, then the sessions. - let mut expired_session = self.expired_sessions.write(); let mut node_ids = self.node_id_to_session.lock(); - let mut sessions = self.sessions.write(); let mut handshakes = self.handshakes.write(); - if sessions.len() >= self.max_sessions { + if self.sessions.read().len() >= self.max_sessions { + return Err(ErrorKind::TooManyConnections.into()); + } + + if handshakes.len() >= self.max_handshakes { return Err(ErrorKind::TooManyConnections.into()); } if let Some(node_id) = id { // check if there is already a connection for the given node id. if let Some(existing_peer_id) = node_ids.get_mut(node_id) { - let existing_session_mutex_o = sessions.get(existing_peer_id).clone(); + let existing_session_mutex_o = self.get_session(existing_peer_id.clone()); if let Some(existing_session_mutex) = existing_session_mutex_o { - let session_expired = { - let session = existing_session_mutex.lock(); - if let Some(id_from_session) = &session.info.id { - if session.info.id == Some(*node_id) { - // we got already got a session for the specified node. - // maybe the old session is already scheduled for getting deleted. - session.expired() - } else { - error!(target: "network", "host cache inconsistency: Session node id mismatch. expected: {} is {}.", existing_peer_id, id_from_session); - return Err(ErrorKind::HostCacheInconsistency.into()); + let session = existing_session_mutex.lock(); + if let Some(id_from_session) = &session.info.id { + if session.info.id == Some(*node_id) { + // we got already got a session for the specified node. + // maybe the old session is already scheduled for getting deleted. + if !session.expired() { + return Err(ErrorKind::AlreadyExists.into()); } } else { - error!(target: "network", "host cache inconsistency: Session has no Node_id defined where it should for {}", existing_peer_id); + error!(target: "network", "host cache inconsistency: Session node id mismatch. expected: {} is {}.", existing_peer_id, id_from_session); return Err(ErrorKind::HostCacheInconsistency.into()); } - }; // session guard is dropped here - - if session_expired { - debug!(target: "network", "Creating new session for expired {} token: {} node id: {:?}", socket_address_to_string(&socket), existing_peer_id, id); - // if the session is expired, we will just create n new session for this node. - let new_session = - Session::new(io, socket, existing_peer_id.clone(), id, nonce, host); - match new_session { - Ok(session) => { - let new_session_arc = Arc::new(Mutex::new(session)); - let old_session_o = - sessions.insert(*existing_peer_id, new_session_arc); - - match old_session_o { - Some(old) => { - // we remember the expired session, so it can get closed and cleaned up in a nice way later. - expired_session.push(old); - } - None => { - // we have a cache mismatch. - // but the only thing is missing is a clean ending of the old session. - // nothing mission-critical. - error!(target: "network", "host cache inconsistency: Session for node id {} was not found in sessions map, but it should be there.", node_id); - } - } - - // in this context, the stream might already be unregistered ?! - // we can just register the stream again. - if let Err(err) = io.register_stream(*existing_peer_id) { - // todo: research this topic, watch out for this message, - // maybe we can keep track of stream registrations as well somehow. - debug!(target: "network", "Failed to register stream for token: {} : {}", existing_peer_id, err); - } - - return Ok(*existing_peer_id); - } - Err(e) => { - error!(target: "network", "Failed to create session for node id: {}", node_id); - return Err(e); - } - } } else { - // this might happen if 2 nodes try to connect to each other at the same time. - debug!(target: "network", "Session already exists for node id: {}", node_id); - return Err(ErrorKind::AlreadyExists.into()); - } - } else { - debug!(target: "network", "reusing peer ID {} for node: {}", existing_peer_id, node_id); - // we have a node id, but there is no session for it (anymore) - // we reuse that peer_id, so other in flight actions are pointing to the same node again. - match Session::new(io, socket, existing_peer_id.clone(), id, nonce, host) { - Ok(new_session) => { - sessions.insert( - existing_peer_id.clone(), - Arc::new(Mutex::new(new_session)), - ); - if let Err(err) = io.register_stream(existing_peer_id.clone()) { - warn!(target: "network", "Failed to register stream for reused token: {} : {}", existing_peer_id, err); - } - return Ok(existing_peer_id.clone()); - } - Err(err) => { - debug!(target: "network", "reusing peer ID {} for node: {}, but could not create session", existing_peer_id, node_id); - return Err(err); - } - } - } - } else { - // this should be the most common scenario. - // we have a new node id, we were either never connected to, or we forgot about it. - - let next_free_token = self.create_token_id(&node_id, &mut node_ids); - trace!(target: "network", "Creating new session {} for new node id:{} with token {}", socket_address_to_string(&socket), node_id, next_free_token); - let new_session = - Session::new(io, socket, next_free_token.clone(), id, nonce, host); - // the token is already registerd. - match new_session { - Ok(session) => { - let session = Arc::new(Mutex::new(session)); - sessions.insert(next_free_token, session.clone()); - // register the stream for the new session. - if let Err(err) = io.register_stream(next_free_token) { - debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); - } - node_ids.insert(node_id.clone(), next_free_token); - - return Ok(next_free_token); - } - Err(e) => { - error!(target: "network", "Failed to create session for node id: {}", node_id); - return Err(e); + error!(target: "network", "host cache inconsistency: Session has no Node_id defined where it should for {}", existing_peer_id); + return Err(ErrorKind::HostCacheInconsistency.into()); } + // session guard is dropped here } } - } else { - // Handle ingress handshakes separately - if handshakes.len() >= self.max_handshakes { - return Err(ErrorKind::TooManyConnections.into()); // Treat as too many handshakes - } + } - let next_free_token = self.create_token_id_for_handshake(&mut handshakes)?; - - trace!(target: "network", "creating session for handshaking peer: {} token: {}", socket_address_to_string(&socket), next_free_token); - // we dont know the NodeID, - // we still need a session to do the handshake. - - let new_session = Session::new(io, socket, next_free_token.clone(), id, nonce, host); - // the token is already registerd. - match new_session { - Ok(session) => { - let session = Arc::new(Mutex::new(session)); - handshakes.insert(next_free_token, session.clone()); // Insert into handshakes map - // register the stream for the new session. - if let Err(err) = io.register_stream(next_free_token) { - debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); - } - return Ok(next_free_token); - } - Err(e) => { - error!(target: "network", "Failed to create handshake session for: {}", next_free_token); - return Err(e); + let next_free_token = self.create_token_id_for_handshake(&mut handshakes)?; + + trace!(target: "network", "creating session for handshaking peer: {} token: {}", socket_address_to_string(&socket), next_free_token); + // we dont know the NodeID, + // we still need a session to do the handshake. + + let new_session = Session::new(io, socket, next_free_token.clone(), id, nonce, host); + // the token is already registerd. + match new_session { + Ok(session) => { + let session = Arc::new(Mutex::new(session)); + handshakes.insert(next_free_token, session.clone()); // Insert into handshakes map + // register the stream for the new session. + if let Err(err) = io.register_stream(next_free_token) { + debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); } + return Ok(next_free_token); + } + Err(e) => { + error!(target: "network", "Failed to create handshake session for: {}", next_free_token); + return Err(e); } } } @@ -401,10 +307,16 @@ impl SessionContainer { return Err(ErrorKind::TooManyConnections.into()); } + io.deregister_stream(token)?; + + let upgraded_token = match node_ids_lock.get_mut(&node_id) { + Some(t) => t.clone(), + None => self.create_token_id(&node_id, &mut node_ids_lock), + }; + // switch the session token here, - let upgraded_token = self.create_token_id(&node_id, &mut node_ids_lock); + // let upgraded_token = self.create_token_id(&node_id, &mut node_ids_lock); - io.deregister_stream(token)?; io.register_stream(upgraded_token.clone())?; session.update_token_id(upgraded_token)?; @@ -413,7 +325,7 @@ impl SessionContainer { // Register/update the NodeId to session token mapping if let Some(old_token) = node_ids_lock.insert(node_id.clone(), upgraded_token) { - if old_token != token { + if old_token != upgraded_token { debug!(target: "network", "Handshake completed: changed primary session for node id {} from {} to {}", node_id, old_token, upgraded_token); } } else { @@ -510,7 +422,12 @@ impl SessionContainer { stream: usize, event_loop: &mut mio::deprecated::EventLoop, ) { - let mut connections = self.sessions.write(); + let mut connections = if stream < self.last_handshake { + self.handshakes.write() + } else { + self.sessions.write() + }; + if let Some(connection) = connections.get(&stream).cloned() { let c = connection.lock(); if c.expired() { @@ -520,16 +437,6 @@ impl SessionContainer { connections.remove(&stream); } } - // Also check the handshakes map for deregistration - let mut handshakes = self.handshakes.write(); - if let Some(connection) = handshakes.get(&stream).cloned() { - let c = connection.lock(); - if c.expired() { - c.deregister_socket(event_loop) - .expect("Error deregistering socket"); - handshakes.remove(&stream); - } - } } pub(crate) fn get_handshake(&self, stream: usize) -> Option { From 79e7be60ff7d378eea4459a51138feace259ff0a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 24 Jul 2025 09:57:05 +0200 Subject: [PATCH 592/687] tracking of Egress Handshake connections to prevent multiple ongoing egress handshakes (especially to reserved peers). --- crates/net/network-devp2p/src/host.rs | 18 ++++---- .../network-devp2p/src/session_container.rs | 46 ++++++++++++------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index b53db607b..820be0e68 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -16,7 +16,6 @@ use crate::{ mio::{deprecated::EventLoop, tcp::*, udp::*, *}, - session, session_container::{SessionContainer, SharedSession}, }; use crypto::publickey::{Generator, KeyPair, Random, Secret}; @@ -57,7 +56,7 @@ use parity_path::restrict_permissions_owner; use parking_lot::{Mutex, RwLock}; use stats::{PrometheusMetrics, PrometheusRegistry}; -const MAX_SESSIONS: usize = 2048 + MAX_HANDSHAKES; +const MAX_SESSIONS: usize = 2048; const MAX_HANDSHAKES: usize = 99; const DEFAULT_PORT: u16 = 30303; @@ -678,14 +677,13 @@ impl Host { } fn have_session(&self, id: &NodeId) -> bool { - //self.sessions.have_session(id) - let result = self.sessions.get_session_for(id).is_some(); - - if !result { - trace!(target: "network", "no session found for {id}"); - } + return self.sessions.get_session_for(id).is_some(); + } - return result; + /// returns if there is a known handshake for the given node id is going on. + /// Only Egress handshakes can be considered, for ingress handshakes the NodeID is unknown. + fn have_handshake(&self, id: &NodeId) -> bool { + return self.sessions.get_handshake_for(id).is_some(); } // returns (handshakes, egress, ingress) @@ -749,7 +747,7 @@ impl Host { let unconnected_reserved_nodes: Vec = reserved_nodes .as_ref() .into_iter() - .filter(|f| !self.have_session(f) && f.ne(&&self_id)) + .filter(|f| f.ne(&&self_id) && !self.have_handshake(f) && !self.have_session(f)) .cloned() .collect(); diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 04532ab85..553fb0b25 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -17,7 +17,7 @@ fn socket_address_to_string(socket: &TcpStream) -> String { } /// SessionContainer manages handshakes, and their upgrade to regular encrypted sessions. -/// It has high performance lookup capabilities for NodeIDs by using a hashmap, instead of linear locking iteration of sessions. +/// It has high performance lookup capabilities for NodeIDs by using a hashmap, instead of linear locking iteration of sessions. pub struct SessionContainer { max_sessions: usize, max_handshakes: usize, // New field to limit concurrent handshakes @@ -27,6 +27,8 @@ pub struct SessionContainer { current_handshake_cursor: Mutex, sessions: Arc>>, handshakes: Arc>>, // Separate map for handshakes + // for egress handshakes, we know the Node ID we want to do a handshake with, so we can do efficient lookups. + handshakes_egress_map: RwLock>, node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. sessions_token_max: Mutex, // curent last used token for regular sessions. } @@ -41,6 +43,7 @@ impl SessionContainer { SessionContainer { sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), handshakes: Arc::new(RwLock::new(std::collections::BTreeMap::new())), + handshakes_egress_map: RwLock::new(BTreeMap::new()), current_handshake_cursor: Mutex::new(first_handshake_token), first_handshake: first_handshake_token, last_handshake: first_handshake_token + max_handshakes, @@ -172,6 +175,11 @@ impl SessionContainer { host: &HostInfo, ) -> Result { let mut node_ids = self.node_id_to_session.lock(); + + // if we known the ID, we also require a lock on the egress map in the same order as we do use to read the egress map + + let mut handshakes_egress_map = id.map(|_| self.handshakes_egress_map.write()); + let mut handshakes = self.handshakes.write(); if self.sessions.read().len() >= self.max_sessions { @@ -221,6 +229,9 @@ impl SessionContainer { Ok(session) => { let session = Arc::new(Mutex::new(session)); handshakes.insert(next_free_token, session.clone()); // Insert into handshakes map + if let Some(mut egress_map) = handshakes_egress_map { + egress_map.insert(id.unwrap().clone(), next_free_token); + } // register the stream for the new session. if let Err(err) = io.register_stream(next_free_token) { debug!(target: "network", "Failed to register stream for token: {} : {}", next_free_token, err); @@ -245,6 +256,16 @@ impl SessionContainer { }) } + pub fn get_handshake_for(&self, id: &NodeId) -> Option { + self.handshakes_egress_map + .read() + .get(id) + .cloned() + .map_or(None, |peer_id| { + self.handshakes.read().get(&peer_id).cloned() + }) + } + pub fn node_id_to_peer_id( &self, node_id: &NodeId, @@ -295,10 +316,17 @@ impl SessionContainer { let mut node_ids_lock = self.node_id_to_session.lock(); let mut sessions_lock = self.sessions.write(); + let mut handshakes_egress_map = self.handshakes_egress_map.write(); let mut handshakes_lock = self.handshakes.write(); // 1. Try to promote from handshakes map if let Some(handshake_session) = handshakes_lock.remove(&token) { + // we remove the known handshake here. + // for ingress handshakes, this call doesnt do anything, + // because we can only track egress handshakes. + // but thats fine. + handshakes_egress_map.remove(&node_id); + // Check session limit before promoting if sessions_lock.len() >= self.max_sessions { error!(target: "network", "Failed to promote handshake {}: too many active sessions.", token); @@ -309,14 +337,12 @@ impl SessionContainer { io.deregister_stream(token)?; + // either we reuse an old token, or we create a new token. let upgraded_token = match node_ids_lock.get_mut(&node_id) { Some(t) => t.clone(), None => self.create_token_id(&node_id, &mut node_ids_lock), }; - // switch the session token here, - // let upgraded_token = self.create_token_id(&node_id, &mut node_ids_lock); - io.register_stream(upgraded_token.clone())?; session.update_token_id(upgraded_token)?; @@ -334,18 +360,6 @@ impl SessionContainer { return Ok(upgraded_token); } else { return Err(ErrorKind::HostCacheInconsistency.into()); - // // 2. If not found in handshakes, it might be an existing session being re-registered - // // (e.g., an outgoing connection where the Node ID was known from the start) - // if let Some(old_token) = node_ids_lock.insert(node_id, token) { - // // in scenarios where we did have registered the session to this node, - // // the token id wont change. - // // but still we need a lock to node_id_to_session anyway. - // if old_token != token { - // debug!(target: "network", "Node ID {} already existed with token {}, overwriting with {}", node_id, old_token, token); - // } - // } else { - // debug!(target: "network", "Node ID {} registered primary session token {}", node_id, token); - // } } } From 603a777d13d0dd1833cf89ccda59cecd3d1c91ec Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 09:30:52 +0200 Subject: [PATCH 593/687] defaulting config to now also to show trace and debug for engine and consensus. --- .../src/engines/hbbft/hbbft_config_generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs index ffe79c932..20d43b78a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_config_generator/src/main.rs @@ -258,7 +258,7 @@ fn to_toml( misc.insert( "logging".into(), Value::String( - logging.unwrap_or("txqueue=trace,consensus=debug,engine=debug,own_tx=trace,tx_filter=trace,sync=trace,network=trace,io=trace") + logging.unwrap_or("txqueue=trace,consensus=trace,engine=trace,own_tx=trace,tx_filter=trace,sync=trace,network=trace,io=trace") .into(), ), ); From 760cd44f490962ba36dc71b67b9c89d7ba505d09 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 09:54:03 +0200 Subject: [PATCH 594/687] warning fixes --- crates/net/network-devp2p/src/session_container.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 553fb0b25..2c1ede636 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -178,7 +178,7 @@ impl SessionContainer { // if we known the ID, we also require a lock on the egress map in the same order as we do use to read the egress map - let mut handshakes_egress_map = id.map(|_| self.handshakes_egress_map.write()); + let handshakes_egress_map = id.map(|_| self.handshakes_egress_map.write()); let mut handshakes = self.handshakes.write(); From c5ba62738233c36469d08fc85ea9282d5afbf0eb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 09:54:59 +0200 Subject: [PATCH 595/687] Error handling during startup: reregistering ENGINE timer. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 00884b4a1..83df2a034 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -345,6 +345,12 @@ impl IoHandler<()> for TransitionHandler { if timer == ENGINE_TIMEOUT_TOKEN { if let Err(err) = self.handle_engine(io) { trace!(target: "consensus", "Error in Honey Badger Engine timeout handler: {:?}", err); + + // in error cases we try again soon. + io.register_timer_once(ENGINE_TIMEOUT_TOKEN, DEFAULT_DURATION) + .unwrap_or_else( + |e| warn!(target: "consensus", "Failed to restart consensus step timer: {}.", e), + ); } } else if timer == ENGINE_SHUTDOWN { // we do not run this on the first occurence, From 0228511b6cbae53ad49791a1755fd454f027c2d5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 20:38:31 +0200 Subject: [PATCH 596/687] fixed a case where resheduling sync message in cases where a Node was just disconnected. --- crates/ethcore/sync/src/chain/propagator.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 14661cbf2..9ed2c7612 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -27,7 +27,7 @@ use crate::{ use bytes::Bytes; use ethereum_types::{H256, H512}; use fastmap::H256FastSet; -use network::{Error, PeerId, client_version::ClientCapabilities}; +use network::{client_version::ClientCapabilities, Error, ErrorKind, PeerId}; use rand::RngCore; use rlp::RlpStream; @@ -429,17 +429,17 @@ impl ChainSync { Some(id) => id, None => { warn!(target: "sync", "Peer with node id {} not found in peers list.", peer); - return Err("No Session for Peer".into()); + return Err(ErrorKind::PeerNotFound.into()); } }; let packet_len = packet.len(); let send_result = ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); - match &send_result { + match send_result { Ok(_) => { self.statistics.log_consensus(packet_len); } Err(e) => { - warn!(target: "sync", "Error sending consensus packet to peer {}: {:?}", peer_id, e); + return Err(e); } } return send_result; From e8b856dacca752e37a3ef1cf5e7ddb999a2596f8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 20:39:36 +0200 Subject: [PATCH 597/687] early_epoch_end gets now 250ms instead of 50ms to read --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 83df2a034..60708aa04 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1020,7 +1020,7 @@ impl HoneyBadgerBFT { { let hbbft_state_option = - self.hbbft_state.try_read_for(Duration::from_millis(50)); + self.hbbft_state.try_read_for(Duration::from_millis(250)); match hbbft_state_option { Some(hbbft_state) => { should_handle_early_epoch_end = hbbft_state.is_validator(); @@ -1037,7 +1037,7 @@ impl HoneyBadgerBFT { } None => { // maybe improve here, to return with a result, that triggers a retry soon. - info!(target: "engine", "Unable to do_validator_engine_actions: Could not acquire read lock for hbbft state. Unable to decide about early epoch end. retrying soon."); + debug!(target: "engine", "Unable to do_validator_engine_actions: Could not acquire read lock for hbbft state. Unable to decide about early epoch end. retrying soon."); } }; } // drop lock for hbbft_state From 464ea54a92cd075e66f34c97f917d7faf5b78563 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 20:41:11 +0200 Subject: [PATCH 598/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/sync/src/chain/propagator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 9ed2c7612..f2716ca85 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -27,7 +27,7 @@ use crate::{ use bytes::Bytes; use ethereum_types::{H256, H512}; use fastmap::H256FastSet; -use network::{client_version::ClientCapabilities, Error, ErrorKind, PeerId}; +use network::{Error, ErrorKind, PeerId, client_version::ClientCapabilities}; use rand::RngCore; use rlp::RlpStream; From d17952473f2c67bc8f640ecda2079ec528f59eb2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 20:51:33 +0200 Subject: [PATCH 599/687] Update crates/runtime/io/src/service_mio.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- crates/runtime/io/src/service_mio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/runtime/io/src/service_mio.rs b/crates/runtime/io/src/service_mio.rs index 7b5d1af90..5b8d8d1cc 100644 --- a/crates/runtime/io/src/service_mio.rs +++ b/crates/runtime/io/src/service_mio.rs @@ -309,7 +309,7 @@ where debug!(target: "io", "No timer available for token {}. handler_index {handler_index}, subtoken {token_id}", token.0); } } else { - debug!(target: "io", "No handler for token {} registererd. handler_index {handler_index}, subtoken {token_id}", token.0); + debug!(target: "io", "No handler for token {} registered. handler_index {handler_index}, subtoken {token_id}", token.0); } } From c5b8f337691e7181ecbd2ff3d6852a129891f961 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 20:52:15 +0200 Subject: [PATCH 600/687] Update crates/net/network-devp2p/src/session_container.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- crates/net/network-devp2p/src/session_container.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 2c1ede636..9f1ef0607 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -48,7 +48,7 @@ impl SessionContainer { first_handshake: first_handshake_token, last_handshake: first_handshake_token + max_handshakes, node_id_to_session: Mutex::new(LruCache::new(max_node_mappings)), - sessions_token_max: Mutex::new(first_handshake_token + max_handshakes + 1), // Renamed from first_session_token + sessions_token_max: Mutex::new(first_handshake_token + max_handshakes + 1), max_sessions, max_handshakes, } From f52f3ff3e925f0aeccffad60cad537e7db7fea8e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 20:52:48 +0200 Subject: [PATCH 601/687] Update crates/net/network-devp2p/src/host.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- crates/net/network-devp2p/src/host.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 820be0e68..f8d6f7cc3 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -787,7 +787,7 @@ impl Host { && self.filter.as_ref().map_or(true, |f| { f.connection_allowed(&self_id, &n.id, ConnectionDirection::Outbound) }) - && !self.have_session(&n.id) // alternative strategy: we might also get an list of active connections, instead of locking here to figure out if we have a session or not. + && !self.have_session(&n.id) // alternative strategy: we might also get a list of active connections, instead of locking here to figure out if we have a session or not. }); trace!(target: "network", "reserved nodes: {:?} nodes_to_connect: {:?}", reserved_nodes, nodes_to_connect); From d5849fc5075452a8b0ce24caa4299583fc308d41 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 20:53:42 +0200 Subject: [PATCH 602/687] Update crates/ethcore/sync/src/api.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- crates/ethcore/sync/src/api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index aefcd3075..511b45dad 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -596,7 +596,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler { trace_time!("sync::connected"); let node_id = io .session_info(*peer) - .expect(format!("peer not found: {peer}").as_str()) + .unwrap_or_else(|| panic!("peer not found: {peer}")) .id; if io.is_reserved_peer(*peer) { trace!(target: "sync", "Connected to reserved peer {node_id:?} {peer}" ); From 14e4df418436385dba90f8da58d66a17636fd816 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 21:22:27 +0200 Subject: [PATCH 603/687] cleanup comments and typos --- crates/ethcore/sync/src/chain/propagator.rs | 2 +- crates/net/network-devp2p/src/session_container.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index f2716ca85..224efdaa6 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -385,7 +385,7 @@ impl ChainSync { let peers = self.get_consensus_peers(); trace!(target: "sync", "Sending proposed blocks to {:?}", peers); for block in proposed { - // todo: sometimes we get at the receiving end blocks, with mismatching total difficulty, + // todo: sometimes we get at the receiving end blocks, with mismatched total difficulty, // so we ignore those blocks on import. // might that be the case if we are sending more than 1 block here ? // more about: https://github.com/DMDcoin/diamond-node/issues/61 diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 9f1ef0607..f75cd5e24 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -418,7 +418,6 @@ impl SessionContainer { } } else { trace!(target: "network", "No session active for {node_id} with peer id {existing_peer_id}"); - // todo: make sure the mapping is rewritten. } trace!(target: "network", "Session {peer_id} has a duplicate :{existing_peer_id} {node_id}"); From dc2f2a8d7696c097b1094884d53f0caf20da77ec Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 25 Jul 2025 21:36:37 +0200 Subject: [PATCH 604/687] changelog and version update --- CHANGELOG.md | 7 +++++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf37e96f..73b8ce468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## Diamond Node Software 3.3.5-hbbft-0.11.6 +- [session double kill problem.](https://github.com/DMDcoin/diamond-node/issues/252) +- [Network Host logic: peer_id to NodeID consistency](https://github.com/DMDcoin/diamond-node/issues/251) +- [sealing messages probably not received](https://github.com/DMDcoin/diamond-node/issues/248) +- [disconnected from reservered peers](https://github.com/DMDcoin/diamond-node/issues/247) +- [separate handshakes and encrypted connections](https://github.com/DMDcoin/diamond-node/issues/254) + ## Diamond Node Software 3.3.5-hbbft-0.11.5 - [Improved reliability of Hbbft targeted message delivery](https://github.com/DMDcoin/diamond-node/issues/248) diff --git a/Cargo.lock b/Cargo.lock index bfa9d8420..b7983c1f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.5" +version = "3.3.5-hbbft-0.11.6" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3578,7 +3578,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.5" +version = "3.3.5-hbbft-0.11.6" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 269794c1a..437ba8b1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.5" +version = "3.3.5-hbbft-0.11.6" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 00d318a46..a6e705738 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.5" +version = "3.3.5-hbbft-0.11.6" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 311337ff0169a4a4633798de5b954cf907f8ae90 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jul 2025 12:21:54 +0200 Subject: [PATCH 605/687] potentially fixed deadlock in deregister_session_stream, buy not overlapping locks and using an upgradable lock on handshakes/sessions. --- .../network-devp2p/src/session_container.rs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index f75cd5e24..268992d11 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -6,7 +6,7 @@ use std::{collections::BTreeMap, sync::Arc, time::Duration}; use crate::{io::*, node_table::*, session::Session}; use network::{Error, ErrorKind, NetworkIoMessage, PeerId}; -use parking_lot::{Mutex, RwLock, RwLockReadGuard}; +use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockUpgradableReadGuard}; pub type SharedSession = Arc>; @@ -25,8 +25,8 @@ pub struct SessionContainer { last_handshake: usize, // the handshake cursor is a improvement to find new available handshake slots. it defines the next starting search position. current_handshake_cursor: Mutex, - sessions: Arc>>, - handshakes: Arc>>, // Separate map for handshakes + sessions: RwLock>, + handshakes: RwLock>, // Separate map for handshakes // for egress handshakes, we know the Node ID we want to do a handshake with, so we can do efficient lookups. handshakes_egress_map: RwLock>, node_id_to_session: Mutex>, // used to map Node IDs to last used session tokens. @@ -41,8 +41,8 @@ impl SessionContainer { max_handshakes: usize, ) -> Self { SessionContainer { - sessions: Arc::new(RwLock::new(std::collections::BTreeMap::new())), - handshakes: Arc::new(RwLock::new(std::collections::BTreeMap::new())), + sessions: RwLock::new(std::collections::BTreeMap::new()), + handshakes: RwLock::new(std::collections::BTreeMap::new()), handshakes_egress_map: RwLock::new(BTreeMap::new()), current_handshake_cursor: Mutex::new(first_handshake_token), first_handshake: first_handshake_token, @@ -433,12 +433,13 @@ impl SessionContainer { pub(crate) fn deregister_session_stream( &self, stream: usize, + event_loop: &mut mio::deprecated::EventLoop, ) { - let mut connections = if stream < self.last_handshake { - self.handshakes.write() + let connections = if stream < self.last_handshake { + self.handshakes.upgradable_read() } else { - self.sessions.write() + self.sessions.upgradable_read() }; if let Some(connection) = connections.get(&stream).cloned() { @@ -447,8 +448,15 @@ impl SessionContainer { // make sure it is the same connection that the event was generated for c.deregister_socket(event_loop) .expect("Error deregistering socket"); - connections.remove(&stream); + drop(c); + let mut connections_write = RwLockUpgradableReadGuard::upgrade(connections); + connections_write.remove(&stream); + //RwLockUpgradableReadGuard::<'_, parking_lot::RawRwLock, BTreeMap>>>::upgrade(connections).remove(&stream); + } else { + debug!(target: "network", "Tried to deregister session stream {} but it is not expired.", stream); } + } else { + debug!(target: "network", "Tried to deregister session stream {} but it does not exist.", stream); } } From 1f05e50088470edf830e078e531c0a2f86def624 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jul 2025 16:21:13 +0200 Subject: [PATCH 606/687] Tracking Block Number for Consensus Messages, outdated messages for consensus are now ignored in the resend loop. https://github.com/DMDcoin/diamond-node/issues/261 --- crates/ethcore/src/client/chain_notify.rs | 2 +- crates/ethcore/src/client/client.rs | 18 ++++++++++--- crates/ethcore/src/client/test_client.rs | 9 +++++-- crates/ethcore/src/client/traits.rs | 4 +-- .../src/engines/authority_round/mod.rs | 10 ++++---- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 25 ++++++++++++++++--- crates/ethcore/sync/src/api.rs | 24 ++++++++++++------ crates/ethcore/sync/src/chain/propagator.rs | 1 - .../network-devp2p/src/session_container.rs | 2 +- 9 files changed, 69 insertions(+), 26 deletions(-) diff --git a/crates/ethcore/src/client/chain_notify.rs b/crates/ethcore/src/client/chain_notify.rs index 030c00875..0834b76ab 100644 --- a/crates/ethcore/src/client/chain_notify.rs +++ b/crates/ethcore/src/client/chain_notify.rs @@ -22,7 +22,7 @@ use std::{collections::HashMap, time::Duration}; /// Messages to broadcast via chain pub enum ChainMessageType { /// Consensus message - Consensus(Vec), + Consensus(u64, Vec), } /// Route type to indicate whether it is enacted or retracted. diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 5597f8e65..99d3a0afe 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -3288,7 +3288,7 @@ impl super::traits::EngineClient for Client { } } - fn broadcast_consensus_message(&self, message: Bytes) { + fn broadcast_consensus_message(&self, future_block_id: u64, message: Bytes) { self.statistics .broadcasted_consensus_messages .fetch_add(1, std::sync::atomic::Ordering::Relaxed); @@ -3296,10 +3296,15 @@ impl super::traits::EngineClient for Client { .broadcasted_consensus_messages_bytes .fetch_add(message.len() as u64, std::sync::atomic::Ordering::Relaxed); - self.notify(|notify| notify.broadcast(ChainMessageType::Consensus(message.clone()))); + self.notify(|notify| { + notify.broadcast(ChainMessageType::Consensus( + future_block_id, + message.clone(), + )) + }); } - fn send_consensus_message(&self, message: Bytes, node_id: Option) { + fn send_consensus_message(&self, future_block_id: u64, message: Bytes, node_id: Option) { self.statistics .sent_consensus_messages .fetch_add(1, std::sync::atomic::Ordering::Relaxed); @@ -3308,7 +3313,12 @@ impl super::traits::EngineClient for Client { .fetch_add(message.len() as u64, std::sync::atomic::Ordering::Relaxed); if let Some(n) = node_id { - self.notify(|notify| notify.send(ChainMessageType::Consensus(message.clone()), &n)); + self.notify(|notify| { + notify.send( + ChainMessageType::Consensus(future_block_id, message.clone()), + &n, + ) + }); } } diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index d884f78e2..a5df50670 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -1232,9 +1232,14 @@ impl super::traits::EngineClient for TestBlockChainClient { } } - fn broadcast_consensus_message(&self, _message: Bytes) {} + fn broadcast_consensus_message(&self, _future_block_id: u64, _message: Bytes) {} - fn send_consensus_message(&self, _message: Bytes, _node_id: Option) { + fn send_consensus_message( + &self, + _future_block_id: u64, + _message: Bytes, + _node_id: Option, + ) { // TODO: allow test to intercept the message to relay it to other test clients } diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 6d5fefd88..86c88e1d9 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -668,10 +668,10 @@ pub trait EngineClient: Sync + Send + ChainInfo { fn submit_seal(&self, block_hash: H256, seal: Vec); /// Broadcast a consensus message to the network. - fn broadcast_consensus_message(&self, message: Bytes); + fn broadcast_consensus_message(&self, future_block_id: u64, message: Bytes); /// Send a consensus message to the specified peer - fn send_consensus_message(&self, message: Bytes, node_id: Option); + fn send_consensus_message(&self, future_block_id: u64, message: Bytes, node_id: Option); /// Get the transition to the epoch the given parent hash is part of /// or transitions to. diff --git a/crates/ethcore/src/engines/authority_round/mod.rs b/crates/ethcore/src/engines/authority_round/mod.rs index e251edcc4..2e7f23a06 100644 --- a/crates/ethcore/src/engines/authority_round/mod.rs +++ b/crates/ethcore/src/engines/authority_round/mod.rs @@ -1158,7 +1158,7 @@ impl AuthorityRound { self.empty_steps.lock().insert(empty_step); } - fn generate_empty_step(&self, parent_hash: &H256) { + fn generate_empty_step(&self, future_block_id: u64, parent_hash: &H256) { let step = self.step.inner.load(); let empty_step_rlp = empty_step_rlp(step, parent_hash); @@ -1173,16 +1173,16 @@ impl AuthorityRound { }; trace!(target: "engine", "broadcasting empty step message: {:?}", empty_step); - self.broadcast_message(message_rlp); + self.broadcast_message(future_block_id, message_rlp); self.handle_empty_step_message(empty_step); } else { warn!(target: "engine", "generate_empty_step: FAIL: accounts secret key unavailable"); } } - fn broadcast_message(&self, message: Vec) { + fn broadcast_message(&self, future_block_id: u64, message: Vec) { if let Ok(c) = self.upgrade_client_or(None) { - c.broadcast_consensus_message(message); + c.broadcast_consensus_message(future_block_id, message); } } @@ -1759,7 +1759,7 @@ impl Engine for AuthorityRound { .compare_exchange(true, false, AtomicOrdering::SeqCst, AtomicOrdering::SeqCst) .is_ok() { - self.generate_empty_step(header.parent_hash()); + self.generate_empty_step(header.number(), header.parent_hash()); } return Seal::None; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 60708aa04..9409000ea 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -72,6 +72,16 @@ enum Message { Sealing(BlockNumber, sealing::Message), } +impl Message { + /// Returns the epoch (block number) of the message. + pub fn block_number(&self) -> BlockNumber { + match self { + Message::HoneyBadger(_, msg) => msg.epoch(), + Message::Sealing(block_num, _) => *block_num, + } + } +} + /// The Honey Badger BFT Engine. pub struct HoneyBadgerBFT { transition_service: IoService<()>, @@ -727,7 +737,11 @@ impl HoneyBadgerBFT { trace!(target: "consensus", "Dispatching message {:?} to {:?}", m.message, set); for node_id in set.into_iter().filter(|p| p != net_info.our_id()) { trace!(target: "consensus", "Sending message to {}", node_id.0); - client.send_consensus_message(ser.clone(), Some(node_id.0)); + client.send_consensus_message( + m.message.block_number(), + ser.clone(), + Some(node_id.0), + ); } } Target::AllExcept(set) => { @@ -737,7 +751,11 @@ impl HoneyBadgerBFT { .filter(|p| (p != &net_info.our_id() && !set.contains(p))) { trace!(target: "consensus", "Sending exclusive message to {}", node_id.0); - client.send_consensus_message(ser.clone(), Some(node_id.0)); + client.send_consensus_message( + m.message.block_number(), + ser.clone(), + Some(node_id.0), + ); } } } @@ -780,6 +798,7 @@ impl HoneyBadgerBFT { message: Message::HoneyBadger(*message_counter, msg.message), } }); + self.dispatch_messages(&client, messages, network_info); std::mem::drop(message_counter); self.process_output(client, step.output, network_info); @@ -813,7 +832,7 @@ impl HoneyBadgerBFT { let step = match self .hbbft_state - .try_write_for(std::time::Duration::from_millis(10)) + .try_write_for(std::time::Duration::from_millis(100)) { Some(mut state_lock) => state_lock.try_send_contribution(client.clone(), &self.signer), None => { diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 511b45dad..16143901b 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -506,6 +506,11 @@ impl SyncProtocolHandler { } fn send_cached_consensus_messages_for(&self, sync_io: &mut dyn SyncIo, node_id: &NodeId) { + let last_interesting_block = self + .chain + .block_number(types::ids::BlockId::Latest) + .unwrap_or(0); + // now since we are connected, lets send any cached messages if let Some(vec_msg) = self.message_cache.write().remove(&Some(*node_id)) { trace!(target: "consensus", "Cached Messages: Trying to send cached messages to {:?}", node_id); @@ -514,7 +519,11 @@ impl SyncProtocolHandler { for msg in vec_msg { match msg { - ChainMessageType::Consensus(message) => { + ChainMessageType::Consensus(block, message) => { + if block < last_interesting_block { + // https://github.com/DMDcoin/diamond-node/issues/261 + continue; + } let send_consensus_result = self.sync.write().send_consensus_packet( sync_io, message.clone(), @@ -525,7 +534,7 @@ impl SyncProtocolHandler { Ok(_) => {} Err(e) => { info!(target: "consensus", "Error sending cached consensus message to peer (re-adding) {:?}: {:?}", node_id, e); - failed_messages.push(ChainMessageType::Consensus(message)); + failed_messages.push(ChainMessageType::Consensus(block, message)); } } } @@ -534,8 +543,9 @@ impl SyncProtocolHandler { if !failed_messages.is_empty() { // If we failed to send some messages, cache them for later - let mut lock = self.message_cache.write(); - lock.entry(Some(*node_id)) + self.message_cache + .write() + .entry(Some(*node_id)) .or_default() .extend(failed_messages); } else { @@ -729,7 +739,7 @@ impl ChainNotify for EthSync { &self.eth_handler.overlay, ); match message_type { - ChainMessageType::Consensus(message) => self + ChainMessageType::Consensus(_block, message) => self .eth_handler .sync .write() @@ -746,13 +756,13 @@ impl ChainNotify for EthSync { &self.eth_handler.overlay); match message_type { - ChainMessageType::Consensus(message) => { + ChainMessageType::Consensus(block, message) => { let send_result = self.eth_handler.sync.write().send_consensus_packet(&mut sync_io, message.clone(), node_id); if let Err(e) = send_result { info!(target: "consensus", "Error sending consensus message to peer - caching message {:?}: {:?}", node_id, e); // If we failed to send the message, cache it for later let mut lock = self.eth_handler.message_cache.write(); - lock.entry(Some(node_id.clone())).or_default().push(ChainMessageType::Consensus(message)); + lock.entry(Some(node_id.clone())).or_default().push(ChainMessageType::Consensus(block, message)); } }, } diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 224efdaa6..30d83c156 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -405,7 +405,6 @@ impl ChainSync { for peer_id in lucky_peers { let send_result = ChainSync::send_packet(io, peer_id, ConsensusDataPacket, packet.clone()); - if let Err(e) = send_result { info!(target: "sync", "Error broadcast consensus packet to peer {}: {:?}", peer_id, e); } else { diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 268992d11..2f72b4029 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -433,7 +433,7 @@ impl SessionContainer { pub(crate) fn deregister_session_stream( &self, stream: usize, - + event_loop: &mut mio::deprecated::EventLoop, ) { let connections = if stream < self.last_handshake { From 064f122989d72afdb4201d157ab28d00e2d05b6c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jul 2025 17:46:51 +0200 Subject: [PATCH 607/687] fixed tests to apply to latest changes --- crates/ethcore/src/test_helpers.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/test_helpers.rs b/crates/ethcore/src/test_helpers.rs index b6c349904..982acc359 100644 --- a/crates/ethcore/src/test_helpers.rs +++ b/crates/ethcore/src/test_helpers.rs @@ -690,14 +690,14 @@ pub struct TestNotify { impl ChainNotify for TestNotify { fn broadcast(&self, message: ChainMessageType) { let data = match message { - ChainMessageType::Consensus(data) => data, + ChainMessageType::Consensus(_message, data) => data, }; self.messages.write().push(data); } fn send(&self, message: ChainMessageType, node_id: &H512) { let data = match message { - ChainMessageType::Consensus(data) => data, + ChainMessageType::Consensus(_message, data) => data, }; self.targeted_messages .write() From d3190e93d79e51d84599c71b277570069d999785 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jul 2025 18:02:09 +0200 Subject: [PATCH 608/687] fixed tests to apply to latest changes --- crates/ethcore/sync/src/tests/helpers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/sync/src/tests/helpers.rs b/crates/ethcore/sync/src/tests/helpers.rs index aee9124e8..8131754ee 100644 --- a/crates/ethcore/sync/src/tests/helpers.rs +++ b/crates/ethcore/sync/src/tests/helpers.rs @@ -276,7 +276,7 @@ where fn process_io_message(&self, message: ChainMessageType) { let mut io = TestIo::new(&*self.chain, &self.snapshot_service, &self.queue, None); match message { - ChainMessageType::Consensus(data) => { + ChainMessageType::Consensus(_block, data) => { self.sync.write().propagate_consensus_packet(&mut io, data) } } From 87b953b5f5bc5e88704f8457f2638723e60d0a28 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Jul 2025 00:06:13 +0200 Subject: [PATCH 609/687] reduced grace period for soft shutdown to 5 seconds (from 90 seconds) --- bin/oe/run.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 691a813d3..5e919bafa 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -716,15 +716,13 @@ impl RunningClient { std::thread::Builder::new() .name("diamond-node-force-quit".to_string()) .spawn(move || { + + let duration_soft = 5; // we make a force quit if after 90 seconds, if this shutdown routine - std::thread::sleep(Duration::from_secs(30)); - warn!(target: "shutdown", "shutdown not happened within 30 seconds, waiting for 60 seconds before force exiting the process."); - std::thread::sleep(Duration::from_secs(50)); - warn!(target: "shutdown", "force exit in 10 seconds."); - std::thread::sleep(Duration::from_secs(10)); - warn!(target: "shutdown", "force exiting now."); + std::thread::sleep(Duration::from_secs(duration_soft)); + warn!(target: "shutdown", "shutdown not happened within {duration_soft} seconds, starting force exiting the process."); + std::thread::sleep(Duration::from_secs(1)); std::process::exit(1); - // Wait for the shutdown manager to finish }) .expect("Failed to spawn Force shutdown thread"); From ab70ac5995ed3e35a2e96d2f891e199b7376e116 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Jul 2025 23:39:10 +0200 Subject: [PATCH 610/687] release preparation 0.11.7 --- CHANGELOG.md | 7 +++++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/net/network-devp2p/src/session_container.rs | 2 +- crates/util/version/Cargo.toml | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b8ce468..2476a8076 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## Diamond Node Software 3.3.5-hbbft-0.11.7 +- [Handshake and Session Management improvements](https://github.com/DMDcoin/diamond-node/issues/262) +- [Reliable Message Broadcast Protocol: message_cache of SyncProtocolHandler does not get cleaned up](https://github.com/DMDcoin/diamond-node/issues/261) +- reduced log outputs for RMBP cached messages +- Fix possible deadlock in deregister_session_stream in combination with session_readable +- reduce timings for shutdown from 90 seconds to 5 seconds, so auto restart of nodes in deadlock cases is faster + ## Diamond Node Software 3.3.5-hbbft-0.11.6 - [session double kill problem.](https://github.com/DMDcoin/diamond-node/issues/252) - [Network Host logic: peer_id to NodeID consistency](https://github.com/DMDcoin/diamond-node/issues/251) diff --git a/Cargo.lock b/Cargo.lock index b7983c1f5..1b7c91618 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.6" +version = "3.3.5-hbbft-0.11.7" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3578,7 +3578,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.6" +version = "3.3.5-hbbft-0.11.7" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 437ba8b1c..2342aaa01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.6" +version = "3.3.5-hbbft-0.11.7" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 2f72b4029..30d18a93b 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -20,7 +20,7 @@ fn socket_address_to_string(socket: &TcpStream) -> String { /// It has high performance lookup capabilities for NodeIDs by using a hashmap, instead of linear locking iteration of sessions. pub struct SessionContainer { max_sessions: usize, - max_handshakes: usize, // New field to limit concurrent handshakes + max_handshakes: usize, first_handshake: usize, last_handshake: usize, // the handshake cursor is a improvement to find new available handshake slots. it defines the next starting search position. diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index a6e705738..62c86d674 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.6" +version = "3.3.5-hbbft-0.11.7" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 8278e2d3f328d8e4c65f7296e0eb4ef048c0fd67 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Aug 2025 00:01:04 +0200 Subject: [PATCH 611/687] fixed by using the handshake lock in host as critical section for deregistering both, the handshake, and the session stream. https://github.com/DMDcoin/diamond-node/issues/267 --- crates/net/network-devp2p/src/host.rs | 8 +++- .../network-devp2p/src/session_container.rs | 45 ++++++++++++++----- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index f8d6f7cc3..a94c995ec 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -1613,7 +1613,13 @@ impl IoHandler for Host { event_loop: &mut EventLoop>, ) { match stream { - FIRST_HANDSHAKE.. => { + FIRST_HANDSHAKE..FIRST_SESSION => { + let _handhake_lock = self.handshake_lock.lock(); // we do not allow new handshakes to get processed during deregistering a stream. + self.sessions + .deregister_handshake_stream(stream, event_loop); + } + FIRST_SESSION..=LAST_SESSION => { + let _handhake_lock = self.handshake_lock.lock(); // since finalizing handshakes is the only way to promot a handshake to a session, we also block handshakes here. self.sessions.deregister_session_stream(stream, event_loop); } DISCOVERY => (), diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 30d18a93b..8cc1f73ae 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -6,7 +6,7 @@ use std::{collections::BTreeMap, sync::Arc, time::Duration}; use crate::{io::*, node_table::*, session::Session}; use network::{Error, ErrorKind, NetworkIoMessage, PeerId}; -use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockUpgradableReadGuard}; +use parking_lot::{Mutex, RwLock, RwLockReadGuard}; pub type SharedSession = Arc>; @@ -430,28 +430,53 @@ impl SessionContainer { return None; } + pub(crate) fn deregister_handshake_stream( + &self, + stream: usize, + event_loop: &mut mio::deprecated::EventLoop, + ) { + if stream < self.first_handshake || stream >= self.last_handshake { + warn!(target: "network", "Tried to deregister handshake stream {} but it is out of range.", stream); + return; + } + + if let Some(connection) = self.get_handshake(stream) { + let c = connection.lock(); + if c.expired() { + // make sure it is the same connection that the event was generated for + c.deregister_socket(event_loop) + .expect("Error deregistering socket"); + drop(c); + + self.handshakes.write().remove(&stream); + //RwLockUpgradableReadGuard::<'_, parking_lot::RawRwLock, BTreeMap>>>::upgrade(connections).remove(&stream); + } else { + debug!(target: "network", "Tried to deregister session stream {} but it is not expired.", stream); + } + } else { + debug!(target: "network", "Tried to deregister session stream {} but it does not exist.", stream); + } + } + pub(crate) fn deregister_session_stream( &self, stream: usize, event_loop: &mut mio::deprecated::EventLoop, ) { - let connections = if stream < self.last_handshake { - self.handshakes.upgradable_read() - } else { - self.sessions.upgradable_read() - }; + if stream < self.last_handshake + 1 { + warn!(target: "network", "Tried to deregister session stream {} but it is out of range.", stream); + return; + } - if let Some(connection) = connections.get(&stream).cloned() { + if let Some(connection) = self.get_session(stream) { let c = connection.lock(); if c.expired() { // make sure it is the same connection that the event was generated for c.deregister_socket(event_loop) .expect("Error deregistering socket"); drop(c); - let mut connections_write = RwLockUpgradableReadGuard::upgrade(connections); - connections_write.remove(&stream); - //RwLockUpgradableReadGuard::<'_, parking_lot::RawRwLock, BTreeMap>>>::upgrade(connections).remove(&stream); + self.sessions.write().remove(&stream); } else { debug!(target: "network", "Tried to deregister session stream {} but it is not expired.", stream); } From 2e6e129a76858d74e3fae3516981865524b84fb6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Aug 2025 00:17:25 +0200 Subject: [PATCH 612/687] version 0.11.8 --- CHANGELOG.md | 3 +++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2476a8076..95d547ac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## Diamond Node Software 3.3.5-hbbft-0.11.8 +- [deregister_session_stream can cause deadlocks](https://github.com/DMDcoin/diamond-node/issues/267) + ## Diamond Node Software 3.3.5-hbbft-0.11.7 - [Handshake and Session Management improvements](https://github.com/DMDcoin/diamond-node/issues/262) - [Reliable Message Broadcast Protocol: message_cache of SyncProtocolHandler does not get cleaned up](https://github.com/DMDcoin/diamond-node/issues/261) diff --git a/Cargo.lock b/Cargo.lock index 1b7c91618..d153a3fd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.7" +version = "3.3.5-hbbft-0.11.8" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3578,7 +3578,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.7" +version = "3.3.5-hbbft-0.11.8" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 2342aaa01..e881d5eb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.7" +version = "3.3.5-hbbft-0.11.8" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 62c86d674..1a9d3bb19 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.7" +version = "3.3.5-hbbft-0.11.8" authors = [ "bit.diamonds developers", "OpenEthereum developers", From c300eaa709bffa0557b58069c2dfcf8973697bf1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Aug 2025 15:52:07 +0200 Subject: [PATCH 613/687] improved logging for deregister_handshake_stream --- crates/net/network-devp2p/src/session_container.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 8cc1f73ae..d2032c11a 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -451,10 +451,10 @@ impl SessionContainer { self.handshakes.write().remove(&stream); //RwLockUpgradableReadGuard::<'_, parking_lot::RawRwLock, BTreeMap>>>::upgrade(connections).remove(&stream); } else { - debug!(target: "network", "Tried to deregister session stream {} but it is not expired.", stream); + debug!(target: "network", "Tried to deregister handshake stream {} but it is not expired.", stream); } } else { - debug!(target: "network", "Tried to deregister session stream {} but it does not exist.", stream); + debug!(target: "network", "Tried to deregister handshake stream {} but it does not exist.", stream); } } From 1d208200ae17c30550367d61810d185fda45f585 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Aug 2025 23:03:09 +0200 Subject: [PATCH 614/687] fixed i270 - not joining hbbft epoch after sync has finished --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 9409000ea..1a52ff1d5 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -102,6 +102,7 @@ pub struct HoneyBadgerBFT { current_minimum_gas_price: Mutex>, early_epoch_manager: Mutex>, hbbft_engine_cache: Mutex, + delayed_hbbft_join: AtomicBool, } struct TransitionHandler { @@ -292,6 +293,17 @@ impl TransitionHandler { // Periodically allow messages received for future epochs to be processed. self.engine.replay_cached_messages(); + // rejoin Hbbft Epoch after sync was completed. + if self + .engine + .delayed_hbbft_join + .load(std::sync::atomic::Ordering::SeqCst) + { + if let Err(e) = self.engine.join_hbbft_epoch() { + error!(target: "engine", "Error trying to join epoch after synced: {}", e); + } + } + self.handle_shutdown_on_missing_block_import(shutdown_on_missing_block_import_config); let mut timer_duration = self.min_block_time_remaining(client.clone()); @@ -456,7 +468,7 @@ impl HoneyBadgerBFT { machine, hbbft_state: RwLock::new(HbbftState::new()), hbbft_message_dispatcher: HbbftMessageDispatcher::new( - params.blocks_to_keep_on_disk.unwrap_or(0), + params.blocks_to_keep_on_disk.unwrap_or(1), params .blocks_to_keep_directory .clone() @@ -469,7 +481,7 @@ impl HoneyBadgerBFT { ), sealing: RwLock::new(BTreeMap::new()), params, - message_counter: Mutex::new(0), + message_counter: Mutex::new(0), // restore message counter from memory here for RBC ? */ random_numbers: RwLock::new(BTreeMap::new()), keygen_transaction_sender: RwLock::new(KeygenTransactionSender::new()), @@ -477,6 +489,7 @@ impl HoneyBadgerBFT { current_minimum_gas_price: Mutex::new(None), early_epoch_manager: Mutex::new(None), hbbft_engine_cache: Mutex::new(HbbftEngineCache::new()), + delayed_hbbft_join: AtomicBool::new(false), }); if !engine.params.is_unit_test.unwrap_or(false) { @@ -496,6 +509,8 @@ impl HoneyBadgerBFT { .hbbft_peers_service .register_handler(Arc::new(peers_handler))?; + // todo: + // setup rev Ok(engine) } @@ -810,9 +825,18 @@ impl HoneyBadgerBFT { let client = self.client_arc().ok_or(EngineError::RequiresClient)?; if self.is_syncing(&client) { trace!(target: "consensus", "tried to join HBBFT Epoch, but still syncing."); + self.delayed_hbbft_join + .store(true, std::sync::atomic::Ordering::SeqCst); return Ok(()); } + if self + .delayed_hbbft_join + .swap(false, std::sync::atomic::Ordering::SeqCst) + { + trace!(target: "consensus", "continued join_hbbft_epoch after sync was completed."); + } + let step = self .hbbft_state .write() @@ -1295,6 +1319,9 @@ impl Engine for HoneyBadgerBFT { error!(target: "engine", "hbbft-hardfork : could not initialialize hardfork manager, no latest block found."); } + // RBC: we need to replay disk cached messages here. + // state.replay_cached_messages(client) + match state.update_honeybadger( client, &self.signer, @@ -1664,6 +1691,7 @@ mod tests { let mut builder: HoneyBadgerBuilder = HoneyBadger::builder(Arc::new(net_info.clone())); + builder.max_future_epochs(20); let mut honey_badger = builder.build(); From 208d12b65d3becc52681353d328ddfa851c7693d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Aug 2025 23:07:49 +0200 Subject: [PATCH 615/687] defaulting to not store outgoing hbbft messages on disk --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 1a52ff1d5..c393ce0b3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -468,7 +468,7 @@ impl HoneyBadgerBFT { machine, hbbft_state: RwLock::new(HbbftState::new()), hbbft_message_dispatcher: HbbftMessageDispatcher::new( - params.blocks_to_keep_on_disk.unwrap_or(1), + params.blocks_to_keep_on_disk.unwrap_or(0), params .blocks_to_keep_directory .clone() From 5a1918c8ca6ca032a92d1806121782869e6af6b9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Aug 2025 23:03:09 +0200 Subject: [PATCH 616/687] fixed i270 - not joining hbbft epoch after sync has finished --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 9409000ea..1a52ff1d5 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -102,6 +102,7 @@ pub struct HoneyBadgerBFT { current_minimum_gas_price: Mutex>, early_epoch_manager: Mutex>, hbbft_engine_cache: Mutex, + delayed_hbbft_join: AtomicBool, } struct TransitionHandler { @@ -292,6 +293,17 @@ impl TransitionHandler { // Periodically allow messages received for future epochs to be processed. self.engine.replay_cached_messages(); + // rejoin Hbbft Epoch after sync was completed. + if self + .engine + .delayed_hbbft_join + .load(std::sync::atomic::Ordering::SeqCst) + { + if let Err(e) = self.engine.join_hbbft_epoch() { + error!(target: "engine", "Error trying to join epoch after synced: {}", e); + } + } + self.handle_shutdown_on_missing_block_import(shutdown_on_missing_block_import_config); let mut timer_duration = self.min_block_time_remaining(client.clone()); @@ -456,7 +468,7 @@ impl HoneyBadgerBFT { machine, hbbft_state: RwLock::new(HbbftState::new()), hbbft_message_dispatcher: HbbftMessageDispatcher::new( - params.blocks_to_keep_on_disk.unwrap_or(0), + params.blocks_to_keep_on_disk.unwrap_or(1), params .blocks_to_keep_directory .clone() @@ -469,7 +481,7 @@ impl HoneyBadgerBFT { ), sealing: RwLock::new(BTreeMap::new()), params, - message_counter: Mutex::new(0), + message_counter: Mutex::new(0), // restore message counter from memory here for RBC ? */ random_numbers: RwLock::new(BTreeMap::new()), keygen_transaction_sender: RwLock::new(KeygenTransactionSender::new()), @@ -477,6 +489,7 @@ impl HoneyBadgerBFT { current_minimum_gas_price: Mutex::new(None), early_epoch_manager: Mutex::new(None), hbbft_engine_cache: Mutex::new(HbbftEngineCache::new()), + delayed_hbbft_join: AtomicBool::new(false), }); if !engine.params.is_unit_test.unwrap_or(false) { @@ -496,6 +509,8 @@ impl HoneyBadgerBFT { .hbbft_peers_service .register_handler(Arc::new(peers_handler))?; + // todo: + // setup rev Ok(engine) } @@ -810,9 +825,18 @@ impl HoneyBadgerBFT { let client = self.client_arc().ok_or(EngineError::RequiresClient)?; if self.is_syncing(&client) { trace!(target: "consensus", "tried to join HBBFT Epoch, but still syncing."); + self.delayed_hbbft_join + .store(true, std::sync::atomic::Ordering::SeqCst); return Ok(()); } + if self + .delayed_hbbft_join + .swap(false, std::sync::atomic::Ordering::SeqCst) + { + trace!(target: "consensus", "continued join_hbbft_epoch after sync was completed."); + } + let step = self .hbbft_state .write() @@ -1295,6 +1319,9 @@ impl Engine for HoneyBadgerBFT { error!(target: "engine", "hbbft-hardfork : could not initialialize hardfork manager, no latest block found."); } + // RBC: we need to replay disk cached messages here. + // state.replay_cached_messages(client) + match state.update_honeybadger( client, &self.signer, @@ -1664,6 +1691,7 @@ mod tests { let mut builder: HoneyBadgerBuilder = HoneyBadger::builder(Arc::new(net_info.clone())); + builder.max_future_epochs(20); let mut honey_badger = builder.build(); From 4eea2efce9cba8b0efab034c6fd0c970ce40d226 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Aug 2025 23:07:49 +0200 Subject: [PATCH 617/687] defaulting to not store outgoing hbbft messages on disk --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 1a52ff1d5..c393ce0b3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -468,7 +468,7 @@ impl HoneyBadgerBFT { machine, hbbft_state: RwLock::new(HbbftState::new()), hbbft_message_dispatcher: HbbftMessageDispatcher::new( - params.blocks_to_keep_on_disk.unwrap_or(1), + params.blocks_to_keep_on_disk.unwrap_or(0), params .blocks_to_keep_directory .clone() From 60274cb6e5544703105f3612e2c3955f4ac41a9f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Aug 2025 01:10:10 +0200 Subject: [PATCH 618/687] updated test_single_contribution to use max_future_epochs 0. Proofs that configuring HBBFT works in this scenario. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index c393ce0b3..d92c9e4d5 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1691,7 +1691,7 @@ mod tests { let mut builder: HoneyBadgerBuilder = HoneyBadger::builder(Arc::new(net_info.clone())); - builder.max_future_epochs(20); + builder.max_future_epochs(0); let mut honey_badger = builder.build(); From 57223e50a7853c67211aabb39fb9b37923ae45d6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Aug 2025 23:03:09 +0200 Subject: [PATCH 619/687] fixed i270 - not joining hbbft epoch after sync has finished --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index c393ce0b3..1a52ff1d5 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -468,7 +468,7 @@ impl HoneyBadgerBFT { machine, hbbft_state: RwLock::new(HbbftState::new()), hbbft_message_dispatcher: HbbftMessageDispatcher::new( - params.blocks_to_keep_on_disk.unwrap_or(0), + params.blocks_to_keep_on_disk.unwrap_or(1), params .blocks_to_keep_directory .clone() From 205e252f47982971ac3457f58f7c066a602361bc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 Aug 2025 23:07:49 +0200 Subject: [PATCH 620/687] defaulting to not store outgoing hbbft messages on disk --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 1a52ff1d5..c393ce0b3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -468,7 +468,7 @@ impl HoneyBadgerBFT { machine, hbbft_state: RwLock::new(HbbftState::new()), hbbft_message_dispatcher: HbbftMessageDispatcher::new( - params.blocks_to_keep_on_disk.unwrap_or(1), + params.blocks_to_keep_on_disk.unwrap_or(0), params .blocks_to_keep_directory .clone() From d2e5d4ca4cbb20b1687a1dc316c8699c4f41d290 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 14 Aug 2025 01:10:10 +0200 Subject: [PATCH 621/687] updated test_single_contribution to use max_future_epochs 0. Proofs that configuring HBBFT works in this scenario. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index c393ce0b3..d92c9e4d5 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1691,7 +1691,7 @@ mod tests { let mut builder: HoneyBadgerBuilder = HoneyBadger::builder(Arc::new(net_info.clone())); - builder.max_future_epochs(20); + builder.max_future_epochs(0); let mut honey_badger = builder.build(); From 4769b3812c890c034ef9dc33cb2c4741c4804213 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Aug 2025 15:52:07 +0200 Subject: [PATCH 622/687] improved logging for deregister_handshake_stream --- crates/net/network-devp2p/src/session_container.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index 8cc1f73ae..d2032c11a 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -451,10 +451,10 @@ impl SessionContainer { self.handshakes.write().remove(&stream); //RwLockUpgradableReadGuard::<'_, parking_lot::RawRwLock, BTreeMap>>>::upgrade(connections).remove(&stream); } else { - debug!(target: "network", "Tried to deregister session stream {} but it is not expired.", stream); + debug!(target: "network", "Tried to deregister handshake stream {} but it is not expired.", stream); } } else { - debug!(target: "network", "Tried to deregister session stream {} but it does not exist.", stream); + debug!(target: "network", "Tried to deregister handshake stream {} but it does not exist.", stream); } } From 5e5653e4e377a9d714aa72fa348e79ec4dcda3c7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 18 Aug 2025 16:21:29 +0200 Subject: [PATCH 623/687] downgrated log level for "Detected an attempt to send a hbbft contribution for block" --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index b0ea11928..6be2dd13f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -429,7 +429,7 @@ impl HbbftState { if let Some(latest_block) = client.block_number(BlockId::Latest) { if honey_badger.epoch() != latest_block + 1 { - info!(target: "consensus", "Detected an attempt to send a hbbft contribution for block {} before the previous block was imported to the chain. (latest block: {})", honey_badger.epoch(), latest_block); + debug!(target: "consensus", "Detected an attempt to send a hbbft contribution for block {} before the previous block was imported to the chain. (latest block: {})", honey_badger.epoch(), latest_block); return None; } } From cd3de731aa65050287f0380a9538c7f80dcd6802 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 27 Aug 2025 23:49:26 +0200 Subject: [PATCH 624/687] fixed race condition: https://github.com/DMDcoin/diamond-node/issues/275 --- crates/ethcore/sync/src/api.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index 16143901b..a8779fd54 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -592,6 +592,11 @@ impl NetworkProtocolHandler for SyncProtocolHandler { } fn read(&self, io: &dyn NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) { + let session_info = io.session_info(*peer); + if session_info.is_none() { + debug!(target: "sync", "Received packet from peer, where no Session info is available anymore (was just disconnected ??): {peer}"); + return; + } let node_id = io.session_info(*peer).unwrap().id; self.sync.dispatch_packet( &mut NetSyncIo::new(io, &*self.chain, &*self.snapshot_service, &self.overlay), From 35c2f5fca2b86c6624597f6bb2e6e7d1fb2472bc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 27 Aug 2025 23:52:16 +0200 Subject: [PATCH 625/687] setting block author ini process output --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 04f1b6452..a1629480b 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -595,9 +595,14 @@ impl HoneyBadgerBFT { .write() .insert(batch.epoch, random_number); - if let Some(header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) { + if let Some(mut header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) { let block_num = header.number(); let hash = header.bare_hash(); + if let Some(reward_contract_address) = self.params.block_reward_contract_address { + header.set_author(reward_contract_address); + } else { + warn!("Creating block with no blockRewardContractAddress {}", block_num); + } // TODO: trace is missleading here: we already got the signature shares, we can already trace!(target: "consensus", "Sending signature share of {} for block {}", hash, block_num); let step = match self @@ -1558,6 +1563,7 @@ impl Engine for HoneyBadgerBFT { if let Some(address) = self.params.block_reward_contract_address { // only if no block reward skips are defined for this block. let header_number = block.header.number(); + block.header.set_author(address); if self .params From a14279ebe405f0d07d6c57089b570fda2d813abb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Aug 2025 20:56:52 +0200 Subject: [PATCH 626/687] Transaction fee distribution: Introduced BlockAuthorOption: Engines are now able to specify who is the block author via BlockAuthorOption::EngineBlockAuthor(Address), --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 22 +++++++++---------- crates/ethcore/src/engines/mod.rs | 16 ++++++++++++-- crates/ethcore/src/miner/miner.rs | 8 +++---- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index a1629480b..9c37dba5d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -11,7 +11,8 @@ use crate::{ traits::{EngineClient, ForceUpdateSealing}, }, engines::{ - Engine, EngineError, ForkChoice, Seal, SealingState, default_system_or_code_call, + BlockAuthorOption, Engine, EngineError, ForkChoice, Seal, SealingState, + default_system_or_code_call, hbbft::{ contracts::random_hbbft::set_current_seed_tx_raw, hbbft_message_memorium::BadSealReason, }, @@ -595,14 +596,9 @@ impl HoneyBadgerBFT { .write() .insert(batch.epoch, random_number); - if let Some(mut header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) { + if let Some(header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) { let block_num = header.number(); let hash = header.bare_hash(); - if let Some(reward_contract_address) = self.params.block_reward_contract_address { - header.set_author(reward_contract_address); - } else { - warn!("Creating block with no blockRewardContractAddress {}", block_num); - } // TODO: trace is missleading here: we already got the signature shares, we can already trace!(target: "consensus", "Sending signature share of {} for block {}", hash, block_num); let step = match self @@ -795,7 +791,7 @@ impl HoneyBadgerBFT { .map(|msg| msg.map(|m| Message::Sealing(block_num, m))); self.dispatch_messages(&client, messages, network_info); if let Some(sig) = step.output.into_iter().next() { - trace!(target: "consensus", "Signature for block {} is ready", block_num); + trace!(target: "consensus", "Signature for block {} is ready.", block_num); let state = Sealing::Complete(sig); self.sealing.write().insert(block_num, state); @@ -1473,8 +1469,11 @@ impl Engine for HoneyBadgerBFT { false } - fn use_block_author(&self) -> bool { - true + fn use_block_author(&self) -> BlockAuthorOption { + if let Some(address) = self.params.block_reward_contract_address { + return BlockAuthorOption::EngineBlockAuthor(address); + } + return BlockAuthorOption::ConfiguredBlockAuthor; } fn on_before_transactions(&self, block: &mut ExecutedBlock) -> Result<(), Error> { @@ -1542,7 +1541,7 @@ impl Engine for HoneyBadgerBFT { /// Allow mutating the header during seal generation. fn on_seal_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> { - let random_numbers = self.random_numbers.read(); + let random_numbers = self.random_numbers.read(); match random_numbers.get(&block.header.number()) { None => { warn!("No rng value available for header."); @@ -1563,7 +1562,6 @@ impl Engine for HoneyBadgerBFT { if let Some(address) = self.params.block_reward_contract_address { // only if no block reward skips are defined for this block. let header_number = block.header.number(); - block.header.set_author(address); if self .params diff --git a/crates/ethcore/src/engines/mod.rs b/crates/ethcore/src/engines/mod.rs index 994a830b2..0135bb26b 100644 --- a/crates/ethcore/src/engines/mod.rs +++ b/crates/ethcore/src/engines/mod.rs @@ -305,6 +305,18 @@ pub enum EpochChange { Yes(Proof), } +/// who shall author a new Block ? +pub enum BlockAuthorOption { + /// use the Zero address as block author. + ZeroBlockAuthor, + + /// use the block author from the config. + ConfiguredBlockAuthor, + + /// use the block author provivided by the EngineClient. + EngineBlockAuthor(Address), +} + /// A consensus mechanism for the chain. Generally either proof-of-work or proof-of-stake-based. /// Provides hooks into each of the major parts of block import. pub trait Engine: Sync + Send { @@ -581,8 +593,8 @@ pub trait Engine: Sync + Send { } /// Use the author as signer as well as block author. - fn use_block_author(&self) -> bool { - true + fn use_block_author(&self) -> BlockAuthorOption { + BlockAuthorOption::ConfiguredBlockAuthor } /// allows engines to define a block that should not get pruned in the DB. diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 70f794e04..32212d73b 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -463,10 +463,10 @@ impl Miner { let params = self.params.read().clone(); let block = match chain.prepare_open_block( - if self.engine.use_block_author() { - params.author - } else { - Address::zero() + match self.engine.use_block_author() { + crate::engines::BlockAuthorOption::ZeroBlockAuthor => Address::zero(), + crate::engines::BlockAuthorOption::ConfiguredBlockAuthor => params.author, + crate::engines::BlockAuthorOption::EngineBlockAuthor(address) => address, }, params.gas_range_target, params.extra_data, From 8db15af83f5776e7fc2cac99e203f3b1b4d51c00 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 4 Sep 2025 14:13:45 +0200 Subject: [PATCH 627/687] increased MAX_HANDSHAKES from 99 to 1999 --- crates/net/network-devp2p/src/host.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index a94c995ec..4f1c57191 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -57,7 +57,7 @@ use parking_lot::{Mutex, RwLock}; use stats::{PrometheusMetrics, PrometheusRegistry}; const MAX_SESSIONS: usize = 2048; -const MAX_HANDSHAKES: usize = 99; +const MAX_HANDSHAKES: usize = 1999; const DEFAULT_PORT: u16 = 30303; From ab3317a36f5f4bb4bc8885f3413821392cdfaefe Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Sep 2025 13:11:07 +0200 Subject: [PATCH 628/687] reapplied changes --- crates/ethcore/sync/src/api.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/api.rs b/crates/ethcore/sync/src/api.rs index a8779fd54..5c8d61647 100644 --- a/crates/ethcore/sync/src/api.rs +++ b/crates/ethcore/sync/src/api.rs @@ -594,7 +594,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler { fn read(&self, io: &dyn NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) { let session_info = io.session_info(*peer); if session_info.is_none() { - debug!(target: "sync", "Received packet from peer, where no Session info is available anymore (was just disconnected ??): {peer}"); + debug!(target: "sync", "Received packet from peer, where no Session info is available anymore (was just disconnected ?): {peer}"); return; } let node_id = io.session_info(*peer).unwrap().id; @@ -614,7 +614,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler { .unwrap_or_else(|| panic!("peer not found: {peer}")) .id; if io.is_reserved_peer(*peer) { - trace!(target: "sync", "Connected to reserved peer {node_id:?} {peer}" ); + debug!(target: "sync", "Connected to reserved peer {node_id:?} {peer}" ); } // If warp protocol is supported only allow warp handshake let warp_protocol = io.protocol_version(PAR_PROTOCOL, *peer).unwrap_or(0) != 0; @@ -630,7 +630,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler { fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId) { trace_time!("sync::disconnected"); if io.is_reserved_peer(*peer) { - warn!(target: "sync", "Disconnected from reserved peer peerID: {} protocol: {} peer: {}",peer , io.subprotocol_name(), io.session_info(*peer).expect("").id.map_or("".to_string(), |f| format!("{:?}", f))); + debug!(target: "sync", "Disconnected from reserved peer peerID: {} protocol: {} peer: {}",peer , io.subprotocol_name(), io.session_info(*peer).expect("").id.map_or("".to_string(), |f| format!("{:?}", f))); } if io.subprotocol_name() != PAR_PROTOCOL { self.sync.write().on_peer_aborting( From 3c9e0e18945c98609db0f945750cc919fb186197 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Sep 2025 15:47:55 +0200 Subject: [PATCH 629/687] prometheus update to 0.14 --- Cargo.lock | 88 +++++++++++++++++++++++++----------- Cargo.toml | 2 +- crates/util/stats/Cargo.toml | 2 +- 3 files changed, 63 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d153a3fd8..89f1b9609 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -784,9 +784,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.5" +version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" dependencies = [ "darling_core", "darling_macro", @@ -794,23 +794,23 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.5" +version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" dependencies = [ "fnv", "ident_case", "proc-macro2 1.0.94", "quote 1.0.40", - "strsim 0.10.0", + "strsim 0.11.1", "syn 2.0.100", ] [[package]] name = "darling_macro" -version = "0.20.5" +version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ "darling_core", "quote 1.0.40", @@ -1003,7 +1003,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "thiserror", + "thiserror 1.0.69", "validator", "validator_derive", ] @@ -2140,7 +2140,7 @@ dependencies = [ "rand_derive", "reed-solomon-erasure", "serde", - "thiserror", + "thiserror 1.0.69", "threshold_crypto", "tiny-keccak 2.0.2", ] @@ -2177,7 +2177,7 @@ dependencies = [ "proptest", "rand 0.7.3", "rand_xorshift 0.2.0", - "thiserror", + "thiserror 1.0.69", "threshold_crypto", ] @@ -3277,9 +3277,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.4.0" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "opaque-debug" @@ -3361,7 +3361,7 @@ dependencies = [ "libc", "log", "mio", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -3928,9 +3928,9 @@ dependencies = [ [[package]] name = "prometheus" -version = "0.13.3" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" +checksum = "3ca5326d8d0b950a9acd87e6a3f94745394f62e4dae1b1ee22b2bc0c394af43a" dependencies = [ "cfg-if 1.0.0", "fnv", @@ -3938,7 +3938,7 @@ dependencies = [ "memchr", "parking_lot 0.12.1", "protobuf", - "thiserror", + "thiserror 2.0.16", ] [[package]] @@ -3963,9 +3963,23 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.16.2" +version = "3.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d65a1d4ddae7d8b5de68153b48f6aa3bba8cb002b243dbdbc55a5afbc98f99f4" +dependencies = [ + "once_cell", + "protobuf-support", + "thiserror 1.0.69", +] + +[[package]] +name = "protobuf-support" +version = "3.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d883f78645c21b7281d21305181aa1f4dd9e9363e7cf2566c93121552cff003e" +checksum = "3e36c2f31e0a47f9280fb347ef5e461ffcd2c52dd520d8e216b52f93b0b0d7d6" +dependencies = [ + "thiserror 1.0.69", +] [[package]] name = "pulldown-cmark" @@ -4821,9 +4835,9 @@ checksum = "032c03039aae92b350aad2e3779c352e104d919cb192ba2fabbd7b831ce4f0f6" [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "subtle" @@ -4972,22 +4986,42 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.20" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" +dependencies = [ + "thiserror-impl 2.0.16", ] [[package]] name = "thiserror-impl" -version = "1.0.20" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2 1.0.94", "quote 1.0.40", - "syn 1.0.94", + "syn 2.0.100", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960" +dependencies = [ + "proc-macro2 1.0.94", + "quote 1.0.40", + "syn 2.0.100", ] [[package]] @@ -5032,7 +5066,7 @@ dependencies = [ "rand 0.7.3", "rand_chacha 0.2.1", "serde", - "thiserror", + "thiserror 1.0.69", "tiny-keccak 2.0.2", "zeroize", ] diff --git a/Cargo.toml b/Cargo.toml index e881d5eb6..9993cfcfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,7 @@ kvdb = "0.1" kvdb-rocksdb = "0.1.3" journaldb = { path = "crates/db/journaldb" } stats = { path = "crates/util/stats" } -prometheus = "0.13.3" +prometheus = "0.14" fs-swap = "0.2.6" net2 = "0.2.38" diff --git a/crates/util/stats/Cargo.toml b/crates/util/stats/Cargo.toml index 18b954bbf..462302e3d 100644 --- a/crates/util/stats/Cargo.toml +++ b/crates/util/stats/Cargo.toml @@ -6,5 +6,5 @@ edition = "2018" [dependencies] log = "0.4" -prometheus = "0.13.3" +prometheus = "0.14" vergen = "0.1" \ No newline at end of file From 17e404e0d72ebd6a0086e82e69d64809db78c961 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Sep 2025 21:24:16 +0200 Subject: [PATCH 630/687] version update to 0.12.0. reduced max Payloads again. --- CHANGELOG.md | 8 ++++++++ Cargo.lock | 5 +++-- Cargo.toml | 2 +- crates/net/network-devp2p/src/connection.rs | 6 +++--- crates/net/network/Cargo.toml | 1 + crates/net/network/src/client_version.rs | 19 +++++-------------- crates/util/version/Cargo.toml | 2 +- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95d547ac3..2203c9c51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## Diamond Node Software 0.12.0 + +- New Versioning Scheme: Since Open Ethereum did not get a new update, diamond-node will not mention 3.3.5 anymore +- [race condition: Incoming data from peer that gets disconnected leads to crash](https://github.com/DMDcoin/diamond-node/issues/275) +- [not joining hbbft epoch after sync has finished](https://github.com/DMDcoin/diamond-node/issues/270) +- [diamond front running resistance](https://github.com/DMDcoin/diamond-node/issues/89) +- [Transaction fees distribution](https://github.com/DMDcoin/diamond-node/issues/40) + ## Diamond Node Software 3.3.5-hbbft-0.11.8 - [deregister_session_stream can cause deadlocks](https://github.com/DMDcoin/diamond-node/issues/267) diff --git a/Cargo.lock b/Cargo.lock index 89f1b9609..1e58f09e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "3.3.5-hbbft-0.11.8" +version = "0.12.0" dependencies = [ "ansi_term 0.10.2", "atty", @@ -1476,6 +1476,7 @@ dependencies = [ "ipnetwork", "lazy_static", "libc", + "log", "parity-crypto", "parity-snappy", "parity-version", @@ -3578,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "3.3.5-hbbft-0.11.8" +version = "0.12.0" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 9993cfcfc..ed2727cba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "3.3.5-hbbft-0.11.8" +version = "0.12.0" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/net/network-devp2p/src/connection.rs b/crates/net/network-devp2p/src/connection.rs index c268f97fc..783f1f860 100644 --- a/crates/net/network-devp2p/src/connection.rs +++ b/crates/net/network-devp2p/src/connection.rs @@ -43,12 +43,12 @@ use std::{ use tiny_keccak::Keccak; const ENCRYPTED_HEADER_LEN: usize = 32; -const RECEIVE_PAYLOAD: Duration = Duration::from_secs(600); -pub const MAX_PAYLOAD_SIZE: usize = (1 << 28) - 1; +const RECEIVE_PAYLOAD: Duration = Duration::from_secs(60); +pub const MAX_PAYLOAD_SIZE: usize = (1 << 26) - 1; /// Network responses should try not to go over this limit. /// This should be lower than MAX_PAYLOAD_SIZE -pub const PAYLOAD_SOFT_LIMIT: usize = (1 << 26) - 1; +pub const PAYLOAD_SOFT_LIMIT: usize = (1 << 22) - 1; pub trait GenericSocket: Read + Write {} diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index 0793b51e3..b6ee75a95 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -22,6 +22,7 @@ parity-snappy = "0.1" semver = {version="0.9.0", features=["serde"]} serde = "1.0" serde_derive = "1.0" +log = "0.4" [dev-dependencies] assert_matches = "1.2" diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index c944ed86d..a2a4779aa 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -16,9 +16,10 @@ //! Parse ethereum client ID strings and provide querying functionality -use semver::{Identifier, Version}; +use semver::{Version}; use std::fmt; + /// Parity client string prefix const LEGACY_CLIENT_ID_PREFIX: &str = "Parity-Ethereum"; const CURRENT_CLIENT_ID_PREFIX: &str = "OpenEthereum"; @@ -155,20 +156,10 @@ impl ClientCapabilities for ClientVersion { fn is_hbbft(&self) -> bool { match self { ClientVersion::ParityClient(client) => { - for id in client.semver.pre.iter() { - match id { - Identifier::AlphaNumeric(alpha) => { - if alpha.contains("hbbft") { - return true; - } - } - Identifier::Numeric(_) => {} - } - } - return false; + return client.name() == parity_version::NODE_SOFTWARE_NAME; } - ClientVersion::ParityUnknownFormat(_) => false, - ClientVersion::Other(_) => false, + ClientVersion::ParityUnknownFormat(_) => { false }, + ClientVersion::Other(_) => { false }, }; return false; } diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 1a9d3bb19..60bbfd7f2 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "3.3.5-hbbft-0.11.8" +version = "0.12.0" authors = [ "bit.diamonds developers", "OpenEthereum developers", From bdecc866052c57ed8c20f0514a1eb4f2762dc12a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Sep 2025 21:30:27 +0200 Subject: [PATCH 631/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/net/network/src/client_version.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index a2a4779aa..622913cea 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -16,10 +16,9 @@ //! Parse ethereum client ID strings and provide querying functionality -use semver::{Version}; +use semver::Version; use std::fmt; - /// Parity client string prefix const LEGACY_CLIENT_ID_PREFIX: &str = "Parity-Ethereum"; const CURRENT_CLIENT_ID_PREFIX: &str = "OpenEthereum"; @@ -158,8 +157,8 @@ impl ClientCapabilities for ClientVersion { ClientVersion::ParityClient(client) => { return client.name() == parity_version::NODE_SOFTWARE_NAME; } - ClientVersion::ParityUnknownFormat(_) => { false }, - ClientVersion::Other(_) => { false }, + ClientVersion::ParityUnknownFormat(_) => false, + ClientVersion::Other(_) => false, }; return false; } From 8f5f4f1a280c130fd5549302e7dbd62d7be930b4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Sep 2025 21:35:31 +0200 Subject: [PATCH 632/687] removed PARITY_CLIENT_LARGE_REQUESTS_VERSION, since all diamond-nodes support large requests --- crates/net/network/src/client_version.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index 622913cea..9984b5778 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -23,12 +23,6 @@ use std::fmt; const LEGACY_CLIENT_ID_PREFIX: &str = "Parity-Ethereum"; const CURRENT_CLIENT_ID_PREFIX: &str = "OpenEthereum"; -lazy_static! { -/// Parity versions starting from this will accept block bodies requests -/// of 256 bodies - static ref PARITY_CLIENT_LARGE_REQUESTS_VERSION: Version = Version::parse("2.4.0").unwrap(); -} - /// Description of the software version running in a peer /// according to https://github.com/ethereum/wiki/wiki/Client-Version-Strings /// This structure as it is represents the format used by Parity clients. Other @@ -55,9 +49,6 @@ impl ParityClientData { os: String, compiler: String, ) -> Self { - // Flags logic - let can_handle_large_requests = &semver >= &PARITY_CLIENT_LARGE_REQUESTS_VERSION; - // Instantiate and return ParityClientData { name: name, @@ -65,8 +56,7 @@ impl ParityClientData { semver: semver, os: os, compiler: compiler, - - can_handle_large_requests: can_handle_large_requests, + can_handle_large_requests: true, // all diamond-nodes can handle large requests } } @@ -120,7 +110,7 @@ impl Default for ClientVersion { /// Provide information about what a particular version of a /// peer software can do pub trait ClientCapabilities { - /// Parity versions before PARITY_CLIENT_LARGE_REQUESTS_VERSION would not + /// Old Parity versions would not /// check the accumulated size of a packet when building a response to a /// GET_BLOCK_BODIES request. If the packet was larger than a given limit, /// instead of sending fewer blocks no packet would get sent at all. Query From 06a2b44873990c8f42f0b6fc3137ac63d3be1574 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 13 Sep 2025 23:41:22 +0200 Subject: [PATCH 633/687] improved logging --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 1 + crates/ethcore/sync/src/chain/handler.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 6be2dd13f..9af0cecb1 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -122,6 +122,7 @@ impl HbbftState { // can be found. if let Some(last_block_number) = client.block_number(block_id) { + debug!(target: "engine", "Current Block: {}", last_block_number); if let Some(network_info) = self.fork_manager.should_fork( last_block_number, self.current_posdao_epoch, diff --git a/crates/ethcore/sync/src/chain/handler.rs b/crates/ethcore/sync/src/chain/handler.rs index ee2e1ffa3..a4a74f0ba 100644 --- a/crates/ethcore/sync/src/chain/handler.rs +++ b/crates/ethcore/sync/src/chain/handler.rs @@ -175,7 +175,7 @@ impl SyncHandler { debug!(target:"sync", "Disabling Peer (this Software Version not whitelisted) {} ip:{} ", peer_version, ip_addr); io.disable_peer(peer); } else if let Err(e) = sync.send_status(io, peer) { - debug!(target:"sync", "Error sending status request: {:?} {:?}", e, io.peer_session_info(peer).as_ref().map_or(" (no Session)", |f| f.remote_address.as_str())); + debug!(target:"sync", "Error sending status request: {peer} {:?} {e:?}", io.peer_session_info(peer).as_ref().map_or(" (no Session)", |f| f.remote_address.as_str())); io.disconnect_peer(peer); } else { sync.handshaking_peers.insert(peer, Instant::now()); From d41c32eb4fb7a1ff85b6c400b6997fbc7200b400 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 13 Sep 2025 23:41:47 +0200 Subject: [PATCH 634/687] cleanup: useless #[macro_use] --- crates/net/network/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index fbdcbca1c..c10c0f9f5 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -37,7 +37,6 @@ extern crate assert_matches; #[macro_use] extern crate error_chain; -#[macro_use] extern crate lazy_static; pub mod client_version; From 97c8c027442102e4857aae63a1c7f3fd9ba8e144 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 13 Sep 2025 23:55:51 +0200 Subject: [PATCH 635/687] session logging --- crates/net/network-devp2p/src/session.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/net/network-devp2p/src/session.rs b/crates/net/network-devp2p/src/session.rs index 47f131f36..bece885fb 100644 --- a/crates/net/network-devp2p/src/session.rs +++ b/crates/net/network-devp2p/src/session.rs @@ -324,7 +324,7 @@ impl Session { bail!(ErrorKind::BadProtocol); } if self.expired() { - debug!(target: "network", "Unable to send to expired session"); + debug!(target: "network", "Unable to send to expired session {}", self.token()); return Err(ErrorKind::Expired.into()); } let mut i = 0usize; From b827cbd5f7b30197a6891936a3828533bcc0a7fb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 13 Sep 2025 23:58:37 +0200 Subject: [PATCH 636/687] handshake refactor for session start, logging improvement --- crates/net/network-devp2p/src/handshake.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/net/network-devp2p/src/handshake.rs b/crates/net/network-devp2p/src/handshake.rs index 5ec866109..7c5cc9f45 100644 --- a/crates/net/network-devp2p/src/handshake.rs +++ b/crates/net/network-devp2p/src/handshake.rs @@ -144,7 +144,13 @@ impl Handshake { while let Some(data) = self.connection.readable()? { match self.state { HandshakeState::New => {} - HandshakeState::StartSession => {} + HandshakeState::StartSession => { + error!(target: "network", "starting session, clearing timer for {}", self.connection.token); + if let Err(e) = io.clear_timer(self.connection.token) { + debug!(target: "network", "failed to clear timer for session: {} {e:?}", self.connection.token); + } + break; + } HandshakeState::ReadingAuth => { self.read_auth(io, host.secret(), &data)?; } @@ -158,10 +164,6 @@ impl Handshake { self.read_ack_eip8(host.secret(), &data)?; } } - if self.state == HandshakeState::StartSession { - io.clear_timer(self.connection.token).ok(); - break; - } } Ok(()) } From 75419c312f6f8b705e1f918a4bf2a348747d7bf8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 13 Sep 2025 23:59:48 +0200 Subject: [PATCH 637/687] finalizing handshakes do not deregister streams anymore. --- crates/net/network-devp2p/src/session_container.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/net/network-devp2p/src/session_container.rs b/crates/net/network-devp2p/src/session_container.rs index d2032c11a..1ce747766 100644 --- a/crates/net/network-devp2p/src/session_container.rs +++ b/crates/net/network-devp2p/src/session_container.rs @@ -335,8 +335,6 @@ impl SessionContainer { return Err(ErrorKind::TooManyConnections.into()); } - io.deregister_stream(token)?; - // either we reuse an old token, or we create a new token. let upgraded_token = match node_ids_lock.get_mut(&node_id) { Some(t) => t.clone(), From 7250ccc47cc856694459de26fdf4756cf5627f2d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 14 Sep 2025 00:00:42 +0200 Subject: [PATCH 638/687] MAX_HANDSHAKES: 1899, this means, first real session ID become 2000. --- crates/net/network-devp2p/src/host.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/net/network-devp2p/src/host.rs b/crates/net/network-devp2p/src/host.rs index 4f1c57191..8fb8bae38 100644 --- a/crates/net/network-devp2p/src/host.rs +++ b/crates/net/network-devp2p/src/host.rs @@ -57,7 +57,7 @@ use parking_lot::{Mutex, RwLock}; use stats::{PrometheusMetrics, PrometheusRegistry}; const MAX_SESSIONS: usize = 2048; -const MAX_HANDSHAKES: usize = 1999; +const MAX_HANDSHAKES: usize = 1899; const DEFAULT_PORT: u16 = 30303; From 87fa3a456dd93298256a601832f72a36e0997b6c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 14 Sep 2025 02:05:34 +0200 Subject: [PATCH 639/687] Informant: current block number --- bin/oe/informant.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/oe/informant.rs b/bin/oe/informant.rs index 2c57b0a87..603ef8f88 100644 --- a/bin/oe/informant.rs +++ b/bin/oe/informant.rs @@ -273,7 +273,8 @@ impl Informant { false => t, }; - info!(target: "import", "{}{} {} {} {}", + info!(target: "import", "#{} {} {} {} {} {}", + chain_info.best_block_number /* Block */, match importing { true => match snapshot_sync { false => format!("Syncing {} {} {} {}+{} Qed", From c333637934f35cacf412d07268f0ff157e893f13 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 14 Sep 2025 02:05:45 +0200 Subject: [PATCH 640/687] Version update --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e58f09e4..3efc90138 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "0.12.0" +version = "0.12.1" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.0" +version = "0.12.1" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index ed2727cba..a762fab02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "0.12.0" +version = "0.12.1" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 60bbfd7f2..5c019eedd 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.0" +version = "0.12.1" authors = [ "bit.diamonds developers", "OpenEthereum developers", From cda5b9d926adba76d93e1c40819d3a57f3a22a92 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 14 Sep 2025 15:56:55 +0200 Subject: [PATCH 641/687] - Key Gen Transactions are now send more aggressivly. - Instead of waiting 3 Blocks they are send immeadially (risking they get reverted since the State DB of clients is not up to date) + version update --- CHANGELOG.md | 10 ++++++++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- .../ethcore/src/engines/hbbft/keygen_transactions.rs | 2 +- crates/util/version/Cargo.toml | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2203c9c51..24be44f85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## Diamond Node Software 0.12.2 + +- [Hotfix: Nodes not fast enough to write parts (keygen)](https://github.com/DMDcoin/diamond-node/issues/280) + +## Diamond Node Software 0.12.1 + +- Logging improvements +- Fixed a bug, where handshakes, that get upgraded to sessions, deregister there stream. + + ## Diamond Node Software 0.12.0 - New Versioning Scheme: Since Open Ethereum did not get a new update, diamond-node will not mention 3.3.5 anymore diff --git a/Cargo.lock b/Cargo.lock index 3efc90138..34dd5abb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "0.12.1" +version = "0.12.2" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.1" +version = "0.12.2" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index a762fab02..c6c1daf29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "0.12.1" +version = "0.12.2" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 6c4e3c051..a65e1dbce 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -57,7 +57,7 @@ impl From for KeyGenError { } } -static KEYGEN_TRANSACTION_SEND_DELAY: u64 = 3; +static KEYGEN_TRANSACTION_SEND_DELAY: u64 = 0; static KEYGEN_TRANSACTION_RESEND_DELAY: u64 = 10; impl KeygenTransactionSender { diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 5c019eedd..4719f665a 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.1" +version = "0.12.2" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 6cff60f17be14d40c2ea6117e39aa407837ab7b2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 16 Sep 2025 11:37:25 +0200 Subject: [PATCH 642/687] - Refactored Key Gen Transaction sender. - respects now Nonces of transactions in the chain - Log Cleanup --- .../src/engines/hbbft/hbbft_peers_handler.rs | 2 - .../engines/hbbft/hbbft_peers_management.rs | 10 +- .../src/engines/hbbft/keygen_transactions.rs | 386 ++++++++++++------ 3 files changed, 263 insertions(+), 135 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs index c5e609d3c..34d2e3c0d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_handler.rs @@ -177,8 +177,6 @@ impl HbbftPeersHandler { error!(target: "engine", "Error trying to announce own internet address: {:?}", error); } - trace!(target: "engine", "Success: trying to announce own internet address for mining address: {:?}", mining_address); - return Ok(()); } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 3db59e6f9..e6e0ee546 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -371,9 +371,9 @@ impl HbbftPeersManagement { engine_client: &dyn EngineClient, mining_address: &Address, staking_address: &Address, - ) -> Result<(), String> { + ) -> Result { if !self.should_announce_own_internet_address(block_chain_client) { - return Ok(()); + return Ok(false); } // updates the nodes internet address if the information on the blockchain is outdated. @@ -392,7 +392,7 @@ impl HbbftPeersManagement { endpoint } else { warn!(target: "engine", "devp2p endpoint not available."); - return Ok(()); + return Ok(false); } } else { error!(target: "engine", "Unable to lock reserved_peers_management"); @@ -413,7 +413,7 @@ impl HbbftPeersManagement { // we don't need to do anything. // but we cache the current endpoint, so we don't have to query the db again. self.last_written_internet_address = Some(current_endpoint); - return Ok(()); + return Ok(false); } match set_validator_internet_address( @@ -423,7 +423,7 @@ impl HbbftPeersManagement { ) { Ok(()) => { self.last_written_internet_address = Some(current_endpoint); - return Ok(()); + return Ok(true); } Err(err) => { error!(target: "engine", "unable to set validator internet address: {:?}", err); diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index a65e1dbce..9a05341b2 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -20,16 +20,40 @@ use crate::{ }, types::ids::BlockId, }; -use ethereum_types::{Address, U256}; +use ethereum_types::{Address, Public, U256}; +use hbbft::sync_key_gen::SyncKeyGen; use itertools::Itertools; use parking_lot::RwLock; -use std::{collections::BTreeMap, sync::Arc}; +use std::{collections::BTreeMap, sync::Arc, time::Instant}; use crate::client::BlockChainClient; +pub enum ServiceTransactionType { + /// KeyGenTransaction: (u64: epoch, u64: round, KeyGenMode) + KeyGenTransaction(u64, u64, KeyGenMode), +} + +pub struct ServiceTransactionMemory { + /// Time when the transaction was send. + pub send_time: Instant, + + // It would be good to have a transaction Hash here. + //pub transaction_hash: H256, + /// Type of the transaction, e.g. KeyGen Part or Ack. + pub transaction_type: ServiceTransactionType, + + /// Nonce of the transaction it was send with. + //pub nonce: U256, + + /// Block number, at wich this transaction was "sent", + /// in the meaning of prepared to be propagated. + pub block_sent: u64, + // It would be good to know if the Service Transaction got included. + // pub inclusion_block: Option, +} + pub struct KeygenTransactionSender { - last_keygen_mode: KeyGenMode, - keygen_mode_counter: u64, + last_keygen_service_transaction: Option, } enum ShouldSendKeyAnswer { @@ -57,14 +81,13 @@ impl From for KeyGenError { } } -static KEYGEN_TRANSACTION_SEND_DELAY: u64 = 0; -static KEYGEN_TRANSACTION_RESEND_DELAY: u64 = 10; +static KEYGEN_TRANSACTION_RESEND_DELAY_SECONDS: u64 = 30; +static KEYGEN_TRANSACTION_RESEND_DELAY_BLOCKS: u64 = 2; impl KeygenTransactionSender { pub fn new() -> Self { KeygenTransactionSender { - last_keygen_mode: KeyGenMode::Other, - keygen_mode_counter: 0, + last_keygen_service_transaction: None, } } @@ -73,29 +96,56 @@ impl KeygenTransactionSender { client: &dyn EngineClient, mining_address: &Address, mode_to_check: KeyGenMode, + upcomming_epoch: &U256, + current_round: &U256, ) -> Result { let keygen_mode = get_pending_validator_key_generation_mode(client, mining_address)?; if keygen_mode == mode_to_check { - if self.last_keygen_mode == mode_to_check { - self.keygen_mode_counter += 1; - if self.keygen_mode_counter == KEYGEN_TRANSACTION_SEND_DELAY { - return Ok(ShouldSendKeyAnswer::Yes); - } else if self.keygen_mode_counter > KEYGEN_TRANSACTION_SEND_DELAY { - // Part should have been sent already, - // give the chain time to include the transaction before trying a re-send. - if (self.keygen_mode_counter - KEYGEN_TRANSACTION_SEND_DELAY) - % KEYGEN_TRANSACTION_RESEND_DELAY - == 0 - { - return Ok(ShouldSendKeyAnswer::Yes); + match &self.last_keygen_service_transaction { + Some(last_sent) => { + match &last_sent.transaction_type { + ServiceTransactionType::KeyGenTransaction( + historic_upcomming_epoch, + historic_round, + historic_key_gen_mode, + ) => { + if *historic_key_gen_mode != keygen_mode + || *historic_upcomming_epoch != upcomming_epoch.as_u64() + || *historic_round != current_round.as_u64() + { + // other key gen mode, we need to send. + return Ok(ShouldSendKeyAnswer::Yes); + } + + // we will check the state of our send transaction. + // client.queued_transactions(). + + // if we are still in the same situation, we need to figure out if we just should retry to send our last transaction. + if last_sent.send_time.elapsed().as_secs() + < KEYGEN_TRANSACTION_RESEND_DELAY_SECONDS + { + // we sent a transaction recently, so we should wait a bit. + return Ok(ShouldSendKeyAnswer::NoWaiting); + } + + let current_block = client.block_number(BlockId::Latest).unwrap_or(0); + + // this check also prevents the resending of Transaction in a manner. + if last_sent.block_sent + KEYGEN_TRANSACTION_RESEND_DELAY_BLOCKS + < current_block + { + // we sent a transaction recently, so we should wait a bit. + return Ok(ShouldSendKeyAnswer::NoWaiting); + } + + return Ok(ShouldSendKeyAnswer::Yes); + } } - } else { - return Ok(ShouldSendKeyAnswer::NoWaiting); } - } else { - self.last_keygen_mode = mode_to_check; - self.keygen_mode_counter = 1; - return Ok(ShouldSendKeyAnswer::NoWaiting); + None => { + // we never sent a key gen transaction, so we should send one. + return Ok(ShouldSendKeyAnswer::Yes); + } } } return Ok(ShouldSendKeyAnswer::NoNotThisKeyGenMode); @@ -105,16 +155,32 @@ impl KeygenTransactionSender { &mut self, client: &dyn EngineClient, mining_address: &Address, + upcomming_epoch: &U256, + current_round: &U256, ) -> Result { - self.should_send(client, mining_address, KeyGenMode::WritePart) + self.should_send( + client, + mining_address, + KeyGenMode::WritePart, + upcomming_epoch, + current_round, + ) } fn should_send_ack( &mut self, client: &dyn EngineClient, mining_address: &Address, + upcomming_epoch: &U256, + current_round: &U256, ) -> Result { - self.should_send(client, mining_address, KeyGenMode::WriteAck) + self.should_send( + client, + mining_address, + KeyGenMode::WriteAck, + upcomming_epoch, + current_round, + ) } /// Returns a collection of transactions the pending validator has to submit in order to @@ -145,6 +211,7 @@ impl KeygenTransactionSender { let vmap = get_validator_pubkeys(&*client, BlockId::Latest, ValidatorType::Pending) .map_err(|e| KeyGenError::CallError(e))?; + let pub_keys: BTreeMap<_, _> = vmap .values() .map(|p| (*p, PublicWrapper { inner: p.clone() })) @@ -179,8 +246,10 @@ impl KeygenTransactionSender { // if we should send our parts, we will send the public keys of the troublemakers instead. + let current_round = get_current_key_gen_round(client)?; + match self - .should_send_part(client, &address) + .should_send_part(client, &address, &upcoming_epoch, ¤t_round) .map_err(|e| KeyGenError::CallError(e))? { ShouldSendKeyAnswer::NoNotThisKeyGenMode => { @@ -196,14 +265,16 @@ impl KeygenTransactionSender { } }; - send_part_transaction( + let current_round = get_current_key_gen_round(client)?; + + self.send_part_transaction( full_client, client, &address, - upcoming_epoch, + &upcoming_epoch, + ¤t_round, serialized_part, )?; - trace!(target:"engine", "PART Transaction send for moving forward key gen phase"); return Ok(()); } } @@ -219,10 +290,12 @@ impl KeygenTransactionSender { } }; - trace!(target:"engine", "preparing to send PARTS for upcoming epoch: {}", upcoming_epoch); + let current_round = get_current_key_gen_round(client)?; + + trace!(target:"engine", "preparing to send keys for upcoming epoch: {} - round {}", upcoming_epoch, current_round); // Check if we already sent our part. - match self.should_send_part(client, &address)? { + match self.should_send_part(client, &address, &upcoming_epoch, ¤t_round)? { ShouldSendKeyAnswer::Yes => { let serialized_part = match bincode::serialize(&part_data) { Ok(part) => part, @@ -232,15 +305,15 @@ impl KeygenTransactionSender { } }; - let nonce = send_part_transaction( + self.send_part_transaction( full_client, client, &address, - upcoming_epoch, + &upcoming_epoch, + ¤t_round, serialized_part, )?; - debug!(target: "engine", "sending Part with nonce: {}", nonce); return Ok(()); } ShouldSendKeyAnswer::NoWaiting => { @@ -251,107 +324,164 @@ impl KeygenTransactionSender { ShouldSendKeyAnswer::NoNotThisKeyGenMode => {} } - trace!(target:"engine", "checking for acks..."); + trace!(target:"engine", "has_acks_of_address_data: {:?}", has_acks_of_address_data(client, address)); + + // Now we are sure all parts are ready, let's check if we sent our Acks. + match self.should_send_ack(client, &address, &upcoming_epoch, ¤t_round)? { + ShouldSendKeyAnswer::Yes => { + self.send_ack_transaction( + full_client, + client, + &address, + &upcoming_epoch, + ¤t_round, + &vmap, + &mut synckeygen, + )?; + } + _ => {} + } + + Ok(()) + } + + fn send_ack_transaction( + &mut self, + full_client: &dyn BlockChainClient, + client: &dyn EngineClient, + mining_address: &Address, + upcoming_epoch: &U256, + current_round: &U256, + vmap: &BTreeMap, + synckeygen: &mut SyncKeyGen, + ) -> Result<(), KeyGenError> { // Return if any Part is missing. let mut acks = Vec::new(); for v in vmap.keys().sorted() { acks.push( - match part_of_address(&*client, *v, &vmap, &mut synckeygen, BlockId::Latest) { - Ok(part_result) => { - match part_result { - Some(ack) => ack, - None => { - trace!(target:"engine", "could not retrieve part for {}", *v); - return Ok(()); - } - } - } - Err(err) => { - error!(target:"engine", "could not retrieve part for {} call failed. Error: {:?}", *v, err); - return Err(KeyGenError::CallError(err)); - } - } - ); + match part_of_address(&*client, *v, &vmap, synckeygen, BlockId::Latest) { + Ok(part_result) => { + match part_result { + Some(ack) => ack, + None => { + trace!(target:"engine", "could not retrieve part for {}", *v); + return Ok(()); + } + } + } + Err(err) => { + error!(target:"engine", "could not retrieve part for {} call failed. Error: {:?}", *v, err); + return Err(KeyGenError::CallError(err)); + } + } + ); } - trace!(target:"engine", "has_acks_of_address_data: {:?}", has_acks_of_address_data(client, address)); + let mut serialized_acks = Vec::new(); + let mut total_bytes_for_acks = 0; - // Now we are sure all parts are ready, let's check if we sent our Acks. - match self.should_send_ack(client, &address)? { - ShouldSendKeyAnswer::Yes => { - let mut serialized_acks = Vec::new(); - let mut total_bytes_for_acks = 0; - - for ack in acks { - let ack_to_push = match bincode::serialize(&ack) { - Ok(serialized_ack) => serialized_ack, - Err(_) => return Err(KeyGenError::Unexpected), - }; - total_bytes_for_acks += ack_to_push.len(); - serialized_acks.push(ack_to_push); - } - let current_round = get_current_key_gen_round(client)?; - let write_acks_data = key_history_contract::functions::write_acks::call( - upcoming_epoch, - current_round, - serialized_acks, - ); - - // the required gas values have been approximated by - // experimenting and it's a very rough estimation. - // it can be further fine tuned to be just above the real consumption. - let gas = total_bytes_for_acks * 850 + 200_000; - trace!(target: "engine","acks-len: {} gas: {}", total_bytes_for_acks, gas); - - let acks_transaction = - TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, write_acks_data.0) - .gas(U256::from(gas)) - .nonce(full_client.nonce(&address, BlockId::Latest).unwrap()) - .gas_price(U256::from(10000000000u64)); - debug!(target: "engine", "sending acks with nonce: {}", acks_transaction.nonce.unwrap()); - let hash = full_client - .transact_silently(acks_transaction) - .map_err(|_| CallError::ReturnValueInvalid)?; - debug!(target: "engine", "sending acks tx: {}", hash); - } - _ => {} + for ack in acks { + let ack_to_push = match bincode::serialize(&ack) { + Ok(serialized_ack) => serialized_ack, + Err(_) => return Err(KeyGenError::Unexpected), + }; + total_bytes_for_acks += ack_to_push.len(); + serialized_acks.push(ack_to_push); } + let write_acks_data = key_history_contract::functions::write_acks::call( + upcoming_epoch, + current_round, + serialized_acks, + ); + + // the required gas values have been approximated by + // experimenting and it's a very rough estimation. + // it can be further fine tuned to be just above the real consumption. + let gas = total_bytes_for_acks * 850 + 200_000; + trace!(target: "engine","acks-len: {} gas: {}", total_bytes_for_acks, gas); + + // full_client.nonce(&mining_address, BlockId::Latest).unwrap(); + // Nonce Management is complex. + // we will include queued transactions here, + // but it could lead to a problem where "unprocessed" stuck transactions are producing Nonce gaps. + + let nonce = full_client.next_nonce(&*mining_address); + + let acks_transaction = TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, write_acks_data.0) + .gas(U256::from(gas)) + .nonce(nonce.clone()) + .gas_price(U256::from(10000000000u64)); + debug!(target: "engine", "sending acks with nonce: {}", acks_transaction.nonce.unwrap()); + let hash = full_client + .transact_silently(acks_transaction) + .map_err(|_| CallError::ReturnValueInvalid)?; + debug!(target: "engine", "sending acks tx: {}", hash); + + self.last_keygen_service_transaction = Some(ServiceTransactionMemory { + send_time: Instant::now(), + transaction_type: ServiceTransactionType::KeyGenTransaction( + upcoming_epoch.as_u64(), + current_round.as_u64(), + KeyGenMode::WriteAck, + ), + //nonce: nonce, + //transaction_hash: hash, + block_sent: client.block_number(BlockId::Latest).unwrap_or(0), + }); + Ok(()) } -} -fn send_part_transaction( - full_client: &dyn BlockChainClient, - client: &dyn EngineClient, - mining_address: &Address, - upcoming_epoch: U256, - data: Vec, -) -> Result { - // the required gas values have been approximated by - // experimenting and it's a very rough estimation. - // it can be further fine tuned to be just above the real consumption. - // ACKs require much more gas, - // and usually run into the gas limit problems. - let gas: usize = data.len() * 800 + 100_000; - - let nonce = full_client.nonce(&mining_address, BlockId::Latest).unwrap(); - let current_round = get_current_key_gen_round(client)?; - let write_part_data = - key_history_contract::functions::write_part::call(upcoming_epoch, current_round, data); - - let part_transaction = TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, write_part_data.0) - .gas(U256::from(gas)) - .nonce(nonce) - .gas_price(U256::from(10000000000u64)); - let hash = full_client - .transact_silently(part_transaction) - .map_err(|e| { - warn!(target:"engine", "could not transact_silently: {:?}", e); - CallError::ReturnValueInvalid - })?; - - debug!(target: "engine", "sending part tx: {}", hash); - - return Ok(nonce); + fn send_part_transaction( + &mut self, + full_client: &dyn BlockChainClient, + client: &dyn EngineClient, + mining_address: &Address, + upcoming_epoch: &U256, + current_round: &U256, + data: Vec, + ) -> Result { + // the required gas values have been approximated by + // experimenting and it's a very rough estimation. + // it can be further fine tuned to be just above the real consumption. + // ACKs require much more gas, + // and usually run into the gas limit problems. + let gas: usize = data.len() * 800 + 100_000; + + // WARNING: This Nonce could conflict with other Service Transactions. + // a better ServiceTransactionManager could be improve this here. + let nonce = full_client.next_nonce(&*mining_address); //full_client.nonce(&mining_address, BlockId::Latest).unwrap(); + + let write_part_data = + key_history_contract::functions::write_part::call(upcoming_epoch, current_round, data); + + let part_transaction = TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, write_part_data.0) + .gas(U256::from(gas)) + .nonce(nonce) + .gas_price(U256::from(10000000000u64)); + let hash = full_client + .transact_silently(part_transaction) + .map_err(|e| { + warn!(target:"engine", "could not transact_silently: {:?}", e); + CallError::ReturnValueInvalid + })?; + + self.last_keygen_service_transaction = Some(ServiceTransactionMemory { + send_time: Instant::now(), + //transaction_hash: hash, + transaction_type: ServiceTransactionType::KeyGenTransaction( + upcoming_epoch.as_u64(), + current_round.as_u64(), + KeyGenMode::WritePart, + ), + //nonce, + block_sent: client.block_number(BlockId::Latest).unwrap_or(0), + }); + + debug!(target: "engine", "sending part tx: {}", hash); + debug!(target: "engine", "sending Part with nonce: {}", nonce); + + return Ok(nonce); + } } From 97b8fe94a1dac2fb8409cd0cc69a4c9a10980044 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 16 Sep 2025 11:39:36 +0200 Subject: [PATCH 643/687] version = "0.12.3" --- CHANGELOG.md | 5 +++++ Cargo.lock | 2 +- crates/util/version/Cargo.toml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24be44f85..c314488b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Diamond Node Software 0.12.3 + +- Refactored KeyGenTransactions. +- Nonces from the Queue are now respected for Key Gen Transactions. + ## Diamond Node Software 0.12.2 - [Hotfix: Nodes not fast enough to write parts (keygen)](https://github.com/DMDcoin/diamond-node/issues/280) diff --git a/Cargo.lock b/Cargo.lock index 34dd5abb1..8d7f796c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.2" +version = "0.12.3" dependencies = [ "parity-bytes", "rlp", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 4719f665a..725111e83 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.2" +version = "0.12.3" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 960e8e51aa11dfb06d44c42c1d125f40c79da673 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 16 Sep 2025 11:58:02 +0200 Subject: [PATCH 644/687] fixed logic for Block Based Resend barrier. --- .../ethcore/src/engines/hbbft/keygen_transactions.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 9a05341b2..0aadbd2de 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -130,10 +130,18 @@ impl KeygenTransactionSender { let current_block = client.block_number(BlockId::Latest).unwrap_or(0); - // this check also prevents the resending of Transaction in a manner. + // this check also prevents the resending of Transactions if no block got mined. (e.g. because of stalled network) if last_sent.block_sent + KEYGEN_TRANSACTION_RESEND_DELAY_BLOCKS - < current_block + > current_block { + // example: + // send on block 10 (last_sent.block_sent = 10) + // KEYGEN_TRANSACTION_RESEND_DELAY_BLOCKS = 2 + // resent after Block 12. + // current block is 11: waiting + // current block is 12: waiting + // current block is 13: not entering => YES + // we sent a transaction recently, so we should wait a bit. return Ok(ShouldSendKeyAnswer::NoWaiting); } From 194bf654f32666d5c052399df581683dd9a1cf09 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 16 Sep 2025 11:59:39 +0200 Subject: [PATCH 645/687] fixed upcomming typo --- .../engines/hbbft/hbbft_network_fork_manager.rs | 8 ++++---- .../src/engines/hbbft/hbbft_peers_management.rs | 2 +- .../src/engines/hbbft/keygen_transactions.rs | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs index c66ab214d..cd52a379d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs @@ -82,10 +82,10 @@ impl HbbftFork { /// It allows cheap queries to see if a Fork is pending, /// and stores information about a fork that is finished. pub struct HbbftNetworkForkManager { - /// a ordered list with upcomming forks. + /// a ordered list with upcoming forks. finished_forks: VecDeque, - /// a ordered list with upcomming forks, including a fork that is in progress. + /// a ordered list with upcoming forks, including a fork that is in progress. /// see @is_currently_forking for more information. pending_forks: VecDeque, @@ -271,12 +271,12 @@ impl HbbftNetworkForkManager { } let fork = HbbftFork::from_definition(fork_def); - debug!(target: "engine", "hbbft-hardfork: added upcomming fork - add block {:?}", fork.start_block); + debug!(target: "engine", "hbbft-hardfork: added upcoming fork - add block {:?}", fork.start_block); self.pending_forks.push_back(fork); } else if fork_def.block_number_start >= startup_block_number { let fork = HbbftFork::from_definition(fork_def); - debug!(target: "engine", "hbbft-hardfork: added upcomming fork - add block {:?}", fork.start_block); + debug!(target: "engine", "hbbft-hardfork: added upcoming fork - add block {:?}", fork.start_block); self.pending_forks.push_back(fork); } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index e6e0ee546..0d1cc8cba 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -256,7 +256,7 @@ impl HbbftPeersManagement { /// if we drop out as a current validator, /// as well a pending validator, we should drop /// all reserved connections. - /// in later addition, we will keep the Partner Node Connections here. (upcomming feature) + /// in later addition, we will keep the Partner Node Connections here. (upcoming feature) pub fn disconnect_all_validators(&mut self, client_arc: &Arc) { // we safely can disconnect even in situation where we are syncing. diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 0aadbd2de..14f3d94b9 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -45,7 +45,7 @@ pub struct ServiceTransactionMemory { /// Nonce of the transaction it was send with. //pub nonce: U256, - /// Block number, at wich this transaction was "sent", + /// Block number, at which this transaction was "sent", /// in the meaning of prepared to be propagated. pub block_sent: u64, // It would be good to know if the Service Transaction got included. @@ -96,7 +96,7 @@ impl KeygenTransactionSender { client: &dyn EngineClient, mining_address: &Address, mode_to_check: KeyGenMode, - upcomming_epoch: &U256, + upcoming_epoch: &U256, current_round: &U256, ) -> Result { let keygen_mode = get_pending_validator_key_generation_mode(client, mining_address)?; @@ -105,12 +105,12 @@ impl KeygenTransactionSender { Some(last_sent) => { match &last_sent.transaction_type { ServiceTransactionType::KeyGenTransaction( - historic_upcomming_epoch, + historic_upcoming_epoch, historic_round, historic_key_gen_mode, ) => { if *historic_key_gen_mode != keygen_mode - || *historic_upcomming_epoch != upcomming_epoch.as_u64() + || *historic_upcoming_epoch != upcoming_epoch.as_u64() || *historic_round != current_round.as_u64() { // other key gen mode, we need to send. @@ -163,14 +163,14 @@ impl KeygenTransactionSender { &mut self, client: &dyn EngineClient, mining_address: &Address, - upcomming_epoch: &U256, + upcoming_epoch: &U256, current_round: &U256, ) -> Result { self.should_send( client, mining_address, KeyGenMode::WritePart, - upcomming_epoch, + upcoming_epoch, current_round, ) } @@ -179,14 +179,14 @@ impl KeygenTransactionSender { &mut self, client: &dyn EngineClient, mining_address: &Address, - upcomming_epoch: &U256, + upcoming_epoch: &U256, current_round: &U256, ) -> Result { self.should_send( client, mining_address, KeyGenMode::WriteAck, - upcomming_epoch, + upcoming_epoch, current_round, ) } From aff981c2416ddd30a84ce40abf4e3426f3fc0c38 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 16 Sep 2025 13:56:40 +0200 Subject: [PATCH 646/687] - removed backward compatibility for alpha2 https://github.com/DMDcoin/diamond-node/issues/110 - investigate requirements for the empty "Key Generation Blocks" https://github.com/DMDcoin/diamond-node/issues/160 --- .../engines/hbbft/contracts/keygen_history.rs | 16 ---------------- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 15 ++++++++++----- .../src/engines/hbbft/keygen_transactions.rs | 3 +-- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index f691ffabc..707b6322c 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -211,24 +211,8 @@ impl<'a> SecretKey for KeyPairWrapper { pub fn all_parts_acks_available( client: &dyn EngineClient, - block_timestamp: u64, num_validators: usize, ) -> Result { - // backward compatibility: - // this is a performance improvement introduced on the DMD Alpha Testnet. - // more about https://github.com/DMDcoin/openethereum-3.x/issues/71 - // this piece of code exists only for the DMD public alpha testnet, - // in order to support the v1 protocol version. - // since the v2 protocol version is better, - // v1 should be never used. - // remove the code: - // see: https://github.com/DMDcoin/openethereum-3.x/issues/72 - - let trigger_timestamp: u64 = 1646395200; // Friday, March 4, 2022 12:00:00 PM - - if block_timestamp > 0 && trigger_timestamp > 0 && block_timestamp < trigger_timestamp { - return Ok(true); - } let c = BoundContract::bind(client, BlockId::Latest, *KEYGEN_HISTORY_ADDRESS); let (num_parts, num_acks) = call_const_key_history!(c, get_number_of_key_fragments_written)?; diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index da954bcc9..dddd81b60 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -899,6 +899,11 @@ impl HoneyBadgerBFT { } fn start_hbbft_epoch_if_next_phase(&self) { + + // experimental deactivation of empty blocks. + // see: https://github.com/DMDcoin/diamond-node/issues/160 + + match self.client_arc() { None => return, Some(client) => { @@ -1118,6 +1123,8 @@ impl HoneyBadgerBFT { ); } + self.do_keygen(); + return Ok(()); } @@ -1130,7 +1137,7 @@ impl HoneyBadgerBFT { } /// Returns true if we are in the keygen phase and a new key has been generated. - fn do_keygen(&self, block_timestamp: u64) -> bool { + fn do_keygen(&self) -> bool { match self.client_arc() { None => false, Some(client) => { @@ -1150,7 +1157,7 @@ impl HoneyBadgerBFT { // The execution needs to be *identical* on all nodes, which means it should *not* use the local signer // when attempting to initialize the synckeygen. if let Ok(all_available) = - all_parts_acks_available(&*client, block_timestamp, validators.len()) + all_parts_acks_available(&*client, validators.len()) { if all_available { let null_signer = Arc::new(RwLock::new(None)); @@ -1572,16 +1579,14 @@ impl Engine for HoneyBadgerBFT { { let mut call = default_system_or_code_call(&self.machine, block); let mut latest_block_number: BlockNumber = 0; - let mut latest_block_timestamp: u64 = 0; if let Some(client) = self.client_arc() { if let Some(header) = client.block_header(BlockId::Latest) { latest_block_number = header.number(); - latest_block_timestamp = header.timestamp() } } // only do the key gen - let is_epoch_end = self.do_keygen(latest_block_timestamp); + let is_epoch_end = self.do_keygen(); trace!(target: "consensus", "calling reward function for block {} isEpochEnd? {} on address: {} (latest block: {}", header_number, is_epoch_end, address, latest_block_number); let contract = BlockRewardContract::new_from_address(address); diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 14f3d94b9..76f814cf9 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -191,8 +191,7 @@ impl KeygenTransactionSender { ) } - /// Returns a collection of transactions the pending validator has to submit in order to - /// complete the keygen history contract data necessary to generate the next key and switch to the new validator set. + /// sends key gen transaction if there are any to send. pub fn send_keygen_transactions( &mut self, client: &dyn EngineClient, From 7dad4955f1a7e0e821586ce4153cdb588e901942 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 16 Sep 2025 14:15:23 +0200 Subject: [PATCH 647/687] version = "0.12.4" --- CHANGELOG.md | 4 ++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c314488b7..7ee66c77e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Diamond Node Software 0.12.4 + +- [Key Gen Transaction do not require block triggers anymore, there is now also a time trigger](https://github.com/DMDcoin/diamond-node/issues/160) + ## Diamond Node Software 0.12.3 - Refactored KeyGenTransactions. diff --git a/Cargo.lock b/Cargo.lock index 8d7f796c3..d6674c815 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "0.12.2" +version = "0.12.4" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.3" +version = "0.12.4" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index c6c1daf29..2eba4c43e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "0.12.2" +version = "0.12.4" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 725111e83..3105100c9 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.3" +version = "0.12.4" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 2d1cf2fe4704417522e78d49bf8a7019357ed9c9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 16 Sep 2025 14:15:46 +0200 Subject: [PATCH 648/687] cargo fmt --all -- --config imports_granularity=Crate --- .../ethcore/src/engines/hbbft/contracts/keygen_history.rs | 1 - crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs index 707b6322c..ee41a17ef 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/keygen_history.rs @@ -213,7 +213,6 @@ pub fn all_parts_acks_available( client: &dyn EngineClient, num_validators: usize, ) -> Result { - let c = BoundContract::bind(client, BlockId::Latest, *KEYGEN_HISTORY_ADDRESS); let (num_parts, num_acks) = call_const_key_history!(c, get_number_of_key_fragments_written)?; Ok(num_parts.low_u64() == (num_validators as u64) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index dddd81b60..7093bcd69 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -899,11 +899,9 @@ impl HoneyBadgerBFT { } fn start_hbbft_epoch_if_next_phase(&self) { - // experimental deactivation of empty blocks. // see: https://github.com/DMDcoin/diamond-node/issues/160 - match self.client_arc() { None => return, Some(client) => { @@ -1156,9 +1154,7 @@ impl HoneyBadgerBFT { // Check if a new key is ready to be generated, return true to switch to the new epoch in that case. // The execution needs to be *identical* on all nodes, which means it should *not* use the local signer // when attempting to initialize the synckeygen. - if let Ok(all_available) = - all_parts_acks_available(&*client, validators.len()) - { + if let Ok(all_available) = all_parts_acks_available(&*client, validators.len()) { if all_available { let null_signer = Arc::new(RwLock::new(None)); match initialize_synckeygen( From 626be843771af8fd9470047ef73563560f6d60a3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 20 Sep 2025 21:28:08 +0200 Subject: [PATCH 649/687] switched order of AnnounceOwnInternetAddress and AnnounceAvailability --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 7093bcd69..18faed426 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1092,9 +1092,6 @@ impl HoneyBadgerBFT { }; } // drop lock for hbbft_state - self.hbbft_peers_service - .send_message(HbbftConnectToPeersMessage::AnnounceOwnInternetAddress)?; - // if we do not have to do anything, we can return early. if !(should_connect_to_validator_set || should_handle_early_epoch_end) { return Ok(()); @@ -1104,6 +1101,11 @@ impl HoneyBadgerBFT { .channel() .send(HbbftConnectToPeersMessage::AnnounceAvailability)?; + + self.hbbft_peers_service + .send_message(HbbftConnectToPeersMessage::AnnounceOwnInternetAddress)?; + + if should_connect_to_validator_set { self.hbbft_peers_service.send_message( HbbftConnectToPeersMessage::ConnectToCurrentPeers(validator_set.clone()), From 124ea094985d260e9d7574f4dea5f5634e55bdbf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 20 Sep 2025 21:31:07 +0200 Subject: [PATCH 650/687] v0.12.5: now announcing availability before announcing IP address --- CHANGELOG.md | 4 ++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 -- crates/util/version/Cargo.toml | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ee66c77e..925771110 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Diamond Node Software 0.12.5 + +- now announcing availability before announcing IP address + ## Diamond Node Software 0.12.4 - [Key Gen Transaction do not require block triggers anymore, there is now also a time trigger](https://github.com/DMDcoin/diamond-node/issues/160) diff --git a/Cargo.lock b/Cargo.lock index d6674c815..fed98acd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "0.12.4" +version = "0.12.5" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.4" +version = "0.12.5" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 2eba4c43e..ca6714ee5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "0.12.4" +version = "0.12.5" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 18faed426..1e2dc1785 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -1101,11 +1101,9 @@ impl HoneyBadgerBFT { .channel() .send(HbbftConnectToPeersMessage::AnnounceAvailability)?; - self.hbbft_peers_service .send_message(HbbftConnectToPeersMessage::AnnounceOwnInternetAddress)?; - if should_connect_to_validator_set { self.hbbft_peers_service.send_message( HbbftConnectToPeersMessage::ConnectToCurrentPeers(validator_set.clone()), diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 3105100c9..632c3a99d 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.4" +version = "0.12.5" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 10a051b9c98c924941d87c7941af08d26e9262df Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 21 Sep 2025 22:48:33 +0200 Subject: [PATCH 651/687] reduced log overhead for deP2P Propagations in trace, while still providing a good balance for debug --- crates/ethcore/sync/src/chain/propagator.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 30d83c156..b41cd87cd 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -28,7 +28,7 @@ use bytes::Bytes; use ethereum_types::{H256, H512}; use fastmap::H256FastSet; use network::{Error, ErrorKind, PeerId, client_version::ClientCapabilities}; -use rand::RngCore; +use rand::{seq::IteratorRandom, RngCore}; use rlp::RlpStream; use crate::chain::propagator_statistics::SyncPropagatorStatistics; @@ -44,6 +44,8 @@ use std::sync::Arc; const NEW_POOLED_HASHES_LIMIT: usize = 4096; +const MAX_TRACE_PROPAGATED_TXS: usize = 20; + /// The Chain Sync Propagator: propagates data to peers // pub struct SyncPropagator<'a> { @@ -193,8 +195,9 @@ impl ChainSync { .retain_pending(&all_transactions_hashes); } - debug!(target: "sync", "Propagating {:?}", all_transactions_hashes); - trace!(target: "sync", "Propagating {} transactions to {} peers", transactions.len(), peers.len()); + + debug!(target: "sync", "Propagating {} transactions to {} peers", transactions.len(), peers.len()); + trace!(target: "sync", "Propagating {:?}", if all_transactions_hashes.len() > MAX_TRACE_PROPAGATED_TXS { all_transactions_hashes.iter().choose_multiple(&mut rand::thread_rng(), MAX_TRACE_PROPAGATED_TXS).iter().collect() } else { all_transactions_hashes }); let send_packet = |io: &mut dyn SyncIo, stats: &mut SyncPropagatorStatistics, From 7cd606295d4e6832c5661d5518dbfacb799deb2c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 21 Sep 2025 22:52:23 +0200 Subject: [PATCH 652/687] removed tests for supporting for outdated clients that do not support large requests --- crates/ethcore/sync/src/chain/propagator.rs | 5 ++--- crates/net/network/src/client_version.rs | 22 --------------------- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index b41cd87cd..078d552d6 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -28,7 +28,7 @@ use bytes::Bytes; use ethereum_types::{H256, H512}; use fastmap::H256FastSet; use network::{Error, ErrorKind, PeerId, client_version::ClientCapabilities}; -use rand::{seq::IteratorRandom, RngCore}; +use rand::{RngCore, seq::IteratorRandom}; use rlp::RlpStream; use crate::chain::propagator_statistics::SyncPropagatorStatistics; @@ -195,8 +195,7 @@ impl ChainSync { .retain_pending(&all_transactions_hashes); } - - debug!(target: "sync", "Propagating {} transactions to {} peers", transactions.len(), peers.len()); + debug!(target: "sync", "Propagating {} transactions to {} peers", transactions.len(), peers.len()); trace!(target: "sync", "Propagating {:?}", if all_transactions_hashes.len() > MAX_TRACE_PROPAGATED_TXS { all_transactions_hashes.iter().choose_multiple(&mut rand::thread_rng(), MAX_TRACE_PROPAGATED_TXS).iter().collect() } else { all_transactions_hashes }); let send_packet = |io: &mut dyn SyncIo, diff --git a/crates/net/network/src/client_version.rs b/crates/net/network/src/client_version.rs index 9984b5778..f853e5198 100644 --- a/crates/net/network/src/client_version.rs +++ b/crates/net/network/src/client_version.rs @@ -494,28 +494,6 @@ pub mod tests { assert_eq!(client_version.to_string(), client_version_string); } - #[test] - pub fn client_capabilities_when_parity_old_version_then_handles_large_requests_false() { - let client_version_string: String = make_old_semver_version_string(); - - let client_version = ClientVersion::from(client_version_string.as_str()); - - assert!(!client_version.can_handle_large_requests()); - } - - #[test] - pub fn client_capabilities_when_parity_beta_version_then_not_handles_large_requests_true() { - let client_version_string: String = format!( - "{}/v{}/{}/{}", - "Parity-Ethereum", "2.4.0-beta", "x86_64-linux-gnu", "rustc1.31.1" - ) - .to_string(); - - let client_version = ClientVersion::from(client_version_string.as_str()); - - assert!(!client_version.can_handle_large_requests()); - } - #[test] pub fn client_version_when_to_owned_then_both_objects_equal() { let client_version_string: String = make_old_semver_version_string(); From c24908c64d08adbb4712f4858d727fde81ac9df3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 21 Sep 2025 23:29:40 +0200 Subject: [PATCH 653/687] reduced Trace Log output for tracing devp2p propagation --- crates/ethcore/sync/src/chain/propagator.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 078d552d6..96ee26b09 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -196,8 +196,13 @@ impl ChainSync { } debug!(target: "sync", "Propagating {} transactions to {} peers", transactions.len(), peers.len()); - trace!(target: "sync", "Propagating {:?}", if all_transactions_hashes.len() > MAX_TRACE_PROPAGATED_TXS { all_transactions_hashes.iter().choose_multiple(&mut rand::thread_rng(), MAX_TRACE_PROPAGATED_TXS).iter().collect() } else { all_transactions_hashes }); - + if all_transactions_hashes.len() > MAX_TRACE_PROPAGATED_TXS { + trace!(target: "sync", "Propagating {:?}", all_transactions_hashes .iter().choose_multiple(&mut rand::thread_rng(), MAX_TRACE_PROPAGATED_TXS)); + } + else { + trace!(target: "sync", "Propagating {:?}", all_transactions_hashes); + }; + let send_packet = |io: &mut dyn SyncIo, stats: &mut SyncPropagatorStatistics, peer_id: PeerId, From 11df2ceb3e1cd19d0eafcab524b41861102af6f7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 21 Sep 2025 23:30:19 +0200 Subject: [PATCH 654/687] Changelog 0.12.6 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 925771110..f6bba1319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +## Diamond Node Software 0.12.6 + +- reduced Trace Log output for tracing devp2p propagation +- removed tests for supporting for outdated clients that do not support large requests + + ## Diamond Node Software 0.12.5 - now announcing availability before announcing IP address From a42cef180d9582dc8dd3378ef4b3190e0a76d15c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 21 Sep 2025 23:33:07 +0200 Subject: [PATCH 655/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/sync/src/chain/propagator.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index 96ee26b09..a765ac9b0 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -198,11 +198,10 @@ impl ChainSync { debug!(target: "sync", "Propagating {} transactions to {} peers", transactions.len(), peers.len()); if all_transactions_hashes.len() > MAX_TRACE_PROPAGATED_TXS { trace!(target: "sync", "Propagating {:?}", all_transactions_hashes .iter().choose_multiple(&mut rand::thread_rng(), MAX_TRACE_PROPAGATED_TXS)); - } - else { + } else { trace!(target: "sync", "Propagating {:?}", all_transactions_hashes); }; - + let send_packet = |io: &mut dyn SyncIo, stats: &mut SyncPropagatorStatistics, peer_id: PeerId, From 75d3e9eade8ef1fcd1aaca4c6ffa9651ee53db8a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 21 Sep 2025 23:56:33 +0200 Subject: [PATCH 656/687] version update --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fed98acd9..e4fce244e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "0.12.5" +version = "0.12.6" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.5" +version = "0.12.6" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index ca6714ee5..572f0aa1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "0.12.5" +version = "0.12.6" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 632c3a99d..e2aaad9c1 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.5" +version = "0.12.6" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 494e241903c72206803a577b5aafbe8593b0f74e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 22 Sep 2025 14:53:46 +0200 Subject: [PATCH 657/687] fixed test: test_staking_account_creation --- crates/ethcore/src/engines/hbbft/test/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/test/mod.rs b/crates/ethcore/src/engines/hbbft/test/mod.rs index 7a01ecd4e..4c935ff7a 100644 --- a/crates/ethcore/src/engines/hbbft/test/mod.rs +++ b/crates/ethcore/src/engines/hbbft/test/mod.rs @@ -98,7 +98,9 @@ fn test_staking_account_creation() { .client .block(BlockId::Number(3)) .expect("Block must exist"); - assert_eq!(block.transactions_count(), 1); + + // block could already include KeyGenTransaction. + assert!(block.transactions_count() >= 1); assert_ne!( mining_by_staking_address(moc.client.as_ref(), &staker_1.address()) From 05ddd7a5ad7893e6a268ca5046754ba4dfd20296 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 22 Sep 2025 15:57:14 +0200 Subject: [PATCH 658/687] Logging improvements. --- bin/oe/run.rs | 10 +++++++-- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 22 ++++++++----------- .../ethcore/src/engines/hbbft/hbbft_state.rs | 11 +++++++--- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 5e919bafa..92dc4feb5 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -154,10 +154,16 @@ impl ChainSyncing for SyncProviderWrapper { Some(client_arc) => { is_major_importing(Some(sync_arc.status().state), client_arc.queue_info()) } - None => true, + None => { + debug!(target: "sync", "is_major_syncing: Client has been destroyed."); + true + } }, // We also indicate the "syncing" state when the SyncProvider has already been destroyed. - None => true, + None => { + debug!(target: "sync", "is_major_syncing: sync_provider has been destroyed."); + true + } } } diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 1e2dc1785..a6199e33d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -705,7 +705,7 @@ impl HoneyBadgerBFT { ) { Some(n) => n, None => { - error!(target: "consensus", "Sealing message for block #{} could not be processed due to missing/mismatching network info.", block_num); + error!(target: "consensus", "Sealing message for block #{} could not be processed due to missing network info for signer {}", block_num, sender_id); self.hbbft_message_dispatcher.report_seal_bad( &sender_id, block_num, @@ -755,12 +755,9 @@ impl HoneyBadgerBFT { Target::Nodes(set) => { trace!(target: "consensus", "Dispatching message {:?} to {:?}", m.message, set); for node_id in set.into_iter().filter(|p| p != net_info.our_id()) { - trace!(target: "consensus", "Sending message to {}", node_id.0); - client.send_consensus_message( - m.message.block_number(), - ser.clone(), - Some(node_id.0), - ); + let block_num = m.message.block_number(); + trace!(target: "consensus", "Sending message to {} for block #{} ", node_id.0, block_num); + client.send_consensus_message(block_num, ser.clone(), Some(node_id.0)); } } Target::AllExcept(set) => { @@ -769,12 +766,9 @@ impl HoneyBadgerBFT { .all_ids() .filter(|p| (p != &net_info.our_id() && !set.contains(p))) { - trace!(target: "consensus", "Sending exclusive message to {}", node_id.0); - client.send_consensus_message( - m.message.block_number(), - ser.clone(), - Some(node_id.0), - ); + let block_num = m.message.block_number(); + trace!(target: "consensus", "Sending exclusive message to {} for block #{}", node_id.0, block_num); + client.send_consensus_message(block_num, ser.clone(), Some(node_id.0)); } } } @@ -1430,6 +1424,8 @@ impl Engine for HoneyBadgerBFT { fn handle_message(&self, message: &[u8], node_id: Option) -> Result<(), EngineError> { let node_id = NodeId(node_id.ok_or(EngineError::UnexpectedMessage)?); + // todo: handling here old message as well. + match rmp_serde::from_slice(message) { Ok(Message::HoneyBadger(msg_idx, hb_msg)) => { self.process_hb_message(msg_idx, hb_msg, node_id) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 9af0cecb1..dd8b81559 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -590,9 +590,14 @@ impl HbbftState { ) -> Option> { self.skip_to_current_epoch(client.clone(), signer); - let posdao_epoch = get_posdao_epoch(&*client, BlockId::Number(block_nr - 1)) - .ok()? - .low_u64(); + // Performance: we can use cache here, since this contract calls return deterministic results. + let posdao_epoch = match get_posdao_epoch(&*client, BlockId::Number(block_nr - 1)) { + Ok(number) => number.low_u64(), + Err(e) => { + error!(target: "consensus", "Failed to get network info - reading POSDAO epoch from contract failed! Error: {:?}", e); + return None; + } + }; if self.current_posdao_epoch != posdao_epoch { error!(target: "consensus", "Trying to get the network info from a different epoch. Current epoch: {}, Requested epoch: {}", From 6c9ce3382e0d64c4e382116e4f8a1b8e9d1081dd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 22 Sep 2025 21:31:22 +0200 Subject: [PATCH 659/687] continuing sending key gen transaction, Even if syncing, if the latest block is not older than 10 seconds. https://github.com/DMDcoin/diamond-node/issues/288 --- .../src/engines/hbbft/keygen_transactions.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 76f814cf9..bd7f68afe 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -28,6 +28,8 @@ use std::{collections::BTreeMap, sync::Arc, time::Instant}; use crate::client::BlockChainClient; +static MAX_BLOCKCHAIN_AGE_FOR_KEYGEN: u64 = 10; // seconds + pub enum ServiceTransactionType { /// KeyGenTransaction: (u64: epoch, u64: round, KeyGenMode) KeyGenTransaction(u64, u64, KeyGenMode), @@ -210,8 +212,21 @@ impl KeygenTransactionSender { // If the chain is still syncing, do not send Parts or Acks. if full_client.is_major_syncing() { - debug!(target:"engine", "skipping sending key gen transaction, because we are syncing"); - return Ok(()); + if let Some(lastes_block) = client.block_header(BlockId::Latest) { + let now = std::time::UNIX_EPOCH + .elapsed() + .expect("Time not available") + .as_secs(); + if now > lastes_block.timestamp() + MAX_BLOCKCHAIN_AGE_FOR_KEYGEN { + debug!(target:"engine", "skipping sending key gen transaction, because we are syncing."); + return Ok(()); + } else { + trace!(target:"engine", "We are syncing, but the latest block is recent. continuing sending key gen transactions"); + } + } else { + debug!(target:"engine", "skipping sending key gen transaction, because we are syncing and could not retrieve latest block."); + return Ok(()); + } } trace!(target:"engine", " get_validator_pubkeys..."); From 35001729875837c6609eb58195f264b449db1f6c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Sep 2025 13:53:01 +0200 Subject: [PATCH 660/687] devP2PTests --- crates/ethcore/sync/src/tests/chain.rs | 12 ++++++++++++ crates/ethcore/sync/src/tests/consensus.rs | 1 + crates/ethcore/sync/src/tests/snapshot.rs | 1 + 3 files changed, 14 insertions(+) diff --git a/crates/ethcore/sync/src/tests/chain.rs b/crates/ethcore/sync/src/tests/chain.rs index ff1b4a09a..bfbc1d0b7 100644 --- a/crates/ethcore/sync/src/tests/chain.rs +++ b/crates/ethcore/sync/src/tests/chain.rs @@ -22,6 +22,7 @@ use ethcore::client::{ use std::sync::Arc; #[test] +#[cfg(feature = "devP2PTests")] fn two_peers() { ::env_logger::try_init().ok(); let mut net = TestNet::new(3); @@ -36,6 +37,7 @@ fn two_peers() { } #[test] +#[cfg(feature = "devP2PTests")] fn long_chain() { ::env_logger::try_init().ok(); let mut net = TestNet::new(2); @@ -70,6 +72,7 @@ fn takes_few_steps() { } #[test] +#[cfg(feature = "devP2PTests")] fn empty_blocks() { ::env_logger::try_init().ok(); let mut net = TestNet::new(3); @@ -91,6 +94,7 @@ fn empty_blocks() { } #[test] +#[cfg(feature = "devP2PTests")] fn forked() { ::env_logger::try_init().ok(); let mut net = TestNet::new(3); @@ -115,6 +119,7 @@ fn forked() { } #[test] +#[cfg(feature = "devP2PTests")] fn forked_with_misbehaving_peer() { ::env_logger::try_init().ok(); let mut net = TestNet::new(3); @@ -139,6 +144,7 @@ fn forked_with_misbehaving_peer() { } #[test] +#[cfg(feature = "devP2PTests")] fn net_hard_fork() { ::env_logger::try_init().ok(); let ref_client = TestBlockChainClient::new(); @@ -164,6 +170,7 @@ fn net_hard_fork() { } #[test] +#[cfg(feature = "devP2PTests")] fn restart() { ::env_logger::try_init().ok(); let mut net = TestNet::new(3); @@ -194,6 +201,7 @@ fn status_empty() { } #[test] +#[cfg(feature = "devP2PTests")] fn status_packet() { let mut net = TestNet::new(2); net.peer(0).chain.add_blocks(100, EachBlockWith::Uncle); @@ -208,6 +216,7 @@ fn status_packet() { } #[test] +#[cfg(feature = "devP2PTests")] fn propagate_hashes() { let mut net = TestNet::new(6); net.peer(1).chain.add_blocks(10, EachBlockWith::Uncle); @@ -235,6 +244,7 @@ fn propagate_hashes() { } #[test] +#[cfg(feature = "devP2PTests")] fn propagate_blocks() { let mut net = TestNet::new(20); net.peer(1).chain.add_blocks(10, EachBlockWith::Uncle); @@ -257,6 +267,7 @@ fn propagate_blocks() { } #[test] +#[cfg(feature = "devP2PTests")] fn restart_on_malformed_block() { ::env_logger::try_init().ok(); let mut net = TestNet::new(2); @@ -286,6 +297,7 @@ fn reject_on_broken_chain() { } #[test] +#[cfg(feature = "devP2PTests")] fn disconnect_on_unrelated_chain() { ::env_logger::try_init().ok(); let mut net = TestNet::new(2); diff --git a/crates/ethcore/sync/src/tests/consensus.rs b/crates/ethcore/sync/src/tests/consensus.rs index ff4493046..ac0229ac5 100644 --- a/crates/ethcore/sync/src/tests/consensus.rs +++ b/crates/ethcore/sync/src/tests/consensus.rs @@ -45,6 +45,7 @@ fn new_tx(secret: &Secret, nonce: U256, chain_id: u64) -> PendingTransaction { } #[test] +#[cfg(feature = "devP2PTests")] fn authority_round() { let s0 = KeyPair::from_secret_slice(keccak("1").as_bytes()).unwrap(); let s1 = KeyPair::from_secret_slice(keccak("0").as_bytes()).unwrap(); diff --git a/crates/ethcore/sync/src/tests/snapshot.rs b/crates/ethcore/sync/src/tests/snapshot.rs index baae4ea9e..354b28654 100644 --- a/crates/ethcore/sync/src/tests/snapshot.rs +++ b/crates/ethcore/sync/src/tests/snapshot.rs @@ -179,6 +179,7 @@ impl SnapshotService for TestSnapshotService { } #[test] +#[cfg(feature = "devP2PTests")] fn snapshot_sync() { ::env_logger::try_init().ok(); let mut config = SyncConfig::default(); From e1cbbfec4b42bf5ff6b64c9107839d197352c5a2 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sat, 4 Oct 2025 17:59:08 +0200 Subject: [PATCH 661/687] Added boolean to optionally defer sending of messages --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 83 ++++++++++++++++--- 1 file changed, 71 insertions(+), 12 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 9c37dba5d..d9da40703 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -62,6 +62,13 @@ use super::{ use crate::engines::hbbft::hbbft_message_memorium::HbbftMessageDispatcher; use std::{ops::Deref, sync::atomic::Ordering}; +// Internal representation for storing deferred outgoing consensus messages. +struct StoredOutgoingMessage { + block_number: BlockNumber, + data: Vec, + recipients: Vec, +} + type TargetedMessage = hbbft::TargetedMessage; /// A message sent between validators that is part of Honey Badger BFT or the block sealing process. @@ -104,6 +111,11 @@ pub struct HoneyBadgerBFT { early_epoch_manager: Mutex>, hbbft_engine_cache: Mutex, delayed_hbbft_join: AtomicBool, + + // When true, outgoing consensus messages are deferred and stored for later delivery. + defer_outgoing_messages: AtomicBool, + // Storage for deferred outgoing messages ready to be delivered later. + stored_outgoing_messages: Mutex>, } struct TransitionHandler { @@ -491,6 +503,9 @@ impl HoneyBadgerBFT { early_epoch_manager: Mutex::new(None), hbbft_engine_cache: Mutex::new(HbbftEngineCache::new()), delayed_hbbft_join: AtomicBool::new(false), + + defer_outgoing_messages: AtomicBool::new(false), + stored_outgoing_messages: Mutex::new(Vec::new()), }); if !engine.params.is_unit_test.unwrap_or(false) { @@ -748,16 +763,14 @@ impl HoneyBadgerBFT { for m in messages { let ser = rmp_serde::to_vec(&m.message).expect("Serialization of consensus message failed"); + + // Determine recipients based on the target, excluding ourselves. + let mut recipients: Vec = Vec::new(); match m.target { Target::Nodes(set) => { trace!(target: "consensus", "Dispatching message {:?} to {:?}", m.message, set); for node_id in set.into_iter().filter(|p| p != net_info.our_id()) { - trace!(target: "consensus", "Sending message to {}", node_id.0); - client.send_consensus_message( - m.message.block_number(), - ser.clone(), - Some(node_id.0), - ); + recipients.push(node_id.0); } } Target::AllExcept(set) => { @@ -766,15 +779,29 @@ impl HoneyBadgerBFT { .all_ids() .filter(|p| (p != &net_info.our_id() && !set.contains(p))) { - trace!(target: "consensus", "Sending exclusive message to {}", node_id.0); - client.send_consensus_message( - m.message.block_number(), - ser.clone(), - Some(node_id.0), - ); + recipients.push(node_id.0); } } } + + let block_number = m.message.block_number(); + + if self.defer_outgoing_messages.load(Ordering::SeqCst) { + // Store for deferred delivery + self.stored_outgoing_messages + .lock() + .push(StoredOutgoingMessage { + block_number, + data: ser, + recipients, + }); + } else { + // Send immediately + for node in recipients { + trace!(target: "consensus", "Sending message to {}", node); + client.send_consensus_message(block_number, ser.clone(), Some(node)); + } + } } } @@ -820,6 +847,38 @@ impl HoneyBadgerBFT { self.process_output(client, step.output, network_info); } + /// Enables or disables deferring of outgoing consensus messages. + pub fn set_defer_outgoing_messages(&self, defer: bool) { + self.defer_outgoing_messages.store(defer, Ordering::SeqCst); + } + + /// Deliver all stored outgoing consensus messages immediately. + /// If no client is registered yet, the messages remain stored. + pub fn deliver_stored_outgoing_messages(&self) { + let client = match self.client_arc() { + Some(c) => c, + None => { + warn!(target: "consensus", "deliver_stored_outgoing_messages: No client available; keeping messages deferred."); + return; + } + }; + + let mut stored = self.stored_outgoing_messages.lock(); + if stored.is_empty() { + return; + } + let mut messages: Vec = Vec::with_capacity(stored.len()); + std::mem::swap(&mut *stored, &mut messages); + drop(stored); + + for msg in messages.into_iter() { + for node in msg.recipients.iter() { + trace!(target: "consensus", "Delivering deferred message to {}", node); + client.send_consensus_message(msg.block_number, msg.data.clone(), Some(*node)); + } + } + } + /// Conditionally joins the current hbbft epoch if the number of received /// contributions exceeds the maximum number of tolerated faulty nodes. fn join_hbbft_epoch(&self) -> Result<(), EngineError> { From 8060ae74623fe2a44ac238d0ca26ce516d926c1a Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sat, 4 Oct 2025 18:13:07 +0200 Subject: [PATCH 662/687] Added a function to reset just the HoneyBadger state --- crates/ethcore/src/engines/hbbft/hbbft_state.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_state.rs b/crates/ethcore/src/engines/hbbft/hbbft_state.rs index 6be2dd13f..504a749a3 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_state.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_state.rs @@ -76,6 +76,16 @@ impl HbbftState { return Some(builder.build()); } + /// Resets only the underlying HoneyBadger instance, leaving all other state intact. + /// Returns Some(()) if the instance was recreated, or None if there is no network_info + /// or HoneyBadger creation failed. + pub fn reset_honeybadger(&mut self) -> Option<()> { + let network_info = self.network_info.as_ref()?.clone(); + let honey_badger = self.new_honey_badger(network_info)?; + self.honey_badger = Some(honey_badger); + Some(()) + } + pub fn init_fork_manager( &mut self, own_id: NodeId, From f41cb3a04ce78b92faa97b98f806cff9fe2554f0 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sat, 4 Oct 2025 20:37:19 +0200 Subject: [PATCH 663/687] A simple, but working, implementation of a hbbft recovery protocol --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index d9da40703..4bd879bfd 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -189,6 +189,8 @@ const ENGINE_DELAYED_UNITL_SYNCED_TOKEN: TimerToken = 3; // Some Operations have no urge on the timing, but are rather expensive. // those are handeled by this slow ticking timer. const ENGINE_VALIDATOR_CANDIDATE_ACTIONS: TimerToken = 4; +// Check for current Phoenix Protocol phase +const ENGINE_PHOENIX_CHECK: TimerToken = 5; impl TransitionHandler { fn handle_shutdown_on_missing_block_import( @@ -374,6 +376,11 @@ impl IoHandler<()> for TransitionHandler { // io.channel() // io.register_stream() + + io.register_timer(ENGINE_PHOENIX_CHECK, Duration::from_secs(10)) + .unwrap_or_else( + |e| warn!(target: "consensus", "ENGINE_PHOENIX_CHECK Timer failed: {}.", e), + ); } fn timeout(&self, io: &IoContext<()>, timer: TimerToken) { @@ -461,6 +468,55 @@ impl IoHandler<()> for TransitionHandler { if let Err(err) = self.engine.do_validator_engine_actions() { error!(target: "consensus", "do_validator_engine_actions failed: {:?}", err); } + } else if timer == ENGINE_PHOENIX_CHECK { + // Phoenix Protocol liveness check: log error if no last block, otherwise warn with its timestamp and human-readable time. + if let Some(ref weak) = *self.client.read() { + if let Some(c) = weak.upgrade() { + // No point in checking the last block's timestamp if we are still syncing + if self.engine.is_syncing(&c) { + return; + } + match c.block_header(BlockId::Latest) { + Some(h) => { + let ts = h.timestamp() as i64; // seconds since Unix epoch + // Compute difference in seconds between now and the block timestamp (signed i64) + let now_ts = unix_now_secs() as i64; + let diff_secs = now_ts - ts; + // If more than 60 seconds have passed since the last block, defer outgoing + // consensus messages and reset the underlying HoneyBadger instance. + if diff_secs > 60 && diff_secs <= 80 { + self.engine.set_defer_outgoing_messages(true); + match self + .engine + .hbbft_state + .try_write_for(Duration::from_millis(100)) + { + Some(mut state) => { + if state.reset_honeybadger().is_some() { + warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages and reset HoneyBadger ({}s since last block)", diff_secs); + } else { + warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages but failed to reset HoneyBadger ({}s since last block)", diff_secs); + } + } + None => { + warn!(target: "consensus", "Phoenix Protocol: Could not acquire hbbft_state lock to reset HoneyBadger while deferring messages ({}s since last block)", diff_secs); + } + } + } else if diff_secs > 80 { + // More than 80 seconds since the last block: stop deferring and flush stored messages + self.engine.set_defer_outgoing_messages(false); + self.engine.deliver_stored_outgoing_messages(); + warn!(target: "consensus", "Phoenix Protocol: Resumed sending and delivered deferred messages ({}s since last block)", diff_secs); + } + + warn!(target: "consensus", "Phoenix Protocol: latest block timestamp: {} (diff_secs: {})", h.timestamp(), diff_secs); + } + None => { + error!(target: "consensus", "Phoenix Protocol: No latest block header available."); + } + } + } + } } } } From 700169e4cf9dd619145fe75e8fd0a94c212b6bdb Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sat, 4 Oct 2025 20:56:53 +0200 Subject: [PATCH 664/687] Refactored recovery protocol for robustness and configurability --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 104 ++++++++++-------- 1 file changed, 61 insertions(+), 43 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 4bd879bfd..29ca896ec 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -116,6 +116,8 @@ pub struct HoneyBadgerBFT { defer_outgoing_messages: AtomicBool, // Storage for deferred outgoing messages ready to be delivered later. stored_outgoing_messages: Mutex>, + // Phoenix recovery protocol: ensure we reset HoneyBadger only once before resuming sending. + phoenix_reset_performed: AtomicBool, } struct TransitionHandler { @@ -469,59 +471,74 @@ impl IoHandler<()> for TransitionHandler { error!(target: "consensus", "do_validator_engine_actions failed: {:?}", err); } } else if timer == ENGINE_PHOENIX_CHECK { - // Phoenix Protocol liveness check: log error if no last block, otherwise warn with its timestamp and human-readable time. - if let Some(ref weak) = *self.client.read() { - if let Some(c) = weak.upgrade() { - // No point in checking the last block's timestamp if we are still syncing - if self.engine.is_syncing(&c) { - return; - } - match c.block_header(BlockId::Latest) { - Some(h) => { - let ts = h.timestamp() as i64; // seconds since Unix epoch - // Compute difference in seconds between now and the block timestamp (signed i64) - let now_ts = unix_now_secs() as i64; - let diff_secs = now_ts - ts; - // If more than 60 seconds have passed since the last block, defer outgoing - // consensus messages and reset the underlying HoneyBadger instance. - if diff_secs > 60 && diff_secs <= 80 { - self.engine.set_defer_outgoing_messages(true); - match self - .engine - .hbbft_state - .try_write_for(Duration::from_millis(100)) - { - Some(mut state) => { - if state.reset_honeybadger().is_some() { - warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages and reset HoneyBadger ({}s since last block)", diff_secs); - } else { - warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages but failed to reset HoneyBadger ({}s since last block)", diff_secs); - } - } - None => { - warn!(target: "consensus", "Phoenix Protocol: Could not acquire hbbft_state lock to reset HoneyBadger while deferring messages ({}s since last block)", diff_secs); + self.engine.handle_phoenix_recovery_protocol(); + } + } +} + +impl HoneyBadgerBFT { + // Phoenix recovery protocol parameters + // Start deferring and reset HoneyBadger after this many seconds without a new block. + const PHOENIX_DEFER_AFTER_SECS: i64 = 60; + // Resume sending and deliver deferred messages after this many seconds. + const PHOENIX_RESUME_AFTER_SECS: i64 = 80; + // Timeout for trying to acquire the hbbft_state lock to reset HoneyBadger, in milliseconds. + const PHOENIX_LOCK_TIMEOUT_MS: u64 = 100; + + /// Phoenix recovery protocol + /// Called periodically to detect stalls and perform a controlled recovery. + fn handle_phoenix_recovery_protocol(&self) { + if let Some(client) = self.client_arc() { + // Skip if still syncing. + if self.is_syncing(&client) { + return; + } + + match client.block_header(BlockId::Latest) { + Some(h) => { + let ts = h.timestamp() as i64; + let now_ts = unix_now_secs() as i64; + let diff_secs = now_ts - ts; + + if diff_secs > Self::PHOENIX_DEFER_AFTER_SECS && diff_secs <= Self::PHOENIX_RESUME_AFTER_SECS { + // Enter deferring mode + self.set_defer_outgoing_messages(true); + + // Ensure we reset the HoneyBadger instance only once during the deferring window. + if !self.phoenix_reset_performed.load(Ordering::SeqCst) { + match self.hbbft_state.try_write_for(Duration::from_millis(Self::PHOENIX_LOCK_TIMEOUT_MS)) { + Some(mut state) => { + if state.reset_honeybadger().is_some() { + self.phoenix_reset_performed.store(true, Ordering::SeqCst); + warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages and reset HoneyBadger ({}s since last block)", diff_secs); + } else { + warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages but failed to reset HoneyBadger ({}s since last block)", diff_secs); } } - } else if diff_secs > 80 { - // More than 80 seconds since the last block: stop deferring and flush stored messages - self.engine.set_defer_outgoing_messages(false); - self.engine.deliver_stored_outgoing_messages(); - warn!(target: "consensus", "Phoenix Protocol: Resumed sending and delivered deferred messages ({}s since last block)", diff_secs); + None => { + warn!(target: "consensus", "Phoenix Protocol: Could not acquire hbbft_state lock to reset HoneyBadger while deferring messages ({}s since last block)", diff_secs); + } } - - warn!(target: "consensus", "Phoenix Protocol: latest block timestamp: {} (diff_secs: {})", h.timestamp(), diff_secs); - } - None => { - error!(target: "consensus", "Phoenix Protocol: No latest block header available."); } + } else if diff_secs > Self::PHOENIX_RESUME_AFTER_SECS { + // Resume and flush stored messages + self.set_defer_outgoing_messages(false); + self.deliver_stored_outgoing_messages(); + // Allow the next cycle to perform a reset again if needed + self.phoenix_reset_performed.store(false, Ordering::SeqCst); + warn!(target: "consensus", "Phoenix Protocol: Resumed sending and delivered deferred messages ({}s since last block)", diff_secs); } + + // Always log the latest timestamp and diff for visibility. + warn!(target: "consensus", "Phoenix Protocol: latest block timestamp: {} (diff_secs: {})", h.timestamp(), diff_secs); + } + None => { + error!(target: "consensus", "Phoenix Protocol: No latest block header available."); } } } } -} -impl HoneyBadgerBFT { /// Creates an instance of the Honey Badger BFT Engine. pub fn new(params: HbbftParams, machine: EthereumMachine) -> Result, Error> { let is_unit_test = params.is_unit_test.unwrap_or(false); @@ -562,6 +579,7 @@ impl HoneyBadgerBFT { defer_outgoing_messages: AtomicBool::new(false), stored_outgoing_messages: Mutex::new(Vec::new()), + phoenix_reset_performed: AtomicBool::new(false), }); if !engine.params.is_unit_test.unwrap_or(false) { From a1e09935b83e13ab106ab6498dc031b167231de9 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sat, 4 Oct 2025 21:28:59 +0200 Subject: [PATCH 665/687] Retrying Phoenix Protocol periodically --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 68 ++++++++++++------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 29ca896ec..588eb6f7d 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -481,12 +481,14 @@ impl HoneyBadgerBFT { // Start deferring and reset HoneyBadger after this many seconds without a new block. const PHOENIX_DEFER_AFTER_SECS: i64 = 60; // Resume sending and deliver deferred messages after this many seconds. - const PHOENIX_RESUME_AFTER_SECS: i64 = 80; + const PHOENIX_RESUME_AFTER_SECS: i64 = 20; // Timeout for trying to acquire the hbbft_state lock to reset HoneyBadger, in milliseconds. const PHOENIX_LOCK_TIMEOUT_MS: u64 = 100; /// Phoenix recovery protocol /// Called periodically to detect stalls and perform a controlled recovery. + /// Retry recovery every n*PHOENIX_DEFER_AFTER_SECS by deferring and resetting, + /// and resume sending messages every n*PHOENIX_DEFER_AFTER_SECS + PHOENIX_RESUME_AFTER_SECS. fn handle_phoenix_recovery_protocol(&self) { if let Some(client) = self.client_arc() { // Skip if still syncing. @@ -500,33 +502,51 @@ impl HoneyBadgerBFT { let now_ts = unix_now_secs() as i64; let diff_secs = now_ts - ts; - if diff_secs > Self::PHOENIX_DEFER_AFTER_SECS && diff_secs <= Self::PHOENIX_RESUME_AFTER_SECS { - // Enter deferring mode - self.set_defer_outgoing_messages(true); - - // Ensure we reset the HoneyBadger instance only once during the deferring window. - if !self.phoenix_reset_performed.load(Ordering::SeqCst) { - match self.hbbft_state.try_write_for(Duration::from_millis(Self::PHOENIX_LOCK_TIMEOUT_MS)) { - Some(mut state) => { - if state.reset_honeybadger().is_some() { - self.phoenix_reset_performed.store(true, Ordering::SeqCst); - warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages and reset HoneyBadger ({}s since last block)", diff_secs); - } else { - warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages but failed to reset HoneyBadger ({}s since last block)", diff_secs); + let defer_after = Self::PHOENIX_DEFER_AFTER_SECS; + let resume_after = Self::PHOENIX_RESUME_AFTER_SECS; + + if diff_secs >= defer_after { + // Determine the current recovery cycle index n and its boundaries. + let n = diff_secs / defer_after; // floor division + let cycle_start = n * defer_after; // n * DEFER + let cycle_resume = cycle_start + resume_after; // n * DEFER + RESUME + let next_cycle_start = (n + 1) * defer_after; // (n+1) * DEFER + + if diff_secs < cycle_resume { + // We are within the deferring window of the current cycle. + self.set_defer_outgoing_messages(true); + + // Ensure we reset the HoneyBadger instance only once during a deferring window. + if !self.phoenix_reset_performed.load(Ordering::SeqCst) { + match self.hbbft_state.try_write_for(Duration::from_millis( + Self::PHOENIX_LOCK_TIMEOUT_MS, + )) { + Some(mut state) => { + if state.reset_honeybadger().is_some() { + self.phoenix_reset_performed + .store(true, Ordering::SeqCst); + warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages and reset HoneyBadger ({}s since last block; cycle n={}, window [{}..{}))", diff_secs, n, cycle_start, cycle_resume); + } else { + warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages but failed to reset HoneyBadger ({}s since last block; cycle n={}, window [{}..{}))", diff_secs, n, cycle_start, cycle_resume); + } + } + None => { + warn!(target: "consensus", "Phoenix Protocol: Could not acquire hbbft_state lock to reset HoneyBadger while deferring messages ({}s since last block; cycle n={}, window [{}..{}))", diff_secs, n, cycle_start, cycle_resume); } } - None => { - warn!(target: "consensus", "Phoenix Protocol: Could not acquire hbbft_state lock to reset HoneyBadger while deferring messages ({}s since last block)", diff_secs); - } + } + } else if diff_secs < next_cycle_start { + // We are in the resume window of the current cycle. + if self.phoenix_reset_performed.load(Ordering::SeqCst) { + self.set_defer_outgoing_messages(false); + self.deliver_stored_outgoing_messages(); + // Allow the next cycle to perform a reset again if needed. + self.phoenix_reset_performed.store(false, Ordering::SeqCst); + warn!(target: "consensus", "Phoenix Protocol: Resumed sending and delivered deferred messages ({}s since last block; cycle n={}, resume @ {}, next_cycle @ {})", diff_secs, n, cycle_resume, next_cycle_start); + } else { + warn!(target: "consensus", "Phoenix Protocol: Expecting block to be generated ({}s since last block; cycle n={}, resume @ {}, next_cycle @ {})", diff_secs, n, cycle_resume, next_cycle_start); } } - } else if diff_secs > Self::PHOENIX_RESUME_AFTER_SECS { - // Resume and flush stored messages - self.set_defer_outgoing_messages(false); - self.deliver_stored_outgoing_messages(); - // Allow the next cycle to perform a reset again if needed - self.phoenix_reset_performed.store(false, Ordering::SeqCst); - warn!(target: "consensus", "Phoenix Protocol: Resumed sending and delivered deferred messages ({}s since last block)", diff_secs); } // Always log the latest timestamp and diff for visibility. From 3e9e89df7b835dfcab49f51d2bbd23a22a637741 Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sat, 4 Oct 2025 21:46:23 +0200 Subject: [PATCH 666/687] Restored logging improvement messages --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 6ba0a219f..7730a8005 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -865,13 +865,11 @@ impl HoneyBadgerBFT { let mut recipients: Vec = Vec::new(); match m.target { Target::Nodes(set) => { - trace!(target: "consensus", "Dispatching message {:?} to {:?}", m.message, set); for node_id in set.into_iter().filter(|p| p != net_info.our_id()) { recipients.push(node_id.0); } } Target::AllExcept(set) => { - trace!(target: "consensus", "Dispatching exclusive message {:?} to all except {:?}", m.message, set); for node_id in net_info .all_ids() .filter(|p| (p != &net_info.our_id() && !set.contains(p))) @@ -885,6 +883,7 @@ impl HoneyBadgerBFT { if self.defer_outgoing_messages.load(Ordering::SeqCst) { // Store for deferred delivery + warn!(target: "consensus", "Phoenix Protocol: Storing message for deferred sending for block #{} ", block_number); self.stored_outgoing_messages .lock() .push(StoredOutgoingMessage { @@ -895,7 +894,7 @@ impl HoneyBadgerBFT { } else { // Send immediately for node in recipients { - trace!(target: "consensus", "Sending message to {}", node); + trace!(target: "consensus", "Sending message to {} for block #{} ", node, block_number); client.send_consensus_message(block_number, ser.clone(), Some(node)); } } From c64c3f913b9c1cac591e32559a548969228456bf Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 5 Oct 2025 07:26:48 +0200 Subject: [PATCH 667/687] Cleaning up Phoenix state if a new block was imported --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 7730a8005..d4c5a18fe 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -547,6 +547,17 @@ impl HoneyBadgerBFT { warn!(target: "consensus", "Phoenix Protocol: Expecting block to be generated ({}s since last block; cycle n={}, resume @ {}, next_cycle @ {})", diff_secs, n, cycle_resume, next_cycle_start); } } + } else { + // A new block has been imported while recovery protocol was active. + // Clean up recovery state: stop deferring and deliver any stored messages. + if self.defer_outgoing_messages.load(Ordering::SeqCst) + || self.phoenix_reset_performed.load(Ordering::SeqCst) + { + self.set_defer_outgoing_messages(false); + self.deliver_stored_outgoing_messages(); + self.phoenix_reset_performed.store(false, Ordering::SeqCst); + warn!(target: "consensus", "Phoenix Protocol: Cleaned up recovery state after new block ({}s since last block < defer threshold {})", diff_secs, defer_after); + } } // Always log the latest timestamp and diff for visibility. From adf1edbda15ae3f0b11820b8b8868f245c28caaf Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 5 Oct 2025 09:28:42 +0200 Subject: [PATCH 668/687] Also resetting the sealing state when resetting the HoneyBadger state --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index d4c5a18fe..91a176b7f 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -523,9 +523,13 @@ impl HoneyBadgerBFT { )) { Some(mut state) => { if state.reset_honeybadger().is_some() { + // Also reset the sealing protocol state to avoid mixing signatures + // from the previous block creation attempt. + self.sealing.write().clear(); + self.phoenix_reset_performed .store(true, Ordering::SeqCst); - warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages and reset HoneyBadger ({}s since last block; cycle n={}, window [{}..{}))", diff_secs, n, cycle_start, cycle_resume); + warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages, reset HoneyBadger and cleared sealing state ({}s since last block; cycle n={}, window [{}..{}))", diff_secs, n, cycle_start, cycle_resume); } else { warn!(target: "consensus", "Phoenix Protocol: Deferred outgoing messages but failed to reset HoneyBadger ({}s since last block; cycle n={}, window [{}..{}))", diff_secs, n, cycle_start, cycle_resume); } From 2d2e0446e17ba7e26ace28061aed7a09e4107f83 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 5 Oct 2025 11:05:46 +0200 Subject: [PATCH 669/687] Hbbft KeyGen Transactions Nonce management reworked: - ignores transactions already in the Queue - could lead to closing of nonce gaps - overwrites other service transactions - possibility that the service transaction is not written, because another one is already inflight. --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 6 +- .../src/engines/hbbft/keygen_transactions.rs | 55 ++++++++++++------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index a6199e33d..15138a78a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -461,7 +461,7 @@ impl HoneyBadgerBFT { let engine = Arc::new(HoneyBadgerBFT { transition_service: IoService::<()>::start("Hbbft", 4)?, hbbft_peers_service: IoService::::start( - "peers_management", + "hbbftp", /* hbbft peers (we use 6 letter acronyms for nice log file layout.) */ 1, )?, client: Arc::new(RwLock::new(None)), @@ -484,7 +484,9 @@ impl HoneyBadgerBFT { params, message_counter: Mutex::new(0), // restore message counter from memory here for RBC ? */ random_numbers: RwLock::new(BTreeMap::new()), - keygen_transaction_sender: RwLock::new(KeygenTransactionSender::new()), + /* Todo: make this configureable + */ + keygen_transaction_sender: RwLock::new(KeygenTransactionSender::new(1, 60000)), has_connected_to_validator_set: AtomicBool::new(false), current_minimum_gas_price: Mutex::new(None), diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index bd7f68afe..7860b609a 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -55,6 +55,13 @@ pub struct ServiceTransactionMemory { } pub struct KeygenTransactionSender { + /// Minimum delay between for resending key gen transactions in milliseconds. + key_gen_transaction_delay_milliseconds: u128, + + /// Minimum delay between for resending key gen in blocks. + key_gen_transaction_delay_blocks: u64, + + /// Last key gen service transaction we sent. last_keygen_service_transaction: Option, } @@ -83,13 +90,15 @@ impl From for KeyGenError { } } -static KEYGEN_TRANSACTION_RESEND_DELAY_SECONDS: u64 = 30; -static KEYGEN_TRANSACTION_RESEND_DELAY_BLOCKS: u64 = 2; - impl KeygenTransactionSender { - pub fn new() -> Self { + pub fn new( + key_gen_transaction_delay_blocks: u64, + key_gen_transaction_delay_milliseconds: u128, + ) -> Self { KeygenTransactionSender { last_keygen_service_transaction: None, + key_gen_transaction_delay_blocks, + key_gen_transaction_delay_milliseconds, } } @@ -119,12 +128,9 @@ impl KeygenTransactionSender { return Ok(ShouldSendKeyAnswer::Yes); } - // we will check the state of our send transaction. - // client.queued_transactions(). - // if we are still in the same situation, we need to figure out if we just should retry to send our last transaction. - if last_sent.send_time.elapsed().as_secs() - < KEYGEN_TRANSACTION_RESEND_DELAY_SECONDS + if last_sent.send_time.elapsed().as_millis() + < self.key_gen_transaction_delay_milliseconds { // we sent a transaction recently, so we should wait a bit. return Ok(ShouldSendKeyAnswer::NoWaiting); @@ -133,12 +139,16 @@ impl KeygenTransactionSender { let current_block = client.block_number(BlockId::Latest).unwrap_or(0); // this check also prevents the resending of Transactions if no block got mined. (e.g. because of stalled network) - if last_sent.block_sent + KEYGEN_TRANSACTION_RESEND_DELAY_BLOCKS + if last_sent.block_sent + self.key_gen_transaction_delay_blocks > current_block { + // rational behind: + // if blocks are not created anyway, + // we do not have to send new transactions. + // example: // send on block 10 (last_sent.block_sent = 10) - // KEYGEN_TRANSACTION_RESEND_DELAY_BLOCKS = 2 + // key_gen_transaction_delay_blocks = 2 // resent after Block 12. // current block is 11: waiting // current block is 12: waiting @@ -423,12 +433,18 @@ impl KeygenTransactionSender { let gas = total_bytes_for_acks * 850 + 200_000; trace!(target: "engine","acks-len: {} gas: {}", total_bytes_for_acks, gas); - // full_client.nonce(&mining_address, BlockId::Latest).unwrap(); // Nonce Management is complex. - // we will include queued transactions here, - // but it could lead to a problem where "unprocessed" stuck transactions are producing Nonce gaps. - - let nonce = full_client.next_nonce(&*mining_address); + // we wont include queued transactions here, + // because key gen transactions are so important, + // that they are topic to "replace" other service transactions. + // it could trigger in a scenario where a service transaction was just sent, + // is getting included by other nodes, but this one does not know about it yet, + // sending a Nonce that is to small. + // A better ServiceTransactionManager could be implemented to handle this more gracefully. + + let nonce = full_client + .nonce(&*mining_address, BlockId::Latest) + .unwrap_or(U256::zero()); let acks_transaction = TransactionRequest::call(*KEYGEN_HISTORY_ADDRESS, write_acks_data.0) .gas(U256::from(gas)) @@ -471,9 +487,10 @@ impl KeygenTransactionSender { // and usually run into the gas limit problems. let gas: usize = data.len() * 800 + 100_000; - // WARNING: This Nonce could conflict with other Service Transactions. - // a better ServiceTransactionManager could be improve this here. - let nonce = full_client.next_nonce(&*mining_address); //full_client.nonce(&mining_address, BlockId::Latest).unwrap(); + // for detailed nonce management rational, check up send_ack_transaction. + let nonce = full_client + .nonce(&*mining_address, BlockId::Latest) + .unwrap_or(U256::zero()); let write_part_data = key_history_contract::functions::write_part::call(upcoming_epoch, current_round, data); From 2cc179e5fded222307ed226442f6acc808cb7ac0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 5 Oct 2025 13:04:48 +0200 Subject: [PATCH 670/687] Client supports now to query the Status of local transactions. + Log Level adjustments --- crates/concensus/miner/src/pool/queue.rs | 13 +++++++++++++ crates/ethcore/src/client/client.rs | 12 +++++++++++- .../src/engines/hbbft/contracts/validator_set.rs | 2 +- .../src/engines/hbbft/hbbft_peers_management.rs | 4 ++-- .../src/engines/hbbft/keygen_transactions.rs | 7 +++++++ crates/ethcore/src/miner/miner.rs | 4 ++++ crates/ethcore/src/miner/mod.rs | 8 +++++++- crates/rpc/src/v1/tests/helpers/miner_service.rs | 4 ++++ 8 files changed, 49 insertions(+), 5 deletions(-) diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index ddea78e91..834f34369 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -41,6 +41,8 @@ use crate::pool::{ verifier, PendingOrdering, PendingSettings, PrioritizationStrategy, }; +use super::local_transactions; + type Listener = ( LocalTransactionsList, (listener::Notifier, listener::Logger), @@ -546,6 +548,17 @@ impl TransactionQueue { ) } + /// Returns status of a local transaction by its hash. + pub fn local_transaction_status(&self, tx_hash: &H256) -> Option { + self.pool + .read() + .listener() + .0 + .all_transactions() + .get(tx_hash) + .cloned() + } + /// Collect pending transactions. /// /// NOTE This is re-computing the pending set and it might be expensive to do so. diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 99d3a0afe..b56d3d883 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -89,7 +89,7 @@ use ansi_term::Colour; use bytes::{Bytes, ToPretty}; use call_contract::{CallContract, RegistryInfo}; use db::{DBTransaction, DBValue, KeyValueDB}; -use ethcore_miner::pool::VerifiedTransaction; +use ethcore_miner::pool::{VerifiedTransaction, local_transactions::Status}; use ethereum_types::{Address, H256, H264, H512, U256}; use hash::keccak; use itertools::Itertools; @@ -1410,6 +1410,16 @@ impl Client { } } + /// Get local transactions from the miner. + pub fn local_transactions(&self) -> BTreeMap { + self.importer.miner.local_transactions() + } + + /// Get local transactions from the miner. + pub fn local_transaction_status(&self, tx_hash: &H256) -> Option { + self.importer.miner.local_transaction_status(tx_hash) + } + /// Get shared miner reference. #[cfg(test)] pub fn miner(&self) -> Arc { diff --git a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs index 59632cea9..9ad5ec5cd 100644 --- a/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs +++ b/crates/ethcore/src/engines/hbbft/contracts/validator_set.rs @@ -81,7 +81,7 @@ pub fn is_pending_validator( call_const_validator!(c, is_pending_validator, staking_address.clone()) } -#[derive(PartialEq)] +#[derive(PartialEq, Debug)] pub enum KeyGenMode { WritePart, WriteAck, diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 0d1cc8cba..183282521 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -91,7 +91,7 @@ impl HbbftPeersManagement { ) { connected_current_pending_validators.push(connected_validator); } else { - warn!(target: "Engine", "could not add pending validator to reserved peers: {}", pending_validator_address); + debug!(target: "Engine", "could not add pending validator to reserved peers: {}", pending_validator_address); } } } @@ -546,7 +546,7 @@ fn connect_to_validator_core( }; if socket_addr.port() == 0 { - error!(target: "engine", "connect_to_validator_core: no port specified for Node ( Public (NodeId): {:?} , staking address: {}, socket_addr: {:?}", node_id, staking_address, socket_addr); + debug!(target: "engine", "connect_to_validator_core: no port specified for Node ( Public (NodeId): {:?} , staking address: {}, socket_addr: {:?}", node_id, staking_address, socket_addr); // we interprate port 0 as NULL. return None; } diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 7860b609a..9fed22d88 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -440,6 +440,13 @@ impl KeygenTransactionSender { // it could trigger in a scenario where a service transaction was just sent, // is getting included by other nodes, but this one does not know about it yet, // sending a Nonce that is to small. + // if a transaction gets replaced, "own_tx Transaction culled" happens, + // in this case we there are signs, that our key gen transaction was not included, + // and we might need to resend it. + // currently there is no "observer" available, to observe culled transactions, + // local_transactions frequently deletes outdated transactions. + // however: we could check if the transaction is neither available in the service transaction pool, + // nor available as included transaction. // A better ServiceTransactionManager could be implemented to handle this more gracefully. let nonce = full_client diff --git a/crates/ethcore/src/miner/miner.rs b/crates/ethcore/src/miner/miner.rs index 32212d73b..ee2135764 100644 --- a/crates/ethcore/src/miner/miner.rs +++ b/crates/ethcore/src/miner/miner.rs @@ -1484,6 +1484,10 @@ impl miner::MinerService for Miner { .expect("remove() returns one result per hash; one hash passed; qed") } + fn local_transaction_status(&self, hash: &H256) -> Option { + self.transaction_queue.local_transaction_status(hash) + } + fn queue_status(&self) -> QueueStatus { self.transaction_queue.status() } diff --git a/crates/ethcore/src/miner/mod.rs b/crates/ethcore/src/miner/mod.rs index cd0365f15..c7e87a0b5 100644 --- a/crates/ethcore/src/miner/mod.rs +++ b/crates/ethcore/src/miner/mod.rs @@ -46,7 +46,10 @@ use crate::types::{ transaction::{self, PendingTransaction, SignedTransaction, UnverifiedTransaction}, }; use bytes::Bytes; -use ethcore_miner::pool::{QueueStatus, VerifiedTransaction, local_transactions}; +use ethcore_miner::pool::{ + QueueStatus, VerifiedTransaction, + local_transactions::{self, Status}, +}; use ethereum_types::{Address, H256, U256}; use crate::{ @@ -287,4 +290,7 @@ pub trait MinerService: Send + Sync { /// Set a new minimum gas limit. /// Will not work if dynamic gas calibration is set. fn set_minimal_gas_price(&self, gas_price: U256) -> Result; + + /// Get the status of a local transaction by its hash. + fn local_transaction_status(&self, hash: &H256) -> Option; } diff --git a/crates/rpc/src/v1/tests/helpers/miner_service.rs b/crates/rpc/src/v1/tests/helpers/miner_service.rs index 3a60429e2..2d9164866 100644 --- a/crates/rpc/src/v1/tests/helpers/miner_service.rs +++ b/crates/rpc/src/v1/tests/helpers/miner_service.rs @@ -286,6 +286,10 @@ impl MinerService for TestMinerService { .collect() } + fn local_transaction_status(&self, tx_hash: &H256) -> Option { + self.local_transactions.lock().get(tx_hash).cloned() + } + fn ready_transactions_filtered( &self, chain: &C, From 42e88fad64f0aeb63f02023a89ba2ca53de888ad Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 5 Oct 2025 14:51:41 +0200 Subject: [PATCH 671/687] KeyGenTransaction sender now directly acts, if a transaction got dropped, Rejected, Replaced, Invalid or Canceled. --- crates/ethcore/src/client/client.rs | 5 ++ crates/ethcore/src/client/test_client.rs | 6 ++- crates/ethcore/src/client/traits.rs | 8 ++- .../src/engines/hbbft/keygen_transactions.rs | 54 +++++++++++++++++-- crates/ethcore/sync/src/chain/propagator.rs | 2 +- 5 files changed, 69 insertions(+), 6 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index b56d3d883..e4cc85d3f 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -3370,6 +3370,11 @@ impl super::traits::EngineClient for Client { .miner .create_pending_block_at(self, txns, timestamp, block_number) } + + /// Get local transactions from the miner. + fn local_transaction_status(&self, tx_hash: &H256) -> Option { + self.importer.miner.local_transaction_status(tx_hash) + } } impl ProvingBlockChainClient for Client { diff --git a/crates/ethcore/src/client/test_client.rs b/crates/ethcore/src/client/test_client.rs index a5df50670..b8be5b6f9 100644 --- a/crates/ethcore/src/client/test_client.rs +++ b/crates/ethcore/src/client/test_client.rs @@ -48,7 +48,7 @@ use crate::{ use bytes::Bytes; use crypto::publickey::{Generator, Random}; use db::{COL_STATE, NUM_COLUMNS}; -use ethcore_miner::pool::VerifiedTransaction; +use ethcore_miner::pool::{VerifiedTransaction, local_transactions::Status}; use ethereum_types::{Address, H256, H512, U256}; use ethtrie; use hash::keccak; @@ -1274,6 +1274,10 @@ impl super::traits::EngineClient for TestBlockChainClient { } fn demand_shutdown(&self) {} + + fn local_transaction_status(&self, tx_hash: &H256) -> Option { + self.miner.local_transaction_status(tx_hash) + } } impl PrometheusMetrics for TestBlockChainClient { diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 86c88e1d9..7c9c5c535 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -45,7 +45,7 @@ use crate::{ }; use bytes::Bytes; use call_contract::{CallContract, RegistryInfo}; -use ethcore_miner::pool::VerifiedTransaction; +use ethcore_miner::pool::{VerifiedTransaction, local_transactions::Status}; use ethereum_types::{Address, H256, H512, U256}; use evm::Schedule; use itertools::Itertools; @@ -707,6 +707,12 @@ pub trait EngineClient: Sync + Send + ChainInfo { fn config_shutdown_on_missing_block_import(&self) -> Option { None } + + /// Get local transaction status. + /// Note that already included transactions might be not available here anymore. + /// As well as transactions that were culled, replaced, dropped or whatever, + /// do not exist forever in the memory. + fn local_transaction_status(&self, tx_hash: &H256) -> Option; } /// Extended client interface for providing proofs of the state. diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 9fed22d88..1048707a2 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -20,7 +20,9 @@ use crate::{ }, types::ids::BlockId, }; +use ethcore_miner::pool::local_transactions::Status; use ethereum_types::{Address, Public, U256}; +use hash::H256; use hbbft::sync_key_gen::SyncKeyGen; use itertools::Itertools; use parking_lot::RwLock; @@ -40,7 +42,8 @@ pub struct ServiceTransactionMemory { pub send_time: Instant, // It would be good to have a transaction Hash here. - //pub transaction_hash: H256, + pub transaction_hash: H256, + /// Type of the transaction, e.g. KeyGen Part or Ack. pub transaction_type: ServiceTransactionType, @@ -128,6 +131,51 @@ impl KeygenTransactionSender { return Ok(ShouldSendKeyAnswer::Yes); } + let mut transaction_lost = false; + // check if our last sent transaction is still pending. + if let Some(service_tx_state) = + client.local_transaction_status(&last_sent.transaction_hash) + { + match service_tx_state { + Status::Culled(_) + | Status::Dropped(_) + | Status::Rejected(..) + | Status::Replaced { .. } + | Status::Invalid(_) + | Status::Canceled(_) => { + transaction_lost = true; + } + _ => {} + } + } else { + // the transaction got lost, and probably transaction info got already deleted. + // it still might also got already included into a block. + transaction_lost = true; + } + + if transaction_lost { + // maybe we lost the key gen transaction, because it got included into a block. + + // make sure we did not just witness block inclusion. + if let Some(full_client) = client.as_full_client() { + if let Some(transaction) = full_client.block_transaction( + types::ids::TransactionId::Hash( + last_sent.transaction_hash.clone(), + ), + ) { + // our service transaction got included. + warn!(target: "engine", "key gen transaction got included in block {} but we are still in wrong state ?!", transaction.block_number); + return Ok(ShouldSendKeyAnswer::NoWaiting); + } else { + // our transaction is not pending anymore, and also has not got included into a block, we should resend. + return Ok(ShouldSendKeyAnswer::Yes); + } + } else { + // that should really never happen. + warn!(target:"engine", "could not get full client to check for inclusion of key gen transaction"); + } + } + // if we are still in the same situation, we need to figure out if we just should retry to send our last transaction. if last_sent.send_time.elapsed().as_millis() < self.key_gen_transaction_delay_milliseconds @@ -471,7 +519,7 @@ impl KeygenTransactionSender { KeyGenMode::WriteAck, ), //nonce: nonce, - //transaction_hash: hash, + transaction_hash: hash, block_sent: client.block_number(BlockId::Latest).unwrap_or(0), }); @@ -515,7 +563,7 @@ impl KeygenTransactionSender { self.last_keygen_service_transaction = Some(ServiceTransactionMemory { send_time: Instant::now(), - //transaction_hash: hash, + transaction_hash: hash, transaction_type: ServiceTransactionType::KeyGenTransaction( upcoming_epoch.as_u64(), current_round.as_u64(), diff --git a/crates/ethcore/sync/src/chain/propagator.rs b/crates/ethcore/sync/src/chain/propagator.rs index a765ac9b0..c0b0fafde 100644 --- a/crates/ethcore/sync/src/chain/propagator.rs +++ b/crates/ethcore/sync/src/chain/propagator.rs @@ -433,7 +433,7 @@ impl ChainSync { let peer_id = match io.node_id_to_peer_id(peer) { Some(id) => id, None => { - warn!(target: "sync", "Peer with node id {} not found in peers list.", peer); + debug!(target: "sync", "Cannot send consensus message: Peer with node id {} seems not to be connected.", peer); return Err(ErrorKind::PeerNotFound.into()); } }; From f46aca9af2f0c9fb3cc72cb2fecc98101a57fcd1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 5 Oct 2025 14:57:09 +0200 Subject: [PATCH 672/687] grammar and import fixes --- crates/concensus/miner/src/pool/queue.rs | 4 +--- crates/ethcore/src/engines/hbbft/keygen_transactions.rs | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index 834f34369..7e3ba897c 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -41,8 +41,6 @@ use crate::pool::{ verifier, PendingOrdering, PendingSettings, PrioritizationStrategy, }; -use super::local_transactions; - type Listener = ( LocalTransactionsList, (listener::Notifier, listener::Logger), @@ -549,7 +547,7 @@ impl TransactionQueue { } /// Returns status of a local transaction by its hash. - pub fn local_transaction_status(&self, tx_hash: &H256) -> Option { + pub fn local_transaction_status(&self, tx_hash: &H256) -> Option { self.pool .read() .listener() diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 1048707a2..2e135ffae 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -61,7 +61,7 @@ pub struct KeygenTransactionSender { /// Minimum delay between for resending key gen transactions in milliseconds. key_gen_transaction_delay_milliseconds: u128, - /// Minimum delay between for resending key gen in blocks. + /// Minimum delay for resending key gen transactions, in milliseconds. key_gen_transaction_delay_blocks: u64, /// Last key gen service transaction we sent. @@ -160,7 +160,7 @@ impl KeygenTransactionSender { if let Some(full_client) = client.as_full_client() { if let Some(transaction) = full_client.block_transaction( types::ids::TransactionId::Hash( - last_sent.transaction_hash.clone(), + last_sent.transaction_hash, ), ) { // our service transaction got included. From 9be7bf90d90d05df083e12b3919b1da08432c753 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 5 Oct 2025 15:04:32 +0200 Subject: [PATCH 673/687] cargo fmt --all -- --config imports_granularity=Crate --- crates/concensus/miner/src/pool/queue.rs | 5 ++++- crates/ethcore/src/engines/hbbft/keygen_transactions.rs | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index 7e3ba897c..3034123d4 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -547,7 +547,10 @@ impl TransactionQueue { } /// Returns status of a local transaction by its hash. - pub fn local_transaction_status(&self, tx_hash: &H256) -> Option { + pub fn local_transaction_status( + &self, + tx_hash: &H256, + ) -> Option { self.pool .read() .listener() diff --git a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs index 2e135ffae..b611865e5 100644 --- a/crates/ethcore/src/engines/hbbft/keygen_transactions.rs +++ b/crates/ethcore/src/engines/hbbft/keygen_transactions.rs @@ -159,9 +159,7 @@ impl KeygenTransactionSender { // make sure we did not just witness block inclusion. if let Some(full_client) = client.as_full_client() { if let Some(transaction) = full_client.block_transaction( - types::ids::TransactionId::Hash( - last_sent.transaction_hash, - ), + types::ids::TransactionId::Hash(last_sent.transaction_hash), ) { // our service transaction got included. warn!(target: "engine", "key gen transaction got included in block {} but we are still in wrong state ?!", transaction.block_number); From 9f3c15fd1b57b2265d71504552b16ec9dc826ee9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 5 Oct 2025 15:37:32 +0200 Subject: [PATCH 674/687] v0.12.7 Changelog --- CHANGELOG.md | 4 ++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6bba1319..1230b680e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ +## Diamond Node Software 0.12.7 + +- [hbbft key generation: double transactions / missing transactions](https://github.com/DMDcoin/diamond-node/issues/290) + ## Diamond Node Software 0.12.6 - reduced Trace Log output for tracing devp2p propagation diff --git a/Cargo.lock b/Cargo.lock index e4fce244e..8e47578f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "0.12.6" +version = "0.12.7" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.6" +version = "0.12.7" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 572f0aa1b..46d350884 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "0.12.6" +version = "0.12.7" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index e2aaad9c1..5a10f82c7 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.6" +version = "0.12.7" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 965c74d0f48dbc178235e66b260112667dd3df4a Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 5 Oct 2025 17:12:36 +0200 Subject: [PATCH 675/687] Using trace level for purely informative Phoenix Protocol logs --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 91a176b7f..ffa7cbac9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -565,7 +565,7 @@ impl HoneyBadgerBFT { } // Always log the latest timestamp and diff for visibility. - warn!(target: "consensus", "Phoenix Protocol: latest block timestamp: {} (diff_secs: {})", h.timestamp(), diff_secs); + trace!(target: "consensus", "Phoenix Protocol: latest block timestamp: {} (diff_secs: {})", h.timestamp(), diff_secs); } None => { error!(target: "consensus", "Phoenix Protocol: No latest block header available."); From 079c92c12a882239d994c982d6c8d795d33fcc6d Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 5 Oct 2025 19:37:04 +0200 Subject: [PATCH 676/687] Implemented incremental increase of time for Phoenix Protocol retries --- .../ethcore/src/engines/hbbft/hbbft_engine.rs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index ffa7cbac9..cb0ee2ea9 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -480,6 +480,12 @@ impl HoneyBadgerBFT { // Phoenix recovery protocol parameters // Start deferring and reset HoneyBadger after this many seconds without a new block. const PHOENIX_DEFER_AFTER_SECS: i64 = 60; + // Add this number to PHOENIX_DEFER_AFTER_SECS for each try after the first try to + // incrementally increase the time for the next block creation attempt. + // If 'n' is the current try, starting at 0 then: + // Try(0): PHOENIX_DEFER_AFTER_SECS + // Try(n): Try(n-1) + PHOENIX_DEFER_AFTER_SECS + n * PHOENIX_DEFER_INCREMENT_SECS + const PHOENIX_DEFER_INCREMENT_SECS: i64 = 2; // Resume sending and deliver deferred messages after this many seconds. const PHOENIX_RESUME_AFTER_SECS: i64 = 20; // Timeout for trying to acquire the hbbft_state lock to reset HoneyBadger, in milliseconds. @@ -506,11 +512,26 @@ impl HoneyBadgerBFT { let resume_after = Self::PHOENIX_RESUME_AFTER_SECS; if diff_secs >= defer_after { - // Determine the current recovery cycle index n and its boundaries. - let n = diff_secs / defer_after; // floor division - let cycle_start = n * defer_after; // n * DEFER - let cycle_resume = cycle_start + resume_after; // n * DEFER + RESUME - let next_cycle_start = (n + 1) * defer_after; // (n+1) * DEFER + // Determine the current recovery cycle index n and its boundaries using + // increasing delays per try. The cumulative start time S_n is defined as: + // S_0 = PHOENIX_DEFER_AFTER_SECS + // S_n = S_{n-1} + PHOENIX_DEFER_AFTER_SECS + n * PHOENIX_DEFER_INCREMENT_SECS + let mut n: i64 = 0; + let mut cycle_start: i64 = defer_after; // S_0 + let next_cycle_start: i64; + loop { + let incr = defer_after + (n + 1) * Self::PHOENIX_DEFER_INCREMENT_SECS; + let candidate_next = cycle_start + incr; // S_{n+1} + if diff_secs >= candidate_next { + n += 1; + cycle_start = candidate_next; // advance to next cycle + continue; + } else { + next_cycle_start = candidate_next; + break; + } + } + let cycle_resume = cycle_start + resume_after; if diff_secs < cycle_resume { // We are within the deferring window of the current cycle. From 50911e00e89af2937ea419d8874f6267e81fd44d Mon Sep 17 00:00:00 2001 From: David Forstenlechner Date: Sun, 5 Oct 2025 19:48:39 +0200 Subject: [PATCH 677/687] Starting Phoenix Protokoll after 10 minutes Every re-try gets 2 minutes more time to create the block. The first 2 minutes validators receive but do not send hbbft messages. This is to account for up to 2 minutes timing differences between validators. --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index cb0ee2ea9..317fc6d80 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -479,15 +479,15 @@ impl IoHandler<()> for TransitionHandler { impl HoneyBadgerBFT { // Phoenix recovery protocol parameters // Start deferring and reset HoneyBadger after this many seconds without a new block. - const PHOENIX_DEFER_AFTER_SECS: i64 = 60; + const PHOENIX_DEFER_AFTER_SECS: i64 = 600; // Add this number to PHOENIX_DEFER_AFTER_SECS for each try after the first try to // incrementally increase the time for the next block creation attempt. // If 'n' is the current try, starting at 0 then: // Try(0): PHOENIX_DEFER_AFTER_SECS // Try(n): Try(n-1) + PHOENIX_DEFER_AFTER_SECS + n * PHOENIX_DEFER_INCREMENT_SECS - const PHOENIX_DEFER_INCREMENT_SECS: i64 = 2; + const PHOENIX_DEFER_INCREMENT_SECS: i64 = 120; // Resume sending and deliver deferred messages after this many seconds. - const PHOENIX_RESUME_AFTER_SECS: i64 = 20; + const PHOENIX_RESUME_AFTER_SECS: i64 = 120; // Timeout for trying to acquire the hbbft_state lock to reset HoneyBadger, in milliseconds. const PHOENIX_LOCK_TIMEOUT_MS: u64 = 100; From b6c969b088ac802876b63b5d9b89b8f4c57ee883 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Oct 2025 16:22:29 +0200 Subject: [PATCH 678/687] v0.12.8 --- CHANGELOG.md | 4 ++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1230b680e..dffda89f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ +## Diamond Node Software 0.12.8 + +- [Phoenix Protocol](https://github.com/DMDcoin/openethereum-3.x/issues/52) + ## Diamond Node Software 0.12.7 - [hbbft key generation: double transactions / missing transactions](https://github.com/DMDcoin/diamond-node/issues/290) diff --git a/Cargo.lock b/Cargo.lock index 8e47578f6..09c35a2b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "0.12.7" +version = "0.12.8" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.7" +version = "0.12.8" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 46d350884..fcc2a1643 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "0.12.7" +version = "0.12.8" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 5a10f82c7..4195e0c7a 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.7" +version = "0.12.8" authors = [ "bit.diamonds developers", "OpenEthereum developers", From a01da6732fade2b74fc061b14faaee4f209a4edb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 7 Oct 2025 22:58:19 +0200 Subject: [PATCH 679/687] Logging Improvement: Do not print "removed 0 peers from reserved peers management." --- crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs index 183282521..8a8cf7c11 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_peers_management.rs @@ -298,7 +298,9 @@ impl HbbftPeersManagement { } } - info!(target: "engine", "removed {} peers from reserved peers management.", removed.len()); + if removed.len() > 0 { + info!(target: "engine", "removed {} peers from reserved peers management.", removed.len()); + } } // regardless of disconnect problems here, we clear all the data here. From 78289f53c04aeae05c75f49251c682942e272a8d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 7 Oct 2025 23:05:17 +0200 Subject: [PATCH 680/687] Phoenix Protocol: do not execute if major syncing --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 0900242e4..57cb679c1 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -498,7 +498,7 @@ impl HoneyBadgerBFT { fn handle_phoenix_recovery_protocol(&self) { if let Some(client) = self.client_arc() { // Skip if still syncing. - if self.is_syncing(&client) { + if self.is_major_syncing(&client) { return; } @@ -1405,6 +1405,14 @@ impl HoneyBadgerBFT { } } + fn is_major_syncing(&self, client: &Arc) -> bool { + match client.as_full_client() { + Some(full_client) => full_client.is_major_syncing(), + // We only support full clients at this point. + None => true, + } + } + /** returns if the signer of hbbft is tracked as available in the hbbft contracts..*/ pub fn is_available(&self) -> bool { self.hbbft_engine_cache.lock().is_available() From 07efbdab27b40211cdd58602a967d26bf373dd17 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Oct 2025 14:21:17 +0200 Subject: [PATCH 681/687] Phoenix Protocol: Only validators need to check for phoenix protocol: https://github.com/DMDcoin/openethereum-3.x/issues/52 --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 57cb679c1..aeda42b56 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -496,6 +496,12 @@ impl HoneyBadgerBFT { /// Retry recovery every n*PHOENIX_DEFER_AFTER_SECS by deferring and resetting, /// and resume sending messages every n*PHOENIX_DEFER_AFTER_SECS + PHOENIX_RESUME_AFTER_SECS. fn handle_phoenix_recovery_protocol(&self) { + + + if self.hbbft_state.read().is_validator() { + return; + } + if let Some(client) = self.client_arc() { // Skip if still syncing. if self.is_major_syncing(&client) { From bb517290825be8f32466b3d21f0b788c2cdc72f6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Oct 2025 23:06:18 +0200 Subject: [PATCH 682/687] Hbbft Engine --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index aeda42b56..5d6857188 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -496,8 +496,6 @@ impl HoneyBadgerBFT { /// Retry recovery every n*PHOENIX_DEFER_AFTER_SECS by deferring and resetting, /// and resume sending messages every n*PHOENIX_DEFER_AFTER_SECS + PHOENIX_RESUME_AFTER_SECS. fn handle_phoenix_recovery_protocol(&self) { - - if self.hbbft_state.read().is_validator() { return; } From 319e8e49cb831444c113e2436eabab38d9d6029e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 8 Oct 2025 23:08:45 +0200 Subject: [PATCH 683/687] updated link to discord --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed4d9b415..29b32681c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Node client for the protocol version 4 of the bit.diamonds network. [license-badge]: https://img.shields.io/badge/license-GPL_v3-green.svg [license-url]: LICENSE -[chat-url]: (https://dmdcoin.slack.com/) +[chat-url]: (https://discord.com/invite/MwqZ2CYcB4) ## Table of Contents From d6780cb25b29280a55470f82c82b21742cef74f7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 11 Oct 2025 16:34:15 +0200 Subject: [PATCH 684/687] Bugfix for Phoenix Protocol --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index 5d6857188..aebf8ea05 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -496,7 +496,8 @@ impl HoneyBadgerBFT { /// Retry recovery every n*PHOENIX_DEFER_AFTER_SECS by deferring and resetting, /// and resume sending messages every n*PHOENIX_DEFER_AFTER_SECS + PHOENIX_RESUME_AFTER_SECS. fn handle_phoenix_recovery_protocol(&self) { - if self.hbbft_state.read().is_validator() { + + if !self.hbbft_state.read().is_validator() { return; } From 045d89a3dcca706b37881e6a82ea306e8b4c0e1f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 11 Oct 2025 17:05:41 +0200 Subject: [PATCH 685/687] version update --- CHANGELOG.md | 4 ++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dffda89f6..0866f9009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ +## Diamond Node Software 0.12.9 + +- [Phoenix Protocol Bugfix for Validators](https://github.com/DMDcoin/openethereum-3.x/issues/52) + ## Diamond Node Software 0.12.8 - [Phoenix Protocol](https://github.com/DMDcoin/openethereum-3.x/issues/52) diff --git a/Cargo.lock b/Cargo.lock index 09c35a2b0..947109e22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "0.12.8" +version = "0.12.9" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.8" +version = "0.12.9" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index fcc2a1643..7564377d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "0.12.8" +version = "0.12.9" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 4195e0c7a..14db45cf7 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.8" +version = "0.12.9" authors = [ "bit.diamonds developers", "OpenEthereum developers", From 857fd0126dc5eccd7d66d40e4d350b93299f3bb9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 11 Oct 2025 17:09:16 +0200 Subject: [PATCH 686/687] V0.12.9 cargo fmt --all -- --config imports_granularity=Crate --- crates/ethcore/src/engines/hbbft/hbbft_engine.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs index aebf8ea05..2ff4f8c1a 100644 --- a/crates/ethcore/src/engines/hbbft/hbbft_engine.rs +++ b/crates/ethcore/src/engines/hbbft/hbbft_engine.rs @@ -496,7 +496,6 @@ impl HoneyBadgerBFT { /// Retry recovery every n*PHOENIX_DEFER_AFTER_SECS by deferring and resetting, /// and resume sending messages every n*PHOENIX_DEFER_AFTER_SECS + PHOENIX_RESUME_AFTER_SECS. fn handle_phoenix_recovery_protocol(&self) { - if !self.hbbft_state.read().is_validator() { return; } From 627213377aac26e67d791f3990ac3726302222f2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 11 Oct 2025 21:25:01 +0200 Subject: [PATCH 687/687] release v4.0.0 --- CHANGELOG.md | 4 ++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- crates/util/version/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0866f9009..1165802c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Diamond Node Software 4.0.0 + +Official Node Software start version for the DMD Diamond network version 4. +see Whitepaper: https://github.com/DMDcoin/whitepaper/wiki ## Diamond Node Software 0.12.9 diff --git a/Cargo.lock b/Cargo.lock index 947109e22..c9f3ba8b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "diamond-node" -version = "0.12.9" +version = "4.0.0" dependencies = [ "ansi_term 0.10.2", "atty", @@ -3579,7 +3579,7 @@ dependencies = [ [[package]] name = "parity-version" -version = "0.12.9" +version = "4.0.0" dependencies = [ "parity-bytes", "rlp", diff --git a/Cargo.toml b/Cargo.toml index 7564377d5..f1b4fc09b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Diamond Node" name = "diamond-node" # NOTE Make sure to update util/version/Cargo.toml as well -version = "0.12.9" +version = "4.0.0" license = "GPL-3.0" authors = [ "bit.diamonds developers", diff --git a/crates/util/version/Cargo.toml b/crates/util/version/Cargo.toml index 14db45cf7..868888bc2 100644 --- a/crates/util/version/Cargo.toml +++ b/crates/util/version/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "parity-version" # NOTE: this value is used for OpenEthereum version string (via env CARGO_PKG_VERSION) -version = "0.12.9" +version = "4.0.0" authors = [ "bit.diamonds developers", "OpenEthereum developers",