firefly
firefly copied to clipboard
Migration to v1.3.0 can cause missed events when contract listeners are listening from latest
As part of the v1.3.0 release, we rearchitected the way event streams from the transaction managers are configured against the namespaces in FireFly. FireFly core will now create one event stream per namespace and as such we wrote code to migrate the existing contract listeners on the previous event stream to the corresponding namespace event stream.
Contract listeners have an option of where to listen from where the choices are accepted:
-
oldest
which defaults to the first block - a specific block number
-
latest
which will be start listen from the creation of the listener.
As such when the listeners get recreated as part of the migration, the ones set to latest
will now listen from a new latest and in the time where the chain has advance and FireFly is starting up some event could get lost! This can get worse with another bug where if FireFly cannot communicate with the Transaction Manager to create the listener it will give up and never listen to those events!
A way to solve this would be:
- Retrieve the previous contract listeners created against the default eventstream
- Find the checkpoint value - i.e the block at which this listener has caught up to!
- When creating the new contract listener against the namespace listener set the option to listen from the checkpoint!
This was we do not lose events.
Looking at the code, this change is tricker than it sounds because the original change simply at startup creates an event stream and apply the listeners created for the namespace. There is no notion of "migration" so this code will need to introduce some code to get the existing listeners on the "global" event stream and hopefully be able to using some identifier correlate them to the new ones that need to be created.