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

`debug_traceTransaction` crashes on websockets #898

Open skyeatshorizon opened 3 years ago

skyeatshorizon commented 3 years ago

Issue

Hi I've been having a problem with the debugger on a certain transaction, where I have a contract, which deploys an ERC777 token over a library. Contract -> calls library -> deploys ERC777 Token. Im getting the following error:

ProviderError: CONNECTION ERROR: Couldn't connect to node on WS.
at /home/user/testing/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:73:1
at /home/user/testing/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:102:1
at Object.callback (/home/user/testing/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:107:1)
at /home/user/testing/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-ws/src/index.js:188:1
at Map.forEach (<anonymous>)
at WebsocketProvider._onClose (/home/user/testing/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-ws/src/index.js:187:1)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/user/testing/node_modules/truffle/build/webpack:/node_modules/yaeti/lib/EventTarget.js:115:1)
at W3CWebSocket.onClose (/home/user/testing/node_modules/truffle/build/webpack:/node_modules/websocket/lib/W3CWebSocket.js:228:1)
at WebSocketConnection.<anonymous> (/home/user/testing/node_modules/truffle/build/webpack:/node_modules/websocket/lib/W3CWebSocket.js:201:1)
at WebSocketConnection.emit (events.js:315:20)
at WebSocketConnection.EventEmitter.emit (domain.js:467:12)
at WebSocketConnection.drop (/home/user/testing/node_modules/truffle/build/webpack:/node_modules/websocket/lib/WebSocketConnection.js:475:1)
at WebSocketConnection.processFrame (/home/user/testing/node_modules/truffle/build/webpack:/node_modules/websocket/lib/WebSocketConnection.js:578:1)
at /home/user/testing/node_modules/truffle/build/webpack:/node_modules/websocket/lib/WebSocketConnection.js:323:34
at processTicksAndRejections (internal/process/task_queues.js:75:11)
at runNextTicks (internal/process/task_queues.js:62:3)
at processImmediate (internal/timers.js:434:9)

Thx for helping me out with this.

Steps to Reproduce

I've already extracted a minimal Example and setup a git repo as my code is too complex to share in this issue.

Expected Behavior

The debugger should not have any problems with this transaction or give a useful error msg instead. If I try to debug a different transaction the debugger works as it should.

Environment

haltman-at commented 3 years ago

Thanks for reporting this! Did you mean to link this git repo with the minimal example? There doesn't seem to be a link.

skyeatshorizon commented 3 years ago

@haltman-at The repo is private, but I'll invite you

haltman-at commented 3 years ago

OK, thanks, I'll take a look!

haltman-at commented 3 years ago

Unfortunately I'm running into trouble compiling your project. It looks like you imported the OpenZeppelin contracts using relative imports, expecting them to live in ./openzeppelin-contracts. But npm of course put them in node_modules at the project root. Now, of course, Truffle allows importing of such contracts, by just doing import "openzeppeling-contracts/...". But Truffle expects that the node_modules folder will live at the Truffle project root, not one directory above it. (Oops, that sentence was false, it works either way!) So I guess to get this to compile, I'll move package.json and package-lock.json to inside the DApps folder, and change those relative imports to absolute ones? Anyway, I'll see what that yields.

Edit: Oh, huh, seems the openzeppelin contracts aren't in the package.json? OK, guess I'll add that...

Edit: OK, after installing the openzeppelin contracts and fixing the import statements, I got it to compile, but now I'm running into problems with deployment requiring gas beyond the block gas limit. I guess I can fix that by just restarting Ganache with a higher limit, though.

Edit: OK, I have now reproduced the problem!

haltman-at commented 3 years ago

OK, the problem seems to be occurring where the debugger makes its debug_traceTransaction call; this is the call that comes back with an error. I'm not sure what we can do about this. But, we'll have to look into it, I suppose. Thanks for reporting this.

haltman-at commented 3 years ago

Oh, I should tag @davidmurdoch, I suppose, as it seems this may actually be a ganache-core error?

Edit: I wonder if the fact that it's using websockets is relevant?

haltman-at commented 3 years ago

OK, the issue appears to be related to the use of websockets. If I turn off websockets in the config, the problem goes away. So, for now, there's your workaround: If you turn off websockets, you should be able to debug just fine.

That said, obviously we should still fix the underlying issue here. I think that'll require @davidmurdoch to take a look though.

Hope that's helpful in the meantime!

davidmurdoch commented 3 years ago

@skyeatshorizon Is it possible for you to share this project with me so I can debug further?

skyeatshorizon commented 3 years ago

Hi @haltman-at Thank you so far for your help. Im sorry, I forgot to tell you that you have to clone with submodules and yes you need a bit more gas for ganache-cli. Hey @davidmurdoch you are invited!

haltman-at commented 3 years ago

Oh hey should this issue be moved to the ganache-core repo? Or is there an already an equivalent there? Otherwise I can make a new one over there for this.