by Dylan16807 · 7y ago · 0 comments
Since it starts at a random point and can't overflow, even if you generate a small number of IDs per millisecond you have a constant 1/2^79 chance of failing. The chance is small but reachable for a large network. (bitcoin does 2^88 hashes a day)
It could have just wrapped with no problem, because there's no possible node that could generate 2^80 IDs by itself. And if you have multiple nodes it doesn't help there either.
Does it? At 50M TH/s (https://www.blockchain.com/en/charts/hash-rate) that's 10^8 TH/s, or 10^8.10^12 = 10^20 hashes per second. There's less than 10^5 seconds so surely that's only 10^25 per day. If I've messed up each of these numbers by an order of magnitude, that would leave it still well under 10^30.
2^88 is absolutely enormous.
10^25 is close to right for one day, and 10^25 is equal to 2^83
2^88 is both absolutely enormous and a real number that bitcoin hits in less than a year.
So the point stands that a large deployment could rarely hit a 2^79 random failure case.
But that's sort of an implementation detail. You could write an implementation that did that and still be compatible with all other implementations.
I suppose, if you're particularly worried about the one-node situation.
> It's a little weird that they didn't just reserve or add some bits for sorting within milliseconds before or instead of having to increment the randomness.
There's no particular reason to make the fields separate. If you mask out the top bit of the random number then they can share and also make overflow effectively impossible.
It's also worth noting that there are two bits that go completely unused. They could eat overflow if the layout was slightly rearranged.
This algorithm doesn't work if you have multiple nodes, so I don't think any other situation is relevant here.
> There's no particular reason to make the fields separate. If you mask out the top bit of the random number then they can share and also make overflow effectively impossible
Yes, this is what I meant by reserving some bits.
> It's also worth noting that there are two bits that go completely unused. They could eat overflow if the layout was slightly rearranged.
Yeah, it's super weird they didn't do that. I guess they just really like having a power of two number of bits.
Then what's the random part for?
> Yes, this is what I meant by reserving some bits.
What I'm saying is, if you separate it out into an increment-field and a random-field, then you need a lot of bits and you need to fundamentally change how it works.
If you merely make sure your random number starts below some threshold, you only need 1 bit, or a small fraction of a bit. You would still increment the random number, but you wouldn't have to worry about hitting the max value if you always start between 0 and 2^79.9, for example.
What percentage of milliseconds in the day would that be?
It’s turtles all the way down from there, but it’s still valuable to scope “best case scenario” with probability math regardless of potential bugs in code.