Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit 925beaa

Browse files
authored
fix unreachable_pub for validator crate (#613)
1 parent 06aeead commit 925beaa

10 files changed

Lines changed: 48 additions & 51 deletions

File tree

crates/validator/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name = "validator"
33
version.workspace = true
44
edition.workspace = true
55

6+
[lints]
7+
workspace = true
8+
69
[dependencies]
710
actix-web = { workspace = true }
811
alloy = { workspace = true }
@@ -34,4 +37,4 @@ url = { workspace = true }
3437

3538
[dev-dependencies]
3639
mockito = { workspace = true }
37-
tempfile = "=3.14.0"
40+
tempfile = "=3.14.0"

crates/validator/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
mod metrics;
2+
mod p2p;
3+
mod store;
4+
mod validators;
5+
6+
pub use metrics::export_metrics;
7+
pub use metrics::MetricsContext;
8+
pub use p2p::P2PClient;
9+
pub use store::redis::RedisStore;
10+
pub use validators::hardware::HardwareValidator;
11+
pub use validators::synthetic_data::types::InvalidationType;
12+
pub use validators::synthetic_data::SyntheticDataValidator;

crates/validator/src/main.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
pub mod metrics;
2-
pub mod p2p;
3-
pub mod store;
4-
pub mod validators;
51
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
62
use alloy::primitives::utils::Unit;
73
use alloy::primitives::{Address, U256};
84
use anyhow::{Context, Result};
95
use clap::Parser;
106
use log::{debug, LevelFilter};
117
use log::{error, info};
12-
use metrics::MetricsContext;
13-
use p2p::P2PClient;
148
use serde_json::json;
159
use shared::models::api::ApiResponse;
1610
use shared::models::node::DiscoveryNode;
@@ -24,14 +18,15 @@ use std::sync::atomic::{AtomicI64, Ordering};
2418
use std::sync::Arc;
2519
use std::time::Duration;
2620
use std::time::{Instant, SystemTime, UNIX_EPOCH};
27-
use store::redis::RedisStore;
2821
use tokio::signal::unix::{signal, SignalKind};
2922
use tokio_util::sync::CancellationToken;
3023
use url::Url;
31-
use validators::hardware::HardwareValidator;
32-
use validators::synthetic_data::SyntheticDataValidator;
3324

34-
use crate::validators::synthetic_data::types::InvalidationType;
25+
use validator::{
26+
export_metrics, HardwareValidator, InvalidationType, MetricsContext, P2PClient, RedisStore,
27+
SyntheticDataValidator,
28+
};
29+
3530
// Track the last time the validation loop ran
3631
static LAST_VALIDATION_TIMESTAMP: AtomicI64 = AtomicI64::new(0);
3732
// Maximum allowed time between validation loops (2 minutes)
@@ -407,7 +402,7 @@ async fn main() -> anyhow::Result<()> {
407402
.route(
408403
"/metrics",
409404
web::get().to(|| async {
410-
match metrics::export_metrics() {
405+
match export_metrics() {
411406
Ok(metrics) => {
412407
HttpResponse::Ok().content_type("text/plain").body(metrics)
413408
}
@@ -634,20 +629,19 @@ async fn main() -> anyhow::Result<()> {
634629

635630
#[cfg(test)]
636631
mod tests {
637-
638632
use actix_web::{test, App};
639633
use actix_web::{
640634
web::{self, post},
641635
HttpResponse, Scope,
642636
};
643637
use shared::models::challenge::{calc_matrix, ChallengeRequest, ChallengeResponse, FixedF64};
644638

645-
pub async fn handle_challenge(challenge: web::Json<ChallengeRequest>) -> HttpResponse {
639+
async fn handle_challenge(challenge: web::Json<ChallengeRequest>) -> HttpResponse {
646640
let result = calc_matrix(&challenge);
647641
HttpResponse::Ok().json(result)
648642
}
649643

650-
pub fn challenge_routes() -> Scope {
644+
fn challenge_routes() -> Scope {
651645
web::scope("/challenge")
652646
.route("", post().to(handle_challenge))
653647
.route("/", post().to(handle_challenge))

crates/validator/src/p2p/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pub mod client;
1+
pub(crate) mod client;
22

33
pub use client::P2PClient;

crates/validator/src/store/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod redis;
1+
pub(crate) mod redis;

crates/validator/src/validators/hardware_challenge.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ use shared::models::{
99
};
1010
use std::str::FromStr;
1111

12-
pub struct HardwareChallenge<'a> {
12+
pub(crate) struct HardwareChallenge<'a> {
1313
p2p_client: &'a P2PClient,
1414
}
1515

1616
impl<'a> HardwareChallenge<'a> {
17-
pub fn new(p2p_client: &'a P2PClient) -> Self {
17+
pub(crate) fn new(p2p_client: &'a P2PClient) -> Self {
1818
Self { p2p_client }
1919
}
2020

21-
pub async fn challenge_node(&self, node: &DiscoveryNode) -> Result<i32, Error> {
21+
pub(crate) async fn challenge_node(&self, node: &DiscoveryNode) -> Result<i32, Error> {
2222
// Check if node has P2P ID and addresses
2323
let p2p_id = node
2424
.node
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
pub mod hardware;
2-
pub mod hardware_challenge;
3-
pub mod synthetic_data;
4-
/// Common trait for all validators
5-
pub trait Validator {
6-
type Error;
7-
8-
/// Returns the name of the validator
9-
fn name(&self) -> &str;
10-
}
1+
pub(crate) mod hardware;
2+
pub(crate) mod hardware_challenge;
3+
pub(crate) mod synthetic_data;

crates/validator/src/validators/synthetic_data/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ use crate::store::redis::RedisStore;
33
use crate::validators::synthetic_data::types::{InvalidationType, RejectionInfo};
44
use alloy::primitives::U256;
55
use anyhow::{Context as _, Error, Result};
6-
use chrono;
76
use futures::future;
87
use log::{debug, warn};
98
use log::{error, info};
109
use redis::AsyncCommands;
11-
use serde_json;
1210
use shared::utils::StorageProvider;
1311
use shared::web3::contracts::implementations::prime_network_contract::PrimeNetworkContract;
1412
use shared::web3::contracts::implementations::work_validators::synthetic_data_validator::{
@@ -19,11 +17,12 @@ use std::collections::HashMap;
1917
use std::str::FromStr;
2018
use std::sync::Arc;
2119
use tokio_util::sync::CancellationToken;
22-
pub mod chain_operations;
20+
21+
pub(crate) mod chain_operations;
2322
#[cfg(test)]
2423
mod tests;
25-
pub mod toploc;
26-
pub mod types;
24+
pub(crate) mod toploc;
25+
pub(crate) mod types;
2726

2827
use toploc::{GroupValidationResult, Toploc, ToplocConfig};
2928
use types::{

crates/validator/src/validators/synthetic_data/toploc.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ pub struct ToplocConfig {
1414
}
1515

1616
#[derive(Clone, Debug)]
17-
pub struct Toploc {
17+
pub(crate) struct Toploc {
1818
config: ToplocConfig,
1919
client: reqwest::Client,
2020
metrics: Option<MetricsContext>,
2121
}
2222

2323
#[derive(Debug, PartialEq, Serialize, Deserialize)]
24-
pub struct GroupValidationResult {
24+
pub(crate) struct GroupValidationResult {
2525
pub status: ValidationResult,
2626
pub input_flops: f64,
2727
pub output_flops: f64,
@@ -31,7 +31,7 @@ pub struct GroupValidationResult {
3131
}
3232

3333
impl Toploc {
34-
pub fn new(config: ToplocConfig, metrics: Option<MetricsContext>) -> Self {
34+
pub(crate) fn new(config: ToplocConfig, metrics: Option<MetricsContext>) -> Self {
3535
let client = reqwest::Client::builder()
3636
.default_headers({
3737
let mut headers = reqwest::header::HeaderMap::new();
@@ -56,7 +56,7 @@ impl Toploc {
5656
}
5757
}
5858

59-
pub fn name(&self) -> String {
59+
pub(crate) fn name(&self) -> String {
6060
let prefix = self
6161
.config
6262
.file_prefix_filter
@@ -80,7 +80,7 @@ impl Toploc {
8080
}
8181
}
8282

83-
pub fn matches_file_name(&self, file_name: &str) -> bool {
83+
pub(crate) fn matches_file_name(&self, file_name: &str) -> bool {
8484
let normalized_name = self.normalize_path(file_name);
8585
match &self.config.file_prefix_filter {
8686
Some(prefix) => {
@@ -93,7 +93,7 @@ impl Toploc {
9393
}
9494
}
9595

96-
pub async fn trigger_single_file_validation(
96+
pub(crate) async fn trigger_single_file_validation(
9797
&self,
9898
file_sha: &str,
9999
key_address: &str,
@@ -157,7 +157,7 @@ impl Toploc {
157157
}
158158
}
159159

160-
pub async fn trigger_group_file_validation(
160+
pub(crate) async fn trigger_group_file_validation(
161161
&self,
162162
file_name: &str,
163163
file_shas: Vec<String>,
@@ -227,7 +227,7 @@ impl Toploc {
227227
}
228228
}
229229

230-
pub async fn get_group_file_validation_status(
230+
pub(crate) async fn get_group_file_validation_status(
231231
&self,
232232
file_name: &str,
233233
) -> Result<GroupValidationResult, Error> {
@@ -328,7 +328,7 @@ impl Toploc {
328328
}
329329
}
330330

331-
pub async fn get_single_file_validation_status(
331+
pub(crate) async fn get_single_file_validation_status(
332332
&self,
333333
file_name: &str,
334334
) -> Result<ValidationResult, Error> {

crates/validator/src/validators/synthetic_data/types.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt;
66
use std::str::FromStr;
77

88
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
9-
pub enum ValidationResult {
9+
pub(crate) enum ValidationResult {
1010
Accept,
1111
Reject,
1212
Crashed,
@@ -33,7 +33,7 @@ impl fmt::Display for ValidationResult {
3333
}
3434

3535
#[derive(Debug, Serialize, Deserialize, PartialEq)]
36-
pub struct WorkValidationInfo {
36+
pub(crate) struct WorkValidationInfo {
3737
pub status: ValidationResult,
3838
pub reason: Option<String>,
3939
}
@@ -61,9 +61,8 @@ impl fmt::Display for InvalidationType {
6161
}
6262

6363
#[derive(Debug)]
64-
pub enum ProcessWorkKeyError {
64+
pub(crate) enum ProcessWorkKeyError {
6565
FileNameResolutionError(String),
66-
ValidationTriggerError(String),
6766
ValidationPollingError(String),
6867
InvalidatingWorkError(String),
6968
MaxAttemptsReached(String),
@@ -83,9 +82,6 @@ impl fmt::Display for ProcessWorkKeyError {
8382
ProcessWorkKeyError::FileNameResolutionError(msg) => {
8483
write!(f, "File name resolution error: {msg}")
8584
}
86-
ProcessWorkKeyError::ValidationTriggerError(msg) => {
87-
write!(f, "Validation trigger error: {msg}")
88-
}
8985
ProcessWorkKeyError::ValidationPollingError(msg) => {
9086
write!(f, "Validation polling error: {msg}")
9187
}

0 commit comments

Comments
 (0)