Skip to content

Commit

Permalink
triedb/pathdb: remove destruct
Browse files Browse the repository at this point in the history
  • Loading branch information
rjl493456442 committed Nov 18, 2024
1 parent 03c9a28 commit 42975b2
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 410 deletions.
2 changes: 1 addition & 1 deletion triedb/pathdb/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newBuffer(limit int, nodes *nodeSet, states *stateSet, layers uint64) *buff
nodes = newNodeSet(nil)
}
if states == nil {
states = newStates(nil, nil, nil)
states = newStates(nil, nil)
}
return &buffer{
layers: layers,
Expand Down
13 changes: 1 addition & 12 deletions triedb/pathdb/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,7 @@ func (t *tester) generate(parent common.Hash) (common.Hash, *trienode.MergedNode
delete(t.storages, addrHash)
}
}
var (
accounts = make(map[common.Hash][]byte)
destructs = make(map[common.Hash]struct{})
)
for addrHash, data := range ctx.accounts {
if len(data) == 0 {
destructs[addrHash] = struct{}{}
} else {
accounts[addrHash] = data
}
}
return root, ctx.nodes, NewStateSetWithOrigin(destructs, accounts, ctx.storages, ctx.accountOrigin, ctx.storageOrigin)
return root, ctx.nodes, NewStateSetWithOrigin(ctx.accounts, ctx.storages, ctx.accountOrigin, ctx.storageOrigin)
}

