Skip to content

refactor: add network-primitives#1101

Merged
klkvr merged 5 commits into
alloy-rs:mainfrom
klkvr:klkvr/network-primitives
Jul 26, 2024
Merged

refactor: add network-primitives#1101
klkvr merged 5 commits into
alloy-rs:mainfrom
klkvr:klkvr/network-primitives

Conversation

@klkvr

@klkvr klkvr commented Jul 25, 2024

Copy link
Copy Markdown
Member

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

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

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

Comment thread crates/rpc-types-eth/src/block.rs
Comment thread crates/rpc-types-eth/src/block.rs Outdated
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Block<T = Transaction> {
pub struct Block {

Copy link
Copy Markdown
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?

@klkvr klkvr Jul 25, 2024

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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

Comment thread crates/rpc-types-eth/src/block.rs

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

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