Skip to content

Commit

Permalink
network action parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacholme7 committed Dec 24, 2024
1 parent 4819cd6 commit 1665cd0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion anchor/eth/src/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl EventProcessor {

// Parse the share byte stream into a list of valid Shares and then verify the signature
debug!(cluster_id = ?cluster_id, "Parsing and verifying shares");
let (signature, shares) = parse_shares(shares.to_vec(), &operator_ids, &cluster_id)
let (signature, shares) = parse_shares(shares.to_vec(), &operator_ids, &cluster_id, &validator_pubkey)
.map_err(|e| {
error!(cluster_id = ?cluster_id, error = %e, "Failed to parse shares");
format!("Failed to parse shares: {e}")
Expand Down
22 changes: 13 additions & 9 deletions anchor/eth/src/network_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use super::gen::SSVContract;
use alloy::primitives::Address;
use alloy::{rpc::types::Log, sol_types::SolEvent};
use ssv_types::OperatorId;
use std::str::FromStr;
use types::PublicKey;

#[derive(Debug, PartialEq)]
pub enum NetworkAction {
StopValidator {
//pubkey: PublicKey,
validator_pubkey: PublicKey,
},
LiquidateCluster {
owner: Address,
Expand All @@ -22,10 +24,7 @@ pub enum NetworkAction {
recipient: Address,
},
ExitValidator {
//pubkey: PublicKey,
//block_number: u64,
//validator_index: u64,
//own_validator: bool,
validator_pubkey: PublicKey,
},
NoOp,
}
Expand All @@ -37,9 +36,11 @@ impl TryFrom<&Log> for NetworkAction {
let topic0 = source.topic0().expect("The log should have a topic0");
match *topic0 {
SSVContract::ValidatorRemoved::SIGNATURE_HASH => {
let _validator_removed_log =
let SSVContract::ValidatorRemoved { publicKey, .. } =
SSVContract::ValidatorRemoved::decode_from_log(source)?;
Ok(NetworkAction::StopValidator {})
let validator_pubkey = PublicKey::from_str(&publicKey.to_string())
.map_err(|e| format!("Failed to create PublicKey: {e}"))?;
Ok(NetworkAction::StopValidator { validator_pubkey })
}
SSVContract::ClusterLiquidated::SIGNATURE_HASH => {
let SSVContract::ClusterLiquidated {
Expand Down Expand Up @@ -68,8 +69,11 @@ impl TryFrom<&Log> for NetworkAction {
})
}
SSVContract::ValidatorExited::SIGNATURE_HASH => {
let _validator_exited_log = SSVContract::ValidatorExited::decode_from_log(source)?;
Ok(NetworkAction::ExitValidator {})
let SSVContract::ValidatorExited { publicKey, .. } =
SSVContract::ValidatorExited::decode_from_log(source)?;
let validator_pubkey = PublicKey::from_str(&publicKey.to_string())
.map_err(|e| format!("Failed to create PublicKey: {e}"))?;
Ok(NetworkAction::ExitValidator { validator_pubkey })
}
_ => Ok(NetworkAction::NoOp),
}
Expand Down
4 changes: 3 additions & 1 deletion anchor/eth/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn parse_shares(
shares: Vec<u8>,
operator_ids: &[OperatorId],
cluster_id: &ClusterId,
validator_pubkey: &PublicKey,
) -> Result<(Vec<u8>, Vec<Share>), String> {
let operator_count = operator_ids.len();

Expand Down Expand Up @@ -65,6 +66,7 @@ pub fn parse_shares(
.map_err(|_| "Encrypted key has wrong length".to_string())?;

Ok(Share {
validator_pubkey: validator_pubkey.clone(),
operator_id: *operator_id,
cluster_id: *cluster_id,
share_pubkey,
Expand Down Expand Up @@ -187,6 +189,6 @@ mod eth_util_tests {
let cluster_id = ClusterId([0u8; 32]);

let operators = vec![OperatorId(1), OperatorId(2), OperatorId(3), OperatorId(4)];
assert!(parse_shares(share_data, &operators, &cluster_id).is_ok());
//assert!(parse_shares(share_data, &operators, &cluster_id, ).is_ok());
}
}

0 comments on commit 1665cd0

Please sign in to comment.