trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.61k stars 676 forks source link

Connection timeout sending transaction with CURL but not error output #4338

Closed MatthieuScarset closed 1 year ago

MatthieuScarset commented 1 year ago

Running ganache in verbose mode ganache -v --logging.debug and sending a transaction (see below) ends up in a Connection timeout error but there is no information about what's wrong.

The transaction values are correct because I can send it successfully via another provider (e.g. tested successfully through Alchemy and Metamask).

use kornrunner\Ethereum\EIP1559Transaction;

$nonce = '01';
$maxPriorityFeePerGas = 'b2d05e00';
$maxFeePerGas = '6fc23ac00';
$gasLimit = '5208';
$to = '11d749256d326d3b316C2dcDF2b7d8cE20CF2cFd';
$value = '29a2241af62c0000';
$data = '';
$chainId = 1337;

$privateKey = 'PRIVATEKEY';

$transaction = new EIP1559Transaction($nonce, $maxPriorityFeePerGas, $maxFeePerGas, $gasLimit, $to, $value, $data);
$rawTx = $transaction->getRaw($privateKey, $chainId);

The POST is as follow:

"[{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0x02f8758205390184b2d05e008506fc23ac008252089411d749256d326d3b316C2dcDF2b7d8cE20CF2cFd8829a2241af62c000080c001a0a391210b5e7390bfd9269476a96b354e73290dedc95fc02c056263d133b5ade6a04268d49d2bce109a00052cb1a692401949af77eeb3db939561fd4ec2428752c5"],"id":0}]"

Ganache receives the transaction as I can see it in my terminal but then it timeout after 30001 milliseconds without explanations. image

Any help will be much appreciated :wave:

jeffsmale90 commented 1 year ago

Thanks @MatthieuScarset for raising this issue. I suspect this is caused by a future-nonce. Can you please check the transaction count of the account you are using with the following:

curl -s http://localhost:8545 -X POST -H "Content-Type:application/json;" -d '{"id":1,"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["0x11d749256d326d3b316C2dcDF2b7d8cE20CF2cFd"]}'

Assuming the transaction count is 0, then you'll need to set the nonce to '00'.

AFAICT this is a problem with Ganache, as it shouldn't fail to return. I feel like there was some work in progress somewhere to address this. I'll have a look tomorrow and see if I can find it.

jeffsmale90 commented 1 year ago

In v7.7.6 we added a log to warn users of the future nonce: https://github.com/trufflesuite/ganache/pull/4166

If you are running >= v7.7.6 and don't get that warning, then it's likely it's another issue. As to holding the connection open, I'll have to chat with the team to understand the reasoning behind this.

MatthieuScarset commented 1 year ago

I forgot to state the version I'm using, sorry. I'm using Ganache 8.19.3 - the latest version as of today.

Thank you for linking the issue #4166. The bug/behavior described in this issue is exactly what I am experiencing.

So either the issue with future nonce is not fixed or it's something else from my transaction's values?

jeffsmale90 commented 1 year ago

@MatthieuScarset can you please double check the version - the latest is v7.7.7

MatthieuScarset commented 1 year ago

Oups sorry. I run a wrong cmd and it gave me the version of npm itself I think... :face_exhaling:

I am using Ganache ^7.7.5 indeed.

Let me try with the latest version to see if I can reproduce the issue or if I have an error returned before timeout.

MatthieuScarset commented 1 year ago

It fails! :tada: with an error message.

{"id":null,"jsonrpc":"2.0","error":{"message":"insufficient funds for gas * price + value","stack":"Error: insufficient funds for gas * price + value\n at TransactionPool.prepareTransaction (\/app\/node_modules\/ganache\/dist\/node\/1.js:2:121958)","code":-32003}}

So I now at least know what I need to work on to fix my transaction.

Thank you for your help!

jeffsmale90 commented 1 year ago

Excellent - let us know if you have any more challenges with Ganache.

Cheers!

davidmurdoch commented 1 year ago

@MatthieuScarset, we've got a feature branch that, upon start up, logs a message to the console that ganache is out of date and you should update. It would look similar to this message:

image

The message is only logged once for each new version we release.

If ganache had this (optional, opt-out) feature do you think you would have updated?

MatthieuScarset commented 1 year ago

I would certainly have updated, yes. It's a side project i'm working on so I don't fear to break things... I would try to keep all dependencies the most up to date possible.