src/validation.cpp
/** Disconnect chainActive's tip.
  * After calling, the mempool will be in an inconsistent state, with
  * transactions from disconnected blocks being added to disconnectpool.  You
  * should make the mempool consistent again by calling UpdateMempoolForReorg.
  * with cs_main held.
  *
  * If disconnectpool is nullptr, then no disconnected transactions are added to
  * disconnectpool (note that the caller is responsible for mempool consistency
  * in any case).
  */
Disconnect chainActive's tip.
After calling, the mempool will be in an inconsistent state, with
transactions from disconnected blocks being added to disconnectpool.  You
should make the mempool consistent again by calling UpdateMempoolForReorg.

If disconnectpool is nullptr, then no disconnected transactions are added to
disconnectpool (note that the caller is responsible for mempool consistency
in any case).
Disconnect chainActive ' s tip . After calling the mempool will be in an inconsistent state with transactions from disconnected blocks being added to disconnectpool . You should make the mempool consistent again by calling UpdateMempoolForReorg . If disconnectpool is nullptr then no disconnected transactions are added to disconnectpool ( note that the caller is responsible for mempool consistency in any case ) .
bool CChainState::DisconnectTip(CValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions *disconnectpool)
{
    CBlockIndex *pindexDelete = chainActive.Tip();
    assert(pindexDelete);
    std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
    CBlock& block = *pblock;
    if (!ReadBlockFromDisk(block, pindexDelete, chainparams.GetConsensus()))
        return AbortNode(state, "Failed to read block");
    int64_t nStart = GetTimeMicros();
    {
        CCoinsViewCache view(pcoinsTip.get());
        assert(view.GetBestBlock() == pindexDelete->GetBlockHash());
        if (DisconnectBlock(block, pindexDelete, view, false) != DISCONNECT_OK)
            return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
        bool flushed = view.Flush();
        assert(flushed);
    }
    LogPrint(BCLog::BENCH, "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * MILLI);
    if (!FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED))
        return false;
    if (disconnectpool) {
        for (auto it = block.vtx.rbegin(); it != block.vtx.rend(); ++it) {
            disconnectpool->addTransaction(*it);
        }
        while (disconnectpool->DynamicMemoryUsage() > MAX_DISCONNECTED_TX_POOL_SIZE * 1000) {
            auto it = disconnectpool->queuedTx.get<insertion_order>().begin();
            mempool.removeRecursive(**it, MemPoolRemovalReason::REORG);
            disconnectpool->removeEntry(it);
        }
    }
    chainActive.SetTip(pindexDelete->pprev);
    UpdateTip(pindexDelete->pprev, chainparams);
    LogPrint(BCLog::HANDLER, "Omni Core handler: block disconnect begin [height: %d, reindex: %d]\n", chainActive.Height(), (int)fReindex);
    mastercore_handler_disc_begin(pindexDelete->nHeight);
    GetMainSignals().BlockDisconnected(pblock);
    for (const CTransactionRef& ptx : pblock->vtx) {
        TryToAddToMarkerCache(ptx);
    }
    LogPrint(BCLog::HANDLER, "Omni Core handler: block disconnect end [height: %d, reindex: %d]\n", chainActive.Height(), (int)fReindex);
    return true;
}
bool CChainState :: DisconnectTip ( CValidationState & state , const CChainParams & chainparams , DisconnectedBlockTransactions * disconnectpool ) { CBlockIndex * pindexDelete = chainActive . Tip ( ) ; assert ( pindexDelete ) ; std :: shared_ptr < CBlock > pblock = std :: make_shared < CBlock > ( ) ; CBlock & block = * pblock ; if ( ! ReadBlockFromDisk ( block , pindexDelete , chainparams . GetConsensus ( ) ) ) return AbortNode ( state , " " ) ; int64_t nStart = GetTimeMicros ( ) ; { CCoinsViewCache view ( pcoinsTip . get ( ) ) ; assert ( view . GetBestBlock ( ) == pindexDelete -> GetBlockHash ( ) ) ; if ( DisconnectBlock ( block , pindexDelete , view , false ) != DISCONNECT_OK ) return error ( " " , pindexDelete -> GetBlockHash ( ) . ToString ( ) ) ; bool flushed = view . Flush ( ) ; assert ( flushed ) ; } LogPrint ( BCLog :: BENCH , " \n " , ( GetTimeMicros ( ) - nStart ) * MILLI ) ; if ( ! FlushStateToDisk ( chainparams , state , FlushStateMode :: IF_NEEDED ) ) return false ; if ( disconnectpool ) { for ( auto it = block . vtx . rbegin ( ) ; it != block . vtx . rend ( ) ; ++ it ) { disconnectpool -> addTransaction ( * it ) ; } while ( disconnectpool -> DynamicMemoryUsage ( ) > MAX_DISCONNECTED_TX_POOL_SIZE * 1000 ) { auto it = disconnectpool -> queuedTx . get < insertion_order > ( ) . begin ( ) ; mempool . removeRecursive ( * * it , MemPoolRemovalReason :: REORG ) ; disconnectpool -> removeEntry ( it ) ; } } chainActive . SetTip ( pindexDelete -> pprev ) ; UpdateTip ( pindexDelete -> pprev , chainparams ) ; LogPrint ( BCLog :: HANDLER , " \n " , chainActive . Height ( ) , ( int ) fReindex ) ; mastercore_handler_disc_begin ( pindexDelete -> nHeight ) ; GetMainSignals ( ) . BlockDisconnected ( pblock ) ; for ( const CTransactionRef & ptx : pblock -> vtx ) { TryToAddToMarkerCache ( ptx ) ; } LogPrint ( BCLog :: HANDLER , " \n " , chainActive . Height ( ) , ( int ) fReindex ) ; return true ; }
Disconnect chainActive's tip.
Disconnect chainActive ' s tip .
// Read block from disk. // Apply the block atomically to the chain state. // Write the chain state to disk, if necessary. // Save transactions to re-add to mempool at end of reorg // Drop the earliest entry, and remove its children from the mempool. //! Omni Core: begin block disconnect notification // Let wallets know transactions went from 1-confirmed to // 0-confirmed or conflicted: //! Omni Core: end of block disconnect notification