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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
3 changes: 1 addition & 2 deletions crates/pbs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,5 +8,6 @@ mod service;
mod state;

pub use api::*;
pub use mev_boost::*;
pub use service::PbsService;
pub use state::{BuilderApiState, PbsState};
28 changes: 17 additions & 11 deletions crates/pbs/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
collections::HashSet,
fmt,
sync::{Arc, Mutex},
};

Expand All @@ -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<U, S: BuilderApiState = ()> {
/// Config data for the Pbs service
pub config: PbsModuleConfig<U>,
Expand All @@ -30,23 +29,30 @@ pub struct PbsState<U, S: BuilderApiState = ()> {
bid_cache: Arc<DashMap<u64, Vec<GetHeaderReponse>>>,
}

impl<U, S> PbsState<U, S>
where
S: BuilderApiState,
{
impl<U> PbsState<U, ()> {
pub fn new(config: PbsModuleConfig<U>) -> 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<S: BuilderApiState>(self, data: S) -> PbsState<U, S> {
PbsState {
data,
config: self.config,
current_slot_info: self.current_slot_info,
bid_cache: self.bid_cache,
}
}
}

impl<U, S> PbsState<U, S>
where
S: BuilderApiState,
{
pub fn publish_event(&self, e: BuilderEvent) {
if let Some(publisher) = self.config.event_publiher.as_ref() {
publisher.publish(e);
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/developing/commit-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ExtraConfig>().unwrap();
let config = load_commit_module_config::<ExtraConfig>().unwrap();
let to_sleep = config.extra.sleep_secs;
```

Expand Down
2 changes: 1 addition & 1 deletion examples/da_commit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtraConfig> struct you get after calling
// `load_module_config::<ExtraConfig>()`
// `load_commit_module_config::<ExtraConfig>()`
#[derive(Debug, Deserialize)]
struct ExtraConfig {
sleep_secs: u64,
Expand Down