// lastHash returns the latest root hash, or empty if nothing is cached.
Expand Down
8 changes: 4 additions & 4 deletions triedb/pathdb/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func (dl *diffLayer) account(hash common.Hash, depth int) ([]byte, error) {
dirtyStateReadMeter.Mark(int64(len(blob)))

if len(blob) == 0 {
stateAccountMissMeter.Mark(1)
stateAccountInexMeter.Mark(1)
} else {
stateAccountHitMeter.Mark(1)
stateAccountExistMeter.Mark(1)
}
return blob, nil
}
Expand All @@ -139,9 +139,9 @@ func (dl *diffLayer) storage(accountHash, storageHash common.Hash, depth int) ([
dirtyStateReadMeter.Mark(int64(len(blob)))

if len(blob) == 0 {
stateStorageMissMeter.Mark(1)
stateStorageInexMeter.Mark(1)
} else {
stateStorageHitMeter.Mark(1)
stateStorageExistMeter.Mark(1)
}
return blob, nil
}
Expand Down
6 changes: 3 additions & 3 deletions triedb/pathdb/difflayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func benchmarkSearch(b *testing.B, depth int, total int) {
nblob = common.CopyBytes(blob)
}
}
return newDiffLayer(parent, common.Hash{}, 0, 0, newNodeSet(nodes), NewStateSetWithOrigin(nil, nil, nil, nil, nil))
return newDiffLayer(parent, common.Hash{}, 0, 0, newNodeSet(nodes), NewStateSetWithOrigin(nil, nil, nil, nil))
}
var layer layer
layer = emptyLayer()
Expand Down Expand Up @@ -118,7 +118,7 @@ func BenchmarkPersist(b *testing.B) {
)
nodes[common.Hash{}][string(path)] = node
}
return newDiffLayer(parent, common.Hash{}, 0, 0, newNodeSet(nodes), NewStateSetWithOrigin(nil, nil, nil, nil, nil))
return newDiffLayer(parent, common.Hash{}, 0, 0, newNodeSet(nodes), NewStateSetWithOrigin(nil, nil, nil, nil))
}
for i := 0; i < b.N; i++ {
b.StopTimer()
Expand Down Expand Up @@ -156,7 +156,7 @@ func BenchmarkJournal(b *testing.B) {
)
nodes[common.Hash{}][string(path)] = node
}
return newDiffLayer(parent, common.Hash{}, 0, 0, newNodeSet(nodes), NewStateSetWithOrigin(nil, nil, nil, nil, nil))
return newDiffLayer(parent, common.Hash{}, 0, 0, newNodeSet(nodes), NewStateSetWithOrigin(nil, nil, nil, nil))
}
var layer layer
layer = emptyLayer()
Expand Down
8 changes: 4 additions & 4 deletions triedb/pathdb/disklayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ func (dl *diskLayer) account(hash common.Hash, depth int) ([]byte, error) {
dirtyStateHitDepthHist.Update(int64(depth))

if len(blob) == 0 {
stateAccountMissMeter.Mark(1)
stateAccountInexMeter.Mark(1)
} else {
stateAccountHitMeter.Mark(1)
stateAccountExistMeter.Mark(1)
}
return blob, nil
}
Expand Down Expand Up @@ -198,9 +198,9 @@ func (dl *diskLayer) storage(accountHash, storageHash common.Hash, depth int) ([
dirtyStateHitDepthHist.Update(int64(depth))

if len(blob) == 0 {
stateStorageMissMeter.Mark(1)
stateStorageInexMeter.Mark(1)
} else {
stateStorageHitMeter.Mark(1)
stateStorageExistMeter.Mark(1)
}
return blob, nil
}
Expand Down
18 changes: 9 additions & 9 deletions triedb/pathdb/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ var (
cleanNodeReadMeter = metrics.NewRegisteredMeter("pathdb/clean/node/read", nil)
cleanNodeWriteMeter = metrics.NewRegisteredMeter("pathdb/clean/node/write", nil)

stateAccountMissMeter = metrics.NewRegisteredMeter("pathdb/state/account/miss/total", nil)
stateAccountHitMeter = metrics.NewRegisteredMeter("pathdb/state/account/hit/total", nil)
stateStorageMissMeter = metrics.NewRegisteredMeter("pathdb/state/storage/miss/total", nil)
stateStorageHitMeter = metrics.NewRegisteredMeter("pathdb/state/storage/hit/total", nil)

dirtyNodeHitMeter = metrics.NewRegisteredMeter("pathdb/dirty/node/hit", nil)
dirtyNodeMissMeter = metrics.NewRegisteredMeter("pathdb/dirty/node/miss", nil)
dirtyNodeReadMeter = metrics.NewRegisteredMeter("pathdb/dirty/node/read", nil)
dirtyNodeWriteMeter = metrics.NewRegisteredMeter("pathdb/dirty/node/write", nil)
dirtyNodeHitDepthHist = metrics.NewRegisteredHistogram("pathdb/dirty/node/depth", nil, metrics.NewExpDecaySample(1028, 0.015))

stateAccountInexMeter = metrics.NewRegisteredMeter("pathdb/state/account/inex/total", nil)
stateStorageInexMeter = metrics.NewRegisteredMeter("pathdb/state/storage/inex/total", nil)
stateAccountExistMeter = metrics.NewRegisteredMeter("pathdb/state/account/exist/total", nil)
stateStorageExistMeter = metrics.NewRegisteredMeter("pathdb/state/storage/exist/total", nil)

dirtyStateHitMeter = metrics.NewRegisteredMeter("pathdb/dirty/state/hit", nil)
dirtyStateMissMeter = metrics.NewRegisteredMeter("pathdb/dirty/state/miss", nil)
dirtyStateReadMeter = metrics.NewRegisteredMeter("pathdb/dirty/state/read", nil)
dirtyStateWriteMeter = metrics.NewRegisteredMeter("pathdb/dirty/state/write", nil)
dirtyStateHitDepthHist = metrics.NewRegisteredHistogram("pathdb/dirty/state/depth", nil, metrics.NewExpDecaySample(1028, 0.015))

cleanFalseMeter = metrics.NewRegisteredMeter("pathdb/clean/false", nil)
dirtyFalseMeter = metrics.NewRegisteredMeter("pathdb/dirty/false", nil)
diskFalseMeter = metrics.NewRegisteredMeter("pathdb/disk/false", nil)
diffFalseMeter = metrics.NewRegisteredMeter("pathdb/diff/false", nil)
nodeCleanFalseMeter = metrics.NewRegisteredMeter("pathdb/clean/false", nil)
nodeDirtyFalseMeter = metrics.NewRegisteredMeter("pathdb/dirty/false", nil)
nodeDiskFalseMeter = metrics.NewRegisteredMeter("pathdb/disk/false", nil)
nodeDiffFalseMeter = metrics.NewRegisteredMeter("pathdb/diff/false", nil)

commitTimeTimer = metrics.NewRegisteredTimer("pathdb/commit/time", nil)
commitNodesMeter = metrics.NewRegisteredMeter("pathdb/commit/nodes", nil)
Expand Down
8 changes: 4 additions & 4 deletions triedb/pathdb/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ func (r *reader) Node(owner common.Hash, path []byte, hash common.Hash) ([]byte,
// is not found.
switch loc.loc {
case locCleanCache:
cleanFalseMeter.Mark(1)
nodeCleanFalseMeter.Mark(1)
case locDirtyCache:
dirtyFalseMeter.Mark(1)
nodeDirtyFalseMeter.Mark(1)
case locDiffLayer:
diffFalseMeter.Mark(1)
nodeDiffFalseMeter.Mark(1)
case locDiskLayer:
diskFalseMeter.Mark(1)
nodeDiskFalseMeter.Mark(1)
}
blobHex := "nil"
if len(blob) > 0 {
Expand Down
Loading

0 comments on commit 42975b2

Please sign in to comment.