feat!(cch): CCH multi-asset swap#1257
Open
doitian wants to merge 1 commit into
Open
Conversation
75583f0 to
f55b11f
Compare
2bdf38b to
8f188f6
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR moves CCH from a single wrapped-BTC assumption to a multi-asset swap model for native CKB and allowlisted UDTs. Although the PR description says “spec only,” the diff already includes the first implementation slice across CCH runtime logic, RPC/API types, persistence, and test/deploy tooling.
Changes:
- Generalizes CCH config, domain types, and actor logic around
fiber_type_script, asset allowlists, fixed-rate assets, and operator-approved proposal flows. - Adds operator-facing swap proposal RPC/subscription endpoints, auth rules, JSON conversions, and CCH tests for the new flow.
- Introduces persisted
CchOrdershape changes, a migration/schema update, and supporting deploy/Bruno/doc updates.
Reviewed changes
Copilot reviewed 25 out of 26 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
tests/nodes/deployer/config.yml |
Replaces single-asset CCH test config with allowlist/fixed-rate asset config. |
tests/deploy/udt-init/src/main.rs |
Patches deployed UDT code hashes into generated CCH node configs. |
tests/bruno/e2e/cross-chain-hub/02-create-send-btc-order.bru |
Adds fiber_type_script to integrated CCH Bruno send_btc request. |
tests/bruno/e2e/cross-chain-hub-separate/02-create-send-btc-order.bru |
Adds fiber_type_script to standalone CCH Bruno send_btc request. |
migrate/src/migrations/mod.rs |
Registers the new CCH multi-asset migration module. |
migrate/src/migrations/mig_20260421_cch_multi_asset.rs |
Migrates stored CCH orders to the new multi-asset layout. |
migrate/Cargo.toml |
Adds migration-only serde/CKB dependencies for the new order shape. |
migrate/Cargo.lock |
Locks the added migration dependencies. |
docs/specs/cch-multi-asset-swap.md |
Adds the multi-asset CCH spec and swap-acceptor protocol. |
crates/fiber-types/src/lib.rs |
Re-exports new CCH proposal-related types. |
crates/fiber-types/src/cch.rs |
Redefines CCH order/proposal domain types for multi-asset swaps. |
crates/fiber-lib/src/store/.schema.json |
Updates persisted schema fingerprints for CCH type changes. |
crates/fiber-lib/src/rpc/README.md |
Regenerates RPC docs for the new CCH APIs. |
crates/fiber-lib/src/rpc/cch.rs |
Adds swap proposal RPC/subscription methods and CCH RPC timeout changes. |
crates/fiber-lib/src/rpc/biscuit.rs |
Adds biscuit auth rules for operator acceptor RPCs. |
crates/fiber-lib/src/cch/tests/state_machine_tests.rs |
Updates state-machine tests for the new CCH order fields. |
crates/fiber-lib/src/cch/tests/scheduler_tests.rs |
Updates scheduler tests for the new CCH order layout. |
crates/fiber-lib/src/cch/tests/dispatcher_tests.rs |
Updates dispatcher tests for the new CCH order layout. |
crates/fiber-lib/src/cch/tests/actor_tests.rs |
Adds actor coverage for fixed-rate and proposal-path CCH behavior. |
crates/fiber-lib/src/cch/mod.rs |
Exports new CCH acceptor/config types. |
crates/fiber-lib/src/cch/error.rs |
Adds proposal-flow-specific CCH errors. |
crates/fiber-lib/src/cch/config.rs |
Replaces single-asset config with allowlist, fixed-rate, and proposal-timeout config. |
crates/fiber-lib/src/cch/actor.rs |
Implements multi-asset send/receive flows and operator proposal handling. |
crates/fiber-lib/src/cch/acceptor.rs |
Implements proposal broadcast, response handling, and timeout logic. |
crates/fiber-json-types/src/convert.rs |
Adds JSON conversion support for new CCH/proposal types. |
crates/fiber-json-types/src/cch.rs |
Defines new JSON-RPC params/responses for multi-asset CCH. |
fe29f52 to
f88f69a
Compare
761dcef to
6e4691b
Compare
6e4691b to
528c50a
Compare
Security ReviewResult: 1 confirmed finding Validation:
Notes:
|
b35547a to
6a3af83
Compare
8ba6f6b to
d8de227
Compare
8c2e4ea to
e775bc7
Compare
- Reshape CchOrder struct to support multiple Fiber-side assets * Replace `wrapped_btc_type_script: Script` with `fiber_type_script: Option<Script>` * Support both native CKB and allowlisted UDT assets * Separate BTC and Fiber amount fields with proper units - Implement per-asset fixed exchange rates - Add fiber-asset allowlist validation - Add CCH swap acceptor protocol implementation - Update RPC types and APIs to expose multi-asset swap capabilities - Update configuration to support multi-asset allowlist
e775bc7 to
8f6064a
Compare
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.
Summary
This PR delivers CCH multi-asset swap: a protocol specification plus the implementation that follows it. The cross-chain hub now swaps Lightning BTC against native CKB and allowlisted UDTs (not just a single wrapped-BTC UDT), and the operator-mediated proposal flow is asynchronous / fire-and-forget.
BREAKING: This PR contains database migration for CCH orders. Once merged and a new version is released, the migration should depend on the new version instead of the version in the workspace.
Specification
docs/specs/cch-multi-asset-swap.md:Implementation
Multi-asset CchOrder
cch/config.rs).CchOrderreshaped (fiber-types,fiber-json-types):fiber_type_script: Option<Script>, separate BTC and Fiber amount fields (btc_amount_msat,btc_fee_msat,fiber_amount_smallest_unit). The counterparty invoice (incoming_invoice: CchInvoice) is always present — the order is only created once the counterparty leg has been priced and its invoice minted.CchPendingProposalis a separate store record (not aCchOrderStatusvariant). It holds theSwapProposalplus the scaffolding needed to build aCchOrderwhen the operator accepts. NoCchOrderexists during the proposal phase.Async / fire-and-forget proposal flow
send_btc/receive_btcvalidate, persist aCchPendingProposalrecord, broadcast theSwapProposalto operator subscribers, and return immediately with aNewOrderResult::PendingProposal(SwapProposal). The client pollsget_cch_order.submit_swap_proposal_response: the actor mints the counterparty invoice, creates a newCchOrderwith statusPending, deletes theCchPendingProposalrecord, and starts the action flow. Reject/timeout deletes the proposal record — noCchOrderis ever created.CchPendingProposalrecord is re-broadcast and its timeout rescheduled to its deadline. Orders are resumed as usual viaResumeOrder.Arc<Mutex<HashSet<Hash256>>>inflight-hash mutex (the tokio shared-state antipattern). All order creation runs inline in the single-threaded actor mailbox, which naturally serializes same-hash requests. The swap acceptor is reduced to a pure pub/sub broadcaster; blockingcall_t!is replaced with fire-and-forget message passing.RPC
cch.rs: async/poll doc semantics;submit_swap_proposal_responseis now the resume path; reverted the inflated proposal-timeout mailbox window.rpc/README.md.Migration
crates/fiber-store/src/migrations/mig_20260610_cch_multi_asset.rs: migrates legacy single-assetCchOrderto the multi-asset shape in the new migration system (auto-registered viabuild.rs). Legacy orders are neverPendingProposal(that variant doesn't exist inCchOrderStatus).Tests / docs
cchactor/dispatcher/scheduler/state-machine tests to the async model (immediatePendingProposalreturn, operator response, poll for resolution, timeout → deleted, restart re-broadcast).store/.schema.json.Validation
cargo build -p fnn -p fiber-bin --features rocksdb✓cargo check --target wasm32-unknown-unknown -p fiber-store✓fiber-storetests,cchtests,make check-migrate, fmt/clippy/typos ✓