Skip to content

Commit 6130f46

Browse files
committed
chore(coprocessor): use DatabaseURL in zkproof-worker
1 parent ff3ea6c commit 6130f46

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

coprocessor/fhevm-engine/zkproof-worker/src/bin/zkproof_worker.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use clap::{command, Parser};
2+
use fhevm_engine_common::telemetry;
23
use fhevm_engine_common::telemetry::{self, MetricsConfig};
3-
use fhevm_engine_common::{healthz_server::HttpServer, metrics_server};
4+
use fhevm_engine_common::{healthz_server::HttpServer, metrics_server, utils::DatabaseURL};
45
use humantime::parse_duration;
6+
use sqlx::Database;
57
use std::{sync::Arc, time::Duration};
68
use tokio::{join, task};
79
use tokio_util::sync::CancellationToken;
@@ -41,7 +43,7 @@ pub struct Args {
4143
/// Postgres database url. If unspecified DATABASE_URL environment variable
4244
/// is used
4345
#[arg(long)]
44-
pub database_url: Option<String>,
46+
pub database_url: Option<DatabaseURL>,
4547

4648
/// Number of zkproof workers to process proofs in parallel
4749
#[arg(long, default_value_t = 8)]
@@ -90,10 +92,7 @@ async fn main() {
9092
.with_max_level(args.log_level)
9193
.init();
9294

93-
let database_url = args
94-
.database_url
95-
.clone()
96-
.unwrap_or_else(|| std::env::var("DATABASE_URL").expect("DATABASE_URL is undefined"));
95+
let database_url = args.database_url.clone().unwrap_or_default();
9796

9897
let conf = zkproof_worker::Config {
9998
database_url,

coprocessor/fhevm-engine/zkproof-worker/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod tests;
55

66
pub mod verifier;
77
use std::{
8+
fmt::{self, Display},
89
io,
910
sync::{LazyLock, OnceLock},
1011
time::Duration,
@@ -16,7 +17,10 @@ use fhevm_engine_common::{
1617
types::FhevmError,
1718
};
1819
use prometheus::Histogram;
20+
21+
use fhevm_engine_common::{pg_pool::ServiceError, types::FhevmError, utils::DatabaseURL};
1922
use thiserror::Error;
23+
use tracing_subscriber::registry::Data;
2024

2125
/// The highest index of an input is 254,
2226
/// cause 255 (0xff) is reserved for handles originating from the FHE operations
@@ -77,7 +81,7 @@ impl From<ExecutionError> for ServiceError {
7781

7882
#[derive(Default, Debug, Clone)]
7983
pub struct Config {
80-
pub database_url: String,
84+
pub database_url: DatabaseURL,
8185
pub listen_database_channel: String,
8286
pub notify_database_channel: String,
8387
pub pg_pool_connections: u32,
@@ -96,3 +100,19 @@ pub static ZKVERIFY_OP_LATENCY_HISTOGRAM: LazyLock<Histogram> = LazyLock::new(||
96100
"ZK verification latencies in seconds",
97101
)
98102
});
103+
impl Display for Config {
104+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
105+
write!(
106+
f,
107+
"Config {{ database_url: {}, listen_database_channel: {}, notify_database_channel: {}, pg_pool_connections: {}, pg_polling_interval: {}, pg_timeout: {:?}, pg_auto_explain_with_min_duration: {:?}, worker_thread_count: {} }}",
108+
self.database_url,
109+
self.listen_database_channel,
110+
self.notify_database_channel,
111+
self.pg_pool_connections,
112+
self.pg_polling_interval,
113+
self.pg_timeout,
114+
self.pg_auto_explain_with_min_duration,
115+
self.worker_thread_count
116+
)
117+
}
118+
}

coprocessor/fhevm-engine/zkproof-worker/src/tests/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub async fn setup() -> anyhow::Result<(PostgresPoolManager, DBInstance)> {
1515
.expect("valid db instance");
1616

1717
let conf = crate::Config {
18-
database_url: test_instance.db_url().to_owned(),
18+
database_url: test_instance.db_url.clone(),
1919
listen_database_channel: "fhevm".to_string(),
2020
notify_database_channel: "notify".to_string(),
2121
pg_pool_connections: 10,

coprocessor/fhevm-engine/zkproof-worker/src/verifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub async fn execute_verify_proofs_loop(
125125
conf: Config,
126126
last_active_at: Arc<RwLock<SystemTime>>,
127127
) -> Result<(), ExecutionError> {
128-
info!(conf = ?conf, "Starting with config");
128+
info!(conf = %conf, "Starting with config");
129129

130130
// Tenants key cache is shared amongst all workers
131131
let tenant_key_cache = Arc::new(RwLock::new(LruCache::new(

0 commit comments

Comments
 (0)