Skip to content

Commit 82926a3

Browse files
committed
Add proper syncinc check
1 parent 0a2aed9 commit 82926a3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/ln/peer_handler.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ impl Peer {
109109
pub fn require_sync(&self)->bool{
110110
if let msgs::InitSyncTracker::Sync(i) = self.sync_status {i} else {false}
111111
}
112+
113+
/// this function checks if the the channel announcements and updates are allowed to be forwarded to a specific peer.
114+
/// If the peer is in syncing state and the channel_id has not been synced then the function returns false as this info will forward at a later stage and
115+
/// we dont want to send duplicate messages. If the channel was already synced then we can forward those messages and the function will then return true.
116+
pub fn is_channel_allowed_to_forward(&self, channel_id : u64)->bool{
117+
match self.sync_status {
118+
msgs::InitSyncTracker::Sync(i) => !i,
119+
msgs::InitSyncTracker::NodeCounter(_i) => false,
120+
msgs::InitSyncTracker::ChannelCounter(i) => (i < channel_id),
121+
}
122+
}
112123
}
113124

114125
struct PeerHolder<Descriptor: SocketDescriptor> {
@@ -904,7 +915,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
904915
let encoded_update_msg = encode_msg!(update_msg, 258);
905916

906917
for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
907-
if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_global_features.is_none() {
918+
if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_global_features.is_none() ||!peer.is_channel_allowed_to_forward(msg.short_channel_id) {
908919
continue
909920
}
910921
match peer.their_node_id {
@@ -927,7 +938,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
927938
let encoded_msg = encode_msg!(msg, 258);
928939

929940
for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
930-
if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_global_features.is_none() || peer.sync_status != msgs::InitSyncTracker::Sync(false) {
941+
if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_global_features.is_none() || !peer.is_channel_allowed_to_forward(msg.short_channel_id) {
931942
continue
932943
}
933944
peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_msg[..]));

0 commit comments

Comments
 (0)