Set a rolling randomx block key
This commit is contained in:
@@ -1161,19 +1161,30 @@ void static RandomXMiner()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: use same block key for groups of blocks
|
// TODO: we may want to tweak these params to more closely match the 2.8 days and ~2 hrs
|
||||||
if(Mining_height > 1024 && (Mining_height % 1024 == 64)) {
|
// which is what they work out to on XMR
|
||||||
// At block height 1024*N+64 we should use the blockhash of block 1024*N as randomx key
|
// The key block will change every ~21.3 hours with a 75s block time
|
||||||
// use blockchain data to set a new key+input for a group of blocks
|
// and every ~17 hours with the default 60s block time for HSCs
|
||||||
uint256 randomxBlockKey;
|
int randomxInterval = 1024;
|
||||||
randomxBlockKey = chainActive[Mining_height - 64]->GetBlockHash();
|
// This lag is 80 mins for 75s blocktime and 64 mins for 60s (default) blocktime for HSCs
|
||||||
|
int randomxBlockLag = 64;
|
||||||
|
|
||||||
|
// Use the initial key at the start of the chain
|
||||||
|
if( (Mining_height-randomxBlockLag) < randomxInterval) {
|
||||||
|
LogPrintf("RandomX using initial key\n");
|
||||||
|
randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey);
|
||||||
|
} else {
|
||||||
|
// At heights between intervals, we use the same block key and wait randomxBlockLag blocks until changing
|
||||||
|
int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval;
|
||||||
|
LogPrintf("RandomX key height=%d\n", keyHeight);
|
||||||
|
uint256 randomxBlockKey = chainActive[keyHeight]->GetBlockHash();
|
||||||
crypto_generichash_blake2b_state new_state;
|
crypto_generichash_blake2b_state new_state;
|
||||||
crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxBlockKey, 32);
|
crypto_generichash_blake2b_update(&state, (unsigned char *)&randomxBlockKey, 32);
|
||||||
crypto_generichash_blake2b_final(&state, randomxInput, 32);
|
crypto_generichash_blake2b_final(&state, randomxInput, 32);
|
||||||
|
|
||||||
|
randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use correct variables
|
|
||||||
randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey);
|
|
||||||
randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL);
|
randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL);
|
||||||
if(myVM == NULL) {
|
if(myVM == NULL) {
|
||||||
LogPrintf("Cannot create RandomX VM, aborting!\n");
|
LogPrintf("Cannot create RandomX VM, aborting!\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user