Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ linters:
- intrange
- loggercheck
- misspell
- modernize
- nilerr
- noctx
- nolintlint
Expand Down
12 changes: 6 additions & 6 deletions internal/bft/heartbeatmonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func TestHeartbeatMonitorLeader(t *testing.T) {
vs.Store(bft.ViewSequence{ViewActive: true})
hm := bft.NewHeartbeatMonitor(scheduler, log, types.DefaultConfig.LeaderHeartbeatTimeout, types.DefaultConfig.LeaderHeartbeatCount, comm, 4, handler, vs, types.DefaultConfig.NumOfTicksBehindBeforeSyncing)

var heartBeatsSent uint32
var heartBeatsSentUntilViewBecomesInactive uint32
var heartBeatsSent atomic.Uint32
var heartBeatsSentUntilViewBecomesInactive atomic.Uint32

var toWG1 sync.WaitGroup
toWG1.Add(10)
Expand All @@ -68,17 +68,17 @@ func TestHeartbeatMonitorLeader(t *testing.T) {
comm.On("BroadcastConsensus", mock.AnythingOfType("*smartbftprotos.Message")).Run(func(args mock.Arguments) {
msg := args[0].(*smartbftprotos.Message)
view := msg.GetHeartBeat().GetView()
atomic.AddUint32(&heartBeatsSent, 1)
heartBeatsSent.Add(1)
if uint64(10) == view {
toWG1.Done()
} else if uint64(20) == view {
toWG2.Done()
totalHBsSent := atomic.LoadUint32(&heartBeatsSent)
totalHBsSent := heartBeatsSent.Load()
if totalHBsSent == 20 {
// View is stopped
vs.Store(bft.ViewSequence{ViewActive: false, ProposalSeq: msg.GetHeartBeat().GetSeq()})
// Record HB number we sent so far
atomic.StoreUint32(&heartBeatsSentUntilViewBecomesInactive, totalHBsSent)
heartBeatsSentUntilViewBecomesInactive.Store(totalHBsSent)
}
}
}).Return()
Expand All @@ -94,7 +94,7 @@ func TestHeartbeatMonitorLeader(t *testing.T) {

clock.advanceTime(10, scheduler)
// Ensure we don't advance heartbeats any longer when view is inactive
require.Equal(t, atomic.LoadUint32(&heartBeatsSentUntilViewBecomesInactive), atomic.LoadUint32(&heartBeatsSent))
require.Equal(t, heartBeatsSentUntilViewBecomesInactive.Load(), heartBeatsSent.Load())

hm.Close()
}
Expand Down
6 changes: 2 additions & 4 deletions internal/bft/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ func TestViewDataInFlightWhileStored(t *testing.T) {

done := make(chan struct{})
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for i := 0; ; i++ {
select {
case <-done:
Expand All @@ -173,7 +171,7 @@ func TestViewDataInFlightWhileStored(t *testing.T) {
vc.InFlight.StorePrepares(0, 0)
}
}
}()
})

inconsistent := 0
for range 100000 {
Expand Down
8 changes: 4 additions & 4 deletions internal/bft/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1483,21 +1483,21 @@ func newNetwork(t *testing.T, size int) testedNetwork {
}

type testedView struct {
offline uint32
offline atomic.Uint32
deciderWG sync.WaitGroup
*bft.View
}

func (tv *testedView) setOffline() {
atomic.StoreUint32(&tv.offline, 1)
tv.offline.Store(1)
}

func (tv *testedView) setOnline() {
atomic.StoreUint32(&tv.offline, 0)
tv.offline.Store(0)
}

func (tv *testedView) HandleMessage(sender uint64, m *protos.Message) {
if atomic.LoadUint32(&tv.offline) == uint32(1) {
if tv.offline.Load() == uint32(1) {
return
}
tv.View.HandleMessage(sender, m)
Expand Down
8 changes: 4 additions & 4 deletions pkg/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type Consensus struct {
consensusLock sync.RWMutex

reconfigChan chan types.Reconfig
running uint64
running atomic.Uint64
}

func (c *Consensus) Complain(viewNum uint64, stopView bool) {
Expand Down Expand Up @@ -99,7 +99,7 @@ func (c *Consensus) Sync() types.SyncResponse {

// GetLeaderID returns the current leader ID or zero if Consensus is not running
func (c *Consensus) GetLeaderID() uint64 {
if atomic.LoadUint64(&c.running) == 0 {
if c.running.Load() == 0 {
return 0
}
return c.controller.GetLeaderID()
Expand Down Expand Up @@ -159,15 +159,15 @@ func (c *Consensus) Start() error {

c.startComponents(view, seq, dec, c.Verifier.VerificationSequence(), true)

atomic.StoreUint64(&c.running, 1)
c.running.Store(1)

return nil
}

func (c *Consensus) run() {
defer func() {
c.Logger.Infof("Exiting consensus run; ID: %d", c.Config.SelfID)
atomic.StoreUint64(&c.running, 0)
c.running.Store(0)
c.Stop()
}()

Expand Down
Loading
Loading