Couple blocks and blobs in gossip (#3670)

* Revert "Add more gossip verification conditions"

This reverts commit 1430b561c3.

* Revert "Add todos"

This reverts commit 91efb9d4c7.

* Revert "Reprocess blob sidecar messages"

This reverts commit 21bf3d37cd.

* Add the coupled topic

* Decode SignedBeaconBlockAndBlobsSidecar correctly

* Process Block and Blobs in beacon processor

* Remove extra blob publishing logic from vc

* Remove blob signing in vc

* Ugly hack to compile
This commit is contained in:
Pawan Dhananjay
2022-11-01 19:58:21 +05:30
committed by GitHub
parent 9f155eec7a
commit 29f2ec46d3
25 changed files with 293 additions and 989 deletions

View File

@@ -13,7 +13,6 @@ mod block_rewards;
mod database;
mod metrics;
mod proposer_duties;
mod publish_blobs;
mod publish_blocks;
mod state_id;
mod sync_committees;
@@ -49,7 +48,7 @@ use types::{
Attestation, AttestationData, AttesterSlashing, BeaconStateError, BlindedPayload,
CommitteeCache, ConfigAndPreset, Epoch, EthSpec, ForkName, FullPayload,
ProposerPreparationData, ProposerSlashing, RelativeEpoch, SignedAggregateAndProof,
SignedBeaconBlock, SignedBlindedBeaconBlock, SignedBlobsSidecar, SignedContributionAndProof,
SignedBeaconBlock, SignedBlindedBeaconBlock, SignedContributionAndProof,
SignedValidatorRegistrationData, SignedVoluntaryExit, Slot, SyncCommitteeMessage,
SyncContributionData,
};
@@ -1047,27 +1046,9 @@ pub fn serve<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>,
log: Logger| async move {
publish_blocks::publish_block(None, block, chain, &network_tx, log)
.await
.map(|()| warp::reply())
},
);
// POST beacon/blobs
let post_beacon_blobs = eth_v1
.and(warp::path("beacon"))
.and(warp::path("blobs"))
.and(warp::path::end())
.and(warp::body::json())
.and(chain_filter.clone())
.and(network_tx_filter.clone())
.and(log_filter.clone())
.and_then(
|blobs: Arc<SignedBlobsSidecar<T::EthSpec>>,
chain: Arc<BeaconChain<T>>,
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>,
log: Logger| async move {
publish_blobs::publish_blobs(blobs, chain, &network_tx, log)
// need to have cached the blob sidecar somewhere in the beacon chain
// to publish
publish_blocks::publish_block(None, block, None, chain, &network_tx, log)
.await
.map(|()| warp::reply())
},
@@ -3183,7 +3164,6 @@ pub fn serve<T: BeaconChainTypes>(
post_beacon_blocks
.boxed()
.or(post_beacon_blinded_blocks.boxed())
.or(post_beacon_blobs.boxed())
.or(post_beacon_pool_attestations.boxed())
.or(post_beacon_pool_attester_slashings.boxed())
.or(post_beacon_pool_proposer_slashings.boxed())

View File

@@ -1,124 +0,0 @@
use crate::metrics;
use beacon_chain::validator_monitor::{get_slot_delay_ms, timestamp_now};
use beacon_chain::{BeaconChain, BeaconChainTypes};
use lighthouse_network::PubsubMessage;
use network::NetworkMessage;
use slog::Logger;
use std::sync::Arc;
use tokio::sync::mpsc::UnboundedSender;
use types::SignedBlobsSidecar;
use warp::Rejection;
/// Handles a request from the HTTP API for full blocks.
pub async fn publish_blobs<T: BeaconChainTypes>(
blobs_sidecar: Arc<SignedBlobsSidecar<T::EthSpec>>,
chain: Arc<BeaconChain<T>>,
network_tx: &UnboundedSender<NetworkMessage<T::EthSpec>>,
log: Logger,
) -> Result<(), Rejection> {
let seen_timestamp = timestamp_now();
// Send the blob, regardless of whether or not it is valid. The API
// specification is very clear that this is the desired behaviour.
crate::publish_pubsub_message(
network_tx,
PubsubMessage::BlobsSidecars(blobs_sidecar.clone()),
)?;
// Determine the delay after the start of the slot, register it with metrics.
let delay = get_slot_delay_ms(
seen_timestamp,
blobs_sidecar.message.beacon_block_slot,
&chain.slot_clock,
);
metrics::observe_duration(&metrics::HTTP_API_BLOB_BROADCAST_DELAY_TIMES, delay);
//FIXME(sean) process blobs
// match chain
// .process_block(blobs_sidecar.clone(), CountUnrealized::True)
// .await
// {
// Ok(root) => {
// info!(
// log,
// "Valid block from HTTP API";
// "block_delay" => ?delay,
// "root" => format!("{}", root),
// "proposer_index" => block.message().proposer_index(),
// "slot" => block.slot(),
// );
//
// // Notify the validator monitor.
// chain.validator_monitor.read().register_api_block(
// seen_timestamp,
// blobs_sidecar.message(),
// root,
// &chain.slot_clock,
// );
//
// // Update the head since it's likely this block will become the new
// // head.
// chain.recompute_head_at_current_slot().await;
//
// // Perform some logging to inform users if their blocks are being produced
// // late.
// //
// // Check to see the thresholds are non-zero to avoid logging errors with small
// // slot times (e.g., during testing)
// let crit_threshold = chain.slot_clock.unagg_attestation_production_delay();
// let error_threshold = crit_threshold / 2;
// if delay >= crit_threshold {
// crit!(
// log,
// "Block was broadcast too late";
// "msg" => "system may be overloaded, block likely to be orphaned",
// "delay_ms" => delay.as_millis(),
// "slot" => block.slot(),
// "root" => ?root,
// )
// } else if delay >= error_threshold {
// error!(
// log,
// "Block broadcast was delayed";
// "msg" => "system may be overloaded, block may be orphaned",
// "delay_ms" => delay.as_millis(),
// "slot" => block.slot(),
// "root" => ?root,
// )
// }
//
// Ok(())
// }
// Err(BlockError::BlockIsAlreadyKnown) => {
// info!(
// log,
// "Block from HTTP API already known";
// "block" => ?block.canonical_root(),
// "slot" => block.slot(),
// );
// Ok(())
// }
// Err(BlockError::RepeatProposal { proposer, slot }) => {
// warn!(
// log,
// "Block ignored due to repeat proposal";
// "msg" => "this can happen when a VC uses fallback BNs. \
// whilst this is not necessarily an error, it can indicate issues with a BN \
// or between the VC and BN.",
// "slot" => slot,
// "proposer" => proposer,
// );
// Ok(())
// }
// Err(e) => {
// let msg = format!("{:?}", e);
// error!(
// log,
// "Invalid block provided to HTTP API";
// "reason" => &msg
// );
// Err(warp_utils::reject::broadcast_without_import(msg))
// }
// }
Ok(())
}

View File

@@ -1,7 +1,7 @@
use crate::metrics;
use beacon_chain::validator_monitor::{get_block_delay_ms, timestamp_now};
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockError, CountUnrealized};
use lighthouse_network::PubsubMessage;
use lighthouse_network::{PubsubMessage, SignedBeaconBlockAndBlobsSidecar};
use network::NetworkMessage;
use slog::{crit, error, info, warn, Logger};
use slot_clock::SlotClock;
@@ -9,8 +9,8 @@ use std::sync::Arc;
use tokio::sync::mpsc::UnboundedSender;
use tree_hash::TreeHash;
use types::{
AbstractExecPayload, BlindedPayload, EthSpec, ExecPayload, ExecutionBlockHash, FullPayload,
Hash256, SignedBeaconBlock,
AbstractExecPayload, BlindedPayload, BlobsSidecar, EthSpec, ExecPayload, ExecutionBlockHash,
FullPayload, Hash256, SignedBeaconBlock, SignedBeaconBlockEip4844,
};
use warp::Rejection;
@@ -18,6 +18,7 @@ use warp::Rejection;
pub async fn publish_block<T: BeaconChainTypes>(
block_root: Option<Hash256>,
block: Arc<SignedBeaconBlock<T::EthSpec>>,
blobs_sidecar: Option<Arc<BlobsSidecar<T::EthSpec>>>,
chain: Arc<BeaconChain<T>>,
network_tx: &UnboundedSender<NetworkMessage<T::EthSpec>>,
log: Logger,
@@ -26,7 +27,24 @@ pub async fn publish_block<T: BeaconChainTypes>(
// Send the block, regardless of whether or not it is valid. The API
// specification is very clear that this is the desired behaviour.
crate::publish_pubsub_message(network_tx, PubsubMessage::BeaconBlock(block.clone()))?;
let message = match &*block {
SignedBeaconBlock::Eip4844(block) => {
if let Some(sidecar) = blobs_sidecar {
PubsubMessage::BeaconBlockAndBlobsSidecars(Arc::new(
SignedBeaconBlockAndBlobsSidecar {
beacon_block: block.clone(),
blobs_sidecar: (*sidecar).clone(),
},
))
} else {
//TODO(pawan): return an empty sidecar instead
return Err(warp_utils::reject::broadcast_without_import(format!("")));
}
}
_ => PubsubMessage::BeaconBlock(block.clone()),
};
crate::publish_pubsub_message(network_tx, message)?;
// Determine the delay after the start of the slot, register it with metrics.
let delay = get_block_delay_ms(seen_timestamp, block.message(), &chain.slot_clock);
@@ -135,6 +153,7 @@ pub async fn publish_blinded_block<T: BeaconChainTypes>(
publish_block::<T>(
Some(block_root),
Arc::new(full_block),
None,
chain,
network_tx,
log,