diff --git a/prdoc/pr_9166.prdoc b/prdoc/pr_9166.prdoc new file mode 100644 index 0000000000000..a9ca451a38a01 --- /dev/null +++ b/prdoc/pr_9166.prdoc @@ -0,0 +1,8 @@ +title: 'pallet-bags-list: Emit `ScoreUpdated` event only if it has changed' +doc: +- audience: Runtime Dev + description: |- + follow-up to https://github.com/paritytech/polkadot-sdk/pull/8684, ensuring all blocks don't have x events when auto-rebag feature is enabled. +crates: +- name: pallet-bags-list + bump: patch diff --git a/substrate/bin/node/bench/src/import.rs b/substrate/bin/node/bench/src/import.rs index db4f37af75e8f..ec112cfee80df 100644 --- a/substrate/bin/node/bench/src/import.rs +++ b/substrate/bin/node/bench/src/import.rs @@ -135,10 +135,9 @@ impl core::Benchmark for ImportBenchmark { // - 2x deposit (Balances::Deposit and Treasury::Deposit) for depositing // the transaction fee into the treasury // - extrinsic success - // +3 Bags List events from on_idle hook assert_eq!( kitchensink_runtime::System::events().len(), - (self.block.extrinsics.len() - 2) * 9 + 2 + 3, + (self.block.extrinsics.len() - 2) * 9 + 2, ); }, BlockType::Noop => { diff --git a/substrate/frame/bags-list/src/lib.rs b/substrate/frame/bags-list/src/lib.rs index f35f0a56d1787..9ff37b4b1b149 100644 --- a/substrate/frame/bags-list/src/lib.rs +++ b/substrate/frame/bags-list/src/lib.rs @@ -553,11 +553,13 @@ impl, I: 'static> Pallet { ) -> Result, ListError> { // If no voter at that node, don't do anything. the caller just wasted the fee to call this. let node = list::Node::::get(&account).ok_or(ListError::NodeNotFound)?; + if node.score != new_score { + Self::deposit_event(Event::::ScoreUpdated { who: account.clone(), new_score }); + } let maybe_movement = List::update_position_for(node, new_score); if let Some((from, to)) = maybe_movement { Self::deposit_event(Event::::Rebagged { who: account.clone(), from, to }); }; - Self::deposit_event(Event::::ScoreUpdated { who: account.clone(), new_score }); Ok(maybe_movement) }