In many places, our code assumes that presence in the address book indicates a non-change key, and absence of an entry in mapAddressBook indicates change.
This no longer holds true after #13756 (first released in 0.19) since it added a “used” DestData populated even for change addresses. Only avoid-reuse wallets should be affected by this issue.
Thankfully, populating DestData does not write a label to the database, so we can retroactively fix this (so long as the user didn’t see the change address and manually assign it a real label).
Fixing it is accomplished by:
- Adding a new bool to CAddressBookData to track if the label has ever been assigned, either by loading one from the database, or by assigning one at runtime.
CAddressBookData::IsChangeandCWallet::FindAddressBookEntryare new methods to assist in excluding change from code that doesn’t expect to see them.- For safety in merging,
CAddressBookData::namehas been made read-only (the actual data is stored inm_label, a new private member, and can be changed only withsetLabelwhich updates them_changeflag), andmapAddressBookhas been renamed tom_address_book(to force old code to be rebased to compile).
A final commit also does some minor optimisation, avoiding redundant lookups in m_address_book when we already have a pointer to the CAddressBookData.