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] web3 api debug_traceCall support javascript tracing #3931

Merged
merged 9 commits into from
Jan 11, 2024
Merged

[api] web3 api debug_traceCall support javascript tracing #3931

merged 9 commits into from
Jan 11, 2024

Conversation

millken
Copy link
Contributor

@millken millken commented Aug 30, 2023

Description

as title

Fixes #3930

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

@codecov
Copy link

codecov bot commented Aug 30, 2023

Codecov Report

Attention: 598 lines in your changes are missing coverage. Please review.

Comparison is base (e1f0636) 75.38% compared to head (df1dc3e) 76.02%.
Report is 144 commits behind head on master.

Files Patch % Lines
blockindex/contractstaking/event_handler.go 67.23% 45 Missing and 13 partials ⚠️
action/protocol/staking/staking_statereader.go 69.76% 35 Missing and 17 partials ⚠️
action/protocol/execution/evm/evm.go 48.38% 47 Missing and 1 partial ⚠️
api/coreservice.go 61.45% 32 Missing and 5 partials ⚠️
api/web3server.go 78.23% 29 Missing and 3 partials ⚠️
action/candidate_endorsement.go 0.00% 31 Missing ⚠️
action/protocol/staking/protocol.go 33.33% 28 Missing ⚠️
action/candidate_activate.go 0.00% 25 Missing ⚠️
...tion/protocol/staking/contractstake_bucket_type.go 0.00% 24 Missing ⚠️
blockindex/contractstaking/util.go 39.47% 22 Missing and 1 partial ⚠️
... and 31 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3931      +/-   ##
==========================================
+ Coverage   75.38%   76.02%   +0.64%     
==========================================
  Files         303      334      +31     
  Lines       25923    28431    +2508     
==========================================
+ Hits        19541    21615    +2074     
- Misses       5360     5716     +356     
- Partials     1022     1100      +78     

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

@@ -59,9 +60,18 @@ import (
"github.com/iotexproject/iotex-core/server/itx/nodestats"
"github.com/iotexproject/iotex-core/state"
"github.com/iotexproject/iotex-core/state/factory"

// Force-load the tracer engines to trigger registration
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
Copy link
Member

Choose a reason for hiding this comment

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

move to the line below L29

@@ -1731,3 +1733,45 @@ func (core *coreService) Track(ctx context.Context, start time.Time, method stri
Success: success,
}, size)
}

func (core *coreService) traceTx(ctx context.Context, txctx *tracers.Context, config *tracers.TraceConfig, simulateFn func(ctx context.Context) ([]byte, *action.Receipt, error)) ([]byte, *action.Receipt, any, error) {
Copy link
Member

@Liuhaai Liuhaai Sep 6, 2023

Choose a reason for hiding this comment

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

create a private func for context initialization instead of traceTx with simulateFn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

create a private func for context initialization instead of traceTx with simulateFn?

traceTx (js tracing) has timeout settings, need to put simulateFn into tractTx.

Copy link
Member

Choose a reason for hiding this comment

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

it seems no need to put simulateFn as param of traceTx, can just call core.SimulateExecution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems no need to put simulateFn as param of traceTx, can just call core.SimulateExecution

If do this, need to pass some core.SimulateExecution required arguments

StructLogs: fromLoggerStructLogs(traces.StructLogs()),
Gas: receipt.GasConsumed,
}, nil
switch tracer := tracer.(type) {
Copy link
Member

Choose a reason for hiding this comment

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

can tracer's type be deduced from the cfg on L928?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you can. but it is cleaner and safer to deduced from the result

@sonarcloud
Copy link

sonarcloud bot commented Sep 7, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
11.7% 11.7% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

t.Stop(errors.New("execution timeout"))
}
}()
defer cancel()
Copy link
Member

Choose a reason for hiding this comment

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

move to L1758

@@ -27,6 +28,10 @@ import (
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"

// Force-load the tracer engines to trigger registration
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
Copy link
Member

Choose a reason for hiding this comment

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

move to L19

DisableStack: disableStack,
DisableStorage: disableStorage,
EnableReturnData: enableReturnData,
cfg := &tracers.TraceConfig{
Copy link
Member

Choose a reason for hiding this comment

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

Why not set Tracer and Timeout, compared with tracCall?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If users have this requirement, they can add.

Copy link
Member

Choose a reason for hiding this comment

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

I mean, does it support tracer and timeout config in traceTransaction just like what we supporting in traceCall?

const (
// defaultTraceTimeout is the amount of time a single transaction can execute
// by default before being forcefully aborted.
defaultTraceTimeout = 5 * time.Second
Copy link
Member

@envestcc envestcc Jan 8, 2024

Choose a reason for hiding this comment

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

Why defaultTraceTimeout is only used in TraceTransaction, but not in TraceCall?

Copy link

sonarcloud bot commented Jan 11, 2024

Quality Gate Failed Quality Gate failed

Failed conditions

12.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@ququzone ququzone self-requested a review January 11, 2024 03:39
@millken millken merged commit e2be18f into iotexproject:master Jan 11, 2024
3 of 5 checks passed
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.

[api] web3 debug_traceCall support custom javascript tracing
5 participants