mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-05 13:54:36 +00:00
Gloas lookup sync boilerplate (#9322)
Implements the boring boilerplate to send envelopes by root requests and process them. Pre-step to - https://github.com/sigp/lighthouse/pull/9155 Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>
This commit is contained in:
@@ -16,6 +16,9 @@ pub use data_columns_by_range::DataColumnsByRangeRequestItems;
|
||||
pub use data_columns_by_root::{
|
||||
DataColumnsByRootRequestItems, DataColumnsByRootSingleBlockRequest,
|
||||
};
|
||||
pub use payload_envelopes_by_root::{
|
||||
PayloadEnvelopesByRootRequestItems, PayloadEnvelopesByRootSingleRequest,
|
||||
};
|
||||
|
||||
use crate::metrics;
|
||||
|
||||
@@ -27,6 +30,7 @@ mod blocks_by_range;
|
||||
mod blocks_by_root;
|
||||
mod data_columns_by_range;
|
||||
mod data_columns_by_root;
|
||||
mod payload_envelopes_by_root;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, IntoStaticStr)]
|
||||
pub enum LookupVerifyError {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
use lighthouse_network::rpc::methods::PayloadEnvelopesByRootRequest;
|
||||
use std::sync::Arc;
|
||||
use types::{EthSpec, ForkContext, Hash256, SignedExecutionPayloadEnvelope};
|
||||
|
||||
use super::{ActiveRequestItems, LookupVerifyError};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PayloadEnvelopesByRootSingleRequest {
|
||||
pub block_root: Hash256,
|
||||
}
|
||||
|
||||
impl PayloadEnvelopesByRootSingleRequest {
|
||||
pub fn into_request(
|
||||
self,
|
||||
fork_context: &ForkContext,
|
||||
) -> Result<PayloadEnvelopesByRootRequest, String> {
|
||||
PayloadEnvelopesByRootRequest::new(vec![self.block_root], fork_context)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PayloadEnvelopesByRootRequestItems<E: EthSpec> {
|
||||
request: PayloadEnvelopesByRootSingleRequest,
|
||||
items: Vec<Arc<SignedExecutionPayloadEnvelope<E>>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> PayloadEnvelopesByRootRequestItems<E> {
|
||||
pub fn new(request: PayloadEnvelopesByRootSingleRequest) -> Self {
|
||||
Self {
|
||||
request,
|
||||
items: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ActiveRequestItems for PayloadEnvelopesByRootRequestItems<E> {
|
||||
type Item = Arc<SignedExecutionPayloadEnvelope<E>>;
|
||||
|
||||
/// Append a response to the single chunk request. We expect exactly one envelope per
|
||||
/// block root. Returns `true` when the single expected item has been received.
|
||||
fn add(&mut self, envelope: Self::Item) -> Result<bool, LookupVerifyError> {
|
||||
let block_root = envelope.message.beacon_block_root;
|
||||
if self.request.block_root != block_root {
|
||||
return Err(LookupVerifyError::UnrequestedBlockRoot(block_root));
|
||||
}
|
||||
|
||||
self.items.push(envelope);
|
||||
// Always returns true, we expect a single envelope per block root
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn consume(&mut self) -> Vec<Self::Item> {
|
||||
std::mem::take(&mut self.items)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user