-
Notifications
You must be signed in to change notification settings - Fork 3
Refactors fx wiring into self-contained modules #46
Conversation
This change does a few things with the ultimate goal of having a cleaner organization of the fx dependency graph: (1) It completely strips out the functional "Options" layer that was being used on top of fx. This layer was obfuscating the real organization of the application dependencies, particularly through the abuse of the "Override" function. (2) Creates an fxmodules package where we moved almost all of the fx providers and invokes into self-contained modules that reflect the high-level organization of the code (e.g., libp2p, node, repo, consensus, etc.). (3) Moves some of the construction of the dependency graph that was outside of fx into the fx framework. Sadly, not all though, but it got the important pieces of the full node API and the RPC server construction. (4) Fixes some antipatterns in the code and the usage of fx. In particular: (a) no more overrides, now the application fails to launch if a dependency is provided twice; (b) in a few places (e.g., mir consensus), providers are now returning the specific struct type and not the interface. We used fx annotations to fix this; (c) Some providers are now private in order to keep modules as self-contained as possible. We didn't go to far with this as the API construction makes it difficult, but it's a start. Hopefully, this will serve as a starting point to make the lotus code cleaner and more modular. The fx module organization proposed here is just a starting point. There's a lot of room for further improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I added minor comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing job! Apart from a few cosmetic suggestions, can we include the new fx
approach also in itests? https://github.com/consensus-shipyard/lotus/blob/spacenet/itests/kit/ensemble.go#L352-L458
If needed we can also choose to create an independent ensemble for eudico as we do here: https://github.com/filecoin-project/eudico/blob/eudico/itests/kit/ensemble_eudico.go (although I would rather avoid a lot of duplicate code).
Once this is done, you can check if it works with make spacenet-test
and if this is the case we are ready to merge (and I'll start migrating tspow
code here) :) Thanks! 🙏
…/lotus into hmoniz/fx_refactoring
This change does a few things with the ultimate goal of having a cleaner organization of the fx dependency graph:
(1) It completely strips out the functional "Options" layer that was being used on top of fx. This layer was obfuscating the real organization of the application dependencies, particularly through the abuse of the "Override" function.
(2) Creates an fxmodules package where we moved almost all of the fx providers and invokes into self-contained modules that reflect the high-level organization of the code (e.g., libp2p, node, repo, consensus, etc.).
(3) Moves some of the construction of the dependency graph that was outside of fx into the fx framework. Sadly, not all though, but it got the important pieces of the full node API and the RPC server construction.
(4) Fixes some antipatterns in the code and the usage of fx. In particular: (a) no more overrides, now the application fails to launch if a dependency is provided twice; (b) in a few places (e.g., mir consensus), providers are now returning the specific struct type and not the interface. We used fx annotations to fix this; (c) Some providers are now private in order to keep modules as self-contained as possible. We didn't go to far with this as the API construction makes it difficult, but it's a start.
Hopefully, this will serve as a starting point to make the lotus code cleaner and more modular. The fx module organization proposed here is just a starting point. There's a lot of room for further improvement.