mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
core: opt storageHistoryIndexBlockKey
This commit is contained in:
parent
3ff99ae52c
commit
c0f04bd2d9
2 changed files with 35 additions and 3 deletions
|
|
@ -396,9 +396,19 @@ func accountHistoryIndexBlockKey(addressHash common.Hash, blockID uint32) []byte
|
||||||
|
|
||||||
// storageHistoryIndexBlockKey = StateHistoryStorageBlockPrefix + addressHash + storageHash + blockID
|
// storageHistoryIndexBlockKey = StateHistoryStorageBlockPrefix + addressHash + storageHash + blockID
|
||||||
func storageHistoryIndexBlockKey(addressHash common.Hash, storageHash common.Hash, blockID uint32) []byte {
|
func storageHistoryIndexBlockKey(addressHash common.Hash, storageHash common.Hash, blockID uint32) []byte {
|
||||||
var buf [4]byte
|
var buf4 [4]byte
|
||||||
binary.BigEndian.PutUint32(buf[:], blockID)
|
binary.BigEndian.PutUint32(buf4[:], blockID)
|
||||||
return append(append(append(StateHistoryStorageBlockPrefix, addressHash.Bytes()...), storageHash.Bytes()...), buf[:]...)
|
|
||||||
|
totalLen := len(StateHistoryStorageBlockPrefix) + len(addressHash) + len(storageHash) + 4
|
||||||
|
out := make([]byte, totalLen)
|
||||||
|
|
||||||
|
off := 0
|
||||||
|
off += copy(out[off:], StateHistoryStorageBlockPrefix)
|
||||||
|
off += copy(out[off:], addressHash.Bytes())
|
||||||
|
off += copy(out[off:], storageHash.Bytes())
|
||||||
|
copy(out[off:], buf4[:])
|
||||||
|
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// transitionStateKey = transitionStatusKey + hash
|
// transitionStateKey = transitionStatusKey + hash
|
||||||
|
|
|
||||||
22
core/rawdb/schema_test.go
Normal file
22
core/rawdb/schema_test.go
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
package rawdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
var sink []byte
|
||||||
|
|
||||||
|
func BenchmarkStorageHistoryIndexBlockKey(b *testing.B) {
|
||||||
|
var h1, h2 common.Hash
|
||||||
|
for i := range h1 {
|
||||||
|
h1[i] = byte(rand.Intn(256))
|
||||||
|
h2[i] = byte(rand.Intn(256))
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
sink = storageHistoryIndexBlockKey(h1, h2, uint32(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue