We never have multiple threads making able to multiple WalletBatchs due to the extensive use of cs_wallet, cs_KeyStore, and cs_desc_man, so the use of refcounting to handle the case where that may happen is unnecessary. Thus we can use an assert to enforce that only one BerkeleyBatch is accessing the BerkeleyDatabase at a time. The only instances where multiple BerkeleyBatchs were being created were where one was made in a caller function, and then the called function created another for itself. For those cases, we instead either pass in the caller’s WalletBatch or limit the scope of the caller’s WalletBatch so that there are no overlaps.
The refcounting in BerkeleyDatabase is kept because it did more than just count the number of BerkeleyBatchs, it also indicated when the database was flushed. However the AddRef and RemoveRef functions have been removed from WalletDatabase.