Skip to content

Commit 2007ccd

Browse files
authored
GH-728: Finish the password-change logic (#355)
* GH-728: add the TODOs * GH-728: removed the code of the NewPasswordMessage * GH-728: use ConfigurationChangeMessage while changing password * GH-728: rename configuration_change_msg_sub_opt to update_min_hops_sub_opt * GH-728: rename new_password_subs to update_password_subs * GH-728: fix wrong name for the actor message * GH-728: send ConfigurationChangeMessage to other actors too * GH-728: add a TODO * GH-728: rename to _opt * GH-728: implement handler for ConfigurationChange::UpdatePassword inside Neighborhood * GH-728: add TODO to implement handler for ConfigurationChange::UpdatePassword inside BlockchainBridge * GH-728: add TODO to implement handler for ConfigurationChange::UpdatePassword inside Accountant * GH-728: create new struct for UpdatePasswordSubs * GH-728: add the new TODO * GH-728: send a ConfigurtionChangeMessage when the consuming wallet is generated * GH-728: add a test for the panic case * GH-728: some refactor changes in configurator.rs * GH-728: test drive the case when the wallet is recovered * GH-728: fix some of the tests * GH-728: fix the remaining 2 failing tests * GH-728: reorder fields * GH-728: the received ConfigurationChangeMessage is properly handled * GH-728: update the password when necessary * GH-728: add a todo * GH-728: add the ability to synchronise password * GH-728: add ability for accountant to handle an unexpected configuration change msg * GH-728: improve tests for handling ConfigurationChangeMessage in accountant * GH-728: minor renames * GH-728: remove finished TODO and formatting changes * GH-728: add test in blockchain bridge for ConfigurationChangeMessage * GH-728: add test in neighborhood for ConfigurationChangeMessage * GH-728: remove useless tests * GH-728: revive an old test * GH-728: improve todo * GH-728: test rename and add more TODOs * GH-728: cleanup and creation of new file configuration_change_subs.rs * GH-728: minor refactor and remove tests * GH-728: introduce trait for ConfigurationChangesubs * GH-728: refactor out the subs for UpdateWallets and UpdatePassword * GH-728: some renames * GH-728: add TODO and minor reordering * GH-728: make the test the_password_is_synchronised_among_other_actors_when_modified stronger * GH-728: add formatting changes * GH-728: make enum usage more explicit * GH-728: remove clippy warnings * GH-728: do some renames * GH-728: fix wrong rename and import * GH-728: use peer actors for generating config change subs * GH-728: recreate ConfigChangeSubs * GH-728: remove config_change_subs.rs * GH-728: test for ConfigChangeMsg in Accountant contain assertions * GH-728: test for ConfigChangeMsg in Neighborhood contain assertions * GH-728: test for ConfigChangeMsg in BlockchainBridge contain assertions * GH-728: small rename * GH-728: add context_id to fn * GH-728: refactor the fn to transform associated functions to methods * GH-728: minor fixes * GH-728: add wallet_opt as a new argument in the begin_scan fn * GH-728: remove the use of field consuming_wallet_opt from BlockchainBridge * GH-728: remove the field consuming_wallet_opt from BlockchainBridge * GH-728: don't send the ConfigChangeMsg to the BlockchainBridge * GH-728: use the earning wallet in Receivable Scanner's begin_scan * GH-728: don't save a reference of earning wallet inside Scanners * GH-728: store the earning wallet directly without an Rc * GH-728: fix the failing test * GH-728: formatting changes * GH-728: remove the earning wallet from ReceivableScannerBuilder * GH-728: check wallet in the begin_scan() for ScannerMock * GH-728: remove unnecessary TODO * GH-728: formatting changes * GH-728: fix the failing test * GH-728: remove unused import in blockchain_interaction_test.rs * GH-728: BlockchainBridge receives consuming_wallet instead of an Option<T> * GH-728: Check consuming wallet before sending a msg to BlockchainBridge * GH-728: remove Option<T> from the wallet_opt param in begin_scan fn * GH-728: remove commented out code * GH-728: modify AccountantBuilder to make it's field names contain opt * GH-728: improve test mocks * GH-728: introduce another URL for mumbai testnet * GH-728: change the message in trace log * GH-728: test drive the NoConsumingWallet Error * GH-728: reordering * GH-728: add better logging * GH-728: Review 2 changes * GH-728: Review 2 leftover changes * GH-728: add better assertions for logger
1 parent 40480d1 commit 2007ccd

File tree

15 files changed

+727
-561
lines changed

15 files changed

+727
-561
lines changed

multinode_integration_tests/tests/blockchain_interaction_test.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::path::PathBuf;
55
use std::time::{Duration, SystemTime};
66

77
use log::Level;
8-
use regex::escape;
98
use serde_derive::Serialize;
109

1110
use masq_lib::messages::{FromMessageBody, ScanType, ToMessageBody, UiScanRequest, UiScanResponse};
@@ -157,19 +156,15 @@ fn blockchain_bridge_starts_properly_on_bootstrap() {
157156
let mut cluster = MASQNodeCluster::start().unwrap();
158157
let private_key = "0011223300112233001122330011223300112233001122330011223300112233";
159158
let subject = cluster.start_real_node(
160-
NodeStartupConfigBuilder::zero_hop()
159+
NodeStartupConfigBuilder::standard()
161160
.consuming_wallet_info(ConsumingWalletInfo::PrivateKey(private_key.to_string()))
162161
.chain(cluster.chain)
163162
.build(),
164163
);
165164

166-
let escaped_pattern = escape(&format!(
167-
"DEBUG: BlockchainBridge: Received BindMessage; consuming wallet address {}",
168-
subject.consuming_wallet().unwrap()
169-
));
170165
MASQNodeUtils::wrote_log_containing(
171166
subject.name(),
172-
&escaped_pattern,
167+
"DEBUG: BlockchainBridge: Received BindMessage",
173168
Duration::from_millis(1000),
174169
)
175170
}

node/src/accountant/mod.rs

Lines changed: 267 additions & 28 deletions
Large diffs are not rendered by default.

node/src/accountant/scanners/mid_scan_msg_handling/payable_scanner/msgs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
use crate::accountant::scanners::mid_scan_msg_handling::payable_scanner::blockchain_agent::BlockchainAgent;
44
use crate::accountant::{ResponseSkeleton, SkeletonOptHolder};
5+
use crate::sub_lib::wallet::Wallet;
56
use actix::Message;
67
use masq_lib::type_obfuscation::Obfuscated;
78
use std::fmt::Debug;
89

910
#[derive(Debug, Message, PartialEq, Eq, Clone)]
1011
pub struct QualifiedPayablesMessage {
1112
pub protected_qualified_payables: Obfuscated,
13+
pub consuming_wallet: Wallet,
1214
pub response_skeleton_opt: Option<ResponseSkeleton>,
1315
}
1416

1517
impl QualifiedPayablesMessage {
1618
pub(in crate::accountant) fn new(
1719
protected_qualified_payables: Obfuscated,
20+
consuming_wallet: Wallet,
1821
response_skeleton_opt: Option<ResponseSkeleton>,
1922
) -> Self {
2023
Self {
2124
protected_qualified_payables,
25+
consuming_wallet,
2226
response_skeleton_opt,
2327
}
2428
}

node/src/accountant/scanners/mod.rs

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ impl Scanners {
6868
pub fn new(
6969
dao_factories: DaoFactories,
7070
payment_thresholds: Rc<PaymentThresholds>,
71-
earning_wallet: Rc<Wallet>,
7271
when_pending_too_long_sec: u64,
7372
financial_statistics: Rc<RefCell<FinancialStatistics>>,
7473
) -> Self {
@@ -94,7 +93,6 @@ impl Scanners {
9493
dao_factories.banned_dao_factory.make(),
9594
Box::new(persistent_configuration),
9695
Rc::clone(&payment_thresholds),
97-
earning_wallet,
9896
financial_statistics,
9997
));
10098

@@ -113,6 +111,7 @@ where
113111
{
114112
fn begin_scan(
115113
&mut self,
114+
wallet: Wallet,
116115
timestamp: SystemTime,
117116
response_skeleton_opt: Option<ResponseSkeleton>,
118117
logger: &Logger,
@@ -193,6 +192,7 @@ pub struct PayableScanner {
193192
impl Scanner<QualifiedPayablesMessage, SentPayables> for PayableScanner {
194193
fn begin_scan(
195194
&mut self,
195+
consuming_wallet: Wallet,
196196
timestamp: SystemTime,
197197
response_skeleton_opt: Option<ResponseSkeleton>,
198198
logger: &Logger,
@@ -225,8 +225,11 @@ impl Scanner<QualifiedPayablesMessage, SentPayables> for PayableScanner {
225225
qualified_payables.len()
226226
);
227227
let protected_payables = self.protect_payables(qualified_payables);
228-
let outgoing_msg =
229-
QualifiedPayablesMessage::new(protected_payables, response_skeleton_opt);
228+
let outgoing_msg = QualifiedPayablesMessage::new(
229+
protected_payables,
230+
consuming_wallet,
231+
response_skeleton_opt,
232+
);
230233
Ok(outgoing_msg)
231234
}
232235
}
@@ -567,6 +570,7 @@ pub struct PendingPayableScanner {
567570
impl Scanner<RequestTransactionReceipts, ReportTransactionReceipts> for PendingPayableScanner {
568571
fn begin_scan(
569572
&mut self,
573+
_irrelevant_wallet: Wallet,
570574
timestamp: SystemTime,
571575
response_skeleton_opt: Option<ResponseSkeleton>,
572576
logger: &Logger,
@@ -825,13 +829,13 @@ pub struct ReceivableScanner {
825829
pub receivable_dao: Box<dyn ReceivableDao>,
826830
pub banned_dao: Box<dyn BannedDao>,
827831
pub persistent_configuration: Box<dyn PersistentConfiguration>,
828-
pub earning_wallet: Rc<Wallet>,
829832
pub financial_statistics: Rc<RefCell<FinancialStatistics>>,
830833
}
831834

832835
impl Scanner<RetrieveTransactions, ReceivedPayments> for ReceivableScanner {
833836
fn begin_scan(
834837
&mut self,
838+
earning_wallet: Wallet,
835839
timestamp: SystemTime,
836840
response_skeleton_opt: Option<ResponseSkeleton>,
837841
logger: &Logger,
@@ -840,14 +844,11 @@ impl Scanner<RetrieveTransactions, ReceivedPayments> for ReceivableScanner {
840844
return Err(BeginScanError::ScanAlreadyRunning(timestamp));
841845
}
842846
self.mark_as_started(timestamp);
843-
info!(
844-
logger,
845-
"Scanning for receivables to {}", self.earning_wallet
846-
);
847+
info!(logger, "Scanning for receivables to {}", earning_wallet);
847848
self.scan_for_delinquencies(timestamp, logger);
848849

849850
Ok(RetrieveTransactions {
850-
recipient: self.earning_wallet.as_ref().clone(),
851+
recipient: earning_wallet,
851852
response_skeleton_opt,
852853
})
853854
}
@@ -893,12 +894,10 @@ impl ReceivableScanner {
893894
banned_dao: Box<dyn BannedDao>,
894895
persistent_configuration: Box<dyn PersistentConfiguration>,
895896
payment_thresholds: Rc<PaymentThresholds>,
896-
earning_wallet: Rc<Wallet>,
897897
financial_statistics: Rc<RefCell<FinancialStatistics>>,
898898
) -> Self {
899899
Self {
900900
common: ScannerCommon::new(payment_thresholds),
901-
earning_wallet,
902901
receivable_dao,
903902
banned_dao,
904903
persistent_configuration,
@@ -985,6 +984,7 @@ impl ReceivableScanner {
985984
#[derive(Debug, PartialEq, Eq)]
986985
pub enum BeginScanError {
987986
NothingToProcess,
987+
NoConsumingWalletFound,
988988
ScanAlreadyRunning(SystemTime),
989989
CalledFromNullScanner, // Exclusive for tests
990990
}
@@ -1007,6 +1007,10 @@ impl BeginScanError {
10071007
scan_type,
10081008
BeginScanError::timestamp_as_string(timestamp)
10091009
)),
1010+
BeginScanError::NoConsumingWalletFound => Some(format!(
1011+
"Cannot initiate {:?} scan because no consuming wallet was found.",
1012+
scan_type
1013+
)),
10101014
BeginScanError::CalledFromNullScanner => match cfg!(test) {
10111015
true => None,
10121016
false => panic!("Null Scanner shouldn't be running inside production code."),
@@ -1134,9 +1138,9 @@ mod tests {
11341138
DaoFactories, FinancialStatistics, PaymentThresholds, ScanIntervals,
11351139
DEFAULT_PAYMENT_THRESHOLDS,
11361140
};
1137-
use crate::test_utils::make_wallet;
11381141
use crate::test_utils::persistent_configuration_mock::PersistentConfigurationMock;
11391142
use crate::test_utils::unshared_test_utils::arbitrary_id_stamp::ArbitraryIdStamp;
1143+
use crate::test_utils::{make_paying_wallet, make_wallet};
11401144
use actix::{Message, System};
11411145
use ethereum_types::U64;
11421146
use masq_lib::logger::Logger;
@@ -1175,7 +1179,6 @@ mod tests {
11751179
total_paid_payable_wei: 1,
11761180
total_paid_receivable_wei: 2,
11771181
};
1178-
let earning_wallet = make_wallet("unique_wallet");
11791182
let payment_thresholds = make_custom_payment_thresholds();
11801183
let payment_thresholds_rc = Rc::new(payment_thresholds);
11811184
let initial_rc_count = Rc::strong_count(&payment_thresholds_rc);
@@ -1189,7 +1192,6 @@ mod tests {
11891192
config_dao_factory: Box::new(config_dao_factory),
11901193
},
11911194
Rc::clone(&payment_thresholds_rc),
1192-
Rc::new(earning_wallet.clone()),
11931195
when_pending_too_long_sec,
11941196
Rc::new(RefCell::new(financial_statistics.clone())),
11951197
);
@@ -1234,10 +1236,6 @@ mod tests {
12341236
*receivable_scanner.financial_statistics.borrow(),
12351237
financial_statistics
12361238
);
1237-
assert_eq!(
1238-
receivable_scanner.earning_wallet.address(),
1239-
earning_wallet.address()
1240-
);
12411239
assert_eq!(
12421240
receivable_scanner.common.payment_thresholds.as_ref(),
12431241
&payment_thresholds
@@ -1274,6 +1272,7 @@ mod tests {
12741272
fn payable_scanner_can_initiate_a_scan() {
12751273
init_test_logging();
12761274
let test_name = "payable_scanner_can_initiate_a_scan";
1275+
let consuming_wallet = make_paying_wallet(b"consuming wallet");
12771276
let now = SystemTime::now();
12781277
let (qualified_payable_accounts, _, all_non_pending_payables) =
12791278
make_payables(now, &PaymentThresholds::default());
@@ -1283,7 +1282,8 @@ mod tests {
12831282
.payable_dao(payable_dao)
12841283
.build();
12851284

1286-
let result = subject.begin_scan(now, None, &Logger::new(test_name));
1285+
let result =
1286+
subject.begin_scan(consuming_wallet.clone(), now, None, &Logger::new(test_name));
12871287

12881288
let timestamp = subject.scan_started_at();
12891289
assert_eq!(timestamp, Some(now));
@@ -1293,6 +1293,7 @@ mod tests {
12931293
protected_qualified_payables: protect_payables_in_test(
12941294
qualified_payable_accounts.clone()
12951295
),
1296+
consuming_wallet,
12961297
response_skeleton_opt: None,
12971298
})
12981299
);
@@ -1307,16 +1308,22 @@ mod tests {
13071308

13081309
#[test]
13091310
fn payable_scanner_throws_error_when_a_scan_is_already_running() {
1311+
let consuming_wallet = make_paying_wallet(b"consuming wallet");
13101312
let now = SystemTime::now();
13111313
let (_, _, all_non_pending_payables) = make_payables(now, &PaymentThresholds::default());
13121314
let payable_dao =
13131315
PayableDaoMock::new().non_pending_payables_result(all_non_pending_payables);
13141316
let mut subject = PayableScannerBuilder::new()
13151317
.payable_dao(payable_dao)
13161318
.build();
1317-
let _result = subject.begin_scan(now, None, &Logger::new("test"));
1319+
let _result = subject.begin_scan(consuming_wallet.clone(), now, None, &Logger::new("test"));
13181320

1319-
let run_again_result = subject.begin_scan(SystemTime::now(), None, &Logger::new("test"));
1321+
let run_again_result = subject.begin_scan(
1322+
consuming_wallet,
1323+
SystemTime::now(),
1324+
None,
1325+
&Logger::new("test"),
1326+
);
13201327

13211328
let is_scan_running = subject.scan_started_at().is_some();
13221329
assert_eq!(is_scan_running, true);
@@ -1328,6 +1335,7 @@ mod tests {
13281335

13291336
#[test]
13301337
fn payable_scanner_throws_error_in_case_no_qualified_payable_is_found() {
1338+
let consuming_wallet = make_paying_wallet(b"consuming wallet");
13311339
let now = SystemTime::now();
13321340
let (_, unqualified_payable_accounts, _) =
13331341
make_payables(now, &PaymentThresholds::default());
@@ -1337,7 +1345,7 @@ mod tests {
13371345
.payable_dao(payable_dao)
13381346
.build();
13391347

1340-
let result = subject.begin_scan(now, None, &Logger::new("test"));
1348+
let result = subject.begin_scan(consuming_wallet, now, None, &Logger::new("test"));
13411349

13421350
let is_scan_running = subject.scan_started_at().is_some();
13431351
assert_eq!(is_scan_running, false);
@@ -2210,6 +2218,7 @@ mod tests {
22102218
fn pending_payable_scanner_can_initiate_a_scan() {
22112219
init_test_logging();
22122220
let test_name = "pending_payable_scanner_can_initiate_a_scan";
2221+
let consuming_wallet = make_paying_wallet(b"consuming wallet");
22132222
let now = SystemTime::now();
22142223
let payable_fingerprint_1 = PendingPayableFingerprint {
22152224
rowid: 555,
@@ -2234,7 +2243,12 @@ mod tests {
22342243
.pending_payable_dao(pending_payable_dao)
22352244
.build();
22362245

2237-
let result = pending_payable_scanner.begin_scan(now, None, &Logger::new(test_name));
2246+
let result = pending_payable_scanner.begin_scan(
2247+
consuming_wallet,
2248+
now,
2249+
None,
2250+
&Logger::new(test_name),
2251+
);
22382252

22392253
let no_of_pending_payables = fingerprints.len();
22402254
let is_scan_running = pending_payable_scanner.scan_started_at().is_some();
@@ -2257,6 +2271,7 @@ mod tests {
22572271
#[test]
22582272
fn pending_payable_scanner_throws_error_in_case_scan_is_already_running() {
22592273
let now = SystemTime::now();
2274+
let consuming_wallet = make_paying_wallet(b"consuming");
22602275
let pending_payable_dao = PendingPayableDaoMock::new()
22612276
.return_all_errorless_fingerprints_result(vec![PendingPayableFingerprint {
22622277
rowid: 1234,
@@ -2270,9 +2285,9 @@ mod tests {
22702285
.pending_payable_dao(pending_payable_dao)
22712286
.build();
22722287
let logger = Logger::new("test");
2273-
let _ = subject.begin_scan(now, None, &logger);
2288+
let _ = subject.begin_scan(consuming_wallet.clone(), now, None, &logger);
22742289

2275-
let result = subject.begin_scan(SystemTime::now(), None, &logger);
2290+
let result = subject.begin_scan(consuming_wallet, SystemTime::now(), None, &logger);
22762291

22772292
let is_scan_running = subject.scan_started_at().is_some();
22782293
assert_eq!(is_scan_running, true);
@@ -2282,13 +2297,15 @@ mod tests {
22822297
#[test]
22832298
fn pending_payable_scanner_throws_an_error_when_no_fingerprint_is_found() {
22842299
let now = SystemTime::now();
2300+
let consuming_wallet = make_paying_wallet(b"consuming_wallet");
22852301
let pending_payable_dao =
22862302
PendingPayableDaoMock::new().return_all_errorless_fingerprints_result(vec![]);
22872303
let mut pending_payable_scanner = PendingPayableScannerBuilder::new()
22882304
.pending_payable_dao(pending_payable_dao)
22892305
.build();
22902306

2291-
let result = pending_payable_scanner.begin_scan(now, None, &Logger::new("test"));
2307+
let result =
2308+
pending_payable_scanner.begin_scan(consuming_wallet, now, None, &Logger::new("test"));
22922309

22932310
let is_scan_running = pending_payable_scanner.scan_started_at().is_some();
22942311
assert_eq!(result, Err(BeginScanError::NothingToProcess));
@@ -2924,10 +2941,14 @@ mod tests {
29242941
let earning_wallet = make_wallet("earning");
29252942
let mut receivable_scanner = ReceivableScannerBuilder::new()
29262943
.receivable_dao(receivable_dao)
2927-
.earning_wallet(earning_wallet.clone())
29282944
.build();
29292945

2930-
let result = receivable_scanner.begin_scan(now, None, &Logger::new(test_name));
2946+
let result = receivable_scanner.begin_scan(
2947+
earning_wallet.clone(),
2948+
now,
2949+
None,
2950+
&Logger::new(test_name),
2951+
);
29312952

29322953
let is_scan_running = receivable_scanner.scan_started_at().is_some();
29332954
assert_eq!(is_scan_running, true);
@@ -2952,11 +2973,16 @@ mod tests {
29522973
let earning_wallet = make_wallet("earning");
29532974
let mut receivable_scanner = ReceivableScannerBuilder::new()
29542975
.receivable_dao(receivable_dao)
2955-
.earning_wallet(earning_wallet)
29562976
.build();
2957-
let _ = receivable_scanner.begin_scan(now, None, &Logger::new("test"));
2977+
let _ =
2978+
receivable_scanner.begin_scan(earning_wallet.clone(), now, None, &Logger::new("test"));
29582979

2959-
let result = receivable_scanner.begin_scan(SystemTime::now(), None, &Logger::new("test"));
2980+
let result = receivable_scanner.begin_scan(
2981+
earning_wallet,
2982+
SystemTime::now(),
2983+
None,
2984+
&Logger::new("test"),
2985+
);
29602986

29612987
let is_scan_running = receivable_scanner.scan_started_at().is_some();
29622988
assert_eq!(is_scan_running, true);
@@ -2989,12 +3015,11 @@ mod tests {
29893015
.receivable_dao(receivable_dao)
29903016
.banned_dao(banned_dao)
29913017
.payment_thresholds(payment_thresholds)
2992-
.earning_wallet(earning_wallet.clone())
29933018
.build();
29943019
let logger = Logger::new("DELINQUENCY_TEST");
29953020
let now = SystemTime::now();
29963021

2997-
let result = receivable_scanner.begin_scan(now, None, &logger);
3022+
let result = receivable_scanner.begin_scan(earning_wallet.clone(), now, None, &logger);
29983023

29993024
assert_eq!(
30003025
result,

0 commit comments

Comments
 (0)