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