Skip to content

Commit 92a04de

Browse files
committed
Refactor PbsState
1 parent 4d7b609 commit 92a04de

File tree

19 files changed

+67
-82
lines changed

19 files changed

+67
-82
lines changed

bin/pbs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use cb_common::{
22
config::load_pbs_config,
33
utils::{initialize_pbs_tracing_log, wait_for_signal},
44
};
5-
use cb_pbs::{DefaultBuilderApi, InnerPbsState, PbsService};
5+
use cb_pbs::{DefaultBuilderApi, PbsService, PbsState};
66
use eyre::Result;
77
use tracing::{error, info};
88

@@ -18,7 +18,7 @@ async fn main() -> Result<()> {
1818

1919
let pbs_config = load_pbs_config().await?;
2020

21-
let state = InnerPbsState::new(pbs_config);
21+
let state = PbsState::new(pbs_config);
2222
PbsService::init_metrics()?;
2323
let server = PbsService::run::<_, DefaultBuilderApi>(state);
2424

bin/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub mod prelude {
1919
pub use cb_metrics::provider::MetricsProvider;
2020
pub use cb_pbs::{
2121
get_header, get_status, register_validator, submit_block, BuilderApi, BuilderApiState,
22-
DefaultBuilderApi, InnerPbsState, PbsService, PbsState,
22+
DefaultBuilderApi, PbsService, PbsState, PbsStateGuard,
2323
};
2424
// The TreeHash derive macro requires tree_hash as import
2525
pub mod tree_hash {

crates/pbs/src/api.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@ use cb_common::pbs::{
77

88
use crate::{
99
mev_boost,
10-
state::{BuilderApiState, InnerPbsState, PbsState},
10+
state::{BuilderApiState, PbsState, PbsStateGuard},
1111
};
1212

1313
#[async_trait]
1414
pub trait BuilderApi<S: BuilderApiState>: 'static {
1515
/// Use to extend the BuilderApi
16-
fn extra_routes() -> Option<Router<PbsState<S>>> {
16+
fn extra_routes() -> Option<Router<PbsStateGuard<S>>> {
1717
None
1818
}
1919

2020
/// https://ethereum.github.io/builder-specs/#/Builder/getHeader
2121
async fn get_header(
2222
params: GetHeaderParams,
2323
req_headers: HeaderMap,
24-
state: InnerPbsState<S>,
24+
state: PbsState<S>,
2525
) -> eyre::Result<Option<GetHeaderResponse>> {
2626
mev_boost::get_header(params, req_headers, state).await
2727
}
2828

2929
/// https://ethereum.github.io/builder-specs/#/Builder/status
30-
async fn get_status(req_headers: HeaderMap, state: InnerPbsState<S>) -> eyre::Result<()> {
30+
async fn get_status(req_headers: HeaderMap, state: PbsState<S>) -> eyre::Result<()> {
3131
mev_boost::get_status(req_headers, state).await
3232
}
3333

3434
/// https://ethereum.github.io/builder-specs/#/Builder/submitBlindedBlock
3535
async fn submit_block(
3636
signed_blinded_block: SignedBlindedBeaconBlock,
3737
req_headers: HeaderMap,
38-
state: InnerPbsState<S>,
38+
state: PbsState<S>,
3939
) -> eyre::Result<SubmitBlindedBlockResponse> {
4040
mev_boost::submit_block(signed_blinded_block, req_headers, state).await
4141
}
@@ -44,12 +44,12 @@ pub trait BuilderApi<S: BuilderApiState>: 'static {
4444
async fn register_validator(
4545
registrations: Vec<ValidatorRegistration>,
4646
req_headers: HeaderMap,
47-
state: InnerPbsState<S>,
47+
state: PbsState<S>,
4848
) -> eyre::Result<()> {
4949
mev_boost::register_validator(registrations, req_headers, state).await
5050
}
5151

52-
async fn reload(state: PbsState<S>) -> eyre::Result<()> {
52+
async fn reload(state: PbsStateGuard<S>) -> eyre::Result<()> {
5353
mev_boost::reload(state).await
5454
}
5555
}

crates/pbs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ pub use api::*;
1212
pub use constants::*;
1313
pub use mev_boost::*;
1414
pub use service::PbsService;
15-
pub use state::{BuilderApiState, InnerPbsState, PbsState};
15+
pub use state::{BuilderApiState, PbsState, PbsStateGuard};

crates/pbs/src/mev_boost/get_header.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{
3232
GET_HEADER_ENDPOINT_TAG, MAX_SIZE_GET_HEADER, TIMEOUT_ERROR_CODE, TIMEOUT_ERROR_CODE_STR,
3333
},
3434
metrics::{RELAY_HEADER_VALUE, RELAY_LAST_SLOT, RELAY_LATENCY, RELAY_STATUS_CODE},
35-
state::{BuilderApiState, InnerPbsState},
35+
state::{BuilderApiState, PbsState},
3636
utils::{check_gas_limit, read_chunked_body_with_max},
3737
};
3838

@@ -41,7 +41,7 @@ use crate::{
4141
pub async fn get_header<S: BuilderApiState>(
4242
params: GetHeaderParams,
4343
req_headers: HeaderMap,
44-
state: InnerPbsState<S>,
44+
state: PbsState<S>,
4545
) -> eyre::Result<Option<GetHeaderResponse>> {
4646
let parent_block = Arc::new(RwLock::new(None));
4747
if state.extra_validation_enabled() {

crates/pbs/src/mev_boost/register_validator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use url::Url;
1515
use crate::{
1616
constants::{MAX_SIZE_DEFAULT, REGISTER_VALIDATOR_ENDPOINT_TAG, TIMEOUT_ERROR_CODE_STR},
1717
metrics::{RELAY_LATENCY, RELAY_STATUS_CODE},
18-
state::{BuilderApiState, InnerPbsState},
18+
state::{BuilderApiState, PbsState},
1919
utils::read_chunked_body_with_max,
2020
};
2121

@@ -24,7 +24,7 @@ use crate::{
2424
pub async fn register_validator<S: BuilderApiState>(
2525
registrations: Vec<ValidatorRegistration>,
2626
req_headers: HeaderMap,
27-
state: InnerPbsState<S>,
27+
state: PbsState<S>,
2828
) -> eyre::Result<()> {
2929
// prepare headers
3030
let mut send_headers = HeaderMap::new();

crates/pbs/src/mev_boost/reload.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use cb_common::config::load_pbs_config;
22
use tracing::warn;
33

4-
use crate::{BuilderApiState, InnerPbsState, PbsState};
4+
use crate::{BuilderApiState, PbsState, PbsStateGuard};
55

66
/// Reload the PBS state with the latest configuration in the config file
77
/// Returns 200 if successful or 500 if failed
8-
pub async fn reload<S: BuilderApiState>(state: PbsState<S>) -> eyre::Result<()> {
9-
let prev_state = state.inner.read().await;
8+
pub async fn reload<S: BuilderApiState>(state: PbsStateGuard<S>) -> eyre::Result<()> {
9+
let prev_state = state.read().await;
1010

1111
let pbs_config = load_pbs_config().await?;
12-
let new_state = InnerPbsState::new(pbs_config).with_data(prev_state.data.clone());
12+
let new_state = PbsState::new(pbs_config).with_data(prev_state.data.clone());
1313

1414
if prev_state.config.pbs_config.host != new_state.config.pbs_config.host {
1515
warn!(
@@ -25,7 +25,7 @@ pub async fn reload<S: BuilderApiState>(state: PbsState<S>) -> eyre::Result<()>
2525
);
2626
}
2727

28-
*state.inner.write().await = new_state;
28+
*state.write().await = new_state;
2929

3030
Ok(())
3131
}

crates/pbs/src/mev_boost/status.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tracing::{debug, error};
1212
use crate::{
1313
constants::{MAX_SIZE_DEFAULT, STATUS_ENDPOINT_TAG, TIMEOUT_ERROR_CODE_STR},
1414
metrics::{RELAY_LATENCY, RELAY_STATUS_CODE},
15-
state::{BuilderApiState, InnerPbsState},
15+
state::{BuilderApiState, PbsState},
1616
utils::read_chunked_body_with_max,
1717
};
1818

@@ -21,7 +21,7 @@ use crate::{
2121
/// relay returns 200
2222
pub async fn get_status<S: BuilderApiState>(
2323
req_headers: HeaderMap,
24-
state: InnerPbsState<S>,
24+
state: PbsState<S>,
2525
) -> eyre::Result<()> {
2626
// If no relay check, return early
2727
if !state.config.pbs_config.relay_check {

crates/pbs/src/mev_boost/submit_block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ use url::Url;
1717
use crate::{
1818
constants::{MAX_SIZE_SUBMIT_BLOCK, SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG, TIMEOUT_ERROR_CODE_STR},
1919
metrics::{RELAY_LATENCY, RELAY_STATUS_CODE},
20-
state::{BuilderApiState, InnerPbsState},
20+
state::{BuilderApiState, PbsState},
2121
utils::read_chunked_body_with_max,
2222
};
2323

2424
/// Implements https://ethereum.github.io/builder-specs/#/Builder/submitBlindedBlock
2525
pub async fn submit_block<S: BuilderApiState>(
2626
signed_blinded_block: SignedBlindedBeaconBlock,
2727
req_headers: HeaderMap,
28-
state: InnerPbsState<S>,
28+
state: PbsState<S>,
2929
) -> eyre::Result<SubmitBlindedBlockResponse> {
3030
// prepare headers
3131
let mut send_headers = HeaderMap::new();

crates/pbs/src/routes/get_header.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ use crate::{
1717
constants::GET_HEADER_ENDPOINT_TAG,
1818
error::PbsClientError,
1919
metrics::BEACON_NODE_STATUS,
20-
state::{BuilderApiState, PbsState},
20+
state::{BuilderApiState, PbsStateGuard},
2121
};
2222

2323
#[tracing::instrument(skip_all, name = "get_header", fields(req_id = %Uuid::new_v4(), slot = params.slot))]
2424
pub async fn handle_get_header<S: BuilderApiState, A: BuilderApi<S>>(
25-
State(state): State<PbsState<S>>,
25+
State(state): State<PbsStateGuard<S>>,
2626
req_headers: HeaderMap,
2727
Path(params): Path<GetHeaderParams>,
2828
) -> Result<impl IntoResponse, PbsClientError> {
29-
let state = state.inner.read().await;
29+
let state = state.read().await;
3030

3131
state.publish_event(BuilderEvent::GetHeaderRequest(params));
3232

0 commit comments

Comments
 (0)