From 59a11750109fe8a0bc2ee1223587c17e746ecbd2 Mon Sep 17 00:00:00 2001 From: utkarshg6 Date: Mon, 3 Oct 2022 15:24:54 +0530 Subject: [PATCH 1/7] GH-611: remove the file .idea/inspectionProfiles/Project_Default.xml from git tracking --- .gitignore | 1 + .idea/inspectionProfiles/Project_Default.xml | 1235 ------------------ 2 files changed, 1 insertion(+), 1235 deletions(-) delete mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.gitignore b/.gitignore index e252b6329..cfcb37e57 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /results/ **/*.rs.bk .idea/azure/ +.idea/inspectionProfiles/Project_Default.xml ### Node node_modules diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 17abb1fb6..000000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,1235 +0,0 @@ - - - - \ No newline at end of file From a5788343fb741476bf7d708fee27f7e3bfa90db5 Mon Sep 17 00:00:00 2001 From: utkarshg6 Date: Tue, 4 Oct 2022 12:53:30 +0530 Subject: [PATCH 2/7] GH-611: use OffsetDateTime in the logger.rs --- masq_lib/src/logger.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/masq_lib/src/logger.rs b/masq_lib/src/logger.rs index 3f1a62e8c..c2cde53b6 100644 --- a/masq_lib/src/logger.rs +++ b/masq_lib/src/logger.rs @@ -686,10 +686,10 @@ mod tests { let one_logger = Logger::new("logger_format_is_correct_one"); let another_logger = Logger::new("logger_format_is_correct_another"); - let before = SystemTime::now(); + let before = OffsetDateTime::now_utc(); error!(one_logger, "one log"); error!(another_logger, "another log"); - let after = SystemTime::now(); + let after = OffsetDateTime::now_utc(); let tlh = TestLogHandler::new(); let prefix_len = "0000-00-00T00:00:00.000".len(); @@ -702,8 +702,8 @@ mod tests { " Thd{}: ERROR: logger_format_is_correct_another: another log", thread_id_as_string(thread_id) ))); - let before_str = timestamp_as_string(&before); - let after_str = timestamp_as_string(&after); + let before_str = timestamp_as_string(before); + let after_str = timestamp_as_string(after); assert_between(&one_log[..prefix_len], &before_str, &after_str); assert_between(&another_log[..prefix_len], &before_str, &after_str); } @@ -872,7 +872,7 @@ mod tests { tlh.exists_log_containing("error! 42"); } - pub fn timestamp_as_string(timestamp: OffsetDateTime) -> String { + fn timestamp_as_string(timestamp: OffsetDateTime) -> String { timestamp .format(&parse(TIME_FORMATTING_STRING).unwrap()) .unwrap() From e9ced12dc048655a4b446e0e5784ae56f26332b9 Mon Sep 17 00:00:00 2001 From: utkarshg6 Date: Tue, 4 Oct 2022 13:19:34 +0530 Subject: [PATCH 3/7] GH-611: reorder items in the src/accountant/mod.rs --- node/src/accountant/mod.rs | 64 +++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/node/src/accountant/mod.rs b/node/src/accountant/mod.rs index adb968b76..9899a29c2 100644 --- a/node/src/accountant/mod.rs +++ b/node/src/accountant/mod.rs @@ -171,31 +171,11 @@ impl Handler for Accountant { } } -impl Handler for Accountant { - type Result = (); - - fn handle(&mut self, msg: SentPayable, _ctx: &mut Self::Context) -> Self::Result { - if let Some(node_to_ui_msg) = self.scanners.payable.finish_scan(msg, &self.logger) { - self.ui_message_sub - .as_ref() - .expect("UIGateway is not bound") - .try_send(node_to_ui_msg) - .expect("UIGateway is dead"); - } - } -} - -#[derive(Debug, PartialEq, Message, Clone)] -pub struct ReportTransactionReceipts { - pub fingerprints_with_receipts: Vec<(Option, PendingPayableFingerprint)>, - pub response_skeleton_opt: Option, -} - -impl Handler for Accountant { +impl Handler for Accountant { type Result = (); - fn handle(&mut self, msg: ReportTransactionReceipts, _ctx: &mut Self::Context) -> Self::Result { - if let Some(node_to_ui_msg) = self.scanners.pending_payable.finish_scan(msg, &self.logger) { + fn handle(&mut self, msg: ReceivedPayments, _ctx: &mut Self::Context) -> Self::Result { + if let Some(node_to_ui_msg) = self.scanners.receivable.finish_scan(msg, &self.logger) { self.ui_message_sub .as_ref() .expect("UIGateway is not bound") @@ -205,11 +185,11 @@ impl Handler for Accountant { } } -impl Handler for Accountant { +impl Handler for Accountant { type Result = (); - fn handle(&mut self, msg: ReceivedPayments, _ctx: &mut Self::Context) -> Self::Result { - if let Some(node_to_ui_msg) = self.scanners.receivable.finish_scan(msg, &self.logger) { + fn handle(&mut self, msg: SentPayable, _ctx: &mut Self::Context) -> Self::Result { + if let Some(node_to_ui_msg) = self.scanners.payable.finish_scan(msg, &self.logger) { self.ui_message_sub .as_ref() .expect("UIGateway is not bound") @@ -264,6 +244,26 @@ impl Handler for Accountant { } } +#[derive(Debug, PartialEq, Message, Clone)] +pub struct ReportTransactionReceipts { + pub fingerprints_with_receipts: Vec<(Option, PendingPayableFingerprint)>, + pub response_skeleton_opt: Option, +} + +impl Handler for Accountant { + type Result = (); + + fn handle(&mut self, msg: ReportTransactionReceipts, _ctx: &mut Self::Context) -> Self::Result { + if let Some(node_to_ui_msg) = self.scanners.pending_payable.finish_scan(msg, &self.logger) { + self.ui_message_sub + .as_ref() + .expect("UIGateway is not bound") + .try_send(node_to_ui_msg) + .expect("UIGateway is dead"); + } + } +} + impl Handler for Accountant { type Result = (); @@ -798,10 +798,8 @@ pub fn unsigned_to_signed(unsigned: u64) -> Result { #[derive(Debug, PartialEq, Clone)] pub enum PendingTransactionStatus { - StillPending(PendingPayableId), - //updates slightly the record, waits an interval and starts a new round - Failure(PendingPayableId), - //official tx failure + StillPending(PendingPayableId), //updates slightly the record, waits an interval and starts a new round + Failure(PendingPayableId), //official tx failure Confirmed(PendingPayableFingerprint), //tx was fully processed and successful } @@ -934,12 +932,6 @@ mod tests { #[test] fn accountant_have_proper_defaulted_values() { - // TODO: Verify Scanners are defaulted properly [write this test once GH-574's recorder's code is merged, or cherry-pick the commit] - // When scan() is called, on a scanner, it sends one message to blockchain bridge and a notify_later message, which in turn - // schedules another scan, in turn accountant sends another message to blockchain bridge. Make sure a scan() call to a scanner results in two messages - // to blockchain bridge (one received directly and other indirectly via notify_later). Make sure 6 messages are received in total. - // The second message is received after test defined scan intervals. - // Make sure to use a real database instead of using mock utilities. It'll require at least one row for each table of individual scanners. let mut bootstrapper_config = make_bc_with_defaults(); let payable_dao_factory = Box::new( PayableDaoFactoryMock::new() From 760e6f935bf622b66d8df71cc1dfeed8f5ed5e75 Mon Sep 17 00:00:00 2001 From: utkarshg6 Date: Tue, 4 Oct 2022 13:41:59 +0530 Subject: [PATCH 4/7] GH-611: rename the file tools.rs to scanners_tools.rs --- node/src/accountant/mod.rs | 4 +- node/src/accountant/scanners.rs | 6 +- .../{tools.rs => scanners_tools.rs} | 86 +------------------ 3 files changed, 7 insertions(+), 89 deletions(-) rename node/src/accountant/{tools.rs => scanners_tools.rs} (82%) diff --git a/node/src/accountant/mod.rs b/node/src/accountant/mod.rs index 9899a29c2..491af4471 100644 --- a/node/src/accountant/mod.rs +++ b/node/src/accountant/mod.rs @@ -3,7 +3,7 @@ pub mod payable_dao; pub mod pending_payable_dao; pub mod receivable_dao; pub mod scanners; -pub mod tools; +pub mod scanners_tools; #[cfg(test)] pub mod test_utils; @@ -18,7 +18,7 @@ use crate::accountant::payable_dao::{Payable, PayableAccount, PayableDaoError, P use crate::accountant::pending_payable_dao::{PendingPayableDao, PendingPayableDaoFactory}; use crate::accountant::receivable_dao::{ReceivableDaoError, ReceivableDaoFactory}; use crate::accountant::scanners::scanners::{BeginScanError, NotifyLaterForScanners, Scanners}; -use crate::accountant::tools::common_tools::timestamp_as_string; +use crate::accountant::scanners_tools::common_tools::timestamp_as_string; use crate::banned_dao::BannedDaoFactory; use crate::blockchain::blockchain_bridge::{PendingPayableFingerprint, RetrieveTransactions}; use crate::blockchain::blockchain_interface::{BlockchainError, BlockchainTransaction}; diff --git a/node/src/accountant/scanners.rs b/node/src/accountant/scanners.rs index 6af36c822..50a3bdf29 100644 --- a/node/src/accountant/scanners.rs +++ b/node/src/accountant/scanners.rs @@ -4,13 +4,13 @@ pub(in crate::accountant) mod scanners { use crate::accountant::payable_dao::{Payable, PayableDao, PayableDaoFactory}; use crate::accountant::pending_payable_dao::{PendingPayableDao, PendingPayableDaoFactory}; use crate::accountant::receivable_dao::ReceivableDao; - use crate::accountant::tools::payable_scanner_tools::{ + use crate::accountant::scanners_tools::payable_scanner_tools::{ investigate_debt_extremes, qualified_payables_and_summary, separate_early_errors, }; - use crate::accountant::tools::pending_payable_scanner_tools::{ + use crate::accountant::scanners_tools::pending_payable_scanner_tools::{ elapsed_in_ms, handle_none_status, handle_status_with_failure, handle_status_with_success, }; - use crate::accountant::tools::receivable_scanner_tools::balance_and_age; + use crate::accountant::scanners_tools::receivable_scanner_tools::balance_and_age; use crate::accountant::{ Accountant, ReceivedPayments, ReportTransactionReceipts, RequestTransactionReceipts, ResponseSkeleton, ScanForPayables, ScanForPendingPayables, ScanForReceivables, SentPayable, diff --git a/node/src/accountant/tools.rs b/node/src/accountant/scanners_tools.rs similarity index 82% rename from node/src/accountant/tools.rs rename to node/src/accountant/scanners_tools.rs index 13270a190..ac539659c 100644 --- a/node/src/accountant/tools.rs +++ b/node/src/accountant/scanners_tools.rs @@ -294,12 +294,12 @@ pub mod common_tools { mod tests { use crate::accountant::payable_dao::{Payable, PayableAccount}; use crate::accountant::receivable_dao::ReceivableAccount; - use crate::accountant::tools::payable_scanner_tools::{ + use crate::accountant::scanners_tools::payable_scanner_tools::{ calculate_payout_threshold, exceeded_summary, investigate_debt_extremes, is_payable_qualified, payable_time_diff, qualified_payables_and_summary, separate_early_errors, }; - use crate::accountant::tools::receivable_scanner_tools::balance_and_age; + use crate::accountant::scanners_tools::receivable_scanner_tools::balance_and_age; use crate::accountant::SentPayable; use crate::blockchain::blockchain_interface::BlockchainError; use crate::database::dao_utils::{from_time_t, to_time_t}; @@ -534,86 +534,4 @@ mod tests { assert_eq!(ok, vec![payable_ok]); assert_eq!(err, vec![error]) } - - // TODO: Either make this test work or write an alternative test in the desired file - // #[test] - // fn threshold_calculation_depends_on_user_defined_payment_thresholds() { - // let safe_age_params_arc = Arc::new(Mutex::new(vec![])); - // let safe_balance_params_arc = Arc::new(Mutex::new(vec![])); - // let calculate_payable_threshold_params_arc = Arc::new(Mutex::new(vec![])); - // let balance = 5555; - // let how_far_in_past = Duration::from_secs(1111 + 1); - // let last_paid_timestamp = SystemTime::now().sub(how_far_in_past); - // let payable_account = PayableAccount { - // wallet: make_wallet("hi"), - // balance, - // last_paid_timestamp, - // pending_payable_opt: None, - // }; - // let custom_payment_thresholds = PaymentThresholds { - // maturity_threshold_sec: 1111, - // payment_grace_period_sec: 2222, - // permanent_debt_allowed_gwei: 3333, - // debt_threshold_gwei: 4444, - // threshold_interval_sec: 5555, - // unban_below_gwei: 3333, - // }; - // let mut bootstrapper_config = BootstrapperConfig::default(); - // bootstrapper_config.accountant_config_opt = Some(AccountantConfig { - // scan_intervals: Default::default(), - // payment_thresholds: custom_payment_thresholds, - // suppress_initial_scans: false, - // when_pending_too_long_sec: DEFAULT_PENDING_TOO_LONG_SEC, - // }); - // let payable_thresholds_tools = PayableThresholdToolsMock::default() - // .is_innocent_age_params(&safe_age_params_arc) - // .is_innocent_age_result( - // how_far_in_past.as_secs() - // <= custom_payment_thresholds.maturity_threshold_sec as u64, - // ) - // .is_innocent_balance_params(&safe_balance_params_arc) - // .is_innocent_balance_result( - // balance <= custom_payment_thresholds.permanent_debt_allowed_gwei, - // ) - // .calculate_payout_threshold_params(&calculate_payable_threshold_params_arc) - // .calculate_payout_threshold_result(4567.0); //made up value - // let mut subject = AccountantBuilder::default() - // .bootstrapper_config(bootstrapper_config) - // .build(); - // subject.scanners.payables.payable_thresholds_tools = Box::new(payable_thresholds_tools); - // - // let result = subject.payable_exceeded_threshold(&payable_account); - // - // assert_eq!(result, Some(4567)); - // let mut safe_age_params = safe_age_params_arc.lock().unwrap(); - // let safe_age_single_params = safe_age_params.remove(0); - // assert_eq!(*safe_age_params, vec![]); - // let (time_elapsed, curve_derived_time) = safe_age_single_params; - // assert!( - // (how_far_in_past.as_secs() - 3) < time_elapsed - // && time_elapsed < (how_far_in_past.as_secs() + 3) - // ); - // assert_eq!( - // curve_derived_time, - // custom_payment_thresholds.maturity_threshold_sec as u64 - // ); - // let safe_balance_params = safe_balance_params_arc.lock().unwrap(); - // assert_eq!( - // *safe_balance_params, - // vec![( - // payable_account.balance, - // custom_payment_thresholds.permanent_debt_allowed_gwei - // )] - // ); - // let mut calculate_payable_curves_params = - // calculate_payable_threshold_params_arc.lock().unwrap(); - // let calculate_payable_curves_single_params = calculate_payable_curves_params.remove(0); - // assert_eq!(*calculate_payable_curves_params, vec![]); - // let (payment_thresholds, time_elapsed) = calculate_payable_curves_single_params; - // assert!( - // (how_far_in_past.as_secs() - 3) < time_elapsed - // && time_elapsed < (how_far_in_past.as_secs() + 3) - // ); - // assert_eq!(payment_thresholds, custom_payment_thresholds) - // } } From 66038885686738c7b3b9c8028be48a89ec11ff3d Mon Sep 17 00:00:00 2001 From: utkarshg6 Date: Tue, 4 Oct 2022 13:54:01 +0530 Subject: [PATCH 5/7] GH-611: remove redundant code --- node/src/lib.rs | 1 - node/src/sub_lib/accountant.rs | 9 --------- node/src/test_utils/recorder.rs | 2 +- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/node/src/lib.rs b/node/src/lib.rs index 4850ed25c..c7d99ce81 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -6,7 +6,6 @@ pub mod sub_lib; #[macro_use] extern crate masq_lib; -extern crate core; #[cfg(test)] mod node_test_utils; diff --git a/node/src/sub_lib/accountant.rs b/node/src/sub_lib/accountant.rs index de12fee70..30734bb94 100644 --- a/node/src/sub_lib/accountant.rs +++ b/node/src/sub_lib/accountant.rs @@ -70,15 +70,6 @@ pub struct ScanIntervals { pub receivable_scan_interval: Duration, } -// TODO: Remove it once you realise you don't want to know which fields was accountant config composed of -// #[derive(Clone, PartialEq, Debug)] -// pub struct AccountantConfig { -// pub scan_intervals: ScanIntervals, -// pub payment_thresholds: PaymentThresholds, -// pub suppress_initial_scans: bool, -// pub when_pending_too_long_sec: u64, -// } - #[derive(Clone)] pub struct AccountantSubs { pub bind: Recipient, diff --git a/node/src/test_utils/recorder.rs b/node/src/test_utils/recorder.rs index 01d2311f9..0091ef7f4 100644 --- a/node/src/test_utils/recorder.rs +++ b/node/src/test_utils/recorder.rs @@ -112,7 +112,6 @@ recorder_message_handler!(AddReturnRouteMessage); recorder_message_handler!(AddRouteMessage); recorder_message_handler!(AddStreamMsg); recorder_message_handler!(BindMessage); -recorder_message_handler!(ConnectionProgressMessage); recorder_message_handler!(CrashNotification); recorder_message_handler!(DaemonBindMessage); recorder_message_handler!(DispatcherNodeQueryMessage); @@ -156,6 +155,7 @@ recorder_message_handler!(ReportTransactionReceipts); recorder_message_handler!(ReportAccountsPayable); recorder_message_handler!(ScanForReceivables); recorder_message_handler!(ScanForPayables); +recorder_message_handler!(ConnectionProgressMessage); recorder_message_handler!(ScanForPendingPayables); impl Handler for Recorder { From 4da98727f985073d046565533184c2b33776ec92 Mon Sep 17 00:00:00 2001 From: utkarshg6 Date: Tue, 4 Oct 2022 14:01:17 +0530 Subject: [PATCH 6/7] GH-611: reorder ReportTransactionReceipts --- node/src/accountant/mod.rs | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/node/src/accountant/mod.rs b/node/src/accountant/mod.rs index 491af4471..17de405ef 100644 --- a/node/src/accountant/mod.rs +++ b/node/src/accountant/mod.rs @@ -244,26 +244,6 @@ impl Handler for Accountant { } } -#[derive(Debug, PartialEq, Message, Clone)] -pub struct ReportTransactionReceipts { - pub fingerprints_with_receipts: Vec<(Option, PendingPayableFingerprint)>, - pub response_skeleton_opt: Option, -} - -impl Handler for Accountant { - type Result = (); - - fn handle(&mut self, msg: ReportTransactionReceipts, _ctx: &mut Self::Context) -> Self::Result { - if let Some(node_to_ui_msg) = self.scanners.pending_payable.finish_scan(msg, &self.logger) { - self.ui_message_sub - .as_ref() - .expect("UIGateway is not bound") - .try_send(node_to_ui_msg) - .expect("UIGateway is dead"); - } - } -} - impl Handler for Accountant { type Result = (); @@ -344,6 +324,26 @@ impl SkeletonOptHolder for RequestTransactionReceipts { } } +#[derive(Debug, PartialEq, Message, Clone)] +pub struct ReportTransactionReceipts { + pub fingerprints_with_receipts: Vec<(Option, PendingPayableFingerprint)>, + pub response_skeleton_opt: Option, +} + +impl Handler for Accountant { + type Result = (); + + fn handle(&mut self, msg: ReportTransactionReceipts, _ctx: &mut Self::Context) -> Self::Result { + if let Some(node_to_ui_msg) = self.scanners.pending_payable.finish_scan(msg, &self.logger) { + self.ui_message_sub + .as_ref() + .expect("UIGateway is not bound") + .try_send(node_to_ui_msg) + .expect("UIGateway is dead"); + } + } +} + impl Handler for Accountant { type Result = (); fn handle(&mut self, msg: PendingPayableFingerprint, _ctx: &mut Self::Context) -> Self::Result { From a464684672842e76e9c8caf29b7fa3ad24fc3878 Mon Sep 17 00:00:00 2001 From: utkarshg6 Date: Tue, 4 Oct 2022 14:05:13 +0530 Subject: [PATCH 7/7] GH-611: add Eq to the PendingTransactionStatus --- node/src/accountant/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/accountant/mod.rs b/node/src/accountant/mod.rs index 17de405ef..d76254ceb 100644 --- a/node/src/accountant/mod.rs +++ b/node/src/accountant/mod.rs @@ -796,7 +796,7 @@ pub fn unsigned_to_signed(unsigned: u64) -> Result { i64::try_from(unsigned).map_err(|_| unsigned) } -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone)] pub enum PendingTransactionStatus { StillPending(PendingPayableId), //updates slightly the record, waits an interval and starts a new round Failure(PendingPayableId), //official tx failure