Skip to content

Commit

Permalink
Fixed some Payload tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElFantasma committed Nov 28, 2024
1 parent 7c47aa5 commit 5e881db
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions crates/networking/rpc/engine/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl NewPayloadRequest {
};

// Payload Validation
request.validate_execution_payload()?;

// Check timestamp is post valid fork
let chain_config = storage.get_chain_config()?;
Expand Down Expand Up @@ -112,6 +113,7 @@ trait NewPayloadRequestImpl {
fn method(&self) -> String;
fn payload(&self) -> &ExecutionPayload;
fn parent_beacon_block_root(&self) -> Option<H256>;
fn validate_execution_payload(&self) -> Result<(), RpcErr>;
fn valid_fork(&self) -> Fork;
fn are_blob_versioned_hashes_invalid(&self, block: &Block) -> bool;
}
Expand Down Expand Up @@ -150,6 +152,16 @@ impl NewPayloadRequestImpl for NewPayloadV3Request {
.collect();
self.expected_blob_versioned_hashes != blob_versioned_hashes
}

fn validate_execution_payload(&self) -> Result<(), RpcErr> {
if self.payload().excess_blob_gas.is_none() {
return Err(RpcErr::WrongParam("excess_blob_gas".to_string()));
}
if self.payload().blob_gas_used.is_none() {
return Err(RpcErr::WrongParam("blob_gas_used".to_string()));
}
Ok(())
}
}

impl From<NewPayloadV3Request> for RpcRequest {
Expand Down Expand Up @@ -213,6 +225,10 @@ impl NewPayloadRequestImpl for NewPayloadV2Request {
fn are_blob_versioned_hashes_invalid(&self, _block: &Block) -> bool {
false
}

fn validate_execution_payload(&self) -> Result<(), RpcErr> {
Ok(())
}
}

impl From<NewPayloadV2Request> for RpcRequest {
Expand Down Expand Up @@ -294,9 +310,18 @@ impl GetPayloadRequest {
request.payload_id
)));
};
// Check timestamp matches valid fork
let chain_config = &context.storage.get_chain_config()?;
let current_fork = chain_config.get_fork(payload.header.timestamp);
info!("Current Fork: {:?}", current_fork);
if current_fork != get_payload_request.valid_fork() {
return Err(RpcErr::UnsuportedFork(format!("{current_fork:?}")));
}

let (blobs_bundle, block_value) = build_payload(&mut payload, &context.storage)
.map_err(|err| RpcErr::Internal(err.to_string()))?;
let execution_payload = ExecutionPayload::from_block(payload);

serde_json::to_value(get_payload_request.build_response(
execution_payload,
blobs_bundle,
Expand All @@ -308,6 +333,7 @@ impl GetPayloadRequest {
trait GetPayloadRequestImpl {
fn method(&self) -> String;
fn request(&self) -> &GetPayloadRequest;
fn valid_fork(&self) -> Fork;
fn build_response(
&self,
execution_payload: ExecutionPayload,
Expand All @@ -327,6 +353,10 @@ impl GetPayloadRequestImpl for GetPayloadV3Request {
&self.0
}

fn valid_fork(&self) -> Fork {
Fork::Cancun
}

fn build_response(
&self,
execution_payload: ExecutionPayload,
Expand Down Expand Up @@ -369,6 +399,10 @@ impl GetPayloadRequestImpl for GetPayloadV2Request {
&self.0
}

fn valid_fork(&self) -> Fork {
Fork::Shanghai
}

fn build_response(
&self,
execution_payload: ExecutionPayload,
Expand Down
6 changes: 3 additions & 3 deletions crates/networking/rpc/types/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct ExecutionPayload {
#[serde(with = "serde_utils::u64::hex_str")]
gas_used: u64,
#[serde(with = "serde_utils::u64::hex_str")]
timestamp: u64,
pub timestamp: u64,
#[serde(with = "serde_utils::bytes")]
extra_data: Bytes,
#[serde(with = "serde_utils::u64::hex_str")]
Expand All @@ -41,13 +41,13 @@ pub struct ExecutionPayload {
with = "serde_utils::u64::hex_str_opt",
default = "Option::default"
)]
blob_gas_used: Option<u64>,
pub blob_gas_used: Option<u64>,
#[serde(
skip_serializing_if = "Option::is_none",
with = "serde_utils::u64::hex_str_opt",
default = "Option::default"
)]
excess_blob_gas: Option<u64>,
pub excess_blob_gas: Option<u64>,
}

#[derive(Clone, Debug)]
Expand Down

0 comments on commit 5e881db

Please sign in to comment.