-
Notifications
You must be signed in to change notification settings - Fork 33
Description
Summary
This RFC proposes replacing the current index-based job identification system with a deterministic hash-based JobId system. This change will make jobs self-identifying, simplify deployment, and improve the development experience.
Problem Statement
Currently, the Service Pallet identifies jobs by their index position in a Vec<Job> within a blueprint. This approach has limitations:
- Jobs are not self-describing of their identity
- Job IDs are positional rather than content-based
- Job identity is dependent on deployment order
- Any change in the Vec order impacts all subsequent job IDs
- Could introduce potential conflicts if multiple jobs have the same identifier in the blueprint code.
Proposal
We propose implementing a deterministic hashing mechanism for job identification similar to how EVM contracts handle function identification.
Deterministic JobId Generation
For each job, we will generate a deterministic hash as follows:
Where:
His the Keccak256 hash functionFQN(job)is the fully qualified name of the functionargsare the concatenated arguments- We take the first 4 bytes of the hash result
Technical Changes
Storage Changes
- Change job_id from u8 (1 byte) to u32 (4 bytes)
- Replace
Vec<Job>withBTreeMap<u32, Job>for efficient job lookup
Blueprint SDK Changes
The Blueprint SDK will be updated to:
- Include methods to compute job IDs deterministically
- Enable direct job routing using these IDs
- Provide validation to ensure no job ID collisions within the same blueprint
Benefits
- Self-describing jobs: Each job computes its own ID based on its function name and parameters
- Stable IDs: Job IDs won't change when other jobs are added or removed
- Simplified development: No need to worry about job ordering
- Better integration with blueprint SDK: Direct routing to jobs
- More robust system: Reduced chances of errors from job position changes
Potential Challenges
- Hash collisions: While unlikely with 4 bytes (≈4 billion possibilities) in the same blueprint, we should implement collision detection at build-time of the blueprint itself
- Backward compatibility: Existing blueprints will need updates, though there is no live production deployment of them yet.
- Documentation: Clear guidance will be needed on computing and using job IDs
Implementation Plan
- Create a prototype implementation
- Add tests for collision detection
- Update the blueprint SDK to support deterministic job IDs
- Update the runtime to support the new storage structure
- Update documentation and examples
Conclusion
Moving to deterministic job IDs will make the Service Pallet more robust, developer-friendly, and flexible. The proposed change aligns with best practices seen in other systems like EVM contracts and will improve the overall developer experience.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status