Skip to content

Commit

Permalink
Add performance metrics to validator list.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Nov 28, 2024
1 parent a634ad3 commit 887f897
Show file tree
Hide file tree
Showing 39 changed files with 159 additions and 135 deletions.
116 changes: 59 additions & 57 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _docker/compose/.env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=0.22.2
VERSION=0.22.3
ENV=production
LOG_LEVEL=debug

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DROP FUNCTION IF EXISTS sub_get_validator_info_batch;

DO $$ BEGIN
DROP FUNCTION IF EXISTS sub_get_validator_info;
DROP TYPE IF EXISTS sub_validator_info;
Expand All @@ -12,7 +14,8 @@ DO $$ BEGIN
reward_points bigint,
heartbeat_received boolean,
dn_node_record_id INTEGER,
dn_status text
dn_status text,
performance TEXT[]
);
END $$;

Expand Down Expand Up @@ -98,7 +101,48 @@ BEGIN
WHERE C.validator_account_id = account_id_param
ORDER BY id DESC
LIMIT 1;

SELECT COALESCE(
ARRAY_AGG(performance),
ARRAY[]::TEXT[]
)
FROM(
SELECT (
era_index::TEXT || ',' ||
session_index::TEXT || ',' ||
implicit_attestation_count::TEXT || ',' ||
explicit_attestation_count::TEXT || ',' ||
missed_attestation_count::TEXT || ',' ||
attestations_per_billion::TEXT
) AS performance
FROM sub_session_validator_performance
WHERE validator_account_id = account_id_param
AND para_validator_index IS NOT NULL
ORDER BY id DESC
LIMIT 10
) AS subquery
INTO result_record.performance;

RETURN result_record;
END
$$ LANGUAGE plpgsql PARALLEL SAFE STABLE;

CREATE OR REPLACE FUNCTION sub_get_validator_info_batch (block_hash_param VARCHAR(66), account_ids_param VARCHAR(66)[], is_active_param boolean[], era_index_param bigint)
RETURNS SETOF sub_validator_info
AS $$

DECLARE
validator_info sub_validator_info;
account_id VARCHAR(66);
i INT = 1;
is_active BOOLEAN = false;
BEGIN
FOREACH account_id IN ARRAY account_ids_param
LOOP
is_active := is_active_param[i];
validator_info := sub_get_validator_info(block_hash_param, account_id, is_active, era_index_param);
RETURN NEXT validator_info;
i:= i + 1;
END LOOP;
END
$$ LANGUAGE plpgsql PARALLEL SAFE STABLE;

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ CREATE TABLE IF NOT EXISTS sub_session_validator_performance
explicit_attestation_count INT,
missed_attestation_count INT,
attestations_per_billion INT,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now(),
CONSTRAINT sub_era_validator_u_era_index_validator
UNIQUE (validator_account_id, era_index, session_index)
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS sub_session_validator_performance_idx_validator_account_id
Expand All @@ -28,4 +26,6 @@ CREATE INDEX IF NOT EXISTS sub_session_validator_performance_idx_validator_accou
CREATE INDEX IF NOT EXISTS sub_session_validator_performance_idx_validator_account_id_para_validator_index_session_index_desc
ON sub_session_validator_performance (validator_account_id, para_validator_index, session_index DESC);
CREATE UNIQUE INDEX IF NOT EXISTS sub_session_validator_performance_u_validator_era_session
ON sub_session_validator_performance (validator_account_id, era_index, session_index);
ON sub_session_validator_performance (validator_account_id, era_index, session_index);
CREATE INDEX IF NOT EXISTS sub_session_validator_performance_idx_validator_para_id
ON sub_session_validator_performance (validator_account_id, para_validator_index, id DESC);
2 changes: 1 addition & 1 deletion subvt-app-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-app-service"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-block-processor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-block-processor"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-config"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-governance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-governance"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-kline-updater/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-kline-updater"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-logging/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-logging"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-metrics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-metrics"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-network-status-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-network-status-server"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-network-status-updater/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-network-status-updater"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-nft/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-nft"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-notification-generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-notification-generator"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-notification-processor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-notification-processor"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-onekv-updater/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-onekv-updater"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-persistence/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-persistence"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
34 changes: 12 additions & 22 deletions subvt-persistence/src/postgres/network/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub type PostgresValidatorInfo = (
Option<bool>,
Option<i32>,
Option<String>,
Vec<String>,
);

