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

[evm] refactor evm parameters #3958

Merged
merged 4 commits into from
Nov 3, 2023
Merged

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented Nov 1, 2023

Description

To ensure easier code maintenance in EVM, the Params struct is used internally to access the required parameters.

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

Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Merging #3958 (10f0aa3) into master (e1f0636) will increase coverage by 0.79%.
Report is 94 commits behind head on master.
The diff coverage is 77.33%.

❗ Current head 10f0aa3 differs from pull request most recent head 66d0e85. Consider uploading reports for the commit 66d0e85 to get more accurate results

@@            Coverage Diff             @@
##           master    #3958      +/-   ##
==========================================
+ Coverage   75.38%   76.17%   +0.79%     
==========================================
  Files         303      328      +25     
  Lines       25923    27982    +2059     
==========================================
+ Hits        19541    21316    +1775     
- Misses       5360     5570     +210     
- Partials     1022     1096      +74     
Files Coverage Δ
action/candidate_register.go 90.00% <100.00%> (ø)
action/candidate_update.go 89.01% <100.00%> (+0.12%) ⬆️
action/claimreward.go 90.62% <100.00%> (-0.42%) ⬇️
action/depositreward.go 87.50% <100.00%> (-0.56%) ⬇️
action/protocol/context.go 67.91% <100.00%> (+0.73%) ⬆️
action/protocol/execution/evm/evmstatedbadapter.go 66.77% <ø> (ø)
action/protocol/execution/protocol.go 42.10% <100.00%> (ø)
action/protocol/rewarding/reward.go 90.07% <100.00%> (+0.60%) ⬆️
...tion/protocol/staking/candidate_buckets_indexer.go 89.31% <100.00%> (-0.47%) ⬇️
...col/staking/ethabi/stake_composite_bucketscount.go 100.00% <100.00%> (ø)
... and 67 more

... and 3 files with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@envestcc envestcc marked this pull request as ready for review November 1, 2023 16:43
retval, depositGas, remainingGas, contractAddress, statusCode, err := executeInEVM(ctx, ps, stateDB, g.Blockchain, blkCtx.GasLimit, blkCtx.BlockHeight)
actionCtx := ps.actionCtx
blkCtx := ps.blkCtx
featureCtx := ps.featureCtx
Copy link
Member

Choose a reason for hiding this comment

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

directly use ps.actionCtx/blkCtx/featureCtx

config = vmCfg
}
chainConfig := getChainConfig(g, blockHeight, evmParams.evmNetworkID)
config := evmParams.evmConfig
Copy link
Member

Choose a reason for hiding this comment

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

directly use evmParams.evmConfig since it is only used 1 time

}
chainConfig := getChainConfig(g, blockHeight, evmParams.evmNetworkID)
config := evmParams.evmConfig
chainConfig := evmParams.chainConfig
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 L426 together

func executeInEVM(evmParams *Params, stateDB *StateDBAdapter) ([]byte, uint64, uint64, string, iotextypes.ReceiptStatus, error) {
gasLimit := evmParams.blkCtx.GasLimit
blockHeight := evmParams.blkCtx.BlockHeight
g := evmParams.genesis
Copy link
Member

@dustinxie dustinxie Nov 2, 2023

Choose a reason for hiding this comment

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

looks better to group together

var (
    gasLimit
    ....
)

@@ -105,6 +111,7 @@ func newParams(
actionCtx := protocol.MustGetActionCtx(ctx)
blkCtx := protocol.MustGetBlockCtx(ctx)
featureCtx := protocol.MustGetFeatureCtx(ctx)
g := genesis.MustExtractGenesisContext(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

looks better to group together

var (
    actionCtx
    ...
)

@@ -162,6 +169,12 @@ func newParams(
Difficulty: new(big.Int).SetUint64(uint64(50)),
BaseFee: new(big.Int),
}
evmNetworkID := protocol.MustGetBlockchainCtx(ctx).EvmNetworkID
vmConfig := vm.Config{}
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 L114

blkCtx protocol.BlockCtx
genesis genesis.Blockchain
featureCtx protocol.FeatureCtx
actionCtx protocol.ActionCtx
Copy link
Member

Choose a reason for hiding this comment

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

L89 executorRawAddress string can be deleted, defined but not used at all

vmConfig vm.Config
contractAddrPointer *common.Address
getHashFn vm.GetHashFunc
)
executorAddr := common.BytesToAddress(actionCtx.Caller.Bytes())
Copy link
Member

@dustinxie dustinxie Nov 3, 2023

Choose a reason for hiding this comment

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

L122 move to L116

Copy link

sonarcloud bot commented Nov 3, 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 2 Code Smells

No Coverage information No Coverage information
9.2% 9.2% Duplication

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

@envestcc envestcc merged commit 04681fd into iotexproject:master Nov 3, 2023
3 of 4 checks passed
@envestcc envestcc deleted the pr_evmparam branch November 3, 2023 08:04
@envestcc envestcc linked an issue Nov 17, 2023 that may be closed by this pull request
6 tasks
@envestcc envestcc mentioned this pull request Nov 24, 2023
6 tasks
@envestcc envestcc removed a link to an issue Nov 24, 2023
6 tasks
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