Skip to content

Commit 527e63b

Browse files
committed
Merge branch 'main' into lt/unify-bls
2 parents a9cfc36 + 7d32afb commit 527e63b

33 files changed

+348
-185
lines changed

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resolver = "2"
55
[workspace.package]
66
edition = "2021"
77
rust-version = "1.83"
8-
version = "0.8.0"
8+
version = "0.8.1-rc.1"
99

1010
[workspace.dependencies]
1111
aes = "0.8"

crates/cli/src/docker_init.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use cb_common::{
1515
PROXY_DIR_KEYS_ENV, PROXY_DIR_SECRETS_DEFAULT, PROXY_DIR_SECRETS_ENV, SIGNER_DEFAULT,
1616
SIGNER_DIR_KEYS_DEFAULT, SIGNER_DIR_KEYS_ENV, SIGNER_DIR_SECRETS_DEFAULT,
1717
SIGNER_DIR_SECRETS_ENV, SIGNER_ENDPOINT_ENV, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME,
18-
SIGNER_URL_ENV,
18+
SIGNER_PORT_DEFAULT, SIGNER_URL_ENV,
1919
},
20-
pbs::{BUILDER_API_PATH, GET_STATUS_PATH},
21-
signer::{ProxyStore, SignerLoader, DEFAULT_SIGNER_PORT},
20+
pbs::{BUILDER_V1_API_PATH, GET_STATUS_PATH},
21+
signer::{ProxyStore, SignerLoader},
2222
types::ModuleId,
2323
utils::random_jwt_secret,
2424
};
@@ -73,7 +73,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
7373
let mut targets = Vec::new();
7474

