Skip to content

Commit ad61361

Browse files
vardan10pipermerriam
authored andcommitted
Replaces set with frozenset (#1602)
* Replaces set with frozenset * Imports frozenSet from typings * minor fix * Adds Set in state * Adds FrozenSet to PeerSubscriber class * replaces set with frozenset * changes in return type * changes in return type * changes set to frozen set * changes set to frozen set
1 parent 071aa2a commit ad61361

File tree

11 files changed

+25
-24
lines changed

11 files changed

+25
-24
lines changed

p2p/peer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Iterator,
2121
List,
2222
NamedTuple,
23-
Set,
23+
FrozenSet,
2424
Tuple,
2525
Type,
2626
)
@@ -636,7 +636,7 @@ class PeerSubscriber(ABC):
636636

637637
@property
638638
@abstractmethod
639-
def subscription_msg_types(self) -> Set[Type[protocol.Command]]:
639+
def subscription_msg_types(self) -> FrozenSet[Type[protocol.Command]]:
640640
"""
641641
The `p2p.protocol.Command` types that this class subscribes to. Any
642642
command which is not in this set will not be passed to this subscriber.
@@ -731,7 +731,7 @@ def subscribe_peer(self, peer: BasePeer) -> Iterator[None]:
731731
class MsgBuffer(PeerSubscriber):
732732
logger = logging.getLogger('p2p.peer.MsgBuffer')
733733
msg_queue_maxsize = 500
734-
subscription_msg_types = {protocol.Command}
734+
subscription_msg_types = frozenset({protocol.Command})
735735

736736
@to_tuple
737737
def get_messages(self) -> Iterator[PeerMessage]:

trinity/plugins/builtin/tx_pool/pool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Callable,
44
Iterable,
55
List,
6-
Set,
6+
FrozenSet,
77
Type,
88
)
99
import uuid
@@ -60,7 +60,7 @@ def __init__(self,
6060
self._bloom = BloomFilter(max_elements=1000000)
6161
self._bloom_salt = str(uuid.uuid4())
6262

63-
subscription_msg_types: Set[Type[Command]] = {Transactions}
63+
subscription_msg_types: FrozenSet[Type[Command]] = frozenset({Transactions})
6464

6565
# This is a rather arbitrary value, but when the sync is operating normally we never see
6666
# the msg queue grow past a few hundred items, so this should be a reasonable limit for

trinity/protocol/bcc/servers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import (
33
cast,
44
Iterable,
5-
Set,
5+
FrozenSet,
66
Type,
77
)
88

@@ -41,9 +41,9 @@
4141

4242

4343
class BCCRequestServer(BaseRequestServer):
44-
subscription_msg_types: Set[Type[Command]] = {
44+
subscription_msg_types: FrozenSet[Type[Command]] = frozenset({
4545
GetBeaconBlocks,
46-
}
46+
})
4747

4848
def __init__(self,
4949
db: BaseBeaconChainDB,

trinity/protocol/common/managers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
AsyncGenerator,
66
Callable,
77
Generic,
8-
Set,
8+
FrozenSet,
99
Tuple,
1010
Type,
1111
cast,
@@ -46,8 +46,8 @@ class ResponseCandidateStream(
4646
# PeerSubscriber
4747
#
4848
@property
49-
def subscription_msg_types(self) -> Set[Type[Command]]:
50-
return {self.response_msg_type}
49+
def subscription_msg_types(self) -> FrozenSet[Type[Command]]:
50+
return frozenset({self.response_msg_type})
5151

5252
msg_queue_maxsize = 100
5353

trinity/protocol/eth/monitors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44

55
class ETHChainTipMonitor(BaseChainTipMonitor):
6-
subscription_msg_types = {commands.NewBlock}
6+
subscription_msg_types = frozenset({commands.NewBlock})

trinity/protocol/eth/servers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import (
22
Any,
33
Dict,
4-
Set,
4+
FrozenSet,
55
Sequence,
66
Type,
77
Union,
@@ -124,7 +124,7 @@ class ETHRequestServer(BaseRequestServer):
124124
Monitor commands from peers, to identify inbound requests that should receive a response.
125125
Handle those inbound requests by querying our local database and replying.
126126
"""
127-
subscription_msg_types: Set[Type[Command]] = {
127+
subscription_msg_types: FrozenSet[Type[Command]] = frozenset({
128128
commands.GetBlockHeaders,
129129
commands.GetBlockBodies,
130130
commands.GetReceipts,
@@ -133,7 +133,7 @@ class ETHRequestServer(BaseRequestServer):
133133
# until the messages are properly handled.
134134
commands.Transactions,
135135
commands.NewBlockHashes,
136-
}
136+
})
137137

138138
def __init__(
139139
self,

trinity/protocol/les/monitors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44

55
class LightChainTipMonitor(BaseChainTipMonitor):
6-
subscription_msg_types = {commands.Announce}
6+
subscription_msg_types = frozenset({commands.Announce})

trinity/protocol/les/servers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import (
22
Any,
33
Dict,
4-
Set,
4+
FrozenSet,
55
Type,
66
cast,
77
)
@@ -44,9 +44,9 @@ class LightRequestServer(BaseRequestServer):
4444
Monitor commands from peers, to identify inbound requests that should receive a response.
4545
Handle those inbound requests by querying our local database and replying.
4646
"""
47-
subscription_msg_types: Set[Type[Command]] = {
47+
subscription_msg_types: FrozenSet[Type[Command]] = frozenset({
4848
commands.GetBlockHeaders,
49-
}
49+
})
5050

5151
def __init__(
5252
self,

trinity/sync/full/chain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Dict,
1414
List,
1515
NamedTuple,
16-
Set,
16+
FrozenSet,
1717
Tuple,
1818
Type,
1919
cast,
@@ -140,7 +140,7 @@ class BaseBodyChainSyncer(BaseHeaderChainSyncer, PeerSubscriber):
140140
_pending_bodies: Dict[BlockHeader, BlockBody]
141141

142142
# We are only interested in peers entering or leaving the pool
143-
subscription_msg_types: Set[Type[Command]] = set()
143+
subscription_msg_types: FrozenSet[Type[Command]] = frozenset()
144144

145145
# This is a rather arbitrary value, but when the sync is operating normally we never see
146146
# the msg queue grow past a few hundred items, so this should be a reasonable limit for

trinity/sync/full/state.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Iterable,
1212
List,
1313
Set,
14+
FrozenSet,
1415
Tuple,
1516
Type,
1617
)
@@ -101,7 +102,7 @@ def __init__(self,
101102
self._peer_missing_nodes: Dict[ETHPeer, Set[Hash32]] = collections.defaultdict(set)
102103

103104
# We are only interested in peers entering or leaving the pool
104-
subscription_msg_types: Set[Type[Command]] = set()
105+
subscription_msg_types: FrozenSet[Type[Command]] = frozenset()
105106

106107
# This is a rather arbitrary value, but when the sync is operating normally we never see
107108
# the msg queue grow past a few hundred items, so this should be a reasonable limit for

0 commit comments

Comments
 (0)