backport fixes to make Gavin's "Simplify storage of orphan transactions"
(159bc4819304c4394a92230c9e7b9f3416abe877) work on 0.8