Skip to content

Commit

Permalink
Always save exit registration
Browse files Browse the repository at this point in the history
Specific dashboard actions where not saving instantly, like exit registration.
This patch adds saving logic for these endpoints and removes some
redundant saving functions which where only used in one location.

There is also a potential logic fix in the saving loop logic never
updating the settings on disk.
  • Loading branch information
jkilpatr committed Aug 16, 2022
1 parent 70b2452 commit 4d031d2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
7 changes: 3 additions & 4 deletions rita_bin/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ fn main() {

start_rita_common_loops();
start_rita_client_loops();
save_to_disk_loop(
SettingsOnDisk::RitaClientSettings(settings::get_rita_client()),
&args.flag_config,
);
save_to_disk_loop(SettingsOnDisk::RitaClientSettings(
settings::get_rita_client(),
));
start_core_rita_endpoints(4);
start_rita_client_endpoints(1);
start_client_dashboard(settings.network.rita_dashboard_port);
Expand Down
9 changes: 4 additions & 5 deletions rita_bin/src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn main() {
// load the settings file, setup a thread to save it out every so often
// and populate the memory cache of settings used throughout the program
let settings = {
let settings_file = args.flag_config.clone();
let settings_file = args.flag_config;
let settings = RitaExitSettingsStruct::new_watched(&settings_file).unwrap();

settings::set_git_hash(env!("GIT_HASH").to_string());
Expand Down Expand Up @@ -132,10 +132,9 @@ fn main() {

start_rita_common_loops();
start_rita_exit_loop();
save_to_disk_loop(
SettingsOnDisk::RitaExitSettingsStruct(settings::get_rita_exit()),
&args.flag_config,
);
save_to_disk_loop(SettingsOnDisk::RitaExitSettingsStruct(
settings::get_rita_exit(),
));

let workers = settings.workers;
start_core_rita_endpoints(workers as usize);
Expand Down
5 changes: 5 additions & 0 deletions rita_client/src/dashboard/exits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use babel_monitor::parse_routes;
use rita_common::RitaCommonError;
use rita_common::KI;
use settings::client::ExitServer;
use settings::write_config;
use std::collections::HashMap;
use std::time::Duration;

Expand Down Expand Up @@ -149,6 +150,10 @@ pub async fn reset_exit(path: Path<String>) -> HttpResponse {
};
rita_client.exit_client.exits = exits;
settings::set_rita_client(rita_client);
let res = write_config();
if let Err(e) = res {
error!("Failed to save exit reset! {:?}", e);
}
HttpResponse::Ok().json(ret)
} else {
error!("Requested a reset on unknown exit {:?}", exit_name);
Expand Down
13 changes: 13 additions & 0 deletions rita_client/src/dashboard/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use actix_web_async::web::Path;
use actix_web_async::{HttpRequest, HttpResponse};
use clarity::Address;
use num256::Uint256;
use settings::write_config;
use std::collections::HashMap;

/// TODO remove after beta 12, provided for backwards compat
Expand All @@ -28,6 +29,10 @@ pub async fn add_to_dao_list(path: Path<Address>) -> HttpResponse {

rita_client.operator = operator;
settings::set_rita_client(rita_client);
let res = write_config();
if let Err(e) = res {
error!("Failed to save operator address! {:?}", e);
}

HttpResponse::Ok().finish()
}
Expand All @@ -41,6 +46,10 @@ pub async fn remove_from_dao_list(_path: Path<Address>) -> HttpResponse {

rita_client.operator = operator;
settings::set_rita_client(rita_client);
let res = write_config();
if let Err(e) = res {
error!("Failed to save operator remove! {:?}", e);
}

HttpResponse::Ok().finish()
}
Expand All @@ -65,6 +74,10 @@ pub async fn set_dao_fee(path: Path<Uint256>) -> HttpResponse {

rita_client.operator = operator;
settings::set_rita_client(rita_client);
let res = write_config();
if let Err(e) = res {
error!("Failed to save operator fee! {:?}", e);
}

HttpResponse::Ok().finish()
}
Expand Down
15 changes: 10 additions & 5 deletions rita_common/src/rita_loop/write_to_disk.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{debt_keeper::save_debt_to_disk, usage_tracker::save_usage_to_disk};
use settings::{
check_if_exit, client::RitaClientSettings, exit::RitaExitSettingsStruct, get_rita_client,
get_rita_exit, save_client_settings, save_exit_settings,
get_rita_exit, write_config,
};
use std::{
thread,
Expand All @@ -26,8 +26,7 @@ pub enum SettingsOnDisk {
/// is. There is also a consideration for the amount of storage the device
/// has on disk since we don't want to save too often if the disk doesn't
/// contain a lot of storage.
pub fn save_to_disk_loop(mut old_settings: SettingsOnDisk, file_path: &str) {
let file_path = file_path.to_string();
pub fn save_to_disk_loop(mut old_settings: SettingsOnDisk) {
let router_storage_small;
let saving_to_disk_frequency: Duration;

Expand Down Expand Up @@ -67,7 +66,10 @@ pub fn save_to_disk_loop(mut old_settings: SettingsOnDisk, file_path: &str) {
let new_settings = get_rita_client();

if old_settings_client != new_settings {
save_client_settings(old_settings_client, file_path.clone());
let res = write_config();
if let Err(e) = res {
error!("Error saving client settings! {:?}", e);
}
}

old_settings = SettingsOnDisk::RitaClientSettings(new_settings);
Expand All @@ -76,7 +78,10 @@ pub fn save_to_disk_loop(mut old_settings: SettingsOnDisk, file_path: &str) {
let new_settings = get_rita_exit();

if old_settings_exit != new_settings {
save_exit_settings(new_settings.clone(), file_path.clone());
let res = write_config();
if let Err(e) = res {
error!("Error saving exit settings! {:?}", e);
}
}

old_settings = SettingsOnDisk::RitaExitSettingsStruct(new_settings);
Expand Down
14 changes: 0 additions & 14 deletions settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,6 @@ pub fn save_settings_on_shutdown() {
info!("Shutdown: saving settings");
}

pub fn save_exit_settings(new_settings: RitaExitSettingsStruct, file_path: String) {
if let Err(e) = new_settings.write(&file_path) {
warn!("writing updated exit config failed {:?}", e);
}
log::info!("Exit Config/settings is being saved to");
}

pub fn save_client_settings(new_settings: RitaClientSettings, file_path: String) {
if let Err(e) = new_settings.write(&file_path) {
warn!("writing updated client config failed {:?}", e);
}
log::info!("Client Config/settings is being saved to");
}

/// get a JSON value of all settings
pub fn get_config_json() -> Result<serde_json::Value, SettingsError> {
match &*SETTINGS.read().unwrap() {
Expand Down

0 comments on commit 4d031d2

Please sign in to comment.