Hyperledger-Frbirc测试环境错误记录

网络

测试网络其中一个组织的peer无法启动

错误描述

在运行./network.sh up时,只启动了一个组织的peer,另一个无法启动。导致在新建channel时报错如下:

1
2
3
4
5
6
2021-01-04 10:49:22.575 CST [comm.tls] ClientHandshake -> ERRO 001 Client TLS handshake failed after 2.157125ms with error: EOF remoteaddress=[::1]:7051
2021-01-04 10:49:23.582 CST [comm.tls] ClientHandshake -> ERRO 002 Client TLS handshake failed after 3.12316ms with error: EOF remoteaddress=[::1]:7051
2021-01-04 10:49:25.157 CST [comm.tls] ClientHandshake -> ERRO 003 Client TLS handshake failed after 4.29759ms with error: EOF remoteaddress=[::1]:7051
Error: error getting endorser client for channel: endorser client failed to connect to localhost:7051: failed to create new connection: context deadline exceeded
After 5 attempts, peer0.org1 has failed to join channel 'mychannel'
Create channel failed

因为这个问题导致的链码无法部署:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(base) apple@WHOAMIdeMacBook-Pro:~/code/open-source/blockchain/hyperledger/fabric-samples/test-network$     ./network.sh deployCC
deploying chaincode on channel 'mychannel'
executing with the following
- CHANNEL_NAME: mychannel
- CC_NAME: basic
- CC_SRC_PATH: NA
- CC_SRC_LANGUAGE: go
- CC_VERSION: 1.0
- CC_SEQUENCE: 1
- CC_END_POLICY: NA
- CC_COLL_CONFIG: NA
- CC_INIT_FCN: NA
- DELAY: 3
- MAX_RETRY: 5
- VERBOSE: false
Determining the path to the chaincode
asset-transfer-basic
Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go/
~/code/open-source/blockchain/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go ~/code/open-source/blockchain/hyperledger/fabric-samples/test-network
~/code/open-source/blockchain/hyperledger/fabric-samples/test-network
Finished vendoring Go dependencies
+ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_1.0
+ res=0
Chaincode is packaged
Installing chaincode on peer0.org1...
Using organization 1
+ peer lifecycle chaincode install basic.tar.gz
+ res=1
Error: failed to retrieve endorser client for install: endorser client failed to connect to localhost:7051: failed to create new connection: context deadline exceeded
Usage:
peer lifecycle chaincode install [flags]

Flags:
--connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
-h, --help help for install
--peerAddresses stringArray The addresses of the peers to connect to
--tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag

Global Flags:
--cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
--certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
--clientauth Use mutual TLS when communicating with the orderer endpoint
--connTimeout duration Timeout for client to connect (default 3s)
--keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
-o, --orderer string Ordering service endpoint
--ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
--tls Use TLS when communicating with the orderer endpoint
--tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

Chaincode installation on peer0.org1 has failed
Deploying chaincode failed

错误原因和解决方案

可能是因为binconfig目录中的版本与启动时指定的版本不一致,./network.sh up命令使用的应该是最新的版本,确认binconfig目录下的也应该是最新的版本。可以重新替换这两个目录的代码。

链码

调用链码

1
peer chaincode invoke -o localhost:8050 --ordererTLSHostnameOverride orderer.supply.com --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem -C coreandfirstchannel -n supply --peerAddresses localhost:8051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/core.supply.com/peers/peer0.core.supply.com/tls/ca.crt --peerAddresses localhost:8053 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/f1.supply.com/peers/peer0.f1.supply.com/tls/ca.crt -c '{"function":"IssueVoucher","Args":["asset001", "100", "一级供应商"]}'

成功信息如下:

1
2020-12-28 18:37:54.285 CST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200

错误信息如下:

1
Error: could not assemble transaction: proposal response was not successful, error code 500, msg Incorrect number of params. Expected 2, received 1 - proposal response: version:1 response:<status:200 > payload:"\n \177\017\350[\344G6\010V\331\332\377\354\216&\035\317&\251[N`\023\036\033\237\237A\005\3670\260\022\266\002\n\237\002\0227\n\n_lifecycle\022)\n'\n!namespaces/fields/supply/Sequence\022\002\010\016\022\343\001\n\006supply\022\330\001\n\003\n\0011\032\320\001\n\0011\032\312\001{\"ID\":\"1\",\"issuer\":\"\346\240\270\345\277\203\344\274\201\344\270\232\",\"owner\":\"\346\240\270\345\277\203\344\274\201\344\270\232\",\"amount\":100,\"createDate\":\"2020-12-28T10:02:30.578872398Z\",\"endDate\":\"2021-06-28T10:02:30.578872527Z\",\"contractHash\":\"test\",\"invoiceHash\":\"test\"}\032\003\010\310\001\"\r\022\006supply\032\0033.0" endorsement:<endorser:"\n\016GylCoreOrg1MSP\022\222\006-----BEGIN CERTIFICATE-----\nMIICFjCCAbygAwIBAgIQU43L5gjtXO+uCpRP2jG2AjAKBggqhkjOPQQDAjBxMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEYMBYGA1UEChMPY29yZS5zdXBwbHkuY29tMRswGQYDVQQDExJjYS5j\nb3JlLnN1cHBseS5jb20wHhcNMjAxMjI1MDkxNzAwWhcNMzAxMjIzMDkxNzAwWjBa\nMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2Fu\nIEZyYW5jaXNjbzEeMBwGA1UEAxMVcGVlcjAuY29yZS5zdXBwbHkuY29tMFkwEwYH\nKoZIzj0CAQYIKoZIzj0DAQcDQgAErf3R+7XpNQpmTsMO+iM4WS7IrOoafiPbAS7Q\nbuFFR3Qs4riIczgSmjh9rOA6I1q2q0CstLhfWDbqpf+8fXPUlKNNMEswDgYDVR0P\nAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAguznqsTisa64dNvOR\nvPwP0KGklWohNpbSe7VgIghx4L8wCgYIKoZIzj0EAwIDSAAwRQIhALIw1VMzezCg\n9LONbO4+V+weY42HQLbShkTP/gCFnGRYAiARyLLSDJIC2wwzSvOHNdm+aDRtbqGC\nNJenP9hmEbYsTw==\n-----END CERTIFICATE-----\n" signature:"0E\002!\000\251\370K6S\020\373\242\321\000\211\312\0001\333\365>\314\324\231\020>u;+\243\303dD\023\221\237\002 z \224\236R\355Z\251\202\363\035\304\365\212\277\235\375?\376\030\371\236\220\354iG6\244\334M\315\331" >

