mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 12:11:59 +00:00
Reduce calls to network channel (#4863)
## Issue Addressed N/A ## Proposed Changes Sends blocks and blobs from http_api to the network channel for publishing in a single network channel send. This is to avoid overhead of multiple calls. Also adds a metric for rpc blob retrieval duration.
This commit is contained in:
@@ -4705,6 +4705,14 @@ fn publish_pubsub_message<T: EthSpec>(
|
||||
)
|
||||
}
|
||||
|
||||
/// Publish a message to the libp2p pubsub network.
|
||||
fn publish_pubsub_messages<T: EthSpec>(
|
||||
network_tx: &UnboundedSender<NetworkMessage<T>>,
|
||||
messages: Vec<PubsubMessage<T>>,
|
||||
) -> Result<(), warp::Rejection> {
|
||||
publish_network_message(network_tx, NetworkMessage::Publish { messages })
|
||||
}
|
||||
|
||||
/// Publish a message to the libp2p network.
|
||||
fn publish_network_message<T: EthSpec>(
|
||||
network_tx: &UnboundedSender<NetworkMessage<T>>,
|
||||
|
||||
@@ -85,19 +85,17 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlockConten
|
||||
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?;
|
||||
}
|
||||
SignedBeaconBlock::Deneb(_) => {
|
||||
crate::publish_pubsub_message(&sender, PubsubMessage::BeaconBlock(block.clone()))
|
||||
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?;
|
||||
let mut pubsub_messages = vec![PubsubMessage::BeaconBlock(block.clone())];
|
||||
if let Some(signed_blobs) = blobs_opt {
|
||||
for (blob_index, blob) in signed_blobs.into_iter().enumerate() {
|
||||
crate::publish_pubsub_message(
|
||||
&sender,
|
||||
PubsubMessage::BlobSidecar(Box::new((blob_index as u64, blob))),
|
||||
)
|
||||
.map_err(|_| {
|
||||
BlockError::BeaconChainError(BeaconChainError::UnableToPublish)
|
||||
})?;
|
||||
pubsub_messages.push(PubsubMessage::BlobSidecar(Box::new((
|
||||
blob_index as u64,
|
||||
blob,
|
||||
))));
|
||||
}
|
||||
}
|
||||
crate::publish_pubsub_messages(&sender, pubsub_messages)
|
||||
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user