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