@@ -1774,16 +1774,23 @@ out:
1774
1774
}
1775
1775
}
1776
1776
1777
- // TestSignatureAnnouncementFullProofWhenRemoteProof tests that if a remote
1777
+ // TestSignatureAnnouncementResendWhenRemoteProof tests that if a remote
1778
1778
// proof is received when we already have the full proof, the gossiper will send
1779
- // the full proof (ChannelAnnouncement) to the remote peer.
1780
- func TestSignatureAnnouncementFullProofWhenRemoteProof (t * testing.T ) {
1779
+ // our signature announcement max once per connection to the remote peer.
1780
+ func TestSignatureAnnouncementResendWhenRemoteProof (t * testing.T ) {
1781
1781
t .Parallel ()
1782
1782
ctx := context .Background ()
1783
1783
1784
1784
tCtx , err := createTestCtx (t , proofMatureDelta , false )
1785
1785
require .NoError (t , err , "can't create context" )
1786
1786
1787
+ // We'll create our test sync manager to have one active syncer.
1788
+ syncMgr := newTestSyncManager (1 )
1789
+ syncMgr .Start ()
1790
+ defer syncMgr .Stop ()
1791
+
1792
+ tCtx .gossiper .syncMgr = syncMgr
1793
+
1787
1794
batch , err := tCtx .createLocalAnnouncements (0 )
1788
1795
require .NoError (t , err , "can't generate announcements" )
1789
1796
@@ -1797,8 +1804,16 @@ func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
1797
1804
remoteKey , sentToPeer , tCtx .gossiper .quit , false ,
1798
1805
)
1799
1806
1807
+ // We create an active syncer for our remote peer.
1808
+ err = syncMgr .InitSyncState (remotePeer )
1809
+ require .NoError (t , err , "failed to init sync state" )
1810
+ remoteSyncer := assertSyncerExistence (t , syncMgr , remotePeer )
1811
+ assertTransitionToChansSynced (t , remoteSyncer , remotePeer )
1812
+ assertActiveGossipTimestampRange (t , remotePeer )
1813
+ assertSyncerStatus (t , remoteSyncer , chansSynced , ActiveSync )
1814
+
1800
1815
// Override NotifyWhenOnline to return the remote peer which we expect
1801
- // meesages to be sent to.
1816
+ // messages to be sent to.
1802
1817
tCtx .gossiper .reliableSender .cfg .NotifyWhenOnline = func (_ [33 ]byte ,
1803
1818
peerChan chan <- lnpeer.Peer ) {
1804
1819
@@ -1940,7 +1955,64 @@ func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
1940
1955
}
1941
1956
1942
1957
// Now give the gossiper the remote proof yet again. This should
1943
- // trigger a send of the signature announcement.
1958
+ // trigger a send of our signature announcement.
1959
+ select {
1960
+ case err = <- tCtx .gossiper .ProcessRemoteAnnouncement (
1961
+ ctx , batch .remoteProofAnn , remotePeer ,
1962
+ ):
1963
+ case <- time .After (2 * time .Second ):
1964
+ t .Fatal ("did not process local announcement" )
1965
+ }
1966
+ require .NoError (t , err , "unable to process remote proof" )
1967
+
1968
+ // We expect the gossiper to send this message to the remote peer.
1969
+ select {
1970
+ case msg := <- sentToPeer :
1971
+ _ , ok := msg .(* lnwire.AnnounceSignatures1 )
1972
+ if ! ok {
1973
+ t .Fatalf ("expected AnnounceSignatures1, instead got " +
1974
+ "%T" , msg )
1975
+ }
1976
+ case <- time .After (2 * time .Second ):
1977
+ t .Fatal ("did not send local proof to peer" )
1978
+ }
1979
+
1980
+ // Now give the gossiper the remote proof a 2nd time. This should _not_
1981
+ // trigger a send of our signature announcement, since we already sent
1982
+ // it once and we only send it once per connection.
1983
+ select {
1984
+ case err = <- tCtx .gossiper .ProcessRemoteAnnouncement (
1985
+ ctx , batch .remoteProofAnn , remotePeer ,
1986
+ ):
1987
+ case <- time .After (2 * time .Second ):
1988
+ t .Fatal ("did not process local announcement" )
1989
+ }
1990
+ require .NoError (t , err , "unable to process remote proof" )
1991
+
1992
+ // We expect the gossiper to _not_ send this message to the remote peer.
1993
+ select {
1994
+ case msg := <- sentToPeer :
1995
+ _ , ok := msg .(* lnwire.AnnounceSignatures1 )
1996
+ if ok {
1997
+ t .Fatalf ("got an AnnounceSignatures1 when none was " +
1998
+ "expected %T" , msg )
1999
+ }
2000
+ case <- time .After (2 * time .Second ):
2001
+ break
2002
+ }
2003
+
2004
+ // We simulate the remote peer disconnecting and reconnecting by
2005
+ // creating a new mock peer. This will reset the connection-specific
2006
+ // state, such as whether we've already sent the proof to this peer.
2007
+ remotePeer = newMockPeer (
2008
+ remoteKey , sentToPeer , tCtx .gossiper .quit , false ,
2009
+ )
2010
+
2011
+ // Now give the gossiper the remote proof a 3rd time. This should
2012
+ // trigger a send of our signature announcement, since the syncer
2013
+ // was pruned and we now have a new syncer for the remote peer.
2014
+ // This is to simulate the case where the remote peer disconnects and
2015
+ // reconnects, and we have to send the signature announcement again.
1944
2016
select {
1945
2017
case err = <- tCtx .gossiper .ProcessRemoteAnnouncement (
1946
2018
ctx , batch .remoteProofAnn , remotePeer ,
0 commit comments