Use RANDOMX_FLAG_FULL_MEM
This commit is contained in:
@@ -1065,6 +1065,23 @@ void static RandomXMiner()
|
||||
cancelSolver = true;
|
||||
}
|
||||
);
|
||||
randomx_flags flags = randomx_get_flags();
|
||||
// flags |= RANDOMX_FLAG_LARGE_PAGES;
|
||||
flags |= RANDOMX_FLAG_FULL_MEM;
|
||||
//flags |= RANDOMX_FLAG_JIT;
|
||||
randomx_cache *randomxCache = randomx_alloc_cache(flags);
|
||||
if (randomxCache == NULL) {
|
||||
LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n");
|
||||
return;
|
||||
}
|
||||
rxdebug("%s: created randomx flags + cache\n");
|
||||
|
||||
randomx_dataset *randomxDataset = randomx_alloc_dataset(flags);
|
||||
rxdebug("%s: created dataset\n");
|
||||
if( randomxDataset == nullptr) {
|
||||
LogPrintf("%s: allocating randomx dataset failed!\n", __func__);
|
||||
return;
|
||||
}
|
||||
miningTimer.start();
|
||||
|
||||
try {
|
||||
@@ -1181,8 +1198,8 @@ void static RandomXMiner()
|
||||
HASHTarget = arith_uint256().SetCompact(savebits);
|
||||
roundrobin_delay = ROUNDROBIN_DELAY;
|
||||
Mining_start = 0;
|
||||
|
||||
gotinvalid = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if ( gotinvalid != 0 ) {
|
||||
@@ -1199,7 +1216,7 @@ void static RandomXMiner()
|
||||
char randomxHash[RANDOMX_HASH_SIZE];
|
||||
//fprintf(stderr,"RandomXMiner: created randomxHash of size %d\n", RANDOMX_HASH_SIZE);
|
||||
char randomxKey[82]; // randomx spec says keysize of >60 bytes is implementation-specific
|
||||
// initial randomx key is unique to every Hush Smart Chain, and has at least 9 bytes (2^128 bits) of entropy
|
||||
// initial randomx key is unique to every Hush Smart Chain, and has at least 9 bytes (2^9=128 bits) of entropy
|
||||
// since magic is 4 bytes, rpc port is 4 bytes and smart chain symbol must be at least 1 character long
|
||||
snprintf(randomxKey, 81, "%08x%s%08x", ASSETCHAINS_MAGIC, SMART_CHAIN_SYMBOL, ASSETCHAINS_RPCPORT);
|
||||
|
||||
@@ -1211,14 +1228,6 @@ void static RandomXMiner()
|
||||
// fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput.size=%lu\n", randomxKey, randomxInput.size() ); //randomxInput);
|
||||
rxdebug("%s: randomxKey=%s randomxInput=%s\n", randomxKey, HexStr(randomxInput).c_str());
|
||||
|
||||
randomx_flags flags = randomx_get_flags();
|
||||
randomx_cache *randomxCache = randomx_alloc_cache(flags);
|
||||
if (randomxCache == NULL) {
|
||||
LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n");
|
||||
return;
|
||||
}
|
||||
// fprintf(stderr,"RandomXMiner: created randomx flags + cache\n");
|
||||
|
||||
// With the defaults of 1024 and 64
|
||||
// the key block will change every ~21.3 hours with a 75s block time
|
||||
// and every ~17 hours with the default 60s block time for HSCs
|
||||
@@ -1240,20 +1249,31 @@ void static RandomXMiner()
|
||||
|
||||
randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxBlockKey);
|
||||
rxdebug("%s: initialized cache with keyHeight=%d, randomxBlockKey=%s\n", keyHeight, randomxBlockKey.ToString().c_str());
|
||||
|
||||
}
|
||||
|
||||
randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL);
|
||||
if(myVM == NULL) {
|
||||
LogPrintf("RandomXMiner: Cannot create RandomX VM, aborting!\n");
|
||||
return;
|
||||
}
|
||||
//TODO: this is hardcoded to use 2 threads instead of the number of mining threads
|
||||
//std::thread t1(&randomx_init_dataset, randomxDataset, randomxCache, 0, datasetItemCount / 2);
|
||||
//std::thread t2(&randomx_init_dataset, randomxDataset, randomxCache, datasetItemCount / 2, datasetItemCount - datasetItemCount / 2);
|
||||
//t1.join();
|
||||
//t2.join();
|
||||
auto datasetItemCount = randomx_dataset_item_count();
|
||||
rxdebug("%s: dataset items=%lu\n", datasetItemCount);
|
||||
|
||||
randomx_init_dataset(randomxDataset, randomxCache, 0, datasetItemCount);
|
||||
rxdebug("%s: dataset initialized\n");
|
||||
// randomx_release_cache(randomxCache);
|
||||
// rxdebug("%s: cache released\n");
|
||||
|
||||
randomx_vm *myVM = randomx_create_vm(flags, nullptr, randomxDataset);
|
||||
if(myVM == NULL) {
|
||||
LogPrintf("RandomXMiner: Cannot create RandomX VM, aborting!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash);
|
||||
// rxdebug("calculated randomx hash\n");
|
||||
|
||||
randomx_destroy_vm(myVM);
|
||||
// fprintf(stderr,"RandomXMiner: destroyed VM\n");
|
||||
randomx_release_cache(randomxCache);
|
||||
rxdebug("%s: calculated randomx hash\n");
|
||||
|
||||
rxdebug("%s: randomxHash=");
|
||||
if (fRandomXDebug) {
|
||||
@@ -1263,6 +1283,9 @@ void static RandomXMiner()
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
randomx_destroy_vm(myVM);
|
||||
rxdebug("%s: destroyed VM\n");
|
||||
|
||||
// Use randomx hash to build a valid block
|
||||
|
||||
std::function<bool(std::vector<unsigned char>)> validBlock =
|
||||
@@ -1372,6 +1395,8 @@ void static RandomXMiner()
|
||||
pblock->nBits = savebits;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (const boost::thread_interrupted&) {
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
@@ -1383,6 +1408,11 @@ void static RandomXMiner()
|
||||
fprintf(stderr,"RandomXMiner: runtime error: %s\n", e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
randomx_release_dataset(randomxDataset);
|
||||
rxdebug("%s: released dataset\n");
|
||||
randomx_release_cache(randomxCache);
|
||||
rxdebug("%s: released cache\n");
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
}
|
||||
@@ -1859,6 +1889,7 @@ void static BitcoinMiner()
|
||||
LogPrintf("HushMiner runtime error: %s\n", e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user