Skip to content

Commit

Permalink
all: use github.com/deckarep/golang-set/v2 (generic set) (#26159)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Lange <fjl@twurst.com>
  • Loading branch information
Jolly23 and fjl authored Nov 14, 2022
1 parent 8c5ce11 commit f58ebd9
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 42 deletions.
15 changes: 7 additions & 8 deletions accounts/keystore/account_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"sync"
"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/common"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -79,7 +79,7 @@ func newAccountCache(keydir string) (*accountCache, chan struct{}) {
keydir: keydir,
byAddr: make(map[common.Address][]accounts.Account),
notify: make(chan struct{}, 1),
fileC: fileCache{all: mapset.NewThreadUnsafeSet()},
fileC: fileCache{all: mapset.NewThreadUnsafeSet[string]()},
}
ac.watcher = newWatcher(ac)
return ac, ac.notify
Expand Down Expand Up @@ -283,16 +283,15 @@ func (ac *accountCache) scanAccounts() error {
// Process all the file diffs
start := time.Now()

for _, p := range creates.ToSlice() {
if a := readAccount(p.(string)); a != nil {
for _, path := range creates.ToSlice() {
if a := readAccount(path); a != nil {
ac.add(*a)
}
}
for _, p := range deletes.ToSlice() {
ac.deleteByFile(p.(string))
for _, path := range deletes.ToSlice() {
ac.deleteByFile(path)
}
for _, p := range updates.ToSlice() {
path := p.(string)
for _, path := range updates.ToSlice() {
ac.deleteByFile(path)
if a := readAccount(path); a != nil {
ac.add(*a)
Expand Down
12 changes: 6 additions & 6 deletions accounts/keystore/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ import (
"sync"
"time"

mapset "github.com/deckarep/golang-set"
mapset "github.com/deckarep/golang-set/v2"
"github.com/ethereum/go-ethereum/log"
)

// fileCache is a cache of files seen during scan of keystore.
type fileCache struct {
all mapset.Set // Set of all files from the keystore folder
lastMod time.Time // Last time instance when a file was modified
all mapset.Set[string] // Set of all files from the keystore folder
lastMod time.Time // Last time instance when a file was modified
mu sync.Mutex
}

// scan performs a new scan on the given directory, compares against the already
// 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()

// List all the files from the keystore folder
Expand All @@ -50,8 +50,8 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
defer fc.mu.Unlock()

// Iterate all the files and gather their metadata
all := mapset.NewThreadUnsafeSet()
mods := mapset.NewThreadUnsafeSet()
all := mapset.NewThreadUnsafeSet[string]()
mods := mapset.NewThreadUnsafeSet[string]()

var newLastMod time.Time
for _, fi := range files {
Expand Down
4 changes: 2 additions & 2 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"runtime"
"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/math"
"github.com/ethereum/go-ethereum/consensus"
Expand Down Expand Up @@ -214,7 +214,7 @@ func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Blo
return nil
}
// 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()
for i := 0; i < 7; i++ {
Expand Down
6 changes: 3 additions & 3 deletions eth/fetcher/tx_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sort"
"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/mclock"
"github.com/ethereum/go-ethereum/core/txpool"
Expand Down Expand Up @@ -148,7 +148,7 @@ type TxFetcher struct {
drop chan *txDrop
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
// broadcast without needing explicit request/reply round trips.
Expand Down Expand Up @@ -202,7 +202,7 @@ func NewTxFetcherForTests(
fetching: make(map[common.Hash]string),
requests: make(map[string]*txRequest),
alternates: make(map[common.Hash]map[string]struct{}),
underpriced: mapset.NewSet(),
underpriced: mapset.NewSet[common.Hash](),
hasTx: hasTx,
addTxs: addTxs,
fetchTxs: fetchTxs,
Expand Down
6 changes: 3 additions & 3 deletions eth/protocols/eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"math/rand"
"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/core/types"
"github.com/ethereum/go-ethereum/p2p"
Expand Down Expand Up @@ -502,15 +502,15 @@ func (p *Peer) RequestTxs(hashes []common.Hash) error {

// knownCache is a cache for known hashes.
type knownCache struct {
hashes mapset.Set
hashes mapset.Set[common.Hash]
max int
}

// newKnownCache creates a new knownCache with a max capacity.
func newKnownCache(max int) *knownCache {
return &knownCache{
max: max,
hashes: mapset.NewSet(),
hashes: mapset.NewSet[common.Hash](),
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/cloudflare/cloudflare-go v0.14.0
github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f
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/dop251/goja v0.0.0-20220405120441-9037c2b61cbf
github.com/edsrzf/mmap-go v1.0.0
Expand Down
Loading

0 comments on commit f58ebd9

Please sign in to comment.