Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,19 @@ func accountHistoryIndexBlockKey(addressHash common.Hash, blockID uint32) []byte

// storageHistoryIndexBlockKey = StateHistoryStorageBlockPrefix + addressHash + storageHash + blockID
func storageHistoryIndexBlockKey(addressHash common.Hash, storageHash common.Hash, blockID uint32) []byte {
var buf [4]byte
binary.BigEndian.PutUint32(buf[:], blockID)
return append(append(append(StateHistoryStorageBlockPrefix, addressHash.Bytes()...), storageHash.Bytes()...), buf[:]...)
var buf4 [4]byte
binary.BigEndian.PutUint32(buf4[:], blockID)

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
Expand Down
22 changes: 22 additions & 0 deletions core/rawdb/schema_test.go
Original file line number Diff line number Diff line change
@@ -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