Skip to content

Commit 9141cc2

Browse files
committed
Use filter-map instead of flat_map
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
1 parent dbd5f97 commit 9141cc2

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

irohad/main/impl/on_demand_ordering_init.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,27 +236,33 @@ namespace iroha {
236236
}),
237237
sync_event_notifier.get_observable()
238238
.tap([this](const synchronizer::SynchronizationEvent &event) {
239-
last_received_round_ = event.round;
239+
if (not last_received_round_
240+
or *last_received_round_ < event.round) {
241+
last_received_round_ = event.round;
242+
} else {
243+
log_->debug("Dropping {}, since {} is already processed",
244+
event.round,
245+
*last_received_round_);
246+
}
240247
})
241248
.lift<iroha::synchronizer::SynchronizationEvent>(
242249
iroha::makeDelay<iroha::synchronizer::SynchronizationEvent>(
243250
delay_func, rxcpp::identity_current_thread()))
244-
.flat_map([this](const auto &event) mutable
245-
-> rxcpp::observable<
246-
ordering::OnDemandOrderingGate::RoundSwitch> {
251+
.filter([this](const auto &event) {
247252
assert(last_received_round_);
248253
if (not last_received_round_) {
249254
log_->error("Cannot continue without last received round");
250-
return rxcpp::observable<>::empty<
251-
ordering::OnDemandOrderingGate::RoundSwitch>();
255+
return false;
252256
}
253257
if (event.round < *last_received_round_) {
254258
log_->debug("Dropping {}, since {} is already processed",
255259
event.round,
256260
*last_received_round_);
257-
return rxcpp::observable<>::empty<
258-
ordering::OnDemandOrderingGate::RoundSwitch>();
261+
return false;
259262
}
263+
return true;
264+
})
265+
.map([this](const auto &event) {
260266
consensus::Round current_round;
261267
switch (event.sync_outcome) {
262268
case iroha::synchronizer::SynchronizationOutcomeType::kCommit:
@@ -282,9 +288,8 @@ namespace iroha {
282288
log_->error("unknown SynchronizationOutcomeType");
283289
assert(false);
284290
}
285-
return rxcpp::observable<>::just(
286-
ordering::OnDemandOrderingGate::RoundSwitch{
287-
std::move(current_round), event.ledger_state});
291+
return ordering::OnDemandOrderingGate::RoundSwitch{
292+
std::move(current_round), event.ledger_state};
288293
}),
289294
std::move(cache),
290295
std::move(proposal_factory),

0 commit comments

Comments
 (0)