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)

@@ -243,13 +246,21 @@ func WithAPIStats(stats *nodestats.APILocalStats) Option {
}
}

// WithArchiveSupport is the option to enable archive support
func WithArchiveSupport(enabled bool) Option {
Copy link
Member

Choose a reason for hiding this comment

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

The enable parameter should be redundant; this option is supposed to enable 'archive mode'.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

pendingNonce = state.PendingNonce()
}
} else {
pendingNonce, err = core.ap.GetPendingNonce(addrStr)
Copy link
Member

Choose a reason for hiding this comment

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

Recommend to move 'nonce from the actpool` to the Account method, and removing the 'archive bool' parameter would make it clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

if err != nil {
return "", nil, status.Error(codes.Internal, err.Error())
}
// ReadContract() is read-only, if no error returned, we consider it a success
receipt.Status = uint64(iotextypes.ReceiptStatus_Success)
Copy link
Member

@envestcc envestcc Dec 24, 2024

Choose a reason for hiding this comment

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

stale code, remove it. refer #4454

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

func (core *coreService) simulateExecution(
ctx context.Context,
height uint64,
archive bool,
Copy link
Member

Choose a reason for hiding this comment

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

can consider passing 'ws' as a parameter instead of the boolean.

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.

that's doable, yet would cause code L2004-2008 to be duplicated at these funcs:

func (core *coreService) ReadContract()
func (core *coreService) isGasLimitEnough()
func (core *coreService) SimulateExecution()
func (core *coreService) TraceTransaction()
func (core *coreService) TraceCall()

IMO the current way is more efficient

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

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.

3 participants