Skip to content

Commit 150f692

Browse files
authored
Add blinded blocks v2 (#352)
1 parent 0e1b9d4 commit 150f692

26 files changed

+280
-145
lines changed

crates/cli/src/docker_init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use cb_common::{
1717
SIGNER_DIR_SECRETS_ENV, SIGNER_ENDPOINT_ENV, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME,
1818
SIGNER_PORT_DEFAULT, SIGNER_URL_ENV,
1919
},
20-
pbs::{BUILDER_API_PATH, GET_STATUS_PATH},
20+
pbs::{BUILDER_V1_API_PATH, GET_STATUS_PATH},
2121
signer::{ProxyStore, SignerLoader},
2222
types::ModuleId,
2323
utils::random_jwt_secret,
@@ -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/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: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use serde::{Deserialize, Serialize};
1010
use url::Url;
1111

1212
use super::{
13-
constants::{BUILDER_API_PATH, GET_STATUS_PATH, REGISTER_VALIDATOR_PATH, SUBMIT_BLOCK_PATH},
13+
constants::{GET_STATUS_PATH, REGISTER_VALIDATOR_PATH, SUBMIT_BLOCK_PATH},
1414
error::PbsError,
1515
HEADER_VERSION_KEY, HEADER_VERSION_VALUE,
1616
};
17-
use crate::{config::RelayConfig, DEFAULT_REQUEST_TIMEOUT};
17+
use crate::{config::RelayConfig, pbs::BuilderApiVersion, DEFAULT_REQUEST_TIMEOUT};
1818

1919
/// A parsed entry of the relay url in the format: scheme://pubkey@host
2020
#[derive(Debug, Clone)]
@@ -101,8 +101,12 @@ impl RelayClient {
101101

102102
Ok(url)
103103
}
104-
pub fn builder_api_url(&self, path: &str) -> Result<Url, PbsError> {
105-
self.get_url(&format!("{BUILDER_API_PATH}{path}"))
104+
pub fn builder_api_url(
105+
&self,
106+
path: &str,
107+
api_version: BuilderApiVersion,
108+
) -> Result<Url, PbsError> {
109+
self.get_url(&format!("{}{path}", api_version.path()))
106110
}
107111

108112
pub fn get_header_url(
@@ -111,19 +115,22 @@ impl RelayClient {
111115
parent_hash: B256,
112116
validator_pubkey: BlsPublicKey,
113117
) -> Result<Url, PbsError> {
114-
self.builder_api_url(&format!("/header/{slot}/{parent_hash}/{validator_pubkey}"))
118+
self.builder_api_url(
119+
&format!("/header/{slot}/{parent_hash}/{validator_pubkey}"),
120+
BuilderApiVersion::V1,
121+
)
115122
}
116123

117124
pub fn get_status_url(&self) -> Result<Url, PbsError> {
118-
self.builder_api_url(GET_STATUS_PATH)
125+
self.builder_api_url(GET_STATUS_PATH, BuilderApiVersion::V1)
119126
}
120127

121128
pub fn register_validator_url(&self) -> Result<Url, PbsError> {
122-
self.builder_api_url(REGISTER_VALIDATOR_PATH)
129+
self.builder_api_url(REGISTER_VALIDATOR_PATH, BuilderApiVersion::V1)
123130
}
124131

125-
pub fn submit_block_url(&self) -> Result<Url, PbsError> {
126-
self.builder_api_url(SUBMIT_BLOCK_PATH)
132+
pub fn submit_block_url(&self, api_version: BuilderApiVersion) -> Result<Url, PbsError> {
133+
self.builder_api_url(SUBMIT_BLOCK_PATH, api_version)
127134
}
128135
}
129136

crates/common/src/pbs/types/beacon_block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ mod tests {
9999
// this is from mev-boost test data
100100
fn test_signed_blinded_block_fb_electra() {
101101
let data = include_str!("testdata/signed-blinded-beacon-block-electra.json");
102-
let block = test_encode_decode::<SignedBlindedBeaconBlock>(&data);
102+
let block = test_encode_decode::<SignedBlindedBeaconBlock>(data);
103103
assert!(matches!(block.message, BlindedBeaconBlock::Electra(_)));
104104
}
105105

@@ -166,7 +166,7 @@ mod tests {
166166
// this is dummy data generated with https://github.com/attestantio/go-eth2-client
167167
fn test_signed_blinded_block_ssz() {
168168
let data_json = include_str!("testdata/signed-blinded-beacon-block-electra-2.json");
169-
let block_json = test_encode_decode::<SignedBlindedBeaconBlock>(&data_json);
169+
let block_json = test_encode_decode::<SignedBlindedBeaconBlock>(data_json);
170170
assert!(matches!(block_json.message, BlindedBeaconBlock::Electra(_)));
171171

172172
let data_ssz = include_bytes!("testdata/signed-blinded-beacon-block-electra-2.ssz");
@@ -181,7 +181,7 @@ mod tests {
181181
// this is dummy data generated with https://github.com/attestantio/go-builder-client
182182
fn test_execution_payload_block_ssz() {
183183
let data_json = include_str!("testdata/execution-payload-electra.json");
184-
let block_json = test_encode_decode::<PayloadAndBlobsElectra>(&data_json);
184+
let block_json = test_encode_decode::<PayloadAndBlobsElectra>(data_json);
185185

186186
let data_ssz = include_bytes!("testdata/execution-payload-electra.ssz");
187187
let data_ssz = alloy::primitives::hex::decode(data_ssz).unwrap();

crates/common/src/pbs/types/execution_payload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ mod tests {
129129
"excess_blob_gas": "95158272"
130130
}"#;
131131

132-
let parsed = test_encode_decode::<ExecutionPayloadHeader<ElectraSpec>>(&data);
132+
let parsed = test_encode_decode::<ExecutionPayloadHeader<ElectraSpec>>(data);
133133

134134
assert_eq!(
135135
parsed.parent_hash,

crates/common/src/pbs/types/get_header.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ mod tests {
166166
}
167167
}"#;
168168

169-
let parsed = test_encode_decode::<GetHeaderResponse>(&data);
169+
let parsed = test_encode_decode::<GetHeaderResponse>(data);
170170
let VersionedResponse::Electra(parsed) = parsed;
171171

172172
assert_eq!(parsed.message.value, U256::from(1));
@@ -187,7 +187,7 @@ mod tests {
187187
let data_json = include_str!("testdata/get-header-response.json");
188188
let block_json = test_encode_decode::<
189189
SignedExecutionPayloadHeader<ExecutionPayloadHeaderMessageElectra>,
190-
>(&data_json);
190+
>(data_json);
191191

192192
let data_ssz = include_bytes!("testdata/get-header-response.ssz");
193193
let data_ssz = alloy::primitives::hex::decode(data_ssz).unwrap();

crates/common/src/signer/store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,12 @@ mod test {
542542
.join(consensus_signer.pubkey().to_string())
543543
.join("TEST_MODULE")
544544
.join("bls")
545-
.join(format!("{}.json", proxy_signer.pubkey().to_string()));
545+
.join(format!("{}.json", proxy_signer.pubkey()));
546546
let sig_path = keys_path
547547
.join(consensus_signer.pubkey().to_string())
548548
.join("TEST_MODULE")
549549
.join("bls")
550-
.join(format!("{}.sig", proxy_signer.pubkey().to_string()));
550+
.join(format!("{}.sig", proxy_signer.pubkey()));
551551
let pass_path = secrets_path
552552
.join(consensus_signer.pubkey().to_string())
553553
.join("TEST_MODULE")
@@ -674,7 +674,7 @@ mod test {
674674
.join(consensus_signer.pubkey().to_string())
675675
.join("TEST_MODULE")
676676
.join("bls")
677-
.join(format!("{}.sig", proxy_signer.pubkey().to_string()))
677+
.join(format!("{}.sig", proxy_signer.pubkey()))
678678
)
679679
.unwrap()
680680
)

0 commit comments

Comments
 (0)