Skip to content

Commit

Permalink
Remove a redundant waitgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk committed Jul 28, 2022
1 parent b563af0 commit d7d13ad
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
6 changes: 1 addition & 5 deletions pkg/core/consensus/reduction/asyncsend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package reduction
import (
"context"
"fmt"
"sync"

"github.com/dusk-network/dusk-blockchain/pkg/core/data/block"
"github.com/dusk-network/dusk-blockchain/pkg/p2p/wire/message"
Expand Down Expand Up @@ -44,14 +43,11 @@ func NewAsyncSend(r *Reduction, round uint64, step uint8, candidate *block.Block

// Go executes SendReduction in a separate goroutine.
// Returns cancel func for canceling the started job.
func (a AsyncSend) Go(ctx context.Context, wg *sync.WaitGroup, resp chan message.Message, flags int) context.CancelFunc {
func (a AsyncSend) Go(ctx context.Context, resp chan message.Message, flags int) context.CancelFunc {
ctx, cancel := context.WithCancel(ctx)

wg.Add(1)

go func() {
defer a.recover()
defer wg.Done()

m, _, err := a.SendReduction(ctx, a.round, a.step, a.candidate)
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions pkg/core/consensus/reduction/firststep/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package firststep
import (
"bytes"
"context"
"sync"
"time"

"github.com/dusk-network/dusk-blockchain/pkg/core/candidate"
Expand Down Expand Up @@ -96,15 +95,13 @@ func (p *Phase) Run(ctx context.Context, queue *consensus.Queue, _, reductionCha
p.handler = reduction.NewHandler(p.Keys, r.P, r.Seed)

// send our own Selection
var wg sync.WaitGroup

a := reduction.NewAsyncSend(p.Reduction, r.Round, step, &p.selectionResult.Candidate)

if p.handler.AmMember(r.Round, step) {
_ = a.Go(ctx, &wg, reductionChan, reduction.Republish)
_ = a.Go(ctx, reductionChan, reduction.Republish)
} else {
if p.handler.AmMember(r.Round, step+1) {
_ = a.Go(ctx, &wg, reductionChan, reduction.ValidateOnly)
_ = a.Go(ctx, reductionChan, reduction.ValidateOnly)
}
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/core/consensus/reduction/secondstep/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"bytes"
"context"
"encoding/hex"
"sync"
"time"

"github.com/dusk-network/dusk-blockchain/pkg/config"
Expand Down Expand Up @@ -96,14 +95,12 @@ func (p *Phase) Run(ctx context.Context, queue *consensus.Queue, _, reductionCha
p.handler = reduction.NewHandler(p.Keys, r.P, r.Seed)
// first we send our own Selection

// wait group
var wg sync.WaitGroup
var cancel context.CancelFunc

a := reduction.NewAsyncSend(p.Reduction, r.Round, step, p.firstStepVotesMsg.Candidate)

if p.handler.AmMember(r.Round, step) {
cancel = a.Go(ctx, &wg, reductionChan, reduction.Republish)
cancel = a.Go(ctx, reductionChan, reduction.Republish)
defer cancel()
}

Expand Down

0 comments on commit d7d13ad

Please sign in to comment.