Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.
Sign up to join this communityAnybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
I'm trying to understand block validity flags, and what happens when a branch occurs. I found a block status flags in the bitcoin core source code:
enum BlockStatus : uint32_t { BLOCK_VALID_UNKNOWN = 0, BLOCK_VALID_RESERVED = 1, BLOCK_VALID_TREE = 2, BLOCK_VALID_TRANSACTIONS = 3, BLOCK_VALID_CHAIN = 4, BLOCK_VALID_SCRIPTS = 5, BLOCK_VALID_MASK = BLOCK_VALID_RESERVED | BLOCK_VALID_TREE | BLOCK_VALID_TRANSACTIONS | BLOCK_VALID_CHAIN | BLOCK_VALID_SCRIPTS, BLOCK_HAVE_DATA = 8, //!< full block available in blk*.dat BLOCK_HAVE_UNDO = 16, //!< undo data available in rev*.dat BLOCK_HAVE_MASK = BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO, BLOCK_FAILED_VALID = 32, //!< stage after last reached validness failed BLOCK_FAILED_CHILD = 64, //!< descends from failed block BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD, BLOCK_OPT_WITNESS = 128, //!< block data in blk*.dat was received with a witness-enforcing client BLOCK_ASSUMED_VALID = 256, };
Supposing that block arrives, the node validates it successfully. I suppose that block status is set to 5 (BLOCK_VALID_SCRIPTS) in this case. Then it is stored in the block index database. Now another sequence of two valid blocks arrives starting at the same height as the block above. I assume that the working node will consider this sequence as the active branch and the previous block will be abandoned. What will happen to the index entry for the abandoned block? Will it remain in the database? How these flags or other fields will be set then to mark this block as abandoned? Is there any easy answer to the question of which branch to follow when traversing the index database or do I need to visit every branch to the very last leaf and choose the longest sequence each time?
What will happen to the index entry for the abandoned block?
Nothing. The block index contains information about the available blocks and branches, and their validity. It does not contain any information about which chain is actually currently considered active by the node. That information is in the chainstate database (which also holds the UTXO set).
Will it remain in the database?
Yes. It is a valid block.
How these flags or other fields will be set then to mark this block as abandoned?
Nothing changes.
Is there any easy answer to the question of which branch to follow when traversing the index database or do I need to visit every branch to the very last leaf and choose the longest sequence each time?
That's a possibility. An alternative is also looking at the chainstate database.
You can get bonuses upto $100 FREE BONUS when you:
π° Install these recommended apps:
π² SocialGood - 100% Crypto Back on Everyday Shopping
π² xPortal - The DeFi For The Next Billion
π² CryptoTab Browser - Lightweight, fast, and ready to mine!
π° Register on these recommended exchanges:
π‘ Binanceπ‘ Bitfinexπ‘ Bitmartπ‘ Bittrexπ‘ Bitget
π‘ CoinExπ‘ Crypto.comπ‘ Gate.ioπ‘ Huobiπ‘ Kucoin.
Comments