Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

too many values to unpack (expected 2) on some ContractEvents subscriptions #178

Open
mortimr opened this issue Dec 21, 2024 · 6 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@mortimr
Copy link

mortimr commented Dec 21, 2024

Environment information

  • ape and plugin versions:
$ ape --version
0.8.22

$ ape plugins list
No plugins installed

$ silverback --version
0.6.5
  • Python Version: 3.12.3
  • OS: osx

What went wrong?

I tested silverback by setting up a simple bot to poll on a Stake event on a contract. Some events (it seems the ones that have tuples and custom types in their ABIs) are crashing silverback at startup. Only having the handler with the decorator on the problematic event causes the crash, so it does happen right when silverback starts and not when an event is actually received.

Here's the bot I have

from silverback import SilverbackBot
from ape import Contract

bot = SilverbackBot()

abi = """
[
  {
    "type": "event",
    "name": "Stake",
    "inputs": [
      {
        "name": "staker",
        "type": "address",
        "indexed": true,
        "internalType": "address"
      },
      {
        "name": "recipient",
        "type": "address",
        "indexed": true,
        "internalType": "address"
      },
      {
        "name": "depositedEth",
        "type": "uint128",
        "indexed": false,
        "internalType": "uint128"
      },
      {
        "name": "mintedTokens",
        "type": "uint128",
        "indexed": false,
        "internalType": "uint128"
      },
      {
        "name": "stakeDetails",
        "type": "tuple[]",
        "indexed": false,
        "internalType": "struct PoolStakeDetails[]",
        "components": [
          {
            "name": "poolId",
            "type": "uint128",
            "internalType": "uint128"
          },
          {
            "name": "ethToPool",
            "type": "uint128",
            "internalType": "uint128"
          },
          {
            "name": "ethToIntegrator",
            "type": "uint128",
            "internalType": "uint128"
          },
          {
            "name": "pSharesFromPool",
            "type": "uint128",
            "internalType": "uint128"
          },
          {
            "name": "pSharesFromIntegrator",
            "type": "uint128",
            "internalType": "uint128"
          }
        ]
      }
    ],
    "anonymous": false
  }
]
"""

contract_instance = Contract(address="0x2401c39d7ba9e283668a53fcc7b8f5fd9e716fdf", abi=abi)

@bot.on_(contract_instance.Stake)
def handle_stake():
    print("transfer")

And here's the output I get

➜  silverback silverback run ocv2 --network ethereum:mainnet:$ETH_RPC_URL

INFO:     Connecting to existing Geth node at xxx.
INFO:     Loading Silverback Bot with settings:
  BOT_NAME="bot"
  BROKER_CLASS="taskiq:InMemoryBroker"
  NETWORK_CHOICE="ethereum:mainnet:node"
SUCCESS:  Loaded Silverback Bot:
  NETWORK="ethereum:mainnet"
  FORK_MODE=False
  SIGNER=None
INFO:     Connecting to existing Geth node at xxx.
INFO:     Using PollingRunner: max_exceptions=10
WARNING:  The polling runner makes a significant amount of requests. Do not use in production over long time periods unless you know what you're doing.
INFO:     Worker using Silverback SDK v0.6.5, available task types:
- system:config
- user:event-log
- system:user-all-taskdata
- user:startup
- system:load-snapshot
- user:shutdown
- system:user-taskdata
- system:create-snapshot
- user:new-block
WARNING:  Runtime error(s) detected, shutting down:
too many values to unpack (expected 2)

And exits right after.

I also tried to see if the issue came from ape and made a small script to do the polling manually, but everything works wite ape.

from ape import Contract
from ape.cli import ConnectedProviderCommand
import click

