1
0
Fork 0
mirror of https://github.com/lightning/bolts.git synced 2025-03-09 15:52:43 +01:00

Use bitcoin wire encoding for witnesses

This commit is contained in:
Duncan Dean 2023-03-29 22:34:17 +02:00 committed by neil saitug
parent c7af874f3d
commit 2ddddbd7c2
2 changed files with 15 additions and 34 deletions

View file

@ -388,14 +388,9 @@ the byte size of the input and output counts on the transaction to one (1).
* [`channel_id`:`channel_id`]
* [`sha256`:`txid`]
* [`u16`:`num_witnesses`]
* [`num_witnesses*witness_stack`:`witnesses`]
* [`num_witnesses*witness`:`witnesses`]
1. subtype: `witness_stack`
2. data:
* [`u16`:`num_witness_elements`]
* [`num_witness_elements*witness_element`:`witness_elements`]
1. subtype: `witness_element`
1. subtype: `witness`
2. data:
* [`u16`:`len`]
* [`len*byte`:`witness_data`]
@ -413,11 +408,11 @@ The sending node:
The receiving node:
- MUST fail the negotiation if:
- the message contains an empty `witness_stack`
- the message contains an empty `witness`
- the number of `witnesses` does not equal the number of inputs
added by the sending node
- the `txid` does not match the txid of the transaction
- the witnesses are non-standard
- the `witnesses` are non-standard
- SHOULD apply the `witnesses` to the transaction and broadcast it
- MUST reply with their `tx_signatures` if not already transmitted
@ -427,8 +422,8 @@ A strict ordering is used to decide which peer sends `tx_signatures` first.
This prevents deadlocks where each peer is waiting for the other peer to
send `tx_signatures`, and enables multiparty tx collaboration.
`witness_data` is the data for a witness element in a witness stack, not
prefixed with its length (since it is already specified in the `len` field).
The `witness_data` is encoded as per bitcoin's wire protocol (a CompactSize number
of elements, with each element a CompactSize length and that many bytes following).
While the `minimum fee` is calculated and verified at `tx_complete` conclusion,
it is possible for the fee for the exchanged witness data to be underpaid.
@ -1363,7 +1358,7 @@ The sending node:
- MUST NOT send a `tx_signatures` message
The receiving node:
- if the `witness_stack` weight lowers the effective `feerate`
- if the `witness` weight lowers the effective `feerate`
below the the *opener*'s feerate for the funding transaction:
- SHOULD broadcast their commitment transaction, closing the channel.
- SHOULD apply `witnesses` to the funding transaction and broadcast it

View file

@ -2940,17 +2940,10 @@ Opener's fees and change:
channel_id: xxx,
txid: "5ca4e657c1aa9d069ea4a5d712045d233a7d7c52738cb02993637289e6386057",
num_witnesses: 1,
witness_stack[{
num_input_witness: 2,
witness_element:[
{
len: 32,
witness: "68656c6c6f2074686572652c2074686973206973206120626974636f6e212121"
},{
len: 39,
witness: "82012088a820add57dfe5277079d069ca4ad4893c96de91f88ffb981fdc6a2a34d5336c66aff87"
}]
}]
witness[{
len: 74,
witness_data: "022068656c6c6f2074686572652c2074686973206973206120626974636f6e2121212782012088a820add57dfe5277079d069ca4ad4893c96de91f88ffb981fdc6a2a34d5336c66aff87"
}]
}
```
@ -2961,17 +2954,10 @@ Opener's fees and change:
channel_id: xxx,
txid: "5ca4e657c1aa9d069ea4a5d712045d233a7d7c52738cb02993637289e6386057",
num_witnesses: 1,
witness_stack[{
num_input_witness: 2,
witness_element:[
{
len: 71,
witness: "304402207de9ba56bb9f641372e805782575ee840a899e61021c8b1572b3ec1d5b5950e9022069e9ba998915dae193d3c25cb89b5e64370e6a3a7755e7f31cf6d7cbc2a49f6d01",
},{
len: 33,
witness: "034695f5b7864c580bf11f9f8cb1a94eb336f2ce9ef872d2ae1a90ee276c772484"
}]
}]
witness[{
len: 107,
witness_data: "0247304402207de9ba56bb9f641372e805782575ee840a899e61021c8b1572b3ec1d5b5950e9022069e9ba998915dae193d3c25cb89b5e64370e6a3a7755e7f31cf6d7cbc2a49f6d0121034695f5b7864c580bf11f9f8cb1a94eb336f2ce9ef872d2ae1a90ee276c772484"
}]
}
```