Skip to content

Commit 7ad4d02

Browse files
committed
Revert "change type of diffLayerChanCache to sync.Map"
This reverts commit f8c6a4a.
1 parent 1e44aa6 commit 7ad4d02

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
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 *sync.Map // Cache for
230+
diffLayerChanCache *lru.Cache // 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 := new(sync.Map)
282+
diffLayerChanCache, _ := lru.New(diffLayerCacheLimit)
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.Load(diffLayer.BlockHash); ok {
532+
if cached, ok := bc.diffLayerChanCache.Get(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.Store(diffLayer.BlockHash, diffLayerCh)
1837+
bc.diffLayerChanCache.Add(diffLayer.BlockHash, diffLayerCh)
18381838

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

core/remote_state_verifier.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,24 @@ func (vm *remoteVerifyManager) NewBlockVerifyTask(header *types.Header) {
182182
}
183183

184184
var diffLayer *types.DiffLayer
185-
if cached, ok := vm.bc.diffLayerChanCache.Load(hash); ok {
185+
if cached, ok := vm.bc.diffLayerChanCache.Get(hash); ok {
186186
diffLayerCh := cached.(chan struct{})
187187
<-diffLayerCh
188-
vm.bc.diffLayerChanCache.Delete(hash)
188+
vm.bc.diffLayerChanCache.Remove(hash)
189189
diffLayer = vm.bc.GetTrustedDiffLayer(hash)
190190
}
191191
// if this block has no diff, there is no need to verify it.
192192
var err error
193193
if diffLayer == nil {
194194
log.Info("block's trusted diffLayer is nil", "hash", hash, "number", header.Number)
195+
//if diffLayer, err = vm.bc.GenerateDiffLayer(hash); err != nil {
196+
// log.Error("failed to get diff layer", "block", hash, "number", header.Number, "error", err)
197+
// return
198+
//} else if diffLayer == nil {
199+
// log.Info("this is an empty block:", "block", hash, "number", header.Number)
200+
// vm.cacheBlockVerified(hash)
201+
// return
202+
//}
195203
}
196204
diffHash, err := CalculateDiffHash(diffLayer)
197205
if err != nil {

0 commit comments

Comments
 (0)