discv5 icon indicating copy to clipboard operation
discv5 copied to clipboard

Update ENR on IP change

Open dapplion opened this issue 4 years ago • 5 comments

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.

dapplion avatar May 24 '21 14:05 dapplion

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

wemeetagain avatar May 24 '21 15:05 wemeetagain

image wouldn't this be passing as enrUpdate to discv5 to be true if no ip provided

g11tech avatar May 24 '21 17:05 g11tech

@wemeetagain @dapplion could you assign this to me

g11tech avatar May 25 '21 13:05 g11tech

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 :

  1. 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) image image

  2. 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) image

  3. I change my network at 11:40.31 image

  4. 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) 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

g11tech avatar Jun 01 '21 12:06 g11tech

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.

g11tech avatar Jun 01 '21 16:06 g11tech