@@ -37,7 +37,7 @@ use polkadot_node_subsystem_util::{
3737 JobTrait , FromJobCommand , Validator , metrics:: { self , prometheus} ,
3838} ;
3939use polkadot_primitives:: v1:: {
40- CandidateReceipt , CollatorId , CoreState , CoreIndex , Hash , Id as ParaId , PoV ,
40+ CandidateReceipt , CollatorId , CoreState , CoreIndex , Hash , Id as ParaId , PoV , BlockNumber ,
4141} ;
4242use polkadot_node_primitives:: SignedFullStatement ;
4343use std:: { pin:: Pin , sync:: Arc } ;
@@ -139,30 +139,47 @@ impl JobTrait for CandidateSelectionJob {
139139 . with_stage ( jaeger:: Stage :: CandidateSelection )
140140 . build ( ) ;
141141
142- let mut assignment = None ;
142+ #[ derive( Debug ) ]
143+ enum AssignmentState {
144+ Unassigned ,
145+ Scheduled ( ParaId ) ,
146+ Occupied ( BlockNumber ) ,
147+ Free ,
148+ }
149+
150+ let mut assignment = AssignmentState :: Unassigned ;
143151
144152 for ( idx, core) in cores. into_iter ( ) . enumerate ( ) {
145- // Ignore prospective assignments on occupied cores for the time being.
146- if let CoreState :: Scheduled ( scheduled) = core {
147- let core_index = CoreIndex ( idx as _ ) ;
148- let group_index = group_rotation_info. group_for_core ( core_index, n_cores) ;
149- if let Some ( g) = validator_groups. get ( group_index. 0 as usize ) {
150- if g. contains ( & validator. index ( ) ) {
151- assignment = Some ( scheduled. para_id ) ;
152- break ;
153+ let core_index = CoreIndex ( idx as _ ) ;
154+ let group_index = group_rotation_info. group_for_core ( core_index, n_cores) ;
155+ if let Some ( g) = validator_groups. get ( group_index. 0 as usize ) {
156+ if g. contains ( & validator. index ( ) ) {
157+ match core {
158+ CoreState :: Scheduled ( scheduled) => {
159+ assignment = AssignmentState :: Scheduled ( scheduled. para_id ) ;
160+ }
161+ CoreState :: Occupied ( occupied) => {
162+ // Ignore prospective assignments on occupied cores
163+ // for the time being.
164+ assignment = AssignmentState :: Occupied ( occupied. occupied_since ) ;
165+ }
166+ CoreState :: Free => {
167+ assignment = AssignmentState :: Free ;
168+ }
153169 }
170+ break ;
154171 }
155172 }
156173 }
157174
158175 let assignment = match assignment {
159- Some ( assignment) => {
176+ AssignmentState :: Scheduled ( assignment) => {
160177 assignment_span. add_string_tag ( "assigned" , "true" ) ;
161178 assignment_span. add_para_id ( assignment) ;
162179
163180 assignment
164181 }
165- None => {
182+ assignment => {
166183 assignment_span. add_string_tag ( "assigned" , "false" ) ;
167184
168185 let validator_index = validator. index ( ) ;
@@ -173,6 +190,7 @@ impl JobTrait for CandidateSelectionJob {
173190 ?relay_parent,
174191 ?validator_index,
175192 ?validator_id,
193+ ?assignment,
176194 "No assignment. Will not select candidate."
177195 ) ;
178196
0 commit comments