Skip to content

fix(api): XDPoS_getRewardByAccount to be able to parse scientific notation#2301

Open
wanwiset25 wants to merge 2 commits intodev-upgradefrom
fix-reward-scientific-notation
Open

fix(api): XDPoS_getRewardByAccount to be able to parse scientific notation#2301
wanwiset25 wants to merge 2 commits intodev-upgradefrom
fix-reward-scientific-notation

Conversation

@wanwiset25
Copy link
Copy Markdown
Collaborator

Proposed changes

fix api XDPoS_getRewardByAccount to be able to parse scientific not

added unit tests

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 13, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dcf1ff17-018f-4f64-bc35-773b23491267

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-reward-scientific-notation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the XDPoS_getRewardByAccount reward parsing path to handle reward values encoded in JSON using scientific notation, and adds unit tests to validate the conversion behavior.

Changes:

  • Added jsonNumberToBigInt to convert json.Number values that may be in scientific notation into *big.Int.
  • Updated reward extraction logic to use the new conversion helper instead of big.Int.SetString.
  • Added unit tests covering integer, scientific-notation, and invalid-number inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
consensus/XDPoS/api.go Adds jsonNumberToBigInt and wires it into reward parsing for masternode/protector/observer reward fields.
consensus/XDPoS/api_test.go Adds unit tests for jsonNumberToBigInt and imports encoding/json.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread consensus/XDPoS/api.go
Comment on lines +626 to +630
// Fall back to big.Float to handle scientific notation.
f, _, err := new(big.Float).SetPrec(256).Parse(s, 10)
if err != nil {
log.Warn("[jsonNumberToBigInt] Failed to parse json.Number:", "number", s, "err", err)
return nil, false
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

Using big.Float with a fixed 256-bit precision to parse JSON numbers can round large values; when this happens, converting to *big.Int may yield an incorrect integer. For reward amounts (which should be exact), consider an exact parsing strategy (e.g., mantissa+exponent to big.Int/big.Rat) instead of big.Float.

Copilot uses AI. Check for mistakes.
Comment thread consensus/XDPoS/api.go Outdated
Comment thread consensus/XDPoS/api_test.go
Comment thread consensus/XDPoS/api_test.go Outdated
@wanwiset25 wanwiset25 changed the title fix(api): XDPoS_getRewardByAccount to be able to parse scientific not fix(api): XDPoS_getRewardByAccount to be able to parse scientific notation Apr 28, 2026
@wanwiset25 wanwiset25 force-pushed the fix-reward-scientific-notation branch from 7894a0f to 48edd5c Compare April 28, 2026 11:26
@wanwiset25 wanwiset25 force-pushed the fix-reward-scientific-notation branch from 48edd5c to 1777b00 Compare April 28, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants