Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/app/src/obolapi/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum Error {

/// Hex decoding error.
#[error("hex decoding error: {0}")]
HexDecode(#[from] hex::FromHexError),
HexDecode(#[from] pluto_ssz::HexDecodeError),

/// Empty hex string.
#[error("empty hex string")]
Expand Down
7 changes: 0 additions & 7 deletions crates/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,6 @@ pub enum CreateClusterError {
#[error("Crypto error: {0}")]
CryptoError(#[from] pluto_crypto::types::Error),

/// Value exceeds u8::MAX.
#[error("Value {value} exceeds u8::MAX (255)")]
ValueExceedsU8 {
/// The value that exceeds u8::MAX.
value: u64,
},

/// Value exceeds usize::MAX.
#[error("Value {value} exceeds usize::MAX")]
ValueExceedsUsize {
Expand Down
22 changes: 9 additions & 13 deletions crates/cluster/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ impl Serialize for Definition {
{
match self.version.as_str() {
V1_0 | V1_1 => DefinitionV1x0or1::try_from(self.clone())
.map_err(|e| serde::ser::Error::custom(format!("Conversion error: {:?}", e)))?
.map_err(|e| serde::ser::Error::custom(format!("Conversion error: {e}")))?
.serialize(serializer),
V1_2 | V1_3 => DefinitionV1x2or3::try_from(self.clone())
.map_err(|e| serde::ser::Error::custom(format!("Conversion error: {:?}", e)))?
.map_err(|e| serde::ser::Error::custom(format!("Conversion error: {e}")))?
.serialize(serializer),
V1_4 => DefinitionV1x4::try_from(self.clone())
.map_err(|e| serde::ser::Error::custom(format!("Conversion error: {:?}", e)))?
.map_err(|e| serde::ser::Error::custom(format!("Conversion error: {e}")))?
.serialize(serializer),
V1_5 | V1_6 | V1_7 => DefinitionV1x5to7::from(self.clone()).serialize(serializer),
V1_8 => DefinitionV1x8::from(self.clone()).serialize(serializer),
Expand Down Expand Up @@ -167,21 +167,21 @@ impl<'de> Deserialize<'de> for Definition {
serde_json::from_value(value).map_err(Error::custom)?;
definition
.try_into()
.map_err(|e| Error::custom(format!("Conversion error: {:?}", e)))
.map_err(|e| Error::custom(format!("Conversion error: {e}")))
}
V1_2 | V1_3 => {
let definition: DefinitionV1x2or3 =
serde_json::from_value(value).map_err(Error::custom)?;
definition
.try_into()
.map_err(|e| Error::custom(format!("Conversion error: {:?}", e)))
.map_err(|e| Error::custom(format!("Conversion error: {e}")))
}
V1_4 => {
let definition: DefinitionV1x4 =
serde_json::from_value(value).map_err(Error::custom)?;
definition
.try_into()
.map_err(|e| Error::custom(format!("Conversion error: {:?}", e)))
.map_err(|e| Error::custom(format!("Conversion error: {e}")))
}
V1_5 | V1_6 | V1_7 => {
let definition: DefinitionV1x5to7 =
Expand Down Expand Up @@ -268,7 +268,7 @@ pub enum DefinitionError {

/// Failed to convert hex string
#[error("Failed to convert hex string")]
FailedToConvertHexString(#[from] hex::FromHexError),
FailedToConvertHexString(#[from] pluto_ssz::HexDecodeError),

/// Invalid target gas limit
#[error("Invalid target gas limit: {0}")]
Expand Down Expand Up @@ -1773,13 +1773,9 @@ mod tests {
result.is_err(),
"u64::MAX num_validators must be rejected, not allocated"
);
// The deserialize dispatch renders the TryFrom error via Debug
// ("Conversion error: NumValidatorsTooLarge {{ .. }}"), so assert on
// the variant name and the enforced max, both of which appear
// in the Debug repr.
let msg = format!("{}", result.unwrap_err());
assert!(
msg.contains("NumValidatorsTooLarge") && msg.contains("65536"),
msg.contains("exceeds maximum") && msg.contains("65536"),
"unexpected error message: {msg}"
);
}
Expand Down Expand Up @@ -1938,7 +1934,7 @@ mod tests {

let err = serde_json::from_value::<Definition>(value).unwrap_err();
assert!(
err.to_string().contains("NonZeroOperatorNonce"),
err.to_string().contains("non-zero operator nonce"),
"unexpected error: {err}"
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cluster/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
eip712sigs, operator,
};

pub use pluto_ssz::{from_0x_hex_str, left_pad, to_0x_hex};
pub use pluto_ssz::{HexDecodeError, from_0x_hex_str, left_pad, to_0x_hex};

/// Error type returned by `verify_sig`.
#[derive(Debug, thiserror::Error)]
Expand Down
2 changes: 1 addition & 1 deletion crates/cluster/src/ssz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub enum SSZError<H: HashWalker> {

/// Failed to convert hex string
#[error("Failed to convert hex string: {0}")]
FailedToConvertHexString(#[from] hex::FromHexError),
FailedToConvertHexString(#[from] pluto_ssz::HexDecodeError),

/// Failed to convert timestamp
#[error("Failed to convert timestamp")]
Expand Down
8 changes: 2 additions & 6 deletions crates/core/src/parsigdb/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,11 @@ impl MemDB {
}
}

inner
.entries
.entry(k.clone())
.or_insert_with(Vec::new)
.push(value);
inner.entries.entry(k.clone()).or_default().push(value);
inner
.keys_by_duty
.entry(k.duty.clone())
.or_insert_with(Vec::new)
.or_default()
.push(k.clone());

if k.duty.duty_type == DutyType::Exit {
Expand Down
4 changes: 0 additions & 4 deletions crates/core/src/parsigex_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ pub enum ParSigExCodecError {
#[error("invalid unsigned data set fields")]
InvalidUnsignedDataSetFields,

/// Invalid partial signed proto.
#[error("invalid partial signed proto")]
InvalidParSignedProto,

/// Invalid duty type.
#[error("invalid duty")]
InvalidDuty,
Expand Down
7 changes: 2 additions & 5 deletions crates/core/src/qbft/internal_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2153,12 +2153,9 @@ fn run_parent_cancel_during_compare_does_not_prepare() {
}

fn buffer_by_source(msgs: &[Msg<TestQbft>]) -> HashMap<i64, Vec<Msg<TestQbft>>> {
let mut buffer = HashMap::new();
let mut buffer: HashMap<i64, Vec<_>> = HashMap::new();
for msg in msgs {
buffer
.entry(msg.source())
.or_insert_with(Vec::new)
.push(msg.clone());
buffer.entry(msg.source()).or_default().push(msg.clone());
}
buffer
}
Expand Down
3 changes: 0 additions & 3 deletions crates/core/src/signeddata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ pub enum SignedDataError {
/// Missing attestation payload for the selected fork.
#[error("no {0} attestation")]
MissingAttestation(versioned::DataVersion),
/// Missing aggregate-and-proof payload for the selected fork.
#[error("no {0} aggregate and proof")]
MissingAggregateAndProof(versioned::DataVersion),
/// Missing unblinded proposal payload for the selected fork.
#[error("no {0} proposal")]
MissingProposal(versioned::DataVersion),
Expand Down
2 changes: 1 addition & 1 deletion crates/dkg/src/exchanger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ async fn push_psigs(

{
let mut inner = sig_data.inner.lock().await;
let entry = inner.entry(sig_type).or_insert_with(HashMap::new);
let entry = inner.entry(sig_type).or_default();
for (pk, psigs) in set {
entry.insert(pk, psigs);
}
Expand Down
8 changes: 2 additions & 6 deletions crates/eth2util/src/deposit/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum DepositError {

// Amount validation errors
/// Amount is below minimum
#[error("Each partial deposit amount must be greater than 1ETH, got {0} Gwei")]
#[error("Each partial deposit amount must be at least 1ETH, got {0} Gwei")]
AmountBelowMinimum(Gwei),

/// Amount exceeds maximum
Expand All @@ -36,7 +36,7 @@ pub enum DepositError {
AmountSumBelowDefault(Gwei),

/// Deposit message minimum amount not met
#[error("Deposit message minimum amount must be >= {MIN_DEPOSIT_AMOUNT} ETH, got {0} Gwei")]
#[error("Deposit message minimum amount must be >= {MIN_DEPOSIT_AMOUNT} Gwei, got {0} Gwei")]
MinimumAmountNotMet(Gwei),

/// Deposit message maximum amount exceeded
Expand All @@ -57,10 +57,6 @@ pub enum DepositError {
#[error("Crypto error: {0}")]
CryptoError(String),

/// Hash tree root computation error
#[error("Hash tree root error: {0}")]
HashTreeRootError(String),

// File operations errors
/// IO error
#[error("IO error: {0}")]
Expand Down
12 changes: 4 additions & 8 deletions crates/eth2util/src/enr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,17 @@ pub enum RecordError {
#[error("Failed to parse the secp256k1 public key: {0}")]
Secp256k1Error(#[from] elliptic_curve::Error),

/// Failed to verify the signature.
#[error("Signature verification succeeded, but the signature is invalid")]
/// Signature verification ran and rejected the signature.
#[error("The record signature does not match the public key")]
FailedToVerifySignature,

/// The signature is invalid.
#[error("The verification failed: {0}")]
/// Signature verification could not be performed.
#[error("Failed to verify the record signature: {0}")]
InvalidSignature(pluto_k1util::K1UtilError),

/// Failed to sign the record.
#[error("Failed to sign the record: {0}")]
FailedToSign(pluto_k1util::K1UtilError),

/// Failed to convert the signature.
#[error("Failed to convert the signature: {0}")]
FailedToConvertSignature(std::array::TryFromSliceError),
}

/// InvalidFormatError is an error type for invalid format errors.
Expand Down
13 changes: 5 additions & 8 deletions crates/eth2util/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ pub enum HelperError {
#[error("Invalid ethereum address: {0}")]
InvalidAddress(String),

/// Hex decoding error
#[error("Invalid ethereum hex address: {0}")]
InvalidHexAddress(String),

/// Invalid HTTP header format
#[error("http headers must be comma separated values formatted as header=value")]
InvalidHTTPHeader,
Expand All @@ -31,9 +27,10 @@ pub enum HelperError {
#[error("getting spec: {0}")]
GettingSpec(String),

/// Failed to fetch a required value from the spec
#[error("fetch slots per epoch")]
FetchSlotsPerEpoch,
/// The beacon node reported a zero slots-per-epoch, so an epoch cannot be
/// derived from a slot.
#[error("beacon node reported slots per epoch as zero")]
ZeroSlotsPerEpoch,

/// The slot for a timestamp could not be computed from the genesis time and
/// slot duration (out-of-range timestamp, overflow, or a zero slot
Expand Down Expand Up @@ -167,7 +164,7 @@ pub async fn epoch_from_slot(
.map_err(|e| HelperError::GettingSpec(e.to_string()))?;

slot.checked_div(slots_per_epoch)
.ok_or(HelperError::FetchSlotsPerEpoch)
.ok_or(HelperError::ZeroSlotsPerEpoch)
}

#[cfg(test)]
Expand Down
4 changes: 0 additions & 4 deletions crates/eth2util/src/keystore/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ pub enum KeystoreError {
#[error("hex decode error: {0}")]
HexDecode(#[from] hex::FromHexError),

/// Unsupported KDF function.
#[error("unsupported KDF: {0}")]
UnsupportedKdf(String),

/// Checksum verification failed.
#[error("decrypt keystore: checksum verification failed")]
InvalidChecksum,
Expand Down
3 changes: 0 additions & 3 deletions crates/eth2util/src/rlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ pub enum RlpError {
/// The input is too short.
#[error("input too short")]
InputTooShort,
/// The length is negative.
#[error("negative length")]
NegativeLength,
/// The length is too large.
#[error("length overflow")]
Overflow,
Expand Down
4 changes: 2 additions & 2 deletions crates/k1util/src/k1util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ pub enum K1UtilError {
type Result<T> = std::result::Result<T, K1UtilError>;

/// Converts a libp2p PublicKey to a secp256k1 PublicKey.
pub fn public_key_from_libp2p(pk: &Libp2pPublicKey) -> Result<PublicKey> {
let secp_key = pk.clone().try_into_secp256k1()?;
pub fn public_key_from_libp2p(pk: Libp2pPublicKey) -> Result<PublicKey> {
let secp_key = pk.try_into_secp256k1()?;
PublicKey::from_sec1_bytes(&secp_key.to_bytes())
.map_err(K1UtilError::FailedToParseSecp256k1PublicKey)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/p2p/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl MutablePeer {
/// Only works for secp256k1 keys.
pub fn peer_id_to_public_key(peer_id: &PeerId) -> Result<K256PublicKey> {
let libp2p_pk = peer_id_to_libp2p_pk(peer_id)?;
pluto_k1util::public_key_from_libp2p(&libp2p_pk).map_err(Into::into)
pluto_k1util::public_key_from_libp2p(libp2p_pk).map_err(Into::into)
}

/// Extracts the libp2p PublicKey from a PeerId.
Expand Down Expand Up @@ -197,7 +197,7 @@ pub fn verify_p2p_key(peers: &[Peer], key: &SecretKey) -> Result<()> {
for peer in peers {
let pub_key = peer_id_to_libp2p_pk(&peer.id)?;

let got = pluto_k1util::public_key_from_libp2p(&pub_key)?;
let got = pluto_k1util::public_key_from_libp2p(pub_key)?;

if got == want {
return Ok(());
Expand Down
4 changes: 2 additions & 2 deletions crates/priority/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub struct ScoredPriority {
///
/// Returns the unknown-peer or invalid-signature error rather than a boolean,
/// so callers reject messages from unrecognised peers or with bad signatures.
pub type MsgVerifier = Box<dyn Fn(&PriorityMsg) -> Result<()> + Send + Sync + 'static>;
pub type MsgVerifier = Arc<dyn Fn(&PriorityMsg) -> Result<()> + Send + Sync + 'static>;

/// Returns a copy of the message signed by `privkey`.
///
Expand Down Expand Up @@ -122,7 +122,7 @@ pub(crate) fn new_msg_verifier(peers: &[PeerId]) -> Result<MsgVerifier> {
keys.insert(peer.to_string(), pk);
}

Ok(Box::new(move |msg: &PriorityMsg| {
Ok(Arc::new(move |msg: &PriorityMsg| {
if msg.duty.is_none() {
return Err(Error::InvalidMsgProtoFields);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/priority/src/prioritiser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct Shared {
/// Cluster peers participating in the protocol.
peers: Vec<PeerId>,
/// Validates received messages (peer membership + signature).
msg_validator: Arc<MsgVerifier>,
msg_validator: MsgVerifier,
/// Cancelled when the engine shuts down, signalling instances to stop.
quit: CancellationToken,
/// Deadline scheduler; expired duties drop their request buffers.
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Shared {
return Err(Error::InvalidPeerId);
}

(self.msg_validator)(&msg)?; // Arc<Box<dyn Fn>> auto-derefs for call.
(self.msg_validator)(&msg)?;

let proto_duty = msg.duty.as_ref().ok_or(Error::InvalidMsgProtoFields)?;
let duty = duty_from_proto(proto_duty);
Expand Down Expand Up @@ -261,7 +261,7 @@ impl Prioritiser {
// feeds the remaining `Inner` fields — no construction cycle.
let shared = Arc::new(Shared {
peers,
msg_validator: Arc::new(msg_validator),
msg_validator,
quit: CancellationToken::new(),
deadliner,
req_buffers: Mutex::new(HashMap::new()),
Expand Down
2 changes: 1 addition & 1 deletion crates/priority/tests/prioritiser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn build_host(
let keypair = keypair_from_secret_key(key).expect("keypair");

// A permissive verifier returning Ok for every message.
let validator = Box::new(|_: &PriorityMsg| Ok(()));
let validator = Arc::new(|_: &PriorityMsg| Ok(()));

let (prioritiser, behaviour) = Prioritiser::new_internal(
peer_id,
Expand Down
Loading
Loading