ethereum / aleth

Aleth – Ethereum C++ client, tools and libraries
GNU General Public License v3.0
3.97k stars 2.17k forks source link

eth_sendTransaction fails with RPC error: Unknown account #5160

Open lrettig opened 6 years ago

lrettig commented 6 years ago

If I run truffle using a basic, out-of-the-box solidity contract (truffle unbox metacoin) and then attempt to deploy/test against a local aleth instance (with jsonrpcproxy), I get a bunch of RPC errors:

2018-08-01 21:40:14  rpc {"jsonrpc":"2.0","id":14,"method":"eth_sendTransaction","params":[{"from":"0xefadf166849f06eee4b44ddb78e4162580f436b1","gas":"0x47b760","gasPrice":"0x4a817c800","data":"0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102f8806100606000396000f300608060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100aa5780638da5cb5b146100d5578063fdacd5761461012c575b600080fd5b34801561007357600080fd5b506100a8600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610159565b005b3480156100b657600080fd5b506100bf610241565b6040518082815260200191505060405180910390f35b3480156100e157600080fd5b506100ea610247565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561013857600080fd5b506101576004803603810190808035906020019092919050505061026c565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561023d578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b15801561022457600080fd5b505af1158015610238573d6000803e3d6000fd5b505050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102c957806001819055505b505600a165627a7a7230582099b1b886ba0812a59fb82ef8207b4c078deb182d5f7e80fee22dcc23942d60590029"}]}
2018-08-01 21:40:14  rpc {"error":{"code":0,"data":null,"message":"Unknown account."},"id":14,"jsonrpc":"2.0"}

2018-08-01 21:40:14  rpc {"jsonrpc":"2.0","method":"eth_call","params":[{"from":"0xefadf166849f06eee4b44ddb78e4162580f436b1","gas":"0x47b760","gasPrice":"0x4a817c800","data":"0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102f8806100606000396000f300608060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100aa5780638da5cb5b146100d5578063fdacd5761461012c575b600080fd5b34801561007357600080fd5b506100a8600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610159565b005b3480156100b657600080fd5b506100bf610241565b6040518082815260200191505060405180910390f35b3480156100e157600080fd5b506100ea610247565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561013857600080fd5b506101576004803603810190808035906020019092919050505061026c565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561023d578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b15801561022457600080fd5b505af1158015610238573d6000803e3d6000fd5b505050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102c957806001819055505b505600a165627a7a7230582099b1b886ba0812a59fb82ef8207b4c078deb182d5f7e80fee22dcc23942d60590029"}],"id":1533174014721}
2018-08-01 21:40:14  rpc {"error":{"code":-32602,"message":"INVALID_PARAMS: Invalid method parameters (invalid name and/or type) recognised"},"id":1533174014721,"jsonrpc":"2.0"}

Full trace is at https://gist.githubusercontent.com/lrettig/63d7e941946a313ec460c6484cecfc82/raw/21f776da70f7a9d389c811abfed6b18258c5a55b/cpp-log.txt

axic commented 6 years ago

As mentioned I think you need to supply usable account addresses present in aleth to Truffle. Or it may require the personal API.

lrettig commented 6 years ago

I did specify an account present in aleth to Truffle. The from of the transaction is valid. If you look at the trace you'll see that account listed.

What's the personal API?

lrettig commented 6 years ago

I think it is an accounts issue. Despite the account in question existing and having a nonzero balance (from the genesis config), aleth doesn't recognize it:

> curl -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":14}' http://127.0.0.1:8545
{"id":14,"jsonrpc":"2.0","result":[]} 
lrettig commented 6 years ago

I also tried using:

  1. The genesis account
  2. Sending eth from the genesis account to a new account
  3. The coinbase account collecting mining rewards

I get the same "Unknown account" error regardless of which account I use.

cdetrio commented 6 years ago

it might be best to forget about eth_sendTransaction and hack truffle to use eth_sendRawTransaction. then you can do all the tx signing on the js side.

cdetrio commented 6 years ago

Also, what do you mean by "The genesis account"? If you want to use eth_sendTransaction, cpp needs to know the private key for whatever account you are trying to send from. Have you added the private key to cpp somehow?

lrettig commented 6 years ago

I was able to work around this by using geth to create a keystore file containing the required private key, then manually copying that into the keystore directory beneath the database directory I'm running aleth in (with the -d flag). Oh, and the first time you send a tx from the account in question, aleth prompts you for the password for the keystore file (even if there is none) -- good luck catching that when running in full verbosity through a tee'ed logfile. So that RPC call will fail, but if you enter the password and hit enter, then the next one should succeed. 🤦‍♂️

I'm also encountering a ton of other errors trying to get truffle to talk to aleth -- bad nonce, random RPC errors. If I keep trying to deploy enough times, it seems to eventually sort itself out and start working. Anyway, the issue outlined in this issue seems to be resolved so I'll close this.

axic commented 6 years ago

I do not call it a resolution if geth needs to create files and random password is prompted for :)

At least create issues for those and/or keep this umbrella one open.

lrettig commented 6 years ago

Here's a braindump of the issues I see:

gumb0 commented 6 years ago

aleth does not appear to contain a toolchain for adequately managing keystore files. alethkey/ethkey does some things but it does not seem able to take a simple private key (in hex) and generate a keystore file/add the key to a keystore.

Did you try aleth-key importbare <private_key_hex> ?

gumb0 commented 6 years ago

aleth -s <private_key_hex> works for me, too, just doesn't report its success, imports the key silently.

gumb0 commented 6 years ago

aleth --unsafe-transactions turns off initial prompt on account first access

gumb0 commented 6 years ago

--password is supposed to give a password to try before asking the user, but it doesn't work for me, at least not for the imported accounts (I suspect it does only for keys create by aleth). We should fix this.