Summary of Hyperledger Fabric issues (continuously updated)

Hyperledger Fabric 2.4.1 2.3.3 problem summary (continuously updated)


Ubuntu 20.04
Hyperledger Fabric 2.3.3
SDK Corresponding Go 1.17.5
Chaincode Corresponding Go 1.18
Fabric-sdk-go 1.0.0
Docker 20.10.12
Docker-Compose 2.11.2

1. After the chaincode is submitted, there is an error in calling the contract function, and the channelID is empty:

call command:

peer chaincode invoke -o localhost:7050 – ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID cychannel --name marriage --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c ‘{“function”:“Register”,“Args”:[“1001”,“jack”]}’

The following error occurs:

Error: The required parameter ‘channelID’ is empty. Rerun the command with -C flag

reason:

There is a problem with the indentation of the called command (commands are error-prone when copied from the local to the virtual machine), and there must be no spaces after --

After solving:

2023-01-03 21:54:08.247 CST 0001 INFO [chaincodeCmd] chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200


2. After the chaincode is submitted, there is an error calling the contract function, the status code is 500, and the chaincode is not installed:

call command:

peer chaincode query -C cychannel -n marriage -c ‘{“Args”:[“searchMarriageInfoByClientId”,“1001”]}’

The following error occurs:

Error: endorsement failure during query. response: status:500 message:“make sure the chaincode marriage has been successfully defined on channel cychannel and try again: chaincode definition for ‘marriage’ exists, but chaincode is not installed”

reason:

This error occurs when the chaincode is successfully submitted. The reason is that the function name starts with a lowercase, which is only valid for calling within this package, and cannot be called externally. Just change the function name to start with an uppercase.

After solving:

{“id”:“1001”,“marriage_id”:“”,“person_name”:“jack”,“is_married”:false}

Supplement: This problem also occurs in another situation
scene:

The local host calls the chaincode of the remote cloud server through the Go-SDK (the firewall has opened TCP 7051 and 9051 ports).

reason:

I added permission judgment in the chaincode function (only clients with org1 certificates can access):
insert image description here
As a result, when I initialized the contract object in the sdk, I used the certificate of org2. Therefore, delete the generated wallet file (this step is critical), and modify all org2 in the code to org1, successfully.


3. When the local SDK calls the chaincode of the remote host, an error is reported, connection is in TRANSIENT_FAILURE:

The following error occurs:

event service creation failed: could not get chConfig cache reference: QueryBlockConfig failed: QueryBlockConfig failed: queryChaincode failed: Transaction processing for endorser [192.168.6.149:7051]: Endorser Client Status Code: (2) CONNECTION_FAILED. Description: dialing connection on target [192.168.6.149:7051]: connection is in TRANSIENT_FAILURE

reason:

The structure of my local SDK project is as follows:
insert image description here
the configuration file I use is under test-network under fabric-samples, and three things need to be prepared in advance:
① Modify the url of connection-org1.yaml in local organizations to the IP of the remote host :
insert image description here
insert image description here

② Add the domain name resolution of the remote host in the local hosts file.
insert image description here

③ Every time the chaincode is successfully deployed, the organizations of the local project need to be updated from the test-network (one organization can only be used for one SDK project).
insert image description here

