@@ -1520,3 +1520,133 @@ fn test_0conf_ann_sigs_racing_conf() {
15201520 let as_announcement = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
15211521 assert_eq ! ( as_announcement. len( ) , 1 ) ;
15221522}
1523+
1524+ #[ test]
1525+ fn test_channel_update_dont_forward_flag ( ) {
1526+ // Test that the `dont_forward` bit (bit 1 of message_flags) is set correctly:
1527+ // - For private channels: message_flags should have bit 1 set (value 3 = must_be_one + dont_forward)
1528+ // - For public channels: message_flags should NOT have bit 1 set (value 1 = must_be_one only)
1529+ let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
1530+ let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
1531+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
1532+ let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
1533+ let node_b_id = nodes[ 1 ] . node . get_our_node_id ( ) ;
1534+ let node_c_id = nodes[ 2 ] . node . get_our_node_id ( ) ;
1535+
1536+ // Create a public (announced) channel between nodes[0] and nodes[1]
1537+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 500_000_000 ) ;
1538+
1539+ // Create a private (unannounced) channel between nodes[1] and nodes[2]
1540+ create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 500_000_000 ) ;
1541+
1542+ // Get the channel details for both channels
1543+ let public_channel = nodes[ 0 ]
1544+ . node
1545+ . list_channels ( )
1546+ . into_iter ( )
1547+ . find ( |c| c. counterparty . node_id == node_b_id)
1548+ . unwrap ( ) ;
1549+ let private_channel = nodes[ 1 ]
1550+ . node
1551+ . list_channels ( )
1552+ . into_iter ( )
1553+ . find ( |c| c. counterparty . node_id == node_c_id)
1554+ . unwrap ( ) ;
1555+
1556+ // Verify is_announced correctly reflects the channel type
1557+ assert ! ( public_channel. is_announced, "Public channel should have is_announced = true" ) ;
1558+ assert ! ( !private_channel. is_announced, "Private channel should have is_announced = false" ) ;
1559+
1560+ // Trigger channel_update by changing config on the public channel
1561+ let mut new_config = public_channel. config . unwrap ( ) ;
1562+ new_config. forwarding_fee_base_msat += 10 ;
1563+ nodes[ 0 ]
1564+ . node
1565+ . update_channel_config ( & node_b_id, & [ public_channel. channel_id ] , & new_config)
1566+ . unwrap ( ) ;
1567+
1568+ // Get the channel_update for the public channel and verify dont_forward is NOT set
1569+ let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1570+ let public_channel_update = events
1571+ . iter ( )
1572+ . find_map ( |e| {
1573+ if let MessageSendEvent :: BroadcastChannelUpdate { ref msg, .. } = e {
1574+ Some ( msg. clone ( ) )
1575+ } else {
1576+ None
1577+ }
1578+ } )
1579+ . expect ( "Expected BroadcastChannelUpdate for public channel" ) ;
1580+ // message_flags should be 1 (only must_be_one bit set, dont_forward NOT set)
1581+ assert_eq ! (
1582+ public_channel_update. contents. message_flags & ( 1 << 1 ) ,
1583+ 0 ,
1584+ "Public channel update should NOT have dont_forward bit set"
1585+ ) ;
1586+ assert_eq ! (
1587+ public_channel_update. contents. message_flags & 1 ,
1588+ 1 ,
1589+ "Public channel update should have must_be_one bit set"
1590+ ) ;
1591+
1592+ // Trigger channel_update by changing config on the private channel
1593+ let mut new_config = private_channel. config . unwrap ( ) ;
1594+ new_config. forwarding_fee_base_msat += 10 ;
1595+ nodes[ 1 ]
1596+ . node
1597+ . update_channel_config ( & node_c_id, & [ private_channel. channel_id ] , & new_config)
1598+ . unwrap ( ) ;
1599+
1600+ // Get the channel_update for the private channel and verify dont_forward IS set
1601+ let private_channel_update =
1602+ get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendChannelUpdate , node_c_id) ;
1603+ // message_flags should have dont_forward bit set
1604+ assert_ne ! (
1605+ private_channel_update. contents. message_flags & ( 1 << 1 ) ,
1606+ 0 ,
1607+ "Private channel update should have dont_forward bit set"
1608+ ) ;
1609+ assert_eq ! (
1610+ private_channel_update. contents. message_flags & 1 ,
1611+ 1 ,
1612+ "Private channel update should have must_be_one bit set"
1613+ ) ;
1614+ }
1615+
1616+ #[ test]
1617+ fn test_unknown_channel_update_with_dont_forward_logs_debug ( ) {
1618+ use bitcoin:: constants:: ChainHash ;
1619+ use bitcoin:: secp256k1:: ecdsa:: Signature ;
1620+ use bitcoin:: secp256k1:: ffi:: Signature as FFISignature ;
1621+ use bitcoin:: Network ;
1622+
1623+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1624+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1625+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1626+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1627+
1628+ let unknown_scid = 42 ;
1629+ let msg = msgs:: ChannelUpdate {
1630+ signature : Signature :: from ( unsafe { FFISignature :: new ( ) } ) ,
1631+ contents : msgs:: UnsignedChannelUpdate {
1632+ chain_hash : ChainHash :: using_genesis_block ( Network :: Testnet ) ,
1633+ short_channel_id : unknown_scid,
1634+ timestamp : 0 ,
1635+ message_flags : 1 | ( 1 << 1 ) , // must_be_one + dont_forward
1636+ channel_flags : 0 ,
1637+ cltv_expiry_delta : 0 ,
1638+ htlc_minimum_msat : 0 ,
1639+ htlc_maximum_msat : msgs:: MAX_VALUE_MSAT ,
1640+ fee_base_msat : 0 ,
1641+ fee_proportional_millionths : 0 ,
1642+ excess_data : Vec :: new ( ) ,
1643+ } ,
1644+ } ;
1645+
1646+ nodes[ 0 ] . node . handle_channel_update ( nodes[ 1 ] . node . get_our_node_id ( ) , & msg) ;
1647+ nodes[ 0 ] . logger . assert_log_contains (
1648+ "lightning::ln::channelmanager" ,
1649+ "Received channel_update for unknown channel" ,
1650+ 1 ,
1651+ ) ;
1652+ }
0 commit comments