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
17 changes: 13 additions & 4 deletions node/src/blockchain/blockchain_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ impl BlockchainBridge {

pub fn extract_max_block_count(error: BlockchainError) -> Option<u64> {
let regex_result =
Regex::new(r".* (max: |allowed for your plan: |is limited to |block range limit \(|exceeds max block range )(?P<max_block_count>\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<max_block_count>\d+).*")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now this is a six-fold regular expression. I think that's probably confusing enough: if there turns out to be a seventh option here, we should redesign this to be a list of single-option regexes. We might even want to put the list in the database so that we can distribute little scripts that customers can run to update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a very good idea.
I added the sixth, so our original approach was getting stacked many-fold.

Ill write a card and we can see if the adding to db is a lot of extra work

.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") {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1742,7 +1742,7 @@ mod tests {
let received_payments_message = accountant_recording.get_record::<ReceivedPayments>(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(),
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -515,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,
Expand Down Expand Up @@ -1176,7 +1178,7 @@ mod tests {
Err(BlockchainError::InvalidResponse),
&logger
),
BlockMarker::Value(150)
BlockMarker::Value(149)
);
assert_eq!(
Subject::calculate_end_block_marker(
Expand All @@ -1194,7 +1196,7 @@ mod tests {
Ok(120.into()),
&logger
),
BlockMarker::Value(50 + 10)
BlockMarker::Value(59)
);
}

Expand Down
Loading