Skip to content

Commit 6d7ae6e

Browse files
committed
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.
1 parent 92556c8 commit 6d7ae6e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,16 @@ impl<Signer: Sign> Channel<Signer> {
18951895
return Err(ChannelError::Close("Minimum confirmation depth must be at least 1".to_owned()));
18961896
}
18971897

1898+
if let Some(ty) = &msg.channel_type {
1899+
if *ty != self.channel_type {
1900+
return Err(ChannelError::Close("Channel Type in accept_channel didn't match the one sent in open_channel.".to_owned()));
1901+
}
1902+
} else if their_features.supports_channel_type() {
1903+
// Assume they've accepted the channel type as they said they understand it.
1904+
} else {
1905+
self.channel_type = ChannelTypeFeatures::from_counterparty_init(&their_features)
1906+
}
1907+
18981908
let counterparty_shutdown_scriptpubkey = if their_features.supports_upfront_shutdown_script() {
18991909
match &msg.shutdown_scriptpubkey {
19001910
&OptionalField::Present(ref script) => {
@@ -4720,6 +4730,7 @@ impl<Signer: Sign> Channel<Signer> {
47204730
Some(script) => script.clone().into_inner(),
47214731
None => Builder::new().into_script(),
47224732
}),
4733+
channel_type: Some(self.channel_type.clone()),
47234734
}
47244735
}
47254736

lightning/src/ln/msgs.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ pub struct AcceptChannel {
204204
pub first_per_commitment_point: PublicKey,
205205
/// Optionally, a request to pre-set the to-sender output's scriptPubkey for when we collaboratively close
206206
pub shutdown_scriptpubkey: OptionalField<Script>,
207+
/// The channel type that this channel will represent. If none is set, we derive the channel
208+
/// type from the intersection of our feature bits with our counterparty's feature bits from
209+
/// the Init message.
210+
///
211+
/// This is required to match the equivalent field in [`OpenChannel::channel_type`].
212+
pub channel_type: Option<ChannelTypeFeatures>,
207213
}
208214

209215
/// A funding_created message to be sent or received from a peer
@@ -1064,7 +1070,9 @@ impl_writeable_msg!(AcceptChannel, {
10641070
htlc_basepoint,
10651071
first_per_commitment_point,
10661072
shutdown_scriptpubkey
1067-
}, {});
1073+
}, {
1074+
(1, channel_type, option),
1075+
});
10681076

10691077
impl_writeable_msg!(AnnouncementSignatures, {
10701078
channel_id,
@@ -2191,7 +2199,8 @@ mod tests {
21912199
delayed_payment_basepoint: pubkey_4,
21922200
htlc_basepoint: pubkey_5,
21932201
first_per_commitment_point: pubkey_6,
2194-
shutdown_scriptpubkey: if shutdown { OptionalField::Present(Address::p2pkh(&::bitcoin::PublicKey{compressed: true, key: pubkey_1}, Network::Testnet).script_pubkey()) } else { OptionalField::Absent }
2202+
shutdown_scriptpubkey: if shutdown { OptionalField::Present(Address::p2pkh(&::bitcoin::PublicKey{compressed: true, key: pubkey_1}, Network::Testnet).script_pubkey()) } else { OptionalField::Absent },
2203+
channel_type: None,
21952204
};
21962205
let encoded_value = accept_channel.encode();
21972206
let mut target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020212345678901234562334032891223698321446687011447600083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap();

0 commit comments

Comments
 (0)