What changed, and why it matters
This is a routine internal code cleanup in LND's watchtower subsystem. It changes which Go package the watchtower code uses to reference channel types and channel close summaries, moving from the older 'channeldb' package to a newer 'chanstate' package. There is no functional change visible in the diff, no bug fix, and no security patch.
No security action required. Treat as a normal refactoring commit during code review or dependency audit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors watchtower blob type derivation and client interfaces to import channel types from the new ‘chanstate’ package instead of ‘channeldb’. Function signatures such as blob.TypeFromChannel, blob.Type.CommitmentType, BreachRetributionBuilder, ClientManager.RegisterChannel, and Config.FetchClosedChannel are updated to use chanstate.ChannelType and chanstate.ChannelCloseSummary. The manager still imports channeldb solely for the closed-channel lookup error (channeldb.ErrClosedChannelNotFound). Test fixtures are updated to match the new types. No logic changes, bounds checks, cryptographic operations, or network behavior are modified.
Changed components
watchtower/blob/type.gowatchtower/wtclient/client.gowatchtower/wtclient/manager.gowatchtower/wtclient/backup_task_internal_test.gowatchtower/wtclient/client_test.goInspect captured patch +25 / −23
diff --git a/watchtower/blob/type.go b/watchtower/blob/type.go
index 00415af..df04769 100644
--- a/watchtower/blob/type.go
+++ b/watchtower/blob/type.go
@@ -4,7 +4,7 @@ import (
"fmt"
"strings"
- "github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
)
// Flag represents a specify option that can be present in a Type.
@@ -97,7 +97,7 @@ const (
// TypeFromChannel returns the appropriate blob Type for the given channel
// type.
-func TypeFromChannel(chanType channeldb.ChannelType) Type {
+func TypeFromChannel(chanType chanstate.ChannelType) Type {
switch {
case chanType.IsTaprootFinal():
return TypeAltruistTaprootFinalCommit
@@ -130,7 +130,7 @@ func (t Type) Identifier() (string, error) {
// CommitmentType returns the appropriate CommitmentType for the given blob Type
// and channel type.
-func (t Type) CommitmentType(chanType *channeldb.ChannelType) (CommitmentType,
+func (t Type) CommitmentType(chanType *chanstate.ChannelType) (CommitmentType,
error) {
switch {
diff --git a/watchtower/wtclient/backup_task_internal_test.go b/watchtower/wtclient/backup_task_internal_test.go
index 1fa1605..5f725a8 100644
--- a/watchtower/wtclient/backup_task_internal_test.go
+++ b/watchtower/wtclient/backup_task_internal_test.go
@@ -10,7 +10,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/v2"
"github.com/btcsuite/btcd/txscript/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/input"
"github.com/lightningnetwork/lnd/keychain"
@@ -65,7 +65,7 @@ type backupTaskTest struct {
bindErr error
expSweepScript []byte
signer input.Signer
- chanType channeldb.ChannelType
+ chanType chanstate.ChannelType
commitType blob.CommitmentType
}
@@ -85,7 +85,7 @@ func genTaskTest(
expSweepAmt int64,
expRewardAmt int64,
bindErr error,
- chanType channeldb.ChannelType) backupTaskTest {
+ chanType chanstate.ChannelType) backupTaskTest {
// Set the anchor or taproot flag in the blob type if the session needs
// to support anchor or taproot channels.
@@ -331,11 +331,11 @@ var (
func TestBackupTask(t *testing.T) {
t.Parallel()
- chanTypes := []channeldb.ChannelType{
- channeldb.SingleFunderBit,
- channeldb.SingleFunderTweaklessBit,
- channeldb.AnchorOutputsBit,
- channeldb.SimpleTaprootFeatureBit,
+ chanTypes := []chanstate.ChannelType{
+ chanstate.SingleFunderBit,
+ chanstate.SingleFunderTweaklessBit,
+ chanstate.AnchorOutputsBit,
+ chanstate.SimpleTaprootFeatureBit,
}
var backupTaskTests []backupTaskTest
@@ -573,7 +573,7 @@ func testBackupTask(t *testing.T, test backupTaskTest) {
// getBreachInfo is a helper closure that returns the breach retribution
// info and channel type for the given channel and commit height.
getBreachInfo := func(id lnwire.ChannelID, commitHeight uint64) (
- *lnwallet.BreachRetribution, channeldb.ChannelType, error) {
+ *lnwallet.BreachRetribution, chanstate.ChannelType, error) {
return test.breachInfo, test.chanType, nil
}
diff --git a/watchtower/wtclient/client.go b/watchtower/wtclient/client.go
index f8f3d3e..41edb59 100644
--- a/watchtower/wtclient/client.go
+++ b/watchtower/wtclient/client.go
@@ -13,7 +13,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btclog/v2"
- "github.com/lightningnetwork/lnd/channeldb"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
@@ -94,7 +94,7 @@ type RegisteredTower struct {
// BreachRetribution from a channel ID and a commitment height.
type BreachRetributionBuilder func(id lnwire.ChannelID,
commitHeight uint64) (*lnwallet.BreachRetribution,
- channeldb.ChannelType, error)
+ chanstate.ChannelType, error)
// newTowerMsg is an internal message we'll use within the client to signal
// that a new tower can be considered.
diff --git a/watchtower/wtclient/client_test.go b/watchtower/wtclient/client_test.go
index b44d3e2..99c0e0a 100644
--- a/watchtower/wtclient/client_test.go
+++ b/watchtower/wtclient/client_test.go
@@ -19,6 +19,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channelnotifier"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
@@ -512,7 +513,7 @@ func newHarness(t *testing.T, cfg harnessCfg) *testHarness {
})
fetchChannel := func(id lnwire.ChannelID) (
- *channeldb.ChannelCloseSummary, error) {
+ *chanstate.ChannelCloseSummary, error) {
h.mu.Lock()
defer h.mu.Unlock()
@@ -522,7 +523,7 @@ func newHarness(t *testing.T, cfg harnessCfg) *testHarness {
return nil, channeldb.ErrClosedChannelNotFound
}
- return &channeldb.ChannelCloseSummary{CloseHeight: height}, nil
+ return &chanstate.ChannelCloseSummary{CloseHeight: height}, nil
}
h.clientPolicy = cfg.policy
@@ -550,11 +551,11 @@ func newHarness(t *testing.T, cfg harnessCfg) *testHarness {
h.clientCfg.BuildBreachRetribution = func(id lnwire.ChannelID,
commitHeight uint64) (*lnwallet.BreachRetribution,
- channeldb.ChannelType, error) {
+ chanstate.ChannelType, error) {
_, retribution := h.channelFromID(id).getState(commitHeight)
- return retribution, channeldb.SimpleTaprootFeatureBit, nil
+ return retribution, chanstate.SimpleTaprootFeatureBit, nil
}
if !cfg.noServerStart {
@@ -687,7 +688,7 @@ func (h *testHarness) closeChannel(id uint64, height uint32) {
}
h.channelEvents.sendUpdate(channelnotifier.ClosedChannelEvent{
- CloseSummary: &channeldb.ChannelCloseSummary{
+ CloseSummary: &chanstate.ChannelCloseSummary{
ChanPoint: wire.OutPoint{
Hash: *chanPointHash,
Index: 0,
@@ -703,7 +704,7 @@ func (h *testHarness) registerChannel(id uint64) {
chanID := chanIDFromInt(id)
err := h.clientMgr.RegisterChannel(
- chanID, channeldb.SimpleTaprootFeatureBit,
+ chanID, chanstate.SimpleTaprootFeatureBit,
)
require.NoError(h.t, err)
}
diff --git a/watchtower/wtclient/manager.go b/watchtower/wtclient/manager.go
index 03a344a..6d9ae18 100644
--- a/watchtower/wtclient/manager.go
+++ b/watchtower/wtclient/manager.go
@@ -12,6 +12,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channelnotifier"
+ "github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwire"
@@ -67,7 +68,7 @@ type ClientManager 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
@@ -93,7 +94,7 @@ type Config struct {
// channel. If the channel is not found or not yet closed then
// channeldb.ErrClosedChannelNotFound will be returned.
FetchClosedChannel func(cid lnwire.ChannelID) (
- *channeldb.ChannelCloseSummary, error)
+ *chanstate.ChannelCloseSummary, error)
// ChainNotifier can be used to subscribe to block notifications.
ChainNotifier chainntnfs.ChainNotifier
@@ -597,7 +598,7 @@ func (m *Manager) Policy(blobType blob.Type) (wtpolicy.Policy, error) {
// within the client. This should be called during link startup to ensure that
// the client is able to support the link during operation.
func (m *Manager) RegisterChannel(id lnwire.ChannelID,
- chanType channeldb.ChannelType) error {
+ chanType chanstate.ChannelType) error {
blobType := blob.TypeFromChannel(chanType)
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.