Split `PeerManager::handle_message` to avoid explicit `mem::drop`
authorElias Rohrer <dev@tnull.de>
Mon, 25 Mar 2024 15:35:37 +0000 (16:35 +0100)
committerElias Rohrer <dev@tnull.de>
Thu, 4 Apr 2024 09:06:07 +0000 (11:06 +0200)
commitf2ecf8db15e8a41fcd061485e01387b536484a60
treef14f271d55e26fb6f9c2d4ed5a489271237ba6d4
parentb8b1ef3149f26992625a03d45c0307bfad70e8bd
Split `PeerManager::handle_message` to avoid explicit `mem::drop`

Previously, `handle_message` was a single large method consisting of two
logical parts: one modifying the peer state hence requiring us to hold
the `peer_lock` `MutexGuard`, and, after calling `mem::drop(peer_lock)`,
the remainder which does not only *not* require to hold the
`MutexGuard`, but relies on it being dropped to avoid double-locking.

However, the `mem::drop` was easily overlooked, making reasoning about
lock orders etc. a headache. Here, we therefore have
`handle_message` call two sub-methods reflecting the two logical parts,
allowing us to avoid the explicit `mem::drop`, while at the same time
making it less error-prone due to the two methods' signatures.
lightning/src/ln/peer_handler.rs