Skip to content

Commit

Permalink
build Inf list, Stm after validation block
Browse files Browse the repository at this point in the history
Signed-off-by: crptec <crptec.fr@gmail.com>
  • Loading branch information
crptec committed Jul 29, 2020
1 parent 6498200 commit 598fa8a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 48 deletions.
21 changes: 0 additions & 21 deletions src/infinitynodetip.cpp
Expand Up @@ -20,27 +20,6 @@ CInfinitynodeTip::CInfinitynodeTip()
*/
void CInfinitynodeTip::UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman& connman)
{
// lock main here
// update our DIN info for each new block
LOCK(cs_main);
infnodeman.UpdatedBlockTip(pindexNew);
if (infnodeman.updateInfinitynodeList(pindexNew->nHeight)){
bool updateStm = infnodeman.deterministicRewardStatement(10) &&
infnodeman.deterministicRewardStatement(5) &&
infnodeman.deterministicRewardStatement(1);
if (updateStm){
LogPrintf("CInfinitynodeTip::UpdatedBlockTip -- update Stm status: %d\n",updateStm);
infnodeman.calculAllInfinityNodesRankAtLastStm();
infnodeman.updateLastStmHeightAndSize(pindexNew->nHeight, 10);
infnodeman.updateLastStmHeightAndSize(pindexNew->nHeight, 5);
infnodeman.updateLastStmHeightAndSize(pindexNew->nHeight, 1);
} else {
LogPrintf("CInfinitynodeTip::UpdatedBlockTip -- update Stm false\n");
}
} else {
LogPrintf("CInfinitynodeTip::UpdatedBlockTip -- Cannot update DIN info\n");
}

static bool fReachedBestHeader = false;
bool fReachedBestHeaderNew = pindexNew->GetBlockHash() == pindexBestHeader->GetBlockHash();

Expand Down
53 changes: 26 additions & 27 deletions src/validation.cpp
Expand Up @@ -2266,34 +2266,12 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
} else if (pindex->nHeight > chainparams.GetConsensus().nINActivationHeight && pindex->nHeight <= chainparams.GetConsensus().nNewDevfeeAddress) {
//Masternode mode: check payment
LogPrintf("Validation -- POW + Masternode\n");
bool retryWithUpdateINF = false;
if (!IsBlockPayeeValid(block.vtx[0], pindex->nHeight, block.vtx[0]->GetValueOut(), pindex->GetBlockHeader())) {
if(!retryWithUpdateINF){
LOCK(infnodeman.cs);
infnodeman.UpdatedBlockTip(pindex);
bool updateStm = infnodeman.deterministicRewardStatement(10) &&
infnodeman.deterministicRewardStatement(5) &&
infnodeman.deterministicRewardStatement(1);
if (updateStm){
LogPrintf("Validation -- update Stm status: %d\n",updateStm);
infnodeman.calculAllInfinityNodesRankAtLastStm();
infnodeman.updateLastStmHeightAndSize(pindex->nHeight, 10);
infnodeman.updateLastStmHeightAndSize(pindex->nHeight, 5);
infnodeman.updateLastStmHeightAndSize(pindex->nHeight, 1);
retryWithUpdateINF = true;
} else {
LogPrintf("Validation -- update Stm false\n");
}
}
if(retryWithUpdateINF && IsBlockPayeeValid(block.vtx[0], pindex->nHeight, block.vtx[0]->GetValueOut(), pindex->GetBlockHeader())){
//retry and good. Block is valid at this step
} else {
mapRejectedBlocks.insert(std::make_pair(block.GetHash(), GetTime()));
LogPrintf("IsBlockPayeeValid -- disconnect block!\n");
if (pindex->nHeight >= chainparams.GetConsensus().nINEnforcementHeight) {
return state.DoS(0, error("ConnectBlock(SIN): couldn't find masternode or superblock payments"),
REJECT_INVALID, "bad-cb-payee");
}
mapRejectedBlocks.insert(std::make_pair(block.GetHash(), GetTime()));
LogPrintf("IsBlockPayeeValid -- disconnect block!\n");
if (pindex->nHeight >= chainparams.GetConsensus().nINEnforcementHeight) {
return state.DoS(0, error("ConnectBlock(SIN): couldn't find masternode or superblock payments"),
REJECT_INVALID, "bad-cb-payee");
}
}
} else {
Expand Down Expand Up @@ -2714,6 +2692,7 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
// Remove conflicting transactions from the mempool.;
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight);
disconnectpool.removeForBlock(blockConnecting.vtx);

// Update chainActive & related variables.
chainActive.SetTip(pindexNew);
UpdateTip(pindexNew, chainparams);
Expand All @@ -2722,6 +2701,26 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
LogPrint(BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime5) * MILLI, nTimePostConnect * MICRO, nTimePostConnect * MILLI / nBlocksTotal);
LogPrint(BCLog::BENCH, "- Connect block: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime1) * MILLI, nTimeTotal * MICRO, nTimeTotal * MILLI / nBlocksTotal);

// update our DIN info for each new block
LOCK(cs_main);
infnodeman.UpdatedBlockTip(pindexNew);
if (infnodeman.updateInfinitynodeList(pindexNew->nHeight)){
bool updateStm = infnodeman.deterministicRewardStatement(10) &&
infnodeman.deterministicRewardStatement(5) &&
infnodeman.deterministicRewardStatement(1);
if (updateStm){
LogPrintf("CInfinitynodeTip::UpdatedBlockTip -- update Stm status: %d\n",updateStm);
infnodeman.calculAllInfinityNodesRankAtLastStm();
infnodeman.updateLastStmHeightAndSize(pindexNew->nHeight, 10);
infnodeman.updateLastStmHeightAndSize(pindexNew->nHeight, 5);
infnodeman.updateLastStmHeightAndSize(pindexNew->nHeight, 1);
} else {
LogPrintf("CInfinitynodeTip::UpdatedBlockTip -- update Stm false\n");
}
} else {
LogPrintf("CInfinitynodeTip::UpdatedBlockTip -- Cannot update DIN info\n");
}

connectTrace.BlockConnected(pindexNew, std::move(pthisBlock));
return true;
}
Expand Down

0 comments on commit 598fa8a

Please sign in to comment.