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

feat: remove txs which do not end up in a block out of the mempool #15

Merged
merged 4 commits into from
May 15, 2024

Conversation

bharath-123
Copy link
Contributor

@bharath-123 bharath-123 commented May 9, 2024

When the txs we receive from ExecuteBlocks call fail to end up in a block, we keep them lying around the geth mempool but clear it from the astria mempool.
This PR attempts to remove such txs from the geth mempool.

@@ -190,7 +187,7 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
noTxs: false,
}
start := time.Now()
full := w.getSealingBlock(emptyParams)
full := w.getSealingBlock(fullParams)
Copy link
Contributor Author

@bharath-123 bharath-123 May 9, 2024

Choose a reason for hiding this comment

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

In vanilla geth, an empty block is created and then a full block is created. This is mainly to spend more time to optimize for gas fees and also to return at least an empty block if we were not able to create a full block on time.
We don't need this astria since we just blindly use the txs received from ExecuteBlock. so fullParams makes more sense than emptyParams over here.

@bharath-123 bharath-123 force-pushed the bharath/remove-invalid-txs branch 2 times, most recently from c8f6554 to ad9cced Compare May 9, 2024 14:34
@bharath-123 bharath-123 closed this May 9, 2024
@bharath-123 bharath-123 reopened this May 9, 2024
@bharath-123 bharath-123 marked this pull request as ready for review May 9, 2024 15:08
@jbowen93
Copy link
Member

jbowen93 commented May 9, 2024

We’ve had previous discussions about the management of txs between the geth/rollup mempool and the Astria sequencer mempool.

Is the focus of this PR to remove transactions which were paid to be included in Astria but didn’t get executed in geth because we ran into the execution gas limit?

miner/worker.go Outdated
@@ -855,6 +857,10 @@ func (w *worker) commitAstriaTransactions(env *environment, txs *types.Transacti
// nonce-too-high clause will prevent us from executing in vain).
log.Debug("Transaction failed, account skipped", "hash", tx.Hash(), "err", err)
}
if err != nil {
log.Trace("Marking transaction as invalid", "hash", tx.Hash(), "err", err)
w.eth.TxPool().UpdateAstriaInvalid(tx)
Copy link
Contributor Author

@bharath-123 bharath-123 May 9, 2024

Choose a reason for hiding this comment

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

should we also remove if a tx is skipped because of a high nonce or low nonce? or only because it exceeded the gas limit?

Copy link
Contributor Author

@bharath-123 bharath-123 May 10, 2024

Choose a reason for hiding this comment

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

We ideally should to maintain 1:1 block determinism. So we should include all of these cases.

func (p *BlobPool) SetAstriaOrdered(types.Transactions) {}
func (p *BlobPool) ClearAstriaOrdered() {}
func (p *BlobPool) UpdateAstriaExcludedFromBlock(*types.Transaction) {}
func (p *BlobPool) AstriaExcludedFromBlock() *types.Transactions { return &types.Transactions{} }
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this public function is added solely for test purposes? Is there another way to manage that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

don't think there is, we can't attribute functions with a #cfg[test] like how we do in rust :( , we need to do hacks like https://github.com/golang/go/blob/master/src/reflect/export_test.go

There are some cases in the Geth codebase where they have written public functions only for testing like this one:

func (payload *Payload) ResolveEmpty() *engine.ExecutionPayloadEnvelope {

func (p *BlobPool) AstriaOrdered() *types.Transactions { return &types.Transactions{} }
func (p *BlobPool) SetAstriaOrdered(types.Transactions) {}
func (p *BlobPool) ClearAstriaOrdered() {}
func (p *BlobPool) UpdateAstriaExcludedFromBlock(*types.Transaction) {}
Copy link
Member

Choose a reason for hiding this comment

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

nit on naming... perhaps NewAstriaOrderedExcludedTx? naming here is always going to be awkward as it's actually a method on a subtype, its semantically kinda wrong.

Not for this PR, but the adding stuff to the mempool has always felt a bit awkward. Might makes more sense to add payload argument or something, or even create a new subpool.

@bharath-123
Copy link
Contributor Author

Merging this to rebase on top of the PR to fix tests

@bharath-123 bharath-123 merged commit 1a9b491 into main May 15, 2024
1 check passed
@bharath-123 bharath-123 deleted the bharath/remove-invalid-txs branch May 15, 2024 17:00
bharath-123 added a commit that referenced this pull request May 29, 2024
When the txs we receive from `ExecuteBlocks` call fail to end up in a
block, we keep them lying around the geth mempool but clear it from the
astria mempool.
This PR attempts to remove such txs from the geth mempool.
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