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

fix: wrong gas estimation due to invalid tx object #2377

Merged
merged 6 commits into from
Apr 22, 2024

Conversation

georgi-l95
Copy link
Collaborator

@georgi-l95 georgi-l95 commented Apr 19, 2024

Description:
This PR adds a formater which checks transaction object, if it complies with the mirror node validations. For example input and data fileds are the same, but mirror node accepts data field as the correct one.

For more context:
The official schema accepts both as correct - data and input field. Where some tools or EVM nodes use one and other use the other. We chose in the mirror node to use data field as the correct one, however for us to be able to support all tools, we have to modify transaction object, so that it complies with the mirror node. That means that, if input field is passed, but data is not, we have to copy one value to the other. For optimization purposes, we can rid of the input property or replace it with empty string.

Related issue(s):

Fixes #2375

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@georgi-l95 georgi-l95 self-assigned this Apr 19, 2024
@georgi-l95 georgi-l95 linked an issue Apr 19, 2024 that may be closed by this pull request
Copy link
Collaborator

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

Great find.
Some suggestions and we can move this forward

* If the transaction has an input property with a length greater than zero and does not have a data property,
* assign the value of transaction.input to transaction.data and remove the input property.
*/
if (transaction.input.length > 0 && !transaction.data) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great. I fyou can add a bit more info. If I recall correctly it's something around the execution apis changes the spec or some EVM clients use one field and others use the other.
I just want people to have context on why it could be either option

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've udpated the description of the PR. And for more info, before this fix, when we sent this to the mirror, it returns 0x, which is invalid and this is why we return 400k gas. The reason why it returns 0x, is because we initiate gas estimation for contract create, but our tx object does not have a data field.

packages/relay/src/lib/eth.ts Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Apr 19, 2024

Tests

    1 files    35 suites   3s ⏱️
194 tests 193 ✔️ 1 💤 0
197 runs  196 ✔️ 1 💤 0

Results for commit 0fbc7d5.

♻️ This comment has been updated with latest results.

Signed-off-by: georgi-l95 <[email protected]>

optimization

Signed-off-by: georgi-l95 <[email protected]>

chore: fix typo

Signed-off-by: georgi-l95 <[email protected]>

test: add unit test

Signed-off-by: georgi-l95 <[email protected]>

fix logic

Signed-off-by: georgi-l95 <[email protected]>

delete input if not used

Signed-off-by: georgi-l95 <[email protected]>
@georgi-l95 georgi-l95 force-pushed the 2375-issue-with-estimategas-api branch from 3925c53 to 2519825 Compare April 19, 2024 21:15
@georgi-l95 georgi-l95 requested a review from Nana-EC April 19, 2024 21:15
Copy link

github-actions bot commented Apr 22, 2024

Acceptance Tests

  15 files  197 suites   16m 32s ⏱️
581 tests 576 ✔️ 4 💤 1
615 runs  608 ✔️ 4 💤 3

Results for commit 0fbc7d5.

♻️ This comment has been updated with latest results.

victor-yanev
victor-yanev previously approved these changes Apr 22, 2024
Copy link
Contributor

@victor-yanev victor-yanev left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

LG assuming change isn't also needed for eth_call

quiet-node
quiet-node previously approved these changes Apr 22, 2024
Copy link
Member

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

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

LG 1 suggestion

@@ -79,6 +79,21 @@ const formatTransactionId = (transactionId: string): string | null => {
return `${payer}-${timestamp}`;
};

