Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: getTotalSupply can fall back to Upstream EN #58

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

blukat29
Copy link
Contributor

@blukat29 blukat29 commented Aug 7, 2024

Proposed changes

  1. In the kaia_getTotalSupply API, add an optional showPartial *bool parameter that controls the error behavior.
  • As-is: API returns...
    • (a) Return a full information or
    • (b) Return a partial information
  • To-be: API returns..
    • Regular use case: If showPartial == nil || *showPartial == false (default)
      • (a) Return a full information or
      • (c) API Fails. If --upstream-en is configured and the error contains "missing trie node", retry with upstream.
    • Advanced/Debugging use case: If *showPartial == true
      • (a) Return a full information or
      • (b) Return a partial information
  1. More generous --upstream-en criteria
  • Updated shouldRequestUpstream() to recognize a wrapped error that contains "missing trie node" error.

Rationale

Regular users of this API are interested in the full information including the totalSupply field. For those uses, responses (b) and (c) are both unsatisfactory. But compared to (b), (c) is better because it can at least retry via --upstream-en.

Response example

  • (a) Return a full information
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "number": "0x99c4ef3",
    "totalSupply": "0x446c3b15f9926687d2d40c284b29cb9e52ac96b5fe",
    "totalMinted": "0x446c3b15f9926687d2c87ebd0341151d6357f80000",
    "totalBurnt": "-0xb8d6b47e8b680ef549eb5fe",
    "burntFee": "0x9e7d0a18207b048528c5",
    "zeroBurn": "0x65c7159b3ef9a5c78e9",
    "deadBurn": "0x36345feb5921447741",
    "kip103Burn": "0x6a15eef7e3a354cf657913",
    "kip160Burn": "-0xbf82646906be407e42a4800"
  }
}
  • (b) Return a partial information with the result.error field containing "missing trie node" error message.
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "number": "0x99c4ef3",
    "error": "cannot determine canonical (0x0, 0xdead) burn amount: missing trie node fa4aa0947dd9fbe527914ecafec8034766cf1a9873f90c2852f5f478900bcfed (path )",
    "totalSupply": null,
    "totalMinted": "0x446c3b15f9926687d2c87ebd0341151d6357f80000",
    "totalBurnt": null,
    "burntFee": "0x9e7d0a18207b048528c5",
    "zeroBurn": null,
    "deadBurn": null,
    "kip103Burn": "0x6a15eef7e3a354cf657913",
    "kip160Burn": "-0xbf82646906be407e42a4800"
  }
}
  • (c) API Fails
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32000,
    "message": "cannot determine canonical (0x0, 0xdead) burn amount: missing trie node fa4aa0947dd9fbe527914ecafec8034766cf1a9873f90c2852f5f478900bcfed (path )"
  }
}

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have read the CLA and signed by comment I have read the CLA Document and I hereby sign the CLA in first time contribute
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@blukat29 blukat29 force-pushed the supply-api-upstream branch from 44fa695 to ae2c6a9 Compare August 7, 2024 12:36
@blukat29 blukat29 changed the title api: getTotalSupply can falls back to upstream upon missing trie node error api: getTotalSupply can falls back to Upstream EN Aug 7, 2024
@blukat29 blukat29 changed the title api: getTotalSupply can falls back to Upstream EN api: getTotalSupply can fall back to Upstream EN Aug 7, 2024
@blukat29 blukat29 marked this pull request as ready for review August 7, 2024 12:44
@blukat29 blukat29 merged commit 8e7f137 into kaiachain:dev Aug 8, 2024
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants