Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static bool ProcessBlockFound( const CBlock * const block, const CChainParams & chainparams )
- {
- - // Found a solution
- - LogPrintf( "%s\n", block->ToString() ) ;
- - LogPrintf( "generated %s\n", FormatMoney( block->vtx[0]->vout[0].nValue ) ) ;
- + assert( block != nullptr ) ;
- + CBlockIndex* lastTip = chainActive.Tip() ; /* mapBlockIndex[ chainActive.Tip()->GetBlockSha256Hash() ] */
- {
- LOCK( cs_main );
- - if ( block->hashPrevBlock != chainActive.Tip()->GetBlockSha256Hash() )
- - return error( "ProcessBlockFound: generated block is stale" ) ;
- +
- + if ( lastTip != nullptr &&
- + block->hashPrevBlock != lastTip->GetBlockSha256Hash() )
- + { // generated block isn't above the chain's current tip block
- + std::string why = "lost in the chain" ;
- +
- + // is it above the previous block?
- + if ( lastTip->pprev != nullptr &&
- + lastTip->pprev->GetBlockSha256Hash() == block->hashPrevBlock )
- + {
- + CValidationState state ;
- + RejectBlock( state, Params(), lastTip ) ;
- + if ( state.IsValid() )
- + if ( ActivateBestChain( state, Params() ) ) why = "" ;
- + else
- + why = state.GetRejectReason() ;
- + }
- +
- + if ( ! why.empty() ) {
- + if ( lastTip->nStatus & BLOCK_FAILED_MASK ) ResetBlockFailureFlags( lastTip ) ;
- + return error( "%s: generated block is stale (%s)", __func__, why ) ;
- + }
- + }
- }
- + // Found a solution
- + LogPrintf( "%s\n", block->ToString() ) ;
- + LogPrintf( "reward %s\n", FormatMoney( block->vtx[0]->vout[0].nValue ) ) ;
- +
- // Say about the new block
- GetMainSignals().BlockFound( block->GetSha256Hash() ) ;
- // Process this block the same as if it were received from another node
- - if ( ! ProcessNewBlock( chainparams, std::make_shared< const CBlock >( *block ), true, nullptr ) )
- + if ( ! ProcessNewBlock( chainparams, std::make_shared< const CBlock >( *block ), true, nullptr ) ) {
- + if ( lastTip->nStatus & BLOCK_FAILED_MASK ) {
- + LOCK( cs_main );
- + ResetBlockFailureFlags( lastTip ) ;
- + }
- return error( "ProcessBlockFound: ProcessNewBlock, block not accepted" ) ;
- + }
- +
- + if ( lastTip->nStatus & BLOCK_FAILED_MASK ) {
- + LOCK( cs_main );
- + ResetBlockFailureFlags( lastTip ) ; // it was just to rewind, not to mark as rejected forever
- + }
- return true ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement