3

I want to write fast RandomX verification in Python.

I'm using pybind11 and want to bind the C function rx_slow_hash:

void rx_slow_hash(const uint64_t mainheight, 
                  const uint64_t seedheight, const char *seedhash, 
                  const void *data, size_t length,
                  char *hash, int miners, int is_alt)

I'm writing code that will use the asyncio module. So I have a one process which performs tasks asynchronously and I do not want to allow this process to be blocked.

Due to my poor C/C++ knowledge I do not know how to use rx_slow_hash in my use case.

I will be grateful if I find answers to questions:

  1. What is the miners parameter for?
  2. Can I start several processes that will use the rx_slow_hash function?
  3. How exactly does verification work? For example, I have one process in which I will run verification with rx_slow_hash function with miners=1. Will this process create a separate thread for verification or will execution be blocked until verification is completed?

1 Answer 1

2
  1. What is the miners parameter for?

How many threads to use for dataset initialization. Also it signals the intent to use full memory mode (for fast mining).

  1. Can I start several processes that will use the rx_slow_hash function?

Of course.

  1. How exactly does verification work?

Verification is just that, verification. Supply the same data, height and seed hash, create the hash, does it equal the same as the hash you are verifying. For verifying, you are only creating one hash (per verification required); mining you are repeatedly creating lots of hashes until you find one that meets the current network difficulty (i.e. you are mining). So unless you are trying to perform lots of different verifications, miners=0 will be fine. This would then limit memory requirements to 256 MiB (light mode). If you need to do lots of fast verifications you can use miners=<number of processors> which will attempt to use full memory, 2080 MiB, fast mode.

For example, I have one process in which I will run verification with rx_slow_hash function with miners=1. Will this process create a separate thread for verification or will execution be blocked until verification is completed?

It will create 1 thread for the dataset initialization. After initialization, your calling thread will block whilst creating the hash.

4
  • 2. But how will running in several processes affect the consumption of RAM? if i don't use a huge pages in my pc.
    – Andrei
    Commented Apr 30, 2020 at 18:14
  • 1
    RAM consumption and huge pages are separate things. Huge pages doesn't affect how much RAM you use directly, it specifies the page size you intend to use. Clearly if you run >1 processes with RX full memory mode, you will need 2080 MiB RAM per process. And this is pointless unless you have >1 NUMA nodes.
    – jtgrassie
    Commented Apr 30, 2020 at 18:18
  • 1
    Thanks so much for the answers! This is what I needed!
    – Andrei
    Commented Apr 30, 2020 at 18:19
  • No problem. github.com/jtgrassie/pyrx might help get you started.
    – jtgrassie
    Commented Apr 30, 2020 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.