iwa 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iwa/core/chain/interface.py +3 -0
- iwa/core/services/transaction.py +77 -44
- {iwa-0.1.1.dist-info → iwa-0.1.2.dist-info}/METADATA +1 -1
- {iwa-0.1.1.dist-info → iwa-0.1.2.dist-info}/RECORD +8 -8
- {iwa-0.1.1.dist-info → iwa-0.1.2.dist-info}/WHEEL +0 -0
- {iwa-0.1.1.dist-info → iwa-0.1.2.dist-info}/entry_points.txt +0 -0
- {iwa-0.1.1.dist-info → iwa-0.1.2.dist-info}/licenses/LICENSE +0 -0
- {iwa-0.1.1.dist-info → iwa-0.1.2.dist-info}/top_level.txt +0 -0
iwa/core/chain/interface.py
CHANGED
|
@@ -94,6 +94,9 @@ class ChainInterface:
|
|
|
94
94
|
"""Get the current active RPC URL."""
|
|
95
95
|
if not self.chain.rpcs:
|
|
96
96
|
return ""
|
|
97
|
+
# Ensure index is valid (could be stale after rpcs list changes or singleton reuse)
|
|
98
|
+
if self._current_rpc_index >= len(self.chain.rpcs):
|
|
99
|
+
self._current_rpc_index = 0
|
|
97
100
|
return self.chain.rpcs[self._current_rpc_index]
|
|
98
101
|
|
|
99
102
|
@property
|
iwa/core/services/transaction.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Transaction service module."""
|
|
2
2
|
|
|
3
|
+
import threading
|
|
3
4
|
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple
|
|
4
5
|
|
|
5
6
|
from loguru import logger
|
|
@@ -220,12 +221,29 @@ class TransferLogger:
|
|
|
220
221
|
class TransactionService:
|
|
221
222
|
"""Manages transaction lifecycle: signing, sending, retrying."""
|
|
222
223
|
|
|
224
|
+
# Class-level lock for managing per-address locks
|
|
225
|
+
_locks_lock = threading.Lock()
|
|
226
|
+
_address_locks: Dict[str, threading.Lock] = {}
|
|
227
|
+
|
|
223
228
|
def __init__(self, key_storage: KeyStorage, account_service: AccountService, safe_service=None):
|
|
224
229
|
"""Initialize TransactionService."""
|
|
225
230
|
self.key_storage = key_storage
|
|
226
231
|
self.account_service = account_service
|
|
227
232
|
self.safe_service = safe_service
|
|
228
233
|
|
|
234
|
+
@classmethod
|
|
235
|
+
def _get_address_lock(cls, address: str) -> threading.Lock:
|
|
236
|
+
"""Get or create a lock for a specific address.
|
|
237
|
+
|
|
238
|
+
This prevents nonce collisions when sending multiple transactions
|
|
239
|
+
from the same address concurrently.
|
|
240
|
+
"""
|
|
241
|
+
address_lower = address.lower()
|
|
242
|
+
with cls._locks_lock:
|
|
243
|
+
if address_lower not in cls._address_locks:
|
|
244
|
+
cls._address_locks[address_lower] = threading.Lock()
|
|
245
|
+
return cls._address_locks[address_lower]
|
|
246
|
+
|
|
229
247
|
def _resolve_label(self, address: str, chain_name: str = "gnosis") -> str:
|
|
230
248
|
"""Resolve address to human-readable label."""
|
|
231
249
|
if not address:
|
|
@@ -255,69 +273,84 @@ class TransactionService:
|
|
|
255
273
|
|
|
256
274
|
Uses ChainInterface.with_retry() for consistent RPC rotation and retry logic.
|
|
257
275
|
Gas errors are handled by increasing gas and retrying within the same mechanism.
|
|
276
|
+
|
|
277
|
+
Note: Uses per-address locking to prevent nonce collisions when multiple
|
|
278
|
+
transactions are sent from the same address concurrently.
|
|
258
279
|
"""
|
|
259
280
|
chain_interface = ChainInterfaces().get(chain_name)
|
|
260
281
|
tx = dict(transaction)
|
|
261
282
|
|
|
262
|
-
|
|
283
|
+
# Resolve signer first to get the address for locking
|
|
284
|
+
signer_account = self.account_service.resolve_account(signer_address_or_tag)
|
|
285
|
+
if not signer_account:
|
|
286
|
+
logger.error(f"Signer {signer_address_or_tag} not found")
|
|
263
287
|
return False, {}
|
|
264
288
|
|
|
265
|
-
# CHECK FOR SAFE TRANSACTION
|
|
266
|
-
signer_account = self.account_service.resolve_account(signer_address_or_tag)
|
|
289
|
+
# CHECK FOR SAFE TRANSACTION (Safe has its own nonce management)
|
|
267
290
|
if isinstance(signer_account, StoredSafeAccount):
|
|
268
291
|
if not self.safe_service:
|
|
269
292
|
logger.error("Attempted Safe transaction but SafeService is not initialized.")
|
|
270
293
|
return False, {}
|
|
294
|
+
# Safe transactions don't need EOA nonce locking
|
|
295
|
+
if not self._prepare_transaction(tx, signer_address_or_tag, chain_interface):
|
|
296
|
+
return False, {}
|
|
271
297
|
return self._execute_via_safe(tx, signer_account, chain_interface, chain_name, tags)
|
|
272
298
|
|
|
273
|
-
#
|
|
274
|
-
|
|
299
|
+
# Acquire lock for this address to prevent nonce collisions
|
|
300
|
+
address_lock = self._get_address_lock(signer_account.address)
|
|
301
|
+
with address_lock:
|
|
302
|
+
if not self._prepare_transaction(tx, signer_address_or_tag, chain_interface):
|
|
303
|
+
return False, {}
|
|
275
304
|
|
|
276
|
-
|
|
277
|
-
""
|
|
278
|
-
try:
|
|
279
|
-
signed_txn = self.key_storage.sign_transaction(tx, signer_address_or_tag)
|
|
280
|
-
txn_hash = chain_interface.web3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
|
281
|
-
receipt = chain_interface.web3.eth.wait_for_transaction_receipt(txn_hash)
|
|
305
|
+
# Mutable state for retry attempts
|
|
306
|
+
state = {"gas_retries": 0, "max_gas_retries": 5}
|
|
282
307
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
308
|
+
def _do_sign_send_wait() -> Tuple[bool, Dict, bytes]:
|
|
309
|
+
"""Inner operation wrapped by with_retry."""
|
|
310
|
+
try:
|
|
311
|
+
signed_txn = self.key_storage.sign_transaction(tx, signer_address_or_tag)
|
|
312
|
+
txn_hash = chain_interface.web3.eth.send_raw_transaction(
|
|
313
|
+
signed_txn.raw_transaction
|
|
314
|
+
)
|
|
315
|
+
receipt = chain_interface.web3.eth.wait_for_transaction_receipt(txn_hash)
|
|
286
316
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
logger.error("Transaction failed (status 0).")
|
|
291
|
-
raise ValueError("Transaction reverted")
|
|
317
|
+
status = getattr(receipt, "status", None)
|
|
318
|
+
if status is None and isinstance(receipt, dict):
|
|
319
|
+
status = receipt.get("status")
|
|
292
320
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
321
|
+
if receipt and status == 1:
|
|
322
|
+
return True, receipt, txn_hash
|
|
323
|
+
# Transaction mined but reverted - don't retry
|
|
324
|
+
logger.error("Transaction failed (status 0).")
|
|
325
|
+
raise ValueError("Transaction reverted")
|
|
297
326
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
self._log_successful_transaction(
|
|
308
|
-
receipt, tx, signer_account, chain_name, txn_hash, tags, chain_interface
|
|
327
|
+
except web3_exceptions.Web3RPCError as e:
|
|
328
|
+
# Handle gas errors by increasing gas and re-raising
|
|
329
|
+
self._handle_gas_retry(e, tx, state)
|
|
330
|
+
raise # Re-raise to trigger with_retry's retry mechanism
|
|
331
|
+
|
|
332
|
+
try:
|
|
333
|
+
success, receipt, txn_hash = chain_interface.with_retry(
|
|
334
|
+
_do_sign_send_wait,
|
|
335
|
+
operation_name=f"sign_and_send to {tx.get('to', 'unknown')[:10]}...",
|
|
309
336
|
)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
337
|
+
if success:
|
|
338
|
+
chain_interface.wait_for_no_pending_tx(signer_account.address)
|
|
339
|
+
logger.info(f"Transaction sent successfully. Tx Hash: {txn_hash.hex()}")
|
|
340
|
+
self._log_successful_transaction(
|
|
341
|
+
receipt, tx, signer_account, chain_name, txn_hash, tags, chain_interface
|
|
342
|
+
)
|
|
343
|
+
return True, receipt
|
|
344
|
+
return False, {}
|
|
345
|
+
except ValueError as e:
|
|
346
|
+
# Transaction reverted - already logged
|
|
347
|
+
if "reverted" in str(e).lower():
|
|
348
|
+
return False, {}
|
|
349
|
+
logger.exception(f"Transaction failed: {e}")
|
|
350
|
+
return False, {}
|
|
351
|
+
except Exception as e:
|
|
352
|
+
logger.exception(f"Transaction failed after retries: {e}")
|
|
315
353
|
return False, {}
|
|
316
|
-
logger.exception(f"Transaction failed: {e}")
|
|
317
|
-
return False, {}
|
|
318
|
-
except Exception as e:
|
|
319
|
-
logger.exception(f"Transaction failed after retries: {e}")
|
|
320
|
-
return False, {}
|
|
321
354
|
|
|
322
355
|
def _prepare_transaction(self, tx: dict, signer_tag: str, chain_interface) -> bool:
|
|
323
356
|
"""Ensure nonce and chainId are set."""
|
|
@@ -23,7 +23,7 @@ iwa/core/utils.py,sha256=FTYpIdQ1wnugD4lYU4TQ7d7_TlDs4CTUIhEpHGEJph4,4281
|
|
|
23
23
|
iwa/core/wallet.py,sha256=xSGFOK5Wzh-ctLGhBMK1BySlXN0Ircpztyk1an21QiQ,13129
|
|
24
24
|
iwa/core/chain/__init__.py,sha256=XJMmn0ed-_aVkY2iEMKpuTxPgIKBd41dexSVmEZTa-o,1604
|
|
25
25
|
iwa/core/chain/errors.py,sha256=9SEbhxZ-qASPkzt-DoI51qq0GRJVqRgqgL720gO7a64,1275
|
|
26
|
-
iwa/core/chain/interface.py,sha256=
|
|
26
|
+
iwa/core/chain/interface.py,sha256=Z7AcLjlYRw8uBj1zklVGep8Z21T-uBCamW48df7w0ew,30952
|
|
27
27
|
iwa/core/chain/manager.py,sha256=XHwn7ciapFCZVk0rPSJopUqM5Wu3Kpp6XrenkgTE1HA,1397
|
|
28
28
|
iwa/core/chain/models.py,sha256=WUhAighMKcFdbAUkPU_3dkGbWyAUpRJqXMHLcWFC1xg,5261
|
|
29
29
|
iwa/core/chain/rate_limiter.py,sha256=Ps1MrR4HHtylxgUAawe6DoC9tuqKagjQdKulqcJD2gs,9093
|
|
@@ -42,7 +42,7 @@ iwa/core/services/balance.py,sha256=MSCEzPRDPlHIjaWD1A2X2oIuiMz5MFJjD7sSHUxQ8OM,
|
|
|
42
42
|
iwa/core/services/plugin.py,sha256=GNNlbtELyHl7MNVChrypF76GYphxXduxDog4kx1MLi8,3277
|
|
43
43
|
iwa/core/services/safe.py,sha256=HG3yAN5IdNR45uuHfjAuaT4XVy_tiivoMTQLoEHlEwY,15701
|
|
44
44
|
iwa/core/services/safe_executor.py,sha256=uZIoE_VeB0B9b-HhZ5jNWXna1kr8e_LZ8qEt63kGxIU,17082
|
|
45
|
-
iwa/core/services/transaction.py,sha256=
|
|
45
|
+
iwa/core/services/transaction.py,sha256=eh--51bAA3rbK1gPjfk7zA5Gm9GJ7CJ82uzG4O5A-Rs,21501
|
|
46
46
|
iwa/core/services/transfer/__init__.py,sha256=7p22xtwrH0murXWTuTGNw0WRKBDqjJEnnVaUpWd8Vfo,5589
|
|
47
47
|
iwa/core/services/transfer/base.py,sha256=sohz-Ss2i-pGYGl4x9bD93cnYKcSvsXaXyvyRawvgQs,9043
|
|
48
48
|
iwa/core/services/transfer/erc20.py,sha256=e6RD1_QcI_-iJvP85kj7aw4p6NnCPjZcm-QSKi14RRA,10104
|
|
@@ -166,7 +166,7 @@ iwa/web/tests/test_web_endpoints.py,sha256=vA25YghHNB23sbmhD4ciesn_f_okSq0tjlkrS
|
|
|
166
166
|
iwa/web/tests/test_web_olas.py,sha256=GunKEAzcbzL7FoUGMtEl8wqiqwYwA5lB9sOhfCNj0TA,16312
|
|
167
167
|
iwa/web/tests/test_web_swap.py,sha256=7A4gBJFL01kIXPtW1E1J17SCsVc_0DmUn-R8kKrnnVA,2974
|
|
168
168
|
iwa/web/tests/test_web_swap_coverage.py,sha256=zGNrzlhZ_vWDCvWmLcoUwFgqxnrp_ACbo49AtWBS_Kw,5584
|
|
169
|
-
iwa-0.1.
|
|
169
|
+
iwa-0.1.2.dist-info/licenses/LICENSE,sha256=eIubm_IlBHPYRQlLNZKbBNKhJUUP3JH0A2miZUhAVfI,1078
|
|
170
170
|
tests/legacy_cow.py,sha256=oOkZvIxL70ReEoD9oHQbOD5GpjIr6AGNHcOCgfPlerU,8389
|
|
171
171
|
tests/legacy_safe.py,sha256=AssM2g13E74dNGODu_H0Q0y412lgqsrYnEzI97nm_Ts,2972
|
|
172
172
|
tests/legacy_transaction_retry_logic.py,sha256=D9RqZ7DBu61Xr2djBAodU2p9UE939LL-DnQXswX5iQk,1497
|
|
@@ -224,8 +224,8 @@ tests/test_utils.py,sha256=vkP49rYNI8BRzLpWR3WnKdDr8upeZjZcs7Rx0pjbQMo,1292
|
|
|
224
224
|
tests/test_workers.py,sha256=MInwdkFY5LdmFB3o1odIaSD7AQZb3263hNafO1De5PE,2793
|
|
225
225
|
tools/create_and_stake_service.py,sha256=1xwy_bJQI1j9yIQ968Oc9Db_F6mk1659LuuZntTASDE,3742
|
|
226
226
|
tools/verify_drain.py,sha256=PkMjblyOOAuQge88FwfEzRtCYeEtJxXhPBmtQYCoQ-8,6743
|
|
227
|
-
iwa-0.1.
|
|
228
|
-
iwa-0.1.
|
|
229
|
-
iwa-0.1.
|
|
230
|
-
iwa-0.1.
|
|
231
|
-
iwa-0.1.
|
|
227
|
+
iwa-0.1.2.dist-info/METADATA,sha256=5YMpXIjANu_J3sb6-iP2cCGT0cFTMTVKg6qRw9RMVqg,7336
|
|
228
|
+
iwa-0.1.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
229
|
+
iwa-0.1.2.dist-info/entry_points.txt,sha256=nwB6kscrfA7M00pYmL2j-sBH6eF6h2ga9IK1BZxdiyQ,241
|
|
230
|
+
iwa-0.1.2.dist-info/top_level.txt,sha256=kedS9cRUbm4JE2wYeabIXilhHjN8KCw0IGbqqqsw0Bs,16
|
|
231
|
+
iwa-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|