6

I was wondering how a block encodes its set of transactions. I know a Merkle Tree is generated, and that it encodes a Hashed version of the transactions. But is the Merkle Tree included in the Block that gets sent to the other nodes for validation? Is there a list of transactions that it also sent?

In my understanding, when a Node wishes to 'Mine', they will:

  1. Generate a new block
  2. Create a coinbase transaction
  3. Gather a subset of the other incomplete transactions (those that have not yet been put into a block) from its copy of the blockchain.
  4. Generate a Merkle Tree using the transactions from steps 2 & 3
  5. Increment a Nonce repeatedly until the Hash of the <Previous Hash, Nonce, Transactions from 4> begin with a certain number of 0s.

It seems that to validate each individual transaction (to ensure money is not double-spent), it would be good to include a list of transactions. But to check that the proof-of-work has actually been completed, the other nodes need the merkle tree to quickly hash.

It is very possible that there is also a way to obtain the list of transactions from a merkle tree, but I just don't understand what that process looks like.

P.S. I am building my own Python demo implementation of a blockchain currency, hence the more-theoretical/less-practical questions.

Thanks.

2 Answers 2

9

You cannot obtain a list of transactions from the merkle tree.

The merkle tree root is part of the block header, which as you said, allows quick verification of the proof-of-work.

After the block header, each block contains a list of serialized transactions in the order they appear in the merkle tree. A complete block is a block header + list of transactions.

When validating a block, nodes will check:

  1. The proof of work (this can be done with just the block header. However, just because the block header validates, it does not mean the block is valid)
  2. The merkle tree - Nodes will take the list of transactions and reconstruct the merkle tree to ensure the root matches what is in the header
  3. Each individual transaction - Individual inputs and outputs are validates to ensure they meet network rules, and that no double spends exist.
1
  • Answers my question perfectly.
    – 3mrsh
    Commented Jul 22, 2018 at 18:49
3

In order to validate a block nodes must have the actual transactions themselves, even a list is insufficient.

But the question "Does a block contain X" is a bit like asking "What is the sound of one hand clapping?". It would be valid to say that a "block" is nothing more than its block header or even that that hash of a block is "the block". You couldn't validate a block from its hash or its header alone, just like you can't validate a block without data you learned from the blocks before it-- but how you get that data is up to you and the part(ies) that are telling you about the block.

This is relevant because today in the Bitcoin network, blocks are usually relayed without sending the transactions according to BIP152-- instead we assume that the regular transaction relay process has already given each node most or all of the transactions and send our peers a compact representation that lets them use their mempools to figure out what was in the block. If they're missing some of the data they need, they can request it.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.