AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 25 Bitcoin

contractcourt: add sync dispatch fast-path for single confirmation closes

Public commit record

What the developer wrote

Authored by Olaoluwa Osuntokun

95/100 · Strong
contractcourt: add sync dispatch fast-path for single confirmation closes

In this commit, we add a fast-path optimization to the chain watcher's
closeObserver that immediately dispatches close events when only a single
confirmation is required (numConfs == 1). This addresses a timing issue
with integration tests that were designed around the old synchronous
blockbeat behavior, where close events were dispatched immediately upon
spend detection.

The recent async confirmation architecture (introduced in commit f6f716ab7)
properly handles reorgs by waiting for N confirmations before dispatching
close events. However, this created a race condition in integration tests
that mine blocks synchronously and expect immediate close notifications.
With the build tag setting numConfs to 1 for itests, the async confirmation
notification could arrive after the test already started waiting for the
close event, causing timeouts.

We introduce a new handleSpendDispatch method that checks if numConfs == 1
and, if so, immediately calls handleCommitSpend to dispatch the close event
synchronously, then returns true to skip the async state machine. This
preserves the old behavior for integration tests while maintaining the full
async reorg protection for production (where numConfs >= 3).

The implementation adds the fast-path check in both spend detection paths
(blockbeat and spend notification) to ensure consistent behavior regardless
of which detects the spend first. We also update the affected unit tests to
remove their expectation of confirmation registration, since the fast-path
bypasses that step entirely.

This approach optimizes for the integration test scenario without compromising
production safety, as the fast-path only activates when a single confirmation
is sufficient - a configuration that only exists in the controlled test
environment.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit adds a special fast-path in LND's channel close watcher. When only one confirmation is needed (which only happens in integration tests), it immediately processes a channel close instead of waiting for the normal multi-confirmation safety check. This is described as a test-only optimization to fix flaky tests, not a production security fix. In normal production use, the code still waits for multiple confirmations before treating a channel close as final, preserving protection against blockchain reorganizations.

Recommended action

No immediate action required. Treat as a test reliability optimization rather than a security vulnerability. If reviewing for security, verify that requiredConfsForSpend() cannot return 1 in production builds and that the fast-path is not reachable outside controlled test configurations. Consider adding an explicit build-tag or runtime guard to ensure the fast-path cannot activate in production.

Security signals we found

01

Bypass of async confirmation state machine under single-confirmation configuration

02

Synchronous dispatch of channel close events upon spend detection when numConfs == 1

03

Change of error handling from return to continue in closeObserver event loop

04

Test expectation changed to remove confirmation registration wait

05

Commit message frames change as test-only optimization with production safety preserved

Risk score

Why this scored 25/100

Our methodology →
Potential impact 4/30
Exploitability 3/25
Stealth signal 3/15
Affected reach 5/15
Confidence 7/10
Evidence quality 3/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.