diff --git a/node-data/src/events.rs b/node-data/src/events.rs index a02cb430c0..de86891339 100644 --- a/node-data/src/events.rs +++ b/node-data/src/events.rs @@ -11,27 +11,27 @@ pub use blocks::BlockEvent; pub use transactions::TransactionEvent; #[derive(Clone, Debug)] -pub struct NodeEvent { - pub target: String, - pub topic: String, +pub struct Event { + pub target: &'static str, + pub topic: &'static str, pub id: String, - pub data: String, + pub data: Option, } -pub trait NodeEventSource { +pub trait EventSource { fn target(&self) -> &'static str; fn topic(&self) -> &'static str; fn id(&self) -> String; - fn data(&self) -> String; + fn data(&self) -> Option; } -impl From for NodeEvent { +impl From for Event { fn from(value: B) -> Self { Self { data: value.data(), - topic: value.topic().into(), + topic: value.topic(), id: value.id(), - target: value.target().into(), + target: value.target(), } } } diff --git a/node-data/src/events/blocks.rs b/node-data/src/events/blocks.rs index 9aca2838db..b9a6f53eca 100644 --- a/node-data/src/events/blocks.rs +++ b/node-data/src/events/blocks.rs @@ -7,7 +7,7 @@ use super::*; use crate::ledger::{Block, Hash}; -impl NodeEventSource for BlockEvent<'_> { +impl EventSource for BlockEvent<'_> { fn target(&self) -> &'static str { "blocks" } @@ -17,15 +17,15 @@ impl NodeEventSource for BlockEvent<'_> { Self::StateChange { .. } => "state_change", } } - fn data(&self) -> String { + fn data(&self) -> Option { match self { - Self::Accepted(_) => String::new(), - Self::StateChange { state, height, .. } => format!( + Self::Accepted(_) => None, + Self::StateChange { state, height, .. } => Some(format!( r#"{{ "state": "{state}", "atHeight": {height} }}"#, - ), + )), } } fn id(&self) -> String { diff --git a/node-data/src/events/transactions.rs b/node-data/src/events/transactions.rs index 014e715ae2..db12d2c7b2 100644 --- a/node-data/src/events/transactions.rs +++ b/node-data/src/events/transactions.rs @@ -14,7 +14,7 @@ pub enum TransactionEvent<'t> { Executed(&'t SpentTransaction), } -impl NodeEventSource for TransactionEvent<'_> { +impl EventSource for TransactionEvent<'_> { fn target(&self) -> &'static str { "transactions" } @@ -25,8 +25,8 @@ impl NodeEventSource for TransactionEvent<'_> { Self::Included(_) => "included", } } - fn data(&self) -> String { - String::new() + fn data(&self) -> Option { + None } fn id(&self) -> String { let hash = match self { diff --git a/node/src/chain.rs b/node/src/chain.rs index 5171aab605..b6c7b4c56f 100644 --- a/node/src/chain.rs +++ b/node/src/chain.rs @@ -23,7 +23,7 @@ use anyhow::Result; use async_trait::async_trait; use dusk_consensus::commons::ConsensusError; pub use header_validation::verify_att; -use node_data::events::NodeEvent; +use node_data::events::Event; use node_data::ledger::{to_str, BlockWithLabel, Label}; use node_data::message::AsyncQueue; use node_data::message::{Payload, Topics}; @@ -53,7 +53,7 @@ pub struct ChainSrv { keys_path: String, acceptor: Option>>>, max_consensus_queue_size: usize, - event_sender: Sender, + event_sender: Sender, } #[async_trait] @@ -242,7 +242,11 @@ impl } impl ChainSrv { - pub fn new(keys_path: String, max_inbound_size: usize, event_sender: Sender) -> Self { + pub fn new( + keys_path: String, + max_inbound_size: usize, + event_sender: Sender, + ) -> Self { info!( "ChainSrv::new with keys_path: {}, max_inbound_size: {}", keys_path, max_inbound_size diff --git a/node/src/chain/acceptor.rs b/node/src/chain/acceptor.rs index aeabfc931b..12c1c0ad5c 100644 --- a/node/src/chain/acceptor.rs +++ b/node/src/chain/acceptor.rs @@ -11,7 +11,7 @@ use dusk_consensus::commons::{ConsensusError, TimeoutSet}; use dusk_consensus::config::{MAX_STEP_TIMEOUT, MIN_STEP_TIMEOUT}; use dusk_consensus::user::provisioners::{ContextProvisioners, Provisioners}; use node_data::bls::PublicKey; -use node_data::events::{BlockEvent, NodeEvent, TransactionEvent}; +use node_data::events::{BlockEvent, Event, TransactionEvent}; use node_data::ledger::{ self, to_str, Block, BlockWithLabel, Label, Seed, Slash, SpentTransaction, }; @@ -70,7 +70,7 @@ pub(crate) struct Acceptor { pub(crate) vm: Arc>, network: Arc>, - event_sender: Sender, + event_sender: Sender, } impl Drop @@ -131,7 +131,7 @@ impl Acceptor { network: Arc>, vm: Arc>, max_queue_size: usize, - event_sender: Sender, + event_sender: Sender, ) -> anyhow::Result { let tip_height = tip.inner().header().height; let tip_state_hash = tip.inner().header().state_hash; @@ -646,7 +646,7 @@ impl Acceptor { pni: u8, blk: &Block, db: &D::P<'_>, - events: &mut Vec, + events: &mut Vec, ) -> Result<(Label, Option)> { let confirmed_after = match pni { 0 => 1u64, diff --git a/node/src/mempool.rs b/node/src/mempool.rs index a002d7cd18..74b6d9da49 100644 --- a/node/src/mempool.rs +++ b/node/src/mempool.rs @@ -10,7 +10,7 @@ use crate::database::{Ledger, Mempool}; use crate::mempool::conf::Params; use crate::{database, vm, LongLivedService, Message, Network}; use async_trait::async_trait; -use node_data::events::{NodeEvent, TransactionEvent}; +use node_data::events::{Event, TransactionEvent}; use node_data::ledger::Transaction; use node_data::message::{AsyncQueue, Payload, Topics}; use std::sync::Arc; @@ -43,11 +43,11 @@ impl From for TxAcceptanceError { pub struct MempoolSrv { inbound: AsyncQueue, - event_sender: Sender, + event_sender: Sender, } impl MempoolSrv { - pub fn new(conf: Params, event_sender: Sender) -> Self { + pub fn new(conf: Params, event_sender: Sender) -> Self { info!("MempoolSrv::new with conf {}", conf); Self { inbound: AsyncQueue::bounded( diff --git a/rusk/src/lib/http/event.rs b/rusk/src/lib/http/event.rs index 562b7c6183..d992dc36ff 100644 --- a/rusk/src/lib/http/event.rs +++ b/rusk/src/lib/http/event.rs @@ -835,8 +835,8 @@ impl From for RuesEvent { } #[cfg(feature = "node")] -impl From for RuesEvent { - fn from(value: node_data::events::NodeEvent) -> Self { +impl From for RuesEvent { + fn from(value: node_data::events::Event) -> Self { let mut headers = serde_json::Map::new(); headers.insert( "Content-Location".into(), @@ -845,7 +845,7 @@ impl From for RuesEvent { Self { headers: serde_json::Map::new(), - data: RuesEventData::Other(value.data.into()), + data: RuesEventData::Other(value.data.unwrap_or_default().into()), } } } diff --git a/rusk/src/lib/node/events.rs b/rusk/src/lib/node/events.rs index 2e724eaf6e..232420bebd 100644 --- a/rusk/src/lib/node/events.rs +++ b/rusk/src/lib/node/events.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use async_trait::async_trait; use node::database::{self}; use node::{LongLivedService, Network}; -use node_data::events::NodeEvent; +use node_data::events::Event as ChainEvent; use tokio::sync::broadcast; use tokio::sync::mpsc::Receiver; use tracing::error; @@ -17,7 +17,7 @@ use tracing::error; use crate::http::RuesEvent; pub(crate) struct NodeEventStreamer { - pub node_receiver: Receiver, + pub node_receiver: Receiver, #[allow(dead_code)] pub rues_sender: broadcast::Sender, }