routing: add strict zombie pruning as a config level param
In this commit, we add strict zombie pruning as a config level param. This allow us to add the option for those that want a tighter graph, and not change the default composition of the channel graph for most users over night. In addition, we expand the test case slightly by testing that the self node won't be pruned, but also that if there's a node with only a single known stale edge, then both variants will prune that edge.
This commit is contained in:
5 files changed
+134
-77
No files matched your search
+18
-10
@@ -188,6 +188,7 @@ type ChannelGraph struct {
|
||||
// returned instance has its own unique reject cache and channel cache.
|
||||
func newChannelGraph(db *DB, rejectCacheSize, chanCacheSize int,
|
||||
batchCommitInterval time.Duration) *ChannelGraph {
|
||||
|
||||
g := &ChannelGraph{
|
||||
db: db,
|
||||
rejectCache: newRejectCache(rejectCacheSize),
|
||||
@@ -199,6 +200,7 @@ func newChannelGraph(db *DB, rejectCacheSize, chanCacheSize int,
|
||||
g.nodeScheduler = batch.NewTimeScheduler(
|
||||
db.Backend, nil, batchCommitInterval,
|
||||
)
|
||||
|
||||
return g
|
||||
}
|
||||
|
||||
@@ -953,7 +955,7 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
||||
// was successfully pruned.
|
||||
err = delChannelEdge(
|
||||
edges, edgeIndex, chanIndex, zombieIndex, nodes,
|
||||
chanID, false,
|
||||
chanID, false, false,
|
||||
)
|
||||
if err != nil && err != ErrEdgeNotFound {
|
||||
return err
|
||||
@@ -1202,7 +1204,7 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) ([]*ChannelEdgeInf
|
||||
for _, k := range keys {
|
||||
err = delChannelEdge(
|
||||
edges, edgeIndex, chanIndex, zombieIndex, nodes,
|
||||
k, false,
|
||||
k, false, false,
|
||||
)
|
||||
if err != nil && err != ErrEdgeNotFound {
|
||||
return err
|
||||
@@ -1301,11 +1303,14 @@ func (c *ChannelGraph) PruneTip() (*chainhash.Hash, uint32, error) {
|
||||
return &tipHash, tipHeight, nil
|
||||
}
|
||||
|
||||
// DeleteChannelEdges removes edges with the given channel IDs from the database
|
||||
// and marks them as zombies. This ensures that we're unable to re-add it to our
|
||||
// database once again. If an edge does not exist within the database, then
|
||||
// ErrEdgeNotFound will be returned.
|
||||
func (c *ChannelGraph) DeleteChannelEdges(chanIDs ...uint64) error {
|
||||
// DeleteChannelEdges removes edges with the given channel IDs from the
|
||||
// database and marks them as zombies. This ensures that we're unable to re-add
|
||||
// it to our database once again. If an edge does not exist within the
|
||||
// database, then ErrEdgeNotFound will be returned. If strictZombiePruning is
|
||||
// true, then when we mark these edges as zombies, we'll set up the keys such
|
||||
// that we require the node that failed to send the fresh update to be the one
|
||||
// that resurrects the channel from its zombie state.
|
||||
func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning bool, chanIDs ...uint64) error {
|
||||
// TODO(roasbeef): possibly delete from node bucket if node has no more
|
||||
// channels
|
||||
// TODO(roasbeef): don't delete both edges?
|
||||
@@ -1340,7 +1345,7 @@ func (c *ChannelGraph) DeleteChannelEdges(chanIDs ...uint64) error {
|
||||
byteOrder.PutUint64(rawChanID[:], chanID)
|
||||
err := delChannelEdge(
|
||||
edges, edgeIndex, chanIndex, zombieIndex, nodes,
|
||||
rawChanID[:], true,
|
||||
rawChanID[:], true, strictZombiePruning,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1929,7 +1934,7 @@ func delEdgeUpdateIndexEntry(edgesBucket kvdb.RwBucket, chanID uint64,
|
||||
}
|
||||
|
||||
func delChannelEdge(edges, edgeIndex, chanIndex, zombieIndex,
|
||||
nodes kvdb.RwBucket, chanID []byte, isZombie bool) error {
|
||||
nodes kvdb.RwBucket, chanID []byte, isZombie, strictZombie bool) error {
|
||||
|
||||
edgeInfo, err := fetchChanEdgeInfo(edgeIndex, chanID)
|
||||
if err != nil {
|
||||
@@ -1997,7 +2002,10 @@ func delChannelEdge(edges, edgeIndex, chanIndex, zombieIndex,
|
||||
return nil
|
||||
}
|
||||
|
||||
nodeKey1, nodeKey2 := makeZombiePubkeys(&edgeInfo, edge1, edge2)
|
||||
nodeKey1, nodeKey2 := edgeInfo.NodeKey1Bytes, edgeInfo.NodeKey2Bytes
|
||||
if strictZombie {
|
||||
nodeKey1, nodeKey2 = makeZombiePubkeys(&edgeInfo, edge1, edge2)
|
||||
}
|
||||
|
||||
return markEdgeZombie(
|
||||
zombieIndex, byteOrder.Uint64(chanID), nodeKey1, nodeKey2,
|
||||
|
||||
@@ -368,7 +368,7 @@ func TestEdgeInsertionDeletion(t *testing.T) {
|
||||
|
||||
// Next, attempt to delete the edge from the database, again this
|
||||
// should proceed without any issues.
|
||||
if err := graph.DeleteChannelEdges(chanID); err != nil {
|
||||
if err := graph.DeleteChannelEdges(false, chanID); err != nil {
|
||||
t.Fatalf("unable to delete edge: %v", err)
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ func TestEdgeInsertionDeletion(t *testing.T) {
|
||||
|
||||
// Finally, attempt to delete a (now) non-existent edge within the
|
||||
// database, this should result in an error.
|
||||
err = graph.DeleteChannelEdges(chanID)
|
||||
err = graph.DeleteChannelEdges(false, chanID)
|
||||
if err != ErrEdgeNotFound {
|
||||
t.Fatalf("deleting a non-existent edge should fail!")
|
||||
}
|
||||
@@ -1756,7 +1756,7 @@ func TestFilterKnownChanIDs(t *testing.T) {
|
||||
if err := graph.AddChannelEdge(&channel); err != nil {
|
||||
t.Fatalf("unable to create channel edge: %v", err)
|
||||
}
|
||||
err := graph.DeleteChannelEdges(channel.ChannelID)
|
||||
err := graph.DeleteChannelEdges(false, channel.ChannelID)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to mark edge zombie: %v", err)
|
||||
}
|
||||
@@ -2038,7 +2038,7 @@ func TestFetchChanInfos(t *testing.T) {
|
||||
if err := graph.AddChannelEdge(&zombieChan); err != nil {
|
||||
t.Fatalf("unable to create channel edge: %v", err)
|
||||
}
|
||||
err = graph.DeleteChannelEdges(zombieChan.ChannelID)
|
||||
err = graph.DeleteChannelEdges(false, zombieChan.ChannelID)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to delete and mark edge zombie: %v", err)
|
||||
}
|
||||
@@ -2654,7 +2654,7 @@ func TestNodeIsPublic(t *testing.T) {
|
||||
// graph. This will make Alice be seen as a private node as it no longer
|
||||
// has any advertised edges.
|
||||
for _, graph := range graphs {
|
||||
err := graph.DeleteChannelEdges(aliceBobEdge.ChannelID)
|
||||
err := graph.DeleteChannelEdges(false, aliceBobEdge.ChannelID)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to remove edge: %v", err)
|
||||
}
|
||||
@@ -2671,7 +2671,7 @@ func TestNodeIsPublic(t *testing.T) {
|
||||
// completely remove the edge as it is not possible for her to know of
|
||||
// it without it being advertised.
|
||||
for i, graph := range graphs {
|
||||
err := graph.DeleteChannelEdges(bobCarolEdge.ChannelID)
|
||||
err := graph.DeleteChannelEdges(false, bobCarolEdge.ChannelID)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to remove edge: %v", err)
|
||||
}
|
||||
@@ -2779,7 +2779,7 @@ func TestDisabledChannelIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
// Delete the channel edge and ensure it is removed from the disabled list.
|
||||
if err = graph.DeleteChannelEdges(edgeInfo.ChannelID); err != nil {
|
||||
if err = graph.DeleteChannelEdges(false, edgeInfo.ChannelID); err != nil {
|
||||
t.Fatalf("unable to delete channel edge: %v", err)
|
||||
}
|
||||
disabledChanIds, err = graph.DisabledChannelIDs()
|
||||
@@ -3017,7 +3017,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(edge.ChannelID)
|
||||
err = graph.DeleteChannelEdges(false, edge.ChannelID)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to mark edge as zombie: %v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user