Skip to content

Commit

Permalink
feat: allow the user to see and update app settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bochaco committed Nov 25, 2024
1 parent 02830bc commit 59315a4
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 114 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tonic = { version = "0.6.2", default-features = false, features = ["tls"], optio
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"], optional = true }
tower = { version = "0.4", optional = true }
tower-http = { version = "0.5", default-features = false, features = ["fs"], optional = true }
url = { version = "2", optional = true }
url = "2"
wasm-bindgen = "=0.2.95"
wasm-bindgen-futures = "0.4"

Expand All @@ -69,7 +69,6 @@ ssr = [
"dep:tokio",
"dep:tower",
"dep:tower-http",
"dep:url",
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
Expand Down
27 changes: 27 additions & 0 deletions migrations/20241122023406_settings.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- How often to check which is the latest version of the node binary.
ALTER TABLE settings ADD COLUMN node_bin_version_polling_freq_secs INTEGER;

-- How often to query balances from the ledger.
ALTER TABLE settings ADD COLUMN rewards_balances_retrieval_freq_secs INTEGER;

-- How often to fetch metrics and node info from active/running nodes
ALTER TABLE settings ADD COLUMN nodes_metrics_polling_freq_secs INTEGER;

-- URL to send queries using RPC to get rewards addresses balances from L2 network.
ALTER TABLE settings ADD COLUMN l2_network_rpc_url TEXT;

-- ERC20 token contract address.
ALTER TABLE settings ADD COLUMN token_contract_address TEXT;


UPDATE settings SET
-- Check latest version of node binary every couple of hours.
node_bin_version_polling_freq_secs = 60 * 60 * 2,
-- Check balances every 15mins.
rewards_balances_retrieval_freq_secs = 60 * 15,
-- Poll nodes metrics every 5 secs.
nodes_metrics_polling_freq_secs = 5,
-- Arbitrum Sepolia testnet.
l2_network_rpc_url = "https://sepolia-rollup.arbitrum.io/rpc",
-- ANT token contract on Arbitrum Sepolia testnet.
token_contract_address = "0xBE1802c27C324a28aeBcd7eeC7D734246C807194";
35 changes: 31 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ use axum::extract::FromRef;
#[cfg(feature = "ssr")]
use std::{collections::HashSet, sync::Arc};
#[cfg(feature = "ssr")]
use tokio::sync::Mutex;
use tokio::sync::{mpsc, Mutex};

#[cfg(feature = "hydrate")]
use gloo_timers::future::TimeoutFuture;
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::{collections::HashMap, time::Duration};
use wasm_bindgen::{prelude::*, JsValue};

#[wasm_bindgen(module = "/public/metamask.js")]
Expand All @@ -35,10 +35,36 @@ extern "C" {
}

// Application settings values.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AppSettings {
pub nodes_auto_upgrade: bool,
pub nodes_auto_upgrade_delay_secs: u64,
pub nodes_auto_upgrade_delay: Duration,
pub node_bin_version_polling_freq: Duration,
pub nodes_metrics_polling_freq: Duration,
pub rewards_balances_retrieval_freq: Duration,
pub l2_network_rpc_url: String,
pub token_contract_address: String,
}

impl Default for AppSettings {
fn default() -> Self {
Self {
// Node auto-upgrading is disabled by default.
nodes_auto_upgrade: false,
// Delay 10 secs. between each node being auto-upgraded.
nodes_auto_upgrade_delay: Duration::from_secs(10),
// Check latest version of node binary every couple of hours.
node_bin_version_polling_freq: Duration::from_secs(60 * 60 * 2),
// How often to fetch metrics and node info from active/running nodes
nodes_metrics_polling_freq: Duration::from_secs(5),
// Retrieve balances every 15 mins.
rewards_balances_retrieval_freq: Duration::from_secs(60 * 15),
// Arbitrum Sepolia testnet.
l2_network_rpc_url: "https://sepolia-rollup.arbitrum.io/rpc".to_string(),
// ANT token contract on Arbitrum Sepolia testnet.
token_contract_address: "0xBE1802c27C324a28aeBcd7eeC7D734246C807194".to_string(),
}
}
}

// Frequency in millis for nodes metrics polling
Expand All @@ -59,6 +85,7 @@ pub struct ServerGlobalState {
pub nodes_metrics: Arc<Mutex<super::metrics_client::NodesMetrics>>,
pub server_api_hit: Arc<Mutex<bool>>,
pub node_status_locked: Arc<Mutex<HashSet<super::node_instance::ContainerId>>>,
pub updated_settings_tx: mpsc::Sender<AppSettings>,
}

// Struct to use client side as a global context/state
Expand Down
Loading

0 comments on commit 59315a4

Please sign in to comment.