Unverified Commit f58ebd96 authored by Jolly Zhao's avatar Jolly Zhao Committed by GitHub

all: use github.com/deckarep/golang-set/v2 (generic set) (#26159)

Co-authored-by: 's avatarFelix Lange <fjl@twurst.com>
parent 8c5ce110
...@@ -27,7 +27,7 @@ import ( ...@@ -27,7 +27,7 @@ import (
"sync" "sync"
"time" "time"
mapset "github.com/deckarep/golang-set" mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -79,7 +79,7 @@ func newAccountCache(keydir string) (*accountCache, chan struct{}) { ...@@ -79,7 +79,7 @@ func newAccountCache(keydir string) (*accountCache, chan struct{}) {
keydir: keydir, keydir: keydir,
byAddr: make(map[common.Address][]accounts.Account), byAddr: make(map[common.Address][]accounts.Account),
notify: make(chan struct{}, 1), notify: make(chan struct{}, 1),
fileC: fileCache{all: mapset.NewThreadUnsafeSet()}, fileC: fileCache{all: mapset.NewThreadUnsafeSet[string]()},
} }
ac.watcher = newWatcher(ac) ac.watcher = newWatcher(ac)
return ac, ac.notify return ac, ac.notify
...@@ -283,16 +283,15 @@ func (ac *accountCache) scanAccounts() error { ...@@ -283,16 +283,15 @@ func (ac *accountCache) scanAccounts() error {
// Process all the file diffs // Process all the file diffs
start := time.Now() start := time.Now()
for _, p := range creates.ToSlice() { for _, path := range creates.ToSlice() {
if a := readAccount(p.(string)); a != nil { if a := readAccount(path); a != nil {
ac.add(*a) ac.add(*a)
} }
} }
for _, p := range deletes.ToSlice() { for _, path := range deletes.ToSlice() {
ac.deleteByFile(p.(string)) ac.deleteByFile(path)
} }
for _, p := range updates.ToSlice() { for _, path := range updates.ToSlice() {
path := p.(string)
ac.deleteByFile(path) ac.deleteByFile(path)
if a := readAccount(path); a != nil { if a := readAccount(path); a != nil {
ac.add(*a) ac.add(*a)
......
...@@ -23,20 +23,20 @@ import ( ...@@ -23,20 +23,20 @@ import (
"sync" "sync"
"time" "time"
mapset "github.com/deckarep/golang-set" mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
// fileCache is a cache of files seen during scan of keystore. // fileCache is a cache of files seen during scan of keystore.
type fileCache struct { type fileCache struct {
all mapset.Set // Set of all files from the keystore folder all mapset.Set[string] // Set of all files from the keystore folder
lastMod time.Time // Last time instance when a file was modified lastMod time.Time // Last time instance when a file was modified
mu sync.Mutex mu sync.Mutex
} }
// scan performs a new scan on the given directory, compares against the already // scan performs a new scan on the given directory, compares against the already
// cached filenames, and returns file sets: creates, deletes, updates. // cached filenames, and returns file sets: creates, deletes, updates.
func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, error) { func (fc *fileCache) scan(keyDir string) (mapset.Set[string], mapset.Set[string], mapset.Set[string], error) {
t0 := time.Now() t0 := time.Now()
// List all the files from the keystore folder // List all the files from the keystore folder
...@@ -50,8 +50,8 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er ...@@ -50,8 +50,8 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
defer fc.mu.Unlock() defer fc.mu.Unlock()
// Iterate all the files and gather their metadata // Iterate all the files and gather their metadata
all := mapset.NewThreadUnsafeSet() all := mapset.NewThreadUnsafeSet[string]()
mods := mapset.NewThreadUnsafeSet() mods := mapset.NewThreadUnsafeSet[string]()
var newLastMod time.Time var newLastMod time.Time
for _, fi := range files { for _, fi := range files {
......
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
"runtime" "runtime"
"time" "time"
mapset "github.com/deckarep/golang-set" mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
...@@ -214,7 +214,7 @@ func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Blo ...@@ -214,7 +214,7 @@ func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Blo
return nil return nil
} }
// Gather the set of past uncles and ancestors // Gather the set of past uncles and ancestors
uncles, ancestors := mapset.NewSet(), make(map[common.Hash]*types.Header) uncles, ancestors := mapset.NewSet[common.Hash](), make(map[common.Hash]*types.Header)
number, parent := block.NumberU64()-1, block.ParentHash() number, parent := block.NumberU64()-1, block.ParentHash()
for i := 0; i < 7; i++ { for i := 0; i < 7; i++ {
......
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
"sort" "sort"
"time" "time"
mapset "github.com/deckarep/golang-set" mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/core/txpool"
...@@ -148,7 +148,7 @@ type TxFetcher struct { ...@@ -148,7 +148,7 @@ type TxFetcher struct {
drop chan *txDrop drop chan *txDrop
quit chan struct{} quit chan struct{}
underpriced mapset.Set // Transactions discarded as too cheap (don't re-fetch) underpriced mapset.Set[common.Hash] // Transactions discarded as too cheap (don't re-fetch)
// Stage 1: Waiting lists for newly discovered transactions that might be // Stage 1: Waiting lists for newly discovered transactions that might be
// broadcast without needing explicit request/reply round trips. // broadcast without needing explicit request/reply round trips.
...@@ -202,7 +202,7 @@ func NewTxFetcherForTests( ...@@ -202,7 +202,7 @@ func NewTxFetcherForTests(
fetching: make(map[common.Hash]string), fetching: make(map[common.Hash]string),
requests: make(map[string]*txRequest), requests: make(map[string]*txRequest),
alternates: make(map[common.Hash]map[string]struct{}), alternates: make(map[common.Hash]map[string]struct{}),
underpriced: mapset.NewSet(), underpriced: mapset.NewSet[common.Hash](),
hasTx: hasTx, hasTx: hasTx,
addTxs: addTxs, addTxs: addTxs,
fetchTxs: fetchTxs, fetchTxs: fetchTxs,
......
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
"math/rand" "math/rand"
"sync" "sync"
mapset "github.com/deckarep/golang-set" mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
...@@ -502,7 +502,7 @@ func (p *Peer) RequestTxs(hashes []common.Hash) error { ...@@ -502,7 +502,7 @@ func (p *Peer) RequestTxs(hashes []common.Hash) error {
// knownCache is a cache for known hashes. // knownCache is a cache for known hashes.
type knownCache struct { type knownCache struct {
hashes mapset.Set hashes mapset.Set[common.Hash]
max int max int
} }
...@@ -510,7 +510,7 @@ type knownCache struct { ...@@ -510,7 +510,7 @@ type knownCache struct {
func newKnownCache(max int) *knownCache { func newKnownCache(max int) *knownCache {
return &knownCache{ return &knownCache{
max: max, max: max,
hashes: mapset.NewSet(), hashes: mapset.NewSet[common.Hash](),
} }
} }
......
...@@ -14,7 +14,7 @@ require ( ...@@ -14,7 +14,7 @@ require (
github.com/cloudflare/cloudflare-go v0.14.0 github.com/cloudflare/cloudflare-go v0.14.0
github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f
github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0 github.com/deckarep/golang-set/v2 v2.1.0
github.com/docker/docker v1.6.2 github.com/docker/docker v1.6.2
github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf
github.com/edsrzf/mmap-go v1.0.0 github.com/edsrzf/mmap-go v1.0.0
......
This diff is collapsed.
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
mapset "github.com/deckarep/golang-set" mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/consensus/misc"
...@@ -89,8 +89,8 @@ type environment struct { ...@@ -89,8 +89,8 @@ type environment struct {
signer types.Signer signer types.Signer
state *state.StateDB // apply state changes here state *state.StateDB // apply state changes here
ancestors mapset.Set // ancestor set (used for checking uncle parent validity) ancestors mapset.Set[common.Hash] // ancestor set (used for checking uncle parent validity)
family mapset.Set // family set (used for checking uncle invalidity) family mapset.Set[common.Hash] // family set (used for checking uncle invalidity)
tcount int // tx count in cycle tcount int // tx count in cycle
gasPool *core.GasPool // available gas used to pack transactions gasPool *core.GasPool // available gas used to pack transactions
coinbase common.Address coinbase common.Address
...@@ -795,8 +795,8 @@ func (w *worker) makeEnv(parent *types.Block, header *types.Header, coinbase com ...@@ -795,8 +795,8 @@ func (w *worker) makeEnv(parent *types.Block, header *types.Header, coinbase com
signer: types.MakeSigner(w.chainConfig, header.Number), signer: types.MakeSigner(w.chainConfig, header.Number),
state: state, state: state,
coinbase: coinbase, coinbase: coinbase,
ancestors: mapset.NewSet(), ancestors: mapset.NewSet[common.Hash](),
family: mapset.NewSet(), family: mapset.NewSet[common.Hash](),
header: header, header: header,
uncles: make(map[common.Hash]*types.Header), uncles: make(map[common.Hash]*types.Header),
} }
......
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
"io" "io"
"sync/atomic" "sync/atomic"
mapset "github.com/deckarep/golang-set" mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
...@@ -46,12 +46,12 @@ type Server struct { ...@@ -46,12 +46,12 @@ type Server struct {
services serviceRegistry services serviceRegistry
idgen func() ID idgen func() ID
run int32 run int32
codecs mapset.Set codecs mapset.Set[*ServerCodec]
} }
// NewServer creates a new server instance with no registered handlers. // NewServer creates a new server instance with no registered handlers.
func NewServer() *Server { func NewServer() *Server {
server := &Server{idgen: randomIDGenerator(), codecs: mapset.NewSet(), run: 1} server := &Server{idgen: randomIDGenerator(), codecs: mapset.NewSet[*ServerCodec](), run: 1}
// Register the default service providing meta information about the RPC service such // Register the default service providing meta information about the RPC service such
// as the services and methods it offers. // as the services and methods it offers.
rpcService := &RPCService{server} rpcService := &RPCService{server}
...@@ -81,8 +81,8 @@ func (s *Server) ServeCodec(codec ServerCodec, options CodecOption) { ...@@ -81,8 +81,8 @@ func (s *Server) ServeCodec(codec ServerCodec, options CodecOption) {
} }
// Add the codec to the set so it can be closed by Stop. // Add the codec to the set so it can be closed by Stop.
s.codecs.Add(codec) s.codecs.Add(&codec)
defer s.codecs.Remove(codec) defer s.codecs.Remove(&codec)
c := initClient(codec, s.idgen, &s.services) c := initClient(codec, s.idgen, &s.services)
<-codec.closed() <-codec.closed()
...@@ -122,8 +122,8 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec) { ...@@ -122,8 +122,8 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec) {
func (s *Server) Stop() { func (s *Server) Stop() {
if atomic.CompareAndSwapInt32(&s.run, 1, 0) { if atomic.CompareAndSwapInt32(&s.run, 1, 0) {
log.Debug("RPC server shutting down") log.Debug("RPC server shutting down")
s.codecs.Each(func(c interface{}) bool { s.codecs.Each(func(c *ServerCodec) bool {
c.(ServerCodec).close() (*c).close()
return true return true
}) })
} }
......
...@@ -27,7 +27,7 @@ import ( ...@@ -27,7 +27,7 @@ import (
"sync" "sync"
"time" "time"
mapset "github.com/deckarep/golang-set" mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
...@@ -69,7 +69,7 @@ func (s *Server) WebsocketHandler(allowedOrigins []string) http.Handler { ...@@ -69,7 +69,7 @@ func (s *Server) WebsocketHandler(allowedOrigins []string) http.Handler {
// websocket upgrade process. When a '*' is specified as an allowed origins all // websocket upgrade process. When a '*' is specified as an allowed origins all
// connections are accepted. // connections are accepted.
func wsHandshakeValidator(allowedOrigins []string) func(*http.Request) bool { func wsHandshakeValidator(allowedOrigins []string) func(*http.Request) bool {
origins := mapset.NewSet() origins := mapset.NewSet[string]()
allowAllOrigins := false allowAllOrigins := false
for _, origin := range allowedOrigins { for _, origin := range allowedOrigins {
...@@ -122,10 +122,10 @@ func (e wsHandshakeError) Error() string { ...@@ -122,10 +122,10 @@ func (e wsHandshakeError) Error() string {
return s return s
} }
func originIsAllowed(allowedOrigins mapset.Set, browserOrigin string) bool { func originIsAllowed(allowedOrigins mapset.Set[string], browserOrigin string) bool {
it := allowedOrigins.Iterator() it := allowedOrigins.Iterator()
for origin := range it.C { for origin := range it.C {
if ruleAllowsOrigin(origin.(string), browserOrigin) { if ruleAllowsOrigin(origin, browserOrigin) {
return true return true
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment