[P2P] Increase performance of Good #2850
Merged
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 actually opens up our need for some more fuzzing and testing to integrate while catching up to various Bitcoin improvements.
It is a partial back port of bitcoin#22974 , reasons being we have to isolate more of the fuzz integrations so we can add them into the code base. Although this provides an improvement of over a factor of 100 for the population of the addrman 'good' peers because we iterate the table twice in order to accomplish this.
First loop is modified because in MakeTried() we can speed this up by stopping it mainly at nRefCount == 0, any further it would absolutely hit an assert. And then we can also check from the bucket that it is originating from peer wise, giving us less buckets to check.
Second loop is removed because in Good_() we look for the entry but if it is not corrupted, there's two places it would be, in new, tried or not in addr db at all. Which means at this point we would not need this and can return earlier.
Some benchmarks from upstream bitcoin#22974 (comment) bitcoin#22974 (comment)