-
Notifications
You must be signed in to change notification settings - Fork 84
feat: Make Pallas WASM compatible #685
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: bkioshn <[email protected]>
Signed-off-by: bkioshn <[email protected]>
Signed-off-by: bkioshn <[email protected]>
Signed-off-by: bkioshn <[email protected]>
pallas-network topallas-primitives and remove redundant const in pallas-traverse|
Thanks @bkioshn, I agree with that this is something we need to support. The What would be the use case of having those constants available in a environment that doesn't support networking? |
We are using those constant network in our cardano-blockchain-types |
WalkthroughCentralizes network constants and Point into pallas-primitives, adds a new types module with CBOR Encode/Decode for Point, replaces in-crate constants with deprecated aliases to the new canonical definitions, adds pallas-primitives as a local dependency, and gates network/hardano exports behind a non-wasm cfg. Changes
Sequence Diagram(s)Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Areas to review closely:
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
pallas-primitives/src/types/point.rs (1)
52-68: Consider improving the error message.The decode error message at line 64 is incomplete: "can't decode Point from array of size" doesn't include the actual size that was encountered. While this is a minor issue, including the size would help debugging.
Consider this improvement:
_ => Err(decode::Error::message( - "can't decode Point from array of size", + &format!("can't decode Point from array of size {:?}", size), )),Note: This requires the error message to be a String rather than a &str. If
decode::Error::messageonly accepts&'static str, you might need to use a different error constructor or accept the current message.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
pallas-network/Cargo.toml(1 hunks)pallas-network/src/miniprotocols/common.rs(1 hunks)pallas-network/src/multiplexer.rs(1 hunks)pallas-primitives/src/lib.rs(1 hunks)pallas-primitives/src/types/mod.rs(1 hunks)pallas-primitives/src/types/network_constant.rs(1 hunks)pallas-primitives/src/types/point.rs(1 hunks)pallas-traverse/src/wellknown.rs(1 hunks)pallas/Cargo.toml(1 hunks)pallas/src/lib.rs(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
pallas-primitives/src/lib.rs (1)
pallas-traverse/src/witnesses.rs (1)
plutus_data(106-128)
pallas-primitives/src/types/point.rs (1)
pallas-primitives/src/lib.rs (4)
decode(181-189)decode(214-233)encode(193-203)encode(237-268)
🔇 Additional comments (14)
pallas-network/Cargo.toml (1)
19-19: LGTM! Dependency addition is correct.The addition of
pallas-primitivesas a dependency is necessary for the multiplexer to reference the canonical network constants and aligns with the overall goal of centralizing these definitions.pallas-primitives/src/lib.rs (1)
10-12: LGTM! Module structure is clean.The addition of the
typesmodule properly exposes the newnetwork_constantandpointsubmodules. The reordering of theplutus_datare-export has no functional impact.pallas-primitives/src/types/mod.rs (1)
1-2: LGTM! Module declarations are correct.Clean module structure exposing
network_constantandpoint.pallas-network/src/multiplexer.rs (1)
490-494: LGTM! Deprecation strategy is sound.The deprecation attribute provides a clear migration path, and the re-export ensures backward compatibility while pointing users to the canonical definition in
pallas_primitives.pallas/Cargo.toml (1)
24-26: LGTM! WASM gating is correctly implemented.Moving
pallas-networkandpallas-hardanoto target-specific dependencies for non-WASM targets is the correct approach to enable WASM compatibility while keeping these crates available for native builds.pallas-primitives/src/types/point.rs (2)
1-35: LGTM! Point type definition and helpers are well-designed.The
Pointenum withOriginandSpecificvariants is clean, and the helper methods (slot_or_default(),new()) provide good ergonomics. TheDebugimplementation with hex-encoded hash is appropriate for developer visibility.
37-50: LGTM! CBOR encoding is correctly implemented.The encoding matches the expected format:
Originas an empty array andSpecificas a 2-element array containing the slot and hash bytes.pallas/src/lib.rs (3)
12-13: LGTM! WASM gating is correctly applied.The conditional export of
pallas_networkfor non-WASM targets aligns with the dependency gating inpallas/Cargo.toml.
55-65: LGTM! Hardano module is properly gated.The WASM gating is correctly combined with the existing feature flag, ensuring the
hardanomodule is only available when both the feature is enabled and the target is not WASM.
71-76: LGTM! Storage export gating is consistent.The WASM gating on the deprecated
hardanostorage re-export maintains consistency with the changes to theinterop::hardanomodule.pallas-traverse/src/wellknown.rs (1)
4-31: Deprecation strategy verified and correct.All eight constants exist in
pallas_primitives::types::network_constant, are properly exported aspub const, and the re-exports inwellknown.rswill maintain the same values. The deprecation messages accurately guide users to the new location.pallas-network/src/miniprotocols/common.rs (3)
2-26: Network magic constants successfully migrated to pallas-primitives with backward-compatible deprecation wrappers.The deprecation pattern correctly re-exports constants from
pallas_primitives::types::network_constantand provides clear migration guidance. All new constants exist with correct values, and existing usage in tests and examples continues to work through the deprecated re-exports.
142-143: Point type re-export verified and correct.The Point type exists at
pallas_primitives::types::point::Pointas a public enum with variantsOriginandSpecific(u64, Vec<u8>). The re-export usingpub usewith deprecation is the appropriate pattern, and the API matches the usage throughout the codebase (verified in test files).
34-139: Protocol constants properly deprecated with verified migration path.All 15 protocol constants in
pallas-network/src/miniprotocols/common.rs(lines 34-139) are correctly deprecated with clear, actionable migration messages. Verification confirms:
- All target constants exist in
pallas_primitives::types::network_constant- Deprecation attributes are properly applied with consistent messaging
- Re-export pattern is correct and functional
Active usage throughout the codebase (106 instances in
facades.rsand other files) is expected during transition and will generate appropriate deprecation warnings to guide further migration.
Signed-off-by: bkioshn <[email protected]>
Signed-off-by: bkioshn <[email protected]>
Description
We are currently implementing Hermes WebAssembly (WASM) application engine designed to provide secure, sandboxed execution of modular applications. Because Hermes targets the WASM platform, it inherits WASM’s inherent limitations - that WASM modules cannot directly access operating system features such as I/O, networking, or threading.
The primary obstacle preventing the WASM module from importing Pallas (either directly or through transitive dependencies) is the
pallas-networkcrate. This crate relies on Tokio and socket APIs for networking, which are incompatible with the WASM environment. Meanwhile, Hermes requires certain constants and general-purpose types currently defined withinpallas-network. Attempting to importpallas-networkinto Hermes results in build failures due to these I/O and async runtime dependencies.To resolve this, we propose extracting these constants and primitive types into a existing crate,
pallas-primitive, which has no dependencies on Tokio or socket APIs. This restructuring allows Hermes to use the necessary shared definitions without bringing in incompatible code. Additionally, this PR includes cleanup of redundant types across the Pallas crates, improving overall code clarity and maintainability.In addiiton,
pallasitself, when import directly should be WASM compatible by disable some feature likepallas-hardanoandpallas-networkforwasmfamily architect.Summary of changes
Pointand constant out ofpallas-networktopallas-primitives. Note the old one as deprecatedpallas-traversepallas-networkandpallas-hardanowhen architect family iswasmSummary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.