channeldb/db: init one ChannelGraph per channeldb.DB

This commit is contained in:
Conner Fromknecht 2019-04-01 11:52:31 -07:00
parent ecbb78651a
commit 3c46ceec1d
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -109,6 +109,7 @@ var (
type DB struct { type DB struct {
*bbolt.DB *bbolt.DB
dbPath string dbPath string
graph *ChannelGraph
} }
// Open opens an existing channeldb. Any necessary schemas migrations due to // Open opens an existing channeldb. Any necessary schemas migrations due to
@ -131,6 +132,7 @@ func Open(dbPath string) (*DB, error) {
DB: bdb, DB: bdb,
dbPath: dbPath, dbPath: dbPath,
} }
chanDB.graph = newChannelGraph(chanDB)
// Synchronize the version of database and apply migrations if needed. // Synchronize the version of database and apply migrations if needed.
if err := chanDB.syncVersions(dbVersions); err != nil { if err := chanDB.syncVersions(dbVersions); err != nil {
@ -895,7 +897,7 @@ type ChannelShell struct {
// well. This method is idempotent, so repeated calls with the same set of // well. This method is idempotent, so repeated calls with the same set of
// channel shells won't modify the database after the initial call. // channel shells won't modify the database after the initial call.
func (d *DB) RestoreChannelShells(channelShells ...*ChannelShell) error { func (d *DB) RestoreChannelShells(channelShells ...*ChannelShell) error {
chanGraph := ChannelGraph{d} chanGraph := d.ChannelGraph()
return d.Update(func(tx *bbolt.Tx) error { return d.Update(func(tx *bbolt.Tx) error {
for _, channelShell := range channelShells { for _, channelShell := range channelShells {
@ -1107,7 +1109,7 @@ func (d *DB) syncVersions(versions []version) error {
// ChannelGraph returns a new instance of the directed channel graph. // ChannelGraph returns a new instance of the directed channel graph.
func (d *DB) ChannelGraph() *ChannelGraph { func (d *DB) ChannelGraph() *ChannelGraph {
return &ChannelGraph{d} return d.graph
} }
func getLatestDBVersion(versions []version) uint32 { func getLatestDBVersion(versions []version) uint32 {