mpt: simplify makeStorageKey() interface

This commit is contained in:
Roman Khimov 2022-01-27 14:25:11 +03:00
parent 9719191770
commit 2bc493a839
6 changed files with 11 additions and 11 deletions

View file

@ -274,7 +274,7 @@ func TestTrie_PutBatchHash(t *testing.T) {
}
tr1.Collapse(1)
tr2.Collapse(1)
key := makeStorageKey(tr1.root.(*BranchNode).Children[2].Hash().BytesBE())
key := makeStorageKey(tr1.root.(*BranchNode).Children[2].Hash())
require.NoError(t, tr1.Store.Delete(key))
require.NoError(t, tr2.Store.Delete(key))
testIncompletePut(t, ps, 1, tr1, tr2)

View file

@ -177,7 +177,7 @@ func (b *Billet) putIntoHash(curr *HashNode, path []byte, val Node) (Node, error
}
func (b *Billet) incrementRefAndStore(h util.Uint256, bs []byte) {
key := makeStorageKey(h.BytesBE())
key := makeStorageKey(h)
if b.refcountEnabled {
var (
err error
@ -325,7 +325,7 @@ func (b *Billet) tryCollapseBranch(curr *BranchNode) Node {
// GetFromStore returns MPT node from the storage.
func (b *Billet) GetFromStore(h util.Uint256) (Node, error) {
data, err := b.Store.Get(makeStorageKey(h.BytesBE()))
data, err := b.Store.Get(makeStorageKey(h))
if err != nil {
return nil, err
}

View file

@ -16,7 +16,7 @@ func TestBillet_RestoreHashNode(t *testing.T) {
_ = expectedRoot.Hash()
_ = tr.root.Hash()
require.Equal(t, expectedRoot, tr.root)
expectedBytes, err := tr.Store.Get(makeStorageKey(expectedNode.Hash().BytesBE()))
expectedBytes, err := tr.Store.Get(makeStorageKey(expectedNode.Hash()))
if expectedRefCount != 0 {
require.NoError(t, err)
require.Equal(t, expectedRefCount, binary.LittleEndian.Uint32(expectedBytes[len(expectedBytes)-4:]))

View file

@ -70,7 +70,7 @@ func VerifyProof(rh util.Uint256, key []byte, proofs [][]byte) ([]byte, bool) {
for i := range proofs {
h := hash.DoubleSha256(proofs[i])
// no errors in Put to memory store
_ = tr.Store.Put(makeStorageKey(h[:]), proofs[i])
_ = tr.Store.Put(makeStorageKey(h), proofs[i])
}
_, leaf, _, err := tr.getWithPath(tr.root, path, true)
if err != nil {

View file

@ -372,8 +372,8 @@ func (t *Trie) StateRoot() util.Uint256 {
return t.root.Hash()
}
func makeStorageKey(mptKey []byte) []byte {
return append([]byte{byte(storage.DataMPT)}, mptKey...)
func makeStorageKey(mptKey util.Uint256) []byte {
return append([]byte{byte(storage.DataMPT)}, mptKey[:]...)
}
// Flush puts every node in the trie except Hash ones to the storage.
@ -392,7 +392,7 @@ func (t *Trie) Flush() {
delete(t.refcount, h)
}
} else if node.refcount > 0 {
_ = t.Store.Put(makeStorageKey(h.BytesBE()), node.bytes)
_ = t.Store.Put(makeStorageKey(h), node.bytes)
}
node.refcount = 0
} else {
@ -407,7 +407,7 @@ func (t *Trie) updateRefCount(h util.Uint256) int32 {
panic("`updateRefCount` is called, but GC is disabled")
}
var data []byte
key := makeStorageKey(h.BytesBE())
key := makeStorageKey(h)
node := t.refcount[h]
cnt := node.initial
if cnt == 0 {
@ -466,7 +466,7 @@ func (t *Trie) removeRef(h util.Uint256, bs []byte) {
}
func (t *Trie) getFromStore(h util.Uint256) (Node, error) {
data, err := t.Store.Get(makeStorageKey(h.BytesBE()))
data, err := t.Store.Get(makeStorageKey(h))
if err != nil {
return nil, err
}

View file

@ -251,7 +251,7 @@ func (tr *Trie) putToStore(n Node) {
}
tr.updateRefCount(n.Hash())
} else {
_ = tr.Store.Put(makeStorageKey(n.Hash().BytesBE()), n.Bytes())
_ = tr.Store.Put(makeStorageKey(n.Hash()), n.Bytes())
}
}