mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 17:26:04 +00:00
cleanup
This commit is contained in:
@@ -352,13 +352,8 @@ pub enum RequestsError {
|
|||||||
|
|
||||||
/// Format of `ExecutionRequests` received over the engine api.
|
/// Format of `ExecutionRequests` received over the engine api.
|
||||||
///
|
///
|
||||||
/// Array of ssz-encoded requests list encoded as hex bytes.
|
/// Array of ssz-encoded requests list encoded as hex bytes prefixed
|
||||||
/// The prefix of the request type is used to index into the array.
|
/// with a `RequestType`
|
||||||
///
|
|
||||||
/// For e.g. [0xab, 0xcd, 0xef]
|
|
||||||
/// Here, 0xab are the deposits bytes (prefix and index == 0)
|
|
||||||
/// 0xcd are the withdrawals bytes (prefix and index == 1)
|
|
||||||
/// 0xef are the consolidations bytes (prefix and index == 2)
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct JsonExecutionRequests(pub Vec<String>);
|
pub struct JsonExecutionRequests(pub Vec<String>);
|
||||||
@@ -383,10 +378,10 @@ impl<E: EthSpec> TryFrom<JsonExecutionRequests> for ExecutionRequests<E> {
|
|||||||
return Err(RequestsError::EmptyRequest(i));
|
return Err(RequestsError::EmptyRequest(i));
|
||||||
}
|
}
|
||||||
// Elements of the list **MUST** be ordered by `request_type` in ascending order
|
// Elements of the list **MUST** be ordered by `request_type` in ascending order
|
||||||
let current_prefix = RequestType::from_prefix(*prefix_byte)
|
let current_prefix = RequestType::from_u8(*prefix_byte)
|
||||||
.ok_or(RequestsError::InvalidPrefix(*prefix_byte))?;
|
.ok_or(RequestsError::InvalidPrefix(*prefix_byte))?;
|
||||||
if let Some(prev) = prev_prefix {
|
if let Some(prev) = prev_prefix {
|
||||||
if prev.to_prefix() >= current_prefix.to_prefix() {
|
if prev.to_u8() >= current_prefix.to_u8() {
|
||||||
return Err(RequestsError::InvalidOrdering);
|
return Err(RequestsError::InvalidOrdering);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,21 +46,21 @@ impl<E: EthSpec> ExecutionRequests<E> {
|
|||||||
let mut requests_list = Vec::new();
|
let mut requests_list = Vec::new();
|
||||||
if !self.deposits.is_empty() {
|
if !self.deposits.is_empty() {
|
||||||
requests_list.push(Bytes::from_iter(
|
requests_list.push(Bytes::from_iter(
|
||||||
[RequestType::Deposit.to_prefix()]
|
[RequestType::Deposit.to_u8()]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(self.deposits.as_ssz_bytes()),
|
.chain(self.deposits.as_ssz_bytes()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if !self.withdrawals.is_empty() {
|
if !self.withdrawals.is_empty() {
|
||||||
requests_list.push(Bytes::from_iter(
|
requests_list.push(Bytes::from_iter(
|
||||||
[RequestType::Withdrawal.to_prefix()]
|
[RequestType::Withdrawal.to_u8()]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(self.withdrawals.as_ssz_bytes()),
|
.chain(self.withdrawals.as_ssz_bytes()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if !self.consolidations.is_empty() {
|
if !self.consolidations.is_empty() {
|
||||||
requests_list.push(Bytes::from_iter(
|
requests_list.push(Bytes::from_iter(
|
||||||
[RequestType::Consolidation.to_prefix()]
|
[RequestType::Consolidation.to_u8()]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(self.consolidations.as_ssz_bytes()),
|
.chain(self.consolidations.as_ssz_bytes()),
|
||||||
));
|
));
|
||||||
@@ -86,7 +86,7 @@ impl<E: EthSpec> ExecutionRequests<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is used to index into the `execution_requests` array.
|
/// The prefix types for `ExecutionRequest` objects.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum RequestType {
|
pub enum RequestType {
|
||||||
Deposit,
|
Deposit,
|
||||||
@@ -95,7 +95,7 @@ pub enum RequestType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RequestType {
|
impl RequestType {
|
||||||
pub fn from_prefix(prefix: u8) -> Option<Self> {
|
pub fn from_u8(prefix: u8) -> Option<Self> {
|
||||||
match prefix {
|
match prefix {
|
||||||
0 => Some(Self::Deposit),
|
0 => Some(Self::Deposit),
|
||||||
1 => Some(Self::Withdrawal),
|
1 => Some(Self::Withdrawal),
|
||||||
@@ -103,7 +103,7 @@ impl RequestType {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn to_prefix(&self) -> u8 {
|
pub fn to_u8(&self) -> u8 {
|
||||||
match self {
|
match self {
|
||||||
Self::Deposit => 0,
|
Self::Deposit => 0,
|
||||||
Self::Withdrawal => 1,
|
Self::Withdrawal => 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user