Skip to content
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-728: Finish the password-change logic #355

Merged
merged 95 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
d2c5b77
GH-728: add the TODOs
utkarshg6 Oct 11, 2023
aec029f
GH-728: removed the code of the NewPasswordMessage
utkarshg6 Oct 23, 2023
a39a0c8
GH-728: use ConfigurationChangeMessage while changing password
utkarshg6 Oct 23, 2023
4ced510
Merge branch 'master' into GH-728
utkarshg6 Oct 23, 2023
b376e92
GH-728: rename configuration_change_msg_sub_opt to update_min_hops_su…
utkarshg6 Oct 24, 2023
b55577a
GH-728: rename new_password_subs to update_password_subs
utkarshg6 Oct 24, 2023
79b6b9a
GH-728: fix wrong name for the actor message
utkarshg6 Oct 24, 2023
8204b01
GH-728: send ConfigurationChangeMessage to other actors too
utkarshg6 Oct 25, 2023
5aa8f0c
GH-728: add a TODO
utkarshg6 Oct 30, 2023
87dcf89
GH-728: rename to _opt
utkarshg6 Oct 30, 2023
507b130
GH-728: implement handler for ConfigurationChange::UpdatePassword ins…
utkarshg6 Oct 30, 2023
4d07e27
Merge branch 'master' into GH-728
utkarshg6 Nov 2, 2023
04533e4
GH-728: add TODO to implement handler for ConfigurationChange::Update…
utkarshg6 Nov 2, 2023
d59409d
GH-728: add TODO to implement handler for ConfigurationChange::Update…
utkarshg6 Nov 2, 2023
c2d0cad
GH-728: create new struct for UpdatePasswordSubs
utkarshg6 Nov 2, 2023
6a8086e
GH-728: add the new TODO
utkarshg6 Jan 23, 2024
3ec34fe
GH-728: send a ConfigurtionChangeMessage when the consuming wallet is…
utkarshg6 Jan 23, 2024
e8edd34
GH-728: add a test for the panic case
utkarshg6 Jan 23, 2024
bfcafdb
GH-728: some refactor changes in configurator.rs
utkarshg6 Jan 23, 2024
2fedf65
GH-728: test drive the case when the wallet is recovered
utkarshg6 Jan 23, 2024
90385a5
GH-728: fix some of the tests
utkarshg6 Jan 25, 2024
2bed071
GH-728: fix the remaining 2 failing tests
utkarshg6 Jan 26, 2024
aef323a
GH-728: reorder fields
utkarshg6 Jan 26, 2024
06aea8e
GH-728: the received ConfigurationChangeMessage is properly handled
utkarshg6 Feb 6, 2024
595a806
Merge branch 'master' into GH-728
utkarshg6 Feb 6, 2024
5f50515
GH-728: update the password when necessary
utkarshg6 Feb 6, 2024
1912a1b
GH-728: add a todo
utkarshg6 Feb 6, 2024
6cab5ef
GH-728: add the ability to synchronise password
utkarshg6 Feb 7, 2024
6ecfe83
GH-728: add ability for accountant to handle an unexpected configurat…
utkarshg6 Feb 8, 2024
f74fb14
GH-728: improve tests for handling ConfigurationChangeMessage in acco…
utkarshg6 Feb 8, 2024
6dd6e72
GH-728: minor renames
utkarshg6 Feb 8, 2024
4b9f138
GH-728: remove finished TODO and formatting changes
utkarshg6 Feb 9, 2024
3de454f
GH-728: add test in blockchain bridge for ConfigurationChangeMessage
utkarshg6 Feb 9, 2024
33b23c5
GH-728: add test in neighborhood for ConfigurationChangeMessage
utkarshg6 Feb 9, 2024
2595ae8
GH-728: remove useless tests
utkarshg6 Feb 9, 2024
a4e0e7a
Merge branch 'master' of https://github.com/MASQ-Project/Node into GH…
utkarshg6 Feb 9, 2024
0f85fe2
GH-728: revive an old test
utkarshg6 Feb 12, 2024
416a14c
GH-728: improve todo
utkarshg6 Feb 12, 2024
42adcff
GH-728: test rename and add more TODOs
utkarshg6 Feb 12, 2024
20f8354
GH-728: cleanup and creation of new file configuration_change_subs.rs
utkarshg6 Feb 12, 2024
c27cc6d
GH-728: minor refactor and remove tests
utkarshg6 Feb 12, 2024
30f3dc6
GH-728: introduce trait for ConfigurationChangesubs
utkarshg6 Feb 12, 2024
7b28dd9
GH-728: refactor out the subs for UpdateWallets and UpdatePassword
utkarshg6 Feb 13, 2024
0d3f0b8
GH-728: some renames
utkarshg6 Feb 13, 2024
9729001
GH-728: add TODO and minor reordering
utkarshg6 Feb 13, 2024
ba7b868
GH-728: make the test the_password_is_synchronised_among_other_actors…
utkarshg6 Feb 13, 2024
15a0317
GH-728: add formatting changes
utkarshg6 Feb 13, 2024
85da70b
GH-728: make enum usage more explicit
utkarshg6 Feb 13, 2024
818f535
GH-728: remove clippy warnings
utkarshg6 Feb 13, 2024
0647933
GH-728: do some renames
utkarshg6 Feb 14, 2024
6a1b5e0
GH-728: fix wrong rename and import
utkarshg6 Feb 14, 2024
e92730a
GH-728: use peer actors for generating config change subs
utkarshg6 Feb 27, 2024
acf39f2
GH-728: recreate ConfigChangeSubs
utkarshg6 Feb 28, 2024
885d528
GH-728: remove config_change_subs.rs
utkarshg6 Feb 28, 2024
4b71c31
GH-728: test for ConfigChangeMsg in Accountant contain assertions
utkarshg6 Feb 28, 2024
c3a34e1
GH-728: test for ConfigChangeMsg in Neighborhood contain assertions
utkarshg6 Feb 28, 2024
83add77
GH-728: test for ConfigChangeMsg in BlockchainBridge contain assertions
utkarshg6 Feb 28, 2024
1b71118
GH-728: small rename
utkarshg6 Mar 4, 2024
4aea52a
GH-728: add context_id to fn
utkarshg6 Mar 4, 2024
8507172
GH-728: refactor the fn to transform associated functions to methods
utkarshg6 Mar 4, 2024
8ce0429
GH-728: minor fixes
utkarshg6 Mar 4, 2024
e956d9f
GH-728: add wallet_opt as a new argument in the begin_scan fn
utkarshg6 Mar 5, 2024
ae6984e
GH-728: remove the use of field consuming_wallet_opt from BlockchainB…
utkarshg6 Mar 5, 2024
0eeb7b1
GH-728: remove the field consuming_wallet_opt from BlockchainBridge
utkarshg6 Mar 5, 2024
0b67ba2
GH-728: don't send the ConfigChangeMsg to the BlockchainBridge
utkarshg6 Mar 5, 2024
4d8e37e
GH-728: use the earning wallet in Receivable Scanner's begin_scan
utkarshg6 Mar 5, 2024
07457e7
GH-728: don't save a reference of earning wallet inside Scanners
utkarshg6 Mar 5, 2024
d99142e
GH-728: store the earning wallet directly without an Rc
utkarshg6 Mar 5, 2024
a8a4d04
GH-728: fix the failing test
utkarshg6 Mar 6, 2024
5d381e4
GH-728: formatting changes
utkarshg6 Mar 6, 2024
f778208
GH-728: remove the earning wallet from ReceivableScannerBuilder
utkarshg6 Mar 7, 2024
962ec0a
GH-728: check wallet in the begin_scan() for ScannerMock
utkarshg6 Mar 7, 2024
778d615
GH-728: remove unnecessary TODO
utkarshg6 Mar 7, 2024
b7243e5
GH-728: formatting changes
utkarshg6 Mar 7, 2024
bd9ea99
GH-728: fix the failing test
utkarshg6 Mar 7, 2024
8224cc0
Merge branch 'master' into GH-728
utkarshg6 Mar 13, 2024
8df5537
GH-728: remove unused import in blockchain_interaction_test.rs
utkarshg6 Mar 14, 2024
90dc6fa
GH-728: BlockchainBridge receives consuming_wallet instead of an Opti…
utkarshg6 Mar 15, 2024
7211a8f
GH-728: Check consuming wallet before sending a msg to BlockchainBridge
utkarshg6 Mar 15, 2024
be55fa7
GH-728: remove Option<T> from the wallet_opt param in begin_scan fn
utkarshg6 Mar 15, 2024
c14d9b4
GH-728: remove commented out code
utkarshg6 Mar 15, 2024
dec9c3f
GH-728: modify AccountantBuilder to make it's field names contain opt
utkarshg6 Mar 18, 2024
2a78da9
GH-728: improve test mocks
utkarshg6 Mar 18, 2024
3d8b011
GH-728: introduce another URL for mumbai testnet
utkarshg6 Mar 19, 2024
ca20828
GH-728: change the message in trace log
utkarshg6 Mar 19, 2024
30c4439
GH-728: test drive the NoConsumingWallet Error
utkarshg6 Mar 19, 2024
cd97bdf
GH-728: reordering
utkarshg6 Mar 19, 2024
f898def
GH-728: add better logging
utkarshg6 Mar 20, 2024
0ed2608
GH-728: Review 2 changes
utkarshg6 Mar 21, 2024
8af33c6
GH-728: Review 2 leftover changes
utkarshg6 Mar 21, 2024
37c3b79
GH-728: add better assertions for logger
utkarshg6 Mar 22, 2024
b13c22d
Merge branch 'master' into GH-728
utkarshg6 Apr 2, 2024
92c0bcc
Merge branch 'master' into GH-728
utkarshg6 May 4, 2024
8a75ff4
Merge branch 'master' into GH-728
utkarshg6 May 29, 2024
c567c12
Merge branch 'master' into GH-728
utkarshg6 May 29, 2024
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
Prev Previous commit
Next Next commit
GH-728: use peer actors for generating config change subs
  • Loading branch information
