Skip to content

Commit 0e58de0

Browse files
committed
fix: address comments
1 parent 59d09ac commit 0e58de0

3 files changed

Lines changed: 22 additions & 41 deletions

File tree

crates/dkg/src/aggregate.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,8 @@ mod tests {
399399
})
400400
.collect::<Vec<_>>();
401401

402-
let mut data = HashMap::new();
403-
data.insert(core_pub_key, partials);
404-
405-
let mut msgs = HashMap::new();
406-
msgs.insert(core_pub_key, reg.clone());
402+
let data = HashMap::from([(core_pub_key, partials)]);
403+
let msgs = HashMap::from([(core_pub_key, reg.clone())]);
407404

408405
let res =
409406
agg_validator_registrations(&data, std::slice::from_ref(&share), &msgs, &fork_version)

crates/dkg/src/dkg.rs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -250,34 +250,15 @@ pub fn log_peer_summary(
250250
.filter(|operator| !operator.address.is_empty())
251251
.map(|operator| operator.address.as_str());
252252
let is_current_peer = peer.id == current_peer;
253-
254-
if let Some(address) = address {
255-
if is_current_peer {
256-
info!(
257-
peer = peer.name,
258-
index = peer.index,
259-
address,
260-
you = "⭐️",
261-
"Peer summary"
262-
);
263-
} else {
264-
info!(
265-
peer = peer.name,
266-
index = peer.index,
267-
address,
268-
"Peer summary"
269-
);
270-
}
271-
} else if is_current_peer {
272-
info!(
273-
peer = peer.name,
274-
index = peer.index,
275-
you = "⭐️",
276-
"Peer summary"
277-
);
278-
} else {
279-
info!(peer = peer.name, index = peer.index, "Peer summary");
280-
}
253+
let you = is_current_peer.then_some("⭐");
254+
255+
info!(
256+
peer = peer.name,
257+
index = peer.index,
258+
address,
259+
you,
260+
"Peer summary"
261+
);
281262
}
282263
}
283264

crates/dkg/src/signing.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ pub type Result<T> = std::result::Result<T, SigningError>;
1616
#[derive(Debug, thiserror::Error)]
1717
pub enum SigningError {
1818
/// Failed to build a core public key from bytes.
19-
#[error("invalid public key length")]
20-
InvalidPublicKeyLength,
19+
#[error("invalid public key length while {error_context}")]
20+
InvalidPublicKeyLength {
21+
/// Signing helper that encountered the invalid key.
22+
error_context: &'static str,
23+
},
2124

2225
/// Failed to sign or verify with threshold BLS.
2326
#[error(transparent)]
@@ -65,8 +68,7 @@ pub fn sign_lock_hash(share_idx: u64, shares: &[Share], hash: &[u8]) -> Result<P
6568
let mut set = ParSignedDataSet::new();
6669

6770
for share in shares {
68-
let pub_key = PubKey::try_from(share.pub_key.as_slice())
69-
.map_err(|_| SigningError::InvalidPublicKeyLength)?;
71+
let pub_key = share_pubkey(share, "signing lock hash")?;
7072
let sig = BlstImpl.sign(&share.secret_share, hash)?;
7173

7274
set.insert(
@@ -97,7 +99,7 @@ pub fn sign_deposit_msgs(
9799

98100
for (share, withdrawal_address) in shares.iter().zip(withdrawal_addresses.iter()) {
99101
let eth2_pubkey = pubkey_to_eth2(share.pub_key);
100-
let pub_key = share_pubkey(share)?;
102+
let pub_key = share_pubkey(share, "signing deposit message")?;
101103
let withdrawal_address = pluto_eth2util::helpers::checksum_address(withdrawal_address)?;
102104

103105
let msg = deposit::new_message(eth2_pubkey, &withdrawal_address, amount, compounding)?;
@@ -139,7 +141,7 @@ pub fn sign_validator_registrations(
139141

140142
for (share, fee_recipient) in shares.iter().zip(fee_recipients.iter()) {
141143
let eth2_pubkey = pubkey_to_eth2(share.pub_key);
142-
let pub_key = share_pubkey(share)?;
144+
let pub_key = share_pubkey(share, "signing validator registration")?;
143145

144146
let reg_msg = registration::new_message(
145147
eth2_pubkey,
@@ -170,8 +172,9 @@ pub fn sign_validator_registrations(
170172
Ok((set, msgs))
171173
}
172174

173-
fn share_pubkey(share: &Share) -> Result<PubKey> {
174-
PubKey::try_from(share.pub_key.as_slice()).map_err(|_| SigningError::InvalidPublicKeyLength)
175+
fn share_pubkey(share: &Share, error_context: &'static str) -> Result<PubKey> {
176+
PubKey::try_from(share.pub_key.as_slice())
177+
.map_err(|_| SigningError::InvalidPublicKeyLength { error_context })
175178
}
176179

177180
#[cfg(test)]

0 commit comments

Comments
 (0)