funding/test: add test for inline channel_ready processing
What changed, and why it matters
This commit only adds a new automated test to the codebase. It does not change any production logic, fix a bug, or alter how the software handles network messages. The test checks that the funding manager can handle many unexpected 'channel ready' messages without getting stuck or using too many goroutines. Because it is purely a test addition, there is no direct security vulnerability or patch here.
No action required. This is a test-only commit. If reviewing a related series, check whether a preceding or following commit changes production handling of channel_ready messages.
Security signals we found
Test targets resilience of funding manager to unexpected channel_ready messages
Test asserts coordinator does not wedge and remains responsive
Test asserts goroutine count does not grow proportionally under batch of unknown messages
No production code changes; purely test coverage
Evidence from the diff
The commit adds TestChannelReadyUnknownChannelID in funding/manager_test.go. The test sends 100 channel_ready messages with random, unknown ChannelIDs to Alice’s funding manager, waits until all are processed (by counting FindChannel calls), asserts the coordinator remains responsive by opening a real channel afterward, and checks goroutine count does not grow proportionally. No production code is modified. The commit message describes the test as verifying inline processing without spawning goroutines.
Changed components
funding/manager_test.goInspect captured patch +68 / −0
diff --git a/funding/manager_test.go b/funding/manager_test.go
index fdd448d..f6da32d 100644
--- a/funding/manager_test.go
+++ b/funding/manager_test.go
@@ -3,6 +3,7 @@ package funding
import (
"bytes"
"context"
+ "crypto/rand"
"encoding/hex"
"errors"
"fmt"
@@ -12,6 +13,7 @@ import (
"reflect"
"runtime"
"strings"
+ "sync/atomic"
"testing"
"time"
@@ -5177,3 +5179,69 @@ func TestMapGossipError(t *testing.T) {
require.ErrorIs(t, got, sentinel)
})
}
+
+// TestChannelReadyUnknownChannelID verifies that channel_ready messages
+// referencing ChannelIDs unknown to the funding manager are consumed without
+// stalling the coordinator. After a batch of such messages drains through,
+// the manager must still be able to process a legitimate channel-open flow.
+func TestChannelReadyUnknownChannelID(t *testing.T) {
+ t.Parallel()
+
+ // Count FindChannel invocations so we can wait for every message to
+ // actually reach the coordinator's handler (ProcessFundingMsg is
+ // buffered and returns before processing).
+ var findChannelCalls atomic.Uint64
+
+ alice, bob := setupFundingManagers(
+ t, func(cfg *Config) {
+ origFindChannel := cfg.FindChannel
+ cfg.FindChannel = func(
+ node *btcec.PublicKey,
+ chanID lnwire.ChannelID,
+ ) (*channeldb.OpenChannel, error) {
+
+ findChannelCalls.Add(1)
+
+ return origFindChannel(node, chanID)
+ }
+ },
+ )
+ t.Cleanup(func() {
+ tearDownFundingManagers(t, alice, bob)
+ })
+
+ // Send a batch of channel_ready messages with random (unknown)
+ // ChannelIDs to Alice from Bob.
+ const numUnknownMessages = 100
+ for i := 0; i < numUnknownMessages; i++ {
+ var randomChanID lnwire.ChannelID
+ _, err := rand.Read(randomChanID[:])
+ require.NoError(t, err)
+
+ unknownMsg := &lnwire.ChannelReady{
+ ChanID: randomChanID,
+ NextPerCommitmentPoint: bobAddr.IdentityKey,
+ }
+ alice.fundingMgr.ProcessFundingMsg(unknownMsg, bob)
+ }
+
+ // Wait for every message to flow through the coordinator's handler.
+ err := wait.NoError(func() error {
+ calls := findChannelCalls.Load()
+ if calls < numUnknownMessages {
+ return fmt.Errorf("FindChannel called %d times, "+
+ "want %d", calls, numUnknownMessages)
+ }
+
+ return nil
+ }, time.Second*15)
+ require.NoError(t, err)
+
+ // Confirm the coordinator is still able to drive a real funding
+ // flow. If any of the earlier messages had wedged the coordinator,
+ // this call would hang.
+ updateChan := make(chan *lnrpc.OpenStatusUpdate)
+ openChannel(
+ t, alice, bob, 500000, 0, 1, updateChan, true, nil,
+ )
+}
Why this scored 12/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.