vortiportfolio.blogg.se

Bitcoin core blockchain download
Bitcoin core blockchain download









bitcoin core blockchain download
  1. Bitcoin core blockchain download full#
  2. Bitcoin core blockchain download verification#
  3. Bitcoin core blockchain download code#

Store C to disk and keep it in mapBlocksIndex - it's a known block.C is valid, but D has a bad transaction (double-spend, invalid signature, etc.): We also remove C because it has less work than B.

bitcoin core blockchain download

At this point, we extend chainActive with B as the new tip, and remove B from setBlockIndexCandidates.

Bitcoin core blockchain download full#

Now we receive the full block for B and it checks out. Assume B has more work than C but less work than D. At this point setBlockIndexCandidates contains. We verify headers for B, C, D and they all look good. Thus, the header is a candidate for extending our chain, but we can't say for sure until we receive the full block (and if the candidate is more than one block away from our current tip, we also need to receive and verify any intermediate blocks.)Įxample 1: Let A be our tip we then receive, in order, B, C, D, such that: (In the normal case where the block extends our current tip, it is easy enough to see that it has more total work than our tip.) Thus, they are "candidates" for extending our current blockchain (or re-organizing from our current chain to the chain that the candidate is on.) We call them "candidates" because we verify the block's proof-of-work when we receive the header, but before we receive the block.

bitcoin core blockchain download

Set of block indexes that have more total work than our current tip. Upon receiving block B, we can connect B as our tip and delete its entries in mapBlocksUnlinked, which would now consist of only one item. Upon receiving block B, we can connect C. The alternative would be to search the entire mapBlockIndex however, it is more efficient to keep track of unlinked blocks in a separate data structure. The purpose of mapBlocksUnlinked is to quickly attach blocks we've already received to the blockchain when we receive a missing, intermediate block. Multimap containing "all pairs A->B, where A (or one if its ancestors) misses transactions, but B has transactions." (comment at main.cpp:125). By comparison, the chainstate wrapper's writing function (BatchWrite) both writes and erases. (Try searching main.cpp for mapBlockIndex.erase.) Observe also that the block index's LevelDB wrapper does not contain functionality for erasing blocks from the database - it's writing function (WriteBatchSync) only writes to the database. MapBlockIndex only grows, it never shrinks. Thereafter, it's updated whenever new blocks are received over the network. MapBlockIndex is initialized from the database in LoadBlockIndexGuts, which is run at Step 7 of startup. It is technically of type BlockMap, which is for readability. Just think of it as your blocks/ LevelDB in memory, with the key being the block hash. Since a block index is created and stored in the LevelDB when a header is received, it's possible to have block indexes in the block map without having received the full block yet, let alone having stored it to disk. This map contains all known blocks (where "block" means "block index").

  • multimap: an ordered map where duplicate keys are allowed (thus, can hold elements ,).
  • set: an ordered container (think of it as a sorted linked list).
  • map: an unordered container (think of it as a hashtable).
  • Note: nChainTx is only stored in memory there is no corresponding entry in the database. In a sense, then, the expression (nChainTx !=0) is shorthand for a status that might be said to be "VALID_nChainTx = 3.5" - because it's more than VALID_TRANSACTIONS but less than VALID_CHAIN. Namely, VALID_TRANSACTIONS only implies that its parents are TREE, while VALID_CHAIN implies that its parents are also CHAIN. This is notable because this information is not available via the block-status enum. Thus, nChainTx > 0 is shorthand for a chain that is VALID_TRANSACTIONS. This value will be set if and only if transactions for this block and all its parents are available.

    bitcoin core blockchain download

    nChainTx: Number of transactions in this block's chain, up to and including this block. nTx > 0 means that the block has a status of at least VALID_TRANSACTIONS. NTx: Number of transactions in this block.

    Bitcoin core blockchain download code#

    The precise meaning of each status code is documented in chain.h.Īlso stored in the block index are two variables worth mentioning: The block's status is one of the following:

    Bitcoin core blockchain download verification#

    Verification status captures the degree to which the code has validated this block, as well as its ancestor blocks. One of the key traits of a block is its "verification status." The block index (block metadata) is well commented in the code: see src/chain.h. See LoadBlockIndexGuts() in src/txdb.cpp. This means the entire block tree, not just the active chain. The block index database gets loaded into memory when the node starts. 4 Disconnecting a block (reorganizations).











    Bitcoin core blockchain download