@@ -196,50 +196,69 @@ impl StateMachine {
196196 info ! ( " ⋅ Epoch has NOT changed, waiting…" ) ;
197197 }
198198 }
199+
199200 SignerState :: ReadyToSign {
200201 time_point,
201202 last_signed_entity_type,
202203 } => {
204+ fn is_same_signed_entity_type (
205+ last_signed_entity_type : & Option < SignedEntityType > ,
206+ pending_certificate : & CertificatePending ,
207+ ) -> bool {
208+ Some ( & pending_certificate. signed_entity_type )
209+ == last_signed_entity_type. as_ref ( )
210+ }
211+
203212 if let Some ( new_epoch) = self . has_epoch_changed ( time_point. epoch ) . await ? {
204213 info ! ( "→ Epoch has changed, transiting to UNREGISTERED" ) ;
205214 * state = self
206215 . transition_from_ready_to_sign_to_unregistered ( new_epoch)
207216 . await ?;
208- } else if let Some ( pending_certificate ) =
209- self . runner . get_pending_certificate ( ) . await . map_err ( |e| {
217+ } else {
218+ match self . runner . get_pending_certificate ( ) . await . map_err ( |e| {
210219 RuntimeError :: KeepState {
211220 message : "could not fetch the pending certificate" . to_string ( ) ,
212221 nested_error : Some ( e) ,
213222 }
214- } ) ?
215- {
216- let is_same_signed_entity_type = last_signed_entity_type
217- . as_ref ( )
218- . map_or ( false , |s| s == & pending_certificate. signed_entity_type ) ;
219-
220- if !is_same_signed_entity_type {
221- info ! (
222- " ⋅ Epoch has NOT changed but there is a pending certificate" ;
223- " pending_certificate" => ?pending_certificate
224- ) ;
225-
226- if self
227- . runner
228- . can_sign_signed_entity_type ( & pending_certificate . signed_entity_type )
229- . await
223+ } ) ? {
224+ Some ( pending_certificate )
225+ if is_same_signed_entity_type (
226+ last_signed_entity_type ,
227+ & pending_certificate,
228+ ) =>
229+ {
230+ info ! ( " ⋅ same entity type, cannot sign pending certificate, waiting…" ) ;
231+ }
232+ Some ( pending_certificate)
233+ if self
234+ . runner
235+ . can_sign_signed_entity_type (
236+ & pending_certificate . signed_entity_type ,
237+ )
238+ . await =>
230239 {
240+ info ! (
241+ " ⋅ Epoch has NOT changed but there is a pending certificate" ;
242+ "pending_certificate" => ?pending_certificate
243+ ) ;
231244 info ! ( " → we can sign this certificate, transiting to READY_TO_SIGN" ) ;
232245 * state = self
233246 . transition_from_ready_to_sign_to_ready_to_sign (
234247 & pending_certificate,
235248 )
236249 . await ?;
237- } else {
250+ }
251+ Some ( pending_certificate) => {
252+ info ! (
253+ " ⋅ Epoch has NOT changed but there is a pending certificate" ;
254+ "pending_certificate" => ?pending_certificate
255+ ) ;
238256 info ! ( " ⋅ cannot sign this pending certificate, waiting…" ) ;
239257 }
258+ None => {
259+ info ! ( " ⋅ no pending certificate, waiting…" ) ;
260+ }
240261 }
241- } else {
242- info ! ( " ⋅ no pending certificate, waiting…" ) ;
243262 }
244263 }
245264 } ;
0 commit comments