Skip to content

Commit 7f11ba8

Browse files
committed
fix conflict
1 parent af94fc8 commit 7f11ba8

File tree

4 files changed

+38
-44
lines changed

4 files changed

+38
-44
lines changed

anchor/eth/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use thiserror::Error;
2+
use crate::util::ShareParseError;
23

34
// Custom execution integration layer errors
45
#[derive(Debug, Error)]
@@ -59,6 +60,9 @@ pub enum ExecutionError {
5960

6061
#[error("Database error: {0}")]
6162
Database(String),
63+
64+
#[error("Share parse error: {0}")]
65+
ShareParseError(#[from] ShareParseError),
6266
}
6367

6468
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: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,35 @@ 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);
27-
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-
}
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 },
30+
31+
#[error("Failed to create public key: {0}")]
32+
PublicKeyCreation(String),
33+
34+
#[error(
35+
"Encrypted key has wrong length: expected {}, got {}",
36+
ENCRYPTED_KEY_LENGTH,
37+
"actual"
38+
)]
39+
EncryptedKeyLength,
3240
}
3341

34-
impl std::error::Error for StringError {}
35-
3642
// Parses shares from a ValidatorAdded event
3743
// Event contains a bytes stream of the form
3844
// [signature | public keys | encrypted keys].
@@ -41,7 +47,7 @@ pub fn parse_shares(
4147
operator_ids: &[OperatorId],
4248
cluster_id: &ClusterId,
4349
validator_pubkey: &PublicKeyBytes,
44-
) -> Result<(Vec<u8>, Vec<Share>), String> {
50+
) -> Result<(Vec<u8>, Vec<Share>), ShareParseError> {
4551
let operator_count = operator_ids.len();
4652

4753
// Calculate offsets for different components within the shares
@@ -51,11 +57,10 @@ pub fn parse_shares(
5157

5258
// Validate total length of shares
5359
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-
));
60+
return Err(InvalidLength {
61+
expected: shares_expected_length,
62+
actual: shares.len(),
63+
});
5964
}
6065

6166
// Extract all of the components
@@ -78,12 +83,12 @@ pub fn parse_shares(
7883

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

8388
// Convert encrypted key into fixed array
8489
let encrypted_array: [u8; 256] = encrypted
8590
.try_into()
86-
.map_err(|_| "Encrypted key has wrong length".to_string())?;
91+
.map_err(|_| ShareParseError::EncryptedKeyLength)?;
8792

8893
Ok(Share {
8994
validator_pubkey: *validator_pubkey,
@@ -93,7 +98,7 @@ pub fn parse_shares(
9398
encrypted_private_key: encrypted_array,
9499
})
95100
})
96-
.collect::<Result<Vec<_>, String>>()?;
101+
.collect::<Result<Vec<_>, ShareParseError>>()?;
97102

98103
Ok((signature, shares))
99104
}
@@ -216,18 +221,15 @@ pub fn validate_operators(
216221
}
217222

218223
/// Helper function to parse validator public keys
219-
pub fn parse_validator_pubkey(pubkey: &Bytes) -> Result<PublicKeyBytes, ExecutionError> {
224+
pub fn parse_validator_pubkey(pubkey: &Bytes) -> Result<PublicKeyBytes, ShareParseError> {
220225
let pubkey_str = pubkey.to_string();
221226
PublicKeyBytes::from_str(&pubkey_str).map_err(|e| {
222227
debug!(
223228
validator_pubkey = %pubkey_str,
224229
error = %e,
225230
"Failed to parse validator public key"
226231
);
227-
ExecutionError::invalid_event(
228-
format!("Failed to parse validator public key: {e}"),
229-
Some(Box::new(StringError(e.to_string()))),
230-
)
232+
ShareParseError::PublicKeyCreation(e)
231233
})
232234
}
233235

0 commit comments

Comments
 (0)