MCPcopy Create free account
hub / github.com/ElementsProject/elements / grind_task

Function grind_task

src/bitcoin-util.cpp:85–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85static void grind_task(uint32_t nBits, CBlockHeader& header_orig, uint32_t offset, uint32_t step, std::atomic<bool>& found)
86{
87 arith_uint256 target;
88 bool neg, over;
89 target.SetCompact(nBits, &neg, &over);
90 if (target == 0 || neg || over) return;
91 CBlockHeader header = header_orig; // working copy
92 header.nNonce = offset;
93
94 uint32_t finish = std::numeric_limits<uint32_t>::max() - step;
95 finish = finish - (finish % step) + offset;
96
97 while (!found && header.nNonce < finish) {
98 const uint32_t next = (finish - header.nNonce < 5000*step) ? finish : header.nNonce + 5000*step;
99 do {
100 if (UintToArith256(header.GetHash()) <= target) {
101 if (!found.exchange(true)) {
102 header_orig.nNonce = header.nNonce;
103 }
104 return;
105 }
106 header.nNonce += step;
107 } while(header.nNonce != next);
108 }
109}
110
111static int Grind(const std::vector<std::string>& args, std::string& strPrint)
112{

Callers

nothing calls this directly

Calls 2

UintToArith256Function · 0.85
GetHashMethod · 0.45

Tested by

no test coverage detected