7575
// address for signer API communication
76-
let signer_port = cb_config.signer.as_ref().map(|s| s.port).unwrap_or(DEFAULT_SIGNER_PORT);
76+
let signer_port = cb_config.signer.as_ref().map(|s| s.port).unwrap_or(SIGNER_PORT_DEFAULT);
7777
let signer_server =
7878
if let Some(SignerConfig { inner: SignerType::Remote { url }, .. }) = &cb_config.signer {
7979
url.to_string()
@@ -308,7 +308,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
308308
healthcheck: Some(Healthcheck {
309309
test: Some(HealthcheckTest::Single(format!(
310310
"curl -f http://localhost:{}{}{}",
311-
cb_config.pbs.pbs_config.port, BUILDER_API_PATH, GET_STATUS_PATH
311+
cb_config.pbs.pbs_config.port, BUILDER_V1_API_PATH, GET_STATUS_PATH
312312
))),
313313
interval: Some("30s".into()),
314314
timeout: Some("5s".into()),

crates/common/src/config/constants.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ pub const SIGNER_MODULE_NAME: &str = "signer";
3434

3535
/// Where the signer module should open the server
3636
pub const SIGNER_ENDPOINT_ENV: &str = "CB_SIGNER_ENDPOINT";
37+
pub const SIGNER_PORT_DEFAULT: u16 = 20000;
3738

38-
// JWT authentication settings
39+
/// Number of auth failures before rate limiting the client
3940
pub const SIGNER_JWT_AUTH_FAIL_LIMIT_ENV: &str = "CB_SIGNER_JWT_AUTH_FAIL_LIMIT";
41+
pub const SIGNER_JWT_AUTH_FAIL_LIMIT_DEFAULT: u32 = 3;
42+
43+
/// How long to rate limit the client after auth failures
4044
pub const SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_ENV: &str =
4145
"CB_SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS";
46+
pub const SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_DEFAULT: u32 = 5 * 60;
4247

4348
/// Comma separated list module_id=jwt_secret
4449
pub const JWTS_ENV: &str = "CB_JWTS";

crates/common/src/config/signer.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ use url::Url;
1212

1313
use super::{
1414
load_jwt_secrets, load_optional_env_var, utils::load_env_var, CommitBoostConfig,
15-
SIGNER_ENDPOINT_ENV, SIGNER_IMAGE_DEFAULT, SIGNER_JWT_AUTH_FAIL_LIMIT_ENV,
16-
SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_ENV,
15+
SIGNER_ENDPOINT_ENV, SIGNER_IMAGE_DEFAULT, SIGNER_JWT_AUTH_FAIL_LIMIT_DEFAULT,
16+
SIGNER_JWT_AUTH_FAIL_LIMIT_ENV, SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_DEFAULT,
17+
SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_ENV, SIGNER_PORT_DEFAULT,
1718
};
1819
use crate::{
1920
config::{DIRK_CA_CERT_ENV, DIRK_CERT_ENV, DIRK_DIR_SECRETS_ENV, DIRK_KEY_ENV},
20-
signer::{
21-
ProxyStore, SignerLoader, DEFAULT_JWT_AUTH_FAIL_LIMIT,
22-
DEFAULT_JWT_AUTH_FAIL_TIMEOUT_SECONDS, DEFAULT_SIGNER_PORT,
23-
},
21+
signer::{ProxyStore, SignerLoader},
2422
types::{Chain, ModuleId},
2523
utils::{default_host, default_u16, default_u32},
2624
};
@@ -32,20 +30,20 @@ pub struct SignerConfig {
3230
#[serde(default = "default_host")]
3331
pub host: Ipv4Addr,
3432
/// Port to listen for signer API calls on
35-
#[serde(default = "default_u16::<DEFAULT_SIGNER_PORT>")]
33+
#[serde(default = "default_u16::<SIGNER_PORT_DEFAULT>")]
3634
pub port: u16,
3735
/// Docker image of the module
38-
#[serde(default = "default_signer")]
36+
#[serde(default = "default_signer_image")]
3937
pub docker_image: String,
4038

4139
/// Number of JWT auth failures before rate limiting an endpoint
4240
/// If set to 0, no rate limiting will be applied
43-
#[serde(default = "default_u32::<DEFAULT_JWT_AUTH_FAIL_LIMIT>")]
41+
#[serde(default = "default_u32::<SIGNER_JWT_AUTH_FAIL_LIMIT_DEFAULT>")]
4442
pub jwt_auth_fail_limit: u32,
4543

4644
/// Duration in seconds to rate limit an endpoint after the JWT auth failure
4745
/// limit has been reached
48-
#[serde(default = "default_u32::<DEFAULT_JWT_AUTH_FAIL_TIMEOUT_SECONDS>")]
46+
#[serde(default = "default_u32::<SIGNER_JWT_AUTH_FAIL_TIMEOUT_SECONDS_DEFAULT>")]
4947
pub jwt_auth_fail_timeout_seconds: u32,
5048

5149
/// Inner type-specific configuration
@@ -70,7 +68,7 @@ impl SignerConfig {
7068
}
7169
}
7270

73-
fn default_signer() -> String {
71+
fn default_signer_image() -> String {
7472
SIGNER_IMAGE_DEFAULT.to_string()
7573
}
7674

crates/common/src/pbs/builder.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::fmt::{Display, Formatter, Result};
2+
3+
use serde::{Deserialize, Serialize};
4+
5+
use crate::pbs::{BUILDER_V1_API_PATH, BUILDER_V2_API_PATH};
6+
7+
// Version of the builder API for various routes
8+
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]
9+
#[serde(rename_all = "lowercase")]
10+
pub enum BuilderApiVersion {
11+
V1 = 1,
12+
V2,
13+
}
14+
impl BuilderApiVersion {
15+
pub const fn path(&self) -> &'static str {
16+
match self {
17+
BuilderApiVersion::V1 => BUILDER_V1_API_PATH,
18+
BuilderApiVersion::V2 => BUILDER_V2_API_PATH,
19+
}
20+
}
21+
}
22+
impl Display for BuilderApiVersion {
23+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
24+
let s = match self {
25+
BuilderApiVersion::V1 => "v1",
26+
BuilderApiVersion::V2 => "v2",
27+
};
28+
write!(f, "{}", s)
29+
}
30+
}

crates/common/src/pbs/constants.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::constants::COMMIT_BOOST_VERSION;
22

3-
pub const BUILDER_API_PATH: &str = "/eth/v1/builder";
3+
pub const BUILDER_V1_API_PATH: &str = "/eth/v1/builder";
4+
pub const BUILDER_V2_API_PATH: &str = "/eth/v2/builder";
45

56
pub const GET_HEADER_PATH: &str = "/header/{slot}/{parent_hash}/{pubkey}";
67
pub const GET_STATUS_PATH: &str = "/status";

crates/common/src/pbs/event.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::{
2020
};
2121
use crate::{
2222
config::{load_optional_env_var, BUILDER_URLS_ENV, HTTP_TIMEOUT_SECONDS_DEFAULT},
23-
pbs::BUILDER_EVENTS_PATH,
23+
pbs::{BuilderApiVersion, BUILDER_EVENTS_PATH},
2424
};
2525

2626
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -29,8 +29,9 @@ pub enum BuilderEvent {
2929
GetHeaderResponse(Box<Option<GetHeaderResponse>>),
3030
GetStatusEvent,
3131
GetStatusResponse,
32-
SubmitBlockRequest(Box<SignedBlindedBeaconBlock>),
33-
SubmitBlockResponse(Box<SubmitBlindedBlockResponse>),
32+
SubmitBlockRequest(Box<SignedBlindedBeaconBlock>, BuilderApiVersion),
33+
SubmitBlockResponseV1(Box<SubmitBlindedBlockResponse>),
34+
SubmitBlockResponseV2,
3435
MissedPayload {
3536
/// Hash for the block for which no payload was received
3637
block_hash: B256,

crates/common/src/pbs/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
mod builder;
12
mod constants;
23
pub mod error;
34
mod event;
45
mod relay;
56
mod types;
67

8+
pub use builder::*;
79
pub use constants::*;
810
pub use event::*;
911
pub use relay::*;

crates/common/src/pbs/relay.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ use serde::{Deserialize, Serialize};
77
use url::Url;
88

99
use super::{
10-
constants::{BUILDER_API_PATH, GET_STATUS_PATH, REGISTER_VALIDATOR_PATH, SUBMIT_BLOCK_PATH},
10+
constants::{GET_STATUS_PATH, REGISTER_VALIDATOR_PATH, SUBMIT_BLOCK_PATH},
1111
error::PbsError,
1212
HEADER_VERSION_KEY, HEADER_VERSION_VALUE,
1313
};
14-
use crate::{config::RelayConfig, types::BlsPublicKey, DEFAULT_REQUEST_TIMEOUT};
14+
use crate::{
15+
config::RelayConfig, pbs::BuilderApiVersion, types::BlsPublicKey, DEFAULT_REQUEST_TIMEOUT,
16+
};
1517

1618
/// A parsed entry of the relay url in the format: scheme://pubkey@host
1719
#[derive(Debug, Clone)]
@@ -98,8 +100,12 @@ impl RelayClient {
98100

99101
Ok(url)
100102
}
101-
pub fn builder_api_url(&self, path: &str) -> Result<Url, PbsError> {
102-
self.get_url(&format!("{BUILDER_API_PATH}{path}"))
103+
pub fn builder_api_url(
104+
&self,
105+
path: &str,
106+
api_version: BuilderApiVersion,
107+
) -> Result<Url, PbsError> {
108+
self.get_url(&format!("{}{path}", api_version.path()))
103109
}
104110

105111
pub fn get_header_url(
@@ -108,19 +114,22 @@ impl RelayClient {
108114
parent_hash: &B256,
109115
validator_pubkey: &BlsPublicKey,
110116
) -> Result<Url, PbsError> {
111-
self.builder_api_url(&format!("/header/{slot}/{parent_hash}/{validator_pubkey}"))
117+
self.builder_api_url(
118+
&format!("/header/{slot}/{parent_hash}/{validator_pubkey}"),
119+
BuilderApiVersion::V1,
120+
)
112121
}
113122

114123
pub fn get_status_url(&self) -> Result<Url, PbsError> {
115-
self.builder_api_url(GET_STATUS_PATH)
124+
self.builder_api_url(GET_STATUS_PATH, BuilderApiVersion::V1)
116125
}
117126

118127
pub fn register_validator_url(&self) -> Result<Url, PbsError> {
119-
self.builder_api_url(REGISTER_VALIDATOR_PATH)
128+
self.builder_api_url(REGISTER_VALIDATOR_PATH, BuilderApiVersion::V1)
120129
}
121130

122-
pub fn submit_block_url(&self) -> Result<Url, PbsError> {
123-
self.builder_api_url(SUBMIT_BLOCK_PATH)
131+
pub fn submit_block_url(&self, api_version: BuilderApiVersion) -> Result<Url, PbsError> {
132+
self.builder_api_url(SUBMIT_BLOCK_PATH, api_version)
124133
}
125134
}
126135

0 commit comments

Comments
 (0)