Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge queue: embarking unstable (1eb8694) and [#5908 + #5932 + #5922 + #5787] together #5936

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions FUNDING.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"drips": {
"ethereum": {
"ownedBy": "0x25c4a76E7d118705e7Ea2e9b7d8C59930d8aCD3b"
}
}
}
13 changes: 1 addition & 12 deletions beacon_node/beacon_chain/src/blob_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::block_verification::{
use crate::kzg_utils::{validate_blob, validate_blobs};
use crate::{metrics, BeaconChainError};
use kzg::{Error as KzgError, Kzg, KzgCommitment};
use merkle_proof::MerkleTreeError;
use slog::debug;
use ssz_derive::{Decode, Encode};
use ssz_types::VariableList;
Expand Down Expand Up @@ -128,13 +127,6 @@ pub enum GossipBlobError<E: EthSpec> {
/// The blob sidecar is invalid and the peer is faulty.
KzgError(kzg::Error),

/// The kzg commitment inclusion proof failed.
///
/// ## Peer scoring
///
/// The blob sidecar is invalid
InclusionProof(MerkleTreeError),

/// The pubkey cache timed out.
///
/// ## Peer scoring
Expand Down Expand Up @@ -459,10 +451,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(

// Verify the inclusion proof in the sidecar
let _timer = metrics::start_timer(&metrics::BLOB_SIDECAR_INCLUSION_PROOF_VERIFICATION);
if !blob_sidecar
.verify_blob_sidecar_inclusion_proof()
.map_err(GossipBlobError::InclusionProof)?
{
if !blob_sidecar.verify_blob_sidecar_inclusion_proof() {
return Err(GossipBlobError::InvalidInclusionProof);
}
drop(_timer);
Expand Down
2 changes: 0 additions & 2 deletions beacon_node/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate slog;

mod compute_light_client_updates;
pub mod config;
mod metrics;
Expand Down
3 changes: 0 additions & 3 deletions beacon_node/eth1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[macro_use]
extern crate lazy_static;

mod block_cache;
mod deposit_cache;
mod inner;
Expand Down
2 changes: 2 additions & 0 deletions beacon_node/eth1/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub use lighthouse_metrics::*;

use lazy_static::lazy_static;

lazy_static! {
/*
* Eth1 blocks
Expand Down
2 changes: 0 additions & 2 deletions beacon_node/execution_layer/src/versioned_hashes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate alloy_consensus;
extern crate alloy_rlp;
use alloy_consensus::TxEnvelope;
use alloy_rlp::Decodable;
use types::{EthSpec, ExecutionPayloadRef, Hash256, Unsigned, VersionedHash};
Expand Down
3 changes: 0 additions & 3 deletions beacon_node/lighthouse_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
/// all required libp2p functionality.
///
/// This crate builds and manages the libp2p services required by the beacon node.
#[macro_use]
extern crate lazy_static;

mod config;
pub mod service;

Expand Down
2 changes: 2 additions & 0 deletions beacon_node/lighthouse_network/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub use lighthouse_metrics::*;

use lazy_static::lazy_static;

lazy_static! {
pub static ref NAT_OPEN: Result<IntGaugeVec> = try_create_int_gauge_vec(
"nat_open",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//!
//! The scoring algorithms are currently experimental.
use crate::service::gossipsub_scoring_parameters::GREYLIST_THRESHOLD as GOSSIPSUB_GREYLIST_THRESHOLD;
use lazy_static::lazy_static;
use serde::Serialize;
use std::time::Instant;
use strum::AsRefStr;
Expand Down
1 change: 1 addition & 0 deletions beacon_node/lighthouse_network/src/rpc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::rpc::codec::{base::BaseInboundCodec, ssz_snappy::SSZSnappyInboundCode
use futures::future::BoxFuture;
use futures::prelude::{AsyncRead, AsyncWrite};
use futures::{FutureExt, StreamExt};
use lazy_static::lazy_static;
use libp2p::core::{InboundUpgrade, UpgradeInfo};
use ssz::Encode;
use ssz_types::VariableList;
Expand Down
3 changes: 0 additions & 3 deletions beacon_node/network/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[macro_use]
extern crate lazy_static;

/// This crate provides the network server for Lighthouse.
pub mod error;
#[allow(clippy::mutable_key_type)] // PeerId in hashmaps are no longer permitted by clippy
Expand Down
1 change: 1 addition & 0 deletions beacon_node/network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use beacon_chain::{
sync_committee_verification::Error as SyncCommitteeError,
};
use fnv::FnvHashMap;
use lazy_static::lazy_static;
pub use lighthouse_metrics::*;
use lighthouse_network::{
peer_manager::peerdb::client::ClientKind, types::GossipKind, GossipTopic, Gossipsub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
| GossipBlobError::InvalidSubnet { .. }
| GossipBlobError::InvalidInclusionProof
| GossipBlobError::KzgError(_)
| GossipBlobError::InclusionProof(_)
| GossipBlobError::NotFinalizedDescendant { .. } => {
warn!(
self.log,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/network/src/sync/network_context/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<E: EthSpec> ActiveBlobsByRootRequest<E> {
if self.request.block_root != block_root {
return Err(LookupVerifyError::UnrequestedBlockRoot(block_root));
}
if !blob.verify_blob_sidecar_inclusion_proof().unwrap_or(false) {
if !blob.verify_blob_sidecar_inclusion_proof() {
return Err(LookupVerifyError::InvalidInclusionProof);
}
if !self.request.indices.contains(&blob.index) {
Expand Down
2 changes: 0 additions & 2 deletions beacon_node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate clap;

mod cli;
mod config;

Expand Down
3 changes: 0 additions & 3 deletions beacon_node/store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
//!
//! Provides a simple API for storing/retrieving all types that sometimes needs type-hints. See
//! tests for implementation examples.
#[macro_use]
extern crate lazy_static;

mod chunk_writer;
pub mod chunked_iter;
pub mod chunked_vector;
Expand Down
1 change: 1 addition & 0 deletions beacon_node/store/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub use lighthouse_metrics::{set_gauge, try_create_int_gauge, *};

use directory::size_of_dir;
use lazy_static::lazy_static;
use std::path::Path;

lazy_static! {
Expand Down
2 changes: 0 additions & 2 deletions common/compare_fields_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};
Expand Down
4 changes: 1 addition & 3 deletions common/eth2_interop_keypairs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
//!
//! This implementation passes the [reference implementation
//! tests](https://github.com/ethereum/eth2.0-pm/blob/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start/keygen_test_vector.yaml).
#[macro_use]
extern crate lazy_static;

use bls::{Keypair, PublicKey, SecretKey};
use ethereum_hashing::hash;
use lazy_static::lazy_static;
use num_bigint::BigUint;
use serde::{Deserialize, Serialize};
use std::fs::File;
Expand Down
3 changes: 1 addition & 2 deletions common/lighthouse_metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
//! ## Example
//!
//! ```rust
//! #[macro_use]
//! extern crate lazy_static;
//! use lazy_static::lazy_static;
//! use lighthouse_metrics::*;
//!
//! // These metrics are "magically" linked to the global registry defined in `lighthouse_metrics`.
Expand Down
4 changes: 1 addition & 3 deletions common/logging/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#[macro_use]
extern crate lazy_static;

use lazy_static::lazy_static;
use lighthouse_metrics::{
inc_counter, try_create_int_counter, IntCounter, Result as MetricsResult,
};
Expand Down
1 change: 1 addition & 0 deletions common/logging/src/tracing_metrics_layer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Exposes [`MetricsLayer`]: A tracing layer that registers metrics of logging events.

use lazy_static::lazy_static;
use lighthouse_metrics as metrics;
use tracing_log::NormalizeEvent;

Expand Down
3 changes: 0 additions & 3 deletions common/slot_clock/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[macro_use]
extern crate lazy_static;

mod manual_slot_clock;
mod metrics;
mod system_time_slot_clock;
Expand Down
1 change: 1 addition & 0 deletions common/slot_clock/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::SlotClock;
use lazy_static::lazy_static;
pub use lighthouse_metrics::*;
use types::{EthSpec, Slot};

Expand Down
4 changes: 1 addition & 3 deletions common/test_random_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
extern crate proc_macro;

use crate::proc_macro::TokenStream;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};

Expand Down
1 change: 1 addition & 0 deletions consensus/types/src/beacon_state/committee_cache/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::test_utils::*;
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use beacon_chain::types::*;
use lazy_static::lazy_static;
use swap_or_not_shuffle::shuffle_list;

pub const VALIDATOR_COUNT: usize = 16;
Expand Down
1 change: 1 addition & 0 deletions consensus/types/src/beacon_state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use beacon_chain::types::{
ChainSpec, Domain, Epoch, EthSpec, Hash256, Keypair, MainnetEthSpec, MinimalEthSpec,
RelativeEpoch, Slot, Vector,
};
use lazy_static::lazy_static;
use ssz::Encode;
use std::ops::Mul;
use swap_or_not_shuffle::compute_shuffled_index;
Expand Down
31 changes: 14 additions & 17 deletions consensus/types/src/blob_sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use kzg::{
};
use merkle_proof::{merkle_root_from_branch, verify_merkle_proof, MerkleTreeError};
use rand::Rng;
use safe_arith::{ArithError, SafeArith};
use safe_arith::ArithError;
use serde::{Deserialize, Serialize};
use ssz::Encode;
use ssz_derive::{Decode, Encode};
Expand Down Expand Up @@ -190,33 +190,30 @@ impl<E: EthSpec> BlobSidecar<E> {
}

/// Verifies the kzg commitment inclusion merkle proof.
pub fn verify_blob_sidecar_inclusion_proof(&self) -> Result<bool, MerkleTreeError> {
// Depth of the subtree rooted at `blob_kzg_commitments` in the `BeaconBlockBody`
// is equal to depth of the ssz List max size + 1 for the length mixin
let kzg_commitments_tree_depth = (E::max_blob_commitments_per_block()
.next_power_of_two()
.ilog2()
.safe_add(1))? as usize;
pub fn verify_blob_sidecar_inclusion_proof(&self) -> bool {
let kzg_commitments_tree_depth = E::kzg_commitments_tree_depth();

// EthSpec asserts that kzg_commitments_tree_depth is less than KzgCommitmentInclusionProofDepth
let (kzg_commitment_subtree_proof, kzg_commitments_proof) = self
.kzg_commitment_inclusion_proof
.split_at(kzg_commitments_tree_depth);

// Compute the `tree_hash_root` of the `blob_kzg_commitments` subtree using the
// inclusion proof branches
let blob_kzg_commitments_root = merkle_root_from_branch(
self.kzg_commitment.tree_hash_root(),
self.kzg_commitment_inclusion_proof
.get(0..kzg_commitments_tree_depth)
.ok_or(MerkleTreeError::PleaseNotifyTheDevs)?,
kzg_commitment_subtree_proof,
kzg_commitments_tree_depth,
self.index as usize,
);
// The remaining inclusion proof branches are for the top level `BeaconBlockBody` tree
Ok(verify_merkle_proof(
verify_merkle_proof(
blob_kzg_commitments_root,
self.kzg_commitment_inclusion_proof
.get(kzg_commitments_tree_depth..E::kzg_proof_inclusion_proof_depth())
.ok_or(MerkleTreeError::PleaseNotifyTheDevs)?,
E::kzg_proof_inclusion_proof_depth().safe_sub(kzg_commitments_tree_depth)?,
kzg_commitments_proof,
E::block_body_tree_depth(),
BLOB_KZG_COMMITMENTS_INDEX,
self.signed_block_header.message.body_root,
))
)
}

pub fn random_valid<R: Rng>(rng: &mut R, kzg: &Kzg) -> Result<Self, String> {
Expand Down
39 changes: 39 additions & 0 deletions consensus/types/src/eth_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,22 @@ pub trait EthSpec:
Self::KzgCommitmentInclusionProofDepth::to_usize()
}

fn kzg_commitments_tree_depth() -> usize {
// Depth of the subtree rooted at `blob_kzg_commitments` in the `BeaconBlockBody`
// is equal to depth of the ssz List max size + 1 for the length mixin
Self::max_blob_commitments_per_block()
.next_power_of_two()
.ilog2()
.safe_add(1)
.expect("The log of max_blob_commitments_per_block can not overflow") as usize
}

fn block_body_tree_depth() -> usize {
Self::kzg_proof_inclusion_proof_depth()
.safe_sub(Self::kzg_commitments_tree_depth())
.expect("Preset values are not configurable and never result in non-positive block body depth")
}

/// Returns the `PENDING_BALANCE_DEPOSITS_LIMIT` constant for this specification.
fn pending_balance_deposits_limit() -> usize {
Self::PendingBalanceDepositsLimit::to_usize()
Expand Down Expand Up @@ -517,3 +533,26 @@ impl EthSpec for GnosisEthSpec {
EthSpecId::Gnosis
}
}

#[cfg(test)]
mod test {
use crate::{EthSpec, GnosisEthSpec, MainnetEthSpec, MinimalEthSpec};

fn assert_valid_spec<E: EthSpec>() {
E::kzg_commitments_tree_depth();
E::block_body_tree_depth();
}

#[test]
fn mainnet_spec() {
assert_valid_spec::<MainnetEthSpec>();
}
#[test]
fn minimal_spec() {
assert_valid_spec::<MinimalEthSpec>();
}
#[test]
fn gnosis_spec() {
assert_valid_spec::<GnosisEthSpec>();
}
}
2 changes: 0 additions & 2 deletions consensus/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
)
)]

#[macro_use]
extern crate lazy_static;
#[macro_use]
pub mod test_utils;

Expand Down
1 change: 1 addition & 0 deletions consensus/types/src/subnet_id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Identifies each shard by an integer identifier.
use crate::{AttestationData, ChainSpec, CommitteeIndex, Epoch, EthSpec, Slot};
use lazy_static::lazy_static;
use safe_arith::{ArithError, SafeArith};
use serde::{Deserialize, Serialize};
use std::ops::{Deref, DerefMut};
Expand Down
1 change: 1 addition & 0 deletions consensus/types/src/sync_subnet_id.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Identifies each sync committee subnet by an integer identifier.
use crate::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT;
use crate::EthSpec;
use lazy_static::lazy_static;
use safe_arith::{ArithError, SafeArith};
use serde::{Deserialize, Serialize};
use ssz_types::typenum::Unsigned;
Expand Down
Loading
Loading