Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-691: Integrate --min-hops with PersistentConfiguration #294

Merged
merged 28 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7839117
GH-691: database migration for 7 to 8
utkarshg6 May 24, 2023
fbc3b2c
GH-691: update CURRENT_SCHEMA_VERSION to 8
utkarshg6 May 26, 2023
073cef4
GH-691: add test to set the min_hops_count inside PersistentConfigura…
utkarshg6 May 26, 2023
e3c20ed
GH-691: fix tests in actor_system_factory.rs
utkarshg6 May 26, 2023
46e970f
GH-691: add the ability to retrieve value of min_hops_count from the …
utkarshg6 May 29, 2023
17e1637
GH-691: add tests for validating min hops count
utkarshg6 May 30, 2023
c4f3a40
Merge branch 'master' into GH-691
utkarshg6 May 31, 2023
64165bd
GH-691: test drive code for validating the min_hops_count value from …
utkarshg6 May 31, 2023
332ab34
GH-691: minor code improvements
utkarshg6 May 31, 2023
2edab63
GH-691: remove second declaration of CURRENT_SCHEMA_VERSION
utkarshg6 May 31, 2023
5b53609
GH-691: remove unnecessary comments
utkarshg6 May 31, 2023
8558e2d
GH-691: improve validate_database_min_hops_count()
utkarshg6 May 31, 2023
8e1f9ee
GH-691: fixed test cleanup_after_deceased_clients_integration
utkarshg6 May 31, 2023
ded2f87
GH-691: add todos to where we should set the min_hops_count
utkarshg6 May 31, 2023
55e744b
GH-691: set min_hops_count value inside configure_database()
utkarshg6 Jun 1, 2023
cd109f3
GH-691: remove code for setting min_hops_count inside actor_system_fa…
utkarshg6 Jun 1, 2023
ee716f8
GH-691: set min_hops_count default value while initializing database
utkarshg6 Jun 1, 2023
f1e5e0e
GH-691: change how min_hops_count is handled inside make_neighborhood…
utkarshg6 Jun 1, 2023
b63d4be
GH-691: instead of defaulting min_hops_count inside clap, default it …
utkarshg6 Jun 1, 2023
62704a0
GH-691: feed min_hops_count value inside ConfigDaoNull
utkarshg6 Jun 1, 2023
87dfd96
GH-691: add test for checking whether the node panics when the min_ho…
utkarshg6 Jun 2, 2023
36ae5a6
GH-691: remove clippy warnings
utkarshg6 Jun 2, 2023
771125d
GH-691: remove redundant code
utkarshg6 Jun 2, 2023
a07bc9e
GH-691: more improvements to validate_database_min_hops_count()
utkarshg6 Jun 2, 2023
d53b61b
GH-691: Review 1 (#300)
utkarshg6 Jun 22, 2023
6b1e7b0
Merge branch 'master' into GH-691
utkarshg6 Jun 22, 2023
45e764f
GH-691: fix the remaining renames (#312)
utkarshg6 Jul 5, 2023
40be820
Merge branch 'master' into GH-691
utkarshg6 Jul 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion masq_lib/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::data_version::DataVersion;
use const_format::concatcp;

pub const DEFAULT_CHAIN: Chain = Chain::PolyMainnet;
pub const CURRENT_SCHEMA_VERSION: usize = 7;
pub const CURRENT_SCHEMA_VERSION: usize = 8;

pub const HIGHEST_RANDOM_CLANDESTINE_PORT: u16 = 9999;
pub const HTTP_PORT: u16 = 80;
Expand Down
5 changes: 2 additions & 3 deletions masq_lib/src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::fmt::{Debug, Formatter};
// Copyright (c) 2019, MASQ (https://masq.ai) and/or its affiliates. All rights reserved.
use crate::constants::CURRENT_SCHEMA_VERSION;
use crate::constants::{
CLIENT_REQUEST_PAYLOAD_CURRENT_VERSION, CLIENT_RESPONSE_PAYLOAD_CURRENT_VERSION,
DNS_RESOLVER_FAILURE_CURRENT_VERSION, GOSSIP_CURRENT_VERSION, GOSSIP_FAILURE_CURRENT_VERSION,
NODE_RECORD_INNER_CURRENT_VERSION,
CURRENT_SCHEMA_VERSION, DNS_RESOLVER_FAILURE_CURRENT_VERSION, GOSSIP_CURRENT_VERSION,
GOSSIP_FAILURE_CURRENT_VERSION, NODE_RECORD_INNER_CURRENT_VERSION,
};
use crate::data_version::DataVersion;
use crate::messages::SerializableLogLevel;
Expand Down
1 change: 0 additions & 1 deletion masq_lib/src/shared_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ pub fn shared_app(head: App<'static, 'static>) -> App<'static, 'static> {
Arg::with_name("min-hops")
.long("min-hops")
.value_name("MIN_HOPS")
.default_value("3")
.required(false)
.min_values(0)
.max_values(1)
Expand Down
32 changes: 16 additions & 16 deletions multinode_integration_tests/src/masq_real_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use masq_lib::test_utils::utils::TEST_DEFAULT_MULTINODE_CHAIN;
use masq_lib::utils::localhost;
use masq_lib::utils::{DEFAULT_CONSUMING_DERIVATION_PATH, DEFAULT_EARNING_DERIVATION_PATH};
use node_lib::blockchain::bip32::Bip32ECKeyProvider;
use node_lib::neighborhood::DEFAULT_MIN_HOPS_COUNT;
use node_lib::neighborhood::DEFAULT_MIN_HOPS;
use node_lib::sub_lib::accountant::{
PaymentThresholds, DEFAULT_EARNING_WALLET, DEFAULT_PAYMENT_THRESHOLDS,
};
Expand Down Expand Up @@ -114,7 +114,7 @@ pub fn make_consuming_wallet_info(token: &str) -> ConsumingWalletInfo {
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct NodeStartupConfig {
pub neighborhood_mode: String,
pub min_hops_count: Hops,
pub min_hops: Hops,
pub ip_info: LocalIpInfo,
pub dns_servers_opt: Option<Vec<IpAddr>>,
pub neighbors: Vec<NodeReference>,
Expand Down Expand Up @@ -146,7 +146,7 @@ impl NodeStartupConfig {
pub fn new() -> NodeStartupConfig {
NodeStartupConfig {
neighborhood_mode: "standard".to_string(),
min_hops_count: DEFAULT_MIN_HOPS_COUNT,
min_hops: DEFAULT_MIN_HOPS,
ip_info: LocalIpInfo::ZeroHop,
dns_servers_opt: None,
neighbors: Vec::new(),
Expand Down Expand Up @@ -179,7 +179,7 @@ impl NodeStartupConfig {
args.push("--neighborhood-mode".to_string());
args.push(self.neighborhood_mode.clone());
args.push("--min-hops".to_string());
args.push(format!("{}", self.min_hops_count as usize));
args.push(format!("{}", self.min_hops as usize));
if let LocalIpInfo::DistributedKnown(ip_addr) = self.ip_info {
args.push("--ip".to_string());
args.push(ip_addr.to_string());
Expand Down Expand Up @@ -409,7 +409,7 @@ impl NodeStartupConfig {

pub struct NodeStartupConfigBuilder {
neighborhood_mode: String,
min_hops_count: Hops,
min_hops: Hops,
ip_info: LocalIpInfo,
dns_servers_opt: Option<Vec<IpAddr>>,
neighbors: Vec<NodeReference>,
Expand Down Expand Up @@ -465,7 +465,7 @@ impl NodeStartupConfigBuilder {
pub fn standard() -> Self {
Self {
neighborhood_mode: "standard".to_string(),
min_hops_count: DEFAULT_MIN_HOPS_COUNT,
min_hops: DEFAULT_MIN_HOPS,
ip_info: LocalIpInfo::DistributedUnknown,
dns_servers_opt: None,
neighbors: vec![],
Expand All @@ -491,7 +491,7 @@ impl NodeStartupConfigBuilder {
pub fn copy(config: &NodeStartupConfig) -> Self {
Self {
neighborhood_mode: config.neighborhood_mode.clone(),
min_hops_count: config.min_hops_count,
min_hops: config.min_hops,
ip_info: config.ip_info,
dns_servers_opt: config.dns_servers_opt.clone(),
neighbors: config.neighbors.clone(),
Expand Down Expand Up @@ -530,8 +530,8 @@ impl NodeStartupConfigBuilder {
}
}

pub fn min_hops_count(mut self, value: Hops) -> Self {
self.min_hops_count = value;
pub fn min_hops(mut self, value: Hops) -> Self {
self.min_hops = value;
self
}

Expand Down Expand Up @@ -648,7 +648,7 @@ impl NodeStartupConfigBuilder {
pub fn build(self) -> NodeStartupConfig {
NodeStartupConfig {
neighborhood_mode: self.neighborhood_mode,
min_hops_count: self.min_hops_count,
min_hops: self.min_hops,
ip_info: self.ip_info,
dns_servers_opt: self.dns_servers_opt,
neighbors: self.neighbors,
Expand Down Expand Up @@ -1304,7 +1304,7 @@ mod tests {

#[test]
fn node_startup_config_builder_settings() {
let min_hops_count = Hops::SixHops;
let min_hops = Hops::SixHops;
let ip_addr = IpAddr::from_str("1.2.3.4").unwrap();
let one_neighbor_key = PublicKey::new(&[1, 2, 3, 4]);
let one_neighbor_ip_addr = IpAddr::from_str("4.5.6.7").unwrap();
Expand Down Expand Up @@ -1333,7 +1333,7 @@ mod tests {
let dns_target = IpAddr::from_str("8.9.10.11").unwrap();

let result = NodeStartupConfigBuilder::standard()
.min_hops_count(min_hops_count)
.min_hops(min_hops)
.ip(ip_addr)
.dns_servers(dns_servers.clone())
.neighbor(neighbors[0].clone())
Expand All @@ -1342,7 +1342,7 @@ mod tests {
.dns_port(35)
.build();

assert_eq!(result.min_hops_count, min_hops_count);
assert_eq!(result.min_hops, min_hops);
assert_eq!(result.ip_info, LocalIpInfo::DistributedKnown(ip_addr));
assert_eq!(result.dns_servers_opt, Some(dns_servers));
assert_eq!(result.neighbors, neighbors);
Expand All @@ -1355,7 +1355,7 @@ mod tests {
fn node_startup_config_builder_copy() {
let original = NodeStartupConfig {
neighborhood_mode: "consume-only".to_string(),
min_hops_count: Hops::TwoHops,
min_hops: Hops::TwoHops,
ip_info: LocalIpInfo::DistributedUnknown,
dns_servers_opt: Some(vec![IpAddr::from_str("255.255.255.255").unwrap()]),
neighbors: vec![NodeReference::new(
Expand Down Expand Up @@ -1434,7 +1434,7 @@ mod tests {
.build();

assert_eq!(result.neighborhood_mode, neighborhood_mode);
assert_eq!(result.min_hops_count, Hops::TwoHops);
assert_eq!(result.min_hops, Hops::TwoHops);
assert_eq!(result.ip_info, LocalIpInfo::DistributedKnown(ip_addr));
assert_eq!(result.dns_servers_opt, Some(dns_servers));
assert_eq!(result.neighbors, neighbors);
Expand Down Expand Up @@ -1501,7 +1501,7 @@ mod tests {

let subject = NodeStartupConfigBuilder::standard()
.neighborhood_mode("consume-only")
.min_hops_count(Hops::SixHops)
.min_hops(Hops::SixHops)
.ip(IpAddr::from_str("1.3.5.7").unwrap())
.neighbor(one_neighbor.clone())
.neighbor(another_neighbor.clone())
Expand Down
8 changes: 4 additions & 4 deletions multinode_integration_tests/tests/data_routing_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ fn http_end_to_end_routing_test() {
);
}

fn assert_http_end_to_end_routing_test(min_hops_count: Hops) {
fn assert_http_end_to_end_routing_test(min_hops: Hops) {
let mut cluster = MASQNodeCluster::start().unwrap();
let config = NodeStartupConfigBuilder::standard()
.min_hops_count(min_hops_count)
.min_hops(min_hops)
.chain(cluster.chain)
.consuming_wallet_info(make_consuming_wallet_info("first_node"))
.build();
let first_node = cluster.start_real_node(config);

let nodes_count = 2 * (min_hops_count as usize) + 1;
let nodes_count = 2 * (min_hops as usize) + 1;
let nodes = (0..nodes_count)
.map(|_| {
cluster.start_real_node(
Expand All @@ -106,7 +106,7 @@ fn assert_http_end_to_end_routing_test(min_hops_count: Hops) {
}

#[test]
fn http_end_to_end_routing_test_with_different_min_hops_count() {
fn http_end_to_end_routing_test_with_different_min_hops() {
// This test fails sometimes due to a timeout: "Couldn't read chunk: Kind(TimedOut)"
// You may fix it by increasing the timeout for the client.
assert_http_end_to_end_routing_test(Hops::OneHop);
Expand Down
22 changes: 12 additions & 10 deletions node/src/actor_system_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ mod tests {
use crate::sub_lib::ui_gateway::UiGatewayConfig;
use crate::test_utils::automap_mocks::{AutomapControlFactoryMock, AutomapControlMock};
use crate::test_utils::make_wallet;
use crate::test_utils::neighborhood_test_utils::MIN_HOPS_COUNT_FOR_TEST;
use crate::test_utils::neighborhood_test_utils::MIN_HOPS_FOR_TEST;
use crate::test_utils::persistent_configuration_mock::PersistentConfigurationMock;
use crate::test_utils::recorder::{
make_accountant_subs_from_recorder, make_blockchain_bridge_subs_from,
Expand Down Expand Up @@ -1084,13 +1084,14 @@ mod tests {
vec![],
rate_pack(100),
),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
},
payment_thresholds_opt: Some(PaymentThresholds::default()),
when_pending_too_long_sec: DEFAULT_PENDING_TOO_LONG_SEC,
};
let persistent_config =
PersistentConfigurationMock::default().chain_name_result("eth-ropsten".to_string());
let persistent_config = PersistentConfigurationMock::default()
.chain_name_result("eth-ropsten".to_string())
utkarshg6 marked this conversation as resolved.
Show resolved Hide resolved
.set_min_hops_result(Ok(()));
Bootstrapper::pub_initialize_cryptdes_for_testing(
&Some(main_cryptde()),
&Some(alias_cryptde()),
Expand Down Expand Up @@ -1158,7 +1159,7 @@ mod tests {
vec![],
rate_pack(100),
),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
},
payment_thresholds_opt: Default::default(),
when_pending_too_long_sec: DEFAULT_PENDING_TOO_LONG_SEC
Expand Down Expand Up @@ -1276,6 +1277,7 @@ mod tests {
let mut config = BootstrapperConfig::default();
config.neighborhood_config = NeighborhoodConfig {
mode: NeighborhoodMode::ConsumeOnly(vec![]),
min_hops: MIN_HOPS_FOR_TEST,
};
let subject = ActorSystemFactoryToolsReal::new();
let state_before = INITIALIZATION_COUNTER.lock().unwrap().0;
Expand All @@ -1302,7 +1304,7 @@ mod tests {
vec![],
rate_pack(100),
),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
};
let make_params_arc = Arc::new(Mutex::new(vec![]));
let mut subject = make_subject_with_null_setter();
Expand Down Expand Up @@ -1456,7 +1458,7 @@ mod tests {
real_user: RealUser::null(),
neighborhood_config: NeighborhoodConfig {
mode: NeighborhoodMode::ConsumeOnly(vec![]),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
},
payment_thresholds_opt: Default::default(),
when_pending_too_long_sec: DEFAULT_PENDING_TOO_LONG_SEC
Expand All @@ -1468,7 +1470,7 @@ mod tests {
let _ = subject.prepare_initial_messages(
make_cryptde_pair(),
config.clone(),
Box::new(PersistentConfigurationMock::new()),
Box::new(PersistentConfigurationMock::new().set_min_hops_result(Ok(()))),
Box::new(actor_factory),
);

Expand Down Expand Up @@ -1645,7 +1647,7 @@ mod tests {
vec![],
rate_pack(100),
),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
},
node_descriptor: Default::default(),
payment_thresholds_opt: Default::default(),
Expand All @@ -1657,7 +1659,7 @@ mod tests {
let _ = subject.prepare_initial_messages(
make_cryptde_pair(),
config.clone(),
Box::new(PersistentConfigurationMock::new()),
Box::new(PersistentConfigurationMock::new().set_min_hops_result(Ok(()))),
Box::new(actor_factory),
);

Expand Down
20 changes: 10 additions & 10 deletions node/src/bootstrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::json_discriminator_factory::JsonDiscriminatorFactory;
use crate::listener_handler::ListenerHandler;
use crate::listener_handler::ListenerHandlerFactory;
use crate::listener_handler::ListenerHandlerFactoryReal;
use crate::neighborhood::DEFAULT_MIN_HOPS_COUNT;
use crate::neighborhood::DEFAULT_MIN_HOPS;
use crate::node_configurator::node_configurator_standard::{
NodeConfiguratorStandardPrivileged, NodeConfiguratorStandardUnprivileged,
};
Expand Down Expand Up @@ -398,7 +398,7 @@ impl BootstrapperConfig {
consuming_wallet_opt: None,
neighborhood_config: NeighborhoodConfig {
mode: NeighborhoodMode::ZeroHop,
min_hops_count: DEFAULT_MIN_HOPS_COUNT,
min_hops: DEFAULT_MIN_HOPS,
},
when_pending_too_long_sec: DEFAULT_PENDING_TOO_LONG_SEC,
}
Expand Down Expand Up @@ -741,7 +741,7 @@ mod tests {
use crate::sub_lib::node_addr::NodeAddr;
use crate::sub_lib::socket_server::ConfiguredByPrivilege;
use crate::sub_lib::stream_connector::ConnectionInfo;
use crate::test_utils::neighborhood_test_utils::MIN_HOPS_COUNT_FOR_TEST;
use crate::test_utils::neighborhood_test_utils::MIN_HOPS_FOR_TEST;
use crate::test_utils::persistent_configuration_mock::PersistentConfigurationMock;
use crate::test_utils::recorder::make_recorder;
use crate::test_utils::recorder::RecordAwaiter;
Expand Down Expand Up @@ -1234,7 +1234,7 @@ mod tests {
let clandestine_port_opt = Some(44444);
let neighborhood_config = NeighborhoodConfig {
mode: NeighborhoodMode::OriginateOnly(vec![], rate_pack(9)),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
};
let earning_wallet = make_wallet("earning wallet");
let consuming_wallet_opt = Some(make_wallet("consuming wallet"));
Expand Down Expand Up @@ -1853,7 +1853,7 @@ mod tests {
))],
rate_pack(100),
),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
};
config.data_directory = data_dir.clone();
config.clandestine_port_opt = Some(port);
Expand Down Expand Up @@ -1923,7 +1923,7 @@ mod tests {
))],
rate_pack(100),
),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
};
config.data_directory = data_dir.clone();
config.clandestine_port_opt = None;
Expand Down Expand Up @@ -1972,7 +1972,7 @@ mod tests {
))],
rate_pack(100),
),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
};
let listener_handler = ListenerHandlerNull::new(vec![]);
let mut subject = BootstrapperBuilder::new()
Expand Down Expand Up @@ -2009,7 +2009,7 @@ mod tests {
Chain::EthRopsten,
cryptde,
))]),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
};
let listener_handler = ListenerHandlerNull::new(vec![]);
let mut subject = BootstrapperBuilder::new()
Expand Down Expand Up @@ -2039,7 +2039,7 @@ mod tests {
config.clandestine_port_opt = None;
config.neighborhood_config = NeighborhoodConfig {
mode: NeighborhoodMode::ZeroHop,
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
};
let listener_handler = ListenerHandlerNull::new(vec![]);
let mut subject = BootstrapperBuilder::new()
Expand Down Expand Up @@ -2070,7 +2070,7 @@ mod tests {
config.data_directory = data_dir.to_path_buf();
config.neighborhood_config = NeighborhoodConfig {
mode: NeighborhoodMode::Standard(NodeAddr::default(), vec![], DEFAULT_RATE_PACK),
min_hops_count: MIN_HOPS_COUNT_FOR_TEST,
min_hops: MIN_HOPS_FOR_TEST,
};
let mut subject = BootstrapperBuilder::new().config(config).build();
subject.set_up_clandestine_port();
Expand Down
Loading