-
Notifications
You must be signed in to change notification settings - Fork 696
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
Enable Merklized Distributions in Assets Pallet #5400
base: master
Are you sure you want to change the base?
Enable Merklized Distributions in Assets Pallet #5400
Conversation
This reverts commit 1cfb29f.
Co-authored-by: Ankan <[email protected]>
…abrizi/polkadot-sdk into shawntabrizi-proving-trie
This PR is blocked because the data structures in |
@@ -538,4 +538,20 @@ impl<T: frame_system::Config> pallet_assets::WeightInfo for WeightInfo<T> { | |||
.saturating_add(T::DbWeight::get().reads(1_u64)) | |||
.saturating_add(T::DbWeight::get().writes(1_u64)) | |||
} | |||
|
|||
fn mint_distribution() -> Weight { | |||
Weight::default() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO prior to merge
|
||
#[derive(Eq, PartialEq, Copy, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)] | ||
pub struct DistributionInfo<AssetId, Hash> { | ||
// The asset id we are distributing. | ||
pub asset_id: AssetId, | ||
// The merkle root which represents all the balances to distribute. | ||
pub merkle_root: Hash, | ||
// Whether the distribution is still active. | ||
pub active: bool, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[derive(Eq, PartialEq, Copy, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)] | |
pub struct DistributionInfo<AssetId, Hash> { | |
// The asset id we are distributing. | |
pub asset_id: AssetId, | |
// The merkle root which represents all the balances to distribute. | |
pub merkle_root: Hash, | |
// Whether the distribution is still active. | |
pub active: bool, | |
} | |
/// Foo bar baz | |
#[derive(Eq, PartialEq, Copy, Clone, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)] | |
pub struct DistributionInfo<AssetId, Hash> { | |
/// The asset id we are distributing. | |
pub asset_id: AssetId, | |
/// The merkle root which represents all the balances to distribute. | |
pub merkle_root: Hash, | |
/// Whether the distribution is still active. | |
pub active: bool, | |
} |
@@ -1798,6 +1848,92 @@ pub mod pallet { | |||
)?; | |||
Ok(()) | |||
} | |||
|
|||
/// Mint a distribution of assets of a particular class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something about this can go into the main top docs and then in https://docs.rs/pallet-assets/latest/pallet_assets/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small nits remaining, but the overall logic is good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass. Haven't looked yet at the proving trie code.
if all_refunded { | ||
Self::deposit_event(Event::<T, I>::DistributionCleaned { distribution_id }); | ||
// Refund weight only the amount we actually used. | ||
Ok(Some(T::WeightInfo::destroy_distribution(refund_count)).into()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the incentive to clean up state? Shouldn't we refund all fees?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyone can clean up state... but yeah we could add a deposit here for doing a distribution
) -> DispatchResult { | ||
let origin = ensure_signed(origin)?; | ||
let id: T::AssetId = id.into(); | ||
Self::do_mint_distribution(id, merkle_root, Some(origin))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking out loud: Should we not take some kind of deposit here (charging for the storage), that is only refunded when state (MerklizedDistributionTracker
) is cleaned up? What stops some one to create large number of distributions?
Co-authored-by: Ankan <[email protected]>
ensure!(check_issuer == details.issuer, Error::<T, I>::NoPermission); | ||
} | ||
|
||
let info = DistributionInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you have already considered this, but I'm still a little concerned that an account can create a bunch of distributions without paying any storage cost.
We could limit this by either
- Requiring a deposit when creating a distribution.
- Or, limit it to one active distribution per asset ID.
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't expect multiple active distribution for an asset, probably that is the most straightforward. We can use AssetId as the key for MerklizedDistribution
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am okay with you adding storage deposit to this PR. i would like to hand it off to someone else to own and take to finish line
|
||
#[pallet::storage] | ||
/// Merklized distribution of an asset. | ||
pub(super) type MerklizedDistribution<T: Config<I>, I: 'static = ()> = StorageMap< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could be a CountedStorageMap
to count active distributions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, because the count would go down when we clean up a distribution. and we want the count to remain unique
/// | ||
/// - `distribution_id`: The identifier of the distribution. | ||
/// - `merkle_proof`: The merkle proof of the account and balance in a compact base-16 | ||
/// merkle trie used to authorize minting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing info about hashes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one concern about preventing distribution spam, otherwise happy to approve.
Depends on: #3881
This PR introduces a way for an asset issuer to distribute their token to many users using a single merkle root.
Users then present a merkle proof which is verified, and triggers the
do_mint
function.A tracking storage ensures that each user only claims their distribution a single time.
The design allows for multiple distributions per asset id.