]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add support for deserializing the new SCID alias in funding_locked
authorMatt Corallo <git@bluematt.me>
Sun, 29 Aug 2021 05:40:28 +0000 (05:40 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 21 Dec 2021 00:16:55 +0000 (00:16 +0000)
lightning/src/ln/channel.rs
lightning/src/ln/msgs.rs
lightning/src/util/ser.rs

index 2357c68f1a4612ab48679e8090463a31d9d85b39..60e162d5a4cfc473ca84eda4d0069bde4e91f5c0 100644 (file)
@@ -3361,6 +3361,7 @@ impl<Signer: Sign> Channel<Signer> {
                        Some(msgs::FundingLocked {
                                channel_id: self.channel_id(),
                                next_per_commitment_point,
+                               short_channel_id_alias: None,
                        })
                } else { None };
 
@@ -3582,6 +3583,7 @@ impl<Signer: Sign> Channel<Signer> {
                                funding_locked: Some(msgs::FundingLocked {
                                        channel_id: self.channel_id(),
                                        next_per_commitment_point,
+                                       short_channel_id_alias: None,
                                }),
                                raa: None, commitment_update: None, mon_update: None,
                                order: RAACommitmentOrder::CommitmentFirst,
@@ -3617,6 +3619,7 @@ impl<Signer: Sign> Channel<Signer> {
                        Some(msgs::FundingLocked {
                                channel_id: self.channel_id(),
                                next_per_commitment_point,
+                               short_channel_id_alias: None,
                        })
                } else { None };
 
@@ -4351,6 +4354,7 @@ impl<Signer: Sign> Channel<Signer> {
                                        return Some(msgs::FundingLocked {
                                                channel_id: self.channel_id,
                                                next_per_commitment_point,
+                                               short_channel_id_alias: None,
                                        });
                                }
                        } else {
index 39c00105f8d675e5cf5ce664b2d7416654c40cfb..c1f1bb5455b527e2a2bb54bccb753cf7177b7827 100644 (file)
@@ -40,7 +40,7 @@ use io_extras::read_to_end;
 
 use util::events::MessageSendEventsProvider;
 use util::logger;
-use util::ser::{Readable, Writeable, Writer, FixedLengthReader, HighZeroBytesDroppedVarInt};
+use util::ser::{U48, Readable, Writeable, Writer, FixedLengthReader, HighZeroBytesDroppedVarInt};
 
 use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
 
@@ -218,6 +218,9 @@ pub struct FundingLocked {
        pub channel_id: [u8; 32],
        /// The per-commitment point of the second commitment transaction
        pub next_per_commitment_point: PublicKey,
+       /// If set, provides a short_channel_id alias for this channel. The sender will accept payments
+       /// which are to be forwarded over this channel ID alias and forward them to us.
+       pub short_channel_id_alias: Option<U48>,
 }
 
 /// A shutdown message to be sent or received from a peer
@@ -1121,7 +1124,9 @@ impl_writeable_msg!(FundingSigned, {
 impl_writeable_msg!(FundingLocked, {
        channel_id,
        next_per_commitment_point,
-}, {});
+}, {
+       (1, short_channel_id_alias, option),
+});
 
 impl Writeable for Init {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
@@ -2190,6 +2195,7 @@ mod tests {
                let funding_locked = msgs::FundingLocked {
                        channel_id: [2; 32],
                        next_per_commitment_point: pubkey_1,
+                       short_channel_id_alias: None,
                };
                let encoded_value = funding_locked.encode();
                let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap();
index 6a52e5e1c898230c0d31a4cb9ce20c6acc236076..d10d1d332e6b056c6e37b8488a059cebe36e0083 100644 (file)
@@ -277,7 +277,19 @@ impl<T: MaybeReadable> Readable for VecReadWrapper<T> {
        }
 }
 
-pub(crate) struct U48(pub u64);
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+/// A 48-bit unsigned integer. This is used in lightning largely to represent the "short channel
+/// ID" values.
+pub struct U48(pub(crate) u64);
+impl U48 {
+       /// Construts a new U48 from a u64, checking that it is in range or returning `Err(())`
+       #[inline]
+       pub fn from_u64(src: u64) -> Result<Self, ()> {
+               if src < (1 << 48) - 1 { Ok(Self(src)) } else { Err(()) }
+       }
+       /// Gets the current value as a u64
+       pub fn as_u64(&self) -> u64 { self.0 }
+}
 impl Writeable for U48 {
        #[inline]
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {