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

Dust Account Detection Strategy? #101

Closed
AurevoirXavier opened this issue Nov 21, 2019 · 3 comments · Fixed by #307
Closed

Dust Account Detection Strategy? #101

AurevoirXavier opened this issue Nov 21, 2019 · 3 comments · Fixed by #307
Assignees

Comments

@AurevoirXavier
Copy link
Member

Account {
	ring: 0,
	kton: 100_000_000,
}

Got killed?

@hackfisher
Copy link
Contributor

In this case, the account should definitely be kept.

For now, let's follow strict and safe strategy:

Only Account.ring < existential_deposit and account.kton == 0 will get killed.

For KTON, there is no existential_deposit, or the default existential_deposit is zero.

@hackfisher hackfisher added U-Help Wanted [Uncategorized] Extra attention is needed Q3-medium and removed enhancement U-Question [Uncategorized] Further information/discussion is requested labels Mar 3, 2020
@AurevoirXavier
Copy link
Member Author

AurevoirXavier commented Mar 3, 2020

Implement ExistentialCheck for darwinia-ring and darwinia-kton.

Will be solved in #307.

Example:

// support.rs
pub trait ExistentialCheck<AccountId, Balance> {
	fn try_drop(who: &AccountId) -> (bool, Balance);
}

// kton.rs
impl<T: Trait<I>, I: Instance> ExistentialCheck<T::AccountId, T::Balance> for Module<T, I>
where
	T::Balance: MaybeSerializeDeserialize + Debug,
{
	fn try_drop(who: &T::AccountId) -> (bool, T::Balance) {
		let dropped_kton = Self::total_balance(who);
		let dropped = !dropped_kton.is_zero() && dropped_kton < T::ExistentialDeposit::get();
		if dropped {
			T::DustRemoval::on_unbalanced(NegativeImbalance::new(dropped_kton));
		}

		(dropped, dropped_kton)
	}
}

// ring.rs
fn post_mutation(who: &T::AccountId, new: ActiveBalance<T::Balance>) -> Option<ActiveBalance<T::Balance>> {
	let total = new.total();
	if total < T::ExistentialDeposit::get() {
		if !total.is_zero() {
			let (dropped, dropped_kton) = T::ExistentialCheck::try_drop(who);
			if dropped {
				T::DustRemoval::on_unbalanced(NegativeImbalance::new(total));
				Self::deposit_event(RawEvent::DustLost(who.clone(), total, dropped_kton));
			}
		}
		None
	} else {
		Some(new)
	}
}

@AurevoirXavier AurevoirXavier added A3-inprogress and removed U-Help Wanted [Uncategorized] Extra attention is needed labels Mar 3, 2020
@hackfisher
Copy link
Contributor

hackfisher commented Mar 4, 2020

Implement ExistentialCheck for darwinia-ring and darwinia-kton.

Will be solved in #307.

Example:

// support.rs
pub trait ExistentialCheck<AccountId, Balance> {
	fn try_drop(who: &AccountId) -> (bool, Balance);
}

// kton.rs
impl<T: Trait<I>, I: Instance> ExistentialCheck<T::AccountId, T::Balance> for Module<T, I>
where
	T::Balance: MaybeSerializeDeserialize + Debug,
{
	fn try_drop(who: &T::AccountId) -> (bool, T::Balance) {
		let dropped_kton = Self::total_balance(who);
		let dropped = !dropped_kton.is_zero() && dropped_kton < T::ExistentialDeposit::get();
		if dropped {
			T::DustRemoval::on_unbalanced(NegativeImbalance::new(dropped_kton));
		}

		(drop, dropped_kton)
	}
}

// ring.rs
fn post_mutation(who: &T::AccountId, new: ActiveBalance<T::Balance>) -> Option<ActiveBalance<T::Balance>> {
	let total = new.total();
	if total < T::ExistentialDeposit::get() {
		if !total.is_zero() {
			let (dropped, dropped_kton) T::ExistentialCheck::try_drop(who);
			if dropped {
				T::DustRemoval::on_unbalanced(NegativeImbalance::new(total));
				Self::deposit_event(RawEvent::DustLost(who.clone(), total, dropped_kton));
			}
		}
		None
	} else {
		Some(new)
	}
}
// ring.rs
fn post_mutation(who: &T::AccountId, new: ActiveBalance<T::Balance>) -> Option<ActiveBalance<T::Balance>> {
	let total = new.total();
	if total < T::ExistentialDeposit::get() {
                 let (dropped, dropped_kton) = T::ExistentialCheck::try_drop(who);
		if dropped {
                          if !total.is_zero(){
				T::DustRemoval::on_unbalanced(NegativeImbalance::new(total));
				Self::deposit_event(RawEvent::DustLost(who.clone(), total, dropped_kton));
			}
                          None
                 } else {
                          Some(new)
                 }
	} else {
		Some(new)
	}
}

@AurevoirXavier AurevoirXavier linked a pull request Mar 4, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants