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

eth_estimateGas CIP-64 and CIP-66 compatibility #91

Merged
merged 6 commits into from
May 15, 2024
Merged

Conversation

ezdac
Copy link

@ezdac ezdac commented Apr 10, 2024

What was the issue?

This fixes wrong gas calculation in eth_estimateGas calls, when the additional feeCurrency parameter is used.

The TransactionArgs struct is used in transaction related endpoints like eth_sendTransaction, eth_signTransaction, eth_estimateGas and many more.

CIP-64 and CIP-66 transaction types make use of an additional transaction parameter feeCurrency and some client libraries are already sending this in the RPC request body, however the remote procedures omitted this during unmarshalling and the value was never passed to the EVM.

Additionally, the TransactionArgs to EVM Message conversion was not compatible with fee-currency conversion yet (see #109) and currency-conversion of internal checks against e.g. the base-fee were missing. Similarly, the binary-search-like gas-estimation algorithm did not consider the fee currency conversion during determining upper-bounds of the search-space.

What this PR implements

  • A new ethapi.Backend wrapper ethapi.CeloBackend is implemented that extends the original with some Celo-specific methods. The initial implementation (celoapi.Backend) of this wrapped backend has a LRU cache for exchange rates. It is now passed to some RPC services instead of the unwrapped backend.
  • Now the TransactionArgs struct includes an optional FeeCurrency field for correct unmarshalling, and the field is passed along downstream when constructing EVM messages out of the struct.
    This e.g. allows gas estimation to consider the different intrinsic gas for transactions paid in non-native token.
  • The TransactionArgs are used in some RPC methods where most fields can be omitted by the method-caller so that the method-server fills in sane default values (see Ensure TransactionArgs works with cip-64 and cip-66 #109 (comment)) - in this PR this is not implemented for CIP-66 transactions' MaxFeeInFeeCurrency and this field is thus required in order to be converted internally to a CIP-66 transaction
  • The binary search algorithm in DoEstimate now simulates CIP-64/66 transactions once without any gas-payment deduction, in order to determine the available fee-currency balance for capping the search-space. This is analogous to the EIP1559/legacy transactions, but since the transactions fee-currency "value" isn't encoded directly as a transaction field (Value), the full transaction has to be simulated to observe the fee currencies' contract state after applying the transaction.

@ezdac ezdac force-pushed the ezdac/fix-estimate-gas branch from 8ce472c to 38f8f25 Compare April 10, 2024 15:36
@ezdac ezdac marked this pull request as draft April 10, 2024 15:56
@ezdac ezdac force-pushed the ezdac/fix-estimate-gas branch from 38f8f25 to d8eb5a6 Compare April 17, 2024 10:18
@ezdac ezdac force-pushed the ezdac/fix-estimate-gas branch 6 times, most recently from d33f580 to 8a7081a Compare May 2, 2024 09:45
@ezdac ezdac changed the title rpc: include feeCurrency in transaction-args eth_estimateGas CIP-64 and CIP-66 compatibility May 2, 2024
Copy link
Author

Choose a reason for hiding this comment

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

The diff here looks a bit confusing - basically I just moved the CeloAPI from the celoapi/backend.go to the celoapi/api.go file, and then added the new CeloBackend implementation in the celoapi/backend.go file.

@ezdac ezdac force-pushed the ezdac/fix-estimate-gas branch from 8a7081a to 2833a73 Compare May 2, 2024 13:13
This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.
@ezdac ezdac force-pushed the ezdac/fix-estimate-gas branch from 2833a73 to 545e43e Compare May 2, 2024 13:15
@ezdac ezdac marked this pull request as ready for review May 2, 2024 13:34
@ezdac ezdac requested a review from karlb May 13, 2024 09:06
e2e_test/js-tests/package-lock.json Outdated Show resolved Hide resolved
internal/celoapi/backend.go Outdated Show resolved Hide resolved
internal/celoapi/backend.go Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
internal/ethapi/backend.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
@karlb karlb mentioned this pull request May 14, 2024
@ezdac ezdac force-pushed the ezdac/fix-estimate-gas branch from dc37292 to 947fc1c Compare May 14, 2024 15:45
Copy link

@karlb karlb left a comment

Choose a reason for hiding this comment

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

Only nitpicking left. Feel free to change or merge right away.

internal/celoapi/backend.go Outdated Show resolved Hide resolved
internal/celoapi/backend.go Outdated Show resolved Hide resolved
@ezdac ezdac merged commit 378073a into celo4 May 15, 2024
6 checks passed
@ezdac ezdac deleted the ezdac/fix-estimate-gas branch May 15, 2024 09:17
karlb pushed a commit that referenced this pull request May 15, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb pushed a commit that referenced this pull request May 15, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb pushed a commit that referenced this pull request May 15, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
palango pushed a commit that referenced this pull request May 31, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
carterqw2 pushed a commit that referenced this pull request Jun 11, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb pushed a commit that referenced this pull request Jul 10, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb pushed a commit that referenced this pull request Jul 10, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb pushed a commit that referenced this pull request Jul 12, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb pushed a commit that referenced this pull request Aug 20, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb pushed a commit that referenced this pull request Aug 26, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb pushed a commit that referenced this pull request Aug 30, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb pushed a commit that referenced this pull request Oct 11, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb added a commit that referenced this pull request Dec 13, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb added a commit that referenced this pull request Dec 16, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
karlb added a commit that referenced this pull request Dec 17, 2024
* rpc: include feeCurrency in transaction-args

This commit fixes wrong gas calculation in `eth_estimateGas` calls,
when the additional `feeCurrency` parameter is used.

The TransactionArgs struct is used in transaction related endpoints like
`eth_sendTransaction`, `eth_signTransaction`, `eth_estimateGas` and many
more.

CIP-64 and CIP-66 transaction types make use of an additional transaction
parameter `feeCurrency` and some client libraries are already sending
this in the RPC request body, however the remote procedures omitted
this during unmarshaling and the value was never passed to the EVM.

Now the TransactionArgs struct includes an optional FeeCurrency field
for correct unmarshaling, and the field is passed along downstream
when constructing EVM messages out of the struct.
This e.g. allows gas estimation to consider the different intrinsic
gas for transactions paid in non-native token.

* Rename celoapi file

* Add Backend wrapper for Celo functionality

* Make transaction-args CIP-64/66 compatible

* Make eth_estimateGas CIP64 and CIP66 compatible

* Move error message inside function
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.

2 participants