Refer to protocol design v0.4
The points i try to optimize are as follows:
-
Simplify on-chain interactions when unilateral closing channel
There are 5 stages in design v0.4: opening -> closing -> clearing -> finalized -> transfer-assets. When unilateral closing channel, 4 types of transactions and at least 4 transactions need be constructed and submitted.
I think it's possible to optimize it to: opening -> closing -> settlement, simplify the interaction flow.
-
Reduce on-chain data usage
Here are the details:
Open channel
- inputs
- capacity provide cell
- capacity: 100 CKB
- lockscript: A
- capacity provide cell
- capacity: 200 CKB
- lockscript: B
- other cells to provide channel cell capacity and tx fee
- outputs
- channel cell
- typescript: PCT
- args: channel-id
- lockscript: anyone-can-unlock
- data
- fixed
- pubkey_hashes: [pubkey_hash of A, pubkey_hash of B]
- closing_period: 1000
- dynamic
- state: OPENING
- version: 0
- balances: [100 CKB, 200 CKB]
- remaining_update_times: [5, 5]
- asset cell
- capacity: 300 CKB
- lockscript: PCL
The differences from v0.4:
- Remove
asset field. Because we already have asset cell, i think it's better to get asset-info from asset cell.
- Change
challenge_period and clear_period to closing_period, closing_period >= max(challenge_period, clear_period).
- Change
update_time_limit and update_times to remaining_update_times.
Unilateral close channel
-header_deps
- header_contains_htlc0_proof_cell
- cell_deps
- htlc0_proof_cell
- inputs
- old channel cell
- data
- dynamic
- state: OPENING
- version: 0
- balances: [100 CKB, 200 CKB]
- remaining_update_times: [5, 5]
- outputs
- new channel cell
- data
- dynamic
- state: CLOSING
- version: 100
- balances: [160 CKB, 100 CKB]
- htlcs_merkle_root
- proved_htlcs: 0x01
- remaining_update_times: [4, 5]
- witnesses
- UnilateralCloseChannel
- data
- channel_id
- version: 100
- balances: [50 CKB, 100 CKB]
- htlcs_merkle_root
- htlc0_merkle_proof
- to: 0
- amount: 110 CKB
- lock
- preimage_timeout: 100
- signatures
- submitter_signature of A
The differences from v0.4:
- Channel_cell_data will not record htlcs-info, but record htlcs_merkle_root and proved_htlcs(in case of duplicated proved_htlc) instead.
proved_htlcs records which htlcs have been proved by proof_cell, and the data type is bitmap(e.g. we have 8 htlcs, and htlcs[0, 2] have been proved, then the proved_htlcs is one byte 0x05).
- When submitting off-chain commitment, participant should include htlcs-prove-data(header_deps, cell_deps), and all-proved-htlcs will be settled directly(pay attention to tx_outputs/channel_cell_data/balances).
Counterparty update channel
-header_deps
- header_contains_htlc1_proof_cell
- cell_deps
- htlc1_proof_cell
- inputs
- old channel cell
- data
- dynamic
- state: CLOSING
- version: 100
- balances: [160 CKB, 100 CKB]
- htlcs_merkle_root
- proved_htlcs: 0x01
- remaining_update_times: [4, 5]
- outputs
- new channel cell
- data
- dynamic
- state: CLOSING
- version: 100
- balances: [160 CKB, 120 CKB]
- htlcs_merkle_root
- proved_htlcs: 0x03
- remaining_update_times: [4, 4]
- witnesses
- htlc1_merkle_proof
- to: 1
- amount: 20 CKB
- lock
- preimage_timeout: 100
- submitter_signature of B
The differences from v0.4:
- Participant B submitted htlc1_merkle_proof (Participiant A not submitted for B). And htlc1 was directly settled in this transaction(pay attention to tx_outputs/channel_cell_data/balances).
Settle channel
- inputs
- assets cell
- capacity: 300 CKB
- lock: PCL
- old channel cell
- since: after closing period
- data
- dynamic
- state: CLOSING
- version: 100
- balances: [160 CKB, 120 CKB]
- htlcs_merkle_root
- proved_htlcs: 0x03
- remaining_update_times: [4, 4]
- outputs
- asset cell 0
- capacity: 180 CKB
- asset cell 1
- capacity: 120 CKB
- witnesses
- htlc2_merkle_proof
- to: 1
- amount: 20 CKB
- lock
- preimage_timeout: 100
The differences from v0.4:
- After closing period, participant can settle channel.
- Unproved_htlcs(should refund) can be settled here. If assets cell are exhausted(all unproved_htlcs have been settled), the channel cell can be destroyed. Otherwise, tx ouputs should keep channel cell for the remaining unsettled unproved_htlcs.
The points i try to optimize are as follows:
Simplify on-chain interactions when unilateral closing channel
There are 5 stages in design v0.4: opening -> closing -> clearing -> finalized -> transfer-assets. When unilateral closing channel, 4 types of transactions and at least 4 transactions need be constructed and submitted.
I think it's possible to optimize it to: opening -> closing -> settlement, simplify the interaction flow.
Reduce on-chain data usage
Here are the details:
Open channel
The differences from v0.4:
assetfield. Because we already have asset cell, i think it's better to get asset-info from asset cell.challenge_periodandclear_periodtoclosing_period,closing_period>= max(challenge_period,clear_period).update_time_limitandupdate_timestoremaining_update_times.Unilateral close channel
The differences from v0.4:
proved_htlcsrecords which htlcs have been proved by proof_cell, and the data type is bitmap(e.g. we have 8 htlcs, and htlcs[0, 2] have been proved, then theproved_htlcsis one byte 0x05).Counterparty update channel
The differences from v0.4:
Settle channel
The differences from v0.4: