@@ -30,7 +30,7 @@ use bitcoin::secp256k1;
3030use bitcoin:: blockdata:: script:: Script ;
3131use bitcoin:: hash_types:: { Txid , BlockHash } ;
3232
33- use ln:: features:: { ChannelFeatures , InitFeatures , NodeFeatures } ;
33+ use ln:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
3434
3535use prelude:: * ;
3636use core:: { cmp, fmt} ;
@@ -148,6 +148,10 @@ pub struct OpenChannel {
148148 pub channel_flags : u8 ,
149149 /// Optionally, a request to pre-set the to-sender output's scriptPubkey for when we collaboratively close
150150 pub shutdown_scriptpubkey : OptionalField < Script > ,
151+ /// The channel type that this channel will represent. If none is set, we derive the channel
152+ /// type from the intersection of our feature bits with our counterparty's feature bits from
153+ /// the Init message.
154+ pub channel_type : Option < ChannelTypeFeatures > ,
151155}
152156
153157/// An accept_channel message to be sent or received from a peer
@@ -1162,7 +1166,9 @@ impl_writeable_msg!(OpenChannel, {
11621166 first_per_commitment_point,
11631167 channel_flags,
11641168 shutdown_scriptpubkey
1165- } , { } ) ;
1169+ } , {
1170+ ( 1 , channel_type, option) ,
1171+ } ) ;
11661172
11671173impl_writeable_msg ! ( RevokeAndACK , {
11681174 channel_id,
@@ -1747,8 +1753,9 @@ impl_writeable_msg!(GossipTimestampFilter, {
17471753mod tests {
17481754 use hex;
17491755 use ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
1756+ use ln:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
17501757 use ln:: msgs;
1751- use ln:: msgs:: { ChannelFeatures , FinalOnionHopData , InitFeatures , NodeFeatures , OptionalField , OnionErrorPacket , OnionHopDataFormat } ;
1758+ use ln:: msgs:: { FinalOnionHopData , OptionalField , OnionErrorPacket , OnionHopDataFormat } ;
17521759 use util:: ser:: { Writeable , Readable } ;
17531760
17541761 use bitcoin:: hashes:: hex:: FromHex ;
@@ -2052,7 +2059,7 @@ mod tests {
20522059 do_encoding_channel_update ( true , true , true , true ) ;
20532060 }
20542061
2055- fn do_encoding_open_channel ( random_bit : bool , shutdown : bool ) {
2062+ fn do_encoding_open_channel ( random_bit : bool , shutdown : bool , incl_chan_type : bool ) {
20562063 let secp_ctx = Secp256k1 :: new ( ) ;
20572064 let ( _, pubkey_1) = get_keys_from ! ( "0101010101010101010101010101010101010101010101010101010101010101" , secp_ctx) ;
20582065 let ( _, pubkey_2) = get_keys_from ! ( "0202020202020202020202020202020202020202020202020202020202020202" , secp_ctx) ;
@@ -2079,7 +2086,8 @@ mod tests {
20792086 htlc_basepoint : pubkey_5,
20802087 first_per_commitment_point : pubkey_6,
20812088 channel_flags : if random_bit { 1 << 5 } else { 0 } ,
2082- shutdown_scriptpubkey : if shutdown { OptionalField :: Present ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , key : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { OptionalField :: Absent }
2089+ shutdown_scriptpubkey : if shutdown { OptionalField :: Present ( Address :: p2pkh ( & :: bitcoin:: PublicKey { compressed : true , key : pubkey_1} , Network :: Testnet ) . script_pubkey ( ) ) } else { OptionalField :: Absent } ,
2090+ channel_type : if incl_chan_type { Some ( ChannelTypeFeatures :: empty ( ) ) } else { None } ,
20832091 } ;
20842092 let encoded_value = open_channel. encode ( ) ;
20852093 let mut target_value = Vec :: new ( ) ;
@@ -2093,15 +2101,22 @@ mod tests {
20932101 if shutdown {
20942102 target_value. append ( & mut hex:: decode ( "001976a91479b000887626b294a914501a4cd226b58b23598388ac" ) . unwrap ( ) ) ;
20952103 }
2104+ if incl_chan_type {
2105+ target_value. append ( & mut hex:: decode ( "0100" ) . unwrap ( ) ) ;
2106+ }
20962107 assert_eq ! ( encoded_value, target_value) ;
20972108 }
20982109
20992110 #[ test]
21002111 fn encoding_open_channel ( ) {
2101- do_encoding_open_channel ( false , false ) ;
2102- do_encoding_open_channel ( true , false ) ;
2103- do_encoding_open_channel ( false , true ) ;
2104- do_encoding_open_channel ( true , true ) ;
2112+ do_encoding_open_channel ( false , false , false ) ;
2113+ do_encoding_open_channel ( false , false , true ) ;
2114+ do_encoding_open_channel ( false , true , false ) ;
2115+ do_encoding_open_channel ( false , true , true ) ;
2116+ do_encoding_open_channel ( true , false , false ) ;
2117+ do_encoding_open_channel ( true , false , true ) ;
2118+ do_encoding_open_channel ( true , true , false ) ;
2119+ do_encoding_open_channel ( true , true , true ) ;
21052120 }
21062121
21072122 fn do_encoding_accept_channel ( shutdown : bool ) {
0 commit comments