-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-744-Review-4 #565
Open
Syther007
wants to merge
10
commits into
GH-744-Review-4-Base
Choose a base branch
from
GH-744-merge-test
base: GH-744-Review-4-Base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
GH-744-Review-4 #565
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6b9d987
GH-744: First commit for review-3, fixed tests
Syther007 d81ac19
GH-744: Refactored TxReceipt
Syther007 69f70c1
GH-744: Refactored TxResponse
Syther007 d30dc27
GH-744 moved & renamed blockchain_interface_utils.rs
Syther007 83dc7bc
GH-744: fixed test: dns_resolution_failure_for_wildcard_ip_with_real_…
Syther007 91eefcf
GH-744: add review 4 changes
utkarshg6 f4b8150
GH-744: add review 5 changes
utkarshg6 64f2f40
GH-744: remove the map_err()
utkarshg6 a047291
GH-744: migrate the logging code to a different function
utkarshg6 d07760b
GH-744: add review 6 changes
utkarshg6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,7 +366,8 @@ impl BlockchainBridge { | |
format!("Error while retrieving transactions: {:?}", e) | ||
}) | ||
.and_then(move |retrieved_blockchain_transactions| { | ||
received_payments_subs.try_send(ReceivedPayments { | ||
received_payments_subs | ||
.try_send(ReceivedPayments { | ||
timestamp: SystemTime::now(), | ||
new_start_block: retrieved_blockchain_transactions.new_start_block, | ||
response_skeleton_opt: msg.response_skeleton_opt, | ||
|
@@ -400,33 +401,32 @@ impl BlockchainBridge { | |
.process_transaction_receipts(transaction_hashes) | ||
.map_err(move |e| e.to_string()) | ||
.and_then(move |transaction_receipts_results| { | ||
let length = transaction_receipts_results.len(); | ||
let mut transactions_found = 0; | ||
for transaction_receipt in &transaction_receipts_results { | ||
if let TransactionReceiptResult::RpcResponse(tx_receipt) = transaction_receipt { | ||
if let TxStatus::Succeeded(_) = tx_receipt.status { | ||
transactions_found += 1; | ||
let (successful_count, failed_count, pending_count) = transaction_receipts_results | ||
.iter() | ||
.fold((0, 0, 0), |(success, fail, pending), transaction_receipt| { | ||
match transaction_receipt { | ||
TransactionReceiptResult::RpcResponse(tx_receipt) => match tx_receipt.status { | ||
TxStatus::Failed => (success, fail + 1, pending), | ||
TxStatus::Pending => (success, fail, pending + 1), | ||
TxStatus::Succeeded(_) => (success + 1, fail, pending), | ||
}, | ||
TransactionReceiptResult::LocalError(_)=> (success, fail, pending + 1), | ||
} | ||
} | ||
} | ||
}); | ||
debug!(logger, "Scan results: Successful: {successful_count}, Pending: {pending_count}, Failed: {failed_count}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think you could pack this whole fold for the debug into a separate function. I've got this in my mind: You can use the trick with
Therefore:
A praise for that nice use of |
||
|
||
let pairs = transaction_receipts_results | ||
.into_iter() | ||
.zip(msg.pending_payable.into_iter()) | ||
.collect_vec(); | ||
|
||
accountant_recipient | ||
.try_send(ReportTransactionReceipts { | ||
fingerprints_with_receipts: pairs, | ||
response_skeleton_opt: msg.response_skeleton_opt, | ||
}) | ||
.expect("Accountant is dead"); | ||
if length != transactions_found { | ||
debug!( | ||
logger, | ||
"Aborting scanning; {} transactions succeed and {} transactions failed", | ||
transactions_found, | ||
length - transactions_found | ||
); | ||
}; | ||
|
||
Ok(()) | ||
}), | ||
) | ||
|
@@ -583,7 +583,7 @@ mod tests { | |
use std::sync::{Arc, Mutex}; | ||
use std::time::{Duration, SystemTime}; | ||
use web3::types::{TransactionReceipt, H160}; | ||
use crate::blockchain::blockchain_interface::blockchain_interface_web3::lower_level_interface_web3::TxReceipt; | ||
use crate::blockchain::blockchain_interface::blockchain_interface_web3::lower_level_interface_web3::{TransactionBlock, TxReceipt}; | ||
|
||
impl Handler<AssertionsMessage<Self>> for BlockchainBridge { | ||
type Result = (); | ||
|
@@ -1198,9 +1198,10 @@ mod tests { | |
pending_payable_fingerprint_1 | ||
), | ||
( | ||
TransactionReceiptResult::RpcResponse(TxReceipt{ | ||
TransactionReceiptResult::RpcResponse(TxReceipt { | ||
transaction_hash: hash_2, | ||
status: TxStatus::Pending }), | ||
status: TxStatus::Pending | ||
}), | ||
pending_payable_fingerprint_2 | ||
), | ||
], | ||
|
@@ -1326,11 +1327,13 @@ mod tests { | |
amount: 7879, | ||
process_error: None, | ||
}; | ||
let mut transaction_receipt = TransactionReceipt::default(); | ||
transaction_receipt.block_number = Some(block_number); | ||
transaction_receipt.block_hash = Some(Default::default()); | ||
transaction_receipt.contract_address = Some(contract_address); | ||
transaction_receipt.status = Some(U64::from(1)); | ||
let transaction_receipt = TxReceipt { | ||
transaction_hash: Default::default(), | ||
status: TxStatus::Succeeded(TransactionBlock { | ||
block_hash: Default::default(), | ||
block_number, | ||
}), | ||
}; | ||
let blockchain_interface = make_blockchain_interface_web3(port); | ||
let system = System::new("test_transaction_receipts"); | ||
let mut subject = BlockchainBridge::new( | ||
|
@@ -1367,7 +1370,7 @@ mod tests { | |
ReportTransactionReceipts { | ||
fingerprints_with_receipts: vec![ | ||
(TransactionReceiptResult::RpcResponse(TxReceipt{ transaction_hash: hash_1, status: TxStatus::Pending }), fingerprint_1), | ||
(TransactionReceiptResult::RpcResponse(transaction_receipt.into()), fingerprint_2), | ||
(TransactionReceiptResult::RpcResponse(transaction_receipt), fingerprint_2), | ||
(TransactionReceiptResult::RpcResponse(TxReceipt{ transaction_hash: hash_3, status: TxStatus::Pending }), fingerprint_3), | ||
(TransactionReceiptResult::LocalError("RPC error: Error { code: ServerError(429), message: \"The requests per second (RPS) of your requests are higher than your plan allows.\", data: None }".to_string()), fingerprint_4) | ||
], | ||
|
@@ -1377,7 +1380,9 @@ mod tests { | |
}), | ||
} | ||
); | ||
TestLogHandler::new().exists_log_containing("DEBUG: BlockchainBridge: Aborting scanning; 1 transactions succeed and 3 transactions failed"); | ||
TestLogHandler::new().exists_log_containing( | ||
"DEBUG: BlockchainBridge: Scan results: Successful: 1, Pending: 3, Failed: 0", | ||
); | ||
} | ||
|
||
#[test] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of points about possibilities for minor optimisations.
move
is redundantif length != transactions_found {
coupled with "Aborting scanning; {} transactions succeed and {} transactions failed" is controversial. It's because the scan hasn't differed from a successful one in the length of the process (you do the same amount of work to figure out all the transactions were successful as you do if there are some pending or failed transactions), therefore speaking of "aborting" is misinterpreting the truth. We didn't abort. We completed everything.However there is more than that: you cannot count the succeeded transactions only and then assume that the rest of them have failed with no exception. That's not right. Be aware that the rest is a mix of legitimately failed transactions, yes, but also those still pending. I'm asking, do you think it's appropriate having the pending transactions counted in the failures? Because that's what you're doing in the debug!() log down here.
If you still think we'd benefit from having that log, I'd recommend to keep track of all three categories: Confirmed, Pending, Failed.
process_transaction_receipts()
, there is a passage in the chain of Future-devoted methods that says.map_err(|e| e)
which is a redundant call with no effect, you can delete that lineget_transaction_receipt_in_batch()
, you can see this snipped:Honestly, I'm surprised that this code even does anything because I've been taught that iterators in Rust are "lazy" and therefore their code isn't executed until a certain terminal method is reached and performed. Most of the time this method is the renowned
collect()
, thenfold()
,partition()
and alsofor_each()
.As you have used none of them in here, it makes me wonder how you got your code working, assuming this has proper test coverage. Anyway, without having to argue over this, we can easily put end to this question with the replacement of
.map()
by.for_each()
. This swap will also rule out the assignment to an anonymous variable sincefor_each()
is not allowed to return a value, naturally: It's meant to allow side effects only. I hope you'll be able to make out what I instruct you for.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this change! 😃
I really appreciated your insights on tracking the different transaction statuses and the iterator usage. I went ahead and implemented those suggestions.
As for the
move
and the redundant error mapping, I decided to leave those as is to keep the original function signature intact.