Skip to content

Commit 7fcb4d8

Browse files
committed
Merge branch 'unstable' into da-checker-das
# Conflicts: # consensus/types/src/chain_spec.rs
2 parents 9a83a7c + 06dff60 commit 7fcb4d8

File tree

109 files changed

+11011
-1325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+11011
-1325
lines changed

Cargo.lock

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ bincode = "1"
101101
bitvec = "1"
102102
byteorder = "1"
103103
bytes = "1"
104-
clap = { version = "4.5.4", features = ["cargo", "wrap_help"] }
104+
clap = { version = "4.5.4", features = ["derive", "cargo", "wrap_help"] }
105105
# Turn off c-kzg's default features which include `blst/portable`. We can turn on blst's portable
106106
# feature ourselves when desired.
107107
c-kzg = { version = "1", default-features = false }
@@ -154,7 +154,7 @@ serde_json = "1"
154154
serde_repr = "0.1"
155155
serde_yaml = "0.9"
156156
sha2 = "0.9"
157-
slog = { version = "2", features = ["max_level_trace", "release_max_level_trace", "nested-values"] }
157+
slog = { version = "2", features = ["max_level_debug", "release_max_level_debug", "nested-values"] }
158158
slog-async = "2"
159159
slog-term = "2"
160160
sloggers = { version = "2", features = ["json"] }
@@ -224,7 +224,7 @@ pretty_reqwest_error = { path = "common/pretty_reqwest_error" }
224224
proto_array = { path = "consensus/proto_array" }
225225
safe_arith = { path = "consensus/safe_arith" }
226226
sensitive_url = { path = "common/sensitive_url" }
227-
slasher = { path = "slasher" }
227+
slasher = { path = "slasher", default-features = false }
228228
slashing_protection = { path = "validator_client/slashing_protection" }
229229
slot_clock = { path = "common/slot_clock" }
230230
state_processing = { path = "consensus/state_processing" }

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ COPY . lighthouse
44
ARG FEATURES
55
ARG PROFILE=release
66
ARG CARGO_USE_GIT_CLI=true
7-
ENV FEATURES $FEATURES
8-
ENV PROFILE $PROFILE
7+
ENV FEATURES=$FEATURES
8+
ENV PROFILE=$PROFILE
99
ENV CARGO_NET_GIT_FETCH_WITH_CLI=$CARGO_USE_GIT_CLI
1010
RUN cd lighthouse && make
1111

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ test-network-%:
174174
# Run the tests in the `slasher` crate for all supported database backends.
175175
test-slasher:
176176
cargo nextest run --release -p slasher --features "lmdb,$(TEST_FEATURES)"
177+
cargo nextest run --release -p slasher --no-default-features --features "redb,$(TEST_FEATURES)"
177178
cargo nextest run --release -p slasher --no-default-features --features "mdbx,$(TEST_FEATURES)"
178-
cargo nextest run --release -p slasher --features "lmdb,mdbx,$(TEST_FEATURES)" # both backends enabled
179+
cargo nextest run --release -p slasher --features "lmdb,mdbx,redb,$(TEST_FEATURES)" # all backends enabled
179180

