Skip to content

Commit

Permalink
Adjust code to new config
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed Nov 3, 2023
1 parent 8d493f1 commit 58d4d17
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
11 changes: 0 additions & 11 deletions certifier/mainnet.yml

This file was deleted.

37 changes: 18 additions & 19 deletions certifier/src/certifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use axum::http::StatusCode;
use axum::{extract::State, Json};
use axum::{routing::post, Router};
use ed25519_dalek::{Signer, SigningKey};
use post::config::{InitConfig, ProofConfig};
use post::pow::randomx::{PoW, RandomXFlag};
use post::verification::{Verifier, VerifyingParams};
use post::verification::Verifier;
use serde::{Deserialize, Serialize};
use serde_with::{base64::Base64, serde_as};
use tracing::instrument;
Expand Down Expand Up @@ -35,24 +36,20 @@ async fn certify(
let pub_key = request.metadata.node_id;
let s = state.clone();

let params = match VerifyingParams::new(&request.metadata, &s.cfg) {
Ok(params) => params,
Err(e) => return Err((StatusCode::BAD_REQUEST, format!("invalid metadata: {e:?}"))),
};
let result = tokio::task::spawn_blocking(move || {
s.verifier.verify(&request.proof, &request.metadata, params)
s.verifier
.verify(&request.proof, &request.metadata, &s.cfg, &s.init_cfg)
})
.await;
match result {
Err(e) => {
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("internal error verifying proof: {e:?}"),
))
}
Ok(Err(e)) => return Err((StatusCode::FORBIDDEN, format!("invalid proof: {e:?}"))),
_ => {}
}
.await
.map_err(|e| {
tracing::error!("internal error verifying proof: {e:?}");
(
StatusCode::INTERNAL_SERVER_ERROR,
"error verifying proof".into(),
)
})?;

result.map_err(|e| (StatusCode::FORBIDDEN, format!("invalid proof: {e:?}")))?;

// Sign the nodeID
let response = CertifyResponse {
Expand All @@ -64,16 +61,18 @@ async fn certify(

struct AppState {
verifier: Verifier,
cfg: post::config::Config,
cfg: ProofConfig,
init_cfg: InitConfig,
signer: SigningKey,
}

pub fn new(cfg: post::config::Config, signer: SigningKey) -> Router {
pub fn new(cfg: ProofConfig, init_cfg: InitConfig, signer: SigningKey) -> Router {
let state = AppState {
verifier: Verifier::new(Box::new(
PoW::new(RandomXFlag::get_recommended_flags()).expect("creating RandomX PoW verifier"),
)),
cfg,
init_cfg,
signer,
};

Expand Down
3 changes: 2 additions & 1 deletion certifier/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pub struct Config {
/// The base64-encoded secret key used to sign the proofs.
/// It's 256-bit key as defined in [RFC8032 § 5.1.5].
pub signing_key: SecretKey,
pub post_cfg: post::config::Config,
pub post_cfg: post::config::ProofConfig,
pub init_cfg: post::config::InitConfig,

/// Whether to enable metrics on /metrics.
pub metrics: bool,
Expand Down
2 changes: 1 addition & 1 deletion certifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("listening on: {:?}, pubkey: {}", config.listen, pubkey_b64,);
info!("using POST configuration: {:?}", config.post_cfg);

let mut app = certifier::certifier::new(config.post_cfg, signer);
let mut app = certifier::certifier::new(config.post_cfg, config.init_cfg, signer);

if config.metrics {
info!("metrics on: {}/metrics", config.listen.to_string());
Expand Down

0 comments on commit 58d4d17

Please sign in to comment.