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.62k stars 683 forks source link

Impossible to debug transaction due to Connector.format string length #4405

Open bropoCorpd opened 1 year ago

bropoCorpd commented 1 year ago

i connect remix to my ganache instance with these parameters : package.json

{
  "dependencies": {
    "@truffle/hdwallet-provider": "^2.1.11",
    "dotenv": "^16.0.3",
    "ganache": "^7.8.0",
    "truffle-hdwallet-provider": "^1.0.17"
  },
      "scripts": {
      "ganache": "ganache --wallet.seed ganacheSeed --chain.allowUnlimitedInitCodeSize true --chain.allowUnlimitedContractSize true --chain.vmErrorsOnRPCResponse true --logging.debug true --chain.networkId 11199111  --chain.vmErrorsOnRPCResponse true --chain.hardfork istanbul --miner.blockGasLimit 0x3938700 --miner.defaultGasPrice 0x0 --database.dbPath /home/xxx/Documents/ganacheDb --logging.verbose false"
  }
}

then i connect remix to ganache, and when i try to debug a transaction created in my migrations file, i get this error:

processing response error (body="{\"id\":65,\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Invalid string length\",\"stack\":\"RangeError: Invalid string length\\n at JSON.stringify (<anonymous>)\\n at Connector.format
 (/home/xxx/IdeaProjects/xxx/xxx/xxx/xxx/xxx/xxx/node_modules/ganache/dist/node/1.js:2:89623)\\n at 
/home/xxx/IdeaProjects/xxx/xxx/xxx/xxx/xxx/xxx/node_modules/ganache/dist/node/1.js:2:252565\",\"code\":
-32700}}", error={"code":-32700}, requestBody="{\"method\":\"debug_traceTransaction\",\"params\":
[\"0x1854e0c32a07ca85a15cbb6576e22c244da4b9d8131b81dc082442b0181db4de\",
{\"disableStorage\":true,\"enableMemory\":true,\"disableStack\":false,\"fullStorage\":false}],\"id\":65,\"jsonrpc\":\"2.0\"}", 
requestMethod="POST", url="http://127.0.0.1:8545", code=SERVER_ERROR, version=web/5.7.1)

if i run truffle debug 0x1854e0c32a07ca85a15cbb6576e22c244da4b9d8131b81dc082442b0181db4de i get this instead :

truffle debug 0x4f5467f156419cd83813554afa19930e6ab5af3281ac7da1318bd40f75decd5e
Starting Truffle Debugger...
✓ Compiling your contracts...
✖ Gathering information about your project and the transaction...
SError: Invalid string length
    at $t.getTrace (/home/sniffnoy/truffle/truffle/packages/debugger/lib/web3/adapter.js:55:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

i tried upping my node heap size limit by putting into my bashrc export NODE_OPTIONS=--max-old-space-size=4096, but i cannot debug my transaction at all. if anyone has an idea on how to fix this, it would be really appreciated, thanks

davidmurdoch commented 1 year ago

Your trace is hitting the max string length size JavaScript can handle.

Ganache has heuristic protections to try to prevent this, but sometimes it's not enough. I have a PR open to work around this Node.js limitation (https://github.com/trufflesuite/ganache/pull/3997) but we haven't had time to review it before merging it yet.

Currently we just check if the number is steps in the transaction is greater than 100000. If it is, we transmit the trace piece by piece instead of all in one blob. You might be able to try modifying the transaction to ensure it runs at least 100000 steps by throwing a big loop in to your code.

You can also try checking out that PR's branch and building it yourself, but I suspect the truffle debugger and remix will both choke on it (since they are both JS and will probably attempt to read the JSON as a string before parsing). I do have a truffle branch that makes the debugger work with these giant traces, but it was just experimental and be a lot more work: https://github.com/trufflesuite/truffle/commits/fix/streaming-web3-http-provider.

bropoCorpd commented 1 year ago

thanks alot for your answer, after searching thoroughly i did find one of your posts mentioning the 10000 limit in the connector, i'll take a look, but i guess my only option would be to make alot of unit tests to test every piece separately, thanks again, and i'll take a look at the truffle branch.

EDIT : for those who need to debug but cannot with remix like me, i found a workaround, you can use ganache console.log alongside truffle console logging, and you can just do console.log in your solidity code...it's amazing i don't really need to debug anymore, i also use unit tests, i have split my code into tiny function calls and i do chai unit tests on them using truffle testing.