Commit 973a7b5 1 parent d91e3df commit 973a7b5 Copy full SHA for 973a7b5
File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,10 @@ namespace cbdc::shard {
144
144
break ;
145
145
}
146
146
147
+ if (blk.m_height <= m_shard.best_block_height ()) {
148
+ break ;
149
+ }
150
+
147
151
// Attempt to catch up to the latest block
148
152
for (uint64_t i = m_shard.best_block_height () + 1 ; i < blk.m_height ;
149
153
i++) {
@@ -227,10 +231,22 @@ namespace cbdc::shard {
227
231
return ;
228
232
}
229
233
234
+ auto status = m_audit_fut.wait_for (std::chrono::seconds (0 ));
235
+ if (status != std::future_status::ready && m_audit_thread.joinable ()) {
236
+ m_logger->warn (
237
+ " Previous audit not finished, skipping audit for h:" ,
238
+ height);
239
+ return ;
240
+ }
241
+
230
242
auto snp = m_shard.get_snapshot ();
231
243
if (m_audit_thread.joinable ()) {
232
- m_audit_thread.join ();
244
+ m_audit_thread.join (); // blocking here
233
245
}
246
+
247
+ m_audit_finished = decltype (m_audit_finished)();
248
+ m_audit_fut = m_audit_finished.get_future ();
249
+
234
250
m_audit_thread = std::thread ([this , s = std::move (snp), height]() {
235
251
auto maybe_total = m_shard.audit (s);
236
252
if (!maybe_total.has_value ()) {
@@ -241,6 +257,7 @@ namespace cbdc::shard {
241
257
height,
242
258
maybe_total.value (),
243
259
" coins total" );
260
+ m_audit_finished.set_value ();
244
261
});
245
262
}
246
263
}
Original file line number Diff line number Diff line change 12
12
#include " util/common/config.hpp"
13
13
#include " util/network/connection_manager.hpp"
14
14
15
+ #include < future>
15
16
#include < memory>
16
17
#include < secp256k1.h>
17
18
@@ -62,6 +63,8 @@ namespace cbdc::shard {
62
63
63
64
std::ofstream m_audit_log;
64
65
std::thread m_audit_thread;
66
+ std::promise<void > m_audit_finished;
67
+ std::future<void > m_audit_fut{m_audit_finished.get_future ()};
65
68
66
69
auto server_handler (cbdc::network::message_t && pkt)
67
70
-> std::optional<cbdc::buffer>;
You can’t perform that action at this time.
0 commit comments