-
Notifications
You must be signed in to change notification settings - Fork 38.7k
addrman: Fix AddrMan::Add() return semantics and logging #23380
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
Conversation
Does not document the return value since we're going to fix the semantics in a future commit.
|
@mzumsande - I think this fixes the logging bug that you encountered. |
|
Concept ACK |
8853611 to
7f06f53
Compare
Previously, Add() would return true if the function created a new AddressInfo object, even if that object could not be successfully entered into the new table and was deleted. That would happen if the new table position was already taken and the existing entry could not be removed. Instead, return true if the new AddressInfo object is successfully entered into the new table. This fixes a bug in the "Added %i addresses" log, which would not always accurately log how many addresses had been added. p2p_addrv2_relay.py and p2p_addr_relay.py need to be updated since they were incorrectly asserting on the buggy log (assuming that addresses are added to addrman, when there could in fact be new table position collisions that prevent some of those address records from being added).
Keep the internal {Function}_() functions grouped together.
Review with `git diff --color-moved=dimmed-zebra`
7f06f53 to
61ec053
Compare
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.
ACK 61ec053
This PR primarily deals with the bug, where Addrman::Add() returns true, even when the AddrInfo object has not been successfully added to the table. This PR also focuses on other minor changes.
(A short description of this PR, in chronological order of the commits. This might help fellow reviewers to understand this PR better.)
Description:
- Expanded the documentation for the
Addrman::Add()function making it more clear. - In AddrManImpl class
Add_()has been renamed toAddSingle()and a new definition ofAdd_()is introduced which can tackle addition of multiple instancesAddressInfoobject. AddSingle()function has been appropriately modified to returnbool 0if theAdrrInfoobject has not been successfully entered into the table.AddrmanImpl::Add()has been appropriately modified to inculcate the changes. One doubt though: was there any specific reason for usingauto ret =instead ofbool ret =?- Finally, reordering of
AddrManImpl::Good_()has been done to group internal functions together.
This PR is able to correct the described bug successfully, and I agree with the changes made in this PR.
A Sidenote:
(Note: This is not specifically part of this PR. And can be taken as a brainstorming activity)
In the AddrmanImpl class, what do you think about making the internal {Function}_() functions protected or private, as a non-class member need not call this function directly, and they should call their respective {Function}()?
|
Thank you for the very thorough review @shaavan!
You're exactly correct that they don't need to be accessed outside the class. In fact, they already are private. There's a Line 144 in ab25ef8
|
Oops, I missed that! 😅. Thanks for informing me! |
@shaavan - The idea was that all of the public functions could have a standard structure of: which could then be replaced by a variadic template to reduce the boilerplate/repetation. I guess that would still work if In any case, I don't think it matters too much either way. |
Makes sense. Both |
|
ACK 61ec053 The bug is fixed and the refactoring makes sense. |
|
ACK 61ec053 Reviewed code and verified that |
… logging 61ec053 [MOVEONLY] reorder functions in addrman_impl.h and addrman.cpp (John Newbery) 2095df7 [addrman] Add Add_() inner function, fix Add() return semantics (John Newbery) 2658eb6 [addrman] Rename Add_() to AddSingle() (John Newbery) e58598e [addrman] Add doxygen comment to AddrMan::Add() (John Newbery) Pull request description: Previously, Add() would return true if the function created a new AddressInfo object, even if that object could not be successfully entered into the new table and was deleted. That would happen if the new table position was already taken and the existing entry could not be removed. Instead, return true if the new AddressInfo object is successfully entered into the new table. This fixes a bug in the "Added %i addresses" log, which would not always accurately log how many addresses had been added. ACKs for top commit: naumenkogs: ACK 61ec053 mzumsande: ACK 61ec053 shaavan: ACK 61ec053 Tree-SHA512: 276f1e8297d4b6d411d05d06ffc7c176f6290a784da039926ab6c471a8ed8e9159ab4f56c893b1285737ae292954930f0d28012d89dfb3f2f825d7df41016feb
Hopefully fixes new addrman unit test failures that appear to have been introduced in commit 2095df7 "Add Add_() inner function, fix Add() return semantics" of PR bitcoin#23380, which was merged in 994aaaa. That commit removed the bool fNew logic from AddSingle() and replaced it with returning fInsert. This patch brings back the fNew logic and combines it with fInsert, so AddSingle() returns whether or not fNew and fInsert are both true.
|
Concept ACK. Good idea. I'm seeing addrman unit test failures that appear to begin with 2095df7; maybe there is an interaction with other changes on master that wasn't apparent in this branch, but I am only beginning to catch up with the changes of the past few weeks. Edit: it looks like the errors had a different cause. |
Previously, Add() would return true if the function created a new
AddressInfo object, even if that object could not be successfully
entered into the new table and was deleted. That would happen if the new
table position was already taken and the existing entry could not be
removed.
Instead, return true if the new AddressInfo object is successfully
entered into the new table. This fixes a bug in the "Added %i addresses"
log, which would not always accurately log how many addresses had been
added.