Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc updates to tee up async ChannelMonitorUpdate persist for claims against closed channels #3413

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Commits on Nov 24, 2024

  1. Make test_durable_preimages_on_closed_channel more robust

    Makes `test_durable_preimages_on_closed_channel` more robust
    against changes to the order in which transactions are broadcast.
    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    aba57bb View commit details
    Browse the repository at this point in the history
  2. When removing PeerState check for in-flight mon updates deeply

    When deciding if we should remove a `PeerState` entry we want to
    ensure we don't remove if there are pending updates in
    `in_flight_monitor_updates`. Previously this was done with a simple
    `in_flight_monitor_updates.is_empty()`, however this can prevent
    removal of `PeerState` entries if a channel had an update at some
    point (leaving an entry in the map) but the update was ultimately
    completed.
    
    Instead, we need to iterate over the entries in
    `in_flight_monitor_updates` and decline to remove `PeerState`s only
    if there is an entry for a pending update still in-flight.
    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    19bf5ee View commit details
    Browse the repository at this point in the history
  3. Don't generate dup force-close ChannelMonitorUpdates on startup

    On startup, if we have a channel which was closed immediately
    before shutdown such that the `ChannelMonitorUpdate` marking the
    channel as closed is still in-flight, it doesn't make sense to
    generate a fresh `ChannelMonitorUpdate` marking the channel as
    closed immediately after the existing in-flight one.
    
    Here we detect this case and drop the extra update, though its not
    all that harmful it does avoid some test changes in the coming
    commits.
    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    76119ce View commit details
    Browse the repository at this point in the history
  4. Handle events immediately if we are running during block connection

    During block connection, we cannot apply `ChannelMonitorUpdate`s if
    we're running during the startup sequence (i.e. before the user has
    called any methods outside of block connection). We previously
    handled this by simply always pushing any `ChannelMonitorUpdate`s
    generated during block connection into the
    `pending_background_events` queue.
    
    However, this results in `ChannelMonitorUpdate`s going through the
    queue when we could just push them immediately. Here we explicitly
    check `background_events_processed_since_startup` and use that to
    decide whether to push updates through the background queue
    instead.
    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    0f7bc98 View commit details
    Browse the repository at this point in the history
  5. f sp

    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    f191f09 View commit details
    Browse the repository at this point in the history
  6. Add additional variants to handle_new_monitor_update!

    In the coming commits we'll start handling `ChannelMonitorUpdate`s
    during channel closure in-line rather than after dropping locks via
    `finish_close_channel`. In order to make that easy, here we add a
    new `REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER` variant to
    `handle_new_monitor_update!` which can attempt to apply an update
    without dropping the locks and processing
    `MonitorUpdateCompletionAction`s immediately.
    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    ca7bd32 View commit details
    Browse the repository at this point in the history
  7. Add monitor update handling to update_maps_on_chan_removal

    Closing channels requires a two step process - first
    `update_maps_on_chan_removal` is called while holding the same
    per-peer lock under which the channel reached the terminal state,
    then after dropping the same lock(s), `finish_close_channel` is
    called.
    
    Because the channel is closed and thus no further
    `ChannelMonitorUpdate`s are generated for the off-chain state, we'd
    previously applied the `ChannelMonitorUpdate` in
    `finish_close_channel`. This was tweaked somewhat in
    c99d3d7 when we stopped using
    `u64::MAX` for any updates after closure. However, we worked around
    the races that implied by setting the `update_id` only when we go
    to apply the `ChannelMonitorUpdate`, rather than when we create it.
    
    In a coming commit, we'll need to have an `update_id` immediately
    upon creation (to track in-flight updates that haven't reached
    application yet). This implies that we can no longer apply closure
    `ChannelMonitorUpdate`s after dropping the per-peer lock(s), as the
    updates must be well-ordered with any later updates to the same
    channel, even after it has been closed.
    
    Thus, here, we add `ChannelMonitorUpdate` handling to
    `update_maps_on_chan_removal`, renaming it `locked_close_channel`
    to better capture its new purpose.
    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    b20e481 View commit details
    Browse the repository at this point in the history
  8. f simplify

    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    8e48aa5 View commit details
    Browse the repository at this point in the history
  9. Properly enforce that all ChannelMonitorUpdates are ordered

    c99d3d7 updated
    `ChannelMonitorUpdate::update_id` to continue counting up even
    after the channel is closed. It, however, accidentally updated the
    `ChannelMonitorUpdate` application logic to skip testing that
    `ChannelMonitorUpdate`s are well-ordered after the channel has been
    closed (in an attempt to ensure other checks in the same
    conditional block were applied).
    
    This fixes that oversight.
    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    92989b8 View commit details
    Browse the repository at this point in the history
  10. Check in-flight updates before completing events on closed chans

    When we handle a `ChannelMonitorUpdate` completion we always
    complete everything that was waiting on any updates to the same
    channel all at once. Thus, we need to skip all updates if there's
    pending updates besides the one that was just completed.
    
    We handled this correctly for open channels, but the shortcut for
    closed channels ignored any other pending updates entirely.
    
    Here we fix this, which is ultimately required for tests which are
    added in a few commits to pass.
    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    0109fe3 View commit details
    Browse the repository at this point in the history
  11. f clean up flow

    TheBlueMatt committed Nov 24, 2024
    Configuration menu
    Copy the full SHA
    0578332 View commit details
    Browse the repository at this point in the history