[NOD-636] Prevent db corruption on crash. (#607)

* [NOD-636] Scope err so defer anonymous defer function will get it.

* [NOD-636] Add comment to explain why this line is needed.

* [NOD-636] Edit comment.
This commit is contained in:
Dan Aharoni 2020-01-28 11:04:41 +02:00 committed by Ori Newman
parent bf36f9ceb6
commit 8b2d3f07ce
2 changed files with 5 additions and 3 deletions

View File

@ -1992,7 +1992,10 @@ func New(config *Config) (*BlockDAG, error) {
if genesis == nil {
genesisBlock := util.NewBlock(dag.dagParams.GenesisBlock)
isOrphan, isDelayed, err := dag.ProcessBlock(genesisBlock, BFNone)
// To prevent the creation of a new err variable unintentionally so the
// defered function above could read err - declare isOrphan and isDelayed explicitly.
var isOrphan, isDelayed bool
isOrphan, isDelayed, err = dag.ProcessBlock(genesisBlock, BFNone)
if err != nil {
return nil, err
}

View File

@ -7,7 +7,6 @@ package ffldb
import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"os"
"path/filepath"
@ -640,7 +639,7 @@ func (b *bucket) CreateBucket(key []byte) (database.Bucket, error) {
// Ensure bucket does not already exist.
bidxKey := bucketIndexKey(b.id, key)
if b.tx.hasKey(bidxKey) {
str := fmt.Sprintf("bucket %s already exists", hex.EncodeToString(bidxKey))
str := fmt.Sprintf("bucket %s already exists", string(bidxKey))
return nil, makeDbErr(database.ErrBucketExists, str, nil)
}