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

feat: transaction trait #11877

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

Conversation

edisontim
Copy link
Contributor

@edisontim edisontim commented Oct 18, 2024

Transaction trait has been partially implemented but it's missing a few trait bounds as well as the behavior of reth_primitives::Transaction
Closes #11533

@edisontim
Copy link
Contributor Author

Hey @emhane ! Could you have a look at this one please?

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

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

good job so far

crates/primitives-traits/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/primitives-traits/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/primitives-traits/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/primitives-traits/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

with these things I recommend starting smol, we can always add more functionality later

crates/primitives-traits/Cargo.toml Outdated Show resolved Hide resolved
crates/primitives-traits/Cargo.toml Outdated Show resolved Hide resolved
crates/primitives-traits/Cargo.toml Outdated Show resolved Hide resolved
crates/primitives-traits/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/primitives-traits/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/primitives-traits/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/primitives-traits/src/transaction/mod.rs Outdated Show resolved Hide resolved
Comment on lines -10 to -13
/// Helper trait that unifies all behaviour required by transaction to support full node operations.
pub trait FullTransaction: Transaction + Compact {}

impl<T> FullTransaction for T where T: Transaction + Compact {}
Copy link
Member

Choose a reason for hiding this comment

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

revert this, we don't want to require Compact be a super trait for Transaction

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

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

almost there

pub trait Transaction:
alloy_consensus::Transaction
#[allow(dead_code)]
/// Inner trait for a raw transaction.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Inner trait for a raw transaction.
/// Abstraction of a transaction.

@@ -1,28 +1,65 @@
//! Transaction abstraction
Copy link
Member

Choose a reason for hiding this comment

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

leave this module docs here, remove them from lib.rs for this module

Comment on lines 48 to 52
/// Trait that defines methods of a raw transaction.
///
/// Transaction types were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718).
#[cfg(feature = "arbitrary")]
pub trait FullTransaction<T>: Transaction<T> + Compact + for<'b> arbitrary::Arbitrary<'b> {}
Copy link
Member

Choose a reason for hiding this comment

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

when asked to revert, please also revert the code docs. one should always think, that the docs and the code are glued together and are inseparable.

Suggested change
/// Trait that defines methods of a raw transaction.
///
/// Transaction types were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718).
#[cfg(feature = "arbitrary")]
pub trait FullTransaction<T>: Transaction<T> + Compact + for<'b> arbitrary::Arbitrary<'b> {}
/// Helper trait that unifies all behaviour required by transaction to support full node operations.
#[cfg(feature = "arbitrary")]
pub trait FullTransaction<T>: Transaction<T> + Compact + for<'b> arbitrary::Arbitrary<'b> {}

Comment on lines 58 to 60
/// Trait that defines methods of a raw transaction.
///
/// Transaction types were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Trait that defines methods of a raw transaction.
///
/// Transaction types were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718).
/// Helper trait that unifies all behaviour required by transaction to support full node operations.

+ Serialize
+ for<'de> Deserialize<'de>
+ From<T>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
+ From<T>

we don't need this

alloy_consensus::Transaction
#[allow(dead_code)]
/// Inner trait for a raw transaction.
pub trait Transaction<T>:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub trait Transaction<T>:
pub trait Transaction:

we don't this to have a generic, if anything, give it an associated type


use alloy_rlp::Encodable;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
use alloy_rlp::Encodable;

+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ PartialEq
+ Encodable
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
+ Encodable

revert to

 + alloy_rlp::Encodable
 + alloy_rlp::Decodable

we like to have the longer path to know what encoding this is

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

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

another idea for arbitrary feature, is to do smthg like this in order to use it as super trait independently of FullTransaction, as you initially thought, but without requiring impl of another trait TransactionInner on transaction types alloy-rs/core#766 (comment)
so for this case it would be

#[cfg(not(feature = "arbitrary"))]
trait MaybeArbitrary {}

#[cfg(feature = "arbitrary")]
trait MaybeArbitrary: for<'a> arbitrary::Arbitrary<'a> {}

pub trait Transaction: .. + MaybeArbitrary {
    ..
}

but we can merge this pr as is and make that change in a follow up pr

@edisontim
Copy link
Contributor Author

another idea for arbitrary feature, is to do smthg like this in order to use it as super trait independently of FullTransaction, as you initially thought, but without requiring impl of another trait TransactionInner on transaction types alloy-rs/core#766 (comment) so for this case it would be

#[cfg(not(feature = "arbitrary"))]
trait MaybeArbitrary {}

#[cfg(feature = "arbitrary")]
trait MaybeArbitrary: for<'a> arbitrary::Arbitrary<'a> {}

pub trait Transaction: .. + MaybeArbitrary {
    ..
}

but we can merge this pr as is and make that change in a follow up pr

That makes sense!

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.

Define trait Transaction
3 participants