Merge branch 'dev' into danger

This commit is contained in:
Duke
2023-10-13 09:27:38 -04:00
41 changed files with 731 additions and 192 deletions

View File

@@ -280,11 +280,16 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
vecPriority.reserve(mempool.mapTx.size() + 1);
//fprintf(stderr,"%s: going to add txs from mempool\n", __func__);
// now add transactions from the mem pool
// now add transactions from the mempool
int32_t Notarizations = 0; uint64_t txvalue;
uint32_t large_zins = 0; // number of ztxs with large number of inputs in block
uint32_t large_zouts = 0; // number of ztxs with large number of outputs in block
const uint32_t LARGE_ZINS_MAX = 1; // max ztxs with large zins per block
const uint32_t LARGE_ZOUTS_MAX = 1; // max ztxs with large zouts per block
const uint32_t LARGE_ZINS_THRESHOLD = 50; // min number of zins to be considered large
const uint32_t LARGE_ZOUTS_THRESHOLD = 10; // min number of zouts to be considered large
for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin();
mi != mempool.mapTx.end(); ++mi)
{
mi != mempool.mapTx.end(); ++mi) {
const CTransaction& tx = mi->GetTx();
int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
@@ -467,6 +472,18 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
// fprintf(stderr,"%s: compared first tx from priority queue\n", __func__);
vecPriority.pop_back();
if(tx.vShieldedSpend.size() >= LARGE_ZINS_THRESHOLD && large_zins >= LARGE_ZINS_MAX) {
LogPrintf("%s: skipping ztx %s with %d zins because there are already %d ztxs with large zins\n",
__func__, tx.GetHash().ToString().c_str(), tx.vShieldedSpend.size(), LARGE_ZINS_MAX);
continue;
}
if(tx.vShieldedOutput.size() >= LARGE_ZOUTS_THRESHOLD && large_zouts >= LARGE_ZOUTS_MAX) {
LogPrintf("%s: skipping ztx %s with %d zouts because there are already %d ztxs with large zouts\n",
__func__, tx.GetHash().ToString().c_str(), tx.vShieldedOutput.size(), LARGE_ZOUTS_MAX);
continue;
}
// Size limits
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
// fprintf(stderr,"%s: nTxSize = %u\n", __func__, nTxSize);
@@ -577,6 +594,18 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
nBlockSigOps += nTxSigOps;
nFees += nTxFees;
if(tx.vShieldedOutput.size() >= LARGE_ZOUTS_THRESHOLD) {
large_zouts++;
LogPrintf("%s: txid=%s has large zouts=%d (%d large zouts in block)\n", __func__, tx.GetHash().ToString().c_str(),
tx.vShieldedOutput.size(), large_zouts );
}
if(tx.vShieldedSpend.size() >= LARGE_ZINS_THRESHOLD) {
large_zins++;
LogPrintf("%s: txid=%s has large zins=%d (%d large zins in block)\n", __func__, tx.GetHash().ToString().c_str(),
tx.vShieldedSpend.size(), large_zins );
}
if (fPrintPriority)
{
LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString());
@@ -1075,14 +1104,14 @@ void static RandomXMiner()
randomx_dataset *randomxDataset = randomx_alloc_dataset(flags);
rxdebug("%s: created dataset\n");
auto datasetItemCount = randomx_dataset_item_count();
rxdebug("%s: dataset items=%lu\n", datasetItemCount);
if( randomxDataset == nullptr) {
LogPrintf("%s: allocating randomx dataset failed!\n", __func__);
return;
}
auto datasetItemCount = randomx_dataset_item_count();
rxdebug("%s: dataset items=%lu\n", datasetItemCount);
char randomxHash[RANDOMX_HASH_SIZE];
rxdebug("%s: created randomxHash of size %d\n", RANDOMX_HASH_SIZE);
char randomxKey[82]; // randomx spec says keysize of >60 bytes is implementation-specific
@@ -1096,6 +1125,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);
@@ -1172,7 +1202,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;
@@ -1398,19 +1428,35 @@ void static RandomXMiner()
} catch (const boost::thread_interrupted&) {
miningTimer.stop();
c.disconnect();
randomx_destroy_vm(myVM);
LogPrintf("%s: destroyed vm via thread interrupt\n", __func__);
randomx_release_dataset(randomxDataset);
rxdebug("%s: released dataset via thread interrupt\n");
randomx_release_cache(randomxCache);
rxdebug("%s: released cache via thread interrupt\n");
LogPrintf("HushRandomXMiner terminated\n");
throw;
} catch (const std::runtime_error &e) {
miningTimer.stop();
c.disconnect();
fprintf(stderr,"RandomXMiner: runtime error: %s\n", e.what());
randomx_destroy_vm(myVM);
LogPrintf("%s: destroyed vm because of error\n", __func__);
randomx_release_dataset(randomxDataset);
rxdebug("%s: released dataset because of error\n");
randomx_release_cache(randomxCache);
rxdebug("%s: released cache because of error\n");
return;
}
randomx_release_dataset(randomxDataset);
rxdebug("%s: released dataset\n");
rxdebug("%s: released dataset in normal exit\n");
randomx_release_cache(randomxCache);
rxdebug("%s: released cache\n");
rxdebug("%s: released cache in normal exit\n");
miningTimer.stop();
c.disconnect();
}