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)
|
||||
}
|
||||
err := b.v1Graph.DeleteChannelEdges(
|
||||
b.cfg.StrictZombiePruning, true, toPrune...,
|
||||
context.TODO(), b.cfg.StrictZombiePruning, true, toPrune...,
|
||||
)
|
||||
if err != nil {
|
||||
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 resurrects the channel from its zombie state. The markZombie bool
|
||||
// denotes whether to mark the channel as a zombie.
|
||||
func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool,
|
||||
chanIDs ...uint64) error {
|
||||
func (c *ChannelGraph) DeleteChannelEdges(ctx context.Context,
|
||||
strictZombiePruning, markZombie bool, chanIDs ...uint64) error {
|
||||
|
||||
infos, err := c.db.DeleteChannelEdges(
|
||||
lnwire.GossipVersion1, strictZombiePruning, markZombie,
|
||||
ctx, lnwire.GossipVersion1, strictZombiePruning, markZombie,
|
||||
chanIDs...,
|
||||
)
|
||||
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 resurrects the channel from its zombie state. The markZombie bool
|
||||
// denotes whether to mark the channel as a zombie.
|
||||
func (c *VersionedGraph) DeleteChannelEdges(strictZombiePruning,
|
||||
markZombie bool, chanIDs ...uint64) error {
|
||||
func (c *VersionedGraph) DeleteChannelEdges(ctx context.Context,
|
||||
strictZombiePruning, markZombie bool, chanIDs ...uint64) error {
|
||||
|
||||
infos, err := c.db.DeleteChannelEdges(
|
||||
c.v, strictZombiePruning, markZombie, chanIDs...,
|
||||
ctx, c.v, strictZombiePruning, markZombie, chanIDs...,
|
||||
)
|
||||
if err != nil {
|
||||
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
|
||||
// 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)
|
||||
|
||||
// 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
|
||||
// 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)
|
||||
}
|
||||
|
||||
@@ -3064,7 +3066,9 @@ func TestFilterKnownChanIDs(t *testing.T) {
|
||||
node1, node2,
|
||||
)
|
||||
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)
|
||||
|
||||
zombieIDs = append(
|
||||
@@ -3403,7 +3407,8 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
err := graph.DeleteChannelEdges(
|
||||
strictPruning, markZombie, chanIDs...,
|
||||
ctx, strictPruning, markZombie,
|
||||
chanIDs...,
|
||||
)
|
||||
if err != nil &&
|
||||
!errors.Is(err, ErrEdgeNotFound) {
|
||||
@@ -3761,7 +3766,9 @@ func testFetchChanInfos(t *testing.T, v lnwire.GossipVersion) {
|
||||
v, 666, 0, 0, 0, node1, node2,
|
||||
)
|
||||
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")
|
||||
edgeQuery = append(edgeQuery, zombieChanID.ToUint64())
|
||||
|
||||
@@ -4226,7 +4233,7 @@ func testNodeIsPublic(t *testing.T, v lnwire.GossipVersion) {
|
||||
// has any advertised edges.
|
||||
for _, graph := range graphs {
|
||||
err := graph.DeleteChannelEdges(
|
||||
false, true, aliceBobEdge.ChannelID,
|
||||
ctx, false, true, aliceBobEdge.ChannelID,
|
||||
)
|
||||
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.
|
||||
for _, graph := range graphs {
|
||||
err := graph.DeleteChannelEdges(
|
||||
false, true, bobCarolEdge.ChannelID,
|
||||
ctx, false, true, bobCarolEdge.ChannelID,
|
||||
)
|
||||
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
|
||||
// list.
|
||||
require.NoError(t, graph.DeleteChannelEdges(
|
||||
false, true, edgeInfo.ChannelID,
|
||||
ctx, false, true, edgeInfo.ChannelID,
|
||||
))
|
||||
disabledChanIds, err = graph.DisabledChannelIDs(ctx)
|
||||
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
|
||||
// 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")
|
||||
isZombie, pubKey1, pubKey2, err := graph.IsZombieEdge(
|
||||
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
|
||||
// channel from its zombie state. The markZombie bool denotes whether
|
||||
// to mark the channel as a zombie.
|
||||
DeleteChannelEdges(v lnwire.GossipVersion, strictZombiePruning,
|
||||
markZombie bool, chanIDs ...uint64) (
|
||||
DeleteChannelEdges(ctx context.Context, v lnwire.GossipVersion,
|
||||
strictZombiePruning, markZombie bool, chanIDs ...uint64) (
|
||||
[]*models.ChannelEdgeInfo, error)
|
||||
|
||||
// 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 resurrects the channel from its zombie state. The markZombie bool
|
||||
// denotes whether or not to mark the channel as a zombie.
|
||||
func (c *KVStore) DeleteChannelEdges(v lnwire.GossipVersion,
|
||||
strictZombiePruning, markZombie bool, chanIDs ...uint64) (
|
||||
func (c *KVStore) DeleteChannelEdges(_ context.Context,
|
||||
v lnwire.GossipVersion, strictZombiePruning, markZombie bool,
|
||||
chanIDs ...uint64) (
|
||||
[]*models.ChannelEdgeInfo, error) {
|
||||
|
||||
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.
|
||||
//
|
||||
// NOTE: part of the Store interface.
|
||||
func (s *SQLStore) DeleteChannelEdges(v lnwire.GossipVersion,
|
||||
strictZombiePruning, markZombie bool, chanIDs ...uint64) (
|
||||
func (s *SQLStore) DeleteChannelEdges(ctx context.Context,
|
||||
v lnwire.GossipVersion, strictZombiePruning, markZombie bool,
|
||||
chanIDs ...uint64) (
|
||||
[]*models.ChannelEdgeInfo, error) {
|
||||
|
||||
s.cacheMu.Lock()
|
||||
@@ -1960,10 +1961,7 @@ func (s *SQLStore) DeleteChannelEdges(v lnwire.GossipVersion,
|
||||
chanLookup[chanID] = struct{}{}
|
||||
}
|
||||
|
||||
var (
|
||||
ctx = context.TODO()
|
||||
edges []*models.ChannelEdgeInfo
|
||||
)
|
||||
var edges []*models.ChannelEdgeInfo
|
||||
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
|
||||
// First, collect all channel rows.
|
||||
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
|
||||
// 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.
|
||||
|
||||
Reference in new issue
Block a user