Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit proper events in Balances when ED is updated #4028

Closed
kianenigma opened this issue Apr 8, 2024 · 2 comments · Fixed by #4936
Closed

Emit proper events in Balances when ED is updated #4028

kianenigma opened this issue Apr 8, 2024 · 2 comments · Fixed by #4936
Labels
T2-pallets This PR/Issue is related to a particular pallet.

Comments

@kianenigma
Copy link
Contributor

Namely, in the Currency impl, the current implementation of pallet_balances is not emitting any instances of Issued and Rescinded events, even though in the fungible equivalents it is.

This is somewhat confusing, and it would be best if the pallet always emits events upon any pdate to the TI.

diff --git a/substrate/frame/balances/src/impl_currency.rs b/substrate/frame/balances/src/impl_currency.rs
index d5fe9934e2..ea2165cd8d 100644
--- a/substrate/frame/balances/src/impl_currency.rs
+++ b/substrate/frame/balances/src/impl_currency.rs
@@ -34,11 +34,12 @@ use frame_support::{
 };
 use frame_system::pallet_prelude::BlockNumberFor;
 pub use imbalances::{NegativeImbalance, PositiveImbalance};
+use sp_runtime::traits::Bounded;
 
 // wrapping these imbalances in a private module is necessary to ensure absolute privacy
 // of the inner member.
 mod imbalances {
-	use super::{result, Config, Imbalance, RuntimeDebug, Saturating, TryDrop, Zero};
+	use super::*;
 	use frame_support::traits::SameOrOther;
 	use sp_std::mem;
 
@@ -200,6 +201,9 @@ mod imbalances {
 		/// Basic drop handler will just square up the total issuance.
 		fn drop(&mut self) {
 			<super::TotalIssuance<T, I>>::mutate(|v| *v = v.saturating_add(self.0));
+			if !self.0.is_zero() {
+				Pallet::<T, I>::deposit_event(Event::<T, I>::Issued { amount: self.0 });
+			}
 		}
 	}
 
@@ -207,6 +211,9 @@ mod imbalances {
 		/// Basic drop handler will just square up the total issuance.
 		fn drop(&mut self) {
 			<super::TotalIssuance<T, I>>::mutate(|v| *v = v.saturating_sub(self.0));
+			if !self.0.is_zero() {
+				Pallet::<T, I>::deposit_event(Event::<T, I>::Rescinded { amount: self.0 });
+			}
 		}
 	}
 }
@@ -263,6 +270,8 @@ where
 				Zero::zero()
 			});
 		});
+
+		Pallet::<T, I>::deposit_event(Event::<T, I>::Rescinded { amount });
 		PositiveImbalance::new(amount)
 	}
 
@@ -279,6 +288,8 @@ where
 				Self::Balance::max_value()
 			})
 		});
+
+		Pallet::<T, I>::deposit_event(Event::<T, I>::Issued { amount });
 		NegativeImbalance::new(amount)
 	}
 
@@ -349,7 +360,7 @@ where
 				};
 				account.free.saturating_reduce(actual);
 				let remaining = value.saturating_sub(actual);
-				Ok((NegativeImbalance::new(actual), remaining))
+				Ok((NegativeImbalance::new(dbg!(actual)), remaining))
 			},
 		) {
 			Ok((imbalance, remaining)) => {

Something like this ^^

@kianenigma kianenigma added the T2-pallets This PR/Issue is related to a particular pallet. label Apr 8, 2024
@mittal-parth
Copy link
Contributor

@kianenigma can I take this up?

@mittal-parth
Copy link
Contributor

Thanks @kianenigma, made a PR #4936

github-merge-queue bot pushed a commit that referenced this issue Jul 19, 2024
# Description

Previously, in the `Currency` impl, the implementation of
`pallet_balances` was not emitting any instances of `Issued` and
`Rescinded` events, even though the `Fungible` equivalent was.

This PR adds the `Issued` and `Rescinded` events in appropriate places
in `impl_currency` along with tests.

Closes #4028 

polkadot address: 5GsLutpKjbzsbTphebs9Uy4YK6gTN47MAaz6njPktidjR5cp

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <info@kchr.de>
TarekkMA pushed a commit to moonbeam-foundation/polkadot-sdk that referenced this issue Aug 2, 2024
…itytech#4936)

# Description

Previously, in the `Currency` impl, the implementation of
`pallet_balances` was not emitting any instances of `Issued` and
`Rescinded` events, even though the `Fungible` equivalent was.

This PR adds the `Issued` and `Rescinded` events in appropriate places
in `impl_currency` along with tests.

Closes paritytech#4028 

polkadot address: 5GsLutpKjbzsbTphebs9Uy4YK6gTN47MAaz6njPktidjR5cp

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <info@kchr.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants