From 4c834f267546181a66bb9ce53827192bb26c397f Mon Sep 17 00:00:00 2001 From: leepl37 Date: Sat, 24 Jan 2026 16:54:04 +0900 Subject: [PATCH 1/4] fix(signer): handle missing/behind KES period on registration --- mithril-signer/src/runtime/runner.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index 235522e16bf..313ff0e35e4 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -198,10 +198,28 @@ impl Runner for SignerRunner { } _ => (None, None), }; - let current_kes_period = self.services.chain_observer.get_current_kes_period().await?; - let kes_evolutions = operational_certificate.map(|operational_certificate| { - current_kes_period.unwrap_or_default() - operational_certificate.get_start_kes_period() - }); + let current_kes_period = self + .services + .chain_observer + .get_current_kes_period() + .await? + .ok_or_else(|| RunnerError::NoValueError("current_kes_period".to_string()))?; + let kes_evolutions = operational_certificate + .map(|operational_certificate| { + let start_kes_period = operational_certificate.get_start_kes_period(); + if current_kes_period < start_kes_period { + warn!( + self.logger, + "Current KES period is behind operational certificate start period."; + "current_kes_period" => u64::from(current_kes_period), + "start_kes_period" => u64::from(start_kes_period) + ); + Err(RunnerError::NoValueError("kes_period_underflow".to_string())) + } else { + Ok(current_kes_period - start_kes_period) + } + }) + .transpose()?; let protocol_initializer = self .services @@ -217,7 +235,7 @@ impl Runner for SignerRunner { stake, &protocol_parameters, self.services.kes_signer.clone(), - current_kes_period, + Some(current_kes_period), )?; let signer = Signer::new( From c4280ccece8505000d7e1f0eb89af0344c37790e Mon Sep 17 00:00:00 2001 From: leepl37 Date: Mon, 26 Jan 2026 19:37:35 +0900 Subject: [PATCH 2/4] style: fix rustfmt errors --- mithril-signer/src/runtime/runner.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index 313ff0e35e4..41a38dab253 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -214,7 +214,9 @@ impl Runner for SignerRunner { "current_kes_period" => u64::from(current_kes_period), "start_kes_period" => u64::from(start_kes_period) ); - Err(RunnerError::NoValueError("kes_period_underflow".to_string())) + Err(RunnerError::NoValueError( + "kes_period_underflow".to_string(), + )) } else { Ok(current_kes_period - start_kes_period) } From 4cb1338444b2da1f5aa4d38eaa4977cccf70eb22 Mon Sep 17 00:00:00 2001 From: leepl37 Date: Tue, 27 Jan 2026 16:52:12 +0900 Subject: [PATCH 3/4] fix(signer): retry on KES period mismatch --- mithril-signer/src/runtime/runner.rs | 88 +++++++++++++++++++++------- 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index 41a38dab253..d4483987ed0 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -198,30 +198,78 @@ impl Runner for SignerRunner { } _ => (None, None), }; - let current_kes_period = self - .services - .chain_observer - .get_current_kes_period() - .await? - .ok_or_else(|| RunnerError::NoValueError("current_kes_period".to_string()))?; - let kes_evolutions = operational_certificate - .map(|operational_certificate| { - let start_kes_period = operational_certificate.get_start_kes_period(); - if current_kes_period < start_kes_period { + let mut attempt = 0; + let max_retries = 5; + let retry_delay = std::time::Duration::from_secs(1); + + let (current_kes_period, kes_evolutions) = loop { + attempt += 1; + + let kes_period = self + .services + .chain_observer + .get_current_kes_period() + .await?; + + let kes_period = match kes_period { + Some(kes_period) => kes_period, + None => { + if attempt >= max_retries { + return Err(RunnerError::NoValueError( + "current_kes_period".to_string(), + ) + .into()); + } warn!( self.logger, - "Current KES period is behind operational certificate start period."; - "current_kes_period" => u64::from(current_kes_period), - "start_kes_period" => u64::from(start_kes_period) + "Current KES period is not available yet. Retrying..."; + "attempt" => attempt, + "max_retries" => max_retries ); - Err(RunnerError::NoValueError( - "kes_period_underflow".to_string(), - )) - } else { - Ok(current_kes_period - start_kes_period) + tokio::time::sleep(retry_delay).await; + continue; } - }) - .transpose()?; + }; + + let check_result = match &operational_certificate { + Some(op_cert) => { + let start_kes_period = op_cert.get_start_kes_period(); + if kes_period < start_kes_period { + Err(start_kes_period) + } else { + Ok(Some(kes_period - start_kes_period)) + } + } + None => Ok(None), + }; + + match check_result { + Ok(evolutions) => break (kes_period, evolutions), + Err(start_kes_period) => { + if attempt >= max_retries { + warn!( + self.logger, + "Current KES period is behind operational certificate start period."; + "current_kes_period" => u64::from(kes_period), + "start_kes_period" => u64::from(start_kes_period) + ); + return Err(RunnerError::NoValueError( + "kes_period_underflow".to_string(), + ) + .into()); + } + warn!( + self.logger, + "KES period mismatch. Retrying..."; + "current_kes_period" => u64::from(kes_period), + "start_kes_period" => u64::from(start_kes_period), + "attempt" => attempt, + "max_retries" => max_retries + ); + tokio::time::sleep(retry_delay).await; + } + } + }; let protocol_initializer = self .services From 42e6ca8ebdd587b93cb27a977a672b5e8e14af29 Mon Sep 17 00:00:00 2001 From: leepl37 Date: Tue, 27 Jan 2026 19:25:54 +0900 Subject: [PATCH 4/4] chore: format runner after KES retry change --- mithril-signer/src/runtime/runner.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index d4483987ed0..6e2d1210aca 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -205,20 +205,15 @@ impl Runner for SignerRunner { let (current_kes_period, kes_evolutions) = loop { attempt += 1; - let kes_period = self - .services - .chain_observer - .get_current_kes_period() - .await?; + let kes_period = self.services.chain_observer.get_current_kes_period().await?; let kes_period = match kes_period { Some(kes_period) => kes_period, None => { if attempt >= max_retries { - return Err(RunnerError::NoValueError( - "current_kes_period".to_string(), - ) - .into()); + return Err( + RunnerError::NoValueError("current_kes_period".to_string()).into() + ); } warn!( self.logger, @@ -253,10 +248,9 @@ impl Runner for SignerRunner { "current_kes_period" => u64::from(kes_period), "start_kes_period" => u64::from(start_kes_period) ); - return Err(RunnerError::NoValueError( - "kes_period_underflow".to_string(), - ) - .into()); + return Err( + RunnerError::NoValueError("kes_period_underflow".to_string()).into(), + ); } warn!( self.logger,