-
Notifications
You must be signed in to change notification settings - Fork 48
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some feedback
crates/rpc/src/handlers/block.rs
Outdated
db: Data<ReamDB>, | ||
block_id: Path<ID>, | ||
) -> Result<impl Responder, ApiError> { | ||
// This endpoint is not implemented yet. |
There was a problem hiding this comment.
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
crates/rpc/src/handlers/block.rs
Outdated
let beacon_block: SignedBeaconBlock = | ||
get_beacon_block_from_id(block_id.into_inner(), &db).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?; |
crates/rpc/src/handlers/block.rs
Outdated
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(), | ||
}; |
There was a problem hiding this comment.
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
crates/rpc/src/handlers/block.rs
Outdated
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))) |
There was a problem hiding this comment.
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
2e7ccb9
to
51277de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some feedback
crates/rpc/src/handlers/block.rs
Outdated
use tracing::error; | ||
|
||
use crate::handlers::state::get_state_from_id; | ||
|
||
pub const OCTET_STREAM_HEADER: &str = "application/octet-stream"; |
There was a problem hiding this comment.
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
pub fn to_signed_blinded_beacon_block(&self) -> anyhow::Result<SignedBlindedBeaconBlock> { | ||
Ok(SignedBlindedBeaconBlock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
crates/rpc/src/handlers/block.rs
Outdated
#[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(), | ||
)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[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
There was a problem hiding this 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
crates/rpc/src/handlers/block.rs
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
What are you trying to achieve?
Fixes #207
How was it implemented/fixed?
Taking most of the data from
SignedBeaconBlock
and usingexecution_payload_header
from its execution payload. Then checking for the request header ifapplication/octet-stream
returning a string response instead of json.To-Do