Skip to content

Conversation

stickies-v
Copy link
Contributor

@stickies-v stickies-v commented Mar 14, 2023

Follow-up to #26612 (comment). As per #26506 (review), ParseNonRFCJSONValue() is no longer necessary and we can use UniValue::read() directly:

IIRC before that PR UniValue::read could only parse JSON object and array values, but now it will parse string/number/boolean/null values as well. laanwj pointed this out in #9028 (comment)

The implementation of ParseNonRFCJSONValue() was already simplified in #26612 and test coverage updated to ensure behaviour didn't change.

To avoid code duplication, we keep the function to throw on invalid input data but rename it to Parse() and remove it from the header.

The existing test coverage we had on ParseNonRFCJSONValue() is moved over to UniValue::read().

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 14, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ryanofsky

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@stickies-v stickies-v force-pushed the 2023-03/remove-ParseNonRFCJSONValue branch from f43b98b to 104e482 Compare March 16, 2023 11:23
@stickies-v stickies-v force-pushed the 2023-03/remove-ParseNonRFCJSONValue branch from 104e482 to 860e707 Compare March 16, 2023 11:35
@fanquake fanquake requested a review from ryanofsky March 19, 2023 12:17
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 860e707. This looks good, but we will have to find another function to give the most confusing function name award to. I left a few minor review suggestions, but they can be ignored.

@stickies-v stickies-v force-pushed the 2023-03/remove-ParseNonRFCJSONValue branch from 860e707 to 79ee14b Compare March 23, 2023 16:35
@stickies-v stickies-v changed the title refactor: rpc: remove ParseNonRFCJSONValue() refactor: rpc: Remove unnecessary uses of ParseNonRFCJSONValue() and rename it Mar 23, 2023
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 79ee14b. Just added static and updated commit description since last review

Preparation to deprecate ParseNonRFCJSONValue() but keep test coverage
on the underlying UniValue::read() unaffected. The test coverage on
AmountFromValue is no longer included, since that is already tested
in the rpc_parse_monetary_values test case.

Fuzzing coverage on ParseNonRFCJSONValue() was duplicated between string.cpp
and parse_univalue.cpp, only the one in parse_univalue.cpp is kept.
As per bitcoin#26506 (review),
this function is no longer necessary and we can use UniValue::read() directly.

To avoid code duplication, we keep the function to throw on invalid input data
but rename it to Parse() and remove it from the header.
@stickies-v stickies-v force-pushed the 2023-03/remove-ParseNonRFCJSONValue branch from 79ee14b to cfbc8a6 Compare March 23, 2023 18:19
@stickies-v
Copy link
Contributor Author

Force pushed to add test a test case on AmountFromValue() that was previously not reached but probably intended.

Addressed all of @ryanofsky's comments - thank you for the review!

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK cfbc8a6. Only change since last review is adding a new test

@fanquake fanquake merged commit 436c185 into bitcoin:master Jun 2, 2023
@stickies-v stickies-v deleted the 2023-03/remove-ParseNonRFCJSONValue branch June 2, 2023 15:19
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 2, 2023
fanquake added a commit that referenced this pull request Apr 17, 2024
fa4c696 test: Fix failing univalue float test (MarcoFalke)

Pull request description:

  Currently the test may fail for some compilers, because `1e-8` may not be possible to represent exactly/consistently.

  ```
  $ ./src/univalue/test/object
  object: univalue/test/object.cpp:424: void univalue_readwrite(): Assertion `v.read("0.00000000000000000000000000000000000001e+30 ") && v.get_real() == 1e-8' failed.
  Aborted (core dumped)
  ```

  Fixes #27256 (comment)

ACKs for top commit:
  laanwj:
    ACK fa4c696
  stickies-v:
    ACK fa4c696 , thanks for fixing!

Tree-SHA512: dea4f4f843381d5e8ffaa812b2290a11e081b29f8777d041751c4aa9942e60f1f8d2d1a652d9a52b41dec470a490c9fe26ca9bc762dd593c3521b328a8af2826
@bitcoin bitcoin locked and limited conversation to collaborators Apr 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants