Commit message · Valentine WallaceDerive MonitorEvent IDs deterministically
MonitorEvent IDs were originally implemented as random. This was broken because
ChannelMonitors may not be persisted on each block, so if a block was connected
to a monitor and generated monitor events that were surfaced to the
ChannelManager, that block may need to be reconnected later and would then
surface the same monitor events but with different ids.
For context, an upcoming version of LDK (say, 0.6) will rely on monitor events
to drive all off- and on-chain HTLC resolution. For outbound payments, this
means guaranteeing that for every payment, a Payment{Sent,Failed} event is
surfaced and the user processes it.
So this previous implementation could lead to a missing Payment{Sent,Failed}
in the following scenario:
1. Send an outbound payment on 0.4
2. Receive preimage on-chain from a block -> surface MonitorEvent::HTLCEvent {
id: X } (monitor not persisted)
3. Process monitor event X, generate PaymentSent with EventCompletionAction {
ack_monitor_event: X } (PaymentSent not processed yet)
4. Restart, monitor last persisted prior to receiving the preimage on-chain
5. Monitor processes the same block again -> surface duplicate
MonitorEvent::HTLCEvent { id: Y }
6. Process monitor event Y, ack it immediately because X is already cached with
PaymentSent
7. Restart on 0.6 with a stale manager that forgot the payment --> neither X or
Y replay and PaymentSent is lost
As such, here we begin setting monitor event IDs deterministically so the same
block replay will result in the same IDs for any resulting monitor events.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
75/100 · AdequateMessage clarity
✓ Descriptive subject✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Names security-relevant behavior explicitly