Skip to content

[TASK] Deterministic JobId for Service Pallet Blueprints #943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tracked by #947
shekohex opened this issue Mar 4, 2025 · 0 comments
Open
Tracked by #947

[TASK] Deterministic JobId for Service Pallet Blueprints #943

shekohex opened this issue Mar 4, 2025 · 0 comments
Assignees
Labels
Breaking Change Breaking change for any dependent apps (gadget, relayer etc..) feature ➕ Tasks that are functional additions or enhancements task ✔️

Comments

@shekohex
Copy link
Contributor

shekohex commented Mar 4, 2025

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:

  1. Jobs are not self-describing of their identity
  2. Job IDs are positional rather than content-based
  3. Job identity is dependent on deployment order
  4. Any change in the Vec order impacts all subsequent job IDs
  5. 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:

$$ \begin{aligned} & \text{let } H = \text{Keccak256 Hash function} \\ & \text{let FQN} = \text{Fully Qualified Name of Function} \\ & \text{let jobName} = \text{FQN(job)} \\ & \text{let args} = A \parallel B \parallel C ... \\ & \text{Then} \\ & \text{jobId} = H(\text{jobName} \parallel \text{args})[0..4] \end{aligned} $$

Where:

  • H is the Keccak256 hash function
  • FQN(job) is the fully qualified name of the function
  • args are the concatenated arguments
  • We take the first 4 bytes of the hash result

Technical Changes

Storage Changes

  1. Change job_id from u8 (1 byte) to u32 (4 bytes)
  2. Replace Vec<Job> with BTreeMap<u32, Job> for efficient job lookup

Blueprint SDK Changes

The Blueprint SDK will be updated to:

  1. Include methods to compute job IDs deterministically
  2. Enable direct job routing using these IDs
  3. Provide validation to ensure no job ID collisions within the same blueprint

Benefits

  1. Self-describing jobs: Each job computes its own ID based on its function name and parameters
  2. Stable IDs: Job IDs won't change when other jobs are added or removed
  3. Simplified development: No need to worry about job ordering
  4. Better integration with blueprint SDK: Direct routing to jobs
  5. More robust system: Reduced chances of errors from job position changes

Potential Challenges

  1. 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
  2. Backward compatibility: Existing blueprints will need updates, though there is no live production deployment of them yet.
  3. Documentation: Clear guidance will be needed on computing and using job IDs

Implementation Plan

  1. Create a prototype implementation
  2. Add tests for collision detection
  3. Update the blueprint SDK to support deterministic job IDs
  4. Update the runtime to support the new storage structure
  5. 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.

@shekohex shekohex added Breaking Change Breaking change for any dependent apps (gadget, relayer etc..) feature ➕ Tasks that are functional additions or enhancements task ✔️ labels Mar 4, 2025
@shekohex shekohex self-assigned this Mar 4, 2025
@github-project-automation github-project-automation bot moved this to Not Started 🕧 in Tangle Universe Mar 4, 2025
@shekohex shekohex moved this from Not Started 🕧 to Planning 🗺️ in Tangle Universe Mar 4, 2025
@drewstone drewstone moved this from Planning 🗺️ to Not Started 🕧 in Tangle Universe May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change Breaking change for any dependent apps (gadget, relayer etc..) feature ➕ Tasks that are functional additions or enhancements task ✔️
Projects
Status: Not Started 🕧
Development

No branches or pull requests

1 participant