channeldb: remove graph db from channeldb

Now that the channel.DB no longer uses the ChannelGraph pointer, we can
completely remove it as a member of channeldb.DB.
This commit is contained in:
Elle Mouton
2024-10-22 14:51:32 +02:00
parent 2c083bc017
commit b86980ec40
9 changed files with 100 additions and 134 deletions

View File

@@ -335,7 +335,6 @@ type DB struct {
channelStateDB *ChannelStateDB
dbPath string
graph *graphdb.ChannelGraph
clock clock.Clock
dryRun bool
keepFailedPaymentAttempts bool
@@ -362,22 +361,18 @@ func Open(dbPath string, modifiers ...OptionModifier) (*DB, error) {
return nil, err
}
graphDB, err := graphdb.NewChannelGraph(backend)
if err != nil {
return nil, err
}
db, err := CreateWithBackend(backend, graphDB, modifiers...)
db, err := CreateWithBackend(backend, modifiers...)
if err == nil {
db.dbPath = dbPath
}
return db, err
}
// CreateWithBackend creates channeldb instance using the passed kvdb.Backend.
// Any necessary schemas migrations due to updates will take place as necessary.
func CreateWithBackend(backend kvdb.Backend, graph *graphdb.ChannelGraph,
modifiers ...OptionModifier) (*DB, error) {
func CreateWithBackend(backend kvdb.Backend, modifiers ...OptionModifier) (*DB,
error) {
opts := DefaultOptions()
for _, modifier := range modifiers {
@@ -403,7 +398,6 @@ func CreateWithBackend(backend kvdb.Backend, graph *graphdb.ChannelGraph,
keepFailedPaymentAttempts: opts.keepFailedPaymentAttempts,
storeFinalHtlcResolutions: opts.storeFinalHtlcResolutions,
noRevLogAmtData: opts.NoRevLogAmtData,
graph: graph,
}
// Set the parent pointer (only used in tests).
@@ -1612,11 +1606,6 @@ func (d *DB) applyOptionalVersions(cfg OptionalMiragtionConfig) error {
return nil
}
// ChannelGraph returns the current instance of the directed channel graph.
func (d *DB) ChannelGraph() *graphdb.ChannelGraph {
return d.graph
}
// ChannelStateDB returns the sub database that is concerned with the channel
// state.
func (d *DB) ChannelStateDB() *ChannelStateDB {
@@ -1832,13 +1821,7 @@ func MakeTestDB(t *testing.T, modifiers ...OptionModifier) (*DB, error) {
return nil, err
}
graphDB, err := graphdb.NewChannelGraph(backend)
if err != nil {
backendCleanup()
return nil, err
}
cdb, err := CreateWithBackend(backend, graphDB, modifiers...)
cdb, err := CreateWithBackend(backend, modifiers...)
if err != nil {
backendCleanup()
return nil, err

View File

@@ -51,10 +51,7 @@ func TestOpenWithCreate(t *testing.T) {
require.NoError(t, err, "unable to get test db backend")
t.Cleanup(cleanup)
graphDB, err := graphdb.NewChannelGraph(backend)
require.NoError(t, err)
cdb, err := CreateWithBackend(backend, graphDB)
cdb, err := CreateWithBackend(backend)
require.NoError(t, err, "unable to create channeldb")
if err := cdb.Close(); err != nil {
t.Fatalf("unable to close channeldb: %v", err)
@@ -90,10 +87,7 @@ func TestWipe(t *testing.T) {
require.NoError(t, err, "unable to get test db backend")
t.Cleanup(cleanup)
graphDB, err := graphdb.NewChannelGraph(backend)
require.NoError(t, err)
fullDB, err := CreateWithBackend(backend, graphDB)
fullDB, err := CreateWithBackend(backend)
require.NoError(t, err, "unable to create channeldb")
defer fullDB.Close()
@@ -194,7 +188,8 @@ func TestMultiSourceAddrsForNode(t *testing.T) {
fullDB, err := MakeTestDB(t)
require.NoError(t, err, "unable to make test database")
graph := fullDB.ChannelGraph()
graph, err := graphdb.MakeTestGraph(t)
require.NoError(t, err)
// We'll make a test vertex to insert into the database, as the source
// node, but this node will only have half the number of addresses it

View File

@@ -25,10 +25,9 @@ func applyMigration(t *testing.T, beforeMigration, afterMigration func(d *DB),
// Create a test node that will be our source node.
testNode := createTestVertex(t)
graph := cdb.ChannelGraph()
if err := graph.SetSourceNode(testNode); err != nil {
t.Fatal(err)
}
graph, err := graphdb.MakeTestGraph(t)
require.NoError(t, err)
require.NoError(t, graph.SetSourceNode(testNode))
// beforeMigration usually used for populating the database
// with test data.
@@ -423,10 +422,7 @@ func TestMigrationReversion(t *testing.T) {
backend, cleanup, err := kvdb.GetTestBackend(tempDirName, "cdb")
require.NoError(t, err, "unable to get test db backend")
graphDB, err := graphdb.NewChannelGraph(backend)
require.NoError(t, err)
cdb, err := CreateWithBackend(backend, graphDB)
cdb, err := CreateWithBackend(backend)
if err != nil {
cleanup()
t.Fatalf("unable to open channeldb: %v", err)
@@ -452,10 +448,7 @@ func TestMigrationReversion(t *testing.T) {
require.NoError(t, err, "unable to get test db backend")
t.Cleanup(cleanup)
graphDB, err = graphdb.NewChannelGraph(backend)
require.NoError(t, err)
_, err = CreateWithBackend(backend, graphDB)
_, err = CreateWithBackend(backend)
if err != ErrDBReversion {
t.Fatalf("unexpected error when opening channeldb, "+
"want: %v, got: %v", ErrDBReversion, err)
@@ -683,11 +676,8 @@ func TestMarkerAndTombstone(t *testing.T) {
err = db.View(EnsureNoTombstone, func() {})
require.ErrorContains(t, err, string(tombstoneText))
graphDB, err := graphdb.NewChannelGraph(db.Backend)
require.NoError(t, err)
// Now that the DB has a tombstone, we should no longer be able to open
// it once we close it.
_, err = CreateWithBackend(db.Backend, graphDB)
_, err = CreateWithBackend(db.Backend)
require.ErrorContains(t, err, string(tombstoneText))
}