storage: drop AppendPrefix/AppendPrefixInt APIs

We're not using them anymore and they allocate.
This commit is contained in:
Roman Khimov 2022-02-18 14:59:59 +03:00
parent d2db58d748
commit 522229d731
3 changed files with 3 additions and 58 deletions

View file

@ -124,8 +124,10 @@ func TestAddBlock(t *testing.T) {
_, err = bc.persist(false) _, err = bc.persist(false)
require.NoError(t, err) require.NoError(t, err)
key := make([]byte, 1+util.Uint256Size)
key[0] = byte(storage.DataExecutable)
for _, block := range blocks { for _, block := range blocks {
key := storage.AppendPrefix(storage.DataExecutable, block.Hash().BytesBE()) copy(key[1:], block.Hash().BytesBE())
_, err := bc.dao.Store.Get(key) _, err := bc.dao.Store.Get(key)
require.NoErrorf(t, err, "block %s not persisted", block.Hash()) require.NoErrorf(t, err, "block %s not persisted", block.Hash())
} }

View file

@ -1,7 +1,6 @@
package storage package storage
import ( import (
"encoding/binary"
"errors" "errors"
"fmt" "fmt"
@ -112,23 +111,6 @@ func (k KeyPrefix) Bytes() []byte {
return []byte{byte(k)} return []byte{byte(k)}
} }
// AppendPrefix appends byteslice b to the given KeyPrefix.
// AppendKeyPrefix(SYSVersion, []byte{0x00, 0x01}).
func AppendPrefix(k KeyPrefix, b []byte) []byte {
dest := make([]byte, len(b)+1)
dest[0] = byte(k)
copy(dest[1:], b)
return dest
}
// AppendPrefixInt append int n to the given KeyPrefix.
// AppendPrefixInt(SYSCurrentHeader, 10001)
func AppendPrefixInt(k KeyPrefix, n int) []byte {
b := make([]byte, 4)
binary.BigEndian.PutUint32(b, uint32(n))
return AppendPrefix(k, b)
}
func seekRangeToPrefixes(sr SeekRange) *util.Range { func seekRangeToPrefixes(sr SeekRange) *util.Range {
var ( var (
rang *util.Range rang *util.Range

View file

@ -3,48 +3,9 @@ package storage
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var (
prefixes = []KeyPrefix{
DataExecutable,
DataMPT,
STStorage,
IXHeaderHashList,
SYSCurrentBlock,
SYSCurrentHeader,
SYSVersion,
}
expected = []uint8{
0x01,
0x03,
0x70,
0x80,
0xc0,
0xc1,
0xf0,
}
)
func TestAppendPrefix(t *testing.T) {
for i := 0; i < len(expected); i++ {
value := []byte{0x01, 0x02}
prefix := AppendPrefix(prefixes[i], value)
assert.Equal(t, KeyPrefix(expected[i]), KeyPrefix(prefix[0]))
}
}
func TestAppendPrefixInt(t *testing.T) {
for i := 0; i < len(expected); i++ {
value := 2000
prefix := AppendPrefixInt(prefixes[i], value)
assert.Equal(t, KeyPrefix(expected[i]), KeyPrefix(prefix[0]))
}
}
func TestBatchToOperations(t *testing.T) { func TestBatchToOperations(t *testing.T) {
b := &MemBatch{ b := &MemBatch{
Put: []KeyValueExists{ Put: []KeyValueExists{