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

Correctly encode non-legacy mempool transactions #415

Merged
merged 2 commits into from
Aug 31, 2021

Conversation

onbjerg
Copy link
Collaborator

@onbjerg onbjerg commented Aug 29, 2021

Motivation

If a non-legacy transaction was fetched from the mempool and then RLP-encoded for inclusion in e.g. a flashbots bundle, then the bundle would fail because the encoding only worked for legacy transactions. See onbjerg/ethers-flashbots#11 (comment)

Solution

RLP encode Transaction response types based on their transaction_type. I'm not super confident about this piece of code since it is a lot of duplicate logic from other files, but I'm not super well known in the codebase yet so I'm not sure what the best way is to improve it. Please let me know if you have any suggestions!

If a non-legacy transaction was fetched from the mempool and
then RLP-encoded for inclusion in e.g. a flashbots bundle,
then the bundle would fail because the encoding only worked
for legacy transactions.
@avocadochicken
Copy link

Not working yet. Please take code from here:
onbjerg/ethers-flashbots#11 (comment)

@onbjerg might do a PR soon.

@onbjerg
Copy link
Collaborator Author

onbjerg commented Aug 31, 2021

Not working yet. Please take code from here:
onbjerg/ethers-flashbots#11 (comment)

@onbjerg might do a PR soon.

Yeah, I have some tests locally and some fixes too, but I want to add one more before pushing. Thanks for the PR on my fork, I'll take a look today :)

@onbjerg
Copy link
Collaborator Author

onbjerg commented Aug 31, 2021

Should be good to go @gakonst

encoded.extend_from_slice(rlp_bytes.as_ref());
encoded.into()
}
_ => rlp_bytes,
Copy link
Owner

Choose a reason for hiding this comment

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

WDYT about matching Some(x) if x == U64::from(0) and encoding with the 0x0 prefix, and default to rlp_bytes only when self.transaction_type is not present OR if the legacy feature is turned on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

NVM. You are right, forgot that we skip it for legacy txs:

Legacy(ref tx) => {
encoded.extend_from_slice(tx.rlp_signed(signature).as_ref());
}

@gakonst gakonst merged commit a1f2600 into gakonst:master Aug 31, 2021
@onbjerg onbjerg deleted the transaction-rlp-encoding branch August 31, 2021 10:43
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