1

How is the merkle root verified if the mempools are different? I already understand how its calculated. If a node has a mempool of transactions, and a miner has only some of those transactions and maybe some different ones, how can the node verify that the hash of the miners block which includes all the parameters and the merkle root is correct. As I understand, in order for a node to verify a block, they must first verify the validity of the paramaters in the block header. Thanks in advance!

2 Answers 2

3

The mempool and the Merkle root have nothing to do with one another.

Blocks consist of a set of transactions chosen by the miner (probably from their mempool, but it doesn't really matter - the composition of blocks is miners' perogative). That block consists of a list of transactions, and a block header that contains among other things a Merkle root committing to those transactions.

When blocks get propagated, nodes verify its Merkle root against its set of transactions. The receiver's mempool is entirely irrelevant in this process of deciding whether or not the received block is valid. Once a new block is accepted, transactions in the receiver's mempool which were included in the block (or conflict with transactions in the block) are removed.

Now, some block relay protocols (notably, BIP152 "compact blocks") take advance of the fact that receivers typically have most if not all transactions in a block already. BIP152 in particular just sends a short hash of each block transaction rather than the full contents immediately, letting the receiver request missing transactions if any. But none of this has anything to do with the block's Merkle root - that's an aspect of validating the block once it is received (and reconstructed). Compact blocks is a means of transmitting the block before validation happens.

2

Before compact blocks (BIP152), a new block received by a node would contain all its transactions in full. Validating the merkle root in the block header would then not involve the node's mempool at all, it would simply build a merkle tree from the received transactions and verify the merkle roots match. Of course, this meant that (nearly) all transactions were relayed over the network twice, with large bandwith spikes on each new block.

Since the introduction of compact blocks, your node instead only receives a list of short transaction IDs and a few transactions the peer thinks you might not have (most notably the coinbase transaction), looks up these transactions in its mempool, optionally asks the peer for any missing transactions, and then it can verify the merkle root as before.

4
  • Ah I see, so the node first checks for its mempool transactions, sends its mempool to peers to check if they are missing transactions and then calculates the merkle root with the rest of the transactions. Thank you! Dec 11, 2022 at 2:14
  • One more thing, when a miner is choosing what transactions to use in its block, does they send those transactions to the node, who then validate if they correspond with their full list of transactions and then calculate the merkle root? Dec 11, 2022 at 2:16
  • Not exactly sure what you mean by "sends its mempool to peers". The receiving node only asks its peer for transactions whose IDs were in the compact block but which weren't in its mempool. Dec 11, 2022 at 14:42
  • For the miner question, you might benefit from reading the answers to What exactly is Mining?. Dec 11, 2022 at 14:48

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.