// Copyright (c) 2026 The MoonBite Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_CRYPTO_RANDOMX_MINER_H #define BITCOIN_CRYPTO_RANDOMX_MINER_H #include #include // MoonBite (ADR-001): fast-mode, multithreaded RandomX nonce search used by the // built-in miner (generatetoaddress / generatetodescriptor). Unlike the // validation path in randomx_hasher (single shared light-mode VM, ~256 MB), this // builds the full ~2 GB dataset once and gives each worker thread its own VM, so // throughput scales with cores instead of serialising on a mutex. // // The produced hash is identical to the validation path (RandomX output is // independent of light vs fast mode), so any nonce found here also satisfies the // consensus CheckProofOfWork() the node applies before accepting the block. // // Searches nonces in [nonceStart, nonceStart + count) across nThreads. header80 // is the 80-byte serialised block header (its nNonce field at offset 76 is // overwritten per trial; the caller's buffer is not modified). target32 is the // 32-byte little-endian PoW target derived from nBits. On success sets // foundNonce and returns true; returns false if the range is exhausted, the // dataset could not be allocated, or should_stop asked the search to end. // // should_stop, when set, is polled from the calling thread every ~50 ms while // the workers hash; returning true ends the search early (used to abandon a // template whose parent is no longer the chain tip). hashes_done, when set, // receives the number of nonces actually tried. Each call has its own search // state, so concurrent calls do not interfere. bool RandomXMineHeader(const unsigned char header80[80], const unsigned char target32[32], uint32_t nonceStart, uint64_t count, int nThreads, uint32_t& foundNonce, const std::function& should_stop = nullptr, uint64_t* hashes_done = nullptr); #endif // BITCOIN_CRYPTO_RANDOMX_MINER_H