@@ -1981,10 +1981,13 @@ where
19811981 }
19821982 }
19831983 NetworkActorCommand :: BroadcastMessages ( message) => {
1984- state
1985- . gossip_actor
1986- . send_message ( GossipActorMessage :: TryBroadcastMessages ( message) )
1987- . expect ( ASSUME_GOSSIP_ACTOR_ALIVE ) ;
1984+ if let Some ( ref gossip_actor) = state. gossip_actor {
1985+ gossip_actor
1986+ . send_message ( GossipActorMessage :: TryBroadcastMessages ( message) )
1987+ . expect ( ASSUME_GOSSIP_ACTOR_ALIVE ) ;
1988+ } else {
1989+ debug ! ( "Gossip actor is not available, skipping broadcast message" ) ;
1990+ }
19881991 }
19891992 NetworkActorCommand :: SendPayment ( payment_request, reply) => {
19901993 let payment_request = match payment_request. build_send_payment_data ( ) {
@@ -2679,7 +2682,8 @@ pub struct NetworkActorState<S, C> {
26792682 // The default tlc fee proportional millionths to be used when auto accepting a channel.
26802683 tlc_fee_proportional_millionths : u128 ,
26812684 // The gossip messages actor to process and send gossip messages.
2682- gossip_actor : ActorRef < GossipActorMessage > ,
2685+ // None if gossip is disabled via sync_network_graph config.
2686+ gossip_actor : Option < ActorRef < GossipActorMessage > > ,
26832687 max_inbound_peers : usize ,
26842688 min_outbound_peers : usize ,
26852689 // The features of the node, used to indicate the capabilities of the node.
@@ -3958,45 +3962,65 @@ where
39583962 let my_peer_id: PeerId = PeerId :: from ( secio_pk) ;
39593963 let handle = NetworkServiceHandle :: new ( myself. clone ( ) ) ;
39603964 let fiber_handle = FiberProtocolHandle :: from ( & handle) ;
3961- let mut gossip_config = GossipConfig :: from ( & config) ;
3962- gossip_config. peer_id = Some ( my_peer_id. clone ( ) ) ;
3963- let ( gossip_service, gossip_handle) = GossipService :: start (
3964- gossip_config,
3965- self . store . clone ( ) ,
3966- self . chain_actor . clone ( ) ,
3967- self . chain_client . clone ( ) ,
3968- myself. get_cell ( ) ,
3969- )
3970- . await ;
3971- let mut graph = self . network_graph . write ( ) . await ;
3972- let graph_subscribing_cursor = graph
3973- . get_latest_cursor ( )
3974- . go_back_for_some_time ( MAX_GRAPH_MISSING_BROADCAST_MESSAGE_TIMESTAMP_DRIFT ) ;
3975-
3976- gossip_service
3977- . get_subscriber ( )
3978- . subscribe ( graph_subscribing_cursor, myself. clone ( ) , |m| {
3979- Some ( NetworkActorMessage :: new_event (
3980- NetworkActorEvent :: GossipMessageUpdates ( m) ,
3981- ) )
3982- } )
3983- . await
3984- . expect ( "subscribe to gossip store updates" ) ;
3985- let gossip_actor = gossip_handle. actor ( ) . clone ( ) ;
3965+
3966+ // Conditionally start GossipService based on sync_network_graph config
3967+ let ( gossip_actor, gossip_handle_opt) = if config. sync_network_graph ( ) {
3968+ let mut gossip_config = GossipConfig :: from ( & config) ;
3969+ gossip_config. peer_id = Some ( my_peer_id. clone ( ) ) ;
3970+ let ( gossip_service, gossip_handle) = GossipService :: start (
3971+ gossip_config,
3972+ self . store . clone ( ) ,
3973+ self . chain_actor . clone ( ) ,
3974+ self . chain_client . clone ( ) ,
3975+ myself. get_cell ( ) ,
3976+ )
3977+ . await ;
3978+
3979+ let graph_subscribing_cursor = {
3980+ let graph = self . network_graph . write ( ) . await ;
3981+ graph
3982+ . get_latest_cursor ( )
3983+ . go_back_for_some_time ( MAX_GRAPH_MISSING_BROADCAST_MESSAGE_TIMESTAMP_DRIFT )
3984+ } ;
3985+
3986+ gossip_service
3987+ . get_subscriber ( )
3988+ . subscribe ( graph_subscribing_cursor, myself. clone ( ) , |m| {
3989+ Some ( NetworkActorMessage :: new_event (
3990+ NetworkActorEvent :: GossipMessageUpdates ( m) ,
3991+ ) )
3992+ } )
3993+ . await
3994+ . expect ( "subscribe to gossip store updates" ) ;
3995+ ( Some ( gossip_handle. actor ( ) . clone ( ) ) , Some ( gossip_handle) )
3996+ } else {
3997+ info ! ( "Gossip network synchronization is disabled (sync_network_graph = false)" ) ;
3998+ ( None , None )
3999+ } ;
4000+
4001+ // Build service with or without gossip protocol based on configuration
39864002 #[ cfg( not( target_arch = "wasm32" ) ) ]
3987- let mut service = ServiceBuilder :: default ( )
3988- . insert_protocol ( fiber_handle. create_meta ( ) )
3989- . insert_protocol ( gossip_handle. create_meta ( ) )
3990- . handshake_type ( secio_kp. into ( ) )
3991- . build ( handle) ;
4003+ let mut service = {
4004+ let mut builder = ServiceBuilder :: default ( )
4005+ . insert_protocol ( fiber_handle. create_meta ( ) )
4006+ . handshake_type ( secio_kp. into ( ) ) ;
4007+ if let Some ( gossip_handle) = gossip_handle_opt {
4008+ builder = builder. insert_protocol ( gossip_handle. create_meta ( ) ) ;
4009+ }
4010+ builder. build ( handle)
4011+ } ;
39924012 #[ cfg( target_arch = "wasm32" ) ]
3993- let mut service = ServiceBuilder :: default ( )
3994- . insert_protocol ( fiber_handle. create_meta ( ) )
3995- . insert_protocol ( gossip_handle. create_meta ( ) )
3996- . handshake_type ( secio_kp. into ( ) )
3997- // Sets forever to true so the network service won't be shutdown due to no incoming connections
3998- . forever ( true )
3999- . build ( handle) ;
4013+ let mut service = {
4014+ let mut builder = ServiceBuilder :: default ( )
4015+ . insert_protocol ( fiber_handle. create_meta ( ) )
4016+ . handshake_type ( secio_kp. into ( ) )
4017+ // Sets forever to true so the network service won't be shutdown due to no incoming connections
4018+ . forever ( true ) ;
4019+ if let Some ( gossip_handle) = gossip_handle_opt {
4020+ builder = builder. insert_protocol ( gossip_handle. create_meta ( ) ) ;
4021+ }
4022+ builder. build ( handle)
4023+ } ;
40004024
40014025 let mut announced_addrs = Vec :: with_capacity ( config. announced_addrs . len ( ) + 1 ) ;
40024026
@@ -4151,7 +4175,10 @@ where
41514175 } ;
41524176
41534177 let node_announcement = state. get_or_create_new_node_announcement_message ( ) ;
4154- graph. process_node_announcement ( node_announcement) ;
4178+ {
4179+ let mut graph = self . network_graph . write ( ) . await ;
4180+ graph. process_node_announcement ( node_announcement) ;
4181+ }
41554182 let announce_node_interval_seconds = config. announce_node_interval_seconds ( ) ;
41564183 if announce_node_interval_seconds > 0 {
41574184 myself. send_interval ( Duration :: from_secs ( announce_node_interval_seconds) , || {
0 commit comments