diff --git a/core/blockchain.go b/core/blockchain.go index a11d08b05d..a6f20cf6b7 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -521,6 +521,15 @@ func (bc *BlockChain) cacheDiffLayer(diffLayer *types.DiffLayer, diffLayerCh cha sort.SliceStable(diffLayer.Storages, func(i, j int) bool { return diffLayer.Storages[i].Account.Hex() < diffLayer.Storages[j].Account.Hex() }) + for _, storage := range diffLayer.Storages { + // Sort keys and vals by key. + sort.SliceStable(storage.Keys, func(i, j int) bool { + return storage.Keys[i] < storage.Keys[j] + }) + sort.SliceStable(storage.Vals, func(i, j int) bool { + return storage.Keys[i] < storage.Keys[j] + }) + } if bc.diffLayerCache.Len() >= diffLayerCacheLimit { bc.diffLayerCache.RemoveOldest() diff --git a/core/state/statedb.go b/core/state/statedb.go index 3179a2c17c..8aad0689df 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1603,12 +1603,8 @@ func (s *StateDB) SnapToDiffLayer() ([]common.Address, []types.DiffAccount, []ty for accountHash, storage := range s.snapStorage { keys := make([]string, 0, len(storage)) values := make([][]byte, 0, len(storage)) - for k := range storage { + for k, v := range storage { keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - v := storage[k] values = append(values, v) } storages = append(storages, types.DiffStorage{