Unless I'm misunderstanding, this means that two clients that both see precisely the same blocks right now may choose different chains because of what order they saw the blocks even if the two chains have different difficulties.
Yes, exactly. This prevents a miner with a lot of power from building their own chain and keeping it private until it is longer than the real chain. And X is chosen to make it unlikely to happen during normal operation.
Oh, okay. You're trying to prevent a different attack from the one I'm imagining. I'm much more worried about an attacker who only changes four or five blocks. (So if you're willing to wait an hour, you're good IMO.)
Yup. And if a transaction is worth paying to have reversed, it is probably also worth waiting for.
Oh, but keep in mind that these two nodes have to be isolated from each other, but still in contact with enough mining power to produce blocks in reasonable times. That means totally isolating part of the internet, and keeping it isolated for a minimum of about 2 hours (assuming the mining power on each half of the divide is equal). The less equal the division, the longer the isolation needs to last before the fork becomes permanent, and also the less difficult the manual cleanup after will be.
I don't see why. The two nodes can be talking to each other directly and each 100% agree on which blocks are available and still pick different chains. Your algorithm only makes any difference if some client at some point knowingly chooses a chain that is not the longest one on the basis of how it got to that point. Any other client that starts up during this condition, lacking that same history, will pick the longer chain.
I'm not sure from this part if I'm misunderstanding your meaning, or if you are fuzzy on how the current chain dispute resolution protocol works on the network.
As soon as a block is found, the miner announces it to every attached node, and they broadcast it to their attached nodes, etc, until it spreads across the entire network. The spreading across the network takes some time, but not much. Another node might also find a block at roughly the same time, and announce it too. Now there are two "next" blocks on the network, both legitimate. The nodes handle it by trusting the one they get first, since the difficulty will always been the same (otherwise one or the other would be invalid). When the second block arrives at a node, it is stored as an alternate. On the network as it is now, this happens roughly once per 200 to 400 blocks by my estimation, that is, every couple of days.
So, now all the miners are working on the next next block, but the next next block they are working on corresponds to whichever next block made it first to the node running the miners. The next next block that is found will determine which of the two previous next blocks wins the race. As it spreads across the network, it will cause a single block reversion on those nodes that had initially seen the other next block first.
Unless, of course, a second next next block is found and announced before the first next next block has had enough time to reach every node. In this case, every node now believes one of the two chains, and keeps the other around as a potential alternate. I'm ignoring the chances of the fork forking here, but that just restarts this phase of the race. I estimate by multiplication that this happens about once every 40,00 to 160,000 blocks.
It can go on from here, of course, but the odds are already stacked against it. Of the first pair, one of them was probably slightly sooner than the other, and the network is probably not very evenly distributed, so most likely one block will be on more nodes than the other, which means that more miners will be working on one of them and the next will probably be found sooner for it. The second pair has all of the same imbalances, plus it started off on a lopsided network. The more blocks are involved in the fork, the more the coincidences have to pile up just to keep the fork from resolving. If my 1 in 300 estimate is even close to right, I won't live long enough to see a fork get to 4 (and probably not even 3).