-
Notifications
You must be signed in to change notification settings - Fork 42
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
fix: loop counter for writing multiaddresses in enr #704
Conversation
Jenkins Builds
|
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
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.
- if the successInd is found, we are trying to write the multiAddress field to the local node again.
I think this logic is enough?
for i := len(multiaddrs) ; i >= 0; i-- {
err = writeMultiaddressField(localnode, multiaddrs[0:i])
if err == nil {
couldWriteENRatLeastOnce = true
successIdx = i
return nil
} else {
failedOnceWritingENR = true
}
}
if failedOnceWritingENR {
return errors.New("could not write new ENR")
}
failedOnceWritingENR is still needed to prevent error in case multiaddrs array is empty.
- Secondly, i goes from n to 0, shouldn't it go from n to 1. The last iteration will provide 0 len array to writemultiAddressField.
The reason why this is done this way is because a failure to write the ENR will still modify the I can do this in a separate PR: i.e. - instead of doing it this way: defer func(){
if e := recover(); e != nil {
// Deleting the multiaddr entry, as we could not write it succesfully
localnode.Delete(enr.WithEntry(MultiaddrENRField, struct{}{}))
err = errors.New("could not write enr record")
}
}() to instead do: var ogMultiaddrValue []byte
if err := node.Record().Load(enr.WithEntry(MultiaddrENRField, &ogMultiaddrValue)); err != nil {
if !enr.IsNotFound(err) {
return err
}
}
defer func(){
if e := recover(); e != nil {
// restoring to original value
localnode.Set(enr.WithEntry(MultiaddrENRField, ogMultiaddrValue))
err = errors.New("could not write enr record")
}
}() |
sounds good. I'll fix this |
0e74ea5
to
0847007
Compare
Description
Writing multiaddresses on the ENR
multiaddr
key worked only when there was more than one multiaddress field that should be stored on that field. Most of the time that wasn't a problem, specially since desktop does not use websocket addresses and always has at least 2 circuit relay addresses