Skip to content

Commit b8e704a

Browse files
authored
GH-552: max_block_count defaults to 100_000 (#558)
* GH-552: max_block_count defaults to 100_000 * GH-552: Cleanup migration tests * GH-552: Bump macos target to macos-13
1 parent 75f6657 commit b8e704a

File tree

8 files changed

+103
-23
lines changed

8 files changed

+103
-23
lines changed

.github/workflows/ci-matrix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
target:
1616
- { name: linux, os: ubuntu-22.04 }
17-
- { name: macos, os: macos-12 }
17+
- { name: macos, os: macos-13 }
1818
- { name: windows, os: windows-2022 }
1919

2020
name: Build node on ${{ matrix.target.os }}

masq_lib/src/constants.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::data_version::DataVersion;
55
use const_format::concatcp;
66

77
pub const DEFAULT_CHAIN: Chain = Chain::PolyMainnet;
8-
pub const CURRENT_SCHEMA_VERSION: usize = 9;
8+
pub const CURRENT_SCHEMA_VERSION: usize = 10;
99

1010
pub const HIGHEST_RANDOM_CLANDESTINE_PORT: u16 = 9999;
1111
pub const HTTP_PORT: u16 = 80;
@@ -24,6 +24,8 @@ pub const WALLET_ADDRESS_LENGTH: usize = 42;
2424
pub const MASQ_TOTAL_SUPPLY: u64 = 37_500_000;
2525
pub const WEIS_IN_GWEI: i128 = 1_000_000_000;
2626

27+
pub const DEFAULT_MAX_BLOCK_COUNT: u64 = 100_000;
28+
2729
pub const ETH_MAINNET_CONTRACT_CREATION_BLOCK: u64 = 11_170_708;
2830
pub const ETH_ROPSTEN_CONTRACT_CREATION_BLOCK: u64 = 8_688_171;
2931
pub const POLYGON_MAINNET_CONTRACT_CREATION_BLOCK: u64 = 14_863_650;

node/src/blockchain/blockchain_bridge.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use actix::Message;
3333
use actix::{Addr, Recipient};
3434
use itertools::Itertools;
3535
use masq_lib::blockchains::chains::Chain;
36+
use masq_lib::constants::DEFAULT_MAX_BLOCK_COUNT;
3637
use masq_lib::logger::Logger;
3738
use masq_lib::messages::ScanType;
3839
use masq_lib::ui_gateway::NodeFromUiMessage;
@@ -287,7 +288,7 @@ impl BlockchainBridge {
287288
};
288289
let max_block_count = match self.persistent_config.max_block_count() {
289290
Ok(Some(mbc)) => mbc,
290-
_ => u64::MAX,
291+
_ => DEFAULT_MAX_BLOCK_COUNT,
291292
};
292293
let use_unlimited_block_count_range = u64::MAX == max_block_count;
293294
let use_latest_block = u64::MAX == start_block_nbr;
@@ -1019,7 +1020,7 @@ mod tests {
10191020
)))
10201021
.lower_interface_results(Box::new(lower_interface));
10211022
let persistent_config = PersistentConfigurationMock::new()
1022-
.max_block_count_result(Ok(Some(100_000)))
1023+
.max_block_count_result(Ok(Some(DEFAULT_MAX_BLOCK_COUNT)))
10231024
.start_block_result(Ok(Some(5))); // no set_start_block_result: set_start_block() must not be called
10241025
let mut subject = BlockchainBridge::new(
10251026
Box::new(blockchain_interface),
@@ -1277,11 +1278,12 @@ mod tests {
12771278
}
12781279

12791280
#[test]
1280-
fn handle_retrieve_transactions_uses_latest_block_number_upon_get_block_number_error() {
1281+
fn handle_retrieve_transactions_uses_default_max_block_count_for_ending_block_number_upon_get_block_number_error(
1282+
) {
12811283
init_test_logging();
12821284
let retrieve_transactions_params_arc = Arc::new(Mutex::new(vec![]));
12831285
let system = System::new(
1284-
"handle_retrieve_transactions_uses_latest_block_number_upon_get_block_number_error",
1286+
"handle_retrieve_transactions_uses_default_max_block_count_for_ending_block_number_upon_get_block_number_error",
12851287
);
12861288
let (accountant, _, accountant_recording_arc) = make_recorder();
12871289
let earning_wallet = make_wallet("somewallet");
@@ -1311,7 +1313,7 @@ mod tests {
13111313
.retrieve_transactions_result(Ok(expected_transactions.clone()))
13121314
.lower_interface_results(Box::new(lower_interface));
13131315
let persistent_config = PersistentConfigurationMock::new()
1314-
.max_block_count_result(Ok(None))
1316+
.max_block_count_result(Ok(Some(DEFAULT_MAX_BLOCK_COUNT)))
13151317
.start_block_result(Ok(Some(6)));
13161318
let subject = BlockchainBridge::new(
13171319
Box::new(blockchain_interface_mock),
@@ -1341,7 +1343,7 @@ mod tests {
13411343
*retrieve_transactions_params,
13421344
vec![(
13431345
BlockNumber::Number(6u64.into()),
1344-
BlockNumber::Latest,
1346+
BlockNumber::Number((DEFAULT_MAX_BLOCK_COUNT + 6u64).into()),
13451347
earning_wallet
13461348
)]
13471349
);
@@ -1361,7 +1363,7 @@ mod tests {
13611363
}),
13621364
}
13631365
);
1364-
TestLogHandler::new().exists_log_containing("DEBUG: BlockchainBridge: Using 'latest' block number instead of a literal number. QueryFailed(\"Failed to read the latest block number\")");
1366+
TestLogHandler::new().exists_log_containing("DEBUG: BlockchainBridge: Using '100006' ending block number. QueryFailed(\"Failed to read the latest block number\")");
13651367
}
13661368

13671369
#[test]
@@ -1400,7 +1402,7 @@ mod tests {
14001402
.retrieve_transactions_result(Ok(expected_transactions.clone()))
14011403
.lower_interface_results(Box::new(lower_interface));
14021404
let persistent_config = PersistentConfigurationMock::new()
1403-
.max_block_count_result(Ok(None))
1405+
.max_block_count_result(Ok(Some(DEFAULT_MAX_BLOCK_COUNT)))
14041406
.start_block_result(Ok(None));
14051407
let subject = BlockchainBridge::new(
14061408
Box::new(blockchain_interface_mock),
@@ -1449,7 +1451,8 @@ mod tests {
14491451
}
14501452

14511453
#[test]
1452-
fn handle_retrieve_transactions_with_latest_for_start_and_end_block_is_supported() {
1454+
fn handle_retrieve_transactions_when_get_block_number_fails_uses_latest_for_start_and_end_block(
1455+
) {
14531456
let retrieve_transactions_params_arc = Arc::new(Mutex::new(vec![]));
14541457
let earning_wallet = make_wallet("somewallet");
14551458
let amount = 42;
@@ -1471,11 +1474,11 @@ mod tests {
14711474
};
14721475

14731476
let system = System::new(
1474-
"handle_retrieve_transactions_with_latest_for_start_and_end_block_is_supported",
1477+
"handle_retrieve_transactions_when_get_block_number_fails_uses_latest_for_start_and_end_block",
14751478
);
14761479
let (accountant, _, accountant_recording_arc) = make_recorder();
14771480
let persistent_config = PersistentConfigurationMock::new()
1478-
.max_block_count_result(Ok(None))
1481+
.max_block_count_result(Ok(Some(DEFAULT_MAX_BLOCK_COUNT)))
14791482
.start_block_result(Ok(None));
14801483
let latest_block_number = LatestBlockNumber::Err(BlockchainError::QueryFailed(
14811484
"Failed to read from block chain service".to_string(),

node/src/database/db_initializer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ mod tests {
652652
#[test]
653653
fn constants_have_correct_values() {
654654
assert_eq!(DATABASE_FILE, "node-data.db");
655-
assert_eq!(CURRENT_SCHEMA_VERSION, 9);
655+
assert_eq!(CURRENT_SCHEMA_VERSION, 10);
656656
}
657657

658658
#[test]

node/src/database/db_migrations/db_migrator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::database::db_migrations::migrations::migration_5_to_6::Migrate_5_to_6
1010
use crate::database::db_migrations::migrations::migration_6_to_7::Migrate_6_to_7;
1111
use crate::database::db_migrations::migrations::migration_7_to_8::Migrate_7_to_8;
1212
use crate::database::db_migrations::migrations::migration_8_to_9::Migrate_8_to_9;
13+
use crate::database::db_migrations::migrations::migration_9_to_10::Migrate_9_to_10;
1314
use crate::database::db_migrations::migrator_utils::{
1415
DBMigDeclarator, DBMigrationUtilities, DBMigrationUtilitiesReal, DBMigratorInnerConfiguration,
1516
};
@@ -78,6 +79,7 @@ impl DbMigratorReal {
7879
&Migrate_6_to_7,
7980
&Migrate_7_to_8,
8081
&Migrate_8_to_9,
82+
&Migrate_9_to_10,
8183
]
8284
}
8385

node/src/database/db_migrations/migrations/migration_8_to_9.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,28 @@ mod tests {
4343
let _ = bring_db_0_back_to_life_and_return_connection(&db_path);
4444
let subject = DbInitializerReal::default();
4545

46+
let result = subject.initialize_to_version(
47+
&dir_path,
48+
8,
49+
DbInitializationConfig::create_or_migrate(make_external_data()),
50+
);
51+
52+
assert!(result.is_ok());
53+
4654
let result = subject.initialize_to_version(
4755
&dir_path,
4856
9,
4957
DbInitializationConfig::create_or_migrate(make_external_data()),
5058
);
59+
5160
let connection = result.unwrap();
5261
let (mp_value, mp_encrypted) = retrieve_config_row(connection.as_ref(), "max_block_count");
5362
let (cs_value, cs_encrypted) = retrieve_config_row(connection.as_ref(), "schema_version");
5463
assert_eq!(mp_value, None);
5564
assert_eq!(mp_encrypted, false);
56-
assert_eq!(cs_value, Some("9".to_string()));
65+
assert_eq!(cs_value, Some(9.to_string()));
5766
assert_eq!(cs_encrypted, false);
5867
TestLogHandler::new().assert_logs_contain_in_order(vec![
59-
"DbMigrator: Database successfully migrated from version 0 to 1",
60-
"DbMigrator: Database successfully migrated from version 1 to 2",
61-
"DbMigrator: Database successfully migrated from version 2 to 3",
62-
"DbMigrator: Database successfully migrated from version 3 to 4",
63-
"DbMigrator: Database successfully migrated from version 4 to 5",
64-
"DbMigrator: Database successfully migrated from version 5 to 6",
65-
"DbMigrator: Database successfully migrated from version 6 to 7",
66-
"DbMigrator: Database successfully migrated from version 7 to 8",
6768
"DbMigrator: Database successfully migrated from version 8 to 9",
6869
]);
6970
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use crate::database::db_migrations::db_migrator::DatabaseMigration;
2+
use crate::database::db_migrations::migrator_utils::DBMigDeclarator;
3+
4+
#[allow(non_camel_case_types)]
5+
pub struct Migrate_9_to_10;
6+
7+
impl DatabaseMigration for Migrate_9_to_10 {
8+
fn migrate<'a>(
9+
&self,
10+
declaration_utils: Box<dyn DBMigDeclarator + 'a>,
11+
) -> rusqlite::Result<()> {
12+
declaration_utils.execute_upon_transaction(&[
13+
&"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'"
14+
])
15+
}
16+
17+
fn old_version(&self) -> usize {
18+
9
19+
}
20+
}
21+
22+
#[cfg(test)]
23+
mod tests {
24+
use crate::database::db_initializer::{
25+
DbInitializationConfig, DbInitializer, DbInitializerReal, DATABASE_FILE,
26+
};
27+
use crate::test_utils::database_utils::{
28+
bring_db_0_back_to_life_and_return_connection, make_external_data, retrieve_config_row,
29+
};
30+
use masq_lib::test_utils::logging::{init_test_logging, TestLogHandler};
31+
use masq_lib::test_utils::utils::ensure_node_home_directory_exists;
32+
use std::fs::create_dir_all;
33+
34+
#[test]
35+
fn migration_from_9_to_10_is_properly_set() {
36+
init_test_logging();
37+
let dir_path = ensure_node_home_directory_exists(
38+
"db_migrations",
39+
"migration_from_9_to_10_is_properly_set",
40+
);
41+
create_dir_all(&dir_path).unwrap();
42+
let db_path = dir_path.join(DATABASE_FILE);
43+
let _ = bring_db_0_back_to_life_and_return_connection(&db_path);
44+
let subject = DbInitializerReal::default();
45+
46+
let result = subject.initialize_to_version(
47+
&dir_path,
48+
9,
49+
DbInitializationConfig::create_or_migrate(make_external_data()),
50+
);
51+
52+
assert!(result.is_ok());
53+
54+
let result = subject.initialize_to_version(
55+
&dir_path,
56+
10,
57+
DbInitializationConfig::create_or_migrate(make_external_data()),
58+
);
59+
60+
let connection = result.unwrap();
61+
let (mp_value, mp_encrypted) = retrieve_config_row(connection.as_ref(), "max_block_count");
62+
let (cs_value, cs_encrypted) = retrieve_config_row(connection.as_ref(), "schema_version");
63+
assert_eq!(mp_value, Some(100_000u64.to_string()));
64+
assert_eq!(mp_encrypted, false);
65+
assert_eq!(cs_value, Some(10.to_string()));
66+
assert_eq!(cs_encrypted, false);
67+
TestLogHandler::new().assert_logs_contain_in_order(vec![
68+
"DbMigrator: Database successfully migrated from version 9 to 10",
69+
]);
70+
}
71+
}

node/src/database/db_migrations/migrations/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pub mod migration_5_to_6;
99
pub mod migration_6_to_7;
1010
pub mod migration_7_to_8;
1111
pub mod migration_8_to_9;
12+
pub mod migration_9_to_10;

0 commit comments

Comments
 (0)