From 1665cd0068ca689c5ee204f8c83e1fd4568ae02b Mon Sep 17 00:00:00 2001 From: Zacholme7 Date: Tue, 24 Dec 2024 16:58:15 +0000 Subject: [PATCH] network action parsing --- anchor/eth/src/event_processor.rs | 2 +- anchor/eth/src/network_actions.rs | 22 +++++++++++++--------- anchor/eth/src/util.rs | 4 +++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/anchor/eth/src/event_processor.rs b/anchor/eth/src/event_processor.rs index 948910d..f4d7fe1 100644 --- a/anchor/eth/src/event_processor.rs +++ b/anchor/eth/src/event_processor.rs @@ -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}") diff --git a/anchor/eth/src/network_actions.rs b/anchor/eth/src/network_actions.rs index 64fa6a4..2af2516 100644 --- a/anchor/eth/src/network_actions.rs +++ b/anchor/eth/src/network_actions.rs @@ -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, @@ -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, } @@ -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 { @@ -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), } diff --git a/anchor/eth/src/util.rs b/anchor/eth/src/util.rs index c2914e1..279de21 100644 --- a/anchor/eth/src/util.rs +++ b/anchor/eth/src/util.rs @@ -20,6 +20,7 @@ pub fn parse_shares( shares: Vec, operator_ids: &[OperatorId], cluster_id: &ClusterId, + validator_pubkey: &PublicKey, ) -> Result<(Vec, Vec), String> { let operator_count = operator_ids.len(); @@ -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, @@ -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()); } }