bitcoin/bitcoin — pull request #5389 by cozz (2014-11-28 14:25:02+00:00)
Title: [Wallet] Wallet-pruning

Wallet pruning can be used to speed up and shrink large wallets.

Transactions will only be removed, if this for sure does not affect your balance.

RPC prunewallet(n) removes transactions older than n days (n >= 1). Or adding prunewallet=n to bitcoin.conf prunes on startup. Note that the latter is required to prevent rescan from readding the transactions.

A transaction is pruned, if the following conditions are met
- at least 100 confirmations
- older than n days according to block-timestamp (n >= 1)
- our outputs must be completely spent and also the spending transaction must
have at least 100 confirmations
- the inputs we spent are also pruned/prunable transactions, so that they dont require us as a spent-flag anymore

A new class STXO has been introduced, which loops over the last 100 blocks and builds a temporary recently-spent-outputs index.
Its only used on rescan, if wallet pruning is enabled. This is necessary to answer the question
"has the spending transaction at least 100 confirmations?".
Because if not, a rescan wants to always add the transaction to the wallet, and not skip.
This is because, when we rescan, we dont have the spending transaction anymore in the wallet, to check how many confirmations it has.
Also a rescan checks if spent or not in our coins-utxo, because the wallet does not know if spent or not while rescaning.

Note that the feature is disabled if someone uses the account-feature. I could add support for this, but I am not bothering if our plan is to remove the account-feature. Because pruning as is, would destroy account-balances.