原因是因为下图,只有一个组织的链码更新到了最新的版本。

![截屏2020-12-28 18.03.06](/Users/apple/Desktop/截屏2020-12-28 18.03.06.png)

**解决方案:**原因是因为设置环境变量CC_PACKAGE_ID时只设置了一个组织的peer,导致旧的环境变量还在生效,重新操作一遍问题解决。

调用chaincode时报错VSCC error如下:

1
2
3
4

2021-01-07 06:44:40.479 UTC [vscc] Validate -> ERRO 62f VSCC error: stateBasedValidator.Validate failed, err validation of endorsement policy for chaincode secured_supply in tx 12:0 failed: implicit policy evaluation failed - 1 sub-policies were satisfied, but this policy requires 3 of the 'Endorsement' sub-policies to be satisfied
2021-01-07 06:44:40.479 UTC [committer.txvalidator] validateTx -> ERRO 630 Dispatch for transaction txId = 101fe5e0aaaafbabcf31a5ce66fa48b92ab834456ba73cdb29730679bd637847 returned error: validation of endorsement policy for chaincode secured_supply in tx 12:0 failed: implicit policy evaluation failed - 1 sub-policies were satisfied, but this policy requires 3 of the 'Endorsement' sub-policies to be satisfied
2021-01-07 06:44:40.479 UTC [committer.txvalidator] Validate -> INFO 631 [alljoinchannel] Validated block [12] in 2ms

错误原因:

背景是我的测试环境有四个组织安装了相同的链码,链码的背书策略是默认的 /Channel/Application/Endorsement所以要求大多数背书,而我只让一个组织签名,所以导致错误。

查询chaincode是否可以被提交时报错

再所有的组织都批准了链码之后,查询批准结果返回的全部是false。

1
2
3
4
5
6
7
8
9
(base) w:supply-finance apple$ peer lifecycle chaincode checkcommitreadiness --channelID alljoinchannel --name secured_supply --version 2.0 --sequence 2 --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem --output json
{
"approvals": {
"GylCoreOrg1MSP": false,
"GylFOrg1MSP": false,
"GylSOrg1MSP": false,
"GylSOrg2MSP": false
}
}

错误原因及解决方案:

因为批准的时候制定了签名策略,但是查询的时候没有指定;在查询时指定背书策略即可。

1
2
3
4
5
6
7
8
9
(base) w:supply-finance apple$ peer lifecycle chaincode checkcommitreadiness --channelID alljoinchannel --name secured_supply --version 2.0 --sequence 2 --signature-policy "OR('GylCoreOrg1MSP.peer','GylFOrg1MSP.peer','GylSOrg1MSP.peer','GylSOrg2MSP.peer')" --tls --cafile ${PWD}/organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp/tlscacerts/tlsca.supply.com-cert.pem --output json
{
"approvals": {
"GylCoreOrg1MSP": true,
"GylFOrg1MSP": true,
"GylSOrg1MSP": true,
"GylSOrg2MSP": true
}
}

signature set did not satisfy policy 签名集合与策略不一致

1
2
2021-01-05 09:40:29.461 UTC [vscc] Validate -> ERRO 3212 VSCC error: stateBasedValidator.Validate failed, err validation of key asset001 (coll'':ns'secured_supply') in tx 59:0 failed: signature set did not satisfy policy
2021-01-05 09:40:29.461 UTC [committer.txvalidator] validateTx -> ERRO 3213 Dispatch for transaction txId = 7d13143d4a24fe370528b0e47e6e8a71d7a8b660798c424769a57b67a9cb69ae returned error: validation of key asset001 (coll'':ns'secured_supply') in tx 59:0 failed: signature set did not satisfy policy

又遇到了签名和背书策略不一致的问题。

Troubleshooting网站

1
2
3
4
5
6
7
Why are my transactions returning an endorsement policy error: signature set did not satisfy policy?
问题情况
When I invoke a smart contract to submit a transaction, the transaction returns the following endorsement policy failure:

returned error: VSCC error: endorsement policy failure, err: signature set did not satisfy policy
问题原因
If you have recently joined a channel and installed the smart contract, this error occurs if you have not added your organization to the endorsement policy. Because your organization is not on the list of organizations who can endorse a transaction from the smart contract, the endorsement from your peers is rejected by the channel. If you encounter this problem, you can change the endorsement policy by upgrading the smart contract. For more information, see Specifying an endorsement policy and Upgrading a smart contract.

错误原因一级解决方案

这个错误的背景是channel、chaincode和key的背书策略都不一样,具体如下:

  • channel:默认的,需要大多数签名
  • chaincode:指定了OR(‘GylCoreOrg1MSP.member’,‘GylFOrg1MSP.member’,‘GylSOrg1MSP.member’,‘GylSOrg2MSP.member’)
  • key:设置了SetStateValidationParameter,只需要拥有者的签名

具体的解决方案需要确认链码的编写是否有问题。