From: Duncan Dean Date: Thu, 20 Oct 2022 20:56:37 +0000 (+0200) Subject: Add message structs required for dual-funded channels X-Git-Tag: v0.0.116-alpha1~48^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=adc1b55a6fa064852d838ceb91b11e6b228d169e;p=rust-lightning Add message structs required for dual-funded channels This is the first of a set of PRs to enable the experimental dual-funded channels feature using interactive transaction construction. This allows both the channel initiator and channel acceptor to contribute funds towards the channel. --- diff --git a/fuzz/src/msg_targets/gen_target.sh b/fuzz/src/msg_targets/gen_target.sh index 753a98325..00eb2ce65 100755 --- a/fuzz/src/msg_targets/gen_target.sh +++ b/fuzz/src/msg_targets/gen_target.sh @@ -33,8 +33,8 @@ GEN_TEST lightning::ln::msgs::UpdateFailHTLC test_msg_simple "" GEN_TEST lightning::ln::msgs::UpdateFailMalformedHTLC test_msg_simple "" GEN_TEST lightning::ln::msgs::UpdateFee test_msg_simple "" GEN_TEST lightning::ln::msgs::UpdateFulfillHTLC test_msg_simple "" +GEN_TEST lightning::ln::msgs::ChannelReestablish test_msg_simple "" -GEN_TEST lightning::ln::msgs::ChannelReestablish test_msg "" GEN_TEST lightning::ln::msgs::DecodedOnionErrorPacket test_msg "" GEN_TEST lightning::ln::msgs::ChannelAnnouncement test_msg_exact "" diff --git a/fuzz/src/msg_targets/msg_channel_reestablish.rs b/fuzz/src/msg_targets/msg_channel_reestablish.rs index 085755580..fdc2d1fa6 100644 --- a/fuzz/src/msg_targets/msg_channel_reestablish.rs +++ b/fuzz/src/msg_targets/msg_channel_reestablish.rs @@ -15,11 +15,11 @@ use crate::utils::test_logger; #[inline] pub fn msg_channel_reestablish_test(data: &[u8], _out: Out) { - test_msg!(lightning::ln::msgs::ChannelReestablish, data); + test_msg_simple!(lightning::ln::msgs::ChannelReestablish, data); } #[no_mangle] pub extern "C" fn msg_channel_reestablish_run(data: *const u8, datalen: usize) { let data = unsafe { std::slice::from_raw_parts(data, datalen) }; - test_msg!(lightning::ln::msgs::ChannelReestablish, data); + test_msg_simple!(lightning::ln::msgs::ChannelReestablish, data); } diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 4111f2fdc..3a324e6f4 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -5695,6 +5695,9 @@ impl Channel { next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.cur_counterparty_commitment_transaction_number - 1, your_last_per_commitment_secret: remote_last_secret, my_current_per_commitment_point: dummy_pubkey, + // TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction construction but have not received `tx_signatures` + // we MUST set `next_funding_txid` to the txid of that interactive transaction, else we MUST NOT set it. + next_funding_txid: None, } } diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index df6a2aba3..2124d9055 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -26,7 +26,7 @@ use bitcoin::secp256k1::PublicKey; use bitcoin::secp256k1::ecdsa::Signature; -use bitcoin::secp256k1; +use bitcoin::{secp256k1, Witness, Transaction}; use bitcoin::blockdata::script::Script; use bitcoin::hash_types::{Txid, BlockHash}; @@ -158,6 +158,8 @@ pub struct Pong { /// An [`open_channel`] message to be sent to or received from a peer. /// +/// Used in V1 channel establishment +/// /// [`open_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message #[derive(Clone, Debug, PartialEq, Eq)] pub struct OpenChannel { @@ -208,8 +210,69 @@ pub struct OpenChannel { pub channel_type: Option, } +/// An open_channel2 message to be sent by or received from the channel initiator. +/// +/// Used in V2 channel establishment +/// +// TODO(dual_funding): Add spec link for `open_channel2`. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct OpenChannelV2 { + /// The genesis hash of the blockchain where the channel is to be opened + pub chain_hash: BlockHash, + /// A temporary channel ID derived using a zeroed out value for the channel acceptor's revocation basepoint + pub temporary_channel_id: [u8; 32], + /// The feerate for the funding transaction set by the channel initiator + pub funding_feerate_sat_per_1000_weight: u32, + /// The feerate for the commitment transaction set by the channel initiator + pub commitment_feerate_sat_per_1000_weight: u32, + /// Part of the channel value contributed by the channel initiator + pub funding_satoshis: u64, + /// The threshold below which outputs on transactions broadcast by the channel initiator will be + /// omitted + pub dust_limit_satoshis: u64, + /// The maximum inbound HTLC value in flight towards channel initiator, in milli-satoshi + pub max_htlc_value_in_flight_msat: u64, + /// The minimum HTLC size incoming to channel initiator, in milli-satoshi + pub htlc_minimum_msat: u64, + /// The number of blocks which the counterparty will have to wait to claim on-chain funds if they + /// broadcast a commitment transaction + pub to_self_delay: u16, + /// The maximum number of inbound HTLCs towards channel initiator + pub max_accepted_htlcs: u16, + /// The locktime for the funding transaction + pub locktime: u32, + /// The channel initiator's key controlling the funding transaction + pub funding_pubkey: PublicKey, + /// Used to derive a revocation key for transactions broadcast by counterparty + pub revocation_basepoint: PublicKey, + /// A payment key to channel initiator for transactions broadcast by counterparty + pub payment_basepoint: PublicKey, + /// Used to derive a payment key to channel initiator for transactions broadcast by channel + /// initiator + pub delayed_payment_basepoint: PublicKey, + /// Used to derive an HTLC payment key to channel initiator + 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 + /// collaboratively close + pub shutdown_scriptpubkey: Option