From bb8eeb2304cbab671c4c8e779b91c5eb4d776354 Mon Sep 17 00:00:00 2001 From: ziggie Date: Tue, 28 Apr 2026 15:08:41 -0300 Subject: [PATCH] channeldb: drop unused kvdb.RTx parameter from FetchChannelByID All four call sites pass nil for tx today (server.go, two in channeldb/db_test.go, funding/manager_test.go). The internal channelScanner(nil, selector) call inside FetchChannelByID is preserved verbatim, so runtime behavior is unchanged. This is a prerequisite for the upcoming chanstate.ChannelStore interface: keeping the parameter would leak kvdb into a domain interface. --- channeldb/db.go | 7 +++---- channeldb/db_test.go | 4 ++-- funding/manager_test.go | 2 +- server.go | 4 +--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/channeldb/db.go b/channeldb/db.go index 9cd627fd5..3f0036b11 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 e2e9a1970..277820b10 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 4924eec7a..c3d1cdbf2 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 83131c6f2..c2b7ea673 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 }