ethereum / pyethapp

MIT License
1.28k stars 604 forks source link

Can't spend Ether eth.transact() on livenet #218

Open AndreMiras opened 7 years ago

AndreMiras commented 7 years ago

Hi, I'm working on a cross platform wallet and I thought I could reuse most of the pyethapp code base. I'm trying to spend Ether on the livenet (also tried on the testnet) using pyethapp run --console. I've installed pyethapp from pypi and on a virtualenv.

pip install pyelliptic==1.5.7 pyethapp

Also my node is not synced to the network, but I though having the correct nonce, enough ETH and signing/broadcasting the transaction it was enough.

Checklist

System/environment

Expected behaviour

The expected behaviour would be to see my transaction on Etherscan and also in the pyethapp console.

>>> eth.find_transaction(tx)
{'block': <Block(...)>, 'index': 0, 'tx': <Transaction(ded9)>}

Observed behaviour

Instead I can never see it on Etherscan nor on the pyethapp console.

>>> eth.find_transaction(tx)
{}

Steps to reproduce

Here is a docstring-style with comments of what I have tried so far:

>>> # sender has 0.1 ETH, but pyethapp is not sync with the network
>>> sender = eth.services.accounts[0]
>>> receiver = eth.services.accounts[1]
>>> sender.unlock("***hidden***")
>>> tx = eth.transact(
... to=receiver.address.encode("hex"),
... sender=sender.address.encode("hex"),
... value=100)
>>> tx
<Transaction(ded9)>
>>> tx.hash.encode("hex")
ded9529e201d8e621cd161776706a5640c1d7fa97ec0ba55b73f08f1c75d52dc
>>> # I have never spent any ETH on the sender address
>>> # so even though I'm not sync, the nonce should (and seems to) be correct
>>> tx.nonce
0
>>> # I though the transaction was supposed to be broadcasted to peers
>>> eth.find_transaction(tx)
{}
>>> # but peers are often quite empty
>>> eth.app.services.peermanager.peers
[]
>>> # even though sometimes I see some
>>> eth.app.services.peermanager.peers
[<Peer('52.16.188.185', 30303) >]

I've also tried the develop branch, but I had other issues. I've also tested on the Testnet, like https://ethereum.stackexchange.com/q/6026, but I'm having the same issue. Also I know some Python and I love Ethereum so I'm totally willing to help (write code, doc, tests) if you give me some hints.

janx commented 7 years ago

Hi @AndreMiras, thanks for the details.

  1. is there ether in account in the not-synced chain?
  2. is there any peers connected when you do transact()? Notice even there is peer connected, the peer might not be on mainnet because master branch misses some chain detection code, which will make tx fail to broadcast.

You can use pyethapp -l eth.chainservice:debug,p2p.peermgr:debug run to get more useful log.

I've also tried the develop branch, but I had other issues.

We just merged many features/fixes back to develop (pyethapp/pyethereum/pydevp2p), worth another try :smiling_imp:

Related code:

AndreMiras commented 7 years ago

Hi @janx, thank you for such a quick and useful reply!

is there ether in account in the not-synced chain?

There's 0.1 ETH in total, but since it's not synced (at all) it would display 0 if I tried to display the balance from pyethapp console. Would this be an issue?

is there any peers connected when you do transact()?

I feels like peers come and quickly leave for some reason. So I would say no. Sometimes before the transaction, sometimes after, but rarely during the transaction.

Notice even there is peer connected, the peer might not be on mainnet because master branch misses some chain detection code, which will make tx fail to broadcast.

OK, good to know. I'll read about the discovery protocol.

You can use pyethapp -l eth.chainservice:debug,p2p.peermgr:debug run to get more useful log. I just gave it a quick try (busy this weekend :S). It gives a lot of useful information!

At first sight it seems to receive a lot of "Connection refused". Also I sometimes get some "hello_received" and "num_peers=1", but the peer eventually goes away for an unknown reason. I'll dig into that later.

We just merged many features/fixes back to develop (pyethapp/pyethereum/pydevp2p), worth another try :smiling_imp:

Very nice! I'll give it a try ASAP (probably Monday or Tuesday)! Thank you so much for such useful information.

janx commented 7 years ago

There's 0.1 ETH in total, but since it's not synced (at all) it would display 0 if I tried to display the balance from pyethapp console. Would this be an issue?

Yes, pyethapp will validate the tx before broadcast, since the account balance is 0 it will be invalid.

There's 0.1 ETH in total, but since it's not synced (at all) it would display 0 if I tried to display the balance from pyethapp console. Would this be an issue?

If the tx passed validation, it still won't be broadcast because there's no peer, then it will be discarded.

At first sight it seems to receive a lot of "Connection refused". Also I sometimes get some "hello_received" and "num_peers=1", but the peer eventually goes away for an unknown reason. I'll dig into that later.

Pyethapp master branch only supports eth61 protocol, while most geth/parity nodes is working on eth62/63, so they won't connect.

AndreMiras commented 7 years ago

Yes, pyethapp will validate the tx before broadcast, since the account balance is 0 it will be invalid.

OK it makes sense eth_service.py#L204. I guess I should ignore the InsufficientBalance exception at some point. I'll play with that then.

If the tx passed validation, it still won't be broadcast because there's no peer, then it will be discarded. Pyethapp master branch only supports eth61 protocol, while most geth/parity nodes is working on eth62/63, so they won't connect.

I think you gave me enough information for me to continue playing for a while. Thank you very much for your time. And please don't close the ticket just now because I may want to update some wiki/docs based on what you provided.