Skip to content

Commit

Permalink
[fix] #1772: Fix after #1764 (#1773)
Browse files Browse the repository at this point in the history
Signed-off-by: s8sato <49983831+s8sato@users.noreply.github.com>
  • Loading branch information
s8sato authored Dec 30, 2021
1 parent 14d1caf commit d7c0b58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
18 changes: 10 additions & 8 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
19 changes: 8 additions & 11 deletions core/src/wsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct WorldStateView<W: WorldTrait> {
pub metrics: Arc<Metrics>,
/// Notifies subscribers when new block is applied
new_block_notifier: Arc<NewBlockNotificationSender>,
// 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<EventsSender>,
}

Expand Down Expand Up @@ -118,15 +118,6 @@ impl<W: WorldTrait> WorldStateView<W> {

/// 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<EventsSender>,
config: Configuration,
world: W,
) -> Self {
let (new_block_notifier, _) = tokio::sync::watch::channel(());

Self {
Expand All @@ -136,10 +127,16 @@ impl<W: WorldTrait> WorldStateView<W> {
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<VersionedCommittedBlock>) {
Expand Down

0 comments on commit d7c0b58

Please sign in to comment.