@@ -30,7 +30,7 @@ use bitcoin::secp256k1;
30
30
use bitcoin:: blockdata:: script:: Script ;
31
31
use bitcoin:: hash_types:: { Txid , BlockHash } ;
32
32
33
- use ln:: features:: { ChannelFeatures , InitFeatures , NodeFeatures } ;
33
+ use ln:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
34
34
35
35
use prelude:: * ;
36
36
use core:: { cmp, fmt} ;
@@ -148,6 +148,10 @@ pub struct OpenChannel {
148
148
pub channel_flags : u8 ,
149
149
/// Optionally, a request to pre-set the to-sender output's scriptPubkey for when we collaboratively close
150
150
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 > ,
151
155
}
152
156
153
157
/// An accept_channel message to be sent or received from a peer
@@ -1162,7 +1166,9 @@ impl_writeable_msg!(OpenChannel, {
1162
1166
first_per_commitment_point,
1163
1167
channel_flags,
1164
1168
shutdown_scriptpubkey
1165
- } , { } ) ;
1169
+ } , {
1170
+ ( 1 , channel_type, option) ,
1171
+ } ) ;
1166
1172
1167
1173
impl_writeable_msg ! ( RevokeAndACK , {
1168
1174
channel_id,
@@ -1747,8 +1753,9 @@ impl_writeable_msg!(GossipTimestampFilter, {
1747
1753
mod tests {
1748
1754
use hex;
1749
1755
use ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
1756
+ use ln:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
1750
1757
use ln:: msgs;
1751
- use ln:: msgs:: { ChannelFeatures , FinalOnionHopData , InitFeatures , NodeFeatures , OptionalField , OnionErrorPacket , OnionHopDataFormat } ;
1758
+ use ln:: msgs:: { FinalOnionHopData , OptionalField , OnionErrorPacket , OnionHopDataFormat } ;
1752
1759
use util:: ser:: { Writeable , Readable } ;
1753
1760
1754
1761
use bitcoin:: hashes:: hex:: FromHex ;
@@ -2052,7 +2059,7 @@ mod tests {
2052
2059
do_encoding_channel_update ( true , true , true , true ) ;
2053
2060
}
2054
2061
2055
- fn do_encoding_open_channel ( random_bit : bool , shutdown : bool ) {
2062
+ fn do_encoding_open_channel ( random_bit : bool , shutdown : bool , chan_type : bool ) {
2056
2063
let secp_ctx = Secp256k1 :: new ( ) ;
2057
2064
let ( _, pubkey_1) = get_keys_from ! ( "0101010101010101010101010101010101010101010101010101010101010101" , secp_ctx) ;
2058
2065
let ( _, pubkey_2) = get_keys_from ! ( "0202020202020202020202020202020202020202020202020202020202020202" , secp_ctx) ;
@@ -2079,7 +2086,8 @@ mod tests {
2079
2086
htlc_basepoint : pubkey_5,
2080
2087
first_per_commitment_point : pubkey_6,
2081
2088
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 chan_type { Some ( ChannelTypeFeatures :: empty ( ) ) } else { None } ,
2083
2091
} ;
2084
2092
let encoded_value = open_channel. encode ( ) ;
2085
2093
let mut target_value = Vec :: new ( ) ;
@@ -2093,15 +2101,22 @@ mod tests {
2093
2101
if shutdown {
2094
2102
target_value. append ( & mut hex:: decode ( "001976a91479b000887626b294a914501a4cd226b58b23598388ac" ) . unwrap ( ) ) ;
2095
2103
}
2104
+ if chan_type {
2105
+ target_value. append ( & mut hex:: decode ( "0100" ) . unwrap ( ) ) ;
2106
+ }
2096
2107
assert_eq ! ( encoded_value, target_value) ;
2097
2108
}
2098
2109
2099
2110
#[ test]
2100
2111
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 ) ;
2105
2120
}
2106
2121
2107
2122
fn do_encoding_accept_channel ( shutdown : bool ) {
0 commit comments