What changed, and why it matters
This commit is a small internal code cleanup in LND's payment routing layer. It swaps some uses of the older `channeldb` package for a newer `chanstate` package when passing around channel type information. There is no change to user-facing behavior, no bug fix, and no security patch.
No security action needed. Treat as routine refactoring; normal code-review and CI pass are sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors htlcswitch interfaces and tests to use chanstate.ChannelType and chanstate.OpenChannel instead of channeldb.ChannelType and channeldb.OpenChannel for tower client registration, channel-update callbacks, and dust-limit helpers. Forwarding-package persistence still uses channeldb. The change is purely architectural boundary movement between internal packages.
Changed components
htlcswitch/interfaces.gohtlcswitch/link.gohtlcswitch/link_test.gohtlcswitch/mailbox_test.goInspect captured patch +10 / −7
diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go
index 53d1c59..ef62eb7 100644
--- a/htlcswitch/interfaces.go
+++ b/htlcswitch/interfaces.go
@@ -6,6 +6,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/fn/v2"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/invoices"
@@ -354,7 +355,7 @@ type TowerClient interface {
// parameters within the client. This should be called during link
// startup to ensure that the client is able to support the link during
// operation.
- RegisterChannel(lnwire.ChannelID, channeldb.ChannelType) error
+ RegisterChannel(lnwire.ChannelID, chanstate.ChannelType) error
// BackupState initiates a request to back up a particular revoked
// state. If the method returns nil, the backup is guaranteed to be
diff --git a/htlcswitch/link.go b/htlcswitch/link.go
index 0b4516d..9e3adf0 100644
--- a/htlcswitch/link.go
+++ b/htlcswitch/link.go
@@ -16,6 +16,7 @@ import (
"github.com/btcsuite/btcd/wire/v2"
"github.com/btcsuite/btclog/v2"
"github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/graph/db/models"
@@ -258,7 +259,7 @@ type ChannelLinkConfig struct {
// NotifyChannelUpdate allows the link to tell the ChannelNotifier when
// a channel's state has been updated.
- NotifyChannelUpdate func(*channeldb.OpenChannel)
+ NotifyChannelUpdate func(*chanstate.OpenChannel)
// HtlcNotifier is an instance of a htlcNotifier which we will pipe htlc
// events through.
@@ -2372,7 +2373,7 @@ type dustClosure func(feerate chainfee.SatPerKWeight, incoming bool,
whoseCommit lntypes.ChannelParty, amt btcutil.Amount) bool
// dustHelper is used to construct the dustClosure.
-func dustHelper(chantype channeldb.ChannelType, localDustLimit,
+func dustHelper(chantype chanstate.ChannelType, localDustLimit,
remoteDustLimit btcutil.Amount) dustClosure {
isDust := func(feerate chainfee.SatPerKWeight, incoming bool,
diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go
index d73a355..2876089 100644
--- a/htlcswitch/link_test.go
+++ b/htlcswitch/link_test.go
@@ -2240,7 +2240,7 @@ func newSingleLinkTestHarness(t *testing.T, chanAmt,
MaxFeeAllocation: DefaultMaxLinkFeeAllocation,
NotifyActiveLink: func(wire.OutPoint) {},
NotifyActiveChannel: func(wire.OutPoint) {},
- NotifyChannelUpdate: func(*channeldb.OpenChannel) {},
+ NotifyChannelUpdate: func(*cstate.OpenChannel) {},
NotifyInactiveChannel: func(wire.OutPoint) {},
NotifyInactiveLinkEvent: func(wire.OutPoint) {},
HtlcNotifier: aliceSwitch.cfg.HtlcNotifier,
@@ -4931,7 +4931,7 @@ func (h *persistentLinkHarness) restartLink(
NotifyActiveChannel: func(wire.OutPoint) {},
NotifyInactiveChannel: func(wire.OutPoint) {},
NotifyInactiveLinkEvent: func(wire.OutPoint) {},
- NotifyChannelUpdate: func(*channeldb.OpenChannel) {},
+ NotifyChannelUpdate: func(*cstate.OpenChannel) {},
HtlcNotifier: h.hSwitch.cfg.HtlcNotifier,
SyncStates: syncStates,
GetAliases: getAliases,
@@ -5779,7 +5779,7 @@ type mockFailLoadFwdPkgStore struct {
// failure handling while all other store methods delegate to the embedded
// store.
func (m *mockFailLoadFwdPkgStore) LoadFwdPkgs(
- *channeldb.OpenChannel) ([]*channeldb.FwdPkg, error) {
+ *cstate.OpenChannel) ([]*channeldb.FwdPkg, error) {
return nil, fmt.Errorf("failing LoadFwdPkgs")
}
diff --git a/htlcswitch/mailbox_test.go b/htlcswitch/mailbox_test.go
index af4b192..b732694 100644
--- a/htlcswitch/mailbox_test.go
+++ b/htlcswitch/mailbox_test.go
@@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcd/btcutil/v2"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/lnmock"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
@@ -586,7 +587,7 @@ func TestMailBoxDustHandling(t *testing.T) {
})
}
-func testMailBoxDust(t *testing.T, chantype channeldb.ChannelType) {
+func testMailBoxDust(t *testing.T, chantype chanstate.ChannelType) {
t.Parallel()
ctx := newMailboxContext(t, time.Now(), testExpiry)
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.