@@ -14,6 +14,7 @@ import (
14
14
"github.com/lightningnetwork/lnd/channeldb"
15
15
"github.com/lightningnetwork/lnd/lnpeer"
16
16
"github.com/lightningnetwork/lnd/lnwire"
17
+ "github.com/lightningnetwork/lnd/tlv"
17
18
"golang.org/x/time/rate"
18
19
)
19
20
@@ -1396,14 +1397,25 @@ func (g *GossipSyncer) FilterGossipMsgs(msgs ...msgWithSenders) {
1396
1397
endTime := startTime .Add (
1397
1398
time .Duration (g .remoteUpdateHorizon .TimestampRange ) * time .Second ,
1398
1399
)
1400
+
1401
+ var (
1402
+ startBlock tlv.RecordT [tlv.TlvType2 , uint32 ]
1403
+ endBlock tlv.RecordT [tlv.TlvType4 , uint32 ]
1404
+ )
1405
+ startBlock = g .remoteUpdateHorizon .FirstBlockHeight .UnwrapOr (startBlock )
1406
+ endBlock = g .remoteUpdateHorizon .BlockRange .UnwrapOr (endBlock )
1399
1407
g .Unlock ()
1400
1408
1401
- passesFilter := func (timeStamp uint32 ) bool {
1409
+ passesTimestampFilter := func (timeStamp uint32 ) bool {
1402
1410
t := time .Unix (int64 (timeStamp ), 0 )
1403
1411
return t .Equal (startTime ) ||
1404
1412
(t .After (startTime ) && t .Before (endTime ))
1405
1413
}
1406
1414
1415
+ passesBlockHeightFilter := func (height uint32 ) bool {
1416
+ return height >= startBlock .Val && height < endBlock .Val
1417
+ }
1418
+
1407
1419
msgsToSend := make ([]lnwire.Message , 0 , len (msgs ))
1408
1420
for _ , msg := range msgs {
1409
1421
// If the target peer is the peer that sent us this message,
@@ -1438,36 +1450,54 @@ func (g *GossipSyncer) FilterGossipMsgs(msgs ...msgWithSenders) {
1438
1450
}
1439
1451
1440
1452
for _ , chanUpdate := range chanUpdates {
1441
- update , ok := chanUpdate .(* lnwire. ChannelUpdate1 )
1442
- if ! ok {
1443
- log . Errorf ( "expected " +
1444
- "*lnwire.ChannelUpdate1, " +
1445
- "got: %T" , update )
1453
+ switch update := chanUpdate .(type ) {
1454
+ case * lnwire. ChannelUpdate1 :
1455
+ if passesTimestampFilter (
1456
+ update . Timestamp ,
1457
+ ) {
1446
1458
1447
- continue
1448
- }
1459
+ msgsToSend = append (
1460
+ msgsToSend , msg ,
1461
+ )
1449
1462
1450
- if passesFilter (update .Timestamp ) {
1451
- msgsToSend = append (msgsToSend , msg )
1452
- break
1463
+ break
1464
+ }
1465
+ case * lnwire.ChannelUpdate2 :
1466
+ if passesBlockHeightFilter (
1467
+ update .BlockHeight .Val ,
1468
+ ) {
1469
+
1470
+ msgsToSend = append (
1471
+ msgsToSend , msg ,
1472
+ )
1473
+
1474
+ break
1475
+ }
1453
1476
}
1454
1477
}
1455
1478
1456
1479
if len (chanUpdates ) == 0 {
1457
1480
msgsToSend = append (msgsToSend , msg )
1458
1481
}
1459
1482
1460
- // For each channel update, we'll only send if it the timestamp
1483
+ // For each channel update 1 , we'll only send if the timestamp
1461
1484
// is between our time range.
1462
1485
case * lnwire.ChannelUpdate1 :
1463
- if passesFilter (msg .Timestamp ) {
1486
+ if passesTimestampFilter (msg .Timestamp ) {
1487
+ msgsToSend = append (msgsToSend , msg )
1488
+ }
1489
+
1490
+ // For each channel update 2, we'll only send if the block
1491
+ // height is between our block range.
1492
+ case * lnwire.ChannelUpdate2 :
1493
+ if passesBlockHeightFilter (msg .BlockHeight .Val ) {
1464
1494
msgsToSend = append (msgsToSend , msg )
1465
1495
}
1466
1496
1467
1497
// Similarly, we only send node announcements if the update
1468
1498
// timestamp ifs between our set gossip filter time range.
1469
1499
case * lnwire.NodeAnnouncement1 :
1470
- if passesFilter (msg .Timestamp ) {
1500
+ if passesTimestampFilter (msg .Timestamp ) {
1471
1501
msgsToSend = append (msgsToSend , msg )
1472
1502
}
1473
1503
}
0 commit comments