Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions prdoc/pr_11425.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: 'fix(pallet-multi-asset-bounties): use non-destructive read in calculate_payout()'
doc:
- audience: Runtime Dev
description: |
Fix `calculate_payout()` using `ChildBountiesValuePerParent::take()` instead of `get()`.
The destructive `take()` deletes the storage entry on first call, causing
`BountyPayoutProcessed` to emit an incorrect payout value when `check_status()` calls
`calculate_payout()` a second time on the success path. Replaced `take()` with `get()`
and moved storage cleanup to `remove_bounty()`.
crates:
- name: pallet-multi-asset-bounties
bump: patch
6 changes: 3 additions & 3 deletions substrate/frame/multi-asset-bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ use frame_system::pallet_prelude::{
};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{AccountIdConversion, BadOrigin, Convert, Saturating, StaticLookup, TryConvert, Zero},
traits::{AccountIdConversion, BadOrigin, Convert, Saturating, StaticLookup, TryConvert},
Permill, RuntimeDebug,
};

Expand Down Expand Up @@ -1551,7 +1551,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
None => {
// Get total child bounties value, and subtract it from the parent
// value.
let children_value = ChildBountiesValuePerParent::<T, I>::take(parent_bounty_id);
let children_value = ChildBountiesValuePerParent::<T, I>::get(parent_bounty_id);
debug_assert!(children_value <= value);
let payout = value.saturating_sub(children_value);
payout
Expand All @@ -1571,7 +1571,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Bounties::<T, I>::remove(parent_bounty_id);
ChildBountiesPerParent::<T, I>::remove(parent_bounty_id);
TotalChildBountiesPerParent::<T, I>::remove(parent_bounty_id);
debug_assert!(ChildBountiesValuePerParent::<T, I>::get(parent_bounty_id).is_zero());
ChildBountiesValuePerParent::<T, I>::remove(parent_bounty_id);
},
Some(child_bounty_id) => {
ChildBounties::<T, I>::remove(parent_bounty_id, child_bounty_id);
Expand Down
11 changes: 10 additions & 1 deletion substrate/frame/multi-asset-bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,16 @@ fn check_status_works() {
set_status(payment_id, PaymentStatus::Success);
assert_ok!(Bounties::check_status(RuntimeOrigin::signed(1), s.parent_bounty_id, None));

// Then
// Then: BountyPayoutProcessed should emit the net payout (parent value minus child
// value), not the full parent value.
let expected_payout = s.value - s.child_value;
expect_events(vec![BountiesEvent::BountyPayoutProcessed {
index: s.parent_bounty_id,
child_index: None,
asset_kind: s.asset_kind,
value: expected_payout,
beneficiary: s.beneficiary,
}]);
assert_eq!(
pallet_bounties::ChildBountiesValuePerParent::<Test>::get(s.parent_bounty_id),
0
Expand Down
Loading