Fabric1.4源码调试debug,IDEA/Goland环境

运行环境


go env设置

  • go env设置,GOARCH windows默认是386,无法开启debug,改成amd64

go env -w set GO111MODULE=auto

go env -w GOARCH=amd64

go env -w GOPROXY=https://goproxy.cn

配置host

127.0.0.1 peer
127.0.0.1 orderer

创建peer和order配置

fabric项目切换为1.4

https://github.com/hyperledger/fabrichttps://github.com/hyperledger/fabricfabric项目网络示例1.4

https://github.com/hyperledger/fabric-sampleshttps://github.com/hyperledger/fabric-samples

下载的fabric项目记得放在GOPATH下,本文为C:\Users\root\go

新建src\github.com\hyperledger\fabric,项目名改为fabric

1.在fabric项目下创建dev-network目录
2.将fabric项目下sampleconfig文件夹下的所有文件复制到 dev-network
3.修改 core.yamlfileSystemPath = $GOPATH/src/github.com/hyperledger/fabric/dev-network/production/peer
4.修改 orderer.yamlLocation =$GOPATH/src/github.com/hyperledger/fabric/dev-network/production/orderer
5.在 dev-network新建 config目录,并复制fabric-samples项目中的chaincode-docker-devmode下的myc.txorderer.block文件到config目录中

 添加Run/debug Configuration

1.进入.idea/workspace.xml文件

2.找到RunManager组件,替换配置,随即出现运行配置

