Skip to content

Commit

Permalink
Merge pull request #534 from lochjin/main
Browse files Browse the repository at this point in the history
Optimize blockchain
  • Loading branch information
dindinw authored Sep 10, 2023
2 parents 9cd1257 + ce6764c commit 58cab6e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions core/blockchain/dbhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion database/legacychaindb/legacychaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 58cab6e

Please sign in to comment.