state machine, transitions and events #1061
Description
- Version: 0.26.0
- Platform: All
- Subsystem: core, repo, init, swarm, bitswap, libp2p, perhaps others..
Type:
Enhancement
Severity:
Medium
Description:
Initialisation and stopping an IPFS node envolves many states and transitions that are hard to handle, can fail and have many corner cases.
Currently, initialisation states and their transitions are verified and managed explicitly at code level. From my experience, this almost invariantly conducts to bugs and weirdness in app start code.
Instead, a finite state machine that contains all the main, intermediary and error states should be well defined and documented.
The initialisation code should be driven by state transitions, and not the other way around (like it is now). This will avoid double user actions, like starting or stopping the node twice concurrently, or trying to stop after stopped, etc.
IMO, special attention should be given so that the implementation:
- is consistent: for instance, even if repo initialisation is not required, a
initialised
or equivalent transition event should be fired. - Some operations should be idempotent: starting a node that is started or is starting should not lead to an error, much less triggering the
startup
procedure again. - Any Irrecoverable error in initialisation should lead to an dead-end "error" state.