Skip to content

fix(cbf): shut down chain source#27

Merged
randomlogin merged 3 commits into
cbf-chain-source-cleanupfrom
cbf-stop
Jun 8, 2026
Merged

fix(cbf): shut down chain source#27
randomlogin merged 3 commits into
cbf-chain-source-cleanupfrom
cbf-stop

Conversation

@febyeji

@febyeji febyeji commented Jun 8, 2026

Copy link
Copy Markdown
Owner
  • Implemented CbfChainSource::stop() by shutting down the active Kyoto requester.
  • Marked the CBF runtime status as stopped when the Kyoto node exits cleanly.
  • Routed generic ChainSource::stop() calls to the CBF backend.

- Implement CBF requester shutdown and mark runtime status stopped on clean exit.
- Route generic chain source stop calls to the CBF backend.

AI-assisted-by: OpenAI Codex
@febyeji febyeji changed the title fix(cbf): shut down chain source cleanly fix(cbf): shut down chain source Jun 8, 2026
@febyeji febyeji marked this pull request as ready for review June 8, 2026 06:09
@randomlogin

Copy link
Copy Markdown
Collaborator

I think we can also add changes you introduced here: 0181500, reordering the stop and wait_on_background_tasks.

@randomlogin

Copy link
Copy Markdown
Collaborator

There is a corner case with restarts: when the node crashed and we wait for the backoff time to tick, if we call stop() it will be ignored and the node rebuilds.

We can solve it as it was previously: https://github.com/febyeji/ldk-node/blob/add-cbf-chain-source/src/chain/cbf.rs#L403

Perhaps can be fixed in the following way (claude-generated):

// Publish the new requester only if stop() didn't fire during the
// backoff sleep. Holding the lock across both the check and the
// assignment makes this atomic w.r.t. stop(): either stop() ran
// first (we observe `Stopped` and bail), or we publish `Started`
// and a later stop() shuts the new node down once it's running.
{
        let mut status = restart_status.lock().expect("lock");
        if matches!(*status, CbfRuntimeStatus::Stopped) {
                log_info!(
                        restart_logger,
                        "CBF restart aborted: stop() called during backoff.",
                );
                break;
        }
        *status = CbfRuntimeStatus::Started { requester: new_requester };
}

current_node = new_node;
current_info_rx = new_info_rx;
current_warn_rx = new_warn_rx;
current_event_rx = new_event_rx;

febyeji added 2 commits June 9, 2026 04:21
- Stop runtime-dependent chain sources before waiting for non-cancellable background tasks.

- Allow the CBF requester shutdown to unblock the node run loop during Node::stop.
- Check CBF runtime status before publishing a rebuilt requester after restart backoff.

- Shut down the newly built requester and exit the restart loop if stop() ran during the backoff.
@randomlogin randomlogin self-assigned this Jun 8, 2026

@randomlogin randomlogin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@randomlogin randomlogin merged commit 1012743 into cbf-chain-source-cleanup Jun 8, 2026
24 of 46 checks passed
@febyeji febyeji deleted the cbf-stop branch June 8, 2026 23:47
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