What changed, and why it matters
This commit adds a new developer/testing command called `generate_blocks` that lets a Monero daemon operator quickly create blocks in 'regtest' mode (a local-only test mode). It does not change normal mainnet or testnet behavior. The command is only useful for testing and is not a security fix or a vulnerability.
No security action required. Treat as a normal feature/testability merge. If deploying a daemon with this build, ensure regtest mode remains disabled in production configurations as per existing operational practice.
Security signals we found
No security-relevant signals in the diff
New command is regtest-only per its own help text
No changes to authentication, authorization, or network listeners
No changes to consensus, cryptography, or transaction validation
Evidence from the diff
The patch exposes the existing RPC generateblocks as an interactive daemon CLI command (generate_blocks <addr> <numblocks> [<starting_nonce>]). It adds parser/executor plumbing, a command-server handler, and a functional test. The command is gated by the daemon’s regtest-only context and uses the existing RPC handler. No new network exposure, privilege changes, or consensus logic are introduced.
Changed components
src/daemon/command_parser_executor.cppsrc/daemon/command_parser_executor.hsrc/daemon/command_server.cppsrc/daemon/rpc_command_executor.cppsrc/daemon/rpc_command_executor.htests/functional_tests/blockchain.pyInspect captured patch +92 / −0
### src/daemon/command_parser_executor.cpp
@@ -494,6 +494,31 @@ bool t_command_parser_executor::stop_mining(const std::vector<std::string>& args
return m_executor.stop_mining();
}
+bool t_command_parser_executor::generate_blocks(const std::vector<std::string>& args)
+{
+ if (args.size() < 2 || args.size() > 3)
+ {
+ std::cout << "Invalid syntax: Expected an address, number of blocks, and optional starting nonce. For more details, use the help command." << std::endl;
+ return true;
+ }
+
+ uint64_t amount = 0;
+ if (!epee::string_tools::get_xtype_from_string(amount, args[1]) || amount == 0)
+ {
+ std::cout << "Invalid syntax: Wrong number of blocks. For more details, use the help command." << std::endl;
+ return true;
+ }
+
+ uint32_t starting_nonce = 0;
+ if (args.size() == 3 && !epee::string_tools::get_xtype_from_string(starting_nonce, args[2]))
+ {
+ std::cout << "Invalid syntax: Wrong starting nonce. For more details, use the help command." << std::endl;
+ return true;
+ }
+
+ return m_executor.generate_blocks(args[0], amount, starting_nonce);
+}
+
bool t_command_parser_executor::mining_status(const std::vector<std::string>& args)
{
return m_executor.mining_status();
### src/daemon/command_parser_executor.h
@@ -98,6 +98,8 @@ class t_command_parser_executor final
bool stop_mining(const std::vector<std::string>& args);
+ bool generate_blocks(const std::vector<std::string>& args);
+
bool mining_status(const std::vector<std::string>& args);
bool stop_daemon(const std::vector<std::string>& args);
### src/daemon/command_server.cpp
@@ -124,6 +124,12 @@ t_command_server::t_command_server(
, std::bind(&t_command_parser_executor::stop_mining, &m_parser, p::_1)
, "Stop mining."
);
+ m_command_lookup.set_handler(
+ "generate_blocks"
+ , std::bind(&t_command_parser_executor::generate_blocks, &m_parser, p::_1)
+ , "generate_blocks <addr> <numblocks> [<starting_nonce>]"
+ , "Generate blocks for the specified address in regtest mode."
+ );
m_command_lookup.set_handler(
"mining_status"
, std::bind(&t_command_parser_executor::mining_status, &m_parser, p::_1)
### src/daemon/rpc_command_executor.cpp
@@ -1388,6 +1388,33 @@ bool t_rpc_command_executor::stop_mining() {
return true;
}
+bool t_rpc_command_executor::generate_blocks(const std::string& address, uint64_t amount, uint32_t starting_nonce)
+{
+ cryptonote::COMMAND_RPC_GENERATEBLOCKS::request req;
+ cryptonote::COMMAND_RPC_GENERATEBLOCKS::response res;
+ epee::json_rpc::error error_resp;
+ req.wallet_address = address;
+ req.amount_of_blocks = amount;
+ req.starting_nonce = starting_nonce;
+
+ const std::string fail_message = "Failed to generate blocks";
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->json_rpc_request(req, res, "generateblocks", fail_message))
+ return true;
+ }
+ else if (!m_rpc_server->on_generateblocks(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
+ {
+ tools::fail_msg_writer() << (error_resp.message.empty() ? make_error(fail_message, res.status) : error_resp.message);
+ return true;
+ }
+
+ tools::success_msg_writer() << "Generated " << res.blocks.size()
+ << (res.blocks.size() == 1 ? " block" : " blocks")
+ << ", last block height " << res.height;
+ return true;
+}
+
bool t_rpc_command_executor::stop_daemon()
{
cryptonote::COMMAND_RPC_STOP_DAEMON::request req;
### src/daemon/rpc_command_executor.h
@@ -110,6 +110,8 @@ class t_rpc_command_executor final {
bool stop_mining();
+ bool generate_blocks(const std::string& address, uint64_t amount, uint32_t starting_nonce);
+
bool mining_status();
bool stop_daemon();
### tests/functional_tests/blockchain.py
@@ -29,6 +29,8 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+import os
+import subprocess
import time
"""Test daemon blockchain RPC calls
@@ -47,6 +49,8 @@
class BlockchainTest():
def run_test(self):
+ self.reset()
+ self._test_generate_blocks_command()
self.reset()
self._test_generateblocks(5)
self._test_alt_chains()
@@ -59,6 +63,32 @@ def reset(self):
daemon.pop_blocks(res.height - 1)
daemon.flush_txpool()
+ def _test_generate_blocks_command(self):
+ print('Test generating blocks with the daemon command')
+ daemon = Daemon()
+ address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
+ build_dir = os.path.dirname(os.path.dirname(os.environ['FUNCTIONAL_TESTS_DIRECTORY']))
+ monerod = os.path.join(build_dir, 'bin', 'monerod')
+
+ def run_command(*args):
+ return subprocess.run([monerod, '--rpc-bind-port', '18180', '--rpc-ssl', 'disabled', 'generate_blocks', address, *args],
+ capture_output = True, text = True, timeout = 120)
+
+ height = daemon.get_height().height
+ for args in [('1',), ('1', '1000000000')]:
+ result = run_command(*args)
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert 'Generated 1 block' in result.stdout, result.stdout + result.stderr
+ height += 1
+ assert daemon.get_height().height == height
+ if len(args) == 2:
+ assert daemon.getblockheaderbyheight(height - 1).block_header.nonce >= 1000000000
+
+ for args in [('1x',), ('1', '4294967296')]:
+ result = run_command(*args)
+ assert 'Invalid syntax' in result.stdout, result.stdout + result.stderr
+ assert daemon.get_height().height == height
+
def _check_blocktemplate_reserved_offset(self, daemon, address, reserve_size):
res = daemon.getblocktemplate(address, reserve_size = reserve_size)
assert res.reserved_offset > 0Why this scored 23/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.