Skip to content

Commit

Permalink
Switch HasVote gossip to TrySend (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored Jul 3, 2024
1 parent 0095edb commit 70f5ff9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func (conR *Reactor) broadcastHasVoteMessage(vote *types.Vote) {
}

go func() {
conR.Switch.BroadcastEnvelope(p2p.Envelope{
conR.Switch.TryBroadcast(p2p.Envelope{
ChannelID: StateChannel,
Message: msg,
})
Expand Down
14 changes: 14 additions & 0 deletions p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,20 @@ func (sw *Switch) BroadcastEnvelope(e Envelope) {
}
}

// TryBroadcast runs a go routine for each attempted send.
//
// NOTE: TryBroadcast uses goroutines, so order of broadcast may not be preserved.
func (sw *Switch) TryBroadcast(e Envelope) {
sw.Logger.Debug("TryBroadcast", "channel", e.ChannelID)

peers := sw.peers.List()
for _, peer := range peers {
go func(p Peer) {
p.TrySendEnvelope(e)
}(peer)
}
}

// NumPeers returns the count of outbound/inbound and outbound-dialing peers.
// unconditional peers are not counted here.
func (sw *Switch) NumPeers() (outbound, inbound, dialing int) {
Expand Down

0 comments on commit 70f5ff9

Please sign in to comment.