mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 12:11:59 +00:00
Runtime rpc request sizes (#4841)
* add runtime variable list type * add configs to ChainSpec * git rid of max request blocks type * fix tests and lints * remove todos * git rid of old const usage * fix decode impl * add new config to `Config` api struct * add docs fix compilt * move methods for per-fork-spec to chainspec * get values off chain spec * fix compile * remove min by root size * add tests for runtime var list --------- Co-authored-by: Jimmy Chen <jchen.tc@gmail.com>
This commit is contained in:
@@ -13,12 +13,11 @@ use beacon_chain::{get_block_root, BeaconChainTypes};
|
||||
use lighthouse_network::rpc::methods::BlobsByRootRequest;
|
||||
use lighthouse_network::rpc::BlocksByRootRequest;
|
||||
use rand::prelude::IteratorRandom;
|
||||
use ssz_types::VariableList;
|
||||
use std::ops::IndexMut;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use types::blob_sidecar::{BlobIdentifier, FixedBlobSidecarList};
|
||||
use types::{BlobSidecar, EthSpec, Hash256, SignedBeaconBlock};
|
||||
use types::{BlobSidecar, ChainSpec, EthSpec, Hash256, SignedBeaconBlock};
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum ResponseType {
|
||||
@@ -87,11 +86,14 @@ pub trait RequestState<L: Lookup, T: BeaconChainTypes> {
|
||||
/* Request building methods */
|
||||
|
||||
/// Construct a new request.
|
||||
fn build_request(&mut self) -> Result<(PeerId, Self::RequestType), LookupRequestError> {
|
||||
fn build_request(
|
||||
&mut self,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(PeerId, Self::RequestType), LookupRequestError> {
|
||||
// Verify and construct request.
|
||||
self.too_many_attempts()?;
|
||||
let peer = self.get_peer()?;
|
||||
let request = self.new_request();
|
||||
let request = self.new_request(spec);
|
||||
Ok((peer, request))
|
||||
}
|
||||
|
||||
@@ -108,7 +110,7 @@ pub trait RequestState<L: Lookup, T: BeaconChainTypes> {
|
||||
}
|
||||
|
||||
// Construct request.
|
||||
let (peer_id, request) = self.build_request()?;
|
||||
let (peer_id, request) = self.build_request(&cx.chain.spec)?;
|
||||
|
||||
// Update request state.
|
||||
self.get_state_mut().state = State::Downloading { peer_id };
|
||||
@@ -151,7 +153,7 @@ pub trait RequestState<L: Lookup, T: BeaconChainTypes> {
|
||||
}
|
||||
|
||||
/// Initialize `Self::RequestType`.
|
||||
fn new_request(&self) -> Self::RequestType;
|
||||
fn new_request(&self, spec: &ChainSpec) -> Self::RequestType;
|
||||
|
||||
/// Send the request to the network service.
|
||||
fn make_request(
|
||||
@@ -254,8 +256,8 @@ impl<L: Lookup, T: BeaconChainTypes> RequestState<L, T> for BlockRequestState<L>
|
||||
type VerifiedResponseType = Arc<SignedBeaconBlock<T::EthSpec>>;
|
||||
type ReconstructedResponseType = RpcBlock<T::EthSpec>;
|
||||
|
||||
fn new_request(&self) -> BlocksByRootRequest {
|
||||
BlocksByRootRequest::new(VariableList::from(vec![self.requested_block_root]))
|
||||
fn new_request(&self, spec: &ChainSpec) -> BlocksByRootRequest {
|
||||
BlocksByRootRequest::new(vec![self.requested_block_root], spec)
|
||||
}
|
||||
|
||||
fn make_request(
|
||||
@@ -353,10 +355,9 @@ impl<L: Lookup, T: BeaconChainTypes> RequestState<L, T> for BlobRequestState<L,
|
||||
type VerifiedResponseType = FixedBlobSidecarList<T::EthSpec>;
|
||||
type ReconstructedResponseType = FixedBlobSidecarList<T::EthSpec>;
|
||||
|
||||
fn new_request(&self) -> BlobsByRootRequest {
|
||||
fn new_request(&self, spec: &ChainSpec) -> BlobsByRootRequest {
|
||||
let blob_id_vec: Vec<BlobIdentifier> = self.requested_ids.clone().into();
|
||||
let blob_ids = VariableList::from(blob_id_vec);
|
||||
BlobsByRootRequest { blob_ids }
|
||||
BlobsByRootRequest::new(blob_id_vec, spec)
|
||||
}
|
||||
|
||||
fn make_request(
|
||||
|
||||
@@ -575,7 +575,7 @@ mod tests {
|
||||
HotColdDB::open_ephemeral(StoreConfig::default(), ChainSpec::minimal(), log.clone())
|
||||
.expect("store");
|
||||
let da_checker = Arc::new(
|
||||
DataAvailabilityChecker::new(slot_clock, None, store.into(), &log, spec)
|
||||
DataAvailabilityChecker::new(slot_clock, None, store.into(), &log, spec.clone())
|
||||
.expect("data availability checker"),
|
||||
);
|
||||
let mut sl = SingleBlockLookup::<TestLookup1, T>::new(
|
||||
@@ -587,6 +587,7 @@ mod tests {
|
||||
);
|
||||
<BlockRequestState<TestLookup1> as RequestState<TestLookup1, T>>::build_request(
|
||||
&mut sl.block_request_state,
|
||||
&spec,
|
||||
)
|
||||
.unwrap();
|
||||
sl.block_request_state.state.state = State::Downloading { peer_id };
|
||||
@@ -616,7 +617,7 @@ mod tests {
|
||||
.expect("store");
|
||||
|
||||
let da_checker = Arc::new(
|
||||
DataAvailabilityChecker::new(slot_clock, None, store.into(), &log, spec)
|
||||
DataAvailabilityChecker::new(slot_clock, None, store.into(), &log, spec.clone())
|
||||
.expect("data availability checker"),
|
||||
);
|
||||
|
||||
@@ -630,6 +631,7 @@ mod tests {
|
||||
for _ in 1..TestLookup2::MAX_ATTEMPTS {
|
||||
<BlockRequestState<TestLookup2> as RequestState<TestLookup2, T>>::build_request(
|
||||
&mut sl.block_request_state,
|
||||
&spec,
|
||||
)
|
||||
.unwrap();
|
||||
sl.block_request_state.state.register_failure_downloading();
|
||||
@@ -638,6 +640,7 @@ mod tests {
|
||||
// Now we receive the block and send it for processing
|
||||
<BlockRequestState<TestLookup2> as RequestState<TestLookup2, T>>::build_request(
|
||||
&mut sl.block_request_state,
|
||||
&spec,
|
||||
)
|
||||
.unwrap();
|
||||
sl.block_request_state.state.state = State::Downloading { peer_id };
|
||||
@@ -654,7 +657,8 @@ mod tests {
|
||||
sl.block_request_state.state.register_failure_processing();
|
||||
assert_eq!(
|
||||
<BlockRequestState<TestLookup2> as RequestState<TestLookup2, T>>::build_request(
|
||||
&mut sl.block_request_state
|
||||
&mut sl.block_request_state,
|
||||
&spec
|
||||
),
|
||||
Err(LookupRequestError::TooManyAttempts {
|
||||
cannot_process: false
|
||||
|
||||
@@ -52,7 +52,6 @@ use beacon_chain::{
|
||||
AvailabilityProcessingStatus, BeaconChain, BeaconChainTypes, BlockError, EngineState,
|
||||
};
|
||||
use futures::StreamExt;
|
||||
use lighthouse_network::rpc::methods::MAX_REQUEST_BLOCKS;
|
||||
use lighthouse_network::rpc::RPCError;
|
||||
use lighthouse_network::types::{NetworkGlobals, SyncState};
|
||||
use lighthouse_network::SyncInfo;
|
||||
@@ -230,7 +229,7 @@ pub fn spawn<T: BeaconChainTypes>(
|
||||
log: slog::Logger,
|
||||
) {
|
||||
assert!(
|
||||
MAX_REQUEST_BLOCKS >= T::EthSpec::slots_per_epoch() * EPOCHS_PER_BATCH,
|
||||
beacon_chain.spec.max_request_blocks >= T::EthSpec::slots_per_epoch() * EPOCHS_PER_BATCH,
|
||||
"Max blocks that can be requested in a single batch greater than max allowed blocks in a single request"
|
||||
);
|
||||
|
||||
|
||||
@@ -475,9 +475,15 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
||||
};
|
||||
let request_id = RequestId::Sync(sync_id);
|
||||
|
||||
if let Some(block_root) = blob_request.blob_ids.first().map(|id| id.block_root) {
|
||||
if let Some(block_root) = blob_request
|
||||
.blob_ids
|
||||
.as_slice()
|
||||
.first()
|
||||
.map(|id| id.block_root)
|
||||
{
|
||||
let indices = blob_request
|
||||
.blob_ids
|
||||
.as_slice()
|
||||
.iter()
|
||||
.map(|id| id.index)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Reference in New Issue
Block a user