@@ -348,6 +348,17 @@ struct GroupAssignments {
348348 current : Vec < ParaId > ,
349349}
350350
351+ /// Represents the result from a hold off operation.
352+ enum HoldOffOperationOutcome {
353+ /// The advertisement was held off and this is the first hold off for the relay parent.
354+ FirstHoldOff ,
355+ /// The advertisement was held off and this is a subsequent hold off for this relay parent.
356+ SubsequentHoldOff ,
357+ /// The advertisement was not held off. The hold off period for this relay parent has already
358+ /// expired.
359+ NoHoldOff ,
360+ }
361+
351362/// Represents the hold off state of a relay parent.
352363enum RelayParentHoldOffState {
353364 /// No Advertisements from non-invulnerable collators were received so far. Nothing was held
@@ -390,17 +401,20 @@ impl RelayParentHoldOffState {
390401 /// Holds off the advertisement, if nothing was held off for this relay parent or there are
391402 /// other advertisements being held off. Return false if the hold off was complete for the
392403 /// relay parent.
393- fn hold_off_if_necessary ( & mut self , advertisement : HeldOffAdvertisement ) -> bool {
404+ fn hold_off_if_necessary (
405+ & mut self ,
406+ advertisement : HeldOffAdvertisement ,
407+ ) -> HoldOffOperationOutcome {
394408 match self {
395409 Self :: NotStarted => {
396410 * self = Self :: HoldingOff ( vec ! [ advertisement] . into ( ) ) ;
397- true
411+ HoldOffOperationOutcome :: FirstHoldOff
398412 } ,
399413 Self :: HoldingOff ( advertisements) => {
400414 advertisements. push_back ( advertisement) ;
401- true
415+ HoldOffOperationOutcome :: SubsequentHoldOff
402416 } ,
403- Self :: Done => false ,
417+ Self :: Done => HoldOffOperationOutcome :: NoHoldOff ,
404418 }
405419 }
406420}
@@ -1069,36 +1083,51 @@ fn hold_off_asset_hub_collation_if_needed(
10691083 return false
10701084 } ;
10711085
1072- if rp_state. ah_held_off_advertisements . hold_off_if_necessary ( HeldOffAdvertisement {
1073- relay_parent,
1074- peer_id,
1075- collator_id,
1076- prospective_candidate,
1077- } ) {
1078- state. ah_held_off_rp_timers . push ( Box :: pin ( async move {
1079- Delay :: new ( hold_off_duration) . await ;
1080- relay_parent
1081- } ) ) ;
1086+ let hold_off_outcome =
1087+ rp_state. ah_held_off_advertisements . hold_off_if_necessary ( HeldOffAdvertisement {
1088+ relay_parent,
1089+ peer_id,
1090+ collator_id,
1091+ prospective_candidate,
1092+ } ) ;
10821093
1083- gum:: debug!(
1084- target: LOG_TARGET ,
1085- ?peer_id,
1086- ?relay_parent,
1087- ?prospective_candidate,
1088- "AssetHub collation held off, not from invulnerable collator" ,
1089- ) ;
1094+ match hold_off_outcome {
1095+ HoldOffOperationOutcome :: FirstHoldOff => {
1096+ state. ah_held_off_rp_timers . push ( Box :: pin ( async move {
1097+ Delay :: new ( hold_off_duration) . await ;
1098+ relay_parent
1099+ } ) ) ;
10901100
1091- return true ;
1092- } else {
1093- gum:: debug!(
1094- target: LOG_TARGET ,
1095- ?peer_id,
1096- ?relay_parent,
1097- ?prospective_candidate,
1098- "AssetHub collation from non-invulnerable collator not held off - already done for this relay parent" ,
1099- ) ;
1101+ gum:: debug!(
1102+ target: LOG_TARGET ,
1103+ ?peer_id,
1104+ ?relay_parent,
1105+ ?prospective_candidate,
1106+ "AssetHub collation held off, not from invulnerable collator. First hold off." ,
1107+ ) ;
11001108
1101- return false
1109+ true
1110+ } ,
1111+ HoldOffOperationOutcome :: SubsequentHoldOff => {
1112+ gum:: debug!(
1113+ target: LOG_TARGET ,
1114+ ?peer_id,
1115+ ?relay_parent,
1116+ ?prospective_candidate,
1117+ "AssetHub collation held off, not from invulnerable collator. Subsequent hold off." ,
1118+ ) ;
1119+ true
1120+ } ,
1121+ HoldOffOperationOutcome :: NoHoldOff => {
1122+ gum:: debug!(
1123+ target: LOG_TARGET ,
1124+ ?peer_id,
1125+ ?relay_parent,
1126+ ?prospective_candidate,
1127+ "AssetHub collation from non-invulnerable collator not held off - already done for this relay parent" ,
1128+ ) ;
1129+ false
1130+ } ,
11021131 }
11031132}
11041133
0 commit comments