Merge pull request #624 from jl777/jl777

Jl777
This commit is contained in:
jl777
2018-04-24 21:36:08 +03:00
committed by GitHub
2 changed files with 45 additions and 28 deletions

View File

@@ -56,6 +56,7 @@ extern uint8_t NOTARY_PUBKEY33[33];
extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN;
int32_t KOMODO_NEWBLOCKS;
int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block);
void komodo_broadcast(CBlock *pblock,int32_t limit);
BlockMap mapBlockIndex;
CChain chainActive;
@@ -3218,6 +3219,8 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001);
LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001);
if ( ASSETCHAINS_SYMBOL[0] == 0 )
komodo_broadcast(pblock,8);
return true;
}
@@ -3774,6 +3777,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,
{
if (blockhdr.GetBlockTime() < GetAdjustedTime() + 600)
*futureblockp = 1;
LogPrintf("CheckBlockHeader block from future %d error",blockhdr.GetBlockTime() - GetAdjustedTime());
return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new");
}
}
@@ -3815,8 +3819,10 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
if (!CheckBlockHeader(futureblockp,height,pindex,block,state,fCheckPOW))
{
if ( *futureblockp == 0 )
{
LogPrintf("CheckBlock header error");
return false;
//else fprintf(stderr,"checkblockheader PoW.%d got futureblock\n",fCheckPOW);
}
}
if ( fCheckPOW )
{
@@ -3888,6 +3894,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
//static uint32_t counter;
//if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
// fprintf(stderr,"check deposit rejection\n");
LogPrintf("CheckBlockHeader komodo_check_deposit error");
return(false);
}
return true;
@@ -4026,8 +4033,10 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat
if (!CheckBlockHeader(futureblockp,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0))
{
if ( *futureblockp == 0 )
{
LogPrintf("AcceptBlockHeader CheckBlockHeader error");
return false;
//else fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader got future block\n");
}
}
// Get prev block index
CBlockIndex* pindexPrev = NULL;
@@ -4042,6 +4051,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat
komodo_requestedhash = block.hashPrevBlock;
komodo_requestedcount = 0;
}*/
LogPrintf("AcceptBlockHeader hashPrevBlock %s not found",block.hashPrevBlock.ToString().c_str());
return(false);
//return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk");
}
@@ -4054,6 +4064,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat
komodo_requestedhash = block.hashPrevBlock;
komodo_requestedcount = 0;
}*/
LogPrintf("AcceptBlockHeader hashPrevBlock %s no pindexPrev",block.hashPrevBlock.ToString().c_str());
return(false);
}
if ( (pindexPrev->nStatus & BLOCK_FAILED_MASK) )
@@ -4062,13 +4073,14 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
{
//fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n");
LogPrintf("AcceptBlockHeader ContextualCheckBlockHeader failed");
return false;
}
if (pindex == NULL)
{
if ( (pindex= AddToBlockIndex(block)) == 0 )
{
fprintf(stderr,"AcceptBlockHeader couldnt add to block index\n");
//fprintf(stderr,"AcceptBlockHeader couldnt add to block index\n");
}
}
if (ppindex)
@@ -4091,12 +4103,14 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C
if (!AcceptBlockHeader(futureblockp,block, state, &pindex))
{
if ( *futureblockp == 0 )
{
LogPrintf("AcceptBlock AcceptBlockHeader error");
return false;
//else fprintf(stderr,"AcceptBlock AcceptBlockHeader got future block\n");
}
}
if ( pindex == 0 )
{
//fprintf(stderr,"AcceptBlock error null pindex\n");
LogPrintf("AcceptBlock null pindex error");
return false;
}
//fprintf(stderr,"acceptblockheader passed\n");
@@ -4110,7 +4124,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C
// blocks which are too close in height to the tip. Apply this test
// regardless of whether pruning is enabled; it should generally be safe to
// not process unrequested blocks.
bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP));
bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + BLOCK_DOWNLOAD_WINDOW)); //MIN_BLOCKS_TO_KEEP));
// TODO: deal better with return value and error conditions for duplicate
// and unrequested blocks.
@@ -4132,8 +4146,9 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C
pindex->nStatus |= BLOCK_FAILED_VALID;
setDirtyBlockIndex.insert(pindex);
}
LogPrintf("AcceptBlock CheckBlock or ContextualCheckBlock error");
return false;
} else fprintf(stderr,"CheckBlock or ContextualCheckBlock got futureblock\n");
}
}
int nHeight = pindex->nHeight;
@@ -4159,7 +4174,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C
FlushStateToDisk(state, FLUSH_STATE_NONE); // we just allocated more disk space for block files
if ( *futureblockp == 0 )
return true;
else return false;
LogPrintf("AcceptBlock block from future error");
return false;
}
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams)

View File

@@ -584,6 +584,26 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
return CreateNewBlock(scriptPubKey);
}
void komodo_broadcast(CBlock *pblock,int32_t limit)
{
int32_t n = 1;
//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;
if ( (rand() % n) == 0 )
{
pnode->PushMessage("block", *pblock);
if ( n++ > limit )
break;
}
}
}
//fprintf(stderr,"finished broadcast new block t.%u\n",(uint32_t)time(NULL));
}
static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
#else
@@ -635,26 +655,7 @@ static bool ProcessBlockFound(CBlock* pblock)
return error("KomodoMiner: ProcessNewBlock, block not accepted");
TrackMinedBlock(pblock->GetHash());
//if ( vNodes.size() < KOMODO_LIMITED_NETWORKSIZE*2 )
{
int32_t n = 1;
//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;
if ( (rand() % n) == 0 )
{
pnode->PushMessage("block", *pblock);
if ( n++ > 8 )
break;
}
}
}
//fprintf(stderr,"finished broadcast new block t.%u\n",(uint32_t)time(NULL));
}
komodo_broadcast(pblock,16);
return true;
}