25
25
#include < shutdown.h>
26
26
#include < timedata.h>
27
27
#include < util.h>
28
+ #include < miner.h>
28
29
#include < utilmoneystr.h>
29
30
#include < wallet/coincontrol.h>
30
31
#include < wallet/feebumper.h>
@@ -4449,11 +4450,21 @@ UniValue generatecontinuous(const JSONRPCRequest& request)
4449
4450
return NullUniValue;
4450
4451
}
4451
4452
4452
- if (request.fHelp || request.params .size () > 2 ) {
4453
+ if (request.fHelp || request.params .size () > 3 ) {
4453
4454
throw std::runtime_error (
4454
- " generatecontinuous (true|false ) (threads )\n "
4455
+ " generatecontinuous <activate> (threads ) (override )\n "
4455
4456
" \n Mine blocks continuously while the request is running.\n "
4456
- " \n (note for Randomx, any value under 4 will use 4 threads)\n "
4457
+ " \n Arguments:\n "
4458
+ " 1. activate (boolean, required) Enable or disable mining\n "
4459
+ " 2. threads (int, required) for enabling, number of threads\n "
4460
+ " 3. override (boolean, optional) override thread warnings\n "
4461
+ " \n Result:\n "
4462
+ " {\n "
4463
+ " \" success\" : true|false, (boolean) Status of the request\n "
4464
+ " \" algorithm\" : \" string\" , (string) Algorithm being mined\n "
4465
+ " \" threads\" : nnn, (int) Number of threads being used\n "
4466
+ " \" message\" : \" text\" , (string) Informational message\n "
4467
+ " }\n "
4457
4468
" \n Examples:\n "
4458
4469
+ HelpExampleCli (" generatecontinuous" , " true 4" )
4459
4470
+ HelpExampleRpc (" generateoontinuous" , " true, 4" )
@@ -4470,20 +4481,64 @@ UniValue generatecontinuous(const JSONRPCRequest& request)
4470
4481
if (request.params .size () > 1 )
4471
4482
nThreads = request.params [1 ].get_int ();
4472
4483
4484
+ bool fOverride = false ;
4485
+ if (request.params .size () > 2 )
4486
+ fOverride = request.params [2 ].get_bool ();
4487
+
4473
4488
std::shared_ptr<CReserveScript> coinbase_script;
4474
4489
pwallet->GetScriptForMining (coinbase_script);
4475
4490
4476
4491
// If the keypool is exhausted, no script is returned at all. Catch this.
4477
4492
if (!coinbase_script) {
4478
- throw JSONRPCError (RPC_WALLET_KEYPOOL_RAN_OUT, " Error: Keypool ran out, please call keypoolrefill first" );
4493
+ throw JSONRPCError (RPC_WALLET_KEYPOOL_RAN_OUT,
4494
+ " Error: Keypool ran out, please call keypoolrefill first" );
4479
4495
}
4480
4496
4481
4497
// throw an error if no script was provided
4482
4498
if (coinbase_script->reserveScript .empty ()) {
4483
4499
throw JSONRPCError (RPC_INTERNAL_ERROR, " No coinbase script available" );
4484
4500
}
4485
4501
4486
- return generateBlocks (fGenerate , nThreads, coinbase_script);
4502
+ int nAlgo = GetMiningAlgorithm ();
4503
+ std::string sAlgo = GetMiningType (nAlgo, false , false );
4504
+ std:string sWarning = " " ;
4505
+
4506
+ if (fGenerate ) {
4507
+ if (GenerateActive ())
4508
+ throw JSONRPCError (RPC_INTERNAL_ERROR, " Mining already active" );
4509
+
4510
+ int nCores = GetNumCores ();
4511
+ if ((nAlgo == MINE_SHA256D) && (nThreads > (nCores - 1 )))
4512
+ sWarning = strprintf (" Available cores: %d, limit sha256d to %d threads" ,
4513
+ nCores, nCores-1 );
4514
+
4515
+ if ((nAlgo == MINE_RANDOMX) && (nThreads < 4 )) {
4516
+ sWarning = " RandomX must be at least 4 threads" ;
4517
+ // Note this changes the nThreads input, for accuracy of the result
4518
+ // message, So this check needs to be below the threads check above
4519
+ nThreads = 4 ;
4520
+ }
4521
+
4522
+ if (!fOverride && sWarning .compare (" " ))
4523
+ throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Error: %s" , sWarning .c_str ()));
4524
+ }
4525
+
4526
+ UniValue result (UniValue::VOBJ);
4527
+ result.pushKV (" success" , true );
4528
+ result.pushKV (" algorithm" , sAlgo );
4529
+ if (!fGenerate ) {
4530
+ result.pushKV (" threads" , 0 );
4531
+ result.pushKV (" message" , " Mining stopped" );
4532
+ } else {
4533
+ result.pushKV (" threads" , nThreads);
4534
+ if (sWarning .compare (" " ))
4535
+ result.pushKV (" message" , strprintf (" Warning: %s" , sWarning .c_str ()));
4536
+ else
4537
+ result.pushKV (" message" , " Mining started" );
4538
+ }
4539
+
4540
+ generateBlocks (fGenerate , nThreads, coinbase_script);
4541
+ return result;
4487
4542
}
4488
4543
4489
4544
UniValue rescanblockchain (const JSONRPCRequest& request)
0 commit comments