After ensuring that the above work is correct, run main.go to call the remote chain code and report an error...
The reason is that fabric-sdk-go is not compatible with fabric2.4.x, and the problem is successfully solved after replacing it with fabric2.3.3.
(If you want to use the 2.4.x version, you need to use the new sdk: fabric-gateway, whose Github address is https://github.com/hyperledger/fabric-gateway)
insert image description here


4. The local SDK calls the chaincode of the remote host and reports an error, configure MSP failed: sanitizeCert failed the supplied identity is not valid: x509: certificate signed by unknown authority:

reason:

Go version problem, my local Go version is 1.19.2, after changing to 1.17.5, the problem is solved.

After solving:

The SDK finally started successfully, and the remote chaincode can be called normally.
insert image description here


5. When creating a channel, the ./network.sh up createChannel command reports an error, and the error message is osnadmin: error: unknown long flag '–channel -id', try --help

Solution:

You need to modify the createChannel.sh file under fabric-samples/test-network/scripts, and change –channel-id in the createChannel function to –channelID
insert image description here

6. When calling the chaincode of the remote host through the SDK, an error is reported: UTC - lazyref.(*Reference).refreshValue -> WARN Error - initializer returned error: load MSPs from config failed: configure MSP failed: sanitizeCert failed the supplied identity is not valid: x509: certificate signed by unknown authority. Will retry again later

Solution:

It's still a problem with the Go version. After I replaced Go 1.19.2 with Go 1.17.5, the problem was solved.

7. How does the SDK set the wallet generation path?

Solution:

wallet, err := gateway.NewFileSystemWallet(“org1/wallet”)


8. Failed to invoke chaincode

Error message:

Error: endorsement failure during invoke. response: status:500 message:“error in simulation: failed to execute transaction 306ed1ca53720d68d6e392198014ca2e91fbfa79a9f6e6be7a7e40f497bf4b1e: could not launch chaincode rent_1.0:e678092929f2e636a5bcb1ddbfd52dd04c45b1fc5128a2a4cf883cb5c7991ee9: chaincode registration failed: container exited with 2”

reason:

The problem with the chaincode itself. Each chaincode function has a receiver of pointer type, and the corresponding instance is a contract that inherits contractapi.Contract. And I accidentally wrote the instance as a custom structure, which caused an error.

Solution:

Defined contract:
insert image description here

mistake:
insert image description here

correct:
insert image description here


9. In the chain code, the contractapi version problem

insert image description here

go mod tidy imports the latest version by default. As of now (2023.03.17), the latest version of contractapi is 1.2.1, which requires the version of go to be above 1.19 (a month ago, the latest version of contractapi was 1.2.0, which supports go 1.18 and does not This problem will occur), and my local go is version 1.18, so there will be an error when installing the chain code.

And after I changed the go version to 1.19, there was an unexpected error when installing the chain code... Therefore, I can only modify the version of contractapi to support the lower version of go. Since the go version of the virtual machine where my chaincode is located is 1.18, I changed the version of the contractapi to 1.2.0 (1.2.0 requires the go version to be above 1.17), which is compatible.

module xxx

go 1.18

require github.com/hyperledger/fabric-contract-api-go v1.2.0

require (
	github.com/go-openapi/jsonpointer v0.19.5 // indirect
	github.com/go-openapi/jsonreference v0.20.0 // indirect
	github.com/go-openapi/spec v0.20.6 // indirect
	github.com/go-openapi/swag v0.21.1 // indirect
	github.com/gobuffalo/envy v1.10.1 // indirect
	github.com/gobuffalo/packd v1.0.1 // indirect
	github.com/gobuffalo/packr v1.30.1 // indirect
	github.com/golang/protobuf v1.5.2 // indirect
	github.com/hyperledger/fabric-chaincode-go v0.0.0-20220720122508-9207360bbddd // indirect
	github.com/hyperledger/fabric-protos-go v0.0.0-20220613214546-bf864f01d75e // indirect
	github.com/joho/godotenv v1.4.0 // indirect
	github.com/josharian/intern v1.0.0 // indirect
	github.com/mailru/easyjson v0.7.7 // indirect
	github.com/rogpeppe/go-internal v1.8.1 // indirect
	github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
	github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
	github.com/xeipuuv/gojsonschema v1.2.0 // indirect
	golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
	golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
	golang.org/x/text v0.3.7 // indirect
	google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f // indirect
	google.golang.org/grpc v1.48.0 // indirect
	google.golang.org/protobuf v1.28.0 // indirect
	gopkg.in/yaml.v2 v2.4.0 // indirect
)

10. The local SDK failed to access the chaincode in the server

Error message:

“Failed to submit: Multiple errors occurred: - Transaction processing for endorser [localhost:7051]: Endorser Client Status Code: (2) CONNECTION_FAILED. Description: dialing connection on target [localhost:7051]: connection is in TRANSIENT_FAILURE - Transaction processing for endorser [localhost:9051]: Endorser Client Status Code: (2) CONNECTION_FAILED. Description: dialing connection on target [localhost:9051]: connection is in TRANSIENT_FAILURE”

Solution:

Set DISCOVERY_AS_LOCALHOST to false in the SDK, otherwise a request will be sent to the local, and the chaincode is placed on the server, which is obviously impossible to access.
insert image description here


11. The local SDK failed to access the chaincode in the server

Error message:

panic: Failed to submit: CreateAndSendTransaction failed: SendTransaction failed: calling orderer ‘orderer.example.com:7050’ failed: Orderer Client Status Code: (2) CONNECTION_FAILED. Description: dialing connection on target [orderer.example.com:7050]: waiting for connection failed: context deadline exceeded [recovered]
panic: Failed to submit: CreateAndSendTransaction failed: SendTransaction failed: calling orderer ‘orderer.example.com:7050’ failed: Orderer Client Status Code: (2) CONNECTION_FAILED. Description: dialing connection on target [orderer.example.com:7050]: waiting for connection failed: context deadline exceeded

analyze:

Looking at the error message, it seems that the access to the orderer node failed. It turned out that the server did not open port 7050.

Solution:

open server port
insert image description here

A similar problem arises in another case:

I added the domain name resolution of multiple servers in the local host file, that is, the domain name of the same organization corresponds to multiple IPs. You need to ensure that the ip in the host file is the ip of the server where the chaincode you want to access is located.


12. After re-opening a terminal, how to call the chaincode function?

method:

PWD=‘/myFabric/fabric-samples/test-network’

export PATH=${PWD}/…/bin:$PATH

export FABRIC_CFG_PATH=${PWD}/…/config/

export CORE_PEER_TLS_ENABLED=true

export CORE_PEER_LOCALMSPID=“Org1MSP”

export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp

export CORE_PEER_ADDRESS=localhost:7051

After setting the above environment variables, just call the chaincode function from the command line.


13. How to convert the character slice obtained through SDK query into an object?

method:

For a json string representing a single object, deserialize to map[string]interface{};
for a json string representing an array of objects, deserialize to []map[string]interface{};

//根据用户ID获取该用户的缴税记录
taxes, err := utils.TaxContract.EvaluateTransaction("GetAllTaxesByUserId", userId)
if err != nil {
    
    
	return err
}
var res []map[string]interface{
    
    }
json.Unmarshal(taxes, &res)
fmt.Println(res)

insert image description here


Guess you like

Origin blog.csdn.net/weixin_46878177/article/details/128540169