@@ -31,21 +31,29 @@ OnDemandOrderingGate::OnDemandOrderingGate(
31
31
network_client_(std::move(network_client)),
32
32
events_subscription_(events.subscribe([this ](auto event) {
33
33
// exclusive lock
34
- std::lock_guard<std::shared_timed_mutex> lock (mutex_);
35
-
34
+ std::unique_lock<std::shared_timed_mutex> lock (mutex_);
36
35
visit_in_place (event,
37
36
[this ](const BlockEvent &block_event) {
38
37
// block committed, increment block round
39
38
log_->debug (" BlockEvent. {}" , block_event.round );
40
39
current_round_ = block_event.round ;
41
- cache_->remove (block_event.hashes );
42
40
},
43
41
[this ](const EmptyEvent &empty_event) {
44
42
// no blocks committed, increment reject round
45
43
log_->debug (" EmptyEvent" );
46
44
current_round_ = empty_event.round ;
47
45
});
48
46
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
+ });
49
57
50
58
auto batches = cache_->pop ();
51
59
@@ -78,9 +86,9 @@ OnDemandOrderingGate::~OnDemandOrderingGate() {
78
86
79
87
void OnDemandOrderingGate::propagateBatch (
80
88
std::shared_ptr<shared_model::interface::TransactionBatch> batch) {
81
- std::shared_lock<std::shared_timed_mutex> lock (mutex_);
82
-
83
89
cache_->addToBack ({batch});
90
+
91
+ std::shared_lock<std::shared_timed_mutex> lock (mutex_);
84
92
network_client_->onBatches (
85
93
current_round_, transport::OdOsNotification::CollectionType{batch});
86
94
}
0 commit comments