Cblockstore class #1429

pull TheBlueMatt wants to merge 22 commits into bitcoin:master from TheBlueMatt:cblockstore-class changing 20 files +875 −478
  1. TheBlueMatt commented at 11:57 PM on June 6, 2012: member

    This is based on #1408 and gives a preview of the goal of the rebase as a whole. It provides a CBlockStore class to store the block chain and allows CHub to call it and returns data to CHub. If it gets merged, CTxMemPool will be adapted to call CBlockStore functions to get info on previous transactions, and a CAlertStorage class will be added.

    I would prefer to not do callbacks from CBlockStore, but I found that cleaner than returning a list of blocks committed (as each call to EmitBlock can commit any number of blocks) through many of the block acceptance functions and back to CHub::EmitBlock, buf if that design is preferred, its not hard to do that.

    In general, though CBlockStore effectively turns several CHub functions into NOOPs, I prefer using a CHub as a convenience class so that CWallet/P2P client don't have to know something about CBlockStore and CTxMemPool and CAlertStore, but only needs to know one API. It also removes the need to duplicate much of the code to deal with callback threads in the storage classes.

    Obviously this does little actual abstraction, but just creates the class and moves functions from CBlock, if it gets merged, things like mapBlockIndex will get moved into CBlockStore.

  2. Add a CHub for communication from p2p/wallet to blockstore.
    The goal is for p2p code/wallet to only get information/communicate
    information about the blockchain through CHub, giving Bitcoin a
    much more clearly-defined structure and allowing for the removal
    of a ton of the current global mess.
    877e3af8ba
  3. Add a basic CHubListener that can be extended. c42d0f15a2
  4. Add EmitBlock/CommitBlock functionality to CHub.
    Replacing ProcessBlock with EmitBlock, and creating callbacks for
    CommitBlock.
    dd3593c500
  5. Fix typo e6d39a8873
  6. Add HandleCommitBlock to net.cpp & move stuff from main.cpp to it 159c528cec
  7. Remove uiInterface.NotifyBlocksChanged and replace with CommitBlock
    Also rename NotifyBlocksChanged to NotifyNewBlock and remove from
    the uiInterface signals list.
    
    This removes some functionality, but NofiyBlocksChanged was not
    used anyway, so it shouldn't matter.  That said, if it is ever
    needed, it would be fairly trivial to add a new callback for it
    in CHub.
    94a440ae79
  8. Add EmitAlert/CommitAlert functionality to CHub.
    Replace ProcessAlert with calls to EmitAlert and create callbacks
    for CommitAlert.
    1aad2e99bb
  9. Use CommitAlert in qt/clientmodel.cpp 5365eca78c
  10. Add RegisterRemoveAlert functionality to CHub. 7da0bed1f2
  11. Replace NotifyAlertChanged with RegisterRemoveAlert. 8f6c206561
  12. Convert Orphan Tx storage to CTransactions from CDataStreams.
    There was no reason to use CDataStream as the transaction was
    already being serialized/deserialized several times, with this
    change, transactions coming in over network are deserialized once
    when received, and then only reserialized in the call to
    RelayMessage, which will be called in a callback thread, not
    blocking cs_main.
    c6c30dca1a
  13. Add a cs around mapAlreadyAskedFor. 9dc89066a8
  14. Add basic EmitTransaction/CommitTransaction functionality to CHub. ac33eeca2c
  15. Use EmitTransaction instead of AcceptToMemoryPool in sendrawtx. 3bfb60f64d
  16. Add CWallet support for registering with a CHub. c277c93f23
  17. Use HandleCommitTransactionToMemoryPool instead of SyncWithWallets. 916ffbfe9d
  18. Remove AcceptToMemoryPool and replace with EmitTransaction.
     * This removes not only CTransaction::AcceptToMemoryPool, but
        also CMerkleTx::AcceptToMemoryPool. It also moves
        CWalletTx::AcceptWalletTransaction to wallet.cpp
    
     * This adds a fCheckInputs flag to EmitTransaction, which is
        similar to the fCheckInputs flag to AcceptToMemoryPool,
        however, it has stricter guidlines that it should only be set
        "when transaction is a supporting tx for one of our own."
        Additionally, "fCheckInputs is ignored (and set to true)
        if !IsInitialBlockDownload() && !fClient"
    
        As a part of these guidelines,
        CWalletTx::AcceptWalletTransaction calls EmitTransaction with
        fCheckInputs set to true (the default) on the final
        transaction, whereas it used to call with fCheckInputs set to
        false. This has the important side-effect of allowing wallet-
        generated transactions to end up getting AddOrphanTx'd.
        However, if a supporting transaction to one of our own had
        previously been AddOrphanTx'd, it would immediately be added
        to memory pool as it is "a supporting tx for one of our own"
        and thus is re-added with fCheckInputs=false.
    
        Note that the possibility of a wallet transaction getting
        AddOrphanTx'd is very low, and should only happen if
        a) a transaction's input is a generate and we are missing that
           block (note that no transactions should be generated with a
           generation input if we don't have that block anyway).
        b) We match the !IsInitialBlockDownload() && !fClient check,
           are not caught up to the latest block, and an input is in a
           block we do not yet have (possible after the last
           checkpoint). This situation is temporary and should resolve
           itself once we catch up (though AddOrphanTx'd transactions
           may be permanently orphaned).
    
        Largely, these guidelines are there because there is no reason
        to add a transaction without checking its inputs, as we have
        those inputs available, and checking them as any other
        transaction would provides additional sanity-checks.
    
     * A second EmitTransaction was added with tx of type CMerkleTx.
        This keeps behavior of CMerkleTx::AcceptToMemoryPool the same
        in fClient mode. Note that new behavior was invented for
        CHub::EmitTransaction(CTransaction&...) in fClient mode,
        namely that ClientConnectInputs is only checked if
        fCheckInputs is true. This was chosen to make emitting a
        transaction possible in fClient mode even if its inputs are
        not available, but could be changed if support for that is not
        needed when fClient mode is actually implemented.
    e60084cae3
  19. Add a CBlockStore class to hold the blockstore. 41ff3cf816
  20. Add support for registering a CBlockStore with CHub. 9a268f437b
  21. Move EmitBlock handling from CHub to CBlockStore. 60ba767b3e
  22. Move block checking from CTxDB::LoadBlockIndex->LoadBlockIndex. 9b926c8d34
  23. Add CWallet::HandleCommitBlock and move junk from main.cpp to it.
    Note that this changes the way the GUI shows coinbases of users:
    it now shows them only after the first non-orphan block based on
    the generating block, instead of after the first block based on
    the generating one period.
    9a8cd1de9b
  24. TheBlueMatt commented at 8:15 PM on July 5, 2012: member

    This needs rebasing, and Im not going to keep rebasing this stuff without any interest in eventually merging. If it ever gets interest, I may reopen.

  25. TheBlueMatt closed this on Jul 5, 2012

  26. suprnurd referenced this in commit 18c83f58e3 on Dec 5, 2017
  27. lateminer referenced this in commit 472f479906 on Jan 22, 2019
  28. lateminer referenced this in commit 623821c799 on May 6, 2020
  29. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-20 03:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me