WIP to change rx key+input for groups of blocks; use full ac_name in rx key
This commit is contained in:
@@ -1134,36 +1134,45 @@ void static RandomXMiner()
|
|||||||
hashTarget = HASHTarget;
|
hashTarget = HASHTarget;
|
||||||
|
|
||||||
char randomxHash[RANDOMX_HASH_SIZE];
|
char randomxHash[RANDOMX_HASH_SIZE];
|
||||||
// Initial randomx key is chain magic + first letter of chain name which is 2^40 bits of entropy
|
// Initial randomx key is chain magic || ac_name which is >= 2^40 bits of entropy assuming strlen(ac_name) >= 1
|
||||||
char randomxKey[5];
|
// For ac_name=DRAGONX we have 4 + 7 = 11 bytes or 2^88 bits of entropy
|
||||||
|
char randomxKey[4 + strlen(SMART_CHAIN_SYMBOL)];
|
||||||
randomxKey[0] = ASSETCHAINS_MAGIC & 0xff;
|
randomxKey[0] = ASSETCHAINS_MAGIC & 0xff;
|
||||||
randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff;
|
randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff;
|
||||||
randomxKey[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff;
|
randomxKey[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff;
|
||||||
randomxKey[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff;
|
randomxKey[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff;
|
||||||
randomxKey[4] = SMART_CHAIN_SYMBOL[0];
|
|
||||||
|
for(int i=0; i++; i<strlen(SMART_CHAIN_SYMBOL) ) {
|
||||||
|
randomxKey[4+i] = SMART_CHAIN_SYMBOL[i];
|
||||||
|
}
|
||||||
|
|
||||||
crypto_generichash_blake2b_state state;
|
crypto_generichash_blake2b_state state;
|
||||||
// Hash = blake2b( key || ac_name)
|
// Hash = blake2b( key || ac_name)
|
||||||
crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxKey[0], 5);
|
crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxKey[0], 4 + strlen(SMART_CHAIN_SYMBOL));
|
||||||
crypto_generichash_blake2b_update(&state, (unsigned char*)&SMART_CHAIN_SYMBOL[0], strlen(SMART_CHAIN_SYMBOL));
|
crypto_generichash_blake2b_update(&state, (unsigned char*)&SMART_CHAIN_SYMBOL[0], strlen(SMART_CHAIN_SYMBOL));
|
||||||
uchar randomxInput[32];
|
uchar randomxInput[32];
|
||||||
crypto_generichash_blake2b_final(&state, randomxInput, 32);
|
crypto_generichash_blake2b_final(&state, randomxInput, 32);
|
||||||
|
|
||||||
randomx_flags flags = randomx_get_flags();
|
randomx_flags flags = randomx_get_flags();
|
||||||
randomx_cache *randomxCache = randomx_alloc_cache(flags);
|
randomx_cache *randomxCache = randomx_alloc_cache(flags);
|
||||||
|
|
||||||
if(Mining_height > 1024 && (Mining_height % 1024 == 64)) {
|
|
||||||
// At block height 1024*N+64 we should use the blockhash of block 1024*N as key
|
|
||||||
// use blockchain data to set a new key+input for a group of blocks
|
|
||||||
// randomxKey = ...
|
|
||||||
// randomxInput = ...
|
|
||||||
}
|
|
||||||
|
|
||||||
if (randomxCache == NULL) {
|
if (randomxCache == NULL) {
|
||||||
LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n");
|
LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: use same block key for groups of blocks
|
||||||
|
if(Mining_height > 1024 && (Mining_height % 1024 == 64)) {
|
||||||
|
// At block height 1024*N+64 we should use the blockhash of block 1024*N as randomx key
|
||||||
|
// use blockchain data to set a new key+input for a group of blocks
|
||||||
|
uint256 randomxBlockKey;
|
||||||
|
randomxBlockKey = chainActive[Mining_height - 64]->GetBlockHash();
|
||||||
|
crypto_generichash_blake2b_state new_state;
|
||||||
|
crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxBlockKey, 32);
|
||||||
|
crypto_generichash_blake2b_final(&state, randomxInput, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use correct variables
|
||||||
randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey);
|
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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user