Closed flyinghuman closed 5 years ago
I think we're close; getting the debug output from the minter will be most helpful to complete this last round of tests. As I'm sure you saw, I put in some new code (#22 ) to remove the confusion we ran into yesterday (I also talked to Warrows @ Pivx about the fact that the PoW threads don't terminate after the PoW phase ends, he would need to look into it, but based on what I stated, it made sense to terminate, so I went ahead with that). Just take another eye when you look at the code to make sure the heights look right, and we don't end up terminating the PoW threads before the last PoW block is processed.
Regarding debugging the blocks. Really the only block we need to see is the failing block, so I think the comment hook I put in the code is where we want to do it:
https://github.com/UCCNetwork/ucc/blob/b58b57d6a7583d783c80c7ddb82eaff769d97624/src/miner.cpp#L432
Looking into decoderawtransaction is where I found the TxtoJSON routine. I see there's also a blockToJSON() routine as well. I just don't have enough experience yet to see how to hook into that and spit it out into a logPrintf (or elsewhere). I will need to play around a bit to see if we can call one of those to get it to spit out the block into the log file.
But that strategy might be overkill once we see what caused the failure on the staking wallet that tried to write that first PoS block. The amount of debugging we added may be very revealing; when you get a chance to look for that info. I know it's getting late for you, so maybe if we need to do another run tonight, and analyse tomorrow, that might make sense.
I think I found it; the code actually added by me when I was trying to take a wild guess; before taking the time to really study what's going on.
if (fProofOfStake) {
unsigned int nExtraNonce = 0;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
LogPrintf("CPUMiner : proof-of-stake block found %s \n", pblock->GetHash().ToString().c_str());
if (!pblock->SignBlock(*pwallet)) {
LogPrintf("CreateNewBlock(): Signing new block with UTXO key failed \n");
return nullptr;
}
}
I saw this code added in Pivx; but now that I look at two different things. SignBlock has changed significantly with Pivx. We do an IncrementExtraNonce (and sign) in BitcoinMiner() before we even get to create new block. Now IncrementExtraNonce:
CMutableTransaction txCoinbase(pblock->vtx[0]);
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
pblock->vtx[0] = txCoinbase;
Looks incredibly dangerous if we're not supposed to be messing with vtx[0]
Thie PoW thread shutdown appears to have worked properly:
2019-06-08 21:33:26 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:33:31 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:33:36 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:33:41 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:33:46 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:33:51 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:33:56 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:34:01 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:34:06 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:34:11 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:34:16 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:34:21 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:34:26 CreateNewBlockWithKey(): Aborting PoW block creation during PoS phase
2019-06-08 21:34:31 BitcoinMiner(): Exiting Proof of Work Mining Thread at height: 1507
2019-06-08 21:34:31 ThreadBitcoinMiner exiting
The change to the PoS difficulty seems to have also worked correctly:
2019-06-08 21:33:29 CheckStakeKernelHash(): nbits: 1e00ffff, bnTargetCoinPerDay: 000000ffff000000000000000000000000000000000000000000000000000000
2019-06-08 21:33:29 CheckStakeKernelHash(): nbits: 1e00ffff, bnTargetCoinPerDay: 000000ffff000000000000000000000000000000000000000000000000000000
2019-06-08 21:33:39 CheckStakeKernelHash(): nbits: 1e00faca, bnTargetCoinPerDay: 000000faca000000000000000000000000000000000000000000000000000000
2019-06-08 21:33:39 CheckStakeKernelHash(): nbits: 1e00faca, bnTargetCoinPerDay: 000000faca000000000000000000000000000000000000000000000000000000
2019-06-08 21:33:49 CheckStakeKernelHash(): nbits: 1e00ee8e, bnTargetCoinPerDay: 000000ee8e000000000000000000000000000000000000000000000000000000
2019-06-08 21:33:49 CheckStakeKernelHash(): nbits: 1e00ee8e, bnTargetCoinPerDay: 000000ee8e000000000000000000000000000000000000000000000000000000
2019-06-08 21:33:59 CheckStakeKernelHash(): nbits: 1e00e637, bnTargetCoinPerDay: 000000e637000000000000000000000000000000000000000000000000000000
2019-06-08 21:33:59 CheckStakeKernelHash(): nbits: 1e00e637, bnTargetCoinPerDay: 000000e637000000000000000000000000000000000000000000000000000000
2019-06-08 21:34:09 CheckStakeKernelHash(): nbits: 1e00dfd9, bnTargetCoinPerDay: 000000dfd9000000000000000000000000000000000000000000000000000000
2019-06-08 21:34:09 CheckStakeKernelHash(): nbits: 1e00dfd9, bnTargetCoinPerDay: 000000dfd9000000000000000000000000000000000000000000000000000000
2019-06-08 21:34:19 CheckStakeKernelHash(): nbits: 1e00d5d6, bnTargetCoinPerDay: 000000d5d6000000000000000000000000000000000000000000000000000000
2019-06-08 21:34:19 CheckStakeKernelHash(): nbits: 1e00d5d6, bnTargetCoinPerDay: 000000d5d6000000000000000000000000000000000000000000000000000000
2019-06-08 21:34:29 CheckStakeKernelHash(): nbits: 1e00cbc0, bnTargetCoinPerDay: 000000cbc0000000000000000000000000000000000000000000000000000000
2019-06-08 21:34:29 CheckStakeKernelHash(): nbits: 1e00cbc0, bnTargetCoinPerDay: 000000cbc0000000000000000000000000000000000000000000000000000000
2019-06-08 21:34:39 CheckStakeKernelHash(): nbits: 1e00c1fa, bnTargetCoinPerDay: 000000c1fa000000000000000000000000000000000000000000000000000000
2019-06-08 21:34:39 CheckStakeKernelHash(): nbits: 1e00c1fa, bnTargetCoinPerDay: 000000c1fa000000000000000000000000000000000000000000000000000000
definitely need to redo the "blockchain info" section after the pos switch; since the numbers get all messed up (802 MHs, level 9, block reward 39)
of course, i opened a new issue for that
here we can discuss the pos switching problem in public. maybe someone has another idea too.
indeed would a function like in php the print_r good for debugging the blocks in the logfile output. maybe we can use the getrawtransaction and decoderawtransaction method for this?