Skip to content

Commit 0982df8

Browse files
feat(permission0): implement re-delegation for namespaces (#127)
This patch introduces the first version of namespace permission re-delegation. Closes CHAIN-107. # Interface Changes: Permission Redelegation and Cascading Revocation ## Extrinsic Signature Changes ### `delegate_namespace_permission` - BREAKING CHANGE ```rust // BEFORE pub fn delegate_namespace_permission( origin: OriginFor<T>, recipient: T::AccountId, paths: BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission>, duration: PermissionDuration<T>, revocation: RevocationTerms<T>, ) -> DispatchResult // AFTER pub fn delegate_namespace_permission( origin: OriginFor<T>, recipient: T::AccountId, paths: BoundedBTreeMap< Option<PermissionId>, // Parent permission (None for root) BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission>, T::MaxNamespacesPerPermission, >, // Now supports inheritance from parent permissions duration: PermissionDuration<T>, revocation: RevocationTerms<T>, instances: u32, // ADDED: Max re-delegation capacity ) -> DispatchResult ``` ## Structure Changes ### `PermissionContract<T>` - BREAKING CHANGES ```rust // BEFORE pub struct PermissionContract<T: Config> { ... pub parent: Option<PermissionId>, // REMOVED } // AFTER pub struct PermissionContract<T: Config> { ... pub max_instances: u32, // ADDED: Controls re-delegation capacity pub children: BoundedBTreeSet<H256, T::MaxChildrenPerPermission>, // ADDED: Enables cascading revocation } ``` ### `NamespaceScope<T>` - BREAKING CHANGE ```rust // BEFORE pub struct NamespaceScope<T: Config> { pub paths: BoundedBTreeSet<NamespacePath, T::MaxNamespacesPerPermission>, } // AFTER pub struct NamespaceScope<T: Config> { pub paths: BoundedBTreeMap< Option<PermissionId>, // Parent permission that granted these paths. // None if path belongs to delegator itself BoundedBTreeSet<NamespacePath, T::MaxNamespacesPerPermission>, T::MaxNamespacesPerPermission, >, } ``` ## Behavioral Changes ### Instance Management - `max_instances` controls how many child permissions can be created - Each child consumes instances from parent, preventing unlimited delegation ### Inheritance Validation - Child permissions must have weaker or equal revocation terms than parent - Namespace paths must be accessible through parent permissions - Supports granular delegation of more specific namespaces ### Cascading Revocation - Revoking a permission automatically revokes ALL child permissions recursively - Multiple `PermissionRevoked` events emitted for each revoked permission ## Migration Impact - All existing permissions get `max_instances = 1` and empty `children` set ## Client SDK Requirements 1. Update `delegate_namespace_permission` call construction 2. Handle new error variants in error handling 3. Update struct parsing for `PermissionContract` and `NamespaceScope` 4. Change event listening from `Permissiondelegated` to `PermissionDelegated` 5. Use accessor methods instead of direct field access 6. Implement cascading revocation event handling 7. Add hierarchy validation using `RevocationTerms::is_weaker()`
1 parent ab724df commit 0982df8

File tree

23 files changed

+2258
-701
lines changed

23 files changed

+2258
-701
lines changed

.zed/settings.json

Whitespace-only changes.

CLAUDE.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,36 @@ Torus is a stake-driven peer-to-peer network built on Substrate. The blockchain
2121
- **`governance`**: Proposals, voting, treasury, roles (allocators, curators)
2222
- **`permission0`**: Permission and access control
2323

24+
### Permission0 Pallet Structure
25+
26+
The `permission0` pallet manages delegated permissions and access control within the Torus network. Key components:
27+
28+
**Core Permission Types** (`pallets/permission0/src/permission.rs`):
29+
- `PermissionContract<T>` - Main permission structure with delegator, recipient, scope, duration, and enforcement
30+
- `PermissionId` - Unique permission identifier (H256 hash)
31+
- `PermissionScope<T>` - Defines what actions the permission covers
32+
- `NamespaceScope<T>` - Defines namespace path permissions for delegation
33+
34+
**Permission Scopes** (`pallets/permission0/src/permission/`):
35+
- `pallets/permission0/src/permission/curator.rs` - `CuratorPermissions` and `CuratorScope` types
36+
- `pallets/permission0/src/permission/emission.rs` - `EmissionAllocation`, `DistributionControl`, and `EmissionScope` types
37+
38+
**Implementation Handlers** (`pallets/permission0/src/ext/`):
39+
- `pallets/permission0/src/ext/curator_impl.rs` - Functions for curator permission enforcement
40+
- `pallets/permission0/src/ext/emission_impl.rs` - Functions for emission permission enforcement
41+
- `pallets/permission0/src/ext/namespace_impl.rs` - Functions for namespace permission enforcement
42+
2443
## Architecture Principles
2544

2645
- **API-first design**: Each pallet has separate `api` crate to prevent circular dependencies
2746
- **Domain separation**: Complex logic split into focused modules (agent.rs, stake.rs, etc.)
2847
- **Storage efficiency**: Use container types to minimize state size
2948
- **Zero-panic policy**: Runtime code must NEVER panic under any circumstances
3049

50+
## Project Structure
51+
52+
- All pallet tests are located within the /tests folder in each pallet's folder
53+
3154
## Essential Commands
3255

3356
```sh
@@ -152,4 +175,4 @@ cargo build --release # Build the node
152175
2. **MUST** run `just check` and fix all warnings
153176
3. **MUST** run `just test` and ensure all pass
154177
4. **MUST** run `cargo xtask coverage` to verify coverage
155-
5. **MUST** test runtime upgrades if storage changed
178+
5. **MUST** test runtime upgrades if storage changed

0 commit comments

Comments
 (0)