Skip to content

Commit 426107f

Browse files
committed
feat(aggregator): add more context when register signer fail
1 parent f0c2c32 commit 426107f

File tree

5 files changed

+62
-25
lines changed

5 files changed

+62
-25
lines changed

mithril-aggregator/src/http_server/routes/signer_routes.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ mod handlers {
114114
.get_signer_registration_total_received_since_startup()
115115
.increment(&[origin_tag.as_deref().unwrap_or_default()]);
116116

117+
let payload = register_signer_message.clone();
117118
let registration_epoch = register_signer_message.epoch;
118119

119120
let signer = match FromRegisterSignerAdapter::try_adapt(register_signer_message) {
120121
Ok(signer) => signer,
121122
Err(err) => {
122-
warn!(logger,"register_signer::payload decoding error"; "error" => ?err);
123+
warn!(logger,"register_signer::payload decoding error"; "full_payload" => #?payload, "error" => ?err);
123124
return Ok(reply::bad_request(
124125
"Could not decode signer payload".to_string(),
125126
err.to_string(),
@@ -141,32 +142,42 @@ mod handlers {
141142
Ok(reply::empty(StatusCode::CREATED))
142143
}
143144
Err(SignerRegistrationError::ExistingSigner(signer_with_stake)) => {
144-
debug!(logger, "register_signer::already_registered");
145+
debug!(
146+
logger, "register_signer::already_registered";
147+
"registration_epoch" => ?registration_epoch, "party_id" => &signer.party_id,
148+
);
145149

146150
event_transmitter.send(EventMessage::signer_registration(
147151
"HTTP::signer_register",
148152
&signer_with_stake,
149153
signer_node_version,
150-
epoch_str.as_str(),
154+
&epoch_str,
151155
));
152156

153157
Ok(reply::empty(StatusCode::CREATED))
154158
}
155-
Err(SignerRegistrationError::FailedSignerRegistration(err)) => {
156-
warn!(logger,"register_signer::failed_signer_registration"; "error" => ?err);
159+
Err(SignerRegistrationError::InvalidSignerRegistration(
160+
_party_id,
161+
_registration_epoch,
162+
err,
163+
)) => {
164+
warn!(logger,"register_signer::failed_signer_registration"; "full_payload" => #?payload, "error" => ?err);
157165
Ok(reply::bad_request(
158166
"failed_signer_registration".to_string(),
159167
err.to_string(),
160168
))
161169
}
162170
Err(SignerRegistrationError::RegistrationRoundNotYetOpened) => {
163-
warn!(logger, "register_signer::registration_round_not_yed_opened");
171+
warn!(
172+
logger, "register_signer::registration_round_not_yed_opened";
173+
"registration_epoch" => ?registration_epoch, "party_id" => &signer.party_id,
174+
);
164175
Ok(reply::server_error(
165176
SignerRegistrationError::RegistrationRoundNotYetOpened,
166177
))
167178
}
168179
Err(err) => {
169-
warn!(logger,"register_signer::error"; "error" => ?err);
180+
warn!(logger,"register_signer::error"; "full_payload" => #?payload, "error" => ?err);
170181
Ok(reply::server_error(err))
171182
}
172183
}
@@ -395,9 +406,11 @@ mod tests {
395406
async fn test_register_signer_post_ko_400() {
396407
let mut mock_signer_registerer = MockSignerRegisterer::new();
397408
mock_signer_registerer.expect_register_signer().return_once(|_, _| {
398-
Err(SignerRegistrationError::FailedSignerRegistration(anyhow!(
399-
ProtocolRegistrationError::OpCertInvalid
400-
)))
409+
Err(SignerRegistrationError::InvalidSignerRegistration(
410+
"party_2".to_string(),
411+
Epoch(4),
412+
anyhow!(ProtocolRegistrationError::OpCertInvalid),
413+
))
401414
});
402415
let mut dependency_manager = initialize_dependencies!().await;
403416
dependency_manager.signer_registerer = Arc::new(mock_signer_registerer);
@@ -433,7 +446,9 @@ mod tests {
433446
let mut mock_signer_registerer = MockSignerRegisterer::new();
434447
mock_signer_registerer.expect_register_signer().return_once(|_, _| {
435448
Err(SignerRegistrationError::FailedSignerRecorder(
436-
"an error occurred".to_string(),
449+
"party_1".to_string(),
450+
Epoch(4),
451+
anyhow!("an error occurred"),
437452
))
438453
});
439454
let mut dependency_manager = initialize_dependencies!().await;

mithril-aggregator/src/services/signer_registration/error.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use thiserror::Error;
22

3-
use mithril_common::{
4-
StdError,
5-
entities::{Epoch, SignerWithStake},
6-
};
3+
use mithril_common::StdError;
4+
use mithril_common::entities::{Epoch, PartyId, SignerWithStake};
75

86
use mithril_cardano_node_chain::chain_observer::ChainObserverError;
97

@@ -42,12 +40,12 @@ pub enum SignerRegistrationError {
4240
EpochService(#[source] StdError),
4341

4442
/// Signer registration failed.
45-
#[error("signer registration failed")]
46-
FailedSignerRegistration(#[source] StdError),
43+
#[error("Signer registration is invalid for party '{0}' and epoch {1}")]
44+
InvalidSignerRegistration(PartyId, Epoch, #[source] StdError),
4745

4846
/// Signer recorder failed.
49-
#[error("signer recorder failed: '{0}'")]
50-
FailedSignerRecorder(String),
47+
#[error("Recording signer registration failed for party '{0}' and epoch {1}")]
48+
FailedSignerRecorder(PartyId, Epoch, #[source] StdError),
5149

5250
/// Signer registration is always closed on a follower aggregator.
5351
#[error("signer registration is always closed on a follower aggregator")]

mithril-aggregator/src/services/signer_registration/follower.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,24 @@ impl MithrilSignerRegistrationFollower {
7070
.signer_registration_verifier
7171
.verify(signer, stake_distribution)
7272
.await
73-
.map_err(SignerRegistrationError::FailedSignerRegistration)?;
73+
.map_err(|err| {
74+
SignerRegistrationError::InvalidSignerRegistration(
75+
signer.party_id.clone(),
76+
epoch,
77+
err,
78+
)
79+
})?;
7480

7581
self.signer_recorder
7682
.record_signer_registration(signer_with_stake.party_id.clone())
7783
.await
78-
.map_err(|e| SignerRegistrationError::FailedSignerRecorder(e.to_string()))?;
84+
.map_err(|err| {
85+
SignerRegistrationError::FailedSignerRecorder(
86+
signer_with_stake.party_id.clone(),
87+
epoch,
88+
err,
89+
)
90+
})?;
7991

8092
self
8193
.verification_key_store

mithril-aggregator/src/services/signer_registration/leader.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,24 @@ impl SignerRegisterer for MithrilSignerRegistrationLeader {
9898
.signer_registration_verifier
9999
.verify(signer, &registration_round.stake_distribution)
100100
.await
101-
.map_err(SignerRegistrationError::FailedSignerRegistration)?;
101+
.map_err(|err| {
102+
SignerRegistrationError::InvalidSignerRegistration(
103+
signer.party_id.clone(),
104+
epoch,
105+
err,
106+
)
107+
})?;
102108

103109
self.signer_recorder
104110
.record_signer_registration(signer_save.party_id.clone())
105111
.await
106-
.map_err(|e| SignerRegistrationError::FailedSignerRecorder(e.to_string()))?;
112+
.map_err(|err| {
113+
SignerRegistrationError::FailedSignerRecorder(
114+
signer_save.party_id.clone(),
115+
registration_round.epoch,
116+
err,
117+
)
118+
})?;
107119

108120
match self
109121
.verification_key_store

mithril-aggregator/src/services/signer_registration/verifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ impl SignerRegistrationVerifier for MithrilSignerRegistrationVerifier {
6262
)
6363
.with_context(|| {
6464
format!(
65-
"KeyRegwrapper can not register signer with party_id: '{party_id_register:?}'"
65+
"KeyRegwrapper can not register signer with party_id: '{party_id_register:?}', kes_period: '{kes_period:?}'"
6666
)
6767
})?;
6868
let party_id_registered_stake = *stake_distribution
6969
.get(&party_id_registered)
70-
.with_context(|| "Stake not found")?;
70+
.with_context(|| format!("Stake not found for party_id: '{party_id_registered}"))?;
7171

7272
Ok(SignerWithStake {
7373
party_id: party_id_registered,

0 commit comments

Comments
 (0)