Skip to content

Commit 4001f37

Browse files
committed
fix sorting difflayer.storage
1 parent e93cced commit 4001f37

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

core/blockchain.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,9 @@ func (bc *BlockChain) cacheDiffLayer(diffLayer *types.DiffLayer, diffLayerCh cha
521521
sort.SliceStable(diffLayer.Storages, func(i, j int) bool {
522522
return diffLayer.Storages[i].Account.Hex() < diffLayer.Storages[j].Account.Hex()
523523
})
524-
for _, storage := range diffLayer.Storages {
524+
for index := range diffLayer.Storages {
525525
// Sort keys and vals by key.
526-
sort.SliceStable(storage.Keys, func(i, j int) bool {
527-
return storage.Keys[i] < storage.Keys[j]
528-
})
529-
sort.SliceStable(storage.Vals, func(i, j int) bool {
530-
return storage.Keys[i] < storage.Keys[j]
531-
})
526+
sort.Sort(&diffLayer.Storages[index])
532527
}
533528

534529
if bc.diffLayerCache.Len() >= diffLayerCacheLimit {

core/types/block.go

+7
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,13 @@ type DiffStorage struct {
480480
Vals [][]byte
481481
}
482482

483+
func (storage *DiffStorage) Len() int { return len(storage.Keys) }
484+
func (storage *DiffStorage) Swap(i, j int) {
485+
storage.Keys[i], storage.Keys[j] = storage.Keys[j], storage.Keys[i]
486+
storage.Vals[i], storage.Vals[j] = storage.Vals[j], storage.Vals[i]
487+
}
488+
func (storage *DiffStorage) Less(i, j int) bool { return storage.Keys[i] < storage.Keys[j] }
489+
483490
type DiffAccountsInTx struct {
484491
TxHash common.Hash
485492
Accounts map[common.Address]*big.Int

0 commit comments

Comments
 (0)