much debug such wow
This commit is contained in:
@@ -504,11 +504,13 @@ void hush_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotarie
|
||||
|
||||
int32_t hush_validate_chain(uint256 srchash,int32_t notarized_height)
|
||||
{
|
||||
fprintf(stderr,"%s\n", __func__);
|
||||
static int32_t last_rewind; int32_t rewindtarget; CBlockIndex *pindex; struct hush_state *sp; char symbol[HUSH_SMART_CHAIN_MAXLEN],dest[HUSH_SMART_CHAIN_MAXLEN];
|
||||
if ( (sp= hush_stateptr(symbol,dest)) == 0 )
|
||||
return(0);
|
||||
if ( IsInitialBlockDownload() == 0 && ((pindex= hush_getblockindex(srchash)) == 0 || pindex->GetHeight() != notarized_height) )
|
||||
{
|
||||
fprintf(stderr,"%s: Not in IBD, height=%d\n", __func__, pindex->GetHeight() );
|
||||
if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < notarized_height )
|
||||
rewindtarget = sp->NOTARIZED_HEIGHT - 1;
|
||||
else if ( notarized_height > 101 )
|
||||
|
||||
18
src/main.cpp
18
src/main.cpp
@@ -2403,7 +2403,9 @@ bool IsInitialBlockDownload()
|
||||
{
|
||||
LogPrintf("Leaving InitialBlockDownload (latching to false)\n");
|
||||
latchToFalse.store(true, std::memory_order_relaxed);
|
||||
} // else fprintf(stderr,"state.%d ht.%d vs %d, t.%u\n",state,(int32_t)chainActive.Height(),(uint32_t)ptr->GetHeight(),(int32_t)ptr->GetBlockTime());
|
||||
} else {
|
||||
fprintf(stderr,"%s: state.%d ht.%d vs %d, t.%u\n",__func__, state,(int32_t)chainActive.Height(),(uint32_t)ptr->GetHeight(),(int32_t)ptr->GetBlockTime());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -2446,12 +2448,14 @@ static CBlockIndex *pindexBestForkBase = NULL;
|
||||
|
||||
void CheckForkWarningConditions()
|
||||
{
|
||||
fprintf(stderr,"%s checking for IBD\n", __func__);
|
||||
AssertLockHeld(cs_main);
|
||||
// Before we get past initial download, we cannot reliably alert about forks
|
||||
// (we assume we don't get stuck on a fork before finishing our initial sync)
|
||||
if (IsInitialBlockDownload())
|
||||
return;
|
||||
|
||||
fprintf(stderr,"%s not in IBD\n", __func__);
|
||||
// If our best fork is no longer within 288 blocks (+/- 12 hours if no one mines it)
|
||||
// of our head, drop it
|
||||
if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->GetHeight() >= 288)
|
||||
@@ -2479,9 +2483,7 @@ void CheckForkWarningConditions()
|
||||
CAlert::Notify(warning, true);
|
||||
fLargeWorkInvalidChainFound = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fLargeWorkForkFound = false;
|
||||
fLargeWorkInvalidChainFound = false;
|
||||
}
|
||||
@@ -5537,23 +5539,23 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
|
||||
// NOTE: CheckBlockHeader is called by CheckBlock
|
||||
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
|
||||
{
|
||||
//fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW);
|
||||
fprintf(stderr,"%s: failure A checkPOW=%d\n",__func__,fCheckPOW);
|
||||
return false;
|
||||
}
|
||||
int32_t futureblock;
|
||||
if (!CheckBlock(&futureblock,indexDummy.GetHeight(),0,block, state, verifier, fCheckPOW, fCheckMerkleRoot))
|
||||
{
|
||||
//fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW);
|
||||
fprintf(stderr,"%s: failure B checkPOW=%d\n",__func__, fCheckPOW);
|
||||
return false;
|
||||
}
|
||||
if (!ContextualCheckBlock(0,block, state, pindexPrev))
|
||||
{
|
||||
//fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW);
|
||||
fprintf(stderr,"%s: failure C checkPOW=%d\n",__func__, fCheckPOW);
|
||||
return false;
|
||||
}
|
||||
if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW))
|
||||
{
|
||||
//fprintf(stderr,"TestBlockValidity failure D checkPOW.%d\n",fCheckPOW);
|
||||
fprintf(stderr,"%s: failure D checkPOW=%d\n",__func__,fCheckPOW);
|
||||
return false;
|
||||
}
|
||||
assert(state.IsValid());
|
||||
|
||||
@@ -154,6 +154,7 @@ bool hush_appendACscriptpub();
|
||||
|
||||
CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake)
|
||||
{
|
||||
fprintf(stderr,"%s\n", __func__);
|
||||
CScript scriptPubKeyIn(_scriptPubKeyIn);
|
||||
|
||||
CPubKey pk;
|
||||
@@ -172,14 +173,14 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
||||
uint64_t deposits,voutsum=0; int32_t isrealtime,hushheight; uint32_t blocktime; const CChainParams& chainparams = Params();
|
||||
bool fNotarizationBlock = false; std::vector<int8_t> NotarizationNotaries;
|
||||
|
||||
//fprintf(stderr,"create new block\n");
|
||||
fprintf(stderr,"%s: create new block with pubkey=%s\n", __func__, HexStr(pk).c_str());
|
||||
// Create new block
|
||||
if ( gpucount < 0 )
|
||||
gpucount = HUSH_MAXGPUCOUNT;
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
|
||||
if(!pblocktemplate.get())
|
||||
{
|
||||
fprintf(stderr,"pblocktemplate.get() failure\n");
|
||||
fprintf(stderr,"%s: pblocktemplate.get() failure\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
||||
@@ -505,8 +506,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
||||
//fprintf(stderr,"fee rate skip\n");
|
||||
continue;
|
||||
}
|
||||
// Prioritise by fee once past the priority size or we run out of high-priority
|
||||
// transactions:
|
||||
// Prioritize by fee once past the priority size or we run out of high-priority transactions
|
||||
if (!fSortedByFee &&
|
||||
((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority)))
|
||||
{
|
||||
@@ -595,7 +595,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
||||
txNew.vout.resize(1);
|
||||
txNew.vout[0].scriptPubKey = scriptPubKeyIn;
|
||||
txNew.vout[0].nValue = GetBlockSubsidy(nHeight,consensusParams) + nFees;
|
||||
fprintf(stderr,"mine ht.%d with %.8f\n",nHeight,(double)txNew.vout[0].nValue/COIN);
|
||||
fprintf(stderr,"%s: mine ht.%d with %.8f\n",__func__,nHeight,(double)txNew.vout[0].nValue/COIN);
|
||||
txNew.nExpiryHeight = 0;
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW <= 0 )
|
||||
txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetTime());
|
||||
@@ -741,7 +741,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
||||
else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (SMART_CHAIN_SYMBOL[0] != 0 || IS_HUSH_NOTARY == 0 || My_notaryid < 0) )
|
||||
{
|
||||
CValidationState state;
|
||||
//fprintf(stderr,"check validity\n");
|
||||
fprintf(stderr,"%s: check validity\n", __func__);
|
||||
if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) // invokes CC checks
|
||||
{
|
||||
if ( SMART_CHAIN_SYMBOL[0] == 0 || (SMART_CHAIN_SYMBOL[0] != 0 && !isStake) )
|
||||
@@ -749,6 +749,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
||||
LEAVE_CRITICAL_SECTION(cs_main);
|
||||
LEAVE_CRITICAL_SECTION(mempool.cs);
|
||||
}
|
||||
fprintf(stderr,"%s: TestBlockValidity failed!\n", __func__);
|
||||
//throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); // crashes the node, moved to GetBlockTemplate and issue return.
|
||||
return(0);
|
||||
}
|
||||
@@ -760,7 +761,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
||||
LEAVE_CRITICAL_SECTION(cs_main);
|
||||
LEAVE_CRITICAL_SECTION(mempool.cs);
|
||||
}
|
||||
//fprintf(stderr,"done new block\n");
|
||||
fprintf(stderr,"%s: done\n", __func__);
|
||||
return pblocktemplate.release();
|
||||
}
|
||||
|
||||
@@ -771,6 +772,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
||||
|
||||
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
|
||||
{
|
||||
fprintf(stderr,"RandomXMiner: %s with nExtraNonce=%u\n", __func__, nExtraNonce);
|
||||
// Update nExtraNonce
|
||||
static uint256 hashPrevBlock;
|
||||
if (hashPrevBlock != pblock->hashPrevBlock)
|
||||
@@ -794,12 +796,14 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
|
||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, int32_t gpucount, bool isStake)
|
||||
{
|
||||
CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i,len;
|
||||
fprintf(stderr,"%s: with nHeight=%d\n", __func__, nHeight);
|
||||
if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] != 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] != 51 )
|
||||
{
|
||||
if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 )
|
||||
{
|
||||
pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY);
|
||||
scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG;
|
||||
fprintf(stderr,"%s: with pubkey=%s\n", __func__, HexStr(pubkey).c_str() );
|
||||
} else {
|
||||
len = strlen(ASSETCHAINS_SCRIPTPUB.c_str());
|
||||
len >>= 1;
|
||||
@@ -823,16 +827,20 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight,
|
||||
} else {
|
||||
// wallet disabled
|
||||
CTxDestination dest = DecodeDestination(GetArg("-mineraddress", ""));
|
||||
char destaddr[65];
|
||||
if (IsValidDestination(dest)) {
|
||||
// CKeyID keyID = boost::get<CKeyID>(dest);
|
||||
// scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
scriptPubKey = GetScriptForDestination(dest);
|
||||
Getscriptaddress(destaddr,scriptPubKey);
|
||||
fprintf(stderr,"%s: wallet disabled with mineraddress=%s\n", __func__, destaddr);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"%s: calling CreateNewBlock\n", __func__);
|
||||
return CreateNewBlock(pubkey, scriptPubKey, gpucount, isStake);
|
||||
}
|
||||
|
||||
@@ -1040,6 +1048,7 @@ void static RandomXMiner()
|
||||
|
||||
while (true)
|
||||
{
|
||||
fprintf(stderr,"RandomXMiner: beginning mining loop on %s with nExtraNonce=%u\n",SMART_CHAIN_SYMBOL, nExtraNonce);
|
||||
if (chainparams.MiningRequiresPeers()) {
|
||||
//if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->GetHeight() < 100 )
|
||||
// break;
|
||||
@@ -1061,9 +1070,8 @@ void static RandomXMiner()
|
||||
//fprintf(stderr,"%s Found peers\n",SMART_CHAIN_SYMBOL);
|
||||
miningTimer.start();
|
||||
}
|
||||
//
|
||||
|
||||
// Create new block
|
||||
//
|
||||
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
|
||||
CBlockIndex* pindexPrev = chainActive.LastTip();
|
||||
if ( Mining_height != pindexPrev->GetHeight()+1 )
|
||||
@@ -1071,11 +1079,14 @@ void static RandomXMiner()
|
||||
Mining_height = pindexPrev->GetHeight()+1;
|
||||
Mining_start = (uint32_t)time(NULL);
|
||||
}
|
||||
fprintf(stderr,"RandomXMiner: Mining_start=%u\n", Mining_start);
|
||||
#ifdef ENABLE_WALLET
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, 0);
|
||||
#else
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey();
|
||||
#endif
|
||||
|
||||
fprintf(stderr,"RandomXMiner: created new block\n");
|
||||
if ( ptr == 0 )
|
||||
{
|
||||
if ( !GetBoolArg("-gen",false))
|
||||
@@ -1087,11 +1098,11 @@ void static RandomXMiner()
|
||||
}
|
||||
static uint32_t counter;
|
||||
if ( counter++ < 10 && ASSETCHAINS_STAKED == 0 )
|
||||
fprintf(stderr,"created illegal blockB, retry\n");
|
||||
fprintf(stderr,"RandomXMiner: created illegal blockB, retry with counter=%u\n", counter);
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
//fprintf(stderr,"get template\n");
|
||||
fprintf(stderr,"RandomXMiner: getting block template\n");
|
||||
unique_ptr<CBlockTemplate> pblocktemplate(ptr);
|
||||
if (!pblocktemplate.get())
|
||||
{
|
||||
@@ -1133,7 +1144,7 @@ void static RandomXMiner()
|
||||
gotinvalid = 0;
|
||||
while (true)
|
||||
{
|
||||
fprintf(stderr,"gotinvalid.%d\n",gotinvalid);
|
||||
fprintf(stderr,"RandomXMiner: gotinvalid=%d\n",gotinvalid);
|
||||
if ( gotinvalid != 0 )
|
||||
break;
|
||||
hush_longestchain();
|
||||
@@ -1186,13 +1197,14 @@ 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: 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) < randomxInterval + randomxBlockLag) {
|
||||
randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey);
|
||||
fprintf(stderr,"RandomXMiner: initialized cache with initial key\n");
|
||||
} else {
|
||||
fprintf(stderr,"RandomXMiner: calculating keyHeight with randomxInterval=%d\n", randomxInterval);
|
||||
// At heights between intervals, we use the same block key and wait randomxBlockLag blocks until changing
|
||||
int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval;
|
||||
fprintf(stderr,"RandomXMiner: key height=%d\n", keyHeight);
|
||||
@@ -1202,12 +1214,12 @@ void static RandomXMiner()
|
||||
crypto_generichash_blake2b_final(&state, randomxInput, 32);
|
||||
|
||||
randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxKey);
|
||||
fprintf(stderr,"RandomXMiner: initialized cache\n");
|
||||
fprintf(stderr,"RandomXMiner: initialized cache with randomxBlockKey=%s\n", randomxBlockKey.ToString().c_str());
|
||||
}
|
||||
|
||||
randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL);
|
||||
if(myVM == NULL) {
|
||||
LogPrintf("Cannot create RandomX VM, aborting!\n");
|
||||
fprintf(stderr,"RandomXMiner: Cannot create RandomX VM, aborting!\n");
|
||||
return;
|
||||
}
|
||||
fprintf(stderr,"RandomXMiner: created VM\n");
|
||||
@@ -1303,7 +1315,7 @@ void static RandomXMiner()
|
||||
// because they become invalid as we created a new block in blockchain.
|
||||
break;
|
||||
} else {
|
||||
fprintf(stderr,"HushRandomXMiner: solution not found, validBlock=false\n");
|
||||
fprintf(stderr,"RandomXMiner: solution not found, validBlock=false\n");
|
||||
}
|
||||
} catch (RandomXSolverCanceledException&) {
|
||||
LogPrintf("HushRandomXMiner solver canceled\n");
|
||||
@@ -1331,19 +1343,15 @@ void static RandomXMiner()
|
||||
pblock->nBits = savebits;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const boost::thread_interrupted&)
|
||||
{
|
||||
} catch (const boost::thread_interrupted&) {
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
LogPrintf("HushRandomXMiner terminated\n");
|
||||
throw;
|
||||
}
|
||||
catch (const std::runtime_error &e)
|
||||
{
|
||||
} catch (const std::runtime_error &e) {
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
LogPrintf("HushRandomXMiner runtime error: %s\n", e.what());
|
||||
fprintf(stderr,"RandomXMiner: runtime error: %s\n", e.what());
|
||||
return;
|
||||
}
|
||||
miningTimer.stop();
|
||||
|
||||
Reference in New Issue
Block a user