From 0152c3bf8a079219e540f2d27eb2b1f71d964fd9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 11 Oct 2023 12:50:56 +0200 Subject: [PATCH 1/3] fix: be defensive when broadcaster selection fails --- state-chain/pallets/cf-broadcast/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/state-chain/pallets/cf-broadcast/src/lib.rs b/state-chain/pallets/cf-broadcast/src/lib.rs index d787a65b1d..37151d6c4c 100644 --- a/state-chain/pallets/cf-broadcast/src/lib.rs +++ b/state-chain/pallets/cf-broadcast/src/lib.rs @@ -790,10 +790,11 @@ impl, I: 'static> Pallet { transaction_out_id: broadcast_attempt.transaction_out_id, }); } else { - const FAILED_SIGNER_SELECTION: &str = "Failed to select signer: We should either: a) have a signer eligible for nomination b) already have aborted this broadcast when scheduling the retry"; - log::error!("{FAILED_SIGNER_SELECTION}"); - #[cfg(test)] - panic!("{FAILED_SIGNER_SELECTION}"); + log::warn!( + "Failed to select a signer for broadcast {:?}. Scheduling Retry", + broadcast_attempt.broadcast_attempt_id + ); + BroadcastRetryQueue::::append(&broadcast_attempt); } } } From 1bc10779b6f0b393f40d0c750152bcfb88fba01e Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 11 Oct 2023 12:51:53 +0200 Subject: [PATCH 2/3] chore: remove rust analyzer warning --- state-chain/pallets/cf-broadcast/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/state-chain/pallets/cf-broadcast/src/lib.rs b/state-chain/pallets/cf-broadcast/src/lib.rs index 37151d6c4c..45df709369 100644 --- a/state-chain/pallets/cf-broadcast/src/lib.rs +++ b/state-chain/pallets/cf-broadcast/src/lib.rs @@ -721,10 +721,12 @@ impl, I: 'static> Pallet { let next_broadcast_attempt_id = broadcast_attempt.broadcast_attempt_id.next_attempt(); - BroadcastAttemptCount::::mutate(broadcast_id, |attempt_count| { - *attempt_count += 1; - *attempt_count - }); + BroadcastAttemptCount::::mutate( + broadcast_id, + |attempt_count: &mut AttemptCount| { + *attempt_count += 1; + }, + ); debug_assert_eq!( BroadcastAttemptCount::::get(broadcast_id), next_broadcast_attempt_id.attempt_count, From cd2be9c893fb90fbc5798c638112ebb6d08cd57f Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 11 Oct 2023 18:14:46 +0200 Subject: [PATCH 3/3] fix: emit event --- state-chain/pallets/cf-broadcast/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/state-chain/pallets/cf-broadcast/src/lib.rs b/state-chain/pallets/cf-broadcast/src/lib.rs index 45df709369..5712e36f3e 100644 --- a/state-chain/pallets/cf-broadcast/src/lib.rs +++ b/state-chain/pallets/cf-broadcast/src/lib.rs @@ -452,10 +452,7 @@ pub mod pallet { .broadcast_id, }); } else { - BroadcastRetryQueue::::append(&signing_attempt.broadcast_attempt); - Self::deposit_event(Event::::BroadcastRetryScheduled { - broadcast_attempt_id: signing_attempt.broadcast_attempt.broadcast_attempt_id, - }); + Self::schedule_for_retry(&signing_attempt.broadcast_attempt); } Ok(().into()) @@ -796,9 +793,16 @@ impl, I: 'static> Pallet { "Failed to select a signer for broadcast {:?}. Scheduling Retry", broadcast_attempt.broadcast_attempt_id ); - BroadcastRetryQueue::::append(&broadcast_attempt); + Self::schedule_for_retry(&broadcast_attempt); } } + + fn schedule_for_retry(broadcast_attempt: &BroadcastAttempt) { + BroadcastRetryQueue::::append(broadcast_attempt); + Self::deposit_event(Event::::BroadcastRetryScheduled { + broadcast_attempt_id: broadcast_attempt.broadcast_attempt_id, + }); + } } impl, I: 'static> Broadcaster for Pallet {