diff --git a/consensus/spos/bls/v2/blsSubroundsFactory.go b/consensus/spos/bls/v2/blsSubroundsFactory.go index 2c9ade325a..53e2b60801 100644 --- a/consensus/spos/bls/v2/blsSubroundsFactory.go +++ b/consensus/spos/bls/v2/blsSubroundsFactory.go @@ -112,6 +112,7 @@ func (fct *factory) GenerateSubrounds() error { fct.initConsensusThreshold() fct.consensusCore.Chronology().RemoveAllSubrounds() fct.worker.RemoveAllReceivedMessagesCalls() + fct.worker.RemoveAllReceivedHeaderHandlers() err := fct.generateStartRoundSubround() if err != nil { diff --git a/consensus/spos/interface.go b/consensus/spos/interface.go index 1281cd8908..071790979c 100644 --- a/consensus/spos/interface.go +++ b/consensus/spos/interface.go @@ -105,6 +105,8 @@ type WorkerHandler interface { AddReceivedMessageCall(messageType consensus.MessageType, receivedMessageCall func(ctx context.Context, cnsDta *consensus.Message) bool) // AddReceivedHeaderHandler adds a new handler function for a received header AddReceivedHeaderHandler(handler func(data.HeaderHandler)) + // RemoveAllReceivedHeaderHandlers removes all the functions handlers + RemoveAllReceivedHeaderHandlers() // AddReceivedProofHandler adds a new handler function for a received proof AddReceivedProofHandler(handler func(consensus.ProofHandler)) // RemoveAllReceivedMessagesCalls removes all the functions handlers diff --git a/consensus/spos/worker.go b/consensus/spos/worker.go index e539071331..804bec8371 100644 --- a/consensus/spos/worker.go +++ b/consensus/spos/worker.go @@ -310,6 +310,13 @@ func (wrk *Worker) AddReceivedHeaderHandler(handler func(data.HeaderHandler)) { wrk.mutReceivedHeadersHandler.Unlock() } +// RemoveAllReceivedHeaderHandlers removes all the functions handlers +func (wrk *Worker) RemoveAllReceivedHeaderHandlers() { + wrk.mutReceivedHeadersHandler.Lock() + wrk.receivedHeadersHandlers = make([]func(data.HeaderHandler), 0) + wrk.mutReceivedHeadersHandler.Unlock() +} + // ReceivedProof process the received proof, calling each received proof handler registered in worker instance func (wrk *Worker) ReceivedProof(proofHandler consensus.ProofHandler) { if check.IfNilReflect(proofHandler) { diff --git a/factory/interface.go b/factory/interface.go index 85331045ec..04849acb35 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -386,6 +386,8 @@ type ConsensusWorker interface { AddReceivedMessageCall(messageType consensus.MessageType, receivedMessageCall func(ctx context.Context, cnsDta *consensus.Message) bool) // AddReceivedHeaderHandler adds a new handler function for a received header AddReceivedHeaderHandler(handler func(data.HeaderHandler)) + // RemoveAllReceivedHeaderHandlers removes all the functions handlers + RemoveAllReceivedHeaderHandlers() // AddReceivedProofHandler adds a new handler function for a received proof AddReceivedProofHandler(handler func(proofHandler consensus.ProofHandler)) // RemoveAllReceivedMessagesCalls removes all the functions handlers diff --git a/testscommon/consensus/sposWorkerMock.go b/testscommon/consensus/sposWorkerMock.go index 3a7e1ef384..f3a6e1cded 100644 --- a/testscommon/consensus/sposWorkerMock.go +++ b/testscommon/consensus/sposWorkerMock.go @@ -17,6 +17,7 @@ type SposWorkerMock struct { receivedMessageCall func(ctx context.Context, cnsDta *consensus.Message) bool, ) AddReceivedHeaderHandlerCalled func(handler func(data.HeaderHandler)) + RemoveAllReceivedHeaderHandlersCalled func() AddReceivedProofHandlerCalled func(handler func(proofHandler consensus.ProofHandler)) RemoveAllReceivedMessagesCallsCalled func() ProcessReceivedMessageCalled func(message p2p.MessageP2P) error @@ -48,6 +49,13 @@ func (sposWorkerMock *SposWorkerMock) AddReceivedHeaderHandler(handler func(data } } +// RemoveAllReceivedHeaderHandlers - +func (sposWorkerMock *SposWorkerMock) RemoveAllReceivedHeaderHandlers() { + if sposWorkerMock.RemoveAllReceivedHeaderHandlersCalled != nil { + sposWorkerMock.RemoveAllReceivedHeaderHandlersCalled() + } +} + func (sposWorkerMock *SposWorkerMock) AddReceivedProofHandler(handler func(proofHandler consensus.ProofHandler)) { if sposWorkerMock.AddReceivedProofHandlerCalled != nil { sposWorkerMock.AddReceivedProofHandlerCalled(handler)