Skip to content

Commit

Permalink
Remove uuid from rpc module + remove unecessary clone
Browse files Browse the repository at this point in the history
  • Loading branch information
adonagy committed Sep 29, 2021
1 parent 2b7d21e commit 97403bf
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ url = "2.2"
rusqlite = "0.25.1"
cached = "0.23"
bincode = "1.3"
uuid = { git = "https://github.com/tezedge/uuid", tag = "v0.8.2-cleanup-unsafe-1", default-features = false, features = ["v4"] }
# local dependencies
crypto = { path = "../crypto" }
# TODO: once full integration is done, remove shell dependency from here
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub struct RpcCollectedState {
}

impl StreamCounter for RpcCollectedState {
fn get_streams(&self) -> StreamWakers {
self.streams.clone()
fn get_streams(&self) -> &StreamWakers {
&self.streams
}

fn get_mutable_streams(&mut self) -> &mut StreamWakers {
Expand Down
11 changes: 5 additions & 6 deletions rpc/src/services/stream_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ use serde_json::Value;
use slog::{error, Logger};
use tezos_api::ffi::{Applied, Errored};
use tezos_messages::p2p::encoding::operation::Operation;
use uuid::Uuid;

use crypto::hash::{BlockHash, ChainId, OperationHash, ProtocolHash};
use shell::mempool::CurrentMempoolStateStorageRef;
use shell_integration::StreamCounter;
use shell_integration::{generate_stream_id, StreamCounter, StreamId};
use storage::{BlockHeaderWithHash, BlockMetaStorage, BlockMetaStorageReader, PersistentStorage};
use tezos_messages::{ts_to_rfc3339, TimestampOutOfRangeError};

Expand Down Expand Up @@ -176,7 +175,7 @@ pub struct HeadMonitorStream {
last_checked_head: Option<BlockHash>,
protocol: Option<ProtocolHash>,
contains_waker: bool,
stream_id: Uuid,
stream_id: StreamId,
log: Logger,
}

Expand All @@ -187,7 +186,7 @@ pub struct OperationMonitorStream {
last_checked_head: BlockHash,
log: Logger,
contains_waker: bool,
stream_id: Uuid,
stream_id: StreamId,
streamed_operations: HashSet<String>,
query: MempoolOperationsQuery,
poll_counter: usize,
Expand All @@ -202,7 +201,7 @@ impl OperationMonitorStream {
last_checked_head: BlockHash,
mempool_operaions_query: MempoolOperationsQuery,
) -> Self {
let stream_id = Uuid::new_v4();
let stream_id: StreamId = generate_stream_id();
Self {
_chain_id,
current_mempool_state_storage,
Expand Down Expand Up @@ -306,7 +305,7 @@ impl HeadMonitorStream {
persistent_storage: &PersistentStorage,
log: Logger,
) -> Self {
let stream_id = Uuid::new_v4();
let stream_id = generate_stream_id();
Self {
state,
protocol,
Expand Down
7 changes: 6 additions & 1 deletion shell-integration/src/streaming_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use futures::task::Waker;
use uuid::Uuid;

pub type StreamWakers = HashMap<Uuid, Waker>;
pub type StreamId = Uuid;

pub trait StreamCounter {
fn get_mutable_streams(&mut self) -> &mut StreamWakers;
fn get_streams(&self) -> StreamWakers;
fn get_streams(&self) -> &StreamWakers;

fn add_stream(&mut self, id: Uuid, waker: Waker) {
let streams = self.get_mutable_streams();
Expand All @@ -28,3 +29,7 @@ pub trait StreamCounter {
streams.iter().for_each(|(_, waker)| waker.wake_by_ref())
}
}

pub fn generate_stream_id() -> StreamId {
Uuid::new_v4()
}
4 changes: 2 additions & 2 deletions shell/src/mempool/mempool_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub struct MempoolState {
}

impl StreamCounter for MempoolState {
fn get_streams(&self) -> StreamWakers {
self.streams.clone()
fn get_streams(&self) -> &StreamWakers {
&self.streams
}

fn get_mutable_streams(&mut self) -> &mut StreamWakers {
Expand Down

0 comments on commit 97403bf

Please sign in to comment.