Skip to content

Commit

Permalink
Use R mutex to create all broadcast list
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopeereboom committed Oct 23, 2024
1 parent 944da87 commit 8cebdeb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions service/tbc/tbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1611,21 +1611,21 @@ func (s *Server) TxBroadcastAllToPeer(ctx context.Context, p *peer) error {
log.Tracef("TxBroadcastAllToPeer %v", p)
defer log.Tracef("TxBroadcastAllToPeer %v exit", p)

s.mtx.Lock()
s.mtx.RLock()
if len(s.broadcast) == 0 {
s.mtx.Unlock()
s.mtx.RUnlock()
return nil
}

invTx := wire.NewMsgInv()
for k := range s.broadcast {
err := invTx.AddInvVect(wire.NewInvVect(wire.InvTypeTx, &k))
if err != nil {
s.mtx.Unlock()
s.mtx.RUnlock()
return fmt.Errorf("invalid vector: %w", err)
}
}
s.mtx.Unlock()
s.mtx.RUnlock()

err := p.write(defaultCmdTimeout, invTx)
if err != nil {
Expand Down Expand Up @@ -1658,8 +1658,8 @@ func (s *Server) TxBroadcast(ctx context.Context, tx *wire.MsgTx, force bool) (*
}
var success atomic.Uint64
inv := func(ctx context.Context, p *peer) {
log.Infof("inv %v", p)
defer log.Infof("inv %v exit", p)
log.Tracef("inv %v", p)
defer log.Tracef("inv %v exit", p)

err := p.write(defaultCmdTimeout, invTx)
if err != nil {
Expand Down

0 comments on commit 8cebdeb

Please sign in to comment.