discv5
discv5 copied to clipboard
Update ENR on IP change
Describe the bug
We don't update the local ENR IP when it changes during node's execution.
Expected behavior
Some component should monitor the node's public IP and update the ENR when that happens. Make sure to persist to disk and broadcast to discv5 if necessary.
Our discv5 impl should already have this functionality, tho it may be turned off via configuration?
https://github.com/ChainSafe/discv5/blob/master/src/service/service.ts#L519-L533
wouldn't this be passing as enrUpdate to discv5 to be true if no ip provided
@wemeetagain @dapplion could you assign this to me
I investigated the issue, and as suspcted when no ip4 or ip6 is provided, enrUpdate to discv5 is going as true.
and whenever IP changes, the enr is updated as well as written to disk (2 times actually).
but here is a detailed chronology of events that i see (with me having (right now) near to zero knowledge of disv5 protocol and how enr works). Do point out if anything is odd :
-
even before peers are being searched (which I am assuming is start of the disvc5 protocol), the enr file has been rewritten multiple times. (3-4 times atleast, a couple of times because the options are being persisted to disk)

-
there are multiple ENR updates that I see in discv5 code (I enabled console log there in the node_modules/@chainsafe/discv5...) , at the startup time, even when no IP manipulation is yet done (one for ipv6 and one for ip4) and each time enr file gets written to (actually 2 times for each update, marked as W1, W2)

-
I change my network at 11:40.31

-
The ENR update is received at 11:43 in discv5, and as expected the file is written two times (W1,W2). However there is constant ENR update being requested (using different node string as highlighted in image)

Conclusion is if no ip4 or ip6 is provided in network options while starting up the beacon, the discv5 protocol constantly look for ENR update and whenever that ENR update comes, its gets written to file)
But I have seen some instances where I changed the network, and no ENR update came in discv5 (and hence is not written to disk). if there is an issue it would be in discv5 (more investigation would be needed there if this needs to be pursued) but this isn't a lodestar issue.
Another issue could be created for 2 saves on every ENR update (and to fix it to just save once), but i see this to be a very very minor issue.
let me know your views @dapplion @wemeetagain
some more observations: this issue comes randomly after flipping between networks some 7-8 times or more, but once the ENR update stops happening, then it never happens throughout that session doesn't matter how many times one flip between networks, average wait between flips was 7-10 minutes.