mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-31 01:11:30 +00:00
Adjust Block height indicators properly when database is created.
This commit is contained in:
parent
9049bcacec
commit
7d679a6228
2 changed files with 16 additions and 2 deletions
|
@ -24,6 +24,14 @@ func TestEmptyDB(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dbname)
|
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
|
// This is a reopen test
|
||||||
db.Close()
|
db.Close()
|
||||||
|
|
||||||
|
@ -34,7 +42,7 @@ func TestEmptyDB(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
sha, height, err := db.NewestSha()
|
sha, height, err = db.NewestSha()
|
||||||
if !sha.IsEqual(&btcwire.ShaHash{}) {
|
if !sha.IsEqual(&btcwire.ShaHash{}) {
|
||||||
t.Errorf("sha not zero hash")
|
t.Errorf("sha not zero hash")
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,13 @@ func CreateDB(dbpath string) (btcdb.Db, error) {
|
||||||
log = btcdb.GetLog()
|
log = btcdb.GetLog()
|
||||||
|
|
||||||
// No special setup needed, just OpenBB
|
// 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() {
|
func (db *LevelDb) close() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue