Skip to content

Commit 1d251ed

Browse files
committed
refactor(dmq): better TTL support in 'DmqMessageBuilder'
1 parent 60c58c3 commit 1d251ed

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

internal/mithril-dmq-node/src/message.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,19 @@ pub struct DmqMessageBuilder {
2222

2323
impl DmqMessageBuilder {
2424
/// Creates a new instance of `DmqMessageBuilder`.
25-
pub fn new(
26-
kes_signer: Arc<dyn KesSigner>,
27-
chain_observer: Arc<dyn ChainObserver>,
28-
ttl_blocks: u16,
29-
) -> Self {
25+
pub fn new(kes_signer: Arc<dyn KesSigner>, chain_observer: Arc<dyn ChainObserver>) -> Self {
3026
Self {
3127
kes_signer,
3228
chain_observer,
33-
ttl_blocks,
29+
ttl_blocks: DMQ_MESSAGE_TTL_IN_BLOCKS,
3430
}
3531
}
3632

37-
/// Creates a new instance of `DmqMessageBuilder` with default TTL.
38-
pub fn new_with_default_ttl(
39-
kes_signer: Arc<dyn KesSigner>,
40-
chain_observer: Arc<dyn ChainObserver>,
41-
) -> Self {
42-
Self {
43-
kes_signer,
44-
chain_observer,
45-
ttl_blocks: DMQ_MESSAGE_TTL_IN_BLOCKS,
46-
}
33+
/// Set the TTL (Time To Live) for DMQ messages in blocks.
34+
pub fn set_ttl(mut self, ttl_blocks: u16) -> Self {
35+
self.ttl_blocks = ttl_blocks;
36+
37+
self
4738
}
4839

4940
/// Builds a DMQ message from the provided message bytes.
@@ -127,7 +118,7 @@ mod tests {
127118
},
128119
..TimePoint::dummy()
129120
})));
130-
let builder = DmqMessageBuilder::new(kes_signer, chain_observer, 100);
121+
let builder = DmqMessageBuilder::new(kes_signer, chain_observer).set_ttl(100);
131122
let message = test_utils::TestMessage {
132123
content: b"test".to_vec(),
133124
};

internal/mithril-dmq-node/src/publisher/pallas.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ mod tests {
159159
Arc::new(kes_signer)
160160
},
161161
Arc::new(FakeChainObserver::default()),
162-
100,
163-
),
162+
)
163+
.set_ttl(100),
164164
TestLogger::stdout(),
165165
);
166166

@@ -195,8 +195,8 @@ mod tests {
195195
Arc::new(kes_signer)
196196
},
197197
Arc::new(FakeChainObserver::default()),
198-
100,
199-
),
198+
)
199+
.set_ttl(100),
200200
TestLogger::stdout(),
201201
);
202202

mithril-signer/src/dependency_injection/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'a> DependenciesBuilder<'a> {
425425
let publisher = match &self.config.dmq_node_socket_path {
426426
Some(dmq_node_socket_path) => {
427427
let cardano_network = &self.config.get_network()?;
428-
let dmq_message_builder = DmqMessageBuilder::new_with_default_ttl(
428+
let dmq_message_builder = DmqMessageBuilder::new(
429429
kes_signer.clone().ok_or(anyhow!(
430430
"A KES signer is mandatory to sign DMQ messages"
431431
))?,

0 commit comments

Comments
 (0)