Skip to content

Commit 1e03d44

Browse files
committed
Explicit ordering of tx_signatures
The peer that sends `tx_signatures` first is taking a risk when they are contributing to the channel funding: the other peer may never send their `tx_signatures`, and the signer will need to double-spend themselves to ensure that their funds are not locked. The accepting node is more at risk here, as they don't choose who tries to open channels to them, whereas an opening node who detects a malicious accepting node can just go somewhere else to open a channel. Thus by default, the opener should send their `tx_signatures` first, unless they explicitly request the accepting node to go first because they are trying to coordinate multiparty tx construction.
1 parent 9a8c907 commit 1e03d44

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

02-peer-protocol.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,6 @@ the byte size of the input and output counts on the transaction to one (1).
381381
#### Requirements
382382

383383
The sending node:
384-
- if it has the lowest total satoshis contributed, as defined by total
385-
`tx_add_input` values, or both peers have contributed equal amounts
386-
but it has the lowest `node_id` (sorted lexicographically):
387-
- MUST transmit their `tx_signatures` first
388384
- MUST order the `witnesses` by the `serial_id` of the input they
389385
correspond to
390386
- `num_witnesses`s MUST equal the number of inputs they added
@@ -401,10 +397,6 @@ The receiving node:
401397

402398
#### Rationale
403399

404-
A strict ordering is used to decide which peer sends `tx_signatures` first.
405-
This prevents deadlocks where each peer is waiting for the other peer to
406-
send `tx_signatures`, and enables multiparty tx collaboration.
407-
408400
`witness_data` is the data for a witness element in a witness stack, not
409401
prefixed with its length (since it is already specified in the `len` field).
410402

@@ -1118,6 +1110,9 @@ This message initiates the v2 channel establishment workflow.
11181110
1. type: 2 (`require_confirmed_inputs`)
11191111
2. data:
11201112
* [`0*byte`:``]
1113+
1. type: 4 (`remote_tx_signatures_first`)
1114+
2. data:
1115+
* [`0*byte`:``]
11211116

11221117
Rationale and Requirements are the same as for [`open_channel`](#the-open_channel-message),
11231118
with the following additions.
@@ -1132,13 +1127,16 @@ The sending node:
11321127
- MUST set `funding_feerate_perkw` to the feerate for this transaction
11331128
- If it requires the receiving node to only use confirmed inputs:
11341129
- MUST set `require_confirmed_inputs`
1130+
- If it requires the accepting node to send their `tx_signatures` first:
1131+
- MUST set `remote_tx_signatures_first`
11351132

11361133
The receiving node:
11371134
- MAY fail the negotiation if:
11381135
- the `locktime` is unacceptable
11391136
- the `funding_feerate_perkw` is unacceptable
11401137
- MUST fail the negotiation if:
11411138
- `require_confirmed_inputs` is set but it cannot provide confirmed inputs
1139+
- `remote_tx_signatures_first` is set, but it doesn't want to sign first
11421140

11431141
#### Rationale
11441142

@@ -1169,6 +1167,19 @@ The sending node may require the other participant to only use confirmed inputs.
11691167
This ensures that the sending node doesn't end up paying the fees of a low
11701168
feerate unconfirmed ancestor of one of the other participant's inputs.
11711169

1170+
A strict ordering is used to decide which peer will send `tx_signatures` first,
1171+
based on whether `remote_tx_signatures_first` was set. This prevents deadlocks
1172+
where each peer is waiting for the other peer to send `tx_signatures`, and
1173+
enables multiparty tx collaboration. The opening node should set
1174+
`remote_tx_signatures_first` when they are batching multiple interactive-tx
1175+
sessions, as they will need to collect all signatures before forwarding
1176+
them. If the accepting node contributes to the channel funding, they are
1177+
taking a risk when they sign first: the opening node may never send their
1178+
`tx_signatures`, which forces the accepting node to eventually double-spend
1179+
themselves to avoid having their funds locked. The accepting node may be
1180+
willing to take that risk if they are paid for contributing to the channel
1181+
funding.
1182+
11721183
### The `accept_channel2` Message
11731184

11741185
This message contains information about a node and indicates its
@@ -1296,24 +1307,25 @@ The receiving node:
12961307
- MUST fail the negotiation
12971308
- if it has not already transmitted its `commitment_signed`:
12981309
- MUST send `commitment_signed`
1299-
- Otherwise:
1300-
- MUST send `tx_signatures` if it should sign first, as specified
1301-
in the [`tx_signatures` requirements](#the-tx_signatures-message)
13021310

13031311
#### Rationale
13041312

13051313
The first commitment transaction has no HTLCs.
13061314

13071315
### Sharing funding signatures: `tx_signatures`
13081316

1309-
After a valid `commitment_signed` has been received
1310-
from the peer and a `commitment_signed` has been sent, a peer:
1311-
- MUST transmit `tx_signatures` with their signatures for the funding
1312-
transaction, following the order specified in the
1313-
[`tx_signatures` requirements](#the-tx_signatures-message)
1317+
After a valid `commitment_signed` has been received from the peer and a
1318+
`commitment_signed` has been sent, peers exchange `tx_signatures` for the
1319+
funding transaction.
13141320

13151321
#### Requirements
13161322

1323+
The opening node, if it has not set `open_channel2.remote_tx_signatures_first`:
1324+
- MUST send `tx_signatures` first
1325+
1326+
The accepting node, if `open_channel2.remote_tx_signatures_first` was set:
1327+
- MUST send `tx_signatures` first
1328+
13171329
The sending node:
13181330
- MUST verify it has received a valid commitment signature from its peer
13191331
- MUST remember the details of this funding transaction
@@ -1331,9 +1343,6 @@ The receiving node:
13311343

13321344
#### Rationale
13331345

1334-
A peer sends their `tx_signatures` after receiving a valid `commitment_signed`
1335-
message, following the order specified in the [`tx_signatures` section](#the-tx_signatures-message).
1336-
13371346
In the case where a peer provides valid witness data that causes their paid
13381347
feerate to fall beneath the `open_channel2.funding_feerate_perkw`, the protocol
13391348
should be aborted and the channel should be double-spent when there is a

0 commit comments

Comments
 (0)