Skip to content

Commit 5f68ae3

Browse files
committed
Add network_security_parameter and enable_transaction_pruning` configs to signer
Also set a default value to them of `2160` (mainnet value) and `true` (enable pruning by default).
1 parent d6bc0a7 commit 5f68ae3

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

mithril-signer/src/configuration.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{path::PathBuf, sync::Arc};
77
use mithril_common::{
88
chain_observer::ChainObserver,
99
crypto_helper::tests_setup,
10-
entities::PartyId,
10+
entities::{BlockNumber, PartyId},
1111
era::{
1212
adapters::{EraReaderAdapterBuilder, EraReaderAdapterType},
1313
EraReaderAdapter,
@@ -27,14 +27,18 @@ pub struct Configuration {
2727
#[example = "`/tmp/cardano.sock`"]
2828
pub cardano_node_socket_path: PathBuf,
2929

30+
/// Cardano network
31+
#[example = "`testnet` or `mainnet` or `devnet`"]
32+
pub network: String,
33+
3034
/// Cardano Network Magic number
3135
/// useful for TestNet & DevNet
3236
#[example = "`1097911063` or `42`"]
3337
pub network_magic: Option<u64>,
3438

35-
/// Cardano network
36-
#[example = "`testnet` or `mainnet` or `devnet`"]
37-
pub network: String,
39+
/// Also known as `k`, it defines the number of blocks that are required for the blockchain to
40+
/// be considered final, preventing any further rollback `[default: 2160]`.
41+
pub network_security_parameter: BlockNumber,
3842

3943
/// Aggregator endpoint
4044
#[example = "`https://aggregator.pre-release-preview.api.mithril.network/aggregator`"]
@@ -95,6 +99,11 @@ pub struct Configuration {
9599
///
96100
/// Will be ignored on (pre)production networks.
97101
pub allow_unparsable_block: bool,
102+
103+
/// If set, the signer will prune the cardano transactions in database older than the
104+
/// [network_security_parameter][Self::network_security_parameter] blocks after each import
105+
/// `[default: true]`.
106+
pub enable_transaction_pruning: bool,
98107
}
99108

100109
impl Configuration {
@@ -111,6 +120,7 @@ impl Configuration {
111120
db_directory: PathBuf::new(),
112121
network: "devnet".to_string(),
113122
network_magic: Some(42),
123+
network_security_parameter: 2160,
114124
party_id: Some(party_id),
115125
run_interval: 5000,
116126
data_stores_directory: PathBuf::new(),
@@ -127,6 +137,7 @@ impl Configuration {
127137
metrics_server_ip: "0.0.0.0".to_string(),
128138
metrics_server_port: 9090,
129139
allow_unparsable_block: false,
140+
enable_transaction_pruning: false,
130141
}
131142
}
132143

@@ -187,6 +198,12 @@ pub struct DefaultConfiguration {
187198

188199
/// Metrics HTTP server listening port.
189200
pub metrics_server_port: u16,
201+
202+
/// Network security parameter
203+
pub network_security_parameter: BlockNumber,
204+
205+
/// Transaction pruning toggle
206+
pub enable_transaction_pruning: bool,
190207
}
191208

192209
impl DefaultConfiguration {
@@ -201,6 +218,8 @@ impl Default for DefaultConfiguration {
201218
era_reader_adapter_type: "bootstrap".to_string(),
202219
metrics_server_ip: "0.0.0.0".to_string(),
203220
metrics_server_port: 9090,
221+
network_security_parameter: 2160, // 2160 is the mainnet value
222+
enable_transaction_pruning: true,
204223
}
205224
}
206225
}
@@ -232,6 +251,16 @@ impl Source for DefaultConfiguration {
232251
into_value(myself.metrics_server_port),
233252
);
234253

254+
result.insert(
255+
"network_security_parameter".to_string(),
256+
into_value(myself.network_security_parameter),
257+
);
258+
259+
result.insert(
260+
"enable_transaction_pruning".to_string(),
261+
into_value(myself.enable_transaction_pruning),
262+
);
263+
235264
Ok(result)
236265
}
237266
}

mithril-signer/src/runtime/signer_services.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ impl<'a> ServiceBuilder for ProductionServiceBuilder<'a> {
275275
));
276276
// Wrap the transaction importer with decorator to prune the transactions after import
277277
let transactions_importer = Arc::new(crate::TransactionsImporterWithPruneDecorator::new(
278-
None,
278+
self.config
279+
.enable_transaction_pruning
280+
.then_some(self.config.network_security_parameter),
279281
transaction_store.clone(),
280282
transactions_importer,
281283
));

0 commit comments

Comments
 (0)