Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
**/*.rs.bk
.idea/azure/
.idea/inspectionProfiles/Project_Default.xml
.idea/copilot.*

### Node
node_modules
Expand Down
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::BaseMainnet;
pub const CURRENT_SCHEMA_VERSION: usize = 11;
pub const CURRENT_SCHEMA_VERSION: usize = 12;

pub const HIGHEST_RANDOM_CLANDESTINE_PORT: u16 = 9999;
pub const HTTP_PORT: u16 = 80;
Expand Down
16 changes: 16 additions & 0 deletions multinode_integration_tests/src/masq_node_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,22 @@ impl MASQNodeCluster {
}

fn create_network() -> Result<(), String> {
let mut command = Command::new(
"docker",
Command::strings(vec!["network", "rm", "integration_net"]),
);
match command.stdout_or_stderr() {
Ok(_) => println!("Removed existing integration_net network"),
Err(msg) if msg.contains("network integration_net not found") => {
println!("No existing integration_net network to remove: cool!")
}
Err(msg) => {
return Err(format!(
"Error removing existing integration_net network: {}",
msg
))
}
}
let mut command = Command::new(
"docker",
Command::strings(vec![
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ automap = { path = "../automap"}
backtrace = "0.3.57"
base64 = "0.13.0"
bytes = "0.4.12"
time = {version = "0.3.11", features = [ "macros" ]}
time = { version = "0.3.11", features = ["macros", "local-offset"] }
clap = "2.33.3"
crossbeam-channel = "0.5.1"
dirs = "4.0.0"
Expand Down
14 changes: 7 additions & 7 deletions node/src/bootstrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ mod tests {
use tokio::prelude::Async;

lazy_static! {
static ref CRYPTDE_PAIR: CryptDEPair = CryptDEPair::null();
static ref BS_CRYPTDE_PAIR: CryptDEPair = CryptDEPair::null();
pub static ref INITIALIZATION: Mutex<bool> = Mutex::new(false);
}

Expand Down Expand Up @@ -1534,13 +1534,13 @@ mod tests {
);
let cryptde_ref = {
let descriptor = Bootstrapper::make_local_descriptor(
CRYPTDE_PAIR.main.as_ref(),
BS_CRYPTDE_PAIR.main.as_ref(),
Some(node_addr),
TEST_DEFAULT_CHAIN,
);
Bootstrapper::report_local_descriptor(CRYPTDE_PAIR.main.as_ref(), &descriptor);
Bootstrapper::report_local_descriptor(BS_CRYPTDE_PAIR.main.as_ref(), &descriptor);

CRYPTDE_PAIR.main.as_ref()
BS_CRYPTDE_PAIR.main.as_ref()
};
let expected_descriptor = format!(
"masq://base-sepolia:{}@2.3.4.5:3456/4567",
Expand Down Expand Up @@ -1576,13 +1576,13 @@ mod tests {
init_test_logging();
let cryptdes = {
let descriptor = Bootstrapper::make_local_descriptor(
CRYPTDE_PAIR.main.as_ref(),
BS_CRYPTDE_PAIR.main.as_ref(),
None,
TEST_DEFAULT_CHAIN,
);
Bootstrapper::report_local_descriptor(CRYPTDE_PAIR.main.as_ref(), &descriptor);
Bootstrapper::report_local_descriptor(BS_CRYPTDE_PAIR.main.as_ref(), &descriptor);

CRYPTDE_PAIR.clone()
BS_CRYPTDE_PAIR.clone()
};
let expected_descriptor = format!(
"masq://base-sepolia:{}@:",
Expand Down
26 changes: 14 additions & 12 deletions node/src/daemon/setup_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ mod tests {
("neighborhood-mode", "originate-only", Set),
("neighbors", "masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@1.2.3.4:1234,masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@5.6.7.8:5678", Set),
("payment-thresholds","1234|50000|1000|1000|20000|20000",Set),
("rate-pack","1|3|3|8",Set),
("rate-pack","100|300|300|800",Set),
#[cfg(not(target_os = "windows"))]
("real-user", "9999:9999:booga", Set),
("scan-intervals","150|150|150",Set),
Expand Down Expand Up @@ -1548,7 +1548,7 @@ mod tests {
("neighborhood-mode", "originate-only", Set),
("neighbors", "masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@1.2.3.4:1234,masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@5.6.7.8:5678", Set),
("payment-thresholds","1234|50000|1000|1000|20000|20000",Set),
("rate-pack","1|3|3|8",Set),
("rate-pack","100|300|300|800",Set),
#[cfg(not(target_os = "windows"))]
("real-user", "9999:9999:booga", Set),
("scan-intervals","150|150|150",Set),
Expand Down Expand Up @@ -1588,7 +1588,7 @@ mod tests {
("neighborhood-mode", "originate-only"),
("neighbors", "masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@1.2.3.4:1234,masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@5.6.7.8:5678"),
("payment-thresholds","1234|50000|1000|1000|15000|15000"),
("rate-pack","1|3|3|8"),
("rate-pack","100|300|300|800"),
#[cfg(not(target_os = "windows"))]
("real-user", "9999:9999:booga"),
("scan-intervals","140|130|150"),
Expand Down Expand Up @@ -1623,7 +1623,7 @@ mod tests {
("neighborhood-mode", "originate-only", Set),
("neighbors", "masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@1.2.3.4:1234,masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@5.6.7.8:5678", Set),
("payment-thresholds","1234|50000|1000|1000|15000|15000",Set),
("rate-pack","1|3|3|8",Set),
("rate-pack","100|300|300|800",Set),
#[cfg(not(target_os = "windows"))]
("real-user", "9999:9999:booga", Set),
("scan-intervals","140|130|150",Set),
Expand Down Expand Up @@ -1664,7 +1664,7 @@ mod tests {
("MASQ_NEIGHBORHOOD_MODE", "originate-only"),
("MASQ_NEIGHBORS", "masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@1.2.3.4:1234,masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@5.6.7.8:5678"),
("MASQ_PAYMENT_THRESHOLDS","12345|50000|1000|1234|19000|20000"),
("MASQ_RATE_PACK","1|3|3|8"),
("MASQ_RATE_PACK","100|300|300|800"),
#[cfg(not(target_os = "windows"))]
("MASQ_REAL_USER", "9999:9999:booga"),
("MASQ_SCANS", "off"),
Expand Down Expand Up @@ -1696,7 +1696,7 @@ mod tests {
("neighborhood-mode", "originate-only", Configured),
("neighbors", "masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@1.2.3.4:1234,masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@5.6.7.8:5678", Configured),
("payment-thresholds","12345|50000|1000|1234|19000|20000",Configured),
("rate-pack","1|3|3|8",Configured),
("rate-pack","100|300|300|800",Configured),
#[cfg(not(target_os = "windows"))]
("real-user", "9999:9999:booga", Configured),
("scan-intervals","133|133|111",Configured),
Expand Down Expand Up @@ -1756,7 +1756,9 @@ mod tests {
.write_all(b"neighborhood-mode = \"standard\"\n")
.unwrap();
config_file.write_all(b"scans = \"off\"\n").unwrap();
config_file.write_all(b"rate-pack = \"2|2|2|2\"\n").unwrap();
config_file
.write_all(b"rate-pack = \"200|200|200|200\"\n")
.unwrap();
config_file
.write_all(b"payment-thresholds = \"3333|55|33|646|999|999\"\n")
.unwrap();
Expand Down Expand Up @@ -1799,7 +1801,7 @@ mod tests {
.unwrap();
config_file.write_all(b"scans = \"off\"\n").unwrap();
config_file
.write_all(b"rate-pack = \"55|50|60|61\"\n")
.write_all(b"rate-pack = \"5500|5000|6000|6100\"\n")
.unwrap();
config_file
.write_all(b"payment-thresholds = \"4000|1000|3000|3333|10000|20000\"\n")
Expand Down Expand Up @@ -1864,7 +1866,7 @@ mod tests {
"4000|1000|3000|3333|10000|20000",
Configured,
),
("rate-pack", "55|50|60|61", Configured),
("rate-pack", "5500|5000|6000|6100", Configured),
#[cfg(not(target_os = "windows"))]
(
"real-user",
Expand Down Expand Up @@ -1914,7 +1916,7 @@ mod tests {
("MASQ_NEIGHBORHOOD_MODE", "originate-only"),
("MASQ_NEIGHBORS", "masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@1.2.3.4:1234,masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@5.6.7.8:5678"),
("MASQ_PAYMENT_THRESHOLDS","1234|50000|1000|1000|20000|20000"),
("MASQ_RATE_PACK","1|3|3|8"),
("MASQ_RATE_PACK","100|300|300|800"),
#[cfg(not(target_os = "windows"))]
("MASQ_REAL_USER", "9999:9999:booga"),
("MASQ_SCANS", "off"),
Expand Down Expand Up @@ -1977,7 +1979,7 @@ mod tests {
Set,
),
("payment-thresholds", "4321|66666|777|987|123456|124444", Set),
("rate-pack", "10|30|13|28", Set),
("rate-pack", "1000|3000|1300|2800", Set),
#[cfg(not(target_os = "windows"))]
("real-user", "6666:6666:agoob", Set),
("scan-intervals", "111|111|111", Set),
Expand Down Expand Up @@ -2011,7 +2013,7 @@ mod tests {
("neighborhood-mode", "originate-only", Configured),
("neighbors", "masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@1.2.3.4:1234,masq://base-sepolia:MTIzNDU2Nzg5MTEyMzQ1Njc4OTIxMjM0NTY3ODkzMTI@5.6.7.8:5678", Configured),
("payment-thresholds","1234|50000|1000|1000|20000|20000",Configured),
("rate-pack","1|3|3|8",Configured),
("rate-pack","100|300|300|800",Configured),
#[cfg(not(target_os = "windows"))]
("real-user", "9999:9999:booga", Configured),
("scan-intervals","150|150|155",Configured),
Expand Down
35 changes: 33 additions & 2 deletions node/src/database/db_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::database::db_migrations::db_migrator::{DbMigrator, DbMigratorReal};
use crate::db_config::secure_config_layer::EXAMPLE_ENCRYPTED;
use crate::neighborhood::DEFAULT_MIN_HOPS;
use crate::sub_lib::accountant::{DEFAULT_PAYMENT_THRESHOLDS, DEFAULT_SCAN_INTERVALS};
use crate::sub_lib::neighborhood::DEFAULT_RATE_PACK;
use crate::sub_lib::neighborhood::{DEFAULT_RATE_PACK, DEFAULT_RATE_PACK_LIMITS};
use crate::sub_lib::utils::db_connection_launch_panic;
use masq_lib::blockchains::chains::Chain;
use masq_lib::constants::{
Expand Down Expand Up @@ -256,6 +256,17 @@ impl DbInitializerReal {
false,
"rate pack",
);
Self::set_config_value(
conn,
"rate_pack_limits",
Some(
DEFAULT_RATE_PACK_LIMITS
.rate_pack_limits_parameter()
.as_str(),
),
false,
"rate pack limits",
);
Self::set_config_value(
conn,
"scan_intervals",
Expand Down Expand Up @@ -661,7 +672,7 @@ mod tests {
#[test]
fn constants_have_correct_values() {
assert_eq!(DATABASE_FILE, "node-data.db");
assert_eq!(CURRENT_SCHEMA_VERSION, 11);
assert_eq!(CURRENT_SCHEMA_VERSION, 12);
}

#[test]
Expand Down Expand Up @@ -959,6 +970,16 @@ mod tests {
Some(&DEFAULT_RATE_PACK.to_string()),
false,
);
verify(
&mut config_vec,
"rate_pack_limits",
Some(
DEFAULT_RATE_PACK_LIMITS
.rate_pack_limits_parameter()
.as_str(),
),
false,
);
verify(
&mut config_vec,
"scan_intervals",
Expand Down Expand Up @@ -1071,6 +1092,16 @@ mod tests {
Some(&DEFAULT_RATE_PACK.to_string()),
false,
);
verify(
&mut config_vec,
"rate_pack_limits",
Some(
DEFAULT_RATE_PACK_LIMITS
.rate_pack_limits_parameter()
.as_str(),
),
false,
);
verify(
&mut config_vec,
"scan_intervals",
Expand Down
2 changes: 2 additions & 0 deletions node/src/database/db_migrations/db_migrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::database::db_initializer::ExternalData;
use crate::database::db_migrations::migrations::migration_0_to_1::Migrate_0_to_1;
use crate::database::db_migrations::migrations::migration_10_to_11::Migrate_10_to_11;
use crate::database::db_migrations::migrations::migration_11_to_12::Migrate_11_to_12;
use crate::database::db_migrations::migrations::migration_1_to_2::Migrate_1_to_2;
use crate::database::db_migrations::migrations::migration_2_to_3::Migrate_2_to_3;
use crate::database::db_migrations::migrations::migration_3_to_4::Migrate_3_to_4;
Expand Down Expand Up @@ -82,6 +83,7 @@ impl DbMigratorReal {
&Migrate_8_to_9,
&Migrate_9_to_10,
&Migrate_10_to_11,
&Migrate_11_to_12,
]
}

Expand Down
77 changes: 77 additions & 0 deletions node/src/database/db_migrations/migrations/migration_11_to_12.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2019, MASQ (https://masq.ai) and/or its affiliates. All rights reserved.

use crate::database::db_migrations::db_migrator::DatabaseMigration;
use crate::database::db_migrations::migrator_utils::DBMigDeclarator;
use crate::sub_lib::neighborhood::DEFAULT_RATE_PACK_LIMITS;

#[allow(non_camel_case_types)]
pub struct Migrate_11_to_12;

impl DatabaseMigration for Migrate_11_to_12 {
fn migrate<'a>(
&self,
declaration_utils: Box<dyn DBMigDeclarator + 'a>,
) -> rusqlite::Result<()> {
declaration_utils.execute_upon_transaction(&[&format!(
"INSERT INTO config (name, value, encrypted) VALUES ('rate_pack_limits', '{}', 0)",
DEFAULT_RATE_PACK_LIMITS.rate_pack_limits_parameter()
)])
}

fn old_version(&self) -> usize {
11
}
}

#[cfg(test)]
mod tests {
use crate::database::db_initializer::{
DbInitializationConfig, DbInitializer, DbInitializerReal, DATABASE_FILE,
};
use crate::test_utils::database_utils::{
bring_db_0_back_to_life_and_return_connection, make_external_data, retrieve_config_row,
};
use masq_lib::test_utils::utils::ensure_node_home_directory_exists;
use std::fs::create_dir_all;

#[test]
fn migration_from_11_to_12_is_properly_set() {
let dir_path = ensure_node_home_directory_exists(
"db_migrations",
"migration_from_11_to_12_is_properly_set",
);
create_dir_all(&dir_path).unwrap();
let db_path = dir_path.join(DATABASE_FILE);
let _ = bring_db_0_back_to_life_and_return_connection(&db_path);
let subject = DbInitializerReal::default();

let result = subject.initialize_to_version(
&dir_path,
11,
DbInitializationConfig::create_or_migrate(make_external_data()),
);

assert!(result.is_ok());

let result = subject.initialize_to_version(
&dir_path,
12,
DbInitializationConfig::create_or_migrate(make_external_data()),
);

assert!(result.is_ok());
let connection = result.unwrap();
let (lc_value, lc_encrypted) = retrieve_config_row(connection.as_ref(), "rate_pack_limits");
let (cs_value, cs_encrypted) = retrieve_config_row(connection.as_ref(), "schema_version");
assert_eq!(
lc_value,
Some(
"100-100000000000000|100-100000000000000|100-100000000000000|100-100000000000000"
.to_string()
)
);
assert_eq!(lc_encrypted, false);
assert_eq!(cs_value, Some("12".to_string()));
assert_eq!(cs_encrypted, false)
}
}
1 change: 1 addition & 0 deletions node/src/database/db_migrations/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod migration_0_to_1;
pub mod migration_10_to_11;
pub mod migration_11_to_12;
pub mod migration_1_to_2;
pub mod migration_2_to_3;
pub mod migration_3_to_4;
Expand Down
9 changes: 8 additions & 1 deletion node/src/db_config/config_dao_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::database::rusqlite_wrappers::TransactionSafeWrapper;
use crate::db_config::config_dao::{ConfigDao, ConfigDaoError, ConfigDaoRecord};
use crate::neighborhood::DEFAULT_MIN_HOPS;
use crate::sub_lib::accountant::{DEFAULT_PAYMENT_THRESHOLDS, DEFAULT_SCAN_INTERVALS};
use crate::sub_lib::neighborhood::DEFAULT_RATE_PACK;
use crate::sub_lib::neighborhood::{DEFAULT_RATE_PACK, DEFAULT_RATE_PACK_LIMITS};
use itertools::Itertools;
use masq_lib::blockchains::chains::Chain;
use masq_lib::constants::{CURRENT_SCHEMA_VERSION, DEFAULT_GAS_PRICE};
Expand Down Expand Up @@ -138,6 +138,13 @@ impl Default for ConfigDaoNull {
"rate_pack".to_string(),
(Some(DEFAULT_RATE_PACK.to_string()), false),
);
data.insert(
"rate_pack_limits".to_string(),
(
Some(DEFAULT_RATE_PACK_LIMITS.rate_pack_limits_parameter()),
false,
),
);
data.insert(
"scan_intervals".to_string(),
(Some(DEFAULT_SCAN_INTERVALS.to_string()), false),
Expand Down
Loading
Loading