update code paths in the network crate (#4065)

* wip

* fix router

* arc the byroot responses we send

* add placeholder for blob verification

* respond to blobs by range and blobs by root request in the most horrible and gross way ever

* everything in sync is now unimplemented

* fix compiation issues

* http_pi change is very small, just add it

* remove ctrl-c ctrl-v's docs
This commit is contained in:
Divma
2023-03-10 06:22:31 -05:00
committed by GitHub
parent 3898cf7be8
commit 140bdd370d
11 changed files with 138 additions and 122 deletions

View File

@@ -65,7 +65,7 @@ use task_executor::TaskExecutor;
use tokio::sync::mpsc;
use types::{
Attestation, AttesterSlashing, Hash256, LightClientFinalityUpdate, LightClientOptimisticUpdate,
ProposerSlashing, SignedAggregateAndProof, SignedBeaconBlock, SignedBeaconBlockAndBlobsSidecar,
ProposerSlashing, SignedAggregateAndProof, SignedBeaconBlock, SignedBlobSidecar,
SignedBlsToExecutionChange, SignedContributionAndProof, SignedVoluntaryExit, SubnetId,
SyncCommitteeMessage, SyncSubnetId,
};
@@ -444,20 +444,22 @@ impl<T: BeaconChainTypes> WorkEvent<T> {
}
/// Create a new `Work` event for some blobs sidecar.
pub fn gossip_block_and_blobs_sidecar(
pub fn gossip_signed_blob_sidecar(
message_id: MessageId,
peer_id: PeerId,
peer_client: Client,
block_and_blobs: SignedBeaconBlockAndBlobsSidecar<T::EthSpec>,
blob_index: u64,
signed_blob: Arc<SignedBlobSidecar<T::EthSpec>>,
seen_timestamp: Duration,
) -> Self {
Self {
drop_during_sync: false,
work: Work::GossipBlockAndBlobsSidecar {
work: Work::GossipSignedBlobSidecar {
message_id,
peer_id,
peer_client,
block_and_blobs,
blob_index,
signed_blob,
seen_timestamp,
},
}
@@ -857,11 +859,12 @@ pub enum Work<T: BeaconChainTypes> {
block: Arc<SignedBeaconBlock<T::EthSpec>>,
seen_timestamp: Duration,
},
GossipBlockAndBlobsSidecar {
GossipSignedBlobSidecar {
message_id: MessageId,
peer_id: PeerId,
peer_client: Client,
block_and_blobs: SignedBeaconBlockAndBlobsSidecar<T::EthSpec>,
blob_index: u64,
signed_blob: Arc<SignedBlobSidecar<T::EthSpec>>,
seen_timestamp: Duration,
},
DelayedImportBlock {
@@ -965,7 +968,7 @@ impl<T: BeaconChainTypes> Work<T> {
Work::GossipAggregate { .. } => GOSSIP_AGGREGATE,
Work::GossipAggregateBatch { .. } => GOSSIP_AGGREGATE_BATCH,
Work::GossipBlock { .. } => GOSSIP_BLOCK,
Work::GossipBlockAndBlobsSidecar { .. } => GOSSIP_BLOCK_AND_BLOBS_SIDECAR,
Work::GossipSignedBlobSidecar { .. } => GOSSIP_BLOCK_AND_BLOBS_SIDECAR,
Work::DelayedImportBlock { .. } => DELAYED_IMPORT_BLOCK,
Work::GossipVoluntaryExit { .. } => GOSSIP_VOLUNTARY_EXIT,
Work::GossipProposerSlashing { .. } => GOSSIP_PROPOSER_SLASHING,
@@ -1459,7 +1462,7 @@ impl<T: BeaconChainTypes> BeaconProcessor<T> {
Work::GossipBlock { .. } => {
gossip_block_queue.push(work, work_id, &self.log)
}
Work::GossipBlockAndBlobsSidecar { .. } => {
Work::GossipSignedBlobSidecar { .. } => {
gossip_block_and_blobs_sidecar_queue.push(work, work_id, &self.log)
}
Work::DelayedImportBlock { .. } => {
@@ -1742,21 +1745,21 @@ impl<T: BeaconChainTypes> BeaconProcessor<T> {
/*
* Verification for blobs sidecars received on gossip.
*/
Work::GossipBlockAndBlobsSidecar {
Work::GossipSignedBlobSidecar {
message_id,
peer_id,
peer_client,
block_and_blobs: block_sidecar_pair,
blob_index,
signed_blob,
seen_timestamp,
} => task_spawner.spawn_async(async move {
worker
.process_gossip_block(
.process_gossip_blob(
message_id,
peer_id,
peer_client,
block_sidecar_pair.into(),
work_reprocessing_tx,
duplicate_cache,
blob_index,
signed_blob,
seen_timestamp,
)
.await

View File

@@ -17,12 +17,13 @@ use operation_pool::ReceivedPreCapella;
use slog::{crit, debug, error, info, trace, warn};
use slot_clock::SlotClock;
use ssz::Encode;
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use store::hot_cold_store::HotColdDBError;
use tokio::sync::mpsc;
use types::{
Attestation, AttesterSlashing, EthSpec, Hash256, IndexedAttestation, LightClientFinalityUpdate,
LightClientOptimisticUpdate, ProposerSlashing, SignedAggregateAndProof,
LightClientOptimisticUpdate, ProposerSlashing, SignedAggregateAndProof, SignedBlobSidecar,
SignedBlsToExecutionChange, SignedContributionAndProof, SignedVoluntaryExit, Slot, SubnetId,
SyncCommitteeMessage, SyncSubnetId,
};
@@ -647,6 +648,27 @@ impl<T: BeaconChainTypes> Worker<T> {
}
}
// TODO: docs
#[allow(clippy::too_many_arguments)]
pub async fn process_gossip_blob(
self,
message_id: MessageId,
peer_id: PeerId,
peer_client: Client,
blob_index: u64,
signed_blob: Arc<SignedBlobSidecar<T::EthSpec>>,
seen_duration: Duration,
) {
// TODO: gossip verification
crit!(self.log, "UNIMPLEMENTED gossip blob verification";
"peer_id" => %peer_id,
"client" => %peer_client,
"blob_topic" => blob_index,
"blob_index" => signed_blob.blob.index,
"blob_slot" => signed_blob.blob.slot
);
}
/// Process the beacon block received from the gossip network and:
///
/// - If it passes gossip propagation criteria, tell the network thread to forward it.

View File

@@ -14,6 +14,7 @@ use slog::{debug, error, warn};
use slot_clock::SlotClock;
use std::sync::Arc;
use task_executor::TaskExecutor;
use types::blob_sidecar::BlobIdentifier;
use types::light_client_bootstrap::LightClientBootstrap;
use types::{Epoch, EthSpec, Hash256, Slot};
@@ -219,24 +220,49 @@ impl<T: BeaconChainTypes> Worker<T> {
request_id: PeerRequestId,
request: BlobsByRootRequest,
) {
// TODO: this code is grossly adjusted to free the blobs. Needs love <3
// Fetching blocks is async because it may have to hit the execution layer for payloads.
executor.spawn(
async move {
let requested_blobs = request.blob_ids.len();
let mut send_block_count = 0;
let mut send_response = true;
for root in request.blob_ids.iter() {
for BlobIdentifier{ block_root: root, index } in request.blob_ids.into_iter() {
match self
.chain
.get_block_and_blobs_checking_early_attester_cache(root)
.get_block_and_blobs_checking_early_attester_cache(&root)
.await
{
Ok(Some(block_and_blobs)) => {
self.send_response(
peer_id,
Response::BlobsByRoot(Some(block_and_blobs)),
request_id,
);
send_block_count += 1;
//
// TODO: HORRIBLE NSFW CODE AHEAD
//
let types::SignedBeaconBlockAndBlobsSidecar {beacon_block, blobs_sidecar} = block_and_blobs;
let types::BlobsSidecar{ beacon_block_root, beacon_block_slot, blobs: blob_bundle, kzg_aggregated_proof }: types::BlobsSidecar<_> = blobs_sidecar.as_ref().clone();
// TODO: this should be unreachable after this is addressed seriously,
// so for now let's be ok with a panic in the expect.
let block = beacon_block.message_eip4844().expect("We fucked up the block blob stuff");
// Intentionally not accessing the list directly
for (known_index, blob) in blob_bundle.into_iter().enumerate() {
if (known_index as u64) == index {
let blob_sidecar = types::BlobSidecar{
block_root: beacon_block_root,
index,
slot: beacon_block_slot,
block_parent_root: block.parent_root,
proposer_index: block.proposer_index,
blob,
kzg_commitment: block.body.blob_kzg_commitments[known_index].clone(), // TODO: needs to be stored in a more logical way so that this won't panic.
kzg_proof: kzg_aggregated_proof // TODO: yeah
};
self.send_response(
peer_id,
Response::BlobsByRoot(Some(Arc::new(blob_sidecar))),
request_id,
);
send_block_count += 1;
}
}
}
Ok(None) => {
debug!(
@@ -250,7 +276,6 @@ impl<T: BeaconChainTypes> Worker<T> {
error!(
self.log,
"No blobs in the store for block root";
"request" => ?request,
"peer" => %peer_id,
"block_root" => ?root
);
@@ -329,7 +354,7 @@ impl<T: BeaconChainTypes> Worker<T> {
self.log,
"Received BlobsByRoot Request";
"peer" => %peer_id,
"requested" => request.blob_ids.len(),
"requested" => requested_blobs,
"returned" => send_block_count
);
@@ -813,12 +838,28 @@ impl<T: BeaconChainTypes> Worker<T> {
for root in block_roots {
match self.chain.get_blobs(&root, data_availability_boundary) {
Ok(Some(blobs)) => {
blobs_sent += 1;
self.send_network_message(NetworkMessage::SendResponse {
peer_id,
response: Response::BlobsByRange(Some(Arc::new(blobs))),
id: request_id,
});
// TODO: more GROSS code ahead. Reader beware
let types::BlobsSidecar{ beacon_block_root, beacon_block_slot, blobs: blob_bundle, kzg_aggregated_proof }: types::BlobsSidecar<_> = blobs;
for (blob_index, blob) in blob_bundle.into_iter().enumerate() {
let blob_sidecar = types::BlobSidecar{
block_root: beacon_block_root,
index: blob_index as u64,
slot: beacon_block_slot,
block_parent_root: Hash256::zero(),
proposer_index: 0,
blob,
kzg_commitment: types::KzgCommitment::default(),
kzg_proof: types::KzgProof::default(),
};
blobs_sent += 1;
self.send_network_message(NetworkMessage::SendResponse {
peer_id,
response: Response::BlobsByRange(Some(Arc::new(blob_sidecar))),
id: request_id,
});
}
}
Ok(None) => {
error!(