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(core): prevent chain_id from serializing for requests #879

Merged
merged 2 commits into from Feb 8, 2022

Conversation

Rjected
Copy link
Contributor

@Rjected Rjected commented Feb 7, 2022

Motivation

OpenEthereum seems to not have a chainId field in its TransactionRequest type.

Solution

This PR disables serialization for the chain_id, so we don't send it in RPC requests.

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

Fixes #877

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

hmm, this is a bit tricky, because I'm not sure what side-effects this could potentially cause, what does? since this is a client issue for openethereum
I believe in geth chainid is omitempty, so this approach seems fine. But not sure if there is some kind of check that chainids match so that tx intended for chain X are rejected on chain Y? so we'd lose that

alternatives:

  • should we skip this instead based on the chainid?
  • should we rather take the chain id if the client is OE, I believe we already have some calls that check the client first, definitely more effort, not ideal.

@Rjected
Copy link
Contributor Author

Rjected commented Feb 8, 2022

Since chain_id was recently introduced to our request types, we shouldn't really be introducing any new issues by not serializing.

I'm not sure that alternative 1 (skip based on the chainid), or any solution that depends on only the chainid would work since OE will not accept any chainId field. Geth does have omitempty for the chainId, but it would be up to us to ensure that the chain_id field matches that of the client when running send_transaction, sign_transaction, etc. This would probably prevent user error.

This would not be necessary for send_raw_transaction, since that depends on RLP, which should already include the chainid. Geth does check the chainId, so if we were to do chainId checks there it would be in case other clients don't do these checks.

@mattsse
Copy link
Collaborator

mattsse commented Feb 8, 2022

thanks, sgtm!

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

smol nit

@@ -42,7 +42,8 @@ pub struct TransactionRequest {
pub nonce: Option<U256>,

/// Chain ID (None for mainnet)
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing)]
#[serde(rename = "chainId")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#[serde(rename = "chainId")]
#[serde(default, rename = "chainId")]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added to both request and 1559 request

@gakonst gakonst merged commit ce0396e into gakonst:master Feb 8, 2022
@tarrencev
Copy link
Contributor

@Rjected I'm still running into this issue after updating foundry to use this PR

(code: -32602, message: Invalid params: unknown field `chainId`, expected one of `type`, `from`, `to`, `gasPrice`, `maxFeePerGas`, `gas`, `value`, `data`, `nonce`, `accessList`, `maxPriorityFeePerGas`., data: None)

It looks like it is still serialized into the txn \"chainId\":\"0x2a\"

@gakonst
Copy link
Owner

gakonst commented Feb 9, 2022

@Rjected maybe let's add a serialization test which ensures that neither txs have chainId in the serialized form?

@tarrencev
Copy link
Contributor

tarrencev commented Feb 9, 2022

@Rjected @gakonst Ah nevermind. I sanity checked forge paths and it was using an old path under .cargo rather than the one in .foundry

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.

unknown field chainId when trying to deploy contract with forge
4 participants