Patch from ArtForz, who discovered the problem.
The problem was chaining large transactions (transactions with lots of ins and outs) would make the berkeley db transaction log get very big, as the dependencies (TxIns) of a transaction might be re-written multiple times.
With this fix, each each transaction referred to by TxIns is written once.