abi = """
[
  {
    "type": "event",
    "name": "Stake",
    "inputs": [
      {
        "name": "staker",
        "type": "address",
        "indexed": true,
        "internalType": "address"
      },
      {
        "name": "recipient",
        "type": "address",
        "indexed": true,
        "internalType": "address"
      },
      {
        "name": "depositedEth",
        "type": "uint128",
        "indexed": false,
        "internalType": "uint128"
      },
      {
        "name": "mintedTokens",
        "type": "uint128",
        "indexed": false,
        "internalType": "uint128"
      },
      {
        "name": "stakeDetails",
        "type": "tuple[]",
        "indexed": false,
        "internalType": "struct PoolStakeDetails[]",
        "components": [
          {
            "name": "poolId",
            "type": "uint128",
            "internalType": "uint128"
          },
          {
            "name": "ethToPool",
            "type": "uint128",
            "internalType": "uint128"
          },
          {
            "name": "ethToIntegrator",
            "type": "uint128",
            "internalType": "uint128"
          },
          {
            "name": "pSharesFromPool",
            "type": "uint128",
            "internalType": "uint128"
          },
          {
            "name": "pSharesFromIntegrator",
            "type": "uint128",
            "internalType": "uint128"
          }
        ]
      }
    ],
    "anonymous": false
  }
]
"""


@click.command(cls=ConnectedProviderCommand)
def cli(network, provider):
    contract_address = "0x2401c39d7ba9e283668a53fcc7b8f5fd9e716fdf"
    contract_instance = Contract(address=contract_address, abi=abi)
    for event in contract_instance.Stake.poll_logs():
        print(event)

And it works as expected, I see logs when the events are found onchain.

Any idea on where the issue might be coming from ? I'm also unable to see any additional traces, and even with max verbosity I have no additional clues.
I can help and give more info / run local tests if needed !

Some of the things I tried, without success:

  • adding more/less parameters to the handler
  • manually tweak the abi to replace the custom type with native types
@mortimr mortimr added the bug Something isn't working label Dec 21, 2024
Copy link

linear bot commented Dec 21, 2024

@fubuloubu
Copy link
Member

handle_stake requires 1 argument for the log data structure from each event log. so change it like this and it should work:

...


@bot.on_(contract_instance.Stake)
def handle_stake(log):
    print("transfer")

@fubuloubu
Copy link
Member

However, will leave this open since the error message should be easier to understand

@mortimr
Copy link
Author

mortimr commented Dec 22, 2024

Sorry, copied the bot script in the latest state I left it. As I mentioned at the end of the issue, I did actually try several combinations for the handler params but still get the error.

I just double checked now with

@bot.on_(contract_instance.Stake)
def handle_stake(stake):
    print("stake", stake)

and got the exact same error

I also tested other events from the same contract

  • simple ones like Transfer work properly
  • there's another event with a custom type that gives me the exact same trouble

Here the other event ABI

  {
    "type": "event",
    "name": "Exit",
    "inputs": [
      {
        "name": "staker",
        "type": "address",
        "indexed": true,
        "internalType": "address"
      },
      {
        "name": "exitedTokens",
        "type": "uint128",
        "indexed": false,
        "internalType": "uint128"
      },
      {
        "name": "exitDetails",
        "type": "tuple[]",
        "indexed": false,
        "internalType": "struct PoolExitDetails[]",
        "components": [
          {
            "name": "poolId",
            "type": "uint128",
            "internalType": "uint128"
          },
          {
            "name": "exitedPoolShares",
            "type": "uint128",
            "internalType": "uint128"
          }
        ]
      }
    ],
    "anonymous": false
  }

It does feel like there's an issue with tuple[] support

@mortimr
Copy link
Author

mortimr commented Jan 2, 2025

Just tested again and it seems that the issue is still here with ape 0.8.24 :/

@dtdang dtdang self-assigned this Jan 2, 2025
@dtdang
Copy link
Contributor

dtdang commented Jan 2, 2025

Just tested again and it seems that the issue is still here with ape 0.8.24 :/

Taking a look at this bug now. I can replicate this error with what you've provided so working on a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants