diff --git a/config.base.yaml b/config.base.yaml index 73f4db5..1bd88d9 100644 --- a/config.base.yaml +++ b/config.base.yaml @@ -7,6 +7,7 @@ network_timeout_ms: 30000 # How long to allow TCP requests to run before timing round_duration_ms: 10000 # How long does it take to run a round? gema_periods: 10 # Factor to use for GEMA price smoothing price_precision: 1024 # How many bits of precision are allowed in prices in the final output? +publish_url: https://infra-integration.silver-train-1la.pages.dev/api/updatePrices consensus: true logs: json: true diff --git a/src/config.rs b/src/config.rs index 0150b04..bcf0c73 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,6 +27,7 @@ struct RawOracleConfig { pub round_duration_ms: u64, pub gema_periods: usize, pub price_precision: u64, + pub publish_url: Option, pub logs: RawLogConfig, pub frost_address: Option, pub keygen: KeygenConfig, @@ -54,6 +55,7 @@ pub struct OracleConfig { pub round_duration: Duration, pub gema_periods: usize, pub price_precision: u64, + pub publish_url: Option, pub logs: LogConfig, pub frost_address: Option, pub keygen: KeygenConfig, @@ -154,6 +156,7 @@ impl TryFrom for OracleConfig { round_duration: Duration::from_millis(raw.round_duration_ms), gema_periods: raw.gema_periods, price_precision: raw.price_precision, + publish_url: raw.publish_url, logs, frost_address: raw.frost_address, keygen: raw.keygen, diff --git a/src/main.rs b/src/main.rs index f9f3e65..1b5bd8f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,7 +76,7 @@ impl Node { let api_server = APIServer::new(&config, payload_source.clone(), price_audit_rx); - let publisher = Publisher::new(&network.id, payload_source)?; + let publisher = Publisher::new(&config, payload_source)?; Ok(Node { api_server, diff --git a/src/publisher.rs b/src/publisher.rs index 2035afc..4d4e21e 100644 --- a/src/publisher.rs +++ b/src/publisher.rs @@ -5,28 +5,26 @@ use reqwest::Client; use tokio::sync::watch; use tracing::{info, trace, warn}; -use crate::{network::NodeId, signature_aggregator::Payload}; - -const URL: &str = "https://infra-integration.silver-train-1la.pages.dev/api/updatePrices"; +use crate::{config::OracleConfig, network::NodeId, signature_aggregator::Payload}; pub struct Publisher { id: NodeId, + url: Option, source: watch::Receiver, client: Client, } impl Publisher { - pub fn new(id: &NodeId, source: watch::Receiver) -> Result { + pub fn new(config: &OracleConfig, source: watch::Receiver) -> Result { Ok(Self { - id: id.clone(), + id: config.id.clone(), + url: config.publish_url.clone(), source, client: Client::builder().build()?, }) } pub async fn run(self) { - const DEBUG: bool = false; - let mut source = self.source; let client = self.client; while source.changed().await.is_ok() { @@ -45,21 +43,23 @@ impl Publisher { } payload }; - info!(payload, "publishing payload"); + if let Some(url) = &self.url { + info!(payload, "publishing payload"); - if !DEBUG { - match make_request(&client, payload).await { + match make_request(url, &client, payload).await { Ok(res) => trace!("Payload published! {}", res), Err(err) => warn!("Could not publish payload: {}", err), } + } else { + info!(payload, "final payload (not publishing)"); } } } } -async fn make_request(client: &Client, payload: String) -> Result { +async fn make_request(url: &str, client: &Client, payload: String) -> Result { let response = client - .post(URL) + .post(url) .header("Content-Type", "application/json") .body(payload) .timeout(Duration::from_secs(5))