Skip to content

Commit cedfff0

Browse files
authored
Merge pull request #822 from input-output-hk/jpraynaud/820-enhance-error-key-registration
Enhance Key Registration errors
2 parents 2322b54 + fd59eea commit cedfff0

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-common"
3-
version = "0.2.29"
3+
version = "0.2.30"
44
authors = { workspace = true }
55
edition = { workspace = true }
66
documentation = { workspace = true }

mithril-common/src/crypto_helper/types.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::crypto_helper::cardano::{
2-
KeyRegWrapper, ProtocolRegistrationErrorWrapper, StmInitializerWrapper,
2+
KeyRegWrapper, ProtocolInitializerErrorWrapper, ProtocolRegistrationErrorWrapper,
3+
StmInitializerWrapper,
34
};
45

56
use mithril_stm::stm::{
@@ -70,8 +71,11 @@ pub type ProtocolGenesisSecretKey = ed25519_dalek::SecretKey;
7071
pub type ProtocolGenesisSignature = ed25519_dalek::Signature;
7172

7273
// Error alias
73-
/// Alias of a wrapper of [MithrilStm:RegisterError](enum@mithril_stm::RegisterError).
74+
/// Alias of a wrapper of [MithrilCommon:ProtocolRegistrationErrorWrapper](enum@mithril_common::ProtocolRegistrationErrorWrapper).
7475
pub type ProtocolRegistrationError = ProtocolRegistrationErrorWrapper;
7576

77+
/// Alias of a wrapper of [MithrilCommon:ProtocolInitializerErrorWrapper](enum@mithril_common::ProtocolInitializerErrorWrapper).
78+
pub type ProtocolInitializerError = ProtocolInitializerErrorWrapper;
79+
7680
/// Alias of [MithrilStm:AggregationError](enum@mithril_stm::AggregationError).
7781
pub type ProtocolAggregationError = AggregationError;

mithril-signer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-signer"
3-
version = "0.2.25"
3+
version = "0.2.26"
44
description = "A Mithril Signer"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-signer/src/runtime/state_machine.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use slog_scope::{crit, debug, error, info};
22
use std::{fmt::Display, thread::sleep, time::Duration};
33

4-
use mithril_common::entities::{Beacon, CertificatePending, Epoch, EpochSettings, SignerWithStake};
4+
use mithril_common::{
5+
crypto_helper::ProtocolInitializerError,
6+
entities::{Beacon, CertificatePending, Epoch, EpochSettings, SignerWithStake},
7+
};
58

69
use super::{Runner, RuntimeError};
710

@@ -304,15 +307,18 @@ impl StateMachine {
304307
.map_err(|e| RuntimeError::KeepState {
305308
message: format!("Could not update stake distribution in 'unregistered → registered' phase for epoch {:?}.", beacon.epoch),
306309
nested_error: Some(e) })?;
307-
self.runner
308-
.register_signer_to_aggregator(
309-
epoch_settings.epoch,
310-
&epoch_settings.next_protocol_parameters,
311-
)
312-
.await
313-
.map_err(|e| RuntimeError::KeepState {
314-
message: format!("Could not register to aggregator in 'unregistered → registered' phase for epoch {:?}.", beacon.epoch),
315-
nested_error: Some(e) })?;
310+
311+
self.runner. register_signer_to_aggregator(
312+
epoch_settings.epoch,
313+
&epoch_settings.next_protocol_parameters,
314+
)
315+
.await.map_err(|e| {
316+
if e.downcast_ref::<ProtocolInitializerError>().is_some(){
317+
RuntimeError::Critical { message: format!("Could not register to aggregator in 'unregistered → registered' phase for epoch {:?}.", beacon.epoch), nested_error: Some(e) }
318+
}else{
319+
RuntimeError::KeepState { message: format!("Could not register to aggregator in 'unregistered → registered' phase for epoch {:?}.", beacon.epoch), nested_error: Some(e) }
320+
}
321+
})?;
316322

317323
Ok(SignerState::Registered { beacon })
318324
}

mithril-signer/src/single_signer.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use thiserror::Error;
55

66
use mithril_common::crypto_helper::{
77
key_decode_hex, key_encode_hex, KESPeriod, ProtocolClerk, ProtocolInitializer,
8-
ProtocolKeyRegistration, ProtocolPartyId, ProtocolRegistrationError, ProtocolSigner,
9-
ProtocolStakeDistribution,
8+
ProtocolInitializerError, ProtocolKeyRegistration, ProtocolPartyId, ProtocolRegistrationError,
9+
ProtocolSigner, ProtocolStakeDistribution,
1010
};
1111
use mithril_common::entities::{
1212
PartyId, ProtocolMessage, ProtocolParameters, SignerWithStake, SingleSignatures, Stake,
@@ -15,14 +15,6 @@ use mithril_common::entities::{
1515
#[cfg(test)]
1616
use mockall::automock;
1717

18-
/// MithrilProtocolInitializerBuilder error structure.
19-
#[derive(Error, Debug)]
20-
pub enum MithrilProtocolInitializerBuilderError {
21-
/// Could not parse a Cardano crypto file
22-
#[error("the cardano cryptographic file could not be parsed.")]
23-
CardanoCryptoParse,
24-
}
25-
2618
/// This is responsible of creating new instances of ProtocolInitializer.
2719
#[derive(Default)]
2820
pub struct MithrilProtocolInitializerBuilder {}
@@ -40,16 +32,15 @@ impl MithrilProtocolInitializerBuilder {
4032
protocol_parameters: &ProtocolParameters,
4133
kes_secret_key_path: Option<PathBuf>,
4234
kes_period: Option<KESPeriod>,
43-
) -> Result<ProtocolInitializer, MithrilProtocolInitializerBuilderError> {
35+
) -> Result<ProtocolInitializer, ProtocolInitializerError> {
4436
let mut rng = rand_core::OsRng;
4537
let protocol_initializer = ProtocolInitializer::setup(
4638
protocol_parameters.to_owned().into(),
4739
kes_secret_key_path,
4840
kes_period,
4941
stake.to_owned(),
5042
&mut rng,
51-
)
52-
.map_err(|_| MithrilProtocolInitializerBuilderError::CardanoCryptoParse)?;
43+
)?;
5344

5445
Ok(protocol_initializer)
5546
}

0 commit comments

Comments
 (0)