From d7c0b582920f036548768b501769e5785cf709db Mon Sep 17 00:00:00 2001 From: s8sato <49983831+s8sato@users.noreply.github.com> Date: Thu, 30 Dec 2021 22:33:46 +0900 Subject: [PATCH] [fix] #1772: Fix after #1764 (#1773) Signed-off-by: s8sato <49983831+s8sato@users.noreply.github.com> --- core/src/lib.rs | 18 ++++++++++-------- core/src/wsv.rs | 19 ++++++++----------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index b0aa02358e5..6ff773a0493 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -197,14 +197,16 @@ where let network_addr = network.start().await; let (events_sender, _) = broadcast::channel(100); - let wsv = Arc::new(WorldStateView::with_events( - Some(events_sender.clone()), - config.wsv, - W::with( - init::domains(&config).wrap_err("Failed to get initial domains")?, - config.sumeragi.trusted_peers.peers.clone(), - ), - )); + let wsv = Arc::new( + WorldStateView::from_configuration( + config.wsv, + W::with( + init::domains(&config).wrap_err("Failed to get initial domains")?, + config.sumeragi.trusted_peers.peers.clone(), + ), + ) + .with_events(events_sender.clone()), + ); let queue = Arc::new(Queue::from_configuration(&config.queue)); let telemetry_started = Self::start_telemetry(telemetry, &config).await?; diff --git a/core/src/wsv.rs b/core/src/wsv.rs index 203c84b6f91..8093e058ba9 100644 --- a/core/src/wsv.rs +++ b/core/src/wsv.rs @@ -75,7 +75,7 @@ pub struct WorldStateView { pub metrics: Arc, /// Notifies subscribers when new block is applied new_block_notifier: Arc, - // TODO Switch to `watch::Sender`, whose original receiver will be passed into `Broker` and cloned for consumers + /// Transmitter to broadcast [`WorldStateView`]-related events. events_sender: Option, } @@ -118,15 +118,6 @@ impl WorldStateView { /// Construct [`WorldStateView`] with specific [`Configuration`]. pub fn from_configuration(config: Configuration, world: W) -> Self { - Self::with_events(None, config, world) - } - - /// Construct [`WorldStateView`] enabling emitting events. - pub fn with_events( - events_sender: Option, - config: Configuration, - world: W, - ) -> Self { let (new_block_notifier, _) = tokio::sync::watch::channel(()); Self { @@ -136,10 +127,16 @@ impl WorldStateView { blocks: Arc::new(Chain::new()), metrics: Arc::new(Metrics::default()), new_block_notifier: Arc::new(new_block_notifier), - events_sender, + events_sender: None, } } + /// Add the ability of emitting events to [`WorldStateView`]. + pub fn with_events(mut self, events_sender: EventsSender) -> Self { + self.events_sender = Some(events_sender); + self + } + /// Initializes WSV with the blocks from block storage. #[iroha_futures::telemetry_future] pub async fn init(&self, blocks: Vec) {