What changed, and why it matters
This commit is a straightforward internal code cleanup. It changes one part of the Lightning Network Daemon (LND) to use a newer, more focused package called `chanstate` for representing open channel data, instead of the older, broader `channeldb` package. The behavior of the program is intended to stay exactly the same; only the names and locations of the data types used in the code have changed. There is no indication this fixes or introduces a security problem.
No security action required. Treat as a normal maintainability refactor and review through standard code-review processes.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors routing/localchans/manager.go and its test file to use github.com/lightningnetwork/lnd/chanstate types (OpenChannel, ChannelConfig, ChannelStateBounds) in place of the equivalent channeldb types. The FetchChannel function signature and helper methods (createMissingEdge, createEdge, getHtlcAmtLimits) are updated accordingly. channeldb is retained only for the concrete ErrChannelNotFound error value. This is a dependency-boundary refactor with no functional change visible in the diff.
Changed components
routing/localchans/manager.gorouting/localchans/manager_test.goInspect captured patch +19 / −16
diff --git a/routing/localchans/manager.go b/routing/localchans/manager.go
index 0eda604..1c9f906 100644
--- a/routing/localchans/manager.go
+++ b/routing/localchans/manager.go
@@ -11,6 +11,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire/v2"
"github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/funding"
@@ -48,7 +49,7 @@ type Manager struct {
// FetchChannel is used to query local channel parameters. Optionally an
// existing db tx can be supplied.
- FetchChannel func(chanPoint wire.OutPoint) (*channeldb.OpenChannel,
+ FetchChannel func(chanPoint wire.OutPoint) (*chanstate.OpenChannel,
error)
// AddEdge is used to add edge/channel to the topology of the router.
@@ -247,7 +248,7 @@ func (r *Manager) UpdatePolicy(ctx context.Context,
}
func (r *Manager) createMissingEdge(ctx context.Context,
- channel *channeldb.OpenChannel,
+ channel *chanstate.OpenChannel,
newSchema routing.ChannelPolicy) (*models.ChannelEdgeInfo,
*models.ChannelEdgePolicy, *lnrpc.FailedUpdate) {
@@ -294,7 +295,7 @@ func (r *Manager) createMissingEdge(ctx context.Context,
}
// createEdge recreates an edge and policy from an open channel in-memory.
-func (r *Manager) createEdge(channel *channeldb.OpenChannel,
+func (r *Manager) createEdge(channel *chanstate.OpenChannel,
timestamp time.Time) (*models.ChannelEdgeInfo,
*models.ChannelEdgePolicy, error) {
@@ -475,7 +476,7 @@ func (r *Manager) updateEdge(chanPoint wire.OutPoint,
// getHtlcAmtLimits retrieves the negotiated channel min and max htlc amount
// constraints.
-func (r *Manager) getHtlcAmtLimits(ch *channeldb.OpenChannel) (
+func (r *Manager) getHtlcAmtLimits(ch *chanstate.OpenChannel) (
lnwire.MilliSatoshi, lnwire.MilliSatoshi, error) {
// The max htlc policy field must be less than or equal to the channel
diff --git a/routing/localchans/manager_test.go b/routing/localchans/manager_test.go
index a23499f..4f0bc78 100644
--- a/routing/localchans/manager_test.go
+++ b/routing/localchans/manager_test.go
@@ -12,6 +12,7 @@ import (
"github.com/btcsuite/btcd/chainhash/v2"
"github.com/btcsuite/btcd/wire/v2"
"github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/graph/db/models"
@@ -138,28 +139,29 @@ func TestManager(t *testing.T) {
return nil
}
- fetchChannel := func(chanPoint wire.OutPoint) (*channeldb.OpenChannel,
+ fetchChannel := func(chanPoint wire.OutPoint) (*chanstate.OpenChannel,
error) {
if chanPoint == chanPointMissing {
- return &channeldb.OpenChannel{}, channeldb.ErrChannelNotFound
+ return &chanstate.OpenChannel{},
+ channeldb.ErrChannelNotFound
}
- bounds := channeldb.ChannelStateBounds{
+ bounds := chanstate.ChannelStateBounds{
MaxPendingAmount: maxPendingAmount,
MinHTLC: minHTLC,
}
- return &channeldb.OpenChannel{
+ return &chanstate.OpenChannel{
FundingOutpoint: chanPointValid,
IdentityPub: remotepub,
- LocalChanCfg: channeldb.ChannelConfig{
+ LocalChanCfg: chanstate.ChannelConfig{
ChannelStateBounds: bounds,
MultiSigKey: keychain.KeyDescriptor{
PubKey: localMultisigKey,
},
},
- RemoteChanCfg: channeldb.ChannelConfig{
+ RemoteChanCfg: chanstate.ChannelConfig{
ChannelStateBounds: bounds,
MultiSigKey: keychain.KeyDescriptor{
PubKey: remoteMultisigKey,
@@ -413,14 +415,14 @@ func TestCreateEdgeLower(t *testing.T) {
TimeLockDelta: 7,
}
- channel := &channeldb.OpenChannel{
+ channel := &chanstate.OpenChannel{
IdentityPub: remotepub,
- LocalChanCfg: channeldb.ChannelConfig{
+ LocalChanCfg: chanstate.ChannelConfig{
MultiSigKey: keychain.KeyDescriptor{
PubKey: localMultisigKey,
},
},
- RemoteChanCfg: channeldb.ChannelConfig{
+ RemoteChanCfg: chanstate.ChannelConfig{
MultiSigKey: keychain.KeyDescriptor{
PubKey: remoteMultisigKey,
},
@@ -504,14 +506,14 @@ func TestCreateEdgeHigher(t *testing.T) {
TimeLockDelta: 7,
}
- channel := &channeldb.OpenChannel{
+ channel := &chanstate.OpenChannel{
IdentityPub: remotepub,
- LocalChanCfg: channeldb.ChannelConfig{
+ LocalChanCfg: chanstate.ChannelConfig{
MultiSigKey: keychain.KeyDescriptor{
PubKey: localMultisigKey,
},
},
- RemoteChanCfg: channeldb.ChannelConfig{
+ RemoteChanCfg: chanstate.ChannelConfig{
MultiSigKey: keychain.KeyDescriptor{
PubKey: remoteMultisigKey,
},
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.