Skip to content

Commit 9adeafa

Browse files
committed
fix conflict
1 parent af94fc8 commit 9adeafa

File tree

6 files changed

+35
-50
lines changed

6 files changed

+35
-50
lines changed

.githooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ echo "Running cargo fmt --all..."
33
cargo +nightly fmt --all || exit 1
44

55
echo "Running cargo clippy --all..."
6-
#cargo clippy --all || exit 1
6+
cargo clippy --all || exit 1
77

88
echo "Running cargo sort workspace..."
99
cargo sort --workspace || exit 1

anchor/common/ssv_types/src/util.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ pub enum RsaParseError {
1818
},
1919
}
2020

21-
impl From<RsaParseError> for String {
22-
fn from(error: RsaParseError) -> Self {
23-
error.to_string()
24-
}
25-
}
26-
2721
// Parse from a RSA public key string into the associated RSA representation
2822
pub fn parse_rsa(pem_data: &str) -> Result<Rsa<Public>, RsaParseError> {
2923
// First decode the base64 data

anchor/eth/src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use thiserror::Error;
22

3+
use crate::util::ShareParseError;
4+
35
// Custom execution integration layer errors
46
#[derive(Debug, Error)]
57
pub enum ExecutionError {
@@ -59,6 +61,9 @@ pub enum ExecutionError {
5961

6062
#[error("Database error: {0}")]
6163
Database(String),
64+
65+
#[error("Share parse error: {0}")]
66+
ShareParseError(#[from] ShareParseError),
6267
}
6368

6469
impl ExecutionError {

anchor/eth/src/event_processor.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
use std::sync::Arc;
22

3-
/// Simple wrapper to make String compatible with Error trait
4-
#[derive(Debug)]
5-
struct StringError(String);
6-
7-
impl std::fmt::Display for StringError {
8-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9-
write!(f, "{}", self.0)
10-
}
11-
}
12-
13-
impl std::error::Error for StringError {}
14-
153
use alloy::{primitives::Address, rpc::types::Log, sol_types::SolEvent};
164
use database::{NetworkDatabase, UniqueIndex};
175
use eth2::types::PublicKeyBytes;
@@ -319,7 +307,7 @@ impl EventProcessor {
319307
Some(validator_pubkey.to_string()),
320308
Some(cluster_id),
321309
"Failed to parse shares",
322-
Some(Box::new(StringError(e))),
310+
Some(Box::new(e)),
323311
)
324312
})?;
325313

@@ -582,7 +570,7 @@ impl EventProcessor {
582570

583571
let block_timestamp = log
584572
.block_timestamp
585-
.ok_or_else(|| ExecutionError::InvalidEvent("Block timestamp not set".to_string()))?;
573+
.ok_or_else(|| ExecutionError::invalid_event("Block timestamp not set", None))?;
586574

587575
let validator_index = match self.get_validator_index(&validator_pubkey) {
588576
Ok(Some(value)) => value,

anchor/eth/src/sync.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl SsvEventSyncer {
130130
exit_tx: ExitTx,
131131
config: Config,
132132
) -> Result<Self, ExecutionError> {
133-
info!("Creating new SSV Event Syncer");
133+
debug!("Creating new SSV Event Syncer");
134134

135135
// Construct the rpc provider
136136
let rpc_client = http_with_timeout_and_fallback(&config.http_urls);
@@ -576,9 +576,9 @@ impl SsvEventSyncer {
576576
continue;
577577
}
578578

579-
let block_number = log.block_number.ok_or_else(|| {
580-
ExecutionError::InvalidEvent("Block number not available".to_string())
581-
})?;
579+
let block_number = log
580+
.block_number
581+
.ok_or_else(|| ExecutionError::invalid_event("Block number not available", None))?;
582582

583583
if let Some(timestamp) = block_timestamp_cache.get(&block_number) {
584584
log.block_timestamp = Some(*timestamp);
@@ -595,7 +595,7 @@ impl SsvEventSyncer {
595595
block
596596
}
597597
Ok(None) => {
598-
return Err(ExecutionError::InvalidEvent("Block not found".to_string()));
598+
return Err(ExecutionError::invalid_event("Block not found", None));
599599
}
600600
Err(e) => {
601601
return Err(ExecutionError::RpcError(format!(

anchor/eth/src/util.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,30 @@ use database::NetworkState;
1010
use reqwest::Client;
1111
use sensitive_url::SensitiveUrl;
1212
use ssv_types::{ClusterId, ENCRYPTED_KEY_LENGTH, OperatorId, Share, ValidatorMetadata};
13+
use thiserror::Error;
1314
use tower::ServiceBuilder;
1415
use tracing::debug;
1516
use types::{Graffiti, PublicKeyBytes, Signature};
1617

17-
use crate::{error::ExecutionError, sync::MAX_OPERATORS};
18+
use crate::{error::ExecutionError, sync::MAX_OPERATORS, util::ShareParseError::InvalidLength};
1819

1920
// phase0.SignatureLength
2021
const SIGNATURE_LENGTH: usize = 96;
2122
// phase0.PublicKeyLength
2223
const PUBLIC_KEY_LENGTH: usize = 48;
2324

24-
// Simple wrapper to make String compatible with Error trait
25-
#[derive(Debug)]
26-
struct StringError(String);
25+
/// Errors that can occur during share parsing
26+
#[derive(Error, Debug)]
27+
pub enum ShareParseError {
28+
#[error("Share data has invalid length: expected {expected}, got {actual}")]
29+
InvalidLength { expected: usize, actual: usize },
2730

28-
impl std::fmt::Display for StringError {
29-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30-
write!(f, "{}", self.0)
31-
}
32-
}
31+
#[error("Failed to create public key: {0}")]
32+
PublicKeyCreation(String),
3333

34-
impl std::error::Error for StringError {}
34+
#[error("Encrypted key has wrong length")]
35+
EncryptedKeyLength,
36+
}
3537

3638
// Parses shares from a ValidatorAdded event
3739
// Event contains a bytes stream of the form
@@ -41,7 +43,7 @@ pub fn parse_shares(
4143
operator_ids: &[OperatorId],
4244
cluster_id: &ClusterId,
4345
validator_pubkey: &PublicKeyBytes,
44-
) -> Result<(Vec<u8>, Vec<Share>), String> {
46+
) -> Result<(Vec<u8>, Vec<Share>), ShareParseError> {
4547
let operator_count = operator_ids.len();
4648

4749
// Calculate offsets for different components within the shares
@@ -51,11 +53,10 @@ pub fn parse_shares(
5153

5254
// Validate total length of shares
5355
if shares_expected_length != shares.len() {
54-
return Err(format!(
55-
"Share data has invalid length: expected {}, got {}",
56-
shares_expected_length,
57-
shares.len()
58-
));
56+
return Err(InvalidLength {
57+
expected: shares_expected_length,
58+
actual: shares.len(),
59+
});
5960
}
6061

6162
// Extract all of the components
@@ -78,12 +79,12 @@ pub fn parse_shares(
7879

7980
// Create public key
8081
let share_pubkey = PublicKeyBytes::from_str(&public_key_hex)
81-
.map_err(|e| format!("Failed to create public key: {e}"))?;
82+
.map_err(ShareParseError::PublicKeyCreation)?;
8283

8384
// Convert encrypted key into fixed array
8485
let encrypted_array: [u8; 256] = encrypted
8586
.try_into()
86-
.map_err(|_| "Encrypted key has wrong length".to_string())?;
87+
.map_err(|_| ShareParseError::EncryptedKeyLength)?;
8788

8889
Ok(Share {
8990
validator_pubkey: *validator_pubkey,
@@ -93,7 +94,7 @@ pub fn parse_shares(
9394
encrypted_private_key: encrypted_array,
9495
})
9596
})
96-
.collect::<Result<Vec<_>, String>>()?;
97+
.collect::<Result<Vec<_>, ShareParseError>>()?;
9798

9899
Ok((signature, shares))
99100
}
@@ -216,18 +217,15 @@ pub fn validate_operators(
216217
}
217218

218219
/// Helper function to parse validator public keys
219-
pub fn parse_validator_pubkey(pubkey: &Bytes) -> Result<PublicKeyBytes, ExecutionError> {
220+
pub fn parse_validator_pubkey(pubkey: &Bytes) -> Result<PublicKeyBytes, ShareParseError> {
220221
let pubkey_str = pubkey.to_string();
221222
PublicKeyBytes::from_str(&pubkey_str).map_err(|e| {
222223
debug!(
223224
validator_pubkey = %pubkey_str,
224225
error = %e,
225226
"Failed to parse validator public key"
226227
);
227-
ExecutionError::invalid_event(
228-
format!("Failed to parse validator public key: {e}"),
229-
Some(Box::new(StringError(e.to_string()))),
230-
)
228+
ShareParseError::PublicKeyCreation(e)
231229
})
232230
}
233231

0 commit comments

Comments
 (0)