Commit 4783f68
committed
feat(api): add centralized int64_as_string support for #6568
Add a thread-local in JsonFormat that, when set, serializes int64/uint64
proto fields as quoted JSON strings to avoid precision loss in clients
whose native number type cannot safely represent integers above 2^53 - 1
(e.g. JavaScript). The flag is read in strict mode:
- GET requests: URL query, parsed once in RateLimiterServlet.service
- POST requests: request body, parsed once in PostParams.getPostParams
The thread-local is cleared in service()'s finally block so reused threads
do not leak state across requests. POST URL query is intentionally not
read in service() because calling getParameter() on a POST consumes
application/x-www-form-urlencoded bodies and would break downstream
getReader(). This also gives clients a single, unambiguous contract:
GET reads the URL, POST reads the body.
- JsonFormat: add INT64_AS_STRING ThreadLocal + setInt64AsString /
clearInt64AsString / isInt64AsString helpers; split printFieldValue
INT64/SINT64/SFIXED64 and UINT64/FIXED64 branches so they emit quoted
strings only when the flag is set.
- Util: add INT64_AS_STRING constant + getInt64AsString (URL query,
mirrors getVisible) + getInt64AsStringPost (JSON body, mirrors
getVisiblePost). Also extract Util.decodeAddress (shared between
getAddress and servlets that read the address from a JSON body) and
add Util.processAddressError (shared "INVALID address" error response).
- PostParams.getPostParams: call JsonFormat.setInt64AsString with the
parsed body value; cleanup is centralized in RateLimiterServlet.
- RateLimiterServlet.service: set ThreadLocal from URL query on GET;
clear in finally for both GET and POST.1 parent 09127ab commit 4783f68
4 files changed
Lines changed: 124 additions & 14 deletions
File tree
- framework/src/main/java/org/tron/core/services/http
Lines changed: 55 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
93 | 129 | | |
94 | 130 | | |
95 | 131 | | |
| |||
340 | 376 | | |
341 | 377 | | |
342 | 378 | | |
343 | | - | |
344 | 379 | | |
345 | | - | |
346 | 380 | | |
347 | | - | |
348 | 381 | | |
349 | 382 | | |
350 | 383 | | |
351 | 384 | | |
352 | 385 | | |
353 | 386 | | |
354 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
355 | 400 | | |
356 | 401 | | |
357 | 402 | | |
358 | 403 | | |
359 | 404 | | |
360 | 405 | | |
361 | 406 | | |
362 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
363 | 414 | | |
364 | 415 | | |
365 | 416 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
105 | 112 | | |
106 | 113 | | |
107 | 114 | | |
| |||
119 | 126 | | |
120 | 127 | | |
121 | 128 | | |
| 129 | + | |
122 | 130 | | |
123 | 131 | | |
124 | 132 | | |
| |||
Lines changed: 57 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
346 | 347 | | |
347 | 348 | | |
348 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
349 | 362 | | |
350 | 363 | | |
351 | 364 | | |
| |||
358 | 371 | | |
359 | 372 | | |
360 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
361 | 389 | | |
362 | 390 | | |
363 | 391 | | |
| |||
483 | 511 | | |
484 | 512 | | |
485 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
486 | 528 | | |
487 | 529 | | |
488 | 530 | | |
| |||
509 | 551 | | |
510 | 552 | | |
511 | 553 | | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
521 | 568 | | |
522 | | - | |
| 569 | + | |
523 | 570 | | |
524 | 571 | | |
525 | 572 | | |
| |||
0 commit comments