ApeWorX / ApePay

A smart contract payment system built for automated service management
https://apeworx.io/apepay
Apache License 2.0
18 stars 5 forks source link

bug: OverflowError: Python int too large to convert to C int #65

Closed mikeshultz closed 8 months ago

mikeshultz commented 8 months ago

Seen just now on sepolia. Will see about instrumenting more tomorrow:

Traceback (most recent call last):
  File "/app/.venv/bin/silverback", line 8, in <module>
    sys.exit(cli())
  File "/app/.venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/app/.venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/app/.venv/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/app/.venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/app/.venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/app/.venv/lib/python3.10/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/app/.venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/app/.venv/lib/python3.10/site-packages/silverback/_cli.py", line 59, in run
    asyncio.run(runner.run())
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/app/.venv/lib/python3.10/site-packages/silverback/runner.py", line 58, in run
    await self.app.broker.startup()
  File "/app/.venv/lib/python3.10/site-packages/taskiq/brokers/inmemory_broker.py", line 159, in startup
    await maybe_awaitable(handler(self.state))
  File "/app/.venv/lib/python3.10/site-packages/taskiq/utils.py", line 23, in maybe_awaitable
    return await possible_coroutine
  File "/app/deployments/daemon.py", line 44, in app_started
    for stream in SM.active_streams(start_block=settings.APEPAY_START_BLOCK):
  File "/app/.venv/lib/python3.10/site-packages/apepay/__init__.py", line 292, in active_streams
    if stream.is_active:
  File "/app/.venv/lib/python3.10/site-packages/apepay/__init__.py", line 445, in is_active
    return self.time_left.total_seconds() > 0
  File "/app/.venv/lib/python3.10/site-packages/apepay/__init__.py", line 430, in time_left
    return timedelta(seconds=self.contract.time_left(self.creator, self.stream_id))
OverflowError: Python int too large to convert to C int
mikeshultz commented 8 months ago

Alright, found a (the?) stream that triggers this error on Sepolia:

It appears that it's not even a large amount of tokens, but a very small amount_per_second causing the issue:

>>> now = int(datetime.utcnow().timestamp())
>>> last_pull = 1697577384
>>> funded_amount = 1000000000008640000
>>> amount_per_second = 100
>>> amount_unlocked = min((now - last_pull) * amount_per_second, funded_amount)
>>> amount_unlocked
87882700
>>> (funded_amount - amount_unlocked) / amount_per_second
9999999999207572.0
>>> int(9999999999207572.0)
9999999999207572
>>> timedelta(seconds=9999999999207572)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C int

So it seems to be a limitation in timedelta. Which honestly is fair, because this stream is funded for over 317 million years.

fubuloubu commented 8 months ago

So it seems to be a limitation in timedelta. Which honestly is fair, because this stream is funded for over 317 million years.

yeah, so like... probably should just raise, since that's unlikely to be a legitimate time to use