Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit f30497f

Browse files
authored
Fix locking in OnDemandOrderingGate (#2088)
Signed-off-by: Andrei Lebedev <[email protected]>
1 parent 69e4a32 commit f30497f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

irohad/ordering/impl/on_demand_ordering_gate.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,29 @@ OnDemandOrderingGate::OnDemandOrderingGate(
3131
network_client_(std::move(network_client)),
3232
events_subscription_(events.subscribe([this](auto event) {
3333
// exclusive lock
34-
std::lock_guard<std::shared_timed_mutex> lock(mutex_);
35-
34+
std::unique_lock<std::shared_timed_mutex> lock(mutex_);
3635
visit_in_place(event,
3736
[this](const BlockEvent &block_event) {
3837
// block committed, increment block round
3938
log_->debug("BlockEvent. {}", block_event.round);
4039
current_round_ = block_event.round;
41-
cache_->remove(block_event.hashes);
4240
},
4341
[this](const EmptyEvent &empty_event) {
4442
// no blocks committed, increment reject round
4543
log_->debug("EmptyEvent");
4644
current_round_ = empty_event.round;
4745
});
4846
log_->debug("Current: {}", current_round_);
47+
lock.unlock();
48+
49+
visit_in_place(event,
50+
[this](const BlockEvent &block_event) {
51+
// block committed, remove transactions from cache
52+
cache_->remove(block_event.hashes);
53+
},
54+
[this](const EmptyEvent &) {
55+
// no blocks committed, no transactions to remove
56+
});
4957

5058
auto batches = cache_->pop();
5159

@@ -78,9 +86,9 @@ OnDemandOrderingGate::~OnDemandOrderingGate() {
7886

7987
void OnDemandOrderingGate::propagateBatch(
8088
std::shared_ptr<shared_model::interface::TransactionBatch> batch) {
81-
std::shared_lock<std::shared_timed_mutex> lock(mutex_);
82-
8389
cache_->addToBack({batch});
90+
91+
std::shared_lock<std::shared_timed_mutex> lock(mutex_);
8492
network_client_->onBatches(
8593
current_round_, transport::OdOsNotification::CollectionType{batch});
8694
}

0 commit comments

Comments
 (0)