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] return an error when the specified height is not supported #4174

Closed
wants to merge 4 commits into from

Conversation

millken
Copy link
Contributor

@millken millken commented Mar 7, 2024

Description

Currently we do not support archive mode. When querying these web3APIs

  • eth_getBalance
  • eth_getCode
  • eth_getTransactionCount
  • eth_getStorageAt
  • eth_call

if a height is specified, the result is returned for the latest height. This PR fixes returning an error if height is not supported

Fixes #4167

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

Copy link

sonarcloud bot commented Mar 7, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
42.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Copy link

codecov bot commented Mar 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.41%. Comparing base (d716bb9) to head (6b36e94).
Report is 26 commits behind head on master.

❗ Current head 6b36e94 differs from pull request most recent head 74b82f4. Consider uploading reports for the commit 74b82f4 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4174      +/-   ##
==========================================
- Coverage   76.51%   76.41%   -0.10%     
==========================================
  Files         340      340              
  Lines       29273    28997     -276     
==========================================
- Hits        22397    22159     -238     
+ Misses       5761     5731      -30     
+ Partials     1115     1107       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -311,11 +312,36 @@ func (svr *web3Handler) getBlockByNumber(in *gjson.Result) (interface{}, error)
return svr.getBlockWithTransactions(blk.Block, blk.Receipts, isDetailed.Bool())
}

func (svr *web3Handler) checkInputBlockNumber(str string) error {
Copy link
Member

@envestcc envestcc Mar 8, 2024

Choose a reason for hiding this comment

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

according to the eth standards, this str could be either a block number, a block enum, or a block hash. The implementation here may be incomplete

Copy link
Member

Choose a reason for hiding this comment

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

and prefer name it as checkInputBlock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block

When requests are made that act on the state of Ethereum, the last default block parameter determines the height of the block.

The following options are possible for the defaultBlock parameter:

HEX String - an integer block number
String "earliest" for the earliest/genesis block
String "latest" - for the latest mined block
String "safe" - for the latest safe head block
String "finalized" - for the latest finalized block
String "pending" - for the pending state/transactions

Copy link
Member

Choose a reason for hiding this comment

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

That content may lack complete details. Refer to the following for specifics:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ququzone
Copy link
Contributor

This fix should be released with archive mode features, because this fix will cause graph-node fail without archive mode.

Copy link

sonarcloud bot commented Apr 15, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
17.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

case "", _earliestBlockNumber, _pendingBlockNumber:
return errInvalidBlockHeight
case _latestBlockNumber:
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete

case _latestBlockNumber:
return nil
default:
//check str is block hash string
Copy link
Collaborator

Choose a reason for hiding this comment

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

tip := svr.coreService.TipHeight()

@@ -322,11 +323,46 @@ func (svr *web3Handler) getBlockByNumber(in *gjson.Result) (interface{}, error)
return svr.getBlockWithTransactions(blk.Block, blk.Receipts, isDetailed.Bool())
}

func (svr *web3Handler) checkInputBlock(str string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

    func (svr *web3Handler) checkHeight(input gjson.Result) error {
        if !input.Exists() {
             return nil
        }

@millken millken closed this by deleting the head repository Aug 18, 2024
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.

Archive mode related RPC return wrong result
4 participants