Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed Jul 26, 2023
1 parent df84f17 commit 1cfa6d2
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 117 deletions.
20 changes: 10 additions & 10 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use crate::validator_monitor::{
};
use crate::validator_pubkey_cache::ValidatorPubkeyCache;
use crate::{metrics, BeaconChainError, BeaconForkChoiceStore, BeaconSnapshot, CachedHead};
use eth2::types::{BlockProposal, EventKind, SseBlock, SseExtendedPayloadAttributes, SyncDuty};
use eth2::types::{EventKind, SseBlock, SseExtendedPayloadAttributes, SyncDuty};
use execution_layer::{
BlockProposalContents, BuilderParams, ChainHealth, ExecutionLayer, FailedCondition,
PayloadAttributes, PayloadStatus,
Expand Down Expand Up @@ -4446,7 +4446,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.task_executor
.spawn_blocking_handle(
move || {
chain.produce_partial_beacon_block::<B>(
chain.produce_partial_beacon_block::<B::Payload>(
state,
state_root_opt,
produce_at_slot,
Expand Down Expand Up @@ -4495,14 +4495,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.map_err(BlockProductionError::TokioJoin)?
}

fn produce_partial_beacon_block<B: BlockProposal<T::EthSpec> + 'static>(
fn produce_partial_beacon_block<Payload: AbstractExecPayload<T::EthSpec> + 'static>(
self: &Arc<Self>,
mut state: BeaconState<T::EthSpec>,
state_root_opt: Option<Hash256>,
produce_at_slot: Slot,
randao_reveal: Signature,
validator_graffiti: Option<Graffiti>,
) -> Result<PartialBeaconBlock<T::EthSpec, B::Payload>, BlockProductionError> {
) -> Result<PartialBeaconBlock<T::EthSpec, Payload>, BlockProductionError> {
let eth1_chain = self
.eth1_chain
.as_ref()
Expand Down Expand Up @@ -4812,14 +4812,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let kzg_proofs = Vec::from(proofs);

match blobs_or_blobs_roots {
BlobsOrBlobRoots::Blobs(blobs) => Some(self.build_blob_sidecars::<B>(
BlobsOrBlobRoots::Blobs(blobs) => Some(self.build_blob_sidecars(
&block,
blobs,
expected_kzg_commitments,
kzg_proofs,
)?),
BlobsOrBlobRoots::BlobRoots(blob_roots) => {
Some(self.build_blinded_blob_sidecars::<B>(
Some(self.build_blinded_blob_sidecars(
&block,
blob_roots,
expected_kzg_commitments,
Expand Down Expand Up @@ -6098,9 +6098,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.unwrap_or(false))
}

fn build_blob_sidecars<B: BlockProposal<T::EthSpec>>(
fn build_blob_sidecars<Payload: AbstractExecPayload<T::EthSpec>>(
&self,
block: &BeaconBlock<T::EthSpec, B::Payload>,
block: &BeaconBlock<T::EthSpec, Payload>,
blobs: Blobs<T::EthSpec>,
expected_kzg_commitments: &KzgCommitments<T::EthSpec>,
kzg_proofs: Vec<KzgProof>,
Expand Down Expand Up @@ -6145,9 +6145,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Ok(SidecarListVariant::Full(blob_sidecars))
}

fn build_blinded_blob_sidecars<B: BlockProposal<T::EthSpec>>(
fn build_blinded_blob_sidecars<Payload: AbstractExecPayload<T::EthSpec>>(
&self,
block: &BeaconBlock<T::EthSpec, B::Payload>,
block: &BeaconBlock<T::EthSpec, Payload>,
blob_roots: BlobRoots<T::EthSpec>,
expected_kzg_commitments: &KzgCommitments<T::EthSpec>,
kzg_proofs: Vec<KzgProof>,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ pub enum BlockProductionError {
blob_block_hash: ExecutionBlockHash,
payload_block_hash: ExecutionBlockHash,
},
NoBlobsCached,
FailedToReadFinalizedBlock(store::Error),
MissingFinalizedBlock(Hash256),
BlockTooLarge(usize),
ShuttingDown,
MissingBlobs,
MissingSyncAggregate,
MissingExecutionPayload,
MissingKzgCommitment(String),
Expand Down
9 changes: 7 additions & 2 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
StateSkipConfig,
};
use bls::get_withdrawal_credentials;
use eth2::types::{BlindedBlockProposal, FullBlockProposal, SignedBlockContentsTuple};
use eth2::types::SignedBlockContentsTuple;
use execution_layer::test_utils::generate_genesis_header;
use execution_layer::{
auth::JwtKey,
Expand Down Expand Up @@ -50,6 +50,7 @@ use state_processing::{
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::marker::PhantomData;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -828,7 +829,11 @@ where
.into_iter()
.map(|blob_sidecar| {
let blinded_sidecar: BlindedBlobSidecar = blob_sidecar.message.into();
SignedSidecar::new(Arc::new(blinded_sidecar), blob_sidecar.signature)
SignedSidecar {
message: Arc::new(blinded_sidecar),
signature: blob_sidecar.signature,
_phantom: PhantomData,
}
})
.collect(),
)
Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/tests/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ async fn get_chain_segment_with_signed_blobs() -> (
.get(&BlobSignatureKey::new(block_root, blob_index))
.unwrap()
.clone(),
_phantom: PhantomData,
}
})
.collect::<Vec<_>>();
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub use engine_api::*;
pub use engine_api::{http, http::deposit_methods, http::HttpJsonRpc};
use engines::{Engine, EngineError};
pub use engines::{EngineState, ForkchoiceState};
use eth2::types::SignedBlockContents;
use eth2::types::{builder_bid::SignedBuilderBid, ForkVersionedResponse};
use eth2::types::{BlindedBlockProposal, SignedBlockContents};
use ethers_core::abi::ethereum_types::FromStrRadixErr;
use ethers_core::types::Transaction as EthersTransaction;
use fork_choice::ForkchoiceUpdateParameters;
Expand Down Expand Up @@ -48,7 +48,8 @@ use types::{
AbstractExecPayload, BeaconStateError, ExecPayload, ExecutionPayloadDeneb, VersionedHash,
};
use types::{
BlindedPayload, BlockType, ChainSpec, Epoch, ExecutionPayloadCapella, ExecutionPayloadMerge,
BlindedBlockProposal, BlindedPayload, BlockType, ChainSpec, Epoch, ExecutionPayloadCapella,
ExecutionPayloadMerge,
};
use types::{ProposerPreparationData, PublicKeyBytes, Signature, Slot, Transaction};

Expand Down Expand Up @@ -1154,7 +1155,6 @@ impl<T: EthSpec> ExecutionLayer<T> {
}
};

// TODO(jimmy): cache blobs bundle
let payload_response = async {
debug!(
self.log(),
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 @@ -28,7 +28,7 @@ pub fn build_block_contents<T: BeaconChainTypes>(
Ok(BlockContents::BlockAndBlobSidecars(block_and_blobs))
} else {
Err(warp_utils::reject::block_production_error(
BlockProductionError::NoBlobsCached,
BlockProductionError::MissingBlobs,
))
}
}
Expand All @@ -54,7 +54,7 @@ pub fn build_blinded_block_contents<T: BeaconChainTypes>(
Ok(BlockContents::BlindedBlockAndBlobSidecars(block_and_blobs))
} else {
Err(warp_utils::reject::block_production_error(
BlockProductionError::NoBlobsCached,
BlockProductionError::MissingBlobs,
))
}
}
Expand Down
13 changes: 6 additions & 7 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ use beacon_chain::{
pub use block_id::BlockId;
use directory::DEFAULT_ROOT_DIR;
use eth2::types::{
self as api_types, BlindedBlockProposal, BroadcastValidation, EndpointVersion, ForkChoice,
ForkChoiceNode, FullBlockProposal, SignedBlockContents, SkipRandaoVerification, ValidatorId,
ValidatorStatus,
self as api_types, BroadcastValidation, EndpointVersion, ForkChoice, ForkChoiceNode,
FullBlockProposal, SignedBlockContents, SkipRandaoVerification, ValidatorId, ValidatorStatus,
};
use lighthouse_network::{types::SyncState, EnrExt, NetworkGlobals, PeerId, PubsubMessage};
use lighthouse_version::version_with_platform;
Expand Down Expand Up @@ -62,10 +61,10 @@ use tokio::sync::mpsc::{Sender, UnboundedSender};
use tokio_stream::{wrappers::BroadcastStream, StreamExt};
use types::{
Attestation, AttestationData, AttestationShufflingId, AttesterSlashing, BeaconStateError,
CommitteeCache, ConfigAndPreset, Epoch, EthSpec, ForkName, ProposerPreparationData,
ProposerSlashing, RelativeEpoch, SignedAggregateAndProof, SignedBlsToExecutionChange,
SignedContributionAndProof, SignedValidatorRegistrationData, SignedVoluntaryExit, Slot,
SyncCommitteeMessage, SyncContributionData,
BlindedBlockProposal, CommitteeCache, ConfigAndPreset, Epoch, EthSpec, ForkName,
ProposerPreparationData, ProposerSlashing, RelativeEpoch, SignedAggregateAndProof,
SignedBlsToExecutionChange, SignedContributionAndProof, SignedValidatorRegistrationData,
SignedVoluntaryExit, Slot, SyncCommitteeMessage, SyncContributionData,
};
use version::{
add_consensus_version_header, execution_optimistic_finalized_fork_versioned_response,
Expand Down
13 changes: 3 additions & 10 deletions beacon_node/http_api/src/publish_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use beacon_chain::{
AvailabilityProcessingStatus, BeaconChain, BeaconChainError, BeaconChainTypes, BlockError,
IntoGossipVerifiedBlockContents, NotifyExecutionLayer,
};
use eth2::types::{BlindedBlockProposal, SignedBlockContents};
use eth2::types::SignedBlockContents;
use eth2::types::{BroadcastValidation, FullBlockProposal};
use execution_layer::ProvenancedPayload;
use lighthouse_network::PubsubMessage;
Expand All @@ -19,8 +19,8 @@ use std::time::Duration;
use tokio::sync::mpsc::UnboundedSender;
use tree_hash::TreeHash;
use types::{
AbstractExecPayload, BeaconBlockRef, EthSpec, ExecPayload, ExecutionBlockHash, FullPayload,
Hash256, SignedBeaconBlock, SignedBlobSidecarList,
AbstractExecPayload, BeaconBlockRef, BlindedBlockProposal, EthSpec, ExecPayload,
ExecutionBlockHash, FullPayload, Hash256, SignedBeaconBlock, SignedBlobSidecarList,
};
use warp::Rejection;

Expand Down Expand Up @@ -317,7 +317,6 @@ pub async fn reconstruct_block<T: BeaconChainTypes>(
.into();
ProvenancedPayload::Local(payload)
// If we already have an execution payload with this transactions root cached, use it.
// TODO(jimmy) get cached blobs
} else if let Some(cached_payload) =
el.get_payload_by_root(&payload_header.tree_hash_root())
{
Expand Down Expand Up @@ -365,20 +364,14 @@ pub async fn reconstruct_block<T: BeaconChainTypes>(
// A block without a payload is pre-merge and we consider it locally
// built.
None => block
// .deconstruct()
// .0
.try_into_full_block(None)
.map(SignedBlockContents::Block)
.map(ProvenancedBlock::local),
Some(ProvenancedPayload::Local(full_payload)) => block
// .deconstruct()
// .0
.try_into_full_block(Some(full_payload))
.map(SignedBlockContents::Block)
.map(ProvenancedBlock::local),
Some(ProvenancedPayload::Builder(full_payload)) => block
// .deconstruct()
// .0
.try_into_full_block(Some(full_payload))
.map(SignedBlockContents::Block)
.map(ProvenancedBlock::builder),
Expand Down
8 changes: 4 additions & 4 deletions beacon_node/http_api/tests/interactive_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use beacon_chain::{
test_utils::{AttestationStrategy, BlockStrategy, SyncCommitteeStrategy},
ChainConfig,
};
use eth2::types::{DepositContractData, StateId};
use eth2::types::{DepositContractData, FullBlockProposal, StateId};
use execution_layer::{ForkchoiceState, PayloadAttributes};
use http_api::test_utils::InteractiveTester;
use parking_lot::Mutex;
Expand All @@ -17,8 +17,8 @@ use std::sync::Arc;
use std::time::Duration;
use tree_hash::TreeHash;
use types::{
Address, Epoch, EthSpec, ExecPayload, ExecutionBlockHash, ForkName, FullPayload,
MainnetEthSpec, MinimalEthSpec, ProposerPreparationData, Slot,
Address, Epoch, EthSpec, ExecPayload, ExecutionBlockHash, ForkName, MainnetEthSpec,
MinimalEthSpec, ProposerPreparationData, Slot,
};

type E = MainnetEthSpec;
Expand Down Expand Up @@ -812,7 +812,7 @@ pub async fn fork_choice_before_proposal() {
.into();
let block_d = tester
.client
.get_validator_blocks::<E, FullPayload<E>>(slot_d, &randao_reveal, None)
.get_validator_blocks::<E, FullBlockProposal>(slot_d, &randao_reveal, None)
.await
.unwrap()
.data
Expand Down
Loading

0 comments on commit 1cfa6d2

Please sign in to comment.