contractcourt: update existing chain watcher tests due to new logic
What changed, and why it matters
This commit only updates test code to match new behavior in the chain watcher component. It does not change any production code, so it cannot directly introduce a security vulnerability or fix one in running software. The tests now simulate waiting for a transaction confirmation after detecting a spend, reflecting a change made elsewhere in the codebase.
No security action needed. Review the related production commit that introduced the new confirmation logic if assessing security impact, as this commit only updates tests to match it.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies contractcourt/chain_watcher_test.go to adapt existing unit tests to new chain watcher logic. It adds a confirmation registration channel (ConfRegistered), sets chanCloseConfs to 1 via fn.Some(uint32(1)), and calls WaitForConfRegistrationAndSend(t) after sending blockbeats/spend events. These are purely test infrastructure changes; no production logic is altered.
Changed components
contractcourt/chain_watcher_test.goInspect captured patch +37 / −12
diff --git a/contractcourt/chain_watcher_test.go b/contractcourt/chain_watcher_test.go
index 2dc3605..c57859c 100644
--- a/contractcourt/chain_watcher_test.go
+++ b/contractcourt/chain_watcher_test.go
@@ -12,6 +12,7 @@ import (
"github.com/lightningnetwork/lnd/chainio"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/input"
lnmock "github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet"
@@ -34,16 +35,19 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
// With the channels created, we'll now create a chain watcher instance
// which will be watching for any closes of Alice's channel.
+ confRegistered := make(chan struct{}, 1)
aliceNotifier := &lnmock.ChainNotifier{
- SpendChan: make(chan *chainntnfs.SpendDetail, 1),
- EpochChan: make(chan *chainntnfs.BlockEpoch),
- ConfChan: make(chan *chainntnfs.TxConfirmation),
+ SpendChan: make(chan *chainntnfs.SpendDetail, 1),
+ EpochChan: make(chan *chainntnfs.BlockEpoch),
+ ConfChan: make(chan *chainntnfs.TxConfirmation, 1),
+ ConfRegistered: confRegistered,
}
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
chanState: aliceChannel.State(),
notifier: aliceNotifier,
signer: aliceChannel.Signer,
extractStateNumHint: lnwallet.GetStateNumHint,
+ chanCloseConfs: fn.Some(uint32(1)),
})
require.NoError(t, err, "unable to create chain watcher")
err = aliceChainWatcher.Start()
@@ -90,6 +94,11 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
t.Fatalf("unable to send blockbeat")
}
+ // Wait for the chain watcher to register for confirmations and send
+ // the confirmation. Since we set chanCloseConfs to 1, one confirmation
+ // is sufficient.
+ aliceNotifier.WaitForConfRegistrationAndSend(t)
+
// We should get a new spend event over the remote unilateral close
// event channel.
var uniClose *RemoteUnilateralCloseInfo
@@ -144,16 +153,19 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
// With the channels created, we'll now create a chain watcher instance
// which will be watching for any closes of Alice's channel.
+ confRegistered := make(chan struct{}, 1)
aliceNotifier := &lnmock.ChainNotifier{
- SpendChan: make(chan *chainntnfs.SpendDetail),
- EpochChan: make(chan *chainntnfs.BlockEpoch),
- ConfChan: make(chan *chainntnfs.TxConfirmation),
+ SpendChan: make(chan *chainntnfs.SpendDetail),
+ EpochChan: make(chan *chainntnfs.BlockEpoch),
+ ConfChan: make(chan *chainntnfs.TxConfirmation),
+ ConfRegistered: confRegistered,
}
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
chanState: aliceChannel.State(),
notifier: aliceNotifier,
signer: aliceChannel.Signer,
extractStateNumHint: lnwallet.GetStateNumHint,
+ chanCloseConfs: fn.Some(uint32(1)),
})
require.NoError(t, err, "unable to create chain watcher")
if err := aliceChainWatcher.Start(); err != nil {
@@ -219,6 +231,11 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
t.Fatalf("unable to send blockbeat")
}
+ // Wait for the chain watcher to register for confirmations and send
+ // the confirmation. Since we set chanCloseConfs to 1, one confirmation
+ // is sufficient.
+ aliceNotifier.WaitForConfRegistrationAndSend(t)
+
// We should get a new spend event over the remote unilateral close
// event channel.
var uniClose *RemoteUnilateralCloseInfo
@@ -331,10 +348,12 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
// With the channels created, we'll now create a chain watcher
// instance which will be watching for any closes of Alice's
// channel.
+ confRegistered := make(chan struct{}, 1)
aliceNotifier := &lnmock.ChainNotifier{
- SpendChan: make(chan *chainntnfs.SpendDetail),
- EpochChan: make(chan *chainntnfs.BlockEpoch),
- ConfChan: make(chan *chainntnfs.TxConfirmation),
+ SpendChan: make(chan *chainntnfs.SpendDetail),
+ EpochChan: make(chan *chainntnfs.BlockEpoch),
+ ConfChan: make(chan *chainntnfs.TxConfirmation),
+ ConfRegistered: confRegistered,
}
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
chanState: aliceChanState,
@@ -407,6 +426,8 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
t.Fatalf("unable to send blockbeat")
}
+ aliceNotifier.WaitForConfRegistrationAndSend(t)
+
// We should get a new uni close resolution that indicates we
// processed the DLP scenario.
var uniClose *RemoteUnilateralCloseInfo
@@ -532,10 +553,12 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
// With the channels created, we'll now create a chain watcher
// instance which will be watching for any closes of Alice's
// channel.
+ confRegistered := make(chan struct{}, 1)
aliceNotifier := &lnmock.ChainNotifier{
- SpendChan: make(chan *chainntnfs.SpendDetail),
- EpochChan: make(chan *chainntnfs.BlockEpoch),
- ConfChan: make(chan *chainntnfs.TxConfirmation),
+ SpendChan: make(chan *chainntnfs.SpendDetail),
+ EpochChan: make(chan *chainntnfs.BlockEpoch),
+ ConfChan: make(chan *chainntnfs.TxConfirmation),
+ ConfRegistered: confRegistered,
}
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
chanState: aliceChanState,
@@ -604,6 +627,8 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
t.Fatalf("unable to send blockbeat")
}
+ aliceNotifier.WaitForConfRegistrationAndSend(t)
+
// We should get a local force close event from Alice as she
// should be able to detect the close based on the commitment
// outputs.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.