-
Notifications
You must be signed in to change notification settings - Fork 335
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
api/coreservice.go
Outdated
gas, err := action.CalculateIntrinsicGas(intrinsicGas, payloadGas, payloadSize) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return gas, err |
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.
return action.CalculateIntrinsicGas(intrinsicGas, payloadGas, payloadSize)
api/coreservice.go
Outdated
switch act := actType.(type) { | ||
case *action.Transfer: | ||
intrinsicGas, payloadGas, payloadSize = action.TransferBaseIntrinsicGas, action.TransferPayloadGas, uint64(len(payload)) |
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 a bit weird to have gas estimation calculation outside of action.Action and hardcoded in core service instead in this way.
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.
Should EstimateGasForNonExecution()
be moved to action.go
?
api/web3server_utils.go
Outdated
return action.NewExecution(to, tx.Nonce(), tx.Value(), tx.Gas(), tx.GasPrice(), tx.Data()) | ||
case address.StakingProtocolAddr: | ||
data := tx.Data() | ||
if len(data) <= 4 { |
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 use action.NewStakingActionFromABIBinary(tx.Data()) in #3095
api/coreservice.go
Outdated
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) { |
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.
payload
is not needed
api/grpcserver.go
Outdated
if err := tmpAct.LoadProto(in.GetTransfer()); err != nil { | ||
return nil, status.Error(codes.InvalidArgument, err.Error()) | ||
} | ||
act, payload = tmpAct, tmpAct.Payload() |
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.
estimatedGas, err = tmpAct.IntrinsicGas()
api/grpcserver.go
Outdated
if err := tmpAct.LoadProto(in.GetStakeCreate()); err != nil { | ||
return nil, status.Error(codes.InvalidArgument, err.Error()) | ||
} | ||
act, payload = tmpAct, tmpAct.Payload() |
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.
estimatedGas, err = tmpAct.IntrinsicGas()
api/grpcserver.go
Outdated
if err := tmpAct.LoadProto(in.GetStakeUnstake()); err != nil { | ||
return nil, status.Error(codes.InvalidArgument, err.Error()) | ||
} | ||
act, payload = tmpAct, tmpAct.Payload() |
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 for all places
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.
I would suggest we don't make this move, especially under the title "add EstimateGasForNonExecution in coreservice"
follows #3095