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] archive-mode for eth_getBalance & eth_call #4529

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dustinxie
Copy link
Member

Description

as title. Based on #4526

Fixes #(issue)

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

@dustinxie dustinxie requested review from CoderZhi, Liuhaai, envestcc and a team as code owners December 19, 2024 01:01
type intrinsicGasCalculator interface {
IntrinsicGas() (uint64, error)
}

var (
// ErrNotFound indicates the record isn't found
ErrNotFound = errors.New("not found")
ErrNotFound = errors.New("not found")
ErrArchiveNotSupported = errors.New("archive-mode not supported")
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment

Copy link
Member Author

Choose a reason for hiding this comment

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

removed L261 comment, the name clears explains what the error is

}

func (core *coreServiceReaderWithHeight) Account(addr address.Address) (*iotextypes.AccountMeta, *iotextypes.BlockIdentifier, error) {
if !core.cs.archiveSupported {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

@dustinxie dustinxie Dec 26, 2024

Choose a reason for hiding this comment

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

it is already supported by factory/statedb, the actual archive support at DB level will be enabled in #4517, #4518


type (
// CoreServiceReaderWithHeight is an interface for state reader at certain height
CoreServiceReaderWithHeight interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you explain why we need to create such an interface?

Copy link
Member Author

@dustinxie dustinxie Dec 26, 2024

Choose a reason for hiding this comment

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

this interface is created to represent APIs needed for archive-mode query (there will be a total 4-6 of them, 2 enabled in this PR, and more to enable in upcoming PR), so we can keep using existing API without having to add the height parameter to it, that is, we can avoid changes like below

Account(address.Address, height uint64) (*iotextypes.AccountMeta, *iotextypes.BlockIdentifier, error)

api/coreservice.go Outdated Show resolved Hide resolved
api/coreservice.go Outdated Show resolved Hide resolved
api/coreservice.go Outdated Show resolved Hide resolved
if err != nil {
return nil, nil, status.Error(codes.Internal, err.Error())
}
ws, err = core.sf.WorkingSet(ctx)
Copy link
Member Author

@dustinxie dustinxie Dec 27, 2024

Choose a reason for hiding this comment

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

these lines would be duplicated multiple times if use ws instead of boolean as input

Comment on lines +409 to +417
var (
accountMeta *iotextypes.AccountMeta
height, archive = blockNumberToHeight(bn)
)
if !archive {
accountMeta, _, err = svr.coreService.Account(ioAddr)
} else {
accountMeta, _, err = svr.coreService.WithHeight(height).Account(ioAddr)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

such that we can always return a Reader from svr.coreService by calling svr.coreService.Reader(bn).Account(ioAddr)

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.

4 participants