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(consensus): correct TxEip1559.encode_with_signature #232

Closed
wants to merge 2 commits into from

Conversation

vbrvk
Copy link

@vbrvk vbrvk commented Feb 23, 2024

Motivation

Fixing TxEip1559 encoding, before fix node reply with "error code -32602: Failed to decode transaction" error

Solution

The tx type byte was missing in encode_with_signature.encode_with_signature method

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Contributor

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

To produce a valid tx you need to encode the tx using a TxEnvelope, which will produce an EIP-2718 compliant tx and add the type byte which was missing. Same for decoding—you're expected to use the envelope (see tests).

@vbrvk
Copy link
Author

vbrvk commented Feb 23, 2024

How can it be used over abstract Transaction trait?

I have next method, how can i use TxEnvelope there?

    pub async fn sign_tx<T: Transaction<Signature = Signature>>(&self, mut tx: T) -> Result<Bytes> {
        let signature = self.local.sign_transaction(&mut tx).await?;

        dbg!(hex::encode(&signature.as_bytes()));
        let signed = TxEnvelope::from(tx.into_signed(signature));
        Ok(signed.into())
    }

Maybe it possible to add

const fn tx_type(&self) -> TxType

method to Transaction trait, so TxEnvelope can be created from any transaction?

@Evalir
Copy link
Contributor

Evalir commented Feb 23, 2024

This is a good question—we're working on streamlining the flow from a TransactionRequest -> signing and converting to a TxEnvelope so it's easy to send transactions over the network with a provider, here: #190 . Right now this flow is not very well polished and it's probably why you found this issue.

The method you posted looks fine—as long as you encode the tx using a tx envelope then this should be working.

@vbrvk vbrvk closed this Feb 23, 2024
@vbrvk vbrvk deleted the fix/eip1559_signing branch February 23, 2024 16:07
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.

2 participants