From 4397c712ac9afd82ce6eca239c35d624f0afee8e Mon Sep 17 00:00:00 2001 From: Hteev Oli Date: Tue, 29 Oct 2024 12:34:17 +0800 Subject: [PATCH] core, eth, accounts, trie: use slices.Concat --- accounts/manager.go | 3 ++- core/bloombits/matcher.go | 5 +++-- core/forkid/forkid.go | 2 +- core/rawdb/schema.go | 11 ++++++----- eth/downloader/downloader.go | 3 ++- trie/sync.go | 5 +++-- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/accounts/manager.go b/accounts/manager.go index cbe4f7c79d..28593c55b4 100644 --- a/accounts/manager.go +++ b/accounts/manager.go @@ -18,6 +18,7 @@ package accounts import ( "reflect" + "slices" "sort" "sync" @@ -255,7 +256,7 @@ func merge(slice []Wallet, wallets ...Wallet) []Wallet { slice = append(slice, wallet) continue } - slice = append(slice[:n], append([]Wallet{wallet}, slice[n:]...)...) + slice = slices.Concat(slice[:n], []Wallet{wallet}, slice[n:]) } return slice } diff --git a/core/bloombits/matcher.go b/core/bloombits/matcher.go index 486581fe23..98b8102803 100644 --- a/core/bloombits/matcher.go +++ b/core/bloombits/matcher.go @@ -21,6 +21,7 @@ import ( "context" "errors" "math" + "slices" "sort" "sync" "sync/atomic" @@ -417,7 +418,7 @@ func (m *Matcher) distributor(dist chan *request, session *MatcherSession) { // New retrieval request arrived to be distributed to some fetcher process queue := requests[req.bit] index := sort.Search(len(queue), func(i int) bool { return queue[i] >= req.section }) - requests[req.bit] = append(queue[:index], append([]uint64{req.section}, queue[index:]...)...) + requests[req.bit] = slices.Concat(queue[:index], []uint64{req.section}, queue[index:]) // If it's a new bit and we have waiting fetchers, allocate to them if len(queue) == 0 { @@ -485,7 +486,7 @@ func (m *Matcher) distributor(dist chan *request, session *MatcherSession) { queue := requests[result.Bit] for _, section := range missing { index := sort.Search(len(queue), func(i int) bool { return queue[i] >= section }) - queue = append(queue[:index], append([]uint64{section}, queue[index:]...)...) + queue = slices.Concat(queue[:index], []uint64{section}, queue[index:]) } requests[result.Bit] = queue diff --git a/core/forkid/forkid.go b/core/forkid/forkid.go index 4db366da82..1bdcde45b9 100644 --- a/core/forkid/forkid.go +++ b/core/forkid/forkid.go @@ -135,7 +135,7 @@ func newFilter(config *params.ChainConfig, genesis *types.Block, headfn func() ( // Calculate the all the valid fork hash and fork next combos var ( forksByBlock, forksByTime = gatherForks(config, genesis.Time()) - forks = append(append([]uint64{}, forksByBlock...), forksByTime...) + forks = slices.Concat(forksByBlock, forksByTime) sums = make([][4]byte, len(forks)+1) // 0th is the genesis ) hash := crc32.ChecksumIEEE(genesis.Hash().Bytes()) diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index 04b5d0d6d2..295d0d0a83 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -20,6 +20,7 @@ package rawdb import ( "bytes" "encoding/binary" + "slices" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -171,7 +172,7 @@ func headerKeyPrefix(number uint64) []byte { // headerKey = headerPrefix + num (uint64 big endian) + hash func headerKey(number uint64, hash common.Hash) []byte { - return append(append(headerPrefix, encodeBlockNumber(number)...), hash.Bytes()...) + return slices.Concat(headerPrefix, encodeBlockNumber(number), hash.Bytes()) } // headerTDKey = headerPrefix + num (uint64 big endian) + hash + headerTDSuffix @@ -181,7 +182,7 @@ func headerTDKey(number uint64, hash common.Hash) []byte { // headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix func headerHashKey(number uint64) []byte { - return append(append(headerPrefix, encodeBlockNumber(number)...), headerHashSuffix...) + return slices.Concat(headerPrefix, encodeBlockNumber(number), headerHashSuffix) } // headerNumberKey = headerNumberPrefix + hash @@ -191,12 +192,12 @@ func headerNumberKey(hash common.Hash) []byte { // blockBodyKey = blockBodyPrefix + num (uint64 big endian) + hash func blockBodyKey(number uint64, hash common.Hash) []byte { - return append(append(blockBodyPrefix, encodeBlockNumber(number)...), hash.Bytes()...) + return slices.Concat(blockBodyPrefix, encodeBlockNumber(number), hash.Bytes()) } // blockReceiptsKey = blockReceiptsPrefix + num (uint64 big endian) + hash func blockReceiptsKey(number uint64, hash common.Hash) []byte { - return append(append(blockReceiptsPrefix, encodeBlockNumber(number)...), hash.Bytes()...) + return slices.Concat(blockReceiptsPrefix, encodeBlockNumber(number), hash.Bytes()) } // txLookupKey = txLookupPrefix + hash @@ -225,7 +226,7 @@ func storageSnapshotsKey(accountHash common.Hash) []byte { // bloomBitsKey = bloomBitsPrefix + bit (uint16 big endian) + section (uint64 big endian) + hash func bloomBitsKey(bit uint, section uint64, hash common.Hash) []byte { - key := append(append(bloomBitsPrefix, make([]byte, 10)...), hash.Bytes()...) + key := slices.Concat(bloomBitsPrefix, make([]byte, 10), hash.Bytes()) binary.BigEndian.PutUint16(key[1:], uint16(bit)) binary.BigEndian.PutUint64(key[3:], section) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index fadb68ef03..cfa04303b4 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "math/big" + "slices" "sync" "sync/atomic" "time" @@ -872,7 +873,7 @@ func (d *Downloader) processSnapSyncContent() error { } } } else { // results already piled up, consume before handling pivot move - results = append(append([]*fetchResult{oldPivot}, oldTail...), results...) + results = slices.Concat([]*fetchResult{oldPivot}, oldTail, results) } // Split around the pivot block and process the two sides via snap/full sync if !d.committed.Load() { diff --git a/trie/sync.go b/trie/sync.go index 3b7caae5b1..a046413f2d 100644 --- a/trie/sync.go +++ b/trie/sync.go @@ -19,6 +19,7 @@ package trie import ( "errors" "fmt" + "slices" "sync" "github.com/ethereum/go-ethereum/common" @@ -553,7 +554,7 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) { } children = []childNode{{ node: node.Val, - path: append(append([]byte(nil), req.path...), key...), + path: slices.Concat(req.path, key), }} // Mark all internal nodes between shortNode and its **in disk** // child as invalid. This is essential in the case of path mode @@ -595,7 +596,7 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) { if node.Children[i] != nil { children = append(children, childNode{ node: node.Children[i], - path: append(append([]byte(nil), req.path...), byte(i)), + path: slices.Concat(req.path, []byte{i}), }) } }