From 42ab8db50b4c0876faeebc47341383a09ad3f28e Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 6 Mar 2024 04:29:08 +0100 Subject: [PATCH] Shorten error message on debug assertion --- .../net/network/src/transactions/fetcher.rs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/net/network/src/transactions/fetcher.rs b/crates/net/network/src/transactions/fetcher.rs index ab4a1be2c0f7..c7b7a3def8b0 100644 --- a/crates/net/network/src/transactions/fetcher.rs +++ b/crates/net/network/src/transactions/fetcher.rs @@ -377,9 +377,8 @@ impl TransactionFetcher { for hash in hashes.into_iter() { debug_assert!( self.hashes_fetch_inflight_and_pending_fetch.peek(&hash).is_some(), - "`%hash` in `@buffered_hashes` that's not in `@unknown_hashes`, `@buffered_hashes` should be a subset of keys in `@unknown_hashes`, broken invariant `@buffered_hashes` and `@unknown_hashes`, -`%hash`: {hash}, -`@self`: {self:?}", + "`%hash` in `@buffered_hashes` that's not in `@hashes_fetch_inflight_and_pending_fetch`, `@buffered_hashes` should be a subset of keys in `@hashes_fetch_inflight_and_pending_fetch`, broken invariant `@buffered_hashes` and `@hashes_fetch_inflight_and_pending_fetch`, +`%hash`: {hash}" ); let Some(TxFetchMetadata { retries, fallback_peers, .. }) = @@ -676,10 +675,10 @@ impl TransactionFetcher { true }(), "`%new_announced_hashes` should been taken out of buffer before packing in a request, breaks invariant `@buffered_hashes` and `@inflight_requests`, -`%new_announced_hashes`: {:?}, -`@self`: {:?}", - new_announced_hashes, self - ); +`@hashes_fetch_inflight_and_pending_fetch` for `%new_announced_hashes`: {:?}", + new_announced_hashes.iter().map(|hash| + (*hash, self.hashes_fetch_inflight_and_pending_fetch.get(hash).cloned()) + ).collect::)>>()); let (response, rx) = oneshot::channel(); let req: PeerRequest = PeerRequest::GetPooledTransactions { @@ -910,12 +909,13 @@ impl TransactionFetcher { let GetPooledTxResponse { peer_id, mut requested_hashes, result } = response; debug_assert!( - self.active_peers.get(&peer_id).is_some(), - "`%peer_id` has been removed from `@active_peers` before inflight request(s) resolved, broken invariant `@active_peers` and `@inflight_requests`, + self.active_peers.get(&peer_id).is_some(), + "`%peer_id` has been removed from `@active_peers` before inflight request(s) resolved, broken invariant `@active_peers` and `@inflight_requests`, `%peer_id`: {}, -`@self`: {:?}", - peer_id, self - ); +`@hashes_fetch_inflight_and_pending_fetch` for `%requested_hashes`: {:?}", + peer_id, requested_hashes.iter().map(|hash| + (*hash, self.hashes_fetch_inflight_and_pending_fetch.get(hash).cloned()) + ).collect::)>>()); self.decrement_inflight_request_count_for(&peer_id); @@ -1071,7 +1071,7 @@ impl Default for TransactionFetcher { } /// Metadata of a transaction hash that is yet to be fetched. -#[derive(Debug, Constructor)] +#[derive(Debug, Constructor, Clone)] pub struct TxFetchMetadata { /// The number of times a request attempt has been made for the hash. retries: u8,