Skip to content

Commit 58766b8

Browse files
committed
Few enhancements in multi signer
1 parent 1843219 commit 58766b8

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

mithril-aggregator/src/http_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ mod handlers {
203203
Ok(Some(beacon)) => {
204204
let message = fake_data::digest(&beacon);
205205
let multi_signer = multi_signer.read().await;
206-
match multi_signer.get_multi_signature(message.encode_hex::<String>()) {
206+
match multi_signer.get_multi_signature(&message.encode_hex::<String>()) {
207207
Ok(None) => {
208208
let mut certificate_pending = fake_data::certificate_pending();
209209
certificate_pending.beacon = beacon.clone();
@@ -285,7 +285,7 @@ mod handlers {
285285
// TODO: This is temporary implementation that will be replaced with real certificate production
286286
let multi_signer = multi_signer.read().await;
287287
let message = certificate_hash.clone();
288-
match multi_signer.get_multi_signature(message.clone()) {
288+
match multi_signer.get_multi_signature(&message) {
289289
Ok(Some(multi_signature)) => {
290290
let beacon_store = beacon_store.read().await;
291291
let beacon = beacon_store.get_current_beacon().await.unwrap().unwrap();

mithril-aggregator/src/multi_signer.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub trait MultiSigner: Sync + Send {
8787
/// Retrieves a multi signature from a message
8888
fn get_multi_signature(
8989
&self,
90-
message: String,
90+
message: &str,
9191
) -> Result<Option<ProtocolMultiSignature>, ProtocolError>;
9292

9393
/// Create a multi signature from single signatures
@@ -96,12 +96,23 @@ pub trait MultiSigner: Sync + Send {
9696

9797
/// MultiSignerImpl is an implementation of the MultiSigner
9898
pub struct MultiSignerImpl {
99+
/// Message that is currently signed
99100
current_message: Option<Bytes>,
101+
102+
/// Protocol parameters used for signing
100103
protocol_parameters: Option<ProtocolParameters>,
104+
105+
/// Stake distribution used for signing
101106
stakes: ProtocolStakeDistribution,
107+
108+
/// Registered signers
102109
signers: HashMap<ProtocolPartyId, ProtocolSignerVerificationKey>,
110+
111+
/// Registered single signatures by party and lottery index
103112
single_signatures:
104113
HashMap<ProtocolPartyId, HashMap<ProtocolLotteryIndex, ProtocolSingleSignature>>,
114+
115+
/// Recorded multi signatures by message signed
105116
multi_signatures: HashMap<String, String>,
106117
}
107118

@@ -271,10 +282,10 @@ impl MultiSigner for MultiSignerImpl {
271282
/// Retrieves a multi signature from a message
272283
fn get_multi_signature(
273284
&self,
274-
message: String,
285+
message: &str,
275286
) -> Result<Option<ProtocolMultiSignature>, ProtocolError> {
276287
debug!("Get multi signature for message {}", message);
277-
match self.multi_signatures.get(&message) {
288+
match self.multi_signatures.get(message) {
278289
Some(multi_signature) => {
279290
let multi_signature: ProtocolMultiSignature =
280291
key_decode_hex(multi_signature).map_err(ProtocolError::Codec)?;
@@ -463,7 +474,7 @@ mod tests {
463474
.create_multi_signature()
464475
.expect("create multi sgnature should not fail");
465476
assert!(multi_signer
466-
.get_multi_signature(message.encode_hex::<String>())
477+
.get_multi_signature(&message.encode_hex::<String>())
467478
.expect("get multi signature should not fail")
468479
.is_none());
469480
signatures[0..quorum_split]
@@ -477,7 +488,7 @@ mod tests {
477488
.create_multi_signature()
478489
.expect("create multi sgnature should not fail");
479490
assert!(multi_signer
480-
.get_multi_signature(message.encode_hex::<String>())
491+
.get_multi_signature(&message.encode_hex::<String>())
481492
.expect("get multi signature should not fail")
482493
.is_none());
483494
signatures[quorum_split..]
@@ -491,7 +502,7 @@ mod tests {
491502
.create_multi_signature()
492503
.expect("create multi sgnature should not fail");
493504
assert!(multi_signer
494-
.get_multi_signature(message.encode_hex::<String>())
505+
.get_multi_signature(&message.encode_hex::<String>())
495506
.expect("get multi signature should not fail")
496507
.is_some());
497508
}

mithril-aggregator/src/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl AggregatorRuntime {
164164
) -> Result<bool, RuntimeError> {
165165
let mut multi_signer = self.multi_signer.write().await;
166166
let mut beacon_store = self.beacon_store.write().await;
167-
match multi_signer.get_multi_signature(message.encode_hex::<String>()) {
167+
match multi_signer.get_multi_signature(&message.encode_hex::<String>()) {
168168
Ok(None) => {
169169
beacon_store.set_current_beacon(beacon.clone()).await?;
170170
multi_signer.update_current_message(message.to_owned())?;

0 commit comments

Comments
 (0)