Skip to content

core: reduce load on txindexer from API #31752

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 14 commits into from
May 5, 2025

Conversation

s1na
Copy link
Contributor

@s1na s1na commented May 1, 2025

Context

Fixes #31732.

This logic was removed in the recent refactoring in the txindexer to handle history cutoff (#31393). It was first introduced in this PR: #28908.

I have tested it and it works as an alternative to #31745.

Content

This PR packs 3 changes to the flow of fetching txes from the API:

  • It caches the indexer tail after each run is over to avoid hitting the db all the time as was done originally in core: cache transaction indexing tail in memory #28908.
  • It propagates the API context to the indexer and handles cancellation. This is to allow goroutines to be cleaned up when a request times out.
  • Changes backend.GetTransaction. It doesn't return an error anymore when tx indexer is in progress. It shifts the responsibility to the caller to check the progress. The reason is that in most cases we anyway check the txpool for the tx. If it was indeed a pending tx we can avoid the indexer progress check.

@s1na s1na requested a review from rjl493456442 as a code owner May 1, 2025 12:59
@s1na s1na requested review from fjl and lightclient as code owners May 1, 2025 13:47
@s1na s1na changed the title core: cache last tail in txindexer for progress report core: reduce load on txindexer from API May 2, 2025
rjl493456442
rjl493456442 previously approved these changes May 2, 2025
@rjl493456442
Copy link
Member

The error handling for whether the transaction indexer is running is much improved compared to before.

SGTM!

@rjl493456442 rjl493456442 added this to the 1.15.11 milestone May 2, 2025
@s1na
Copy link
Contributor Author

s1na commented May 2, 2025

Tested the PR on my node. It's fast!

@s1na s1na mentioned this pull request May 2, 2025
rjl493456442
rjl493456442 previously approved these changes May 4, 2025
@s1na
Copy link
Contributor Author

s1na commented May 4, 2025

With the latest changes. Still apart from some spikes goroutine under control. So IMO it's good to go.

Screenshot 2025-05-04 at 15 06 39

I did notice some blocks taking very long in the logs when the script from #31732 (comment) is running as the node is being hammered with requests. So I can imagine why engine API requests might time out if the OP's node is not as powerful.

INFO [05-04|13:01:35.218] Imported new potential chain segment     number=22,410,559 hash=d134fa..c732a1 blocks=1 txs=187 mgas=35.981 elapsed=8.266s      mgasps=4.353   snapdiffs=7.08MiB triediffs=228.70MiB triedirty=157.61MiB

INFO [05-04|13:06:30.010] Imported new potential chain segment     number=22,410,584 hash=68e4d8..aa6140 blocks=1 txs=180 mgas=34.197 elapsed=4.928s       mgasps=6.938   snapdiffs=8.21MiB triediffs=229.50MiB triedirty=170.21MiB

@rjl493456442 rjl493456442 merged commit 615d29f into ethereum:master May 5, 2025
3 of 4 checks passed
0g-wh pushed a commit to 0g-wh/0g-geth that referenced this pull request May 8, 2025
Fixes ethereum#31732.

This logic was removed in the recent refactoring in the txindexer to
handle history cutoff (ethereum#31393). It was first introduced in this PR:
ethereum#28908.

I have tested it and it works as an alternative to ethereum#31745.

This PR packs 3 changes to the flow of fetching txs from the API:

- It caches the indexer tail after each run is over to avoid hitting the
db all the time as was done originally in ethereum#28908.

- Changes `backend.GetTransaction`. It doesn't return an error anymore
when tx indexer is in progress. It shifts the responsibility to the
caller to check the progress. The reason is that in most cases we anyway
check the txpool for the tx. If it was indeed a pending tx we can avoid
the indexer progress check.

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node stuck / indexer stuck / goroutine leak
2 participants