Skip to content

Commit 961bb62

Browse files
fixes after review
1 parent 5601282 commit 961bb62

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

process/throttle/antiflood/p2pAntiflood.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ func (af *p2pAntiflood) BlacklistPeer(peer core.PeerID, reason string, duration
278278

279279
// Close will call the close function on all sub components
280280
func (af *p2pAntiflood) Close() error {
281-
af.mutDebugger.Lock()
282-
defer af.mutDebugger.Unlock()
281+
af.mutDebugger.RLock()
282+
defer af.mutDebugger.RUnlock()
283283

284284
return af.debugger.Close()
285285
}

process/throttle/antiflood/p2pAntiflood_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ func TestP2pAntiflood_SetConsensusSizeNotifier(t *testing.T) {
316316

317317
wasCalled := false
318318
expectedSize := 878264
319+
testShardId := uint32(5)
319320
var actualSize int
320321
afm, _ := antiflood.NewP2PAntiflood(
321322
&mock.PeerBlackListHandlerStub{},
@@ -329,7 +330,7 @@ func TestP2pAntiflood_SetConsensusSizeNotifier(t *testing.T) {
329330
)
330331

331332
chainParamsSubscriber := chainparametersnotifier.NewChainParametersNotifier()
332-
afm.SetConsensusSizeNotifier(chainParamsSubscriber, 5)
333+
afm.SetConsensusSizeNotifier(chainParamsSubscriber, testShardId)
333334

334335
chainParamsSubscriber.UpdateCurrentChainParameters(config.ChainParametersByEpochConfig{
335336
ShardConsensusGroupSize: uint32(expectedSize),
@@ -480,7 +481,15 @@ func TestP2pAntiflood_IsOriginatorEligibleForTopic(t *testing.T) {
480481
func TestP2pAntiflood_ConcurrentOperations(t *testing.T) {
481482
afm, _ := antiflood.NewP2PAntiflood(
482483
&mock.PeerBlackListHandlerStub{},
483-
&mock.TopicAntiFloodStub{},
484+
&mock.TopicAntiFloodStub{
485+
IncreaseLoadCalled: func(pid core.PeerID, topic string, numMessages uint32) error {
486+
if topic == "should error" {
487+
return errors.New("error")
488+
}
489+
490+
return nil
491+
},
492+
},
484493
&mock.FloodPreventerStub{},
485494
)
486495

@@ -516,10 +525,12 @@ func TestP2pAntiflood_ConcurrentOperations(t *testing.T) {
516525
_ = afm.Debugger()
517526
case 12:
518527
_ = afm.SetPeerValidatorMapper(&mock.PeerShardResolverStub{})
528+
case 13:
529+
_ = afm.CanProcessMessagesOnTopic("peer", "should error", 37, 39, []byte("sequence"))
519530
}
520531

521532
wg.Done()
522-
}(i % 13)
533+
}(i % 14)
523534
}
524535

525536
wg.Wait()

0 commit comments

Comments
 (0)