From 0d8e3988e9bebc871914c2011958761b67d668de Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Apr 2018 22:44:01 +0300 Subject: [PATCH 1/6] Immediate submit block from miner --- src/miner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3bd4b1c66..204047a57 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -635,7 +635,7 @@ static bool ProcessBlockFound(CBlock* pblock) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); - if ( vNodes.size() < KOMODO_LIMITED_NETWORKSIZE*2 ) + //if ( vNodes.size() < KOMODO_LIMITED_NETWORKSIZE*2 ) { int32_t n = 1; //fprintf(stderr,"broadcast new block t.%u\n",(uint32_t)time(NULL)); @@ -648,7 +648,8 @@ static bool ProcessBlockFound(CBlock* pblock) if ( (rand() % n) == 0 ) { pnode->PushMessage("block", *pblock); - n++; + if ( n++ > 8 ) + break; } } } From e3b04fea0c072abdf3cede39ec5e57d69878f7f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Apr 2018 10:43:41 +0300 Subject: [PATCH 2/6] Return error if prevblock != best block --- src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 008bd3197..a9d1223ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2593,6 +2593,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); + if ( hashPrevBlock != view.GetBestBlock() ) + { + fprintf(stderr,"ConnectBlock(): hashPrevBlock != view.GetBestBlock()\n"); + return state.DoS(1, error("ConnectBlock(): hashPrevBlock != view.GetBestBlock()"), + REJECT_INVALID, "hashPrevBlock-not-bestblock"); + } assert(hashPrevBlock == view.GetBestBlock()); // Special case for the genesis block, skipping connection of its transactions From a36fcdf53da8765be07293f2494b3e85e6c8750b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Apr 2018 11:28:37 +0300 Subject: [PATCH 3/6] Test --- src/komodo_gateway.h | 2 +- src/main.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 945f0b71b..93767844d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -707,7 +707,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( overflow != 0 || total > COIN/10 ) { - //fprintf(stderr,">>>>>>>> <<<<<<<<<< ht.%d illegal nonz output %.8f n.%d\n",height,dstr(block.vtx[0].vout[1].nValue),n); + fprintf(stderr,">>>>>>>> <<<<<<<<<< ht.%d illegal nonz output %.8f n.%d\n",height,dstr(block.vtx[0].vout[1].nValue),n); if ( height >= activation ) return(-1); } diff --git a/src/main.cpp b/src/main.cpp index a9d1223ab..631d6657e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3798,7 +3798,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 ) @@ -3870,7 +3870,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; @@ -4139,7 +4139,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo bool checked; uint256 hash; auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); - //fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); + fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); if ( chainActive.Tip() != 0 ) komodo_currentheight_set(chainActive.Tip()->nHeight); checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); From 41427baa043e6aedb0f36eb47667b98e74192a87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Apr 2018 11:36:15 +0300 Subject: [PATCH 4/6] Test --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 631d6657e..a9d1223ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3798,7 +3798,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 ) @@ -3870,7 +3870,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; @@ -4139,7 +4139,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo bool checked; uint256 hash; auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); - fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); + //fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); if ( chainActive.Tip() != 0 ) komodo_currentheight_set(chainActive.Tip()->nHeight); checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); From a36c1a705a9cc65b43739dd0d1d8d785a85c7baa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Apr 2018 14:53:16 +0300 Subject: [PATCH 5/6] +print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 204047a57..5853b0535 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -214,7 +214,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) continue; if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) { - fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); + fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); continue; } COrphan* porphan = NULL; From 64b45b7192ddcf0869d2268602a4dbf7e6feb27a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Apr 2018 15:16:44 +0300 Subject: [PATCH 6/6] Test --- src/main.cpp | 4 ++-- src/miner.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a9d1223ab..014efac2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3551,7 +3551,7 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block) if (it != mapBlockIndex.end()) { //if ( ASSETCHAINS_STAKED == 0 || it->second != 0 ) // change behavior to allow komodo_ensure to work - if ( vNodes.size() >= KOMODO_LIMITED_NETWORKSIZE || it->second != 0 ) // change behavior to allow komodo_ensure to work + if ( it->second != 0 ) // vNodes.size() >= KOMODO_LIMITED_NETWORKSIZE, change behavior to allow komodo_ensure to work { // this is the strange case where somehow the hash is in the mapBlockIndex via as yet undetermined process, but the pindex for the hash is not there. Theoretically it is due to processing the block headers, but I have seen it get this case without having received it from the block headers or anywhere else... jl777 //fprintf(stderr,"addtoblockindex already there %p\n",it->second); @@ -4162,7 +4162,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo } // Store to disk CBlockIndex *pindex = NULL; - if ( vNodes.size() < KOMODO_LIMITED_NETWORKSIZE ) //ASSETCHAINS_STAKED != 0 )// + //if ( vNodes.size() < KOMODO_LIMITED_NETWORKSIZE ) //ASSETCHAINS_STAKED != 0 )// { // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync komodo_ensure(pblock,hash); diff --git a/src/miner.cpp b/src/miner.cpp index 5853b0535..a8569980d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -214,7 +214,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) continue; if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) { - fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); + //fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); continue; } COrphan* porphan = NULL;