Fix randomx memory leak but create some mining errors
This change lifts the declaration of the randomx VM out of an inner loop into the main function body of RandomXMiner(), which allows us to destroy it later on when catching exceptions. We cannot lift the allocation of it's memory (randomx_create_vm) because it depends on things that change in every iteration of the inner loop. Otherwise, the VM will only sometimes be destroyed, which is what I think causes the memleak. But this seems to create one invalid block when mining each block height : STDOUT: TestBlockValidity: failure C checkPOW=1 RandomXMiner: Invalid randomx block mined, try again 05f30f419133b2d862106b89c20059967639e4f2699dd5afc5d2b0832f1ac76a debug.log: 2023-10-11 16:10:41 CreateNewBlock(): total size 1000 blocktime.1697040642 nBits.200e77d1 2023-10-11 16:10:41 Running HushRandomXMiner with 1 transactions in block (260 bytes) 2023-10-11 16:10:41 ERROR: ContextualCheckBlock: block height mismatch in coinbase Mining does seem to continue normally when testing with -testnode=1
This commit is contained in:
@@ -1122,6 +1122,7 @@ void static RandomXMiner()
|
||||
int randomxInterval = GetArg("-ac_randomx_interval",1024);
|
||||
// This lag is 80 mins for 75s blocktime and 64 mins for 60s (default) blocktime for HSCs
|
||||
int randomxBlockLag = GetArg("-ac_randomx_lag", 64);
|
||||
randomx_vm *myVM = nullptr;
|
||||
|
||||
try {
|
||||
// fprintf(stderr,"RandomXMiner: mining %s with randomx\n",SMART_CHAIN_SYMBOL);
|
||||
@@ -1198,7 +1199,7 @@ void static RandomXMiner()
|
||||
// randomx_init_dataset(randomxDataset, randomxCache, 0, datasetItemCount);
|
||||
rxdebug("%s: dataset initialized\n");
|
||||
|
||||
randomx_vm *myVM = randomx_create_vm(flags, nullptr, randomxDataset);
|
||||
myVM = randomx_create_vm(flags, nullptr, randomxDataset);
|
||||
if(myVM == NULL) {
|
||||
LogPrintf("RandomXMiner: Cannot create RandomX VM, aborting!\n");
|
||||
return;
|
||||
@@ -1425,6 +1426,8 @@ void static RandomXMiner()
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
|
||||
randomx_destroy_vm(myVM);
|
||||
LogPrintf("%s: destroyed vm\n", __func__);
|
||||
randomx_release_dataset(randomxDataset);
|
||||
rxdebug("%s: released dataset\n");
|
||||
randomx_release_cache(randomxCache);
|
||||
@@ -1437,6 +1440,8 @@ void static RandomXMiner()
|
||||
c.disconnect();
|
||||
fprintf(stderr,"RandomXMiner: runtime error: %s\n", e.what());
|
||||
|
||||
randomx_destroy_vm(myVM);
|
||||
LogPrintf("%s: destroyed vm\n", __func__);
|
||||
randomx_release_dataset(randomxDataset);
|
||||
rxdebug("%s: released dataset\n");
|
||||
randomx_release_cache(randomxCache);
|
||||
|
||||
Reference in New Issue
Block a user