Merge pull request #4094 from realbigsean/free-blob-lints

Free blob lints
This commit is contained in:
realbigsean 2023-03-15 16:56:53 -04:00 committed by GitHub
commit 1a87222641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 130 additions and 111 deletions

View File

@ -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>>()

View File

@ -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::{
@ -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)
@ -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)?;

View File

@ -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,
));
))
}
}
}

View File

@ -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;
@ -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,
};

View File

@ -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};
@ -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;

View File

@ -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 {
@ -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!(

View File

@ -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>,
@ -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
@ -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
@ -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(),
@ -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(),
@ -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);
@ -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);
}
@ -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 {
@ -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
@ -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,
});
@ -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,
@ -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,

View File

@ -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";

View File

@ -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(
@ -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() {

View File

@ -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;

View File

@ -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 {
@ -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");
}
}

View File

@ -5,6 +5,7 @@ use crate::Error as ServerError;
use lighthouse_network::{ConnectionDirection, Enr, Multiaddr, PeerConnectionStatus};
use mime::{Mime, APPLICATION, JSON, OCTET_STREAM, STAR};
use serde::{Deserialize, Serialize};
use ssz_derive::Encode;
use std::cmp::Reverse;
use std::convert::TryFrom;
use std::fmt;
@ -1322,3 +1323,60 @@ impl<T: EthSpec, Payload: AbstractExecPayload<T>> Into<BeaconBlock<T, Payload>>
}
}
}
pub type BlockContentsTuple<T, Payload> = (
SignedBeaconBlock<T, Payload>,
Option<VariableList<SignedBlobSidecar<T>, <T as EthSpec>::MaxBlobsPerBlock>>,
);
/// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobSidecars`].
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
#[serde(bound = "T: EthSpec")]
pub enum SignedBlockContents<T: EthSpec, Payload: AbstractExecPayload<T> = FullPayload<T>> {
BlockAndBlobSidecars(SignedBeaconBlockAndBlobSidecars<T, Payload>),
Block(SignedBeaconBlock<T, Payload>),
}
impl<T: EthSpec, Payload: AbstractExecPayload<T>> SignedBlockContents<T, Payload> {
pub fn signed_block(&self) -> &SignedBeaconBlock<T, Payload> {
match self {
SignedBlockContents::BlockAndBlobSidecars(block_and_sidecars) => {
&block_and_sidecars.signed_block
}
SignedBlockContents::Block(block) => block,
}
}
pub fn deconstruct(self) -> BlockContentsTuple<T, Payload> {
match self {
SignedBlockContents::BlockAndBlobSidecars(block_and_sidecars) => (
block_and_sidecars.signed_block,
Some(block_and_sidecars.signed_blob_sidecars),
),
SignedBlockContents::Block(block) => (block, None),
}
}
}
impl<T: EthSpec, Payload: AbstractExecPayload<T>> From<SignedBeaconBlock<T, Payload>>
for SignedBlockContents<T, Payload>
{
fn from(block: SignedBeaconBlock<T, Payload>) -> Self {
match block {
SignedBeaconBlock::Base(_)
| SignedBeaconBlock::Altair(_)
| SignedBeaconBlock::Merge(_)
| SignedBeaconBlock::Capella(_) => SignedBlockContents::Block(block),
//TODO: error handling, this should be try from
SignedBeaconBlock::Eip4844(_block) => todo!(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Encode)]
#[serde(bound = "T: EthSpec")]
pub struct SignedBeaconBlockAndBlobSidecars<T: EthSpec, Payload: AbstractExecPayload<T>> {
pub signed_block: SignedBeaconBlock<T, Payload>,
pub signed_blob_sidecars: VariableList<SignedBlobSidecar<T>, <T as EthSpec>::MaxBlobsPerBlock>,
}

View File

@ -102,7 +102,6 @@ pub mod blob_sidecar;
pub mod blobs_sidecar;
pub mod signed_blob;
pub mod signed_block_and_blobs;
pub mod signed_block_contents;
pub mod transaction;
use ethereum_types::{H160, H256};
@ -185,10 +184,8 @@ pub use crate::signed_beacon_block::{
pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader;
pub use crate::signed_blob::*;
pub use crate::signed_block_and_blobs::{
SignedBeaconBlockAndBlobSidecars, SignedBeaconBlockAndBlobsSidecar,
SignedBeaconBlockAndBlobsSidecarDecode,
SignedBeaconBlockAndBlobsSidecar, SignedBeaconBlockAndBlobsSidecarDecode,
};
pub use crate::signed_block_contents::SignedBlockContents;
pub use crate::signed_bls_to_execution_change::SignedBlsToExecutionChange;
pub use crate::signed_contribution_and_proof::SignedContributionAndProof;
pub use crate::signed_voluntary_exit::SignedVoluntaryExit;

View File

@ -1,12 +1,8 @@
use crate::{
AbstractExecPayload, BlobsSidecar, EthSpec, SignedBeaconBlock, SignedBeaconBlockEip4844,
SignedBlobSidecar,
};
use crate::{BlobsSidecar, EthSpec, SignedBeaconBlock, SignedBeaconBlockEip4844};
use derivative::Derivative;
use serde_derive::{Deserialize, Serialize};
use ssz::{Decode, DecodeError};
use ssz_derive::{Decode, Encode};
use ssz_types::VariableList;
use std::sync::Arc;
use tree_hash_derive::TreeHash;
@ -37,11 +33,3 @@ impl<T: EthSpec> SignedBeaconBlockAndBlobsSidecar<T> {
})
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash, Derivative)]
#[derivative(PartialEq, Hash(bound = "T: EthSpec"))]
#[serde(bound = "T: EthSpec")]
pub struct SignedBeaconBlockAndBlobSidecars<T: EthSpec, Payload: AbstractExecPayload<T>> {
pub signed_block: SignedBeaconBlock<T, Payload>,
pub signed_blob_sidecars: VariableList<SignedBlobSidecar<T>, <T as EthSpec>::MaxBlobsPerBlock>,
}

