Skip to content

Commit 29586c4

Browse files
authored
Merge pull request #1905 from input-output-hk/djo/1898/aggregator_root_route-cardano_transactions_signing_config
Add Cardano transactions signing configuration in Aggregator '/' route
2 parents 8c3a9b0 + 105c0ca commit 29586c4

File tree

7 files changed

+134
-35
lines changed

7 files changed

+134
-35
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
demo/protocol-demo/artifacts/
22
docs/website/.docusaurus/
3+
docs/website/build/
34
mithril-client-wasm/pkg/
45
mithril-explorer/font.css.hbs
56
mithril-explorer/out/

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-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.56"
3+
version = "0.5.57"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

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

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,32 @@ mod handlers {
5353
"root::error"
5454
);
5555

56-
let signed_entity_types =
57-
signed_entity_config.list_allowed_signed_entity_types_discriminants();
58-
59-
let cardano_transactions_prover_capabilities = signed_entity_types
56+
let mut capabilities = AggregatorCapabilities {
57+
signed_entity_types: signed_entity_config
58+
.list_allowed_signed_entity_types_discriminants(),
59+
cardano_transactions_prover: None,
60+
cardano_transactions_signing_config: None,
61+
};
62+
63+
if capabilities
64+
.signed_entity_types
6065
.contains(&SignedEntityTypeDiscriminants::CardanoTransactions)
61-
.then_some(CardanoTransactionsProverCapabilities {
62-
max_hashes_allowed_by_request: configuration
63-
.cardano_transactions_prover_max_hashes_allowed_by_request,
64-
});
66+
{
67+
capabilities.cardano_transactions_prover =
68+
Some(CardanoTransactionsProverCapabilities {
69+
max_hashes_allowed_by_request: configuration
70+
.cardano_transactions_prover_max_hashes_allowed_by_request,
71+
});
72+
73+
capabilities.cardano_transactions_signing_config =
74+
Some(configuration.cardano_transactions_signing_config.clone());
75+
}
6576

6677
Ok(json(
6778
&AggregatorFeaturesMessage {
6879
open_api_version: open_api_version.to_string(),
6980
documentation_url: env!("CARGO_PKG_HOMEPAGE").to_string(),
70-
capabilities: AggregatorCapabilities {
71-
signed_entity_types,
72-
cardano_transactions_prover: cardano_transactions_prover_capabilities,
73-
},
81+
capabilities,
7482
},
7583
StatusCode::OK,
7684
))
@@ -81,7 +89,9 @@ mod handlers {
8189
mod tests {
8290
use crate::http_server::SERVER_BASE_PATH;
8391
use crate::{initialize_dependencies, DependencyContainer};
84-
use mithril_common::entities::SignedEntityTypeDiscriminants;
92+
use mithril_common::entities::{
93+
BlockNumber, CardanoTransactionsSigningConfig, SignedEntityTypeDiscriminants,
94+
};
8595
use mithril_common::messages::{
8696
AggregatorCapabilities, AggregatorFeaturesMessage, CardanoTransactionsProverCapabilities,
8797
};
@@ -150,7 +160,8 @@ mod tests {
150160
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
151161
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
152162
]),
153-
cardano_transactions_prover: None
163+
cardano_transactions_prover: None,
164+
cardano_transactions_signing_config: None,
154165
},
155166
}
156167
);
@@ -168,7 +179,7 @@ mod tests {
168179
}
169180

170181
#[tokio::test]
171-
async fn test_root_route_ok_with_cardano_transactions_prover_capabilities() {
182+
async fn test_root_route_ok_with_cardano_transactions_enabled() {
172183
let method = Method::GET.as_str();
173184
let path = "/";
174185
let mut dependency_manager = initialize_dependencies().await;
@@ -179,6 +190,13 @@ mod tests {
179190
dependency_manager
180191
.config
181192
.cardano_transactions_prover_max_hashes_allowed_by_request = 99;
193+
let signing_config = CardanoTransactionsSigningConfig {
194+
security_parameter: BlockNumber(70),
195+
step: BlockNumber(15),
196+
};
197+
dependency_manager
198+
.config
199+
.cardano_transactions_signing_config = signing_config.clone();
182200

183201
let response = request()
184202
.method(method)
@@ -197,6 +215,12 @@ mod tests {
197215
max_hashes_allowed_by_request: 99
198216
})
199217
);
218+
assert_eq!(
219+
response_body
220+
.capabilities
221+
.cardano_transactions_signing_config,
222+
Some(signing_config)
223+
);
200224

201225
APISpec::verify_conformity(
202226
APISpec::get_all_spec_files(),

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

mithril-common/src/messages/aggregator_features.rs

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::BTreeSet;
22

33
use serde::{Deserialize, Serialize};
44

5-
use crate::entities::SignedEntityTypeDiscriminants;
5+
use crate::entities::{CardanoTransactionsSigningConfig, SignedEntityTypeDiscriminants};
66

77
/// Message advertised by an Aggregator to inform about its features
88
#[derive(Debug, Serialize, Deserialize, PartialEq)]
@@ -28,6 +28,7 @@ impl AggregatorFeaturesMessage {
2828
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
2929
]),
3030
cardano_transactions_prover: None,
31+
cardano_transactions_signing_config: None,
3132
},
3233
}
3334
}
@@ -42,6 +43,10 @@ pub struct AggregatorCapabilities {
4243
/// Cardano transactions prover capabilities
4344
#[serde(skip_serializing_if = "Option::is_none")]
4445
pub cardano_transactions_prover: Option<CardanoTransactionsProverCapabilities>,
46+
47+
/// Cardano transactions signing configuration
48+
#[serde(skip_serializing_if = "Option::is_none")]
49+
pub cardano_transactions_signing_config: Option<CardanoTransactionsSigningConfig>,
4550
}
4651

