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

feat: ethrpc: implement call, estimateGas, getTransactionCount #9306

Merged
merged 11 commits into from
Sep 28, 2022

Conversation

ychiaoli18
Copy link
Contributor

@ychiaoli18 ychiaoli18 commented Sep 14, 2022

Related Issues

ref-fvm #854

Proposed Changes

  • implement the following methods
    • eth_call
    • eth_estimateGas
    • eth_getTransactionCount
    • eth_protocolVersion
    • eth_maxPriorityFeePerGas
    • eth_gasPrice
    • eth_getTransactionReceipt

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

  • All commits have a clear commit message.
  • The PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, INTERFACE BREAKING CHANGE, CONSENSUS BREAKING, build, chore, ci, docs,perf, refactor, revert, style, test
    • area: api, chain, state, vm, data transfer, market, mempool, message, block production, multisig, networking, paychan, proving, sealing, wallet, deps
  • This PR has tests for new functionality or change in behaviour
  • If new user-facing features are introduced, clear usage guidelines and / or documentation updates should be included in https://lotus.filecoin.io or Discussion Tutorials.
  • CI is green

@ychiaoli18 ychiaoli18 requested a review from a team as a code owner September 14, 2022 03:01
@ychiaoli18 ychiaoli18 requested review from raulk and removed request for a team September 14, 2022 03:01
@ychiaoli18 ychiaoli18 marked this pull request as draft September 14, 2022 03:36
@ychiaoli18 ychiaoli18 closed this Sep 14, 2022
@ychiaoli18 ychiaoli18 deleted the kevin/feat/eth_call branch September 14, 2022 03:37
@ychiaoli18 ychiaoli18 reopened this Sep 14, 2022
@ychiaoli18
Copy link
Contributor Author

ychiaoli18 commented Sep 14, 2022

I’m a little concerned that the gas estimation result is slightly different from lotus chain invoke-evm-actor.
Testing contract: SimpleCoin
Method: getBalance
Testing command: lotus chain invoke-evm-actor t01002 f8b2cb4f0000000000000000000000000000000064

  1. lotus chain invoke-evm-actor: 3670765
  2. call GasEstimateGasLimit in the context of executing lotus chain invoke-evm-actor: 3665565
  3. call GasEstimateGasLimit or my implementation (EthModule.applyEvmMsg) in the context of eth_estimateGas: 3603165

It seems to me that the difference is the execution context (e.g. the state of stmgr). @raulk any idea about this?

@ychiaoli18 ychiaoli18 marked this pull request as ready for review September 15, 2022 01:04
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

I have no idea what's causing the gas difference, but the code looks correct (I have some nits, but they're really not important.

Comment on lines 185 to 189
receipt := api.NewEthTxReceipt(tx)
err = receipt.PopulateReceipt(msgLookup, replay)
if err != nil {
return api.EthTxReceipt{}, err
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: splitting these into two methods doesn't really seem necessary.

api/eth_types.go Outdated
func CheckContractCreation(lookup *MsgLookup) (*EthAddress, error) {
var result init8.ExecReturn
ret := bytes.NewReader(lookup.Receipt.Return)
if err := result.UnmarshalCBOR(ret); lookup.Receipt.ExitCode.IsSuccess() && err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we check IsSuccess first (no need to decode?)?

BlockNumber EthInt `json:"blockNumber"`
TransactionIndex EthInt `json:"transacionIndex"`
From EthAddress `json:"from"`
To *EthAddress `json:"to"`
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a pointer? I believe that from is optional because the node would use its default account in that case, but didn't know that to can be optional?

Copy link
Contributor Author

@ychiaoli18 ychiaoli18 Sep 27, 2022

Choose a reason for hiding this comment

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

@raulk to should be optional, because if the tx creates a contract, ethereum's behavior is to return "to": null for both the tx and the tx receipt

Copy link
Member

Choose a reason for hiding this comment

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

Ah, true, I had forgotten about that edge case.

var result init8.ExecReturn
ret := bytes.NewReader(lookup.Receipt.Return)
if err := result.UnmarshalCBOR(ret); err == nil {
contractAddr, err := EthAddressFromFilecoinIDAddress(result.IDAddress)
Copy link
Member

@raulk raulk Sep 27, 2022

Choose a reason for hiding this comment

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

nit (can save for a future PR): should probably return a specific error message instead of letting it fall through to the "not a contract creation tx" error.

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