mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 21:08:32 +00:00
Exclude empty requests and add back prefix
This commit is contained in:
@@ -43,10 +43,29 @@ impl<E: EthSpec> ExecutionRequests<E> {
|
||||
/// Returns the encoding according to EIP-7685 to send
|
||||
/// to the execution layer over the engine api.
|
||||
pub fn get_execution_requests_list(&self) -> Vec<Bytes> {
|
||||
let deposit_bytes = Bytes::from(self.deposits.as_ssz_bytes());
|
||||
let withdrawal_bytes = Bytes::from(self.withdrawals.as_ssz_bytes());
|
||||
let consolidation_bytes = Bytes::from(self.consolidations.as_ssz_bytes());
|
||||
vec![deposit_bytes, withdrawal_bytes, consolidation_bytes]
|
||||
let mut requests_list = Vec::new();
|
||||
if !self.deposits.is_empty() {
|
||||
requests_list.push(Bytes::from_iter(
|
||||
[RequestType::Deposit.to_prefix()]
|
||||
.into_iter()
|
||||
.chain(self.deposits.as_ssz_bytes()),
|
||||
));
|
||||
}
|
||||
if !self.withdrawals.is_empty() {
|
||||
requests_list.push(Bytes::from_iter(
|
||||
[RequestType::Withdrawal.to_prefix()]
|
||||
.into_iter()
|
||||
.chain(self.withdrawals.as_ssz_bytes()),
|
||||
));
|
||||
}
|
||||
if !self.consolidations.is_empty() {
|
||||
requests_list.push(Bytes::from_iter(
|
||||
[RequestType::Consolidation.to_prefix()]
|
||||
.into_iter()
|
||||
.chain(self.consolidations.as_ssz_bytes()),
|
||||
));
|
||||
}
|
||||
requests_list
|
||||
}
|
||||
|
||||
/// Generate the execution layer `requests_hash` based on EIP-7685.
|
||||
@@ -55,9 +74,8 @@ impl<E: EthSpec> ExecutionRequests<E> {
|
||||
pub fn requests_hash(&self) -> Hash256 {
|
||||
let mut hasher = DynamicContext::new();
|
||||
|
||||
for (i, request) in self.get_execution_requests_list().iter().enumerate() {
|
||||
for request in self.get_execution_requests_list().iter() {
|
||||
let mut request_hasher = DynamicContext::new();
|
||||
request_hasher.update(&[i as u8]);
|
||||
request_hasher.update(request);
|
||||
let request_hash = request_hasher.finalize();
|
||||
|
||||
@@ -70,13 +88,13 @@ impl<E: EthSpec> ExecutionRequests<E> {
|
||||
|
||||
/// This is used to index into the `execution_requests` array.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum RequestPrefix {
|
||||
pub enum RequestType {
|
||||
Deposit,
|
||||
Withdrawal,
|
||||
Consolidation,
|
||||
}
|
||||
|
||||
impl RequestPrefix {
|
||||
impl RequestType {
|
||||
pub fn from_prefix(prefix: u8) -> Option<Self> {
|
||||
match prefix {
|
||||
0 => Some(Self::Deposit),
|
||||
@@ -85,6 +103,13 @@ impl RequestPrefix {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn to_prefix(&self) -> u8 {
|
||||
match self {
|
||||
Self::Deposit => 0,
|
||||
Self::Withdrawal => 1,
|
||||
Self::Consolidation => 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -170,7 +170,7 @@ pub use crate::execution_payload_header::{
|
||||
ExecutionPayloadHeaderDeneb, ExecutionPayloadHeaderElectra, ExecutionPayloadHeaderRef,
|
||||
ExecutionPayloadHeaderRefMut,
|
||||
};
|
||||
pub use crate::execution_requests::{ExecutionRequests, RequestPrefix};
|
||||
pub use crate::execution_requests::{ExecutionRequests, RequestType};
|
||||
pub use crate::fork::Fork;
|
||||
pub use crate::fork_context::ForkContext;
|
||||
pub use crate::fork_data::ForkData;
|
||||
|
||||
Reference in New Issue
Block a user