Skip to content

Commit

Permalink
Add debug_assertions whenever calling queue_notification (#3056)
Browse files Browse the repository at this point in the history
Provides more clarity about the problem if `queue_notification` panics.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
tomaka and mergify[bot] committed Nov 30, 2022
1 parent 891e14c commit bc4ec47
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/network/service/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ where
})
};

debug_assert!(self
.inner
.can_queue_notification(&peer_id, notifications_protocol_index));
let _ = self.inner.queue_notification(
&peer_id,
notifications_protocol_index,
Expand Down Expand Up @@ -663,6 +666,12 @@ where
scale_encoded_header: &[u8],
is_best: bool,
) -> Result<(), QueueNotificationError> {
// In order to provide clarity about the problem, check ahead of time whether calling
// `queue_notification` will panic below.
debug_assert!(self
.inner
.can_queue_notification(target, chain_index * NOTIFICATIONS_PROTOCOLS_PER_CHAIN));

let buffers_to_send = protocol::encode_block_announce(protocol::BlockAnnounceRef {
scale_encoded_header,
is_best,
Expand Down Expand Up @@ -713,6 +722,12 @@ where
chain_index: usize,
extrinsic: &[u8],
) -> Result<(), QueueNotificationError> {
// In order to provide clarity about the problem, check ahead of time whether calling
// `queue_notification` will panic below.
debug_assert!(self
.inner
.can_queue_notification(target, chain_index * NOTIFICATIONS_PROTOCOLS_PER_CHAIN + 1));

let mut val = Vec::with_capacity(1 + extrinsic.len());
val.extend_from_slice(util::encode_scale_compact_usize(1).as_ref());
val.extend_from_slice(extrinsic);
Expand Down

0 comments on commit bc4ec47

Please sign in to comment.