p2p/discv5: fix reg lookup, polish code, use logger#15737
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR does a few polishes and cleanups in the p2p discoveryv5 ticketing code.
Functionality wise it fixes a (probably harmless) bug when iterating the known topics for registration. The previous code in
nextRegisterLookupcreated a list of topics to iterate over, and then exhausted that list (recreating if it became empty), until it found the same topic it started iterating from.This logic is a bit convoluted, because topic queuing and iteration was spanned out over multiple methods, which both messed around some internal cache. One bug was that doing a "full round" of iteration meant that the first topic will be consumed twice. This is a harmless issue in this case.
The second potentially bigger bug was that iteration order was random due to being backed by a map, so the queue constructor could make the following queues in subsequent iterations:
[a, b, c, d],[d, a, b, c]. If mynextRegisterLookupinvocation starts at topicdfrom the first listing, which is empty, the next call will again bed, causing the method to return a 40 second sleep, even though there are plenty more topics to try.The fix in the PR is to take the leftover queue from the previous invocation, and expand it randomly with all the topics not contained within it. This makes everything simpler: a full iteration is guaranteed to go over all the topics, without duplicates, and to correctly stop when every one of them was tried.
Furthermore the PR swaps
tickets map[Topic]topicTicketstotickets map[Topic]*topicTickets. This is needed because the code was full ofs.topics[topic].buckets == nilchecks, which is essence only intended to check ifs.topics[topic]existed, but in the non-pointer version they always return the zero value of the struct, making the code harder to understand.Lastly, the PR removes all the
debugLoginvocations in favor oflog.Trace. This allows us to use the fine grained controls out logging framework has to debug discovery issues. I've also added some minor simplifications in the logs. Now we have a much more readable stream of events to trace with: