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

Refactor TransactionForRpc (Alternative) #7483

Merged
merged 189 commits into from
Oct 14, 2024

Conversation

emlautarom1
Copy link
Contributor

@emlautarom1 emlautarom1 commented Sep 23, 2024

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.

@@ -280,8 +281,12 @@ public ResultWrapper<byte[]> eth_sign(Address addressData, byte[] message)

public virtual Task<ResultWrapper<Hash256>> eth_sendTransaction(TransactionForRpc rpcTx)
{
Transaction tx = rpcTx.ToTransactionWithDefaults(_blockchainBridge.GetChainId());
TxHandlingOptions options = rpcTx.Nonce is null ? TxHandlingOptions.ManagedNonce : TxHandlingOptions.None;
Transaction tx = rpcTx.ToTransaction();
Copy link
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
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

@emlautarom1 emlautarom1 merged commit 966113f into master Oct 14, 2024
73 checks passed
@emlautarom1 emlautarom1 deleted the refactor/transaction-for-rpc-hierarchy branch October 14, 2024 20:05
@@ -80,7 +80,7 @@ static async Task<int> CountNumberOfMessages(Socket socket, CancellationToken to
byte[] buffer = new byte[10];
while (true)
{
ReceiveResult? result = await stream.ReceiveAsync(buffer);
ReceiveResult? result = await stream.ReceiveAsync(buffer).ConfigureAwait(false);
Copy link
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
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