Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ RUST_LOG=info
RUST_BACKTRACE="full"

# BLS private key to sign Builder API responses
RELAY_KEY=0x64496d4e301e541a6e1237d6ef13a8f8b8b6cb82be9d8ac90073a833dfc2af11
RELAY_KEY=0x64496d4e301e541a6e1237d6ef13a8f8b8b6cb82be9d8ac90073a833dfc2af11

POSTGRES_PASSWORD=password
ADMIN_TOKEN=test
1 change: 0 additions & 1 deletion config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ postgres:
port: 5432
db_name: postgres
user: postgres
password: password
region: 0
region_name: "LOCAL"
broadcasters:
Expand Down
11 changes: 6 additions & 5 deletions crates/common/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashSet, fs::File, path::PathBuf};
use std::{collections::HashSet, env, fs::File, path::PathBuf};

use clap::Parser;
use eyre::ensure;
Expand Down Expand Up @@ -50,7 +50,6 @@ pub struct RelayConfig {
pub inclusion_list: Option<InclusionListConfig>,
pub is_submission_instance: bool,
pub is_registration_instance: bool,
pub admin_token: String,
#[serde(default)]
is_local_dev: bool,
/// Cores configuration, recommended to be set for production use
Expand Down Expand Up @@ -83,7 +82,6 @@ impl RelayConfig {
inclusion_list: Default::default(),
is_submission_instance: Default::default(),
is_registration_instance: Default::default(),
admin_token: Default::default(),
is_local_dev: Default::default(),
cores: CoresConfig {
auctioneer: 1,
Expand Down Expand Up @@ -169,8 +167,12 @@ pub fn load_config<R: AsRef<RelayConfig> + DeserializeOwned>() -> R {
config
}

pub fn expect_env_var(env_var: &str) -> String {
env::var(env_var).expect(&format!("{} should be set", env_var))
}

pub fn load_keypair() -> BlsKeypair {
let signing_key_str = std::env::var("RELAY_KEY").expect("could not find RELAY_KEY in env");
let signing_key_str = expect_env_var("RELAY_KEY");
let signing_key_bytes =
alloy_primitives::hex::decode(signing_key_str).expect("invalid RELAY_KEY bytes");

Expand All @@ -189,7 +191,6 @@ pub struct PostgresConfig {
pub port: u16,
pub db_name: String,
pub user: String,
pub password: String,
pub region: i16,
pub region_name: String,
}
Expand Down
18 changes: 8 additions & 10 deletions crates/relay/src/api/admin_service.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{net::SocketAddr, sync::Arc};

use axum::{Extension, Router, http::StatusCode, response::IntoResponse, routing::post};
use helix_common::{RelayConfig, local_cache::LocalCache};
use helix_common::local_cache::LocalCache;
use tower_http::validate_request::ValidateRequestHeaderLayer;
use tracing::{error, info};

pub async fn run_admin_service(auctioneer: Arc<LocalCache>, config: RelayConfig) {
pub async fn run_admin_service(auctioneer: Arc<LocalCache>, admin_token: String) {
let router = Router::new()
.route("/admin/v1/killswitch", post(enable_kill_switch).delete(disable_kill_switch))
.layer(Extension(auctioneer))
.layer(ValidateRequestHeaderLayer::bearer(&config.admin_token));
.layer(ValidateRequestHeaderLayer::bearer(&admin_token));

let listener = tokio::net::TcpListener::bind("0.0.0.0:4050").await.unwrap();
match axum::serve(listener, router.into_make_service_with_connect_info::<SocketAddr>()).await {
Expand Down Expand Up @@ -39,7 +39,7 @@ async fn disable_kill_switch(
mod test {
use std::sync::Arc;

use helix_common::{config, local_cache::LocalCache};
use helix_common::local_cache::LocalCache;
use serial_test::serial;

use crate::api::admin_service::run_admin_service;
Expand All @@ -49,9 +49,8 @@ mod test {
async fn test_admin_service() {
let auctioneer = Arc::new(LocalCache::new_test());

let mut config = config::RelayConfig::empty_for_test();
config.admin_token = "test_token".into();
tokio::spawn(run_admin_service(auctioneer.clone(), config));
let admin_token = "test_token".into();
tokio::spawn(run_admin_service(auctioneer.clone(), admin_token));
tokio::time::sleep(std::time::Duration::from_secs(1)).await; // wait for server to start
let client = reqwest::Client::new();

Expand Down Expand Up @@ -79,9 +78,8 @@ mod test {
async fn test_admin_service_unauthorized() {
let auctioneer = Arc::new(LocalCache::new_test());

let mut config = config::RelayConfig::empty_for_test();
config.admin_token = "test_token".into();
tokio::spawn(run_admin_service(auctioneer.clone(), config));
let admin_token = "test_token".into();
tokio::spawn(run_admin_service(auctioneer.clone(), admin_token));
tokio::time::sleep(std::time::Duration::from_secs(1)).await; // wait for server to start
let client = reqwest::Client::new();

Expand Down
6 changes: 3 additions & 3 deletions crates/relay/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::sync::Arc;

use helix_common::{RelayConfig, api_provider::ApiProvider, local_cache::LocalCache};
use helix_common::{api_provider::ApiProvider, local_cache::LocalCache};
pub use service::start_api_service;

pub use crate::auctioneer::{BidAdjustor, DefaultBidAdjustor};
Expand All @@ -16,8 +16,8 @@ pub mod relay_data;
pub mod router;
pub mod service;

pub fn start_admin_service(auctioneer: Arc<LocalCache>, config: &RelayConfig) {
tokio::spawn(admin_service::run_admin_service(auctioneer, config.clone()));
pub fn start_admin_service(auctioneer: Arc<LocalCache>, admin_token: String) {
tokio::spawn(admin_service::run_admin_service(auctioneer, admin_token));
}

pub trait Api: Clone + Send + Sync + 'static {
Expand Down
6 changes: 4 additions & 2 deletions crates/relay/src/database/postgres/postgres_db_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use helix_common::{
proposer_api::{GetHeaderParams, ValidatorRegistrationInfo},
},
bid_submission::OptimisticVersion,
expect_env_var,
metrics::{CACHE_SIZE, DbMetricRecord},
utils::utcnow_ms,
};
Expand Down Expand Up @@ -58,6 +59,7 @@ struct PendingBlockSubmissionValue {
const BLOCK_SUBMISSION_FIELD_COUNT: usize = 17;
const MAINNET_VALIDATOR_COUNT: usize = 1_100_000;
static DELIVERED_PAYLOADS_MIG_SLOT: AtomicU64 = AtomicU64::new(0);
const POSTGRES_PASSWORD_ENV_VAR: &'static str = "POSTGRES_PASSWORD";

fn new_validator_set() -> FxHashSet<BlsPublicKeyBytes> {
FxHashSet::with_capacity_and_hasher(MAINNET_VALIDATOR_COUNT, Default::default())
Expand Down Expand Up @@ -106,7 +108,7 @@ impl PostgresDatabaseService {
cfg.port = Some(relay_config.postgres.port);
cfg.dbname = Some(relay_config.postgres.db_name.clone());
cfg.user = Some(relay_config.postgres.user.clone());
cfg.password = Some(relay_config.postgres.password.clone());
cfg.password = Some(expect_env_var(POSTGRES_PASSWORD_ENV_VAR));
cfg.manager = Some(ManagerConfig { recycling_method: RecyclingMethod::Fast });

let pool = loop {
Expand All @@ -129,7 +131,7 @@ impl PostgresDatabaseService {
}
};

PostgresDatabaseService {
Self {
validator_registration_cache: Arc::new(DashMap::new()),
pending_validator_registrations: Arc::new(DashSet::new()),
block_submissions_sender: None,
Expand Down
6 changes: 4 additions & 2 deletions crates/relay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use eyre::eyre;
use helix_common::{
RelayConfig,
api_provider::DefaultApiProvider,
load_config, load_keypair,
expect_env_var, load_config, load_keypair,
local_cache::LocalCache,
metrics::start_metrics_server,
signing::RelaySigningContext,
Expand All @@ -30,6 +30,8 @@ use tracing::{error, info};
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

const ADMIN_TOKEN_ENV_VAR: &'static str = "ADMIN_TOKEN";

#[derive(Clone)]
struct ApiProd;

Expand Down Expand Up @@ -112,7 +114,7 @@ async fn run(instance_id: String, config: RelayConfig, keypair: BlsKeypair) -> e

let terminating = Arc::new(AtomicBool::default());

start_admin_service(local_cache.clone(), &config);
start_admin_service(local_cache.clone(), expect_env_var(ADMIN_TOKEN_ENV_VAR));

tokio::spawn(start_api_service::<ApiProd>(
config.clone(),
Expand Down
2 changes: 0 additions & 2 deletions crates/simulator/src/block_merging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use reth_ethereum::{
Evm, EvmEnvFor, EvmError,
block::{BlockExecutionError, BlockExecutor},
execute::BlockBuilder as RethBlockBuilder,
tx,
},
revm::{cached::CachedReads, database::StateProviderDatabase},
},
Expand All @@ -41,7 +40,6 @@ use reth_primitives::{GotExpected, Recovered};
use revm::{
DatabaseCommit, DatabaseRef,
database::{CacheDB, State},
interpreter::gas,
state::AccountInfo,
};
use tracing::{debug, info, warn};
Expand Down
1 change: 0 additions & 1 deletion crates/simulator/src/block_merging/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use reth_node_builder::ConfigureEvm;
use reth_primitives::{NodePrimitives, Recovered};
use serde::{Deserialize, Serialize};
use serde_with::{DisplayFromStr, serde_as};
use tracing::debug;

pub(crate) type SignedTx = <<EthEvmConfig as ConfigureEvm>::Primitives as NodePrimitives>::SignedTx;
pub(crate) type RecoveredTx = Recovered<SignedTx>;
Expand Down