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

Relax Trait Bounds on TransactionPool and EthPoolTransaction #11079

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

Conversation

ewoolsey
Copy link
Contributor

@ewoolsey ewoolsey commented Sep 20, 2024

I'm working on the World Coin Block builder and ran into a problem implementing TransactionPool which currently requires

    PoolTransaction<
        Consensus = TransactionSignedEcRecovered,
        Pooled = PooledTransactionsElementEcRecovered
    >

which is unnecessarily restrictive. I've created a super trait which looks like this:

/// Super trait for transactions that can be converted to and from Eth transactions
pub trait EthPoolTransaction:
    PoolTransaction<
        Consensus: From<TransactionSignedEcRecovered> + Into<TransactionSignedEcRecovered>,
        Pooled: From<PooledTransactionsElementEcRecovered>
                    + Into<PooledTransactionsElementEcRecovered>,
    > + IntoRecoveredTransaction
{
    /// Extracts the blob sidecar from the transaction.
    fn take_blob(&mut self) -> EthBlobTransactionSidecar;

    /// Returns the number of blobs this transaction has.
    fn blob_count(&self) -> usize;

    /// Validates the blob sidecar of the transaction with the given settings.
    fn validate_blob(
        &self,
        blob: &BlobTransactionSidecar,
        settings: &KzgSettings,
    ) -> Result<(), BlobTransactionValidationError>;

    /// Returns the number of authorizations this transaction has.
    fn authorization_count(&self) -> usize;
}

which should be far more versatile for anyone else looking to implement the trait.

I was considering removing IntoRecoveredTransaction since it seems unnecessary since now you can simply call .into_consensus().into() in every case where you would have called .to_recovered_transaction But I decided to leave it since I wasn't sure if there were any other use cases for it. If you guys want to remove it we can do that in another PR.

Additionally perhaps we should consider renaming trait TransactionPool to trait EthTransactionPool to better illustrate it's bounds.

Would love your feedback, and looking forward to getting this merged in. Thanks!

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.

honestly prefer if we leave this completely without trait bounds for now, following design in #10616 and #10997

smthg like

trait PoolTransaction {
    type Error;
    type BlobSideCar;
    etc.
}

associated types for all types used in trait methods except KzgSettings probably

pls change title of pr, it mentions the wrong trait

Pooled = PooledTransactionsElementEcRecovered,
Consensus = TransactionSignedEcRecovered,
>;
type Transaction: EthPoolTransaction;
Copy link
Contributor Author

@ewoolsey ewoolsey Sep 21, 2024

Choose a reason for hiding this comment

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

@emhane I've named the PR because this is specifically the trait bound on TransactionPool I am attempting to relax

@ewoolsey ewoolsey changed the title Relax Transaction Pool Trait Bounds Relax TransactionPool Trait Bounds to EthPoolTransaction Sep 21, 2024
@ewoolsey
Copy link
Contributor Author

@emhane thanks so much for taking a look.

I'm not 100% sure what you're suggesting though. Are you saying to remove type Consensus from PoolTransaction entirely?

Or are you suggesting removing all bounds from EthPoolTransaction in favour of requiring Into/From on methods only where required?

I had a look at the 2 PRs you linked and I'm not entirely sure how they relate. Thanks for clarification!

@ewoolsey ewoolsey changed the title Relax TransactionPool Trait Bounds to EthPoolTransaction Relax Trait Bounds on TransactionPool and EthPoolTransaction Sep 21, 2024
@emhane
Copy link
Member

emhane commented Sep 22, 2024

Or are you suggesting removing all bounds from EthPoolTransaction in favour of requiring Into/From on methods only where required?

this :)

@emhane
Copy link
Member

emhane commented Sep 22, 2024

@mattsse tried to move away from those Into/From trait bounds recently, so don't think we want to reintroduce them now

imo worth exploring if it's possible to delay those trait bounds to where you need them and not have them on the trait definition

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.

2 participants