utkarshg6 committed Feb 27, 2024
commit e92730acb7f99a3ff267679cdfe8bc44f244c198
116 changes: 56 additions & 60 deletions node/src/node_configurator/configurator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ pub const CRASH_KEY: &str = "CONFIGURATOR";
pub struct Configurator {
persistent_config: Box<dyn PersistentConfiguration>,
node_to_ui_sub_opt: Option<Recipient<NodeToUiMessage>>,
update_min_hops_subs_opt: Option<Box<dyn ConfigChangeSubs>>,
update_password_subs_opt: Option<Box<dyn ConfigChangeSubs>>,
update_wallets_subs_opt: Option<Box<dyn ConfigChangeSubs>>,
config_change_subs_opt: Option<Vec<Recipient<ConfigChangeMsg>>>,
// all actors
// update_min_hops_subs_opt: Option<Box<dyn ConfigChangeSubs>>,
// update_password_subs_opt: Option<Box<dyn ConfigChangeSubs>>,
// update_wallets_subs_opt: Option<Box<dyn ConfigChangeSubs>>,
crashable: bool,
logger: Logger,
}
Expand All @@ -66,17 +68,7 @@ impl Handler<BindMessage> for Configurator {

fn handle(&mut self, msg: BindMessage, _ctx: &mut Self::Context) -> Self::Result {
self.node_to_ui_sub_opt = Some(msg.peer_actors.ui_gateway.node_to_ui_message_sub.clone());
self.update_min_hops_subs_opt = Some(Box::new(UpdateMinHopsSubs {
neighborhood: msg.peer_actors.neighborhood.config_change_msg_sub.clone(),
}));
self.update_password_subs_opt = Some(Box::new(UpdatePasswordSubs {
neighborhood: msg.peer_actors.neighborhood.config_change_msg_sub.clone(),
}));
self.update_wallets_subs_opt = Some(Box::new(UpdateWalletsSubs {
accountant: msg.peer_actors.accountant.config_change_msg_sub,
blockchain_bridge: msg.peer_actors.blockchain_bridge.config_change_msg_sub,
neighborhood: msg.peer_actors.neighborhood.config_change_msg_sub,
}));
self.config_change_subs_opt = Some(msg.peer_actors.config_change_subs());
}
}

