Skip to content
Merged

Devnet6 #4404

Show file tree
Hide file tree
Changes from 154 commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
8d80200
some blob reprocessing work
realbigsean Mar 28, 2023
9642ec0
remove ForceBlockLookup
realbigsean Mar 29, 2023
b78a6e8
reorder enum match arms in sync manager
realbigsean Mar 29, 2023
8403402
a lot more reprocessing work
realbigsean Mar 31, 2023
a17405a
impl logic for triggerng blob lookups along with block lookups
realbigsean Mar 31, 2023
22694d1
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 4, 2023
6f12df3
deal with rpc blobs in groups per block in the da checker. don't cach…
realbigsean Apr 4, 2023
38e0994
make single block lookup generic
realbigsean Apr 4, 2023
66e09f4
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 6, 2023
25ff6e8
more work
realbigsean Apr 11, 2023
2f8c885
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 12, 2023
8618c30
add delayed processing logic and combine some requests
realbigsean Apr 14, 2023
195d802
start fixing some compile errors
realbigsean Apr 17, 2023
0ad9fdf
fix compilation in main block lookup mod
realbigsean Apr 19, 2023
374ec48
much work
realbigsean Apr 19, 2023
c714249
get things compiling
realbigsean Apr 20, 2023
0cc1704
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 20, 2023
bacec52
parent blob lookups
realbigsean Apr 20, 2023
3e854ae
fix compile
realbigsean Apr 21, 2023
d8ed811
revert red/stevie changes
pawanjay176 Apr 21, 2023
b2a4c4e
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 22, 2023
269122f
Merge branch 'some-blob-reprocessing-work' of https://github.com/real…
realbigsean Apr 22, 2023
03de817
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 24, 2023
93df0f5
fix up sync manager delay message logic
realbigsean Apr 24, 2023
381044a
add peer usefulness enum
realbigsean Apr 24, 2023
b6531aa
should remove lookup refactor
realbigsean Apr 24, 2023
274aba9
consolidate retry error handling
realbigsean Apr 24, 2023
0560b7d
improve peer scoring during certain failures in parent lookups
realbigsean Apr 24, 2023
1d18756
improve retry code
realbigsean Apr 24, 2023
76c09de
drop parent lookup if either req has a peer disconnect during download
realbigsean Apr 24, 2023
91594ad
refactor single block processed method
realbigsean Apr 25, 2023
b8708e3
processing peer refactor
realbigsean Apr 25, 2023
53c0356
smol bugfix
realbigsean Apr 25, 2023
9c2acee
fix some todos
realbigsean Apr 25, 2023
b5440f7
fix lints
realbigsean Apr 25, 2023
14e5bfa
fix lints
realbigsean Apr 25, 2023
ff58698
fix compile in lookup tests
realbigsean Apr 26, 2023
83c3ee1
fix lints
realbigsean Apr 26, 2023
46a9b3a
fix lints
realbigsean Apr 26, 2023
4390036
fix existing block lookup tests
realbigsean Apr 26, 2023
69e5e00
renamings
realbigsean Apr 26, 2023
13f7217
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 26, 2023
d850788
fix after merge
realbigsean Apr 26, 2023
0978848
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 26, 2023
2cad638
cargo fmt
realbigsean Apr 26, 2023
3c9fb78
compilation fix in beacon chain tests
realbigsean Apr 26, 2023
7614abf
fix
realbigsean Apr 26, 2023
f226721
refactor lookup tests to work with multiple forks and response types
realbigsean Apr 27, 2023
8e9c98e
make tests into macros
realbigsean Apr 27, 2023
d224fce
wrap availability check error
realbigsean Apr 27, 2023
eadf293
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 27, 2023
185b761
fix compile after merge
realbigsean Apr 27, 2023
a9b24bb
add random blobs
realbigsean Apr 27, 2023
bfb5242
start fixing up lookup verify error handling
realbigsean Apr 28, 2023
93bcd62
some bug fixes and the start of deneb only tests
realbigsean Apr 28, 2023
8edefb7
make tests work for all forks
realbigsean May 2, 2023
56b2365
track information about peer source
realbigsean May 2, 2023
e3f4218
error refactoring
realbigsean May 2, 2023
af15789
improve peer scoring
realbigsean May 2, 2023
f5facd6
fix test compilation
realbigsean May 2, 2023
a0f6159
make sure blobs are sent for processing after stream termination, del…
realbigsean May 3, 2023
6aff52c
add some tests and fix a bug
realbigsean May 8, 2023
51c4506
smol bugfixes and moar tests
realbigsean May 9, 2023
542e3c1
add tests and fix some things
realbigsean May 18, 2023
4dd1184
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean May 18, 2023
bef63e4
compile after merge
realbigsean May 18, 2023
c7aad77
lots of refactoring
realbigsean May 19, 2023
c59a3fc
retry on invalid block/blob
realbigsean May 22, 2023
8ea98c5
merge unknown parent messages before current slot lookup
realbigsean May 23, 2023
98d7a10
get tests compiling
realbigsean May 23, 2023
944c973
penalize blob peer on invalid blobs
realbigsean May 23, 2023
dc20155
Check disk on in-memory cache miss
ethDreamer May 27, 2023
4c17993
Update beacon_node/beacon_chain/src/data_availability_checker/overflo…
realbigsean May 30, 2023
2bcdfc6
Merge pull request #30 from ethDreamer/check_disk
realbigsean May 30, 2023
4ba3849
Update beacon_node/network/src/sync/network_context.rs
realbigsean Jun 1, 2023
8c5c92b
fix bug in matching blocks and blobs in range sync
realbigsean Jun 1, 2023
f31c551
Merge branch 'some-blob-reprocessing-work' of https://github.com/real…
realbigsean Jun 1, 2023
28b92cd
pr feedback
realbigsean Jun 1, 2023
e503c8e
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Jun 2, 2023
e617486
fix conflicts
realbigsean Jun 2, 2023
844920c
upgrade logs from warn to crit when we receive incorrect response in …
realbigsean Jun 2, 2023
4b687c9
synced_and_connected_within_tolerance -> should_search_for_block
realbigsean Jun 2, 2023
e6b0754
remove todo
realbigsean Jun 6, 2023
6970f7a
add data gas used and update excess data gas to u64
realbigsean Jun 7, 2023
ee9578f
Fix Broken Overflow Tests
ethDreamer Jun 7, 2023
584eb6e
Merge pull request #31 from ethDreamer/fix_overflow_tests
realbigsean Jun 7, 2023
5d73a9b
payload verification with commitments
realbigsean Jun 7, 2023
ad422c3
Merge branch 'some-blob-reprocessing-work' of https://github.com/real…
realbigsean Jun 7, 2023
c9727ae
merge upstream
realbigsean Jun 7, 2023
185aecb
fix merge conflicts
realbigsean Jun 7, 2023
390b440
Merge branch 'some-blob-reprocessing-work' of https://github.com/real…
realbigsean Jun 7, 2023
9359371
restore payload file
realbigsean Jun 7, 2023
8f81558
Restore payload file
realbigsean Jun 7, 2023
7758e06
remove todo
realbigsean Jun 7, 2023
2809a84
add max blob commitments per block
realbigsean Jun 7, 2023
1391905
c-kzg lib update
realbigsean Jun 7, 2023
8da95ac
Fix ef tests
realbigsean Jun 8, 2023
0289804
Abstract over minimal/mainnet spec in kzg crate
michaelsproul Jun 9, 2023
59415cc
Start integrating new KZG
michaelsproul Jun 9, 2023
28576c9
checkpoint sync without alignment
realbigsean Jun 9, 2023
9fa67cc
checkpoint sync without alignment
realbigsean Jun 9, 2023
5f7610d
add import
realbigsean Jun 9, 2023
da25512
add import
realbigsean Jun 9, 2023
5fda708
query for checkpoint state by slot rather than state root (teku doesn…
realbigsean Jun 9, 2023
b465530
query for checkpoint state by slot rather than state root (teku doesn…
realbigsean Jun 9, 2023
069d13d
loosen check
realbigsean Jun 9, 2023
1ddd335
get state first and query by most recent block root
realbigsean Jun 12, 2023
30fe57e
Revert "loosen check"
realbigsean Jun 12, 2023
1f611fe
get state first and query by most recent block root
realbigsean Jun 12, 2023
bb07e34
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Jun 12, 2023
7478e75
merge max blobs change
realbigsean Jun 12, 2023
d656d4b
simplify delay logic
realbigsean Jun 13, 2023
7461731
rename unknown parent sync message variants
realbigsean Jun 13, 2023
453e038
rename parameter, block_slot -> slot
realbigsean Jun 13, 2023
c39ae51
add some docs to the lookup module
realbigsean Jun 13, 2023
61b1a11
use interval instead of sleep
realbigsean Jun 13, 2023
a69b4af
drop request if blocks and blobs requests both return `None` for `Id`
realbigsean Jun 13, 2023
ef8630c
clean up `find_single_lookup` logic
realbigsean Jun 13, 2023
2a1ea23
add lookup source enum
realbigsean Jun 13, 2023
2d5a256
clean up `find_single_lookup` logic
realbigsean Jun 13, 2023
59df842
add docs to find_single_lookup_request
realbigsean Jun 13, 2023
3b84894
move LookupSource our of param where unnecessary
realbigsean Jun 13, 2023
db20e2e
remove unnecessary todo
realbigsean Jun 13, 2023
52ed9ab
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Jun 13, 2023
36309d3
query for block by `state.latest_block_header.slot`
realbigsean Jun 13, 2023
b61772e
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Jun 13, 2023
1c240fc
fix lint
realbigsean Jun 13, 2023
9a8f932
Merge branch 'some-blob-reprocessing-work' of https://github.com/real…
realbigsean Jun 13, 2023
17592e7
fix merge transition ef tests
realbigsean Jun 13, 2023
4dd2130
fix test
realbigsean Jun 13, 2023
5a2026a
fix test
realbigsean Jun 13, 2023
7887d40
Merge branch 'checkpoint-sync-without-alignment' of https://github.co…
realbigsean Jun 13, 2023
74a3c19
Merge branch 'some-blob-reprocessing-work' of https://github.com/real…
realbigsean Jun 13, 2023
147d8a5
fix observed blob sidecars test
realbigsean Jun 13, 2023
4553b40
Add some metrics (#33)
pawanjay176 Jun 14, 2023
e241bc8
fix protocol limits for blobs by root
realbigsean Jun 14, 2023
238fa10
Merge branch 'devnet6' of https://github.com/realbigsean/lighthouse i…
realbigsean Jun 14, 2023
29b7737
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Jun 15, 2023
db4d597
Update Engine API for 1:1 Structure Method
ethDreamer Jun 20, 2023
dfc46a4
Merge pull request #34 from ethDreamer/single_object_engine_api
realbigsean Jun 22, 2023
97d5e90
make beacon chain tests to fix devnet 6 changes
realbigsean Jun 23, 2023
602342f
Merge branch 'abstract-kzg-minimal' of https://github.com/michaelspro…
realbigsean Jun 23, 2023
ae5d355
get ckzg working and fix some tests
realbigsean Jun 27, 2023
18af05a
fix remaining tests
realbigsean Jun 27, 2023
5a7b761
Merge pull request #35 from realbigsean/devnet6-test
realbigsean Jun 27, 2023
c81ef8c
fix lints
realbigsean Jun 27, 2023
57f55d5
Fix KZG linking issues
michaelsproul Jun 28, 2023
03524ec
Merge pull request #36 from michaelsproul/devnet6-kzg-fix
realbigsean Jun 28, 2023
2259190
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Jun 28, 2023
8c9cd29
remove unused dep
realbigsean Jun 28, 2023
49528c4
lockfile
realbigsean Jun 28, 2023
d12db6f
test fixes
realbigsean Jun 28, 2023
923baee
remove dbgs
realbigsean Jun 28, 2023
372f97f
remove unwrap
realbigsean Jun 28, 2023
3469283
cleanup tx generator
realbigsean Jun 28, 2023
bde5987
small fixes
realbigsean Jun 28, 2023
a515fd9
fixing fixes
realbigsean Jun 28, 2023
7d8106a
more self reivew
realbigsean Jun 28, 2023
c2e045c
more self review
realbigsean Jun 28, 2023
c9c49e6
refactor genesis header initialization
realbigsean Jun 28, 2023
b24cf80
refactor mock el instantiations
realbigsean Jun 28, 2023
32a4e7e
fix compile
realbigsean Jun 28, 2023
89306dd
fix network test, make sure they run for each fork
realbigsean Jun 28, 2023
afc4290
pr feedback
realbigsean Jun 29, 2023
e51ad1b
fix last test (hopefully)
realbigsean Jun 29, 2023
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
786 changes: 438 additions & 348 deletions Cargo.lock

Large diffs are not rendered by default.

47 changes: 13 additions & 34 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ use store::{
use task_executor::{ShutdownReason, TaskExecutor};
use tokio_stream::Stream;
use tree_hash::TreeHash;
use types::beacon_block_body::KzgCommitments;
use types::beacon_state::CloneConfig;
use types::blob_sidecar::{BlobSidecarList, Blobs};
use types::blob_sidecar::BlobSidecarList;
use types::consts::deneb::MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS;
use types::*;

Expand Down Expand Up @@ -466,7 +465,7 @@ pub struct BeaconChain<T: BeaconChainTypes> {
pub genesis_backfill_slot: Slot,
pub proposal_blob_cache: BlobCache<T::EthSpec>,
pub data_availability_checker: Arc<DataAvailabilityChecker<T>>,
pub kzg: Option<Arc<Kzg>>,
pub kzg: Option<Arc<Kzg<<T::EthSpec as EthSpec>::Kzg>>>,
}

type BeaconBlockAndState<T, Payload> = (BeaconBlock<T, Payload>, BeaconState<T>);
Expand Down Expand Up @@ -2914,7 +2913,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
) -> Result<AvailabilityProcessingStatus, BlockError<T::EthSpec>> {
let availability = cache_fn(self.clone())?;
match availability {
Availability::Available(block) => self.import_available_block(block).await,
Availability::Available(block) => {
// This is the time since start of the slot where all the components of the block have become available
let delay =
get_slot_delay_ms(timestamp_now(), block.block.slot(), &self.slot_clock);
metrics::observe_duration(&metrics::BLOCK_AVAILABILITY_DELAY, delay);
// Block is fully available, import into fork choice
self.import_available_block(block).await
}
Availability::MissingComponents(block_root) => Ok(
AvailabilityProcessingStatus::MissingComponents(slot, block_root),
),
Expand Down Expand Up @@ -4903,7 +4909,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

//FIXME(sean)
// - add a new timer for processing here
if let Some(blobs) = blobs_opt {
if let (Some(blobs), Some(proofs)) = (blobs_opt, proofs_opt) {
let kzg = self
.kzg
.as_ref()
Expand All @@ -4924,14 +4930,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
)));
}

let kzg_proofs = if let Some(proofs) = proofs_opt {
Vec::from(proofs)
} else {
Self::compute_blob_kzg_proofs(kzg, &blobs, expected_kzg_commitments, slot)?
};
let kzg_proofs = Vec::from(proofs);

kzg_utils::validate_blobs::<T::EthSpec>(
kzg,
kzg.as_ref(),
expected_kzg_commitments,
&blobs,
&kzg_proofs,
Expand Down Expand Up @@ -4982,29 +4984,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Ok((block, state))
}

fn compute_blob_kzg_proofs(
kzg: &Arc<Kzg>,
blobs: &Blobs<T::EthSpec>,
expected_kzg_commitments: &KzgCommitments<T::EthSpec>,
slot: Slot,
) -> Result<Vec<KzgProof>, BlockProductionError> {
blobs
.iter()
.enumerate()
.map(|(blob_index, blob)| {
let kzg_commitment = expected_kzg_commitments.get(blob_index).ok_or(
BlockProductionError::MissingKzgCommitment(format!(
"Missing KZG commitment for slot {} blob index {}",
slot, blob_index
)),
)?;

kzg_utils::compute_blob_kzg_proof::<T::EthSpec>(kzg, blob, *kzg_commitment)
.map_err(BlockProductionError::KzgError)
})
.collect::<Result<Vec<KzgProof>, BlockProductionError>>()
}

/// This method must be called whenever an execution engine indicates that a payload is
/// invalid.
///
Expand Down
103 changes: 75 additions & 28 deletions beacon_node/beacon_chain/src/blob_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use state_processing::state_advance::partial_state_advance;
use std::sync::Arc;

use crate::beacon_chain::{
BeaconChain, BeaconChainTypes, MAXIMUM_GOSSIP_CLOCK_DISPARITY,
VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT,
BeaconChain, BeaconChainTypes, BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT,
MAXIMUM_GOSSIP_CLOCK_DISPARITY, VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT,
};
use crate::data_availability_checker::{
AvailabilityCheckError, AvailabilityPendingBlock, AvailableBlock,
Expand All @@ -20,9 +20,9 @@ use ssz_types::FixedVector;
use std::borrow::Cow;
use types::blob_sidecar::{BlobIdentifier, FixedBlobSidecarList};
use types::{
BeaconBlockRef, BeaconState, BeaconStateError, BlobSidecar, ChainSpec, CloneConfig, Epoch,
EthSpec, FullPayload, Hash256, KzgCommitment, RelativeEpoch, SignedBeaconBlock,
SignedBeaconBlockHeader, SignedBlobSidecar, Slot,
BeaconBlockRef, BeaconState, BeaconStateError, BlobSidecar, BlobSidecarList, ChainSpec,
CloneConfig, Epoch, EthSpec, FullPayload, Hash256, KzgCommitment, RelativeEpoch,
SignedBeaconBlock, SignedBeaconBlockHeader, SignedBlobSidecar, Slot,
};

#[derive(Debug)]
Expand Down Expand Up @@ -240,36 +240,72 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
"block_root" => %block_root,
"index" => %blob_index,
);
// The cached head state is in the same epoch as the blob or the state has already been
// advanced to the blob's epoch
let snapshot = &chain.canonical_head.cached_head().snapshot;
if snapshot.beacon_state.current_epoch() == blob_slot.epoch(T::EthSpec::slots_per_epoch()) {
(
snapshot
.beacon_state
.get_beacon_proposer_index(blob_slot, &chain.spec)?,
snapshot.beacon_state.fork(),
)
if let Some(mut snapshot) = chain

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to understand why the snapshot_cache is better than the cacnonical head in this case. Is it because it has less lock contention?
P.S. I don't remember why I used the cached_head in the first place 😂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need to make sure we are getting shuffling based on the parent state of this blob we're verifying, and our cached head might not be the one this blob builds on, but we still need to verify it. So we could use the cached head and fall back to the snapshot cache if the cached head isn't what the blob builds on but I figured this was simpler.

.snapshot_cache
.try_read_for(BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT)
.and_then(|snapshot_cache| {
snapshot_cache.get_cloned(block_parent_root, CloneConfig::committee_caches_only())
})
{
if snapshot.beacon_state.slot() == blob_slot {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering why we need to clone the state if we don't need to advance it in this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling get_state_for_block_processing evicts the state from the snapshot cache which we don't want because we want to use the same state for block and all blob verification. This is actually making me realize we want to make sure we aren't evicting the state during block processing or we will always get cache misses here 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tree states would end up making this a lot simpler... i'm not really sure how we should be handling this here..

debug!(
chain.log,
"Cloning snapshot cache state for blob verification";
"block_root" => %block_root,
"index" => %blob_index,
);
(
snapshot
.beacon_state
.get_beacon_proposer_index(blob_slot, &chain.spec)?,
snapshot.beacon_state.fork(),
)
} else {
debug!(
chain.log,
"Cloning and advancing snapshot cache state for blob verification";
"block_root" => %block_root,
"index" => %blob_index,
);
let state = cheap_state_advance_to_obtain_committees(
&mut snapshot.beacon_state,
Some(snapshot.beacon_block_root),
blob_slot,
&chain.spec,
)?;
(
state.get_beacon_proposer_index(blob_slot, &chain.spec)?,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we prime the proposer cache here as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should... I'm wondering if we should separate this state-loading issue into a new task/pr.. what's here should work but is probably pretty suboptimal in practice. I'm not sure we should block merging this on this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

state.fork(),
)
}
}
// Need to advance the state to get the proposer index
else {
// Reaching this condition too often might be an issue since we could theoretically have
// 5 threads (4 blob indices + 1 block) cloning the state.
// We shouldn't be seeing this condition a lot because we try to advance the state
// 3 seconds before the start of a slot. However, if this becomes an issue during testing, we should
// consider sending a blob for reprocessing to reduce the number of state clones.
warn!(
chain.log,
"Cached head not advanced for blob verification";
"Snapshot cache miss for blob verification";
"block_root" => %block_root,
"index" => %blob_index,
"action" => "contact the devs if you see this msg too often"
);
// The state produced is only valid for determining proposer/attester shuffling indices.
let mut cloned_state = snapshot.clone_with(CloneConfig::committee_caches_only());

let parent_block = chain
.get_blinded_block(&block_parent_root)
.map_err(BlobError::BeaconChainError)?
.ok_or_else(|| {
BlobError::from(BeaconChainError::MissingBeaconBlock(block_parent_root))
})?;

let mut parent_state = chain
.get_state(&parent_block.state_root(), Some(parent_block.slot()))?
.ok_or_else(|| {
BeaconChainError::DBInconsistent(format!(
"Missing state {:?}",
parent_block.state_root()
))
})?;
let state = cheap_state_advance_to_obtain_committees(
&mut cloned_state.beacon_state,
None,
&mut parent_state,
Some(parent_block.state_root()),
blob_slot,
&chain.spec,
)?;
Expand Down Expand Up @@ -449,8 +485,9 @@ impl<T: EthSpec> KzgVerifiedBlob<T> {
/// Returns an error if the kzg verification check fails.
pub fn verify_kzg_for_blob<T: EthSpec>(
blob: Arc<BlobSidecar<T>>,
kzg: &Kzg,
kzg: &Kzg<T::Kzg>,
) -> Result<KzgVerifiedBlob<T>, AvailabilityCheckError> {
let _timer = crate::metrics::start_timer(&crate::metrics::KZG_VERIFICATION_SINGLE_TIMES);
//TODO(sean) remove clone
if validate_blob::<T>(kzg, blob.blob.clone(), blob.kzg_commitment, blob.kzg_proof)
.map_err(AvailabilityCheckError::Kzg)?
Expand All @@ -468,8 +505,9 @@ pub fn verify_kzg_for_blob<T: EthSpec>(
/// in a loop since this function kzg verifies a list of blobs more efficiently.
pub fn verify_kzg_for_blob_list<T: EthSpec>(
blob_list: Vec<Arc<BlobSidecar<T>>>,
kzg: &Kzg,
kzg: &Kzg<T::Kzg>,
) -> Result<KzgVerifiedBlobList<T>, AvailabilityCheckError> {
let _timer = crate::metrics::start_timer(&crate::metrics::KZG_VERIFICATION_BATCH_TIMES);
let (blobs, (commitments, proofs)): (Vec<_>, (Vec<_>, Vec<_>)) = blob_list
.clone()
.into_iter()
Expand Down Expand Up @@ -612,6 +650,15 @@ pub enum BlockWrapper<E: EthSpec> {
}

impl<E: EthSpec> BlockWrapper<E> {
pub fn new(block: Arc<SignedBeaconBlock<E>>, blobs: Option<BlobSidecarList<E>>) -> Self {
match blobs {
Some(blobs) => {
let blobs = FixedVector::from(blobs.into_iter().map(Some).collect::<Vec<_>>());
BlockWrapper::BlockAndBlobs(block, blobs)
}
None => BlockWrapper::Block(block),
}
}
pub fn deconstruct(self) -> (Arc<SignedBeaconBlock<E>>, Option<FixedBlobSidecarList<E>>) {
match self {
BlockWrapper::Block(block) => (block, None),
Expand Down
44 changes: 14 additions & 30 deletions beacon_node/beacon_chain/src/data_availability_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use kzg::Kzg;
use slog::{debug, error};
use slot_clock::SlotClock;
use ssz_types::{Error, FixedVector, VariableList};
use state_processing::per_block_processing::deneb::deneb::verify_kzg_commitments_against_transactions;
use std::collections::HashSet;
use std::sync::Arc;
use strum::IntoStaticStr;
Expand All @@ -21,7 +20,7 @@ use types::blob_sidecar::{BlobIdentifier, BlobSidecar, FixedBlobSidecarList};
use types::consts::deneb::MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS;
use types::ssz_tagged_signed_beacon_block;
use types::{
BeaconBlockRef, BlobSidecarList, ChainSpec, Epoch, EthSpec, ExecPayload, FullPayload, Hash256,
BeaconBlockRef, BlobSidecarList, ChainSpec, Epoch, EthSpec, FullPayload, Hash256,
SignedBeaconBlock, SignedBeaconBlockHeader, Slot,
};

Expand Down Expand Up @@ -85,7 +84,7 @@ impl From<ssz::DecodeError> for AvailabilityCheckError {
pub struct DataAvailabilityChecker<T: BeaconChainTypes> {
availability_cache: Arc<OverflowLRUCache<T>>,
slot_clock: T::SlotClock,
kzg: Option<Arc<Kzg>>,
kzg: Option<Arc<Kzg<<T::EthSpec as EthSpec>::Kzg>>>,
spec: ChainSpec,
}

Expand Down Expand Up @@ -114,7 +113,7 @@ impl<T: EthSpec> Availability<T> {
impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
pub fn new(
slot_clock: T::SlotClock,
kzg: Option<Arc<Kzg>>,
kzg: Option<Arc<Kzg<<T::EthSpec as EthSpec>::Kzg>>>,
store: BeaconStore<T>,
spec: ChainSpec,
) -> Result<Self, AvailabilityCheckError> {
Expand Down Expand Up @@ -296,35 +295,20 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
&self,
block: &Arc<SignedBeaconBlock<T::EthSpec, FullPayload<T::EthSpec>>>,
) -> Result<BlobRequirements, AvailabilityCheckError> {
let verified_blobs = if let (Ok(block_kzg_commitments), Ok(payload)) = (
block.message().body().blob_kzg_commitments(),
block.message().body().execution_payload(),
) {
if let Some(transactions) = payload.transactions() {
let verified = verify_kzg_commitments_against_transactions::<T::EthSpec>(
transactions,
block_kzg_commitments,
)
.map_err(|e| AvailabilityCheckError::TxKzgCommitmentMismatch(format!("{e:?}")))?;
if !verified {
return Err(AvailabilityCheckError::TxKzgCommitmentMismatch(
"a commitment and version didn't match".to_string(),
));
}
}

if self.da_check_required(block.epoch()) {
if block_kzg_commitments.is_empty() {
BlobRequirements::EmptyBlobs
let verified_blobs =
if let Ok(block_kzg_commitments) = block.message().body().blob_kzg_commitments() {
if self.da_check_required(block.epoch()) {
if block_kzg_commitments.is_empty() {
BlobRequirements::EmptyBlobs
} else {
BlobRequirements::Required
}
} else {
BlobRequirements::Required
BlobRequirements::NotRequired
}
} else {
BlobRequirements::NotRequired
}
} else {
BlobRequirements::PreDeneb
};
BlobRequirements::PreDeneb
};
Ok(verified_blobs)
}

Expand Down
17 changes: 13 additions & 4 deletions beacon_node/beacon_chain/src/execution_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use proto_array::{Block as ProtoBlock, ExecutionStatus};
use slog::{debug, warn};
use slot_clock::SlotClock;
use state_processing::per_block_processing::{
compute_timestamp_at_slot, get_expected_withdrawals, is_execution_enabled,
self, compute_timestamp_at_slot, get_expected_withdrawals, is_execution_enabled,
is_merge_transition_complete, partially_verify_execution_payload,
};
use std::sync::Arc;
Expand Down Expand Up @@ -68,15 +68,16 @@ impl<T: BeaconChainTypes> PayloadNotifier<T> {
// the block as optimistically imported. This is particularly relevant in the case
// where we do not send the block to the EL at all.
let block_message = block.message();
let payload = block_message.execution_payload()?;
partially_verify_execution_payload::<_, FullPayload<_>>(
state,
block.slot(),
payload,
block_message.body(),
&chain.spec,
)
.map_err(BlockError::PerBlockProcessingError)?;

let payload = block_message.execution_payload()?;

match notify_execution_layer {
NotifyExecutionLayer::No if chain.config.optimistic_finalized_sync => {
// Verify the block hash here in Lighthouse and immediately mark the block as
Expand Down Expand Up @@ -139,14 +140,22 @@ async fn notify_new_payload<'a, T: BeaconChainTypes>(
block: BeaconBlockRef<'a, T::EthSpec>,
) -> Result<PayloadVerificationStatus, BlockError<T::EthSpec>> {
let execution_payload = block.execution_payload()?;
let versioned_hashes = block.body().blob_kzg_commitments().ok().map(|commitments| {
commitments
.into_iter()
.map(|commitment| {
per_block_processing::deneb::deneb::kzg_commitment_to_versioned_hash(commitment)
})
.collect::<Vec<_>>()
});

let execution_layer = chain
.execution_layer
.as_ref()
.ok_or(ExecutionPayloadError::NoExecutionConnection)?;

let new_payload_response = execution_layer
.notify_new_payload(&execution_payload.into())
.notify_new_payload(&execution_payload.into(), versioned_hashes)
.await;

match new_payload_response {
Expand Down
Loading