Acquire `per_peer_state` `write` lock earlier in `ChannelManager::write`
Previously, we would hold the `per_peer_state` `read` lock during the
serialization of channel objects. While this might have reduced lock
congestion minimally, we also calculated the number of serializable
peers in this phase, only to use it later after dropping and reacquiring
the `per_peer_state` `write` lock.
This could potentially result in inconsistiencies if the
`serializable_peer_count` would change after we dropped the `read` lock
but before we acquired the `write` lock.
To mitigate the issue we just acquire the `write` lock ealier and hold
it for the remainder of `ChannelManager::write`.