@@ -28,9 +28,8 @@ import (
2828 "sync/atomic"
2929 "time"
3030
31- "golang.org/x/crypto/sha3"
32-
3331 lru "github.com/hashicorp/golang-lru"
32+ "golang.org/x/crypto/sha3"
3433
3534 "github.com/ethereum/go-ethereum/common"
3635 "github.com/ethereum/go-ethereum/common/mclock"
@@ -509,31 +508,27 @@ func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts) {
509508 bc .receiptsCache .Add (hash , receipts )
510509}
511510
512- func (bc * BlockChain ) cacheDiffLayer (diffLayer * types.DiffLayer , sorted bool ) {
513- if ! sorted {
514- sort .SliceStable (diffLayer .Codes , func (i , j int ) bool {
515- return diffLayer .Codes [i ].Hash .Hex () < diffLayer .Codes [j ].Hash .Hex ()
516- })
517- sort .SliceStable (diffLayer .Destructs , func (i , j int ) bool {
518- return diffLayer .Destructs [i ].Hex () < (diffLayer .Destructs [j ].Hex ())
519- })
520- sort .SliceStable (diffLayer .Accounts , func (i , j int ) bool {
521- return diffLayer .Accounts [i ].Account .Hex () < diffLayer .Accounts [j ].Account .Hex ()
522- })
523- sort .SliceStable (diffLayer .Storages , func (i , j int ) bool {
524- return diffLayer .Storages [i ].Account .Hex () < diffLayer .Storages [j ].Account .Hex ()
525- })
526- }
511+ func (bc * BlockChain ) cacheDiffLayer (diffLayer * types.DiffLayer , diffLayerCh chan struct {}) {
512+ sort .SliceStable (diffLayer .Codes , func (i , j int ) bool {
513+ return diffLayer .Codes [i ].Hash .Hex () < diffLayer .Codes [j ].Hash .Hex ()
514+ })
515+ sort .SliceStable (diffLayer .Destructs , func (i , j int ) bool {
516+ return diffLayer .Destructs [i ].Hex () < (diffLayer .Destructs [j ].Hex ())
517+ })
518+ sort .SliceStable (diffLayer .Accounts , func (i , j int ) bool {
519+ return diffLayer .Accounts [i ].Account .Hex () < diffLayer .Accounts [j ].Account .Hex ()
520+ })
521+ sort .SliceStable (diffLayer .Storages , func (i , j int ) bool {
522+ return diffLayer .Storages [i ].Account .Hex () < diffLayer .Storages [j ].Account .Hex ()
523+ })
527524
528525 if bc .diffLayerCache .Len () >= diffLayerCacheLimit {
529526 bc .diffLayerCache .RemoveOldest ()
530527 }
531528
532529 bc .diffLayerCache .Add (diffLayer .BlockHash , diffLayer )
533- if cached , ok := bc .diffLayerChanCache .Get (diffLayer .BlockHash ); ok {
534- diffLayerCh := cached .(chan struct {})
535- close (diffLayerCh )
536- }
530+ close (diffLayerCh )
531+
537532 if bc .db .DiffStore () != nil {
538533 // push to priority queue before persisting
539534 bc .diffQueueBuffer <- diffLayer
@@ -1840,7 +1835,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
18401835 }
18411836 bc .diffLayerChanCache .Add (diffLayer .BlockHash , diffLayerCh )
18421837
1843- go bc .cacheDiffLayer (diffLayer , false )
1838+ go bc .cacheDiffLayer (diffLayer , diffLayerCh )
18441839 }
18451840
18461841 wg .Wait ()
@@ -2156,7 +2151,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
21562151 return it .index , err
21572152 }
21582153 if statedb .NoTrie () {
2159- statedb .SetCurrentRoot (block .Root ())
2154+ statedb .SetExpectedStateRoot (block .Root ())
21602155 }
21612156 bc .updateHighestVerifiedHeader (block .Header ())
21622157
@@ -2833,10 +2828,10 @@ func (bc *BlockChain) HandleDiffLayer(diffLayer *types.DiffLayer, pid string, fu
28332828 return nil
28342829 }
28352830
2836- diffHash := common.Hash {}
2837- if diffLayer .DiffHash .Load () != nil {
2838- diffHash = diffLayer .DiffHash .Load ().(common.Hash )
2831+ if diffLayer .DiffHash .Load () == nil {
2832+ return fmt .Errorf ("unexpected difflayer which diffHash is nil from peeer %s" , pid )
28392833 }
2834+ diffHash := diffLayer .DiffHash .Load ().(common.Hash )
28402835
28412836 bc .diffMux .Lock ()
28422837 defer bc .diffMux .Unlock ()
@@ -3178,7 +3173,7 @@ func EnableBlockValidator(chainConfig *params.ChainConfig, engine consensus.Engi
31783173 }
31793174}
31803175
3181- func (bc * BlockChain ) GetRootByDiffHash (blockNumber uint64 , blockHash common.Hash , diffHash common.Hash ) * VerifyResult {
3176+ func (bc * BlockChain ) GetVerifyResult (blockNumber uint64 , blockHash common.Hash , diffHash common.Hash ) * VerifyResult {
31823177 var res VerifyResult
31833178 res .BlockNumber = blockNumber
31843179 res .BlockHash = blockHash
0 commit comments