Skip to content

Commit 7153ecf

Browse files
committed
Resolve TODO for observed times with data columns
1 parent a1b7d61 commit 7153ecf

File tree

5 files changed

+70
-48
lines changed

5 files changed

+70
-48
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -3011,6 +3011,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
30113011
}
30123012

30133013
self.emit_sse_blob_sidecar_events(&block_root, std::iter::once(blob.as_blob()));
3014+
self.observe_data_for_block_import(block_root, blob.slot());
30143015

30153016
let r = self.check_gossip_blob_availability_and_import(blob).await;
30163017
self.remove_notified(&block_root, r)
@@ -3044,6 +3045,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
30443045
return Err(BlockError::DuplicateFullyImported(block_root));
30453046
}
30463047

3048+
self.observe_data_for_block_import(block_root, slot);
3049+
30473050
let r = self
30483051
.check_gossip_data_columns_availability_and_import(
30493052
slot,
@@ -3091,6 +3094,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
30913094
}
30923095

30933096
self.emit_sse_blob_sidecar_events(&block_root, blobs.iter().flatten().map(Arc::as_ref));
3097+
self.observe_data_for_block_import(block_root, slot);
30943098

30953099
let r = self
30963100
.check_rpc_blob_availability_and_import(slot, block_root, blobs)
@@ -3122,6 +3126,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
31223126

31233127
self.emit_sse_blob_sidecar_events(&block_root, blobs.iter().flatten().map(Arc::as_ref));
31243128

3129+
self.observe_data_for_block_import(block_root, slot);
3130+
31253131
let r = self
31263132
.check_engine_blob_availability_and_import(slot, block_root, blobs, data_column_recv)
31273133
.await;
@@ -3149,6 +3155,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
31493155
}
31503156
}
31513157

3158+
/// Record seeing block data (blob / data column) required for block import (excludes data
3159+
/// columns for sampling).
3160+
fn observe_data_for_block_import(&self, block_root: Hash256, slot: Slot) {
3161+
self.block_times_cache
3162+
.write()
3163+
.set_time_data_for_import_observed(block_root, slot, timestamp_now());
3164+
}
3165+
31523166
/// Cache the columns in the processing cache, process it, then evict it from the cache if it was
31533167
/// imported or errors.
31543168
pub async fn process_rpc_custody_columns(
@@ -3189,6 +3203,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
31893203
}
31903204
}
31913205

3206+
self.observe_data_for_block_import(block_root, slot);
3207+
31923208
let r = self
31933209
.check_rpc_custody_columns_availability_and_import(slot, block_root, custody_columns)
31943210
.await;
@@ -3681,16 +3697,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
36813697
data_column_recv,
36823698
} = import_data;
36833699

3684-
// Record the time at which this block's blobs became available.
3685-
if let Some(blobs_available) = block.blobs_available_timestamp() {
3686-
self.block_times_cache.write().set_time_blob_observed(
3687-
block_root,
3688-
block.slot(),
3689-
blobs_available,
3690-
);
3691-
}
3692-
3693-
// TODO(das) record custody column available timestamp
3700+
// Record the time at which this block is considered available.
3701+
self.block_times_cache.write().set_time_available(
3702+
block_root,
3703+
block.slot(),
3704+
block.available_timestamp(),
3705+
);
36943706

36953707
// import
36963708
let chain = self.clone();

beacon_node/beacon_chain/src/block_times_cache.rs

