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

Aio: Unable to reconnect another node #164

Closed
biobdeveloper opened this issue May 27, 2020 · 3 comments
Closed

Aio: Unable to reconnect another node #164

biobdeveloper opened this issue May 27, 2020 · 3 comments

Comments

@biobdeveloper
Copy link

biobdeveloper commented May 27, 2020

I try to change node in connected aio.bitshares instance, but receive an error:

from bitshares.aio.graphene import BitShares

async def foo():
    bitshares_instance = BitShares(node="wss://node_1")
    await bitshares_instance.connect()
    assert bitshares_instance.is_connected()
    bitshares_instance.rpc.url = "wss://node_2"
    await bitshares_instance.connect()


/graphenecommon/aio/chain.py", line 43, in connect
    await self.rpc.connect()
/grapheneapi/aio/api.py", line 48, in connect
    await self.next()
grapheneapi/aio/api.py", line 56, in next
    await self.connection.disconnect()
AttributeError: 'function' object has no attribute 'disconnect'
@biobdeveloper biobdeveloper changed the title Aio: Unable to reconnect another node in aio Aio: Unable to reconnect another node May 27, 2020
bitphage added a commit to bitshares/python-bitshares that referenced this issue May 28, 2020
@bitphage
Copy link
Contributor

  1. You do it in a wrong way.
  2. The bug you discovered was due to double-call of await bitshres_instance.connect() which I fixed.

Why this is a wrong way:

  1. await bitshares_instance.connect() instantiates an RPC instance (Websocket or Http).
  2. Then you're changing it's url bitshares_instance.rpc.url = ...
  3. but then you're crating a new RPC instance via await bitshares_instance.connect() with initial url, e.g. step 2 is just lost.

Correct way should be

    bitshares_instance = BitShares(node="wss://node_1")
    await bitshares_instance.connect()
    bitshares_instance.rpc.url = "wss://node_2"
    await bitshares_instance.rpc.connect()

But I wonder why you're not using multiple nodes and next() call?

nodes = ['wss://node_1', 'wss://node_2']
bitshares_instance = BitShares(node=nodes)
await bitshares_instance.connect()
await bitshares_instance.rpc.next()  # switch node

@biobdeveloper
Copy link
Author

biobdeveloper commented May 28, 2020

But if I need to switch determined node, what I need to do? Seems like .rpc.next() just iterate over list, without choosing node by user

@bitphage
Copy link
Contributor

Then use "correct way" solution.

@xeroc xeroc closed this as completed in bb237db Jun 23, 2020
xeroc pushed a commit to bitshares/python-bitshares that referenced this issue Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants