Only print out randomx debug stuff when -debug=randomx

This commit is contained in:
Duke Leto
2022-07-11 18:33:10 -04:00
parent 66e9bd835a
commit a70897966a
5 changed files with 59 additions and 37 deletions

View File

@@ -512,7 +512,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", 0)); strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", 0));
strUsage += HelpMessageOpt("-nuparams=hexBranchId:activationHeight", "Use given activation height for specified network upgrade (regtest-only)"); strUsage += HelpMessageOpt("-nuparams=hexBranchId:activationHeight", "Use given activation height for specified network upgrade (regtest-only)");
} }
string debugCategories = "addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, tls, partitioncheck, pow, proxy, prune, rand, reindex, rpc, selectcoins, stratum, tor, zmq, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these string debugCategories = "addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, tls, partitioncheck, pow, proxy, prune, rand, randomx, reindex, rpc, selectcoins, stratum, tor, zmq, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these
strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " + strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " +
_("If <category> is not supplied or if <category> = 1, output all debugging information.") + " " + _("<category> can be:") + " " + debugCategories + "."); _("If <category> is not supplied or if <category> = 1, output all debugging information.") + " " + _("<category> can be:") + " " + debugCategories + ".");
strUsage += HelpMessageOpt("-experimentalfeatures", _("Enable use of experimental features")); strUsage += HelpMessageOpt("-experimentalfeatures", _("Enable use of experimental features"));
@@ -1249,6 +1249,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
v.push_back("zrpc"); v.push_back("zrpc");
} }
} }
if (find(categories.begin(), categories.end(), string("randomx")) != categories.end()) {
fRandomXDebug = true;
fprintf(stderr,"%s: enabled randomx debug\n", __func__);
}
//fprintf(stderr,"%s tik5\n", __FUNCTION__); //fprintf(stderr,"%s tik5\n", __FUNCTION__);
// Check for -debugnet // Check for -debugnet

View File