+30-22
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ type BlockRoot = Hash256;
1818
#[derive(Clone, Default)]
1919
pub struct Timestamps {
2020
pub observed: Option<Duration>,
21-
pub all_blobs_observed: Option<Duration>,
21+
pub all_data_for_import_observed: Option<Duration>,
2222
pub consensus_verified: Option<Duration>,
2323
pub started_execution: Option<Duration>,
24+
pub available: Option<Duration>,
2425
pub executed: Option<Duration>,
2526
pub attestable: Option<Duration>,
2627
pub imported: Option<Duration>,
@@ -32,15 +33,13 @@ pub struct Timestamps {
3233
pub struct BlockDelays {
3334
/// Time after start of slot we saw the block.
3435
pub observed: Option<Duration>,
35-
/// The time after the start of the slot we saw all blobs.
36-
pub all_blobs_observed: Option<Duration>,
36+
/// The time after the start of the slot we saw all blobs / data columns.
37+
pub all_data_for_import_observed: Option<Duration>,
3738
/// The time it took to complete consensus verification of the block.
3839
pub consensus_verification_time: Option<Duration>,
3940
/// The time it took to complete execution verification of the block.
4041
pub execution_time: Option<Duration>,
4142
/// The delay from the start of the slot before the block became available
42-
///
43-
/// Equal to max(`observed + execution_time`, `all_blobs_observed`).
4443
pub available: Option<Duration>,
4544
/// Time after `available`.
4645
pub attestable: Option<Duration>,
@@ -59,34 +58,34 @@ impl BlockDelays {
5958
let observed = times
6059
.observed
6160
.and_then(|observed_time| observed_time.checked_sub(slot_start_time));
62-
let all_blobs_observed = times
63-
.all_blobs_observed
64-
.and_then(|all_blobs_observed| all_blobs_observed.checked_sub(slot_start_time));
61+
let all_data_for_import_observed =
62+
times
63+
.all_data_for_import_observed
64+
.and_then(|all_data_for_import_observed| {
65+
all_data_for_import_observed.checked_sub(slot_start_time)
66+
});
6567
let consensus_verification_time = times
6668
.consensus_verified
6769
.and_then(|consensus_verified| consensus_verified.checked_sub(times.observed?));
6870
let execution_time = times
6971
.executed
7072
.and_then(|executed| executed.checked_sub(times.started_execution?));
71-
// Duration since UNIX epoch at which block became available.
72-
let available_time = times
73-
.executed
74-
.map(|executed| std::cmp::max(executed, times.all_blobs_observed.unwrap_or_default()));
7573
// Duration from the start of the slot until the block became available.
76-
let available_delay =
77-
available_time.and_then(|available_time| available_time.checked_sub(slot_start_time));
74+
let available_delay = times
75+
.available
76+
.and_then(|available_time| available_time.checked_sub(slot_start_time));
7877
let attestable = times
7978
.attestable
8079
.and_then(|attestable_time| attestable_time.checked_sub(slot_start_time));
8180
let imported = times
8281
.imported
83-
.and_then(|imported_time| imported_time.checked_sub(available_time?));
82+
.and_then(|imported_time| imported_time.checked_sub(times.available?));
8483
let set_as_head = times
8584
.set_as_head
8685
.and_then(|set_as_head_time| set_as_head_time.checked_sub(times.imported?));
8786
BlockDelays {
8887
observed,
89-
all_blobs_observed,
88+
all_data_for_import_observed,
9089
consensus_verification_time,
9190
execution_time,
9291
available: available_delay,
@@ -157,25 +156,25 @@ impl BlockTimesCache {
157156
}
158157
}
159158

160-
pub fn set_time_blob_observed(
159+
pub fn set_time_data_for_import_observed(
161160
&mut self,
162161
block_root: BlockRoot,
163162
slot: Slot,
164163
timestamp: Duration,
165164
) {
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.
165+
// Unlike other functions in this file, we update the data observed time only if it is
166+
// *greater* than existing data observation times. This allows us to know the observation
167+
// time of the last data to arrive.
169168
let block_times = self
170169
.cache
171170
.entry(block_root)
172171
.or_insert_with(|| BlockTimesCacheValue::new(slot));
173172
if block_times
174173
.timestamps
175-
.all_blobs_observed
174+
.all_data_for_import_observed
176175
.map_or(true, |prev| timestamp > prev)
177176
{
178-
block_times.timestamps.all_blobs_observed = Some(timestamp);
177+
block_times.timestamps.all_data_for_import_observed = Some(timestamp);
179178
}
180179
}
181180

@@ -237,6 +236,15 @@ impl BlockTimesCache {
237236
)
238237
}
239238

239+
pub fn set_time_available(&mut self, block_root: BlockRoot, slot: Slot, timestamp: Duration) {
240+
self.set_time_if_less(
241+
block_root,
242+
slot,
243+
|timestamps| &mut timestamps.available,
244+
timestamp,
245+
)
246+
}
247+
240248
pub fn set_time_attestable(&mut self, block_root: BlockRoot, slot: Slot, timestamp: Duration) {
241249
self.set_time_if_less(
242250
block_root,

beacon_node/beacon_chain/src/canonical_head.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1361,12 +1361,12 @@ fn observe_head_block_delays<E: EthSpec, S: SlotClock>(
13611361
.as_millis() as i64,
13621362
);
13631363

1364-
// The time from the start of the slot when all blobs have been observed. Technically this
1365-
// is the time we last saw a blob related to this block/slot.
1364+
// The time from the start of the slot when all blobs / custody data columns have been
1365+
// observed. Technically this is the time we last saw a blob related to this block/slot.
13661366
metrics::set_gauge(
13671367
&metrics::BEACON_BLOB_DELAY_ALL_OBSERVED_SLOT_START,
13681368
block_delays
1369-
.all_blobs_observed
1369+
.all_data_for_import_observed
13701370
.unwrap_or_else(|| Duration::from_secs(0))
13711371
.as_millis() as i64,
13721372
);
@@ -1441,7 +1441,7 @@ fn observe_head_block_delays<E: EthSpec, S: SlotClock>(
14411441
"slot" => head_block_slot,
14421442
"total_delay_ms" => block_delay_total.as_millis(),
14431443
"observed_delay_ms" => format_delay(&block_delays.observed),
1444-
"blob_delay_ms" => format_delay(&block_delays.all_blobs_observed),
1444+
"data_delay_ms" => format_delay(&block_delays.all_data_for_import_observed),
14451445
"consensus_time_ms" => format_delay(&block_delays.consensus_verification_time),
14461446
"execution_time_ms" => format_delay(&block_delays.execution_time),
14471447
"available_delay_ms" => format_delay(&block_delays.available),
@@ -1458,7 +1458,7 @@ fn observe_head_block_delays<E: EthSpec, S: SlotClock>(
14581458
"slot" => head_block_slot,
14591459
"total_delay_ms" => block_delay_total.as_millis(),
14601460
"observed_delay_ms" => format_delay(&block_delays.observed),
1461-
"blob_delay_ms" => format_delay(&block_delays.all_blobs_observed),
1461+
"data_delay_ms" => format_delay(&block_delays.all_data_for_import_observed),
14621462
"consensus_time_ms" => format_delay(&block_delays.consensus_verification_time),
14631463
"execution_time_ms" => format_delay(&block_delays.execution_time),
14641464
"available_delay_ms" => format_delay(&block_delays.available),

beacon_node/beacon_chain/src/data_availability_checker.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::block_verification_types::{
55
use crate::data_availability_checker::overflow_lru_cache::{
66
DataAvailabilityCheckerInner, ReconstructColumnsDecision,
77
};
8+
use crate::validator_monitor::timestamp_now;
89
use crate::{metrics, BeaconChain, BeaconChainTypes, BeaconStore};
910
use kzg::Kzg;
1011
use slog::{debug, error, Logger};
@@ -350,8 +351,8 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
350351
block_root,
351352
block,
352353
blobs,
353-
blobs_available_timestamp: None,
354354
data_columns: None,
355+
available_timestamp: timestamp_now(),
355356
spec: self.spec.clone(),
356357
}))
357358
} else {
@@ -370,13 +371,13 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
370371
block_root,
371372
block,
372373
blobs: None,
373-
blobs_available_timestamp: None,
374374
data_columns: Some(
375375
data_column_list
376376
.into_iter()
377377
.map(|d| d.clone_arc())
378378
.collect(),
379379
),
380+
available_timestamp: timestamp_now(),
380381
spec: self.spec.clone(),
381382
}))
382383
} else {
@@ -388,8 +389,8 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
388389
block_root,
389390
block,
390391
blobs: None,
391-
blobs_available_timestamp: None,
392392
data_columns: None,
393+
available_timestamp: timestamp_now(),
393394
spec: self.spec.clone(),
394395
}))
395396
}
@@ -445,8 +446,8 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
445446
block_root,
446447
block,
447448
blobs,
448-
blobs_available_timestamp: None,
449449
data_columns: None,
450+
available_timestamp: timestamp_now(),
450451
spec: self.spec.clone(),
451452
})
452453
} else {
@@ -461,7 +462,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
461462
data_columns: data_columns.map(|data_columns| {
462463
data_columns.into_iter().map(|d| d.into_inner()).collect()
463464
}),
464-
blobs_available_timestamp: None,
465+
available_timestamp: timestamp_now(),
465466
spec: self.spec.clone(),
466467
})
467468
} else {
@@ -473,7 +474,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
473474
block,
474475
blobs: None,
475476
data_columns: None,
476-
blobs_available_timestamp: None,
477+
available_timestamp: timestamp_now(),
477478
spec: self.spec.clone(),
478479
})
479480
};
@@ -750,7 +751,7 @@ pub struct AvailableBlock<E: EthSpec> {
750751
blobs: Option<BlobSidecarList<E>>,
751752
data_columns: Option<DataColumnSidecarList<E>>,
752753
/// Timestamp at which this block first became available (UNIX timestamp, time since 1970).
753-
blobs_available_timestamp: Option<Duration>,
754+
available_timestamp: Duration,
754755
pub spec: Arc<ChainSpec>,
755756
}
756757

