Coverage for tests/utils/block_generation.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 19:49 +0000

1from monero import MoneroDaemon 

2 

3MAX_GENERATE_DIFFICULTY: int = 100 

4"""Highest difficulty at which blocks are generated instead of mined. 

5 

6`generateblocks` hashes with one thread in the light mode of RandomX, about 75 hashes per second, so a block takes difficulty / 75 seconds 

7(0.04 s at difficulty 1, 6.7 s at 500). The miner of the daemon hashes with the full dataset and is much faster: at a high difficulty 

8mining makes the blocks sooner, at a low one it makes dozens while the tests sleep, and the chain grows past what they want. 

9""" 

10 

11 

12def is_generation_fast(daemon: MoneroDaemon) -> bool: 

13 """Indicates if the daemon generates blocks faster than it mines them: a regtest daemon with a low difficulty. 

14 

15 :param MoneroDaemon daemon: daemon to ask the difficulty of. 

16 :returns bool: `True` if blocks should be generated, `False` if they should be mined. 

17 """ 

18 try: 

19 info = daemon.get_info() 

20 difficulty: int = (info.difficulty_high or 0) << 64 | (info.difficulty_low or 0) 

21 return info.is_regtest is not False and 0 < difficulty <= MAX_GENERATE_DIFFICULTY 

22 except Exception: 

23 return False