@@ -863,9 +863,15 @@ fn assert_action_timeout_awaiting_response(action: &msgs::ErrorAction) {
863863 ) ) ;
864864}
865865
866+ pub enum ChanType {
867+ Legacy ,
868+ KeyedAnchors ,
869+ ZeroFeeCommitments ,
870+ }
871+
866872#[ inline]
867873pub fn do_test < Out : Output + MaybeSend + MaybeSync > (
868- data : & [ u8 ] , underlying_out : Out , anchors : bool ,
874+ data : & [ u8 ] , underlying_out : Out , chan_type : ChanType ,
869875) {
870876 let out = SearchingOutput :: new ( underlying_out) ;
871877 let broadcast_a = Arc :: new ( TestBroadcaster { txn_broadcasted : RefCell :: new ( Vec :: new ( ) ) } ) ;
@@ -926,8 +932,19 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
926932 config. channel_config. forwarding_fee_proportional_millionths = 0 ;
927933 config. channel_handshake_config. announce_for_forwarding = true ;
928934 config. reject_inbound_splices = false ;
929- if !anchors {
930- config. channel_handshake_config. negotiate_anchors_zero_fee_htlc_tx = false ;
935+ match chan_type {
936+ ChanType :: Legacy => {
937+ config. channel_handshake_config. negotiate_anchors_zero_fee_htlc_tx = false ;
938+ config. channel_handshake_config. negotiate_anchor_zero_fee_commitments = false ;
939+ } ,
940+ ChanType :: KeyedAnchors => {
941+ config. channel_handshake_config. negotiate_anchors_zero_fee_htlc_tx = true ;
942+ config. channel_handshake_config. negotiate_anchor_zero_fee_commitments = false ;
943+ } ,
944+ ChanType :: ZeroFeeCommitments => {
945+ config. channel_handshake_config. negotiate_anchors_zero_fee_htlc_tx = false ;
946+ config. channel_handshake_config. negotiate_anchor_zero_fee_commitments = true ;
947+ } ,
931948 }
932949 let network = Network :: Bitcoin ;
933950 let best_block_timestamp = genesis_block( network) . header. time;
@@ -978,8 +995,19 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
978995 config. channel_config . forwarding_fee_proportional_millionths = 0 ;
979996 config. channel_handshake_config . announce_for_forwarding = true ;
980997 config. reject_inbound_splices = false ;
981- if !anchors {
982- config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = false ;
998+ match chan_type {
999+ ChanType :: Legacy => {
1000+ config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = false ;
1001+ config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = false ;
1002+ } ,
1003+ ChanType :: KeyedAnchors => {
1004+ config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
1005+ config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = false ;
1006+ } ,
1007+ ChanType :: ZeroFeeCommitments => {
1008+ config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = false ;
1009+ config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = true ;
1010+ } ,
9831011 }
9841012
9851013 let mut monitors = new_hash_map ( ) ;
@@ -1078,8 +1106,23 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
10781106 } } ;
10791107 }
10801108 macro_rules! make_channel {
1081- ( $source: expr, $dest: expr, $source_monitor: expr, $dest_monitor: expr, $dest_keys_manager: expr, $chan_id: expr) => { {
1082- $source. create_channel( $dest. get_our_node_id( ) , 100_000 , 42 , 0 , None , None ) . unwrap( ) ;
1109+ ( $source: expr, $dest: expr, $source_monitor: expr, $dest_monitor: expr, $dest_keys_manager: expr, $chan_id: expr, $trusted_open: expr, $trusted_accept: expr) => { {
1110+ if $trusted_open {
1111+ $source
1112+ . create_channel_to_trusted_peer_0reserve(
1113+ $dest. get_our_node_id( ) ,
1114+ 100_000 ,
1115+ 42 ,
1116+ 0 ,
1117+ None ,
1118+ None ,
1119+ )
1120+ . unwrap( ) ;
1121+ } else {
1122+ $source
1123+ . create_channel( $dest. get_our_node_id( ) , 100_000 , 42 , 0 , None , None )
1124+ . unwrap( ) ;
1125+ }
10831126 let open_channel = {
10841127 let events = $source. get_and_clear_pending_msg_events( ) ;
10851128 assert_eq!( events. len( ) , 1 ) ;
@@ -1104,14 +1147,27 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
11041147 random_bytes
11051148 . copy_from_slice( & $dest_keys_manager. get_secure_random_bytes( ) [ ..16 ] ) ;
11061149 let user_channel_id = u128 :: from_be_bytes( random_bytes) ;
1107- $dest
1108- . accept_inbound_channel(
1109- temporary_channel_id,
1110- counterparty_node_id,
1111- user_channel_id,
1112- None ,
1113- )
1114- . unwrap( ) ;
1150+ if $trusted_accept {
1151+ $dest
1152+ . accept_inbound_channel_from_trusted_peer(
1153+ temporary_channel_id,
1154+ counterparty_node_id,
1155+ user_channel_id,
1156+ false ,
1157+ true ,
1158+ None ,
1159+ )
1160+ . unwrap( ) ;
1161+ } else {
1162+ $dest
1163+ . accept_inbound_channel(
1164+ temporary_channel_id,
1165+ counterparty_node_id,
1166+ user_channel_id,
1167+ None ,
1168+ )
1169+ . unwrap( ) ;
1170+ }
11151171 } else {
11161172 panic!( "Wrong event type" ) ;
11171173 }
@@ -1287,12 +1343,16 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
12871343 // Fuzz mode uses XOR-based hashing (all bytes XOR to one byte), and
12881344 // versions 0-5 cause collisions between A-B and B-C channel pairs
12891345 // (e.g., A-B with Version(1) collides with B-C with Version(3)).
1290- make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , monitor_a, monitor_b, keys_manager_b, 1 ) ;
1291- make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , monitor_a, monitor_b, keys_manager_b, 2 ) ;
1292- make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , monitor_a, monitor_b, keys_manager_b, 3 ) ;
1293- make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , monitor_b, monitor_c, keys_manager_c, 4 ) ;
1294- make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , monitor_b, monitor_c, keys_manager_c, 5 ) ;
1295- make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , monitor_b, monitor_c, keys_manager_c, 6 ) ;
1346+ // A-B: channel 2 A and B have 0-reserve (trusted open + trusted accept),
1347+ // channel 3 A has 0-reserve (trusted accept)
1348+ make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , monitor_a, monitor_b, keys_manager_b, 1 , false , false ) ;
1349+ make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , monitor_a, monitor_b, keys_manager_b, 2 , true , true ) ;
1350+ make_channel ! ( nodes[ 0 ] , nodes[ 1 ] , monitor_a, monitor_b, keys_manager_b, 3 , false , true ) ;
1351+ // B-C: channel 4 B has 0-reserve (via trusted accept),
1352+ // channel 5 C has 0-reserve (via trusted open)
1353+ make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , monitor_b, monitor_c, keys_manager_c, 4 , false , true ) ;
1354+ make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , monitor_b, monitor_c, keys_manager_c, 5 , true , false ) ;
1355+ make_channel ! ( nodes[ 1 ] , nodes[ 2 ] , monitor_b, monitor_c, keys_manager_c, 6 , false , false ) ;
12961356
12971357 // Wipe the transactions-broadcasted set to make sure we don't broadcast any transactions
12981358 // during normal operation in `test_return`.
@@ -2301,7 +2361,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
23012361
23022362 0x80 => {
23032363 let mut max_feerate = last_htlc_clear_fee_a;
2304- if !anchors {
2364+ if matches ! ( chan_type , ChanType :: Legacy ) {
23052365 max_feerate *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE as u32 ;
23062366 }
23072367 if fee_est_a. ret_val . fetch_add ( 250 , atomic:: Ordering :: AcqRel ) + 250 > max_feerate {
@@ -2316,7 +2376,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
23162376
23172377 0x84 => {
23182378 let mut max_feerate = last_htlc_clear_fee_b;
2319- if !anchors {
2379+ if matches ! ( chan_type , ChanType :: Legacy ) {
23202380 max_feerate *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE as u32 ;
23212381 }
23222382 if fee_est_b. ret_val . fetch_add ( 250 , atomic:: Ordering :: AcqRel ) + 250 > max_feerate {
@@ -2331,7 +2391,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(
23312391
23322392 0x88 => {
23332393 let mut max_feerate = last_htlc_clear_fee_c;
2334- if !anchors {
2394+ if matches ! ( chan_type , ChanType :: Legacy ) {
23352395 max_feerate *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE as u32 ;
23362396 }
23372397 if fee_est_c. ret_val . fetch_add ( 250 , atomic:: Ordering :: AcqRel ) + 250 > max_feerate {
@@ -2783,12 +2843,26 @@ impl<O: Output> SearchingOutput<O> {
27832843}
27842844
27852845pub fn chanmon_consistency_test < Out : Output + MaybeSend + MaybeSync > ( data : & [ u8 ] , out : Out ) {
2786- do_test ( data, out. clone ( ) , false ) ;
2787- do_test ( data, out, true ) ;
2846+ do_test ( data, out. clone ( ) , ChanType :: Legacy ) ;
2847+ do_test ( data, out. clone ( ) , ChanType :: KeyedAnchors ) ;
2848+ do_test ( data, out, ChanType :: ZeroFeeCommitments ) ;
27882849}
27892850
27902851#[ no_mangle]
27912852pub extern "C" fn chanmon_consistency_run ( data : * const u8 , datalen : usize ) {
2792- do_test ( unsafe { std:: slice:: from_raw_parts ( data, datalen) } , test_logger:: DevNull { } , false ) ;
2793- do_test ( unsafe { std:: slice:: from_raw_parts ( data, datalen) } , test_logger:: DevNull { } , true ) ;
2853+ do_test (
2854+ unsafe { std:: slice:: from_raw_parts ( data, datalen) } ,
2855+ test_logger:: DevNull { } ,
2856+ ChanType :: Legacy ,
2857+ ) ;
2858+ do_test (
2859+ unsafe { std:: slice:: from_raw_parts ( data, datalen) } ,
2860+ test_logger:: DevNull { } ,
2861+ ChanType :: KeyedAnchors ,
2862+ ) ;
2863+ do_test (
2864+ unsafe { std:: slice:: from_raw_parts ( data, datalen) } ,
2865+ test_logger:: DevNull { } ,
2866+ ChanType :: ZeroFeeCommitments ,
2867+ ) ;
27942868}
0 commit comments