lisk-sdk
lisk-sdk copied to clipboard
Avoid Event Missusages
Expected behavior
We need to make sure events are used for its intended purpose only; currently different modules could be using registered events passing different event.data causing the subscribers to get more than one event and potentially causing unexpected side effects in different modules. We should also probably document what's the intended use for existing events.
Actual behavior
Events can be fired with different data and subscriber can potentially behave erratically
Steps to reproduce
- Emit a registered event that's in use and send random data or data that's not the expected by the subscribers
Which version(s) does this affect? (Environment, OS, etc...)
I think event name needs to be cleaned up and make it more clear what is publishing.
Instead of
block:change
we should publish newBlock
or deleteBlock
etc
Example pseudo-stack which might cause failures
Original Stack:
- FileA.js -> channel.subscribe('event:xyz', cb);
- FileB.js -> channel.publish('event:xyz',
{ foo: 'bar', value: 42}
); - FileA.js -> executes actions expecting
{ foo: 'bar', value: 42}
All good so far
New Stack due to someone reusing an existing event:
- FileA.js -> channel.subscribe('event:xyz', cb);
- FileC.js -> channel.publish('event:zyz',
['radio', 'head', 'pearl', 'jam']
); - FileB.js -> channel.publish('event:xyz',
{ foo: 'bar', value: 42}
); - FileA.js -> executes actions expecting
{ foo: 'bar', value: 42}
but first gets['radio', 'head', 'pearl', 'jam']
As the subscriber is probably expecting an schema the new first publishing to event:zyz
with different schema will make it fail.
Closing this issue for no activity and value added is small