Skip to content

Commit 248538a

Browse files
authored
feat: enable configuration hot-reloading (#231)
1 parent d396f7b commit 248538a

File tree

23 files changed

+224
-39
lines changed

23 files changed

+224
-39
lines changed

api/signer-api.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ info:
55
description: API that allows commit modules to request generic signatures from validators
66
tags:
77
- name: Signer
8+
- name: Management
89
paths:
910
/signer/v1/get_pubkeys:
1011
get:
@@ -254,6 +255,20 @@ paths:
254255
type: string
255256
example: "Internal error"
256257

258+
/status:
259+
get:
260+
summary: Get the status of the Signer API module
261+
tags:
262+
- Management
263+
responses:
264+
"200":
265+
description: Success
266+
content:
267+
text/plain:
268+
schema:
269+
type: string
270+
example: "OK"
271+
257272
components:
258273
securitySchemes:
259274
BearerAuth:

bin/src/lib.rs

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

crates/common/src/commit/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub const GET_PUBKEYS_PATH: &str = "/signer/v1/get_pubkeys";
22
pub const REQUEST_SIGNATURE_PATH: &str = "/signer/v1/request_signature";
33
pub const GENERATE_PROXY_KEY_PATH: &str = "/signer/v1/generate_proxy_key";
44
pub const STATUS_PATH: &str = "/status";
5+
pub const RELOAD_PATH: &str = "/reload";

crates/common/src/pbs/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub const GET_HEADER_PATH: &str = "/header/{slot}/{parent_hash}/{pubkey}";
66
pub const GET_STATUS_PATH: &str = "/status";
77
pub const REGISTER_VALIDATOR_PATH: &str = "/validators";
88
pub const SUBMIT_BLOCK_PATH: &str = "/blinded_blocks";
9+
pub const RELOAD_PATH: &str = "/reload";
910

1011
// https://ethereum.github.io/builder-specs/#/Builder
1112

crates/common/src/pbs/event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub enum BuilderEvent {
3737
},
3838
RegisterValidatorRequest(Vec<ValidatorRegistration>),
3939
RegisterValidatorResponse,
40+
ReloadEvent,
41+
ReloadResponse,
4042
}
4143

4244
#[derive(Debug, Clone)]

crates/pbs/src/api.rs

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

88
use crate::{
99
mev_boost,
10-
state::{BuilderApiState, 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

@@ -48,6 +48,10 @@ pub trait BuilderApi<S: BuilderApiState>: 'static {
4848
) -> eyre::Result<()> {
4949
mev_boost::register_validator(registrations, req_headers, state).await
5050
}
51+
52+
async fn reload(state: PbsState<S>) -> eyre::Result<PbsState<S>> {
53+
mev_boost::reload(state).await
54+
}
5155
}
5256

5357
pub struct DefaultBuilderApi;

crates/pbs/src/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub const STATUS_ENDPOINT_TAG: &str = "status";
22
pub const REGISTER_VALIDATOR_ENDPOINT_TAG: &str = "register_validator";
33
pub const SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG: &str = "submit_blinded_block";
44
pub const GET_HEADER_ENDPOINT_TAG: &str = "get_header";
5+
pub const RELOAD_ENDPOINT_TAG: &str = "reload";
56

67
/// For metrics recorded when a request times out
78
pub const TIMEOUT_ERROR_CODE: u16 = 555;

crates/pbs/src/error.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ use axum::{http::StatusCode, response::IntoResponse};
55
pub enum PbsClientError {
66
NoResponse,
77
NoPayload,
8+
Internal,
89
}
910

1011
impl PbsClientError {
1112
pub fn status_code(&self) -> StatusCode {
1213
match self {
1314
PbsClientError::NoResponse => StatusCode::BAD_GATEWAY,
1415
PbsClientError::NoPayload => StatusCode::BAD_GATEWAY,
16+
PbsClientError::Internal => StatusCode::INTERNAL_SERVER_ERROR,
1517
}
1618
}
1719
}
1820

1921
impl IntoResponse for PbsClientError {
2022
fn into_response(self) -> axum::response::Response {
21-
let msg = match self {
22-
PbsClientError::NoResponse => "no response from relays",
23-
PbsClientError::NoPayload => "no payload from relays",
23+
let msg = match &self {
24+
PbsClientError::NoResponse => "no response from relays".to_string(),
25+
PbsClientError::NoPayload => "no payload from relays".to_string(),
26+
PbsClientError::Internal => "internal server error".to_string(),
2427
};
2528

2629
(self.status_code(), msg).into_response()

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, PbsState};
15+
pub use state::{BuilderApiState, PbsState, PbsStateGuard};

crates/pbs/src/mev_boost/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
mod get_header;
22
mod register_validator;
3+
mod reload;
34
mod status;
45
mod submit_block;
56

67
pub use get_header::get_header;
78
pub use register_validator::register_validator;
9+
pub use reload::reload;
810
pub use status::get_status;
911
pub use submit_block::submit_block;

0 commit comments

Comments
 (0)