在通道上实例化节点链码时出错
Error when instantiating a node chaincode on a channel
我正在尝试在通道上实例化一个已安装的节点链代码,但失败并出现错误:failed to invoke chaincode name:"lscc" , error: container exited with 0
到目前为止我做了什么:
- 使用来自构建您的第一个网络 (v1.4) 教程的
./byfn up -c some-channel -s couchdb -o etcdraft -l node
脚本,成功启动了一个包含 2 个组织的网络,每个组织有 2 个对等节点,并达成了 raft 共识。网络已经有一个名为 mycc
. 的实例化链码
- 使用 Node.js SDK 从我的脚本连接到网络。我能够从我的脚本中成功调用
mycc
链码的读写链码方法。
- 使用每个组织的管理员身份在所有 4 个节点上安装了新的链代码。我可以通过查询对等节点上已安装的链代码来确认链代码确实已安装。对等容器日志也确认链代码已成功安装。
- 尝试实例化已安装的链代码,遇到上述错误。
以下是我尝试实例化链代码的方式:
// Load the network configuration
const ccpPath = path.resolve(__dirname, ccpName);
let ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
// Create a new file system based wallet for managing identities.
const walletPath = path.join(process.cwd(), walletName);
const wallet = new FileSystemWallet(walletPath);
console.log(`Wallet path: ${walletPath}`);
// Check to see if we've already enrolled the user.
const identity = await wallet.exists(identityName);
if (!identity) {
console.log(`An identity for the user ${identityName} does not exist in the wallet`);
console.log('Run the registerUser.js application before retrying');
return;
}
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccp, { wallet, identity: identityName, discovery: { enabled: true, asLocalhost: true } });
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork(channelName);
const client = gateway.getClient();
const channel = network.getChannel(channelName);
let channelPeers = channel.getPeers().map(peer => peer._peer);
// console.log(channelPeers);
const endorsementPolicy = {
identities: [
{ role: { name: 'member', mspId: 'Org1MSP' }},
{ role: { name: 'member', mspId: 'Org2MSP' }}
],
policy: {
'1-of': [{ 'signed-by': 0 }, { 'signed-by': 1 }]
}
};
console.log(channelPeers[0]._name);
const instantiateChaincodeRequest = {
targets: channelPeers,
chaincodeType: 'node',
chaincodeId: 'deal',
chaincodeVersion: '1.0.0',
txId: client.newTransactionID(true),
'endorsement-policy': endorsementPolicy
};
const instantiateResponse = await channel.sendInstantiateProposal(instantiateChaincodeRequest, 300000);
console.log(instantiateResponse[0]);
此脚本解决此错误:
{ Error: chaincode registration failed: container exited with 0
at self._endorserClient.processProposal (/home/projects/testing/vs-code-hlf-sc/node_modules/fabric-client/lib/Peer.js:144:36)
at Object.onReceiveStatus (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:1212:9)
at InterceptingListener._callNext (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:847:24)
status: 500,
payload: <Buffer >,
peer:
{ url: 'grpcs://localhost:9051',
name: 'peer0.org2.example.com:9051',
options: [Object] },
isProposalResponse: true }
以下是相关的对等容器日志:
2020-09-08 08:27:09.274 UTC [endorser] callChaincode -> INFO 0c7 [][7fdf845f] Entry chaincode: name:"lscc"
2020-09-08 08:27:09.277 UTC [lscc] executeInstall -> INFO 0c8 Installed Chaincode [deal] Version [1.0.0] to peer
2020-09-08 08:27:09.277 UTC [endorser] callChaincode -> INFO 0c9 [][7fdf845f] Exit chaincode: name:"lscc" (3ms)
2020-09-08 08:27:09.277 UTC [comm.grpc.server] 1 -> INFO 0ca unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=192.168.48.1:59702 grpc.code=OK grpc.call_duration=3.376691ms
2020-09-08 08:45:34.201 UTC [endorser] callChaincode -> INFO 0dd [some-channel][d3a00bc9] Entry chaincode: name:"lscc"
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0de
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0df > deal@1.0.0 start /usr/local/src
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0e0 > node deal-contract.js "--peer.address" "peer0.org2.example.com:9052"
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0e1
2020-09-08 08:46:17.141 UTC [dockercontroller] func2 -> INFO 0e2 Container dev-peer0.org2.example.com-deal-1.0.0 has closed its IO channel
2020-09-08 08:46:17.314 UTC [endorser] callChaincode -> INFO 0e3 [some-channel][d3a00bc9] Exit chaincode: name:"lscc" (43113ms)
2020-09-08 08:46:17.314 UTC [endorser] SimulateProposal -> ERRO 0e4 [some-channel][d3a00bc9] failed to invoke chaincode name:"lscc" , error: container exited with 0
github.com/hyperledger/fabric/core/chaincode.(*RuntimeLauncher).Launch.func1
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/runtime_launcher.go:63
runtime.goexit
/opt/go/src/runtime/asm_amd64.s:1357
chaincode registration failed
日志显示链码安装成功,然后日志显示 lscc
链码错误。所以我假设错误与链代码的构建阶段有关。但是,当我使用 VS Code IBM Blockchain Extension 部署它时,同样的链码可以完美运行。
到目前为止我尝试过的:
- 以多种方式提供/不提供背书策略和调整实例化请求对象
- 使用不同的身份
- 正在检查
ccenv
容器的日志,该容器在收到实例化请求时生成约 30 秒。没有错误
- 从头开始重新启动网络,删除所有结构 docker 图像并重新开始。
所以基本上问题是:
如何使用 Node.js SDK 正确实例化通道上已安装的链代码?
我的环境:
Ubuntu 18.04
Hyperledger Fabric v1.4
fabric-network
1.4.8
fabric-client
1.4.10
节点 10.22.0
npm 6.14.6
docker 19.03.12,构建 48a66213fe
docker-编写 1.26.2,构建 eefe0d31
链码是使用fabric-contract-api
开发的
我的建议是你必须为两个不同的链代码使用两个不同的通道。您可以在每个对等节点上安装任意数量的链码,但是当您尝试实例化链码时就会出现问题,因为此过程直接涉及网络和通道。尽管他们从版本 >= 2.
更改了实例化过程
备案:
对于 运行 企业,一些组织必须达成共识,因此他们必须创建一个只有获得许可的组织属性才能访问的渠道。
在这里,在一个通道内,每个有效的组织节点都持有业务交易记录的物理副本,这被称为分类账,其中分类账是相同的,这意味着属于同一通道的每个分类账必须持有相同的记录。
分类帐由两个不同但相关的部分组成——世界状态和区块链。世界状态——一个保存一组账本状态当前值的数据库。区块链——一个交易日志,记录了导致当前世界状态的所有变化。
链码是用于读取分类帐记录或将新记录写入分类帐或更新现有记录的业务逻辑。
一个链码由多个智能合约组成。
所以惯例是针对每个通道,你需要一个相同的链码。如果你有 2 个通道,那么你有两个不同的链码是约定俗成的。
所以,为了以后参考,我终于想通了。出于某种原因,我的一个自定义链代码 classes 在从 fabric-shim
扩展 Chaincode
class 后没有继承 Init()
和 Invoke()
方法。我在我的链代码 class 中显式地重新声明了这些方法,它成功地实例化了。
Hyperledger Fabric v1.4 Runtime Launcher 需要这些方法。
我正在尝试在通道上实例化一个已安装的节点链代码,但失败并出现错误:failed to invoke chaincode name:"lscc" , error: container exited with 0
到目前为止我做了什么:
- 使用来自构建您的第一个网络 (v1.4) 教程的
./byfn up -c some-channel -s couchdb -o etcdraft -l node
脚本,成功启动了一个包含 2 个组织的网络,每个组织有 2 个对等节点,并达成了 raft 共识。网络已经有一个名为mycc
. 的实例化链码
- 使用 Node.js SDK 从我的脚本连接到网络。我能够从我的脚本中成功调用
mycc
链码的读写链码方法。 - 使用每个组织的管理员身份在所有 4 个节点上安装了新的链代码。我可以通过查询对等节点上已安装的链代码来确认链代码确实已安装。对等容器日志也确认链代码已成功安装。
- 尝试实例化已安装的链代码,遇到上述错误。
以下是我尝试实例化链代码的方式:
// Load the network configuration
const ccpPath = path.resolve(__dirname, ccpName);
let ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
// Create a new file system based wallet for managing identities.
const walletPath = path.join(process.cwd(), walletName);
const wallet = new FileSystemWallet(walletPath);
console.log(`Wallet path: ${walletPath}`);
// Check to see if we've already enrolled the user.
const identity = await wallet.exists(identityName);
if (!identity) {
console.log(`An identity for the user ${identityName} does not exist in the wallet`);
console.log('Run the registerUser.js application before retrying');
return;
}
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccp, { wallet, identity: identityName, discovery: { enabled: true, asLocalhost: true } });
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork(channelName);
const client = gateway.getClient();
const channel = network.getChannel(channelName);
let channelPeers = channel.getPeers().map(peer => peer._peer);
// console.log(channelPeers);
const endorsementPolicy = {
identities: [
{ role: { name: 'member', mspId: 'Org1MSP' }},
{ role: { name: 'member', mspId: 'Org2MSP' }}
],
policy: {
'1-of': [{ 'signed-by': 0 }, { 'signed-by': 1 }]
}
};
console.log(channelPeers[0]._name);
const instantiateChaincodeRequest = {
targets: channelPeers,
chaincodeType: 'node',
chaincodeId: 'deal',
chaincodeVersion: '1.0.0',
txId: client.newTransactionID(true),
'endorsement-policy': endorsementPolicy
};
const instantiateResponse = await channel.sendInstantiateProposal(instantiateChaincodeRequest, 300000);
console.log(instantiateResponse[0]);
此脚本解决此错误:
{ Error: chaincode registration failed: container exited with 0
at self._endorserClient.processProposal (/home/projects/testing/vs-code-hlf-sc/node_modules/fabric-client/lib/Peer.js:144:36)
at Object.onReceiveStatus (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:1212:9)
at InterceptingListener._callNext (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:847:24)
status: 500,
payload: <Buffer >,
peer:
{ url: 'grpcs://localhost:9051',
name: 'peer0.org2.example.com:9051',
options: [Object] },
isProposalResponse: true }
以下是相关的对等容器日志:
2020-09-08 08:27:09.274 UTC [endorser] callChaincode -> INFO 0c7 [][7fdf845f] Entry chaincode: name:"lscc"
2020-09-08 08:27:09.277 UTC [lscc] executeInstall -> INFO 0c8 Installed Chaincode [deal] Version [1.0.0] to peer
2020-09-08 08:27:09.277 UTC [endorser] callChaincode -> INFO 0c9 [][7fdf845f] Exit chaincode: name:"lscc" (3ms)
2020-09-08 08:27:09.277 UTC [comm.grpc.server] 1 -> INFO 0ca unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=192.168.48.1:59702 grpc.code=OK grpc.call_duration=3.376691ms
2020-09-08 08:45:34.201 UTC [endorser] callChaincode -> INFO 0dd [some-channel][d3a00bc9] Entry chaincode: name:"lscc"
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0de
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0df > deal@1.0.0 start /usr/local/src
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0e0 > node deal-contract.js "--peer.address" "peer0.org2.example.com:9052"
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0e1
2020-09-08 08:46:17.141 UTC [dockercontroller] func2 -> INFO 0e2 Container dev-peer0.org2.example.com-deal-1.0.0 has closed its IO channel
2020-09-08 08:46:17.314 UTC [endorser] callChaincode -> INFO 0e3 [some-channel][d3a00bc9] Exit chaincode: name:"lscc" (43113ms)
2020-09-08 08:46:17.314 UTC [endorser] SimulateProposal -> ERRO 0e4 [some-channel][d3a00bc9] failed to invoke chaincode name:"lscc" , error: container exited with 0
github.com/hyperledger/fabric/core/chaincode.(*RuntimeLauncher).Launch.func1
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/runtime_launcher.go:63
runtime.goexit
/opt/go/src/runtime/asm_amd64.s:1357
chaincode registration failed
日志显示链码安装成功,然后日志显示 lscc
链码错误。所以我假设错误与链代码的构建阶段有关。但是,当我使用 VS Code IBM Blockchain Extension 部署它时,同样的链码可以完美运行。
到目前为止我尝试过的:
- 以多种方式提供/不提供背书策略和调整实例化请求对象
- 使用不同的身份
- 正在检查
ccenv
容器的日志,该容器在收到实例化请求时生成约 30 秒。没有错误 - 从头开始重新启动网络,删除所有结构 docker 图像并重新开始。
所以基本上问题是: 如何使用 Node.js SDK 正确实例化通道上已安装的链代码?
我的环境:
Ubuntu 18.04
Hyperledger Fabric v1.4
fabric-network
1.4.8fabric-client
1.4.10节点 10.22.0
npm 6.14.6
docker 19.03.12,构建 48a66213fe
docker-编写 1.26.2,构建 eefe0d31
链码是使用
开发的fabric-contract-api
我的建议是你必须为两个不同的链代码使用两个不同的通道。您可以在每个对等节点上安装任意数量的链码,但是当您尝试实例化链码时就会出现问题,因为此过程直接涉及网络和通道。尽管他们从版本 >= 2.
更改了实例化过程备案:
对于 运行 企业,一些组织必须达成共识,因此他们必须创建一个只有获得许可的组织属性才能访问的渠道。
在这里,在一个通道内,每个有效的组织节点都持有业务交易记录的物理副本,这被称为分类账,其中分类账是相同的,这意味着属于同一通道的每个分类账必须持有相同的记录。
分类帐由两个不同但相关的部分组成——世界状态和区块链。世界状态——一个保存一组账本状态当前值的数据库。区块链——一个交易日志,记录了导致当前世界状态的所有变化。
链码是用于读取分类帐记录或将新记录写入分类帐或更新现有记录的业务逻辑。
一个链码由多个智能合约组成。
所以惯例是针对每个通道,你需要一个相同的链码。如果你有 2 个通道,那么你有两个不同的链码是约定俗成的。
所以,为了以后参考,我终于想通了。出于某种原因,我的一个自定义链代码 classes 在从 fabric-shim
扩展 Chaincode
class 后没有继承 Init()
和 Invoke()
方法。我在我的链代码 class 中显式地重新声明了这些方法,它成功地实例化了。
Hyperledger Fabric v1.4 Runtime Launcher 需要这些方法。