We should have a unit test which covers the case that an ancestor is represented more than once.
Currently, suppose that you have a transaction set like:
Txn B: A3 -> {B0, B1} Txn C: B1 -> {C0, C1, C2} Txn D: {C0, B0} -> {D0}
Then D's ancestor count should be 2, but it's possible to make an error and over count A (and maybe B) as an ancestor twice (once via A3->B1->C0, once by A3->B0).
This is distinct from a transaction such as:
Txn E: {B0, B1} -> {E0, E1, E2, E3}
Because it'd be easy to implement a set of hashes from the inputs rather than properly from all the ancestors.
The current code is of course correct, but this came up in testing a change that it wasn't covered.
Currently, wallet_labels.py is the only test which, probabilistically, checks this.