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(l1): add temporary fix to transaction filtering & handle tx filtering unwrap edge case #1018

Merged
merged 12 commits into from
Oct 31, 2024

Conversation

ilitteri
Copy link
Contributor

@ilitteri ilitteri commented Oct 30, 2024

Motivation

To avoid panicking when the transaction filter fails to filter a transaction because we do not yet filter transactions with invalid tip.

Description

  • Filter transactions whose effective gas tip calculation underflowed.
  • Handle the unwrap of the effective_gas_tip calculation. Even though this is an edge case that shouldn't happen, it is better to have a descriptive error if it happens someday than to panic.

@ilitteri ilitteri self-assigned this Oct 30, 2024
@ilitteri ilitteri requested a review from a team as a code owner October 30, 2024 14:59
Copy link
Collaborator

@rodrigo-o rodrigo-o left a comment

Choose a reason for hiding this comment

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

LGTM (small np comment that could be ignored)

crates/blockchain/mempool.rs Outdated Show resolved Hide resolved
@ilitteri ilitteri changed the title fix(l1): effective_gas_tip computation fix(l1): add temporary fix to transaction filtering & handle tx filtering unwrap edge case Oct 30, 2024
Comment on lines 83 to 88
// This is a temporary fix to avoid invalid transactions to be included.
// This should be removed once https://github.com/lambdaclass/ethereum_rust/issues/680
// is addressed.
if tx.effective_gas_tip(filter.base_fee).is_none() {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could add this check on the else block of the min_tip check, that way we can leave the check even when the issue is fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But, this should be an else if right? We still need to know if effective_gas_tip returned None, or am I missing something?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As I understood it, yes, we still need to check for the None of effective_gas_tip even in the else of let Some(min_tip) = filter.min_tip

Copy link
Contributor

Choose a reason for hiding this comment

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

What I mean is that with this change we have:

check effective fee != None
  if min_tip:
      check effective fee != None && > min_tip

When we could have:

if min_tip:
   check effective fee != None && > min_tip
else:
   check effective fee != None

That way we only compute the effective fee once in any case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 62e4d9c

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>
#[error(
"Attempted to add an invalid transaction to the block. The transaction filter must have failed."
)]
AttemptedToAddInvalidTransaction,
Copy link
Collaborator

Choose a reason for hiding this comment

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

the error is a bit long. Why not just InvalidTransaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a problem, renaming it asap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 6f3a2fb

Generalize the error to InvalidTransaction which can be raised with additional context.
@ilitteri ilitteri added this pull request to the merge queue Oct 31, 2024
Merged via the queue into main with commit 27159b9 Oct 31, 2024
11 checks passed
@ilitteri ilitteri deleted the fix_effective_gas_tip branch October 31, 2024 15:59
github-merge-queue bot pushed a commit that referenced this pull request Oct 31, 2024
**Motivation**

Have the tx spammer running instead of immediatly shutting down when we
are the first node in the devnet setup.

**Description**

This PR tackled a couple of issues until we were able to process an
initial transaction, (they are small changes):
- We were returning an error on `eth_getTransactionCount` when we either
didn't have a `latest` block before genesis or at any point when we
don't have `pending` blocks. The solution in this case was returning
`0x0` in those cases.
- When requesting `eth_getTransactionCount` on `pending` after some
transaction went through we were defaulting to `0x0`, it appears that
the idea is to default to the `latest` in those case which make sense.
- There were a missing filter that made the node panic when building
payloads for transactions with fees lower than the base_fee_per_gas,
this generated that those kind of transactions stopped the node's
ability to build blocks when they were in the mempool, we made a quick
workaround in this PR, but will remove it in favor of #1018

Closes #1026
h3lio5 pushed a commit to h3lio5/lambda_ethereum_rust that referenced this pull request Oct 31, 2024
…ring unwrap edge case (lambdaclass#1018)

**Motivation**

<!-- Why does this pull request exist? What are its goals? -->

To avoid panicking when the transaction filter fails to filter a
transaction because we do not yet filter transactions with invalid tip.

**Description**

- Filter transactions whose effective gas tip calculation underflowed.
- Handle the unwrap of the `effective_gas_tip` calculation. Even though
this is an edge case that shouldn't happen, it is better to have a
descriptive error if it happens someday than to panic.

---------

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>
h3lio5 pushed a commit to h3lio5/lambda_ethereum_rust that referenced this pull request Oct 31, 2024
**Motivation**

Have the tx spammer running instead of immediatly shutting down when we
are the first node in the devnet setup.

**Description**

This PR tackled a couple of issues until we were able to process an
initial transaction, (they are small changes):
- We were returning an error on `eth_getTransactionCount` when we either
didn't have a `latest` block before genesis or at any point when we
don't have `pending` blocks. The solution in this case was returning
`0x0` in those cases.
- When requesting `eth_getTransactionCount` on `pending` after some
transaction went through we were defaulting to `0x0`, it appears that
the idea is to default to the `latest` in those case which make sense.
- There were a missing filter that made the node panic when building
payloads for transactions with fees lower than the base_fee_per_gas,
this generated that those kind of transactions stopped the node's
ability to build blocks when they were in the mempool, we made a quick
workaround in this PR, but will remove it in favor of lambdaclass#1018

Closes lambdaclass#1026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants