From db4e2b1529c08886fa2dde107c2e77b62d70c204 Mon Sep 17 00:00:00 2001 From: KauriHero Date: Mon, 27 Oct 2025 13:04:46 +1300 Subject: [PATCH 1/3] Refine regex for max block count extraction and add test Updated regex to capture maximum block count from error messages more accurately - namely update to Nodies provider. Added a new test case for extracting this specific error response. --- node/src/blockchain/blockchain_bridge.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/node/src/blockchain/blockchain_bridge.rs b/node/src/blockchain/blockchain_bridge.rs index a0e501393..ab1290ca9 100644 --- a/node/src/blockchain/blockchain_bridge.rs +++ b/node/src/blockchain/blockchain_bridge.rs @@ -507,8 +507,8 @@ impl BlockchainBridge { pub fn extract_max_block_count(error: BlockchainError) -> Option { let regex_result = - Regex::new(r".* (max: |allowed for your plan: |is limited to |block range limit \(|exceeds max block range )(?P\d+).*") - .expect("Invalid regex"); + Regex::new(r".* (max: |allowed for your plan: |is limited to |block range limit \(|exceeds max block range |maximum allowed is )(?P\d+).*") + .expect("Invalid regex"); let max_block_count = match error { BlockchainError::QueryFailed(msg) => match regex_result.captures(msg.as_str()) { Some(captures) => match captures.name("max_block_count") { @@ -2201,6 +2201,15 @@ mod tests { assert_eq!(Some(100000), max_block_count); } + #[test] + fn extract_max_block_range_for_nodies_error_response_v2() { + let result = BlockchainError::QueryFailed("RPC error: Error { code: ServerError(-32001), message: \"Block range too large: maximum allowed is 20000 blocks\", data: None }".to_string()); + + let max_block_count = BlockchainBridge::extract_max_block_count(result); + + assert_eq!(Some(20000), max_block_count); + } + #[test] fn extract_max_block_range_for_expected_batch_got_single_error_response() { let result = BlockchainError::QueryFailed( From 816f44b1c7a0e9716307698941cb899be3c51392 Mon Sep 17 00:00:00 2001 From: KauriHero Date: Wed, 5 Nov 2025 10:50:50 +1300 Subject: [PATCH 2/3] Fix inclusive range calculation for block scanning in BlockchainInterfaceWeb3 Adjusted the end block marker calculation to correctly account for inclusive ranges by subtracting 1 from the scan range. T --- .../blockchain_interface/blockchain_interface_web3/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node/src/blockchain/blockchain_interface/blockchain_interface_web3/mod.rs b/node/src/blockchain/blockchain_interface/blockchain_interface_web3/mod.rs index 92f8e9145..4c3ec64fe 100644 --- a/node/src/blockchain/blockchain_interface/blockchain_interface_web3/mod.rs +++ b/node/src/blockchain/blockchain_interface/blockchain_interface_web3/mod.rs @@ -367,7 +367,9 @@ impl BlockchainInterfaceWeb3 { ) -> BlockMarker { let locally_determined_end_block_marker = match (start_block_marker, scan_range) { (BlockMarker::Value(start_block), BlockScanRange::Range(scan_range_number)) => { - BlockMarker::Value(start_block + scan_range_number) + // Subtract 1 because the range is inclusive: [start_block, end_block] + // Example: If max range is 20000, we need start_block to start_block+20000-1 (ending up with 20000 blocks total) + BlockMarker::Value(start_block + scan_range_number - 1) } (_, _) => BlockMarker::Uninitialized, }; From 152f6c5415166b03a44b8e7bbd486e7972c1b944 Mon Sep 17 00:00:00 2001 From: KauriHero Date: Wed, 5 Nov 2025 12:44:42 +1300 Subject: [PATCH 3/3] Fix block marker calculations in tests for blockchain bridge and interface. Adjusted expected new start block values to ensure accurate transaction retrieval and logging. --- node/src/blockchain/blockchain_bridge.rs | 4 ++-- .../blockchain_interface/blockchain_interface_web3/mod.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/node/src/blockchain/blockchain_bridge.rs b/node/src/blockchain/blockchain_bridge.rs index ab1290ca9..e5b164279 100644 --- a/node/src/blockchain/blockchain_bridge.rs +++ b/node/src/blockchain/blockchain_bridge.rs @@ -1541,7 +1541,7 @@ mod tests { system.run(); let after = SystemTime::now(); let expected_transactions = RetrievedBlockchainTransactions { - new_start_block: BlockMarker::Value(42 + 9_000_000 + 1), + new_start_block: BlockMarker::Value(42 + 9_000_000), transactions: vec![ BlockchainTransaction { block_number: 6040059, @@ -1742,7 +1742,7 @@ mod tests { let received_payments_message = accountant_recording.get_record::(0); check_timestamp(before, received_payments_message.timestamp, after); let expected_transactions = RetrievedBlockchainTransactions { - new_start_block: BlockMarker::Value(6 + 5000 + 1), + new_start_block: BlockMarker::Value(6 + 5000), transactions: vec![BlockchainTransaction { block_number: 2000, from: earning_wallet.clone(), diff --git a/node/src/blockchain/blockchain_interface/blockchain_interface_web3/mod.rs b/node/src/blockchain/blockchain_interface/blockchain_interface_web3/mod.rs index 4c3ec64fe..3971555d1 100644 --- a/node/src/blockchain/blockchain_interface/blockchain_interface_web3/mod.rs +++ b/node/src/blockchain/blockchain_interface/blockchain_interface_web3/mod.rs @@ -517,8 +517,8 @@ mod tests { let start_block_marker = BlockMarker::Value(42); let scan_range = BlockScanRange::Range(1000); let block_response = "0x7d0"; // 2_000 - let expected_new_start_block = BlockMarker::Value(42 + 1000 + 1); - let expected_log = "from start block: Number(42) to end block: Number(1042)"; + let expected_new_start_block = BlockMarker::Value(42 + 1000); + let expected_log = "from start block: Number(42) to end block: Number(1041)"; assert_on_retrieves_transactions( start_block_marker, scan_range, @@ -1178,7 +1178,7 @@ mod tests { Err(BlockchainError::InvalidResponse), &logger ), - BlockMarker::Value(150) + BlockMarker::Value(149) ); assert_eq!( Subject::calculate_end_block_marker( @@ -1196,7 +1196,7 @@ mod tests { Ok(120.into()), &logger ), - BlockMarker::Value(50 + 10) + BlockMarker::Value(59) ); }