Add SubQuery indexer for pallet-robonomics-cps#411
Closed
Copilot wants to merge 9 commits intorelease/4.1from
Closed
Add SubQuery indexer for pallet-robonomics-cps#411Copilot wants to merge 9 commits intorelease/4.1from
Copilot wants to merge 9 commits intorelease/4.1from
Conversation
* Initial plan * Implement pallet-robonomics-cps with core functionality Co-authored-by: akru <786394+akru@users.noreply.github.com> * Fix code review issues: assert_ok usage and weight calculations Co-authored-by: akru <786394+akru@users.noreply.github.com> * Change MaxSize to module-level constant and remove id fields from structs - Changed MaxSize from generic parameter to module-level constant ConstU32<2048> - Removed id field from Node struct (ID is DB-level only) - Removed id field from CryptoProfile struct (ID is DB-level only) - Removed MaxDataSize from Config trait (now using module constant) - Updated all type signatures to remove MaxSize generic parameter - All tests pass Co-authored-by: akru <786394+akru@users.noreply.github.com> * Cleanup * Refactor crypto profiles to use enum and add encrypted data tests - Changed crypto profile from storage-based ID system to CryptoAlgorithm enum - Removed CryptoProfiles and NextProfileId storage items - Removed create_crypto_profile extrinsic - Removed CryptoProfileNotFound and DataTooLarge errors - Updated NodeData to use CryptoAlgorithm::XChaCha20Poly1305 - Added comprehensive tests for encrypted node data (meta, payload, both) - Updated README with encryption examples and privacy model - Fixed README MaxDataSize documentation (2048 bytes) - Updated benchmarking and weights to remove crypto profile extrinsic - All 19 tests pass Co-authored-by: akru <786394+akru@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add delete_node extrinsic, storage version, and security improvements High Priority: - Added delete_node extrinsic with proper index cleanup - Added storage version v1 for future migrations - Added NodeHasChildren error for delete validation - Removed NodesByOwner storage (off-chain indexing) - Changed to Blake2_128Concat hasher for better security Changes: - New delete_node extrinsic validates ownership and prevents deletion of nodes with children - Storage version tracking enables safe future migrations - Blake2_128Concat provides cryptographic security vs Twox64Concat - Removed MaxNodesPerOwner config and TooManyNodesPerOwner error - Added 4 comprehensive delete_node tests (leaf, root, with children, non-owner) - Updated benchmarking and weights for delete_node - Updated README with security notes and delete_node documentation All 23 tests pass Co-authored-by: akru <786394+akru@users.noreply.github.com> * Store complete ancestor path in nodes to eliminate loops Performance improvement: - Added path field to Node struct storing complete ancestor path from root - Replaced loop-based is_ancestor() with O(1) path.contains() check - Replaced loop-based check_tree_depth() with O(1) path.len() check - Added update_descendant_paths() to recursively update paths after moves Benefits: - O(1) cycle detection during node moves - O(1) depth validation during node creation - No loop instructions in pallet logic - Predictable gas costs regardless of tree depth - Path automatically maintained during create and move operations Changes: - Node struct now generic over Config to access MaxTreeDepth - Path built incrementally during node creation - Path updated for entire subtree when node is moved - Replaced is_ancestor test with path_tracking test - Added move_node_updates_descendant_paths test All 24 tests pass Co-authored-by: akru <786394+akru@users.noreply.github.com> * Add SCALE compact encoding for node paths to reduce storage costs Storage optimization: - Implemented CompactNodePath wrapper type with custom SCALE encoding - Each NodeId in path encoded as Compact<u64> instead of plain u64 - Path length also encoded as compact - Manual Clone, Debug, Index implementations for CompactNodePath - Updated all path usage throughout the codebase Benefits: - 50-87% storage reduction for paths with small node IDs (< 2^14) - Typical path with 3 small IDs: ~6 bytes vs 24 bytes - No performance overhead - O(1) operations remain O(1) - Maintains all existing functionality Technical details: - Added Get trait import for generic bounds - CompactNodePath<S: Get<u32>> wraps BoundedVec<NodeId, S> - Custom Encode/Decode implementations use Compact wrapper - DecodeWithMemTracking derived automatically - All 24 tests pass All 24 tests pass Co-authored-by: akru <786394+akru@users.noreply.github.com> * Replace CompactNodePath with NodeId newtype for simpler compact encoding Simplified compact encoding approach: - Removed custom CompactNodePath wrapper type - Changed NodeId from type alias to newtype struct with #[codec(compact)] attribute - BoundedVec<NodeId> automatically uses compact encoding for each element - Added saturating_add method to NodeId for node ID increments - Added From<u64> and Into<u64> implementations for NodeId - Updated all tests to use NodeId(value) constructor Benefits: - Cleaner, more idiomatic Rust code - Leverages built-in SCALE codec compact support - No manual Encode/Decode implementations needed - Same storage savings (50-87% for small IDs) - Better type safety with newtype pattern - Simpler API - BoundedVec operations work directly Technical changes: - Added DecodeWithMemTracking derive to NodeId, CryptoAlgorithm, NodeData, and Node - Node.path changed from CompactNodePath<T::MaxTreeDepth> to BoundedVec<NodeId, T::MaxTreeDepth> - All test cases updated to use NodeId constructor - README updated to reflect newtype approach - All 24 tests pass Co-authored-by: akru <786394+akru@users.noreply.github.com> * Restructure documentation: conceptual README + technical lib.rs docs Improved documentation structure per @akru feedback: README.md (Conceptual): - Added real-world use cases (supply chain, smart city, medical devices) - Visual tree diagrams with ASCII art - Conceptual explanations of hierarchy benefits - Security guarantees and threat model - Storage efficiency tables with examples - Integration guide for runtime and dApp developers - Comparison with alternative approaches - Roadmap for future features lib.rs (Technical): - Comprehensive module-level documentation (120+ lines) - Architecture overview with storage layout - Performance characteristics analysis - Compact encoding details with tables - Usage examples with code snippets - Security invariants documentation - Query patterns and best practices - Detailed inline docs for all types with examples Benefits: - README now targets end-users and integrators - lib.rs targets developers working on/with the pallet - Clear separation of concerns - Better discoverability with examples - All 24 tests pass Co-authored-by: akru <786394+akru@users.noreply.github.com> * Fix benchmarking to use NodeId newtype wrapper consistently Updated all benchmarking code to use NodeId wrapper: - Changed raw integer literals (0, 1, 2) to NodeId(0), NodeId(1), NodeId(2) - Updated extrinsic call parameters to use NodeId wrapper - Updated storage access calls to use NodeId wrapper - Updated assertions to use NodeId wrapper for comparisons This ensures type safety and consistency with the NodeId newtype pattern used throughout the codebase. All 24 tests pass Co-authored-by: akru <786394+akru@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: akru <786394+akru@users.noreply.github.com> Co-authored-by: Alexander Krupenkin <mail@akru.me> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: akru <786394+akru@users.noreply.github.com>
Co-authored-by: akru <786394+akru@users.noreply.github.com>
Co-authored-by: akru <786394+akru@users.noreply.github.com>
Co-authored-by: akru <786394+akru@users.noreply.github.com>
Co-authored-by: akru <786394+akru@users.noreply.github.com>
Co-authored-by: akru <786394+akru@users.noreply.github.com>
Co-authored-by: akru <786394+akru@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add SubQuery indexer for pallet-robonomics-cps
Add SubQuery indexer for pallet-robonomics-cps
Nov 29, 2025
Member
|
Used #488 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a production-ready SubQuery indexer for the CPS pallet, exposing hierarchical node structures, ownership data, and audit trails via GraphQL.
Implementation
Event Handlers (5 total)
GraphQL Schema
Node: Hierarchical tree with parent-child relationships via auto-generatedparentIdNodeHistory: Audit log (action, block, timestamp, actor, values)OwnerIndex: O(1) owner → nodes mappingStatistics,DailyStats: Aggregated metricsType Safety
unwrapOption()helper for Substrate Option handlinglogger,store)Example Queries
Get tree structure with history:
Get all nodes by owner:
Project Structure
Notes
api.query.cps.nodes(nodeId)Deployment
Local:
npm run start:docker→ GraphQL at http://localhost:3000Production:
subql publish && subql deployment:deployOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.