graph/db: thread context through DeleteChannelEdges
This commit is contained in:
8 files changed
+34
-28
No files matched your search
+1
-1
@@ -630,7 +630,7 @@ func (b *Builder) pruneZombieChans() error {
|
|||||||
log.Tracef("Pruning zombie channel with ChannelID(%v)", chanID)
|
log.Tracef("Pruning zombie channel with ChannelID(%v)", chanID)
|
||||||
}
|
}
|
||||||
err := b.v1Graph.DeleteChannelEdges(
|
err := b.v1Graph.DeleteChannelEdges(
|
||||||
b.cfg.StrictZombiePruning, true, toPrune...,
|
context.TODO(), b.cfg.StrictZombiePruning, true, toPrune...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to delete zombie channels: %w", err)
|
return fmt.Errorf("unable to delete zombie channels: %w", err)
|
||||||
|
|||||||
+6
-6
@@ -389,11 +389,11 @@ func (c *ChannelGraph) MarkEdgeLive(ctx context.Context, chanID uint64) error {
|
|||||||
// that we require the node that failed to send the fresh update to be the one
|
// that we require the node that failed to send the fresh update to be the one
|
||||||
// that resurrects the channel from its zombie state. The markZombie bool
|
// that resurrects the channel from its zombie state. The markZombie bool
|
||||||
// denotes whether to mark the channel as a zombie.
|
// denotes whether to mark the channel as a zombie.
|
||||||
func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool,
|
func (c *ChannelGraph) DeleteChannelEdges(ctx context.Context,
|
||||||
chanIDs ...uint64) error {
|
strictZombiePruning, markZombie bool, chanIDs ...uint64) error {
|
||||||
|
|
||||||
infos, err := c.db.DeleteChannelEdges(
|
infos, err := c.db.DeleteChannelEdges(
|
||||||
lnwire.GossipVersion1, strictZombiePruning, markZombie,
|
ctx, lnwire.GossipVersion1, strictZombiePruning, markZombie,
|
||||||
chanIDs...,
|
chanIDs...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -889,11 +889,11 @@ func (c *VersionedGraph) SourceNode(ctx context.Context) (*models.Node,
|
|||||||
// that we require the node that failed to send the fresh update to be the one
|
// that we require the node that failed to send the fresh update to be the one
|
||||||
// that resurrects the channel from its zombie state. The markZombie bool
|
// that resurrects the channel from its zombie state. The markZombie bool
|
||||||
// denotes whether to mark the channel as a zombie.
|
// denotes whether to mark the channel as a zombie.
|
||||||
func (c *VersionedGraph) DeleteChannelEdges(strictZombiePruning,
|
func (c *VersionedGraph) DeleteChannelEdges(ctx context.Context,
|
||||||
markZombie bool, chanIDs ...uint64) error {
|
strictZombiePruning, markZombie bool, chanIDs ...uint64) error {
|
||||||
|
|
||||||
infos, err := c.db.DeleteChannelEdges(
|
infos, err := c.db.DeleteChannelEdges(
|
||||||
c.v, strictZombiePruning, markZombie, chanIDs...,
|
ctx, c.v, strictZombiePruning, markZombie, chanIDs...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
+16
-9
@@ -699,7 +699,9 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) {
|
|||||||
|
|
||||||
// Next, attempt to delete the edge from the database, again this
|
// Next, attempt to delete the edge from the database, again this
|
||||||
// should proceed without any issues.
|
// should proceed without any issues.
|
||||||
require.NoError(t, graph.DeleteChannelEdges(false, true, chanID))
|
require.NoError(t, graph.DeleteChannelEdges(
|
||||||
|
ctx, false, true, chanID,
|
||||||
|
))
|
||||||
assertNoEdge(t, graph.ChannelGraph, chanID)
|
assertNoEdge(t, graph.ChannelGraph, chanID)
|
||||||
|
|
||||||
// Ensure that any query attempts to lookup the delete channel edge are
|
// Ensure that any query attempts to lookup the delete channel edge are
|
||||||
@@ -720,7 +722,7 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) {
|
|||||||
|
|
||||||
// Finally, attempt to delete a (now) non-existent edge within the
|
// Finally, attempt to delete a (now) non-existent edge within the
|
||||||
// database, this should result in an error.
|
// database, this should result in an error.
|
||||||
err = graph.DeleteChannelEdges(false, true, chanID)
|
err = graph.DeleteChannelEdges(ctx, false, true, chanID)
|
||||||
require.ErrorIs(t, err, ErrEdgeNotFound)
|
require.ErrorIs(t, err, ErrEdgeNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3064,7 +3066,9 @@ func TestFilterKnownChanIDs(t *testing.T) {
|
|||||||
node1, node2,
|
node1, node2,
|
||||||
)
|
)
|
||||||
require.NoError(t, graph.AddChannelEdge(ctx, channel))
|
require.NoError(t, graph.AddChannelEdge(ctx, channel))
|
||||||
err := graph.DeleteChannelEdges(false, true, channel.ChannelID)
|
err := graph.DeleteChannelEdges(
|
||||||
|
ctx, false, true, channel.ChannelID,
|
||||||
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
zombieIDs = append(
|
zombieIDs = append(
|
||||||
@@ -3403,7 +3407,8 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := graph.DeleteChannelEdges(
|
err := graph.DeleteChannelEdges(
|
||||||
strictPruning, markZombie, chanIDs...,
|
ctx, strictPruning, markZombie,
|
||||||
|
chanIDs...,
|
||||||
)
|
)
|
||||||
if err != nil &&
|
if err != nil &&
|
||||||
!errors.Is(err, ErrEdgeNotFound) {
|
!errors.Is(err, ErrEdgeNotFound) {
|
||||||
@@ -3761,7 +3766,9 @@ func testFetchChanInfos(t *testing.T, v lnwire.GossipVersion) {
|
|||||||
v, 666, 0, 0, 0, node1, node2,
|
v, 666, 0, 0, 0, node1, node2,
|
||||||
)
|
)
|
||||||
require.NoError(t, graph.AddChannelEdge(ctx, zombieChan))
|
require.NoError(t, graph.AddChannelEdge(ctx, zombieChan))
|
||||||
err := graph.DeleteChannelEdges(false, true, zombieChan.ChannelID)
|
err := graph.DeleteChannelEdges(
|
||||||
|
ctx, false, true, zombieChan.ChannelID,
|
||||||
|
)
|
||||||
require.NoError(t, err, "unable to delete and mark edge zombie")
|
require.NoError(t, err, "unable to delete and mark edge zombie")
|
||||||
edgeQuery = append(edgeQuery, zombieChanID.ToUint64())
|
edgeQuery = append(edgeQuery, zombieChanID.ToUint64())
|
||||||
|
|
||||||
@@ -4226,7 +4233,7 @@ func testNodeIsPublic(t *testing.T, v lnwire.GossipVersion) {
|
|||||||
// has any advertised edges.
|
// has any advertised edges.
|
||||||
for _, graph := range graphs {
|
for _, graph := range graphs {
|
||||||
err := graph.DeleteChannelEdges(
|
err := graph.DeleteChannelEdges(
|
||||||
false, true, aliceBobEdge.ChannelID,
|
ctx, false, true, aliceBobEdge.ChannelID,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to remove edge")
|
require.NoError(t, err, "unable to remove edge")
|
||||||
}
|
}
|
||||||
@@ -4243,7 +4250,7 @@ func testNodeIsPublic(t *testing.T, v lnwire.GossipVersion) {
|
|||||||
// it without it being advertised.
|
// it without it being advertised.
|
||||||
for _, graph := range graphs {
|
for _, graph := range graphs {
|
||||||
err := graph.DeleteChannelEdges(
|
err := graph.DeleteChannelEdges(
|
||||||
false, true, bobCarolEdge.ChannelID,
|
ctx, false, true, bobCarolEdge.ChannelID,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to remove edge")
|
require.NoError(t, err, "unable to remove edge")
|
||||||
|
|
||||||
@@ -4404,7 +4411,7 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) {
|
|||||||
// Delete the channel edge and ensure it is removed from the disabled
|
// Delete the channel edge and ensure it is removed from the disabled
|
||||||
// list.
|
// list.
|
||||||
require.NoError(t, graph.DeleteChannelEdges(
|
require.NoError(t, graph.DeleteChannelEdges(
|
||||||
false, true, edgeInfo.ChannelID,
|
ctx, false, true, edgeInfo.ChannelID,
|
||||||
))
|
))
|
||||||
disabledChanIds, err = graph.DisabledChannelIDs(ctx)
|
disabledChanIds, err = graph.DisabledChannelIDs(ctx)
|
||||||
require.NoError(t, err, "unable to get disabled channel ids")
|
require.NoError(t, err, "unable to get disabled channel ids")
|
||||||
@@ -4571,7 +4578,7 @@ func TestGraphZombieIndex(t *testing.T) {
|
|||||||
|
|
||||||
// If we delete the edge and mark it as a zombie, then we should expect
|
// If we delete the edge and mark it as a zombie, then we should expect
|
||||||
// to see it within the index.
|
// to see it within the index.
|
||||||
err = graph.DeleteChannelEdges(false, true, edge.ChannelID)
|
err = graph.DeleteChannelEdges(ctx, false, true, edge.ChannelID)
|
||||||
require.NoError(t, err, "unable to mark edge as zombie")
|
require.NoError(t, err, "unable to mark edge as zombie")
|
||||||
isZombie, pubKey1, pubKey2, err := graph.IsZombieEdge(
|
isZombie, pubKey1, pubKey2, err := graph.IsZombieEdge(
|
||||||
ctx, edge.ChannelID,
|
ctx, edge.ChannelID,
|
||||||
|
|||||||
@@ -230,8 +230,8 @@ type Store interface { //nolint:interfacebloat
|
|||||||
// failed to send the fresh update to be the one that resurrects the
|
// failed to send the fresh update to be the one that resurrects the
|
||||||
// channel from its zombie state. The markZombie bool denotes whether
|
// channel from its zombie state. The markZombie bool denotes whether
|
||||||
// to mark the channel as a zombie.
|
// to mark the channel as a zombie.
|
||||||
DeleteChannelEdges(v lnwire.GossipVersion, strictZombiePruning,
|
DeleteChannelEdges(ctx context.Context, v lnwire.GossipVersion,
|
||||||
markZombie bool, chanIDs ...uint64) (
|
strictZombiePruning, markZombie bool, chanIDs ...uint64) (
|
||||||
[]*models.ChannelEdgeInfo, error)
|
[]*models.ChannelEdgeInfo, error)
|
||||||
|
|
||||||
// AddEdgeProof sets the proof of an existing edge in the graph
|
// AddEdgeProof sets the proof of an existing edge in the graph
|
||||||
|
|||||||
@@ -1934,8 +1934,9 @@ func (c *KVStore) PruneTip() (*chainhash.Hash, uint32, error) {
|
|||||||
// that we require the node that failed to send the fresh update to be the one
|
// that we require the node that failed to send the fresh update to be the one
|
||||||
// that resurrects the channel from its zombie state. The markZombie bool
|
// that resurrects the channel from its zombie state. The markZombie bool
|
||||||
// denotes whether or not to mark the channel as a zombie.
|
// denotes whether or not to mark the channel as a zombie.
|
||||||
func (c *KVStore) DeleteChannelEdges(v lnwire.GossipVersion,
|
func (c *KVStore) DeleteChannelEdges(_ context.Context,
|
||||||
strictZombiePruning, markZombie bool, chanIDs ...uint64) (
|
v lnwire.GossipVersion, strictZombiePruning, markZombie bool,
|
||||||
|
chanIDs ...uint64) (
|
||||||
[]*models.ChannelEdgeInfo, error) {
|
[]*models.ChannelEdgeInfo, error) {
|
||||||
|
|
||||||
if v != lnwire.GossipVersion1 {
|
if v != lnwire.GossipVersion1 {
|
||||||
|
|||||||
@@ -1946,8 +1946,9 @@ func (s *SQLStore) NumZombies(ctx context.Context) (uint64, error) {
|
|||||||
// denotes whether to mark the channel as a zombie.
|
// denotes whether to mark the channel as a zombie.
|
||||||
//
|
//
|
||||||
// NOTE: part of the Store interface.
|
// NOTE: part of the Store interface.
|
||||||
func (s *SQLStore) DeleteChannelEdges(v lnwire.GossipVersion,
|
func (s *SQLStore) DeleteChannelEdges(ctx context.Context,
|
||||||
strictZombiePruning, markZombie bool, chanIDs ...uint64) (
|
v lnwire.GossipVersion, strictZombiePruning, markZombie bool,
|
||||||
|
chanIDs ...uint64) (
|
||||||
[]*models.ChannelEdgeInfo, error) {
|
[]*models.ChannelEdgeInfo, error) {
|
||||||
|
|
||||||
s.cacheMu.Lock()
|
s.cacheMu.Lock()
|
||||||
@@ -1960,10 +1961,7 @@ func (s *SQLStore) DeleteChannelEdges(v lnwire.GossipVersion,
|
|||||||
chanLookup[chanID] = struct{}{}
|
chanLookup[chanID] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var edges []*models.ChannelEdgeInfo
|
||||||
ctx = context.TODO()
|
|
||||||
edges []*models.ChannelEdgeInfo
|
|
||||||
)
|
|
||||||
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
|
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
|
||||||
// First, collect all channel rows.
|
// First, collect all channel rows.
|
||||||
var channelRows []sqlc.GetChannelsBySCIDWithPoliciesRow
|
var channelRows []sqlc.GetChannelsBySCIDWithPoliciesRow
|
||||||
|
|||||||
+1
-1
@@ -3212,7 +3212,7 @@ func abandonChanFromGraph(chanGraph *graphdb.VersionedGraph,
|
|||||||
|
|
||||||
// If the channel ID is still in the graph, then that means the channel
|
// If the channel ID is still in the graph, then that means the channel
|
||||||
// is still open, so we'll now move to purge it from the graph.
|
// is still open, so we'll now move to purge it from the graph.
|
||||||
return chanGraph.DeleteChannelEdges(false, true, chanID)
|
return chanGraph.DeleteChannelEdges(context.TODO(), false, true, chanID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// abandonChan removes a channel from the database, graph and contract court.
|
// abandonChan removes a channel from the database, graph and contract court.
|
||||||
|
|||||||
@@ -1426,7 +1426,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = s.v1Graph.DeleteChannelEdges(
|
err = s.v1Graph.DeleteChannelEdges(
|
||||||
false, false, scid.ToUint64(),
|
context.TODO(), false, false, scid.ToUint64(),
|
||||||
)
|
)
|
||||||
return ourPolicy, err
|
return ourPolicy, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user