channeldb/graph: remove MarkEdgeZombie

This commit removes the MarkEdgeZombie method from channeldb. This
method is currently not used in any live code paths in production, and
is only used in unit tests. However, incorrect usage of this method
could result in an edge being present in both the zombie and channel
indexes, which deviates from any state we would expect to see in
production. Removing the method will help mitigate the potential for
writing incorrect unit tests in the future, by forcing zombie edges to
be created via the relevant, production APIs, e.g. DeleteChannelEdge.

The existing unit tests that use this method have been modified to use
the DeleteChannelEdge instead. No regressions were discovered in the
process.
This commit is contained in:
Conner Fromknecht 2019-04-09 17:47:12 -07:00
parent 4a755435e6
commit f82b7c9bac
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 18 additions and 41 deletions

@ -3065,36 +3065,6 @@ func (c *ChannelGraph) NewChannelEdgePolicy() *ChannelEdgePolicy {
return &ChannelEdgePolicy{db: c.db}
}
// MarkEdgeZombie marks an edge as a zombie within the graph's zombie index.
// The public keys should represent the node public keys of the two parties
// involved in the edge.
func (c *ChannelGraph) MarkEdgeZombie(chanID uint64, pubKey1,
pubKey2 [33]byte) error {
c.cacheMu.Lock()
defer c.cacheMu.Unlock()
err := c.db.Update(func(tx *bbolt.Tx) error {
edges := tx.Bucket(edgeBucket)
if edges == nil {
return ErrGraphNoEdgesFound
}
zombieIndex, err := edges.CreateBucketIfNotExists(zombieBucket)
if err != nil {
return err
}
return markEdgeZombie(zombieIndex, chanID, pubKey1, pubKey2)
})
if err != nil {
return err
}
c.rejectCache.remove(chanID)
c.chanCache.remove(chanID)
return nil
}
// markEdgeZombie marks an edge as a zombie within our zombie index. The public
// keys should represent the node public keys of the two parties involved in the
// edge.

@ -1750,9 +1750,8 @@ func TestFilterKnownChanIDs(t *testing.T) {
if err := graph.AddChannelEdge(&channel); err != nil {
t.Fatalf("unable to create channel edge: %v", err)
}
if err := graph.MarkEdgeZombie(
chanID.ToUint64(), node1.PubKeyBytes, node2.PubKeyBytes,
); err != nil {
err := graph.DeleteChannelEdge(&channel.ChannelPoint)
if err != nil {
t.Fatalf("unable to mark edge zombie: %v", err)
}
@ -2864,20 +2863,28 @@ func TestGraphZombieIndex(t *testing.T) {
if err != nil {
t.Fatalf("unable to create test vertex: %v", err)
}
edge, _, _ := createChannelEdge(db, node1, node2)
// If the graph is not aware of the edge, then it should not be a
// zombie.
// Swap the nodes if the second's pubkey is smaller than the first.
// Without this, the comparisons at the end will fail probabilistically.
if bytes.Compare(node2.PubKeyBytes[:], node1.PubKeyBytes[:]) < 0 {
node1, node2 = node2, node1
}
edge, _, _ := createChannelEdge(db, node1, node2)
if err := graph.AddChannelEdge(edge); err != nil {
t.Fatalf("unable to create channel edge: %v", err)
}
// Since the edge is known the graph and it isn't a zombie, IsZombieEdge
// should not report the channel as a zombie.
isZombie, _, _ := graph.IsZombieEdge(edge.ChannelID)
if isZombie {
t.Fatal("expected edge to not be marked as zombie")
}
// If we mark the edge as a zombie, then we should expect to see it
// within the index.
err = graph.MarkEdgeZombie(
edge.ChannelID, node1.PubKeyBytes, node2.PubKeyBytes,
)
// If we delete the edge and mark it as a zombie, then we should expect
// to see it within the index.
err = graph.DeleteChannelEdge(&edge.ChannelPoint)
if err != nil {
t.Fatalf("unable to mark edge as zombie: %v", err)
}