From fc2d652261ff4dece4fe8b5bfcbb16fc10f9b7c9 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 30 Sep 2022 14:17:14 +0200 Subject: [PATCH] channeldb: check for tombstone before opening DB To avoid running a channel DB that was successfully migrated to another system by accident, we check if there is a tombstone marker before we open the DB for use. --- channeldb/db.go | 5 +++++ channeldb/meta_test.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/channeldb/db.go b/channeldb/db.go index 3e6590878..8fa236caf 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -436,6 +436,11 @@ func (d *DB) Wipe() error { // the database are created. func initChannelDB(db kvdb.Backend) error { err := kvdb.Update(db, func(tx kvdb.RwTx) error { + // Check if DB was marked as inactive with a tomb stone. + if err := EnsureNoTombstone(tx); err != nil { + return err + } + meta := &Meta{} // Check if DB is already initialized. err := FetchMeta(meta, tx) diff --git a/channeldb/meta_test.go b/channeldb/meta_test.go index a6a965f11..574744ba6 100644 --- a/channeldb/meta_test.go +++ b/channeldb/meta_test.go @@ -681,4 +681,9 @@ func TestMarkerAndTombstone(t *testing.T) { // cannot be used anymore. err = db.View(EnsureNoTombstone, func() {}) require.ErrorContains(t, err, string(tombstoneText)) + + // Now that the DB has a tombstone, we should no longer be able to open + // it once we close it. + _, err = CreateWithBackend(db.Backend) + require.ErrorContains(t, err, string(tombstoneText)) }