mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-19 12:01:27 +02:00
multi: remove kvdb.Tx from ChannelGraphSource.ForAllOutgoingChannels
and the same for ChannelStateDB.FetchChannel. Most of the calls to these methods provide a `nil` Tx anyways. The only place that currently provides a non-nil tx is in the `localchans.Manager`. It takes the transaction provided to the `ForAllOutgoingChannels` callback and passes it to it's `updateEdge` method. Note, however, that the `ForAllOutgoingChannels` call is a call to the graph db and the call to `updateEdge` is a call to the `ChannelStateDB`. There is no reason that these two calls need to happen under the same transaction as they are reading from two completely disjoint databases. And so in the effort to completely split untangle the relationship between the two databases, we now dont use the same transaction for these two calls.
This commit is contained in:
@@ -657,9 +657,8 @@ func (c *ChannelStateDB) fetchNodeChannels(chainBucket kvdb.RBucket) (
|
||||
|
||||
// FetchChannel attempts to locate a channel specified by the passed channel
|
||||
// point. If the channel cannot be found, then an error will be returned.
|
||||
// Optionally an existing db tx can be supplied.
|
||||
func (c *ChannelStateDB) FetchChannel(tx kvdb.RTx, chanPoint wire.OutPoint) (
|
||||
*OpenChannel, error) {
|
||||
func (c *ChannelStateDB) FetchChannel(chanPoint wire.OutPoint) (*OpenChannel,
|
||||
error) {
|
||||
|
||||
var targetChanPoint bytes.Buffer
|
||||
err := graphdb.WriteOutpoint(&targetChanPoint, &chanPoint)
|
||||
@@ -674,7 +673,7 @@ func (c *ChannelStateDB) FetchChannel(tx kvdb.RTx, chanPoint wire.OutPoint) (
|
||||
return targetChanPointBytes, &chanPoint, nil
|
||||
}
|
||||
|
||||
return c.channelScanner(tx, selector)
|
||||
return c.channelScanner(nil, selector)
|
||||
}
|
||||
|
||||
// FetchChannelByID attempts to locate a channel specified by the passed channel
|
||||
@@ -1366,7 +1365,7 @@ func (c *ChannelStateDB) AbandonChannel(chanPoint *wire.OutPoint,
|
||||
// With the chanPoint constructed, we'll attempt to find the target
|
||||
// channel in the database. If we can't find the channel, then we'll
|
||||
// return the error back to the caller.
|
||||
dbChan, err := c.FetchChannel(nil, *chanPoint)
|
||||
dbChan, err := c.FetchChannel(*chanPoint)
|
||||
switch {
|
||||
// If the channel wasn't found, then it's possible that it was already
|
||||
// abandoned from the database.
|
||||
|
@@ -246,7 +246,7 @@ func TestFetchChannel(t *testing.T) {
|
||||
channelState := createTestChannel(t, cdb, openChannelOption())
|
||||
|
||||
// Next, attempt to fetch the channel by its chan point.
|
||||
dbChannel, err := cdb.FetchChannel(nil, channelState.FundingOutpoint)
|
||||
dbChannel, err := cdb.FetchChannel(channelState.FundingOutpoint)
|
||||
require.NoError(t, err, "unable to fetch channel")
|
||||
|
||||
// The decoded channel state should be identical to what we stored
|
||||
@@ -270,7 +270,7 @@ func TestFetchChannel(t *testing.T) {
|
||||
uniqueOutputIndex.Add(1)
|
||||
channelState2.FundingOutpoint.Index = uniqueOutputIndex.Load()
|
||||
|
||||
_, err = cdb.FetchChannel(nil, channelState2.FundingOutpoint)
|
||||
_, err = cdb.FetchChannel(channelState2.FundingOutpoint)
|
||||
require.ErrorIs(t, err, ErrChannelNotFound)
|
||||
|
||||
chanID2 := lnwire.NewChanIDFromOutPoint(channelState2.FundingOutpoint)
|
||||
@@ -410,7 +410,7 @@ func TestRestoreChannelShells(t *testing.T) {
|
||||
|
||||
// We should also be able to find the channel if we query for it
|
||||
// directly.
|
||||
_, err = cdb.FetchChannel(nil, channelShell.Chan.FundingOutpoint)
|
||||
_, err = cdb.FetchChannel(channelShell.Chan.FundingOutpoint)
|
||||
require.NoError(t, err, "unable to fetch channel")
|
||||
|
||||
// We should also be able to find the link node that was inserted by
|
||||
@@ -459,7 +459,7 @@ func TestAbandonChannel(t *testing.T) {
|
||||
|
||||
// At this point, the channel should no longer be found in the set of
|
||||
// open channels.
|
||||
_, err = cdb.FetchChannel(nil, chanState.FundingOutpoint)
|
||||
_, err = cdb.FetchChannel(chanState.FundingOutpoint)
|
||||
if err != ErrChannelNotFound {
|
||||
t.Fatalf("channel should not have been found: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user