Skip to content

refactor: EventSwitch implementation#569

Merged
shotonoff merged 8 commits intotd-115-fix-consensus-deadlockfrom
remove-listener-id-from-event-switcher
Feb 10, 2023
Merged

refactor: EventSwitch implementation#569
shotonoff merged 8 commits intotd-115-fix-consensus-deadlockfrom
remove-listener-id-from-event-switcher

Conversation

@shotonoff
Copy link
Collaborator

@shotonoff shotonoff commented Feb 1, 2023

Issue being fixed or feature implemented

Implementation events.EventSwitch has a few downsides which were eliminated with these changes.

  • it has listenerID argument that is required to add a listener for the event. it is redundant parameter, and in some cases lead to unexpected behaviour, like overriding listener function.
  • The naming convention for components and methods is slightly different and can be confusing

The main motivation was to deprecate *listenerID*, but in the process I made the component intuitive.

What was done?

  • Changed package name from events on eventemitter
  • Renamed EventSwitch on EventEmitter
  • Added logger to the constructor function as an optional parameter
  • Renamed methods
  • Removed listenerID

How Has This Been Tested?

Unit / E2E tests

Breaking Changes

N/A

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

…ename on EventEmitter, change EventEmitter api
Copy link
Collaborator

@lklimek lklimek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great code, good job!

See minor comments

listeners := e.events[event][:]
e.mtx.RUnlock()
for _, listener := range listeners {
err := listener(data)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider either:

  • adding a timeout here, to detect deadlocks, or
  • documenting that the listener is responsible for correct timeout handling

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the listeners' execution is synchronous, then the listener itself has to be responsible for managing concurrent behavior.
as an option, we can add the ability of asynchronous execution, but not sure we need this at this moment.

for _, listener := range listeners {
err := listener(data)
if err != nil {
e.logger.Error("got error from a listener", "error", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we display name of the listener, to add some debugging info (replacing listener ID)? Maybe fmt.Sprintf("%T", listener) will do the job?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since listenerID is deprecated, we don't have any information about the listener itself.
I believe, the error must provide all the necessary information to identify the problem

Copy link
Collaborator Author

@shotonoff shotonoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

answered

listeners := e.events[event][:]
e.mtx.RUnlock()
for _, listener := range listeners {
err := listener(data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the listeners' execution is synchronous, then the listener itself has to be responsible for managing concurrent behavior.
as an option, we can add the ability of asynchronous execution, but not sure we need this at this moment.

for _, listener := range listeners {
err := listener(data)
if err != nil {
e.logger.Error("got error from a listener", "error", err)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since listenerID is deprecated, we don't have any information about the listener itself.
I believe, the error must provide all the necessary information to identify the problem

@shotonoff shotonoff merged commit a4376b3 into td-115-fix-consensus-deadlock Feb 10, 2023
@shotonoff shotonoff deleted the remove-listener-id-from-event-switcher branch February 10, 2023 08:26
shotonoff added a commit that referenced this pull request Mar 17, 2023
* refactor: add sendMessage method to consensus.State

* refactor: modify sendMessage

* refactor: decompose WAL interface on a few small

* refactor: refactor an approach of message consuming for consensus state component

* refactor: add graceful stop for chanMsgReader

* refactor: consensus state priv-validator

* refactor: huge refactoring of consensus state, separate each state change task as a separate command, similar to state machine implementation

* refactor: add a stop function to a consensus to be able to stop receiveRoutine by a condition

* fix: remove block validating in finalizeCommit

* refactor: define Executor and VoteExtender interfaces, add executor mock, refactor return statement of Executor.ExtendVote

* test: add TestChanQueue, TestChanMsgSender, TestChanMsgReader

* test: generate PrivValidator mock

* refactor: move sending stats data from message handler

* refactor: add-vote operation (#558)

* refactor: separate TryAddVote.addVote logic on small function with one responsibility, use 2 sets (prevote and precommit) to process adding of vote
* refactor: replace peerID on proTxHash for peer catchup rounds in HeightVoteSet component
* fix: remove unused errors and StateData.validateVote

* refactor: EventSwitch implementation (#569)

* refactor: package lib/events rename on eventemitter and EventSwitch rename on EventEmitter, change EventEmitter api

* fix: add PeerManager.Unsubscribe method (#594)

* refactor: set and decide proposal operations (#565)

* refactor: set and decide proposal operations move to the separated component proposaler

* refactor: consensus peer gossip mechanism (#551)

* refactor: separate a gossip logic on implementation and a standard way of iterative handling a gossip condition

* chore: remove unless commented line

* refactor: remove custom "peerSyncErr" error

* refactor: add Gossiper interface, generate Gossiper mock struct, add unit test to queryMaj23GossipHandler

* refactor: peerGossipWorker implements service.Service

* refactor: blocksync module is refactored on using worker-pool

* test: replace custom assertError on tmrequire.Error

* refactor: add Now function into flowrate package, to obtain the current time

* fix: TestHandshakeErrorsIfAppReturnsWrongAppHash in replay_test.go

* refactor: move the logic wait-for blockchain sync from reactor to BlockPool

* fix: TestReactor_SyncTime

* test: change timing for test TestBlockPoolBasic

* chore: replace clock on clockwork

* refactor: replace reactor's consuming on separate consumer function in Channel, rename SetPeerRange on AddPeer

* test: add TestConsumeError

* chore: remove unused mustHexToBytes

* chore: add examples in promise/example_test.go and docs comments

* chore: change a package for MockValidatorSet from types on factory

* Update internal/blocksync/channel.go

* feat: create p2p/client package (#602)

* refactor: add internal/p2p/client implementation

* refactor: change blocksync module to support p2p client

* test: fix TestMakeHTTPDialerURL (#605)

* refactor: rename RandomNode on AnyNode as more specific name

* refactor: introduce p2p client in mempool module (#606)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants