channeldb: bucket not found during .Wipe() is no longer an error

This commit changes the current behavior around channeldb.Wipe().
Previously if a channel had never been closed, and a wipe was
attempted, then wipe operation would fail and the transaction would be
rolled back.

This commit fixes this behavior by checking for bolt.ErrBucketNotFound
error, and handling the specific error as a noop.
This commit is contained in:
Olaoluwa Osuntokun 2016-07-21 16:16:13 -07:00
parent 6283eb29bf
commit 504c8bf5f3
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -77,11 +77,17 @@ func (d *DB) RegisterCryptoSystem(ed EncryptorDecryptor) {
// operation is fully atomic.
func (d *DB) Wipe() error {
return d.store.Update(func(tx *bolt.Tx) error {
if err := tx.DeleteBucket(openChannelBucket); err != nil {
err := tx.DeleteBucket(openChannelBucket)
if err != nil && err != bolt.ErrBucketNotFound {
return err
}
return tx.DeleteBucket(closedChannelBucket)
err = tx.DeleteBucket(closedChannelBucket)
if err != nil && err != bolt.ErrBucketNotFound {
return err
}
return nil
})
}