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

Implement Inactive balance tracking in Assets pallet #1747

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions prdoc/pr_1747.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Implement Inactive balance tracking in Assets pallet

doc:
- audience: Runtime Dev
description: |
The trait `fungibles::Unbalanced` provides methods to increase and decrease active issuance.
This PR addresses the lack of this feature in Assets, by introducing a new field `inactive` in the `Asset` struct and implementing the methods accordingly.

crates:
- name: pallet-assets
1 change: 1 addition & 0 deletions substrate/frame/assets/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
admin: owner.clone(),
freezer: owner.clone(),
supply: Zero::zero(),
inactive: Zero::zero(),
deposit: Zero::zero(),
min_balance,
is_sufficient,
Expand Down
17 changes: 16 additions & 1 deletion substrate/frame/assets/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,22 @@ impl<T: Config<I>, I: 'static> fungibles::Unbalanced<T::AccountId> for Pallet<T,
Ok(amount)
}

// TODO: #13196 implement deactivate/reactivate once we have inactive balance tracking.
fn deactivate(asset: Self::AssetId, amount: Self::Balance) {
Asset::<T, I>::mutate(&asset, |maybe_asset| match maybe_asset {
Some(ref mut asset) => {
// Inactive amount can't exceed supply
asset.inactive = asset.inactive.saturating_add(amount).max(asset.supply);
Comment on lines +170 to +171
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems this be a defensive check if the runtime is trying to set the inactive amt > total supply, probably indicates a bug?

},
None => log::error!("Called deactivate for nonexistent asset {:?}", asset),
});
}

fn reactivate(asset: Self::AssetId, amount: Self::Balance) {
Asset::<T, I>::mutate(&asset, |maybe_asset| match maybe_asset {
Some(ref mut asset) => asset.inactive.saturating_reduce(amount),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be defensive in case > total inactive amount is attempted to be reactivated?

None => log::error!("Called reactivate for nonexistent asset {:?}", asset),
});
}
}

impl<T: Config<I>, I: 'static> fungibles::Create<T::AccountId> for Pallet<T, I> {
Expand Down
6 changes: 4 additions & 2 deletions substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ pub mod pallet {
};
use frame_system::pallet_prelude::*;

/// The in-code storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
/// The current storage version.
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
/// The current storage version.
/// The in-code storage version.

const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down Expand Up @@ -440,6 +440,7 @@ pub mod pallet {
admin: owner.clone(),
freezer: owner.clone(),
supply: Zero::zero(),
inactive: Zero::zero(),
deposit: Zero::zero(),
min_balance: *min_balance,
is_sufficient: *is_sufficient,
Expand Down Expand Up @@ -666,6 +667,7 @@ pub mod pallet {
admin: admin.clone(),
freezer: admin.clone(),
supply: Zero::zero(),
inactive: Zero::zero(),
deposit,
min_balance,
is_sufficient: false,
Expand Down
138 changes: 0 additions & 138 deletions substrate/frame/assets/src/migration.rs

This file was deleted.

21 changes: 21 additions & 0 deletions substrate/frame/assets/src/migration/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/// Version 0 to 1.
pub mod v1;
/// Version 1 to 2.
pub mod v2;
Loading
Loading