I'm having a problem figuring out how miners solve the following problem:
Let's say we have 2 miners: M1, M2.
M1 adds transactions A,B,C,D to their block. M2 adds transactions A,B,C to their block. For some reason, transaction D will come to M2 a few seconds after M1 received it.
Now, M2 solves the block and sends this block to everyone. Consequently, M1 throws their block away and starts working on new block.
Next, M1 adds transactions E,F,G to their block, whereas M2 adds D,E,F,G (M2 gets D now) to their block. Now, M1 solves the block first and broadcasts it. Therefore, M2 throws their block away and starts a new one.
In this case, transaction D won't get in any block! (The problem is caused by network speed which caused the fact that D arrived at M2 a few seconds after it got to M1.)
So, how is this problem handled or avoided?