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 Transaction rlp encoding #7871

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Gabriel-Trintinalia
Copy link
Contributor

PR Description

This pull request introduces refactoring to simplify the encoding and decoding of transactions by utilizing a new class RlpProvider. The changes replace the direct usage of TransactionEncoder and TransactionDecoder with methods provided by RlpProvider.

Key updates include decoupling the encoding and decoding logic from the Transaction class itself, resulting in the removal of the readFrom() and writeTo() methods from the Transaction class.

Static calls for encoding and decoding have been replaced with calls to a singleton object, which can be configured to use different encoding classes if necessary. The next pull request will extend the RLP service to allow plugins to register different transaction encoding and decoding objects. This will enable networks with different RLP serialisation to replace the mainnet RLP serialisation.

Additionally, this pull request removes the encoding context from the transaction decoders/encoders to align them with other decoders. Some code cleanup was also performed by utilising the encoded() method of the Transaction class.

Key Changes:

  • Refactoring to use RlpProvider: Replaced TransactionEncoder.encodeOpaqueBytes and TransactionDecoder.decodeOpaqueBytes with RlpProvider.transaction().encodeOpaqueBytes and RlpProvider.transaction().decodeOpaqueBytes respectively in various files.

  • Decoupling from Transaction class: Removed readFrom() and writeTo() methods from the Transaction class.

  • Singleton Object for Encoding/Decoding: Replaced static calls with calls to a singleton object, allowing for configurable encoding classes.

  • Code Cleanup: Utilized the encoded() method of the Transaction class for cleaner code.

Future Extensions:

  • Prepared the RLP service for future extensions to allow plugins to register different transaction encoding and decoding objects.
  • Use the same approach for Block and Blockhead

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Copy link
Contributor

@jflo jflo left a comment

Choose a reason for hiding this comment

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

Thanks, this will help future Daggerization

pooledTransactionEncoder = new PooledMainnetTransactionEncoder();
}

protected static RlpRegistry getInstance() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be a singleton? It's only usage is from the RlpProvider.

Copy link
Contributor Author

@Gabriel-Trintinalia Gabriel-Trintinalia Nov 20, 2024

Choose a reason for hiding this comment

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

The next pull request will extend the RLP service to allow plugins to register different transaction encoding and decoding objects, by either setting the instance or registering a factory.

Copy link
Contributor

@ahamlat ahamlat left a comment

Choose a reason for hiding this comment

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

Can you test on mainnet with parallel transaction execution enabled ?


private RlpProvider() {}

public static TransactionHandler transaction() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a method in general should be in a form of action, like a verb, ex. getTransactionHandler. When reading the method without having the context, it is hard to know what the method is doing.

RlpRegistry.getInstance().getTransactionEncoder());
}

public static TransactionHandler pooledTransaction() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The same as above, getPooledTransactionHandler ?

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.

4 participants