/**
* Formats a transaction object by moving input to data, if data is absent.
Copy link
Member

Choose a reason for hiding this comment

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

Would you consider adding an explanation for why such a transformation is necessary here? I mean the PR description explains it very well, and I think incorporating that explanation here in the codebase would make it a good reference for this method, and help developers to understand why it's important without looking into the PR to find the description.

Signed-off-by: georgi-l95 <[email protected]>
@georgi-l95 georgi-l95 dismissed stale reviews from quiet-node and victor-yanev via 5eeccdb April 22, 2024 15:16
Signed-off-by: georgi-l95 <[email protected]>
Signed-off-by: georgi-l95 <[email protected]>
Copy link
Member

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

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

LG but a couple of suggestions.

packages/relay/tests/lib/eth/eth_estimateGas.spec.ts Outdated Show resolved Hide resolved
// Support either data or input. https://ethereum.github.io/execution-apis/api-documentation/ lists input but many EVM tools still use data.
if (transaction.input && transaction.data === undefined) {
transaction.data = transaction.input;
delete transaction.input;
Copy link
Member

Choose a reason for hiding this comment

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

correct me if I'm wrong but I think we didn't have a unit test that makes sure the transaction.input's value is transferred to transaction.data, and transaction.input is deleted from the original txObject.

packages/server/tests/acceptance/rpc_batch2.spec.ts Outdated Show resolved Hide resolved
Signed-off-by: georgi-l95 <[email protected]>
Signed-off-by: georgi-l95 <[email protected]>
Copy link

sonarcloud bot commented Apr 22, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

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

LGTM! Great work!

@quiet-node quiet-node merged commit 24a1424 into main Apr 22, 2024
28 checks passed
@quiet-node quiet-node deleted the 2375-issue-with-estimategas-api branch April 22, 2024 21:39
AlfredoG87 pushed a commit that referenced this pull request Apr 22, 2024
* fix: wrong gas estimation due to invalid tx object

Signed-off-by: georgi-l95 <[email protected]>

optimization

Signed-off-by: georgi-l95 <[email protected]>

chore: fix typo

Signed-off-by: georgi-l95 <[email protected]>

test: add unit test

Signed-off-by: georgi-l95 <[email protected]>

fix logic

Signed-off-by: georgi-l95 <[email protected]>

delete input if not used

Signed-off-by: georgi-l95 <[email protected]>

* add simple fix

Signed-off-by: georgi-l95 <[email protected]>

* remove unused import

Signed-off-by: georgi-l95 <[email protected]>

* revert changes

Signed-off-by: georgi-l95 <[email protected]>

* fix acceptance tests

Signed-off-by: georgi-l95 <[email protected]>

* add unit tests

Signed-off-by: georgi-l95 <[email protected]>

---------

Signed-off-by: georgi-l95 <[email protected]>
Signed-off-by: Alfredo Gutierrez <[email protected]>
AlfredoG87 added a commit that referenced this pull request Apr 22, 2024
fix: wrong gas estimation due to invalid tx object (#2377)

* fix: wrong gas estimation due to invalid tx object



optimization



chore: fix typo



test: add unit test



fix logic



delete input if not used



* add simple fix



* remove unused import



* revert changes



* fix acceptance tests



* add unit tests



---------

Signed-off-by: georgi-l95 <[email protected]>
Signed-off-by: Alfredo Gutierrez <[email protected]>
Co-authored-by: Georgi Lazarov <[email protected]>
@AlfredoG87 AlfredoG87 added this to the 0.46.1 milestone Apr 23, 2024
AlfredoG87 pushed a commit that referenced this pull request Apr 23, 2024
* fix: wrong gas estimation due to invalid tx object

Signed-off-by: georgi-l95 <[email protected]>

optimization

Signed-off-by: georgi-l95 <[email protected]>

chore: fix typo

Signed-off-by: georgi-l95 <[email protected]>

test: add unit test

Signed-off-by: georgi-l95 <[email protected]>

fix logic

Signed-off-by: georgi-l95 <[email protected]>

delete input if not used

Signed-off-by: georgi-l95 <[email protected]>

* add simple fix

Signed-off-by: georgi-l95 <[email protected]>

* remove unused import

Signed-off-by: georgi-l95 <[email protected]>

* revert changes

Signed-off-by: georgi-l95 <[email protected]>

* fix acceptance tests

Signed-off-by: georgi-l95 <[email protected]>

* add unit tests

Signed-off-by: georgi-l95 <[email protected]>

---------

Signed-off-by: georgi-l95 <[email protected]>
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.

Issue with estimateGas api
5 participants