first time posting here.
I was interested on how mining software works down to the bytes. I came across this well written article right here:
Under "Notes and References", he provides a python program that generates the merkle root from a list of transaction hashes. What I don't understand however is, why or how the hash of the coinbase transaction is included in that list.
Lets say you are in the process of mining a new block. You make your list of transaction hashes(without the coinbase transaction, as you haven't mined the block), create the merkle root and guess the nonce until you create a block. Now the coinbase transaction takes place and you get your bitcoins, the coinbase transaction hash now has to be included in the list of transaction hashes. But that changes the merkle root and thus the entire block, which would make it unvalid.
How is this solved? Do you know the hash of the coinbase transaction in advance? Or do you not include the coinbase transaction for the new block and the python code is not correct?
Also a side question is, in the python code this part confuses me a bit:
h = hashlib.sha256(hashlib.sha256(a1+b1).digest()).digest()
Does a1+b1 mean that you perform addition of the hash values or that you just append the two hashes together?
Thanks in advance,