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: add network-primitives #1101

Merged
merged 5 commits into from
Jul 26, 2024
Merged

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Jul 25, 2024

Motivation

alloy-rpc-types-eth are supposed to be concrete, thus having generics on types defined in it is not helpful and makes it hard to define implementations based on traits from other crates.

Solution

  • Move ReceiptResponse and TransactionResponse from alloy-network to new crate alloy-network-primitives, allowing their usage without depending on alloy-network
  • Move BlockTransactions<T> into network-primitives and provide implementations for T: TransactionResponse instead of concrete rpc_types_eth::Transaction

This sets us up for block response abstraction, making it possible to add getters for BlockTransactions generic over N::TransactionResponse ref #267

Note: This changed Iterator::Item for BlockTransactionHashes from &B256 to B256 as this is what TransactionResponse::tx_hash returns. Is it fine or should I update the trait instead? It seems that it's OK to expect TransactionResponse to own a hash.

This also removes BlockTransactionHashesMut

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Member

@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.

lgtm, one nit

as dicussed we need this split so we can avoid cyclic dependencies for network/consensus/rpc

This also removes BlockTransactionHashesMut

this is reasonable I believe, I don't think we want to support this

crates/rpc-types-eth/src/block.rs Show resolved Hide resolved
@@ -14,7 +15,7 @@ pub use alloy_eips::{
/// Block representation
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Block<T = Transaction> {
pub struct Block {
Copy link
Member

Choose a reason for hiding this comment

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

hmm, can we keep this generic? otherwise we can't reuse that block type?

Copy link
Member Author

@klkvr klkvr Jul 25, 2024

Choose a reason for hiding this comment

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

right, this could be useful in some cases, though I think for most of the rollups entire Block would be different as there'll be no withdrawals for example, so we'd likely want to just add more reusable generic components for custom blocks (like BlockTransactions<T>)

added generic back as it doesn't hurt anyway

Copy link
Member

Choose a reason for hiding this comment

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

yep I also think this will be the case but this can be useful for rollups that only have 1 additional tx type for example

crates/rpc-types-eth/src/block.rs Show resolved Hide resolved
Copy link
Member

@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.

ah now I get why we can't reuse the BlocktransactionsMut

lgtm

not sure what's up with the clippy error...

@klkvr klkvr merged commit 4ba5323 into alloy-rs:main Jul 26, 2024
21 of 22 checks passed
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
* refactor: add network-primitives

* fix tests

* fix docs

* add re-exports

* Block<T>
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