Skip to content

Commit

Permalink
Merge pull request #4094 from realbigsean/free-blob-lints
Browse files Browse the repository at this point in the history
Free blob lints
  • Loading branch information
realbigsean authored Mar 15, 2023
2 parents 34cea6d + cf4285e commit 1a87222
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 111 deletions.
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4857,7 +4857,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
)),
)?;

kzg_utils::compute_blob_kzg_proof::<T::EthSpec>(kzg, blob, kzg_commitment.clone())
kzg_utils::compute_blob_kzg_proof::<T::EthSpec>(kzg, blob, *kzg_commitment)
.map_err(BlockProductionError::KzgError)
})
.collect::<Result<Vec<KzgProof>, BlockProductionError>>()
Expand Down
10 changes: 5 additions & 5 deletions beacon_node/beacon_chain/src/blob_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use slot_clock::SlotClock;
use std::sync::Arc;

use crate::beacon_chain::{BeaconChain, BeaconChainTypes, MAXIMUM_GOSSIP_CLOCK_DISPARITY};
use crate::{kzg_utils, BeaconChainError};
use crate::BeaconChainError;
use state_processing::per_block_processing::eip4844::eip4844::verify_kzg_commitments_against_transactions;
use types::signed_beacon_block::BlobReconstructionError;
use types::{
Expand Down Expand Up @@ -116,11 +116,11 @@ pub fn validate_blob_for_gossip<T: BeaconChainTypes>(
}

fn verify_data_availability<T: BeaconChainTypes>(
blob_sidecar: &BlobsSidecar<T::EthSpec>,
_blob_sidecar: &BlobsSidecar<T::EthSpec>,
kzg_commitments: &[KzgCommitment],
transactions: &Transactions<T::EthSpec>,
block_slot: Slot,
block_root: Hash256,
_block_slot: Slot,
_block_root: Hash256,
chain: &BeaconChain<T>,
) -> Result<(), BlobError> {
if verify_kzg_commitments_against_transactions::<T::EthSpec>(transactions, kzg_commitments)
Expand All @@ -130,7 +130,7 @@ fn verify_data_availability<T: BeaconChainTypes>(
}

// Validatate that the kzg proof is valid against the commitments and blobs
let kzg = chain
let _kzg = chain
.kzg
.as_ref()
.ok_or(BlobError::TrustedSetupNotInitialized)?;
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/http_api/src/build_block_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ pub fn build_block_contents<T: BeaconChainTypes, Payload: AbstractExecPayload<T:

Ok(BlockContents::BlockAndBlobSidecars(block_and_blobs))
} else {
return Err(warp_utils::reject::block_production_error(
Err(warp_utils::reject::block_production_error(
BlockProductionError::NoBlobsCached,
));
))
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use beacon_chain::{
pub use block_id::BlockId;
use directory::DEFAULT_ROOT_DIR;
use eth2::types::{
self as api_types, EndpointVersion, SkipRandaoVerification, ValidatorId, ValidatorStatus,
self as api_types, EndpointVersion, SignedBlockContents, SkipRandaoVerification, ValidatorId,
ValidatorStatus,
};
use lighthouse_network::{types::SyncState, EnrExt, NetworkGlobals, PeerId, PubsubMessage};
use lighthouse_version::version_with_platform;
Expand All @@ -57,7 +58,7 @@ use types::{
Attestation, AttestationData, AttesterSlashing, BeaconStateError, BlindedPayload,
CommitteeCache, ConfigAndPreset, Epoch, EthSpec, ForkName, FullPayload,
ProposerPreparationData, ProposerSlashing, RelativeEpoch, SignedAggregateAndProof,
SignedBeaconBlock, SignedBlindedBeaconBlock, SignedBlockContents, SignedBlsToExecutionChange,
SignedBeaconBlock, SignedBlindedBeaconBlock, SignedBlsToExecutionChange,
SignedContributionAndProof, SignedValidatorRegistrationData, SignedVoluntaryExit, Slot,
SyncCommitteeMessage, SyncContributionData,
};
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/http_api/src/publish_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use beacon_chain::blob_verification::{AsBlock, BlockWrapper, IntoAvailableBlock}
use beacon_chain::validator_monitor::{get_block_delay_ms, timestamp_now};
use beacon_chain::NotifyExecutionLayer;
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockError, CountUnrealized};
use eth2::types::SignedBlockContents;
use lighthouse_network::PubsubMessage;
use network::NetworkMessage;
use slog::{debug, error, info, warn, Logger};
Expand All @@ -12,7 +13,7 @@ use tokio::sync::mpsc::UnboundedSender;
use tree_hash::TreeHash;
use types::{
AbstractExecPayload, BlindedPayload, EthSpec, ExecPayload, ExecutionBlockHash, FullPayload,
Hash256, SignedBeaconBlock, SignedBlockContents,
Hash256, SignedBeaconBlock,
};
use warp::Rejection;

Expand Down
7 changes: 5 additions & 2 deletions beacon_node/http_api/tests/interactive_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,13 @@ pub async fn proposer_boost_re_org_test(
let randao_reveal = harness
.sign_randao_reveal(&state_b, proposer_index, slot_c)
.into();
let unsigned_block_c = tester
let unsigned_block_contents_c = tester
.client
.get_validator_blocks(slot_c, &randao_reveal, None)
.await
.unwrap()
.data;
let unsigned_block_c = unsigned_block_contents_c.deconstruct().0;
let block_c = harness.sign_beacon_block(unsigned_block_c, &state_b);

if should_re_org {
Expand Down Expand Up @@ -700,7 +701,9 @@ pub async fn fork_choice_before_proposal() {
.get_validator_blocks::<E, FullPayload<E>>(slot_d, &randao_reveal, None)
.await
.unwrap()
.data;
.data
.deconstruct()
.0;

// Head is now B.
assert_eq!(
Expand Down
62 changes: 41 additions & 21 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ struct ApiTester {
harness: Arc<BeaconChainHarness<EphemeralHarnessType<E>>>,
chain: Arc<BeaconChain<EphemeralHarnessType<E>>>,
client: BeaconNodeHttpClient,
next_block: SignedBeaconBlock<E>,
reorg_block: SignedBeaconBlock<E>,
next_block: SignedBlockContents<E>,
reorg_block: SignedBlockContents<E>,
attestations: Vec<Attestation<E>>,
contribution_and_proofs: Vec<SignedContributionAndProof<E>>,
attester_slashing: AttesterSlashing<E>,
Expand Down Expand Up @@ -154,11 +154,13 @@ impl ApiTester {
let (next_block, _next_state) = harness
.make_block(head.beacon_state.clone(), harness.chain.slot().unwrap())
.await;
let next_block = SignedBlockContents::from(next_block);

// `make_block` adds random graffiti, so this will produce an alternate block
let (reorg_block, _reorg_state) = harness
.make_block(head.beacon_state.clone(), harness.chain.slot().unwrap())
.await;
let reorg_block = SignedBlockContents::from(reorg_block);

let head_state_root = head.beacon_state_root();
let attestations = harness
Expand Down Expand Up @@ -288,11 +290,13 @@ impl ApiTester {
let (next_block, _next_state) = harness
.make_block(head.beacon_state.clone(), harness.chain.slot().unwrap())
.await;
let next_block = SignedBlockContents::from(next_block);

// `make_block` adds random graffiti, so this will produce an alternate block
let (reorg_block, _reorg_state) = harness
.make_block(head.beacon_state.clone(), harness.chain.slot().unwrap())
.await;
let reorg_block = SignedBlockContents::from(reorg_block);

let head_state_root = head.beacon_state_root();
let attestations = harness
Expand Down Expand Up @@ -975,9 +979,9 @@ impl ApiTester {
}

pub async fn test_post_beacon_blocks_valid(mut self) -> Self {
let next_block = &self.next_block;
let next_block = self.next_block.clone();

self.client.post_beacon_blocks(next_block).await.unwrap();
self.client.post_beacon_blocks(&next_block).await.unwrap();

assert!(
self.network_rx.network_recv.recv().await.is_some(),
Expand All @@ -988,10 +992,14 @@ impl ApiTester {
}

pub async fn test_post_beacon_blocks_invalid(mut self) -> Self {
let mut next_block = self.next_block.clone();
let mut next_block = self.next_block.clone().deconstruct().0;
*next_block.message_mut().proposer_index_mut() += 1;

assert!(self.client.post_beacon_blocks(&next_block).await.is_err());
assert!(self
.client
.post_beacon_blocks(&SignedBlockContents::from(next_block))
.await
.is_err());

assert!(
self.network_rx.network_recv.recv().await.is_some(),
Expand Down Expand Up @@ -2065,11 +2073,17 @@ impl ApiTester {
.get_validator_blocks::<E, FullPayload<E>>(slot, &randao_reveal, None)
.await
.unwrap()
.data;
.data
.deconstruct()
.0;

let signed_block = block.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
let signed_block_contents = SignedBlockContents::from(signed_block.clone());

self.client.post_beacon_blocks(&signed_block).await.unwrap();
self.client
.post_beacon_blocks(&signed_block_contents)
.await
.unwrap();

assert_eq!(self.chain.head_beacon_block().as_ref(), &signed_block);

Expand All @@ -2093,7 +2107,9 @@ impl ApiTester {
)
.await
.unwrap()
.data;
.data
.deconstruct()
.0;
assert_eq!(block.slot(), slot);
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
}
Expand Down Expand Up @@ -3760,12 +3776,12 @@ impl ApiTester {

// Submit the next block, which is on an epoch boundary, so this will produce a finalized
// checkpoint event, head event, and block event
let block_root = self.next_block.canonical_root();
let block_root = self.next_block.signed_block().canonical_root();

// current_duty_dependent_root = block root because this is the first slot of the epoch
let current_duty_dependent_root = self.chain.head_beacon_block_root();
let current_slot = self.chain.slot().unwrap();
let next_slot = self.next_block.slot();
let next_slot = self.next_block.signed_block().slot();
let finalization_distance = E::slots_per_epoch() * 2;

let expected_block = EventKind::Block(SseBlock {
Expand All @@ -3777,7 +3793,7 @@ impl ApiTester {
let expected_head = EventKind::Head(SseHead {
block: block_root,
slot: next_slot,
state: self.next_block.state_root(),
state: self.next_block.signed_block().state_root(),
current_duty_dependent_root,
previous_duty_dependent_root: self
.chain
Expand Down Expand Up @@ -3826,13 +3842,17 @@ impl ApiTester {
.unwrap();

let expected_reorg = EventKind::ChainReorg(SseChainReorg {
slot: self.next_block.slot(),
slot: self.next_block.signed_block().slot(),
depth: 1,
old_head_block: self.next_block.canonical_root(),
old_head_state: self.next_block.state_root(),
new_head_block: self.reorg_block.canonical_root(),
new_head_state: self.reorg_block.state_root(),
epoch: self.next_block.slot().epoch(E::slots_per_epoch()),
old_head_block: self.next_block.signed_block().canonical_root(),
old_head_state: self.next_block.signed_block().state_root(),
new_head_block: self.reorg_block.signed_block().canonical_root(),
new_head_state: self.reorg_block.signed_block().state_root(),
epoch: self
.next_block
.signed_block()
.slot()
.epoch(E::slots_per_epoch()),
execution_optimistic: false,
});

Expand Down Expand Up @@ -3894,8 +3914,8 @@ impl ApiTester {
.await
.unwrap();

let block_root = self.next_block.canonical_root();
let next_slot = self.next_block.slot();
let block_root = self.next_block.signed_block().canonical_root();
let next_slot = self.next_block.signed_block().slot();

let expected_block = EventKind::Block(SseBlock {
block: block_root,
Expand All @@ -3906,7 +3926,7 @@ impl ApiTester {
let expected_head = EventKind::Head(SseHead {
block: block_root,
slot: next_slot,
state: self.next_block.state_root(),
state: self.next_block.signed_block().state_root(),
current_duty_dependent_root: self.chain.genesis_block_root,
previous_duty_dependent_root: self.chain.genesis_block_root,
epoch_transition: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,12 @@ impl<T: BeaconChainTypes> Worker<T> {
#[allow(clippy::too_many_arguments)]
pub async fn process_gossip_blob(
self,
message_id: MessageId,
_message_id: MessageId,
peer_id: PeerId,
peer_client: Client,
blob_index: u64,
signed_blob: Arc<SignedBlobSidecar<T::EthSpec>>,
seen_duration: Duration,
_seen_duration: Duration,
) {
// TODO: gossip verification
crit!(self.log, "UNIMPLEMENTED gossip blob verification";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<T: BeaconChainTypes> Worker<T> {
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_commitment: block.body.blob_kzg_commitments[known_index], // 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(
Expand Down Expand Up @@ -843,7 +843,7 @@ impl<T: BeaconChainTypes> Worker<T> {
beacon_block_root,
beacon_block_slot,
blobs: blob_bundle,
kzg_aggregated_proof,
kzg_aggregated_proof: _,
}: types::BlobsSidecar<_> = blobs;

for (blob_index, blob) in blob_bundle.into_iter().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/network/src/sync/block_sidecar_coupling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<T: EthSpec> BlocksAndBlobsRequestInfo<T> {
pub fn into_responses(self) -> Result<Vec<TempBlockWrapper<T>>, &'static str> {
let BlocksAndBlobsRequestInfo {
accumulated_blocks,
mut accumulated_sidecars,
accumulated_sidecars,
..
} = self;

Expand Down
6 changes: 3 additions & 3 deletions beacon_node/network/src/sync/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,8 @@ impl<T: BeaconChainTypes> SyncManager<T> {
fn rpc_blobs_received(
&mut self,
request_id: RequestId,
peer_id: PeerId,
maybe_blob: Option<Arc<BlobSidecar<<T>::EthSpec>>>,
_peer_id: PeerId,
_maybe_blob: Option<Arc<BlobSidecar<<T>::EthSpec>>>,
_seen_timestamp: Duration,
) {
match request_id {
Expand All @@ -892,7 +892,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
RequestId::RangeBlocks { .. } => {
unreachable!("Only-blocks range requests don't receive sidecars")
}
RequestId::RangeBlobs { id } => {
RequestId::RangeBlobs { id: _ } => {
unimplemented!("Adjust range");
}
}
Expand Down
Loading

0 comments on commit 1a87222

Please sign in to comment.