Skip to content

Commit

Permalink
Don't wait on previous audit in atomizer shard
Browse files Browse the repository at this point in the history
Do not skip audit if there was no previous audit running

Signed-off-by: James Lovejoy <[email protected]>
  • Loading branch information
metalicjames authored and HalosGhost committed Jun 9, 2023
1 parent d91e3df commit 973a7b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/uhs/atomizer/shard/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ namespace cbdc::shard {
break;
}

if(blk.m_height <= m_shard.best_block_height()) {
break;
}

// Attempt to catch up to the latest block
for(uint64_t i = m_shard.best_block_height() + 1; i < blk.m_height;
i++) {
Expand Down Expand Up @@ -227,10 +231,22 @@ namespace cbdc::shard {
return;
}

auto status = m_audit_fut.wait_for(std::chrono::seconds(0));
if(status != std::future_status::ready && m_audit_thread.joinable()) {
m_logger->warn(
"Previous audit not finished, skipping audit for h:",
height);
return;
}

auto snp = m_shard.get_snapshot();
if(m_audit_thread.joinable()) {
m_audit_thread.join();
m_audit_thread.join(); // blocking here
}

m_audit_finished = decltype(m_audit_finished)();
m_audit_fut = m_audit_finished.get_future();

m_audit_thread = std::thread([this, s = std::move(snp), height]() {
auto maybe_total = m_shard.audit(s);
if(!maybe_total.has_value()) {
Expand All @@ -241,6 +257,7 @@ namespace cbdc::shard {
height,
maybe_total.value(),
"coins total");
m_audit_finished.set_value();
});
}
}
3 changes: 3 additions & 0 deletions src/uhs/atomizer/shard/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "util/common/config.hpp"
#include "util/network/connection_manager.hpp"

#include <future>
#include <memory>
#include <secp256k1.h>

Expand Down Expand Up @@ -62,6 +63,8 @@ namespace cbdc::shard {

std::ofstream m_audit_log;
std::thread m_audit_thread;
std::promise<void> m_audit_finished;
std::future<void> m_audit_fut{m_audit_finished.get_future()};

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

0 comments on commit 973a7b5

Please sign in to comment.