Skip to content

Commit

Permalink
rusk: move node events to own module
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Aug 2, 2024
1 parent 3a7200d commit b131e96
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 46 deletions.
50 changes: 4 additions & 46 deletions rusk/src/lib/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,29 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

mod events;
mod rusk;
mod vm;

use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;

use async_trait::async_trait;
use events::NodeEventStreamer;
use kadcast::config::Config as KadcastConfig;
use node::chain::ChainSrv;
use node::database::rocksdb::{self, Backend};
use node::database::DB;
use node::database::{self, DatabaseOptions};
use node::database::{DatabaseOptions, DB};
use node::databroker::conf::Params as BrokerParam;
use node::databroker::DataBrokerSrv;
use node::mempool::MempoolSrv;
use node::network::Kadcast;
use node::telemetry::TelemetrySrv;
use node::{LongLivedService, Network, Node};
use node_data::events::NodeEvent;
use node::{LongLivedService, Node};
use parking_lot::RwLock;
use rusk_abi::dusk::{dusk, Dusk};
use rusk_abi::VM;
use tokio::sync::mpsc::Receiver;
use tokio::sync::{broadcast, mpsc};
use tracing::info;

use crate::http::{HandleRequest, RuesEvent};

Expand Down Expand Up @@ -232,42 +229,3 @@ pub const fn emission_amount(block_height: u64) -> Dusk {
_ => dusk(0.0),
}
}

pub struct NodeEventStreamer {
node_receiver: Receiver<NodeEvent>,
#[allow(dead_code)]
rues_sender: broadcast::Sender<RuesEvent>,
}

// impl From<NodeEvent> for RuesEvent {
// fn from(value: NodeEvent) -> Self {
// Self {
// headers: serde_json::Map::new(),
// data: RuesEventData::Contract(event),
// }
// }
// }

#[async_trait]
impl<N: Network, DB: database::DB, VM: node::vm::VMExecution>
LongLivedService<N, DB, VM> for NodeEventStreamer
{
async fn execute(
&mut self,
_: Arc<tokio::sync::RwLock<N>>,
_: Arc<tokio::sync::RwLock<DB>>,
_: Arc<tokio::sync::RwLock<VM>>,
) -> anyhow::Result<usize> {
loop {
if let Some(_msg) = self.node_receiver.recv().await {
// self.sender.send()
info!("event received");
}
}
}

/// Returns service name.
fn name(&self) -> &'static str {
"event streamer"
}
}
56 changes: 56 additions & 0 deletions rusk/src/lib/node/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use std::sync::Arc;

use async_trait::async_trait;
use node::database::{self};
use node::{LongLivedService, Network};
use node_data::events::NodeEvent;
use tokio::sync::broadcast;
use tokio::sync::mpsc::Receiver;
use tracing::info;

use crate::http::RuesEvent;

pub(crate) struct NodeEventStreamer {
pub node_receiver: Receiver<NodeEvent>,
#[allow(dead_code)]
pub rues_sender: broadcast::Sender<RuesEvent>,
}

// impl From<NodeEvent> for RuesEvent {
// fn from(value: NodeEvent) -> Self {
// Self {
// headers: serde_json::Map::new(),
// data: RuesEventData::Contract(event),
// }
// }
// }

#[async_trait]
impl<N: Network, DB: database::DB, VM: node::vm::VMExecution>
LongLivedService<N, DB, VM> for NodeEventStreamer
{
async fn execute(
&mut self,
_: Arc<tokio::sync::RwLock<N>>,
_: Arc<tokio::sync::RwLock<DB>>,
_: Arc<tokio::sync::RwLock<VM>>,
) -> anyhow::Result<usize> {
loop {
if let Some(_msg) = self.node_receiver.recv().await {
// self.sender.send()
info!("event received");
}
}
}

/// Returns service name.
fn name(&self) -> &'static str {
"event streamer"
}
}

0 comments on commit b131e96

Please sign in to comment.