Expand Down Expand Up @@ -124,9 +116,7 @@ impl Configurator {
Configurator {
persistent_config,
node_to_ui_sub_opt: None,
update_min_hops_subs_opt: None,
update_password_subs_opt: None,
update_wallets_subs_opt: None,
config_change_subs_opt: None,
crashable,
logger: Logger::new("Configurator"),
}
Expand Down Expand Up @@ -756,17 +746,18 @@ impl Configurator {
} else if "start-block" == &msg.name {
Self::set_start_block(msg.value, persistent_config)?;
} else if "min-hops" == &msg.name {
let update_min_hops_subs = self
.update_min_hops_subs_opt
.as_ref()
.expect("UpdateMinHopsSubs is not properly initialized")
.as_ref();
Self::set_min_hops(
msg.value,
persistent_config,
update_min_hops_subs,
&self.logger,
)?;
todo!("GH-728: Send it to all actors.");
// let update_min_hops_subs = self
// .update_min_hops_subs_opt
// .as_ref()
// .expect("UpdateMinHopsSubs is not properly initialized")
// .as_ref();
// Self::set_min_hops(
// msg.value,
// persistent_config,
// update_min_hops_subs,
// &self.logger,
// )?;
} else {
return Err((
UNRECOGNIZED_PARAMETER,
Expand Down Expand Up @@ -847,14 +838,24 @@ impl Configurator {
.expect("UiGateway is dead");
}

fn send_config_change_msg(&self, msg: ConfigChangeMsg)
{
self.config_change_subs_opt
.as_ref()
.expect("ConfigChangeSubs are uninitialized")
.iter()
.for_each(|recipient| {
recipient
.try_send(msg.clone())
.expect("ConfigChangeMsg recipient is dead")
})
}

fn send_new_password_to_subs(&self, new_password: String) {
let msg = ConfigChangeMsg {
change: ConfigChange::UpdatePassword(new_password),
};
self.update_password_subs_opt
.as_ref()
.expect("UpdatePasswordSubs is uninitialized")
.send_msg_to_subs(msg);
self.send_config_change_msg(msg);
}

fn send_updated_wallets_to_subs(&self, db_password: &str) {
Expand All @@ -866,16 +867,12 @@ impl Configurator {
if let (Ok(Some(new_consuming_wallet)), Ok(Some(new_earning_wallet))) =
(consuming_wallet_result_opt, earning_wallet_result_opt)
{
let msg = ConfigChangeMsg {
self.send_config_change_msg(ConfigChangeMsg {
change: ConfigChange::UpdateWallets(WalletPair {
consuming_wallet: new_consuming_wallet,
earning_wallet: new_earning_wallet,
}),
};
self.update_wallets_subs_opt
.as_ref()
.expect("Configuration is unbound")
.send_msg_to_subs(msg);
});
} else {
panic!("Unable to retrieve wallets from persistent configuration")
};
Expand Down Expand Up @@ -971,17 +968,11 @@ mod tests {
.initialize(&data_dir, DbInitializationConfig::test_default())
.unwrap(),
)));
let (recorder, _, _) = make_recorder();
let recorder_addr = recorder.start();
let (neighborhood, _, _) = make_recorder();
let neighborhood_sub = neighborhood.start().recipient();

let peer_actors = peer_actors_builder().build();
let mut subject = Configurator::new(data_dir, false);
subject.config_change_subs_opt = Some(peer_actors.config_change_subs());
subject.node_to_ui_sub_opt = Some(peer_actors.ui_gateway.node_to_ui_message_sub);

subject.node_to_ui_sub_opt = Some(recorder_addr.recipient());
subject.update_password_subs_opt = Some(Box::new(UpdatePasswordSubs {
neighborhood: neighborhood_sub,
}));
let _ = subject.handle_change_password(
UiChangePasswordRequest {
old_password_opt: None,
Expand All @@ -990,6 +981,7 @@ mod tests {
0,
0,
);

assert_eq!(
verifier.check_password(Some("password".to_string())),
Ok(true)
Expand Down Expand Up @@ -1162,6 +1154,7 @@ mod tests {
}

fn assert_wallets_synchronisation_among_other_actors(msg: NodeFromUiMessage) {
// TODO: GH-728 - Maybe remove this function and the corresponding test
let system = System::new("consuming_wallet_is_updated_when_new_wallet_is_generated");
utkarshg6 marked this conversation as resolved.
Show resolved Hide resolved
let consuming_wallet = make_paying_wallet(b"consuming");
let earning_wallet = make_wallet("earning");
Expand Down Expand Up @@ -1803,6 +1796,11 @@ mod tests {
}
}

fn make_config_change_subs() -> Vec<Recipient<ConfigChangeMsg>> {
let peer_actors = peer_actors_builder().build();
peer_actors.config_change_subs()
}

#[test]
fn handle_recover_wallets_works_with_earning_wallet_derivation_path() {
let set_wallet_info_params_arc = Arc::new(Mutex::new(vec![]));
Expand All @@ -1813,7 +1811,7 @@ mod tests {
.consuming_wallet_result(Ok(Some(make_paying_wallet(b"consuming"))))
.earning_wallet_result(Ok(Some(make_wallet("earning"))));
let mut subject = make_subject(Some(persistent_config));
subject.update_wallets_subs_opt = Some(Box::new(make_update_wallets_subs()));
subject.config_change_subs_opt = Some(make_config_change_subs());
let mut request = make_example_recover_wallets_request_with_paths();
request.earning_derivation_path_opt = Some(derivation_path(0, 5));

Expand Down Expand Up @@ -1869,7 +1867,7 @@ mod tests {
.consuming_wallet_result(Ok(Some(make_paying_wallet(b"consuming"))))
.earning_wallet_result(Ok(Some(make_wallet("earning"))));
let mut subject = make_subject(Some(persistent_config));
subject.update_wallets_subs_opt = Some(Box::new(make_update_wallets_subs()));
subject.config_change_subs_opt = Some(make_config_change_subs());
let mut request = make_example_recover_wallets_request_with_paths();
request
.seed_spec_opt
Expand Down Expand Up @@ -2331,12 +2329,12 @@ mod tests {
.set_min_hops_result(Ok(()));
let system = System::new("handle_set_configuration_works_for_min_hops");
let (neighborhood, _, neighborhood_recording_arc) = make_recorder();
let neighborhood_sub = neighborhood.start().recipient();
// let neighborhood_sub = neighborhood.start().recipient();
let mut subject = make_subject(Some(persistent_config));
subject.logger = Logger::new(test_name);
subject.update_min_hops_subs_opt = Some(Box::new(UpdateMinHopsSubs {
neighborhood: neighborhood_sub,
}));
// subject.update_min_hops_subs_opt = Some(Box::new(UpdateMinHopsSubs {
// neighborhood: neighborhood_sub,
// }));

let result = subject.handle_set_configuration(
UiSetConfigurationRequest {
Expand Down Expand Up @@ -2377,7 +2375,7 @@ mod tests {
init_test_logging();
let test_name = "handle_set_configuration_throws_err_for_invalid_min_hops";
let mut subject = make_subject(None);
subject.update_min_hops_subs_opt = Some(Box::new(ConfigChangeSubsNull));
// subject.update_min_hops_subs_opt = Some(Box::new(ConfigChangeSubsNull));
subject.logger = Logger::new(test_name);

let result = subject.handle_set_configuration(
Expand Down Expand Up @@ -2416,9 +2414,9 @@ mod tests {
let (neighborhood, _, neighborhood_recording_arc) = make_recorder();
let neighborhood_sub = neighborhood.start().recipient::<ConfigChangeMsg>();
let mut subject = make_subject(Some(persistent_config));
subject.update_min_hops_subs_opt = Some(Box::new(UpdateMinHopsSubs {
neighborhood: neighborhood_sub,
}));
// subject.update_min_hops_subs_opt = Some(Box::new(UpdateMinHopsSubs {
// neighborhood: neighborhood_sub,
// }));
subject.logger = Logger::new(test_name);

let result = subject.handle_set_configuration(
Expand Down Expand Up @@ -3014,9 +3012,7 @@ mod tests {
Configurator {
persistent_config,
node_to_ui_sub_opt: None,
update_min_hops_subs_opt: None,
update_password_subs_opt: None,
update_wallets_subs_opt: None,
config_change_subs_opt: None,
crashable: false,
logger: Logger::new("Configurator"),
}
Expand Down
14 changes: 12 additions & 2 deletions node/src/sub_lib/peer_actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crate::sub_lib::blockchain_bridge::BlockchainBridgeSubs;
use crate::sub_lib::configurator::ConfiguratorSubs;
use crate::sub_lib::dispatcher::DispatcherSubs;
use crate::sub_lib::hopper::HopperSubs;
use crate::sub_lib::neighborhood::NeighborhoodSubs;
use crate::sub_lib::neighborhood::{ConfigChangeMsg, NeighborhoodSubs};
use crate::sub_lib::proxy_client::ProxyClientSubs;
use crate::sub_lib::proxy_server::ProxyServerSubs;
use crate::sub_lib::ui_gateway::UiGatewaySubs;
use actix::Message;
use actix::{Message, Recipient};
use std::fmt;
use std::fmt::Debug;
use std::fmt::Formatter;
Expand All @@ -33,6 +33,16 @@ impl Debug for PeerActors {
}
}

impl PeerActors {
pub fn config_change_subs(&self) -> Vec<Recipient<ConfigChangeMsg>> {
vec![
self.accountant.config_change_msg_sub.clone(),
self.blockchain_bridge.config_change_msg_sub.clone(),
self.neighborhood.config_change_msg_sub.clone(),
]
}
}

#[derive(Debug, Message, Clone, PartialEq, Eq)]
pub struct BindMessage {
pub peer_actors: PeerActors,
Expand Down
Loading