fix: correctly fetch pending hashes (#19938)

This commit is contained in:
Arsenii Kulikov
2025-11-24 18:36:43 +04:00
committed by GitHub
parent c2d73988de
commit 4467bc9f4b
2 changed files with 13 additions and 7 deletions

View File

@@ -423,7 +423,7 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
&mut self,
peers: &HashMap<PeerId, PeerMetadata<N>>,
has_capacity_wrt_pending_pool_imports: impl Fn(usize) -> bool,
) {
) -> bool {
let mut hashes_to_request = RequestTxHashes::with_capacity(
DEFAULT_MARGINAL_COUNT_HASHES_GET_POOLED_TRANSACTIONS_REQUEST,
);
@@ -440,7 +440,7 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
budget_find_idle_fallback_peer,
) else {
// no peers are idle or budget is depleted
return
return false
};
peer_id
@@ -449,7 +449,7 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
);
// peer should always exist since `is_session_active` already checked
let Some(peer) = peers.get(&peer_id) else { return };
let Some(peer) = peers.get(&peer_id) else { return false };
let conn_eth_version = peer.version;
// fill the request with more hashes pending fetch that have been announced by the peer.
@@ -493,7 +493,10 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
);
self.buffer_hashes(failed_to_request_hashes, Some(peer_id));
return false
}
true
}
/// Filters out hashes that have been seen before. For hashes that have already been seen, the

View File

@@ -495,7 +495,9 @@ impl<Pool: TransactionPool, N: NetworkPrimitives> TransactionsManager<Pool, N> {
}
/// Runs an operation to fetch hashes that are cached in [`TransactionFetcher`].
fn on_fetch_hashes_pending_fetch(&mut self) {
///
/// Returns `true` if a request was sent.
fn on_fetch_hashes_pending_fetch(&mut self) -> bool {
// try drain transaction hashes pending fetch
let info = &self.pending_pool_imports_info;
let max_pending_pool_imports = info.max_pending_pool_imports;
@@ -503,7 +505,7 @@ impl<Pool: TransactionPool, N: NetworkPrimitives> TransactionsManager<Pool, N> {
|divisor| info.has_capacity(max_pending_pool_imports / divisor);
self.transaction_fetcher
.on_fetch_pending_hashes(&self.peers, has_capacity_wrt_pending_pool_imports);
.on_fetch_pending_hashes(&self.peers, has_capacity_wrt_pending_pool_imports)
}
fn on_request_error(&self, peer_id: PeerId, req_err: RequestError) {
@@ -1625,8 +1627,9 @@ where
// Sends at most one request.
duration_metered_exec!(
{
if this.has_capacity_for_fetching_pending_hashes() {
this.on_fetch_hashes_pending_fetch();
if this.has_capacity_for_fetching_pending_hashes() &&
this.on_fetch_hashes_pending_fetch()
{
maybe_more_tx_fetch_events = true;
}
},