impl PostgreSQLNetworkStorage {
Expand Down Expand Up @@ -339,6 +340,16 @@ impl PostgreSQLNetworkStorage {
}
}
unclaimed_era_indices.sort_unstable();
let performance: Vec<Vec<u32>> = db_validator_info
.11
.iter()
.map(|session_performance| {
session_performance
.split(',')
.map(|v| v.parse::<u32>().unwrap())
.collect()
})
.collect();
ValidatorInfo {
discovered_at: db_validator_info.0.map(|value| value as u64),
slash_count: db_validator_info.1 as u64,
Expand All @@ -351,31 +362,10 @@ impl PostgreSQLNetworkStorage {
heartbeat_received: db_validator_info.8,
dn_record_id: db_validator_info.9.map(|value| value as u32),
dn_status: db_validator_info.10.clone(),
performance,
}
}

pub async fn get_validator_info(
&self,
block_hash: &str,
validator_account_id: &AccountId,
is_active: bool,
era_index: u32,
) -> anyhow::Result<ValidatorInfo> {
let db_validator_info: PostgresValidatorInfo = sqlx::query_as(
r#"
SELECT discovered_at, slash_count, offline_offence_count, active_era_count, inactive_era_count, unclaimed_eras, blocks_authored, reward_points, heartbeat_received, dn_node_record_id, dn_status
FROM sub_get_validator_info($1, $2, $3, $4)
"#
)
.bind(block_hash)
.bind(validator_account_id.to_string())
.bind(is_active)
.bind(era_index as i64)
.fetch_one(&self.connection_pool)
.await?;
Ok(Self::db_record_into_validator_info(&db_validator_info))
}

pub async fn get_validator_info_batch(
&self,
block_hash: &str,
Expand Down
2 changes: 1 addition & 1 deletion subvt-plotter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-plotter"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ proc-macro = true

[package]
name = "subvt-proc-macro"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-referendum-updater/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-referendum-updater"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-report-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-report-service"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-service-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-service-common"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-session-validator-performance-updater/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-session-validator-performance-updater"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
5 changes: 4 additions & 1 deletion subvt-session-validator-performance-updater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ impl Service for SessionValidatorPerformanceUpdater {
"Sleep for {} seconds.",
CONFIG.session_validator_performance_updater.sleep_seconds
);
tokio::time::sleep(std::time::Duration::from_secs(CONFIG.dn.refresh_seconds)).await;
tokio::time::sleep(std::time::Duration::from_secs(
CONFIG.session_validator_performance_updater.sleep_seconds,
))
.await;
}
}
}
2 changes: 1 addition & 1 deletion subvt-substrate-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-substrate-client"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
4 changes: 2 additions & 2 deletions subvt-telegram-bot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-telegram-bot"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand All @@ -10,7 +10,7 @@ async-recursion = "1.0"
async-trait = "0.1"
chrono = "0.4"
enum-iterator = "2.0"
frankenstein = { version = "0.34", default-features = false, features = ["async-http-client", "async-telegram-trait"] }
frankenstein = { version = "0.35", default-features = false, features = ["async-http-client", "async-telegram-trait"] }
futures = "0.3"
itertools = { workspace = true }
lazy_static = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion subvt-telemetry-processor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-telemetry-processor"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
2 changes: 1 addition & 1 deletion subvt-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "subvt-types"
version = "0.22.2"
version = "0.22.3"
edition = "2021"
rust-version = "1.67.0"

Expand Down
1 change: 1 addition & 0 deletions subvt-types/src/rdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct ValidatorInfo {
pub heartbeat_received: Option<bool>,
pub dn_record_id: Option<u32>,
pub dn_status: Option<String>,
pub performance: Vec<Vec<u32>>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
Loading

0 comments on commit 887f897

Please sign in to comment.