Commit b63f3fa
committed
fix(storage): keep token amounts exact instead of truncating to uint64
TokenRecord.Amount was uint64 while the backing column is
amount NUMERIC(78, 0), sized for a 256-bit value. AppendToken narrowed the
quantity with big.Int.Uint64(), which returns the low 64 bits with no error
for anything larger, so for a token whose quantity exceeds 2^64-1 the amount
column silently received a wrapped value while the authoritative hex quantity
column stayed correct.
Widen the field to *big.Int and insert its exact decimal representation,
following the pattern already used for movement and transaction records.
StoreToken now refuses a nil amount (the column is NOT NULL) and one wider
than maxAmountBits, so a value the column cannot hold surfaces as an error
instead of a row whose two amount columns disagree. No consumer relied on the
uint64 type; the only call sites were the test fixtures updated here.
Note that only Postgres can hold such a value: SQLite gives a NUMERIC column
NUMERIC affinity and converts an integer literal too large for int64 to REAL.
With this change that fails loudly on read rather than corrupting silently.
The exact round-trip case is therefore wired into the Postgres suite, while
the write-time validation case runs on every backend.
Fixes #2021
Signed-off-by: AkramBitar <akram@il.ibm.com>1 parent 62e8a9c commit b63f3fa
9 files changed
Lines changed: 151 additions & 51 deletions
File tree
- token/services
- selector/testutils
- storage/db
- dbtest
- driver
- sql
- common
- postgres
- tokens
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
173 | 174 | | |
174 | 175 | | |
175 | 176 | | |
176 | | - | |
| 177 | + | |
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
0 commit comments