@@ -163,20 +163,29 @@ pub fn get_adjusted_notary_delay(
163
163
rank,
164
164
) {
165
165
NotaryDelay :: CanNotarizeAfter ( duration) => Some ( duration) ,
166
- NotaryDelay :: ReachedMaxNotarizationCertificationGap => {
166
+ NotaryDelay :: ReachedMaxNotarizationCertificationGap {
167
+ notarized_height,
168
+ certified_height,
169
+ } => {
167
170
warn ! (
168
171
every_n_seconds => 5 ,
169
172
log,
170
- "notarization certification gap exceeds hard bound of\
173
+ "The gap between the notarization height ({notarized_height}) and \
174
+ the certification height ({certified_height}) exceeds hard bound of \
171
175
{ACCEPTABLE_NOTARIZATION_CERTIFICATION_GAP}"
172
176
) ;
173
177
None
174
178
}
175
- NotaryDelay :: ReachedMaxNotarizationCUPGap => {
179
+ NotaryDelay :: ReachedMaxNotarizationCUPGap {
180
+ notarized_height,
181
+ cup_height,
182
+ } => {
176
183
warn ! (
177
184
every_n_seconds => 5 ,
178
185
log,
179
- "notarization CUP gap exceeds hard bound of {ACCEPTABLE_NOTARIZATION_CUP_GAP}"
186
+ "The gap between the notarization height ({notarized_height}) and \
187
+ the CUP height ({cup_height}) exceeds hard bound of \
188
+ {ACCEPTABLE_NOTARIZATION_CUP_GAP}"
180
189
) ;
181
190
None
182
191
}
@@ -189,10 +198,16 @@ pub enum NotaryDelay {
189
198
CanNotarizeAfter ( Duration ) ,
190
199
/// Gap between notarization and certification is too large. Because we have a
191
200
/// hard limit on this gap, the notary cannot progress for now.
192
- ReachedMaxNotarizationCertificationGap ,
201
+ ReachedMaxNotarizationCertificationGap {
202
+ notarized_height : Height ,
203
+ certified_height : Height ,
204
+ } ,
193
205
/// Gap between notarization and the next CUP is too large. Because we have a
194
206
/// hard limit on this gap, the notary cannot progress for now.
195
- ReachedMaxNotarizationCUPGap ,
207
+ ReachedMaxNotarizationCUPGap {
208
+ notarized_height : Height ,
209
+ cup_height : Height ,
210
+ } ,
196
211
}
197
212
198
213
/// Calculate the required delay for notary based on the rank of block to notarize,
@@ -212,12 +227,17 @@ pub fn get_adjusted_notary_delay_from_settings(
212
227
} = settings;
213
228
214
229
// We impose a hard limit on the gap between notarization and certification.
215
- let notarized_height = pool. get_notarized_height ( ) . get ( ) ;
216
- let certified_height = state_manager. latest_certified_height ( ) . get ( ) ;
217
- if notarized_height. saturating_sub ( certified_height)
230
+ let notarized_height = pool. get_notarized_height ( ) ;
231
+ let certified_height = state_manager. latest_certified_height ( ) ;
232
+ if notarized_height
233
+ . get ( )
234
+ . saturating_sub ( certified_height. get ( ) )
218
235
>= ACCEPTABLE_NOTARIZATION_CERTIFICATION_GAP
219
236
{
220
- return NotaryDelay :: ReachedMaxNotarizationCertificationGap ;
237
+ return NotaryDelay :: ReachedMaxNotarizationCertificationGap {
238
+ notarized_height,
239
+ certified_height,
240
+ } ;
221
241
}
222
242
223
243
// We adjust regular delay based on the gap between finalization and
@@ -247,7 +267,6 @@ pub fn get_adjusted_notary_delay_from_settings(
247
267
// We measure the gap between our current CUP height and the current notarized
248
268
// height. If the notarized height is in a DKG interval for which we don't yet have
249
269
// the CUP, we limit the notarization-CUP gap to ACCEPTABLE_NOTARIZATION_CUP_GAP.
250
- let cup_gap = notarized_height. saturating_sub ( pool. get_catch_up_height ( ) . get ( ) ) ;
251
270
let last_cup = pool. get_highest_catch_up_package ( ) ;
252
271
let last_cup_dkg_info = & last_cup
253
272
. content
@@ -257,8 +276,13 @@ pub fn get_adjusted_notary_delay_from_settings(
257
276
. as_ref ( )
258
277
. as_summary ( )
259
278
. dkg ;
279
+ let cup_height = last_cup. height ( ) ;
280
+ let cup_gap = notarized_height. get ( ) . saturating_sub ( cup_height. get ( ) ) ;
260
281
if cup_gap >= last_cup_dkg_info. interval_length . get ( ) + ACCEPTABLE_NOTARIZATION_CUP_GAP {
261
- return NotaryDelay :: ReachedMaxNotarizationCUPGap ;
282
+ return NotaryDelay :: ReachedMaxNotarizationCUPGap {
283
+ notarized_height,
284
+ cup_height,
285
+ } ;
262
286
}
263
287
264
288
NotaryDelay :: CanNotarizeAfter ( Duration :: from_millis ( certified_adjusted_delay) )
@@ -575,6 +599,7 @@ pub fn get_oldest_ecdsa_state_registry_version(
575
599
576
600
#[ cfg( test) ]
577
601
mod tests {
602
+ use assert_matches:: assert_matches;
578
603
use std:: str:: FromStr ;
579
604
580
605
use super :: * ;
@@ -676,14 +701,14 @@ mod tests {
676
701
. expect_latest_certified_height ( )
677
702
. return_const ( gap_trigger_height) ;
678
703
679
- assert_eq ! (
704
+ assert_matches ! (
680
705
get_adjusted_notary_delay_from_settings(
681
706
settings. clone( ) ,
682
707
& PoolReader :: new( & pool) ,
683
708
state_manager. as_ref( ) ,
684
709
Rank ( 0 ) ,
685
710
) ,
686
- NotaryDelay :: ReachedMaxNotarizationCertificationGap ,
711
+ NotaryDelay :: ReachedMaxNotarizationCertificationGap { .. }
687
712
) ;
688
713
689
714
state_manager. get_mut ( ) . checkpoint ( ) ;
@@ -710,14 +735,14 @@ mod tests {
710
735
711
736
pool. advance_round_normal_operation_no_cup ( ) ;
712
737
713
- assert_eq ! (
738
+ assert_matches ! (
714
739
get_adjusted_notary_delay_from_settings(
715
740
settings,
716
741
& PoolReader :: new( & pool) ,
717
742
state_manager. as_ref( ) ,
718
743
Rank ( 0 ) ,
719
744
) ,
720
- NotaryDelay :: ReachedMaxNotarizationCUPGap ,
745
+ NotaryDelay :: ReachedMaxNotarizationCUPGap { .. }
721
746
) ;
722
747
} ) ;
723
748
}
0 commit comments