<component name="RunManager" selected="Go Build.orderer">
    <configuration default="true" type="ArquillianTestNG" factoryName="" nameIsGenerated="true">
      <option name="arquillianRunConfiguration">
        <value>
          <option name="containerStateName" value="" />
        </value>
      </option>
      <option name="TEST_OBJECT" value="CLASS" />
      <properties />
      <listeners />
      <method v="2">
        <option name="Make" enabled="true" />
      </method>
    </configuration>
    <configuration name="chaincode install" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
      <module name="fabric" />
      <working_directory value="$PROJECT_DIR$" />
      <parameters value="chaincode install -p github.com/hyperledger/fabric/examples/chaincode/go/example02 -n mycc -v 1.0" />
      <envs>
        <env name="CORE_PEER_LOCALMSPID" value="DEFAULT" />
        <env name="CORE_PEER_ID" value="cli" />
        <env name="CORE_PEER_MSPCONFIGPATH" value="$PROJECT_DIR$/dev-network/msp" />
        <env name="CORE_PEER_ADDRESS" value="127.0.0.1:7051" />
        <env name="FABRIC_CFG_PATH" value="$PROJECT_DIR$/dev-network" />
      </envs>
      <kind value="PACKAGE" />
      <filePath value="$PROJECT_DIR$/peer/main.go" />
      <package value="github.com/hyperledger/fabric/peer" />
      <directory value="$PROJECT_DIR$" />
      <method v="2" />
    </configuration>
    <configuration name="chaincode instantiate" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
      <module name="fabric" />
      <working_directory value="$PROJECT_DIR$" />
      <parameters value="chaincode instantiate -n mycc -v 1.0 -c '{&quot;Args&quot;:[&quot;init&quot;,&quot;a&quot;,&quot;100&quot;,&quot;b&quot;,&quot;200&quot;]}' -C myc" />
      <envs>
        <env name="CORE_PEER_LOCALMSPID" value="DEFAULT" />
        <env name="CORE_PEER_ID" value="cli" />
        <env name="CORE_PEER_MSPCONFIGPATH" value="$PROJECT_DIR$/dev-network/msp" />
        <env name="CORE_PEER_ADDRESS" value="127.0.0.1:7051" />
        <env name="FABRIC_CFG_PATH" value="$PROJECT_DIR$/dev-network" />
      </envs>
      <kind value="PACKAGE" />
      <filePath value="$PROJECT_DIR$/peer/main.go" />
      <package value="github.com/hyperledger/fabric/peer" />
      <directory value="$PROJECT_DIR$" />
      <method v="2" />
    </configuration>
    <configuration name="chaincode invoke" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
      <module name="fabric" />
      <working_directory value="$PROJECT_DIR$" />
      <parameters value="chaincode   invoke   -n   mycc   -c   '{&quot;Args&quot;:[&quot;invoke&quot;,&quot;a&quot;,&quot;b&quot;,&quot;10&quot;]}'   -C   myc" />
      <envs>
        <env name="CORE_PEER_LOCALMSPID" value="DEFAULT" />
        <env name="CORE_PEER_ID" value="cli" />
        <env name="CORE_PEER_MSPCONFIGPATH" value="$PROJECT_DIR$/dev-network/msp" />
        <env name="CORE_PEER_ADDRESS" value="127.0.0.1:7051" />
        <env name="FABRIC_CFG_PATH" value="$PROJECT_DIR$/dev-network" />
      </envs>
      <kind value="PACKAGE" />
      <filePath value="$PROJECT_DIR$/peer/main.go" />
      <package value="github.com/hyperledger/fabric/peer" />
      <directory value="$PROJECT_DIR$" />
      <method v="2" />
    </configuration>
    <configuration name="chaincode query" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
      <module name="fabric" />
      <working_directory value="$PROJECT_DIR$" />
      <parameters value="chaincode query -n mycc -c '{&quot;Args&quot;:[&quot;query&quot;,&quot;a&quot;]}' -C myc" />
      <envs>
        <env name="CORE_PEER_LOCALMSPID" value="DEFAULT" />
        <env name="CORE_PEER_ID" value="cli" />
        <env name="CORE_PEER_MSPCONFIGPATH" value="$PROJECT_DIR$/dev-network/msp" />
        <env name="CORE_PEER_ADDRESS" value="127.0.0.1:7051" />
        <env name="FABRIC_CFG_PATH" value="$PROJECT_DIR$/dev-network" />
      </envs>
      <kind value="PACKAGE" />
      <filePath value="$PROJECT_DIR$/peer/main.go" />
      <package value="github.com/hyperledger/fabric/peer" />
      <directory value="$PROJECT_DIR$" />
      <method v="2" />
    </configuration>
    <configuration name="channel create" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
      <module name="fabric" />
      <working_directory value="$PROJECT_DIR$" />
      <parameters value="channel create -c myc -f $PROJECT_DIR$/dev-network/config/myc.tx -o 127.0.0.1:7050 " />
      <envs>
        <env name="CORE_PEER_LOCALMSPID" value="DEFAULT" />
        <env name="CORE_PEER_ID" value="cli" />
        <env name="CORE_PEER_MSPCONFIGPATH" value="$PROJECT_DIR$/dev-network/msp" />
        <env name="CORE_PEER_ADDRESS" value="127.0.0.1:7051" />
        <env name="FABRIC_CFG_PATH" value="$PROJECT_DIR$/dev-network" />
      </envs>
      <kind value="PACKAGE" />
      <filePath value="$PROJECT_DIR$/peer/main.go" />
      <package value="github.com/hyperledger/fabric/peer" />
      <directory value="$PROJECT_DIR$" />
      <method v="2" />
    </configuration>
    <configuration name="channel join" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
      <module name="fabric" />
      <working_directory value="$PROJECT_DIR$" />
      <parameters value="channel join -b myc.block " />
      <envs>
        <env name="CORE_PEER_LOCALMSPID" value="DEFAULT" />
        <env name="CORE_PEER_ID" value="cli" />
        <env name="CORE_PEER_MSPCONFIGPATH" value="$PROJECT_DIR$/dev-network/msp" />
        <env name="CORE_PEER_ADDRESS" value="127.0.0.1:7051" />
        <env name="FABRIC_CFG_PATH" value="$PROJECT_DIR$/dev-network" />
      </envs>
      <kind value="PACKAGE" />
      <filePath value="$PROJECT_DIR$/peer/main.go" />
      <package value="github.com/hyperledger/fabric/peer" />
      <directory value="$PROJECT_DIR$" />
      <method v="2" />
    </configuration>
    <configuration name="orderer" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
      <module name="fabric" />
      <working_directory value="$PROJECT_DIR$" />
      <envs>
        <env name="ORDERER_GENERAL_LISTENADDRESS" value="0.0.0.0" />
        <env name="ORDERER_GENERAL_GENESISMETHOD" value="file" />
        <env name="ORDERER_GENERAL_GENESISFILE" value="$PROJECT_DIR$/dev-network/config/orderer.block" />
        <env name="ORDERER_GENERAL_LOCALMSPID" value="DEFAULT" />
        <env name="ORDERER_GENERAL_LOCALMSPDIR" value="$PROJECT_DIR$/dev-network/msp" />
        <env name="FABRIC_CFG_PATH" value="$PROJECT_DIR$/dev-network" />
      </envs>
      <kind value="PACKAGE" />
      <filePath value="$PROJECT_DIR$/orderer/main.go" />
      <package value="github.com/hyperledger/fabric/orderer" />
      <directory value="$PROJECT_DIR$" />
      <method v="2" />
    </configuration>
    <configuration name="peer" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
      <module name="fabric" />
      <working_directory value="$PROJECT_DIR$" />
      <parameters value="node start --peer-chaincodedev=true" />
      <envs>
        <env name="CORE_PEER_LOCALMSPID" value="DEFAULT" />
        <env name="CORE_PEER_ID" value="peer" />
        <env name="CORE_PEER_MSPCONFIGPATH" value="$PROJECT_DIR$/dev-network/msp" />
        <env name="CORE_PEER_ADDRESS" value="127.0.0.1:7051" />
        <env name="FABRIC_CFG_PATH" value="$PROJECT_DIR$/dev-network" />
      </envs>
      <kind value="PACKAGE" />
      <filePath value="$PROJECT_DIR$/peer/main.go" />
      <package value="github.com/hyperledger/fabric/peer" />
      <directory value="$PROJECT_DIR$" />
      <method v="2" />
    </configuration>
    <configuration name="run chaincode example02" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
      <module name="fabric" />
      <working_directory value="$PROJECT_DIR$" />
      <envs>
        <env name="CORE_PEER_ADDRESS" value="127.0.0.1:7052" />
        <env name="CORE_CHAINCODE_ID_NAME" value="mycc:1.0" />
      </envs>
      <kind value="PACKAGE" />
      <filePath value="$PROJECT_DIR$/peer/main.go" />
      <package value="github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd" />
      <directory value="$PROJECT_DIR$" />
      <method v="2" />
    </configuration>
    <list>
      <item itemvalue="Go Build.orderer" />
      <item itemvalue="Go Build.peer" />
      <item itemvalue="Go Build.channel create" />
      <item itemvalue="Go Build.channel join" />
      <item itemvalue="Go Build.chaincode install" />
      <item itemvalue="Go Build.chaincode instantiate" />
      <item itemvalue="Go Build.run chaincode example02" />
      <item itemvalue="Go Build.chaincode query" />
      <item itemvalue="Go Build.chaincode invoke" />
    </list>
    <recent_temporary>
      <list>
        <item itemvalue="Go Build.chaincode install" />
        <item itemvalue="Go Build.peer" />
        <item itemvalue="Go Build.orderer" />
        <item itemvalue="Go Build.chaincode query" />
        <item itemvalue="Go Build.run chaincode example02" />
      </list>
    </recent_temporary>
  </component>

3. 切换到调试窗口,在需要跟踪的地方打好断点
4. 依次运行order 、peer、channel create 、channel join、chaincode install、run chaincode example02、chaincode instantiate、chaincode invoke、chaincode query
5. 观察debug控制台和terminal变化

PS:windows环境下,链码安装时,会出现路径问题,可自行debug调试,或尝试切换linux mac环境调试

参考文章:

【fabric源码】vscode调试Hyperledger Fabric 1.4源码、单机网络_KK下山去买菜-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值