mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Add missing header to eth/v1/builder/blinded_blocks (#5407)
* add missing header * read header in mock builder * Merge branch 'unstable' into builder-blinded-blocks-missing-header
This commit is contained in:
@@ -5,7 +5,8 @@ use eth2::types::{
|
|||||||
};
|
};
|
||||||
use eth2::types::{FullPayloadContents, SignedBlindedBeaconBlock};
|
use eth2::types::{FullPayloadContents, SignedBlindedBeaconBlock};
|
||||||
pub use eth2::Error;
|
pub use eth2::Error;
|
||||||
use eth2::{ok_or_error, StatusCode};
|
use eth2::{ok_or_error, StatusCode, CONSENSUS_VERSION_HEADER};
|
||||||
|
use reqwest::header::{HeaderMap, HeaderValue};
|
||||||
use reqwest::{IntoUrl, Response};
|
use reqwest::{IntoUrl, Response};
|
||||||
use sensitive_url::SensitiveUrl;
|
use sensitive_url::SensitiveUrl;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
@@ -108,13 +109,20 @@ impl BuilderHttpClient {
|
|||||||
&self,
|
&self,
|
||||||
url: U,
|
url: U,
|
||||||
body: &T,
|
body: &T,
|
||||||
|
headers: HeaderMap,
|
||||||
timeout: Option<Duration>,
|
timeout: Option<Duration>,
|
||||||
) -> Result<Response, Error> {
|
) -> Result<Response, Error> {
|
||||||
let mut builder = self.client.post(url);
|
let mut builder = self.client.post(url);
|
||||||
if let Some(timeout) = timeout {
|
if let Some(timeout) = timeout {
|
||||||
builder = builder.timeout(timeout);
|
builder = builder.timeout(timeout);
|
||||||
}
|
}
|
||||||
let response = builder.json(body).send().await.map_err(Error::from)?;
|
|
||||||
|
let response = builder
|
||||||
|
.headers(headers)
|
||||||
|
.json(body)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(Error::from)?;
|
||||||
ok_or_error(response).await
|
ok_or_error(response).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,10 +159,16 @@ impl BuilderHttpClient {
|
|||||||
.push("builder")
|
.push("builder")
|
||||||
.push("blinded_blocks");
|
.push("blinded_blocks");
|
||||||
|
|
||||||
|
let mut headers = HeaderMap::new();
|
||||||
|
if let Ok(value) = HeaderValue::from_str(&blinded_block.fork_name_unchecked().to_string()) {
|
||||||
|
headers.insert(CONSENSUS_VERSION_HEADER, value);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(self
|
Ok(self
|
||||||
.post_with_raw_response(
|
.post_with_raw_response(
|
||||||
path,
|
path,
|
||||||
&blinded_block,
|
&blinded_block,
|
||||||
|
headers,
|
||||||
Some(self.timeouts.post_blinded_blocks),
|
Some(self.timeouts.post_blinded_blocks),
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::test_utils::{DEFAULT_BUILDER_PAYLOAD_VALUE_WEI, DEFAULT_JWT_SECRET};
|
use crate::test_utils::{DEFAULT_BUILDER_PAYLOAD_VALUE_WEI, DEFAULT_JWT_SECRET};
|
||||||
use crate::{Config, ExecutionLayer, PayloadAttributes};
|
use crate::{Config, ExecutionLayer, PayloadAttributes};
|
||||||
use eth2::types::{BlobsBundle, BlockId, StateId, ValidatorId};
|
use eth2::types::{BlobsBundle, BlockId, StateId, ValidatorId};
|
||||||
use eth2::{BeaconNodeHttpClient, Timeouts};
|
use eth2::{BeaconNodeHttpClient, Timeouts, CONSENSUS_VERSION_HEADER};
|
||||||
use fork_choice::ForkchoiceUpdateParameters;
|
use fork_choice::ForkchoiceUpdateParameters;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use sensitive_url::SensitiveUrl;
|
use sensitive_url::SensitiveUrl;
|
||||||
@@ -321,56 +321,57 @@ pub fn serve<E: EthSpec>(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let blinded_block = prefix
|
let blinded_block =
|
||||||
.and(warp::path("blinded_blocks"))
|
prefix
|
||||||
.and(warp::body::json())
|
.and(warp::path("blinded_blocks"))
|
||||||
.and(warp::path::end())
|
.and(warp::body::json())
|
||||||
.and(ctx_filter.clone())
|
.and(warp::header::header::<ForkName>(CONSENSUS_VERSION_HEADER))
|
||||||
.and_then(
|
.and(warp::path::end())
|
||||||
|block: SignedBlindedBeaconBlock<E>, builder: MockBuilder<E>| async move {
|
.and(ctx_filter.clone())
|
||||||
let slot = block.slot();
|
.and_then(
|
||||||
let root = match block {
|
|block: SignedBlindedBeaconBlock<E>,
|
||||||
SignedBlindedBeaconBlock::Base(_) | types::SignedBeaconBlock::Altair(_) => {
|
fork_name: ForkName,
|
||||||
return Err(reject("invalid fork"));
|
builder: MockBuilder<E>| async move {
|
||||||
}
|
let root = match block {
|
||||||
SignedBlindedBeaconBlock::Merge(block) => {
|
SignedBlindedBeaconBlock::Base(_) | types::SignedBeaconBlock::Altair(_) => {
|
||||||
block.message.body.execution_payload.tree_hash_root()
|
return Err(reject("invalid fork"));
|
||||||
}
|
}
|
||||||
SignedBlindedBeaconBlock::Capella(block) => {
|
SignedBlindedBeaconBlock::Merge(block) => {
|
||||||
block.message.body.execution_payload.tree_hash_root()
|
block.message.body.execution_payload.tree_hash_root()
|
||||||
}
|
}
|
||||||
SignedBlindedBeaconBlock::Deneb(block) => {
|
SignedBlindedBeaconBlock::Capella(block) => {
|
||||||
block.message.body.execution_payload.tree_hash_root()
|
block.message.body.execution_payload.tree_hash_root()
|
||||||
}
|
}
|
||||||
SignedBlindedBeaconBlock::Electra(block) => {
|
SignedBlindedBeaconBlock::Deneb(block) => {
|
||||||
block.message.body.execution_payload.tree_hash_root()
|
block.message.body.execution_payload.tree_hash_root()
|
||||||
}
|
}
|
||||||
};
|
SignedBlindedBeaconBlock::Electra(block) => {
|
||||||
|
block.message.body.execution_payload.tree_hash_root()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let payload = builder
|
||||||
|
.el
|
||||||
|
.get_payload_by_root(&root)
|
||||||
|
.ok_or_else(|| reject("missing payload for tx root"))?;
|
||||||
|
let resp: ForkVersionedResponse<_> = ForkVersionedResponse {
|
||||||
|
version: Some(fork_name),
|
||||||
|
metadata: Default::default(),
|
||||||
|
data: payload,
|
||||||
|
};
|
||||||
|
|
||||||
let fork_name = builder.spec.fork_name_at_slot::<E>(slot);
|
let json_payload = serde_json::to_string(&resp)
|
||||||
let payload = builder
|
.map_err(|_| reject("coudn't serialize response"))?;
|
||||||
.el
|
Ok::<_, warp::reject::Rejection>(
|
||||||
.get_payload_by_root(&root)
|
warp::http::Response::builder()
|
||||||
.ok_or_else(|| reject("missing payload for tx root"))?;
|
.status(200)
|
||||||
let resp: ForkVersionedResponse<_> = ForkVersionedResponse {
|
.body(
|
||||||
version: Some(fork_name),
|
serde_json::to_string(&json_payload)
|
||||||
metadata: Default::default(),
|
.map_err(|_| reject("invalid JSON"))?,
|
||||||
data: payload,
|
)
|
||||||
};
|
.unwrap(),
|
||||||
|
)
|
||||||
let json_payload = serde_json::to_string(&resp)
|
},
|
||||||
.map_err(|_| reject("coudn't serialize response"))?;
|
);
|
||||||
Ok::<_, warp::reject::Rejection>(
|
|
||||||
warp::http::Response::builder()
|
|
||||||
.status(200)
|
|
||||||
.body(
|
|
||||||
serde_json::to_string(&json_payload)
|
|
||||||
.map_err(|_| reject("nvalid JSON"))?,
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let status = prefix
|
let status = prefix
|
||||||
.and(warp::path("status"))
|
.and(warp::path("status"))
|
||||||
|
|||||||
Reference in New Issue
Block a user