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(p2p): Add GetReceipts eth handler implementation #3959

Merged
merged 5 commits into from
Jul 31, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions crates/net/network/src/eth_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reth_eth_wire::{
};
use reth_interfaces::p2p::error::RequestResult;
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, PeerId};
use reth_provider::{BlockReader, HeaderProvider};
use reth_provider::{BlockReader, HeaderProvider, ReceiptProvider};
use std::{
borrow::Borrow,
future::Future,
Expand Down Expand Up @@ -70,7 +70,7 @@ impl<C> EthRequestHandler<C> {

impl<C> EthRequestHandler<C>
where
C: BlockReader + HeaderProvider,
C: BlockReader + HeaderProvider + ReceiptProvider,
{
/// Returns the list of requested headers
fn get_headers_response(&self, request: GetBlockHeaders) -> Vec<Header> {
Expand Down Expand Up @@ -185,6 +185,32 @@ where

let _ = response.send(Ok(BlockBodies(bodies)));
}

fn on_receipts_request(
&mut self,
_peer_id: PeerId,
request: GetReceipts,
response: oneshot::Sender<RequestResult<Receipts>>,
) {
let mut receipts = Vec::new();

for hash in request.0 {
if let Some(receipts_by_block) =
self.client.receipts_by_block(BlockHashOrNumber::Hash(hash)).unwrap_or_default()
{
receipts.push(
receipts_by_block
.into_iter()
.map(|receipt| receipt.with_bloom())
.collect::<Vec<_>>(),
);
} else {
break
}
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
}

let _ = response.send(Ok(Receipts(receipts)));
}
}

/// An endless future.
Expand All @@ -211,7 +237,9 @@ where
this.on_bodies_request(peer_id, request, response)
}
IncomingEthRequest::GetNodeData { .. } => {}
IncomingEthRequest::GetReceipts { .. } => {}
IncomingEthRequest::GetReceipts { peer_id, request, response } => {
this.on_receipts_request(peer_id, request, response)
}
},
}
}
Expand Down