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

Bug/93 update vec to bounded vec #95

Merged
merged 17 commits into from
May 3, 2022
Merged

Conversation

bmacer
Copy link
Contributor

@bmacer bmacer commented Mar 16, 2022

addresses #93. We may be able to alias some of the generics to make it a bit more readable, but this should pass tests for all of equip, market and core, and should successfully remove #[pallet::without_storage_info]

@bmacer bmacer requested a review from ilionic March 16, 2022 16:54
Copy link
Contributor

@ilionic ilionic left a comment

Choose a reason for hiding this comment

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

Great stuff, few minor comments.

pallets/rmrk-equip/src/tests.rs Outdated Show resolved Hide resolved
pallets/rmrk-equip/src/mock.rs Show resolved Hide resolved
@ilionic ilionic requested a review from HashWarlock March 18, 2022 11:44
Copy link
Contributor

@HashWarlock HashWarlock left a comment

Choose a reason for hiding this comment

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

No longer needed comments can be removed and one request on the burn_nft if it is plausible.

pallets/rmrk-equip/src/lib.rs Outdated Show resolved Hide resolved
pallets/rmrk-equip/src/lib.rs Outdated Show resolved Hide resolved
pallets/rmrk-core/src/functions.rs Outdated Show resolved Hide resolved
pallets/rmrk-core/src/functions.rs Outdated Show resolved Hide resolved
@bmacer bmacer requested review from HashWarlock and ilionic April 18, 2022 20:22
Copy link
Contributor

@HashWarlock HashWarlock left a comment

Choose a reason for hiding this comment

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

Remove unused code. I still think the drain_prefix should be used for the burn_nft function. Maybe @h4x3rotab can clarify if my suggestion is optimal in this situation. Overall looks good though just a few minor changes.

pallets/rmrk-core/src/lib.rs Outdated Show resolved Hide resolved
pallets/rmrk-core/src/lib.rs Outdated Show resolved Hide resolved
pallets/rmrk-core/src/functions.rs Outdated Show resolved Hide resolved
pallets/rmrk-equip/src/lib.rs Outdated Show resolved Hide resolved
pallets/rmrk-equip/src/mock.rs Outdated Show resolved Hide resolved
runtime/src/lib.rs Outdated Show resolved Hide resolved
runtime/src/lib.rs Outdated Show resolved Hide resolved
traits/src/collection.rs Outdated Show resolved Hide resolved
@bmacer
Copy link
Contributor Author

bmacer commented Apr 22, 2022

Remove unused code. I still think the drain_prefix should be used for the burn_nft function. Maybe @h4x3rotab can clarify if my suggestion is optimal in this situation. Overall looks good though just a few minor changes.

@HashWarlock fixed in 390f3c2
Couldn't add to burn_nft, because we need to iterate through in order to remove from the Children storage. but I implemented the drain_prefix inside that loop. Not sure if that's efficient enough, but that seems required, since we need to iterate through the Children in order to burn, for example, grandchildren.

Cleaned up all the dead code mentioned.

@bmacer bmacer requested a review from HashWarlock April 22, 2022 19:40
@HashWarlock
Copy link
Contributor

Remove unused code. I still think the drain_prefix should be used for the burn_nft function. Maybe @h4x3rotab can clarify if my suggestion is optimal in this situation. Overall looks good though just a few minor changes.

@HashWarlock fixed in 390f3c2 Couldn't add to burn_nft, because we need to iterate through in order to remove from the Children storage. but I implemented the drain_prefix inside that loop. Not sure if that's efficient enough, but that seems required, since we need to iterate through the Children in order to burn, for example, grandchildren.

Cleaned up all the dead code mentioned.

The drain_prefix iterates though so there's no need for the iter_prefix. At least this is what I see from the docs https://crates.parity.io/frame_support/storage/types/struct.StorageDoubleMap.html#method.drain_prefix

@bmacer
Copy link
Contributor Author

bmacer commented Apr 25, 2022

Remove unused code. I still think the drain_prefix should be used for the burn_nft function. Maybe @h4x3rotab can clarify if my suggestion is optimal in this situation. Overall looks good though just a few minor changes.

@HashWarlock fixed in 390f3c2 Couldn't add to burn_nft, because we need to iterate through in order to remove from the Children storage. but I implemented the drain_prefix inside that loop. Not sure if that's efficient enough, but that seems required, since we need to iterate through the Children in order to burn, for example, grandchildren.
Cleaned up all the dead code mentioned.

