Insert genesis block if needed on db load.
Previously, the genesis block was only inserted when the database was created, but it's possible due to rollback that the database is created and the genesis block insert gets rolled back if the app is existed too quickly. This commit modifies the logic to test the need for the genesis block any time the database is loaded and insert it if necessary.
This commit is contained in:
parent
aad69df74b
commit
eab9c1f0c1
1 changed files with 15 additions and 11 deletions
|
@ -425,17 +425,6 @@ func loadBlockDB() (btcdb.Db, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Insert the appropriate genesis block for the bitcoin network
|
||||
// being connected to.
|
||||
genesis := btcutil.NewBlock(activeNetParams.genesisBlock)
|
||||
_, err := db.InsertBlock(genesis)
|
||||
if err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
log.Infof("[BMGR] Inserted genesis block %v",
|
||||
activeNetParams.genesisHash)
|
||||
}
|
||||
|
||||
// Get the latest block height from the database.
|
||||
|
@ -444,6 +433,21 @@ func loadBlockDB() (btcdb.Db, error) {
|
|||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Insert the appropriate genesis block for the bitcoin network being
|
||||
// connected to if needed.
|
||||
if height == -1 {
|
||||
genesis := btcutil.NewBlock(activeNetParams.genesisBlock)
|
||||
_, err := db.InsertBlock(genesis)
|
||||
if err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
log.Infof("[BMGR] Inserted genesis block %v",
|
||||
activeNetParams.genesisHash)
|
||||
height = 0
|
||||
}
|
||||
|
||||
log.Infof("[BMGR] Block database loaded with block height %d", height)
|
||||
return db, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue