diff --git a/README.md b/README.md index 202d59d2..dc08ceb4 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ struct Datagram { #[tokio::main] async fn main() { - let config = load_module_config::<()>().unwrap(); + let config = load_commit_module_config::<()>().unwrap(); let pubkeys = config.signer_client.get_pubkeys().await.unwrap(); let pubkey = *pubkeys.consensus.first().unwrap(); diff --git a/bin/src/lib.rs b/bin/src/lib.rs index 9aab7bc4..24b77689 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -7,7 +7,10 @@ pub mod prelude { utils::{initialize_tracing_log, utcnow_ms, utcnow_ns, utcnow_sec, utcnow_us}, }; pub use cb_metrics::provider::MetricsProvider; - + pub use cb_pbs::{ + get_header, get_status, register_validator, submit_block, BuilderApi, BuilderApiState, + PbsState, + }; // The TreeHash derive macro requires tree_hash:: as import pub mod tree_hash { pub use tree_hash::*; diff --git a/crates/pbs/src/lib.rs b/crates/pbs/src/lib.rs index 47eeee64..e3b219c5 100644 --- a/crates/pbs/src/lib.rs +++ b/crates/pbs/src/lib.rs @@ -1,5 +1,3 @@ -// implements https://github.com/ethereum/builder-specs and multiplexes to multiple builderAPI compatible clients (ie MEV Boost relays) - mod api; mod constants; mod error; @@ -10,5 +8,6 @@ mod service; mod state; pub use api::*; +pub use mev_boost::*; pub use service::PbsService; pub use state::{BuilderApiState, PbsState}; diff --git a/crates/pbs/src/state.rs b/crates/pbs/src/state.rs index 6f0616cb..3641dffa 100644 --- a/crates/pbs/src/state.rs +++ b/crates/pbs/src/state.rs @@ -1,6 +1,5 @@ use std::{ collections::HashSet, - fmt, sync::{Arc, Mutex}, }; @@ -12,13 +11,13 @@ use cb_common::{ use dashmap::DashMap; use uuid::Uuid; -pub trait BuilderApiState: fmt::Debug + Default + Clone + Sync + Send + 'static {} +pub trait BuilderApiState: Clone + Sync + Send + 'static {} impl BuilderApiState for () {} /// State for the Pbs module. It can be extended in two ways: /// - By adding extra configs to be loaded at startup /// - By adding extra data to the state -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct PbsState { /// Config data for the Pbs service pub config: PbsModuleConfig, @@ -30,23 +29,30 @@ pub struct PbsState { bid_cache: Arc>>, } -impl PbsState -where - S: BuilderApiState, -{ +impl PbsState { pub fn new(config: PbsModuleConfig) -> Self { Self { config, - data: S::default(), - current_slot_info: Arc::new(Mutex::new((0, Uuid::default()))), + data: (), + current_slot_info: Arc::new(Mutex::new((0, Uuid::new_v4()))), bid_cache: Arc::new(DashMap::new()), } } - pub fn with_data(self, data: S) -> Self { - Self { data, ..self } + pub fn with_data(self, data: S) -> PbsState { + PbsState { + data, + config: self.config, + current_slot_info: self.current_slot_info, + bid_cache: self.bid_cache, + } } +} +impl PbsState +where + S: BuilderApiState, +{ pub fn publish_event(&self, e: BuilderEvent) { if let Some(publisher) = self.config.event_publiher.as_ref() { publisher.publish(e); diff --git a/docs/docs/developing/commit-module.md b/docs/docs/developing/commit-module.md index b8a1fb59..77ada17f 100644 --- a/docs/docs/developing/commit-module.md +++ b/docs/docs/developing/commit-module.md @@ -32,10 +32,10 @@ struct ExtraConfig { sleep_secs: u64, } ``` -then pass that struct to the `load_module_config` function, which will load and parse the config. Your custom config will be under the `extra` field. +then pass that struct to the `load_commit_module_config` function, which will load and parse the config. Your custom config will be under the `extra` field. ```rust -let config = load_module_config::().unwrap(); +let config = load_commit_module_config::().unwrap(); let to_sleep = config.extra.sleep_secs; ``` diff --git a/examples/da_commit/src/main.rs b/examples/da_commit/src/main.rs index 567c46cc..da49bbc4 100644 --- a/examples/da_commit/src/main.rs +++ b/examples/da_commit/src/main.rs @@ -30,7 +30,7 @@ struct DaCommitService { // Extra configurations parameters can be set here and will be automatically // parsed from the .config.toml file These parameters will be in the .extra // field of the StartModuleConfig struct you get after calling -// `load_module_config::()` +// `load_commit_module_config::()` #[derive(Debug, Deserialize)] struct ExtraConfig { sleep_secs: u64,