core: do not copy key/value results got from MemCachedStore.Seek

They are already copied inside the MemCachedStore.Seek, so that
persistent storage  can't change them anymore.
This commit is contained in:
Anna Shaleva 2021-09-24 18:44:42 +03:00
parent 72726d46d3
commit f2ac07a3c0
3 changed files with 10 additions and 18 deletions

View file

@ -490,9 +490,8 @@ func (bc *Blockchain) jumpToStateInternal(p uint32, stage stateJumpStage) error
// Firstly, remove all old genesis-related items.
b := bc.dao.Store.Batch()
bc.dao.Store.Seek([]byte{byte(storage.STStorage)}, func(k, _ []byte) {
// Must copy here, #1468.
key := slice.Copy(k)
b.Delete(key)
// #1468, but don't need to copy here, because it is done by Store.
b.Delete(k)
})
b.Put(jumpStageKey, []byte{byte(oldStorageItemsRemoved)})
err := bc.dao.Store.PutBatch(b)
@ -509,14 +508,12 @@ func (bc *Blockchain) jumpToStateInternal(p uint32, stage stateJumpStage) error
if count >= maxStorageBatchSize {
return
}
// Must copy here, #1468.
oldKey := slice.Copy(k)
b.Delete(oldKey)
// #1468, but don't need to copy here, because it is done by Store.
b.Delete(k)
key := make([]byte, len(k))
key[0] = byte(storage.STStorage)
copy(key[1:], k[1:])
value := slice.Copy(v)
b.Put(key, value)
b.Put(key, slice.Copy(v))
count += 2
})
if count > 0 {

View file

@ -16,7 +16,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
)
// HasTransaction errors.
@ -324,12 +323,10 @@ func (dao *Simple) GetStorageItemsWithPrefix(id int32, prefix []byte) ([]state.S
saveToArr := func(k, v []byte) {
// Cut prefix and hash.
// Must copy here, #1468.
key := slice.Copy(k)
val := slice.Copy(v)
// #1468, but don't need to copy here, because it is done by Store.
siArr = append(siArr, state.StorageItemWithKey{
Key: key,
Item: state.StorageItem(val),
Key: k,
Item: state.StorageItem(v),
})
}
dao.Seek(id, prefix, saveToArr)

View file

@ -13,7 +13,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/util/slice"
"go.uber.org/atomic"
"go.uber.org/zap"
)
@ -147,9 +146,8 @@ func (s *Module) CleanStorage() error {
//
b := s.Store.Batch()
s.Store.Seek([]byte{byte(storage.DataMPT)}, func(k, _ []byte) {
// Must copy here, #1468.
key := slice.Copy(k)
b.Delete(key)
// #1468, but don't need to copy here, because it is done by Store.
b.Delete(k)
})
err = s.Store.PutBatch(b)
if err != nil {