Skip to content

Commit b7e3687

Browse files
authored
Dz nym node stats (#5418)
* Remove blacklisted, inactive, reserve fields * Remove gw.blacklisted * Remove blacklisted and bonded count * DB operations * Improve logging * Remove unused functions * get_nym_nodes for scraping WIP * Separate nym_nodes from mixnode stats - fixes FOREIGN_KEY_CONSTRAINT error when storing stats for nym_nodes which aren't in mixnodes table * Daily aggregation works * mixnodes/stats exposes correct info * Undo unnecessary tidbits * Replace obsolete stats * Add total_stake * Bump cargo.toml version * Rename MixingNodeKind for better clarity
1 parent b9b969b commit b7e3687

28 files changed

+987
-609
lines changed

Cargo.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/http-api-client/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ where
768768
E: DeserializeOwned + Display,
769769
{
770770
let status = res.status();
771-
tracing::debug!("Status: {} (success: {})", &status, status.is_success());
771+
tracing::trace!("Status: {} (success: {})", &status, status.is_success());
772772

773773
if !allow_empty {
774774
if let Some(0) = res.content_length() {

nym-node-status-api/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
nym-node-status-agent/nym-gateway-probe
22
nym-node-status-agent/keys/
33
data/
4+
settings.sql
45
enter_db.sh
56
nym-gateway-probe
67
*.sqlite

nym-node-status-api/nym-node-status-api/Cargo.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[package]
55
name = "nym-node-status-api"
6-
version = "1.0.0-rc.7"
6+
version = "1.0.0-rc.8"
77
authors.workspace = true
88
repository.workspace = true
99
homepage.workspace = true
@@ -22,6 +22,7 @@ cosmwasm-std = { workspace = true }
2222
envy = { workspace = true }
2323
futures-util = { workspace = true }
2424
moka = { workspace = true, features = ["future"] }
25+
nym-contracts-common = { path = "../../common/cosmwasm-smart-contracts/contracts-common" }
2526
nym-bin-common = { path = "../../common/bin-common", features = ["models"] }
2627
nym-node-status-client = { path = "../nym-node-status-client" }
2728
nym-crypto = { path = "../../common/crypto", features = ["asymmetric", "serde"] }
@@ -50,10 +51,6 @@ tracing-log = { workspace = true }
5051
tower-http = { workspace = true, features = ["cors", "trace"] }
5152
utoipa = { workspace = true, features = ["axum_extras", "time"] }
5253
utoipa-swagger-ui = { workspace = true, features = ["axum"] }
53-
# TODO dz `cargo update async-trait`
54-
# for automatic schema detection, which was merged, but not released yet
55-
# https://github.com/ProbablyClem/utoipauto/pull/38
56-
# utoipauto = { git = "https://github.com/ProbablyClem/utoipauto", rev = "eb04cba" }
5754
utoipauto = { workspace = true }
5855

5956
nym-node-metrics = { path = "../../nym-node/nym-node-metrics" }

nym-node-status-api/nym-node-status-api/build.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@ fn read_env_var(var: &str) -> Result<String> {
3636

3737
/// use `./enter_db.sh` to inspect DB
3838
async fn write_db_path_to_file(out_dir: &str, db_filename: &str) -> anyhow::Result<()> {
39+
let mut file = File::create("settings.sql").await?;
40+
let settings = ".mode columns
41+
.headers on";
42+
file.write_all(settings.as_bytes()).await?;
43+
3944
let mut file = File::create("enter_db.sh").await?;
40-
let _ = file.write(b"#!/bin/bash\n").await?;
41-
file.write_all(format!("sqlite3 {}/{}", out_dir, db_filename).as_bytes())
42-
.await?;
45+
let contents = format!(
46+
"#!/bin/bash\n\
47+
sqlite3 -init settings.sql {}/{}",
48+
out_dir, db_filename,
49+
);
50+
file.write_all(contents.as_bytes()).await?;
4351

4452
#[cfg(target_family = "unix")]
4553
file.set_permissions(Permissions::from_mode(0o755))

nym-node-status-api/nym-node-status-api/launch_node_status_api.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
set -e
44

55
user_rust_log_preference=$RUST_LOG
6+
export ENVIRONMENT=${ENVIRONMENT:-"sandbox"}
67
export NYM_API_CLIENT_TIMEOUT=60
78
export EXPLORER_CLIENT_TIMEOUT=60
89
export NODE_STATUS_API_TESTRUN_REFRESH_INTERVAL=120
910

11+
if [ "$ENVIRONMENT" = "mainnet" ]; then
12+
export NYM_NODE_STATUS_API_HM_URL="https://harbourmaster.nymtech.net"
13+
fi
14+
1015
# public counterpart of the agent's private key.
1116
# For TESTING only. NOT used in any other environment
1217
export NODE_STATUS_API_AGENT_KEY_LIST="H4z8kx5Kkf5JMQHhxaW1MwYndjKCDHC7HsVhHTFfBZ4J"
1318

14-
export ENVIRONMENT=${ENVIRONMENT:-"sandbox"}
15-
1619
script_dir=$(dirname $(realpath "$0"))
1720
monorepo_root=$(realpath "${script_dir}/../..")
1821

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ALTER TABLE mixnodes DROP COLUMN blacklisted;
2+
ALTER TABLE gateways DROP COLUMN blacklisted;
3+
4+
CREATE TABLE nym_nodes (
5+
node_id INTEGER PRIMARY KEY,
6+
ed25519_identity_pubkey VARCHAR NOT NULL UNIQUE,
7+
total_stake INTEGER NOT NULL,
8+
ip_addresses TEXT NOT NULL,
9+
mix_port INTEGER NOT NULL,
10+
x25519_sphinx_pubkey VARCHAR NOT NULL UNIQUE,
11+
node_role TEXT NOT NULL,
12+
supported_roles TEXT NOT NULL,
13+
performance VARCHAR NOT NULL,
14+
entry TEXT,
15+
last_updated_utc INTEGER NOT NULL
16+
);
17+
18+
CREATE INDEX idx_nym_nodes_node_id ON nym_nodes (node_id);
19+
CREATE INDEX idx_nym_nodes_ed25519_identity_pubkey ON nym_nodes (ed25519_identity_pubkey);
20+
21+
CREATE TABLE nym_node_descriptions (
22+
id INTEGER PRIMARY KEY AUTOINCREMENT,
23+
node_id INTEGER UNIQUE NOT NULL,
24+
moniker VARCHAR,
25+
website VARCHAR,
26+
security_contact VARCHAR,
27+
details VARCHAR,
28+
last_updated_utc INTEGER NOT NULL,
29+
FOREIGN KEY (node_id) REFERENCES nym_nodes (node_id)
30+
);
31+
32+
CREATE TABLE nym_nodes_packet_stats_raw (
33+
id INTEGER PRIMARY KEY AUTOINCREMENT,
34+
node_id INTEGER NOT NULL,
35+
timestamp_utc INTEGER NOT NULL,
36+
packets_received INTEGER,
37+
packets_sent INTEGER,
38+
packets_dropped INTEGER,
39+
FOREIGN KEY (node_id) REFERENCES nym_nodes (node_id)
40+
);
41+
42+
CREATE INDEX idx_nym_nodes_packet_stats_raw_node_id_timestamp_utc ON nym_nodes_packet_stats_raw (node_id, timestamp_utc);
43+
44+
CREATE TABLE nym_node_daily_mixing_stats (
45+
id INTEGER PRIMARY KEY AUTOINCREMENT,
46+
node_id INTEGER NOT NULL,
47+
total_stake BIGINT NOT NULL,
48+
date_utc VARCHAR NOT NULL,
49+
packets_received INTEGER DEFAULT 0,
50+
packets_sent INTEGER DEFAULT 0,
51+
packets_dropped INTEGER DEFAULT 0,
52+
FOREIGN KEY (node_id) REFERENCES nym_nodes (node_id),
53+
UNIQUE (node_id, date_utc) -- This constraint automatically creates an index
54+
);

nym-node-status-api/nym-node-status-api/src/cli/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ pub(crate) struct Cli {
8383
env = "NYM_NODE_STATUS_API_MAX_AGENT_COUNT"
8484
)]
8585
pub(crate) max_agent_count: i64,
86+
87+
#[clap(long, default_value = "", env = "NYM_NODE_STATUS_API_HM_URL")]
88+
pub(crate) hm_url: String,
8689
}
8790

8891
fn parse_duration(arg: &str) -> Result<std::time::Duration, std::num::ParseIntError> {

0 commit comments

Comments
 (0)