Skip to content

Commit f8c6a4a

Browse files
committed
change type of diffLayerChanCache to sync.Map
1 parent 5675916 commit f8c6a4a

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

core/blockchain.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ type BlockChain struct {
227227
// trusted diff layers
228228
diffLayerCache *lru.Cache // Cache for the diffLayers
229229
diffLayerRLPCache *lru.Cache // Cache for the rlp encoded diffLayers
230-
diffLayerChanCache *lru.Cache // Cache for
230+
diffLayerChanCache *sync.Map // Cache for
231231
diffQueue *prque.Prque // A Priority queue to store recent diff layer
232232
diffQueueBuffer chan *types.DiffLayer
233233
diffLayerFreezerBlockLimit uint64
@@ -279,7 +279,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
279279
futureBlocks, _ := lru.New(maxFutureBlocks)
280280
diffLayerCache, _ := lru.New(diffLayerCacheLimit)
281281
diffLayerRLPCache, _ := lru.New(diffLayerRLPCacheLimit)
282-
diffLayerChanCache, _ := lru.New(diffLayerCacheLimit)
282+
diffLayerChanCache := new(sync.Map)
283283

284284
bc := &BlockChain{
285285
chainConfig: chainConfig,
@@ -529,7 +529,7 @@ func (bc *BlockChain) cacheDiffLayer(diffLayer *types.DiffLayer, sorted bool) {
529529
}
530530

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

18361836
diffLayerCh := make(chan struct{})
1837-
bc.diffLayerChanCache.Add(diffLayer.BlockHash, diffLayerCh)
1837+
bc.diffLayerChanCache.Store(diffLayer.BlockHash, diffLayerCh)
18381838

18391839
go bc.cacheDiffLayer(diffLayer, false)
18401840
}

core/remote_state_verifier.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func NewVerifyManager(blockchain *BlockChain, peers verifyPeers, allowInsecure b
7676
}
7777
diffLayerCh := make(chan struct{})
7878
close(diffLayerCh)
79-
blockchain.diffLayerChanCache.Add(blockHash, diffLayerCh)
79+
blockchain.diffLayerChanCache.Store(blockHash, diffLayerCh)
8080
}
8181

8282
vm := &remoteVerifyManager{
@@ -167,24 +167,16 @@ func (vm *remoteVerifyManager) NewBlockVerifyTask(header *types.Header) {
167167
}
168168

169169
var diffLayer *types.DiffLayer
170-
if cached, ok := vm.bc.diffLayerChanCache.Get(hash); ok {
170+
if cached, ok := vm.bc.diffLayerChanCache.Load(hash); ok {
171171
diffLayerCh := cached.(chan struct{})
172172
<-diffLayerCh
173-
vm.bc.diffLayerChanCache.Remove(hash)
173+
vm.bc.diffLayerChanCache.Delete(hash)
174174
diffLayer = vm.bc.GetTrustedDiffLayer(hash)
175175
}
176176
// if this block has no diff, there is no need to verify it.
177177
var err error
178178
if diffLayer == nil {
179179
log.Info("block's trusted diffLayer is nil", "hash", hash, "number", header.Number)
180-
//if diffLayer, err = vm.bc.GenerateDiffLayer(hash); err != nil {
181-
// log.Error("failed to get diff layer", "block", hash, "number", header.Number, "error", err)
182-
// return
183-
//} else if diffLayer == nil {
184-
// log.Info("this is an empty block:", "block", hash, "number", header.Number)
185-
// vm.cacheBlockVerified(hash)
186-
// return
187-
//}
188180
}
189181
diffHash, err := CalculateDiffHash(diffLayer)
190182
if err != nil {

0 commit comments

Comments
 (0)