@@ -58,6 +58,8 @@
#endif #endif
#include <mutex> #include <mutex>
#define rxdebug(format, ...) if(fRandomXDebug) { fprintf(stderr, format, __func__, ## __VA_ARGS__ ); }
using namespace std; using namespace std;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@@ -117,6 +119,7 @@ public:
extern int8_t ASSETCHAINS_ADAPTIVEPOW; extern int8_t ASSETCHAINS_ADAPTIVEPOW;
extern uint32_t ASSETCHAINS_RANDOMX; extern uint32_t ASSETCHAINS_RANDOMX;
extern bool fRandomXDebug;
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
{ {
@@ -793,7 +796,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce) void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
{ {
fprintf(stderr,"RandomXMiner: %s with nExtraNonce=%u\n", __func__, nExtraNonce); //fprintf(stderr,"RandomXMiner: %s with nExtraNonce=%u\n", __func__, nExtraNonce);
// Update nExtraNonce // Update nExtraNonce
static uint256 hashPrevBlock; static uint256 hashPrevBlock;
if (hashPrevBlock != pblock->hashPrevBlock) if (hashPrevBlock != pblock->hashPrevBlock)
@@ -1065,11 +1068,15 @@ void static RandomXMiner()
miningTimer.start(); miningTimer.start();
try { try {
fprintf(stderr,"RandomXMiner: mining %s with randomx\n",SMART_CHAIN_SYMBOL); // fprintf(stderr,"RandomXMiner: mining %s with randomx\n",SMART_CHAIN_SYMBOL);
rxdebug("%s: mining %s with randomx\n", SMART_CHAIN_SYMBOL);
while (true) while (true)
{ {
fprintf(stderr,"RandomXMiner: beginning mining loop on %s with nExtraNonce=%u\n",SMART_CHAIN_SYMBOL, nExtraNonce); // fprintf(stderr,"RandomXMiner: beginning mining loop on %s with nExtraNonce=%u\n",SMART_CHAIN_SYMBOL, nExtraNonce);
rxdebug("%s: start mining loop on %s with nExtraNonce=%u\n", SMART_CHAIN_SYMBOL, nExtraNonce);
if (chainparams.MiningRequiresPeers()) { if (chainparams.MiningRequiresPeers()) {
//if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->GetHeight() < 100 ) //if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->GetHeight() < 100 )
// break; // break;
@@ -1100,14 +1107,15 @@ void static RandomXMiner()
Mining_height = pindexPrev->GetHeight()+1; Mining_height = pindexPrev->GetHeight()+1;
Mining_start = (uint32_t)time(NULL); Mining_start = (uint32_t)time(NULL);
} }
fprintf(stderr,"RandomXMiner: Mining_start=%u\n", Mining_start); //fprintf(stderr,"RandomXMiner: Mining_start=%u\n", Mining_start);
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, 0); CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, 0);
#else #else
CBlockTemplate *ptr = CreateNewBlockWithKey(); CBlockTemplate *ptr = CreateNewBlockWithKey();
#endif #endif
fprintf(stderr,"RandomXMiner: created new block\n"); // fprintf(stderr,"RandomXMiner: created new block with Mining_start=%u\n",Mining_start);
rxdebug("%s: created new block with Mining_start=%u\n",Mining_start);
if ( ptr == 0 ) if ( ptr == 0 )
{ {
if ( !GetBoolArg("-gen",false)) if ( !GetBoolArg("-gen",false))
@@ -1123,7 +1131,9 @@ void static RandomXMiner()
sleep(1); sleep(1);
continue; continue;
} }
fprintf(stderr,"RandomXMiner: getting block template\n"); // fprintf(stderr,"RandomXMiner: getting block template\n");
rxdebug("%s: getting block template\n");
unique_ptr<CBlockTemplate> pblocktemplate(ptr); unique_ptr<CBlockTemplate> pblocktemplate(ptr);
if (!pblocktemplate.get()) if (!pblocktemplate.get())
{ {
@@ -1151,7 +1161,7 @@ void static RandomXMiner()
} }
} }
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
fprintf(stderr,"RandomXMiner: %u transactions in block\n",(int32_t)pblock->vtx.size()); // fprintf(stderr,"RandomXMiner: %u transactions in block\n",(int32_t)pblock->vtx.size());
LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION));
// Search // Search
@@ -1173,7 +1183,8 @@ void static RandomXMiner()
} }
hush_longestchain(); hush_longestchain();
fprintf(stderr,"RandomXMiner: solving with nNonce = %s\n",pblock->nNonce.ToString().c_str()); // fprintf(stderr,"RandomXMiner: solving with nNonce = %s\n",pblock->nNonce.ToString().c_str());
rxdebug("%s: solving with nNonce = %s\n",pblock->nNonce.ToString().c_str());
arith_uint256 hashTarget; arith_uint256 hashTarget;
hashTarget = HASHTarget; hashTarget = HASHTarget;
@@ -1188,8 +1199,9 @@ void static RandomXMiner()
// Use the current block as randomx input // Use the current block as randomx input
randomxInput << pblocktemplate->block; randomxInput << pblocktemplate->block;
std::cerr << "RandomXMiner: randomxInput=" << HexStr(randomxInput) << "\n"; // std::cerr << "RandomXMiner: randomxInput=" << HexStr(randomxInput) << "\n";
fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput.size=%lu\n", randomxKey, randomxInput.size() ); //randomxInput); // fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput.size=%lu\n", randomxKey, randomxInput.size() ); //randomxInput);
rxdebug("%s: randomxKey=%s randomxInput=%s", randomxKey, HexStr(randomxInput).c_str());
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);
@@ -1206,43 +1218,43 @@ void static RandomXMiner()
// This lag is 80 mins for 75s blocktime and 64 mins for 60s (default) blocktime for HSCs // This lag is 80 mins for 75s blocktime and 64 mins for 60s (default) blocktime for HSCs
int randomxBlockLag = GetArg("-ac_randomx_lag", 64); int randomxBlockLag = GetArg("-ac_randomx_lag", 64);
fprintf(stderr,"RandomXMiner: using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag); // fprintf(stderr,"RandomXMiner: using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag);
fprintf(stderr,"RandomXMiner: Mining_height=%u\n", Mining_height); rxdebug("%s: using initial key, interval=%d, lag=%d, Mining_height=%u\n", randomxInterval, randomxBlockLag, Mining_height);
// Use the initial key at the start of the chain, until the first key block // Use the initial key at the start of the chain, until the first key block
if( (Mining_height) < randomxInterval + randomxBlockLag) { if( (Mining_height) < randomxInterval + randomxBlockLag) {
randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey);
fprintf(stderr,"RandomXMiner: initialized cache with initial key\n"); rxdebug("%s: initialized cache with initial key\n");
} else { } else {
fprintf(stderr,"RandomXMiner: calculating keyHeight with randomxInterval=%d\n", randomxInterval); rxdebug("%s: calculating keyHeight with randomxInterval=%d\n", randomxInterval);
// At heights between intervals, we use the same block key and wait randomxBlockLag blocks until changing // At heights between intervals, we use the same block key and wait randomxBlockLag blocks until changing
int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval; int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval;
fprintf(stderr,"RandomXMiner: key height=%d\n", keyHeight);
uint256 randomxBlockKey = chainActive[keyHeight]->GetBlockHash(); uint256 randomxBlockKey = chainActive[keyHeight]->GetBlockHash();
randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxBlockKey); randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxBlockKey);
fprintf(stderr,"RandomXMiner: initialized cache with randomxBlockKey=%s\n", randomxBlockKey.ToString().c_str()); rxdebug("%s: initialized cache with keyHeight=%d, randomxBlockKey=%s\n", keyHeight, randomxBlockKey.ToString().c_str());
} }
randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL); randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL);
if(myVM == NULL) { if(myVM == NULL) {
fprintf(stderr,"RandomXMiner: Cannot create RandomX VM, aborting!\n"); LogPrintf("RandomXMiner: Cannot create RandomX VM, aborting!\n");
return; return;
} }
// fprintf(stderr,"RandomXMiner: created VM\n");
randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash); randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash);
fprintf(stderr,"RandomXMiner: calculated randomx hash\n"); // rxdebug("calculated randomx hash\n");
randomx_destroy_vm(myVM); randomx_destroy_vm(myVM);
// fprintf(stderr,"RandomXMiner: destroyed VM\n"); // fprintf(stderr,"RandomXMiner: destroyed VM\n");
randomx_release_cache(randomxCache); randomx_release_cache(randomxCache);
printf("RandomXMiner: randomxHash="); rxdebug("%s: randomxHash=");
for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) { if (fRandomXDebug) {
printf("%02x", randomxHash[i] & 0xff); for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) {
} printf("%02x", randomxHash[i] & 0xff);
}
printf("\n"); printf("\n");
}
// Use randomx hash to build a valid block // Use randomx hash to build a valid block
std::function<bool(std::vector<unsigned char>)> validBlock = std::function<bool(std::vector<unsigned char>)> validBlock =
@@ -1254,23 +1266,25 @@ void static RandomXMiner()
(std::vector<unsigned char> soln) { (std::vector<unsigned char> soln) {
int32_t z; arith_uint256 h; CBlock B; int32_t z; arith_uint256 h; CBlock B;
// Write the solution to the hash and compute the result. // Write the solution to the hash and compute the result.
fprintf(stderr,"RandomXMiner: Checking solution against target\n"); rxdebug("%s: Checking solution against target\n");
pblock->nSolution = soln; pblock->nSolution = soln;
solutionTargetChecks.increment(); solutionTargetChecks.increment();
B = *pblock; B = *pblock;
h = UintToArith256(B.GetHash()); h = UintToArith256(B.GetHash());
fprintf(stderr,"RandomXMiner: h="); rxdebug("%s: h=");
for (z=31; z>=0; z--) if (fRandomXDebug) {
fprintf(stderr,"%02x",((uint8_t *)&h)[z]); for (z=31; z>=0; z--)
fprintf(stderr," , hashTarget="); fprintf(stderr,"%02x",((uint8_t *)&h)[z]);
for (z=31; z>=0; z--) fprintf(stderr," , hashTarget=");
fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); for (z=31; z>=0; z--)
fprintf(stderr,"\n"); fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]);
fprintf(stderr,"\n");
}
if ( h > hashTarget ) if ( h > hashTarget )
{ {
fprintf(stderr,"RandomXMiner: h > hashTarget"); rxdebug("%s: h > hashTarget");
return false; return false;
} }
@@ -1316,12 +1330,12 @@ void static RandomXMiner()
std::vector<unsigned char> sol_char(randomxHash, randomxHash+32); std::vector<unsigned char> sol_char(randomxHash, randomxHash+32);
bool found = validBlock(sol_char); bool found = validBlock(sol_char);
if (found) { if (found) {
fprintf(stderr,"RandomXMiner: found solution!\n"); rxdebug("%s: found solution!\n");
// If we find a POW solution, do not try other solutions // If we find a POW solution, do not try other solutions
// because they become invalid as we created a new block in blockchain. // because they become invalid as we created a new block in blockchain.
break; break;
} else { } else {
fprintf(stderr,"RandomXMiner: solution not found, validBlock=false\n"); rxdebug("%s: solution not found, validBlock=false\n");
} }
} catch (RandomXSolverCanceledException&) { } catch (RandomXSolverCanceledException&) {
LogPrintf("HushRandomXMiner solver canceled\n"); LogPrintf("HushRandomXMiner solver canceled\n");

View File

@@ -119,6 +119,7 @@ using namespace std;
map<string, string> mapArgs; map<string, string> mapArgs;
map<string, vector<string> > mapMultiArgs; map<string, vector<string> > mapMultiArgs;
bool fDebug = false; bool fDebug = false;
bool fRandomXDebug = false;
bool fZdebug = false; bool fZdebug = false;
bool fPrintToConsole = false; bool fPrintToConsole = false;
bool fPrintToDebugLog = true; bool fPrintToDebugLog = true;

View File

@@ -58,6 +58,7 @@ public:
extern std::map<std::string, std::string> mapArgs; extern std::map<std::string, std::string> mapArgs;
extern std::map<std::string, std::vector<std::string> > mapMultiArgs; extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
extern bool fDebug; extern bool fDebug;
extern bool fRandomXDebug;
extern bool fZdebug; extern bool fZdebug;
extern bool fPrintToConsole; extern bool fPrintToConsole;
extern bool fPrintToDebugLog; extern bool fPrintToDebugLog;

View File

@@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX10 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 # any CLI args given to this script will be passed along
# example: ./test_randomx -debug=randomx
./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX10 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 $@
# to run via the debugger # to run via the debugger
# type "run" when gdb prompt appears # type "run" when gdb prompt appears