-
Notifications
You must be signed in to change notification settings - Fork 438
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
Refactor TransactionForRpc
#7446
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Expose test values and `ValidateSchema`
- Forgot to change the name
- Follows https://github.com/ethereum-optimism/op-geth fields and tests
- Replaces old `AccessListItemForRpc` with proper container
- A lot of questions/unknowns/design decisions
- Mimics `JsonConverter<T>` from `System.Text.Json`
- There is no longer "roundtrip"
- Not specific to RPC
- Includes global converter
- We throw either way
- Use `RpcNethermindTransaction` directly - Avoid additonal indirection - Have always known fields available
emlautarom1
requested review from
benaadams,
tanishqjasoria,
LukaszRozmej and
jmederosalvarado
September 16, 2024 20:58
16 tasks
We'll move forward with the alternative design (#7483) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partially solves #7313
Changes
TransactionForRpc
RpcGenericTransaction
only for deserializing RPC transactions.RpcNethermindTransaction
and individual transaction types (Legacy
,AccessList
,EIP1559
,Blob
andDeposit
), with support for extension.Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?
Notes on testing
Documentation
Requires documentation update
Requires explanation in Release Notes
Remarks
Unfortunately a very long PR due to the introduction of several changes. Currently, we have a single class used for both serialization and deserialization:
nethermind/src/Nethermind/Nethermind.Facade/Eth/TransactionForRpc.cs
Line 16 in c6a768d
This class does everything, from JSON (de)serializing based on reflection, to conversion from/to our main
Transaction
type. This is cumbersome and makes extending the possible transaction types very brittle (see https://github.com/NethermindEth/nethermind/blob/c6a768d2f2f80fe09f2e711d502e0c8347bd9e02/src/Nethermind/Nethermind.Optimism/Rpc/OptimismTransactionForRpc.cs).This PR separates these responsibilities:
When deserializing:
RpcGenericTransaction
, based on the Ethereum JSON-RPC spec, specifically https://github.com/ethereum/execution-apis/blob/1d4f70e84191bb574286fd7cea6c48795bf73e78/src/schemas/transaction.yaml#L358Converter
s that know how to take thisRpcGenericTransaction
and build aTransaction
, defaulting when appropriate (ex. if the transaction isAccessList
, then the resultingAccessList
field inTransaction
is an empty access list, notnull
). We use the same approach of a registry that contains converters mapped to transaction types (TxType
).When serializing
Converter
s that know how to take aTransaction
and build aRpcNethermindTransaction
, which is a base class for all JSON-RPC Transaction types. We enrich this type with some Nethermind specific data not included in the spec (ex. transaction hash). Each converter knows how to take a Transaction with a specificTxType
and build a subclass (ex. there is a converter fromTransaction
toRpcBlobTransaction
). Each converter is again based on the Ethereum JSON-RPC spec to ensure no fields are missing. Again, we use the same registry approach.RpcNethermindTransaction
but, for example,RpcEIP1559Transaction
.The main difference with the original design is the separation of input from output Transactions. Initially I tried to use the same classes for both (ex. (de)serialize
RpcLegacyTransaction
just using theTxType
value) but this quickly becomes a mess since input fields might be optional but required when serializing and we have two defaulting mechanism, C# and Ethereum (ex.Address? SenderAddress
defaults tonull
by the type system, but we might want to default it to a different value likeAddress.SystemUser
).Lastly, this PR is in draft and suggestions are welcome.