Skip to content

Commit

Permalink
Shorten error message on debug assertion (#6988)
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Mar 6, 2024
1 parent a1df972 commit ed08649
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions crates/net/network/src/transactions/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. }) =
Expand Down Expand Up @@ -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::<Vec<(TxHash, Option<TxFetchMetadata>)>>());

let (response, rx) = oneshot::channel();
let req: PeerRequest = PeerRequest::GetPooledTransactions {
Expand Down Expand Up @@ -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::<Vec<(TxHash, Option<TxFetchMetadata>)>>());

self.decrement_inflight_request_count_for(&peer_id);

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ed08649

Please sign in to comment.