@@ -29,8 +29,8 @@ use chain::chaininterface::{BroadcasterInterface,ChainListener,FeeEstimator};
29
29
use chain:: transaction:: OutPoint ;
30
30
use ln:: channel:: { Channel , ChannelError } ;
31
31
use ln:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdateErr , ManyChannelMonitor , CLTV_CLAIM_BUFFER , LATENCY_GRACE_PERIOD_BLOCKS , ANTI_REORG_DELAY } ;
32
+ use ln:: features:: { InitFeatures , NodeFeatures } ;
32
33
use ln:: router:: Route ;
33
- use ln:: features:: InitFeatures ;
34
34
use ln:: msgs;
35
35
use ln:: onion_utils;
36
36
use ln:: msgs:: { ChannelMessageHandler , DecodeError , LightningError } ;
@@ -368,6 +368,10 @@ pub struct ChannelManager<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref,
368
368
channel_state : Mutex < ChannelHolder < ChanSigner > > ,
369
369
our_network_key : SecretKey ,
370
370
371
+ /// Used to track the last value sent in a node_announcement "timestamp" field. We ensure this
372
+ /// value increases strictly since we don't assume access to a time source.
373
+ last_node_announcement_serial : AtomicUsize ,
374
+
371
375
/// The bulk of our storage will eventually be here (channels and message queues and the like).
372
376
/// If we are connected to a peer we always at least have an entry here, even if no channels
373
377
/// are currently open with that peer.
@@ -665,6 +669,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
665
669
} ) ,
666
670
our_network_key : keys_manager. get_node_secret ( ) ,
667
671
672
+ last_node_announcement_serial : AtomicUsize :: new ( 0 ) ,
673
+
668
674
per_peer_state : RwLock :: new ( HashMap :: new ( ) ) ,
669
675
670
676
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
@@ -1334,6 +1340,40 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
1334
1340
} )
1335
1341
}
1336
1342
1343
+ /// Generates a signed node_announcement from the given arguments and creates a
1344
+ /// BroadcastNodeAnnouncement event. Note that such messages will be ignored unless peers have
1345
+ /// seen a channel_announcement from us (ie unless we have public channels open).
1346
+ ///
1347
+ /// RGB is a node "color" and alias is a printable human-readable string to describe this node
1348
+ /// to humans. They carry no in-protocol meaning.
1349
+ ///
1350
+ /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
1351
+ /// incoming connections. These will be broadcast to the network, publicly tying these
1352
+ /// addresses together. If you wish to preserve user privacy, addresses should likely contain
1353
+ /// only Tor Onion addresses.
1354
+ pub fn broadcast_node_announcement ( & self , rgb : [ u8 ; 3 ] , alias : [ u8 ; 32 ] , addresses : msgs:: NetAddressSet ) {
1355
+ let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
1356
+
1357
+ let announcement = msgs:: UnsignedNodeAnnouncement {
1358
+ features : NodeFeatures :: supported ( ) ,
1359
+ timestamp : self . last_node_announcement_serial . fetch_add ( 1 , Ordering :: AcqRel ) as u32 ,
1360
+ node_id : self . get_our_node_id ( ) ,
1361
+ rgb, alias,
1362
+ addresses : addresses. into_vec ( ) ,
1363
+ excess_address_data : Vec :: new ( ) ,
1364
+ excess_data : Vec :: new ( ) ,
1365
+ } ;
1366
+ let msghash = hash_to_message ! ( & Sha256dHash :: hash( & announcement. encode( ) [ ..] ) [ ..] ) ;
1367
+
1368
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1369
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: BroadcastNodeAnnouncement {
1370
+ msg : msgs:: NodeAnnouncement {
1371
+ signature : self . secp_ctx . sign ( & msghash, & self . our_network_key ) ,
1372
+ contents : announcement
1373
+ } ,
1374
+ } ) ;
1375
+ }
1376
+
1337
1377
/// Processes HTLCs which are pending waiting on random forward delay.
1338
1378
///
1339
1379
/// Should only really ever be called in response to a PendingHTLCsForwardable event.
@@ -2970,6 +3010,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
2970
3010
& events:: MessageSendEvent :: SendShutdown { ref node_id, .. } => node_id != their_node_id,
2971
3011
& events:: MessageSendEvent :: SendChannelReestablish { ref node_id, .. } => node_id != their_node_id,
2972
3012
& events:: MessageSendEvent :: BroadcastChannelAnnouncement { .. } => true ,
3013
+ & events:: MessageSendEvent :: BroadcastNodeAnnouncement { .. } => true ,
2973
3014
& events:: MessageSendEvent :: BroadcastChannelUpdate { .. } => true ,
2974
3015
& events:: MessageSendEvent :: HandleError { ref node_id, .. } => node_id != their_node_id,
2975
3016
& events:: MessageSendEvent :: PaymentFailureNetworkUpdate { .. } => true ,
@@ -3288,6 +3329,8 @@ impl<ChanSigner: ChannelKeys + Writeable, M: Deref, T: Deref, K: Deref, F: Deref
3288
3329
peer_state. latest_features . write ( writer) ?;
3289
3330
}
3290
3331
3332
+ ( self . last_node_announcement_serial . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
3333
+
3291
3334
Ok ( ( ) )
3292
3335
}
3293
3336
}
@@ -3459,6 +3502,8 @@ impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: De
3459
3502
per_peer_state. insert ( peer_pubkey, Mutex :: new ( peer_state) ) ;
3460
3503
}
3461
3504
3505
+ let last_node_announcement_serial: u32 = Readable :: read ( reader) ?;
3506
+
3462
3507
let channel_manager = ChannelManager {
3463
3508
genesis_hash,
3464
3509
fee_estimator : args. fee_estimator ,
@@ -3478,6 +3523,8 @@ impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: De
3478
3523
} ) ,
3479
3524
our_network_key : args. keys_manager . get_node_secret ( ) ,
3480
3525
3526
+ last_node_announcement_serial : AtomicUsize :: new ( last_node_announcement_serial as usize ) ,
3527
+
3481
3528
per_peer_state : RwLock :: new ( per_peer_state) ,
3482
3529
3483
3530
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
0 commit comments