Skip to content
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

Removed Redundant JSON Structures #3630

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions beacon_node/beacon_chain/tests/payload_invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use beacon_chain::{
INVALID_JUSTIFIED_PAYLOAD_SHUTDOWN_REASON,
};
use execution_layer::{
json_structures::{JsonForkChoiceStateV1, JsonPayloadAttributesV1},
test_utils::ExecutionBlockGenerator,
ExecutionLayer, ForkChoiceState, PayloadAttributes,
test_utils::ExecutionBlockGenerator, ExecutionLayer, ForkChoiceState, PayloadAttributes,
};
use fork_choice::{
CountUnrealized, Error as ForkChoiceError, InvalidationOperation, PayloadVerificationStatus,
Expand Down Expand Up @@ -126,14 +124,14 @@ impl InvalidPayloadRig {
let params = json.get("params").expect("no params");

let fork_choice_state_json = params.get(0).expect("no payload param");
let fork_choice_state: JsonForkChoiceStateV1 =
let fork_choice_state: ForkChoiceState =
serde_json::from_value(fork_choice_state_json.clone()).unwrap();

let payload_param_json = params.get(1).expect("no payload param");
let attributes: JsonPayloadAttributesV1 =
let attributes: PayloadAttributes =
serde_json::from_value(payload_param_json.clone()).unwrap();

(fork_choice_state.into(), attributes.into())
(fork_choice_state, attributes)
}

fn previous_payload_attributes(&self) -> PayloadAttributes {
Expand Down
21 changes: 17 additions & 4 deletions beacon_node/execution_layer/src/engine_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::engines::ForkChoiceState;
pub use ethers_core::types::Transaction;
use http::deposit_methods::RpcError;
pub use json_structures::TransitionConfigurationV1;
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
use strum::IntoStaticStr;
Expand Down Expand Up @@ -72,7 +71,8 @@ impl From<builder_client::Error> for Error {
}
}

#[derive(Clone, Copy, Debug, PartialEq, IntoStaticStr)]
#[derive(Clone, Copy, Debug, PartialEq, IntoStaticStr, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "snake_case")]
pub enum PayloadStatusV1Status {
Valid,
Expand All @@ -82,7 +82,8 @@ pub enum PayloadStatusV1Status {
InvalidBlockHash,
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PayloadStatusV1 {
pub status: PayloadStatusV1Status,
pub latest_valid_hash: Option<ExecutionBlockHash>,
Expand Down Expand Up @@ -140,8 +141,10 @@ pub struct ExecutionBlockWithTransactions<T: EthSpec> {
pub transactions: Vec<Transaction>,
}

#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PayloadAttributes {
#[serde(with = "eth2_serde_utils::u64_hex_be")]
pub timestamp: u64,
pub prev_randao: Hash256,
pub suggested_fee_recipient: Address,
Expand All @@ -153,6 +156,16 @@ pub struct ForkchoiceUpdatedResponse {
pub payload_id: Option<PayloadId>,
}

#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransitionConfigurationV1 {
#[serde(with = "eth2_serde_utils::u256_hex_be")]
pub terminal_total_difficulty: Uint256,
pub terminal_block_hash: ExecutionBlockHash,
#[serde(with = "eth2_serde_utils::u64_hex_be")]
pub terminal_block_number: u64,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ProposeBlindedBlockResponseStatus {
Valid,
Expand Down
30 changes: 10 additions & 20 deletions beacon_node/execution_layer/src/engine_api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,39 +642,29 @@ impl HttpJsonRpc {
&self,
execution_payload: ExecutionPayload<T>,
) -> Result<PayloadStatusV1, Error> {
let params = json!([JsonExecutionPayloadV1::from(execution_payload)]);
let params = json!([execution_payload]);

let response: JsonPayloadStatusV1 = self
.rpc_request(ENGINE_NEW_PAYLOAD_V1, params, ENGINE_NEW_PAYLOAD_TIMEOUT)
.await?;

Ok(response.into())
self.rpc_request(ENGINE_NEW_PAYLOAD_V1, params, ENGINE_NEW_PAYLOAD_TIMEOUT)
.await
}

pub async fn get_payload_v1<T: EthSpec>(
&self,
payload_id: PayloadId,
) -> Result<ExecutionPayload<T>, Error> {
let params = json!([JsonPayloadIdRequest::from(payload_id)]);

let response: JsonExecutionPayloadV1<T> = self
.rpc_request(ENGINE_GET_PAYLOAD_V1, params, ENGINE_GET_PAYLOAD_TIMEOUT)
.await?;

Ok(response.into())
self.rpc_request(ENGINE_GET_PAYLOAD_V1, params, ENGINE_GET_PAYLOAD_TIMEOUT)
.await
}

pub async fn forkchoice_updated_v1(
&self,
forkchoice_state: ForkChoiceState,
payload_attributes: Option<PayloadAttributes>,
) -> Result<ForkchoiceUpdatedResponse, Error> {
let params = json!([
JsonForkChoiceStateV1::from(forkchoice_state),
payload_attributes.map(JsonPayloadAttributesV1::from)
]);
let params = json!([forkchoice_state, payload_attributes]);

let response: JsonForkchoiceUpdatedV1Response = self
let response: JsonForkchoiceUpdatedResponse = self
.rpc_request(
ENGINE_FORKCHOICE_UPDATED_V1,
params,
Expand Down Expand Up @@ -817,7 +807,7 @@ mod test {
fn encode_transactions<E: EthSpec>(
transactions: Transactions<E>,
) -> Result<serde_json::Value, serde_json::Error> {
let ep: JsonExecutionPayloadV1<E> = JsonExecutionPayloadV1 {
let ep: ExecutionPayload<E> = ExecutionPayload {
transactions,
..<_>::default()
};
Expand Down Expand Up @@ -847,7 +837,7 @@ mod test {
json.as_object_mut()
.unwrap()
.insert("transactions".into(), transactions);
let ep: JsonExecutionPayloadV1<E> = serde_json::from_value(json)?;
let ep: ExecutionPayload<E> = serde_json::from_value(json)?;
Ok(ep.transactions)
}

Expand Down Expand Up @@ -1341,7 +1331,7 @@ mod test {
extra_data: vec![].into(),
base_fee_per_gas: Uint256::from(7),
block_hash: ExecutionBlockHash::from_str("0x6359b8381a370e2f54072a5784ddd78b6ed024991558c511d4452eb4f6ac898c").unwrap(),
transactions: vec![].into(),
transactions: vec![].into(),
};

assert_eq!(payload, expected);
Expand Down
Loading