diff --git a/ldb/boundary_test.go b/ldb/boundary_test.go index dc0bdd06..df2a6ebd 100644 --- a/ldb/boundary_test.go +++ b/ldb/boundary_test.go @@ -24,6 +24,14 @@ func TestEmptyDB(t *testing.T) { } defer os.RemoveAll(dbname) + sha, height, err := db.NewestSha() + if !sha.IsEqual(&btcwire.ShaHash{}) { + t.Errorf("sha not zero hash") + } + if height != -1 { + t.Errorf("height not -1 %v", height) + } + // This is a reopen test db.Close() @@ -34,7 +42,7 @@ func TestEmptyDB(t *testing.T) { } defer db.Close() - sha, height, err := db.NewestSha() + sha, height, err = db.NewestSha() if !sha.IsEqual(&btcwire.ShaHash{}) { t.Errorf("sha not zero hash") } diff --git a/ldb/leveldb.go b/ldb/leveldb.go index ed22318f..7713c5ce 100644 --- a/ldb/leveldb.go +++ b/ldb/leveldb.go @@ -170,7 +170,13 @@ func CreateDB(dbpath string) (btcdb.Db, error) { log = btcdb.GetLog() // No special setup needed, just OpenBB - return openDB(dbpath, opt.OFCreateIfMissing) + db, err := openDB(dbpath, opt.OFCreateIfMissing) + if err == nil { + ldb := db.(*LevelDb) + ldb.lastBlkIdx = -1 + ldb.nextBlock = 0 + } + return db, err } func (db *LevelDb) close() {