Skip to content

Remove Completed from Watch trait, making updates always-async#4451

Draft
joostjager wants to merge 1 commit intolightningdevkit:mainfrom
joostjager:async-only-chanmgr
Draft

Remove Completed from Watch trait, making updates always-async#4451
joostjager wants to merge 1 commit intolightningdevkit:mainfrom
joostjager:async-only-chanmgr

Conversation

@joostjager
Copy link
Contributor

The complexity of maintaining both synchronous and asynchronous monitor update completion paths in ChannelManager has become increasingly difficult to reason about. Each new feature touching monitor updates must account for both modes, and subtle bugs have emerged from the interplay.

This PR removes the sync path by making the Watch-ChannelManager interface always-async. ChainMonitor maps Persist::Completed onto an immediately-queued MonitorEvent::Completed, so channels unblock on the next event processing round rather than inline. The Persist trait and ChannelMonitorUpdateStatus enum are unchanged.

The Watch trait previously shared ChannelMonitorUpdateStatus (with
Completed, InProgress, UnrecoverableError variants) with the Persist
trait. This meant ChannelManager had to handle both synchronous
completion and asynchronous completion, including a runtime check
(monitor_update_type atomic) to ensure they weren't mixed.

This commit makes the Watch trait always-async: watch_channel returns
Result<(), ()> and update_channel returns (). ChainMonitor maps
Persist::Completed onto an immediately-queued MonitorEvent::Completed
so the channel unblocks on the next event processing round. When
Persist returns Completed but prior async updates are still pending,
no event is emitted since the prior updates' eventual completion via
channel_monitor_updated will cover this update too.

This allows removing from ChannelManager:
- The WatchUpdateStatus enum (and former ChannelMonitorUpdateStatus
  usage in Watch)
- The monitor_update_type atomic and its mode-mixing checks
- handle_monitor_update_res (was just a log, inlined)
- handle_post_close_monitor_update (trivial wrapper, inlined)
- handle_new_monitor_update_with_status (sync completion path)

AI tools were used in preparing this commit.
@ldk-reviews-bot
Copy link

👋 Hi! I see this is a draft PR.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants