Skip to content

Commit 973a7b5

Browse files
metalicjamesHalosGhost
authored andcommitted
Don't wait on previous audit in atomizer shard
Do not skip audit if there was no previous audit running Signed-off-by: James Lovejoy <[email protected]>
1 parent d91e3df commit 973a7b5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/uhs/atomizer/shard/controller.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ namespace cbdc::shard {
144144
break;
145145
}
146146

147+
if(blk.m_height <= m_shard.best_block_height()) {
148+
break;
149+
}
150+
147151
// Attempt to catch up to the latest block
148152
for(uint64_t i = m_shard.best_block_height() + 1; i < blk.m_height;
149153
i++) {
@@ -227,10 +231,22 @@ namespace cbdc::shard {
227231
return;
228232
}
229233

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+
230242
auto snp = m_shard.get_snapshot();
231243
if(m_audit_thread.joinable()) {
232-
m_audit_thread.join();
244+
m_audit_thread.join(); // blocking here
233245
}
246+
247+
m_audit_finished = decltype(m_audit_finished)();
248+
m_audit_fut = m_audit_finished.get_future();
249+
234250
m_audit_thread = std::thread([this, s = std::move(snp), height]() {
235251
auto maybe_total = m_shard.audit(s);
236252
if(!maybe_total.has_value()) {
@@ -241,6 +257,7 @@ namespace cbdc::shard {
241257
height,
242258
maybe_total.value(),
243259
"coins total");
260+
m_audit_finished.set_value();
244261
});
245262
}
246263
}

src/uhs/atomizer/shard/controller.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "util/common/config.hpp"
1313
#include "util/network/connection_manager.hpp"
1414

15+
#include <future>
1516
#include <memory>
1617
#include <secp256k1.h>
1718

@@ -62,6 +63,8 @@ namespace cbdc::shard {
6263

6364
std::ofstream m_audit_log;
6465
std::thread m_audit_thread;
66+
std::promise<void> m_audit_finished;
67+
std::future<void> m_audit_fut{m_audit_finished.get_future()};
6568

6669
auto server_handler(cbdc::network::message_t&& pkt)
6770
-> std::optional<cbdc::buffer>;

0 commit comments

Comments
 (0)