two_phase_commit: split some common code out