IBM-Blockchain / blockchain-vscode-extension

IBM Blockchain Platform extension for Visual Studio Code (this project is no longer active)
https://marketplace.visualstudio.com/items?itemName=IBMBlockchain.ibm-blockchain-platform
Other
266 stars 156 forks source link

[v2 merge] Debug smart contract - update or remove #2660

Closed lquintai closed 1 year ago

lquintai commented 3 years ago

Description

Check if:

Decide if we should support debug for both versions, just one, or none. Create issues as needed.

Jakeeyturner commented 3 years ago

We won't be doing this in the first pass!

koakh commented 3 years ago

Hello I'm try hard to debug chaincodes in vscode with blockchain-vscode-extension, for me it's a vital feature, useful when we have big chaincodes with many models and some logic

the error is, I start debug and no problem, everyting ok, debugger is launched and attached, but when I click "Debug command list" appears in Blockchain output

[1/23/2021 6:37:24 PM] [ERROR] The current debug session is not debugging a smart contract, this command can only be run when debugging a smart contract

but now way it seems that it's is not possible or not documented

I read in README

The IBM Blockchain Platform extension helps developers to create, test and debug smart contracts, connect to Hyperledger Fabric environments, and build applications that transact on your blockchain network.

Is this information valid? debug smart contracts?

other question is, it is possible to debug v2 with minifab or it will be in a near future

I think is better to update the README to show this info, this way other users don't waste precious time like

debug v1 OK debug v2 KO

currently I use hyperledger v1.4.x with convector package and can debug chaincodes in typescript without any issue

awesome extension

thanks

if I can help debugging, and try testing some stuff please just say, I'm glad to help

FelipeSanchezCalzada commented 3 years ago

Debug chaincode is vital for me too, without the possibility of debugging it is impossible for me to use the new version of the extension. Is there an approximate date for the implementation of the fabric version 2.0 debug? Is there an approximate date for the second pass? Thanks for the work

koakh commented 3 years ago

After I google a lot I can't find anyone that know how, or want/have time to help,

But I never give up, and in the end I have found a way to debug it with hlf 2.3, node chainCode, javascript, and/or with typescript sourceMaps too 👍

I lost 4 nights but in the end is simple and easy setup, and it's better that I was expected, the developing experience is perfect, better that with Convector (I work with convector and hlf 1.4.x with debug), dev-mode setup is super fast, we debug in 5 seconds, without deploy chaincode on peer, works with breakpoints, inspector and all the cool stuff

Just launch (launch.json) debug and it works, for me the trick is using peer in dev-mode

In the past I put the vscode extension working with peer dev-mode, but in that time I don't know all the hacks I need to put it work, now I know, I will try to use in vscode extension too, and if it works I post here I think minifab works too, but dev-mode in my opinion is the better way, we just run chainCode outside of containers and is lightning fast

(sorry If I spam this issue)

update1:: I think the extension source is here blockchain-extension I will try figure out if is better hack the installed extension or working on repo

update2:: I clone de repo, but seems to complex to work with extension code, there is so many things in it, maybe its easier to hack the installed extension, or just use run the peer in dev-mode, and disable tls that is the only thing we need in extension :)

FABRIC_LOGGING_SPEC=chaincode=debug CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052 peer node start --peer-chaincodedev=true

update:: I found days ago, in one of my fails, that the trick is inside the container core.yaml, and in start.sh and not outside in extension code or in paths

~/.vscode/extensions/ibmblockchain.ibm-blockchain-platform-2.0.0
~/.fabric-vscode

update:: I hack the environment network and confirm that we can connect with peer in dev-mode without problem (after we hack core.yaml), and we can attach the debugger, but when we use the gateway to invoke functions the breakpoints don't work, maybe because we are using the deployed tar.gz chaincode and not the chaincode that we are running externally and connected to peer dev-mode, is just a guess

and I can't use peer live cycle commands to deploy it because we don't have msp folder, and we required the crypto materials, maybe the msp folder is inside container, maybe when I have more time I search for it

lasharela commented 3 years ago

I'm facing the same issue. Looks like everything is running but the debugger is not working still.

lasharela commented 3 years ago

any updates on this?

davidkel commented 3 years ago

@lasharela It looks like for fabric v2, only fabric 2.3.x supports dev mode required for debug and the fabric environment used by the extension is from microfab which only provides a fabric 2.2 environment. Also microfab would have to be able to bring the peers up in dev mode and doesn't have the capability to do so. You may be able to get debug working yourself by bringing up your own local fabric 2.3 network and enabling dev mode on the peers yourself (see https://hyperledger-fabric.readthedocs.io/en/release-2.3/peer-chaincode-devmode.html) then importing that into the extension (see https://github.com/IBM-Blockchain/blockchain-vscode-extension/wiki/Common-tasks-and-how-to-complete-them#connecting-to-an-instance-of-hyperledger-fabric). I've not tried this myself. The alternative is to go back to the V1 extension.

lasharela commented 3 years ago

Guys, is there any information on when debugging will be solved?

riki95 commented 2 years ago

I am using extension version 2.0.4, created a smart contract package from scratch and I cannot debug neither in local environment neither in microfab. Any idea of when this will be fixed? Debugging smart contracts is a very useful feature and a high priority one

cazfletch commented 2 years ago

Sorry no timeline for this yet. It requires some changes to microfab first

riki95 commented 2 years ago

Greetings, any update on this? Debugging locally is very important to test chaincode.

riki95 commented 2 years ago

Greetings, just checking if there is any update on this thread or maybe possibility to contribute. Debugging chaincodes is a very important feature. I've seen that there is an investigation opened by @jt-nti so maybe also further updates on what you will be doing to re-insert the feature on the extension. Thanks a lot

jt-nti commented 2 years ago

Hi @riki95, sorry I should have left a comment as well as adding the investigation tag! It would be useful to investigate whether using the Chaincode As A Server (CCaaS) feature in Fabric would help with debugging chaincodes.

Having said that, no one is actively investigating but the recent Fabric release has simplified CCaaS so it should be possible to debug chaincode in this way without changes to the vscode extension. For example, Running Chaincode as Service with the Test Network explains how to run CCaaS in the Fabric test network. If I find more details that would help, I'll add them here.

Any contributions to help to fix debugging in the vscode extension would be very welcome.

riki95 commented 2 years ago

Hi @jt-nti , I managed to deploy the typescript assets transfer basic on the test-network and invoking it via the peer commands but that's not exactly what I would like to do. I would need to debug with vs code and breakpoints and this was doable in the past (Fabric 1.4).

I have no idea of how to debug the chaincode that I deployed. Also, there are scripts to deploy typescript files but not standard javascript ones. With them, the scripts are failing so I think they are not complete.

I think the breakpoint debug is a very needed feature for production projects so it's strange is not well implemented

lasharela commented 2 years ago

Common guys, is this still an open issue? :)

riki95 commented 2 years ago

Still needed! Really hope this can be developed

jt-nti commented 2 years ago

Hyperledger Fabric is moving away from the traditional chaincode deployment model and development mode, towards executing chaincode outside of Fabric, which does make developing and debugging chaincode much easier.

Recent updates in Fabric 2.4 make deploying chaincode as a server more straightforward than it used to be, unfortunately there are still missing pieces, and I'm also not sure when the vscode extension is likely to be updated to support this approach.

Having said that, it should still be possible to use built in vscode capabilities to debug chaincode, and there is an early draft of some documentation which will hopefully help with that...

https://github.com/hyperledgendary/fabric-contract-debug-scenario/blob/main/README.md

jt-nti commented 1 year ago

See #3183