From ca8c82edce93a1ef862a6938379d91cee963035b Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Wed, 20 Aug 2025 15:48:36 +0800 Subject: [PATCH] core, trie: polish --- core/stateless/database.go | 1 - core/stateless/stats.go | 8 ++++---- trie/trie.go | 10 ++-------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/core/stateless/database.go b/core/stateless/database.go index b2d3efb0b1..f54c123dda 100644 --- a/core/stateless/database.go +++ b/core/stateless/database.go @@ -63,6 +63,5 @@ func (w *Witness) MakeHashDB() ethdb.Database { rawdb.WriteLegacyTrieNode(memdb, common.BytesToHash(hash), blob) } - return memdb } diff --git a/core/stateless/stats.go b/core/stateless/stats.go index 088e06c9bb..46022ac74b 100644 --- a/core/stateless/stats.go +++ b/core/stateless/stats.go @@ -46,8 +46,8 @@ func newDepthStats() *depthStats { return &depthStats{minDepth: -1} } -// Add records a new depth sample. -func (d *depthStats) Add(n int64) { +// add records a new depth sample. +func (d *depthStats) add(n int64) { if n < 0 { return } @@ -92,11 +92,11 @@ func NewWitnessStats() *WitnessStats { func (s *WitnessStats) Add(nodes map[string][]byte, owner common.Hash) { if owner == (common.Hash{}) { for path := range maps.Keys(nodes) { - s.accountTrie.Add(int64(len(path))) + s.accountTrie.add(int64(len(path))) } } else { for path := range maps.Keys(nodes) { - s.storageTrie.Add(int64(len(path))) + s.storageTrie.add(int64(len(path))) } } } diff --git a/trie/trie.go b/trie/trie.go index fe8b5837d4..874bd4f510 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -21,6 +21,7 @@ import ( "bytes" "errors" "fmt" + "slices" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -517,7 +518,7 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) { // always creates a new slice) instead of append to // avoid modifying n.Key since it might be shared with // other nodes. - return true, &shortNode{concat(n.Key, child.Key...), child.Val, t.newFlag()}, nil + return true, &shortNode{slices.Concat(n.Key, child.Key...), child.Val, t.newFlag()}, nil default: return true, &shortNode{n.Key, child, t.newFlag()}, nil } @@ -612,13 +613,6 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) { } } -func concat(s1 []byte, s2 ...byte) []byte { - r := make([]byte, len(s1)+len(s2)) - copy(r, s1) - copy(r[len(s1):], s2) - return r -} - // copyNode deep-copies the supplied node along with its children recursively. func copyNode(n node) node { switch n := (n).(type) {