@@ -468,15 +468,23 @@ type annBatch struct {
468
468
remoteProofAnn * lnwire.AnnounceSignatures1
469
469
}
470
470
471
- func createLocalAnnouncements (blockHeight uint32 ) (* annBatch , error ) {
472
- return createAnnouncements (blockHeight , selfKeyPriv , remoteKeyPriv1 )
471
+ func (ctx * testCtx ) createLocalAnnouncements (blockHeight uint32 ) (* annBatch ,
472
+ error ) {
473
+
474
+ return ctx .createAnnouncements (blockHeight , selfKeyPriv , remoteKeyPriv1 )
473
475
}
474
476
475
- func createRemoteAnnouncements (blockHeight uint32 ) (* annBatch , error ) {
476
- return createAnnouncements (blockHeight , remoteKeyPriv1 , remoteKeyPriv2 )
477
+ func (ctx * testCtx ) createRemoteAnnouncements (blockHeight uint32 ) (* annBatch ,
478
+ error ) {
479
+
480
+ return ctx .createAnnouncements (
481
+ blockHeight , remoteKeyPriv1 , remoteKeyPriv2 ,
482
+ )
477
483
}
478
484
479
- func createAnnouncements (blockHeight uint32 , key1 , key2 * btcec.PrivateKey ) (* annBatch , error ) {
485
+ func (ctx * testCtx ) createAnnouncements (blockHeight uint32 , key1 ,
486
+ key2 * btcec.PrivateKey ) (* annBatch , error ) {
487
+
480
488
var err error
481
489
var batch annBatch
482
490
timestamp := testTimestamp
@@ -491,7 +499,9 @@ func createAnnouncements(blockHeight uint32, key1, key2 *btcec.PrivateKey) (*ann
491
499
return nil , err
492
500
}
493
501
494
- batch .chanAnn , err = createChannelAnnouncement (blockHeight , key1 , key2 )
502
+ batch .chanAnn , err = ctx .createChannelAnnouncement (
503
+ blockHeight , key1 , key2 ,
504
+ )
495
505
if err != nil {
496
506
return nil , err
497
507
}
@@ -616,7 +626,7 @@ func signUpdate(nodeKey *btcec.PrivateKey, a *lnwire.ChannelUpdate1) error {
616
626
return nil
617
627
}
618
628
619
- func createAnnouncementWithoutProof (blockHeight uint32 ,
629
+ func ( ctx * testCtx ) createAnnouncementWithoutProof (blockHeight uint32 ,
620
630
key1 , key2 * btcec.PublicKey ,
621
631
extraBytes ... []byte ) * lnwire.ChannelAnnouncement1 {
622
632
@@ -639,16 +649,21 @@ func createAnnouncementWithoutProof(blockHeight uint32,
639
649
return a
640
650
}
641
651
642
- func createRemoteChannelAnnouncement (blockHeight uint32 ,
652
+ func ( ctx * testCtx ) createRemoteChannelAnnouncement (blockHeight uint32 ,
643
653
extraBytes ... []byte ) (* lnwire.ChannelAnnouncement1 , error ) {
644
654
645
- return createChannelAnnouncement (blockHeight , remoteKeyPriv1 , remoteKeyPriv2 , extraBytes ... )
655
+ return ctx .createChannelAnnouncement (
656
+ blockHeight , remoteKeyPriv1 , remoteKeyPriv2 , extraBytes ... ,
657
+ )
646
658
}
647
659
648
- func createChannelAnnouncement (blockHeight uint32 , key1 , key2 * btcec.PrivateKey ,
660
+ func (ctx * testCtx ) createChannelAnnouncement (blockHeight uint32 , key1 ,
661
+ key2 * btcec.PrivateKey ,
649
662
extraBytes ... []byte ) (* lnwire.ChannelAnnouncement1 , error ) {
650
663
651
- a := createAnnouncementWithoutProof (blockHeight , key1 .PubKey (), key2 .PubKey (), extraBytes ... )
664
+ a := ctx .createAnnouncementWithoutProof (
665
+ blockHeight , key1 .PubKey (), key2 .PubKey (), extraBytes ... ,
666
+ )
652
667
653
668
signer := mock.SingleSigner {Privkey : key1 }
654
669
sig , err := netann .SignAnnouncement (& signer , testKeyLoc , a )
@@ -846,7 +861,7 @@ func TestProcessAnnouncement(t *testing.T) {
846
861
847
862
// First, we'll craft a valid remote channel announcement and send it to
848
863
// the gossiper so that it can be processed.
849
- ca , err := createRemoteChannelAnnouncement (0 )
864
+ ca , err := ctx . createRemoteChannelAnnouncement (0 )
850
865
require .NoError (t , err , "can't create channel announcement" )
851
866
852
867
select {
@@ -958,7 +973,7 @@ func TestPrematureAnnouncement(t *testing.T) {
958
973
// remote side, but block height of this announcement is greater than
959
974
// highest know to us, for that reason it should be ignored and not
960
975
// added to the router.
961
- ca , err := createRemoteChannelAnnouncement (1 )
976
+ ca , err := ctx . createRemoteChannelAnnouncement (1 )
962
977
require .NoError (t , err , "can't create channel announcement" )
963
978
964
979
select {
@@ -996,7 +1011,7 @@ func TestSignatureAnnouncementLocalFirst(t *testing.T) {
996
1011
}
997
1012
}
998
1013
999
- batch , err := createLocalAnnouncements (0 )
1014
+ batch , err := ctx . createLocalAnnouncements (0 )
1000
1015
require .NoError (t , err , "can't generate announcements" )
1001
1016
1002
1017
remoteKey , err := btcec .ParsePubKey (batch .nodeAnn2 .NodeID [:])
@@ -1172,7 +1187,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
1172
1187
}
1173
1188
}
1174
1189
1175
- batch , err := createLocalAnnouncements (0 )
1190
+ batch , err := ctx . createLocalAnnouncements (0 )
1176
1191
require .NoError (t , err , "can't generate announcements" )
1177
1192
1178
1193
remoteKey , err := btcec .ParsePubKey (batch .nodeAnn2 .NodeID [:])
@@ -1343,7 +1358,7 @@ func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
1343
1358
ctx , err := createTestCtx (t , proofMatureDelta , false )
1344
1359
require .NoError (t , err , "can't create context" )
1345
1360
1346
- batch , err := createLocalAnnouncements (0 )
1361
+ batch , err := ctx . createLocalAnnouncements (0 )
1347
1362
require .NoError (t , err , "can't generate announcements" )
1348
1363
1349
1364
remoteKey , err := btcec .ParsePubKey (batch .nodeAnn2 .NodeID [:])
@@ -1578,7 +1593,7 @@ func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
1578
1593
ctx , err := createTestCtx (t , proofMatureDelta , false )
1579
1594
require .NoError (t , err , "can't create context" )
1580
1595
1581
- batch , err := createLocalAnnouncements (0 )
1596
+ batch , err := ctx . createLocalAnnouncements (0 )
1582
1597
require .NoError (t , err , "can't generate announcements" )
1583
1598
1584
1599
remoteKey , err := btcec .ParsePubKey (batch .nodeAnn2 .NodeID [:])
@@ -1766,6 +1781,8 @@ func TestDeDuplicatedAnnouncements(t *testing.T) {
1766
1781
timestamp := testTimestamp
1767
1782
announcements := deDupedAnnouncements {}
1768
1783
announcements .Reset ()
1784
+ ctx , err := createTestCtx (t , 0 , false )
1785
+ require .NoError (t , err )
1769
1786
1770
1787
// Ensure that after new deDupedAnnouncements struct is created and
1771
1788
// reset that storage of each announcement type is empty.
@@ -1781,7 +1798,7 @@ func TestDeDuplicatedAnnouncements(t *testing.T) {
1781
1798
1782
1799
// Ensure that remote channel announcements are properly stored
1783
1800
// and de-duplicated.
1784
- ca , err := createRemoteChannelAnnouncement (0 )
1801
+ ca , err := ctx . createRemoteChannelAnnouncement (0 )
1785
1802
require .NoError (t , err , "can't create remote channel announcement" )
1786
1803
1787
1804
nodePeer := & mockPeer {bitcoinKeyPub2 , nil , nil , atomic.Bool {}}
@@ -1797,7 +1814,7 @@ func TestDeDuplicatedAnnouncements(t *testing.T) {
1797
1814
// We'll create a second instance of the same announcement with the
1798
1815
// same channel ID. Adding this shouldn't cause an increase in the
1799
1816
// number of items as they should be de-duplicated.
1800
- ca2 , err := createRemoteChannelAnnouncement (0 )
1817
+ ca2 , err := ctx . createRemoteChannelAnnouncement (0 )
1801
1818
require .NoError (t , err , "can't create remote channel announcement" )
1802
1819
announcements .AddMsgs (networkMsg {
1803
1820
msg : ca2 ,
@@ -2022,7 +2039,7 @@ func TestForwardPrivateNodeAnnouncement(t *testing.T) {
2022
2039
// We'll start off by processing a channel announcement without a proof
2023
2040
// (i.e., an unadvertised channel), followed by a node announcement for
2024
2041
// this same channel announcement.
2025
- chanAnn := createAnnouncementWithoutProof (
2042
+ chanAnn := ctx . createAnnouncementWithoutProof (
2026
2043
startingHeight - 2 , selfKeyDesc .PubKey , remoteKeyPub1 ,
2027
2044
)
2028
2045
pubKey := remoteKeyPriv1 .PubKey ()
@@ -2068,7 +2085,9 @@ func TestForwardPrivateNodeAnnouncement(t *testing.T) {
2068
2085
// by opening a public channel on the network. We'll create a
2069
2086
// ChannelAnnouncement and hand it off to the gossiper in order to
2070
2087
// process it.
2071
- remoteChanAnn , err := createRemoteChannelAnnouncement (startingHeight - 1 )
2088
+ remoteChanAnn , err := ctx .createRemoteChannelAnnouncement (
2089
+ startingHeight - 1 ,
2090
+ )
2072
2091
require .NoError (t , err , "unable to create remote channel announcement" )
2073
2092
peer := & mockPeer {pubKey , nil , nil , atomic.Bool {}}
2074
2093
@@ -2118,7 +2137,7 @@ func TestRejectZombieEdge(t *testing.T) {
2118
2137
ctx , err := createTestCtx (t , 0 , false )
2119
2138
require .NoError (t , err , "unable to create test context" )
2120
2139
2121
- batch , err := createRemoteAnnouncements (0 )
2140
+ batch , err := ctx . createRemoteAnnouncements (0 )
2122
2141
require .NoError (t , err , "unable to create announcements" )
2123
2142
remotePeer := & mockPeer {pk : remoteKeyPriv2 .PubKey ()}
2124
2143
@@ -2219,7 +2238,7 @@ func TestProcessZombieEdgeNowLive(t *testing.T) {
2219
2238
ctx , err := createTestCtx (t , 0 , false )
2220
2239
require .NoError (t , err , "unable to create test context" )
2221
2240
2222
- batch , err := createRemoteAnnouncements (0 )
2241
+ batch , err := ctx . createRemoteAnnouncements (0 )
2223
2242
require .NoError (t , err , "unable to create announcements" )
2224
2243
2225
2244
remotePeer := & mockPeer {pk : remoteKeyPriv1 .PubKey ()}
@@ -2374,7 +2393,7 @@ func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
2374
2393
ctx , err := createTestCtx (t , proofMatureDelta , false )
2375
2394
require .NoError (t , err , "can't create context" )
2376
2395
2377
- batch , err := createLocalAnnouncements (0 )
2396
+ batch , err := ctx . createLocalAnnouncements (0 )
2378
2397
require .NoError (t , err , "can't generate announcements" )
2379
2398
2380
2399
remoteKey , err := btcec .ParsePubKey (batch .nodeAnn2 .NodeID [:])
@@ -2581,7 +2600,7 @@ func TestExtraDataChannelAnnouncementValidation(t *testing.T) {
2581
2600
// that we don't know of ourselves, but should still include in the
2582
2601
// final signature check.
2583
2602
extraBytes := []byte ("gotta validate this still!" )
2584
- ca , err := createRemoteChannelAnnouncement (0 , extraBytes )
2603
+ ca , err := ctx . createRemoteChannelAnnouncement (0 , extraBytes )
2585
2604
require .NoError (t , err , "can't create channel announcement" )
2586
2605
2587
2606
// We'll now send the announcement to the main gossiper. We should be
@@ -2613,7 +2632,7 @@ func TestExtraDataChannelUpdateValidation(t *testing.T) {
2613
2632
// In this scenario, we'll create two announcements, one regular
2614
2633
// channel announcement, and another channel update announcement, that
2615
2634
// has additional data that we won't be interpreting.
2616
- chanAnn , err := createRemoteChannelAnnouncement (0 )
2635
+ chanAnn , err := ctx . createRemoteChannelAnnouncement (0 )
2617
2636
require .NoError (t , err , "unable to create chan ann" )
2618
2637
chanUpdAnn1 , err := createUpdateAnnouncement (
2619
2638
0 , 0 , remoteKeyPriv1 , timestamp ,
@@ -2729,7 +2748,7 @@ func TestRetransmit(t *testing.T) {
2729
2748
ctx , err := createTestCtx (t , proofMatureDelta , false )
2730
2749
require .NoError (t , err , "can't create context" )
2731
2750
2732
- batch , err := createLocalAnnouncements (0 )
2751
+ batch , err := ctx . createLocalAnnouncements (0 )
2733
2752
require .NoError (t , err , "can't generate announcements" )
2734
2753
2735
2754
remoteKey , err := btcec .ParsePubKey (batch .nodeAnn2 .NodeID [:])
@@ -2835,7 +2854,7 @@ func TestNodeAnnouncementNoChannels(t *testing.T) {
2835
2854
ctx , err := createTestCtx (t , 0 , false )
2836
2855
require .NoError (t , err , "can't create context" )
2837
2856
2838
- batch , err := createRemoteAnnouncements (0 )
2857
+ batch , err := ctx . createRemoteAnnouncements (0 )
2839
2858
require .NoError (t , err , "can't generate announcements" )
2840
2859
2841
2860
remoteKey , err := btcec .ParsePubKey (batch .nodeAnn2 .NodeID [:])
@@ -2928,7 +2947,7 @@ func TestOptionalFieldsChannelUpdateValidation(t *testing.T) {
2928
2947
2929
2948
// In this scenario, we'll test whether the message flags field in a
2930
2949
// channel update is properly handled.
2931
- chanAnn , err := createRemoteChannelAnnouncement (chanUpdateHeight )
2950
+ chanAnn , err := ctx . createRemoteChannelAnnouncement (chanUpdateHeight )
2932
2951
require .NoError (t , err , "can't create channel announcement" )
2933
2952
2934
2953
select {
@@ -3019,7 +3038,7 @@ func TestSendChannelUpdateReliably(t *testing.T) {
3019
3038
ctx , err := createTestCtx (t , proofMatureDelta , false )
3020
3039
require .NoError (t , err , "unable to create test context" )
3021
3040
3022
- batch , err := createLocalAnnouncements (0 )
3041
+ batch , err := ctx . createLocalAnnouncements (0 )
3023
3042
require .NoError (t , err , "can't generate announcements" )
3024
3043
3025
3044
// We'll also create two keys, one for ourselves and another for the
@@ -3376,7 +3395,7 @@ func TestPropagateChanPolicyUpdate(t *testing.T) {
3376
3395
const numChannels = 3
3377
3396
channelsToAnnounce := make ([]* annBatch , 0 , numChannels )
3378
3397
for i := 0 ; i < numChannels ; i ++ {
3379
- newChan , err := createLocalAnnouncements (uint32 (i + 1 ))
3398
+ newChan , err := ctx . createLocalAnnouncements (uint32 (i + 1 ))
3380
3399
if err != nil {
3381
3400
t .Fatalf ("unable to make new channel ann: %v" , err )
3382
3401
}
@@ -3553,10 +3572,10 @@ func TestProcessChannelAnnouncementOptionalMsgFields(t *testing.T) {
3553
3572
ctx , err := createTestCtx (t , 0 , false )
3554
3573
require .NoError (t , err , "unable to create test context" )
3555
3574
3556
- chanAnn1 := createAnnouncementWithoutProof (
3575
+ chanAnn1 := ctx . createAnnouncementWithoutProof (
3557
3576
100 , selfKeyDesc .PubKey , remoteKeyPub1 ,
3558
3577
)
3559
- chanAnn2 := createAnnouncementWithoutProof (
3578
+ chanAnn2 := ctx . createAnnouncementWithoutProof (
3560
3579
101 , selfKeyDesc .PubKey , remoteKeyPub1 ,
3561
3580
)
3562
3581
@@ -3772,7 +3791,7 @@ func TestBroadcastAnnsAfterGraphSynced(t *testing.T) {
3772
3791
3773
3792
// A remote channel announcement should not be broadcast since the graph
3774
3793
// has not yet been synced.
3775
- chanAnn1 , err := createRemoteChannelAnnouncement (0 )
3794
+ chanAnn1 , err := ctx . createRemoteChannelAnnouncement (0 )
3776
3795
require .NoError (t , err , "unable to create channel announcement" )
3777
3796
assertBroadcast (chanAnn1 , true , false )
3778
3797
@@ -3786,7 +3805,7 @@ func TestBroadcastAnnsAfterGraphSynced(t *testing.T) {
3786
3805
// should to be broadcast.
3787
3806
ctx .gossiper .syncMgr .markGraphSynced ()
3788
3807
3789
- chanAnn2 , err := createRemoteChannelAnnouncement (1 )
3808
+ chanAnn2 , err := ctx . createRemoteChannelAnnouncement (1 )
3790
3809
require .NoError (t , err , "unable to create channel announcement" )
3791
3810
assertBroadcast (chanAnn2 , true , true )
3792
3811
}
@@ -3811,7 +3830,7 @@ func TestRateLimitChannelUpdates(t *testing.T) {
3811
3830
// We'll create a batch of signed announcements, including updates for
3812
3831
// both sides, for a channel and process them. They should all be
3813
3832
// forwarded as this is our first time learning about the channel.
3814
- batch , err := createRemoteAnnouncements (blockHeight )
3833
+ batch , err := ctx . createRemoteAnnouncements (blockHeight )
3815
3834
require .NoError (t , err )
3816
3835
3817
3836
nodePeer1 := & mockPeer {
@@ -3951,7 +3970,7 @@ func TestIgnoreOwnAnnouncement(t *testing.T) {
3951
3970
ctx , err := createTestCtx (t , proofMatureDelta , false )
3952
3971
require .NoError (t , err , "can't create context" )
3953
3972
3954
- batch , err := createLocalAnnouncements (0 )
3973
+ batch , err := ctx . createLocalAnnouncements (0 )
3955
3974
require .NoError (t , err , "can't generate announcements" )
3956
3975
3957
3976
remoteKey , err := btcec .ParsePubKey (batch .nodeAnn2 .NodeID [:])
@@ -4097,7 +4116,7 @@ func TestRejectCacheChannelAnn(t *testing.T) {
4097
4116
4098
4117
// First, we create a channel announcement to send over to our test
4099
4118
// peer.
4100
- batch , err := createRemoteAnnouncements (0 )
4119
+ batch , err := ctx . createRemoteAnnouncements (0 )
4101
4120
require .NoError (t , err , "can't generate announcements" )
4102
4121
4103
4122
remoteKey , err := btcec .ParsePubKey (batch .nodeAnn2 .NodeID [:])
@@ -4189,7 +4208,7 @@ func TestChanAnnBanningNonChanPeer(t *testing.T) {
4189
4208
// Craft a valid channel announcement for a channel we don't
4190
4209
// have. We will ensure that it fails validation by modifying
4191
4210
// the router.
4192
- ca , err := createRemoteChannelAnnouncement (uint32 (i ))
4211
+ ca , err := ctx . createRemoteChannelAnnouncement (uint32 (i ))
4193
4212
require .NoError (t , err , "can't create channel announcement" )
4194
4213
4195
4214
select {
@@ -4209,7 +4228,7 @@ func TestChanAnnBanningNonChanPeer(t *testing.T) {
4209
4228
// Assert that nodePeer has been disconnected.
4210
4229
require .True (t , nodePeer1 .disconnected .Load ())
4211
4230
4212
- ca , err := createRemoteChannelAnnouncement (101 )
4231
+ ca , err := ctx . createRemoteChannelAnnouncement (101 )
4213
4232
require .NoError (t , err , "can't create channel announcement" )
4214
4233
4215
4234
// Set the error to ErrChannelSpent so that we can test that the
@@ -4269,7 +4288,7 @@ func TestChanAnnBanningChanPeer(t *testing.T) {
4269
4288
// Craft a valid channel announcement for a channel we don't
4270
4289
// have. We will ensure that it fails validation by modifying
4271
4290
// the router.
4272
- ca , err := createRemoteChannelAnnouncement (uint32 (i ))
4291
+ ca , err := ctx . createRemoteChannelAnnouncement (uint32 (i ))
4273
4292
require .NoError (t , err , "can't create channel announcement" )
4274
4293
4275
4294
select {
0 commit comments