diff --git a/consensus/consensus_test.go b/consensus/consensus_test.go index cc86e401..eb67b8a4 100644 --- a/consensus/consensus_test.go +++ b/consensus/consensus_test.go @@ -22,12 +22,13 @@ func TestAloneConsensus(t *testing.T) { if err != nil { t.Error(err) } - defer db.Close() + cons := NewPure(cfg, db) err = cons.Init() if err != nil { t.Error(err) } + db.Close() // remove temporary data err = os.RemoveAll(cfg.HomeDir) if err != nil { diff --git a/core/blockchain/dbhelper.go b/core/blockchain/dbhelper.go index bb871bc0..71bba48d 100644 --- a/core/blockchain/dbhelper.go +++ b/core/blockchain/dbhelper.go @@ -5,7 +5,6 @@ import ( "github.com/Qitmeer/qng/common/hash" "github.com/Qitmeer/qng/consensus/model" "github.com/Qitmeer/qng/core/types" - "github.com/Qitmeer/qng/database/legacydb" ) // dbFetchBlockByHash uses an existing database transaction to retrieve the raw @@ -26,9 +25,6 @@ func dbFetchHeaderByHash(db model.DataBase, hash *hash.Hash) (*types.BlockHeader func dbMaybeStoreBlock(db model.DataBase, block *types.SerializedBlock) error { err := db.PutBlock(block) if err != nil { - if legacydb.IsError(err, legacydb.ErrBlockExists) { - return nil - } return err } return nil diff --git a/database/legacychaindb/legacychaindb.go b/database/legacychaindb/legacychaindb.go index 3ba80cf2..a7a8b161 100644 --- a/database/legacychaindb/legacychaindb.go +++ b/database/legacychaindb/legacychaindb.go @@ -337,9 +337,16 @@ func (cdb *LegacyChainDB) GetHeader(hash *hash.Hash) (*types.BlockHeader, error) } func (cdb *LegacyChainDB) PutBlock(block *types.SerializedBlock) error { - return cdb.db.Update(func(dbTx legacydb.Tx) error { + err := cdb.db.Update(func(dbTx legacydb.Tx) error { return dbTx.StoreBlock(block) }) + if err != nil { + if legacydb.IsError(err, legacydb.ErrBlockExists) { + return nil + } + return err + } + return nil } func (cdb *LegacyChainDB) HasBlock(hash *hash.Hash) bool {