feat: update el requests for devnet 4 (#11865)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Oliver
2024-10-19 14:48:35 +02:00
committed by GitHub
parent 2ae93682b4
commit 3bd695ee63
106 changed files with 799 additions and 1328 deletions

View File

@ -2,11 +2,11 @@ use crate::{
capabilities::EngineCapabilities, metrics::EngineApiMetrics, EngineApiError, EngineApiResult,
};
use alloy_eips::eip4844::BlobAndProofV1;
use alloy_primitives::{BlockHash, BlockNumber, B256, U64};
use alloy_primitives::{BlockHash, BlockNumber, Bytes, B256, U64};
use alloy_rpc_types_engine::{
CancunPayloadFields, ClientVersionV1, ExecutionPayload, ExecutionPayloadBodiesV1,
ExecutionPayloadInputV2, ExecutionPayloadV1, ExecutionPayloadV3, ExecutionPayloadV4,
ForkchoiceState, ForkchoiceUpdated, PayloadId, PayloadStatus, TransitionConfiguration,
ExecutionPayloadInputV2, ExecutionPayloadV1, ExecutionPayloadV3, ForkchoiceState,
ForkchoiceUpdated, PayloadId, PayloadStatus, TransitionConfiguration,
};
use async_trait::async_trait;
use jsonrpsee_core::RpcResult;
@ -140,7 +140,7 @@ where
self.inner
.validator
.validate_version_specific_fields(EngineApiMessageVersion::V1, payload_or_attrs)?;
Ok(self.inner.beacon_consensus.new_payload(payload, None).await?)
Ok(self.inner.beacon_consensus.new_payload(payload, None, None).await?)
}
/// See also <https://github.com/ethereum/execution-apis/blob/584905270d8ad665718058060267061ecfd79ca5/src/engine/shanghai.md#engine_newpayloadv2>
@ -156,7 +156,7 @@ where
self.inner
.validator
.validate_version_specific_fields(EngineApiMessageVersion::V2, payload_or_attrs)?;
Ok(self.inner.beacon_consensus.new_payload(payload, None).await?)
Ok(self.inner.beacon_consensus.new_payload(payload, None, None).await?)
}
/// See also <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#engine_newpayloadv3>
@ -178,15 +178,18 @@ where
let cancun_fields = CancunPayloadFields { versioned_hashes, parent_beacon_block_root };
Ok(self.inner.beacon_consensus.new_payload(payload, Some(cancun_fields)).await?)
Ok(self.inner.beacon_consensus.new_payload(payload, Some(cancun_fields), None).await?)
}
/// See also <https://github.com/ethereum/execution-apis/blob/7907424db935b93c2fe6a3c0faab943adebe8557/src/engine/prague.md#engine_newpayloadv4>
pub async fn new_payload_v4(
&self,
payload: ExecutionPayloadV4,
payload: ExecutionPayloadV3,
versioned_hashes: Vec<B256>,
parent_beacon_block_root: B256,
// TODO(onbjerg): Figure out why we even get these here, since we'll check the requests
// from execution against the requests root in the header.
execution_requests: Vec<Bytes>,
) -> EngineApiResult<PayloadStatus> {
let payload = ExecutionPayload::from(payload);
let payload_or_attrs =
@ -200,7 +203,13 @@ where
let cancun_fields = CancunPayloadFields { versioned_hashes, parent_beacon_block_root };
Ok(self.inner.beacon_consensus.new_payload(payload, Some(cancun_fields)).await?)
// HACK(onbjerg): We should have a pectra payload fields struct, this is just a temporary
// workaround.
Ok(self
.inner
.beacon_consensus
.new_payload(payload, Some(cancun_fields), Some(execution_requests))
.await?)
}
/// Sends a message to the beacon consensus engine to update the fork choice _without_
@ -370,7 +379,7 @@ where
.map_err(|_| EngineApiError::UnknownPayload)?
.try_into()
.map_err(|_| {
warn!("could not transform built payload into ExecutionPayloadV4");
warn!("could not transform built payload into ExecutionPayloadV3");
EngineApiError::UnknownPayload
})
}
@ -665,15 +674,22 @@ where
/// See also <https://github.com/ethereum/execution-apis/blob/03911ffc053b8b806123f1fc237184b0092a485a/src/engine/prague.md#engine_newpayloadv4>
async fn new_payload_v4(
&self,
payload: ExecutionPayloadV4,
payload: ExecutionPayloadV3,
versioned_hashes: Vec<B256>,
parent_beacon_block_root: B256,
execution_requests: Vec<Bytes>,
) -> RpcResult<PayloadStatus> {
trace!(target: "rpc::engine", "Serving engine_newPayloadV4");
let start = Instant::now();
let gas_used = payload.payload_inner.payload_inner.payload_inner.gas_used;
let res =
Self::new_payload_v4(self, payload, versioned_hashes, parent_beacon_block_root).await;
let gas_used = payload.payload_inner.payload_inner.gas_used;
let res = Self::new_payload_v4(
self,
payload,
versioned_hashes,
parent_beacon_block_root,
execution_requests,
)
.await;
let elapsed = start.elapsed();
self.inner.metrics.latency.new_payload_v4.record(elapsed);
self.inner.metrics.new_payload_response.update_response_metrics(&res, gas_used, elapsed);

View File

@ -75,7 +75,7 @@ fn payload_validation() {
b
});
assert_matches!(try_into_sealed_block(block_with_valid_extra_data, None), Ok(_));
assert_matches!(try_into_sealed_block(block_with_valid_extra_data, None, None), Ok(_));
// Invalid extra data
let block_with_invalid_extra_data = Bytes::from_static(&[0; 33]);
@ -84,7 +84,7 @@ fn payload_validation() {
b
});
assert_matches!(
try_into_sealed_block(invalid_extra_data_block,None),
try_into_sealed_block(invalid_extra_data_block, None, None),
Err(PayloadError::ExtraData(data)) if data == block_with_invalid_extra_data
);
@ -94,8 +94,7 @@ fn payload_validation() {
b
});
assert_matches!(
try_into_sealed_block(block_with_zero_base_fee,None),
try_into_sealed_block(block_with_zero_base_fee, None, None),
Err(PayloadError::BaseFee(val)) if val.is_zero()
);
@ -114,8 +113,7 @@ fn payload_validation() {
b
});
assert_matches!(
try_into_sealed_block(block_with_ommers.clone(),None),
try_into_sealed_block(block_with_ommers.clone(), None, None),
Err(PayloadError::BlockHash { consensus, .. })
if consensus == block_with_ommers.block_hash()
);
@ -126,9 +124,8 @@ fn payload_validation() {
b
});
assert_matches!(
try_into_sealed_block(block_with_difficulty.clone(),None),
try_into_sealed_block(block_with_difficulty.clone(), None, None),
Err(PayloadError::BlockHash { consensus, .. }) if consensus == block_with_difficulty.block_hash()
);
// None zero nonce
@ -137,7 +134,7 @@ fn payload_validation() {
b
});
assert_matches!(
try_into_sealed_block(block_with_nonce.clone(),None),
try_into_sealed_block(block_with_nonce.clone(), None, None),
Err(PayloadError::BlockHash { consensus, .. }) if consensus == block_with_nonce.block_hash()
);