Discv5 has a number of services. It maintains an Arc<RwLock< ENR>> which passes it around the different services.
Lighthouse also has a global network variable list. Inside it, holds a RwLock<< ENR>> and the global variable list is usually Arc'd around between different threads.
We currently have the situation where we are storing two kinds of Enr in memory. One (that actual source of truth) lies inside of discv5. The second, the one Lighthouse knows about, lies in the NetworkGlobals.
We try and keep these in sync by updating our view based on messages we receive from discovery. However, I think a better design is to just keep the one record and share mutable access across Lighthouse and discovery.
The benefits I think are:
Simpler code, because we can just mutate the Enr from within Lighthouse.
Enr's will always be in sync, no error from missing messages and keeping track of two records
Downsides are:
We need to expose the ENR is discovery. This gives users access to modify the local ENR in discovery. In principle, doing bad mutations can cause issues with discovery (i.e modifying sequence numbers etc).
We need to be mindful of deadlocks. I can't think of any, but it's worth mentioning here.
Implementation:
I think to implement this we need to expose the local ENR in the discv5 struct (in the discv5 repo). Once exposed, we need to build it for discovery and then store the resulting reference in the NetworkGlobals.
Description
Discv5 has a number of services. It maintains an Arc<RwLock< ENR>> which passes it around the different services.
Lighthouse also has a global network variable list. Inside it, holds a RwLock<< ENR>> and the global variable list is usually Arc'd around between different threads.
We currently have the situation where we are storing two kinds of Enr in memory. One (that actual source of truth) lies inside of discv5. The second, the one Lighthouse knows about, lies in the NetworkGlobals.
We try and keep these in sync by updating our view based on messages we receive from discovery. However, I think a better design is to just keep the one record and share mutable access across Lighthouse and discovery.
The benefits I think are:
Downsides are:
Implementation:
I think to implement this we need to expose the local ENR in the discv5 struct (in the discv5 repo). Once exposed, we need to build it for discovery and then store the resulting reference in the NetworkGlobals.
There are some immediate simplifications we can make once doing this. I'd start with removing functions like this: https://github.com/sigp/lighthouse/blob/stable/beacon_node/lighthouse_network/src/discovery/mod.rs#L405 and probably the calling code.