180181
# Runs only the tests/state_transition_vectors tests.
181182
run-state-transition-tests:

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,14 +3088,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
30883088
notify_execution_layer,
30893089
)?;
30903090
publish_fn()?;
3091+
3092+
// Record the time it took to complete consensus verification.
3093+
if let Some(timestamp) = self.slot_clock.now_duration() {
3094+
self.block_times_cache
3095+
.write()
3096+
.set_time_consensus_verified(block_root, block_slot, timestamp)
3097+
}
3098+
30913099
let executed_block = chain.into_executed_block(execution_pending).await?;
3092-
// Record the time it took to ask the execution layer.
3093-
if let Some(seen_timestamp) = self.slot_clock.now_duration() {
3094-
self.block_times_cache.write().set_execution_time(
3095-
block_root,
3096-
block_slot,
3097-
seen_timestamp,
3098-
)
3100+
3101+
// Record the *additional* time it took to wait for execution layer verification.
3102+
if let Some(timestamp) = self.slot_clock.now_duration() {
3103+
self.block_times_cache
3104+
.write()
3105+
.set_time_executed(block_root, block_slot, timestamp)
30993106
}
31003107

31013108
match executed_block {

beacon_node/beacon_chain/src/block_times_cache.rs

Lines changed: 87 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ type BlockRoot = Hash256;
1919
pub struct Timestamps {
2020
pub observed: Option<Duration>,
2121
pub all_blobs_observed: Option<Duration>,
22-
pub execution_time: Option<Duration>,
22+
pub consensus_verified: Option<Duration>,
23+
pub started_execution: Option<Duration>,
24+
pub executed: Option<Duration>,
2325
pub attestable: Option<Duration>,
2426
pub imported: Option<Duration>,
2527
pub set_as_head: Option<Duration>,
@@ -32,7 +34,9 @@ pub struct BlockDelays {
3234
pub observed: Option<Duration>,
3335
/// The time after the start of the slot we saw all blobs.
3436
pub all_blobs_observed: Option<Duration>,
35-
/// The time it took to get verification from the EL for the block.
37+
/// The time it took to complete consensus verification of the block.
38+
pub consensus_verification_time: Option<Duration>,
39+
/// The time it took to complete execution verification of the block.
3640
pub execution_time: Option<Duration>,
3741
/// The delay from the start of the slot before the block became available
3842
///
@@ -58,13 +62,16 @@ impl BlockDelays {
5862
let all_blobs_observed = times
5963
.all_blobs_observed
6064
.and_then(|all_blobs_observed| all_blobs_observed.checked_sub(slot_start_time));
65+
let consensus_verification_time = times
66+
.consensus_verified
67+
.and_then(|consensus_verified| consensus_verified.checked_sub(times.observed?));
6168
let execution_time = times
62-
.execution_time
63-
.and_then(|execution_time| execution_time.checked_sub(times.observed?));
69+
.executed
70+
.and_then(|executed| executed.checked_sub(times.started_execution?));
6471
// Duration since UNIX epoch at which block became available.
65-
let available_time = times.execution_time.map(|execution_time| {
66-
std::cmp::max(execution_time, times.all_blobs_observed.unwrap_or_default())
67-
});
72+
let available_time = times
73+
.executed
74+
.map(|executed| std::cmp::max(executed, times.all_blobs_observed.unwrap_or_default()));
6875
// Duration from the start of the slot until the block became available.
6976
let available_delay =
7077
available_time.and_then(|available_time| available_time.checked_sub(slot_start_time));
@@ -80,6 +87,7 @@ impl BlockDelays {
8087
BlockDelays {
8188
observed,
8289
all_blobs_observed,
90+
consensus_verification_time,
8391
execution_time,
8492
available: available_delay,
8593
attestable,
@@ -155,6 +163,9 @@ impl BlockTimesCache {
155163
slot: Slot,
156164
timestamp: Duration,
157165
) {
166+
// Unlike other functions in this file, we update the blob observed time only if it is
167+
// *greater* than existing blob observation times. This allows us to know the observation
168+
// time of the last blob to arrive.
158169
let block_times = self
159170
.cache
160171
.entry(block_root)
@@ -168,48 +179,89 @@ impl BlockTimesCache {
168179
}
169180
}
170181

171-
pub fn set_execution_time(&mut self, block_root: BlockRoot, slot: Slot, timestamp: Duration) {
182+
/// Set the timestamp for `field` if that timestamp is less than any previously known value.
183+
///
184+
/// If no previous value is known for the field, then the supplied timestamp will always be
185+
/// stored.
186+
pub fn set_time_if_less(
187+
&mut self,
188+
block_root: BlockRoot,
189+
slot: Slot,
190+
field: impl Fn(&mut Timestamps) -> &mut Option<Duration>,
191+
timestamp: Duration,
192+
) {
172193
let block_times = self
173194
.cache
174195
.entry(block_root)
175196
.or_insert_with(|| BlockTimesCacheValue::new(slot));
176-
if block_times
177-
.timestamps
178-
.execution_time
179-
.map_or(true, |prev| timestamp < prev)
180-
{
181-
block_times.timestamps.execution_time = Some(timestamp);
197+
let existing_timestamp = field(&mut block_times.timestamps);
198+
if existing_timestamp.map_or(true, |prev| timestamp < prev) {
199+
*existing_timestamp = Some(timestamp);
182200
}
183201
}
184202

203+
pub fn set_time_consensus_verified(
204+
&mut self,
205+
block_root: BlockRoot,
206+
slot: Slot,
207+
timestamp: Duration,
208+
) {
209+
self.set_time_if_less(
210+
block_root,
211+
slot,
212+
|timestamps| &mut timestamps.consensus_verified,
213+
timestamp,
214+
)
215+
}
216+
217+
pub fn set_time_executed(&mut self, block_root: BlockRoot, slot: Slot, timestamp: Duration) {
218+
self.set_time_if_less(
219+
block_root,
220+
slot,
221+
|timestamps| &mut timestamps.executed,
222+
timestamp,
223+
)
224+
}
225+
226+
pub fn set_time_started_execution(
227+
&mut self,
228+
block_root: BlockRoot,
229+
slot: Slot,
230+
timestamp: Duration,
231+
) {
232+
self.set_time_if_less(
233+
block_root,
234+
slot,
235+
|timestamps| &mut timestamps.started_execution,
236+
timestamp,
237+
)
238+
}
239+
185240
pub fn set_time_attestable(&mut self, block_root: BlockRoot, slot: Slot, timestamp: Duration) {
186-
let block_times = self
187-
.cache
188-
.entry(block_root)
189-
.or_insert_with(|| BlockTimesCacheValue::new(slot));
190-
if block_times
191-
.timestamps
192-
.attestable
193-
.map_or(true, |prev| timestamp < prev)
194-
{
195-
block_times.timestamps.attestable = Some(timestamp);
196-
}
241+
self.set_time_if_less(
242+
block_root,
243+
slot,
244+
|timestamps| &mut timestamps.attestable,
245+
timestamp,
246+
)
197247
}
198248

199249
pub fn set_time_imported(&mut self, block_root: BlockRoot, slot: Slot, timestamp: Duration) {
200-
let block_times = self
201-
.cache
202-
.entry(block_root)
203-
.or_insert_with(|| BlockTimesCacheValue::new(slot));
204-
block_times.timestamps.imported = Some(timestamp);
250+
self.set_time_if_less(
251+
block_root,
252+
slot,
253+
|timestamps| &mut timestamps.imported,
254+
timestamp,
255+
)
205256
}
206257

207258
pub fn set_time_set_as_head(&mut self, block_root: BlockRoot, slot: Slot, timestamp: Duration) {
208-
let block_times = self
209-
.cache
210-
.entry(block_root)
211-
.or_insert_with(|| BlockTimesCacheValue::new(slot));
212-
block_times.timestamps.set_as_head = Some(timestamp);
259+
self.set_time_if_less(
260+
block_root,
261+
slot,
262+
|timestamps| &mut timestamps.set_as_head,
263+
timestamp,
264+
)
213265
}
214266

215267
pub fn get_block_delays(

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use crate::{
6767
metrics, BeaconChain, BeaconChainError, BeaconChainTypes,
6868
};
6969
use derivative::Derivative;
70-
use eth2::types::{EventKind, PublishBlockRequest};
70+
use eth2::types::{BlockGossip, EventKind, PublishBlockRequest};
7171
use execution_layer::PayloadStatus;
7272
pub use fork_choice::{AttestationFromBlock, PayloadVerificationStatus};
7373
use parking_lot::RwLockReadGuard;
@@ -93,7 +93,6 @@ use std::io::Write;
9393
use std::sync::Arc;
9494
use store::{Error as DBError, HotStateSummary, KeyValueStore, StoreOp};
9595
use task_executor::JoinHandle;
96-
use tree_hash::TreeHash;
9796
use types::{
9897
BeaconBlockRef, BeaconState, BeaconStateError, ChainSpec, Epoch, EthSpec, ExecutionBlockHash,
9998
Hash256, InconsistentFork, PublicKey, PublicKeyBytes, RelativeEpoch, SignedBeaconBlock,
@@ -975,6 +974,16 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
975974
// Validate the block's execution_payload (if any).
976975
validate_execution_payload_for_gossip(&parent_block, block.message(), chain)?;
977976

977+
// Beacon API block_gossip events
978+
if let Some(event_handler) = chain.event_handler.as_ref() {
979+
if event_handler.has_block_gossip_subscribers() {
980+
event_handler.register(EventKind::BlockGossip(Box::new(BlockGossip {
981+
slot: block.slot(),
982+
block: block_root,
983+
})));
984+
}
985+
}
986+
978987
// Having checked the proposer index and the block root we can cache them.
979988
let consensus_context = ConsensusContext::new(block.slot())
980989
.set_current_block_root(block_root)
@@ -1335,6 +1344,13 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
13351344
// The specification declares that this should be run *inside* `per_block_processing`,
13361345
// however we run it here to keep `per_block_processing` pure (i.e., no calls to external
13371346
// servers).
1347+
if let Some(started_execution) = chain.slot_clock.now_duration() {
1348+
chain.block_times_cache.write().set_time_started_execution(
1349+
block_root,
1350+
block.slot(),
1351+
started_execution,
1352+
);
1353+
}
13381354
let payload_verification_status = payload_notifier.notify_new_payload().await?;
13391355

13401356
// If the payload did not validate or invalidate the block, check to see if this block is
@@ -2107,7 +2123,14 @@ pub fn verify_header_signature<T: BeaconChainTypes, Err: BlockBlobError>(
21072123

21082124
fn write_state<E: EthSpec>(prefix: &str, state: &BeaconState<E>, log: &Logger) {
21092125
if WRITE_BLOCK_PROCESSING_SSZ {
2110-
let root = state.tree_hash_root();
2126+
let mut state = state.clone();
2127+
let Ok(root) = state.canonical_root() else {
2128+
error!(
2129+
log,
2130+
"Unable to hash state for writing";
2131+
);
2132+
return;
2133+
};
21112134
let filename = format!("{}_slot_{}_root_{}.ssz", prefix, state.slot(), root);
21122135
let mut path = std::env::temp_dir().join("lighthouse");
21132136
let _ = fs::create_dir_all(path.clone());

beacon_node/beacon_chain/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ mod test {
11951195

11961196
let head = chain.head_snapshot();
11971197

1198-
let state = &head.beacon_state;
1198+
let mut state = head.beacon_state.clone();
11991199
let block = &head.beacon_block;
12001200

12011201
assert_eq!(state.slot(), Slot::new(0), "should start from genesis");
@@ -1206,7 +1206,7 @@ mod test {
12061206
);
12071207
assert_eq!(
12081208
block.state_root(),
1209-
state.canonical_root(),
1209+
state.canonical_root().unwrap(),
12101210
"block should have correct state root"
12111211
);
12121212
assert_eq!(

0 commit comments

Comments
 (0)