diff --git a/.github/workflows/ci-matrix.yml b/.github/workflows/ci-matrix.yml index 71a537d48..845add861 100644 --- a/.github/workflows/ci-matrix.yml +++ b/.github/workflows/ci-matrix.yml @@ -14,7 +14,7 @@ jobs: matrix: target: - { name: linux, os: ubuntu-22.04 } - - { name: macos, os: macos-12 } + - { name: macos, os: macos-13 } - { name: windows, os: windows-2022 } name: Build node on ${{ matrix.target.os }} diff --git a/masq_lib/src/constants.rs b/masq_lib/src/constants.rs index 9cfdc90c6..155bff5cc 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 = 9; +pub const CURRENT_SCHEMA_VERSION: usize = 10; pub const HIGHEST_RANDOM_CLANDESTINE_PORT: u16 = 9999; pub const HTTP_PORT: u16 = 80; @@ -24,6 +24,8 @@ pub const WALLET_ADDRESS_LENGTH: usize = 42; pub const MASQ_TOTAL_SUPPLY: u64 = 37_500_000; pub const WEIS_IN_GWEI: i128 = 1_000_000_000; +pub const DEFAULT_MAX_BLOCK_COUNT: u64 = 100_000; + pub const ETH_MAINNET_CONTRACT_CREATION_BLOCK: u64 = 11_170_708; pub const ETH_ROPSTEN_CONTRACT_CREATION_BLOCK: u64 = 8_688_171; pub const POLYGON_MAINNET_CONTRACT_CREATION_BLOCK: u64 = 14_863_650; diff --git a/node/src/blockchain/blockchain_bridge.rs b/node/src/blockchain/blockchain_bridge.rs index eadfc40d3..67d018e27 100644 --- a/node/src/blockchain/blockchain_bridge.rs +++ b/node/src/blockchain/blockchain_bridge.rs @@ -33,6 +33,7 @@ use actix::Message; use actix::{Addr, Recipient}; use itertools::Itertools; use masq_lib::blockchains::chains::Chain; +use masq_lib::constants::DEFAULT_MAX_BLOCK_COUNT; use masq_lib::logger::Logger; use masq_lib::messages::ScanType; use masq_lib::ui_gateway::NodeFromUiMessage; @@ -287,7 +288,7 @@ impl BlockchainBridge { }; let max_block_count = match self.persistent_config.max_block_count() { Ok(Some(mbc)) => mbc, - _ => u64::MAX, + _ => DEFAULT_MAX_BLOCK_COUNT, }; let use_unlimited_block_count_range = u64::MAX == max_block_count; let use_latest_block = u64::MAX == start_block_nbr; @@ -1019,7 +1020,7 @@ mod tests { ))) .lower_interface_results(Box::new(lower_interface)); let persistent_config = PersistentConfigurationMock::new() - .max_block_count_result(Ok(Some(100_000))) + .max_block_count_result(Ok(Some(DEFAULT_MAX_BLOCK_COUNT))) .start_block_result(Ok(Some(5))); // no set_start_block_result: set_start_block() must not be called let mut subject = BlockchainBridge::new( Box::new(blockchain_interface), @@ -1277,11 +1278,12 @@ mod tests { } #[test] - fn handle_retrieve_transactions_uses_latest_block_number_upon_get_block_number_error() { + fn handle_retrieve_transactions_uses_default_max_block_count_for_ending_block_number_upon_get_block_number_error( + ) { init_test_logging(); let retrieve_transactions_params_arc = Arc::new(Mutex::new(vec![])); let system = System::new( - "handle_retrieve_transactions_uses_latest_block_number_upon_get_block_number_error", + "handle_retrieve_transactions_uses_default_max_block_count_for_ending_block_number_upon_get_block_number_error", ); let (accountant, _, accountant_recording_arc) = make_recorder(); let earning_wallet = make_wallet("somewallet"); @@ -1311,7 +1313,7 @@ mod tests { .retrieve_transactions_result(Ok(expected_transactions.clone())) .lower_interface_results(Box::new(lower_interface)); let persistent_config = PersistentConfigurationMock::new() - .max_block_count_result(Ok(None)) + .max_block_count_result(Ok(Some(DEFAULT_MAX_BLOCK_COUNT))) .start_block_result(Ok(Some(6))); let subject = BlockchainBridge::new( Box::new(blockchain_interface_mock), @@ -1341,7 +1343,7 @@ mod tests { *retrieve_transactions_params, vec![( BlockNumber::Number(6u64.into()), - BlockNumber::Latest, + BlockNumber::Number((DEFAULT_MAX_BLOCK_COUNT + 6u64).into()), earning_wallet )] ); @@ -1361,7 +1363,7 @@ mod tests { }), } ); - TestLogHandler::new().exists_log_containing("DEBUG: BlockchainBridge: Using 'latest' block number instead of a literal number. QueryFailed(\"Failed to read the latest block number\")"); + TestLogHandler::new().exists_log_containing("DEBUG: BlockchainBridge: Using '100006' ending block number. QueryFailed(\"Failed to read the latest block number\")"); } #[test] @@ -1400,7 +1402,7 @@ mod tests { .retrieve_transactions_result(Ok(expected_transactions.clone())) .lower_interface_results(Box::new(lower_interface)); let persistent_config = PersistentConfigurationMock::new() - .max_block_count_result(Ok(None)) + .max_block_count_result(Ok(Some(DEFAULT_MAX_BLOCK_COUNT))) .start_block_result(Ok(None)); let subject = BlockchainBridge::new( Box::new(blockchain_interface_mock), @@ -1449,7 +1451,8 @@ mod tests { } #[test] - fn handle_retrieve_transactions_with_latest_for_start_and_end_block_is_supported() { + fn handle_retrieve_transactions_when_get_block_number_fails_uses_latest_for_start_and_end_block( + ) { let retrieve_transactions_params_arc = Arc::new(Mutex::new(vec![])); let earning_wallet = make_wallet("somewallet"); let amount = 42; @@ -1471,11 +1474,11 @@ mod tests { }; let system = System::new( - "handle_retrieve_transactions_with_latest_for_start_and_end_block_is_supported", + "handle_retrieve_transactions_when_get_block_number_fails_uses_latest_for_start_and_end_block", ); let (accountant, _, accountant_recording_arc) = make_recorder(); let persistent_config = PersistentConfigurationMock::new() - .max_block_count_result(Ok(None)) + .max_block_count_result(Ok(Some(DEFAULT_MAX_BLOCK_COUNT))) .start_block_result(Ok(None)); let latest_block_number = LatestBlockNumber::Err(BlockchainError::QueryFailed( "Failed to read from block chain service".to_string(), diff --git a/node/src/database/db_initializer.rs b/node/src/database/db_initializer.rs index bcb9a3a0a..3619cc1b4 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, 9); + assert_eq!(CURRENT_SCHEMA_VERSION, 10); } #[test] diff --git a/node/src/database/db_migrations/db_migrator.rs b/node/src/database/db_migrations/db_migrator.rs index 746af3e26..7d1ec4f8c 100644 --- a/node/src/database/db_migrations/db_migrator.rs +++ b/node/src/database/db_migrations/db_migrator.rs @@ -10,6 +10,7 @@ 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, }; @@ -78,6 +79,7 @@ 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_8_to_9.rs b/node/src/database/db_migrations/migrations/migration_8_to_9.rs index c5928edb6..4bf95e955 100644 --- a/node/src/database/db_migrations/migrations/migration_8_to_9.rs +++ b/node/src/database/db_migrations/migrations/migration_8_to_9.rs @@ -43,27 +43,28 @@ mod tests { let _ = bring_db_0_back_to_life_and_return_connection(&db_path); let subject = DbInitializerReal::default(); + let result = subject.initialize_to_version( + &dir_path, + 8, + DbInitializationConfig::create_or_migrate(make_external_data()), + ); + + assert!(result.is_ok()); + let result = subject.initialize_to_version( &dir_path, 9, DbInitializationConfig::create_or_migrate(make_external_data()), ); + let connection = result.unwrap(); let (mp_value, mp_encrypted) = retrieve_config_row(connection.as_ref(), "max_block_count"); 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("9".to_string())); + assert_eq!(cs_value, Some(9.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", ]); } 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 new file mode 100644 index 000000000..7622ef01f --- /dev/null +++ b/node/src/database/db_migrations/migrations/migration_9_to_10.rs @@ -0,0 +1,71 @@ +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 ('max_block_count', 100000, 0) ON CONFLICT(name) DO UPDATE SET value = 100000 WHERE name = 'max_block_count'" + ]) + } + + 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, + 9, + DbInitializationConfig::create_or_migrate(make_external_data()), + ); + + assert!(result.is_ok()); + + 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(), "max_block_count"); + let (cs_value, cs_encrypted) = retrieve_config_row(connection.as_ref(), "schema_version"); + assert_eq!(mp_value, Some(100_000u64.to_string())); + 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 9 to 10", + ]); + } +} diff --git a/node/src/database/db_migrations/migrations/mod.rs b/node/src/database/db_migrations/migrations/mod.rs index 68b10ca9b..bcdb14176 100644 --- a/node/src/database/db_migrations/migrations/mod.rs +++ b/node/src/database/db_migrations/migrations/mod.rs @@ -9,3 +9,4 @@ 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;