Skip to content

Commit

Permalink
fix sorting difflayer.storage
Browse files Browse the repository at this point in the history
  • Loading branch information
dean65 committed May 5, 2022
1 parent e93cced commit 4001f37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 2 additions & 7 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,9 @@ 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 {
for index := 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]
})
sort.Sort(&diffLayer.Storages[index])
}

if bc.diffLayerCache.Len() >= diffLayerCacheLimit {
Expand Down
7 changes: 7 additions & 0 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ type DiffStorage struct {
Vals [][]byte
}

func (storage *DiffStorage) Len() int { return len(storage.Keys) }
func (storage *DiffStorage) Swap(i, j int) {
storage.Keys[i], storage.Keys[j] = storage.Keys[j], storage.Keys[i]
storage.Vals[i], storage.Vals[j] = storage.Vals[j], storage.Vals[i]
}
func (storage *DiffStorage) Less(i, j int) bool { return storage.Keys[i] < storage.Keys[j] }

type DiffAccountsInTx struct {
TxHash common.Hash
Accounts map[common.Address]*big.Int
Expand Down

0 comments on commit 4001f37

Please sign in to comment.