monero-ecosystem / monero-python

A comprehensive Python module for handling Monero cryptocurrency
BSD 3-Clause "New" or "Revised" License
245 stars 79 forks source link

generate blocks rpc commands #118

Closed euri10 closed 1 year ago

euri10 commented 2 years ago

I was not able to find the rpc command generate_blocks see https://github.com/monero-project/monero/blob/9a124f681119855949f6406ecd69c2ad91da9770/utils/python-rpc/framework/daemon.py#L213-L226

I think I can hack it using the raw_jsonrpc_request method but would you accept a PR that adds it ?

emesik commented 2 years ago

Is it documented anywhere? I don't see it at https://www.getmonero.org/resources/developer-guides/daemon-rpc.html

Anyway, you may just inherit and extend the monero.backends.jsonrpc.daemon.JSONRPCDaemon class to add such method.

euri10 commented 2 years ago

I dont think it is documented, it apparently can only be used with the regtest flag, hence my other issue opened.

for the backgroupnd I'm trying to setup a fixture that spawn a private testnet that mines faster, and this discussion on irc led me to both regtest and generate_blocks

<euri10> Greetings, I'm currently using monero-python and I have questions about the way people test their code when it deals with monero. 
<euri10> So far I have setup a private test network in a container, that runs 2 daemons, and creates 2 wallets with deterministic adresses, and uses a low difficulty.
<euri10> My test suite then setup a pytest fixture that runs the container, starts mining on one of the 2 addresses, waits for the wallet to have enough xmr to spend.
<euri10> The "issue" I'm facing is the following: mining takes time. Afaik the first mined xmr becomes available only at height 60, is it something I can tweak to increase speed ?
<euri10> Another question is : can I mine up to a given height and stop mining once reached ? I didn't see an rpc command parameter for that (up to x height)
<euri10> But after I made all those questions, I'm reaching that point where I'm just wondering if integrated testing is the way to go and if I should not mock the various monero part I'm interested in interacting with.
<euri10> thanks for the read !
<sech1> euri10 use --fixed-difficulty parameter for monerod to mine faster
<euri10> yep already set at 1
<sech1> then it should be very fast to mine 60 blocks
<moneromooo> There's a generate_blocks RPC, you tell it how many blocks to mine. See tests/functional_tests.
<moneromooo> Also, set MONERO_FASTER_POW=1 if you don't care about verifying the PoW from another program. It'll use keccak IIRC.
<moneromooo> Ah nvm that never got merged. You can apply it from my "crash" branch if you don't mind running a slightly patched daemon.
<euri10> ok ok :) good infos here, will definitely check that
<moneromooo> https://git.townforge.net/townforge/townforge/commit/d8e4f4078598221a2f7320564a507c9d5bbce6a3 is the one with keccak, it doesn't seem to be in my crash branch. Should be easy to merge.
<moneromooo> Also, generate_blocks only works in regtest mode for some reason, but I doubt that'll be a problem here.
<euri10> what is regtest mode ?
<moneromooo> A global state set by --regtest IIRC, which enables that and a "delete chain before we start".
<euri10> ok ok, with all that hopefully I can speed up my test suite, many thanks
<moneromooo> Which made me add a --keep-fake-chain because useful, especially to investigate when stuff went wrong. So not sure why this mode exists in the first place.
<euri10> @moneromooo as soon as I add the regtest flag to the daemon command, it seems the daemon is not accepting rpc connections anymore, is that possible ? I raised an issue here, maybe you have better insights: https://github.com/monero-ecosystem/monero-python/issues/117