Branch data Line data Source code
1 : : // Copyright (c) 2010 Satoshi Nakamoto
2 : : // Copyright (c) 2009-present The Bitcoin Core developers
3 : : // Distributed under the MIT software license, see the accompanying
4 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 : :
6 : : #include <bitcoin-build-config.h> // IWYU pragma: keep
7 : :
8 : : #include <chain.h>
9 : : #include <chainparams.h>
10 : : #include <chainparamsbase.h>
11 : : #include <common/system.h>
12 : : #include <consensus/amount.h>
13 : : #include <consensus/consensus.h>
14 : : #include <consensus/merkle.h>
15 : : #include <consensus/params.h>
16 : : #include <consensus/validation.h>
17 : : #include <core_io.h>
18 : : #include <deploymentinfo.h>
19 : : #include <deploymentstatus.h>
20 : : #include <interfaces/mining.h>
21 : : #include <key_io.h>
22 : : #include <net.h>
23 : : #include <node/context.h>
24 : : #include <node/miner.h>
25 : : #include <node/warnings.h>
26 : : #include <policy/ephemeral_policy.h>
27 : : #include <pow.h>
28 : : #include <rpc/blockchain.h>
29 : : #include <rpc/mining.h>
30 : : #include <rpc/server.h>
31 : : #include <rpc/server_util.h>
32 : : #include <rpc/util.h>
33 : : #include <script/descriptor.h>
34 : : #include <script/script.h>
35 : : #include <script/signingprovider.h>
36 : : #include <txmempool.h>
37 : : #include <univalue.h>
38 : : #include <util/signalinterrupt.h>
39 : : #include <util/strencodings.h>
40 : : #include <util/string.h>
41 : : #include <util/time.h>
42 : : #include <util/translation.h>
43 : : #include <validation.h>
44 : : #include <validationinterface.h>
45 : :
46 : : #include <memory>
47 : : #include <stdint.h>
48 : :
49 : : using interfaces::BlockTemplate;
50 : : using interfaces::Mining;
51 : : using node::BlockAssembler;
52 : : using node::NodeContext;
53 : : using node::RegenerateCommitments;
54 : : using node::UpdateTime;
55 : : using util::ToString;
56 : :
57 : : /**
58 : : * Return average network hashes per second based on the last 'lookup' blocks,
59 : : * or from the last difficulty change if 'lookup' is -1.
60 : : * If 'height' is -1, compute the estimate from current chain tip.
61 : : * If 'height' is a valid block height, compute the estimate at the time when a given block was found.
62 : : */
63 : 27 : static UniValue GetNetworkHashPS(int lookup, int height, const CChain& active_chain) {
64 [ + + ]: 27 : if (lookup < -1 || lookup == 0) {
65 [ + - + - ]: 8 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid nblocks. Must be a positive number or -1.");
66 : : }
67 : :
68 [ + + + + ]: 23 : if (height < -1 || height > active_chain.Height()) {
69 [ + - + - ]: 8 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Block does not exist at specified height");
70 : : }
71 : :
72 [ + - ]: 19 : const CBlockIndex* pb = active_chain.Tip();
73 : :
74 [ + + ]: 19 : if (height >= 0) {
75 : 2 : pb = active_chain[height];
76 : : }
77 : :
78 [ + - + + ]: 19 : if (pb == nullptr || !pb->nHeight)
79 : 5 : return 0;
80 : :
81 : : // If lookup is -1, then use blocks since last difficulty change.
82 [ + + ]: 14 : if (lookup == -1)
83 : 2 : lookup = pb->nHeight % Params().GetConsensus().DifficultyAdjustmentInterval() + 1;
84 : :
85 : : // If lookup is larger than chain, then set it to chain length.
86 [ + + ]: 14 : if (lookup > pb->nHeight)
87 : 2 : lookup = pb->nHeight;
88 : :
89 : 14 : const CBlockIndex* pb0 = pb;
90 : 14 : int64_t minTime = pb0->GetBlockTime();
91 : 14 : int64_t maxTime = minTime;
92 [ + + ]: 1602 : for (int i = 0; i < lookup; i++) {
93 : 1588 : pb0 = pb0->pprev;
94 [ + + ]: 1588 : int64_t time = pb0->GetBlockTime();
95 [ + + ]: 1588 : minTime = std::min(time, minTime);
96 [ + + ]: 1589 : maxTime = std::max(time, maxTime);
97 : : }
98 : :
99 : : // In case there's a situation where minTime == maxTime, we don't want a divide by zero exception.
100 [ - + ]: 14 : if (minTime == maxTime)
101 : 0 : return 0;
102 : :
103 : 14 : arith_uint256 workDiff = pb->nChainWork - pb0->nChainWork;
104 : 14 : int64_t timeDiff = maxTime - minTime;
105 : :
106 : 14 : return workDiff.getdouble() / timeDiff;
107 : : }
108 : :
109 : 2145 : static RPCHelpMan getnetworkhashps()
110 : : {
111 : 2145 : return RPCHelpMan{"getnetworkhashps",
112 : : "\nReturns the estimated network hashes per second based on the last n blocks.\n"
113 : : "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
114 : : "Pass in [height] to estimate the network speed at the time when a certain block was found.\n",
115 : : {
116 [ + - ]: 4290 : {"nblocks", RPCArg::Type::NUM, RPCArg::Default{120}, "The number of previous blocks to calculate estimate from, or -1 for blocks since last difficulty change."},
117 [ + - ]: 4290 : {"height", RPCArg::Type::NUM, RPCArg::Default{-1}, "To estimate at the time of the given height."},
118 : : },
119 : 0 : RPCResult{
120 [ + - + - : 4290 : RPCResult::Type::NUM, "", "Hashes per second estimated"},
+ - ]
121 : 2145 : RPCExamples{
122 [ + - + - : 4290 : HelpExampleCli("getnetworkhashps", "")
+ - ]
123 [ + - + - : 8580 : + HelpExampleRpc("getnetworkhashps", "")
+ - + - ]
124 [ + - ]: 2145 : },
125 : 27 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
126 : : {
127 : 27 : ChainstateManager& chainman = EnsureAnyChainman(request.context);
128 : 27 : LOCK(cs_main);
129 [ + - + - : 27 : return GetNetworkHashPS(self.Arg<int>("nblocks"), self.Arg<int>("height"), chainman.ActiveChain());
+ - + + ]
130 : 19 : },
131 [ + - + - : 34320 : };
+ - + - +
- + - + -
+ - + + -
- ]
132 [ + - + - : 10725 : }
+ - - - ]
133 : :
134 : 37884 : static bool GenerateBlock(ChainstateManager& chainman, CBlock&& block, uint64_t& max_tries, std::shared_ptr<const CBlock>& block_out, bool process_new_block)
135 : : {
136 : 37884 : block_out.reset();
137 : 37884 : block.hashMerkleRoot = BlockMerkleRoot(block);
138 : :
139 [ + + + - : 1113439 : while (max_tries > 0 && block.nNonce < std::numeric_limits<uint32_t>::max() && !CheckProofOfWork(block.GetHash(), block.nBits, chainman.GetConsensus()) && !chainman.m_interrupt) {
+ + + - ]
140 : 1037671 : ++block.nNonce;
141 : 1037671 : --max_tries;
142 : : }
143 [ + + + - ]: 37884 : if (max_tries == 0 || chainman.m_interrupt) {
144 : 1 : return false;
145 : : }
146 [ + - ]: 37883 : if (block.nNonce == std::numeric_limits<uint32_t>::max()) {
147 : : return true;
148 : : }
149 : :
150 [ - + ]: 37883 : block_out = std::make_shared<const CBlock>(std::move(block));
151 : :
152 [ + + ]: 37883 : if (!process_new_block) return true;
153 : :
154 [ - + ]: 37880 : if (!chainman.ProcessNewBlock(block_out, /*force_processing=*/true, /*min_pow_checked=*/true, nullptr)) {
155 [ # # # # ]: 0 : throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
156 : : }
157 : :
158 : : return true;
159 : : }
160 : :
161 : 2636 : static UniValue generateBlocks(ChainstateManager& chainman, Mining& miner, const CScript& coinbase_output_script, int nGenerate, uint64_t nMaxTries)
162 : : {
163 : 2636 : UniValue blockHashes(UniValue::VARR);
164 [ + + + - : 40182 : while (nGenerate > 0 && !chainman.m_interrupt) {
+ - ]
165 : 37546 : std::unique_ptr<BlockTemplate> block_template(miner.createNewBlock({ .coinbase_output_script = coinbase_output_script }));
166 [ + - ]: 37547 : CHECK_NONFATAL(block_template);
167 : :
168 : 37547 : std::shared_ptr<const CBlock> block_out;
169 [ + - + - : 37547 : if (!GenerateBlock(chainman, block_template->getBlock(), nMaxTries, block_out, /*process_new_block=*/true)) {
+ + ]
170 : : break;
171 : : }
172 : :
173 [ + - ]: 37546 : if (block_out) {
174 : 37546 : --nGenerate;
175 [ + - + - : 37546 : blockHashes.push_back(block_out->GetHash().GetHex());
+ - + - ]
176 : : }
177 : 37547 : }
178 : 2636 : return blockHashes;
179 [ + - ]: 37547 : }
180 : :
181 : 1106 : static bool getScriptFromDescriptor(const std::string& descriptor, CScript& script, std::string& error)
182 : : {
183 : 1106 : FlatSigningProvider key_provider;
184 [ + - ]: 1106 : const auto descs = Parse(descriptor, key_provider, error, /* require_checksum = */ false);
185 [ + + ]: 1106 : if (descs.empty()) return false;
186 [ - + ]: 788 : if (descs.size() > 1) {
187 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Multipath descriptor not accepted");
188 : : }
189 [ + - ]: 788 : const auto& desc = descs.at(0);
190 [ + - + + ]: 788 : if (desc->IsRange()) {
191 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Ranged descriptor not accepted. Maybe pass through deriveaddresses first?");
192 : : }
193 : :
194 : 787 : FlatSigningProvider provider;
195 : 787 : std::vector<CScript> scripts;
196 [ + - + + ]: 787 : if (!desc->Expand(0, key_provider, scripts, provider)) {
197 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Cannot derive script without private keys");
198 : : }
199 : :
200 : : // Combo descriptors can have 2 or 4 scripts, so we can't just check scripts.size() == 1
201 [ + - - + : 786 : CHECK_NONFATAL(scripts.size() > 0 && scripts.size() <= 4);
+ - ]
202 : :
203 [ + + ]: 786 : if (scripts.size() == 1) {
204 [ + - ]: 784 : script = scripts.at(0);
205 [ + + ]: 2 : } else if (scripts.size() == 4) {
206 : : // For uncompressed keys, take the 3rd script, since it is p2wpkh
207 [ + - ]: 1 : script = scripts.at(2);
208 : : } else {
209 : : // Else take the 2nd script, since it is p2pkh
210 [ + - ]: 1 : script = scripts.at(1);
211 : : }
212 : :
213 : 786 : return true;
214 : 1110 : }
215 : :
216 : 2870 : static RPCHelpMan generatetodescriptor()
217 : : {
218 : 2870 : return RPCHelpMan{
219 : : "generatetodescriptor",
220 : : "Mine to a specified descriptor and return the block hashes.",
221 : : {
222 [ + - ]: 2870 : {"num_blocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated."},
223 [ + - ]: 2870 : {"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor to send the newly generated bitcoin to."},
224 [ + - ]: 5740 : {"maxtries", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_MAX_TRIES}, "How many iterations to try."},
225 : : },
226 : 0 : RPCResult{
227 : : RPCResult::Type::ARR, "", "hashes of blocks generated",
228 : : {
229 : : {RPCResult::Type::STR_HEX, "", "blockhash"},
230 : : }
231 [ + - + - : 8610 : },
+ - + - +
- + - + -
+ + - - ]
232 : 2870 : RPCExamples{
233 [ + - + - : 8610 : "\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")},
+ - + - +
- ]
234 : 763 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
235 : : {
236 : 763 : const auto num_blocks{self.Arg<int>("num_blocks")};
237 : 763 : const auto max_tries{self.Arg<uint64_t>("maxtries")};
238 : :
239 : 763 : CScript coinbase_output_script;
240 [ + - ]: 763 : std::string error;
241 [ + - + - : 763 : if (!getScriptFromDescriptor(self.Arg<std::string>("descriptor"), coinbase_output_script, error)) {
- + ]
242 [ # # ]: 0 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error);
243 : : }
244 : :
245 [ + - ]: 763 : NodeContext& node = EnsureAnyNodeContext(request.context);
246 [ + - ]: 763 : Mining& miner = EnsureMining(node);
247 [ + - ]: 763 : ChainstateManager& chainman = EnsureChainman(node);
248 : :
249 [ + - ]: 763 : return generateBlocks(chainman, miner, coinbase_output_script, num_blocks, max_tries);
250 : 763 : },
251 [ + - + - : 48790 : };
+ - + - +
- + - + -
+ - + - +
- + + -
- ]
252 [ + - + - : 25830 : }
+ - + - +
- + - -
- ]
253 : :
254 : 2109 : static RPCHelpMan generate()
255 : : {
256 [ + - + - ]: 8436 : return RPCHelpMan{"generate", "has been replaced by the -generate cli option. Refer to -help for more information.", {}, {}, RPCExamples{""}, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
257 [ + - + - ]: 2 : throw JSONRPCError(RPC_METHOD_NOT_FOUND, self.ToString());
258 [ + - + - : 10545 : }};
+ - + - ]
259 : : }
260 : :
261 : 3983 : static RPCHelpMan generatetoaddress()
262 : : {
263 : 3983 : return RPCHelpMan{"generatetoaddress",
264 : : "Mine to a specified address and return the block hashes.",
265 : : {
266 [ + - ]: 3983 : {"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated."},
267 [ + - ]: 3983 : {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address to send the newly generated bitcoin to."},
268 [ + - ]: 7966 : {"maxtries", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_MAX_TRIES}, "How many iterations to try."},
269 : : },
270 : 0 : RPCResult{
271 : : RPCResult::Type::ARR, "", "hashes of blocks generated",
272 : : {
273 : : {RPCResult::Type::STR_HEX, "", "blockhash"},
274 [ + - + - : 11949 : }},
+ - + - +
- + - + -
+ + - - ]
275 : 3983 : RPCExamples{
276 : : "\nGenerate 11 blocks to myaddress\n"
277 [ + - + - : 7966 : + HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
+ - + - ]
278 : 3983 : + "If you are using the " CLIENT_NAME " wallet, you can get a new address to send the newly generated bitcoin to with:\n"
279 [ + - + - : 15932 : + HelpExampleCli("getnewaddress", "")
+ - + - ]
280 [ + - ]: 3983 : },
281 : 1875 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
282 : : {
283 : 1875 : const int num_blocks{request.params[0].getInt<int>()};
284 [ + + ]: 1875 : const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].getInt<int>()};
285 : :
286 : 1875 : CTxDestination destination = DecodeDestination(request.params[1].get_str());
287 [ + - + + ]: 1875 : if (!IsValidDestination(destination)) {
288 [ + - + - ]: 4 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address");
289 : : }
290 : :
291 [ + - ]: 1873 : NodeContext& node = EnsureAnyNodeContext(request.context);
292 [ + - ]: 1873 : Mining& miner = EnsureMining(node);
293 [ + - ]: 1873 : ChainstateManager& chainman = EnsureChainman(node);
294 : :
295 [ + - ]: 1873 : CScript coinbase_output_script = GetScriptForDestination(destination);
296 : :
297 [ + - ]: 1873 : return generateBlocks(chainman, miner, coinbase_output_script, num_blocks, max_tries);
298 : 1873 : },
299 [ + - + - : 67711 : };
+ - + - +
- + - + -
+ - + - +
- + + -
- ]
300 [ + - + - : 35847 : }
+ - + - +
- + - -
- ]
301 : :
302 : 2450 : static RPCHelpMan generateblock()
303 : : {
304 : 2450 : return RPCHelpMan{"generateblock",
305 : : "Mine a set of ordered transactions to a specified address or descriptor and return the block hash.",
306 : : {
307 [ + - ]: 2450 : {"output", RPCArg::Type::STR, RPCArg::Optional::NO, "The address or descriptor to send the newly generated bitcoin to."},
308 [ + - ]: 2450 : {"transactions", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of hex strings which are either txids or raw transactions.\n"
309 : : "Txids must reference transactions currently in the mempool.\n"
310 : : "All transactions must be valid and in valid order, otherwise the block will be rejected.",
311 : : {
312 [ + - ]: 2450 : {"rawtx/txid", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
313 : : },
314 : : },
315 [ + - ]: 4900 : {"submit", RPCArg::Type::BOOL, RPCArg::Default{true}, "Whether to submit the block before the RPC call returns or to return it as hex."},
316 : : },
317 : 0 : RPCResult{
318 : : RPCResult::Type::OBJ, "", "",
319 : : {
320 : : {RPCResult::Type::STR_HEX, "hash", "hash of generated block"},
321 : : {RPCResult::Type::STR_HEX, "hex", /*optional=*/true, "hex of generated block, only present when submit=false"},
322 : : }
323 [ + - + - : 9800 : },
+ - + - +
- + - + -
+ - + - +
- + + -
- ]
324 : 2450 : RPCExamples{
325 : : "\nGenerate a block to myaddress, with txs rawtx and mempool_txid\n"
326 [ + - + - : 4900 : + HelpExampleCli("generateblock", R"("myaddress" '["rawtx", "mempool_txid"]')")
+ - + - ]
327 [ + - ]: 2450 : },
328 : 343 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
329 : : {
330 : 343 : const auto address_or_descriptor = request.params[0].get_str();
331 : 343 : CScript coinbase_output_script;
332 [ + + ]: 343 : std::string error;
333 : :
334 [ + + + + ]: 343 : if (!getScriptFromDescriptor(address_or_descriptor, coinbase_output_script, error)) {
335 [ + - ]: 318 : const auto destination = DecodeDestination(address_or_descriptor);
336 [ + - + + ]: 318 : if (!IsValidDestination(destination)) {
337 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address or descriptor");
338 : : }
339 : :
340 [ + - ]: 634 : coinbase_output_script = GetScriptForDestination(destination);
341 : 318 : }
342 : :
343 [ + - ]: 340 : NodeContext& node = EnsureAnyNodeContext(request.context);
344 [ + - ]: 340 : Mining& miner = EnsureMining(node);
345 [ + - ]: 340 : const CTxMemPool& mempool = EnsureMemPool(node);
346 : :
347 : 340 : std::vector<CTransactionRef> txs;
348 [ + - + - : 340 : const auto raw_txs_or_txids = request.params[1].get_array();
+ - ]
349 [ + + ]: 358 : for (size_t i = 0; i < raw_txs_or_txids.size(); i++) {
350 [ + - + - ]: 20 : const auto& str{raw_txs_or_txids[i].get_str()};
351 : :
352 [ + - ]: 20 : CMutableTransaction mtx;
353 [ + - + + ]: 20 : if (auto hash{uint256::FromHex(str)}) {
354 [ + - ]: 4 : const auto tx{mempool.get(*hash)};
355 [ + + ]: 4 : if (!tx) {
356 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Transaction %s not in mempool.", str));
357 : : }
358 : :
359 [ + - ]: 3 : txs.emplace_back(tx);
360 : :
361 [ + - + + ]: 20 : } else if (DecodeHexTx(mtx, str)) {
362 [ + - + - : 30 : txs.push_back(MakeTransactionRef(std::move(mtx)));
- + ]
363 : :
364 : : } else {
365 [ + - + - ]: 2 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("Transaction decode failed for %s. Make sure the tx has at least one input.", str));
366 : : }
367 : 20 : }
368 : :
369 [ + - + + : 338 : const bool process_new_block{request.params[2].isNull() ? true : request.params[2].get_bool()};
+ - + - ]
370 : 338 : CBlock block;
371 : :
372 [ + - ]: 338 : ChainstateManager& chainman = EnsureChainman(node);
373 : 338 : {
374 [ + - ]: 338 : LOCK(chainman.GetMutex());
375 : 338 : {
376 : 0 : std::unique_ptr<BlockTemplate> block_template{miner.createNewBlock({.use_mempool = false, .coinbase_output_script = coinbase_output_script})};
377 [ + - ]: 338 : CHECK_NONFATAL(block_template);
378 : :
379 [ + - ]: 338 : block = block_template->getBlock();
380 : 338 : }
381 : :
382 [ + - ]: 338 : CHECK_NONFATAL(block.vtx.size() == 1);
383 : :
384 : : // Add transactions
385 [ + - ]: 338 : block.vtx.insert(block.vtx.end(), txs.begin(), txs.end());
386 [ + - ]: 338 : RegenerateCommitments(block, chainman);
387 : :
388 [ + - ]: 338 : BlockValidationState state;
389 [ + - + - : 338 : if (!TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) {
+ - + + ]
390 [ + - + - : 2 : throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("TestBlockValidity failed: %s", state.ToString()));
+ - ]
391 : : }
392 [ + - ]: 339 : }
393 : :
394 : 337 : std::shared_ptr<const CBlock> block_out;
395 : 337 : uint64_t max_tries{DEFAULT_MAX_TRIES};
396 : :
397 [ + - + - : 337 : if (!GenerateBlock(chainman, std::move(block), max_tries, block_out, process_new_block) || !block_out) {
- + ]
398 [ # # # # ]: 0 : throw JSONRPCError(RPC_MISC_ERROR, "Failed to make block.");
399 : : }
400 : :
401 : 337 : UniValue obj(UniValue::VOBJ);
402 [ + - + - : 674 : obj.pushKV("hash", block_out->GetHash().GetHex());
+ - + - +
- ]
403 [ + + ]: 337 : if (!process_new_block) {
404 : 3 : DataStream block_ser;
405 [ + - ]: 3 : block_ser << TX_WITH_WITNESS(*block_out);
406 [ + - + - : 6 : obj.pushKV("hex", HexStr(block_ser));
+ - + - ]
407 : 3 : }
408 [ + - ]: 337 : return obj;
409 [ + - ]: 693 : },
410 [ + - + - : 49000 : };
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + + +
+ - - -
- ]
411 [ + - + - : 29400 : }
+ - + - +
- + - + -
+ - - - -
- ]
412 : :
413 : 2125 : static RPCHelpMan getmininginfo()
414 : : {
415 : 2125 : return RPCHelpMan{"getmininginfo",
416 : : "\nReturns a json object containing mining-related information.",
417 : : {},
418 : 0 : RPCResult{
419 : : RPCResult::Type::OBJ, "", "",
420 : : {
421 : : {RPCResult::Type::NUM, "blocks", "The current block"},
422 : : {RPCResult::Type::NUM, "currentblockweight", /*optional=*/true, "The block weight of the last assembled block (only present if a block was ever assembled)"},
423 : : {RPCResult::Type::NUM, "currentblocktx", /*optional=*/true, "The number of block transactions of the last assembled block (only present if a block was ever assembled)"},
424 : : {RPCResult::Type::NUM, "difficulty", "The current difficulty"},
425 : : {RPCResult::Type::NUM, "networkhashps", "The network hashes per second"},
426 : : {RPCResult::Type::NUM, "pooledtx", "The size of the mempool"},
427 : : {RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"},
428 : : {RPCResult::Type::STR_HEX, "signet_challenge", /*optional=*/true, "The block challenge (aka. block script), in hexadecimal (only present if the current network is a signet)"},
429 [ + - + - : 2125 : (IsDeprecatedRPCEnabled("warnings") ?
- + ]
430 [ - - - - : 2125 : RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} :
- - - + -
+ - + - -
- - - - ]
431 : : RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)",
432 : : {
433 : : {RPCResult::Type::STR, "", "warning"},
434 : : }
435 [ + - + - : 17000 : }
+ - + - +
- + - + -
+ - + + +
- + - + -
+ - + - -
- - - - -
- - - - -
- - - -
- ]
436 : : ),
437 [ + - + - : 27625 : }},
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + + -
- ]
438 : 2125 : RPCExamples{
439 [ + - + - : 4250 : HelpExampleCli("getmininginfo", "")
+ - ]
440 [ + - + - : 8500 : + HelpExampleRpc("getmininginfo", "")
+ - + - ]
441 [ + - ]: 2125 : },
442 : 9 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
443 : : {
444 : 9 : NodeContext& node = EnsureAnyNodeContext(request.context);
445 : 9 : const CTxMemPool& mempool = EnsureMemPool(node);
446 : 9 : ChainstateManager& chainman = EnsureChainman(node);
447 : 9 : LOCK(cs_main);
448 [ + - ]: 9 : const CChain& active_chain = chainman.ActiveChain();
449 : :
450 : 9 : UniValue obj(UniValue::VOBJ);
451 [ + - + - : 18 : obj.pushKV("blocks", active_chain.Height());
+ - ]
452 [ + + + - : 12 : if (BlockAssembler::m_last_block_weight) obj.pushKV("currentblockweight", *BlockAssembler::m_last_block_weight);
+ - + - ]
453 [ + + + - : 12 : if (BlockAssembler::m_last_block_num_txs) obj.pushKV("currentblocktx", *BlockAssembler::m_last_block_num_txs);
+ - + - ]
454 [ + - + - : 27 : obj.pushKV("difficulty", GetDifficulty(*CHECK_NONFATAL(active_chain.Tip())));
+ - + - +
- + - ]
455 [ + - + - : 18 : obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request));
+ - + - ]
456 [ + - + - : 18 : obj.pushKV("pooledtx", (uint64_t)mempool.size());
+ - + - ]
457 [ + - + - : 18 : obj.pushKV("chain", chainman.GetParams().GetChainTypeString());
+ - + - ]
458 [ + + ]: 9 : if (chainman.GetParams().GetChainType() == ChainType::SIGNET) {
459 : 3 : const std::vector<uint8_t>& signet_challenge =
460 : 3 : chainman.GetParams().GetConsensus().signet_challenge;
461 [ + - + - : 6 : obj.pushKV("signet_challenge", HexStr(signet_challenge));
+ - + - ]
462 : : }
463 [ + - + - : 18 : obj.pushKV("warnings", node::GetWarningsForRpc(*CHECK_NONFATAL(node.warnings), IsDeprecatedRPCEnabled("warnings")));
+ - + - +
- + - ]
464 [ + - ]: 9 : return obj;
465 : 9 : },
466 [ + - + - : 12750 : };
+ - + - ]
467 [ + - + - : 23375 : }
+ - + - +
- + - + -
+ - + - -
- + - + -
- - ]
468 : :
469 : :
470 : : // NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
471 : 2841 : static RPCHelpMan prioritisetransaction()
472 : : {
473 : 2841 : return RPCHelpMan{"prioritisetransaction",
474 : : "Accepts the transaction into mined blocks at a higher (or lower) priority\n",
475 : : {
476 [ + - ]: 2841 : {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id."},
477 [ + - ]: 2841 : {"dummy", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "API-Compatibility for previous API. Must be zero or null.\n"
478 : : " DEPRECATED. For forward compatibility use named arguments and omit this parameter."},
479 [ + - ]: 2841 : {"fee_delta", RPCArg::Type::NUM, RPCArg::Optional::NO, "The fee value (in satoshis) to add (or subtract, if negative).\n"
480 : : " Note, that this value is not a fee rate. It is a value to modify absolute fee of the TX.\n"
481 : : " The fee is not actually paid, only the algorithm for selecting transactions into a block\n"
482 : : " considers the transaction as it would have paid a higher (or lower) fee."},
483 : : },
484 : 0 : RPCResult{
485 [ + - + - : 5682 : RPCResult::Type::BOOL, "", "Returns true"},
+ - ]
486 : 2841 : RPCExamples{
487 [ + - + - : 5682 : HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000")
+ - ]
488 [ + - + - : 11364 : + HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")
+ - + - ]
489 [ + - ]: 2841 : },
490 : 719 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
491 : : {
492 : 719 : LOCK(cs_main);
493 : :
494 [ + - + + ]: 719 : uint256 hash(ParseHashV(request.params[0], "txid"));
495 [ + - ]: 717 : const auto dummy{self.MaybeArg<double>("dummy")};
496 [ + - + - ]: 717 : CAmount nAmount = request.params[2].getInt<int64_t>();
497 : :
498 [ + + + + ]: 717 : if (dummy && *dummy != 0) {
499 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Priority is no longer supported, dummy argument to prioritisetransaction must be 0.");
500 : : }
501 : :
502 [ + - ]: 716 : CTxMemPool& mempool = EnsureAnyMemPool(request.context);
503 : :
504 : : // Non-0 fee dust transactions are not allowed for entry, and modification not allowed afterwards
505 [ + - ]: 716 : const auto& tx = mempool.get(hash);
506 [ + - + + : 961 : if (mempool.m_opts.require_standard && tx && !GetDust(*tx, mempool.m_opts.dust_relay_feerate).empty()) {
+ - + + +
+ ]
507 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Priority is not supported for transactions with dust outputs.");
508 : : }
509 : :
510 [ + - ]: 715 : mempool.PrioritiseTransaction(hash, nAmount);
511 [ + - ]: 715 : return true;
512 [ + - ]: 1431 : },
513 [ + - + - : 42615 : };
+ - + - +
- + - + -
+ - + - +
- + + -
- ]
514 [ + - + - : 19887 : }
+ - + - -
- ]
515 : :
516 : 2145 : static RPCHelpMan getprioritisedtransactions()
517 : : {
518 : 2145 : return RPCHelpMan{"getprioritisedtransactions",
519 : : "Returns a map of all user-created (see prioritisetransaction) fee deltas by txid, and whether the tx is present in mempool.",
520 : : {},
521 : 0 : RPCResult{
522 : : RPCResult::Type::OBJ_DYN, "", "prioritisation keyed by txid",
523 : : {
524 : : {RPCResult::Type::OBJ, "<transactionid>", "", {
525 : : {RPCResult::Type::NUM, "fee_delta", "transaction fee delta in satoshis"},
526 : : {RPCResult::Type::BOOL, "in_mempool", "whether this transaction is currently in mempool"},
527 : : {RPCResult::Type::NUM, "modified_fee", /*optional=*/true, "modified fee in satoshis. Only returned if in_mempool=true"},
528 : : }}
529 : : },
530 [ + - + - : 15015 : },
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + +
+ + - - -
- ]
531 : 2145 : RPCExamples{
532 [ + - + - : 4290 : HelpExampleCli("getprioritisedtransactions", "")
+ - ]
533 [ + - + - : 8580 : + HelpExampleRpc("getprioritisedtransactions", "")
+ - + - ]
534 [ + - ]: 2145 : },
535 : 28 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
536 : : {
537 : 28 : NodeContext& node = EnsureAnyNodeContext(request.context);
538 : 28 : CTxMemPool& mempool = EnsureMemPool(node);
539 : 28 : UniValue rpc_result{UniValue::VOBJ};
540 [ + - + + ]: 56 : for (const auto& delta_info : mempool.GetPrioritisedTransactions()) {
541 : 28 : UniValue result_inner{UniValue::VOBJ};
542 [ + - + - : 56 : result_inner.pushKV("fee_delta", delta_info.delta);
+ - ]
543 [ + - + - : 56 : result_inner.pushKV("in_mempool", delta_info.in_mempool);
+ - ]
544 [ + + ]: 28 : if (delta_info.in_mempool) {
545 [ + - + - : 36 : result_inner.pushKV("modified_fee", *delta_info.modified_fee);
+ - ]
546 : : }
547 [ + - + - ]: 56 : rpc_result.pushKV(delta_info.txid.GetHex(), std::move(result_inner));
548 : 28 : }
549 : 28 : return rpc_result;
550 : 0 : },
551 [ + - + - : 12870 : };
+ - + - ]
552 [ + - + - : 10725 : }
+ - + - +
- - - ]
553 : :
554 : :
555 : : // NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller
556 : 20040 : static UniValue BIP22ValidationResult(const BlockValidationState& state)
557 : : {
558 [ + + ]: 20040 : if (state.IsValid())
559 : 17520 : return UniValue::VNULL;
560 : :
561 [ - + ]: 2520 : if (state.IsError())
562 [ # # # # ]: 0 : throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString());
563 [ + - ]: 2520 : if (state.IsInvalid())
564 : : {
565 : 2520 : std::string strRejectReason = state.GetRejectReason();
566 [ - + ]: 2520 : if (strRejectReason.empty())
567 [ # # ]: 0 : return "rejected";
568 [ + - ]: 2520 : return strRejectReason;
569 : 2520 : }
570 : : // Should be impossible
571 : 0 : return "valid?";
572 : : }
573 : :
574 : 4121 : static std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
575 : 4121 : const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
576 : 4121 : std::string s = vbinfo.name;
577 [ - + ]: 4121 : if (!vbinfo.gbt_force) {
578 [ # # ]: 0 : s.insert(s.begin(), '!');
579 : : }
580 : 4121 : return s;
581 : 0 : }
582 : :
583 : 4195 : static RPCHelpMan getblocktemplate()
584 : : {
585 : 4195 : return RPCHelpMan{"getblocktemplate",
586 : : "\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
587 : : "It returns data needed to construct a block to work on.\n"
588 : : "For full specification, see BIPs 22, 23, 9, and 145:\n"
589 : : " https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki\n"
590 : : " https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki\n"
591 : : " https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n"
592 : : " https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki\n",
593 : : {
594 [ + - ]: 4195 : {"template_request", RPCArg::Type::OBJ, RPCArg::Optional::NO, "Format of the template",
595 : : {
596 [ + - ]: 4195 : {"mode", RPCArg::Type::STR, /* treat as named arg */ RPCArg::Optional::OMITTED, "This must be set to \"template\", \"proposal\" (see BIP 23), or omitted"},
597 [ + - ]: 4195 : {"capabilities", RPCArg::Type::ARR, /* treat as named arg */ RPCArg::Optional::OMITTED, "A list of strings",
598 : : {
599 [ + - ]: 4195 : {"str", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported feature, 'longpoll', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"},
600 : : }},
601 [ + - ]: 4195 : {"rules", RPCArg::Type::ARR, RPCArg::Optional::NO, "A list of strings",
602 : : {
603 [ + - ]: 4195 : {"segwit", RPCArg::Type::STR, RPCArg::Optional::NO, "(literal) indicates client side segwit support"},
604 [ + - ]: 4195 : {"str", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "other client side supported softfork deployment"},
605 : : }},
606 [ + - ]: 4195 : {"longpollid", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "delay processing request until the result would vary significantly from the \"longpollid\" of a prior template"},
607 [ + - ]: 4195 : {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "proposed block data to check, encoded in hexadecimal; valid only for mode=\"proposal\""},
608 : : },
609 : : },
610 : : },
611 : : {
612 [ + - + - : 8390 : RPCResult{"If the proposal was accepted with mode=='proposal'", RPCResult::Type::NONE, "", ""},
+ - + - ]
613 [ + - + - : 8390 : RPCResult{"If the proposal was not accepted with mode=='proposal'", RPCResult::Type::STR, "", "According to BIP22"},
+ - + - ]
614 : : RPCResult{"Otherwise", RPCResult::Type::OBJ, "", "",
615 : : {
616 : : {RPCResult::Type::NUM, "version", "The preferred block version"},
617 : : {RPCResult::Type::ARR, "rules", "specific block rules that are to be enforced",
618 : : {
619 : : {RPCResult::Type::STR, "", "name of a rule the client must understand to some extent; see BIP 9 for format"},
620 : : }},
621 : : {RPCResult::Type::OBJ_DYN, "vbavailable", "set of pending, supported versionbit (BIP 9) softfork deployments",
622 : : {
623 : : {RPCResult::Type::NUM, "rulename", "identifies the bit number as indicating acceptance and readiness for the named softfork rule"},
624 : : }},
625 : : {RPCResult::Type::ARR, "capabilities", "",
626 : : {
627 : : {RPCResult::Type::STR, "value", "A supported feature, for example 'proposal'"},
628 : : }},
629 : : {RPCResult::Type::NUM, "vbrequired", "bit mask of versionbits the server requires set in submissions"},
630 : : {RPCResult::Type::STR, "previousblockhash", "The hash of current highest block"},
631 : : {RPCResult::Type::ARR, "transactions", "contents of non-coinbase transactions that should be included in the next block",
632 : : {
633 : : {RPCResult::Type::OBJ, "", "",
634 : : {
635 : : {RPCResult::Type::STR_HEX, "data", "transaction data encoded in hexadecimal (byte-for-byte)"},
636 : : {RPCResult::Type::STR_HEX, "txid", "transaction hash excluding witness data, shown in byte-reversed hex"},
637 : : {RPCResult::Type::STR_HEX, "hash", "transaction hash including witness data, shown in byte-reversed hex"},
638 : : {RPCResult::Type::ARR, "depends", "array of numbers",
639 : : {
640 : : {RPCResult::Type::NUM, "", "transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is"},
641 : : }},
642 : : {RPCResult::Type::NUM, "fee", "difference in value between transaction inputs and outputs (in satoshis); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one"},
643 : : {RPCResult::Type::NUM, "sigops", "total SigOps cost, as counted for purposes of block limits; if key is not present, sigop cost is unknown and clients MUST NOT assume it is zero"},
644 : : {RPCResult::Type::NUM, "weight", "total transaction weight, as counted for purposes of block limits"},
645 : : }},
646 : : }},
647 : : {RPCResult::Type::OBJ_DYN, "coinbaseaux", "data that should be included in the coinbase's scriptSig content",
648 : : {
649 : : {RPCResult::Type::STR_HEX, "key", "values must be in the coinbase (keys may be ignored)"},
650 : : }},
651 : : {RPCResult::Type::NUM, "coinbasevalue", "maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis)"},
652 : : {RPCResult::Type::STR, "longpollid", "an id to include with a request to longpoll on an update to this template"},
653 : : {RPCResult::Type::STR, "target", "The hash target"},
654 [ + - ]: 8390 : {RPCResult::Type::NUM_TIME, "mintime", "The minimum timestamp appropriate for the next block time, expressed in " + UNIX_EPOCH_TIME},
655 : : {RPCResult::Type::ARR, "mutable", "list of ways the block template may be changed",
656 : : {
657 : : {RPCResult::Type::STR, "value", "A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'"},
658 : : }},
659 : : {RPCResult::Type::STR_HEX, "noncerange", "A range of valid nonces"},
660 : : {RPCResult::Type::NUM, "sigoplimit", "limit of sigops in blocks"},
661 : : {RPCResult::Type::NUM, "sizelimit", "limit of block size"},
662 : : {RPCResult::Type::NUM, "weightlimit", /*optional=*/true, "limit of block weight"},
663 [ + - ]: 8390 : {RPCResult::Type::NUM_TIME, "curtime", "current timestamp in " + UNIX_EPOCH_TIME},
664 : : {RPCResult::Type::STR, "bits", "compressed target of next block"},
665 : : {RPCResult::Type::NUM, "height", "The height of the next block"},
666 : : {RPCResult::Type::STR_HEX, "signet_challenge", /*optional=*/true, "Only on signet"},
667 : : {RPCResult::Type::STR_HEX, "default_witness_commitment", /*optional=*/true, "a valid witness commitment for the unmodified block template"},
668 [ + - + - : 209750 : }},
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + + + +
+ + + + +
+ + + + +
+ + + + -
- - - - -
- - - - -
- - - - -
- - ]
669 : : },
670 : 4195 : RPCExamples{
671 [ + - + - : 8390 : HelpExampleCli("getblocktemplate", "'{\"rules\": [\"segwit\"]}'")
+ - ]
672 [ + - + - : 16780 : + HelpExampleRpc("getblocktemplate", "{\"rules\": [\"segwit\"]}")
+ - + - ]
673 [ + - ]: 4195 : },
674 : 2079 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
675 : : {
676 : 2079 : NodeContext& node = EnsureAnyNodeContext(request.context);
677 : 2079 : ChainstateManager& chainman = EnsureChainman(node);
678 : 2079 : Mining& miner = EnsureMining(node);
679 : 2079 : LOCK(cs_main);
680 [ + - + - : 2079 : uint256 tip{CHECK_NONFATAL(miner.getTip()).value().hash};
+ - ]
681 : :
682 [ + - ]: 2079 : std::string strMode = "template";
683 [ + - ]: 2079 : UniValue lpval = NullUniValue;
684 [ + - ]: 2079 : std::set<std::string> setClientRules;
685 [ + - + - ]: 2079 : if (!request.params[0].isNull())
686 : : {
687 [ + - + - ]: 2079 : const UniValue& oparam = request.params[0].get_obj();
688 [ + - ]: 2079 : const UniValue& modeval = oparam.find_value("mode");
689 [ + + ]: 2079 : if (modeval.isStr())
690 [ + - + - ]: 13 : strMode = modeval.get_str();
691 [ - + ]: 2066 : else if (modeval.isNull())
692 : : {
693 : : /* Do nothing */
694 : : }
695 : : else
696 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
697 [ + - + - ]: 2079 : lpval = oparam.find_value("longpollid");
698 : :
699 [ + + ]: 2079 : if (strMode == "proposal")
700 : : {
701 [ + - ]: 13 : const UniValue& dataval = oparam.find_value("data");
702 [ - + ]: 13 : if (!dataval.isStr())
703 [ # # # # ]: 0 : throw JSONRPCError(RPC_TYPE_ERROR, "Missing data String key for proposal");
704 : :
705 : 13 : CBlock block;
706 [ + - + - : 13 : if (!DecodeHexBlk(block, dataval.get_str()))
+ + ]
707 [ + - + - ]: 4 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
708 : :
709 [ + - ]: 11 : uint256 hash = block.GetHash();
710 [ + - ]: 11 : const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
711 [ - + ]: 11 : if (pindex) {
712 [ # # # # ]: 0 : if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
713 [ # # ]: 0 : return "duplicate";
714 [ # # ]: 0 : if (pindex->nStatus & BLOCK_FAILED_MASK)
715 [ # # ]: 0 : return "duplicate-invalid";
716 [ # # ]: 0 : return "duplicate-inconclusive";
717 : : }
718 : :
719 : : // TestBlockValidity only supports blocks built on the current Tip
720 [ + + ]: 11 : if (block.hashPrevBlock != tip) {
721 [ + - ]: 1 : return "inconclusive-not-best-prevblk";
722 : : }
723 [ + - ]: 10 : BlockValidationState state;
724 [ + - + - : 10 : TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/true);
+ - ]
725 [ + - ]: 10 : return BIP22ValidationResult(state);
726 : 23 : }
727 : :
728 [ + - ]: 2066 : const UniValue& aClientRules = oparam.find_value("rules");
729 [ + + ]: 2066 : if (aClientRules.isArray()) {
730 [ + + ]: 4131 : for (unsigned int i = 0; i < aClientRules.size(); ++i) {
731 [ + - ]: 2066 : const UniValue& v = aClientRules[i];
732 [ + - + - ]: 2066 : setClientRules.insert(v.get_str());
733 : : }
734 : : }
735 : : }
736 : :
737 [ - + ]: 2066 : if (strMode != "template")
738 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
739 : :
740 [ + - - + ]: 2066 : if (!miner.isTestChain()) {
741 [ # # ]: 0 : const CConnman& connman = EnsureConnman(node);
742 [ # # # # ]: 0 : if (connman.GetNodeCount(ConnectionDirection::Both) == 0) {
743 [ # # # # ]: 0 : throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, CLIENT_NAME " is not connected!");
744 : : }
745 : :
746 [ # # # # ]: 0 : if (miner.isInitialBlockDownload()) {
747 [ # # # # ]: 0 : throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, CLIENT_NAME " is in initial sync and waiting for blocks...");
748 : : }
749 : : }
750 : :
751 : 2066 : static unsigned int nTransactionsUpdatedLast;
752 [ + - ]: 2066 : const CTxMemPool& mempool = EnsureMemPool(node);
753 : :
754 [ + + ]: 2066 : if (!lpval.isNull())
755 : : {
756 : : // Wait to respond until either the best block changes, OR a minute has passed and there are more transactions
757 : 3 : uint256 hashWatchedChain;
758 : 3 : unsigned int nTransactionsUpdatedLastLP;
759 : :
760 [ + - ]: 3 : if (lpval.isStr())
761 : : {
762 : : // Format: <hashBestChain><nTransactionsUpdatedLast>
763 [ + - ]: 3 : const std::string& lpstr = lpval.get_str();
764 : :
765 [ + - + - : 3 : hashWatchedChain = ParseHashV(lpstr.substr(0, 64), "longpollid");
+ - ]
766 [ + - + - ]: 3 : nTransactionsUpdatedLastLP = LocaleIndependentAtoi<int64_t>(lpstr.substr(64));
767 : : }
768 : : else
769 : : {
770 : : // NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier
771 : 0 : hashWatchedChain = tip;
772 : 0 : nTransactionsUpdatedLastLP = nTransactionsUpdatedLast;
773 : : }
774 : :
775 : : // Release lock while waiting
776 : 3 : LEAVE_CRITICAL_SECTION(cs_main);
777 : 3 : {
778 : 3 : MillisecondsDouble checktxtime{std::chrono::minutes(1)};
779 [ + - + - : 3 : while (tip == hashWatchedChain && IsRPCRunning()) {
+ - ]
780 [ + - ]: 3 : tip = miner.waitTipChanged(hashWatchedChain, checktxtime).hash;
781 : : // Timeout: Check transactions for update
782 : : // without holding the mempool lock to avoid deadlocks
783 [ + - - + ]: 3 : if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
784 : : break;
785 : 0 : checktxtime = std::chrono::seconds(10);
786 : : }
787 : : }
788 [ + - ]: 3 : ENTER_CRITICAL_SECTION(cs_main);
789 : :
790 [ + - + - : 3 : tip = CHECK_NONFATAL(miner.getTip()).value().hash;
+ - ]
791 : :
792 [ + - - + ]: 3 : if (!IsRPCRunning())
793 [ # # # # ]: 0 : throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
794 : : // TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
795 : : }
796 : :
797 [ + + ]: 2066 : const Consensus::Params& consensusParams = chainman.GetParams().GetConsensus();
798 : :
799 : : // GBT must be called with 'signet' set in the rules for signet chains
800 [ + + + - : 2067 : if (consensusParams.signet_blocks && setClientRules.count("signet") != 1) {
- + - + ]
801 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the signet rule set (call with {\"rules\": [\"segwit\", \"signet\"]})");
802 : : }
803 : :
804 : : // GBT must be called with 'segwit' set in the rules
805 [ + - + + ]: 2066 : if (setClientRules.count("segwit") != 1) {
806 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the segwit rule set (call with {\"rules\": [\"segwit\"]})");
807 : : }
808 : :
809 : : // Update block
810 : 2065 : static CBlockIndex* pindexPrev;
811 : 2065 : static int64_t time_start;
812 [ + + + - ]: 3118 : static std::unique_ptr<BlockTemplate> block_template;
813 [ + + + + ]: 2065 : if (!pindexPrev || pindexPrev->GetBlockHash() != tip ||
814 [ + - + + : 2010 : (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - time_start > 5))
+ - + + ]
815 : : {
816 : : // Clear pindexPrev so future calls make a new block, despite any failures from here on
817 : 57 : pindexPrev = nullptr;
818 : :
819 : : // Store the pindexBest used before createNewBlock, to avoid races
820 [ + - ]: 57 : nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
821 [ + - ]: 57 : CBlockIndex* pindexPrevNew = chainman.m_blockman.LookupBlockIndex(tip);
822 [ + - ]: 57 : time_start = GetTime();
823 : :
824 : : // Create new block
825 : 114 : block_template = miner.createNewBlock();
826 [ + - ]: 57 : CHECK_NONFATAL(block_template);
827 : :
828 : :
829 : : // Need to update only after we know createNewBlock succeeded
830 : 57 : pindexPrev = pindexPrevNew;
831 : : }
832 [ + - ]: 2065 : CHECK_NONFATAL(pindexPrev);
833 [ + - ]: 2065 : CBlock block{block_template->getBlock()};
834 : :
835 : : // Update nTime
836 [ + - ]: 2065 : UpdateTime(&block, consensusParams, pindexPrev);
837 : 2065 : block.nNonce = 0;
838 : :
839 : : // NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration
840 : 2065 : const bool fPreSegWit = !DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_SEGWIT);
841 : :
842 [ + - + - ]: 2065 : UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
843 : :
844 : 2065 : UniValue transactions(UniValue::VARR);
845 [ + - ]: 2065 : std::map<uint256, int64_t> setTxIndex;
846 [ + - ]: 2065 : std::vector<CAmount> tx_fees{block_template->getTxFees()};
847 [ + - ]: 2065 : std::vector<CAmount> tx_sigops{block_template->getTxSigops()};
848 : :
849 : 2065 : int i = 0;
850 [ + + ]: 4189 : for (const auto& it : block.vtx) {
851 [ + - ]: 2124 : const CTransaction& tx = *it;
852 : 2124 : uint256 txHash = tx.GetHash();
853 [ + - ]: 2124 : setTxIndex[txHash] = i++;
854 : :
855 [ + + ]: 2124 : if (tx.IsCoinBase())
856 : 2065 : continue;
857 : :
858 : 59 : UniValue entry(UniValue::VOBJ);
859 : :
860 [ + - + - : 118 : entry.pushKV("data", EncodeHexTx(tx));
+ - + - ]
861 [ + - + - : 118 : entry.pushKV("txid", txHash.GetHex());
+ - + - ]
862 [ + - + - : 118 : entry.pushKV("hash", tx.GetWitnessHash().GetHex());
+ - + - ]
863 : :
864 : 59 : UniValue deps(UniValue::VARR);
865 [ + + ]: 118 : for (const CTxIn &in : tx.vin)
866 : : {
867 [ + + ]: 59 : if (setTxIndex.count(in.prevout.hash))
868 [ + - + - : 6 : deps.push_back(setTxIndex[in.prevout.hash]);
+ - ]
869 : : }
870 [ + - + - ]: 118 : entry.pushKV("depends", std::move(deps));
871 : :
872 : 59 : int index_in_template = i - 1;
873 [ + - + - : 118 : entry.pushKV("fee", tx_fees.at(index_in_template));
+ - + - ]
874 [ + - ]: 59 : int64_t nTxSigOps{tx_sigops.at(index_in_template)};
875 [ + + ]: 59 : if (fPreSegWit) {
876 [ + - ]: 5 : CHECK_NONFATAL(nTxSigOps % WITNESS_SCALE_FACTOR == 0);
877 : 5 : nTxSigOps /= WITNESS_SCALE_FACTOR;
878 : : }
879 [ + - + - : 118 : entry.pushKV("sigops", nTxSigOps);
+ - ]
880 [ + - + - : 118 : entry.pushKV("weight", GetTransactionWeight(tx));
+ - ]
881 : :
882 [ + - ]: 59 : transactions.push_back(std::move(entry));
883 : 59 : }
884 : :
885 : 2065 : UniValue aux(UniValue::VOBJ);
886 : :
887 [ + - ]: 4130 : arith_uint256 hashTarget = arith_uint256().SetCompact(block.nBits);
888 : :
889 : 2065 : UniValue aMutable(UniValue::VARR);
890 [ + - + - ]: 2065 : aMutable.push_back("time");
891 [ + - + - ]: 2065 : aMutable.push_back("transactions");
892 [ + - + - ]: 2065 : aMutable.push_back("prevblock");
893 : :
894 : 2065 : UniValue result(UniValue::VOBJ);
895 [ + - + - ]: 4130 : result.pushKV("capabilities", std::move(aCaps));
896 : :
897 : 2065 : UniValue aRules(UniValue::VARR);
898 [ + - + - ]: 2065 : aRules.push_back("csv");
899 [ + + + - : 2065 : if (!fPreSegWit) aRules.push_back("!segwit");
+ - ]
900 [ + + ]: 2065 : if (consensusParams.signet_blocks) {
901 : : // indicate to miner that they must understand signet rules
902 : : // when attempting to mine with this template
903 [ + - + - ]: 1 : aRules.push_back("!signet");
904 : : }
905 : :
906 : 2065 : UniValue vbavailable(UniValue::VOBJ);
907 [ + + ]: 6195 : for (int j = 0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
908 : 4130 : Consensus::DeploymentPos pos = Consensus::DeploymentPos(j);
909 [ + - ]: 4130 : ThresholdState state = chainman.m_versionbitscache.State(pindexPrev, consensusParams, pos);
910 [ + + + + ]: 4130 : switch (state) {
911 : : case ThresholdState::DEFINED:
912 : : case ThresholdState::FAILED:
913 : : // Not exposed to GBT at all
914 : : break;
915 : 3 : case ThresholdState::LOCKED_IN:
916 : : // Ensure bit is set in block version
917 [ + - ]: 3 : block.nVersion |= chainman.m_versionbitscache.Mask(consensusParams, pos);
918 : 56 : [[fallthrough]];
919 : 56 : case ThresholdState::STARTED:
920 : 56 : {
921 : 56 : const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
922 [ + - + - : 112 : vbavailable.pushKV(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit);
+ - ]
923 [ + - + - ]: 56 : if (setClientRules.find(vbinfo.name) == setClientRules.end()) {
924 [ - + ]: 56 : if (!vbinfo.gbt_force) {
925 : : // If the client doesn't support this, don't indicate it in the [default] version
926 [ # # ]: 0 : block.nVersion &= ~chainman.m_versionbitscache.Mask(consensusParams, pos);
927 : : }
928 : : }
929 : : break;
930 : : }
931 : 4065 : case ThresholdState::ACTIVE:
932 : 4065 : {
933 : : // Add to rules only
934 : 4065 : const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
935 [ + - + - : 4065 : aRules.push_back(gbt_vb_name(pos));
+ - ]
936 [ + - + - ]: 4065 : if (setClientRules.find(vbinfo.name) == setClientRules.end()) {
937 : : // Not supported by the client; make sure it's safe to proceed
938 [ - + ]: 4065 : if (!vbinfo.gbt_force) {
939 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Support for '%s' rule requires explicit client support", vbinfo.name));
940 : : }
941 : : }
942 : : break;
943 : : }
944 : : }
945 : : }
946 [ + - + - : 4130 : result.pushKV("version", block.nVersion);
+ - ]
947 [ + - + - ]: 4130 : result.pushKV("rules", std::move(aRules));
948 [ + - + - ]: 4130 : result.pushKV("vbavailable", std::move(vbavailable));
949 [ + - + - : 4130 : result.pushKV("vbrequired", int(0));
+ - ]
950 : :
951 [ + - + - : 4130 : result.pushKV("previousblockhash", block.hashPrevBlock.GetHex());
+ - + - ]
952 [ + - + - ]: 4130 : result.pushKV("transactions", std::move(transactions));
953 [ + - + - ]: 4130 : result.pushKV("coinbaseaux", std::move(aux));
954 [ + - + - : 4130 : result.pushKV("coinbasevalue", (int64_t)block.vtx[0]->vout[0].nValue);
+ - ]
955 [ + - + - : 4130 : result.pushKV("longpollid", tip.GetHex() + ToString(nTransactionsUpdatedLast));
+ - + - +
- + - ]
956 [ + - + - : 4130 : result.pushKV("target", hashTarget.GetHex());
+ - + - ]
957 [ + - + - : 4130 : result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1);
+ - ]
958 [ + - + - ]: 4130 : result.pushKV("mutable", std::move(aMutable));
959 [ + - + - : 4130 : result.pushKV("noncerange", "00000000ffffffff");
+ - ]
960 : 2065 : int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST;
961 : 2065 : int64_t nSizeLimit = MAX_BLOCK_SERIALIZED_SIZE;
962 [ + + ]: 2065 : if (fPreSegWit) {
963 [ + - ]: 4 : CHECK_NONFATAL(nSigOpLimit % WITNESS_SCALE_FACTOR == 0);
964 : 4 : nSigOpLimit /= WITNESS_SCALE_FACTOR;
965 [ + - ]: 4 : CHECK_NONFATAL(nSizeLimit % WITNESS_SCALE_FACTOR == 0);
966 : 4 : nSizeLimit /= WITNESS_SCALE_FACTOR;
967 : : }
968 [ + - + - : 4130 : result.pushKV("sigoplimit", nSigOpLimit);
+ - ]
969 [ + - + - : 4130 : result.pushKV("sizelimit", nSizeLimit);
+ - ]
970 [ + + ]: 2065 : if (!fPreSegWit) {
971 [ + - + - : 4122 : result.pushKV("weightlimit", (int64_t)MAX_BLOCK_WEIGHT);
+ - ]
972 : : }
973 [ + - + - : 4130 : result.pushKV("curtime", block.GetBlockTime());
+ - ]
974 [ + - + - : 4130 : result.pushKV("bits", strprintf("%08x", block.nBits));
+ - + - ]
975 [ + - + - : 4130 : result.pushKV("height", (int64_t)(pindexPrev->nHeight+1));
+ - ]
976 : :
977 [ + + ]: 2065 : if (consensusParams.signet_blocks) {
978 [ + - + - : 2 : result.pushKV("signet_challenge", HexStr(consensusParams.signet_challenge));
+ - + - ]
979 : : }
980 : :
981 [ + - + - ]: 2065 : if (!block_template->getCoinbaseCommitment().empty()) {
982 [ + - + - : 4130 : result.pushKV("default_witness_commitment", HexStr(block_template->getCoinbaseCommitment()));
+ - + - +
- ]
983 : : }
984 : :
985 : 2065 : return result;
986 [ + - + - : 6337 : },
+ - ]
987 [ + - + - : 155215 : };
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + +
+ + + + +
+ + + - -
- - - - -
- - - ]
988 [ + - + - : 247505 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- - - - -
- - - - -
- ]
989 : :
990 : : class submitblock_StateCatcher final : public CValidationInterface
991 : : {
992 : : public:
993 : : uint256 hash;
994 : : bool found{false};
995 : : BlockValidationState state;
996 : :
997 : 25057 : explicit submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), state() {}
998 : :
999 : : protected:
1000 : 20096 : void BlockChecked(const CBlock& block, const BlockValidationState& stateIn) override {
1001 [ + + ]: 20096 : if (block.GetHash() != hash)
1002 : : return;
1003 : 20030 : found = true;
1004 : 20030 : state = stateIn;
1005 : : }
1006 : : };
1007 : :
1008 : 27174 : static RPCHelpMan submitblock()
1009 : : {
1010 : : // We allow 2 arguments for compliance with BIP22. Argument 2 is ignored.
1011 : 27174 : return RPCHelpMan{"submitblock",
1012 : : "\nAttempts to submit new block to network.\n"
1013 : : "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n",
1014 : : {
1015 [ + - ]: 27174 : {"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block data to submit"},
1016 [ + - ]: 54348 : {"dummy", RPCArg::Type::STR, RPCArg::DefaultHint{"ignored"}, "dummy value, for compatibility with BIP22. This value is ignored."},
1017 : : },
1018 : : {
1019 [ + - + - : 54348 : RPCResult{"If the block was accepted", RPCResult::Type::NONE, "", ""},
+ - + - ]
1020 [ + - + - : 54348 : RPCResult{"Otherwise", RPCResult::Type::STR, "", "According to BIP22"},
+ - + - ]
1021 : : },
1022 : 27174 : RPCExamples{
1023 [ + - + - : 54348 : HelpExampleCli("submitblock", "\"mydata\"")
+ - ]
1024 [ + - + - : 108696 : + HelpExampleRpc("submitblock", "\"mydata\"")
+ - + - ]
1025 [ + - ]: 27174 : },
1026 : 25058 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1027 : : {
1028 : 25058 : std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
1029 [ + - ]: 25058 : CBlock& block = *blockptr;
1030 [ + - + - : 25058 : if (!DecodeHexBlk(block, request.params[0].get_str())) {
+ - + + ]
1031 [ + - + - ]: 2 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
1032 : : }
1033 : :
1034 [ + - ]: 25057 : ChainstateManager& chainman = EnsureAnyChainman(request.context);
1035 : 25057 : {
1036 [ + - ]: 25057 : LOCK(cs_main);
1037 [ + - ]: 25057 : const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock);
1038 [ + + ]: 25057 : if (pindex) {
1039 [ + - ]: 25053 : chainman.UpdateUncommittedBlockStructures(block, pindex);
1040 : : }
1041 : 0 : }
1042 : :
1043 : 25057 : bool new_block;
1044 [ + - ]: 25057 : auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash());
1045 [ + - + - : 50114 : CHECK_NONFATAL(chainman.m_options.signals)->RegisterSharedValidationInterface(sc);
+ - ]
1046 [ + - + - : 50114 : bool accepted = chainman.ProcessNewBlock(blockptr, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/&new_block);
+ - ]
1047 [ + - + - : 50114 : CHECK_NONFATAL(chainman.m_options.signals)->UnregisterSharedValidationInterface(sc);
+ - ]
1048 [ + + + + ]: 25057 : if (!new_block && accepted) {
1049 [ + - ]: 4941 : return "duplicate";
1050 : : }
1051 [ + + ]: 20116 : if (!sc->found) {
1052 [ + - ]: 86 : return "inconclusive";
1053 : : }
1054 [ + - ]: 20030 : return BIP22ValidationResult(sc->state);
1055 [ + - ]: 50114 : },
1056 [ + - + - : 461958 : };
+ - + - +
- + - + -
+ - + - +
+ + + - -
- - ]
1057 [ + - + - : 217392 : }
+ - + - +
- + - - -
- - ]
1058 : :
1059 : 3838 : static RPCHelpMan submitheader()
1060 : : {
1061 : 3838 : return RPCHelpMan{"submitheader",
1062 : : "\nDecode the given hexdata as a header and submit it as a candidate chain tip if valid."
1063 : : "\nThrows when the header is invalid.\n",
1064 : : {
1065 [ + - ]: 3838 : {"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block header data"},
1066 : : },
1067 : 0 : RPCResult{
1068 [ + - + - : 7676 : RPCResult::Type::NONE, "", "None"},
+ - ]
1069 : 3838 : RPCExamples{
1070 [ + - + - : 7676 : HelpExampleCli("submitheader", "\"aabbcc\"") +
+ - ]
1071 [ + - + - : 11514 : HelpExampleRpc("submitheader", "\"aabbcc\"")
+ - + - ]
1072 [ + - ]: 3838 : },
1073 : 1722 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1074 : : {
1075 : 1722 : CBlockHeader h;
1076 [ + + ]: 1722 : if (!DecodeHexBlockHeader(h, request.params[0].get_str())) {
1077 [ + - + - ]: 4 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block header decode failed");
1078 : : }
1079 : 1720 : ChainstateManager& chainman = EnsureAnyChainman(request.context);
1080 : 1720 : {
1081 : 1720 : LOCK(cs_main);
1082 [ + - + + ]: 1720 : if (!chainman.m_blockman.LookupBlockIndex(h.hashPrevBlock)) {
1083 [ + - + - : 3 : throw JSONRPCError(RPC_VERIFY_ERROR, "Must submit previous header (" + h.hashPrevBlock.GetHex() + ") first");
+ - ]
1084 : : }
1085 : 1 : }
1086 : :
1087 [ + - ]: 1719 : BlockValidationState state;
1088 [ + - ]: 1719 : chainman.ProcessNewBlockHeaders({{h}}, /*min_pow_checked=*/true, state);
1089 [ + + ]: 1719 : if (state.IsValid()) return UniValue::VNULL;
1090 [ - + ]: 6 : if (state.IsError()) {
1091 [ # # # # ]: 0 : throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString());
1092 : : }
1093 [ + - + - ]: 12 : throw JSONRPCError(RPC_VERIFY_ERROR, state.GetRejectReason());
1094 : 1713 : },
1095 [ + - + - : 34542 : };
+ - + - +
- + - + +
- - ]
1096 [ + - + - ]: 11514 : }
1097 : :
1098 : 1183 : void RegisterMiningRPCCommands(CRPCTable& t)
1099 : : {
1100 : 1183 : static const CRPCCommand commands[]{
1101 : : {"mining", &getnetworkhashps},
1102 : : {"mining", &getmininginfo},
1103 : : {"mining", &prioritisetransaction},
1104 : : {"mining", &getprioritisedtransactions},
1105 : : {"mining", &getblocktemplate},
1106 : : {"mining", &submitblock},
1107 : : {"mining", &submitheader},
1108 : :
1109 : : {"hidden", &generatetoaddress},
1110 : : {"hidden", &generatetodescriptor},
1111 : : {"hidden", &generateblock},
1112 : : {"hidden", &generate},
1113 [ + + + - : 2236 : };
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - -
- ]
1114 [ + + ]: 14196 : for (const auto& c : commands) {
1115 : 13013 : t.appendCommand(c.name, &c);
1116 : : }
1117 : 1183 : }
|