@@ -767,7 +768,7 @@ impl<E: EthSpec> AvailableBlock<E> {
767768
block,
768769
blobs,
769770
data_columns,
770-
blobs_available_timestamp: None,
771+
available_timestamp: timestamp_now(),
771772
spec,
772773
}
773774
}
@@ -783,8 +784,8 @@ impl<E: EthSpec> AvailableBlock<E> {
783784
self.blobs.as_ref()
784785
}
785786

786-
pub fn blobs_available_timestamp(&self) -> Option<Duration> {
787-
self.blobs_available_timestamp
787+
pub fn available_timestamp(&self) -> Duration {
788+
self.available_timestamp
788789
}
789790

790791
pub fn data_columns(&self) -> Option<&DataColumnSidecarList<E>> {

beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::block_verification_types::{
66
};
77
use crate::data_availability_checker::{Availability, AvailabilityCheckError};
88
use crate::data_column_verification::KzgVerifiedCustodyDataColumn;
9+
use crate::validator_monitor::timestamp_now;
910
use crate::BeaconChainTypes;
1011
use lru::LruCache;
1112
use parking_lot::RwLock;
@@ -332,7 +333,7 @@ impl<E: EthSpec> PendingComponents<E> {
332333
block,
333334
blobs,
334335
data_columns,
335-
blobs_available_timestamp,
336+
available_timestamp: timestamp_now(),
336337
spec: spec.clone(),
337338
};
338339
Ok(Availability::Available(Box::new(

0 commit comments

Comments
 (0)