Unverified Commit 2f4dbb4f authored by Marius van der Wijden's avatar Marius van der Wijden Committed by GitHub

core/rawdb: allocate database keys with explicit size to avoid slice growth (#27772)

parent 4abc4123
...@@ -195,7 +195,11 @@ func accountSnapshotKey(hash common.Hash) []byte { ...@@ -195,7 +195,11 @@ func accountSnapshotKey(hash common.Hash) []byte {
// storageSnapshotKey = SnapshotStoragePrefix + account hash + storage hash // storageSnapshotKey = SnapshotStoragePrefix + account hash + storage hash
func storageSnapshotKey(accountHash, storageHash common.Hash) []byte { func storageSnapshotKey(accountHash, storageHash common.Hash) []byte {
return append(append(SnapshotStoragePrefix, accountHash.Bytes()...), storageHash.Bytes()...) buf := make([]byte, len(SnapshotStoragePrefix)+common.HashLength+common.HashLength)
n := copy(buf, SnapshotStoragePrefix)
n += copy(buf[n:], accountHash.Bytes())
copy(buf[n:], storageHash.Bytes())
return buf
} }
// storageSnapshotsKey = SnapshotStoragePrefix + account hash + storage hash // storageSnapshotsKey = SnapshotStoragePrefix + account hash + storage hash
...@@ -259,7 +263,11 @@ func accountTrieNodeKey(path []byte) []byte { ...@@ -259,7 +263,11 @@ func accountTrieNodeKey(path []byte) []byte {
// storageTrieNodeKey = trieNodeStoragePrefix + accountHash + nodePath. // storageTrieNodeKey = trieNodeStoragePrefix + accountHash + nodePath.
func storageTrieNodeKey(accountHash common.Hash, path []byte) []byte { func storageTrieNodeKey(accountHash common.Hash, path []byte) []byte {
return append(append(trieNodeStoragePrefix, accountHash.Bytes()...), path...) buf := make([]byte, len(trieNodeStoragePrefix)+common.HashLength+len(path))
n := copy(buf, trieNodeStoragePrefix)
n += copy(buf[n:], accountHash.Bytes())
copy(buf[n:], path)
return buf
} }
// IsLegacyTrieNode reports whether a provided database entry is a legacy trie // IsLegacyTrieNode reports whether a provided database entry is a legacy trie
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment