-
Notifications
You must be signed in to change notification settings - Fork 36.2k
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
addrman: Fix new table bucketing during unserialization #20557
Conversation
The code currently rebuckets entries (losing the additional bucket positions) if the asmap checksum changes. I'm not sure if that's necessary and don't see any downside to keeping the same bucketing if restarting with a new asmap. If others agree, I can update this PR to not do that rebucketing. |
We should also add a regression test for this. I think a good test would be to add a round trip serialize/unserialize to the addrman fuzz test, and compare the addrman before and after that round trip. There's some internal state that isn't reconstructed from serialize/unserialize (eg the vRandom ordering), but a comparator function that checked number of entries and bucket->entry pairs should work. If anyone wants to add that fuzz test or other tests, I'm happy to add them to this PR. |
595e9e5
to
0fff708
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
Concept ACK.
That would mean that asmap is applied to only newly learned addresses, which is a downside (assuming asmap is an improvement). On the other hand, losing the existing 8 buckets is unfortunate. We could do the 8 existing + 1 asmap bucket if we really want... but that also has some consequences of potentially overriding existing buckets etc. Also, we should keep in mind that non-rebucketing on a new asmap may allow existing records to appear in 16 buckets now instead of 8 (probably all existing records on first asmap appearance). Which is... also not particularly terrible but should be considered? |
Currently the bucket positions for existing new addresses are lost entirely when changing asmap, so I don't understand how this is a downside. The choice is between throwing away those bucket positions or not.
No. We won't add an entry to more than 8 buckets: Lines 294 to 296 in 257cf05
|
I expressed my agreement with you in the following sentence: "On the other hand, losing the existing 8 buckets is unfortunate.". Still, ideally, we would apply a new asmap to existing addrs without losing the data. Unfortunately, since we don't store addr source, we have to make this choice between the two. And I agree that of these 2 choices, the one you're suggesting is probably better.
Good to know! That was just my wrong assumption without looking deep into code :) |
0fff708
to
dbdf63c
Compare
Thanks for the review @naumenkogs. I've addressed all your comments. |
Concept ACK, and the code change looks overall good to me. Agree that a test would be useful, to make it easier to see that this fixes the mentioned problems and prevent future regression. |
utACK dbdf63c |
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.
code review ACK dbdf63c
Can see that it fixes the bug from ec45646, previously looped over each entry, retrieving the first bucket we recorded in entryToBucket
, and now creates a list of <bucket, index>
pairs and loops over all of those instead. Some clarifying questions because I'm super unfamiliar with this code and stared at it for a long time.
dbdf63c
to
36f3d9d
Compare
An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. Fix that.
Version implies that higher numbers take precendence. This is really a checksum, to check whether the provided asmap is the same as the one used when the peers.dat file was serialized. Also update the comments to explain where/why this is used.
Only rebucket if the asmap checksum has changed, not if the file format has changed but no asmap is provided. Also, don't try to add an entry to another bucket if it already appears in ADDRMAN_NEW_BUCKETS_PER_ADDRESS buckets.
Improved the naming of one of the variables as suggested in #20557 (comment) : |
36f3d9d
to
ac3547e
Compare
Rebased on master |
ACK ac3547e |
Created such test at: jnewbery#18.
|
Thanks for the review @vasild. I've resolved your review comments. I haven't taken your fuzz test yet since it seems like there's a bit more work to make sure that it's getting reliable coverage. |
9a0760d
to
195a12d
Compare
Thanks to Vasil Dimov <vd@FreeBSD.org> for these suggestions
Thanks to Vasil Dimov <vd@FreeBSD.org> for these suggestions
195a12d
to
4676a4f
Compare
ACK 4676a4f
|
re-ACK 4676a4f, changes were a rename, comments, and removing repeat-logging. |
ACK 4676a4f |
@MarcoFalke or @laanwj - this PR now has 3 ACKs. If one of you re-reviewed, then it might be ready for merge. |
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 4676a4f
A couple nits and questions below.
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.
Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore.
src/addrman.h
Outdated
for (auto bucket_entry : bucket_entries) { | ||
int bucket{bucket_entry.first}; | ||
const int n{bucket_entry.second}; |
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.
In commit "[addrman] Fix new table bucketing during unserialization" (b4c5fda)
Could avoid some verbosity here with
- for (auto bucket_entry : bucket_entries) {
- int bucket{bucket_entry.first};
- const int n{bucket_entry.second};
+ for (auto [bucket, n] : bucket_entries) {
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.
❤️ structured bindings. Good suggestion. I'll do in a follow-up.
std::map<int, int> entryToBucket; // Represents which entry belonged to which bucket when serializing | ||
// An entry may appear in up to ADDRMAN_NEW_BUCKETS_PER_ADDRESS buckets, | ||
// so we store all bucket-entry_index pairs to iterate through later. | ||
std::vector<std::pair<int, int>> bucket_entries; |
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.
In commit "[addrman] Fix new table bucketing during unserialization" (b4c5fda)
Seems like having a data structure here is superfluous if it's just going to be filled up then immediately iterated over and discarded. Maybe it would make sense to remove this vector later.
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.
I think that vector could be avoided only if we could seek into the stream. Then we could change the current:
read new buckets
read asmap checksum
process the new buckets that were read, depending on the asmap checksum
to
seek forward and read the asmap checksum (last 32 bytes)
seek back and read+process the new bucketing data, depending on the asmap checksum
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.
We only know how we're going to use the vector after we've deserialized the asmap_checksum field, so I don't think we can get rid of it.
src/addrman.h
Outdated
@@ -509,7 +511,7 @@ friend class CAddrManTest; | |||
int nIndex = 0; | |||
s >> nIndex; | |||
if (nIndex >= 0 && nIndex < nNew) { | |||
entryToBucket[nIndex] = bucket; | |||
bucket_entries.emplace_back(bucket, nIndex); |
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.
In commit "[addrman] Fix new table bucketing during unserialization" (b4c5fda)
It would be good to have some test coverage for this. A functional test might be hard but I would think a c++ unit test should be straightforward. Past bugs predict future bugs so a test here could steer coverage in a useful direction.
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.
A test is in the baking at jnewbery#18.
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.
I definitely agree. @vasild has a test here: jnewbery#18 which can be added after this PR.
src/addrman.h
Outdated
int nUBucketPos = info.GetBucketPosition(nKey, true, bucket); | ||
if (format >= Format::V2_ASMAP && nUBuckets == ADDRMAN_NEW_BUCKET_COUNT && vvNew[bucket][nUBucketPos] == -1 && | ||
info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS && serialized_asmap_checksum == supplied_asmap_checksum) { | ||
if (restore_bucketing && vvNew[bucket][nUBucketPos] == -1) { |
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.
In commit "[addrman] Don't rebucket new table entries unnecessarily" (a5c9b04)
Just some notes to make sure I'm following this correctly.
- The
restore_bucketing
change here is aesthetic and the only actual change this line is dropping theformat >= Format::V2_ASMAP
condition. - The effect of dropping
format
condition is this will now keep existing bucket positions instead of rebucketing when an old format is loaded and there is no asmap. ("Only rebucket if" in commit description means "Use existing bucket positions if") - In the case where an old format is loaded an there is an asmap, this logic isn't triggered because the
serialized_asmap_checksum == supplied_asmap_checksum
condition is false. - Maybe could be a unit test checking old format number + no asmap uses existing bucket positions
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.
The restore_bucketing change here is aesthetic and the only actual change this line is dropping the format >= Format::V2_ASMAP condition.
Right, this condition doesn't change during loop iterations, so it's clearer to move it out of the loop, mark it const, and only do a conditional check inside the loop on what can change over iterations.
The effect of dropping format condition is this will now keep existing bucket positions instead of rebucketing when an old format is loaded and there is no asmap. ("Only rebucket if" in commit description means "Use existing bucket positions if")
That's right. If the file format is old (no asmap), and we don't have an asmap, then we gain nothing by dropping new bucket positions.
In the case where an old format is loaded an there is an asmap, this logic isn't triggered because the serialized_asmap_checksum == supplied_asmap_checksum condition is false.
Right.
Maybe could be a unit test checking old format number + no asmap uses existing bucket positions
Perhaps. It's a bit difficult to test because we can't easily serialize addrman in the old format.
Thanks @dhruv and @ryanofsky for the reviews. I think this is ready for merge now, and the remaining review comments can be done in follow-ups:
|
Code review ACK 4676a4f |
…ization 4676a4f [addrman] Don't repeat "Bucketing method was updated" log multiple times (John Newbery) 4362923 [addrman] Improve serialization comments (John Newbery) ac3547e [addrman] Improve variable naming/code style of touched code. (John Newbery) a5c9b04 [addrman] Don't rebucket new table entries unnecessarily (John Newbery) 8062d92 [addrman] Rename asmap version to asmap checksum (John Newbery) 009b8e0 [addrman] Improve variable naming/code style of touched code. (John Newbery) b4c5fda [addrman] Fix new table bucketing during unserialization (John Newbery) Pull request description: This fixes three issues in addrman unserialization. 1. An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. 2. Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket. 3. We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that. ACKs for top commit: vasild: ACK 4676a4f glozow: re-ACK bitcoin@4676a4f, changes were a rename, comments, and removing repeat-logging. naumenkogs: ACK 4676a4f laanwj: Code review ACK 4676a4f dhruv: ACK 4676a4f ryanofsky: Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore. Tree-SHA512: b228984f6dec5910be23c3740ae20258da33bcf66ceb7edb10e5a53163450f743bab349e47f09808b7e8d40f27143119ec3e0981d7e678aa494d8559a1c99c23
…ization 4676a4f [addrman] Don't repeat "Bucketing method was updated" log multiple times (John Newbery) 4362923 [addrman] Improve serialization comments (John Newbery) ac3547e [addrman] Improve variable naming/code style of touched code. (John Newbery) a5c9b04 [addrman] Don't rebucket new table entries unnecessarily (John Newbery) 8062d92 [addrman] Rename asmap version to asmap checksum (John Newbery) 009b8e0 [addrman] Improve variable naming/code style of touched code. (John Newbery) b4c5fda [addrman] Fix new table bucketing during unserialization (John Newbery) Pull request description: This fixes three issues in addrman unserialization. 1. An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. 2. Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket. 3. We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that. ACKs for top commit: vasild: ACK 4676a4f glozow: re-ACK bitcoin@4676a4f, changes were a rename, comments, and removing repeat-logging. naumenkogs: ACK 4676a4f laanwj: Code review ACK 4676a4f dhruv: ACK 4676a4f ryanofsky: Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore. Tree-SHA512: b228984f6dec5910be23c3740ae20258da33bcf66ceb7edb10e5a53163450f743bab349e47f09808b7e8d40f27143119ec3e0981d7e678aa494d8559a1c99c23
…ization 4676a4f [addrman] Don't repeat "Bucketing method was updated" log multiple times (John Newbery) 4362923 [addrman] Improve serialization comments (John Newbery) ac3547e [addrman] Improve variable naming/code style of touched code. (John Newbery) a5c9b04 [addrman] Don't rebucket new table entries unnecessarily (John Newbery) 8062d92 [addrman] Rename asmap version to asmap checksum (John Newbery) 009b8e0 [addrman] Improve variable naming/code style of touched code. (John Newbery) b4c5fda [addrman] Fix new table bucketing during unserialization (John Newbery) Pull request description: This fixes three issues in addrman unserialization. 1. An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. 2. Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket. 3. We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that. ACKs for top commit: vasild: ACK 4676a4f glozow: re-ACK bitcoin@4676a4f, changes were a rename, comments, and removing repeat-logging. naumenkogs: ACK 4676a4f laanwj: Code review ACK 4676a4f dhruv: ACK 4676a4f ryanofsky: Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore. Tree-SHA512: b228984f6dec5910be23c3740ae20258da33bcf66ceb7edb10e5a53163450f743bab349e47f09808b7e8d40f27143119ec3e0981d7e678aa494d8559a1c99c23
…ization 4676a4f [addrman] Don't repeat "Bucketing method was updated" log multiple times (John Newbery) 4362923 [addrman] Improve serialization comments (John Newbery) ac3547e [addrman] Improve variable naming/code style of touched code. (John Newbery) a5c9b04 [addrman] Don't rebucket new table entries unnecessarily (John Newbery) 8062d92 [addrman] Rename asmap version to asmap checksum (John Newbery) 009b8e0 [addrman] Improve variable naming/code style of touched code. (John Newbery) b4c5fda [addrman] Fix new table bucketing during unserialization (John Newbery) Pull request description: This fixes three issues in addrman unserialization. 1. An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. 2. Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket. 3. We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that. ACKs for top commit: vasild: ACK 4676a4f glozow: re-ACK bitcoin@4676a4f, changes were a rename, comments, and removing repeat-logging. naumenkogs: ACK 4676a4f laanwj: Code review ACK 4676a4f dhruv: ACK 4676a4f ryanofsky: Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore. Tree-SHA512: b228984f6dec5910be23c3740ae20258da33bcf66ceb7edb10e5a53163450f743bab349e47f09808b7e8d40f27143119ec3e0981d7e678aa494d8559a1c99c23
…ization 4676a4f [addrman] Don't repeat "Bucketing method was updated" log multiple times (John Newbery) 4362923 [addrman] Improve serialization comments (John Newbery) ac3547e [addrman] Improve variable naming/code style of touched code. (John Newbery) a5c9b04 [addrman] Don't rebucket new table entries unnecessarily (John Newbery) 8062d92 [addrman] Rename asmap version to asmap checksum (John Newbery) 009b8e0 [addrman] Improve variable naming/code style of touched code. (John Newbery) b4c5fda [addrman] Fix new table bucketing during unserialization (John Newbery) Pull request description: This fixes three issues in addrman unserialization. 1. An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. 2. Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket. 3. We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that. ACKs for top commit: vasild: ACK 4676a4f glozow: re-ACK bitcoin@4676a4f, changes were a rename, comments, and removing repeat-logging. naumenkogs: ACK 4676a4f laanwj: Code review ACK 4676a4f dhruv: ACK 4676a4f ryanofsky: Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore. Tree-SHA512: b228984f6dec5910be23c3740ae20258da33bcf66ceb7edb10e5a53163450f743bab349e47f09808b7e8d40f27143119ec3e0981d7e678aa494d8559a1c99c23
…ization 4676a4f [addrman] Don't repeat "Bucketing method was updated" log multiple times (John Newbery) 4362923 [addrman] Improve serialization comments (John Newbery) ac3547e [addrman] Improve variable naming/code style of touched code. (John Newbery) a5c9b04 [addrman] Don't rebucket new table entries unnecessarily (John Newbery) 8062d92 [addrman] Rename asmap version to asmap checksum (John Newbery) 009b8e0 [addrman] Improve variable naming/code style of touched code. (John Newbery) b4c5fda [addrman] Fix new table bucketing during unserialization (John Newbery) Pull request description: This fixes three issues in addrman unserialization. 1. An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. 2. Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket. 3. We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that. ACKs for top commit: vasild: ACK 4676a4f glozow: re-ACK bitcoin@4676a4f, changes were a rename, comments, and removing repeat-logging. naumenkogs: ACK 4676a4f laanwj: Code review ACK 4676a4f dhruv: ACK 4676a4f ryanofsky: Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore. Tree-SHA512: b228984f6dec5910be23c3740ae20258da33bcf66ceb7edb10e5a53163450f743bab349e47f09808b7e8d40f27143119ec3e0981d7e678aa494d8559a1c99c23
…ization 4676a4f [addrman] Don't repeat "Bucketing method was updated" log multiple times (John Newbery) 4362923 [addrman] Improve serialization comments (John Newbery) ac3547e [addrman] Improve variable naming/code style of touched code. (John Newbery) a5c9b04 [addrman] Don't rebucket new table entries unnecessarily (John Newbery) 8062d92 [addrman] Rename asmap version to asmap checksum (John Newbery) 009b8e0 [addrman] Improve variable naming/code style of touched code. (John Newbery) b4c5fda [addrman] Fix new table bucketing during unserialization (John Newbery) Pull request description: This fixes three issues in addrman unserialization. 1. An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. 2. Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket. 3. We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that. ACKs for top commit: vasild: ACK 4676a4f glozow: re-ACK bitcoin@4676a4f, changes were a rename, comments, and removing repeat-logging. naumenkogs: ACK 4676a4f laanwj: Code review ACK 4676a4f dhruv: ACK 4676a4f ryanofsky: Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore. Tree-SHA512: b228984f6dec5910be23c3740ae20258da33bcf66ceb7edb10e5a53163450f743bab349e47f09808b7e8d40f27143119ec3e0981d7e678aa494d8559a1c99c23
…ization 4676a4f [addrman] Don't repeat "Bucketing method was updated" log multiple times (John Newbery) 4362923 [addrman] Improve serialization comments (John Newbery) ac3547e [addrman] Improve variable naming/code style of touched code. (John Newbery) a5c9b04 [addrman] Don't rebucket new table entries unnecessarily (John Newbery) 8062d92 [addrman] Rename asmap version to asmap checksum (John Newbery) 009b8e0 [addrman] Improve variable naming/code style of touched code. (John Newbery) b4c5fda [addrman] Fix new table bucketing during unserialization (John Newbery) Pull request description: This fixes three issues in addrman unserialization. 1. An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. 2. Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket. 3. We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that. ACKs for top commit: vasild: ACK 4676a4f glozow: re-ACK bitcoin@4676a4f, changes were a rename, comments, and removing repeat-logging. naumenkogs: ACK 4676a4f laanwj: Code review ACK 4676a4f dhruv: ACK 4676a4f ryanofsky: Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore. Tree-SHA512: b228984f6dec5910be23c3740ae20258da33bcf66ceb7edb10e5a53163450f743bab349e47f09808b7e8d40f27143119ec3e0981d7e678aa494d8559a1c99c23
…ization 4676a4f [addrman] Don't repeat "Bucketing method was updated" log multiple times (John Newbery) 4362923 [addrman] Improve serialization comments (John Newbery) ac3547e [addrman] Improve variable naming/code style of touched code. (John Newbery) a5c9b04 [addrman] Don't rebucket new table entries unnecessarily (John Newbery) 8062d92 [addrman] Rename asmap version to asmap checksum (John Newbery) 009b8e0 [addrman] Improve variable naming/code style of touched code. (John Newbery) b4c5fda [addrman] Fix new table bucketing during unserialization (John Newbery) Pull request description: This fixes three issues in addrman unserialization. 1. An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. 2. Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket. 3. We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that. ACKs for top commit: vasild: ACK 4676a4f glozow: re-ACK bitcoin@4676a4f, changes were a rename, comments, and removing repeat-logging. naumenkogs: ACK 4676a4f laanwj: Code review ACK 4676a4f dhruv: ACK 4676a4f ryanofsky: Code review ACK 4676a4f. I'm not previously familiar with this code but all the changes here do make sense and seem like improvements. Left some notes and comments, but they aren't important so feel to ignore. Tree-SHA512: b228984f6dec5910be23c3740ae20258da33bcf66ceb7edb10e5a53163450f743bab349e47f09808b7e8d40f27143119ec3e0981d7e678aa494d8559a1c99c23
This fixes three issues in addrman unserialization.
An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket.
Unserialization may result in an entry appearing in a 9th bucket. If the entry already appears in 8 buckets don't try to place it in another bucket.
We unnecessarily rebucket when reading a peers.dat with file version 1. Don't do that.