mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-09 11:25:55 +00:00
impl logic for triggerng blob lookups along with block lookups
This commit is contained in:
@@ -4,19 +4,22 @@
|
|||||||
use super::block_sidecar_coupling::BlocksAndBlobsRequestInfo;
|
use super::block_sidecar_coupling::BlocksAndBlobsRequestInfo;
|
||||||
use super::manager::{Id, RequestId as SyncRequestId};
|
use super::manager::{Id, RequestId as SyncRequestId};
|
||||||
use super::range_sync::{BatchId, ByRangeRequestType, ChainId};
|
use super::range_sync::{BatchId, ByRangeRequestType, ChainId};
|
||||||
|
use crate::beacon_processor::Work::BlobsByRootsRequest;
|
||||||
use crate::beacon_processor::WorkEvent;
|
use crate::beacon_processor::WorkEvent;
|
||||||
use crate::service::{NetworkMessage, RequestId};
|
use crate::service::{NetworkMessage, RequestId};
|
||||||
use crate::status::ToStatusMessage;
|
use crate::status::ToStatusMessage;
|
||||||
use beacon_chain::blob_verification::BlockWrapper;
|
use beacon_chain::blob_verification::BlockWrapper;
|
||||||
use beacon_chain::{BeaconChain, BeaconChainTypes, EngineState};
|
use beacon_chain::{BeaconChain, BeaconChainTypes, EngineState};
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use lighthouse_network::rpc::methods::BlobsByRangeRequest;
|
use lighthouse_network::rpc::methods::{BlobsByRangeRequest, BlobsByRootRequest};
|
||||||
use lighthouse_network::rpc::{BlocksByRangeRequest, BlocksByRootRequest, GoodbyeReason};
|
use lighthouse_network::rpc::{BlocksByRangeRequest, BlocksByRootRequest, GoodbyeReason};
|
||||||
use lighthouse_network::{Client, NetworkGlobals, PeerAction, PeerId, ReportSource, Request};
|
use lighthouse_network::{Client, NetworkGlobals, PeerAction, PeerId, ReportSource, Request};
|
||||||
use slog::{debug, trace, warn};
|
use slog::{debug, trace, warn};
|
||||||
|
use ssz_types::VariableList;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
use types::blob_sidecar::BlobIdentifier;
|
||||||
use types::{BlobSidecar, EthSpec, SignedBeaconBlock};
|
use types::{BlobSidecar, EthSpec, SignedBeaconBlock};
|
||||||
|
|
||||||
pub struct BlocksAndBlobsByRangeResponse<T: EthSpec> {
|
pub struct BlocksAndBlobsByRangeResponse<T: EthSpec> {
|
||||||
@@ -414,34 +417,56 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
|||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
request: BlocksByRootRequest,
|
request: BlocksByRootRequest,
|
||||||
) -> Result<Id, &'static str> {
|
) -> Result<Id, &'static str> {
|
||||||
let request = if self
|
let id = self.next_id();
|
||||||
|
let request_id = RequestId::Sync(SyncRequestId::SingleBlock { id });
|
||||||
|
if self
|
||||||
.chain
|
.chain
|
||||||
.is_data_availability_check_required()
|
.is_data_availability_check_required()
|
||||||
.map_err(|_| "Unable to read slot clock")?
|
.map_err(|_| "Unable to read slot clock")?
|
||||||
{
|
{
|
||||||
|
let mut blob_ids =
|
||||||
|
VariableList::new(vec![]).map_err(|_| "could not create blob request list")?;
|
||||||
|
for block_root in request.block_roots.iter() {
|
||||||
|
// Request all blobs because we have no way of knowing how many blobs exist for a block
|
||||||
|
// until we have the block.
|
||||||
|
let blobs_per_block = T::EthSpec::max_blobs_per_block();
|
||||||
|
for i in 0..blobs_per_block {
|
||||||
|
blob_ids
|
||||||
|
.push(BlobIdentifier {
|
||||||
|
block_root: *block_root,
|
||||||
|
index: i as u64,
|
||||||
|
})
|
||||||
|
.map_err(|_| "too many blobs in by root request")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let blobs_count = blob_ids.len();
|
||||||
|
let blob_request = Request::BlobsByRoot(BlobsByRootRequest { blob_ids });
|
||||||
|
self.send_network_msg(NetworkMessage::SendRequest {
|
||||||
|
peer_id,
|
||||||
|
request: blob_request,
|
||||||
|
request_id,
|
||||||
|
})?;
|
||||||
trace!(
|
trace!(
|
||||||
self.log,
|
self.log,
|
||||||
"Sending BlobsByRoot Request";
|
"Sending BlobsByRoot Request";
|
||||||
"method" => "BlobsByRoot",
|
"method" => "BlobsByRoot",
|
||||||
"count" => request.block_roots.len(),
|
"count" => blobs_count,
|
||||||
"peer" => %peer_id
|
"peer" => %peer_id
|
||||||
);
|
);
|
||||||
unimplemented!("There is no longer such thing as a single block lookup, since we nede to ask for blobs and blocks separetely");
|
}
|
||||||
} else {
|
|
||||||
trace!(
|
trace!(
|
||||||
self.log,
|
self.log,
|
||||||
"Sending BlocksByRoot Request";
|
"Sending BlocksByRoot Request";
|
||||||
"method" => "BlocksByRoot",
|
"method" => "BlocksByRoot",
|
||||||
"count" => request.block_roots.len(),
|
"count" => request.block_roots.len(),
|
||||||
"peer" => %peer_id
|
"peer" => %peer_id
|
||||||
);
|
);
|
||||||
Request::BlocksByRoot(request)
|
|
||||||
};
|
|
||||||
let id = self.next_id();
|
|
||||||
let request_id = RequestId::Sync(SyncRequestId::SingleBlock { id });
|
|
||||||
self.send_network_msg(NetworkMessage::SendRequest {
|
self.send_network_msg(NetworkMessage::SendRequest {
|
||||||
peer_id,
|
peer_id,
|
||||||
request,
|
request: Request::BlocksByRoot(request),
|
||||||
request_id,
|
request_id,
|
||||||
})?;
|
})?;
|
||||||
Ok(id)
|
Ok(id)
|
||||||
@@ -453,36 +478,56 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
|||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
request: BlocksByRootRequest,
|
request: BlocksByRootRequest,
|
||||||
) -> Result<Id, &'static str> {
|
) -> Result<Id, &'static str> {
|
||||||
let request = if self
|
let id = self.next_id();
|
||||||
|
let request_id = RequestId::Sync(SyncRequestId::ParentLookup { id });
|
||||||
|
if self
|
||||||
.chain
|
.chain
|
||||||
.is_data_availability_check_required()
|
.is_data_availability_check_required()
|
||||||
.map_err(|_| "Unable to read slot clock")?
|
.map_err(|_| "Unable to read slot clock")?
|
||||||
{
|
{
|
||||||
|
let mut blob_ids =
|
||||||
|
VariableList::new(vec![]).map_err(|e| "could not create blob request list")?;
|
||||||
|
for block_root in request.block_roots.iter() {
|
||||||
|
// Request all blobs because we have no way of knowing how many blobs exist for a block
|
||||||
|
// until we have the block.
|
||||||
|
let blobs_per_block = T::EthSpec::max_blobs_per_block();
|
||||||
|
for i in 0..blobs_per_block {
|
||||||
|
blob_ids
|
||||||
|
.push(BlobIdentifier {
|
||||||
|
block_root: *block_root,
|
||||||
|
index: i as u64,
|
||||||
|
})
|
||||||
|
.map_err(|_| "too many blobs in by root request")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let blobs_count = blob_ids.len();
|
||||||
|
let blob_request = Request::BlobsByRoot(BlobsByRootRequest { blob_ids });
|
||||||
|
self.send_network_msg(NetworkMessage::SendRequest {
|
||||||
|
peer_id,
|
||||||
|
request: blob_request,
|
||||||
|
request_id,
|
||||||
|
})?;
|
||||||
trace!(
|
trace!(
|
||||||
self.log,
|
self.log,
|
||||||
"Sending BlobsByRoot Request";
|
"Sending BlobsByRoot Request";
|
||||||
"method" => "BlobsByRoot",
|
"method" => "BlobsByRoot",
|
||||||
"count" => request.block_roots.len(),
|
"count" => blobs_count,
|
||||||
"peer" => %peer_id
|
"peer" => %peer_id
|
||||||
);
|
);
|
||||||
unimplemented!(
|
}
|
||||||
"Parent requests now need to interleave blocks and blobs or something like that."
|
|
||||||
)
|
trace!(
|
||||||
} else {
|
self.log,
|
||||||
trace!(
|
"Sending BlocksByRoot Request";
|
||||||
self.log,
|
"method" => "BlocksByRoot",
|
||||||
"Sending BlocksByRoot Request";
|
"count" => request.block_roots.len(),
|
||||||
"method" => "BlocksByRoot",
|
"peer" => %peer_id
|
||||||
"count" => request.block_roots.len(),
|
);
|
||||||
"peer" => %peer_id
|
|
||||||
);
|
|
||||||
Request::BlocksByRoot(request)
|
|
||||||
};
|
|
||||||
let id = self.next_id();
|
|
||||||
let request_id = RequestId::Sync(SyncRequestId::ParentLookup { id });
|
|
||||||
self.send_network_msg(NetworkMessage::SendRequest {
|
self.send_network_msg(NetworkMessage::SendRequest {
|
||||||
peer_id,
|
peer_id,
|
||||||
request,
|
request: Request::BlocksByRoot(request),
|
||||||
request_id,
|
request_id,
|
||||||
})?;
|
})?;
|
||||||
Ok(id)
|
Ok(id)
|
||||||
|
|||||||
Reference in New Issue
Block a user