Skip to content

Commit

Permalink
Insufficient funds is really a special case and its own exception, no…
Browse files Browse the repository at this point in the history
…t a subclass.

It is also not needed as a extra strategy (at least for now), since it is encountered during firing to txs.
It may/may not be considered a fault so left the Fault.INSUFFICIENT_FUNDS enum for now.
More to be explored in a future issue/PR.
  • Loading branch information
derekpierre committed Mar 6, 2024
1 parent 9ea695c commit f42264d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
7 changes: 2 additions & 5 deletions atxm/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum

from web3.types import PendingTx, RPCError, TxReceipt
from web3.types import PendingTx, TxReceipt


class Fault(Enum):
Expand All @@ -13,9 +13,6 @@ class Fault(Enum):
# Strategy has been running for too long
TIMEOUT = "timeout"

# Transaction has been capped and subsequently timed out
PAUSE = "pause"

# Transaction reverted
REVERT = "revert"

Expand All @@ -26,7 +23,7 @@ class Fault(Enum):
INSUFFICIENT_FUNDS = "insufficient_funds"


class InsufficientFunds(RPCError):
class InsufficientFunds(Exception):
"""raised when a transaction exceeds the spending cap"""


Expand Down
2 changes: 0 additions & 2 deletions atxm/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from atxm.strategies import (
AsyncTxStrategy,
ExponentialSpeedupStrategy,
InsufficientFundsPause,
TimeoutStrategy,
)
from atxm.tracker import _TxTracker
Expand Down Expand Up @@ -97,7 +96,6 @@ class _Machine(StateMachine):
_BLOCK_SAMPLE_SIZE = 10_000 # blocks

STRATEGIES: List[Type[AsyncTxStrategy]] = [
InsufficientFundsPause,
TimeoutStrategy,
ExponentialSpeedupStrategy,
]
Expand Down
20 changes: 0 additions & 20 deletions atxm/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,6 @@ def execute(self, pending: PendingTx) -> Optional[TxParams]:
raise NotImplementedError


class InsufficientFundsPause(AsyncTxStrategy):
"""Pause strategy for pending transactions."""

_NAME = "insufficient-funds"

def execute(self, pending: PendingTx) -> Optional[TxParams]:
balance = self.w3.eth.get_balance(pending.params["from"])
if balance == 0:
self.log.warn(
f"Insufficient funds for transaction #{pending.params['nonce']}"
)
raise TransactionFaulted(
tx=pending,
fault=Fault.INSUFFICIENT_FUNDS,
message="Insufficient funds",
)
# log.warn(f"Insufficient funds for transaction #{pending.params['nonce']}")
return None


class TimeoutStrategy(AsyncTxStrategy):
"""Timeout strategy for pending transactions."""

Expand Down

0 comments on commit f42264d

Please sign in to comment.