feat: support external wallet signing for channel funding#1120
Open
joii2020 wants to merge 34 commits intonervosnetwork:developfrom
Open
feat: support external wallet signing for channel funding#1120joii2020 wants to merge 34 commits intonervosnetwork:developfrom
joii2020 wants to merge 34 commits intonervosnetwork:developfrom
Conversation
d03759a to
7aac5c9
Compare
1dff6e5 to
8d284bd
Compare
1986689 to
654c2a4
Compare
Implement RPC endpoints that allow users to open payment channels by signing funding transactions with their own external wallets, instead of having the node automatically sign with its private key. New RPC methods: - open_channel_with_external_funding: negotiates channel with peer and returns unsigned funding tx for user to sign externally - submit_signed_funding_tx: accepts signed tx and completes channel opening Key changes: - Add AwaitingExternalFunding channel state for channels waiting for user signature - Add ExternalFundingTxBuilder to build unsigned funding transactions - Add BuildUnsignedFundingTx message to CKB chain actor - Add timeout mechanism for external funding (reuses existing funding timeout) - Update RPC documentation with new endpoints (cherry picked from commit f6f6dd2) Co-authored-by: Cursor <cursoragent@cursor.com>
…ingTxBuilder Extract duplicated methods into shared free functions: - collect_udt_inputs_outputs: UDT cell collection logic - build_base_from_funding_cell: common build_base_async logic - build_and_balance_tx: CKB RPC balance/unlock logic - finalize_funding_tx_update: FundingTx update + exclusion map This eliminates ~150 lines of duplicated code while keeping build_funding_cell separate since the two builders have legitimately different funding cell construction logic. Co-authored-by: Cursor <cursoragent@cursor.com>
Add clarifying comments to two independent fixes that were included in this branch but are unrelated to external funding: 1. restore_missing_revocation_send_nonce: fixes deadlock during channel reestablishment when send nonce is lost during persistence 2. On-the-fly channel reestablish in ChannelNormalOperation handler: prevents messages from being dropped after reconnect These should ideally be reviewed/cherry-picked separately. Co-authored-by: Cursor <cursoragent@cursor.com>
…ngth The assert!(data.as_ref().len() >= 16) in is_tx_final would panic if an externally-submitted funding transaction had malformed UDT output data. Replace with a proper InvalidParameter error return since this code path is now exposed to external input via external funding. Co-authored-by: Cursor <cursoragent@cursor.com>
Document why the runtime JS object patching is needed (CKB dep_type naming inconsistency between camelCase and snake_case across different SDKs/wallets) and add a TODO for a proper serde-layer fix. Co-authored-by: Cursor <cursoragent@cursor.com>
POSIX text files should end with a newline character. Co-authored-by: Cursor <cursoragent@cursor.com>
Move external funding runtime context out of ChannelActorState persistence and store it in ChannelEphemeralConfig, so open_channel_with_external_funding -> submit_signed_funding_tx no longer writes local channel state. Also keep ChannelState bincode compatibility by appending AwaitingExternalFunding variant, and update tests/samples accordingly.
…heck Replace panic-inducing assert! with a proper error return when UDT output data is shorter than expected. This prevents node crash when processing malformed transactions. This is an independent bug fix unrelated to external funding.
Fix a deadlock during channel reestablishment when the send nonce is lost during persistence (e.g., consumed before state was saved). Restore it from verify/next nonces if available. This is an independent bug fix unrelated to external funding.
If a channel message arrives for a channel not yet tracked in session_channels_map (e.g., after reconnect), attempt to reestablish it on-the-fly so the message is not dropped. This is an independent bug fix unrelated to external funding.
c5f9486 to
1b57d10
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.
Background
This PR is built on top of #1083.
Fiber currently relies on a CKB private key for initialization and transaction signing, but most Web Wallets do not support private key export.
This PR adds support for opening channels with externally signed funding transactions.
Changes
open_channel_with_external_fundingsubmit_signed_funding_txopen_channel_with_external_fundingnow returnstemporary_channel_idandunsigned_funding_txsubmit_signed_funding_txopen_channel_with_external_funding+submit_signed_funding_tx).Impact
No change to the existing
open_channelflow; this only adds a new external-funding path.e2e test
Because an external signature is required, the e2e test is not placed in CI and can be executed manually:
Execute in another terminal:
# Need to wait for the node to be init ./tests/nodes/wait.sh ./tests/bruno/e2e/external-funding-open/run-success-flow.sh