Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

make ToStakingPot and DealWithFees structs generic over account formats #2910

Open
bernardoaraujor opened this issue Jul 19, 2023 · 0 comments
Labels
J0-enhancement An additional feature request.

Comments

@bernardoaraujor
Copy link
Contributor

bernardoaraujor commented Jul 19, 2023

I'm working on a project where we're using AccountId20 instead of AccountId32

I was having a hard time getting parachains_common::impls::DealWithFees and parachains_common::impls::ToStakingPot to compile with this account format.

so my workaround was to copy the parachains_common implementations of ToStakingPot and DealWithFees structs into my own codebase, with the basic modification of:

/// Implementation of `OnUnbalanced` that deals with the fees by combining tip and fee and passing
/// the result on to `ToStakingPot`.
pub struct DealWithFees<R>(PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for DealWithFees<R>
where
	R: pallet_balances::Config + pallet_collator_selection::Config,
-	AccountIdOf<R>: From<polkadot_primitives::AccountId> + Into<polkadot_primitives::AccountId>,
+	AccountIdOf<R>: From<fp_account::AccountId20> + Into<fp_account::AccountId20>,
	<R as frame_system::Config>::RuntimeEvent: From<pallet_balances::Event<R>>,
{
	fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance<R>>) {
		if let Some(mut fees) = fees_then_tips.next() {
			if let Some(tips) = fees_then_tips.next() {
				tips.merge_into(&mut fees);
			}
			<ToStakingPot<R> as OnUnbalanced<_>>::on_unbalanced(fees);
		}
	}
}

/// Implementation of `OnUnbalanced` that deposits the fees into a staking pot for later payout.
pub struct ToStakingPot<R>(PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for ToStakingPot<R>
where
	R: pallet_balances::Config + pallet_collator_selection::Config,
-	AccountIdOf<R>: From<polkadot_primitives::AccountId> + Into<polkadot_primitives::AccountId>,
+	AccountIdOf<R>: From<fp_account::AccountId20> + Into<fp_account::AccountId20>,
	<R as frame_system::Config>::RuntimeEvent: From<pallet_balances::Event<R>>,
{
	fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) {
		let staking_pot = <pallet_collator_selection::Pallet<R>>::account_id();
		<pallet_balances::Pallet<R>>::resolve_creating(&staking_pot, amount);
	}
}

but that feels quite dirty.

wouldn't it make sense to make ToStakingPot and DealWithFees structs generic over account formats, so that runtimes could import them from parachains_common::impls without having to re-implement them?

@bernardoaraujor bernardoaraujor added the J0-enhancement An additional feature request. label Jul 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request.
Projects
None yet
Development

No branches or pull requests

1 participant