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

Dz nym node stats #5418

Merged
merged 15 commits into from
Feb 11, 2025
Prev Previous commit
Rename MixingNodeKind for better clarity
dynco-nym committed Feb 10, 2025
commit 9150ac2b9c5f7559465a550c9b7bc769dfdec4e4
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@ ALTER TABLE mixnodes DROP COLUMN blacklisted;
ALTER TABLE gateways DROP COLUMN blacklisted;

CREATE TABLE nym_nodes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
node_id INTEGER NOT NULL UNIQUE,
node_id INTEGER PRIMARY KEY,
ed25519_identity_pubkey VARCHAR NOT NULL UNIQUE,
total_stake INTEGER NOT NULL,
ip_addresses TEXT NOT NULL,
7 changes: 2 additions & 5 deletions nym-node-status-api/nym-node-status-api/src/db/models.rs
Original file line number Diff line number Diff line change
@@ -360,14 +360,14 @@ impl TryFrom<GatewaySessionsRecord> for http::models::SessionStats {
}
}

pub(crate) enum NodeKind {
pub(crate) enum MixingNodeKind {
LegacyMixnode,
NymNode,
}

pub(crate) struct ScraperNodeInfo {
pub node_id: i64,
pub node_kind: NodeKind,
pub node_kind: MixingNodeKind,
pub hosts: Vec<String>,
pub http_api_port: i64,
}
@@ -409,8 +409,6 @@ pub(crate) struct NymNodeDto {

#[derive(Debug)]
pub(crate) struct NymNodeInsertRecord {
#[allow(dead_code)]
pub id: i64,
pub node_id: i64,
pub ed25519_identity_pubkey: String,
pub total_stake: i64,
@@ -429,7 +427,6 @@ impl NymNodeInsertRecord {
let now = OffsetDateTime::now_utc().to_string();

let record = Self {
id: Default::default(),
node_id: skimmed_node.node_id.into(),
ed25519_identity_pubkey: skimmed_node.ed25519_identity_pubkey.to_base58_string(),
total_stake,
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use crate::db::{
models::{NodeKind, NodeStats, ScraperNodeInfo},
models::{MixingNodeKind, NodeStats, ScraperNodeInfo},
DbPool,
};
use anyhow::Result;

pub(crate) async fn insert_node_packet_stats(
pool: &DbPool,
node_id: i64,
node_kind: &NodeKind,
node_kind: &MixingNodeKind,
stats: &NodeStats,
timestamp_utc: i64,
) -> Result<()> {
let mut conn = pool.acquire().await?;

match node_kind {
NodeKind::LegacyMixnode => {
MixingNodeKind::LegacyMixnode => {
sqlx::query!(
r#"
INSERT INTO mixnode_packet_stats_raw (
@@ -30,7 +30,7 @@ pub(crate) async fn insert_node_packet_stats(
.execute(&mut *conn)
.await?;
}
NodeKind::NymNode => {
MixingNodeKind::NymNode => {
sqlx::query!(
r#"
INSERT INTO nym_nodes_packet_stats_raw (
@@ -60,7 +60,7 @@ pub(crate) async fn get_raw_node_stats(
let packets = match node.node_kind {
// if no packets are found, it's fine to assume 0 because that's also
// SQL default value if none provided
NodeKind::LegacyMixnode => {
MixingNodeKind::LegacyMixnode => {
sqlx::query_as!(
NodeStats,
r#"
@@ -78,7 +78,7 @@ pub(crate) async fn get_raw_node_stats(
.fetch_optional(&mut *conn)
.await?
}
NodeKind::NymNode => {
MixingNodeKind::NymNode => {
sqlx::query_as!(
NodeStats,
r#"
@@ -110,7 +110,7 @@ pub(crate) async fn insert_daily_node_stats(
let mut conn = pool.acquire().await?;

match node.node_kind {
NodeKind::LegacyMixnode => {
MixingNodeKind::LegacyMixnode => {
let total_stake = sqlx::query_scalar!(
r#"
SELECT
@@ -146,7 +146,7 @@ pub(crate) async fn insert_daily_node_stats(
.execute(&mut *conn)
.await?;
}
NodeKind::NymNode => {
MixingNodeKind::NymNode => {
let total_stake = sqlx::query_scalar!(
r#"
SELECT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
db::{
models::{NodeKind, ScraperNodeInfo},
models::{MixingNodeKind, ScraperNodeInfo},
queries, DbPool,
},
mixnet_scraper::helpers::NodeDescriptionResponse,
@@ -17,7 +17,7 @@ pub(crate) async fn get_mixing_nodes_for_scraping(pool: &DbPool) -> Result<Vec<S
.for_each(|node| {
nodes_to_scrape.push(ScraperNodeInfo {
node_id: node.node_id.into(),
node_kind: NodeKind::NymNode,
node_kind: MixingNodeKind::NymNode,
hosts: node
.ip_addresses
.into_iter()
@@ -64,7 +64,7 @@ pub(crate) async fn get_mixing_nodes_for_scraping(pool: &DbPool) -> Result<Vec<S
{
nodes_to_scrape.push(ScraperNodeInfo {
node_id: mixnode.node_id,
node_kind: NodeKind::LegacyMixnode,
node_kind: MixingNodeKind::LegacyMixnode,
hosts: vec![mixnode.host],
http_api_port: mixnode.http_api_port,
})
@@ -89,15 +89,15 @@ pub(crate) async fn get_mixing_nodes_for_scraping(pool: &DbPool) -> Result<Vec<S

pub(crate) async fn insert_scraped_node_description(
pool: &DbPool,
node_kind: &NodeKind,
node_kind: &MixingNodeKind,
node_id: i64,
description: &NodeDescriptionResponse,
) -> Result<()> {
let timestamp = Utc::now().timestamp();
let mut conn = pool.acquire().await?;

match node_kind {
NodeKind::LegacyMixnode => {
MixingNodeKind::LegacyMixnode => {
sqlx::query!(
r#"
INSERT INTO mixnode_description (
@@ -120,7 +120,7 @@ pub(crate) async fn insert_scraped_node_description(
.execute(&mut *conn)
.await?;
}
NodeKind::NymNode => {
MixingNodeKind::NymNode => {
sqlx::query!(
r#"
INSERT INTO nym_node_descriptions (
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ impl Scraper {
});
}

#[instrument(level = "debug", name = "description_scraper", skip_all)]
#[instrument(level = "info", name = "description_scraper", skip_all)]
async fn run_description_scraper(
pool: &SqlitePool,
queue: Arc<Mutex<Vec<ScraperNodeInfo>>>,
@@ -86,7 +86,7 @@ impl Scraper {
Ok(())
}

#[instrument(level = "debug", name = "packet_scraper", skip_all)]
#[instrument(level = "info", name = "packet_scraper", skip_all)]
async fn run_packet_scraper(
pool: &SqlitePool,
queue: Arc<Mutex<Vec<ScraperNodeInfo>>>,