Skip to content

Commit

Permalink
remove v1 consensus callbacks from worker after v2 activation
Browse files Browse the repository at this point in the history
  • Loading branch information
AdoAdoAdo committed Jan 15, 2025
1 parent 6e25ca3 commit 25276b1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions consensus/spos/bls/v2/blsSubroundsFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions consensus/spos/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions consensus/spos/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions factory/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions testscommon/consensus/sposWorkerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 25276b1

Please sign in to comment.