-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: moving node initialization code to node_factory.nim #2479
Conversation
waku/node/node_factory.nim
Outdated
../../apps/wakunode2/external_config, | ||
../../apps/wakunode2/internal_config, | ||
../../apps/wakunode2/wakunode2_validator_signed |
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.
I have mixed feelings regarding importing code from the apps
directory.
On one hand, the node's configuration parameters are defined there and we need them in order to create a node.
On the other, code related to the app should be separate from the the waku node modules.
Not sure if we should move the configs out of the app
directory or what would be the most appropriate way to go
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.
Good point! What if we move the external_config
, internal_config
, and wakunode2_validator_signed
modules into the folder waky/node/
?
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.
Sounds good :))
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.
So took a look and was able to move internal_config.nim
and wakunode2_validator_signed
but moving external_config.nim
caused some conflicts because of its code related to parsing CLI commands, which also makes sense that is part of the apps
directory.
Ideally we should decouple a node's configuration options to the application's CLI parameters.
The decoupling would make sense only if we find a way to do it without duplicating everything. So I left external_config.nim
in apps
until we find a better solution.
You can find the image built from this PR at
Built from 38862f8 |
This PR may contain changes to configuration options of one of the apps. If you are introducing a breaking change (i.e. the set of options in latest release would no longer be applicable) make sure the original option is preserved with a deprecation note for 2 following releases before it is actually removed. Please also make sure the label |
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 would avoid naming things node. I suggest factory
instead of node_factory
and maybe naming the folder initialization (or init).
Mmm makes sense, having the word node is kind of redundant. On the other hand, it does make clear that it isn't code specific to a protocol and that it's related to the @Ivansete-status @NagyZoltanPeter thoughts? |
waku/node/validator_signed.nim
Outdated
@@ -19,9 +19,9 @@ import | |||
const MessageWindowInSec = 5*60 # +- 5 minutes | |||
|
|||
import |
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.
unsure if @jm-clius agrees.
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.
Better having the signed validator in apps
? the idea is to have all the pieces to build a Waku node with standard features under waku/node
(but without adding it to the WakuNode
object itself).
Thought that a signed validator entered into the set of "standard features"
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.
However, these elements (app-level validation, app's DB config, etc.) were moved out of the node for a reason. This (incorrectly) brings back awareness of the app environment into the node object, while the app environment should know about the node and not the other way around. Amongst other things, you're now seeing a lot of interesting circular imports (such as internal_config
depending on waku_node
, while waku_node
also depends on internal_config
).
Perhaps the solution is rather to raise the bindings to the app level? Of course, creating a convenient app-level node factory or middleware that can be wrapped in bindings will be part of this effort.
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.
the solution is rather to raise the bindings to the app level and, of course, create a convenient app-level node factory or middleware.
👍
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.
Makes sense! Maybe all of this should be at app level.
Notice that here we did not change the node object at all - we only moved the procs that initialize nodes from the app
file to a node_factory
file inside waku/node
directory which isn't used by any other file related to the node.
Or in other words, we're attaching to waku_node
a separate "kit" to easily create a node. So once you import waku_node
you get both the basic procs to do everything from scratch and a separate already built "node factory" with standard implementations.
Regarding the circular imports, notice that those two are different files. internal_config
depends on waku/node/waku_node.nim
which has the actual WakuNode
implementation. And then there's waku/waku_node.nim
that imports files from the waku/node
directory and exports them as a bundle so apps don't have to import all the files individually.
Here we're adding the node factory to the second one, to waku/waku_node.nim
. But we are not touching the node's implementation.
Maybe we should have all of this at the app level. But the only thing that would change here is the file path, the logic is already separate.
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.
Right, good point about the import here - waku/waku_node.nim
is just a barrel import. However, it remains a bit weird that there are now "app" imports in modules that live very closely with the node. It indeed only affects import and directory structure afaics, but I guess what we need is:
a) node (the wrapper around libp2p switch)
b) app middleware (config, factory, validators, etc. that's used by all apps, including ones using the bindings)
c) specific apps, e.g. wakunode2 - bare minimum to use the app middleware to create a specific type of waku application, such as wakunode2
binary.
This layered approach should also reflect in the import structure (outer app can import app middleware can import node, but never the other way).
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.
Sounds great! Really like that idea of a new "middleware" layer - agree 100% that it's a much more logically sound structure.
Will re-organize the it like that.
Thanks so much! 🤩
Looking at the content of the source file, it's not a true factory for me, in terms of factory pattern. |
I personally prefer being explicit with |
Yes! So the idea is that it will be an actual factory. We're first trying to move the existing code and dependencies there so when we add its main code the diff won't be enormous filled with copy-pasted things. It would be difficult to differentiate what's new code and what's copy-pasted procs being moved around. So this PR is only so the following PRs are more scoped and easier to review |
49f0062
to
d845d1f
Compare
Went over everything today with @Ivansete-status today The new "middleware" layer is now in the directory All the imports should now follow the hierarchical logical structure. Notice that this is only the first step of a bigger refactor task. This PR is intended as a reordering of existing logic and no new code is introduced. The next step is to build on top on this and add functionalities to |
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.
I think its a great step ahead with in mind it will evolve. Thank you!
99d5c38
to
f9badca
Compare
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.
Thanks!
@@ -33,6 +33,7 @@ import | |||
../../waku/waku_node, | |||
../../waku/node/waku_metrics, | |||
../../waku/node/peer_manager, | |||
../../waku/factory/builder, | |||
../../waku/common/utils/nat, | |||
./config_chat2 |
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.
Eventually it may be possible for all apps, including chat2, to start using the common factory/external_config
and only add app-specific config items in an extension module. Nothing to action for now. :)
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.
Great movement! Thanks for it! 💯
I didn't check the detail of every block as I assume is block movement.
Cheers
…d from app to node modules
82788f3
to
2d3710e
Compare
Description
As a first step towards refactoring
app.nim
, we're moving code related to node initialization to a new factory/middleware layer.A new directory named
waku/factory
was created, which will contain all logic related to this functionality.In addition, introduced a file named
node_factory.nim
, which will contain the core logic of this layer.The idea is to be able to pass down node configurations and get a node in response.
A PR will follow extending the functionalities in
node_factory
beyond moving existing code.Changes
factory
directory andfactory/node_factory.nim
fileapp.nim
tofactory/node_factory.nim
internal_config.nim
,external_config.nim
andwakunode2_validator_signed.nim
fromapps/wakunode2
towaku/factory
builder.nim
fromwaku/node
towaku/factory
directorywakunode2_validator_signed.nim
tovalidator_signed.nim
Issue
#2441