The drain_prefix iterates though so there's no need for the iter_prefix. At least this is what I see from the docs https://crates.parity.io/frame_support/storage/types/struct.StorageDoubleMap.html#method.drain_prefix

Right, but We need to iterate through the Children to get the Nfts to burn. We can use drain_prefix inside of this (and outside of it), but I don't see how to fully eliminate iter_prefix since we're using the data we're iterating through to drain other storages. Maybe I'm missing something?

Nfts::<T>::remove(collection_id, nft_id);
for _ in Resources::<T>::drain_prefix((collection_id, nft_id)) {}
for ((child_collection_id, child_nft_id), _) in Children::<T>::iter_prefix((collection_id, nft_id,)) {
for _ in Children::<T>::drain_prefix((collection_id, nft_id)) {}
Self::nft_burn(child_collection_id, child_nft_id, max_recursions - 1)?;
}
// decrement nfts counter
Collections::<T>::try_mutate(collection_id, |collection| -> DispatchResult {
let collection = collection.as_mut().ok_or(Error::<T>::CollectionUnknown)?;
collection.nfts_count.saturating_dec();
Ok(())
})?;

@HashWarlock
Copy link
Contributor

Remove unused code. I still think the drain_prefix should be used for the burn_nft function. Maybe @h4x3rotab can clarify if my suggestion is optimal in this situation. Overall looks good though just a few minor changes.

@HashWarlock fixed in 390f3c2 Couldn't add to burn_nft, because we need to iterate through in order to remove from the Children storage. but I implemented the drain_prefix inside that loop. Not sure if that's efficient enough, but that seems required, since we need to iterate through the Children in order to burn, for example, grandchildren.
Cleaned up all the dead code mentioned.

The drain_prefix iterates though so there's no need for the iter_prefix. At least this is what I see from the docs https://crates.parity.io/frame_support/storage/types/struct.StorageDoubleMap.html#method.drain_prefix

Right, but We need to iterate through the Children to get the Nfts to burn. We can use drain_prefix inside of this (and outside of it), but I don't see how to fully eliminate iter_prefix since we're using the data we're iterating through to drain other storages. Maybe I'm missing something?

Nfts::<T>::remove(collection_id, nft_id);
for _ in Resources::<T>::drain_prefix((collection_id, nft_id)) {}
for ((child_collection_id, child_nft_id), _) in Children::<T>::iter_prefix((collection_id, nft_id,)) {
for _ in Children::<T>::drain_prefix((collection_id, nft_id)) {}
Self::nft_burn(child_collection_id, child_nft_id, max_recursions - 1)?;
}
// decrement nfts counter
Collections::<T>::try_mutate(collection_id, |collection| -> DispatchResult {
let collection = collection.as_mut().ok_or(Error::<T>::CollectionUnknown)?;
collection.nfts_count.saturating_dec();
Ok(())
})?;

Maybe I'm confused. I was thinking this would be fine since we would get the child NFTs as we iterate the Children using drain_prefix. Then we call the burn_nft to take care of burning the children and their children as well. Does this cause problems with altering other storages?

 for ((child_collection_id, child_nft_id), _) in Children::<T>::drain_prefix((collection_id, nft_id,)) {  
 	Self::nft_burn(child_collection_id, child_nft_id, max_recursions - 1)?; 
 } 

@HashWarlock
Copy link
Contributor

I spoke with @h4x3rotab and the suggestion to replace iter_prefix with drain_prefix should suffice since we will be recursively calling the burn_nft function with the child NFT's collection id and nft id. He also noted that whenever we call drain_prefix without utilizing the Iterator that is returned then we can instead call remove_prefix.

Here is an example of this on line 319:

for _ in Resources::<T>::drain_prefix((collection_id, nft_id)) {}

Instead we can change it to this and avoid iterating through the Resources:

Resources::<T>::remove_prefix((collection_id, nft_id), None);

@ilionic
Copy link
Contributor

ilionic commented May 3, 2022

Will merge to avoid conflicts, if any adjustments required please create new issue.

@ilionic ilionic merged commit 83dab74 into main May 3, 2022
@ilionic ilionic deleted the bug/93-update-vec-to-bounded-vec branch May 3, 2022 07:32
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 this pull request may close these issues.

3 participants