@@ -19,7 +19,9 @@ type BlockRoot = Hash256;
19
19
pub struct Timestamps {
20
20
pub observed : Option < Duration > ,
21
21
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 > ,
23
25
pub attestable : Option < Duration > ,
24
26
pub imported : Option < Duration > ,
25
27
pub set_as_head : Option < Duration > ,
@@ -32,7 +34,9 @@ pub struct BlockDelays {
32
34
pub observed : Option < Duration > ,
33
35
/// The time after the start of the slot we saw all blobs.
34
36
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.
36
40
pub execution_time : Option < Duration > ,
37
41
/// The delay from the start of the slot before the block became available
38
42
///
@@ -58,13 +62,16 @@ impl BlockDelays {
58
62
let all_blobs_observed = times
59
63
. all_blobs_observed
60
64
. 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 ?) ) ;
61
68
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 ?) ) ;
64
71
// 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 ( ) ) ) ;
68
75
// Duration from the start of the slot until the block became available.
69
76
let available_delay =
70
77
available_time. and_then ( |available_time| available_time. checked_sub ( slot_start_time) ) ;
@@ -80,6 +87,7 @@ impl BlockDelays {
80
87
BlockDelays {
81
88
observed,
82
89
all_blobs_observed,
90
+ consensus_verification_time,
83
91
execution_time,
84
92
available : available_delay,
85
93
attestable,
@@ -155,6 +163,9 @@ impl BlockTimesCache {
155
163
slot : Slot ,
156
164
timestamp : Duration ,
157
165
) {
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.
158
169
let block_times = self
159
170
. cache
160
171
. entry ( block_root)
@@ -168,48 +179,89 @@ impl BlockTimesCache {
168
179
}
169
180
}
170
181
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
+ ) {
172
193
let block_times = self
173
194
. cache
174
195
. entry ( block_root)
175
196
. 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) ;
182
200
}
183
201
}
184
202
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
+
185
240
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
+ )
197
247
}
198
248
199
249
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
+ )
205
256
}
206
257
207
258
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
+ )
213
265
}
214
266
215
267
pub fn get_block_delays (
0 commit comments