From 2236b0ba68474e30bae114f97b687756ad219395 Mon Sep 17 00:00:00 2001 From: Bruno Wu Date: Fri, 9 Feb 2024 16:07:07 +0000 Subject: [PATCH] New validator nonce (#430) --- .../bridge/bridge-validators/src/bridge_node.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/products/bridge/bridge-validators/src/bridge_node.rs b/products/bridge/bridge-validators/src/bridge_node.rs index b2a5f775b..ccd569a08 100644 --- a/products/bridge/bridge-validators/src/bridge_node.rs +++ b/products/bridge/bridge-validators/src/bridge_node.rs @@ -28,6 +28,7 @@ use crate::{ #[derive(Debug)] pub struct BridgeNode { event_signatures: HashMap, + relay_nonces: HashSet, outbound_message_sender: UnboundedSender, inbound_message_receiver: UnboundedReceiverStream, inbound_message_sender: UnboundedSender, @@ -53,6 +54,7 @@ impl BridgeNode { inbound_message_receiver, inbound_message_sender, is_leader, + relay_nonces: HashSet::new(), }; bridge_node.update_validators().await?; @@ -199,7 +201,15 @@ impl BridgeNode { Ok(()) } - fn handle_relay_event(&self, event: RelayedFilter) -> Result<()> { + fn handle_relay_event(&mut self, event: RelayedFilter) -> Result<()> { + if self.relay_nonces.contains(&event.nonce) { + info!( + "Chain: {} event duplicated {}", + self.chain_client.chain_id, event + ); + return Ok(()); + } + info!( "Chain: {} event found to be broadcasted: {}", self.chain_client.chain_id, event @@ -215,6 +225,8 @@ impl BridgeNode { let relay_event = RelayEvent::from(event, self.chain_client.chain_id); + self.relay_nonces.insert(relay_event.nonce); + self.broadcast_message(Relay { signature: relay_event.sign(&self.chain_client.wallet)?, event: relay_event,