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

Pallet Elections Phragment migrates to use Fungibles trait #2011

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

wirednkod
Copy link
Contributor

This PR updates the Elections Phragment pallet to use the fungible traits instead of the Currency trait (More information appear on #226);

@wirednkod wirednkod added T1-FRAME This PR/Issue is related to core FRAME, the framework. D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. labels Oct 24, 2023
@wirednkod wirednkod requested review from a team October 24, 2023 15:56
@wirednkod wirednkod marked this pull request as draft October 24, 2023 16:14
#[pallet::config]
pub trait Config: frame_system::Config {
pub trait Config: frame_system::Config
where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double check whether we need this constraints.

@@ -196,17 +206,59 @@ pub mod pallet {
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

#[pallet::composite_enum]
pub enum HoldReason<I: 'static = ()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub enum HoldReason<I: 'static = ()> {
pub enum HoldReason<I: 'static = ()> {
/// Hold deposit for phragmen pallet.
Phragmen,
}


/// A reason for freezing funds.
#[pallet::composite_enum]
pub enum FreezeReason<I: 'static = ()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar as as HoldReason.

let _remainder = T::Currency::unreserve(&who, to_unreserve);
debug_assert!(_remainder.is_zero());
// Must unreserve a bit.
let released = T::Currency::release_all(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be release(to_unreserve) and not release_all

},
};

// Amount to be locked up.
let locked_stake = value.min(T::Currency::free_balance(&who));
T::Currency::set_lock(T::PalletId::get(), &who, locked_stake, WithdrawReasons::all());
let locked_stake = value.min(T::Currency::balance(&who));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let locked_stake = value.min(T::Currency::balance(&who));
let locked_stake = value.min(T::Currency::reducible_balance(&who, ....));

Probably?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why do we need to lock and reserve in the same action?

debug_assert!(_remainder.is_zero());

let released = T::Currency::release_all(
&HoldReason::ReleaseForRunnerUp.into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&HoldReason::ReleaseForRunnerUp.into(),
&HoldReason::Candidacy.into()

Copy link
Contributor Author

@wirednkod wirednkod Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpestana since Candidancy is altered here to Phragmen - shouldn't Phragmen should be the HoldReason here?

@@ -529,8 +596,12 @@ pub mod pallet {
.binary_search_by(|(c, _)| c.cmp(&who))
.map_err(|_| Error::<T>::InvalidRenouncing)?;
let (_removed, deposit) = candidates.remove(index);
let _remainder = T::Currency::unreserve(&who, deposit);
debug_assert!(_remainder.is_zero());
let _released = T::Currency::release(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not release here again, maybe thaw?

@@ -737,7 +808,7 @@ pub mod pallet {
.map(|(ref member, ref stake)| {
// make sure they have enough stake.
assert!(
T::Currency::free_balance(member) >= *stake,
T::Currency::balance(member) >= *stake,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reducible_balance maybe?

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6469390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants