Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Debugging on a forked network #97

Closed
kulho opened this issue Jun 7, 2022 · 16 comments
Closed

Debugging on a forked network #97

kulho opened this issue Jun 7, 2022 · 16 comments
Assignees

Comments

@kulho
Copy link

kulho commented Jun 7, 2022

Hello,

Steps to reproduce:

  1. create a new basic project with the extension in vs code
  2. ganache --fork.network rinkeby
  3. right click on contract and deploy on the ganache
  4. try to debug transaction with the extension
    Behavior:
    eth_getBlockByNumber goes on forever

not sure if it is trying to go through the 10M+ blocks, but it would be nice to somehow limit it or stop it and get the latest transactions.
Could anyone please advise me if there is any fix? Thank you.

Node v16.15.0
Truffle v5.5.17
Truffle for VS Code v2.2.1
ganache v7.2.0

@michaeljohnbennett
Copy link
Contributor

Hey, are you using the pre-release version of the extension from the marketplace? We have added some new features to allow forking.

@kulho
Copy link
Author

kulho commented Jun 8, 2022

Hey, thanks for the response. I just upgraded to the new release 2.3.1. The new features are really nice, thanks for that :)

The original issue still persists and there is one more thing.

When I create the forked ganache using the new features it is first run without forking. Correct me if I am doing something wrong. Steps to reproduce are the following:

  1. create a new basic project with the extension
  2. Create a new network -> Ganache Service -> Fork -> Rinkeby -> Leave blank for latest block -> port 8545 -> development
  3. Truffle: Deploy Contracts -> select development

In the output Truffle: Ganache Server:8545 there is no mention of the fork. A workaround I found is to restart ganache. A new instance is opened with Forked Chain information.

I have also tried to run deployments that refer to some deployed contracts on Rinkeby and they fail to deploy before I restart the ganache - confirming that the network is not a fork. After I reset Ganache they ran without any issues.


Now back to the original issue. I have tested it with the above-mentioned Fork and Local Ganache and it still looks like on the fork it is trying to read all the blocks since block 0.
Steps to reproduce with the newest release 2.3.1 are the following:

  1. create a new basic project with the extension
  2. Create a new network -> Ganache Service -> Fork -> Rinkeby -> Leave blank for latest block -> port 8545 -> development
  3. Truffle: Restart Ganache
  4. Truffle: Deploy Contracts -> select development
  5. Truffle: Debug Transaction

After the 5th step just take a look at the output Truffle: Ganache Server:8545 and you will see the endless eth_getBlockByNumber

I can also confirm that if you use the truffle console for debugging and you load the transaction manually by its tx hash it will work properly. Anyway, it would be amazing to use the native IDE debugging that the extension offers. I'd love to hear any suggestions on how to achieve it on a forked chain.

@kevinbluer
Copy link
Member

Hey @kulho, super sorry as it looks like this one slipped through net! Happy to help troubleshoot if it's still an issue though.

Just tried the repro steps and it was looking ok on my side (tried with both a fork of rinkeby and mainnet). All looked good with both deploying and debugging the contract.

Screen Shot 2022-07-07 at 4 40 20 PM

Would you mind trying on the latest release of the extension (v2.3.4) just to rule that out?

@kulho
Copy link
Author

kulho commented Jul 11, 2022

Hey @kevinbluer, I just tested with the latest release and it is still not working correctly.

If you do not start the Ganache instance manually - by right click start or via Truffle: Start Ganache it will not run a forked version of Ganache even though you selected it to be. Deploying to development will only launch a local network, not a fork. Scroll in your output higher and see if you get the forked info.
This one is without starting the ganache manually - not being forked.
Screenshot 2022-07-11 at 23 20 54
This one is with the ganache started manually - right click and start ganache.
Screenshot 2022-07-11 at 23 22 31

If you try to debug the transaction on the forked chain I still get an endless "eth_getBlockByNumber"
Screenshot 2022-07-11 at 23 24 15

Note, in the case of a not forked network it behaves correctly.

@kevinbluer
Copy link
Member

Hey @kulho, thanks for the follow-up and your patience while we get this resolved! Regarding the first screenshot (without starting the ganache manually - not being forked) where is that output coming from? The reason I ask is I believe if you've just added the forked network it won't have started yet. In the second screenshot, that looks correct in that you've manually started Ganache. Few thoughts though...

  • Adding some visual representation of running status would help mitigate some of the confusion (something we'd talked about doing but not yet implemented)
  • It's probably logical that we have the instance start straight after being added. Thoughts welcome on this.

Regarding the other issue (if you try to debug the transaction on the forked chain I still get an endless "eth_getBlockByNumber"), I've just tried again and been able to reproduce it 🙂 Interestingly, it looks like it's the Truffle console continuously polling for it because if the console is exited then the eth_getBlockByNumber calls stop. Going to raise this one with the core team to see if they're aware of it.

cc @xhulz for visibility 👍

@kevinbluer
Copy link
Member

Also should note that I'm seeing the eth_getBlockByNumber polling occur on either a forked or non-forked network.

@kevinbluer
Copy link
Member

Initial response re the eth_getBlockByNumber polling...

that's not due to Truffle Console per se, rather it's due to Truffle Contract, and more specifically it's due to Truffle Contract using web3, which does that

Also it can be turned off by setting the disableConfirmationListener network option to true in your truffle-config.js...e.g.

    development: {
     host: "127.0.0.1",
     port: 8545,
     network_id: "*",
     disableConfirmationListener: true
    },

@kulho
Copy link
Author

kulho commented Jul 12, 2022

Regarding the first screenshot (without starting the ganache manually - not being forked) where is that output coming from?

It is coming from the "Truffle: Ganache Server:8545" which is started by the deployment of the contract.

  • It's probably logical that we have the instance start straight after being added. Thoughts welcome on this.

Either that or at least if I deploy contracts to that (added forked) network it should start the forked one and not a local one.

Also it can be turned off by setting the disableConfirmationListener network option to true in your truffle-config.js...e.g.

I have also found this but it does not change anything for me if I add it to the config.

@kevinbluer
Copy link
Member

Hey @kulho, thanks for clarifying! @xhulz was actually able to repro ✨ and has opened an issue (#140) accordingly. We should have fix out shortly 🙂

Re disableConfirmationListener not working, did you send the txn via the Truffle console? If so it might be a bit nuanced in that you'll need to have the associated network entry with disableConfirmationListener: true set and explicitly connect to that...e.g. truffle console --network <entry-with-disableConfirmationListener-set>? Let me know if that doesn't make sense and I'll explain a bit more prescriptively.

Thanks again!

@kulho
Copy link
Author

kulho commented Jul 13, 2022

Hey @kevinbluer, thanks for your support. I made a giff to better illustrate what I am doing :)
bug

It kinda has 2 parts:
First illustrates the new issue (#140 ) with the development network, but the debugging is working.
The second is the debugging issue on the forked network.

@kevinbluer
Copy link
Member

Awesome, thanks for recording that @kulho (and likewise thanks so much for the support). Re the first one, it's already cued up for the next sprint so all good there 👌

Re the second and debugging on the fork, I'm able to repro myself too (the gif definitely helped so thanks again for that). I'll relay to the team and we'll aim to come back with an ETA for a fix shortly.

@kulho
Copy link
Author

kulho commented Jul 13, 2022

No problem, glad to be of help.

There is one offtopic regarding the debugging features I would like to ask. Are you planning to or have you implemented the "fetch external sources" option for the native vs code debugger as well? That would be amazing. I am referring to this feature of the truffle debugger https://trufflesuite.com/blog/debugging-verified-external-contracts-with-truffle-debugger/

@kevinbluer
Copy link
Member

Awesome suggestion @kulho and it's something we've actually talked about implementing! Any interest in creating a new issue for it (as we don't actually have one yet)? 🙌

@xhulz
Copy link
Contributor

xhulz commented Jul 28, 2022

Hey @kulho! How is it going?

Just a friendly reminder about the improvements:

Next release, all these fix will be available. Anyway, when we finish the last one, I let you know

Cheers!

@xhulz xhulz moved this from In Progress to Code Review in vscode-ext-v2.5-haiku 📝 Aug 2, 2022
@xhulz
Copy link
Contributor

xhulz commented Aug 5, 2022

Hey @kulho! How is it going?

Just a friendly reminder about the improvements:

#140 - ✅ Already done and merged
#141 - ✅ Already done and merged
#97 - ✅ Already done and merged

Next release, all these fix will be available.

Thank you so much for you contribution!

cc @kevinbluer

Cheers!

@xhulz xhulz moved this from Code Review to Done in vscode-ext-v2.5-haiku 📝 Aug 5, 2022
@kevinbluer
Copy link
Member

Closing this one given it's been addressed (details above from @xhulz). @kulho feedback welcome and feel free to create new issues for anything else that comes up 👌

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

4 participants