feat: delegation pallet storage refactor#226
Conversation
…rily remove benchmarks from peregrine runtime
|
pls merge develop! 😁 |
…a-delegation-refactoring
…a-delegation-refactoring
weichweich
left a comment
There was a problem hiding this comment.
didn't look at migrations.rs yet
| permissions, | ||
| revoked: false, | ||
| #[derive(Clone, Debug, Encode, Decode, PartialEq)] | ||
| pub struct DelegationDetails<T: Config> { |
There was a problem hiding this comment.
why do we move the details to a separate struct?
There was a problem hiding this comment.
Because I think it's easier to self-contain whatever does not belong to a node as such, such as a parent, an ID, and the children.
There was a problem hiding this comment.
So you would like to have an abstract tree and then just some content. I wouldn't call it DelegationTree then but Tree<Delegation> maybe there is already a tree implementation that we could use. 🤔
But i think it makes it not clearer and just adds one unnecessary step. 🤷🏻 But that is subjective.
There was a problem hiding this comment.
I don't think we need to have such a general implementation of a tree, but on the contrary I think that not having everything on the same level is a good idea.
There was a problem hiding this comment.
I think I couldn't convey my point so let me rephrase this.
In my opinion it's always a good idea to structure data when there is a category to structure them by. Eg. don't have x and y fields, but have a nested position field that has y and x. It makes sense to have position because it is a meaningful group for x and y.
Looking at the DelegationDetails it's not clear what this category is. What goes into details and what doesn't? details is not a real category. It's just a way of saying the number of fields in this struct was to high and i move it some where else.
But I think you actually split the fields by things that are relevant for the tree structure and things that are not relevant for the tree structure. So for me a meaningful category would be tree_content which makes only sense if you have a generic tree data structure.
For me it looks like the structure does more harm than it helps at the moment (especially DelegationHierarchyDetails which only has one field).
That said, this is my opinion and it's a style thing. So if i couldn't convince you go ahead and merge.
tl;dr; I fucking hate the word details! could be anything! What even are details?!
There was a problem hiding this comment.
I see your point, and I probably agree that details is not the best word. Plus, you got the point that my intention here is twofold:
- group everything that is tree-related and everything else that is not tree related. How could that be achieved in a different way that perhaps satisfies both preferences?
- for the hierarchy, it is true that for now it is just the CTYPE, but could be in future something else as well. And we would have to make it a struct anyway eventually, right? In order to avoid having tuples around. What would be your suggestion here?
There was a problem hiding this comment.
imHo i wouldn't have a nested structure here. 😅 If you prefer it nested, I don't see a better solution.
pallets/delegation/src/lib.rs
Outdated
| root_node_id: DelegationNodeIdOf<T>, | ||
| parent_id: DelegationNodeIdOf<T>, |
There was a problem hiding this comment.
would it be possible to pass a different root_node_id than the one that is stored in the parent? Since we always query the parent, no need to have the root node as a parameter?
wischli
left a comment
There was a problem hiding this comment.
Very minor things on the nitpick level. Otherwise, LGTM! Really like the updated approach. Looks much cleaner.
wischli
left a comment
There was a problem hiding this comment.
LGTM! I suppose Albi should still take a look once he's back.
weichweich
left a comment
There was a problem hiding this comment.
everything has been said!
…a-delegation-refactoring
…a-delegation-refactoring # Conflicts: # pallets/attestation/src/lib.rs # pallets/delegation/src/delegation_hierarchy.rs # pallets/delegation/src/lib.rs
* feat: initial commit * feat: pallet compiling * wip: fixing test cases * wip: refactoring test cases * test: unit tests passing again * benchmark tests passing * test: attestation unit tests passing * chore: clippy fixes * chore: fmt fixes * bench: re-execute benchmarks for delegation and attestation + temporarily remove benchmarks from peregrine runtime * fix: adjust pre-condition for an attestation unit test * wip: add initial support for delegation storage migrations * delegation storage migrator compiling * wip: storage migrator working, now writing unit tests for it * test: unit tests passing * chore: clippy hints * chore: further clippy fixes * chore: fmt * wip: adjusting last things before possible to review * chore: clippy + fmt * fix: address part of PR review comments * fix: more comments from PR review * wip: change vector of versions to enum * test: unit tests refactor for the new storage migrator version * chore: refactor * test: unit tests passing again * chore: move deprecated type to deprecated.rs * chore: refactor import/export * doc: refine documentation * chore: fmt + clippy * test: add TODO to improve post_migration tests * feat: remove test feature from traits * test: add checks during migration in try-runtime * bench: add spiritnet benchmarks for delegation and attestation * feat: additional logs for count of migrated nodes * chore: fmt * chore: removed useless file * chore: bump runtime version * fix: PR comments * fix: re-introduce root_id in delegation creation hash * chore: capitalize storage version enum * chore: move migrations in their own module * chore: move migrations.rs out of the migrations folder * fix: add check for parent revocation status when creating a delegation * chore: fmt * feat: remove revoke_hierarchy extrinsic * bench: add peregrine benchmarks * bench: re-run delegation and attestation default benchmarks * chore: fmt
* feat: initial commit * feat: pallet compiling * wip: fixing test cases * wip: refactoring test cases * test: unit tests passing again * benchmark tests passing * test: attestation unit tests passing * chore: clippy fixes * chore: fmt fixes * bench: re-execute benchmarks for delegation and attestation + temporarily remove benchmarks from peregrine runtime * fix: adjust pre-condition for an attestation unit test * wip: add initial support for delegation storage migrations * delegation storage migrator compiling * wip: storage migrator working, now writing unit tests for it * test: unit tests passing * chore: clippy hints * chore: further clippy fixes * chore: fmt * wip: adjusting last things before possible to review * chore: clippy + fmt * fix: address part of PR review comments * fix: more comments from PR review * wip: change vector of versions to enum * test: unit tests refactor for the new storage migrator version * chore: refactor * test: unit tests passing again * chore: move deprecated type to deprecated.rs * chore: refactor import/export * doc: refine documentation * chore: fmt + clippy * test: add TODO to improve post_migration tests * feat: remove test feature from traits * test: add checks during migration in try-runtime * bench: add spiritnet benchmarks for delegation and attestation * feat: additional logs for count of migrated nodes * chore: fmt * chore: removed useless file * chore: bump runtime version * fix: PR comments * fix: re-introduce root_id in delegation creation hash * chore: capitalize storage version enum * chore: move migrations in their own module * chore: move migrations.rs out of the migrations folder * fix: add check for parent revocation status when creating a delegation * chore: fmt * feat: remove revoke_hierarchy extrinsic * bench: add peregrine benchmarks * bench: re-run delegation and attestation default benchmarks * chore: fmt
* test: first unit tests passing after refactor * feat: refactor complete * feat: revert DID creation to old version and update test cases * fix: update test cases and benchmarks * wip: comment out current weights * feat: delegation pallet storage refactor (#226) * feat: initial commit * feat: pallet compiling * wip: fixing test cases * wip: refactoring test cases * test: unit tests passing again * benchmark tests passing * test: attestation unit tests passing * chore: clippy fixes * chore: fmt fixes * bench: re-execute benchmarks for delegation and attestation + temporarily remove benchmarks from peregrine runtime * fix: adjust pre-condition for an attestation unit test * wip: add initial support for delegation storage migrations * delegation storage migrator compiling * wip: storage migrator working, now writing unit tests for it * test: unit tests passing * chore: clippy hints * chore: further clippy fixes * chore: fmt * wip: adjusting last things before possible to review * chore: clippy + fmt * fix: address part of PR review comments * fix: more comments from PR review * wip: change vector of versions to enum * test: unit tests refactor for the new storage migrator version * chore: refactor * test: unit tests passing again * chore: move deprecated type to deprecated.rs * chore: refactor import/export * doc: refine documentation * chore: fmt + clippy * test: add TODO to improve post_migration tests * feat: remove test feature from traits * test: add checks during migration in try-runtime * bench: add spiritnet benchmarks for delegation and attestation * feat: additional logs for count of migrated nodes * chore: fmt * chore: removed useless file * chore: bump runtime version * fix: PR comments * fix: re-introduce root_id in delegation creation hash * chore: capitalize storage version enum * chore: move migrations in their own module * chore: move migrations.rs out of the migrations folder * fix: add check for parent revocation status when creating a delegation * chore: fmt * feat: remove revoke_hierarchy extrinsic * bench: add peregrine benchmarks * bench: re-run delegation and attestation default benchmarks * chore: fmt * fix: refine code after checking the changes * chore: update comments to reflect latest changes * bench: update benchmarks * chore: fmt * bench: add peregrine benchmarks * fix: add new DID weights to peregrine runtime * chore: bump runtime version * chore: fmt + clippy * chore: clippy * fix: test errors * fix: typo in docs * chore: remove useless elements in unit tests * feat: remove TryFrom for DidDetails * chore: fmt * fix: replace tuple with two parameters in from_creation_details
…unded versions (#228) * wip: use bounded vec in staking * fix: add try_insert_replace * fix: staking benchmarks * fix: migrations by adding deprecated * fix: clippy fix: clippy * refactor: apply migration structure from #226 * chore: add staking migration to v5 * chore: migrate to BoundedBTreeMap in staking * fix: remove v5 migration * chore: migrate UnlockingAt to BoundedVec * chore: use BoundedVec in DelegatedAttestations * refactor: align exceeded errors * feat: delegation pallet storage refactor (#226) * feat: initial commit * feat: pallet compiling * wip: fixing test cases * wip: refactoring test cases * test: unit tests passing again * benchmark tests passing * test: attestation unit tests passing * chore: clippy fixes * chore: fmt fixes * bench: re-execute benchmarks for delegation and attestation + temporarily remove benchmarks from peregrine runtime * fix: adjust pre-condition for an attestation unit test * wip: add initial support for delegation storage migrations * delegation storage migrator compiling * wip: storage migrator working, now writing unit tests for it * test: unit tests passing * chore: clippy hints * chore: further clippy fixes * chore: fmt * wip: adjusting last things before possible to review * chore: clippy + fmt * fix: address part of PR review comments * fix: more comments from PR review * wip: change vector of versions to enum * test: unit tests refactor for the new storage migrator version * chore: refactor * test: unit tests passing again * chore: move deprecated type to deprecated.rs * chore: refactor import/export * doc: refine documentation * chore: fmt + clippy * test: add TODO to improve post_migration tests * feat: remove test feature from traits * test: add checks during migration in try-runtime * bench: add spiritnet benchmarks for delegation and attestation * feat: additional logs for count of migrated nodes * chore: fmt * chore: removed useless file * chore: bump runtime version * fix: PR comments * fix: re-introduce root_id in delegation creation hash * chore: capitalize storage version enum * chore: move migrations in their own module * chore: move migrations.rs out of the migrations folder * fix: add check for parent revocation status when creating a delegation * chore: fmt * feat: remove revoke_hierarchy extrinsic * bench: add peregrine benchmarks * bench: re-run delegation and attestation default benchmarks * chore: fmt * chore: convert BTreeSet to bounded version in delegations * refactor: add missing const declarations * wip: migrate did pallet to bounded * fix: did tests * refactor: rm redundancy, improve mock by splitting * fix: clippy * docs: improve insertion attempt comments * fix: incorrect names in Debug * refactor: remove redundant isCandidate check * fix: migrate Url to BoundedVec * refactor: MaxPublicKeysPerDid * fix: bounds for did structs * refactor: apply shorter unlocking mutation * fix: remove unused pub * refactor: try_insert, try_upsert * fix: rm expect in delegator constructor * fix: allow delegator constructor to throw * refactor: apply suggestion for sort_greatest_to_lowest * refactor: remove deprecated in staking * fix: clippy * fix: split did::mock to make benchmarks work again * refactor: DidKeyAgreementKeys * chore: update benchmarks * chore: bump spec version to 20 Co-authored-by: Antonio <antonio@kilt.io>
fixes KILTProtocol/ticket#1451
fixes KILTProtocol/ticket#1476
fixes KILTProtocol/ticket#1478
This PR improves the efficiency of the delegation pallet's storage so that for most of the operations less DB reads and writes are performed. The base concept is the following:
DelegationNodesstorage entry.DelegationHierarchies, which maps from a root node ID to the details of a hierarchy, which at the moment only includes the CTYPE hash.create_roothas been renamed tocreate_hierarchy.How to test:
Run
cargo test --all --all-features --all-targets. Weights for the delegation pallets can also be compared with the currentdevelopversion to get an idea of the changed efficiency of the pallet.For a dry run of migration on the live peregrine parachain, run
Note
We decided to halt merging this PR until we are sure we can merge the updated SDK as well, so we avoid getting the new node version in the security audit but the SDK does not include the changes.
Custom types
KILTprotocol/type-definitions#10.
Checklist:
array[3]useget(3), ...)