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] add EstimateGasForNonExecution in coreservice #3174

Merged
merged 13 commits into from
Mar 17, 2022

Conversation

Liuhaai
Copy link
Member

@Liuhaai Liuhaai commented Mar 9, 2022

follows #3095

@Liuhaai Liuhaai requested a review from a team as a code owner March 9, 2022 06:12
@codecov
Copy link

codecov bot commented Mar 9, 2022

Codecov Report

Merging #3174 (c867fa0) into master (76bd834) will decrease coverage by 0.06%.
The diff coverage is 64.10%.

@@            Coverage Diff             @@
##           master    #3174      +/-   ##
==========================================
- Coverage   75.07%   75.00%   -0.07%     
==========================================
  Files         227      227              
  Lines       21272    21329      +57     
==========================================
+ Hits        15970    15998      +28     
- Misses       4465     4481      +16     
- Partials      837      850      +13     
Impacted Files Coverage Δ
api/grpcserver.go 85.23% <53.48%> (-4.74%) ⬇️
api/coreservice.go 67.88% <60.00%> (-0.12%) ⬇️
api/web3server_utils.go 67.12% <76.47%> (+0.46%) ⬆️
api/web3server.go 71.29% <84.61%> (-0.19%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76bd834...c867fa0. Read the comment docs.

Comment on lines 1444 to 1448
gas, err := action.CalculateIntrinsicGas(intrinsicGas, payloadGas, payloadSize)
if err != nil {
return 0, err
}
return gas, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

return action.CalculateIntrinsicGas(intrinsicGas, payloadGas, payloadSize)

Comment on lines 1424 to 1426
switch act := actType.(type) {
case *action.Transfer:
intrinsicGas, payloadGas, payloadSize = action.TransferBaseIntrinsicGas, action.TransferPayloadGas, uint64(len(payload))
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is a bit weird to have gas estimation calculation outside of action.Action and hardcoded in core service instead in this way.

Copy link
Member Author

@Liuhaai Liuhaai Mar 9, 2022

Choose a reason for hiding this comment

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

Should EstimateGasForNonExecution() be moved to action.go?

return action.NewExecution(to, tx.Nonce(), tx.Value(), tx.Gas(), tx.GasPrice(), tx.Data())
case address.StakingProtocolAddr:
data := tx.Data()
if len(data) <= 4 {
Copy link
Member Author

Choose a reason for hiding this comment

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

Will use action.NewStakingActionFromABIBinary(tx.Data()) in #3095

func (core *coreService) CalculateGasConsumption(intrinsicGas, payloadGas, payloadSize uint64) (uint64, error) {
return action.CalculateIntrinsicGas(intrinsicGas, payloadGas, payloadSize)
// EstimateGasForNonExecution estimates action gas except execution
func (core *coreService) EstimateGasForNonExecution(actType action.Action, payload []byte) (uint64, error) {
Copy link
Member

@dustinxie dustinxie Mar 10, 2022

Choose a reason for hiding this comment

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

payload is not needed

if err := tmpAct.LoadProto(in.GetTransfer()); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
act, payload = tmpAct, tmpAct.Payload()
Copy link
Member

Choose a reason for hiding this comment

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

estimatedGas, err = tmpAct.IntrinsicGas()

if err := tmpAct.LoadProto(in.GetStakeCreate()); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
act, payload = tmpAct, tmpAct.Payload()
Copy link
Member

Choose a reason for hiding this comment

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

estimatedGas, err = tmpAct.IntrinsicGas()

if err := tmpAct.LoadProto(in.GetStakeUnstake()); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
act, payload = tmpAct, tmpAct.Payload()
Copy link
Member

Choose a reason for hiding this comment

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

same for all places

Copy link
Collaborator

@CoderZhi CoderZhi left a comment

Choose a reason for hiding this comment

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

I would suggest we don't make this move, especially under the title "add EstimateGasForNonExecution in coreservice"

@Liuhaai Liuhaai merged commit 2febef9 into iotexproject:master Mar 17, 2022
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