nitpicking change

This commit is contained in:
maskpp 2024-04-25 22:50:43 +08:00
parent a0282fc94f
commit 155150b8fb
3 changed files with 13 additions and 15 deletions

View file

@ -145,8 +145,8 @@ func (t *tester) randAccount() (common.Address, []byte) {
func (t *tester) generateStorage(ctx *genctx, addr common.Address) common.Hash { func (t *tester) generateStorage(ctx *genctx, addr common.Address) common.Hash {
var ( var (
addrHash = crypto.Keccak256Hash(addr.Bytes()) addrHash = crypto.Keccak256Hash(addr.Bytes())
storage = make(map[common.Hash][]byte) storage = make(map[common.Hash][]byte, 10)
origin = make(map[common.Hash][]byte) origin = make(map[common.Hash][]byte, 10)
) )
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
v, _ := rlp.EncodeToBytes(common.TrimLeftZeroes(testrand.Bytes(32))) v, _ := rlp.EncodeToBytes(common.TrimLeftZeroes(testrand.Bytes(32)))
@ -195,8 +195,8 @@ func (t *tester) mutateStorage(ctx *genctx, addr common.Address, root common.Has
func (t *tester) clearStorage(ctx *genctx, addr common.Address, root common.Hash) common.Hash { func (t *tester) clearStorage(ctx *genctx, addr common.Address, root common.Hash) common.Hash {
var ( var (
addrHash = crypto.Keccak256Hash(addr.Bytes()) addrHash = crypto.Keccak256Hash(addr.Bytes())
storage = make(map[common.Hash][]byte) storage = make(map[common.Hash][]byte, len(t.storages[addrHash]))
origin = make(map[common.Hash][]byte) origin = make(map[common.Hash][]byte, len(t.storages[addrHash]))
) )
for hash, val := range t.storages[addrHash] { for hash, val := range t.storages[addrHash] {
origin[hash] = val origin[hash] = val

View file

@ -62,8 +62,7 @@ func benchmarkSearch(b *testing.B, depth int, total int) {
) )
// First, we set up 128 diff layers, with 3K items each // First, we set up 128 diff layers, with 3K items each
fill := func(parent layer, index int) *diffLayer { fill := func(parent layer, index int) *diffLayer {
nodes := make(map[common.Hash]map[string]*trienode.Node) nodes := map[common.Hash]map[string]*trienode.Node{common.Hash{}: make(map[string]*trienode.Node, 3000)}
nodes[common.Hash{}] = make(map[string]*trienode.Node)
for i := 0; i < 3000; i++ { for i := 0; i < 3000; i++ {
var ( var (
path = testrand.Bytes(32) path = testrand.Bytes(32)
@ -108,8 +107,7 @@ func benchmarkSearch(b *testing.B, depth int, total int) {
func BenchmarkPersist(b *testing.B) { func BenchmarkPersist(b *testing.B) {
// First, we set up 128 diff layers, with 3K items each // First, we set up 128 diff layers, with 3K items each
fill := func(parent layer) *diffLayer { fill := func(parent layer) *diffLayer {
nodes := make(map[common.Hash]map[string]*trienode.Node) nodes := map[common.Hash]map[string]*trienode.Node{common.Hash{}: make(map[string]*trienode.Node, 3000)}
nodes[common.Hash{}] = make(map[string]*trienode.Node)
for i := 0; i < 3000; i++ { for i := 0; i < 3000; i++ {
var ( var (
path = testrand.Bytes(32) path = testrand.Bytes(32)
@ -146,8 +144,7 @@ func BenchmarkJournal(b *testing.B) {
// First, we set up 128 diff layers, with 3K items each // First, we set up 128 diff layers, with 3K items each
fill := func(parent layer) *diffLayer { fill := func(parent layer) *diffLayer {
nodes := make(map[common.Hash]map[string]*trienode.Node) nodes := map[common.Hash]map[string]*trienode.Node{common.Hash{}: make(map[string]*trienode.Node, 3000)}
nodes[common.Hash{}] = make(map[string]*trienode.Node)
for i := 0; i < 3000; i++ { for i := 0; i < 3000; i++ {
var ( var (
path = testrand.Bytes(32) path = testrand.Bytes(32)

View file

@ -34,8 +34,8 @@ import (
// randomStateSet generates a random state change set. // randomStateSet generates a random state change set.
func randomStateSet(n int) *triestate.Set { func randomStateSet(n int) *triestate.Set {
var ( var (
accounts = make(map[common.Address][]byte) accounts = make(map[common.Address][]byte, n)
storages = make(map[common.Address]map[common.Hash][]byte) storages = make(map[common.Address]map[common.Hash][]byte, n)
) )
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
addr := testrand.Address() addr := testrand.Address()
@ -154,8 +154,8 @@ func TestTruncateHeadHistory(t *testing.T) {
func TestTruncateTailHistory(t *testing.T) { func TestTruncateTailHistory(t *testing.T) {
var ( var (
roots []common.Hash
hs = makeHistories(10) hs = makeHistories(10)
roots = make([]common.Hash, 0, len(hs))
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
freezer, _ = openFreezer(t.TempDir(), false) freezer, _ = openFreezer(t.TempDir(), false)
) )
@ -197,12 +197,11 @@ func TestTruncateTailHistories(t *testing.T) {
} }
for i, c := range cases { for i, c := range cases {
var ( var (
roots []common.Hash
hs = makeHistories(10) hs = makeHistories(10)
roots = make([]common.Hash, 0, len(hs))
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
freezer, _ = openFreezer(t.TempDir()+fmt.Sprintf("%d", i), false) freezer, _ = openFreezer(t.TempDir()+fmt.Sprintf("%d", i), false)
) )
defer freezer.Close()
for i := 0; i < len(hs); i++ { for i := 0; i < len(hs); i++ {
accountData, storageData, accountIndex, storageIndex := hs[i].encode() accountData, storageData, accountIndex, storageIndex := hs[i].encode()
@ -221,6 +220,8 @@ func TestTruncateTailHistories(t *testing.T) {
checkHistoriesInRange(t, db, freezer, uint64(1), c.maxPruned, roots[:tail], false) checkHistoriesInRange(t, db, freezer, uint64(1), c.maxPruned, roots[:tail], false)
checkHistoriesInRange(t, db, freezer, c.minUnpruned, uint64(10), roots[tail:], true) checkHistoriesInRange(t, db, freezer, c.minUnpruned, uint64(10), roots[tail:], true)
} }
freezer.Close()
} }
} }