@@ -28,9 +28,8 @@ import (
28
28
"sync/atomic"
29
29
"time"
30
30
31
- "golang.org/x/crypto/sha3"
32
-
33
31
lru "github.com/hashicorp/golang-lru"
32
+ "golang.org/x/crypto/sha3"
34
33
35
34
"github.com/ethereum/go-ethereum/common"
36
35
"github.com/ethereum/go-ethereum/common/mclock"
@@ -509,31 +508,27 @@ func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts) {
509
508
bc .receiptsCache .Add (hash , receipts )
510
509
}
511
510
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
+ })
527
524
528
525
if bc .diffLayerCache .Len () >= diffLayerCacheLimit {
529
526
bc .diffLayerCache .RemoveOldest ()
530
527
}
531
528
532
529
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
+
537
532
if bc .db .DiffStore () != nil {
538
533
// push to priority queue before persisting
539
534
bc .diffQueueBuffer <- diffLayer
@@ -1840,7 +1835,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
1840
1835
}
1841
1836
bc .diffLayerChanCache .Add (diffLayer .BlockHash , diffLayerCh )
1842
1837
1843
- go bc .cacheDiffLayer (diffLayer , false )
1838
+ go bc .cacheDiffLayer (diffLayer , diffLayerCh )
1844
1839
}
1845
1840
1846
1841
wg .Wait ()
@@ -2156,7 +2151,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
2156
2151
return it .index , err
2157
2152
}
2158
2153
if statedb .NoTrie () {
2159
- statedb .SetCurrentRoot (block .Root ())
2154
+ statedb .SetExpectedStateRoot (block .Root ())
2160
2155
}
2161
2156
bc .updateHighestVerifiedHeader (block .Header ())
2162
2157
@@ -2833,10 +2828,10 @@ func (bc *BlockChain) HandleDiffLayer(diffLayer *types.DiffLayer, pid string, fu
2833
2828
return nil
2834
2829
}
2835
2830
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 )
2839
2833
}
2834
+ diffHash := diffLayer .DiffHash .Load ().(common.Hash )
2840
2835
2841
2836
bc .diffMux .Lock ()
2842
2837
defer bc .diffMux .Unlock ()
@@ -3178,7 +3173,7 @@ func EnableBlockValidator(chainConfig *params.ChainConfig, engine consensus.Engi
3178
3173
}
3179
3174
}
3180
3175
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 {
3182
3177
var res VerifyResult
3183
3178
res .BlockNumber = blockNumber
3184
3179
res .BlockHash = blockHash
0 commit comments