Skip to content

eth/catalyst: force sync of txpool before clearing subpools in Rollback #31228

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

Merged
merged 2 commits into from
Mar 27, 2025

Conversation

dahu33
Copy link
Contributor

@dahu33 dahu33 commented Feb 21, 2025

This PR enforces a transaction pool synchronization before clearing it in the (c *SimulatedBeacon) Rollback() function.

An alternative approach would be to modify (p *TxPool) Clear() to call (p *TxPool) Sync() directly before clearing, but this PR opts to perform the synchronization explicitly in Rollback().

Issue Description

In the example below, without the enforced sync, transactions from blocks between oldHead and newHead are unexpectedly included in the newly committed block, rendering the rollback ineffective.

simulatedBeacon.Fork(newHead)
simulatedBeacon.Rollback()
simulatedBeacon.Commit()

However, introducing a time.Sleep between Fork() and Rollback() produces the expected behavior, where transactions from intermediate blocks are correctly dropped, confirming the flakey behavior:

simulatedBeacon.Fork(newHead)
time.Sleep(1 * time.Second)
simulatedBeacon.Rollback()
simulatedBeacon.Commit()

@jwasinger
Copy link
Contributor

I think perhaps we could perform a Sync as the first thing within Clear, as it makes sense intuitively: Any in-limbo transactions should be removed by Clear. I have to think about this some more.

@jwasinger jwasinger self-assigned this Feb 21, 2025
@dahu33
Copy link
Contributor Author

dahu33 commented Feb 25, 2025

I think perhaps we could perform a Sync as the first thing within Clear, as it makes sense intuitively: Any in-limbo transactions should be removed by Clear. I have to think about this some more.

Agreed, updated the commit to reflect this.

@dahu33
Copy link
Contributor Author

dahu33 commented Mar 10, 2025

@jwasinger any update on this?

@jwasinger jwasinger changed the title eth/catalyst: ensure TX Pool sync before clearing in Rollback() eth/catalyst: force sync of txpool before clearing subpools in Rollback Mar 11, 2025
jwasinger
jwasinger previously approved these changes Mar 11, 2025
Copy link
Contributor

@jwasinger jwasinger left a comment

Choose a reason for hiding this comment

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

I thought that it might be more proper to make SubPool.Clear sync any pending transactions, instead of doing this behavior in the global pool. But it's not trivial to implement and I don't think it actually adds any value (the subpools themselves aren't exposed).

@dahu33
Copy link
Contributor Author

dahu33 commented Mar 11, 2025

Thanks for the review @jwasinger, committed your suggested change which reverted your approval.

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

SGTM

@jwasinger
Copy link
Contributor

lint failing. @dahu33 can you fix them? or enable contributor pushing to this branch and I can do it?

@dahu33
Copy link
Contributor Author

dahu33 commented Mar 13, 2025

lint failing. @dahu33 can you fix them? or enable contributor pushing to this branch and I can do it?

My bad. Should have achieved perfection now :)

@jwasinger jwasinger merged commit cc273ce into ethereum:master Mar 27, 2025
3 of 4 checks passed
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