Refactor TransactionForRpc#7446
Closed
emlautarom1 wants to merge 78 commits into
Closed
Conversation
- 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
16 tasks
Contributor
Author
|
We'll move forward with the alternative design (#7483) |
This file contains hidden or 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
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
TransactionForRpcRpcGenericTransactiononly for deserializing RPC transactions.RpcNethermindTransactionand individual transaction types (Legacy,AccessList,EIP1559,BlobandDeposit), 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
Transactiontype. 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#L358Converters that know how to take thisRpcGenericTransactionand build aTransaction, defaulting when appropriate (ex. if the transaction isAccessList, then the resultingAccessListfield inTransactionis an empty access list, notnull). We use the same approach of a registry that contains converters mapped to transaction types (TxType).When serializing
Converters that know how to take aTransactionand 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 specificTxTypeand build a subclass (ex. there is a converter fromTransactiontoRpcBlobTransaction). Each converter is again based on the Ethereum JSON-RPC spec to ensure no fields are missing. Again, we use the same registry approach.RpcNethermindTransactionbut, 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
RpcLegacyTransactionjust using theTxTypevalue) 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? SenderAddressdefaults tonullby 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.