chanstate: use channel types in switch config
What changed, and why it matters
This commit is a straightforward internal code cleanup: it changes which Go package provides the data structures used to describe open and closed channels inside the HTLC switch. There is no change to how data is validated, stored, or transmitted, and no security-relevant behavior is altered.
No security action required; treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors htlcswitch to import channel-state types from the new chanstate package instead of channeldb. Callback signatures in CircuitMapConfig and Switch.Config (FetchAllOpenChannels, FetchAllChannels, FetchClosedChannels) and a mock preimage-cache subscription signature are updated to use chanstate.OpenChannel, chanstate.ChannelCloseSummary, and chanstate.HTLC. The diff is purely type aliasing/import replacement; logic, serialization, and storage remain unchanged.
Changed components
htlcswitch/circuit_map.gohtlcswitch/circuit_map_test.gohtlcswitch/mock.gohtlcswitch/switch.goInspect captured patch +13 / −10
diff --git a/htlcswitch/circuit_map.go b/htlcswitch/circuit_map.go
index 15d4b5f..299abff 100644
--- a/htlcswitch/circuit_map.go
+++ b/htlcswitch/circuit_map.go
@@ -6,7 +6,7 @@ import (
"fmt"
"sync"
- "github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnutils"
@@ -203,12 +203,12 @@ type CircuitMapConfig struct {
// FetchAllOpenChannels is a function that fetches all currently open
// channels from the channel database.
- FetchAllOpenChannels func() ([]*channeldb.OpenChannel, error)
+ FetchAllOpenChannels func() ([]*chanstate.OpenChannel, error)
// FetchClosedChannels is a function that fetches all closed channels
// from the channel database.
FetchClosedChannels func(
- pendingOnly bool) ([]*channeldb.ChannelCloseSummary, error)
+ pendingOnly bool) ([]*chanstate.ChannelCloseSummary, error)
// ExtractErrorEncrypter derives the shared secret used to encrypt
// errors from the obfuscator's ephemeral public key.
diff --git a/htlcswitch/circuit_map_test.go b/htlcswitch/circuit_map_test.go
index c4b6e44..7b93fb0 100644
--- a/htlcswitch/circuit_map_test.go
+++ b/htlcswitch/circuit_map_test.go
@@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcd/btcutil/v2"
"github.com/btcsuite/btcd/wire/v2"
"github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
@@ -362,7 +363,7 @@ func createTestCloseChannelSummery(tx kvdb.RwTx, isPending bool,
}
outputPoint := wire.OutPoint{Hash: hash1, Index: 1}
- ccs := &channeldb.ChannelCloseSummary{
+ ccs := &chanstate.ChannelCloseSummary{
ChanPoint: outputPoint,
ShortChanID: chanID,
ChainHash: hash1,
@@ -371,7 +372,7 @@ func createTestCloseChannelSummery(tx kvdb.RwTx, isPending bool,
RemotePub: testEphemeralKey,
Capacity: btcutil.Amount(10000),
SettledBalance: btcutil.Amount(50000),
- CloseType: channeldb.RemoteForceClose,
+ CloseType: chanstate.RemoteForceClose,
IsPending: isPending,
}
var b bytes.Buffer
@@ -389,7 +390,7 @@ func createTestCloseChannelSummery(tx kvdb.RwTx, isPending bool,
func serializeChannelCloseSummary(
w io.Writer,
- cs *channeldb.ChannelCloseSummary) error {
+ cs *chanstate.ChannelCloseSummary) error {
err := channeldb.WriteElements(
w,
diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go
index e9be926..a3079e6 100644
--- a/htlcswitch/mock.go
+++ b/htlcswitch/mock.go
@@ -22,6 +22,7 @@ import (
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/fn/v2"
@@ -74,7 +75,7 @@ func (m *mockPreimageCache) AddPreimages(preimages ...lntypes.Preimage) error {
}
func (m *mockPreimageCache) SubscribeUpdates(
- chanID lnwire.ShortChannelID, htlc *channeldb.HTLC,
+ chanID lnwire.ShortChannelID, htlc *chanstate.HTLC,
payload *hop.Payload,
nextHopOnionBlob []byte) (*contractcourt.WitnessSubscription, error) {
diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go
index b86d7be..2c0bbdd 100644
--- a/htlcswitch/switch.go
+++ b/htlcswitch/switch.go
@@ -15,6 +15,7 @@ import (
"github.com/btcsuite/btcd/wire/v2"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/fn/v2"
@@ -150,16 +151,16 @@ type Config struct {
// FetchAllOpenChannels is a function that fetches all currently open
// channels from the channel database.
- FetchAllOpenChannels func() ([]*channeldb.OpenChannel, error)
+ FetchAllOpenChannels func() ([]*chanstate.OpenChannel, error)
// FetchAllChannels is a function that fetches all pending open, open,
// and waiting close channels from the database.
- FetchAllChannels func() ([]*channeldb.OpenChannel, error)
+ FetchAllChannels func() ([]*chanstate.OpenChannel, error)
// FetchClosedChannels is a function that fetches all closed channels
// from the channel database.
FetchClosedChannels func(
- pendingOnly bool) ([]*channeldb.ChannelCloseSummary, error)
+ pendingOnly bool) ([]*chanstate.ChannelCloseSummary, error)
// SwitchPackager provides access to the forwarding packages of all
// active channels. This gives the switch the ability to read arbitrary
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.