-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
WIP Node services - Brainstorm #123
Conversation
I think we should able to use Node's built-in EventEmitter API. It'll give us enough flexibility for supporting async communication, makes the code quite easy to maintain and read and we don't need to build out extra support. As for passing global objects, I think we should minimize this as much as possible. It could potentially cause issues down the line. However, there are perhaps some cases in which we should use this approach. As for the services you have, I think you covered most of them. What I would add would be services for light clients like in the ethereum-js client you posted. In the future, we might need shard services. |
I'm in a time bind and I'll contribute more in little bit, but a few things that came to my mind: Events:
Global Objects:
DB:
|
👍
Agreed, I threw it out there hoping there would be some consensus against going that route.
Good to keep in mind. Current eth2.0 light client proposal
Oh yeah, the validator isn't represented anywhere here yet. I'm hoping that we can design that as a separate module that communicates w the beacon chain via rpc or some other such mechanism (eg: a MessageChannel/MessageChannel if they're running in different workers in the same deployment/process).
I feel like we should start simple, just assuming the single thread, and move to a more complicated multithreaded setup once its clear that we need it. I think we will probably need it, but I also think it will be easier to iterate on the codebase while its simpler. The needs of a multithreaded system will become more clear once we've gotten further. Also should give us time to research the relevant APIs and figure out how to best implement such a system for our needs. If we avoid gratuitous use of shared global objects between services and are careful about how we link dependent services, it should be a straightforward process.
For multithreading, I think we should target use of Workers/Workers. The API looks the same between node and the web. I think in conjunction w the MessageChannel api linked above, we should be able to pass data pretty efficiently between worker threads. |
One thing I would like to note is to perhaps take into account future dev tooling. I know this is super early but if we can design this to be quite modular and easy to use, then building out future dev tools become less of a hassle. However, unless you have a crystal ball, this will be very hard to predict and we can only try our best while designing out the architecture. |
Ah yes, thats actually what I was referencing. I'm very Pro to your earlier comment about not wanting to get too complicated.
Thats ultimately the idea behind spinning off these "services" |
I asked rauljordan about those services in the prysmatic discord: Q:
A:
|
Regarding a multithreaded / worker-based solution, what's tricky/interesting to think about is how to best (most ergonomically + efficiently) send data across the worker boundaries. Each worker is a separate thread, but it seems that memory between workers isn't readily available, only available through the Data is mostly just copied/cloned across the channel, but
Another comment rauljordan made:
There does exist a BroadcastChannel which exposes a handle which can broadcast across multiple workers at once, but I don't really recommend relying on it directly, bc there is not good browser support yet and its not implemented in node (there's also a We would probably want to research/develop a solution that provides a unified interface for broadcasting/subscribing that uses |
Hmm that is interesting. ... none the less I'm a fan of doing it naively, as long as its extremely modular |
Another suggestion I got was from @jacobheun of libp2p. Instead of using node's After doing a bit of research, it seems like the main advantage (depending on the context) of using Any thoughts? |
Not super familiar with how async iterators are created/used in practice, but I like the idea of using async iterators where we can.
|
Codecov Report
@@ Coverage Diff @@
## master #123 +/- ##
=======================================
Coverage 81.56% 81.56%
=======================================
Files 17 17
Lines 716 716
Branches 36 36
=======================================
Hits 584 584
Misses 130 130
Partials 2 2
Continue to review full report at Codecov.
|
I moved this PR from draft so we could try to get this skeleton code merged. RE worker threads:
|
does anyone else want to review/approve this PR? |
Gonna merge this. This stuff is not set in stone, just some skeleton code to help give a little more structure to the project. |
WIP/brainstorming on organization of the various BeaconNode services.
Some questions:
Is this the right direction to push? Are these the right level of granularity to start with?
Are we missing any important services?
I didn't copy prysm's services exactly, because 1. I didn't really see what each service was there for, 2. we may have different needs. But for the sake of brainstorming, do we need eg: a sync service, an operations service? (both are prysm services not represented explicitly here)
How do we best handle dependencies / data sharing/passing between various services?
You may notice, some of the services instantiated in BeaconNode (intuitively-speaking) should rely in some way on other services (eg: "the beacon chain relies on the db")
I think we want rough guidelines/patterns for how data is passed/shared that help us keep our services reasonably decoupled and help us stay sane as the codebase grows
eg: do we