View File

@ -1,49 +0,0 @@
use crate::signed_block_and_blobs::SignedBeaconBlockAndBlobSidecars;
use crate::{AbstractExecPayload, EthSpec, FullPayload, SignedBeaconBlock, SignedBlobSidecar};
use derivative::Derivative;
use serde_derive::{Deserialize, Serialize};
use ssz_types::VariableList;
/// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobSidecars`].
#[derive(Clone, Debug, Derivative, Serialize, Deserialize)]
#[derivative(PartialEq, Hash(bound = "T: EthSpec"))]
#[serde(untagged)]
#[serde(bound = "T: EthSpec")]
pub enum SignedBlockContents<T: EthSpec, Payload: AbstractExecPayload<T> = FullPayload<T>> {
BlockAndBlobSidecars(SignedBeaconBlockAndBlobSidecars<T, Payload>),
Block(SignedBeaconBlock<T, Payload>),
}
impl<T: EthSpec, Payload: AbstractExecPayload<T>> SignedBlockContents<T, Payload> {
pub fn signed_block(&self) -> &SignedBeaconBlock<T, Payload> {
match self {
SignedBlockContents::BlockAndBlobSidecars(block_and_sidecars) => {
&block_and_sidecars.signed_block
}
SignedBlockContents::Block(block) => block,
}
}
pub fn deconstruct(
self,
) -> (
SignedBeaconBlock<T, Payload>,
Option<VariableList<SignedBlobSidecar<T>, <T as EthSpec>::MaxBlobsPerBlock>>,
) {
match self {
SignedBlockContents::BlockAndBlobSidecars(block_and_sidecars) => (
block_and_sidecars.signed_block,
Some(block_and_sidecars.signed_blob_sidecars),
),
SignedBlockContents::Block(block) => (block, None),
}
}
}
impl<T: EthSpec, Payload: AbstractExecPayload<T>> From<SignedBeaconBlock<T, Payload>>
for SignedBlockContents<T, Payload>
{
fn from(block: SignedBeaconBlock<T, Payload>) -> Self {
SignedBlockContents::Block(block)
}
}

View File

@ -7,6 +7,7 @@ use crate::{
};
use crate::{http_metrics::metrics, validator_store::ValidatorStore};
use environment::RuntimeContext;
use eth2::types::SignedBlockContents;
use slog::{crit, debug, error, info, trace, warn};
use slot_clock::SlotClock;
use std::ops::Deref;
@ -16,7 +17,7 @@ use tokio::sync::mpsc;
use tokio::time::sleep;
use types::{
AbstractExecPayload, BeaconBlock, BlindedPayload, BlockType, EthSpec, FullPayload, Graffiti,
PublicKeyBytes, SignedBlockContents, Slot,
PublicKeyBytes, Slot,
};
#[derive(Debug)]
@ -388,7 +389,6 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
))
})?
.data
.into()
}
};
@ -455,7 +455,7 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
);
beacon_node
// TODO: need to be adjusted for blobs
.post_beacon_blinded_blocks(&signed_block_contents.signed_block())
.post_beacon_blinded_blocks(signed_block_contents.signed_block())
.await
.map_err(|e| {
BlockError::Irrecoverable(format!(