I was looking through the code for ABE, and I discovered that the relationship of blocks to transactions is many to many.
Why are some transactions stored in the transaction lists of multiple blocks?
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 communityI was looking through the code for ABE, and I discovered that the relationship of blocks to transactions is many to many.
Why are some transactions stored in the transaction lists of multiple blocks?
Within one chain of blocks, every transaction can only occur once. However, the data structure people frequently call "the block chain" is actually a tree structure, with one root (the genesis block) and different branches. The longest valid branch of this tree is called the active block chain, but occassionally, during a reorganisation, nodes switch to another branch (usually only the last 1-2 blocks change). Any transactions that were in the old branch but not in the new are then attempted to be mined again when possible. This results in one transaction being in several blocks within the tree - but not the same chain.
There existed another way. Early on, there was a possibility for two coinbase transactions to be identical. This occurred in blocks at height 91842 and 91880. It has since been made illegal and later impossible through BIP30 and BIP34.
getblockhash
it will give you the hash of the block in the currently active chain. So no, except for the duplicated coinbases, you will never find a transaction twice that way. You need to search in blocks that are not in the main chain. The RPC queries the local database, which has all blocks (also those not in the main chain) you node has ever accepted, but only the active ones are indexed and accessible through getblockhash
.
Jul 20, 2013 at 9:36
getblockhash
locally. Yet you also say getblockhash
gives you a block in the currently active chain, but "also those not in the main chain", and that you'd "have to search in blocks that are not in the main chain" to be able to find a transaction twice. Can you specifically search for blocks "not in the main chain" with getblockhash
?
getblockhash
gives you the hash of a block at a particular height in the currently active chain. When you're requesting an actual block through getblock
you can specify any block hash, including of other blocks.
Jul 20, 2013 at 21:46
getblockhash
then getblock
via the RPC, is it possible to see two transactions in different blocks?