-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Auto-incremental CollectionId #11796
Auto-incremental CollectionId #11796
Conversation
@jsidorenko Could you please review this? |
The general stuff in this PR is correct, but we need something to handle the fact that Statemine and Statemint already have various IDs at different values taken. I think a clean solution would be:
let me know if this makes sense. |
Ok, we could probably make a |
@Szegoo we should avoid loops in runtime code actually, so better it only increments once, and we call it multiple times. This is a weight / runtime safety consideration :) |
…o/substrate into autoincrement-collectionId
@shawntabrizi I have added |
@Szegoo i think you misunderstood the solution here. there should be a completely new extrinsic which does the Existing logic should just make sure that the next id to be used is not already in use. If it is in use, then the whole function fails, and the user must call |
Here is some pseudo code: next_id: u32;
#[call]
fn create_asset() {
// Make sure that the asset does not already exist before we try to create it
// If this check fails, the whole call fails, and the user must manually increment the next_id
ensure(!asset(next_id).exists());
do_create_asset();
next_id ++;
}
#[call]
fn try_increment_id() {
// Check the next id is ALREADY used. This means we are allowed to increment the id.
// If this check fails, then the next id is already available, and they should use `create_asset`
ensure(asset(next_id).exists());
next_id ++;
} |
@shawntabrizi I have fixed my code, I had a different idea so I did this in a totally different way. Now it is fixed, I am not done here, but I wanted you to check if this is what you wanted. I will add more tests, and I will run a benchmark to get the weight for the |
/tip medium |
@shawntabrizi A medium tip was successfully submitted for Szegoo (126X27SbhrV19mBFawys3ovkyBS87SGfYwtwa8J2FjHrtbmA on polkadot). https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/treasury/tips |
bot merge |
Error: "Check reviews" status is not passing for paritytech/cumulus#1460 |
It seems like the tip bot is getting the tip :P (https://www.dotreasury.com/dot/tips) |
bot merge |
Error: "Check reviews" status is not passing for paritytech/cumulus#1460 |
@shawntabrizi Should be able to merge now, the "Check reviews" is passing on the companion. |
@Szegoo thanks for the report, should be fixed now |
/tip medium |
@shawntabrizi A medium tip was successfully submitted for Szegoo (126X27SbhrV19mBFawys3ovkyBS87SGfYwtwa8J2FjHrtbmA on polkadot). https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/treasury/tips |
bot merge |
+ MaxEncodedLen | ||
+ Copy | ||
+ Default | ||
+ AtLeast32BitUnsigned; |
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.
@jsidorenko @Szegoo This trait bound here is breaking XCMv3, as we're using a MultiLocation
for the CollectionId
, which isn't an unsigned integer (but contains variants that can accept unsigned ints).
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.
@KiChjang Hmm, I will look more into this, but I am not even sure if it would be possible to have this auto-increment feature since as you said the MultiLocation
is used for CollectionId
, and not all variants store a uint.
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.
In that case, we should revert this change and really think about how exactly we should implement it. As it is, it's breaking code that was originally working without this PR.
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.
Looks like it is ordered, we could let the caller increment it off-chain.
PS: Not really, since the caller could set it to the highest value...
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.
Maybe we could for now make this feature optional for some chains that don't support XCM and don't use MultiLocation
for theCollectionId
.
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 will continue working on this in #12057
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.
Super! And pls point into js/uniques-v2-main-branch
afterwards
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 to make sure I understand this correctly, we should add an Incrementable
trait bound to the CollectionId
as I suggested earlier, so this means that we are not going to store this internal ref_id
field, right?
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.
This is how I understood it as well. @KiChjang Pls correct us if we're wrong
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.
That's correct, the idea is to let runtime configuration figure out what the next ID is, instead of having it become a concern for the uniques pallet itself.
* autoincrementing CollectionId * fix * benchmarking fix * fmt * fix * update before checking * fmt * fix * fmt * commit * tests & fix * fix * commit * docs * safe math * unexpose function * benchmark * fmt * better naming * fix? * merge fixes * fmt * ".git/.scripts/bench-bot.sh" pallet dev pallet_uniques * wrong weight * Update frame/uniques/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/uniques/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * using substrate trait instead of num-traits * remove unnecessary trait * emit NextCollectionIdIncremented in do_create_collection * fix in benchmarks * check for event & group import * docs Co-authored-by: Sergej Sakač <sergejsakac@Sergejs-MacBook-Air.local> Co-authored-by: command-bot <> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
* autoincrementing CollectionId * fix * benchmarking fix * fmt * fix * update before checking * fmt * fix * fmt * commit * tests & fix * fix * commit * docs * safe math * unexpose function * benchmark * fmt * better naming * fix? * merge fixes * fmt * ".git/.scripts/bench-bot.sh" pallet dev pallet_uniques * wrong weight * Update frame/uniques/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/uniques/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * using substrate trait instead of num-traits * remove unnecessary trait * emit NextCollectionIdIncremented in do_create_collection * fix in benchmarks * check for event & group import * docs Co-authored-by: Sergej Sakač <sergejsakac@Sergejs-MacBook-Air.local> Co-authored-by: command-bot <> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This PR solves the
auto-incremental collections ids
task from #11783cumulus companion: paritytech/cumulus#1460
polkadot address: 126X27SbhrV19mBFawys3ovkyBS87SGfYwtwa8J2FjHrtbmA