What changed, and why it matters
This is a routine internal code cleanup in LND's channel backup system. It replaces references to the older `channeldb` package with a newer `chanstate` package for channel type definitions. The actual backup data, encryption, and recovery logic are unchanged. There is no indication this fixes a security bug or introduces a vulnerability.
No security action required. Treat as normal refactoring. Reviewers may optionally verify that `chanstate` types are binary/field-compatible with the prior `channeldb` aliases to avoid backup format regressions, though the diff shows no serialization changes.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors chanbackup to use chanstate.OpenChannel, chanstate.ChannelConfig, chanstate.ChannelCommitment, and chanstate.ChannelType instead of the channeldb compatibility aliases. The LiveChannelSource interface, assembleChanBackup, buildCloseTxInputs, ChannelWithAddrs, Single, and NewSingle all switch types. The commit message explicitly frames this as moving static channel backup construction to chanstate channel types and notes that channeldb is still imported for real database concerns. No functional behavior changes are visible in the diff.
Changed components
chanbackup/backup.gochanbackup/backup_test.gochanbackup/pubsub.gochanbackup/single.gochanbackup/single_test.goInspect captured patch +30 / −27
diff --git a/chanbackup/backup.go b/chanbackup/backup.go
index 88b8a0c..6af6f38 100644
--- a/chanbackup/backup.go
+++ b/chanbackup/backup.go
@@ -6,6 +6,7 @@ import (
"github.com/btcsuite/btcd/wire/v2"
"github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/fn/v2"
)
@@ -14,11 +15,11 @@ import (
// commitment transaction broadcast.
type LiveChannelSource interface {
// FetchAllChannels returns all known live channels.
- FetchAllChannels() ([]*channeldb.OpenChannel, error)
+ FetchAllChannels() ([]*chanstate.OpenChannel, error)
// FetchChannel attempts to locate a live channel identified by the
// passed chanPoint. Optionally an existing db tx can be supplied.
- FetchChannel(chanPoint wire.OutPoint) (*channeldb.OpenChannel, error)
+ FetchChannel(chanPoint wire.OutPoint) (*chanstate.OpenChannel, error)
}
// assembleChanBackup attempts to assemble a static channel backup for the
@@ -26,7 +27,7 @@ type LiveChannelSource interface {
// the channel, as well as addressing information so we can find the peer and
// reconnect to them to initiate the protocol.
func assembleChanBackup(ctx context.Context, addrSource channeldb.AddrSource,
- openChan *channeldb.OpenChannel) (*Single, error) {
+ openChan *chanstate.OpenChannel) (*Single, error) {
log.Debugf("Crafting backup for ChannelPoint(%v)",
openChan.FundingOutpoint)
@@ -55,7 +56,7 @@ func assembleChanBackup(ctx context.Context, addrSource channeldb.AddrSource,
// in loss of funds! This may happen if an outdated channel backup is attempted
// to be used to force close the channel.
func buildCloseTxInputs(
- targetChan *channeldb.OpenChannel) fn.Option[CloseTxInputs] {
+ targetChan *chanstate.OpenChannel) fn.Option[CloseTxInputs] {
log.Debugf("Crafting CloseTxInputs for ChannelPoint(%v)",
targetChan.FundingOutpoint)
diff --git a/chanbackup/backup_test.go b/chanbackup/backup_test.go
index f2a10c2..264649b 100644
--- a/chanbackup/backup_test.go
+++ b/chanbackup/backup_test.go
@@ -8,12 +8,12 @@ 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/stretchr/testify/require"
)
type mockChannelSource struct {
- chans map[wire.OutPoint]*channeldb.OpenChannel
+ chans map[wire.OutPoint]*chanstate.OpenChannel
failQuery bool
@@ -22,17 +22,19 @@ type mockChannelSource struct {
func newMockChannelSource() *mockChannelSource {
return &mockChannelSource{
- chans: make(map[wire.OutPoint]*channeldb.OpenChannel),
+ chans: make(map[wire.OutPoint]*chanstate.OpenChannel),
addrs: make(map[[33]byte][]net.Addr),
}
}
-func (m *mockChannelSource) FetchAllChannels() ([]*channeldb.OpenChannel, error) {
+func (m *mockChannelSource) FetchAllChannels() (
+ []*chanstate.OpenChannel, error) {
+
if m.failQuery {
return nil, fmt.Errorf("fail")
}
- chans := make([]*channeldb.OpenChannel, 0, len(m.chans))
+ chans := make([]*chanstate.OpenChannel, 0, len(m.chans))
for _, channel := range m.chans {
chans = append(chans, channel)
}
@@ -41,7 +43,7 @@ func (m *mockChannelSource) FetchAllChannels() ([]*channeldb.OpenChannel, error)
}
func (m *mockChannelSource) FetchChannel(chanPoint wire.OutPoint) (
- *channeldb.OpenChannel, error) {
+ *chanstate.OpenChannel, error) {
if m.failQuery {
return nil, fmt.Errorf("fail")
diff --git a/chanbackup/pubsub.go b/chanbackup/pubsub.go
index 1915127..4b5493f 100644
--- a/chanbackup/pubsub.go
+++ b/chanbackup/pubsub.go
@@ -10,7 +10,7 @@ import (
"sync/atomic"
"github.com/btcsuite/btcd/wire/v2"
- "github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnutils"
)
@@ -31,7 +31,7 @@ type Swapper interface {
// ChannelWithAddrs bundles an open channel along with all the addresses for
// the channel peer.
type ChannelWithAddrs struct {
- *channeldb.OpenChannel
+ *chanstate.OpenChannel
// Addrs is the set of addresses that we can use to reach the target
// peer.
diff --git a/chanbackup/single.go b/chanbackup/single.go
index 4acd649..5cf6547 100644
--- a/chanbackup/single.go
+++ b/chanbackup/single.go
@@ -11,7 +11,7 @@ import (
"github.com/btcsuite/btcd/btcutil/v2"
"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/fn/v2"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnencrypt"
@@ -169,7 +169,7 @@ type Single struct {
//
// NOTE: Of the items in the ChannelConstraints, we only write the CSV
// delay.
- LocalChanCfg channeldb.ChannelConfig
+ LocalChanCfg chanstate.ChannelConfig
// RemoteChanCfg is the remote channel confirmation. We store this as
// well since we'll need some of their keys to re-derive things like
@@ -178,7 +178,7 @@ type Single struct {
//
// NOTE: Of the items in the ChannelConstraints, we only write the CSV
// delay.
- RemoteChanCfg channeldb.ChannelConfig
+ RemoteChanCfg chanstate.ChannelConfig
// ShaChainRootDesc describes how to derive the private key that was
// used as the shachain root for this channel.
@@ -234,7 +234,7 @@ type CloseTxInputs struct {
// connect to the channel peer. If possible, we include the data needed to
// produce a force close transaction from the most recent state using externally
// provided private key.
-func NewSingle(channel *channeldb.OpenChannel,
+func NewSingle(channel *chanstate.OpenChannel,
nodeAddrs []net.Addr) Single {
var shaChainRootDesc keychain.KeyDescriptor
diff --git a/chanbackup/single_test.go b/chanbackup/single_test.go
index 881aedf..3468fb0 100644
--- a/chanbackup/single_test.go
+++ b/chanbackup/single_test.go
@@ -12,7 +12,7 @@ import (
"github.com/btcsuite/btcd/chainhash/v2"
"github.com/btcsuite/btcd/wire/v2"
"github.com/davecgh/go-spew/spew"
- "github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnencrypt"
@@ -135,7 +135,7 @@ func assertSingleEqual(t *testing.T, a, b Single) {
}
}
-func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
+func genRandomOpenChannelShell() (*chanstate.OpenChannel, error) {
var testPriv [32]byte
if _, err := rand.Read(testPriv[:]); err != nil {
return nil, err
@@ -162,11 +162,11 @@ func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
isInitiator = true
}
- chanType := channeldb.ChannelType(rand.Intn(1 << 12))
+ chanType := chanstate.ChannelType(rand.Intn(1 << 12))
- localCfg := channeldb.ChannelConfig{
- ChannelStateBounds: channeldb.ChannelStateBounds{},
- CommitmentParams: channeldb.CommitmentParams{
+ localCfg := chanstate.ChannelConfig{
+ ChannelStateBounds: chanstate.ChannelStateBounds{},
+ CommitmentParams: chanstate.CommitmentParams{
CsvDelay: uint16(rand.Int63()),
},
MultiSigKey: keychain.KeyDescriptor{
@@ -201,8 +201,8 @@ func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
},
}
- remoteCfg := channeldb.ChannelConfig{
- CommitmentParams: channeldb.CommitmentParams{
+ remoteCfg := chanstate.ChannelConfig{
+ CommitmentParams: chanstate.CommitmentParams{
CsvDelay: uint16(rand.Int63()),
},
MultiSigKey: keychain.KeyDescriptor{
@@ -222,14 +222,14 @@ func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
},
}
- var localCommit channeldb.ChannelCommitment
+ var localCommit chanstate.ChannelCommitment
if chanType.IsTaproot() {
var commitSig [64]byte
if _, err := rand.Read(commitSig[:]); err != nil {
return nil, err
}
- localCommit = channeldb.ChannelCommitment{
+ localCommit = chanstate.ChannelCommitment{
CommitTx: sampleCommitTx,
CommitSig: commitSig[:],
CommitHeight: rand.Uint64(),
@@ -245,7 +245,7 @@ func genRandomOpenChannelShell() (*channeldb.OpenChannel, error) {
tapscriptRootOption = fn.Some(tapscriptRoot)
}
- return &channeldb.OpenChannel{
+ return &chanstate.OpenChannel{
ChainHash: chainHash,
ChanType: chanType,
IsInitiator: isInitiator,
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.