From 504c8bf5f3f374ca3e32e0b72fbcafa5810a1ba8 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 21 Jul 2016 16:16:13 -0700 Subject: [PATCH] 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. --- channeldb/db.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/channeldb/db.go b/channeldb/db.go index 926a922f..2d24bc30 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -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 }) }