Skip to content

Commit

Permalink
Optimize difflayer
Browse files Browse the repository at this point in the history
  • Loading branch information
lochjin committed Oct 21, 2023
1 parent 8bd7eea commit 3e2e2bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions database/chaindb/chaindb_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (

func (cdb *ChainDB) PutTxIdxEntrys(sblock *types.SerializedBlock, block model.Block) error {
if cdb.diff != nil {
return cdb.diff.PutTxIdxEntrys(sblock,block)
return cdb.diff.PutTxIdxEntrys(sblock, block)
}
return rawdb.WriteTxLookupEntriesByBlock(cdb.db, sblock, uint64(block.GetID()))
}

func (cdb *ChainDB) GetTxIdxEntry(id *hash.Hash, verbose bool) (*types.Tx, *hash.Hash, error) {
if cdb.diff != nil {
return cdb.diff.GetTxIdxEntry(id,verbose)
return cdb.diff.GetTxIdxEntry(id, verbose)
}
if !verbose {
blockID := rawdb.ReadTxLookupEntry(cdb.db, id)
Expand Down
10 changes: 8 additions & 2 deletions database/chaindb/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
com "github.com/Qitmeer/qng/database/common"
"github.com/Qitmeer/qng/database/rawdb"
"github.com/Qitmeer/qng/meerdag"
"github.com/Qitmeer/qng/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"sync"
Expand Down Expand Up @@ -44,12 +45,17 @@ type diffLayer struct {
}

func (dl *diffLayer) handler() {
timer := time.NewTicker(time.Minute)
timer := time.NewTicker(params.ActiveNetParams.TargetTimePerBlock)
out:
for {
select {
case <-timer.C:
if dl.memory.Load() >= dl.cache {
dl.lock.RLock()
bcSize := len(dl.blocks)
dl.lock.RUnlock()

if dl.memory.Load() >= dl.cache ||
bcSize >= meerdag.MinBlockDataCache {
err := dl.flatten()
if err != nil {
log.Error(err.Error())
Expand Down

0 comments on commit 3e2e2bb

Please sign in to comment.