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 trace error in Polygon | Pass Engin to the Base API #6131

Merged
merged 4 commits into from
Dec 4, 2022

Conversation

ngotchac
Copy link
Contributor

So there is an issue with tracing certain blocks/transactions on Polygon, for example:

> '{"method": "trace_transaction","params":["0xb198d93f640343a98f90d93aa2b74b4fc5c64f3a649f1608d2bfd1004f9dee0e"],"id":1,"jsonrpc":"2.0"}'

gives the error first run for txIndex 1 error: insufficient funds for gas * price + value: address 0x10AD27A96CDBffC90ab3b83bF695911426A69f5E have 16927727762862809 want 17594166808296934

The reason is that this transaction is from the author of the block, which doesn't have enough ETH to pay for the gas fee + tx value if he's not the block author receiving transactions fees.

The issue is that currently the APIs are using ethash.NewFaker() Engine for running traces, etc. which doesn't know how to get the author for a specific block (which is consensus dependant); as it was noting in several TODO comments.

The fix is to pass the Engine to the BaseAPI, which can then be used to create the right Block Context. I chose to split the current Engine interface in 2, with Reader and Writer, so that the BaseAPI only receives the Reader one, which might be safer (even though it's only used for getting the block Author).

Comment on lines +31 to +33
// TODO: Replace with correct consensus Engine
engine := ethash.NewFaker()
apiList := commands.APIList(db, borDb, backend, txPool, mining, ff, stateCache, blockReader, agg, *cfg, engine)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would need to be modified in theory, but I wasn't quite sure whether it was worth the extra work (we need extra arguments about Heimdall RPC for Polygon, etc.)

Copy link
Collaborator

@AskAlexSharov AskAlexSharov left a comment

Choose a reason for hiding this comment

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

  • Any proofs that all current engines are thread-safe?
  • if you need only limited amount of methods - lets use smaller interface

@ngotchac
Copy link
Contributor Author

  • Any proofs that all current engines are thread-safe?
  • if you need only limited amount of methods - lets use smaller interface

I looked a bit at some of the consensus and saw some locks, so I thought it was safe. Looking a bit more carefully, it wasn't actually always the case. Thus, I reduced the EngineReader interface, added comments to explicit why the methods are safe, and added a RWLock in Aura to make IsServiceTransaction thread safe

@AskAlexSharov
Copy link
Collaborator

@ngotchac merge devel plz

@ngotchac ngotchac force-pushed the ngotchac/api-pass-engine branch from fd54538 to 898f8f1 Compare November 30, 2022 07:55
@ngotchac
Copy link
Contributor Author

@ngotchac merge devel plz

Done!

@AskAlexSharov AskAlexSharov merged commit 961a007 into erigontech:devel Dec 4, 2022
@ngotchac ngotchac deleted the ngotchac/api-pass-engine branch December 5, 2022 09:26
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