@@ -417,8 +417,8 @@ type WebsocketNetwork struct {
417
417
// messagesOfInterestMu protects messagesOfInterest and ensures
418
418
// that messagesOfInterestEnc does not change once it is set during
419
419
// network start.
420
- messagesOfInterestMu deadlock.Mutex
421
- messagesOfInterestCond * sync. Cond
420
+ messagesOfInterestMu deadlock.Mutex
421
+ messagesOfInterestRefresh chan struct {}
422
422
423
423
// peersConnectivityCheckTicker is the timer for testing that all the connected peers
424
424
// are still transmitting or receiving information. The channel produced by this ticker
@@ -764,7 +764,7 @@ func (wn *WebsocketNetwork) setup() {
764
764
SupportedProtocolVersions = []string {wn .config .NetworkProtocolVersion }
765
765
}
766
766
767
- wn .messagesOfInterestCond = sync . NewCond ( & wn . messagesOfInterestMu )
767
+ wn .messagesOfInterestRefresh = make ( chan struct {}, 2 )
768
768
wn .messagesOfInterestGeneration = 1 // something nonzero so that any new wsPeer needs updating
769
769
if wn .relayMessages {
770
770
wn .RegisterMessageInterest (protocol .CompactCertSigTag )
@@ -1178,7 +1178,7 @@ func (wn *WebsocketNetwork) maybeSendMessagesOfInterest(peer *wsPeer, messagesOf
1178
1178
if messagesOfInterestEnc != nil {
1179
1179
peer .sendMessagesOfInterest (messagesOfInterestGeneration , messagesOfInterestEnc )
1180
1180
} else {
1181
- wn .log .Infof ("msgOfInterest Enc=nil" )
1181
+ wn .log .Infof ("msgOfInterest Enc=nil, MOIGen=%d" , messagesOfInterestGeneration )
1182
1182
}
1183
1183
}
1184
1184
}
@@ -1726,14 +1726,10 @@ func (wn *WebsocketNetwork) OnNetworkAdvance() {
1726
1726
defer wn .lastNetworkAdvanceMu .Unlock ()
1727
1727
wn .lastNetworkAdvance = time .Now ().UTC ()
1728
1728
if wn .nodeInfo != nil && ! wn .relayMessages && ! wn .config .ForceFetchTransactions {
1729
- // if we're not a relay, and not participating, we don't need txn pool
1730
- wantTXGossip := wn .nodeInfo .IsParticipating ()
1731
- if wantTXGossip && (wn .wantTXGossip != wantTXGossipYes ) {
1732
- wn .RegisterMessageInterest (protocol .TxnTag )
1733
- wn .wantTXGossip = wantTXGossipYes
1734
- } else if ! wantTXGossip && (wn .wantTXGossip != wantTXGossipNo ) {
1735
- wn .DeregisterMessageInterest (protocol .TxnTag )
1736
- wn .wantTXGossip = wantTXGossipNo
1729
+ select {
1730
+ case wn .messagesOfInterestRefresh <- struct {}{}:
1731
+ default :
1732
+ // if the notify chan is full, it will get around to updating the latest when it actually runs
1737
1733
}
1738
1734
}
1739
1735
}
@@ -2350,18 +2346,24 @@ func (wn *WebsocketNetwork) updateMessagesOfInterestEnc() {
2350
2346
wn .messagesOfInterestEnc = MarshallMessageOfInterestMap (wn .messagesOfInterest )
2351
2347
wn .messagesOfInterestEncoded = true
2352
2348
atomic .AddUint32 (& wn .messagesOfInterestGeneration , 1 )
2353
- wn .messagesOfInterestCond .Broadcast ()
2349
+ var peers []* wsPeer
2350
+ peers , _ = wn .peerSnapshot (peers )
2351
+ for _ , peer := range peers {
2352
+ wn .maybeSendMessagesOfInterest (peer , wn .messagesOfInterestEnc )
2353
+ }
2354
2354
}
2355
2355
2356
2356
func (wn * WebsocketNetwork ) postMessagesOfInterestThread () {
2357
- var peers []* wsPeer
2358
- wn .messagesOfInterestMu .Lock ()
2359
- defer wn .messagesOfInterestMu .Unlock ()
2360
2357
for {
2361
- wn .messagesOfInterestCond .Wait ()
2362
- peers , _ = wn .peerSnapshot (peers )
2363
- for _ , peer := range peers {
2364
- wn .maybeSendMessagesOfInterest (peer , wn .messagesOfInterestEnc )
2358
+ <- wn .messagesOfInterestRefresh
2359
+ // if we're not a relay, and not participating, we don't need txn pool
2360
+ wantTXGossip := wn .nodeInfo .IsParticipating ()
2361
+ if wantTXGossip && (wn .wantTXGossip != wantTXGossipYes ) {
2362
+ wn .RegisterMessageInterest (protocol .TxnTag )
2363
+ atomic .StoreUint32 (& wn .wantTXGossip , wantTXGossipYes )
2364
+ } else if ! wantTXGossip && (wn .wantTXGossip != wantTXGossipNo ) {
2365
+ wn .DeregisterMessageInterest (protocol .TxnTag )
2366
+ atomic .StoreUint32 (& wn .wantTXGossip , wantTXGossipNo )
2365
2367
}
2366
2368
}
2367
2369
}
0 commit comments