Skip to content

Commit

Permalink
Revert "change type of diffLayerChanCache to sync.Map"
Browse files Browse the repository at this point in the history
This reverts commit f8c6a4a.
  • Loading branch information
j75689 committed Apr 20, 2022
1 parent 1e44aa6 commit 7ad4d02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ type BlockChain struct {
// trusted diff layers
diffLayerCache *lru.Cache // Cache for the diffLayers
diffLayerRLPCache *lru.Cache // Cache for the rlp encoded diffLayers
diffLayerChanCache *sync.Map // Cache for
diffLayerChanCache *lru.Cache // Cache for
diffQueue *prque.Prque // A Priority queue to store recent diff layer
diffQueueBuffer chan *types.DiffLayer
diffLayerFreezerBlockLimit uint64
Expand Down Expand Up @@ -279,7 +279,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
futureBlocks, _ := lru.New(maxFutureBlocks)
diffLayerCache, _ := lru.New(diffLayerCacheLimit)
diffLayerRLPCache, _ := lru.New(diffLayerRLPCacheLimit)
diffLayerChanCache := new(sync.Map)
diffLayerChanCache, _ := lru.New(diffLayerCacheLimit)

bc := &BlockChain{
chainConfig: chainConfig,
Expand Down Expand Up @@ -529,7 +529,7 @@ func (bc *BlockChain) cacheDiffLayer(diffLayer *types.DiffLayer, sorted bool) {
}

bc.diffLayerCache.Add(diffLayer.BlockHash, diffLayer)
if cached, ok := bc.diffLayerChanCache.Load(diffLayer.BlockHash); ok {
if cached, ok := bc.diffLayerChanCache.Get(diffLayer.BlockHash); ok {
diffLayerCh := cached.(chan struct{})
close(diffLayerCh)
}
Expand Down Expand Up @@ -1834,7 +1834,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
diffLayer.Number = block.NumberU64()

diffLayerCh := make(chan struct{})
bc.diffLayerChanCache.Store(diffLayer.BlockHash, diffLayerCh)
bc.diffLayerChanCache.Add(diffLayer.BlockHash, diffLayerCh)

go bc.cacheDiffLayer(diffLayer, false)
}
Expand Down
12 changes: 10 additions & 2 deletions core/remote_state_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,24 @@ func (vm *remoteVerifyManager) NewBlockVerifyTask(header *types.Header) {
}

var diffLayer *types.DiffLayer
if cached, ok := vm.bc.diffLayerChanCache.Load(hash); ok {
if cached, ok := vm.bc.diffLayerChanCache.Get(hash); ok {
diffLayerCh := cached.(chan struct{})
<-diffLayerCh
vm.bc.diffLayerChanCache.Delete(hash)
vm.bc.diffLayerChanCache.Remove(hash)
diffLayer = vm.bc.GetTrustedDiffLayer(hash)
}
// if this block has no diff, there is no need to verify it.
var err error
if diffLayer == nil {
log.Info("block's trusted diffLayer is nil", "hash", hash, "number", header.Number)
//if diffLayer, err = vm.bc.GenerateDiffLayer(hash); err != nil {
// log.Error("failed to get diff layer", "block", hash, "number", header.Number, "error", err)
// return
//} else if diffLayer == nil {
// log.Info("this is an empty block:", "block", hash, "number", header.Number)
// vm.cacheBlockVerified(hash)
// return
//}
}
diffHash, err := CalculateDiffHash(diffLayer)
if err != nil {
Expand Down

0 comments on commit 7ad4d02

Please sign in to comment.