avoid coredump by hardcoding some things
This commit is contained in:
@@ -1146,24 +1146,31 @@ void static RandomXMiner()
|
||||
fprintf(stderr,"RandomXMiner: created randomxHash of size %d\n", RANDOMX_HASH_SIZE);
|
||||
// Initial randomx key is chain magic || ac_name which is >= 2^40 bits of entropy assuming strlen(ac_name) >= 1
|
||||
// For ac_name=DRAGONX we have 4 + 7 = 11 bytes or 2^88 bits of entropy
|
||||
char randomxKey[4 + strlen(SMART_CHAIN_SYMBOL)];
|
||||
fprintf(stderr,"RandomXMiner: creating randomxKey of size %d\n", 4 + strlen(SMART_CHAIN_SYMBOL));
|
||||
//int randomxKeySize = sizeof(randomxKey); // 4 + strlen(SMART_CHAIN_SYMBOL)];
|
||||
char randomxKey[] = "RANDOMX";
|
||||
//fprintf(stderr,"RandomXMiner: creating randomxKey of size %d\n", randomxKeySize);
|
||||
/*
|
||||
randomxKey[0] = ASSETCHAINS_MAGIC & 0xff;
|
||||
randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff;
|
||||
randomxKey[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff;
|
||||
randomxKey[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff;
|
||||
|
||||
|
||||
for(int i=0; i++; i<strlen(SMART_CHAIN_SYMBOL) ) {
|
||||
randomxKey[4+i] = SMART_CHAIN_SYMBOL[i];
|
||||
fprintf(stderr,"RandomXMiner: added %s to randomxKey\n", SMART_CHAIN_SYMBOL[i]);
|
||||
}
|
||||
fprintf(stderr,"RandomXMiner: created randomxKey=%s\n", randomxKey);
|
||||
*/
|
||||
|
||||
crypto_generichash_blake2b_state state;
|
||||
// Hash = blake2b( key || ac_name)
|
||||
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));
|
||||
uchar randomxInput[32];
|
||||
crypto_generichash_blake2b_final(&state, randomxInput, 32);
|
||||
//crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxKey[0], sizeof(randomxKey));
|
||||
//crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxKey[0], 4 + strlen(SMART_CHAIN_SYMBOL) + 1);
|
||||
//crypto_generichash_blake2b_update(&state, (unsigned char*)&SMART_CHAIN_SYMBOL[0], sizeof(SMART_CHAIN_SYMBOL));
|
||||
//uchar randomxInput[32];
|
||||
//crypto_generichash_blake2b_final(&state, randomxInput, 32);
|
||||
unsigned char randomxInput[] = "RANDOMX";
|
||||
fprintf(stderr,"RandomXMiner: created randomxInput\n");
|
||||
|
||||
randomx_flags flags = randomx_get_flags();
|
||||
randomx_cache *randomxCache = randomx_alloc_cache(flags);
|
||||
@@ -1179,20 +1186,23 @@ void static RandomXMiner()
|
||||
// This lag is 80 mins for 75s blocktime and 64 mins for 60s (default) blocktime for HSCs
|
||||
int randomxBlockLag = 64;
|
||||
|
||||
fprintf(stderr,"RandomX using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag);
|
||||
fprintf(stderr,"RandomXMiner: Mining_height=%u\n", Mining_height);
|
||||
// Use the initial key at the start of the chain
|
||||
if( (Mining_height-randomxBlockLag) < randomxInterval) {
|
||||
fprintf(stderr,"RandomX using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag);
|
||||
if( (Mining_height) < randomxInterval + randomxBlockLag) {
|
||||
randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey);
|
||||
fprintf(stderr,"RandomXMiner: initialized cache with initial key\n");
|
||||
} 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);
|
||||
fprintf(stderr,"RandomXMiner: key height=%d\n", keyHeight);
|
||||
uint256 randomxBlockKey = chainActive[keyHeight]->GetBlockHash();
|
||||
crypto_generichash_blake2b_state new_state;
|
||||
crypto_generichash_blake2b_update(&state, (unsigned char *)&randomxBlockKey, 32);
|
||||
crypto_generichash_blake2b_final(&state, randomxInput, 32);
|
||||
|
||||
randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxKey);
|
||||
fprintf(stderr,"RandomXMiner: initialized cache\n");
|
||||
}
|
||||
|
||||
randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL);
|
||||
@@ -1200,10 +1210,13 @@ void static RandomXMiner()
|
||||
LogPrintf("Cannot create RandomX VM, aborting!\n");
|
||||
return;
|
||||
}
|
||||
fprintf(stderr,"RandomXMiner: created VM\n");
|
||||
|
||||
randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash);
|
||||
fprintf(stderr,"RandomXMiner: calculated randomx hash\n");
|
||||
|
||||
randomx_destroy_vm(myVM);
|
||||
fprintf(stderr,"RandomXMiner: destroyed VM\n");
|
||||
randomx_release_cache(randomxCache);
|
||||
|
||||
printf("RandomX Hash: ");
|
||||
|
||||
Reference in New Issue
Block a user