Skip to content

Refactor TransactionForRpc (Alternative)#7483

Merged
emlautarom1 merged 189 commits into
masterfrom
refactor/transaction-for-rpc-hierarchy
Oct 14, 2024
Merged

Refactor TransactionForRpc (Alternative)#7483
emlautarom1 merged 189 commits into
masterfrom
refactor/transaction-for-rpc-hierarchy

Conversation

@emlautarom1

@emlautarom1 emlautarom1 commented Sep 23, 2024

Copy link
Copy Markdown
Contributor

Partially solves #7313

Changes

  • Make TransactionForRpc an abstract base class
  • Introduce multiple subclasses of TransactionForRpc for specific Transaction types (Legacy, AccessList, EIP1559, Blob and Optimism)
  • Support JSON (de)serializing
  • Removed TransactionForRpc -> Transaction "default" conversions: conversions now use domain specific defaults (ex. GasLimit defaults to 90_000) instead of C# specific.
  • Introduced mechanism to register new subclasses.

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Documentation

Requires documentation update

  • Yes
  • No

Requires explanation in Release Notes

  • Yes
  • No

Remarks

This PR is an alternative version of #7446 that does not introduce a RpcGenericTransaction for deserializing purposes; instead we reuse the same type hierarchy for both serialization and deserialization. As a quick summary, this PR introduces the following changes:

When deserializing

  • We read JSON and construct a specific subclass of TransactionForRpc based on the Type field of the incoming JSON object (if this field is missing we default to Legacy transactions).
  • Each subclass should implement a ToTransaction method that constructs a proper Transaction object while setting up the appropriate domain defaults when fields are missing (ex. if the transaction is AccessList, then the resulting AccessList field in Transaction is an empty access list, not null).

When serializing

  • We have multiple Converters that know how to take a Transaction and build a TransactionForRpc (the above mentioned abstract base class). Each converter knows how to take a Transaction with a specific TxType and build a subclass (ex. there is a converter from Transaction to BlobTransactionForRpc). Each converter is based on the Ethereum JSON-RPC spec to ensure no fields are missing.
  • To write JSON, we instruct the serializer to use the runtime type rather than the static type, that is, don't use TransactionForRpc but, for example, EIP1559TransactionForRpc.

Comment thread src/Nethermind/Nethermind.JsonRpc.Test/RpcTest.cs Outdated
Comment thread src/Nethermind/Nethermind.JsonRpc.Test/RpcTest.cs Outdated
{
Transaction tx = rpcTx.ToTransactionWithDefaults(_blockchainBridge.GetChainId());
TxHandlingOptions options = rpcTx.Nonce is null ? TxHandlingOptions.ManagedNonce : TxHandlingOptions.None;
Transaction tx = rpcTx.ToTransaction();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe the parameter here should be LegacyTransactionForRpc?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we do that then we cannot override in OptimismEthRpcModule. We could not override and make the Optimism module use OptimismTransactionForRpc but I'm not sure what method is going to be picked up. Need to double check

Comment thread src/Nethermind/Nethermind.Facade/Eth/RpcTransaction/AuthorizationListForRpc.cs Outdated
Comment thread src/Nethermind/Nethermind.Facade/Eth/RpcTransaction/AuthorizationListForRpc.cs Outdated
@emlautarom1 emlautarom1 merged commit 966113f into master Oct 14, 2024
@emlautarom1 emlautarom1 deleted the refactor/transaction-for-rpc-hierarchy branch October 14, 2024 20:05
while (true)
{
ReceiveResult? result = await stream.ReceiveAsync(buffer);
ReceiveResult? result = await stream.ReceiveAsync(buffer).ConfigureAwait(false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@emlautarom1 Why ConfigureAwait(false)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Change introduced by @benaadams

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.

6 participants