Skip to content

Commit 858adfa

Browse files
authored
GH-598-hot-fix-panic-bug: fixed (#746)
1 parent 25af8cb commit 858adfa

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

node/src/blockchain/blockchain_bridge.rs

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -312,28 +312,32 @@ impl BlockchainBridge {
312312

313313
Box::new(
314314
self.process_payments(msg.agent, msg.priced_templates)
315-
.map_err(move |e: LocalPayableError| {
316-
sent_payable_subs_err
317-
.try_send(SentPayables {
318-
payment_procedure_result: Self::payment_procedure_result_from_error(
319-
e.clone(),
320-
),
321-
payable_scan_type,
322-
response_skeleton_opt: skeleton_opt,
323-
})
324-
.expect("Accountant is dead");
325-
326-
format!("ReportAccountsPayable: {}", e)
327-
})
328-
.and_then(move |batch_results| {
329-
sent_payable_subs_success
330-
.try_send(SentPayables {
331-
payment_procedure_result: Ok(batch_results),
332-
payable_scan_type,
333-
response_skeleton_opt: skeleton_opt,
334-
})
335-
.expect("Accountant is dead");
336-
315+
.then(move |result| {
316+
match result {
317+
Ok(batch_results) => {
318+
sent_payable_subs_success
319+
.try_send(SentPayables {
320+
payment_procedure_result: Ok(batch_results),
321+
payable_scan_type,
322+
response_skeleton_opt: skeleton_opt,
323+
})
324+
.expect("Accountant is dead");
325+
}
326+
Err(e) => {
327+
sent_payable_subs_err
328+
.try_send(SentPayables {
329+
payment_procedure_result:
330+
Self::payment_procedure_result_from_error(e),
331+
payable_scan_type,
332+
response_skeleton_opt: skeleton_opt,
333+
})
334+
.expect("Accountant is dead");
335+
}
336+
}
337+
// TODO Temporary workaround: prevents the Accountant from receiving two messages
338+
// describing the same error. Duplicate notifications could previously trigger
339+
// a panic in the scanners, because the substitution call for a given scanner
340+
// was executed twice and tripped the guard that enforces a single concurrent scan.
337341
Ok(())
338342
}),
339343
)
@@ -1021,7 +1025,7 @@ mod tests {
10211025
// let pending_payable_fingerprint_seeds_msg =
10221026
// accountant_recording.get_record::<PendingPayableFingerprintSeeds>(0);
10231027
let sent_payables_msg = accountant_recording.get_record::<SentPayables>(0);
1024-
let scan_error_msg = accountant_recording.get_record::<ScanError>(1);
1028+
// let scan_error_msg = accountant_recording.get_record::<ScanError>(1);
10251029
let batch_results = sent_payables_msg.clone().payment_procedure_result.unwrap();
10261030
let failed_tx = FailedTx {
10271031
hash: H256::from_str(
@@ -1048,22 +1052,23 @@ mod tests {
10481052
// amount: account.balance_wei
10491053
// }]
10501054
// );
1051-
assert_eq!(scan_error_msg.scan_type, DetailedScanType::NewPayables);
1052-
assert_eq!(
1053-
scan_error_msg.response_skeleton_opt,
1054-
Some(ResponseSkeleton {
1055-
client_id: 1234,
1056-
context_id: 4321
1057-
})
1058-
);
1059-
assert!(scan_error_msg
1060-
.msg
1061-
.contains("ReportAccountsPayable: Sending error: \"Transport error: Error(IncompleteMessage)\". Signed and hashed transactions:"), "This string didn't contain the expected: {}", scan_error_msg.msg);
1062-
assert!(scan_error_msg.msg.contains(
1063-
"FailedTx { hash: 0x81d20df32920161727cd20e375e53c2f9df40fd80256a236fb39e444c999fb6c,"
1064-
));
1065-
assert!(scan_error_msg.msg.contains("FailedTx { hash: 0x81d20df32920161727cd20e375e53c2f9df40fd80256a236fb39e444c999fb6c, receiver_address: 0x00000000000000000000000000000000626c6168, amount_minor: 111420204, timestamp:"), "This string didn't contain the expected: {}", scan_error_msg.msg);
1066-
assert_eq!(accountant_recording.len(), 2);
1055+
// assert_eq!(scan_error_msg.scan_type, DetailedScanType::NewPayables);
1056+
// assert_eq!(
1057+
// scan_error_msg.response_skeleton_opt,
1058+
// Some(ResponseSkeleton {
1059+
// client_id: 1234,
1060+
// context_id: 4321
1061+
// })
1062+
// );
1063+
// assert!(scan_error_msg
1064+
// .msg
1065+
// .contains("ReportAccountsPayable: Sending error: \"Transport error: Error(IncompleteMessage)\". Signed and hashed transactions:"), "This string didn't contain the expected: {}", scan_error_msg.msg);
1066+
// assert!(scan_error_msg.msg.contains(
1067+
// "FailedTx { hash: 0x81d20df32920161727cd20e375e53c2f9df40fd80256a236fb39e444c999fb6c,"
1068+
// ));
1069+
// assert!(scan_error_msg.msg.contains("FailedTx { hash: 0x81d20df32920161727cd20e375e53c2f9df40fd80256a236fb39e444c999fb6c, receiver_address: 0x00000000000000000000000000000000626c6168, amount_minor: 111420204, timestamp:"), "This string didn't contain the expected: {}", scan_error_msg.msg);
1070+
//assert_eq!(accountant_recording.len(), 2);
1071+
assert_eq!(accountant_recording.len(), 1);
10671072
}
10681073

10691074
#[test]

0 commit comments

Comments
 (0)