Skip to content

Commit 5ae812f

Browse files
committed
Avoid writing ChannelManager when hitting lnd bug 6039
When we hit lnd bug 6039, we end up sending error messages to peers in a loop. This should be fine, but because we used the generic `PersistenceNotifierGuard::notify_on_drop` lock above the specific handling, we end up writing `ChannelManager` every time we manage a round-trip to our peer. This can add up quite quickly, and isn't actually changing, so we really need to avoid writing the `ChannelManager` in this case.
1 parent b435384 commit 5ae812f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8178,8 +8178,6 @@ where
81788178
}
81798179

81808180
fn handle_error(&self, counterparty_node_id: &PublicKey, msg: &msgs::ErrorMessage) {
8181-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
8182-
81838181
match &msg.data as &str {
81848182
"cannot co-op close channel w/ active htlcs"|
81858183
"link failed to shutdown" =>
@@ -8213,13 +8211,21 @@ where
82138211
log_level: Level::Trace,
82148212
}
82158213
});
8214+
// This can happen in a fairly tight loop, so we absolutely cannot trigger
8215+
// a `ChannelManager` write here.
8216+
PersistenceNotifierGuard::optionally_notify(
8217+
self,
8218+
|| -> NotifyOption { NotifyOption::SkipPersistHandleEvents }
8219+
);
82168220
}
82178221
}
82188222
return;
82198223
}
82208224
_ => {}
82218225
}
82228226

8227+
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
8228+
82238229
if msg.channel_id.is_zero() {
82248230
let channel_ids: Vec<ChannelId> = {
82258231
let per_peer_state = self.per_peer_state.read().unwrap();

0 commit comments

Comments
 (0)