Adjust Block height indicators properly when database is created.

This commit is contained in:
Dale Rahn 2013-09-10 14:17:24 -04:00
parent 9049bcacec
commit 7d679a6228
2 changed files with 16 additions and 2 deletions

View file

@ -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")
}

View file

@ -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() {