From 600da6909c411ce4130e3ceee7c1778b633f44bd Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 18 Feb 2022 14:35:17 +0300 Subject: [PATCH] storage: put uint32 into keys using in big endianness Which allows to iterate over the contents easily. --- pkg/core/blockchain.go | 2 +- pkg/core/dao/dao.go | 23 ++++------------------- pkg/core/storage/store.go | 2 +- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 00690e6be..751d916bf 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -46,7 +46,7 @@ import ( // Tuning parameters. const ( headerBatchCount = 2000 - version = "0.2.3" + version = "0.2.4" defaultInitialGAS = 52000000_00000000 defaultGCPeriod = 10000 diff --git a/pkg/core/dao/dao.go b/pkg/core/dao/dao.go index 37e8a8d6d..23ca3bb68 100644 --- a/pkg/core/dao/dao.go +++ b/pkg/core/dao/dao.go @@ -6,7 +6,6 @@ import ( "encoding/binary" "errors" iocore "io" - "sort" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/state" @@ -506,33 +505,19 @@ func (dao *Simple) GetStateSyncCurrentBlockHeight() (uint32, error) { // GetHeaderHashes returns a sorted list of header hashes retrieved from // the given underlying store. func (dao *Simple) GetHeaderHashes() ([]util.Uint256, error) { - hashMap := make(map[uint32][]util.Uint256) + var hashes = make([]util.Uint256, 0) + dao.Store.Seek(storage.SeekRange{ Prefix: storage.IXHeaderHashList.Bytes(), }, func(k, v []byte) bool { - storedCount := binary.LittleEndian.Uint32(k[1:]) - hashes, err := read2000Uint256Hashes(v) + newHashes, err := read2000Uint256Hashes(v) if err != nil { panic(err) } - hashMap[storedCount] = hashes + hashes = append(hashes, newHashes...) return true }) - var ( - hashes = make([]util.Uint256, 0, len(hashMap)) - sortedKeys = make([]uint32, 0, len(hashMap)) - ) - - for k := range hashMap { - sortedKeys = append(sortedKeys, k) - } - sort.Slice(sortedKeys, func(i, j int) bool { return sortedKeys[i] < sortedKeys[j] }) - - for _, key := range sortedKeys { - hashes = append(hashes[:key], hashMap[key]...) - } - return hashes, nil } diff --git a/pkg/core/storage/store.go b/pkg/core/storage/store.go index 8d4bfad9d..b6cfe80bf 100644 --- a/pkg/core/storage/store.go +++ b/pkg/core/storage/store.go @@ -125,7 +125,7 @@ func AppendPrefix(k KeyPrefix, b []byte) []byte { // AppendPrefixInt(SYSCurrentHeader, 10001) func AppendPrefixInt(k KeyPrefix, n int) []byte { b := make([]byte, 4) - binary.LittleEndian.PutUint32(b, uint32(n)) + binary.BigEndian.PutUint32(b, uint32(n)) return AppendPrefix(k, b) }