channeldb: drop unused kvdb.RTx parameter from FetchChannelByID
What changed, and why it matters
This is a small internal code cleanup: a function that fetches a channel by its ID had an optional database-transaction parameter that nobody was actually using (every caller passed nil). The patch removes that unused parameter and updates the four callers. The commit message explicitly says runtime behavior is unchanged, and the diff confirms the internal call still passes nil exactly as before. There is no security-relevant change here.
No security action needed. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
FetchChannelByID in channeldb/db.go drops the kvdb.RTx parameter. All call sites (server.go, channeldb/db_test.go twice, funding/manager_test.go) previously passed nil and are updated to the new signature. The body still calls c.channelScanner(nil, selector), preserving identical behavior. The motivation is to keep kvdb out of an upcoming chanstate.ChannelStore interface.
Changed components
channeldb/db.gochanneldb/db_test.gofunding/manager_test.goserver.goInspect captured patch +7 / −10
diff --git a/channeldb/db.go b/channeldb/db.go
index 9cd627f..3f0036b 100644
--- a/channeldb/db.go
+++ b/channeldb/db.go
@@ -729,9 +729,8 @@ func (c *ChannelStateDB) FetchChannel(chanPoint wire.OutPoint) (*OpenChannel,
// FetchChannelByID attempts to locate a channel specified by the passed channel
// ID. If the channel cannot be found, then an error will be returned.
-// Optionally an existing db tx can be supplied.
-func (c *ChannelStateDB) FetchChannelByID(tx kvdb.RTx, id lnwire.ChannelID) (
- *OpenChannel, error) {
+func (c *ChannelStateDB) FetchChannelByID(id lnwire.ChannelID) (*OpenChannel,
+ error) {
selector := func(chainBkt walletdb.ReadBucket) ([]byte, *wire.OutPoint,
error) {
@@ -774,7 +773,7 @@ func (c *ChannelStateDB) FetchChannelByID(tx kvdb.RTx, id lnwire.ChannelID) (
return targetChanPointBytes, targetChanPoint, nil
}
- return c.channelScanner(tx, selector)
+ return c.channelScanner(nil, selector)
}
// ChanCount is used by the server in determining access control.
diff --git a/channeldb/db_test.go b/channeldb/db_test.go
index e2e9a19..277820b 100644
--- a/channeldb/db_test.go
+++ b/channeldb/db_test.go
@@ -253,7 +253,7 @@ func TestFetchChannel(t *testing.T) {
// Next, attempt to fetch the channel by its channel ID.
chanID := lnwire.NewChanIDFromOutPoint(channelState.FundingOutpoint)
- dbChannel, err = cdb.FetchChannelByID(nil, chanID)
+ dbChannel, err = cdb.FetchChannelByID(chanID)
require.NoError(t, err, "unable to fetch channel")
// The decoded channel state should be identical to what we stored
@@ -272,7 +272,7 @@ func TestFetchChannel(t *testing.T) {
require.ErrorIs(t, err, ErrChannelNotFound)
chanID2 := lnwire.NewChanIDFromOutPoint(channelState2.FundingOutpoint)
- _, err = cdb.FetchChannelByID(nil, chanID2)
+ _, err = cdb.FetchChannelByID(chanID2)
require.ErrorIs(t, err, ErrChannelNotFound)
}
diff --git a/funding/manager_test.go b/funding/manager_test.go
index 4924eec..c3d1cdb 100644
--- a/funding/manager_test.go
+++ b/funding/manager_test.go
@@ -1118,7 +1118,7 @@ func assertConfirmationHeight(t *testing.T, node *testNode,
err := wait.NoError(func() error {
pendingChannel, err := node.fundingMgr.cfg.Wallet.Cfg.Database.
- FetchChannelByID(nil, chanID)
+ FetchChannelByID(chanID)
if err != nil {
return fmt.Errorf("unable to fetch pending channel: %w",
err)
diff --git a/server.go b/server.go
index 83131c6..c2b7ea6 100644
--- a/server.go
+++ b/server.go
@@ -1760,9 +1760,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
commitHeight uint64) (*lnwallet.BreachRetribution,
channeldb.ChannelType, error) {
- channel, err := s.chanStateDB.FetchChannelByID(
- nil, chanID,
- )
+ channel, err := s.chanStateDB.FetchChannelByID(chanID)
if err != nil {
return nil, 0, err
}
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.