chore: reduce scope of commitment (#5426)

* reduce scope of commitment

* avoid clone for last reference

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into mod_merge_single_blob
This commit is contained in:
zhiqiangxu 2024-03-23 02:16:52 +08:00 committed by GitHub
parent 5bfe6a8ae3
commit 5121d655f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 4 deletions

View File

@ -108,11 +108,10 @@ pub trait AvailabilityView<E: EthSpec> {
/// 1. The blob entry at the index is empty and no block exists, or /// 1. The blob entry at the index is empty and no block exists, or
/// 2. The block exists and its commitment matches the blob's commitment. /// 2. The block exists and its commitment matches the blob's commitment.
fn merge_single_blob(&mut self, index: usize, blob: Self::BlobType) { fn merge_single_blob(&mut self, index: usize, blob: Self::BlobType) {
let commitment = *blob.get_commitment();
if let Some(cached_block) = self.get_cached_block() { if let Some(cached_block) = self.get_cached_block() {
let block_commitment_opt = cached_block.get_commitments().get(index).copied(); let block_commitment_opt = cached_block.get_commitments().get(index).copied();
if let Some(block_commitment) = block_commitment_opt { if let Some(block_commitment) = block_commitment_opt {
if block_commitment == commitment { if block_commitment == *blob.get_commitment() {
self.insert_blob_at_index(index, blob) self.insert_blob_at_index(index, blob)
} }
} }

View File

@ -82,11 +82,11 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlockConten
| SignedBeaconBlock::Altair(_) | SignedBeaconBlock::Altair(_)
| SignedBeaconBlock::Merge(_) | SignedBeaconBlock::Merge(_)
| SignedBeaconBlock::Capella(_) => { | SignedBeaconBlock::Capella(_) => {
crate::publish_pubsub_message(&sender, PubsubMessage::BeaconBlock(block.clone())) crate::publish_pubsub_message(&sender, PubsubMessage::BeaconBlock(block))
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?; .map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?;
} }
SignedBeaconBlock::Deneb(_) => { SignedBeaconBlock::Deneb(_) => {
let mut pubsub_messages = vec![PubsubMessage::BeaconBlock(block.clone())]; let mut pubsub_messages = vec![PubsubMessage::BeaconBlock(block)];
if let Some(blob_sidecars) = blobs_opt { if let Some(blob_sidecars) = blobs_opt {
for (blob_index, blob) in blob_sidecars.into_iter().enumerate() { for (blob_index, blob) in blob_sidecars.into_iter().enumerate() {
pubsub_messages.push(PubsubMessage::BlobSidecar(Box::new(( pubsub_messages.push(PubsubMessage::BlobSidecar(Box::new((