Skip to content

Commit 64daa84

Browse files
authored
Merge pull request #1939 from input-output-hk/ensemble/1923/retrieve-custom-signing-config-with-epoch-settings
Retrieve custom signing configuration with epoch settings in Signer
2 parents 27fdfa0 + 6e9fb44 commit 64daa84

File tree

14 files changed

+342
-66
lines changed

14 files changed

+342
-66
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ As a minor extension, we have adopted a slightly different versioning convention
1111

1212
- Optimizations of the state machine used by the signer to create individual signatures.
1313

14-
- Support for buffering of incoming single signatures by the aggregator if it can not aggregate them yet
14+
- Support for buffering of incoming single signatures by the aggregator if it can not aggregate them yet.
15+
16+
- Expose the Cardano transactions signing configuration for the current and upcoming epoch via the `/epoch-settings` route.
1517

1618
- Crates versions:
1719

Cargo.lock

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

mithril-aggregator/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-aggregator"
3-
version = "0.5.64"
3+
version = "0.5.65"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

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

Lines changed: 125 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
use crate::http_server::routes::middlewares;
2-
use crate::DependencyContainer;
31
use std::sync::Arc;
42
use warp::Filter;
53

4+
use mithril_common::{
5+
entities::{SignedEntityConfig, SignedEntityTypeDiscriminants},
6+
messages::{EpochSettingsMessage, SignerMessagePart},
7+
StdResult,
8+
};
9+
10+
use crate::dependency_injection::EpochServiceWrapper;
11+
use crate::http_server::routes::middlewares;
12+
use crate::DependencyContainer;
13+
614
pub fn routes(
715
dependency_manager: Arc<DependencyContainer>,
816
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
@@ -15,70 +23,86 @@ fn epoch_settings(
1523
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
1624
warp::path!("epoch-settings")
1725
.and(warp::get())
18-
.and(middlewares::with_epoch_service(dependency_manager))
26+
.and(middlewares::with_epoch_service(dependency_manager.clone()))
27+
.and(middlewares::with_signed_entity_config(dependency_manager))
1928
.and_then(handlers::epoch_settings)
2029
}
2130

31+
async fn get_epoch_settings_message(
32+
epoch_service: EpochServiceWrapper,
33+
signed_entity_config: SignedEntityConfig,
34+
) -> StdResult<EpochSettingsMessage> {
35+
let epoch_service = epoch_service.read().await;
36+
37+
let epoch = epoch_service.epoch_of_current_data()?;
38+
let protocol_parameters = epoch_service.next_protocol_parameters()?.clone();
39+
let next_protocol_parameters = epoch_service.upcoming_protocol_parameters()?.clone();
40+
let current_signers = epoch_service.current_signers()?;
41+
let next_signers = epoch_service.next_signers()?;
42+
43+
let cardano_transactions_signing_config = signed_entity_config
44+
.list_allowed_signed_entity_types_discriminants()
45+
.contains(&SignedEntityTypeDiscriminants::CardanoTransactions)
46+
.then_some(signed_entity_config.cardano_transactions_signing_config);
47+
let next_cardano_transactions_signing_config = cardano_transactions_signing_config.clone();
48+
49+
let epoch_settings_message = EpochSettingsMessage {
50+
epoch,
51+
protocol_parameters,
52+
next_protocol_parameters,
53+
current_signers: SignerMessagePart::from_signers(current_signers.to_vec()),
54+
next_signers: SignerMessagePart::from_signers(next_signers.to_vec()),
55+
cardano_transactions_signing_config,
56+
next_cardano_transactions_signing_config,
57+
};
58+
59+
Ok(epoch_settings_message)
60+
}
61+
2262
mod handlers {
23-
use crate::dependency_injection::EpochServiceWrapper;
24-
use crate::http_server::routes::reply;
25-
use mithril_common::messages::{EpochSettingsMessage, SignerMessagePart};
26-
use slog_scope::{debug, warn};
63+
use slog_scope::debug;
2764
use std::convert::Infallible;
2865
use warp::http::StatusCode;
2966

67+
use mithril_common::entities::SignedEntityConfig;
68+
69+
use crate::dependency_injection::EpochServiceWrapper;
70+
use crate::http_server::routes::epoch_routes::get_epoch_settings_message;
71+
use crate::http_server::routes::reply;
72+
3073
/// Epoch Settings
3174
pub async fn epoch_settings(
3275
epoch_service: EpochServiceWrapper,
76+
signed_entity_config: SignedEntityConfig,
3377
) -> Result<impl warp::Reply, Infallible> {
3478
debug!("⇄ HTTP SERVER: epoch_settings");
35-
let epoch_service = epoch_service.read().await;
36-
37-
match (
38-
epoch_service.epoch_of_current_data(),
39-
epoch_service.next_protocol_parameters(),
40-
epoch_service.upcoming_protocol_parameters(),
41-
epoch_service.current_signers(),
42-
epoch_service.next_signers(),
43-
) {
44-
(
45-
Ok(epoch),
46-
Ok(protocol_parameters),
47-
Ok(next_protocol_parameters),
48-
Ok(current_signers),
49-
Ok(next_signers),
50-
) => {
51-
let epoch_settings_message = EpochSettingsMessage {
52-
epoch,
53-
protocol_parameters: protocol_parameters.clone(),
54-
next_protocol_parameters: next_protocol_parameters.clone(),
55-
current_signers: SignerMessagePart::from_signers(current_signers.to_vec()),
56-
next_signers: SignerMessagePart::from_signers(next_signers.to_vec()),
57-
};
58-
Ok(reply::json(&epoch_settings_message, StatusCode::OK))
59-
}
60-
(Err(err), _, _, _, _)
61-
| (_, Err(err), _, _, _)
62-
| (_, _, Err(err), _, _)
63-
| (_, _, _, Err(err), _)
64-
| (_, _, _, _, Err(err)) => {
65-
warn!("epoch_settings::error"; "error" => ?err);
66-
Ok(reply::server_error(err))
67-
}
79+
let epoch_settings_message =
80+
get_epoch_settings_message(epoch_service, signed_entity_config).await;
81+
82+
match epoch_settings_message {
83+
Ok(message) => Ok(reply::json(&message, StatusCode::OK)),
84+
Err(err) => Ok(reply::server_error(err)),
6885
}
6986
}
7087
}
7188

7289
#[cfg(test)]
7390
mod tests {
91+
use serde_json::Value::Null;
92+
use std::collections::BTreeSet;
93+
use tokio::sync::RwLock;
94+
use warp::{
95+
http::{Method, StatusCode},
96+
test::request,
97+
};
98+
7499
use mithril_common::{
75-
entities::Epoch,
100+
entities::{
101+
BlockNumber, CardanoTransactionsSigningConfig, Epoch, SignedEntityConfig,
102+
SignedEntityTypeDiscriminants,
103+
},
76104
test_utils::{apispec::APISpec, MithrilFixtureBuilder},
77105
};
78-
use serde_json::Value::Null;
79-
use tokio::sync::RwLock;
80-
use warp::http::{Method, StatusCode};
81-
use warp::test::request;
82106

83107
use crate::http_server::SERVER_BASE_PATH;
84108
use crate::initialize_dependencies;
@@ -99,6 +123,62 @@ mod tests {
99123
.and(routes(dependency_manager).with(cors))
100124
}
101125

126+
#[tokio::test]
127+
async fn get_epoch_settings_message_with_cardano_transactions_enabled() {
128+
let fixture = MithrilFixtureBuilder::default().with_signers(3).build();
129+
let epoch_service = FakeEpochService::from_fixture(Epoch(4), &fixture);
130+
let epoch_service = Arc::new(RwLock::new(epoch_service));
131+
132+
let cardano_transactions_signing_config = CardanoTransactionsSigningConfig {
133+
security_parameter: BlockNumber(70),
134+
step: BlockNumber(15),
135+
};
136+
let signed_entity_config = SignedEntityConfig {
137+
cardano_transactions_signing_config: cardano_transactions_signing_config.clone(),
138+
allowed_discriminants: BTreeSet::from([
139+
SignedEntityTypeDiscriminants::CardanoTransactions,
140+
]),
141+
..SignedEntityConfig::dummy()
142+
};
143+
144+
let message = get_epoch_settings_message(epoch_service, signed_entity_config)
145+
.await
146+
.unwrap();
147+
148+
assert_eq!(
149+
message.cardano_transactions_signing_config,
150+
Some(cardano_transactions_signing_config.clone())
151+
);
152+
assert_eq!(
153+
message.next_cardano_transactions_signing_config,
154+
Some(cardano_transactions_signing_config)
155+
);
156+
}
157+
158+
#[tokio::test]
159+
async fn get_epoch_settings_message_with_cardano_transactions_not_enabled() {
160+
let fixture = MithrilFixtureBuilder::default().with_signers(3).build();
161+
let epoch_service = FakeEpochService::from_fixture(Epoch(4), &fixture);
162+
let epoch_service = Arc::new(RwLock::new(epoch_service));
163+
164+
let cardano_transactions_signing_config = CardanoTransactionsSigningConfig {
165+
security_parameter: BlockNumber(70),
166+
step: BlockNumber(15),
167+
};
168+
let signed_entity_config = SignedEntityConfig {
169+
cardano_transactions_signing_config,
170+
allowed_discriminants: BTreeSet::new(),
171+
..SignedEntityConfig::dummy()
172+
};
173+
174+
let message = get_epoch_settings_message(epoch_service, signed_entity_config)
175+
.await
176+
.unwrap();
177+
178+
assert_eq!(message.cardano_transactions_signing_config, None);
179+
assert_eq!(message.next_cardano_transactions_signing_config, None);
180+
}
181+
102182
#[tokio::test]
103183
async fn test_epoch_settings_get_ok() {
104184
let method = Method::GET.as_str();

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.4.52"
3+
version = "0.4.53"
44
description = "Common types, interfaces, and utilities for Mithril nodes."
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-common/src/entities/epoch_settings.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::entities::{Epoch, ProtocolParameters};
1+
use crate::entities::{CardanoTransactionsSigningConfig, Epoch, ProtocolParameters};
22

33
use super::Signer;
44

@@ -19,4 +19,10 @@ pub struct EpochSettings {
1919

2020
/// Signers that will be able to sign on the next epoch
2121
pub next_signers: Vec<Signer>,
22+
23+
/// Cardano transactions signing configuration for the current epoch
24+
pub cardano_transactions_signing_config: Option<CardanoTransactionsSigningConfig>,
25+
26+
/// Cardano transactions signing configuration for the next epoch
27+
pub next_cardano_transactions_signing_config: Option<CardanoTransactionsSigningConfig>,
2228
}

0 commit comments

Comments
 (0)