Let's assume 2 miners, A and B, are adding / validating transactions and build a block. Both blocks contain 50 identical transactions. All other transactions differ. Now one miner, B, solves the mathematical puzzle and appends his block to the chain. What would then happen to the remaining transactions within the other block of miner A? Will these be automatically removed from the block that didn't make it and the miner needs to add 50 different ones? Or does miner A needs to start all over from zero? How's that solved and does this actually happen in reality?
2 Answers
Let's assume 2 miners, A and B, are adding / validating transactions and build a block. Both blocks contain 50 identical transactions. All other transactions differ. Now one miner, B, solves the mathematical puzzle and appends his block to the chain. What would then happen to the remaining transactions within the other block of miner A?
When miner A receives the block constructed by B, A will remove the transactions in its mempool that conflict with that block, which in your case includes at least the 50 common transactions.
Subsequent block candidates A tries to construct will be drawn from that mempool, which has been updated to not include the conflicts anymore.
Will these be automatically removed from the block that didn't make it and the miner needs to add 50 different ones?
Blocks once produced cannot be changed, but A in your scenario never constructed a block. A has been constructing block candidates (which don't satisfy proof of work) based on its mempool, and the mempool changed, so future candidates will reflect that change.
Or does miner A needs to start all over from zero?
Miner A is already, continuously, "starting over" all the time. It is entirely irrelevant for the miners in A whether the mempool the transactions are drawn from, or the block it is building on, changed in between two attempts. It's just a new attempt like any other.
It's important to see that mining is progress free. There is not a single special block that all miners are competing to find first. There are an infinite number of potentially valid solutions, and miners are all looking for different ones. Mining proceeds by constructing candidate blocks, computing their hash, and if the hash does not have enough zeroes, continue with another candidate block. Each attempt has the same probability of success, independent of how many candidates the miner has already tried, and independent of how many candidates anyone else has already tried.
How's that solved and does this actually happen in reality?
Yes, it happens all the time. Every time someone finds a block, all other miners will update their mempools so their future block candidates reflect the state after the found block.
What would then happen to the remaining transactions within the other block of miner A?
Miner A would need to construct a new block which doesn't include the transactions that have already been mined and "solve the mathematical puzzle" for the new block.
Will these be automatically removed from the block that didn't make it and the miner needs to add 50 different ones?
Their mining software should construct a new block that doesn't include transactions from the now mined block. (If it doesn't that could be a costly mistake as it could successfully mine a block that the rest of the network rejects.) It doesn't need to add exactly 50 new ones and in some cases won't be able to if some of the new transactions are particularly big.
Or does miner A needs to start all over from zero? How's that solved and does this actually happen in reality?
Effectively miner A needs to start from zero, yes. It doesn't need to re-verify transactions it has already verified but in terms of the mining aspect it starts the block construction and mining process from scratch again. It happens regularly in reality as there will be a large overlap between the transactions in the various blocks that miners are competing to mine.