Skip to content

Commit

Permalink
resolve cloning and log msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
woocash2 committed Oct 6, 2023
1 parent d55db7e commit 38be508
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions rmc/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ impl<H: Signable + Hash + Eq + Clone + Debug, MK: MultiKeychain> Handler<H, MK>
/// version of the hash for broadcast. Should be called at most once for a particular hash.
pub fn on_start_rmc(&mut self, hash: H) -> Signed<Indexed<H>, MK> {
let signed_hash = Signed::sign_with_index(hash, &self.keychain);
self.handle_signed_hash(signed_hash.clone());
if !self.already_completed(signed_hash.as_signable().as_signable()) {
self.handle_signed_hash(signed_hash.clone());
}
signed_hash
}
/// Update the internal state with the signed hash. If the hash is incorrectly signed then
Expand All @@ -54,30 +56,32 @@ impl<H: Signable + Hash + Eq + Clone + Debug, MK: MultiKeychain> Handler<H, MK>
let signed_hash = unchecked
.check(&self.keychain)
.map_err(|_| Error::BadSignature)?;
Ok(self.handle_signed_hash(signed_hash))
Ok(
match self.already_completed(signed_hash.as_signable().as_signable()) {
true => None,
false => self.handle_signed_hash(signed_hash),
},
)
}

fn handle_signed_hash(&mut self, signed: Signed<Indexed<H>, MK>) -> Option<Multisigned<H, MK>> {
let hash = signed.as_signable().as_signable().clone();
if self.already_completed(&hash) {
return None;
}
let new_state = match self.hash_states.remove(&hash) {
None => signed.into_partially_multisigned(&self.keychain),
Some(partial) => partial.add_signature(signed, &self.keychain),
};
match new_state {
PartiallyMultisigned::Complete { multisigned } => {
self.hash_states.insert(
hash.clone(),
hash,
PartiallyMultisigned::Complete {
multisigned: multisigned.clone(),
},
);
Some(multisigned)
}
incomplete => {
self.hash_states.insert(hash.clone(), incomplete);
self.hash_states.insert(hash, incomplete);
None
}
}
Expand Down
4 changes: 2 additions & 2 deletions rmc/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ where
}
Ok(None) => {}
Err(error) => {
warn!(target: LOG_TARGET, "{}", error);
warn!(target: LOG_TARGET, "failed handling signed hash: {}", error);
}
}
}
Expand All @@ -102,7 +102,7 @@ where
}
Ok(None) => {}
Err(error) => {
warn!(target: LOG_TARGET, "{}", error);
warn!(target: LOG_TARGET, "failed handling multisigned hash: {}", error);
}
}
}
Expand Down

0 comments on commit 38be508

Please sign in to comment.