diff --git a/masq/src/commands/set_configuration_command.rs b/masq/src/commands/set_configuration_command.rs index e22101fd1..8cf0eebc7 100644 --- a/masq/src/commands/set_configuration_command.rs +++ b/masq/src/commands/set_configuration_command.rs @@ -35,7 +35,7 @@ impl SetConfigurationCommand { } fn validate_start_block(start_block: String) -> Result<(), String> { - if "none".eq_ignore_ascii_case(&start_block) { + if "latest".eq_ignore_ascii_case(&start_block) || "none".eq_ignore_ascii_case(&start_block) { Ok(()) } else { match start_block.parse::() { @@ -63,7 +63,7 @@ impl Command for SetConfigurationCommand { const SET_CONFIGURATION_ABOUT: &str = "Sets Node configuration parameters being enabled for this operation when the Node is running."; const START_BLOCK_HELP: &str = - "Ordinal number of the Ethereum block where scanning for transactions will start. Use 'none' for Latest block."; + "Ordinal number of the Ethereum block where scanning for transactions will start. Use 'latest' or 'none' for Latest block."; pub fn set_configurationify<'a>(shared_schema_arg: Arg<'a, 'a>) -> Arg<'a, 'a> { shared_schema_arg.takes_value(true).min_values(1) @@ -107,7 +107,7 @@ mod tests { ); assert_eq!( START_BLOCK_HELP, - "Ordinal number of the Ethereum block where scanning for transactions will start. Use 'none' for Latest block." + "Ordinal number of the Ethereum block where scanning for transactions will start. Use 'latest' or 'none' for Latest block." ); } @@ -130,6 +130,7 @@ mod tests { fn validate_start_block_works() { assert!(validate_start_block("abc".to_string()).is_err()); assert!(validate_start_block("1566".to_string()).is_ok()); + assert!(validate_start_block("latest".to_string()).is_ok()); assert!(validate_start_block("none".to_string()).is_ok()); } diff --git a/masq_lib/src/constants.rs b/masq_lib/src/constants.rs index 11d1abb67..7bdcbe1e1 100644 --- a/masq_lib/src/constants.rs +++ b/masq_lib/src/constants.rs @@ -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 = 10; +pub const CURRENT_SCHEMA_VERSION: usize = 9; pub const HIGHEST_RANDOM_CLANDESTINE_PORT: u16 = 9999; pub const HTTP_PORT: u16 = 80; diff --git a/node/src/accountant/scanners/mod.rs b/node/src/accountant/scanners/mod.rs index f1341ed10..61d607753 100644 --- a/node/src/accountant/scanners/mod.rs +++ b/node/src/accountant/scanners/mod.rs @@ -861,7 +861,7 @@ impl Scanner for ReceivableScanner { match self .persistent_configuration - .set_start_block(msg.new_start_block) + .set_start_block(Some(msg.new_start_block)) { Ok(()) => debug!(logger, "Start block updated to {}", msg.new_start_block), Err(e) => panic!( @@ -1245,7 +1245,7 @@ mod tests { assert_eq!(receivable_scanner.common.initiated_at_opt.is_some(), false); receivable_scanner .persistent_configuration - .set_start_block(136890) + .set_start_block(Some(136890)) .unwrap(); let set_params = set_params_arc.lock().unwrap(); assert_eq!( @@ -3061,7 +3061,7 @@ mod tests { assert_eq!(message_opt, None); let set_start_block_params = set_start_block_params_arc.lock().unwrap(); - assert_eq!(*set_start_block_params, vec![4321]); + assert_eq!(*set_start_block_params, vec![Some(4321)]); TestLogHandler::new().exists_log_containing(&format!( "INFO: {test_name}: No newly received payments were detected during the scanning process." )); diff --git a/node/src/blockchain/blockchain_bridge.rs b/node/src/blockchain/blockchain_bridge.rs index 6db6b87f3..1ed9d148d 100644 --- a/node/src/blockchain/blockchain_bridge.rs +++ b/node/src/blockchain/blockchain_bridge.rs @@ -1435,6 +1435,7 @@ mod tests { .retrieve_transactions_params(&retrieve_transactions_params_arc) .retrieve_transactions_result(Ok(expected_transactions.clone())) .lower_interface_results(Box::new(lower_interface)); + let set_start_block_params_arc = Arc::new(Mutex::new(vec![])); let persistent_config = PersistentConfigurationMock::new() .max_block_count_result(Ok(None)) .start_block_result(Ok(Some(6))) @@ -1499,6 +1500,7 @@ mod tests { #[test] fn handle_retrieve_transactions_sends_received_payments_back_to_accountant() { let retrieve_transactions_params_arc = Arc::new(Mutex::new(vec![])); + let set_start_block_params_arc = Arc::new(Mutex::new(vec![])); let system = System::new("handle_retrieve_transactions_sends_received_payments_back_to_accountant"); let (accountant, _, accountant_recording_arc) = make_recorder(); @@ -1557,7 +1559,7 @@ mod tests { system.run(); let after = SystemTime::now(); let set_start_block_params = set_start_block_params_arc.lock().unwrap(); - assert_eq!(*set_start_block_params, vec![Some(1234u64)]); + assert_eq!(*set_start_block_params, vec![Some(9876u64)]); let retrieve_transactions_params = retrieve_transactions_params_arc.lock().unwrap(); assert_eq!( *retrieve_transactions_params, @@ -1596,6 +1598,7 @@ mod tests { transactions: vec![], })) .lower_interface_results(Box::new(lower_interface)); + let set_start_block_params_arc = Arc::new(Mutex::new(vec![])); let persistent_config = PersistentConfigurationMock::new() .max_block_count_result(Ok(Some(10000u64))) .start_block_result(Ok(Some(6))) diff --git a/node/src/database/db_initializer.rs b/node/src/database/db_initializer.rs index 3619cc1b4..bcb9a3a0a 100644 --- a/node/src/database/db_initializer.rs +++ b/node/src/database/db_initializer.rs @@ -652,7 +652,7 @@ mod tests { #[test] fn constants_have_correct_values() { assert_eq!(DATABASE_FILE, "node-data.db"); - assert_eq!(CURRENT_SCHEMA_VERSION, 10); + assert_eq!(CURRENT_SCHEMA_VERSION, 9); } #[test] diff --git a/node/src/database/db_migrations/db_migrator.rs b/node/src/database/db_migrations/db_migrator.rs index 7d1ec4f8c..746af3e26 100644 --- a/node/src/database/db_migrations/db_migrator.rs +++ b/node/src/database/db_migrations/db_migrator.rs @@ -10,7 +10,6 @@ use crate::database::db_migrations::migrations::migration_5_to_6::Migrate_5_to_6 use crate::database::db_migrations::migrations::migration_6_to_7::Migrate_6_to_7; use crate::database::db_migrations::migrations::migration_7_to_8::Migrate_7_to_8; use crate::database::db_migrations::migrations::migration_8_to_9::Migrate_8_to_9; -use crate::database::db_migrations::migrations::migration_9_to_10::Migrate_9_to_10; use crate::database::db_migrations::migrator_utils::{ DBMigDeclarator, DBMigrationUtilities, DBMigrationUtilitiesReal, DBMigratorInnerConfiguration, }; @@ -79,7 +78,6 @@ impl DbMigratorReal { &Migrate_6_to_7, &Migrate_7_to_8, &Migrate_8_to_9, - &Migrate_9_to_10, ] } diff --git a/node/src/database/db_migrations/migrations/migration_9_to_10.rs b/node/src/database/db_migrations/migrations/migration_9_to_10.rs deleted file mode 100644 index de761a3a5..000000000 --- a/node/src/database/db_migrations/migrations/migration_9_to_10.rs +++ /dev/null @@ -1,71 +0,0 @@ -use crate::database::db_migrations::db_migrator::DatabaseMigration; -use crate::database::db_migrations::migrator_utils::DBMigDeclarator; - -#[allow(non_camel_case_types)] -pub struct Migrate_9_to_10; - -impl DatabaseMigration for Migrate_9_to_10 { - fn migrate<'a>( - &self, - declaration_utils: Box, - ) -> rusqlite::Result<()> { - declaration_utils.execute_upon_transaction(&[ - &"INSERT INTO config (name, value, encrypted) VALUES ('start_block', null, 0) ON CONFLICT DO NOTHING", - ]) - } - - fn old_version(&self) -> usize { - 9 - } -} - -#[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::logging::{init_test_logging, TestLogHandler}; - use masq_lib::test_utils::utils::ensure_node_home_directory_exists; - use std::fs::create_dir_all; - - #[test] - fn migration_from_9_to_10_is_properly_set() { - init_test_logging(); - let dir_path = ensure_node_home_directory_exists( - "db_migrations", - "migration_from_9_to_10_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, - 10, - DbInitializationConfig::create_or_migrate(make_external_data()), - ); - let connection = result.unwrap(); - let (mp_value, mp_encrypted) = retrieve_config_row(connection.as_ref(), "start_block"); - let (cs_value, cs_encrypted) = retrieve_config_row(connection.as_ref(), "schema_version"); - assert_eq!(mp_value, None); - assert_eq!(mp_encrypted, false); - assert_eq!(cs_value, Some("10".to_string())); - assert_eq!(cs_encrypted, false); - TestLogHandler::new().assert_logs_contain_in_order(vec![ - "DbMigrator: Database successfully migrated from version 0 to 1", - "DbMigrator: Database successfully migrated from version 1 to 2", - "DbMigrator: Database successfully migrated from version 2 to 3", - "DbMigrator: Database successfully migrated from version 3 to 4", - "DbMigrator: Database successfully migrated from version 4 to 5", - "DbMigrator: Database successfully migrated from version 5 to 6", - "DbMigrator: Database successfully migrated from version 6 to 7", - "DbMigrator: Database successfully migrated from version 7 to 8", - "DbMigrator: Database successfully migrated from version 8 to 9", - "DbMigrator: Database successfully migrated from version 9 to 10", - ]); - } -} diff --git a/node/src/database/db_migrations/migrations/mod.rs b/node/src/database/db_migrations/migrations/mod.rs index bcdb14176..68b10ca9b 100644 --- a/node/src/database/db_migrations/migrations/mod.rs +++ b/node/src/database/db_migrations/migrations/mod.rs @@ -9,4 +9,3 @@ pub mod migration_5_to_6; pub mod migration_6_to_7; pub mod migration_7_to_8; pub mod migration_8_to_9; -pub mod migration_9_to_10; diff --git a/node/src/test_utils/database_utils.rs b/node/src/test_utils/database_utils.rs index 2005166c0..9c483ee51 100644 --- a/node/src/test_utils/database_utils.rs +++ b/node/src/test_utils/database_utils.rs @@ -40,6 +40,27 @@ pub fn bring_db_0_back_to_life_and_return_connection(db_path: &Path) -> Connecti conn } +pub fn bring_db_9_back_to_life_and_return_connection(db_path: &Path) -> Connection { + match remove_file(db_path) { + Err(e) if e.kind() == std::io::ErrorKind::NotFound => (), + Err(e) => panic!("Unexpected but serious error: {}", e), + _ => (), + } + let file_path = current_dir() + .unwrap() + .join("src") + .join("test_utils") + .join("database_version_9_sql.txt"); + let mut file = File::open(file_path).unwrap(); + let mut buffer = String::new(); + file.read_to_string(&mut buffer).unwrap(); + let conn = Connection::open(&db_path).unwrap(); + buffer.lines().for_each(|stm| { + conn.execute(stm, []).unwrap(); + }); + conn +} + #[derive(Default)] pub struct DbMigratorMock { logger: Option, @@ -196,7 +217,7 @@ fn contains_particular_list_of_key_words( found += 1 } }); - assert_eq!(found,1, "We found {} occurrences of the searched line in the tested sql although only a one is considered correct", found) + assert_eq!(found, 1, "We found {} occurrences of the searched line in the tested sql although only a one is considered correct", found) } fn prepare_expected_vectors_of_words_including_sorting( diff --git a/node/src/test_utils/database_version_0_sql.txt b/node/src/test_utils/database_version_0_sql.txt index c2763125a..cacdbb40d 100644 --- a/node/src/test_utils/database_version_0_sql.txt +++ b/node/src/test_utils/database_version_0_sql.txt @@ -7,7 +7,7 @@ insert into config (name, value, encrypted) values ('consuming_wallet_public_key insert into config (name, value, encrypted) values ('earning_wallet_address', null, 0) insert into config (name, value, encrypted) values ('schema_version', '0', 0) insert into config (name, value, encrypted) values ('seed', null, 0) -insert into config (name, value, encrypted) values ('start_block', null, 0) +insert into config (name, value, encrypted) values ('start_block', 8688171, 0) insert into config (name, value, encrypted) values ('gas_price', '1', 0) insert into config (name, value, encrypted) values ('past_neighbors', null, 1) create table payable (wallet_address text primary key, balance integer not null, last_paid_timestamp integer not null, pending_payment_transaction text null) @@ -15,4 +15,4 @@ create unique index idx_payable_wallet_address on payable (wallet_address) create table receivable (wallet_address text primary key, balance integer not null, last_received_timestamp integer not null) create unique index idx_receivable_wallet_address on receivable (wallet_address) create table banned ( wallet_address text primary key ) -create unique index idx_banned_wallet_address on banned (wallet_address) +create unique index idx_banned_wallet_address on banned (wallet_address) \ No newline at end of file diff --git a/node/src/test_utils/database_version_9_sql.txt b/node/src/test_utils/database_version_9_sql.txt new file mode 100644 index 000000000..7bb54be14 --- /dev/null +++ b/node/src/test_utils/database_version_9_sql.txt @@ -0,0 +1,18 @@ +create table config (name text not null, value text, encrypted integer not null) +create unique index idx_config_name on config (name) +insert into config (name, value, encrypted) values ('example_encrypted', null, 1) +insert into config (name, value, encrypted) values ('clandestine_port', '2897', 0) +insert into config (name, value, encrypted) values ('consuming_wallet_derivation_path', null, 0) +insert into config (name, value, encrypted) values ('consuming_wallet_public_key', null, 0) +insert into config (name, value, encrypted) values ('earning_wallet_address', null, 0) +insert into config (name, value, encrypted) values ('schema_version', '10', 0) +insert into config (name, value, encrypted) values ('seed', null, 0) +insert into config (name, value, encrypted) values ('start_block', null, 0) +insert into config (name, value, encrypted) values ('gas_price', '1', 0) +insert into config (name, value, encrypted) values ('past_neighbors', null, 1) +create table payable (wallet_address text primary key, balance integer not null, last_paid_timestamp integer not null, pending_payment_transaction text null) +create unique index idx_payable_wallet_address on payable (wallet_address) +create table receivable (wallet_address text primary key, balance integer not null, last_received_timestamp integer not null) +create unique index idx_receivable_wallet_address on receivable (wallet_address) +create table banned ( wallet_address text primary key ) +create unique index idx_banned_wallet_address on banned (wallet_address)