@@ -11,6 +11,7 @@ import (
11
11
"time"
12
12
13
13
"github.com/btcsuite/btcd/chaincfg/chainhash"
14
+ "github.com/lightningnetwork/lnd/fn"
14
15
"github.com/lightningnetwork/lnd/lnpeer"
15
16
"github.com/lightningnetwork/lnd/lnwire"
16
17
"golang.org/x/time/rate"
@@ -604,8 +605,12 @@ func (g *GossipSyncer) channelGraphSyncer() {
604
605
if g .localUpdateHorizon == nil &&
605
606
syncType .IsActiveSync () {
606
607
608
+ startBlock := g .cfg .bestHeight ()
609
+ blockRange := uint32 (math .MaxUint32 )
610
+
607
611
err := g .sendGossipTimestampRange (
608
612
time .Now (), math .MaxUint32 ,
613
+ & startBlock , & blockRange ,
609
614
)
610
615
if err != nil {
611
616
log .Errorf ("Unable to send update " +
@@ -672,12 +677,23 @@ func (g *GossipSyncer) replyHandler() {
672
677
// sendGossipTimestampRange constructs and sets a GossipTimestampRange for the
673
678
// syncer and sends it to the remote peer.
674
679
func (g * GossipSyncer ) sendGossipTimestampRange (firstTimestamp time.Time ,
675
- timestampRange uint32 ) error {
680
+ timestampRange uint32 , firstBlock , blockRange * uint32 ) error {
676
681
677
682
endTimestamp := firstTimestamp .Add (
678
683
time .Duration (timestampRange ) * time .Second ,
679
684
)
680
685
686
+ if firstBlock != nil && blockRange != nil {
687
+ log .Infof ("GossipSyncer(%x): applying " +
688
+ "gossipFilter(start-time=%v, end-time=%v, " +
689
+ "start-block=%v, block-range=%v)" , g .cfg .peerPub [:],
690
+ firstTimestamp , endTimestamp , * firstBlock , * blockRange )
691
+ } else {
692
+ log .Infof ("GossipSyncer(%x): applying " +
693
+ "gossipFilter(start-time=%v, end-time=%v" ,
694
+ g .cfg .peerPub [:], firstTimestamp , endTimestamp )
695
+ }
696
+
681
697
log .Infof ("GossipSyncer(%x): applying gossipFilter(start=%v, end=%v)" ,
682
698
g .cfg .peerPub [:], firstTimestamp , endTimestamp )
683
699
@@ -687,11 +703,22 @@ func (g *GossipSyncer) sendGossipTimestampRange(firstTimestamp time.Time,
687
703
TimestampRange : timestampRange ,
688
704
}
689
705
706
+ if firstBlock != nil {
707
+ localUpdateHorizon .FirstBlockHeight = fn .Some (* firstBlock )
708
+ }
709
+
710
+ if blockRange != nil {
711
+ localUpdateHorizon .BlockRange = fn .Some (* blockRange )
712
+ }
713
+
690
714
if err := g .cfg .sendToPeer (localUpdateHorizon ); err != nil {
691
715
return err
692
716
}
693
717
694
- if firstTimestamp == zeroTimestamp && timestampRange == 0 {
718
+ noTimeStamps := firstTimestamp == zeroTimestamp && timestampRange == 0
719
+ noBlockHeights := firstBlock == nil && blockRange == nil
720
+
721
+ if noTimeStamps && noBlockHeights {
695
722
g .localUpdateHorizon = nil
696
723
} else {
697
724
g .localUpdateHorizon = localUpdateHorizon
@@ -1511,6 +1538,8 @@ func (g *GossipSyncer) handleSyncTransition(req *syncTransitionReq) error {
1511
1538
var (
1512
1539
firstTimestamp time.Time
1513
1540
timestampRange uint32
1541
+ firstBlock * uint32
1542
+ blockRange * uint32
1514
1543
)
1515
1544
1516
1545
switch req .newSyncType {
@@ -1519,6 +1548,10 @@ func (g *GossipSyncer) handleSyncTransition(req *syncTransitionReq) error {
1519
1548
case ActiveSync , PinnedSync :
1520
1549
firstTimestamp = time .Now ()
1521
1550
timestampRange = math .MaxUint32
1551
+ bestHeight := g .cfg .bestHeight ()
1552
+ firstBlock = & bestHeight
1553
+ heightRange := uint32 (math .MaxUint32 )
1554
+ blockRange = & heightRange
1522
1555
1523
1556
// If a PassiveSync transition has been requested, then we should no
1524
1557
// longer receive any new updates from the remote peer. We can do this
@@ -1533,7 +1566,9 @@ func (g *GossipSyncer) handleSyncTransition(req *syncTransitionReq) error {
1533
1566
req .newSyncType )
1534
1567
}
1535
1568
1536
- err := g .sendGossipTimestampRange (firstTimestamp , timestampRange )
1569
+ err := g .sendGossipTimestampRange (
1570
+ firstTimestamp , timestampRange , firstBlock , blockRange ,
1571
+ )
1537
1572
if err != nil {
1538
1573
return fmt .Errorf ("unable to send local update horizon: %v" , err )
1539
1574
}
0 commit comments