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
|
// database. The deletion is done in a single transaction, therefore this
|
||||||
// operation is fully atomic.
|
// operation is fully atomic.
|
||||||
func (d *DB) Wipe() error {
|
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 {
|
for _, tlb := range topLevelBuckets {
|
||||||
err := tx.DeleteTopLevelBucket(tlb)
|
err := tx.DeleteTopLevelBucket(tlb)
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
if err != nil && err != kvdb.ErrBucketNotFound {
|
||||||
@ -324,6 +324,11 @@ func (d *DB) Wipe() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, func() {})
|
}, func() {})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return initChannelDB(d.Backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
// createChannelDB creates and initializes a fresh version of channeldb. In
|
// createChannelDB creates and initializes a fresh version of channeldb. In
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/shachain"
|
"github.com/lightningnetwork/lnd/shachain"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOpenWithCreate(t *testing.T) {
|
func TestOpenWithCreate(t *testing.T) {
|
||||||
@ -96,16 +97,13 @@ func TestWipe(t *testing.T) {
|
|||||||
t.Fatalf("unable to wipe channeldb: %v", err)
|
t.Fatalf("unable to wipe channeldb: %v", err)
|
||||||
}
|
}
|
||||||
// Check correct errors are returned
|
// Check correct errors are returned
|
||||||
_, err = cdb.FetchAllOpenChannels()
|
openChannels, err := cdb.FetchAllOpenChannels()
|
||||||
if err != ErrNoActiveChannels {
|
require.NoError(t, err, "fetching open channels")
|
||||||
t.Fatalf("fetching open channels: expected '%v' instead got '%v'",
|
require.Equal(t, 0, len(openChannels))
|
||||||
ErrNoActiveChannels, err)
|
|
||||||
}
|
closedChannels, err := cdb.FetchClosedChannels(false)
|
||||||
_, err = cdb.FetchClosedChannels(false)
|
require.NoError(t, err, "fetching closed channels")
|
||||||
if err != ErrNoClosedChannels {
|
require.Equal(t, 0, len(closedChannels))
|
||||||
t.Fatalf("fetching closed channels: expected '%v' instead got '%v'",
|
|
||||||
ErrNoClosedChannels, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestFetchClosedChannelForID tests that we are able to properly retrieve a
|
// TestFetchClosedChannelForID tests that we are able to properly retrieve a
|
||||||
|
Loading…
Reference in New Issue
Block a user