Skip to content

Commit

Permalink
f add require_confirmed_inputs and second_per_commitment_point fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dunxen committed Dec 23, 2022
1 parent f5f439e commit 43f2e77
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ pub struct OpenChannelV2 {
pub htlc_basepoint: PublicKey,
/// The first to-be-broadcast-by-channel-initiator transaction's per commitment point
pub first_per_commitment_point: PublicKey,
/// The second to-be-broadcast-by-channel-initiator transaction's per commitment point
pub second_per_commitment_point: PublicKey,
/// Channel flags
pub channel_flags: u8,
/// Optionally, a request to pre-set the to-channel-initiator output's scriptPubkey for when we
Expand All @@ -231,6 +233,8 @@ pub struct OpenChannelV2 {
/// type from the intersection of our feature bits with our counterparty's feature bits from
/// the Init message.
pub channel_type: Option<ChannelTypeFeatures>,
/// Optionally, a requirement that only confirmed inputs can be added
pub require_confirmed_inputs: Option<()>,
}

/// An accept_channel message to be sent or received from a peer.
Expand Down Expand Up @@ -1707,10 +1711,12 @@ impl_writeable_msg!(OpenChannelV2, {
delayed_payment_basepoint,
htlc_basepoint,
first_per_commitment_point,
second_per_commitment_point,
channel_flags,
shutdown_scriptpubkey
}, {
(1, channel_type, option),
(2, require_confirmed_inputs, option),
});

impl_writeable_msg!(RevokeAndACK, {
Expand Down Expand Up @@ -2690,14 +2696,15 @@ mod tests {
do_encoding_open_channel(true, true, true);
}

fn do_encoding_open_channelv2(random_bit: bool, shutdown: bool, incl_chan_type: bool) {
fn do_encoding_open_channelv2(random_bit: bool, shutdown: bool, incl_chan_type: bool, require_confirmed_inputs: bool) {
let secp_ctx = Secp256k1::new();
let (_, pubkey_1) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);
let (_, pubkey_2) = get_keys_from!("0202020202020202020202020202020202020202020202020202020202020202", secp_ctx);
let (_, pubkey_3) = get_keys_from!("0303030303030303030303030303030303030303030303030303030303030303", secp_ctx);
let (_, pubkey_4) = get_keys_from!("0404040404040404040404040404040404040404040404040404040404040404", secp_ctx);
let (_, pubkey_5) = get_keys_from!("0505050505050505050505050505050505050505050505050505050505050505", secp_ctx);
let (_, pubkey_6) = get_keys_from!("0606060606060606060606060606060606060606060606060606060606060606", secp_ctx);
let (_, pubkey_7) = get_keys_from!("0707070707070707070707070707070707070707070707070707070707070707", secp_ctx);
let open_channelv2 = msgs::OpenChannelV2 {
chain_hash: BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap(),
temporary_channel_id: [2; 32],
Expand All @@ -2716,14 +2723,33 @@ mod tests {
delayed_payment_basepoint: pubkey_4,
htlc_basepoint: pubkey_5,
first_per_commitment_point: pubkey_6,
second_per_commitment_point: pubkey_7,
channel_flags: if random_bit { 1 << 5 } else { 0 },
shutdown_scriptpubkey: if shutdown { OptionalField::Present(Address::p2pkh(&::bitcoin::PublicKey{compressed: true, inner: pubkey_1}, Network::Testnet).script_pubkey()) } else { OptionalField::Absent },
channel_type: if incl_chan_type { Some(ChannelTypeFeatures::empty()) } else { None },
require_confirmed_inputs: if require_confirmed_inputs { Some(()) } else { None },
};
let encoded_value = open_channelv2.encode();
let mut target_value = Vec::new();
target_value.append(&mut hex::decode("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f").unwrap());
target_value.append(&mut hex::decode("0202020202020202020202020202020202020202020202020202020202020202000c89d4000c89d412345678901234563214466870114476763303089620319800083a840000034dc0bcc0bc12345678031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap());
target_value.append(&mut hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap());
target_value.append(&mut hex::decode("000c89d4").unwrap());
target_value.append(&mut hex::decode("000c89d4").unwrap());
target_value.append(&mut hex::decode("1234567890123456").unwrap());
target_value.append(&mut hex::decode("3214466870114476").unwrap());
target_value.append(&mut hex::decode("7633030896203198").unwrap());
target_value.append(&mut hex::decode("00083a840000034d").unwrap());
target_value.append(&mut hex::decode("c0bc").unwrap());
target_value.append(&mut hex::decode("c0bc").unwrap());
target_value.append(&mut hex::decode("12345678").unwrap());
target_value.append(&mut hex::decode("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap());
target_value.append(&mut hex::decode("024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766").unwrap());
target_value.append(&mut hex::decode("02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337").unwrap());
target_value.append(&mut hex::decode("03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap());
target_value.append(&mut hex::decode("0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f7").unwrap());
target_value.append(&mut hex::decode("03f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap());
target_value.append(&mut hex::decode("02989c0b76cb563971fdc9bef31ec06c3560f3249d6ee9e5d83c57625596e05f6f").unwrap());

if random_bit {
target_value.append(&mut hex::decode("20").unwrap());
} else {
Expand All @@ -2735,19 +2761,30 @@ mod tests {
if incl_chan_type {
target_value.append(&mut hex::decode("0100").unwrap());
}
if require_confirmed_inputs {
target_value.append(&mut hex::decode("0200").unwrap());
}
assert_eq!(encoded_value, target_value);
}

#[test]
fn encoding_open_channelv2() {
do_encoding_open_channelv2(false, false, false);
do_encoding_open_channelv2(false, false, true);
do_encoding_open_channelv2(false, true, false);
do_encoding_open_channelv2(false, true, true);
do_encoding_open_channelv2(true, false, false);
do_encoding_open_channelv2(true, false, true);
do_encoding_open_channelv2(true, true, false);
do_encoding_open_channelv2(true, true, true);
do_encoding_open_channelv2(false, false, false, false);
do_encoding_open_channelv2(false, false, false, true);
do_encoding_open_channelv2(false, false, true, false);
do_encoding_open_channelv2(false, false, true, true);
do_encoding_open_channelv2(false, true, false, false);
do_encoding_open_channelv2(false, true, false, true);
do_encoding_open_channelv2(false, true, true, false);
do_encoding_open_channelv2(false, true, true, true);
do_encoding_open_channelv2(true, false, false, false);
do_encoding_open_channelv2(true, false, false, true);
do_encoding_open_channelv2(true, false, true, false);
do_encoding_open_channelv2(true, false, true, true);
do_encoding_open_channelv2(true, true, false, false);
do_encoding_open_channelv2(true, true, false, true);
do_encoding_open_channelv2(true, true, true, false);
do_encoding_open_channelv2(true, true, true, true);
}

fn do_encoding_accept_channel(shutdown: bool) {
Expand Down

0 comments on commit 43f2e77

Please sign in to comment.