Skip to content

Commit 42bf484

Browse files
authored
core/rawdb: enhance database key construction (#32431)
1 parent 7cc0137 commit 42bf484

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

core/rawdb/schema.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,48 @@ func accountHistoryIndexKey(addressHash common.Hash) []byte {
384384

385385
// storageHistoryIndexKey = StateHistoryStorageMetadataPrefix + addressHash + storageHash
386386
func storageHistoryIndexKey(addressHash common.Hash, storageHash common.Hash) []byte {
387-
return append(append(StateHistoryStorageMetadataPrefix, addressHash.Bytes()...), storageHash.Bytes()...)
387+
totalLen := len(StateHistoryStorageMetadataPrefix) + 2*common.HashLength
388+
out := make([]byte, totalLen)
389+
390+
off := 0
391+
off += copy(out[off:], StateHistoryStorageMetadataPrefix)
392+
off += copy(out[off:], addressHash.Bytes())
393+
copy(out[off:], storageHash.Bytes())
394+
395+
return out
388396
}
389397

390398
// accountHistoryIndexBlockKey = StateHistoryAccountBlockPrefix + addressHash + blockID
391399
func accountHistoryIndexBlockKey(addressHash common.Hash, blockID uint32) []byte {
392-
var buf [4]byte
393-
binary.BigEndian.PutUint32(buf[:], blockID)
394-
return append(append(StateHistoryAccountBlockPrefix, addressHash.Bytes()...), buf[:]...)
400+
var buf4 [4]byte
401+
binary.BigEndian.PutUint32(buf4[:], blockID)
402+
403+
totalLen := len(StateHistoryAccountBlockPrefix) + common.HashLength + 4
404+
out := make([]byte, totalLen)
405+
406+
off := 0
407+
off += copy(out[off:], StateHistoryAccountBlockPrefix)
408+
off += copy(out[off:], addressHash.Bytes())
409+
copy(out[off:], buf4[:])
410+
411+
return out
395412
}
396413

397414
// storageHistoryIndexBlockKey = StateHistoryStorageBlockPrefix + addressHash + storageHash + blockID
398415
func storageHistoryIndexBlockKey(addressHash common.Hash, storageHash common.Hash, blockID uint32) []byte {
399-
var buf [4]byte
400-
binary.BigEndian.PutUint32(buf[:], blockID)
401-
return append(append(append(StateHistoryStorageBlockPrefix, addressHash.Bytes()...), storageHash.Bytes()...), buf[:]...)
416+
var buf4 [4]byte
417+
binary.BigEndian.PutUint32(buf4[:], blockID)
418+
419+
totalLen := len(StateHistoryStorageBlockPrefix) + 2*common.HashLength + 4
420+
out := make([]byte, totalLen)
421+
422+
off := 0
423+
off += copy(out[off:], StateHistoryStorageBlockPrefix)
424+
off += copy(out[off:], addressHash.Bytes())
425+
off += copy(out[off:], storageHash.Bytes())
426+
copy(out[off:], buf4[:])
427+
428+
return out
402429
}
403430

404431
// transitionStateKey = transitionStatusKey + hash

0 commit comments

Comments
 (0)