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?
jtgrassie
  • 19,601
  • 4
  • 17
  • 54
Andrei
  • 367
  • 1
  • 9

1 Answers1

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.

jtgrassie
  • 19,601
  • 4
  • 17
  • 54