From 3a443f33783403426de613c24702c6eeb22a39bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 14:45:08 +0300 Subject: [PATCH 01/72] -print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 790a84860..c952f91cc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -489,7 +489,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nTime = pindexPrev->nTime + 60; while ( pblock->GetBlockTime() > GetAdjustedTime() + 60 ) sleep(1); - 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)); + //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)); } pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); From e4f63a3df018c6b47416b1a13cee2993ac696395 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 21:32:00 +0300 Subject: [PATCH 02/72] Exemption for PoS/PoW --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3aa54f402..3056ac11d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3773,6 +3773,8 @@ int32_t komodo_fast_checkPOW(CBlock *pblock,int32_t height) fprintf(stderr,"komodo_fast_checkPOW ht.%d CheckEquihashSolution failed\n",height); return(-1); } + if ( ASSETCHAINS_STAKED != 0 ) // add PoS/PoW checks + return(0); bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); if ( UintToArith256(pblock->GetHash()) > bnTarget ) { @@ -3791,7 +3793,7 @@ int32_t komodo_fast_checkPOW(CBlock *pblock,int32_t height) } } } - fprintf(stderr,"komodo_fast_checkPOW ht.%d notaryid.%d failed.%d\n",height,notaryid,failed); + //fprintf(stderr,"komodo_fast_checkPOW ht.%d notaryid.%d failed.%d\n",height,notaryid,failed); if ( failed != 0 && notaryid < 0 ) return(-1); else return(0); From cdb2a22f71d1c4d4891f76d8f1d6cb273b20a310 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 21:49:15 +0300 Subject: [PATCH 03/72] Test --- src/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3056ac11d..ee5676c62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2585,8 +2585,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin auto disabledVerifier = libzcash::ProofVerifier::Disabled(); // Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in - if (!CheckBlock(pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck)) //!fJustCheck, !fJustCheck)) + if (!CheckBlock(pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck)) + { + fprintf(stderr,"checkblock failure in connectblock\n"); return false; + } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); @@ -3810,7 +3813,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()) ) @@ -4188,7 +4191,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex } if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { - //fprintf(stderr,"TestBlockValidity failure D\n"); + fprintf(stderr,"TestBlockValidity failure D\n"); return false; } assert(state.IsValid()); From 58a17a82a1b292eb6ca21e2a059bd08056ea9064 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 21:54:16 +0300 Subject: [PATCH 04/72] Test --- src/komodo_gateway.h | 2 +- src/main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f6ad28c59..539c86754 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -764,7 +764,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); - if ( 1 ) + if ( 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); diff --git a/src/main.cpp b/src/main.cpp index ee5676c62..c2387b39e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4181,12 +4181,12 @@ 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)) { - //fprintf(stderr,"TestBlockValidity failure C\n"); + fprintf(stderr,"TestBlockValidity failure C\n"); return false; } if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) From 1a26c3fa79ce15da5cb34395d0d66f889e6285b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 21:56:58 +0300 Subject: [PATCH 05/72] Test --- src/komodo_gateway.h | 4 ++-- src/main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 539c86754..5df44a2e5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -896,12 +896,12 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim hashval = UintToArith256(block.GetHash()); if ( hashval > bnTarget ) { - /*for (i=31; i>=0; i--) + for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," > "); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED);*/ + fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED); return(-1); } } diff --git a/src/main.cpp b/src/main.cpp index c2387b39e..071fc018f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3873,8 +3873,8 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat REJECT_INVALID, "bad-blk-sigops", true); if ( komodo_check_deposit(height,block,(pindex==0||pindex->pprev==0)?0:pindex->pprev->nTime) < 0 ) { - static uint32_t counter; - if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) + //static uint32_t counter; + //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) fprintf(stderr,"check deposit rejection\n"); return(false); } From 178273cf249e863f92b68b096464eeb5e288a934 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:02:25 +0300 Subject: [PATCH 06/72] Test --- src/miner.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index c952f91cc..1485f80a2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -882,6 +882,7 @@ void static BitcoinMiner() } while (true) { + hashtarget = HASHTarget; /*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); @@ -926,7 +927,10 @@ void static BitcoinMiner() CValidationState state; if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false)) { - fprintf(stderr,"Invalid block mined, try again\n"); + int32_t z; uint256 h = pblock->GetHash(); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," Invalid block mined, try again\n"); return(false); } if ( ASSETCHAINS_STAKED == 0 ) From f8ef6ca931583b4f44f715200f10eb70ff6bbe55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:03:29 +0300 Subject: [PATCH 07/72] Test --- src/miner.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 1485f80a2..244a4df29 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -882,7 +882,6 @@ void static BitcoinMiner() } while (true) { - hashtarget = HASHTarget; /*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); From a9550b923b2cd1885e566372cabfdcd2173482b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:07:22 +0300 Subject: [PATCH 08/72] Test --- src/miner.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 244a4df29..652659aaf 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -913,20 +913,22 @@ void static BitcoinMiner() [&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams] #endif (std::vector soln) { + int32_t z; arith_uint256 h = UintToArith256(pblock->GetHash()); // Write the solution to the hash and compute the result. LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); - if ( UintToArith256(pblock->GetHash()) > HASHTarget ) + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + if ( h > HASHTarget ) { - //if ( ASSETCHAINS_SYMBOL[0] != 0 ) - // fprintf(stderr," missed target\n"); + fprintf(stderr," missed target\n"); return false; } + fprintf(stderr," mined hash\n"); CValidationState state; if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false)) { - int32_t z; uint256 h = pblock->GetHash(); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," Invalid block mined, try again\n"); From aea2d1aaddc1227d6894f7477ce3d57b00fcbdd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:12:00 +0300 Subject: [PATCH 09/72] Test --- src/miner.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 652659aaf..7fd50e426 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -918,14 +918,20 @@ void static BitcoinMiner() LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); - for (z=31; z>=0; z--) + for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); if ( h > HASHTarget ) { fprintf(stderr," missed target\n"); return false; } - fprintf(stderr," mined hash\n"); + fprintf(stderr," mined "); + for (z=31; z>=16; z--) + fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr," hashTarget "); + for (z=31; z>=16; z--) + fprintf(stderr,"%02x",((uint8_t *)&HASHTarget)[z]); + fprintf(stderr," HASHTarget\n"); CValidationState state; if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false)) { From 23fc88bbda29ec5d59e39ef445d4e3cd28c3ee06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:18:40 +0300 Subject: [PATCH 10/72] Test --- src/miner.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 7fd50e426..b29c26dac 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -878,7 +878,7 @@ void static BitcoinMiner() HASHTarget = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget)[z]); - fprintf(stderr," PoW for staked coin\n"); + fprintf(stderr," PoW for staked coin %p\n",&HASHTarget); } while (true) { @@ -918,13 +918,8 @@ void static BitcoinMiner() LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); - for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); if ( h > HASHTarget ) - { - fprintf(stderr," missed target\n"); return false; - } fprintf(stderr," mined "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); @@ -1095,11 +1090,13 @@ void static BitcoinMiner() 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); + UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); + if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) + { + // Changing pblock->nTime can change work required on testnet: + HASHTarget.SetCompact(pblock->nBits); + } } } } From 919fa982ea3b723e1823bf24fde1c3558d28007d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:19:31 +0300 Subject: [PATCH 11/72] Test --- src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 071fc018f..6f43e59b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3875,7 +3875,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat { //static uint32_t counter; //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) - fprintf(stderr,"check deposit rejection\n"); + // fprintf(stderr,"check deposit rejection\n"); return(false); } return true; @@ -4176,22 +4176,22 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - fprintf(stderr,"TestBlockValidity failure A\n"); + //fprintf(stderr,"TestBlockValidity failure A\n"); return false; } 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)) { - fprintf(stderr,"TestBlockValidity failure C\n"); + //fprintf(stderr,"TestBlockValidity failure C\n"); return false; } if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { - fprintf(stderr,"TestBlockValidity failure D\n"); + //fprintf(stderr,"TestBlockValidity failure D\n"); return false; } assert(state.IsValid()); From 3fdbd5bf82aaa55aa95de234ee95018075929c34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:23:10 +0300 Subject: [PATCH 12/72] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index b29c26dac..177df1fb7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1089,7 +1089,7 @@ void static BitcoinMiner() // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; - if ( ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 ) + if ( ASSETCHAINS_STAKED == 0 && NOTARY_PUBKEY33[0] == 0 ) { UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) From 98a5a298ed98b43c72dbbea7c9df52a8762ea7e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:35:24 +0300 Subject: [PATCH 13/72] Test --- src/miner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 177df1fb7..6a3451084 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -905,7 +905,9 @@ void static BitcoinMiner() // (x_1, x_2, ...) = A(I, V, n, k) LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString()); arith_uint256 hashTarget = HASHTarget; - //fprintf(stderr,"running solver\n"); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr," running solver\n"); std::function)> validBlock = #ifdef ENABLE_WALLET [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] From 44b34dfba526cb5e0c85294a1d1b51ee2fb038ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:37:07 +0300 Subject: [PATCH 14/72] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 6a3451084..1a22a1626 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -905,7 +905,7 @@ void static BitcoinMiner() // (x_1, x_2, ...) = A(I, V, n, k) LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString()); arith_uint256 hashTarget = HASHTarget; - for (z=31; z>=0; z--) + int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); fprintf(stderr," running solver\n"); std::function)> validBlock = From 02c30aac1ea9cc15e368d0ec41ac4eb235c6989c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:39:53 +0300 Subject: [PATCH 15/72] Test --- src/miner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 1a22a1626..9a3757fe3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -922,6 +922,8 @@ void static BitcoinMiner() solutionTargetChecks.increment(); if ( h > HASHTarget ) return false; + for (z=31; z>=16; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); From 30eaf9e23d66813772b434d957cab7a8b917479c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:42:21 +0300 Subject: [PATCH 16/72] Test --- src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6f43e59b6..071fc018f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3875,7 +3875,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat { //static uint32_t counter; //if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) - // fprintf(stderr,"check deposit rejection\n"); + fprintf(stderr,"check deposit rejection\n"); return(false); } return true; @@ -4176,22 +4176,22 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - //fprintf(stderr,"TestBlockValidity failure A\n"); + fprintf(stderr,"TestBlockValidity failure A\n"); return false; } 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)) { - //fprintf(stderr,"TestBlockValidity failure C\n"); + fprintf(stderr,"TestBlockValidity failure C\n"); return false; } if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { - //fprintf(stderr,"TestBlockValidity failure D\n"); + fprintf(stderr,"TestBlockValidity failure D\n"); return false; } assert(state.IsValid()); From 6cbd97e3e90bd0c4cbe96b828bca0f84fa707641 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 22:47:50 +0300 Subject: [PATCH 17/72] Test --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 6fb357ac6..09e5a4beb 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 ( 0 && height > 792000 ) + //if ( 0 && height > 792000 ) { for (i=31; i>=0; i--) printf("%02x",((uint8_t *)&hash)[i]); From 18443f692d9cba5c74a6f93b1bad205c9d22c6bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 13:59:36 +0300 Subject: [PATCH 18/72] Cleanup assetchains mining options --- src/komodo_bitcoind.h | 276 ++++++++++++++++++++++++++++++++++++++++++ src/komodo_gateway.h | 200 ------------------------------ src/main.cpp | 58 ++------- src/miner.cpp | 62 ++++------ src/pow.cpp | 3 - 5 files changed, 314 insertions(+), 285 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b82be68a6..eb8747500 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1046,3 +1046,279 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ return(0); } +/* + komodo_checkPOW (fast) is called early in the process and should only refer to data immediately available. it is a filter to prevent bad blocks from going into the local DB + + komodo_checkPOW (slow) is called right before connecting blocks so all prior blocks can be assumed to be there and all checks must pass + + commission must be in coinbase.vout[1] and must be >= 10000 sats + PoS stake must be without txfee and in the last tx in the block at vout[0] + PoW mining on PoS chain must solve a harder diff that adjusts, but never less than KOMODO_POWMINMULT + */ +#define KOMODO_POWMINMULT 16 + +uint64_t komodo_commission(const CBlock *pblock) +{ + int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; + txn_count = pblock->vtx.size(); + for (i=0; ivtx[i].vout.size(); + for (j=0; jvtx[i].vout[j].nValue; + } + } + //fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); + commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + if ( commission < 10000 ) + commission = 0; + return(commission); +} + +uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) +{ + CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + txtime = komodo_txtime(&value,txid,vout,address); + if ( value == 0 || txtime == 0 ) + return(0); + if ( (minage= nHeight*3) > 6000 ) + minage = 6000; + if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) + { + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + segid = ((nHeight + addrhash.uints[0]) & 0x3f); + pasthash = pindex->GetBlockHash(); + memcpy(hashbuf,&pasthash,sizeof(pasthash)); + memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); + vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); + //fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); + for (iter=0; iter<3600; iter++) + { + diff = (iter + blocktime - txtime - minage); + if ( diff > 3600*24 ) + break; + coinage = (value * diff) * ((diff >> 16) + 1); + hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); + if ( hashval <= bnTarget ) + { + winner = 1; + if ( validateflag == 0 ) + { + blocktime += iter; + blocktime += segid * 2; + } + break; + } + if ( validateflag != 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs target "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff); + break; + } + } + //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); + if ( 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff); + } + } + if ( nHeight < 2 ) + return(blocktime); + return(blocktime * winner); +} + +arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) +{ + CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff; + *percPoSp = percPoS = 0; + sum = arith_uint256(0); + ave = sum; + for (i=n=0; i<100; i++) + { + ht = height - 100 + i; + if ( (pindex= komodo_chainactive(ht)) != 0 ) + { + bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); + bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); + hashval = UintToArith256(pindex->GetBlockHash()); + if ( hashval <= bnTarget ) // PoW is never as easy as PoS/64, some PoS will be counted as PoW + { + sum += hashval; + n++; + } else percPoS++; + } + } + *percPoSp = percPoS; + target = (target / arith_uint256(KOMODO_POWMINMULT)); + if ( n > 0 ) + { + ave = (sum / arith_uint256(n)); + if ( ave > target ) + ave = target; + } else return(target); + if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget + { + bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); + if ( 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); + fprintf(stderr," increase diff -> "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," floor diff "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&target)[i]); + fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + } + } + else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget + { + bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + if ( 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); + fprintf(stderr," decrease diff -> "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," floor diff "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&target)[i]); + fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + } + } + else bnTarget = ave; // recent ave is perfect + return(bnTarget); +} + +int32_t komodo_is_PoSblock(int32_t slowflag,CBlock *pblock,arith_uint256 bnTarget) +{ + CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t prevtime=0; int32_t vout,txn_count,isPoS = 0; + txn_count = pblock->vtx.size(); + if ( txn_count > 1 ) + { + if ( prevtime == 0 ) + { + if ( (previndex= mapBlockIndex[pblock->hashPrevBlock]) != 0 ) + prevtime = (uint32_t)previndex->nTime; + } + txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; + vout = pblock->vtx[txn_count-1].vin[0].prevout.n; + if ( prevtime != 0 ) + { + eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); + if ( eligible == 0 || eligible > pblock->nTime ) + { + fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); + } else isPoS = 1; + } + else if ( slowflag == 0 )// maybe previous block is not seen yet, do the best approx + { + txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) + { + strcpy(voutaddr,CBitcoinAddress(address).ToString().c_str()); + if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[txn_count-1].vout[0].value == value ) + isPoS = 1; // close enough for a pre-filter + else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].value)); + } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height); + } else return(-1); + } + return(isPoS); +} + +int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) +{ + arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; + if ( height == 0 ) + return(0); + if ( !CheckEquihashSolution(pblock, Params()) ) + { + fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height); + return(-1); + } + bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); + bhash = UintToArith256(pblock->GetHash()); + komodo_block2pubkey33(pubkey33,pblock); + if ( slowflag != 0 ) + { + if ( !CheckProofOfWork(height,pubkey33,bhash,pblock->nBits,Params().GetConsensus(),pblock->nTime) ) + return state.DoS(1, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash"); + } + if ( bhash > bnTarget ) + { + failed = 1; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) // for the fast case + { + if ( (n= komodo_notaries(pubkeys,height,pblock->nTime)) > 0 ) + { + for (i=0; i= 2 ) // must PoS or have at least 16x better PoW + { + if ( (is_PoSblock= komodo_is_PoSblock(slowflag,&block,bnTarget)) == 0 ) + { + if ( ASSETCHAINS_STAKED == 100 || height <= 100 ) // only PoS allowed! + return(-1); + else + { + if ( slowflag != 0 ) + bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); + else bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); // lower bound + if ( bhash > bnTarget ) + { + for (i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," > "); + for (i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED); + return(-1); + } + } + } else if ( isPoSblock < 0 ) + return(-1); + } + if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) + { + checktoshis = komodo_commission(pblock); + if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) + return(-1); + else if ( checktoshis != 0 ) + { + script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + return(-1); + if ( pblock->vtx[0].vout[1].nValue != checktoshis ) + { + fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue)); + return(-1); + } + } + } + //fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d notaryid.%d failed.%d\n",slowflag,height,notaryid,failed); + if ( failed != 0 && notaryid < 0 ) + return(-1); + else return(0); +} + diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5df44a2e5..945f0b71b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -650,153 +650,6 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) void komodo_passport_iteration(); -uint64_t komodo_commission(const CBlock &block) -{ - int32_t i,j,n=0,txn_count; uint64_t total = 0; - txn_count = block.vtx.size(); - for (i=0; i %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); - return((total * ASSETCHAINS_COMMISSION) / COIN); -} - -uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) -{ - CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - txtime = komodo_txtime(&value,txid,vout,address); - if ( value == 0 || txtime == 0 ) - return(0); - if ( (minage= nHeight*3) > 6000 ) - minage = 6000; - if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) - { - vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); - segid = ((nHeight + addrhash.uints[0]) & 0x3f); - pasthash = pindex->GetBlockHash(); - memcpy(hashbuf,&pasthash,sizeof(pasthash)); - memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); - vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); - //fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); - for (iter=0; iter<3600; iter++) - { - diff = (iter + blocktime - txtime - minage); - if ( diff > 3600*24 ) - break; - coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); - if ( hashval <= bnTarget ) - { - winner = 1; - if ( validateflag == 0 ) - { - blocktime += iter; - blocktime += segid * 2; - } - break; - } - if ( validateflag != 0 ) - { - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs target "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff); - break; - } - } - //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 ) - { - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff); - } - } - if ( nHeight < 2 ) - return(blocktime); - return(blocktime * winner); -} - -#define KOMODO_POWMINMULT 16 -arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) -{ - CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff; - *percPoSp = percPoS = 0; - sum = arith_uint256(0); - ave = sum; - for (i=n=0; i<100; i++) - { - ht = height - 100 + i; - if ( (pindex= komodo_chainactive(ht)) != 0 ) - { - bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); - bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); - hashval = UintToArith256(pindex->GetBlockHash()); - if ( hashval <= bnTarget ) // PoW is never as easy as PoS/64, some PoS will be counted as PoW - { - sum += hashval; - n++; - } else percPoS++; - } - } - *percPoSp = percPoS; - target = (target / arith_uint256(KOMODO_POWMINMULT)); - if ( n > 0 ) - { - ave = (sum / arith_uint256(n)); - if ( ave > target ) - ave = target; - } else return(target); - if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget - { - bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); - if ( 0 ) - { - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); - fprintf(stderr," increase diff -> "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," floor diff "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&target)[i]); - fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); - } - } - else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget - { - bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); - if ( 1 ) - { - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); - fprintf(stderr," decrease diff -> "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," floor diff "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&target)[i]); - fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); - } - } - else bnTarget = ave; // recent ave is perfect - return(bnTarget); -} - int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; @@ -867,59 +720,6 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } else { - if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) - { - arith_uint256 bnTarget,hashval; int32_t PoSperc; bool fNegative,fOverflow; CBlockIndex *previndex; uint32_t eligible,isPoS = 0; - bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - if ( txn_count > 1 ) - { - if ( prevtime == 0 ) - { - if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 ) - prevtime = (uint32_t)previndex->nTime; - } - eligible = komodo_stake(1,bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime,(char *)""); - if ( eligible == 0 || eligible > block.nTime ) - { - fprintf(stderr,"PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); - } else isPoS = 1; - } - if ( isPoS == 0 && height > 100 ) - { - if ( ASSETCHAINS_STAKED == 100 ) - { - fprintf(stderr,"ht.%d 100%% PoS after height 100 rule violated for -ac_staking=100\n",height); - return(-1); - } - // check PoW - bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - hashval = UintToArith256(block.GetHash()); - if ( hashval > bnTarget ) - { - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," > "); - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED); - return(-1); - } - } - } - if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) - { - script = (uint8_t *)block.vtx[0].vout[1].scriptPubKey.data(); - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) - return(-1); - if ( (checktoshis = komodo_commission(block)) != 0 ) - { - if ( block.vtx[0].vout[1].nValue != checktoshis ) - { - fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); - return(-1); - } else return(0); - } - } if ( overflow != 0 || total > 0 ) return(-1); } diff --git a/src/main.cpp b/src/main.cpp index 071fc018f..c50d3dcd2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2801,14 +2801,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001); CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus()) + sum; - if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) + if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) { uint64_t checktoshis; - if ( (checktoshis = komodo_commission(block)) != 0 ) + if ( (checktoshis= komodo_commission((CBlock *)&block)) != 0 ) { if ( block.vtx[0].vout.size() == 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; - else fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); + else fprintf(stderr,"checktoshis %.8f numvouts %d\n",dstr(checktoshis),block.vtx[0].vout.size()); } } if ( block.vtx[0].GetValueOut() > blockReward+1 ) @@ -3765,42 +3765,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime); - -int32_t komodo_fast_checkPOW(CBlock *pblock,int32_t height) -{ - arith_uint256 bnTarget; bool fNegative,fOverflow; uint8_t pubkey33[33],pubkeys[64][33]; int32_t i,n,failed = 0,notaryid = -1; - if ( height == 0 ) - return(0); - if ( !CheckEquihashSolution(pblock, Params()) ) - { - fprintf(stderr,"komodo_fast_checkPOW ht.%d CheckEquihashSolution failed\n",height); - return(-1); - } - if ( ASSETCHAINS_STAKED != 0 ) // add PoS/PoW checks - return(0); - bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); - if ( UintToArith256(pblock->GetHash()) > bnTarget ) - { - failed = 1; - if ( ASSETCHAINS_SYMBOL[0] == 0 ) - { - komodo_block2pubkey33(pubkey33,pblock); - if ( (n= komodo_notaries(pubkeys,height,pblock->nTime)) > 0 ) - { - for (i=0; iGetHash()); fRequested |= fForceProcessing; - if ( checked != 0 && komodo_fast_checkPOW(pblock,height) < 0 ) + if ( checked != 0 && komodo_checkPOW(0,pblock,height) < 0 ) checked = 0; if (!checked) { diff --git a/src/miner.cpp b/src/miner.cpp index 9a3757fe3..be2bb5e03 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -119,7 +119,7 @@ int32_t komodo_is_issuer(); int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t tokomodo); int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); -uint64_t komodo_commission(const CBlock &block); +uint64_t komodo_commission(const CBlock *block); int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) @@ -428,33 +428,9 @@ 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()); - }*/ - + pblock->vtx[0] = txNew; - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); @@ -669,7 +645,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t FOUND_BLOCK,KOMODO_MAYBEMINED; extern int32_t KOMODO_LASTMINED; int32_t roundrobin_delay; -arith_uint256 HASHTarget; +arith_uint256 HASHTarget,HASHTarget_POW; #ifdef ENABLE_WALLET void static BitcoinMiner(CWallet *pwallet) @@ -875,7 +851,7 @@ void static BitcoinMiner() sleep(60); continue; } - HASHTarget = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); + HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget)[z]); fprintf(stderr," PoW for staked coin %p\n",&HASHTarget); @@ -904,7 +880,10 @@ void static BitcoinMiner() crypto_generichash_blake2b_update(&curr_state,pblock->nNonce.begin(),pblock->nNonce.size()); // (x_1, x_2, ...) = A(I, V, n, k) LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString()); - arith_uint256 hashTarget = HASHTarget; + arith_uint256 hashTarget; + if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) + hashTarget = HASHTarget_POW; + else hashTarget = HASHTarget; int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); fprintf(stderr," running solver\n"); @@ -920,17 +899,25 @@ void static BitcoinMiner() LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); - if ( h > HASHTarget ) - return false; + if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) + { + if ( h > HASHTarget_POW ) + return false; + } + else + { + if ( h > HASHTarget ) + return false; + } for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr,"%02x",((uint8_t *)&HASHTarget)[z]); fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&HASHTarget)[z]); - fprintf(stderr," HASHTarget\n"); + fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); + fprintf(stderr," POW\n"); CValidationState state; if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false)) { @@ -958,7 +945,7 @@ void static BitcoinMiner() { if ( NOTARY_PUBKEY33[0] != 0 ) { - printf("need to wait %d seconds to submit\n",(int32_t)(pblock->nTime - GetAdjustedTime())); + printf("need to wait %d seconds to submit staked block\n",(int32_t)(pblock->nTime - GetAdjustedTime())); while ( GetAdjustedTime() < pblock->nTime ) sleep(1); } @@ -1093,13 +1080,14 @@ void static BitcoinMiner() // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; - if ( ASSETCHAINS_STAKED == 0 && NOTARY_PUBKEY33[0] == 0 ) + if ( 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); + HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); } } } diff --git a/src/pow.cpp b/src/pow.cpp index 09e5a4beb..0cb6e89ce 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -206,9 +206,6 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int 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; } From 3acce0422987e46307f857fed2022eb972a53dd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:06:01 +0300 Subject: [PATCH 19/72] syntax --- src/komodo_bitcoind.h | 25 +++++++++++++------------ src/main.cpp | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index eb8747500..696008623 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1063,7 +1063,7 @@ uint64_t komodo_commission(const CBlock *pblock) txn_count = pblock->vtx.size(); for (i=0; ivtx[i].vout.size(); + n = pblock->vtx[i].vout.size(); for (j=0; jvtx.size(); if ( txn_count > 1 ) { @@ -1230,10 +1230,10 @@ int32_t komodo_is_PoSblock(int32_t slowflag,CBlock *pblock,arith_uint256 bnTarge txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) { - strcpy(voutaddr,CBitcoinAddress(address).ToString().c_str()); - if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[txn_count-1].vout[0].value == value ) + strcpy(voutaddr,CBitcoinAddress(destaddress).ToString().c_str()); + if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[txn_count-1].vout[0].nValue == value ) isPoS = 1; // close enough for a pre-filter - else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].value)); + else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].nValue)); } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height); } else return(-1); } @@ -1242,7 +1242,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,CBlock *pblock,arith_uint256 bnTarge int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { - arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; + uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; if ( height == 0 ) return(0); if ( !CheckEquihashSolution(pblock, Params()) ) @@ -1251,12 +1251,13 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); - bhash = UintToArith256(pblock->GetHash()); + hash = pblock->GetHash(); + bhash = UintToArith256(hash); komodo_block2pubkey33(pubkey33,pblock); if ( slowflag != 0 ) { - if ( !CheckProofOfWork(height,pubkey33,bhash,pblock->nBits,Params().GetConsensus(),pblock->nTime) ) - return state.DoS(1, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash"); + if ( !CheckProofOfWork(height,pubkey33,hash,pblock->nBits,Params().GetConsensus(),pblock->nTime) ) + return(-1); } if ( bhash > bnTarget ) { @@ -1276,7 +1277,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { - if ( (is_PoSblock= komodo_is_PoSblock(slowflag,&block,bnTarget)) == 0 ) + if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) { if ( ASSETCHAINS_STAKED == 100 || height <= 100 ) // only PoS allowed! return(-1); @@ -1296,7 +1297,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } - } else if ( isPoSblock < 0 ) + } else if ( is_PoSblock < 0 ) return(-1); } if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) diff --git a/src/main.cpp b/src/main.cpp index c50d3dcd2..42a7fda56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3786,7 +3786,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat //if ( !CheckEquihashSolution(&block, Params()) ) // return state.DoS(100, error("CheckBlock: Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); komodo_block2pubkey33(pubkey33,(CBlock *)&block); - if ( komodo_checkPOW(1,&block,height) < 0 ) // checks Equihash + if ( komodo_checkPOW(1,(CBlock *)&block,height) < 0 ) // checks Equihash return state.DoS(100, error("CheckBlock: failed slow_checkPOW"),REJECT_INVALID, "failed-slow_checkPOW"); } // Check the merkle root. From 2808b68f942810ab733fd34cebe309970a5e2d89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:09:02 +0300 Subject: [PATCH 20/72] Syntax --- src/komodo_bitcoind.h | 8 ++++---- src/main.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 696008623..470f6a90e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1206,7 +1206,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget) { - CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; CTxDestination destaddress; + CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; txn_count = pblock->vtx.size(); if ( txn_count > 1 ) { @@ -1222,7 +1222,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { - fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); + fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); } else isPoS = 1; } else if ( slowflag == 0 )// maybe previous block is not seen yet, do the best approx @@ -1230,7 +1230,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) { - strcpy(voutaddr,CBitcoinAddress(destaddress).ToString().c_str()); + strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[txn_count-1].vout[0].nValue == value ) isPoS = 1; // close enough for a pre-filter else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].nValue)); @@ -1289,7 +1289,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( bhash > bnTarget ) { for (i=31; i>=16; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr,"%02x",((uint8_t *)&bhash)[i]); fprintf(stderr," > "); for (i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); diff --git a/src/main.cpp b/src/main.cpp index 42a7fda56..4792ac536 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2808,7 +2808,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { if ( block.vtx[0].vout.size() == 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; - else fprintf(stderr,"checktoshis %.8f numvouts %d\n",dstr(checktoshis),block.vtx[0].vout.size()); + else fprintf(stderr,"checktoshis %.8f numvouts %d\n",dstr(checktoshis),(int32_t)block.vtx[0].vout.size()); } } if ( block.vtx[0].GetValueOut() > blockReward+1 ) From f8f740a966178f5f39d524a0dbb2a8a5d5e8ab12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:10:25 +0300 Subject: [PATCH 21/72] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index be2bb5e03..fe97b97c7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1082,6 +1082,7 @@ void static BitcoinMiner() pblock->nBits = savebits; if ( NOTARY_PUBKEY33[0] == 0 ) { + int32_t percPoS; UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) { From 8fbee9292d5d601d4feb1c82fba075a27c326f02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:17:47 +0300 Subject: [PATCH 22/72] Test --- src/komodo_bitcoind.h | 5 ----- src/main.cpp | 10 ++++++---- src/miner.cpp | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 470f6a90e..fd9b6e4b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1254,11 +1254,6 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) hash = pblock->GetHash(); bhash = UintToArith256(hash); komodo_block2pubkey33(pubkey33,pblock); - if ( slowflag != 0 ) - { - if ( !CheckProofOfWork(height,pubkey33,hash,pblock->nBits,Params().GetConsensus(),pblock->nTime) ) - return(-1); - } if ( bhash > bnTarget ) { failed = 1; diff --git a/src/main.cpp b/src/main.cpp index 4792ac536..304e766c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3786,6 +3786,8 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat //if ( !CheckEquihashSolution(&block, Params()) ) // return state.DoS(100, error("CheckBlock: Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); komodo_block2pubkey33(pubkey33,(CBlock *)&block); + if ( !CheckProofOfWork(height,pubkey33,blockhdr.GetHash(),block.nBits,Params().GetConsensus(),block.nTime) ) + return state.DoS(50, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash"); if ( komodo_checkPOW(1,(CBlock *)&block,height) < 0 ) // checks Equihash return state.DoS(100, error("CheckBlock: failed slow_checkPOW"),REJECT_INVALID, "failed-slow_checkPOW"); } @@ -4144,22 +4146,22 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - fprintf(stderr,"TestBlockValidity failure A\n"); + fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW); return false; } if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) { - fprintf(stderr,"TestBlockValidity failure B\n"); + fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW); return false; } if (!ContextualCheckBlock(block, state, pindexPrev)) { - fprintf(stderr,"TestBlockValidity failure C\n"); + fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW); return false; } if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { - fprintf(stderr,"TestBlockValidity failure D\n"); + fprintf(stderr,"TestBlockValidity failure D checkPOW.%d\n",fCheckPOW); return false; } assert(state.IsValid()); diff --git a/src/miner.cpp b/src/miner.cpp index fe97b97c7..41e6c025f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -853,8 +853,8 @@ void static BitcoinMiner() } HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&HASHTarget)[z]); - fprintf(stderr," PoW for staked coin %p\n",&HASHTarget); + fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); + fprintf(stderr," PoW for staked coin %p\n",&HASHTarget_POW); } while (true) { From fbd15acf157408542be4d049e4332d6244149ad8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:18:44 +0300 Subject: [PATCH 23/72] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 304e766c2..8d607cb5c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3786,7 +3786,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat //if ( !CheckEquihashSolution(&block, Params()) ) // return state.DoS(100, error("CheckBlock: Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); komodo_block2pubkey33(pubkey33,(CBlock *)&block); - if ( !CheckProofOfWork(height,pubkey33,blockhdr.GetHash(),block.nBits,Params().GetConsensus(),block.nTime) ) + if ( !CheckProofOfWork(height,pubkey33,block.GetHash(),block.nBits,Params().GetConsensus(),block.nTime) ) return state.DoS(50, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash"); if ( komodo_checkPOW(1,(CBlock *)&block,height) < 0 ) // checks Equihash return state.DoS(100, error("CheckBlock: failed slow_checkPOW"),REJECT_INVALID, "failed-slow_checkPOW"); From d335898793733060523534a2a1a977710d662f20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:31:27 +0300 Subject: [PATCH 24/72] Test --- src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 8d607cb5c..c92a04d39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3787,7 +3787,13 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // return state.DoS(100, error("CheckBlock: Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); komodo_block2pubkey33(pubkey33,(CBlock *)&block); if ( !CheckProofOfWork(height,pubkey33,block.GetHash(),block.nBits,Params().GetConsensus(),block.nTime) ) + { + uint256 h = block.GetHash(); + for (z=0; z<32; z++) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," failed hash\n"); return state.DoS(50, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash"); + } if ( komodo_checkPOW(1,(CBlock *)&block,height) < 0 ) // checks Equihash return state.DoS(100, error("CheckBlock: failed slow_checkPOW"),REJECT_INVALID, "failed-slow_checkPOW"); } From 4202cc246ca5e8846399126e19029ff33e5fde8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:32:27 +0300 Subject: [PATCH 25/72] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c92a04d39..5e8c76650 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3788,7 +3788,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat komodo_block2pubkey33(pubkey33,(CBlock *)&block); if ( !CheckProofOfWork(height,pubkey33,block.GetHash(),block.nBits,Params().GetConsensus(),block.nTime) ) { - uint256 h = block.GetHash(); + int32_t z; uint256 h = block.GetHash(); for (z=0; z<32; z++) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," failed hash\n"); From 80afe35bdca8fdd05ac28e4cabf109676bec18bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:44:05 +0300 Subject: [PATCH 26/72] test --- src/main.cpp | 4 ++-- src/pow.cpp | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5e8c76650..34c39424d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3789,9 +3789,9 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat if ( !CheckProofOfWork(height,pubkey33,block.GetHash(),block.nBits,Params().GetConsensus(),block.nTime) ) { int32_t z; uint256 h = block.GetHash(); - for (z=0; z<32; z++) + for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," failed hash\n"); + fprintf(stderr," failed hash ht.%d\n",height); return state.DoS(50, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash"); } if ( komodo_checkPOW(1,(CBlock *)&block,height) < 0 ) // checks Equihash diff --git a/src/pow.cpp b/src/pow.cpp index 0cb6e89ce..2de78050f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -136,6 +136,9 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int extern int32_t KOMODO_REWIND; bool fNegative,fOverflow; uint8_t origpubkey33[33]; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,flag = 0, mids[66]; uint32_t tiptime,blocktimes[66]; arith_uint256 bnTarget; uint8_t pubkeys[66][33]; + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); + fprintf(stderr," checkpow\n"); memcpy(origpubkey33,pubkey33,33); memset(blocktimes,0,sizeof(blocktimes)); tiptime = komodo_chainactive_timestamp(); @@ -195,17 +198,17 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int //if ( 0 && height > 792000 ) { for (i=31; i>=0; i--) - printf("%02x",((uint8_t *)&hash)[i]); - printf(" hash vs "); + fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); + fprintf(stderr," 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)); + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," ht.%d special.%d notaryid.%d ht.%d mod.%d error\n",height,special,notaryid,fheight,(height % 35)); for (i=0; i<33; i++) - printf("%02x",pubkey33[i]); - printf(" <- pubkey\n"); + fprintf(stderr,"%02x",pubkey33[i]); + fprintf(stderr," <- pubkey\n"); for (i=0; i<33; i++) - printf("%02x",origpubkey33[i]); - printf(" <- origpubkey\n"); + fprintf(stderr,"%02x",origpubkey33[i]); + fprintf(stderr," <- origpubkey\n"); } return false; } From 4b5d43e3ff6c3c3aa054155497f76e26812e7512 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:45:16 +0300 Subject: [PATCH 27/72] Test --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 2de78050f..1638909e3 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -202,7 +202,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int fprintf(stderr," hash vs "); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," ht.%d special.%d notaryid.%d ht.%d mod.%d error\n",height,special,notaryid,fheight,(height % 35)); + fprintf(stderr," ht.%d special.%d notaryid.%d mod.%d error\n",height,special,notaryid,(height % 35)); for (i=0; i<33; i++) fprintf(stderr,"%02x",pubkey33[i]); fprintf(stderr," <- pubkey\n"); From bb3ab99ac0a1977399a34ce271020f794b8182fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:50:22 +0300 Subject: [PATCH 28/72] Test --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 41e6c025f..6a72979dd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -884,9 +884,9 @@ void static BitcoinMiner() if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; - int32_t z; for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); - fprintf(stderr," running solver\n"); + //int32_t z; for (z=31; z>=0; z--) + // fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + //fprintf(stderr," running solver\n"); std::function)> validBlock = #ifdef ENABLE_WALLET [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] From e5d9a70246db09bf7ed0b3e95317c115cf4d9e90 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 14:57:51 +0300 Subject: [PATCH 29/72] Test --- src/main.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 34c39424d..e7e4a9754 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3771,7 +3771,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat libzcash::ProofVerifier& verifier, bool fCheckPOW, bool fCheckMerkleRoot) { - uint8_t pubkey33[33]; + uint8_t pubkey33[33]; uint256 hash; // These are checks that are independent of context. // Check that the header is valid (particularly PoW). This is mostly @@ -3783,14 +3783,18 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat } if ( fCheckPOW ) { - //if ( !CheckEquihashSolution(&block, Params()) ) + int32_t z; + //if ( !CheckEquihashSolution(&block, Params()) ) // return state.DoS(100, error("CheckBlock: Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); + hash = block.GetHash(); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hash)[z]); + fprintf(stderr," check hash ht.%d\n",height); komodo_block2pubkey33(pubkey33,(CBlock *)&block); - if ( !CheckProofOfWork(height,pubkey33,block.GetHash(),block.nBits,Params().GetConsensus(),block.nTime) ) + if ( !CheckProofOfWork(height,pubkey33,hash,block.nBits,Params().GetConsensus(),block.nTime) ) { - int32_t z; uint256 h = block.GetHash(); for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr,"%02x",((uint8_t *)&hash)[z]); fprintf(stderr," failed hash ht.%d\n",height); return state.DoS(50, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash"); } From 18dd6a3b58f40dae53221deba96c36c5879ce8e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 15:12:19 +0300 Subject: [PATCH 30/72] Test --- src/main.cpp | 24 ++++++++++++++++++++++-- src/miner.cpp | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e7e4a9754..df911fa7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3773,7 +3773,11 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat { uint8_t pubkey33[33]; uint256 hash; // These are checks that are independent of context. - + hash = block.GetHash(); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hash)[z]); + fprintf(stderr," CheckBlock ht.%d\n",height); + // Check that the header is valid (particularly PoW). This is mostly // redundant with the call in AcceptBlockHeader. if (!CheckBlockHeader(height,pindex,block,state,fCheckPOW)) @@ -4152,23 +4156,39 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex indexDummy.nHeight = pindexPrev->nHeight + 1; // JoinSplit proofs are verified in ConnectBlock auto verifier = libzcash::ProofVerifier::Disabled(); - + uint256 h; + h = block.GetHash(); + for (z=31; z>=16; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," test hash\n"); // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW); return false; } + h = block.GetHash(); + for (z=31; z>=16; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," test hash2\n"); if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) { fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW); return false; } + h = block.GetHash(); + for (z=31; z>=16; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," test hash3\n"); if (!ContextualCheckBlock(block, state, pindexPrev)) { fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW); return false; } + h = block.GetHash(); + for (z=31; z>=16; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," test hash4\n"); if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { fprintf(stderr,"TestBlockValidity failure D checkPOW.%d\n",fCheckPOW); diff --git a/src/miner.cpp b/src/miner.cpp index 6a72979dd..149f0ea87 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1080,7 +1080,7 @@ void static BitcoinMiner() // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; - if ( NOTARY_PUBKEY33[0] == 0 ) + /*if ( NOTARY_PUBKEY33[0] == 0 ) { int32_t percPoS; UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); @@ -1090,7 +1090,7 @@ void static BitcoinMiner() HASHTarget.SetCompact(pblock->nBits); HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); } - } + }*/ } } } From fb3cd913efa83ac4c45ea2e735f9f871f233920e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 15:13:50 +0300 Subject: [PATCH 31/72] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index df911fa7d..b7c77bb51 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3774,6 +3774,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat uint8_t pubkey33[33]; uint256 hash; // These are checks that are independent of context. hash = block.GetHash(); + int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&hash)[z]); fprintf(stderr," CheckBlock ht.%d\n",height); @@ -3787,7 +3788,6 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat } if ( fCheckPOW ) { - int32_t z; //if ( !CheckEquihashSolution(&block, Params()) ) // return state.DoS(100, error("CheckBlock: Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); hash = block.GetHash(); @@ -4156,7 +4156,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex indexDummy.nHeight = pindexPrev->nHeight + 1; // JoinSplit proofs are verified in ConnectBlock auto verifier = libzcash::ProofVerifier::Disabled(); - uint256 h; + int32_t z; uint256 h; h = block.GetHash(); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); From 2ae7e0b5fa3163d785f144c4ffdba3e1b88f7c40 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 15:19:58 +0300 Subject: [PATCH 32/72] Test --- src/miner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 149f0ea87..759c6e013 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -894,11 +894,12 @@ void static BitcoinMiner() [&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams] #endif (std::vector soln) { - int32_t z; arith_uint256 h = UintToArith256(pblock->GetHash()); + int32_t z; arith_uint256 h; // Write the solution to the hash and compute the result. LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); + h = UintToArith256(pblock->GetHash()); if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) { if ( h > HASHTarget_POW ) @@ -921,6 +922,7 @@ void static BitcoinMiner() CValidationState state; if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false)) { + h = UintToArith256(pblock->GetHash()); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," Invalid block mined, try again\n"); From c21c630657c638e877b6d45c78ed741ef42151a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 15:33:36 +0300 Subject: [PATCH 33/72] Test --- src/miner.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 759c6e013..759567278 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -884,9 +884,6 @@ void static BitcoinMiner() if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; - //int32_t z; for (z=31; z>=0; z--) - // fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); - //fprintf(stderr," running solver\n"); std::function)> validBlock = #ifdef ENABLE_WALLET [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] @@ -894,22 +891,22 @@ void static BitcoinMiner() [&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams] #endif (std::vector soln) { - int32_t z; arith_uint256 h; + int32_t z; arith_uint256 h; CBlock B; // Write the solution to the hash and compute the result. + B = *pblock; + h = UintToArith256(B.GetHash()); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr," running solver\n"); LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); - h = UintToArith256(pblock->GetHash()); - if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) - { - if ( h > HASHTarget_POW ) - return false; - } - else - { - if ( h > HASHTarget ) - return false; - } + h = UintToArith256(B.GetHash()); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr," running solver2\n"); + if ( h > hashTarget ) + return false; for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); @@ -920,9 +917,9 @@ void static BitcoinMiner() fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); fprintf(stderr," POW\n"); CValidationState state; - if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), true, false)) + if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) { - h = UintToArith256(pblock->GetHash()); + h = UintToArith256(B.GetHash()); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," Invalid block mined, try again\n"); From 286d95b1df048c6c69649ceed989f0f4fbc16a87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 15:38:34 +0300 Subject: [PATCH 34/72] Test --- src/miner.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 759567278..11f25cb71 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -895,16 +895,9 @@ void static BitcoinMiner() // Write the solution to the hash and compute the result. B = *pblock; h = UintToArith256(B.GetHash()); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); - fprintf(stderr," running solver\n"); LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); - h = UintToArith256(B.GetHash()); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); - fprintf(stderr," running solver2\n"); if ( h > hashTarget ) return false; for (z=31; z>=16; z--) @@ -950,7 +943,7 @@ void static BitcoinMiner() } else { - uint256 tmp = pblock->GetHash(); + uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); fprintf(stderr," mined block!\n"); From eff2c3a35a07b488bbc08cea0a0c5eeaa3c36719 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 15:43:39 +0300 Subject: [PATCH 35/72] Test --- src/miner.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 11f25cb71..92a274644 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -893,14 +893,14 @@ void static BitcoinMiner() (std::vector soln) { int32_t z; arith_uint256 h; CBlock B; // Write the solution to the hash and compute the result. - B = *pblock; - h = UintToArith256(B.GetHash()); LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); + B = *pblock; + h = UintToArith256(B.GetHash()); if ( h > hashTarget ) return false; - for (z=31; z>=16; z--) + /*for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) @@ -908,7 +908,7 @@ void static BitcoinMiner() fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n"); + fprintf(stderr," POW\n");*/ CValidationState state; if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) { @@ -937,8 +937,8 @@ void static BitcoinMiner() { if ( NOTARY_PUBKEY33[0] != 0 ) { - printf("need to wait %d seconds to submit staked block\n",(int32_t)(pblock->nTime - GetAdjustedTime())); - while ( GetAdjustedTime() < pblock->nTime ) + printf("need to wait %d seconds to submit staked block\n",(int32_t)(B.nTime - GetAdjustedTime())); + while ( GetAdjustedTime() < B.nTime ) sleep(1); } else @@ -953,11 +953,11 @@ void static BitcoinMiner() // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL); LogPrintf("KomodoMiner:\n"); - LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), HASHTarget.GetHex()); + LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", B.GetHash().GetHex(), HASHTarget.GetHex()); #ifdef ENABLE_WALLET - if (ProcessBlockFound(pblock, *pwallet, reservekey)) { + if (ProcessBlockFound(&B, *pwallet, reservekey)) { #else - if (ProcessBlockFound(pblock)) { + if (ProcessBlockFound(&B)) { #endif // Ignore chain updates caused by us std::lock_guard lock{m_cs}; @@ -1019,7 +1019,7 @@ void static BitcoinMiner() bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled); ehSolverRuns.increment(); if (found) { - int32_t i; uint256 hash = pblock->GetHash(); + int32_t i; uint256 hash = B.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); @@ -1051,7 +1051,7 @@ void static BitcoinMiner() break; } } - if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff) + if ((UintToArith256(B.nNonce) & 0xffff) == 0xffff) { //if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"0xffff, break\n"); From 997ddd92c75d4ff531ef4c86b4a195eb2dadd316 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 15:44:56 +0300 Subject: [PATCH 36/72] Test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 92a274644..7e8fa4196 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1019,7 +1019,7 @@ void static BitcoinMiner() bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled); ehSolverRuns.increment(); if (found) { - int32_t i; uint256 hash = B.GetHash(); + 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); @@ -1051,7 +1051,7 @@ void static BitcoinMiner() break; } } - if ((UintToArith256(B.nNonce) & 0xffff) == 0xffff) + if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff) { //if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"0xffff, break\n"); From bf30e02d79618e593f8742ad9a74e59f6ac06dfc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 15:53:28 +0300 Subject: [PATCH 37/72] Test --- src/main.cpp | 17 ----------------- src/miner.cpp | 2 +- src/pow.cpp | 6 +++--- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b7c77bb51..194f3ce7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4156,39 +4156,22 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex indexDummy.nHeight = pindexPrev->nHeight + 1; // JoinSplit proofs are verified in ConnectBlock auto verifier = libzcash::ProofVerifier::Disabled(); - int32_t z; uint256 h; - h = block.GetHash(); - for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," test hash\n"); // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW); return false; } - h = block.GetHash(); - for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," test hash2\n"); if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) { fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW); return false; } - h = block.GetHash(); - for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," test hash3\n"); if (!ContextualCheckBlock(block, state, pindexPrev)) { fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW); return false; } - h = block.GetHash(); - for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," test hash4\n"); if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { fprintf(stderr,"TestBlockValidity failure D checkPOW.%d\n",fCheckPOW); diff --git a/src/miner.cpp b/src/miner.cpp index 7e8fa4196..494629552 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -854,7 +854,7 @@ void static BitcoinMiner() HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," PoW for staked coin %p\n",&HASHTarget_POW); + fprintf(stderr," PoW for staked coin PoS %d%%\n",&HASHTarget_POW,percPoS); } while (true) { diff --git a/src/pow.cpp b/src/pow.cpp index 1638909e3..310e9721b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -136,9 +136,9 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int extern int32_t KOMODO_REWIND; bool fNegative,fOverflow; uint8_t origpubkey33[33]; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,flag = 0, mids[66]; uint32_t tiptime,blocktimes[66]; arith_uint256 bnTarget; uint8_t pubkeys[66][33]; - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); - fprintf(stderr," checkpow\n"); + //for (i=31; i>=0; i--) + // fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); + //fprintf(stderr," checkpow\n"); memcpy(origpubkey33,pubkey33,33); memset(blocktimes,0,sizeof(blocktimes)); tiptime = komodo_chainactive_timestamp(); From af0c41ee3df86a2f9dd98966de05979f66b96240 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 15:55:17 +0300 Subject: [PATCH 38/72] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 494629552..fe01faaad 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -854,7 +854,7 @@ void static BitcoinMiner() HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," PoW for staked coin PoS %d%%\n",&HASHTarget_POW,percPoS); + fprintf(stderr," PoW for staked coin PoS %d%%\n",percPoS); } while (true) { From 7bb789bb6646edf4921be246c49fccf40202ae4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 16:03:51 +0300 Subject: [PATCH 39/72] Test --- src/main.cpp | 18 +++++------------- src/main.h | 2 +- src/miner.cpp | 2 +- src/rpcmining.cpp | 4 ++-- src/test/miner_tests.cpp | 4 ++-- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 194f3ce7c..481adb10d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3774,10 +3774,6 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat uint8_t pubkey33[33]; uint256 hash; // These are checks that are independent of context. hash = block.GetHash(); - int32_t z; - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&hash)[z]); - fprintf(stderr," CheckBlock ht.%d\n",height); // Check that the header is valid (particularly PoW). This is mostly // redundant with the call in AcceptBlockHeader. @@ -3790,10 +3786,6 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat { //if ( !CheckEquihashSolution(&block, Params()) ) // return state.DoS(100, error("CheckBlock: Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); - hash = block.GetHash(); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&hash)[z]); - fprintf(stderr," check hash ht.%d\n",height); komodo_block2pubkey33(pubkey33,(CBlock *)&block); if ( !CheckProofOfWork(height,pubkey33,hash,block.nBits,Params().GetConsensus(),block.nTime) ) { @@ -4105,7 +4097,7 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned void komodo_currentheight_set(int32_t height); -bool ProcessNewBlock(int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) +bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) { // Preliminary checks bool checked; @@ -4117,7 +4109,7 @@ bool ProcessNewBlock(int32_t height,CValidationState &state, CNode* pfrom, CBloc LOCK(cs_main); bool fRequested = MarkBlockAsReceived(pblock->GetHash()); fRequested |= fForceProcessing; - if ( checked != 0 && komodo_checkPOW(0,pblock,height) < 0 ) + if ( checked != 0 && komodo_checkPOW(from_miner,pblock,height) < 0 ) checked = 0; if (!checked) { @@ -4919,7 +4911,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) // process in case the block isn't known yet if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) { CValidationState state; - if (ProcessNewBlock(0,state, NULL, &block, true, dbp)) + if (ProcessNewBlock(0,0,state, NULL, &block, true, dbp)) nLoaded++; if (state.IsError()) break; @@ -4941,7 +4933,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(), head.ToString()); CValidationState dummy; - if (ProcessNewBlock(0,dummy, NULL, &block, true, &it->second)) + if (ProcessNewBlock(0,0,dummy, NULL, &block, true, &it->second)) { nLoaded++; queue.push_back(block.GetHash()); @@ -6026,7 +6018,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // Such an unrequested block may still be processed, subject to the // conditions in AcceptBlock(). bool forceProcessing = pfrom->fWhitelisted && !IsInitialBlockDownload(); - ProcessNewBlock(0,state, pfrom, &block, forceProcessing, NULL); + ProcessNewBlock(0,0,state, pfrom, &block, forceProcessing, NULL); int nDoS; if (state.IsInvalid(nDoS)) { pfrom->PushMessage("reject", strCommand, state.GetRejectCode(), diff --git a/src/main.h b/src/main.h index 035328a22..f52fa222d 100644 --- a/src/main.h +++ b/src/main.h @@ -190,7 +190,7 @@ void UnregisterNodeSignals(CNodeSignals& nodeSignals); * @param[out] dbp If pblock is stored to disk (or already there), this will be set to its location. * @return True if state.IsValid() */ -bool ProcessNewBlock(int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp); +bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp); /** Check whether enough disk space is available for an incoming block */ bool CheckDiskSpace(uint64_t nAdditionalBytes = 0); /** Open a block file (blk?????.dat) */ diff --git a/src/miner.cpp b/src/miner.cpp index fe01faaad..211f55d7a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -631,7 +631,7 @@ static bool ProcessBlockFound(CBlock* pblock) // 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)) + if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index d141c42c4..aea5694f2 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -267,7 +267,7 @@ UniValue generate(const UniValue& params, bool fHelp) } endloop: CValidationState state; - if (!ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); ++nHeight; blockHashes.push_back(pblock->GetHash().GetHex()); @@ -807,7 +807,7 @@ UniValue submitblock(const UniValue& params, bool fHelp) CValidationState state; submitblock_StateCatcher sc(block.GetHash()); RegisterValidationInterface(&sc); - bool fAccepted = ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL); + bool fAccepted = ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL); UnregisterValidationInterface(&sc); if (fBlockPresent) { diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 9b8674f04..27edc8669 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) CValidationState state; - if (ProcessNewBlock(state, NULL, pblock, true, NULL) && state.IsValid()) { + if (ProcessNewBlock(1,state, NULL, pblock, true, NULL) && state.IsValid()) { goto foundit; } @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) */ CValidationState state; - BOOST_CHECK(ProcessNewBlock(state, NULL, pblock, true, NULL)); + BOOST_CHECK(ProcessNewBlock(1,state, NULL, pblock, true, NULL)); BOOST_CHECK_MESSAGE(state.IsValid(), state.GetRejectReason()); pblock->hashPrevBlock = pblock->GetHash(); From 560da193c645ec2904883bd9db65e2275b362ec4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 16:06:31 +0300 Subject: [PATCH 40/72] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 481adb10d..d104b7992 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3789,7 +3789,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat komodo_block2pubkey33(pubkey33,(CBlock *)&block); if ( !CheckProofOfWork(height,pubkey33,hash,block.nBits,Params().GetConsensus(),block.nTime) ) { - for (z=31; z>=0; z--) + int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&hash)[z]); fprintf(stderr," failed hash ht.%d\n",height); return state.DoS(50, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash"); From b509fdae1431807b3eeb9d65226319c6d2156583 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 16:27:54 +0300 Subject: [PATCH 41/72] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 211f55d7a..3ead4b6bc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -854,7 +854,7 @@ void static BitcoinMiner() HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," PoW for staked coin PoS %d%%\n",percPoS); + fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%%\n",percPoS,(int32_t)ASSETCHAINS_STAKED); } while (true) { From 56930f21f15e87e5982caecf9cf5b4a74ac872ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 17:30:09 +0300 Subject: [PATCH 42/72] Test --- src/komodo_bitcoind.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fd9b6e4b8..41e3fbfd5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1141,7 +1141,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff; + CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave,factor; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff; *percPoSp = percPoS = 0; sum = arith_uint256(0); ave = sum; @@ -1170,8 +1170,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { - bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); - if ( 0 ) + factor = arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); + bnTarget = (ave * factor * factor); + if ( 1 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); From d4da197214160e64ea72c60b1cc1c22a7d7688ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 17:31:51 +0300 Subject: [PATCH 43/72] Test --- src/komodo_bitcoind.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 41e3fbfd5..7886576d4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1170,8 +1170,12 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { - factor = arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); - bnTarget = (ave * factor * factor); + if ( height < 1120 ) + { + factor = arith_uint256(goalperc) / arith_uint256(percPoS + goalperc); + bnTarget = (ave * factor * factor); + } + else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); if ( 1 ) { for (i=31; i>=24; i--) From 861319af5e830f4c9e75c70ed4766922ba19afed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 17:32:09 +0300 Subject: [PATCH 44/72] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7886576d4..095941657 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1170,7 +1170,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { - if ( height < 1120 ) + if ( height > 1120 ) { factor = arith_uint256(goalperc) / arith_uint256(percPoS + goalperc); bnTarget = (ave * factor * factor); From ff556351ad5ce3e94c2bc235da9f09b97c41bb48 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 17:35:25 +0300 Subject: [PATCH 45/72] Test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 095941657..be4c94484 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1170,10 +1170,10 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { - if ( height > 1120 ) + if ( height > 1200 ) { - factor = arith_uint256(goalperc) / arith_uint256(percPoS + goalperc); - bnTarget = (ave * factor * factor); + factor = arith_uint256(goalperc * goalperc) / arith_uint256((percPoS + goalperc) * (percPoS + goalperc)); + bnTarget = (ave * factor); } else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); if ( 1 ) From 6897193353d9c88d3adceaea5090bedeb41e0253 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 17:41:56 +0300 Subject: [PATCH 46/72] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index be4c94484..625d81cd8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1172,7 +1172,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { if ( height > 1200 ) { - factor = arith_uint256(goalperc * goalperc) / arith_uint256((percPoS + goalperc) * (percPoS + goalperc)); + factor = arith_uint256(goalperc * goalperc) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); bnTarget = (ave * factor); } else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); From 96cf6918b7273cea4e4e0e6273dca86ba763b334 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 17:46:08 +0300 Subject: [PATCH 47/72] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 625d81cd8..b22e3fa56 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1170,7 +1170,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { - if ( height > 1200 ) + if ( height > 1165 ) { factor = arith_uint256(goalperc * goalperc) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); bnTarget = (ave * factor); From 67eaffd906da86472608638db736869d05d5d0b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 17:58:27 +0300 Subject: [PATCH 48/72] Test --- src/komodo_bitcoind.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b22e3fa56..40a3e5231 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1141,7 +1141,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave,factor; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff; + CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff; *percPoSp = percPoS = 0; sum = arith_uint256(0); ave = sum; @@ -1171,10 +1171,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { if ( height > 1165 ) - { - factor = arith_uint256(goalperc * goalperc) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); - bnTarget = (ave * factor); - } + bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); if ( 1 ) { From d5a8071bc78e5d0de71104eb1394e9febdd1fdae Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 18:16:01 +0300 Subject: [PATCH 49/72] Test --- src/komodo_bitcoind.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 40a3e5231..7b0eb45f0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1171,7 +1171,11 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { if ( height > 1165 ) - bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); + { + if ( height > 1180 ) + bnTarget = ((ave * arith_uint256(percPoS)) + (target * arith_uint256(goalperc))) / arith_uint256(2 * (percPoS + goalperc)); + else bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); + } else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); if ( 1 ) { From 1247b7d42915efe0754e57dbcd090f83429e21cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 18:32:29 +0300 Subject: [PATCH 50/72] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7b0eb45f0..23f8820a6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1141,7 +1141,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff; + CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; *percPoSp = percPoS = 0; sum = arith_uint256(0); ave = sum; @@ -1173,7 +1173,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( height > 1165 ) { if ( height > 1180 ) - bnTarget = ((ave * arith_uint256(percPoS)) + (target * arith_uint256(goalperc))) / arith_uint256(2 * (percPoS + goalperc)); + bnTarget = ave * arith_uint256(persPoS * persPoS)) / arith_uint256((percPoS + goalperc) * (percPoS + goalperc)); else bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); } else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); From b36ad22ad678755f02364e7e449eba1b9d3198fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 18:33:15 +0300 Subject: [PATCH 51/72] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 23f8820a6..e0c340aed 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1173,7 +1173,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( height > 1165 ) { if ( height > 1180 ) - bnTarget = ave * arith_uint256(persPoS * persPoS)) / arith_uint256((percPoS + goalperc) * (percPoS + goalperc)); + bnTarget = ave * arith_uint256(percPoS * percPoS)) / arith_uint256((percPoS + goalperc) * (percPoS + goalperc)); else bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); } else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); From d395043eb3824977b878fe4266c9ac1515c9e3db Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 18:35:16 +0300 Subject: [PATCH 52/72] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0c340aed..9cca24b65 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1173,7 +1173,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( height > 1165 ) { if ( height > 1180 ) - bnTarget = ave * arith_uint256(percPoS * percPoS)) / arith_uint256((percPoS + goalperc) * (percPoS + goalperc)); + bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256((percPoS + goalperc) * (percPoS + goalperc)); else bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); } else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); From 689a24a7724b4d76d9278f9636839bfe5f686867 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 18:40:20 +0300 Subject: [PATCH 53/72] Test --- src/komodo_bitcoind.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9cca24b65..dd04d92e2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1155,11 +1155,18 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he hashval = UintToArith256(pindex->GetBlockHash()); if ( hashval <= bnTarget ) // PoW is never as easy as PoS/64, some PoS will be counted as PoW { + fprintf(stderr,"1"); sum += hashval; n++; - } else percPoS++; + } + else + { + percPoS++; + fprintf(stderr,"0"); + } } } + fprintf(stderr," -> %d%% percPoS ht.%d\n",percPoS,height); *percPoSp = percPoS; target = (target / arith_uint256(KOMODO_POWMINMULT)); if ( n > 0 ) From 23b680a0f4f205e3889cfb0aaef4896361bb1407 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 19:24:53 +0300 Subject: [PATCH 54/72] Test --- src/komodo_bitcoind.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index dd04d92e2..7866595b5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1180,7 +1180,11 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( height > 1165 ) { if ( height > 1180 ) - bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256((percPoS + goalperc) * (percPoS + goalperc)); + { + if ( height > 1230 ) + bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256((goalperc) * (goalperc)); + else bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc); + } else bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); } else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); @@ -1200,7 +1204,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); - if ( 0 ) + if ( 1 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); From 7b6d6985a996a102f05eaebee20d094804f9957f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 20:33:41 +0300 Subject: [PATCH 55/72] Test --- src/komodo_bitcoind.h | 10 ++++++---- src/wallet/rpcwallet.cpp | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7866595b5..b6c3d651b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1082,10 +1082,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); - if ( value == 0 || txtime == 0 ) + if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) return(0); if ( (minage= nHeight*3) > 6000 ) minage = 6000; + if ( blocktime < prevtime+57 ) + blocktime = prevtime+57; if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) { vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); @@ -1177,7 +1179,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { - if ( height > 1165 ) + bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256((goalperc) * (goalperc)); + /*if ( height > 1165 ) { if ( height > 1180 ) { @@ -1186,8 +1189,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he else bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc); } else bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); - } - else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); + } else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc);*/ if ( 1 ) { for (i=31; i>=24; i--) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 347c15f2d..010f51319 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4494,7 +4494,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( eligible > 0 ) { if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) - fprintf(stderr,"validation of winning blocktime failed %u -> eligible.%u\n",*blocktimep,eligible); + { + //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + } else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { earliest = eligible; From 23b2b0fab8b536108655a395a52ab0f444e79e3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 20:42:52 +0300 Subject: [PATCH 56/72] Test --- src/komodo_bitcoind.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b6c3d651b..00adc28a6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1086,8 +1086,6 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh return(0); if ( (minage= nHeight*3) > 6000 ) minage = 6000; - if ( blocktime < prevtime+57 ) - blocktime = prevtime+57; if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) { vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); From 6d7537dedb5fe173f4e648935a3746659cd64b07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 20:48:27 +0300 Subject: [PATCH 57/72] Test --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 00adc28a6..10a95d3f7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1086,6 +1086,8 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh return(0); if ( (minage= nHeight*3) > 6000 ) minage = 6000; + if ( blocktime < prevtime+57 ) + blocktime = prevtime+57; if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) { vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); @@ -1291,7 +1293,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) { - if ( ASSETCHAINS_STAKED == 100 || height <= 100 ) // only PoS allowed! + if ( ASSETCHAINS_STAKED == 100 && height > 100 ) // only PoS allowed! return(-1); else { From 8ab6dd61df84968934b6906c6a788c9b1e81834e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 20:51:43 +0300 Subject: [PATCH 58/72] Test --- src/komodo_bitcoind.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 10a95d3f7..5b0ddf0c3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1145,6 +1145,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; *percPoSp = percPoS = 0; + if ( height < 100 ) + return(target); sum = arith_uint256(0); ave = sum; for (i=n=0; i<100; i++) From d9935f2b615fd46e88d0d7d3542b9997c2233df2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 20:54:47 +0300 Subject: [PATCH 59/72] Test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3ead4b6bc..dbdc87309 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -846,11 +846,11 @@ void static BitcoinMiner() if ( ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] == 0 ) { int32_t percPoS,z; - if ( Mining_height <= 100 ) + /*if ( Mining_height <= 100 ) { sleep(60); continue; - } + }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); From d07308d221a62da3a10a3dd40f1a4d6b34e43c5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 20:59:03 +0300 Subject: [PATCH 60/72] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index dbdc87309..d31ebb995 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -384,7 +384,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); From a1a721bd4589923921b6bdd1093f293e9f8f3f8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 21:00:57 +0300 Subject: [PATCH 61/72] Test --- src/komodo_bitcoind.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5b0ddf0c3..10a95d3f7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1145,8 +1145,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; *percPoSp = percPoS = 0; - if ( height < 100 ) - return(target); sum = arith_uint256(0); ave = sum; for (i=n=0; i<100; i++) From 96df006a14a8b5c594bd2dbb1acb44e8e6aa675d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 21:11:09 +0300 Subject: [PATCH 62/72] Test --- src/komodo_bitcoind.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 10a95d3f7..2db96544e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1145,6 +1145,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; *percPoSp = percPoS = 0; + if ( height < 3 ) + return(target); sum = arith_uint256(0); ave = sum; for (i=n=0; i<100; i++) From bd87f0c09ee1939644952e707a1ac6226dca2b86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 22:43:52 +0300 Subject: [PATCH 63/72] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index d104b7992..56756ee9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4109,7 +4109,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo LOCK(cs_main); bool fRequested = MarkBlockAsReceived(pblock->GetHash()); fRequested |= fForceProcessing; - if ( checked != 0 && komodo_checkPOW(from_miner,pblock,height) < 0 ) + if ( checked != 0 && komodo_checkPOW(from_miner && ASSETCHAINS_STAKED == 0,pblock,height) < 0 ) checked = 0; if (!checked) { From 13b8b2ed264b4d3f77ee67b28e5118c6bda86646 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 23:11:11 +0300 Subject: [PATCH 64/72] Test --- src/komodo_bitcoind.h | 5 ++++- src/main.cpp | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2db96544e..afbcd537d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1246,7 +1246,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); } else isPoS = 1; } - else if ( slowflag == 0 )// maybe previous block is not seen yet, do the best approx + else if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx { txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) @@ -1265,7 +1265,10 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; if ( height == 0 ) + { + fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d null\n",slowflag,height); return(0); + } if ( !CheckEquihashSolution(pblock, Params()) ) { fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height); diff --git a/src/main.cpp b/src/main.cpp index 56756ee9f..e51e7318b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4016,12 +4016,12 @@ 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 ) { - //fprintf(stderr,"unexpected AcceptBlock error null pindex\n"); + fprintf(stderr,"unexpected AcceptBlock error null pindex\n"); return false; } //fprintf(stderr,"acceptblockheader passed\n"); @@ -4110,7 +4110,10 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo bool fRequested = MarkBlockAsReceived(pblock->GetHash()); fRequested |= fForceProcessing; if ( checked != 0 && komodo_checkPOW(from_miner && ASSETCHAINS_STAKED == 0,pblock,height) < 0 ) + { checked = 0; + fprintf(stderr,"passed checkblock but failed checkPOW\n"); + } if (!checked) { if ( pfrom != 0 ) From f1b57a6e76a59ebdeafaed182161706ef1e6b1d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 23:18:23 +0300 Subject: [PATCH 65/72] Test --- src/komodo_bitcoind.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index afbcd537d..17e9752db 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1264,16 +1264,16 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; - if ( height == 0 ) - { - fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d null\n",slowflag,height); - return(0); - } if ( !CheckEquihashSolution(pblock, Params()) ) { fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height); return(-1); } + if ( height == 0 ) + { + fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d null\n",slowflag,height); + return(0); + } bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); hash = pblock->GetHash(); bhash = UintToArith256(hash); From ec5b59fd30e47b35c456cad05a32a28b195481cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 23:34:55 +0300 Subject: [PATCH 66/72] Test --- src/komodo_bitcoind.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 17e9752db..49efdd38e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1263,19 +1263,22 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { - uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; + uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; if ( !CheckEquihashSolution(pblock, Params()) ) { fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height); return(-1); } + hash = pblock->GetHash(); if ( height == 0 ) { - fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d null\n",slowflag,height); - return(0); + if ( (pprev= mapBlockIndex[pblock->hashPrevBlock]) != 0 ) + height = pprev->nHeight + 1; + fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d zeroheight\n",slowflag,height); + if ( height == 0 ) + return(0); } bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); - hash = pblock->GetHash(); bhash = UintToArith256(hash); komodo_block2pubkey33(pubkey33,pblock); if ( bhash > bnTarget ) From 8eb43ab4ff24488e92e8686653f5e20c5f8144c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Apr 2018 00:23:58 +0300 Subject: [PATCH 67/72] Decrement notes for assetchains, need to test --- src/main.cpp | 2 +- src/wallet/wallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e51e7318b..b53e39294 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4021,7 +4021,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"); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a1c7039cf..77a27c69a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -414,7 +414,7 @@ void CWallet::ChainTip(const CBlockIndex *pindex, const CBlock *pblock, { if (added) { IncrementNoteWitnesses(pindex, pblock, tree); - } else if ( ASSETCHAINS_SYMBOL[0] == 0 || nWitnessCacheSize > 1 ){ + } else if ( nWitnessCacheSize > 1 ){ //ASSETCHAINS_SYMBOL[0] == 0 || DecrementNoteWitnesses(pindex); } else fprintf(stderr,"would have decremented %s nWitnessCacheSize.%d\n",ASSETCHAINS_SYMBOL,(int32_t)nWitnessCacheSize); } From 65b4e8809d38753ab5a508d921c6e81950448ff1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Apr 2018 00:39:38 +0300 Subject: [PATCH 68/72] Test --- src/miner.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index d31ebb995..7a07bb060 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -635,7 +635,17 @@ static bool ProcessBlockFound(CBlock* pblock) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); - + fprintf(stderr,"broadcast new block t.%u\n",(uint32_t)time(NULL)); + { + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes) + { + if ( pnode->hSocket == INVALID_SOCKET ) + continue; + pnode->PushMessage("block", *pblock); + } + } + fprintf(stderr,"finished broadcast new block t.%u\n",(uint32_t)time(NULL)); return true; } From 7377cedcf6274308bd70b14811a42a732390687f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Apr 2018 00:40:03 +0300 Subject: [PATCH 69/72] Test --- src/miner.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 7a07bb060..7b7b81a19 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -635,17 +635,20 @@ static bool ProcessBlockFound(CBlock* pblock) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); - fprintf(stderr,"broadcast new block t.%u\n",(uint32_t)time(NULL)); + if ( ASSETCHAINS_STAKED != 0 ) { - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) + fprintf(stderr,"broadcast new block t.%u\n",(uint32_t)time(NULL)); { - if ( pnode->hSocket == INVALID_SOCKET ) - continue; - pnode->PushMessage("block", *pblock); + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes) + { + if ( pnode->hSocket == INVALID_SOCKET ) + continue; + pnode->PushMessage("block", *pblock); + } } + fprintf(stderr,"finished broadcast new block t.%u\n",(uint32_t)time(NULL)); } - fprintf(stderr,"finished broadcast new block t.%u\n",(uint32_t)time(NULL)); return true; } From 8d028ba0612e200ff15ee4e614d1c5d264b68322 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Apr 2018 01:06:43 +0300 Subject: [PATCH 70/72] Test --- src/komodo_bitcoind.h | 4 ++-- src/main.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 49efdd38e..ed465b083 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1275,7 +1275,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( (pprev= mapBlockIndex[pblock->hashPrevBlock]) != 0 ) height = pprev->nHeight + 1; fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d zeroheight\n",slowflag,height); - if ( height == 0 ) + //if ( height == 0 ) return(0); } bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); @@ -1339,7 +1339,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } } } - //fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d notaryid.%d failed.%d\n",slowflag,height,notaryid,failed); + fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d notaryid.%d failed.%d\n",slowflag,height,notaryid,failed); if ( failed != 0 && notaryid < 0 ) return(-1); else return(0); diff --git a/src/main.cpp b/src/main.cpp index b53e39294..ef7227bfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4112,7 +4112,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo if ( checked != 0 && komodo_checkPOW(from_miner && ASSETCHAINS_STAKED == 0,pblock,height) < 0 ) { checked = 0; - fprintf(stderr,"passed checkblock but failed checkPOW\n"); + fprintf(stderr,"passed checkblock but failed checkPOW.%d\n",from_miner && ASSETCHAINS_STAKED == 0); } if (!checked) { From 02290a3fd86453ca023c32c87d0ddbba13afff30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Apr 2018 01:15:21 +0300 Subject: [PATCH 71/72] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ef7227bfd..0aee36d10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1677,7 +1677,7 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos,bo return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString()); } // Check the header - if ( checkPOW != 0 ) + if ( 0 && checkPOW != 0 ) { komodo_block2pubkey33(pubkey33,(CBlock *)&block); if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime))) From 26f6fa01cbbbd47afdab67abaf30b3beadef467f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Apr 2018 09:38:46 +0300 Subject: [PATCH 72/72] Add back MoM that dev merge undid --- src/komodo.h | 23 +++++++++++------------ src/komodo_events.h | 8 ++++---- src/komodo_notary.h | 6 +++--- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9212269eb..1b557d08b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -121,7 +121,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char MoMdepth = 0; } //if ( matched != 0 ) global independent states -> inside *sp - komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height);//,MoM,MoMdepth); + komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height,MoM,MoMdepth); } else if ( func == 'U' ) // deprecated { @@ -266,7 +266,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long memset(&MoM,0,sizeof(MoM)); MoMdepth = 0; } - komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height);//,MoM,MoMdepth); + komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height,MoM,MoMdepth); } else if ( func == 'U' ) // deprecated { @@ -482,10 +482,9 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); if ( sp != 0 ) { - //if ( sp->MoMdepth > 0 && sp->MoM != zero ) - // fputc('M',fp); - //else - fputc('N',fp); + if ( sp->MoMdepth > 0 && sp->MoM != zero ) + fputc('M',fp); + else fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) ) @@ -494,14 +493,14 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) errs++; - /*if ( sp->MoMdepth > 0 && sp->MoM != zero ) + if ( sp->MoMdepth > 0 && sp->MoM != zero ) { if ( fwrite(&sp->MoM,1,sizeof(sp->MoM),fp) != sizeof(sp->MoM) ) errs++; if ( fwrite(&sp->MoMdepth,1,sizeof(sp->MoMdepth),fp) != sizeof(sp->MoMdepth) ) errs++; - }*/ - komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT);//,sp->MoM,sp->MoMdepth); + } + komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT,sp->MoM,sp->MoMdepth); } } fflush(fp); @@ -680,7 +679,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else { - //komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata); + komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata); //printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth); } if ( MoMoMdata.pairs != 0 ) @@ -688,8 +687,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr memset(&ccdata,0,sizeof(ccdata)); memset(&MoMoMdata,0,sizeof(MoMoMdata)); } - //else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 ) - // komodo_rwccdata((char *)"KMD",1,&ccdata,0); + else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 ) + komodo_rwccdata((char *)"KMD",1,&ccdata,0); if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) { sp->NOTARIZED_HEIGHT = *notarizedheightp; diff --git a/src/komodo_events.h b/src/komodo_events.h index 219d6e479..c64ccbaa2 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -37,7 +37,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char return(ep); } -void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight)//,uint256 MoM,int32_t MoMdepth) +void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight,uint256 MoM,int32_t MoMdepth) { struct komodo_event_notarized N; if ( NOTARY_PUBKEY33[0] != 0 && komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) @@ -53,12 +53,12 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig N.blockhash = notarized_hash; N.desttxid = notarized_desttxid; N.notarizedheight = notarizedheight; - //N.MoM = MoM; - //N.MoMdepth = MoMdepth; + N.MoM = MoM; + N.MoMdepth = MoMdepth; strncpy(N.dest,dest,sizeof(N.dest)-1); komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); if ( sp != 0 ) - komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid);//,MoM,MoMdepth); + komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid,MoM,MoMdepth); } } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 1bd726ce5..24e8500fd 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -493,7 +493,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n return(0); } -void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t notarized_height,uint256 notarized_hash,uint256 notarized_desttxid)//,uint256 MoM,int32_t MoMdepth) +void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t notarized_height,uint256 notarized_hash,uint256 notarized_desttxid,uint256 MoM,int32_t MoMdepth) { struct notarized_checkpoint *np; if ( notarized_height >= nHeight ) @@ -511,8 +511,8 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not sp->NOTARIZED_HEIGHT = np->notarized_height = notarized_height; sp->NOTARIZED_HASH = np->notarized_hash = notarized_hash; sp->NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid; - //sp->MoM = np->MoM = MoM; - //sp->MoMdepth = np->MoMdepth = MoMdepth; + sp->MoM = np->MoM = MoM; + sp->MoMdepth = np->MoMdepth = MoMdepth; portable_mutex_unlock(&komodo_mutex); }