diff --git a/accounts/keystore/account_cache.go b/accounts/keystore/account_cache.go index a3ec6e9c5..9276b3cfc 100644 --- a/accounts/keystore/account_cache.go +++ b/accounts/keystore/account_cache.go @@ -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" @@ -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 @@ -275,16 +275,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) diff --git a/accounts/keystore/file_cache.go b/accounts/keystore/file_cache.go index b3ecf8946..a67fb7b1d 100644 --- a/accounts/keystore/file_cache.go +++ b/accounts/keystore/file_cache.go @@ -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 failes from the keystore folder @@ -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 { diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 5c61fc9ca..686c1dcdf 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -22,7 +22,7 @@ import ( "math/big" "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" @@ -153,7 +153,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++ { diff --git a/eth/fetcher/tx_fetcher.go b/eth/fetcher/tx_fetcher.go index c7842d897..d4269e67f 100644 --- a/eth/fetcher/tx_fetcher.go +++ b/eth/fetcher/tx_fetcher.go @@ -23,7 +23,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" @@ -147,7 +147,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. @@ -201,7 +201,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, diff --git a/eth/protocols/eth/peer.go b/eth/protocols/eth/peer.go index 5ced71ebd..3851c95d8 100644 --- a/eth/protocols/eth/peer.go +++ b/eth/protocols/eth/peer.go @@ -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" @@ -75,14 +75,14 @@ type Peer struct { head common.Hash // Latest advertised head block hash td *big.Int // Latest advertised head block total difficulty - knownBlocks mapset.Set // Set of block hashes known to be known by this peer - queuedBlocks chan *blockPropagation // Queue of blocks to broadcast to the peer - queuedBlockAnns chan *types.Block // Queue of blocks to announce to the peer + knownBlocks mapset.Set[common.Hash] // Set of block hashes known to be known by this peer + queuedBlocks chan *blockPropagation // Queue of blocks to broadcast to the peer + queuedBlockAnns chan *types.Block // Queue of blocks to announce to the peer - txpool TxPool // Transaction pool used by the broadcasters for liveness checks - knownTxs mapset.Set // Set of transaction hashes known to be known by this peer - txBroadcast chan []common.Hash // Channel used to queue transaction propagation requests - txAnnounce chan []common.Hash // Channel used to queue transaction announcement requests + txpool TxPool // Transaction pool used by the broadcasters for liveness checks + knownTxs mapset.Set[common.Hash] // Set of transaction hashes known to be known by this peer + txBroadcast chan []common.Hash // Channel used to queue transaction propagation requests + txAnnounce chan []common.Hash // Channel used to queue transaction announcement requests term chan struct{} // Termination channel to stop the broadcasters lock sync.RWMutex // Mutex protecting the internal fields @@ -98,8 +98,8 @@ func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter, txpool TxPool) *Pe Peer: p, rw: rw, version: version, - knownTxs: mapset.NewSet(), - knownBlocks: mapset.NewSet(), + knownTxs: mapset.NewSet[common.Hash](), + knownBlocks: mapset.NewSet[common.Hash](), queuedBlocks: make(chan *blockPropagation, maxQueuedBlocks), queuedBlockAnns: make(chan *types.Block, maxQueuedBlockAnns), txBroadcast: make(chan []common.Hash), diff --git a/eth/protocols/eth/qlight_deps.go b/eth/protocols/eth/qlight_deps.go index 2f1e573b3..8b8f5b233 100644 --- a/eth/protocols/eth/qlight_deps.go +++ b/eth/protocols/eth/qlight_deps.go @@ -1,7 +1,7 @@ package eth import ( - 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" "github.com/ethereum/go-ethereum/core/types" @@ -47,8 +47,8 @@ func NewPeerNoBroadcast(version uint, p *p2p.Peer, rw p2p.MsgReadWriter, txpool Peer: p, rw: rw, version: version, - knownTxs: mapset.NewSet(), - knownBlocks: mapset.NewSet(), + knownTxs: mapset.NewSet[common.Hash](), + knownBlocks: mapset.NewSet[common.Hash](), queuedBlocks: make(chan *blockPropagation, maxQueuedBlocks), queuedBlockAnns: make(chan *types.Block, maxQueuedBlockAnns), txBroadcast: make(chan []common.Hash), diff --git a/eth/protocols/qlight/peer.go b/eth/protocols/qlight/peer.go index 77086e646..fe4c95cf9 100644 --- a/eth/protocols/qlight/peer.go +++ b/eth/protocols/qlight/peer.go @@ -3,7 +3,7 @@ package qlight import ( "math/big" - 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/eth/protocols/eth" @@ -35,8 +35,8 @@ type Peer struct { EthPeer *eth.Peer - knownBlocks mapset.Set // Set of block hashes known to be known by this peer - queuedBlocks chan *blockPropagation // Queue of blocks to broadcast to the peer + knownBlocks mapset.Set[common.Hash] // Set of block hashes known to be known by this peer + queuedBlocks chan *blockPropagation // Queue of blocks to broadcast to the peer term chan struct{} // Termination channel to stop the broadcasters @@ -59,7 +59,7 @@ func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter, ethPeer *eth.Peer) logger: log.New("peer", id[:8]), EthPeer: ethPeer, term: make(chan struct{}), - knownBlocks: mapset.NewSet(), + knownBlocks: mapset.NewSet[common.Hash](), queuedBlocks: make(chan *blockPropagation, maxQueuedBlocks), } } diff --git a/go.mod b/go.mod index 7581eb3e2..bc7c53afa 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/consensys/gnark-crypto v0.14.0 github.com/coreos/etcd v3.3.27+incompatible github.com/davecgh/go-spew v1.1.1 - github.com/deckarep/golang-set v1.8.0 + github.com/deckarep/golang-set/v2 v2.6.0 github.com/docker/docker v27.2.1+incompatible github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498 github.com/eapache/channels v1.1.0 diff --git a/go.sum b/go.sum index d4e0093b4..2322c3ebb 100644 --- a/go.sum +++ b/go.sum @@ -158,8 +158,8 @@ github.com/dave/jennifer v1.2.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhr github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= -github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= +github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM= +github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= diff --git a/light/postprocess.go b/light/postprocess.go index 891c8a586..88773991c 100644 --- a/light/postprocess.go +++ b/light/postprocess.go @@ -25,7 +25,7 @@ import ( "math/big" "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/bitutil" "github.com/ethereum/go-ethereum/core" @@ -134,7 +134,7 @@ type ChtIndexerBackend struct { diskdb, trieTable ethdb.Database odr OdrBackend triedb *trie.Database - trieset mapset.Set + trieset mapset.Set[common.Hash] section, sectionSize uint64 lastHash common.Hash trie *trie.Trie @@ -148,7 +148,7 @@ func NewChtIndexer(db ethdb.Database, odr OdrBackend, size, confirms uint64, dis odr: odr, trieTable: trieTable, triedb: trie.NewDatabaseWithConfig(trieTable, &trie.Config{Cache: 1}), // Use a tiny cache only to keep memory down - trieset: mapset.NewSet(), + trieset: mapset.NewSet[common.Hash](), sectionSize: size, disablePruning: disablePruning, } @@ -323,7 +323,7 @@ type BloomTrieIndexerBackend struct { disablePruning bool diskdb, trieTable ethdb.Database triedb *trie.Database - trieset mapset.Set + trieset mapset.Set[common.Hash] odr OdrBackend section uint64 parentSize uint64 @@ -341,7 +341,7 @@ func NewBloomTrieIndexer(db ethdb.Database, odr OdrBackend, parentSize, size uin odr: odr, trieTable: trieTable, triedb: trie.NewDatabaseWithConfig(trieTable, &trie.Config{Cache: 1}), // Use a tiny cache only to keep memory down - trieset: mapset.NewSet(), + trieset: mapset.NewSet[common.Hash](), parentSize: parentSize, size: size, disablePruning: disablePruning, diff --git a/miner/worker.go b/miner/worker.go index 2ba3cc663..da60774b2 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -24,7 +24,7 @@ import ( "sync/atomic" "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/consensus" "github.com/ethereum/go-ethereum/consensus/misc" @@ -83,12 +83,12 @@ const ( type environment struct { signer types.Signer - state *state.StateDB // apply state changes here - ancestors mapset.Set // ancestor set (used for checking uncle parent validity) - family mapset.Set // family set (used for checking uncle invalidity) - uncles mapset.Set // uncle set - tcount int // tx count in cycle - gasPool *core.GasPool // available gas used to pack transactions + state *state.StateDB // apply state changes here + ancestors mapset.Set[common.Hash] // ancestor set (used for checking uncle parent validity) + family mapset.Set[common.Hash] // family set (used for checking uncle invalidity) + uncles mapset.Set[common.Hash] // uncle set + tcount int // tx count in cycle + gasPool *core.GasPool // available gas used to pack transactions header *types.Header txs []*types.Transaction @@ -507,14 +507,10 @@ func (w *worker) mainLoop() { start := time.Now() if err := w.commitUncle(w.current, ev.Block.Header()); err == nil { var uncles []*types.Header - w.current.uncles.Each(func(item interface{}) bool { - hash, ok := item.(common.Hash) - if !ok { - return false - } - uncle, exist := w.localUncles[hash] + w.current.uncles.Each(func(item common.Hash) bool { + uncle, exist := w.localUncles[item] if !exist { - uncle, exist = w.remoteUncles[hash] + uncle, exist = w.remoteUncles[item] } if !exist { return false @@ -766,9 +762,9 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error { env := &environment{ signer: types.MakeSigner(w.chainConfig, header.Number), state: publicState, - ancestors: mapset.NewSet(), - family: mapset.NewSet(), - uncles: mapset.NewSet(), + ancestors: mapset.NewSet[common.Hash](), + family: mapset.NewSet[common.Hash](), + uncles: mapset.NewSet[common.Hash](), header: header, // Quorum privateStateRepo: privateStateRepo, @@ -819,14 +815,10 @@ func (w *worker) updateSnapshot() { defer w.snapshotMu.Unlock() var uncles []*types.Header - w.current.uncles.Each(func(item interface{}) bool { - hash, ok := item.(common.Hash) - if !ok { - return false - } - uncle, exist := w.localUncles[hash] + w.current.uncles.Each(func(item common.Hash) bool { + uncle, exist := w.localUncles[item] if !exist { - uncle, exist = w.remoteUncles[hash] + uncle, exist = w.remoteUncles[item] } if !exist { return false diff --git a/raft/handler.go b/raft/handler.go index bdd506595..a6f92db3b 100644 --- a/raft/handler.go +++ b/raft/handler.go @@ -21,7 +21,7 @@ import ( "github.com/coreos/etcd/rafthttp" "github.com/coreos/etcd/snap" "github.com/coreos/etcd/wal" - mapset "github.com/deckarep/golang-set" + mapset "github.com/deckarep/golang-set/v2" "github.com/syndtr/goleveldb/leveldb" "github.com/ethereum/go-ethereum/core" @@ -55,7 +55,7 @@ type ProtocolManager struct { // Remote peer state (protected by mu vs concurrent access via JS) leader uint16 peers map[uint16]*Peer - removedPeers mapset.Set // *Permanently removed* peers + removedPeers mapset.Set[uint16] // *Permanently removed* peers // P2P transport p2pServer *p2p.Server @@ -109,7 +109,7 @@ func NewProtocolManager(raftId uint16, raftPort uint16, blockchain *core.BlockCh bootstrapNodes: bootstrapNodes, peers: make(map[uint16]*Peer), leader: uint16(etcdRaft.None), - removedPeers: mapset.NewSet(), + removedPeers: mapset.NewSet[uint16](), joinExisting: joinExisting, blockchain: blockchain, eventMux: mux, @@ -208,11 +208,11 @@ func (pm *ProtocolManager) NodeInfo() *RaftNodeInfo { peerIdx += 1 } - removedPeerIfaces := pm.removedPeers - removedPeerIds := make([]uint16, removedPeerIfaces.Cardinality()) + removedPeerMapset := pm.removedPeers + removedPeerIds := make([]uint16, removedPeerMapset.Cardinality()) i := 0 - for removedIface := range removedPeerIfaces.Iterator().C { - removedPeerIds[i] = removedIface.(uint16) + for removedId := range removedPeerMapset.Iterator().C { + removedPeerIds[i] = removedId i++ } @@ -256,10 +256,8 @@ func (pm *ProtocolManager) nextRaftId() uint16 { } } - removedPeerIfaces := pm.removedPeers - for removedIface := range removedPeerIfaces.Iterator().C { - removedId := removedIface.(uint16) - + removedPeerMapset := pm.removedPeers + for removedId := range removedPeerMapset.Iterator().C { if maxId < removedId { maxId = removedId } diff --git a/raft/minter_test.go b/raft/minter_test.go index ea4e3bb84..99effd44d 100644 --- a/raft/minter_test.go +++ b/raft/minter_test.go @@ -8,7 +8,7 @@ import ( "time" "github.com/coreos/etcd/raft/raftpb" - 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/hexutil" "github.com/ethereum/go-ethereum/core/types" @@ -194,7 +194,7 @@ func newTestRaftService(t *testing.T, raftId uint16, nodes []uint64, learners [] raftId: raftId, bootstrapNodes: peers, confChangeProposalC: make(chan raftpb.ConfChange), - removedPeers: mapset.NewSet(), + removedPeers: mapset.NewSet[uint16](), confState: raftpb.ConfState{Nodes: nodes, Learners: learners}, p2pServer: mockp2p, } diff --git a/raft/snapshot.go b/raft/snapshot.go index e2e1bd17a..2776ef52a 100644 --- a/raft/snapshot.go +++ b/raft/snapshot.go @@ -12,7 +12,7 @@ import ( "github.com/coreos/etcd/raft/raftpb" "github.com/coreos/etcd/snap" "github.com/coreos/etcd/wal/walpb" - 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/eth/downloader" @@ -78,7 +78,7 @@ func (pm *ProtocolManager) buildSnapshot() *SnapshotWithHostnames { // Populate removed IDs i := 0 for removedIface := range pm.removedPeers.Iterator().C { - snapshot.RemovedRaftIds[i] = removedIface.(uint16) + snapshot.RemovedRaftIds[i] = removedIface i++ } return snapshot @@ -116,8 +116,8 @@ func (pm *ProtocolManager) triggerSnapshot(index uint64) { pm.mu.Unlock() } -func confStateIdSet(confState raftpb.ConfState) mapset.Set { - set := mapset.NewSet() +func confStateIdSet(confState raftpb.ConfState) mapset.Set[uint16] { + set := mapset.NewSet[uint16]() for _, rawRaftId := range append(confState.Nodes, confState.Learners...) { set.Add(uint16(rawRaftId)) } @@ -132,7 +132,7 @@ func (pm *ProtocolManager) updateClusterMembership(newConfState raftpb.ConfState // Update tombstones for permanently removed peers. For simplicity we do not // allow the re-use of peer IDs once a peer is removed. - removedPeers := mapset.NewSet() + removedPeers := mapset.NewSet[uint16]() for _, removedRaftId := range removedRaftIds { removedPeers.Add(removedRaftId) } @@ -145,8 +145,8 @@ func (pm *ProtocolManager) updateClusterMembership(newConfState raftpb.ConfState prevIds := confStateIdSet(prevConfState) newIds := confStateIdSet(newConfState) idsToRemove := prevIds.Difference(newIds) - for idIfaceToRemove := range idsToRemove.Iterator().C { - raftId := idIfaceToRemove.(uint16) + for idToRemove := range idsToRemove.Iterator().C { + raftId := idToRemove log.Info("removing old raft peer", "peer id", raftId) pm.removePeer(raftId) diff --git a/raft/speculative_chain.go b/raft/speculative_chain.go index 2067edf0e..6ced0dc78 100644 --- a/raft/speculative_chain.go +++ b/raft/speculative_chain.go @@ -1,7 +1,7 @@ package raft import ( - mapset "github.com/deckarep/golang-set" + mapset "github.com/deckarep/golang-set/v2" "gopkg.in/oleiade/lane.v1" "github.com/ethereum/go-ethereum/common" @@ -21,16 +21,16 @@ import ( type speculativeChain struct { head *types.Block unappliedBlocks *lane.Deque - expectedInvalidBlockHashes mapset.Set // This is thread-safe. This set is referred to as our "guard" below. - proposedTxes mapset.Set // This is thread-safe. + expectedInvalidBlockHashes mapset.Set[common.Hash] // This is thread-safe. This set is referred to as our "guard" below. + proposedTxes mapset.Set[common.Hash] // This is thread-safe. } func newSpeculativeChain() *speculativeChain { return &speculativeChain{ head: nil, unappliedBlocks: lane.NewDeque(), - expectedInvalidBlockHashes: mapset.NewSet(), - proposedTxes: mapset.NewSet(), + expectedInvalidBlockHashes: mapset.NewSet[common.Hash](), + proposedTxes: mapset.NewSet[common.Hash](), } } @@ -135,7 +135,7 @@ func (chain *speculativeChain) unwindFrom(invalidHash common.Hash, headBlock *ty // supplying us these transactions until they are in the chain (after having // flown through raft). func (chain *speculativeChain) recordProposedTransactions(txes types.Transactions) { - txHashIs := make([]interface{}, len(txes)) + txHashIs := make([]common.Hash, len(txes)) for i, tx := range txes { txHashIs[i] = tx.Hash() } @@ -153,7 +153,7 @@ func (chain *speculativeChain) recordProposedTransactions(txes types.Transaction // need them in there anymore) so that it doesn't grow endlessly. func (chain *speculativeChain) removeProposedTxes(block *types.Block) { minedTxes := block.Transactions() - minedTxInterfaces := make([]interface{}, len(minedTxes)) + minedTxInterfaces := make([]common.Hash, len(minedTxes)) for i, tx := range minedTxes { minedTxInterfaces[i] = tx.Hash() } diff --git a/rpc/server.go b/rpc/server.go index 2b50ee752..96a65e8f2 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -22,7 +22,7 @@ import ( "net/http" "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/plugin/security" ) @@ -47,7 +47,7 @@ type Server struct { services serviceRegistry idgen func() ID run int32 - codecs mapset.Set + codecs mapset.Set[*ServerCodec] // Quorum // The implementation would authenticate the token coming from a request @@ -68,7 +68,7 @@ func NewProtectedServer(authManager security.AuthenticationManager, isMultitenan // NewServer creates a new server instance with no registered handlers. func NewServer() *Server { - server := &Server{idgen: randomIDGenerator(), codecs: mapset.NewSet(), run: 1, + server := &Server{idgen: randomIDGenerator(), codecs: mapset.NewSet[*ServerCodec](), run: 1, authenticationManager: security.NewDisabledAuthenticationManager(), isMultitenant: false, } @@ -101,8 +101,8 @@ func (s *Server) ServeCodec(codec ServerCodec, options CodecOption) { } // Add the codec to the set so it can be closed by Stop. - s.codecs.Add(codec) - defer s.codecs.Remove(codec) + s.codecs.Add(&codec) + defer s.codecs.Remove(&codec) c := initClient(codec, s.idgen, &s.services) <-codec.closed() @@ -142,8 +142,8 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec) { func (s *Server) Stop() { if atomic.CompareAndSwapInt32(&s.run, 1, 0) { log.Debug("RPC server shutting down") - s.codecs.Each(func(c interface{}) bool { - c.(ServerCodec).close() + s.codecs.Each(func(c *ServerCodec) bool { + (*c).close() return true }) } diff --git a/rpc/websocket.go b/rpc/websocket.go index 558de2d54..c6cb78eea 100644 --- a/rpc/websocket.go +++ b/rpc/websocket.go @@ -28,7 +28,7 @@ import ( "sync" "time" - mapset "github.com/deckarep/golang-set" + mapset "github.com/deckarep/golang-set/v2" "github.com/ethereum/go-ethereum/log" "github.com/gorilla/websocket" ) @@ -70,7 +70,7 @@ func (s *Server) WebsocketHandler(allowedOrigins []string) http.Handler { // websocket upgrade process. When a '*' is specified as an allowed origins all // connections are accepted. func wsHandshakeValidator(allowedOrigins []string) func(*http.Request) bool { - origins := mapset.NewSet() + origins := mapset.NewSet[string]() allowAllOrigins := false for _, origin := range allowedOrigins { @@ -125,10 +125,10 @@ func (e wsHandshakeError) Error() string { return s } -func originIsAllowed(allowedOrigins mapset.Set, browserOrigin string) bool { +func originIsAllowed(allowedOrigins mapset.Set[string], browserOrigin string) bool { it := allowedOrigins.Iterator() for origin := range it.C { - if ruleAllowsOrigin(origin.(string), browserOrigin) { + if ruleAllowsOrigin(origin, browserOrigin) { return true } }