Fix reorg handling

Our reorg handling was relying on DB transaction rollback behavior. IMO, that is slightly abusive. In any case, it also had a material performance impact on transaction processing during reorgs as the memory pool lock is scoped by the wrapping DB transaction and reorgs trigger acquisition of the lock. Transaction processing could get blocked for several seconds.

The fix is to tighten the scope of our DB transactions. We really only need transaction safety guarantees around a single disconnect/connect. They need to be atomic but the entire reorg doesn't need to be. To do this I had to more closely mimic the reference implementation's behavior. It looks like https://github.com/bitcoin/bitcoin/commit/4e0eed88acdd41826868c151373068bfad18b84d was added recently for a very similar reason.

Not ready to merge as I need to test this in staging. Would be good to have other eyes on it though.