8000 feat: add endpoint for blinded block by aditya172926 · Pull Request #613 · ReamLabs/ream · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add endpoint for blinded block #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 26, 2025

Conversation

aditya172926
Copy link
Contributor
@aditya172926 aditya172926 commented Jun 23, 2025

What are you trying to achieve?

Fixes #207

How was it implemented/fixed?

Taking most of the data from SignedBeaconBlock and using execution_payload_header from its execution payload. Then checking for the request header if application/octet-stream returning a string response instead of json.

To-Do

Copy link
Contributor
@KolbyML KolbyML left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some feedback

db: Data<ReamDB>,
block_id: Path<ID>,
) -> Result<impl Responder, ApiError> {
// This endpoint is not implemented yet.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is supposed to be here

Comment on lines 347 8000 to 348
let beacon_block: SignedBeaconBlock =
get_beacon_block_from_id(block_id.into_inner(), &db).await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let beacon_block: SignedBeaconBlock =
get_beacon_block_from_id(block_id.into_inner(), &db).await?;
let beacon_block = get_beacon_block_from_id(block_id.into_inner(), &db).await?;

Comment on lines 349 to 376
let signed_blind_block: SignedBlindedBeaconBlock = SignedBlindedBeaconBlock {
message: BlindedBeaconBlock {
slot: beacon_block.message.slot,
proposer_index: beacon_block.message.proposer_index,
parent_root: beacon_block.message.parent_root,
state_root: beacon_block.message.state_root,
body: BlindedBeaconBlockBody {
randao_reveal: beacon_block.message.body.randao_reveal,
eth1_data: beacon_block.message.body.eth1_data,
graffiti: beacon_block.message.body.graffiti,
proposer_slashings: beacon_block.message.body.proposer_slashings,
attester_slashings: beacon_block.message.body.attester_slashings,
attestations: beacon_block.message.body.attestations,
deposits: beacon_block.message.body.deposits,
voluntary_exits: beacon_block.message.body.voluntary_exits,
sync_aggregate: beacon_block.message.body.sync_aggregate,
execution_payload_header: beacon_block
.message
.body
.execution_payload
.to_execution_payload_header(),
bls_to_execution_changes: beacon_block.message.body.bls_to_execution_changes,
blob_kzg_commitments: beacon_block.message.body.blob_kzg_commitments,
execution_requests: beacon_block.message.body.execution_requests,
},
},
signature: beacon_block.signature.clone(),
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a function on SignedBeaconBlock called toSignedBlindedBeaconBlock

Comment on lines 377 to 386
if let Some(header) = req.headers().get("application/octet-stream") {
if header.to_str().unwrap_or_default() == "application/octet-stream" {
let ssz_response = Bytes::from(signed_blind_block.as_ssz_bytes()).to_string();
return Ok(HttpResponse::Ok()
.content_type("application/octet-stream")
.body(ssz_response));
}
}

Ok(HttpResponse::Ok().json(BeaconVersionedResponse::new(signed_blind_block)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you do a match case like done in other parts of the code, also please use the consts for application/octet-stream

Copy link
Contributor
@KolbyML KolbyML left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some feedback

use tracing::error;

use crate::handlers::state::get_state_from_id;

pub const OCTET_STREAM_HEADER: &str = "application/octet-stream";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have a const in the codebase for this right value, could you reuse it

Comment on lines 79 to 80
pub fn to_signed_blinded_beacon_block(&self) -> anyhow::Result<SignedBlindedBeaconBlock> {
Ok(SignedBlindedBeaconBlock {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn to_signed_blinded_beacon_block(&self) -> anyhow::Result<SignedBlindedBeaconBlock> {
Ok(SignedBlindedBeaconBlock {
pub fn as_signed_blinded_beacon_block(&self) -> SignedBlindedBeaconBlock {
SignedBlindedBeaconBlock {

I think we should call this as, as we are only taking a reference to self, we aren't converting self to SignedBlindedBeaconBlock

also we don't need to result here so please remove it

Comment on lines 345 to 371
#[get("/beacon/blind_block/{block_id}")]
pub async fn get_blind_block(
req: HttpRequest,
db: Data<ReamDB>,
block_id: Path<ID>,
) -> Result<impl Responder, ApiError> {
let beacon_block = get_beacon_block_from_id(block_id.into_inner(), &db).await?;
if let Ok(signed_blind_block) = beacon_block.to_signed_blinded_beacon_block() {
match req
.headers()
.get(OCTET_STREAM_HEADER)
.and_then(|header| header.to_str().ok())
{
Some(OCTET_STREAM_HEADER) => {
let ssz_response = Bytes::from(signed_blind_block.as_ssz_bytes()).to_string();
Ok(HttpResponse::Ok()
.content_type(OCTET_STREAM_HEADER)
.body(ssz_response))
}
_ => Ok(HttpResponse::Ok().json(BeaconVersionedResponse::new(signed_blind_block))),
}
} else {
Err(ApiError::InternalError(
"Failed to convert beacon block to signed blinded beacon block".to_string(),
))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[get("/beacon/blind_block/{block_id}")]
pub async fn get_blind_block(
req: HttpRequest,
db: Data<ReamDB>,
block_id: Path<ID>,
) -> Result<impl Responder, ApiError> {
let beacon_block = get_beacon_block_from_id(block_id.into_inner(), &db).await?;
if let Ok(signed_blind_block) = beacon_block.to_signed_blinded_beacon_block() {
match req
.headers()
.get(OCTET_STREAM_HEADER)
.and_then(|header| header.to_str().ok())
{
Some(OCTET_STREAM_HEADER) => {
let ssz_response = Bytes::from(signed_blind_block.as_ssz_bytes()).to_string();
Ok(HttpResponse::Ok()
.content_type(OCTET_STREAM_HEADER)
.body(ssz_response))
}
_ => Ok(HttpResponse::Ok().json(BeaconVersionedResponse::new(signed_blind_block))),
}
} else {
Err(ApiError::InternalError(
"Failed to convert beacon block to signed blinded beacon block".to_string(),
))
}
}
#[get("/beacon/blind_block/{block_id}")]
pub async fn get_blind_block(
8000 http_request: HttpRequest,
db: Data<ReamDB>,
block_id: Path<ID>,
) -> Result<impl Responder, ApiError> {
let beacon_block = get_beacon_block_from_id(block_id.into_inner(), &db).await?;
let blinded_beacon_block = beacon_block.as_signed_blinded_beacon_block()
match http_request
.headers()
.get(OCTET_STREAM_HEADER)
.and_then(|header| header.to_str().ok())
{
Some(OCTET_STREAM_HEADER) => {
Ok(HttpResponse::Ok()
.content_type(OCTET_STREAM_HEADER)
.body(blinded_beacon_block.as_ssz_bytes()))
}
_ => Ok(HttpResponse::Ok().json(BeaconVersionedResponse::new(blinded_beacon_block))),
}
}

The code should look like this, make sure you update the constant though

@aditya172926 aditya172926 requested a review from KolbyML June 26, 2025 16:58
Copy link
Contributor
@KolbyML KolbyML left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this last concern is resolved I will merge the PR

Comment on lines 346 to 352
req: HttpRequest,
db: Data<ReamDB>,
block_id: Path<ID>,
) -> Result<impl Responder, ApiError> {
let beacon_block = get_beacon_block_from_id(block_id.into_inner(), &db).await?;
let blinded_beacon_block = beacon_block.as_signed_blinded_beacon_block();
match req
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
req: HttpRequest,
db: Data<ReamDB>,
block_id: Path<ID>,
) -> Result<impl Responder, ApiError> {
let beacon_block = get_beacon_block_from_id(block_id.into_inner(), &db).await?;
let blinded_beacon_block = beacon_block.as_signed_blinded_beacon_block();
match req
http_request: HttpRequest,
db: Data<ReamDB>,
block_id: Path<ID>,
) -> Result<impl Responder, ApiError> {
let beacon_block = get_beacon_block_from_id(block_id.into_inner(), &db).await?;
let blinded_beacon_block = beacon_block.as_signed_blinded_beacon_block();
match http_request

@KolbyML KolbyML enabled auto-merge June 26, 2025 19:28
@KolbyML KolbyML added this pull request to the merge queue Jun 26, 2025
Merged via the queue into ReamLabs:master with commit 9f187a8 Jun 26, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement /eth/v1/beacon/blinded_blocks/{block_id}
2 participants
0