-
Notifications
You must be signed in to change notification settings - Fork 328
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 functions parameters #3959
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3959 +/- ##
==========================================
+ Coverage 75.38% 76.12% +0.74%
==========================================
Files 303 330 +27
Lines 25923 28076 +2153
==========================================
+ Hits 19541 21372 +1831
- Misses 5360 5606 +246
- Partials 1022 1098 +76
... and 4 files with indirect coverage changes 📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
b8b6ed6
to
59c3d73
Compare
helperCtx := mustGetHelperCtx(ctx) | ||
ctx = WithHelperCtx(ctx, HelperContext{ | ||
GetBlockHash: helperCtx.GetBlockHash, | ||
DepositGasFunc: func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) { | ||
return nil, nil | ||
}, | ||
Sgd: nil, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add TODO: move the logic out of SimulateExecution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is preferred to be done in this pr since putting mustGetHelperCtx
aside WithHelperCtx
is strange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will open another PR to address it, to avoid causing too many code conflicts in the upcoming PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add TODO
func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) { | ||
return nil, nil | ||
}, | ||
nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong implementation. SimulateExecution
is supposed to have the same behavior as ExecuteContract
, including gas
func(height uint64) (hash.Hash256, error) { | ||
return hash.ZeroHash256, nil | ||
}, | ||
func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) { | ||
return nil, nil | ||
}, | ||
nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a TODO
func (core *coreService) simulateExecution(ctx context.Context, addr address.Address, exec *action.Execution, getBlockHash evm.GetBlockHash) ([]byte, *action.Receipt, error) { | ||
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ | ||
GetBlockHash: getBlockHash, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a TODO
to add depositGas
data, _, err := factory.SimulateExecution(ctx, addr, ex, dao.GetBlockHash) | ||
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ | ||
GetBlockHash: dao.GetBlockHash, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
if err != nil { | ||
return nil, nil, err | ||
} | ||
sgd := ps.helperCtx.Sgd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change L277-287:
receiver, sharedGas, err = processSGD(ctx, sm, execution, consumedGas, helperCtx)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to process Sharing of Gas-fee with DApps")
}
after modifying func processSGD(ctx, sm, execution, consumeGas, helperCtx)
08595a8
to
d7bf0a4
Compare
action/protocol/execution/evm/evm.go
Outdated
func depositeGas(ctx context.Context, sm protocol.StateManager, execution *action.Execution, consumedGas uint64, gasPrice *big.Int, hCtx HelperContext, fCtx protocol.FeatureCtx) (*action.TransactionLog, error) { | ||
var ( | ||
receiver address.Address | ||
sharedGas uint64 | ||
sharedGasFee, totalGasFee *big.Int | ||
err error | ||
) | ||
if fCtx.SharedGasWithDapp && hCtx.Sgd != nil { | ||
receiver, sharedGas, err = processSGD(ctx, sm, execution, consumedGas, hCtx.Sgd) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to process Sharing of Gas-fee with DApps") | ||
} | ||
} | ||
if sharedGas > 0 { | ||
sharedGasFee = big.NewInt(int64(sharedGas)) | ||
sharedGasFee.Mul(sharedGasFee, gasPrice) | ||
} | ||
totalGasFee = new(big.Int).Mul(new(big.Int).SetUint64(consumedGas), gasPrice) | ||
return hCtx.DepositGasFunc(ctx, sm, receiver, totalGasFee, sharedGasFee) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not what I mean.
func processSGD(ctx context.Context, sm protocol.StateManager, execution *action.Execution, consumedGas uint64, sgd SGDRegistry,
) (address.Address, uint64, error) {
if sgd == nil {
return nil, 0, nil
}
....
thus, outside, we only need to checkif ps.featureCtx.SharedGasWithDapp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted, and added TODO
@@ -291,7 +294,10 @@ func getContractReaderForGenesisStates(ctx context.Context, sm protocol.StateMan | |||
return nil, err | |||
} | |||
|
|||
res, _, err := evm.SimulateExecution(ctx, sm, addr, ex, getBlockHash) | |||
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WithHelperCtx could be called by the caller, then getBlockHash
argument can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a TODO
action/protocol/execution/evm/evm.go
Outdated
@@ -316,6 +300,27 @@ func ExecuteContract( | |||
return retval, receipt, nil | |||
} | |||
|
|||
func depositeGas(ctx context.Context, sm protocol.StateManager, execution *action.Execution, consumedGas uint64, gasPrice *big.Int, hCtx HelperContext, fCtx protocol.FeatureCtx) (*action.TransactionLog, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change isn't related to the intro of WithHelperCtx
, which could be done in another pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
d7bf0a4
to
8d71e84
Compare
SonarCloud Quality Gate failed. 0 Bugs No Coverage information Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
Description
Introducing
HelperContext
in EVM simplifies the parameter passing in public methods, mitigates the issue of passing parameters through multiple layers, and minimize subsequent modifications when adding parameters.Type of change
Please delete options that are not relevant.
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
Test Configuration:
Checklist: