channeldb/db: properly reinit wallet during Wipe
Previously we wouldn't recreate some of the top level buckets that are now considered expected with our migration logic. This bug was preexisting, but never surfaced because the other TLB buckets were not touched by this unit test.
This commit is contained in:
parent
08bb8abaa3
commit
08ee754a6d
@ -315,7 +315,7 @@ var topLevelBuckets = [][]byte{
|
||||
// database. The deletion is done in a single transaction, therefore this
|
||||
// operation is fully atomic.
|
||||
func (d *DB) Wipe() error {
|
||||
return kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||
err := kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||
for _, tlb := range topLevelBuckets {
|
||||
err := tx.DeleteTopLevelBucket(tlb)
|
||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
||||
@ -324,6 +324,11 @@ func (d *DB) Wipe() error {
|
||||
}
|
||||
return nil
|
||||
}, func() {})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return initChannelDB(d.Backend)
|
||||
}
|
||||
|
||||
// createChannelDB creates and initializes a fresh version of channeldb. In
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/shachain"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOpenWithCreate(t *testing.T) {
|
||||
@ -96,16 +97,13 @@ func TestWipe(t *testing.T) {
|
||||
t.Fatalf("unable to wipe channeldb: %v", err)
|
||||
}
|
||||
// Check correct errors are returned
|
||||
_, err = cdb.FetchAllOpenChannels()
|
||||
if err != ErrNoActiveChannels {
|
||||
t.Fatalf("fetching open channels: expected '%v' instead got '%v'",
|
||||
ErrNoActiveChannels, err)
|
||||
}
|
||||
_, err = cdb.FetchClosedChannels(false)
|
||||
if err != ErrNoClosedChannels {
|
||||
t.Fatalf("fetching closed channels: expected '%v' instead got '%v'",
|
||||
ErrNoClosedChannels, err)
|
||||
}
|
||||
openChannels, err := cdb.FetchAllOpenChannels()
|
||||
require.NoError(t, err, "fetching open channels")
|
||||
require.Equal(t, 0, len(openChannels))
|
||||
|
||||
closedChannels, err := cdb.FetchClosedChannels(false)
|
||||
require.NoError(t, err, "fetching closed channels")
|
||||
require.Equal(t, 0, len(closedChannels))
|
||||
}
|
||||
|
||||
// TestFetchClosedChannelForID tests that we are able to properly retrieve a
|
||||
|
Loading…
Reference in New Issue
Block a user