MIN_UNUSED_ADDRESSES

const val MIN_UNUSED_ADDRESSES: Int = 100

If we fall below this many unused addresses, make more. This happens whenever the wallet "sees" an address being used by a transaction. In the situation where a foreign same-seed wallet is spending, we might miss some transactions if more than this number of addresses are used in a block. The situation occurs because tx are not committed in creation order in blocks, so if we are tracking N unused addresses, the N+1th unused address could appear in the block first, but we haven't yet started tracking it. Ofc, no money is lost, the SPV wallet just doesn't 'see' the deposit/UTXO. Set this number high enough that such a situation would be extremely unlikely. Also to avoid race conditions when installing the bloom filter and using an address, it makes sense to generate the new ones well before they are used.

If a single wallet places this many new addresses in a single block, we may miss a transaction on rediscovery because we haven't installed the bloom filter for the new transactions yet. So we always want to be watching many transactions ahead.