Thanks for pushing me here.
I did a bit of research on StackExchange and apparently CBlockIndexWorkComparator decides longest blockchain using the following rules in order:
- Which blockchain has the most work?
- Which one was received first? (This can be different for different clients, which is why the previous rule is applied first.)
- Which one has a larger pointer address? (This is largely random, and different for different clients.)”
However, with the exceptions of attacks and edge cases, rule 1 is always a tie, because the work, or expected number of attempts that were necessary to mine a block it is (2²⁵⁶ / block_target), and block target is only changed every 2016 blocks.
As Satoshi said: “If two nodes broadcast different versions of the next block simultaneously, some nodes may receive one or the other first. In that case, they work on the first one they received, […]The tie will be broken when the next proof-of-work is found and one branch becomes longer.”