diff --git a/src/blockchain_utilities/CMakeLists.txt b/src/blockchain_utilities/CMakeLists.txt index a89b64de9..ab7130277 100644 --- a/src/blockchain_utilities/CMakeLists.txt +++ b/src/blockchain_utilities/CMakeLists.txt @@ -145,9 +145,12 @@ monero_private_headers(blockchain_scanner if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/blockchain_audit.cpp" AND NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/blockchain_audit.cpp") set(blockchain_audit_sources blockchain_audit.cpp + threadpool_boost.cpp ) - set(blockchain_audit_private_headers) + set(blockchain_audit_private_headers + threadpool_boost.h + ) monero_private_headers(blockchain_audit ${blockchain_audit_private_headers}) @@ -329,6 +332,8 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/blockchain_audit.cpp" AND NOT IS_DIRECTO ${blockchain_audit_sources} ${blockchain_audit_private_headers}) + target_include_directories(blockchain_audit PRIVATE /usr/include/mysql-cppconn/jdbc) + target_link_libraries(blockchain_audit PRIVATE wallet @@ -338,6 +343,7 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/blockchain_audit.cpp" AND NOT IS_DIRECTO blockchain_db version epee + mysqlcppconn ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} diff --git a/src/blockchain_utilities/threadpool_boost.cpp b/src/blockchain_utilities/threadpool_boost.cpp new file mode 100644 index 000000000..264d1d97a --- /dev/null +++ b/src/blockchain_utilities/threadpool_boost.cpp @@ -0,0 +1,44 @@ +#include +#include "threadpool_boost.h" + +ThreadPool::ThreadPool(size_t numThreads) + : workGuard(boost::asio::make_work_guard(ioService)) { + for (size_t i = 0; i < numThreads; ++i) { + workers.emplace_back([this]() { + std::cerr << "Thread started" << std::endl; + ioService.run(); + std::cerr << "Thread finished" << std::endl; + }); + } +} + +void ThreadPool::enqueue(std::function task) { + ioService.post([task]() { + try { + task(); // Run the task + } catch (const std::exception& e) { + std::cerr << "Exception in thread pool task: " << e.what() << std::endl; + } catch (...) { + std::cerr << "Unknown exception in thread pool task!" << std::endl; + } + }); +} + +bool ThreadPool::isStopping() const { + return ioService.stopped(); // Check if io_context has stopped +} + +void ThreadPool::waitForCompletion() { + std::cout << "Waiting for completion...\n"; + workGuard.reset(); // Allow ioService to stop when no more tasks + ioService.run(); // Ensure no threads are left hanging + + for (auto &worker : workers) { + if (worker.joinable()) worker.join(); + } + std::cout << "All threads joined.\n"; +} + +ThreadPool::~ThreadPool() { + waitForCompletion(); +} diff --git a/src/blockchain_utilities/threadpool_boost.h b/src/blockchain_utilities/threadpool_boost.h new file mode 100644 index 000000000..bbcc01704 --- /dev/null +++ b/src/blockchain_utilities/threadpool_boost.h @@ -0,0 +1,24 @@ +#ifndef THREADPOOL_BOOST_H +#define THREADPOOL_BOOST_H + +#include +#include +#include +#include + +class ThreadPool { +public: + explicit ThreadPool(size_t numThreads); + ~ThreadPool(); + + void enqueue(std::function task); + bool isStopping() const; + void waitForCompletion(); + +private: + boost::asio::io_service ioService; + boost::asio::executor_work_guard workGuard; + std::vector workers; +}; + +#endif // THREADPOOL_BOOST_H diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 52db3fb8e..f37af7261 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1550,10 +1550,13 @@ bool Blockchain::validate_protocol_transaction(const block& b, uint64_t height, } // if nothing is created by this TX - check no money is included - size_t vout_size = b.protocol_tx.vout.size(); CHECK_AND_ASSERT_MES(b.protocol_tx.vin.size() == 1, false, "coinbase protocol transaction in the block has no inputs"); - CHECK_AND_ASSERT_MES(vout_size != 0, true, "coinbase protocol transaction in the block has no outputs"); - + size_t vout_size = b.protocol_tx.vout.size(); + if (vout_size == 0) { + LOG_PRINT_L2("coinbase protocol transaction in the block has no outputs"); + return true; + } + // Can we have matured STAKE transactions yet? uint64_t stake_lock_period = get_config(m_nettype).STAKE_LOCK_PERIOD; if (height <= stake_lock_period) {