refactor(net): some refactor in eth requests (#9205)

This commit is contained in:
Thomas Coratger
2024-07-01 11:39:48 +02:00
committed by GitHub
parent 2a9fa4869e
commit 84e385753e

View File

@ -66,8 +66,12 @@ pub struct EthRequestHandler<C> {
impl<C> EthRequestHandler<C> {
/// Create a new instance
pub fn new(client: C, peers: PeersHandle, incoming: Receiver<IncomingEthRequest>) -> Self {
let metrics = Default::default();
Self { client, peers, incoming_requests: ReceiverStream::new(incoming), metrics }
Self {
client,
peers,
incoming_requests: ReceiverStream::new(incoming),
metrics: Default::default(),
}
}
}
@ -124,11 +128,7 @@ where
total_bytes += header.length();
headers.push(header);
if headers.len() >= MAX_HEADERS_SERVE {
break
}
if total_bytes > SOFT_RESPONSE_LIMIT {
if headers.len() >= MAX_HEADERS_SERVE || total_bytes > SOFT_RESPONSE_LIMIT {
break
}
} else {
@ -163,21 +163,12 @@ where
for hash in request.0 {
if let Some(block) = self.client.block_by_hash(hash).unwrap_or_default() {
let body = BlockBody {
transactions: block.body,
ommers: block.ommers,
withdrawals: block.withdrawals,
requests: block.requests,
};
let body: BlockBody = block.into();
total_bytes += body.length();
bodies.push(body);
if bodies.len() >= MAX_BODIES_SERVE {
break
}
if total_bytes > SOFT_RESPONSE_LIMIT {
if bodies.len() >= MAX_BODIES_SERVE || total_bytes > SOFT_RESPONSE_LIMIT {
break
}
} else {
@ -212,11 +203,7 @@ where
total_bytes += receipt.length();
receipts.push(receipt);
if receipts.len() >= MAX_RECEIPTS_SERVE {
break
}
if total_bytes > SOFT_RESPONSE_LIMIT {
if receipts.len() >= MAX_RECEIPTS_SERVE || total_bytes > SOFT_RESPONSE_LIMIT {
break
}
} else {