Skip to content

Commit 75da907

Browse files
Erigaraappetrosyan
authored andcommitted
[refactor] #2307: Make events_sender in WorldStateView non-optional (#2417)
Signed-off-by: Shanin Roman <[email protected]>
1 parent 7c2755d commit 75da907

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

cli/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ where
177177
domains(&config),
178178
config.sumeragi.trusted_peers.peers.clone(),
179179
);
180-
let wsv = Arc::new(
181-
WorldStateView::from_configuration(config.wsv, world)
182-
.with_events(events_sender.clone()),
183-
);
180+
let wsv = Arc::new(WorldStateView::from_configuration(
181+
config.wsv,
182+
world,
183+
events_sender.clone(),
184+
));
184185

185186
let query_validator = Arc::new(query_validator);
186187

core/src/wsv.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use iroha_crypto::HashOf;
1414
use iroha_data_model::{prelude::*, small::SmallVec};
1515
use iroha_logger::prelude::*;
1616
use iroha_telemetry::metrics::Metrics;
17-
use tokio::task;
17+
use tokio::{sync::broadcast, task};
1818

1919
use crate::{
2020
block::Chain,
@@ -86,7 +86,7 @@ pub struct WorldStateView {
8686
/// Notifies subscribers when new block is applied
8787
new_block_notifier: Arc<NewBlockNotificationSender>,
8888
/// Transmitter to broadcast [`WorldStateView`]-related events.
89-
events_sender: Option<EventsSender>,
89+
events_sender: EventsSender,
9090
}
9191

9292
impl Default for WorldStateView {
@@ -117,14 +117,9 @@ impl WorldStateView {
117117
#[must_use]
118118
#[inline]
119119
pub fn new(world: World) -> Self {
120-
Self::from_configuration(Configuration::default(), world)
121-
}
122-
123-
/// Add the ability of emitting events to [`WorldStateView`].
124-
#[must_use]
125-
pub fn with_events(mut self, events_sender: EventsSender) -> Self {
126-
self.events_sender = Some(events_sender);
127-
self
120+
// Added to remain backward compatible with other code primary in tests
121+
let (events_sender, _) = broadcast::channel(1);
122+
Self::from_configuration(Configuration::default(), world, events_sender)
128123
}
129124

130125
/// Get `Account`'s `Asset`s
@@ -277,14 +272,7 @@ impl WorldStateView {
277272

278273
/// Send [`Event`]s to known subscribers.
279274
fn produce_event(&self, event: impl Into<Event>) {
280-
self.events_sender.as_ref().map_or_else(
281-
|| {
282-
warn!("wsv does not equip an events sender");
283-
},
284-
|events_sender| {
285-
drop(events_sender.send(event.into()));
286-
},
287-
)
275+
let _result = self.events_sender.send(event.into());
288276
}
289277

290278
/// Tries to get asset or inserts new with `default_asset_value`.
@@ -497,7 +485,11 @@ impl WorldStateView {
497485

498486
/// Construct [`WorldStateView`] with specific [`Configuration`].
499487
#[inline]
500-
pub fn from_configuration(config: Configuration, world: World) -> Self {
488+
pub fn from_configuration(
489+
config: Configuration,
490+
world: World,
491+
events_sender: EventsSender,
492+
) -> Self {
501493
let (new_block_notifier, _) = tokio::sync::watch::channel(());
502494

503495
Self {
@@ -507,7 +499,7 @@ impl WorldStateView {
507499
blocks: Arc::new(Chain::new()),
508500
metrics: Arc::new(Metrics::default()),
509501
new_block_notifier: Arc::new(new_block_notifier),
510-
events_sender: None,
502+
events_sender,
511503
}
512504
}
513505

0 commit comments

Comments
 (0)