channeldb: add storage of an on-disk directed channel graph
This commit introduces a new capability to the database: storage of an on-disk directed channel graph. The on-disk representation of the graph within boltdb is essentially a modified adjacency list which separates the storage of the edge’s existence and the storage of the edge information itself. The new objects provided within he ChannelGraph carry an API which facilitates easy graph traversal via their ForEach* methods. As a result, path finding algorithms will be able to be expressed in a natural way using the range methods as a for-range language extension within Go. Additionally caching will likely be added either at this layer or the layer above (the RoutingManager) in order keep queries and outgoing payments speedy. In a future commit a new set of RPC’s to query the state of a particular edge or node will also be added.
This commit is contained in:
4 files changed
+1653
-1
No files matched your search
@@ -116,6 +116,15 @@ func (d *DB) Wipe() error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.DeleteBucket(nodeBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
err = tx.DeleteBucket(edgeBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -154,6 +163,13 @@ func createChannelDB(dbPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.CreateBucket(nodeBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.CreateBucket(edgeBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.CreateBucket(metaBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -349,6 +365,11 @@ func (d *DB) syncVersions(versions []version) error {
|
||||
})
|
||||
}
|
||||
|
||||
// ChannelGraph returns a new instance of the directed channel graph.
|
||||
func (d *DB) ChannelGraph() *ChannelGraph {
|
||||
return &ChannelGraph{d}
|
||||
}
|
||||
|
||||
func getLatestDBVersion(versions []version) uint32 {
|
||||
return versions[len(versions)-1].number
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user