From afa02103c9a4ab198bf097683c0f0f836aa67907 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 16 Apr 2018 07:21:04 +0200 Subject: [PATCH 01/23] update Makefile --- src/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 90a52c207..5166a6103 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -527,7 +527,8 @@ wallet_utility_LDADD = \ $(CRYPTO_LIBS) \ $(LIBZCASH) \ $(LIBSNARK) \ - $(LIBZCASH_LIBS) + $(LIBZCASH_LIBS)\ + $(LIBCRYPTOCONDITIONS) endif # zcash-tx binary # From 562deb53ca4ccef7de007919638deb1592b5649f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 08:23:29 +0300 Subject: [PATCH 02/23] Test validity in mined block path --- src/miner.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index e571f3617..176fb83a7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -917,6 +917,12 @@ void static BitcoinMiner() // fprintf(stderr," missed target\n"); return false; } + CValidationState state; + if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false)) + { + fprintf(stderr,"Invalid block mined, try again\n"); + return(false); + } if ( ASSETCHAINS_STAKED == 0 ) { if ( Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay ) @@ -934,12 +940,6 @@ void static BitcoinMiner() } else { - CValidationState state; - if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false)) - { - fprintf(stderr,"Invalid block mined, try again\n"); - return(false); - } if ( NOTARY_PUBKEY33[0] != 0 ) { printf("need to wait %d seconds to submit\n",(int32_t)(pblock->nTime - GetAdjustedTime())); From 5db22eedcbcaa39af7d585c7013bf336da8dc92a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 11:30:54 +0300 Subject: [PATCH 03/23] if ( pindex != 0 ) --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9840863d2..1d21289f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4029,7 +4029,8 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc if ( *ppindex == 0 ) fprintf(stderr,"unexpected null *ppindex\n"); #endif - return true; + if ( pindex != 0 ) + return true; } if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) @@ -4051,7 +4052,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - fprintf(stderr,"ContextualCheckBlockHeader failed\n"); + //fprintf(stderr,"ContextualCheckBlockHeader failed\n"); return false; } if (pindex == NULL) From 8441f3f92f8562e369fda97624612a9816429afe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 13:03:58 +0300 Subject: [PATCH 04/23] Disable auto rewind --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 32fcce047..829d64ec2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -587,7 +587,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr { if ( last_rewind != 0 ) { - KOMODO_REWIND = rewindtarget; + //KOMODO_REWIND = rewindtarget; fprintf(stderr,"%s FORK detected. notarized.%d %s not in this chain! last notarization %d -> rewindtarget.%d\n",ASSETCHAINS_SYMBOL,*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT,rewindtarget); } last_rewind = rewindtarget; From d03b421d7964c88a4ff52649e53a7d5e8f5d9b01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 16:45:44 +0300 Subject: [PATCH 05/23] Allow genesis version and move checkequihash, this is a must update --- src/main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1d21289f2..1c50f4c1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3748,12 +3748,12 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); } // Check block version - //if (block.nVersion < MIN_BLOCK_VERSION) - // return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low"); + if (height > 0 && block.nVersion < MIN_BLOCK_VERSION) + return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low"); // Check Equihash solution is valid - if ( fCheckPOW && !CheckEquihashSolution(&blockhdr, Params()) ) - return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); + /*if ( fCheckPOW && !CheckEquihashSolution(&blockhdr, Params()) ) + return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution");*/ // Check proof of work matches claimed amount /*komodo_index2pubkey33(pubkey33,pindex,height); @@ -3811,6 +3811,8 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW); return false; } + if ( fCheckPOW && !CheckEquihashSolution(&blockhdr, Params()) ) + return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); komodo_block2pubkey33(pubkey33,(CBlock *)&block); if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus()) ) { From ca0a5c31cf16f075b95a0a634445f6c0bcd03b5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 17:11:47 +0300 Subject: [PATCH 06/23] Blockader --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 1c50f4c1c..f2d6c1071 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3748,7 +3748,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); } // Check block version - if (height > 0 && block.nVersion < MIN_BLOCK_VERSION) + if (height > 0 && blockhdr.nVersion < MIN_BLOCK_VERSION) return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low"); // Check Equihash solution is valid From 22f6339d764fbe3f8a9036be1840da265c0defa4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 19:10:45 +0300 Subject: [PATCH 07/23] Blockhdr -> block --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f2d6c1071..3bfbc3f2c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3811,7 +3811,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW); return false; } - if ( fCheckPOW && !CheckEquihashSolution(&blockhdr, Params()) ) + if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) ) return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); komodo_block2pubkey33(pubkey33,(CBlock *)&block); if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus()) ) From 5d4f0421af481e2d6451389064ebb7e9a9cd4e00 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Mon, 16 Apr 2018 19:31:48 +0300 Subject: [PATCH 08/23] fix vout values display in Insight KMD explorer --- src/rpcrawtransaction.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 3f93e07d6..dbd3702b5 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -174,6 +174,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& out.push_back(Pair("interest", ValueFromAmount(interest))); } out.push_back(Pair("valueZat", txout.nValue)); + out.push_back(Pair("valueSat", txout.nValue)); // [+] Decker out.push_back(Pair("n", (int64_t)i)); UniValue o(UniValue::VOBJ); ScriptPubKeyToJSON(txout.scriptPubKey, o, true); From a4ea4a3fde69959d275dcd58024056303b02efc7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 21:23:25 +0300 Subject: [PATCH 09/23] Test --- src/komodo_bitcoind.h | 25 +++++++++++++++--------- src/pow.cpp | 45 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9a379abc..2863b984a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -804,7 +804,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) return(komodo_electednotary(&numnotaries,pubkey33,height,timestamp)); }*/ -int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height) +int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height) { int32_t i,j,n,duplicate; CBlock block; CBlockIndex *pindex; uint8_t notarypubs33[64][33]; memset(mids,-1,sizeof(*mids)*66); @@ -813,6 +813,7 @@ int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *non { if ( (pindex= komodo_chainactive(height-i)) != 0 ) { + blocktimes[i] = pindex->nTime; if ( komodo_blockload(block,pindex) == 0 ) { komodo_block2pubkey33(pubkeys[i],&block); @@ -849,10 +850,10 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width) // depre return(-1); } -int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t height,uint8_t pubkey33[33],uint32_t timestamp) +int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t blocktimes[66],int32_t height,uint8_t pubkey33[33],uint32_t blocktime) { int32_t i,j,notaryid=0,minerid,limit,nid; uint8_t destpubkey33[33]; - komodo_chosennotary(¬aryid,height,pubkey33,timestamp); + komodo_chosennotary(¬aryid,height,pubkey33,blocktimes[0]); if ( height >= 82000 ) { if ( notaryid >= 0 ) @@ -861,15 +862,21 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t heigh { if ( mids[i] == notaryid ) { - //for (j=0; j<66; j++) - // fprintf(stderr,"%d ",mids[j]); - //fprintf(stderr,"ht.%d repeat notaryid.%d in mids[%d]\n",height,notaryid,i); if ( height > 792000 ) + { + for (j=0; j<66; j++) + fprintf(stderr,"%d ",mids[j]); + fprintf(stderr,"ht.%d repeat notaryid.%d in mids[%d]\n",height,notaryid,i); return(-1); - else break; + } else break; } } - return(1); + if ( blocktime != 0 && blocktimes[1] != 0 && blocktime < blocktimes[1]+57 ) + { + fprintf(stderr,"lag.%d ht.%d n.%d blocktimes[%u vs %u %u]\n",blocktime-blocktimes[1],height,notaryid,blocktime,blocktimes[0],blocktimes[1]); + if ( height > 807000 ) + return(-2); + } else return(1); } else return(0); } else @@ -883,7 +890,7 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t heigh else limit = 66; for (i=1; i 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary { - special = komodo_chosennotary(¬aryid,height,pubkey33,timestamp); + special = komodo_chosennotary(¬aryid,height,pubkey33,tiptime); for (i=0; i<33; i++) { if ( pubkey33[i] != 0 ) @@ -157,8 +158,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in //fprintf(stderr,"ht.%d null pubkey checkproof return\n",height); return(true); // will come back via different path with pubkey set } - flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height); - special2 = komodo_is_special(pubkeys,mids,height,pubkey33,timestamp); + flag = komodo_eligiblenotary(pubkeys,mids,blocktimes,&nonzpkeys,height); + special2 = komodo_is_special(pubkeys,mids,blocktimes,height,pubkey33,blocktime); if ( notaryid >= 0 ) { if ( height > 10000 && height < 80000 && (special != 0 || special2 > 0) ) @@ -175,7 +176,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in flag = 0; else fprintf(stderr,"ht.%d notaryid.%d special.%d flag.%d special2.%d\n",height,notaryid,special,flag,special2); } - if ( flag != 0 || special2 > 0 ) + if ( (flag != 0 || special2 > 0) && special2 != -2 ) { //fprintf(stderr,"EASY MINING ht.%d\n",height); bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); @@ -190,8 +191,34 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in if ( KOMODO_LOADINGBLOCKS != 0 ) return true; if ( ASSETCHAINS_SYMBOL[0] != 0 || height > 792000 ) + { + if ( 1 && height > 792000 ) + { + for (i=31; i>=0; i--) + printf("%02x",((uint8_t *)&hash)[i]); + printf(" hash vs "); + for (i=31; i>=0; i--) + printf("%02x",((uint8_t *)&bnTarget)[i]); + printf(" ht.%d special.%d notaryid.%d ht.%d mod.%d error\n",height,special,notaryid,height,(height % 35)); + for (i=0; i<33; i++) + printf("%02x",pubkey33[i]); + printf(" <- pubkey\n"); + for (i=0; i<33; i++) + printf("%02x",origpubkey33[i]); + printf(" <- origpubkey\n"); + for (i=0; i<66; i++) + printf("%d ",mids[i]); + printf(" minerids from ht.%d\n",height); + } return false; + } } + /*for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); + fprintf(stderr," hash vs "); + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," height.%d notaryid.%d PoW valid\n",height,notaryid);*/ return true; } From 2997771652650d85ca54ee6af61bb661aa0c28b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 21:31:41 +0300 Subject: [PATCH 10/23] Test --- src/main.cpp | 6 +++--- src/pow.cpp | 3 ++- src/pow.h | 2 +- src/rpcmining.cpp | 2 +- src/txdb.cpp | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3bfbc3f2c..d7b0c1f7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1678,7 +1678,7 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos) } // Check the header komodo_block2pubkey33(pubkey33,(CBlock *)&block); - if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus()))) + if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime))) { int32_t i; for (i=0; i<33; i++) fprintf(stderr,"%02x",pubkey33[i]); @@ -3757,7 +3757,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl // Check proof of work matches claimed amount /*komodo_index2pubkey33(pubkey33,pindex,height); - if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,blockhdr.GetHash(), blockhdr.nBits, Params().GetConsensus()) ) + if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,blockhdr.GetHash(), blockhdr.nBits, Params().GetConsensus(),blockhdr.nTime) ) return state.DoS(50, error("CheckBlockHeader(): proof of work failed"),REJECT_INVALID, "high-hash");*/ return true; } @@ -3814,7 +3814,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) ) return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); komodo_block2pubkey33(pubkey33,(CBlock *)&block); - if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus()) ) + if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime) ) { //komodo_reverify_blockcheck(state,height,pindex); return state.DoS(1, error("CheckBlock(): proof of work failed"),REJECT_INVALID, "high-hash"); diff --git a/src/pow.cpp b/src/pow.cpp index ebb5c774c..6fb357ac6 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -192,7 +192,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int return true; if ( ASSETCHAINS_SYMBOL[0] != 0 || height > 792000 ) { - if ( 1 && height > 792000 ) + if ( 0 && height > 792000 ) { for (i=31; i>=0; i--) printf("%02x",((uint8_t *)&hash)[i]); @@ -222,6 +222,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int return true; } + arith_uint256 GetBlockProof(const CBlockIndex& block) { arith_uint256 bnTarget; diff --git a/src/pow.h b/src/pow.h index 3edec74ac..213fe228d 100644 --- a/src/pow.h +++ b/src/pow.h @@ -25,7 +25,7 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams&); /** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */ -bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params&); +bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params&,uint32_t blocktime); arith_uint256 GetBlockProof(const CBlockIndex& block); /** Return the time it would take to redo the work difference between from and to, assuming the current hashrate corresponds to the difficulty at tip, in seconds. */ diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index da1d5207f..d141c42c4 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -257,7 +257,7 @@ UniValue generate(const UniValue& params, bool fHelp) LOCK(cs_main); pblock->nSolution = soln; solutionTargetChecks.increment(); - return CheckProofOfWork(chainActive.Height(),NOTARY_PUBKEY33,pblock->GetHash(), pblock->nBits, Params().GetConsensus()); + return CheckProofOfWork(chainActive.Height(),NOTARY_PUBKEY33,pblock->GetHash(), pblock->nBits, Params().GetConsensus(),pblock->nTime); }; bool found = EhBasicSolveUncancellable(n, k, curr_state, validBlock); ehSolverRuns.increment(); diff --git a/src/txdb.cpp b/src/txdb.cpp index f37f66daf..3e4602d32 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -530,7 +530,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts() diskindex.ToString(), pindexNew->ToString()); uint8_t pubkey33[33]; komodo_index2pubkey33(pubkey33,pindexNew,pindexNew->nHeight); - if (!CheckProofOfWork(pindexNew->nHeight,pubkey33,pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus())) + if (!CheckProofOfWork(pindexNew->nHeight,pubkey33,pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus(),pindexNew->nHeight)) return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString()); pcursor->Next(); } else { From 508a62733fcc84c44eaddc12f3b924488e26cdba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 21:38:59 +0300 Subject: [PATCH 11/23] Test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 176fb83a7..6000c11cd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -657,7 +657,7 @@ static bool ProcessBlockFound(CBlock* pblock) } int32_t komodo_baseid(char *origbase); -int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height); +int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height); arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc); int32_t FOUND_BLOCK,KOMODO_MAYBEMINED; extern int32_t KOMODO_LASTMINED; @@ -812,7 +812,7 @@ void static BitcoinMiner() j = 65; if ( (Mining_height >= 235300 && Mining_height < 236000) || (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 ) { - komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,pindexPrev->nHeight); + komodo_eligiblenotary(pubkeys,mids,blocktimes,&nonzpkeys,pindexPrev->nHeight); if ( nonzpkeys > 0 ) { for (i=0; i<33; i++) From 56ef9fdbd8887f6719fef287fbd4acb84834e241 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 21:40:35 +0300 Subject: [PATCH 12/23] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 6000c11cd..b419c40c0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -803,7 +803,7 @@ void static BitcoinMiner() // // Search // - uint8_t pubkeys[66][33]; int mids[256],gpucount,nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); + uint8_t pubkeys[66][33]; uint32_t blocktimes[66]; int mids[256],gpucount,nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); savebits = pblock->nBits; HASHTarget = arith_uint256().SetCompact(pblock->nBits); roundrobin_delay = ROUNDROBIN_DELAY; From e9e70b9544a84245a3ece58d608f9cf796e778b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 22:41:14 +0300 Subject: [PATCH 13/23] Test --- src/komodo_bitcoind.h | 3 +- src/miner.cpp | 597 +++++++++++++++++++++--------------------- 2 files changed, 301 insertions(+), 299 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2863b984a..89b9e0aab 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -876,7 +876,8 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t bloc fprintf(stderr,"lag.%d ht.%d n.%d blocktimes[%u vs %u %u]\n",blocktime-blocktimes[1],height,notaryid,blocktime,blocktimes[0],blocktimes[1]); if ( height > 807000 ) return(-2); - } else return(1); + } + return(1); } else return(0); } else diff --git a/src/miner.cpp b/src/miner.cpp index b419c40c0..062156822 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -63,7 +63,7 @@ public: set setDependsOn; CFeeRate feeRate; double dPriority; - + COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0) { } @@ -77,10 +77,10 @@ typedef boost::tuple TxPriority; class TxPriorityCompare { bool byFee; - + public: TxPriorityCompare(bool _byFee) : byFee(_byFee) { } - + bool operator()(const TxPriority& a, const TxPriority& b) { if (byFee) @@ -159,30 +159,30 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // -blockversion=N to test forking scenarios if (Params().MineBlocksOnDemand()) pblock->nVersion = GetArg("-blockversion", pblock->nVersion); - + // Add dummy coinbase tx as first transaction pblock->vtx.push_back(CTransaction()); pblocktemplate->vTxFees.push_back(-1); // updated at end pblocktemplate->vTxSigOps.push_back(-1); // updated at end - + // Largest block you're willing to create: unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE); // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity: nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize)); - + // How much of the block should be dedicated to high-priority transactions, // included regardless of the fees they pay unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE); nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize); - + // Minimum block size you want to create; block will be filled with free transactions // until there are no more or the block reaches this size: unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE); nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); - + // Collect memory pool transactions into the block CAmount nFees = 0; - + { LOCK2(cs_main, mempool.cs); CBlockIndex* pindexPrev = chainActive.Tip(); @@ -197,7 +197,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) list vOrphan; // list memory doesn't move map > mapDependers; bool fPrintPriority = GetBoolArg("-printpriority", false); - + // This vector will be sorted into a priority queue: vector vecPriority; vecPriority.reserve(mempool.mapTx.size()); @@ -205,14 +205,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) mi != mempool.mapTx.end(); ++mi) { const CTransaction& tx = mi->GetTx(); - + int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) - ? nMedianTimePast - : pblock->GetBlockTime(); - + ? nMedianTimePast + : pblock->GetBlockTime(); + if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) continue; - if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 ) + if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) { fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); continue; @@ -238,7 +238,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) vOrphan.pop_back(); break; } - + // Has to wait for dependencies if (!porphan) { @@ -253,27 +253,27 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } const CCoins* coins = view.AccessCoins(txin.prevout.hash); assert(coins); - + CAmount nValueIn = coins->vout[txin.prevout.n].nValue; nTotalIn += nValueIn; - + int nConf = nHeight - coins->nHeight; - + dPriority += (double)nValueIn * nConf; } nTotalIn += tx.GetJoinSplitValueIn(); - + if (fMissingInputs) continue; - + // Priority is sum(valuein * age) / modified_txsize unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); dPriority = tx.ComputePriority(dPriority, nTxSize); - + uint256 hash = tx.GetHash(); mempool.ApplyDeltas(hash, dPriority, nTotalIn); - + CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); - + if (porphan) { porphan->dPriority = dPriority; @@ -282,37 +282,37 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) else vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); } - + // Collect transactions into block uint64_t nBlockSize = 1000; uint64_t nBlockTx = 0; int64_t interest; int nBlockSigOps = 100; bool fSortedByFee = (nBlockPrioritySize <= 0); - + TxPriorityCompare comparer(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - + while (!vecPriority.empty()) { // Take highest priority transaction off the priority queue: double dPriority = vecPriority.front().get<0>(); CFeeRate feeRate = vecPriority.front().get<1>(); const CTransaction& tx = *(vecPriority.front().get<2>()); - + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); vecPriority.pop_back(); - + // Size limits unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); if (nBlockSize + nTxSize >= nBlockMaxSize) continue; - + // Legacy limits on sigOps: unsigned int nTxSigOps = GetLegacySigOpCount(tx); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) continue; - + // Skip free transactions if we're past the minimum block size: const uint256& hash = tx.GetHash(); double dPriorityDelta = 0; @@ -320,7 +320,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) continue; - + // Prioritise by fee once past the priority size or we run out of high-priority // transactions: if (!fSortedByFee && @@ -330,16 +330,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) comparer = TxPriorityCompare(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); } - + if (!view.HaveInputs(tx)) continue; - + CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); - + nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) continue; - + // Note that flags: we don't want to set mempool/IsStandard() // policy here, but we still have to ensure that the block we // create only contains transactions that are valid in new blocks. @@ -347,9 +347,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) PrecomputedTransactionData txdata(tx); if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) continue; - + UpdateCoins(tx, view, nHeight); - + // Added pblock->vtx.push_back(tx); pblocktemplate->vTxFees.push_back(nTxFees); @@ -358,12 +358,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ++nBlockTx; nBlockSigOps += nTxSigOps; nFees += nTxFees; - + if (fPrintPriority) { LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString()); } - + // Add transactions that depend on this one to the priority queue if (mapDependers.count(hash)) { @@ -381,7 +381,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } } } - + nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); @@ -401,21 +401,21 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - if ( GetAdjustedTime()+30 < pblock->nTime ) + if ( GetAdjustedTime() < pblock->nTime ) { - //printf("need to wait %d seconds to submit: ",(int32_t)(pblock->nTime - GetAdjustedTime())); - /*while ( GetAdjustedTime()+30 < pblock->nTime ) + printf("need to wait %d seconds to submit: ",(int32_t)(pblock->nTime - GetAdjustedTime())); + while ( GetAdjustedTime()+30 < pblock->nTime ) { sleep(30); fprintf(stderr,"%d ",(int32_t)(pblock->nTime - GetAdjustedTime())); - }*/ - //fprintf(stderr,"finished waiting\n"); - sleep(30); + } + fprintf(stderr,"finished waiting\n"); + //sleep(pblock->nTime - GetAdjustedTime()); } - + } else fprintf(stderr,"no utxos eligible for staking\n"); } - + // Create coinbase tx CMutableTransaction txNew = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); txNew.vin.resize(1); @@ -428,30 +428,30 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Add fees txNew.vout[0].nValue += nFees; txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; - + /*if ( ASSETCHAINS_SYMBOL[0] == 0 ) - { - int32_t i,opretlen; uint8_t opret[256],*ptr; - if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 ) - { - if ( (opretlen= komodo_pax_opreturn((int32_t)nHeight,opret,sizeof(opret))) > 0 ) // have pricefeed - { - txNew.vout.resize(2); - txNew.vout[1].scriptPubKey.resize(opretlen); - ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); - for (i=0; i 1 ) - fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size()); - }*/ + { + int32_t i,opretlen; uint8_t opret[256],*ptr; + if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 ) + { + if ( (opretlen= komodo_pax_opreturn((int32_t)nHeight,opret,sizeof(opret))) > 0 ) // have pricefeed + { + txNew.vout.resize(2); + txNew.vout[1].scriptPubKey.resize(opretlen); + ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); + for (i=0; i 1 ) + fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size()); + }*/ pblock->vtx[0] = txNew; if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 ) @@ -475,7 +475,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) nonce <<= 32; nonce >>= 16; pblock->nNonce = ArithToUint256(nonce); - + // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashReserved = uint256(); @@ -484,64 +484,66 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) UpdateTime(pblock, Params().GetConsensus(), pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); } + if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 ) + pblock->nTime = pindexPrev->nTime + 60; pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); - + CValidationState state; if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) { static uint32_t counter; //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) - fprintf(stderr,"warning: miner testblockvalidity failed\n"); + fprintf(stderr,"warning: miner testblockvalidity failed\n"); return(0); } } - + return pblocktemplate.release(); } /* -#ifdef ENABLE_WALLET -boost::optional GetMinerScriptPubKey(CReserveKey& reservekey) -#else -boost::optional GetMinerScriptPubKey() -#endif -{ - CKeyID keyID; - CBitcoinAddress addr; - if (addr.SetString(GetArg("-mineraddress", ""))) { - addr.GetKeyID(keyID); - } else { -#ifdef ENABLE_WALLET - CPubKey pubkey; - if (!reservekey.GetReservedKey(pubkey)) { - return boost::optional(); - } - keyID = pubkey.GetID(); -#else - return boost::optional(); -#endif - } - - CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG; - return scriptPubKey; -} - -#ifdef ENABLE_WALLET -CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) -{ - boost::optional scriptPubKey = GetMinerScriptPubKey(reservekey); -#else -CBlockTemplate* CreateNewBlockWithKey() -{ - boost::optional scriptPubKey = GetMinerScriptPubKey(); -#endif - - if (!scriptPubKey) { - return NULL; - } - return CreateNewBlock(*scriptPubKey); -}*/ + #ifdef ENABLE_WALLET + boost::optional GetMinerScriptPubKey(CReserveKey& reservekey) + #else + boost::optional GetMinerScriptPubKey() + #endif + { + CKeyID keyID; + CBitcoinAddress addr; + if (addr.SetString(GetArg("-mineraddress", ""))) { + addr.GetKeyID(keyID); + } else { + #ifdef ENABLE_WALLET + CPubKey pubkey; + if (!reservekey.GetReservedKey(pubkey)) { + return boost::optional(); + } + keyID = pubkey.GetID(); + #else + return boost::optional(); + #endif + } + + CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG; + return scriptPubKey; + } + + #ifdef ENABLE_WALLET + CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) + { + boost::optional scriptPubKey = GetMinerScriptPubKey(reservekey); + #else + CBlockTemplate* CreateNewBlockWithKey() + { + boost::optional scriptPubKey = GetMinerScriptPubKey(); + #endif + + if (!scriptPubKey) { + return NULL; + } + return CreateNewBlock(*scriptPubKey); + }*/ ////////////////////////////////////////////////////////////////////////////// // @@ -564,7 +566,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& 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; pblock->hashMerkleRoot = pblock->BuildMerkleTree(); } @@ -609,7 +611,7 @@ static bool ProcessBlockFound(CBlock* pblock) { LogPrintf("%s\n", pblock->ToString()); LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.Tip()->nHeight+1); - + // Found a solution { LOCK(cs_main); @@ -624,11 +626,11 @@ static bool ProcessBlockFound(CBlock* pblock) for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip (stale)\n"); - + return error("KomodoMiner: generated block is stale"); } } - + #ifdef ENABLE_WALLET // Remove key from key pool if ( IS_KOMODO_NOTARY == 0 ) @@ -645,19 +647,19 @@ static bool ProcessBlockFound(CBlock* pblock) wallet.mapRequestCount[pblock->GetHash()] = 0; } #endif - + // Process this block the same as if we had received it from another node CValidationState state; if (!ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) return error("KomodoMiner: ProcessNewBlock, block not accepted"); - + TrackMinedBlock(pblock->GetHash()); - + return true; } int32_t komodo_baseid(char *origbase); -int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height); +int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t *blocktimes,int32_t *nonzpkeysp,int32_t height); arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc); int32_t FOUND_BLOCK,KOMODO_MAYBEMINED; extern int32_t KOMODO_LASTMINED; @@ -674,15 +676,15 @@ void static BitcoinMiner() SetThreadPriority(THREAD_PRIORITY_LOWEST); RenameThread("komodo-miner"); const CChainParams& chainparams = Params(); - + #ifdef ENABLE_WALLET // Each thread has its own key CReserveKey reservekey(pwallet); #endif - + // Each thread has its own counter unsigned int nExtraNonce = 0; - + unsigned int n = chainparams.EquihashN(); unsigned int k = chainparams.EquihashK(); uint8_t *script; uint64_t total,checktoshis; int32_t i,j,notaryid = -1; @@ -692,12 +694,11 @@ void static BitcoinMiner() if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 ) break; } - //sleep(60); komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime()); - + std::string solver; //if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 ) - solver = "tromp"; + solver = "tromp"; //else solver = "default"; assert(solver == "tromp" || solver == "default"); LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k); @@ -706,13 +707,13 @@ void static BitcoinMiner() std::mutex m_cs; bool cancelSolver = false; boost::signals2::connection c = uiInterface.NotifyBlockTip.connect( - [&m_cs, &cancelSolver](const uint256& hashNewTip) mutable { - std::lock_guard lock{m_cs}; - cancelSolver = true; - } - ); + [&m_cs, &cancelSolver](const uint256& hashNewTip) mutable { + std::lock_guard lock{m_cs}; + cancelSolver = true; + } + ); miningTimer.start(); - + try { if ( ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); @@ -735,16 +736,16 @@ void static BitcoinMiner() break; MilliSleep(5000); //fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload()); - + } while (true); //fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); miningTimer.start(); } /*while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT ) - { - fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight); - sleep(3); - }*/ + { + fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight); + sleep(3); + }*/ // // Create new block // @@ -877,11 +878,11 @@ void static BitcoinMiner() while (true) { /*if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) // skips when it shouldnt - { - fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL); - sleep(10); - break; - }*/ + { + fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL); + sleep(10); + break; + }*/ // Hash state KOMODO_CHOSEN_ONE = 0; crypto_generichash_blake2b_state state; @@ -902,11 +903,11 @@ void static BitcoinMiner() //fprintf(stderr,"running solver\n"); std::function)> validBlock = #ifdef ENABLE_WALLET - [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] + [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] #else - [&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams] + [&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams] #endif - (std::vector soln) { + (std::vector soln) { // Write the solution to the hash and compute the result. LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; @@ -962,178 +963,178 @@ void static BitcoinMiner() #ifdef ENABLE_WALLET if (ProcessBlockFound(pblock, *pwallet, reservekey)) { #else - if (ProcessBlockFound(pblock)) { + if (ProcessBlockFound(pblock)) { #endif - // Ignore chain updates caused by us + // Ignore chain updates caused by us + std::lock_guard lock{m_cs}; + cancelSolver = false; + } + KOMODO_CHOSEN_ONE = 0; + SetThreadPriority(THREAD_PRIORITY_LOWEST); + // In regression test mode, stop mining after a block is found. + if (chainparams.MineBlocksOnDemand()) { + // Increment here because throwing skips the call below + ehSolverRuns.increment(); + throw boost::thread_interrupted(); + } + //if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 ) + // sleep(1800); + return true; + }; + std::function cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) { std::lock_guard lock{m_cs}; - cancelSolver = false; - } - KOMODO_CHOSEN_ONE = 0; - SetThreadPriority(THREAD_PRIORITY_LOWEST); - // In regression test mode, stop mining after a block is found. - if (chainparams.MineBlocksOnDemand()) { - // Increment here because throwing skips the call below - ehSolverRuns.increment(); - throw boost::thread_interrupted(); - } - //if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 ) - // sleep(1800); - return true; - }; - std::function cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) { - std::lock_guard lock{m_cs}; - return cancelSolver; - }; - - // TODO: factor this out into a function with the same API for each solver. - if (solver == "tromp" ) { //&& notaryid >= 0 ) { - // Create solver and initialize it. - equi eq(1); - eq.setstate(&curr_state); - - // Initialization done, start algo driver. - eq.digit0(0); - eq.xfull = eq.bfull = eq.hfull = 0; - eq.showbsizes(0); - for (u32 r = 1; r < WK; r++) { - (r&1) ? eq.digitodd(r, 0) : eq.digiteven(r, 0); + return cancelSolver; + }; + + // TODO: factor this out into a function with the same API for each solver. + if (solver == "tromp" ) { //&& notaryid >= 0 ) { + // Create solver and initialize it. + equi eq(1); + eq.setstate(&curr_state); + + // Initialization done, start algo driver. + eq.digit0(0); eq.xfull = eq.bfull = eq.hfull = 0; - eq.showbsizes(r); - } - eq.digitK(0); - ehSolverRuns.increment(); - - // Convert solution indices to byte array (decompress) and pass it to validBlock method. - for (size_t s = 0; s < eq.nsols; s++) { - LogPrint("pow", "Checking solution %d\n", s+1); - std::vector index_vector(PROOFSIZE); - for (size_t i = 0; i < PROOFSIZE; i++) { - index_vector[i] = eq.sols[s][i]; + eq.showbsizes(0); + for (u32 r = 1; r < WK; r++) { + (r&1) ? eq.digitodd(r, 0) : eq.digiteven(r, 0); + eq.xfull = eq.bfull = eq.hfull = 0; + eq.showbsizes(r); } - std::vector sol_char = GetMinimalFromIndices(index_vector, DIGITBITS); - - if (validBlock(sol_char)) { - // If we find a POW solution, do not try other solutions - // because they become invalid as we created a new block in blockchain. - break; + eq.digitK(0); + ehSolverRuns.increment(); + + // Convert solution indices to byte array (decompress) and pass it to validBlock method. + for (size_t s = 0; s < eq.nsols; s++) { + LogPrint("pow", "Checking solution %d\n", s+1); + std::vector index_vector(PROOFSIZE); + for (size_t i = 0; i < PROOFSIZE; i++) { + index_vector[i] = eq.sols[s][i]; + } + std::vector sol_char = GetMinimalFromIndices(index_vector, DIGITBITS); + + if (validBlock(sol_char)) { + // If we find a POW solution, do not try other solutions + // because they become invalid as we created a new block in blockchain. + break; + } + } + } else { + try { + // If we find a valid block, we rebuild + bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled); + ehSolverRuns.increment(); + if (found) { + int32_t i; uint256 hash = pblock->GetHash(); + for (i=0; i<32; i++) + fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); + fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height); + FOUND_BLOCK = 1; + KOMODO_MAYBEMINED = Mining_height; + break; + } + } catch (EhSolverCancelledException&) { + LogPrint("pow", "Equihash solver cancelled\n"); + std::lock_guard lock{m_cs}; + cancelSolver = false; } } - } else { - try { - // If we find a valid block, we rebuild - bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled); - ehSolverRuns.increment(); - if (found) { - int32_t i; uint256 hash = pblock->GetHash(); - for (i=0; i<32; i++) - fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); - fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height); - FOUND_BLOCK = 1; - KOMODO_MAYBEMINED = Mining_height; + + // Check for stop or if block needs to be rebuilt + boost::this_thread::interruption_point(); + // Regtest mode doesn't require peers + if ( FOUND_BLOCK != 0 ) + { + FOUND_BLOCK = 0; + fprintf(stderr,"FOUND_BLOCK!\n"); + //sleep(2000); + } + if (vNodes.empty() && chainparams.MiningRequiresPeers()) + { + if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT ) + { + fprintf(stderr,"no nodes, break\n"); break; } - } catch (EhSolverCancelledException&) { - LogPrint("pow", "Equihash solver cancelled\n"); - std::lock_guard lock{m_cs}; - cancelSolver = false; } - } - - // Check for stop or if block needs to be rebuilt - boost::this_thread::interruption_point(); - // Regtest mode doesn't require peers - if ( FOUND_BLOCK != 0 ) - { - FOUND_BLOCK = 0; - fprintf(stderr,"FOUND_BLOCK!\n"); - //sleep(2000); - } - if (vNodes.empty() && chainparams.MiningRequiresPeers()) - { - if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT ) + if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff) { - fprintf(stderr,"no nodes, break\n"); + //if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr,"0xffff, break\n"); break; } - } - if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff) - { - //if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) - fprintf(stderr,"0xffff, break\n"); - break; - } - if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60) - { - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) - fprintf(stderr,"timeout, break\n"); - break; - } - if ( pindexPrev != chainActive.Tip() ) - { - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) - fprintf(stderr,"Tip advanced, break\n"); - break; - } - // Update nNonce and nTime - pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); - pblock->nBits = savebits; - if ( ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 ) - UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); - if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) - { - // Changing pblock->nTime can change work required on testnet: - HASHTarget.SetCompact(pblock->nBits); + if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60) + { + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr,"timeout, break\n"); + break; + } + if ( pindexPrev != chainActive.Tip() ) + { + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr,"Tip advanced, break\n"); + break; + } + // Update nNonce and nTime + pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); + pblock->nBits = savebits; + if ( ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 ) + UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); + if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) + { + // Changing pblock->nTime can change work required on testnet: + HASHTarget.SetCompact(pblock->nBits); + } } } } - } - catch (const boost::thread_interrupted&) - { - miningTimer.stop(); - c.disconnect(); - LogPrintf("KomodoMiner terminated\n"); - throw; - } - catch (const std::runtime_error &e) - { + catch (const boost::thread_interrupted&) + { + miningTimer.stop(); + c.disconnect(); + LogPrintf("KomodoMiner terminated\n"); + throw; + } + catch (const std::runtime_error &e) + { + miningTimer.stop(); + c.disconnect(); + LogPrintf("KomodoMiner runtime error: %s\n", e.what()); + return; + } miningTimer.stop(); c.disconnect(); - LogPrintf("KomodoMiner runtime error: %s\n", e.what()); - return; } - miningTimer.stop(); - c.disconnect(); -} - + #ifdef ENABLE_WALLET -void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads) + void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads) #else -void GenerateBitcoins(bool fGenerate, int nThreads) + void GenerateBitcoins(bool fGenerate, int nThreads) #endif -{ - static boost::thread_group* minerThreads = NULL; - - if (nThreads < 0) - nThreads = GetNumCores(); - - if (minerThreads != NULL) { - minerThreads->interrupt_all(); - delete minerThreads; - minerThreads = NULL; - } - - if (nThreads == 0 || !fGenerate) - return; - - minerThreads = new boost::thread_group(); - for (int i = 0; i < nThreads; i++) { + static boost::thread_group* minerThreads = NULL; + + if (nThreads < 0) + nThreads = GetNumCores(); + + if (minerThreads != NULL) + { + minerThreads->interrupt_all(); + delete minerThreads; + minerThreads = NULL; + } + + if (nThreads == 0 || !fGenerate) + return; + + minerThreads = new boost::thread_group(); + for (int i = 0; i < nThreads; i++) { #ifdef ENABLE_WALLET - minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); + minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); #else - minerThreads->create_thread(&BitcoinMiner); + minerThreads->create_thread(&BitcoinMiner); #endif + } } -} - + #endif // ENABLE_MINING From 2ad1015fe70a7d816b5d47b09c9664fe056a970d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 22:52:25 +0300 Subject: [PATCH 14/23] Test --- src/main.cpp | 4 ++-- src/miner.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d7b0c1f7a..42ec9d111 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3808,7 +3808,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // redundant with the call in AcceptBlockHeader. if (!CheckBlockHeader(height,pindex,block,state,fCheckPOW)) { - fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW); + //fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW); return false; } if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) ) @@ -4216,7 +4216,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex } if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) { - fprintf(stderr,"TestBlockValidity failure B\n"); + //fprintf(stderr,"TestBlockValidity failure B\n"); return false; } if (!ContextualCheckBlock(block, state, pindexPrev)) diff --git a/src/miner.cpp b/src/miner.cpp index 062156822..df75ba6dc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -492,9 +492,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) CValidationState state; if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) { - static uint32_t counter; + //static uint32_t counter; //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) - fprintf(stderr,"warning: miner testblockvalidity failed\n"); + //fprintf(stderr,"warning: miner testblockvalidity failed\n"); return(0); } } From 209fce71879196dba4f5cb1aa27dbb81c146d48a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 23:17:46 +0300 Subject: [PATCH 15/23] Test --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 89b9e0aab..9413f7ef3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -873,7 +873,7 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t bloc } if ( blocktime != 0 && blocktimes[1] != 0 && blocktime < blocktimes[1]+57 ) { - fprintf(stderr,"lag.%d ht.%d n.%d blocktimes[%u vs %u %u]\n",blocktime-blocktimes[1],height,notaryid,blocktime,blocktimes[0],blocktimes[1]); + //fprintf(stderr,"lag.%d ht.%d n.%d blocktimes[%u vs %u %u]\n",blocktime-blocktimes[1],height,notaryid,blocktime,blocktimes[0],blocktimes[1]); if ( height > 807000 ) return(-2); } diff --git a/src/main.cpp b/src/main.cpp index 42ec9d111..4e6972417 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4060,7 +4060,9 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc if (pindex == NULL) { if ( (pindex= AddToBlockIndex(block)) == 0 ) - fprintf(stderr,"couldnt add to block index\n"); + { + //fprintf(stderr,"couldnt add to block index\n"); + } } if (ppindex) *ppindex = pindex; @@ -4075,7 +4077,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, CBlockIndex *&pindex = *ppindex; if (!AcceptBlockHeader(block, state, &pindex)) { - fprintf(stderr,"AcceptBlockHeader rejected\n"); + //fprintf(stderr,"AcceptBlockHeader rejected\n"); return false; } if ( pindex == 0 ) From 091240c1c223d2fc3f285b3d0a4f708873e7d198 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 23:20:46 +0300 Subject: [PATCH 16/23] Test --- src/miner.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index df75ba6dc..84194f5ba 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -485,7 +485,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); } if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 ) + { pblock->nTime = pindexPrev->nTime + 60; + fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60)); + while ( pblock->GetBlockTime() > GetAdjustedTime() + 60 ) + sleep(1); + } pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); From eec7c7822b32af88a4d60f63172b2911342cf5c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Apr 2018 23:36:08 +0300 Subject: [PATCH 17/23] Test --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 84194f5ba..01817c759 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -934,9 +934,9 @@ void static BitcoinMiner() if ( Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay ) { //printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+roundrobin_delay-time(NULL))); - int32_t nseconds = Mining_start+roundrobin_delay-time(NULL); - if ( nseconds > 0 ) - sleep(nseconds); + //int32_t nseconds = Mining_start+roundrobin_delay-time(NULL); + //if ( nseconds > 0 ) + // sleep(nseconds); MilliSleep((rand() % 1700) + 1); } else if ( ASSETCHAINS_SYMBOL[0] != 0 ) From 00f59870757a8117e07722f8c81f9e044b0a2650 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Apr 2018 10:38:33 +0300 Subject: [PATCH 18/23] New notaries activate 814000 --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 4e6972417..be5320f97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4034,7 +4034,6 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc if ( pindex != 0 ) return true; } - if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { fprintf(stderr,"CheckBlockHeader failed\n"); From d8892310a29bb87a9a396a6c3667bf543e2ecc04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Apr 2018 10:41:18 +0300 Subject: [PATCH 19/23] 814000 activation --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index ca56ecb61..1aca83614 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -127,7 +127,7 @@ const char *Notaries_elected0[][2] = }; #define KOMODO_NOTARIES_TIMESTAMP1 1525132800 // May 1st 2018 1530921600 // 7/7/2017 -#define KOMODO_NOTARIES_HEIGHT1 ((820000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) +#define KOMODO_NOTARIES_HEIGHT1 ((814000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) const char *Notaries_elected1[][2] = { From 98af287fc3ffff128b718d76062839db9eeee8e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Apr 2018 11:53:19 +0300 Subject: [PATCH 20/23] Revert special case --- src/main.cpp | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index be5320f97..cc2497616 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3994,45 +3994,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); -#ifdef DEXcode - if ( pindex != 0 && IsInitialBlockDownload() == 0 ) // jl777 debug test - { - if (!CheckBlockHeader(pindex->nHeight,pindex, block, state,0)) - { - pindex->nStatus |= BLOCK_FAILED_MASK; - fprintf(stderr,"known block failing CheckBlockHeader %d\n",(int32_t)pindex->nHeight); - return false; - } - CBlockIndex* pindexPrev = NULL; - if (hash != chainparams.GetConsensus().hashGenesisBlock) - { - BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); - if (mi == mapBlockIndex.end()) - { - pindex->nStatus |= BLOCK_FAILED_MASK; - fprintf(stderr,"known block.%d failing to find prevblock\n",(int32_t)pindex->nHeight); - return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); - } - pindexPrev = (*mi).second; - if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) - { - pindex->nStatus |= BLOCK_FAILED_MASK; - fprintf(stderr,"known block.%d found invalid prevblock\n",(int32_t)pindex->nHeight); - return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); - } - } - if (!ContextualCheckBlockHeader(block, state, pindexPrev)) - { - pindex->nStatus |= BLOCK_FAILED_MASK; - //fprintf(stderr,"known block.%d failing ContextualCheckBlockHeader\n",(int32_t)pindex->nHeight); - return false; - } - } - if ( *ppindex == 0 ) - fprintf(stderr,"unexpected null *ppindex\n"); -#endif - if ( pindex != 0 ) - return true; + return true; } if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { From 4e864502193755be25c56e182b527243003acaac Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Apr 2018 11:56:43 +0300 Subject: [PATCH 21/23] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cc2497616..4d44c21ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4043,7 +4043,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, } if ( pindex == 0 ) { - fprintf(stderr,"unexpected AcceptBlock error null pindex\n"); + //fprintf(stderr,"unexpected AcceptBlock error null pindex\n"); return false; } //fprintf(stderr,"acceptblockheader passed\n"); From 0bdff151249dceb0f585a2c438e367a4931d0572 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Apr 2018 13:54:51 +0300 Subject: [PATCH 22/23] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 4d44c21ea..11faf062b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4184,7 +4184,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex } if (!ContextualCheckBlock(block, state, pindexPrev)) { - fprintf(stderr,"TestBlockValidity failure C\n"); + //fprintf(stderr,"TestBlockValidity failure C\n"); return false; } if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) From 20f6a7273f210f0d15d86c1acba80cc08f624f48 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Apr 2018 21:24:14 +0300 Subject: [PATCH 23/23] Default JUMBLR paused --- src/komodo_globals.h | 2 +- src/rpcmisc.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 31ba6c32c..dec9a6603 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -46,7 +46,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; -int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE; +int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 20ea27f0a..7c8d7bb85 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -203,7 +203,10 @@ UniValue jumblr_deposit(const UniValue& params, bool fHelp) { string addr = params[0].get_str(); if ( (retval= Jumblr_depositaddradd((char *)addr.c_str())) >= 0 ) + { result.push_back(Pair("result", retval)); + JUMBLR_PAUSE = 0; + } else result.push_back(Pair("error", retval)); } else result.push_back(Pair("error", "invalid address")); return(result); @@ -222,6 +225,7 @@ UniValue jumblr_secret(const UniValue& params, bool fHelp) retval = Jumblr_secretaddradd((char *)addr.c_str()); result.push_back(Pair("result", "success")); result.push_back(Pair("num", retval)); + JUMBLR_PAUSE = 0; } else result.push_back(Pair("error", "invalid address")); return(result); } @@ -1084,4 +1088,4 @@ UniValue getspentinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("height", value.blockHeight)); return obj; -} \ No newline at end of file +}