Skip to content

Commit c41d118

Browse files
authored
Use Fork variants instead of version for JsonPayload types (#7909)
With Fulu, we increment the engine API version for `get_payload` but we do not also increment `new_payload`. In Lighthouse, we have a tight coupling between these version numbers and the Fork variants. For example, both `get_payload_v3` and `new_payload_v3` correspond to Deneb, `v4` to Electra, etc. However this coupling breaks with Fulu where only `get_payload_v5` is related to Fulu and `new_payload_v4` now also corresponds to Fulu (new_payload_v5 does not exist). While we can work around this, it creates a confusing situation where the versions and Fork variants are out of sync. See the following code snippet where we are using the v4 endpoint, and yet passing a `V5` payload variant: https://github.com/sigp/lighthouse/blob/522bd9e9c6ac167f2231525e937c9ebbcb86cf6e/beacon_node/execution_layer/src/engine_api/http.rs#L849-L870 1. Remove `new_payload_v5` as it is unused in Fulu. 2. Rename the `JsonExecutionPayload` and `JsonGetExecutionPayloadResponse` types to use Fork variants instead of version variants. This clarifies the relationship between them.
1 parent 884f300 commit c41d118

File tree

5 files changed

+116
-159
lines changed

5 files changed

+116
-159
lines changed

beacon_node/execution_layer/src/engine_api.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::http::{
55
ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V1, ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V1,
66
ENGINE_GET_PAYLOAD_V1, ENGINE_GET_PAYLOAD_V2, ENGINE_GET_PAYLOAD_V3, ENGINE_GET_PAYLOAD_V4,
77
ENGINE_GET_PAYLOAD_V5, ENGINE_NEW_PAYLOAD_V1, ENGINE_NEW_PAYLOAD_V2, ENGINE_NEW_PAYLOAD_V3,
8-
ENGINE_NEW_PAYLOAD_V4, ENGINE_NEW_PAYLOAD_V5,
8+
ENGINE_NEW_PAYLOAD_V4,
99
};
1010
use eth2::types::{
1111
BlobsBundle, SsePayloadAttributes, SsePayloadAttributesV1, SsePayloadAttributesV2,
@@ -541,7 +541,6 @@ pub struct EngineCapabilities {
541541
pub new_payload_v2: bool,
542542
pub new_payload_v3: bool,
543543
pub new_payload_v4: bool,
544-
pub new_payload_v5: bool,
545544
pub forkchoice_updated_v1: bool,
546545
pub forkchoice_updated_v2: bool,
547546
pub forkchoice_updated_v3: bool,
@@ -572,9 +571,6 @@ impl EngineCapabilities {
572571
if self.new_payload_v4 {
573572
response.push(ENGINE_NEW_PAYLOAD_V4);
574573
}
575-
if self.new_payload_v5 {
576-
response.push(ENGINE_NEW_PAYLOAD_V5);
577-
}
578574
if self.forkchoice_updated_v1 {
579575
response.push(ENGINE_FORKCHOICE_UPDATED_V1);
580576
}

beacon_node/execution_layer/src/engine_api/http.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub const ENGINE_NEW_PAYLOAD_V1: &str = "engine_newPayloadV1";
3535
pub const ENGINE_NEW_PAYLOAD_V2: &str = "engine_newPayloadV2";
3636
pub const ENGINE_NEW_PAYLOAD_V3: &str = "engine_newPayloadV3";
3737
pub const ENGINE_NEW_PAYLOAD_V4: &str = "engine_newPayloadV4";
38-
pub const ENGINE_NEW_PAYLOAD_V5: &str = "engine_newPayloadV5";
3938
pub const ENGINE_NEW_PAYLOAD_TIMEOUT: Duration = Duration::from_secs(8);
4039

4140
pub const ENGINE_GET_PAYLOAD_V1: &str = "engine_getPayloadV1";
@@ -75,7 +74,6 @@ pub static LIGHTHOUSE_CAPABILITIES: &[&str] = &[
7574
ENGINE_NEW_PAYLOAD_V2,
7675
ENGINE_NEW_PAYLOAD_V3,
7776
ENGINE_NEW_PAYLOAD_V4,
78-
ENGINE_NEW_PAYLOAD_V5,
7977
ENGINE_GET_PAYLOAD_V1,
8078
ENGINE_GET_PAYLOAD_V2,
8179
ENGINE_GET_PAYLOAD_V3,
@@ -805,7 +803,7 @@ impl HttpJsonRpc {
805803
new_payload_request_deneb: NewPayloadRequestDeneb<'_, E>,
806804
) -> Result<PayloadStatusV1, Error> {
807805
let params = json!([
808-
JsonExecutionPayload::V3(new_payload_request_deneb.execution_payload.clone().into()),
806+
JsonExecutionPayload::Deneb(new_payload_request_deneb.execution_payload.clone().into()),
809807
new_payload_request_deneb.versioned_hashes,
810808
new_payload_request_deneb.parent_beacon_block_root,
811809
]);
@@ -826,7 +824,9 @@ impl HttpJsonRpc {
826824
new_payload_request_electra: NewPayloadRequestElectra<'_, E>,
827825
) -> Result<PayloadStatusV1, Error> {
828826
let params = json!([
829-
JsonExecutionPayload::V4(new_payload_request_electra.execution_payload.clone().into()),
827+
JsonExecutionPayload::Electra(
828+
new_payload_request_electra.execution_payload.clone().into()
829+
),
830830
new_payload_request_electra.versioned_hashes,
831831
new_payload_request_electra.parent_beacon_block_root,
832832
new_payload_request_electra
@@ -850,7 +850,7 @@ impl HttpJsonRpc {
850850
new_payload_request_fulu: NewPayloadRequestFulu<'_, E>,
851851
) -> Result<PayloadStatusV1, Error> {
852852
let params = json!([
853-
JsonExecutionPayload::V5(new_payload_request_fulu.execution_payload.clone().into()),
853+
JsonExecutionPayload::Fulu(new_payload_request_fulu.execution_payload.clone().into()),
854854
new_payload_request_fulu.versioned_hashes,
855855
new_payload_request_fulu.parent_beacon_block_root,
856856
new_payload_request_fulu
@@ -875,7 +875,7 @@ impl HttpJsonRpc {
875875
) -> Result<GetPayloadResponse<E>, Error> {
876876
let params = json!([JsonPayloadIdRequest::from(payload_id)]);
877877

878-
let payload_v1: JsonExecutionPayloadV1<E> = self
878+
let payload_v1: JsonExecutionPayloadBellatrix<E> = self
879879
.rpc_request(
880880
ENGINE_GET_PAYLOAD_V1,
881881
params,
@@ -901,26 +901,26 @@ impl HttpJsonRpc {
901901

902902
match fork_name {
903903
ForkName::Bellatrix => {
904-
let response: JsonGetPayloadResponseV1<E> = self
904+
let response: JsonGetPayloadResponseBellatrix<E> = self
905905
.rpc_request(
906906
ENGINE_GET_PAYLOAD_V2,
907907
params,
908908
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
909909
)
910910
.await?;
911-
JsonGetPayloadResponse::V1(response)
911+
JsonGetPayloadResponse::Bellatrix(response)
912912
.try_into()
913913
.map_err(Error::BadResponse)
914914
}
915915
ForkName::Capella => {
916-
let response: JsonGetPayloadResponseV2<E> = self
916+
let response: JsonGetPayloadResponseCapella<E> = self
917917
.rpc_request(
918918
ENGINE_GET_PAYLOAD_V2,
919919
params,
920920
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
921921
)
922922
.await?;
923-
JsonGetPayloadResponse::V2(response)
923+
JsonGetPayloadResponse::Capella(response)
924924
.try_into()
925925
.map_err(Error::BadResponse)
926926
}
@@ -940,14 +940,14 @@ impl HttpJsonRpc {
940940

941941
match fork_name {
942942
ForkName::Deneb => {
943-
let response: JsonGetPayloadResponseV3<E> = self
943+
let response: JsonGetPayloadResponseDeneb<E> = self
944944
.rpc_request(
945945
ENGINE_GET_PAYLOAD_V3,
946946
params,
947947
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
948948
)
949949
.await?;
950-
JsonGetPayloadResponse::V3(response)
950+
JsonGetPayloadResponse::Deneb(response)
951951
.try_into()
952952
.map_err(Error::BadResponse)
953953
}
@@ -967,14 +967,14 @@ impl HttpJsonRpc {
967967

968968
match fork_name {
969969
ForkName::Electra => {
970-
let response: JsonGetPayloadResponseV4<E> = self
970+
let response: JsonGetPayloadResponseElectra<E> = self
971971
.rpc_request(
972972
ENGINE_GET_PAYLOAD_V4,
973973
params,
974974
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
975975
)
976976
.await?;
977-
JsonGetPayloadResponse::V4(response)
977+
JsonGetPayloadResponse::Electra(response)
978978
.try_into()
979979
.map_err(Error::BadResponse)
980980
}
@@ -994,14 +994,14 @@ impl HttpJsonRpc {
994994

995995
match fork_name {
996996
ForkName::Fulu => {
997-
let response: JsonGetPayloadResponseV5<E> = self
997+
let response: JsonGetPayloadResponseFulu<E> = self
998998
.rpc_request(
999999
ENGINE_GET_PAYLOAD_V5,
10001000
params,
10011001
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
10021002
)
10031003
.await?;
1004-
JsonGetPayloadResponse::V5(response)
1004+
JsonGetPayloadResponse::Fulu(response)
10051005
.try_into()
10061006
.map_err(Error::BadResponse)
10071007
}
@@ -1135,7 +1135,6 @@ impl HttpJsonRpc {
11351135
new_payload_v2: capabilities.contains(ENGINE_NEW_PAYLOAD_V2),
11361136
new_payload_v3: capabilities.contains(ENGINE_NEW_PAYLOAD_V3),
11371137
new_payload_v4: capabilities.contains(ENGINE_NEW_PAYLOAD_V4),
1138-
new_payload_v5: capabilities.contains(ENGINE_NEW_PAYLOAD_V5),
11391138
forkchoice_updated_v1: capabilities.contains(ENGINE_FORKCHOICE_UPDATED_V1),
11401139
forkchoice_updated_v2: capabilities.contains(ENGINE_FORKCHOICE_UPDATED_V2),
11411140
forkchoice_updated_v3: capabilities.contains(ENGINE_FORKCHOICE_UPDATED_V3),
@@ -1501,10 +1500,11 @@ mod test {
15011500
fn encode_transactions<E: EthSpec>(
15021501
transactions: Transactions<E>,
15031502
) -> Result<serde_json::Value, serde_json::Error> {
1504-
let ep: JsonExecutionPayload<E> = JsonExecutionPayload::V1(JsonExecutionPayloadV1 {
1505-
transactions,
1506-
..<_>::default()
1507-
});
1503+
let ep: JsonExecutionPayload<E> =
1504+
JsonExecutionPayload::Bellatrix(JsonExecutionPayloadBellatrix {
1505+
transactions,
1506+
..<_>::default()
1507+
});
15081508
let json = serde_json::to_value(ep)?;
15091509
Ok(json.get("transactions").unwrap().clone())
15101510
}

0 commit comments

Comments
 (0)