4752
/// Cardano transactions prover capabilities
@@ -53,9 +58,40 @@ pub struct CardanoTransactionsProverCapabilities {
5358

5459
#[cfg(test)]
5560
mod tests {
61+
use crate::entities::BlockNumber;
62+
5663
use super::*;
5764

58-
fn golden_message() -> AggregatorFeaturesMessage {
65+
#[derive(Debug, Serialize, Deserialize, PartialEq)]
66+
struct AggregatorFeaturesMessagePrevious {
67+
pub open_api_version: String,
68+
pub documentation_url: String,
69+
pub capabilities: AggregatorCapabilitiesPrevious,
70+
}
71+
72+
#[derive(Debug, Serialize, Deserialize, PartialEq)]
73+
struct AggregatorCapabilitiesPrevious {
74+
pub signed_entity_types: BTreeSet<SignedEntityTypeDiscriminants>,
75+
#[serde(skip_serializing_if = "Option::is_none")]
76+
pub cardano_transactions_prover: Option<CardanoTransactionsProverCapabilities>,
77+
}
78+
79+
fn golden_message_previous() -> AggregatorFeaturesMessagePrevious {
80+
AggregatorFeaturesMessagePrevious {
81+
open_api_version: "0.0.1".to_string(),
82+
documentation_url: "https://example.com".to_string(),
83+
capabilities: AggregatorCapabilitiesPrevious {
84+
signed_entity_types: BTreeSet::from([
85+
SignedEntityTypeDiscriminants::CardanoTransactions,
86+
]),
87+
cardano_transactions_prover: Some(CardanoTransactionsProverCapabilities {
88+
max_hashes_allowed_by_request: 100,
89+
}),
90+
},
91+
}
92+
}
93+
94+
fn golden_message_actual() -> AggregatorFeaturesMessage {
5995
AggregatorFeaturesMessage {
6096
open_api_version: "0.0.1".to_string(),
6197
documentation_url: "https://example.com".to_string(),
@@ -66,26 +102,43 @@ mod tests {
66102
cardano_transactions_prover: Some(CardanoTransactionsProverCapabilities {
67103
max_hashes_allowed_by_request: 100,
68104
}),
105+
cardano_transactions_signing_config: Some(CardanoTransactionsSigningConfig {
106+
security_parameter: BlockNumber(70),
107+
step: BlockNumber(20),
108+
}),
69109
},
70110
}
71111
}
72112

113+
const ACTUAL_JSON: &str = r#"{
114+
"open_api_version": "0.0.1",
115+
"documentation_url": "https://example.com",
116+
"capabilities": {
117+
"signed_entity_types": ["CardanoTransactions"],
118+
"cardano_transactions_prover": {
119+
"max_hashes_allowed_by_request": 100
120+
},
121+
"cardano_transactions_signing_config": {
122+
"security_parameter": 70,
123+
"step": 20
124+
}
125+
}
126+
}"#;
127+
73128
// Test the retro compatibility with possible future upgrades.
74129
#[test]
75-
fn test_v1() {
76-
let json = r#"{
77-
"open_api_version": "0.0.1",
78-
"documentation_url": "https://example.com",
79-
"capabilities": {
80-
"signed_entity_types": ["CardanoTransactions"],
81-
"cardano_transactions_prover": {
82-
"max_hashes_allowed_by_request": 100
83-
}
84-
}
85-
}"#;
130+
fn test_actual_json_deserialized_into_previous_message() {
131+
let json = ACTUAL_JSON;
132+
let message: AggregatorFeaturesMessagePrevious = serde_json::from_str(json).unwrap();
86133

134+
assert_eq!(golden_message_previous(), message);
135+
}
136+
137+
#[test]
138+
fn test_actual_json_deserialized_into_actual_message() {
139+
let json = ACTUAL_JSON;
87140
let message: AggregatorFeaturesMessage = serde_json::from_str(json).unwrap();
88141

89-
assert_eq!(golden_message(), message);
142+
assert_eq!(golden_message_actual(), message);
90143
}
91144
}

openapi.yaml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ info:
44
# `mithril-common/src/lib.rs` file. If you plan to update it
55
# here to reflect changes in the API, please also update the constant in the
66
# Rust file.
7-
version: 0.1.27
7+
version: 0.1.28
88
title: Mithril Aggregator Server
99
description: |
1010
The REST API provided by a Mithril Aggregator Node in a Mithril network.
@@ -663,6 +663,25 @@ components:
663663
description: Maximum number of hashes allowed for a single request
664664
type: integer
665665
format: int64
666+
cardano_transactions_signing_config:
667+
description: |
668+
Cardano transactions signing configuration
669+
670+
Mandatory if `signed_entity_types` contains `CardanoTransactions`.
671+
type: object
672+
additionalProperties: false
673+
required:
674+
- security_parameter
675+
- step
676+
properties:
677+
security_parameter:
678+
description: Number of blocks to discard from the tip of the chain when importing Cardano transactions
679+
type: integer
680+
format: int64
681+
step:
682+
description: Number of blocks between signature of Cardano transactions
683+
type: integer
684+
format: int64
666685
example:
667686
{
668687
"open_api_version": "0.1.17",
@@ -676,7 +695,9 @@ components:
676695
"CardanoTransactions"
677696
],
678697
"cardano_transactions_prover":
679-
{ "max_hashes_allowed_by_request": 100 }
698+
{ "max_hashes_allowed_by_request": 100 },
699+
"cardano_transactions_signing_config":
700+
{ "security_parameter": 100, "step": 10 }
680701
}
681702
}
682703

0 commit comments

Comments
 (0)