Skip to content

Commit aa66a4e

Browse files
committed
Fix mypy issues in missed packages
1 parent 3fb837e commit aa66a4e

5 files changed

Lines changed: 52 additions & 32 deletions

File tree

raiden/network/resolver/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from eth_utils import to_bytes, to_hex
55

66
from raiden.raiden_service import RaidenService
7+
from raiden.storage.wal import WriteAheadLog
78
from raiden.transfer.mediated_transfer.events import SendSecretRequest
89
from raiden.transfer.mediated_transfer.state_change import ReceiveSecretReveal
910

@@ -15,6 +16,7 @@ def reveal_secret_with_resolver(
1516
if "resolver_endpoint" not in raiden.config:
1617
return False
1718

19+
assert isinstance(raiden.wal, WriteAheadLog), "RaidenService has not been started"
1820
current_state = raiden.wal.state_manager.current_state
1921
task = current_state.payment_mapping.secrethashes_to_task[secret_request_event.secrethash]
2022
token = task.target_state.transfer.token

raiden/storage/migrations/v17_to_v18.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_token_network_by_identifier(
2020
return None
2121

2222

23-
def _transform_snapshot(raw_snapshot: Dict[Any, Any]) -> str:
23+
def _transform_snapshot(raw_snapshot: str) -> str:
2424
"""
2525
This migration upgrades the object:
2626
- `MediatorTransferState` such that a list of routes is added
@@ -48,7 +48,11 @@ def _transform_snapshot(raw_snapshot: Dict[Any, Any]) -> str:
4848
token_network_identifier = transfer["balance_proof"]["token_network_identifier"]
4949
token_network = get_token_network_by_identifier(snapshot, token_network_identifier)
5050
channel_identifier = transfer["balance_proof"]["channel_identifier"]
51-
channel = token_network.get("channelidentifiers_to_channels").get(channel_identifier)
51+
channel = None
52+
if token_network is not None:
53+
channel = token_network.get("channelidentifiers_to_channels", {}).get(
54+
channel_identifier
55+
)
5256
if not channel:
5357
raise ChannelNotFound(
5458
f"Upgrading to v18 failed. "

raiden/storage/migrations/v18_to_v19.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BlockHashCache:
2222

2323
def __init__(self, web3: Web3):
2424
self.web3 = web3
25-
self.mapping = {}
25+
self.mapping: Dict[BlockNumber, str] = {}
2626

2727
def get(self, block_number: BlockNumber) -> str:
2828
"""Given a block number returns the hex representation of the blockhash"""
@@ -47,7 +47,7 @@ def _query_blocknumber_and_update_statechange_data(
4747
) -> Tuple[str, int]:
4848
data = record.data
4949
data["block_hash"] = record.cache.get(record.block_number)
50-
return (json.dumps(data), record.state_change_identifier)
50+
return json.dumps(data), record.state_change_identifier
5151

5252

5353
def _add_blockhash_to_state_changes(storage: SQLiteStorage, cache: BlockHashCache) -> None:
@@ -69,7 +69,7 @@ def _add_blockhash_to_state_changes(storage: SQLiteStorage, cache: BlockHashCach
6969
data = json.loads(state_change.data)
7070
assert "block_hash" not in data, "v18 state changes cant contain blockhash"
7171
record = BlockQueryAndUpdateRecord(
72-
block_number=int(data["block_number"]),
72+
block_number=BlockNumber(int(data["block_number"])),
7373
data=data,
7474
state_change_identifier=state_change.state_change_identifier,
7575
cache=cache,
@@ -112,7 +112,7 @@ def _add_blockhash_to_events(storage: SQLiteStorage, cache: BlockHashCache) -> N
112112
if "block_hash" in statechange_data:
113113
data["triggered_by_block_hash"] = statechange_data["block_hash"]
114114
elif "block_number" in statechange_data:
115-
block_number = int(statechange_data["block_number"])
115+
block_number = BlockNumber(int(statechange_data["block_number"]))
116116
data["triggered_by_block_hash"] = cache.get(block_number)
117117

118118
updated_events.append((json.dumps(data), event.event_identifier))
@@ -123,7 +123,7 @@ def _add_blockhash_to_events(storage: SQLiteStorage, cache: BlockHashCache) -> N
123123
def _transform_snapshot(raw_snapshot: str, storage: SQLiteStorage, cache: BlockHashCache) -> str:
124124
"""Upgrades a single snapshot by adding the blockhash to it and to any pending transactions"""
125125
snapshot = json.loads(raw_snapshot)
126-
block_number = int(snapshot["block_number"])
126+
block_number = BlockNumber(int(snapshot["block_number"]))
127127
snapshot["block_hash"] = cache.get(block_number)
128128

129129
pending_transactions = snapshot["pending_transactions"]
@@ -158,7 +158,7 @@ class TransformSnapshotRecord(NamedTuple):
158158
cache: BlockHashCache
159159

160160

161-
def _do_transform_snapshot(record: TransformSnapshotRecord) -> Tuple[Dict[str, Any], int]:
161+
def _do_transform_snapshot(record: TransformSnapshotRecord) -> Tuple[str, int]:
162162
new_snapshot = _transform_snapshot(
163163
raw_snapshot=record.data, storage=record.storage, cache=record.cache
164164
)

raiden/storage/migrations/v19_to_v20.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
import json
22
from functools import partial
3+
from typing import TYPE_CHECKING
34

45
from eth_utils import to_canonical_address
56
from gevent.pool import Pool
67

78
from raiden.constants import EMPTY_MERKLE_ROOT
89
from raiden.exceptions import RaidenUnrecoverableError
910
from raiden.network.proxies.utils import get_onchain_locksroots
10-
from raiden.storage.sqlite import SQLiteStorage, StateChangeRecord
11+
from raiden.storage.sqlite import SnapshotRecord, SQLiteStorage, StateChangeRecord
1112
from raiden.transfer.identifiers import CanonicalIdentifier
1213
from raiden.utils.serialization import serialize_bytes
13-
from raiden.utils.typing import Any, Dict, Locksroot, Tuple
14+
from raiden.utils.typing import (
15+
Any,
16+
ChainID,
17+
ChannelID,
18+
Dict,
19+
Locksroot,
20+
TokenNetworkAddress,
21+
Tuple,
22+
)
23+
24+
if TYPE_CHECKING:
25+
# pylint: disable=unused-import
26+
from raiden.raiden_service import RaidenService # noqa: F401
1427

15-
RaidenService = "RaidenService"
1628

1729
SOURCE_VERSION = 19
1830
TARGET_VERSION = 20
@@ -31,7 +43,7 @@ def _find_channel_new_state_change(
3143

3244

3345
def _get_onchain_locksroots(
34-
raiden: RaidenService,
46+
raiden: "RaidenService",
3547
storage: SQLiteStorage,
3648
token_network: Dict[str, Any],
3749
channel: Dict[str, Any],
@@ -49,9 +61,9 @@ def _get_onchain_locksroots(
4961
)
5062

5163
canonical_identifier = CanonicalIdentifier(
52-
chain_identifier=-1,
53-
token_network_address=to_canonical_address(token_network["address"]),
54-
channel_identifier=int(channel["identifier"]),
64+
chain_identifier=ChainID(-1),
65+
token_network_address=TokenNetworkAddress(to_canonical_address(token_network["address"])),
66+
channel_identifier=ChannelID(int(channel["identifier"])),
5567
)
5668

5769
our_locksroot, partner_locksroot = get_onchain_locksroots(
@@ -96,7 +108,7 @@ def _add_onchain_locksroot_to_channel_new_state_changes(storage: SQLiteStorage,)
96108

97109

98110
def _add_onchain_locksroot_to_channel_settled_state_changes(
99-
raiden: RaidenService, storage: SQLiteStorage
111+
raiden: "RaidenService", storage: SQLiteStorage
100112
) -> None:
101113
""" Adds `our_onchain_locksroot` and `partner_onchain_locksroot` to
102114
ContractReceiveChannelSettled. """
@@ -134,9 +146,11 @@ def _add_onchain_locksroot_to_channel_settled_state_changes(
134146
new_channel_state = channel_state_data["channel_state"]
135147

136148
canonical_identifier = CanonicalIdentifier(
137-
chain_identifier=-1,
138-
token_network_address=to_canonical_address(token_network_identifier),
139-
channel_identifier=int(channel_identifier),
149+
chain_identifier=ChainID(-1),
150+
token_network_address=TokenNetworkAddress(
151+
to_canonical_address(token_network_identifier)
152+
),
153+
channel_identifier=ChannelID(int(channel_identifier)),
140154
)
141155
our_locksroot, partner_locksroot = get_onchain_locksroots(
142156
chain=raiden.chain,
@@ -156,8 +170,8 @@ def _add_onchain_locksroot_to_channel_settled_state_changes(
156170

157171

158172
def _add_onchain_locksroot_to_snapshot(
159-
raiden: RaidenService, storage: SQLiteStorage, snapshot_record: StateChangeRecord
160-
) -> str:
173+
raiden: "RaidenService", storage: SQLiteStorage, snapshot_record: SnapshotRecord
174+
) -> Tuple[str, int]:
161175
"""
162176
Add `onchain_locksroot` to each NettingChannelEndState
163177
"""
@@ -178,7 +192,7 @@ def _add_onchain_locksroot_to_snapshot(
178192
return json.dumps(snapshot, indent=4), snapshot_record.identifier
179193

180194

181-
def _add_onchain_locksroot_to_snapshots(raiden: RaidenService, storage: SQLiteStorage) -> None:
195+
def _add_onchain_locksroot_to_snapshots(raiden: "RaidenService", storage: SQLiteStorage) -> None:
182196
snapshots = storage.get_snapshots()
183197

184198
transform_func = partial(_add_onchain_locksroot_to_snapshot, raiden, storage)

raiden/storage/migrations/v21_to_v22.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import TYPE_CHECKING, TypeVar
2+
from typing import TYPE_CHECKING, Tuple, TypeVar
33

44
from eth_utils import to_checksum_address
55

@@ -16,15 +16,15 @@
1616

1717
BATCH_UNLOCK = "raiden.transfer.state_change.ContractReceiveChannelBatchUnlock"
1818

19-
SPELLING_VARS_TOKEN_NETWORK = (
19+
SPELLING_VARS_TOKEN_NETWORK = [
2020
"token_network_address",
2121
"token_network_id",
2222
"token_network_identifier",
23-
)
23+
]
2424

25-
SPELLING_VARS_CHANNEL = ("channel_identifier", "channel_id", "identifier")
25+
SPELLING_VARS_CHANNEL = ["channel_identifier", "channel_id", "identifier"]
2626

27-
SPELLING_VARS_CHAIN = ("chain_id", "chain_identifier")
27+
SPELLING_VARS_CHAIN = ["chain_id", "chain_identifier"]
2828

2929

3030
# these are missing the chain-id
@@ -224,8 +224,8 @@ def _add_canonical_identifier_to_statechanges(
224224
our_address = str(to_checksum_address(raiden.address)).lower()
225225

226226
for state_change_batch in storage.batch_query_state_changes(batch_size=500):
227-
updated_state_changes = list()
228-
delete_state_changes = list()
227+
updated_state_changes: List[Tuple[str, int]] = list()
228+
delete_state_changes: List[int] = list()
229229

230230
for state_change_record in state_change_batch:
231231
state_change_obj = json.loads(state_change_record.data)
@@ -236,16 +236,16 @@ def _add_canonical_identifier_to_statechanges(
236236
)
237237

238238
if should_delete:
239-
delete_state_changes.append(state_change_record.identifier)
239+
delete_state_changes.append(state_change_record.state_change_identifier)
240240
else:
241-
channel_id = None
241+
channel_id: Optional[int] = None
242242
if is_unlock:
243243
channel_id = resolve_channel_id_for_unlock(
244244
storage, state_change_obj, our_address
245245
)
246246
walk_dicts(
247247
state_change_obj,
248-
lambda obj, channel_id=channel_id: upgrade_object(obj, chain_id, channel_id),
248+
lambda obj, channel_id_=channel_id: upgrade_object(obj, chain_id, channel_id_),
249249
)
250250

251251
walk_dicts(state_change_obj, constraint_has_canonical_identifier_or_values_removed)

0 commit comments

Comments
 (0)