Skip to content

Commit 9eb26c6

Browse files
committed
Remove all debugs
1 parent ea8ee59 commit 9eb26c6

File tree

4 files changed

+23
-208
lines changed

4 files changed

+23
-208
lines changed

builder-server/src/server.rs

Lines changed: 4 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use axum::{
99
Json, Router,
1010
};
1111
use builder_api_types::{
12-
eth_spec::EthSpec, fork_versioned_response::ForkVersionDecode, ExecutionBlockHash, ForkName,
13-
FullPayloadContents, MainnetEthSpec, PublicKeyBytes, SignedBlindedBeaconBlock,
12+
EthSpec, ExecutionBlockHash, PublicKeyBytes, SignedBlindedBeaconBlock,
1413
SignedValidatorRegistrationData, Slot,
1514
};
1615
use ethereum_apis_common::{
@@ -57,7 +56,7 @@ where
5756
A: Builder<E>,
5857
{
5958
let res = api_impl.as_ref().register_validators(registrations).await;
60-
build_response(res).await
59+
build_response(res)
6160
}
6261

6362
async fn submit_blinded_block<I, A, E>(
@@ -70,7 +69,6 @@ where
7069
I: AsRef<A> + Send + Sync,
7170
A: Builder<E>,
7271
{
73-
dbg!(&headers);
7472
let content_type_header = headers.get(CONTENT_TYPE);
7573
let content_type = content_type_header.and_then(|value| value.to_str().ok());
7674
let content_type = match content_type {
@@ -81,12 +79,7 @@ where
8179

8280
let res = api_impl.as_ref().submit_blinded_block(block).await;
8381

84-
println!("in submit_blinded_block");
85-
let response =
86-
build_response_with_headers(res, content_type, api_impl.as_ref().fork_name_at_slot(slot))
87-
.await;
88-
println!("Got response ok {}", response.is_ok());
89-
response
82+
build_response_with_headers(res, content_type, api_impl.as_ref().fork_name_at_slot(slot))
9083
}
9184

9285
async fn get_status() -> StatusCode {
@@ -123,112 +116,5 @@ where
123116
.get_header(slot, parent_hash, pubkey)
124117
.await;
125118
tracing::info!("Got response from builder, constructing response");
126-
build_response_with_headers(res, content_type, api_impl.as_ref().fork_name_at_slot(slot)).await
127-
}
128-
129-
#[cfg(test)]
130-
mod tests {
131-
use super::*;
132-
use async_trait::async_trait;
133-
use axum::{body::Body, http::Request};
134-
use builder_api_types::{
135-
builder_bid::SignedBuilderBid, BeaconBlock, BeaconBlockDeneb, Blob, BlobsBundle,
136-
EmptyBlock, ExecutionPayload, ExecutionPayloadAndBlobs, ExecutionPayloadDeneb, ForkName,
137-
ForkVersionDecode, FullPayloadContents, KzgCommitment, KzgProof, MainnetEthSpec, Signature,
138-
};
139-
use ethereum_apis_common::{ErrorResponse, CONSENSUS_VERSION_HEADER};
140-
use http::HeaderValue;
141-
use ssz::Encode;
142-
use std::{marker::PhantomData, usize};
143-
use tower::ServiceExt;
144-
145-
#[derive(Clone)]
146-
struct DummyBuilder<E: EthSpec> {
147-
_phantom: PhantomData<E>,
148-
}
149-
150-
impl<E: EthSpec> AsRef<DummyBuilder<E>> for DummyBuilder<E> {
151-
fn as_ref(&self) -> &DummyBuilder<E> {
152-
self
153-
}
154-
}
155-
156-
#[async_trait]
157-
impl<E: EthSpec> Builder<E> for DummyBuilder<E> {
158-
fn fork_name_at_slot(&self, _slot: Slot) -> builder_api_types::ForkName {
159-
ForkName::Deneb
160-
}
161-
162-
async fn get_header(
163-
&self,
164-
_slot: Slot,
165-
_parent_hash: ExecutionBlockHash,
166-
_pubkey: PublicKeyBytes,
167-
) -> Result<SignedBuilderBid<E>, ErrorResponse> {
168-
todo!()
169-
}
170-
171-
async fn register_validators(
172-
&self,
173-
_registrations: Vec<SignedValidatorRegistrationData>,
174-
) -> Result<(), ErrorResponse> {
175-
Ok(())
176-
}
177-
178-
async fn submit_blinded_block(
179-
&self,
180-
_block: SignedBlindedBeaconBlock<E>,
181-
) -> Result<FullPayloadContents<E>, ErrorResponse> {
182-
let payload_and_blobs: ExecutionPayloadAndBlobs<E> = ExecutionPayloadAndBlobs {
183-
blobs_bundle: BlobsBundle {
184-
commitments: vec![KzgCommitment::empty_for_testing()].into(),
185-
proofs: vec![KzgProof::empty()].into(),
186-
blobs: vec![Blob::<E>::new(vec![42; E::bytes_per_blob()]).unwrap()].into(),
187-
},
188-
execution_payload: ExecutionPayload::Deneb(ExecutionPayloadDeneb {
189-
..Default::default()
190-
}),
191-
};
192-
let full_payload = FullPayloadContents::PayloadAndBlobs(payload_and_blobs);
193-
Ok(full_payload)
194-
}
195-
}
196-
197-
#[tokio::test]
198-
async fn test_api() {
199-
let app = new(DummyBuilder::<MainnetEthSpec> {
200-
_phantom: PhantomData,
201-
});
202-
203-
let spec = MainnetEthSpec::default_spec();
204-
let dummy_block = SignedBlindedBeaconBlock::<MainnetEthSpec>::from_block(
205-
BeaconBlock::Deneb(BeaconBlockDeneb::empty(&spec)),
206-
Signature::empty(),
207-
);
208-
let request = Request::builder()
209-
.uri("/eth/v1/builder/blinded_blocks")
210-
.method("POST")
211-
.header(
212-
CONTENT_TYPE,
213-
HeaderValue::from_static("application/octet-stream"),
214-
)
215-
.header(CONSENSUS_VERSION_HEADER, HeaderValue::from_static("deneb"))
216-
.body(Body::from(dummy_block.as_ssz_bytes()))
217-
.unwrap();
218-
219-
let response = app.oneshot(request).await.unwrap();
220-
221-
// Assert status code
222-
// assert_eq!(response.status(), StatusCode::ACCEPTED);
223-
224-
// Get response body as bytes
225-
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
226-
.await
227-
.unwrap();
228-
229-
dbg!(
230-
FullPayloadContents::<MainnetEthSpec>::from_ssz_bytes_by_fork(&body, ForkName::Deneb)
231-
.unwrap()
232-
);
233-
}
119+
build_response_with_headers(res, content_type, api_impl.as_ref().fork_name_at_slot(slot))
234120
}

common/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ http.workspace = true
1414
mediatype.workspace = true
1515
serde.workspace = true
1616
serde_json.workspace = true
17-
tokio.workspace = true
1817
tracing.workspace = true
1918
beacon-api-types = { path = "../beacon-api-types" }

common/src/lib.rs

Lines changed: 10 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use tracing::error;
1919

2020
pub const CONSENSUS_VERSION_HEADER: &str = "Eth-Consensus-Version";
2121

22-
pub async fn build_response_with_headers<T>(
22+
pub fn build_response_with_headers<T>(
2323
result: Result<T, ErrorResponse>,
2424
content_type: ContentType,
2525
fork_name: ForkName,
@@ -31,10 +31,6 @@ where
3131

3232
let resp = match result {
3333
Ok(body) => {
34-
println!(
35-
"Got a valid response from builder, content-type {:?}",
36-
content_type
37-
);
3834
let mut response = response_builder.status(200);
3935

4036
if let Some(response_headers) = response.headers_mut() {
@@ -54,7 +50,6 @@ where
5450
})?,
5551
);
5652
}
57-
dbg!(&content_type);
5853
let body_content = match content_type {
5954
ContentType::Json => {
6055
let body = ForkVersionedResponse {
@@ -70,11 +65,10 @@ where
7065

7166
ContentType::Ssz => T::as_ssz_bytes(&body),
7267
};
73-
let resp = response.body(Body::from(body_content)).map_err(|e| {
68+
response.body(Body::from(body_content)).map_err(|e| {
7469
error!(error = ?e);
7570
StatusCode::INTERNAL_SERVER_ERROR
76-
});
77-
resp
71+
})
7872
}
7973
Err(body) => {
8074
let mut response = response_builder.status(body.code);
@@ -89,17 +83,10 @@ where
8983
);
9084
}
9185

92-
let body_content = tokio::task::spawn_blocking(move || {
93-
serde_json::to_vec(&body).map_err(|e| {
94-
error!(error = ?e);
95-
StatusCode::INTERNAL_SERVER_ERROR
96-
})
97-
})
98-
.await
99-
.map_err(|e| {
86+
let body_content = serde_json::to_vec(&body).map_err(|e| {
10087
error!(error = ?e);
10188
StatusCode::INTERNAL_SERVER_ERROR
102-
})??;
89+
})?;
10390

10491
response.body(Body::from(body_content)).map_err(|e| {
10592
error!(error = ?e);
@@ -111,9 +98,7 @@ where
11198
resp
11299
}
113100

114-
pub async fn build_response<T>(
115-
result: Result<T, ErrorResponse>,
116-
) -> Result<Response<Body>, StatusCode>
101+
pub fn build_response<T>(result: Result<T, ErrorResponse>) -> Result<Response<Body>, StatusCode>
117102
where
118103
T: Serialize + Send + 'static,
119104
{
@@ -133,17 +118,10 @@ where
133118
);
134119
}
135120

136-
let body_content = tokio::task::spawn_blocking(move || {
137-
serde_json::to_vec(&body).map_err(|e| {
138-
error!(error = ?e);
139-
StatusCode::INTERNAL_SERVER_ERROR
140-
})
141-
})
142-
.await
143-
.map_err(|e| {
121+
let body_content = serde_json::to_vec(&body).map_err(|e| {
144122
error!(error = ?e);
145123
StatusCode::INTERNAL_SERVER_ERROR
146-
})??;
124+
})?;
147125

148126
response.body(Body::from(body_content)).map_err(|e| {
149127
error!(error = ?e);
@@ -163,17 +141,10 @@ where
163141
);
164142
}
165143

166-
let body_content = tokio::task::spawn_blocking(move || {
167-
serde_json::to_vec(&body).map_err(|e| {
168-
error!(error = ?e);
169-
StatusCode::INTERNAL_SERVER_ERROR
170-
})
171-
})
172-
.await
173-
.map_err(|e| {
144+
let body_content = serde_json::to_vec(&body).map_err(|e| {
174145
error!(error = ?e);
175146
StatusCode::INTERNAL_SERVER_ERROR
176-
})??;
147+
})?;
177148

178149
response.body(Body::from(body_content)).map_err(|e| {
179150
error!(error = ?e);
@@ -526,44 +497,3 @@ impl FromStr for Accept {
526497
accept_type.ok_or_else(|| "accept header is not supported".to_string())
527498
}
528499
}
529-
530-
#[cfg(test)]
531-
mod tests {
532-
// use std::usize;
533-
534-
use super::*;
535-
// use axum::body::to_bytes;
536-
use beacon_api_types::{
537-
Blob, BlobsBundle, EthSpec, ExecutionPayload, ExecutionPayloadAndBlobs,
538-
ExecutionPayloadDeneb, FullPayloadContents, KzgCommitment, KzgProof, MainnetEthSpec,
539-
};
540-
541-
#[tokio::test]
542-
async fn test_something() {
543-
let payload_and_blobs: ExecutionPayloadAndBlobs<MainnetEthSpec> =
544-
ExecutionPayloadAndBlobs {
545-
blobs_bundle: BlobsBundle {
546-
commitments: vec![KzgCommitment::empty_for_testing()].into(),
547-
proofs: vec![KzgProof::empty()].into(),
548-
blobs: vec![Blob::<MainnetEthSpec>::new(vec![
549-
42;
550-
MainnetEthSpec::bytes_per_blob()
551-
])
552-
.unwrap()]
553-
.into(),
554-
},
555-
execution_payload: ExecutionPayload::Deneb(ExecutionPayloadDeneb {
556-
..Default::default()
557-
}),
558-
};
559-
let full_payload = FullPayloadContents::PayloadAndBlobs(payload_and_blobs);
560-
let resp = build_response_with_headers(Ok(full_payload), ContentType::Ssz, ForkName::Deneb)
561-
.await
562-
.unwrap();
563-
dbg!(&resp);
564-
// let body = to_bytes(resp.into_body(), usize::MAX).await.unwrap();
565-
// dbg!(&body.len());
566-
// FullPayloadContents::<MainnetEthSpec>::from_ssz_bytes_by_fork(&body, ForkName::Deneb)
567-
// .unwrap();
568-
}
569-
}

relay-server/src/server.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ where
7171
A: Builder<E>,
7272
{
7373
let result = api_impl.as_ref().submit_block(query_params, body).await;
74-
build_response(result).await
74+
build_response(result)
7575
}
7676

7777
/// SubmitBlockOptimisticV2 - POST /relay/v1/builder/blocks_optimistic_v2
@@ -90,7 +90,7 @@ where
9090
.as_ref()
9191
.submit_block_optimistic_v2(query_params, body)
9292
.await;
93-
build_response(result).await
93+
build_response(result)
9494
}
9595

9696
/// SubmitHeader - POST /relay/v1/builder/headers
@@ -106,7 +106,7 @@ where
106106
A: Builder<E>,
107107
{
108108
let result = api_impl.as_ref().submit_header(query_params, body).await;
109-
build_response(result).await
109+
build_response(result)
110110
}
111111

112112
/// SubmitCancellation - POST /relay/v1/builder/cancel_bid
@@ -121,7 +121,7 @@ where
121121
A: Builder<E>,
122122
{
123123
let result = api_impl.as_ref().submit_cancellation(body).await;
124-
build_response(result).await
124+
build_response(result)
125125
}
126126

127127
/// GetValidators - GET /relay/v1/builder/validators
@@ -133,7 +133,7 @@ where
133133
E: EthSpec,
134134
{
135135
let result = api_impl.as_ref().get_validators().await;
136-
build_response(result).await
136+
build_response(result)
137137
}
138138

139139
/// GetTopBids - GET /relay/v1/builder/top_bids
@@ -173,7 +173,7 @@ where
173173
while let Some(update) = stream.next().await {
174174
match serde_json::to_string(&update) {
175175
Ok(json) => {
176-
if let Err(e) = sender.send(Message::Text(json)).await {
176+
if let Err(e) = sender.send(Message::text(json)).await {
177177
tracing::error!("Error sending message: {:?}", e);
178178
break;
179179
}
@@ -213,7 +213,7 @@ where
213213
A: Data,
214214
{
215215
let result = api_impl.as_ref().get_delivered_payloads(query_params).await;
216-
build_response(result).await
216+
build_response(result)
217217
}
218218

219219
/// GetReceivedBids - GET /relay/v1/data/bidtraces/builder_blocks_received
@@ -227,7 +227,7 @@ where
227227
A: Data,
228228
{
229229
let result = api_impl.as_ref().get_received_bids(query_params).await;
230-
build_response(result).await
230+
build_response(result)
231231
}
232232

233233
/// GetValidatorRegistration - GET /relay/v1/data/validator_registration
@@ -244,5 +244,5 @@ where
244244
.as_ref()
245245
.get_validator_registration(query_params)
246246
.await;
247-
build_response(result).await
247+
build_response(result)
248248
}

0 commit comments

Comments
 (0)