marcus1987
New Member
- Messages
- 66
- Reaction score
- 0
- Location
- Sydney, NSW
Spent most of last night debugging a payout discrepancy on a site I help run and it came down to the dumbest thing possible. My balances column was DOUBLE PRECISION. Set it up two years ago in a hurry because "it's just a number" and I never touched it again.
Yeah. 0.1 + 0.2 does not equal 0.3, and when you're counting in wei you're not even in the same zip code. The whole thing surfaced because a guy withdrew 0.05 ETH and his balance didn't zero out. Showed like 0.0000000000000002 left sitting there. He screenshotted it, dropped it in our TG, and within an hour everyone's convinced we're skimming pennies. Six hours of my life to prove it was floating point and not theft.
Moved everything to NUMERIC(38,18) and I'm never going back. Same weekend I also found a nonce counter stored as a plain INT that wrapped negative after a busy stretch, which was a great surprise at 3am when withdrawals started failing silently.
And before anyone says just use a regulated processor, I've been down that road, they'll hold your funds for a week and charge you for the privilege. Hard pass.
If you're storing wei or satoshis anywhere, use numeric or bigint from day one. Anyone else get wrecked by this early on? Curious how many of you caught it before a user did.