From f027818e6050153697be49fed22536df9661f40b Mon Sep 17 00:00:00 2001 From: cryyl <1226241521@qq.com> Date: Thu, 5 May 2022 19:10:52 +0800 Subject: [PATCH] fix to resolve comments Signed-off-by: cryyl <1226241521@qq.com> --- core/blockchain.go | 9 +++++++++ core/state/statedb.go | 6 +----- 2 files changed, 10 insertions(+), 5 deletions(-) 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{