From 2ddddbd7c2461610f17763bd8d306824ff42443c Mon Sep 17 00:00:00 2001 From: Duncan Dean Date: Wed, 29 Mar 2023 22:34:17 +0200 Subject: [PATCH] Use bitcoin wire encoding for witnesses --- 02-peer-protocol.md | 19 +++++++------------ 03-transactions.md | 30 ++++++++---------------------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/02-peer-protocol.md b/02-peer-protocol.md index aee5cd3..a7efe44 100644 --- a/02-peer-protocol.md +++ b/02-peer-protocol.md @@ -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 diff --git a/03-transactions.md b/03-transactions.md index fd3fa86..1437f8e 100644 --- a/03-transactions.md +++ b/03-transactions.md @@ -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" + }] } ```