From 6d7ae6e174fff61545d04b75b01c3cf36e9101c1 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 16 Feb 2022 21:34:16 +0000 Subject: [PATCH] Update channel-type implementation to upstream spec as merged Somehow, our channel type implementation doesn't echo back the channel type as we believe it was negotiated, as we should. Though the spec doesn't explicitly require this, some implementations may require it and it appears to have been in the BOLTs from the start of the channel type logic. --- lightning/src/ln/channel.rs | 11 +++++++++++ lightning/src/ln/msgs.rs | 13 +++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 8e8254bdf..2b03e2d42 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1895,6 +1895,16 @@ impl Channel { return Err(ChannelError::Close("Minimum confirmation depth must be at least 1".to_owned())); } + if let Some(ty) = &msg.channel_type { + if *ty != self.channel_type { + return Err(ChannelError::Close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned())); + } + } else if their_features.supports_channel_type() { + // Assume they've accepted the channel type as they said they understand it. + } else { + self.channel_type = ChannelTypeFeatures::from_counterparty_init(&their_features) + } + let counterparty_shutdown_scriptpubkey = if their_features.supports_upfront_shutdown_script() { match &msg.shutdown_scriptpubkey { &OptionalField::Present(ref script) => { @@ -4720,6 +4730,7 @@ impl Channel { Some(script) => script.clone().into_inner(), None => Builder::new().into_script(), }), + channel_type: Some(self.channel_type.clone()), } } diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 203e2426f..7233bed28 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -204,6 +204,12 @@ pub struct AcceptChannel { pub first_per_commitment_point: PublicKey, /// Optionally, a request to pre-set the to-sender output's scriptPubkey for when we collaboratively close pub shutdown_scriptpubkey: OptionalField