Victor Lopez
Victor Lopez

Reputation: 110

Migrate to 2.0 Lifecycle, Hyperledger Fabric EVM

I'm trying, without much luck, to compile the EVM chaincode that is been packed with Hyperledger Fabric from https://github.com/hyperledger/fabric-chaincode-evm

It is required for us to compile this to version 2.0.1 of the ledger since that's what our network uses, everything runs fine, I managed to compile with the fabric v2.0.0 dependency inside the go.mod dependencies file and later on pulled the missing 1.4.0 dependencies (peer, shim) with

go get github.com/hyperledger/fabric/protos/peer
go get github.com/hyperledger/fabric/core/chaincode/shim

Also changed integration/vendor/github.com/hyperledger/fabric/protos/common/configuration.proto from 1 to 2, like so:

message Capabilities {
    map<string, Capability> capabilities = 2;
}

However, when making instantiation I'm getting an error:

Error: could not assemble transaction, err proposal response was not successful, error code 500, msg Channel 'evm' has been migrated to the new lifecycle, LSCC is now read-only

I'm not sure where can I change the flag to use the new lifecycle inside the EVM chaincode, I'm not a go expert, so I better put this as a question and rely on more expert developers.

How can I upgrade to the new lifecycle?

I think I'm missing the command parameters to approve the chaincode for all the peers inside the network, I'm trying

peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --channelID evm --name evmcc --version ${EVM_VERSION} --init-required --package-id ${PACKAGE_ID} --sequence ${EVM_VERSION} --waitForEvent

But I don't know how to extract the package-id from an installed chaincode package.

Thanks in advance.

Upvotes: 0

Views: 1010

Answers (1)

Victor Lopez
Victor Lopez

Reputation: 110

It got solved by using invoke.

Instead of instantiating first we approve for the org, then invoke for each peer in the network. Like so:


export PEER_CONN_PARMS="--peerAddresses $ORG1_PEER0_CORE_PEER_ADDRESS --peerAddresses $ORG1_PEER1_CORE_PEER_ADDRESS --peerAddresses $ORG2_PEER0_CORE_PEER_ADDRESS --peerAddresses $ORG2_PEER1_CORE_PEER_ADDRESS --tlsRootCertFiles $ORG1_PEER0_CORE_PEER_TLS_ROOTCERT_FILE --tlsRootCertFiles $ORG1_PEER1_CORE_PEER_TLS_ROOTCERT_FILE --tlsRootCertFiles $ORG2_PEER0_CORE_PEER_TLS_ROOTCERT_FILE --tlsRootCertFiles $ORG2_PEER1_CORE_PEER_TLS_ROOTCERT_FILE"

echo $PEER_CONN_PARMS

peer lifecycle chaincode package evmcc.tar.gz --path ${CC_SRC_PATH} --lang ${CC_RUNTIME_LANGUAGE} --label evmcc_${VERSION} >&log.txt
cat log.txt

setGlobals 1 0

peer lifecycle chaincode install evmcc.tar.gz --peerAddresses $ORG1_PEER0_CORE_PEER_ADDRESS  --tlsRootCertFiles $ORG1_PEER0_CORE_PEER_TLS_ROOTCERT_FILE >&log.txt
cat log.txt

setGlobals 1 1

peer lifecycle chaincode install evmcc.tar.gz --peerAddresses $ORG1_PEER1_CORE_PEER_ADDRESS --tlsRootCertFiles $ORG1_PEER1_CORE_PEER_TLS_ROOTCERT_FILE >&log.txt
cat log.txt

setGlobals 2 0

peer lifecycle chaincode install evmcc.tar.gz --peerAddresses $ORG2_PEER0_CORE_PEER_ADDRESS --tlsRootCertFiles $ORG2_PEER0_CORE_PEER_TLS_ROOTCERT_FILE >&log.txt
cat log.txt

setGlobals 2 1

peer lifecycle chaincode install evmcc.tar.gz --peerAddresses $ORG2_PEER1_CORE_PEER_ADDRESS --tlsRootCertFiles $ORG2_PEER1_CORE_PEER_TLS_ROOTCERT_FILE >&log.txt
cat log.txt

peer lifecycle chaincode queryinstalled >&log.txt
PACKAGE_ID=$(sed -n "/evmcc_${VERSION}/{s/^Package ID: //; s/, Label:.*$//; p;}" log.txt)

cat log.txt

echo $PACKAGE_ID

setGlobals 1 0

peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name evmcc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence ${SEQUENCE}  >&log.txt
cat log.txt 

setGlobals 2 0

peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name evmcc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence ${SEQUENCE}  >&log.txt
cat log.txt 


ORGAPPROVAL=$(peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID ${CHANNEL_NAME} --tls --cafile $ORDERER_CA --name evmcc --version ${VERSION} --init-required --sequence ${SEQUENCE} --output json | jq -r '.approvals') 


ORG1APPROVAL=$(echo $ORGAPPROVAL | jq -r --arg key "$ORG1_MSP" '.[$key]')
ORG2APPROVAL=$(echo $ORGAPPROVAL | jq -r --arg key "$ORG2_MSP" '.[$key]')

if [ "$ORG1APPROVAL" = true ] ; then
    if [ "$ORG2APPROVAL" = true ] ; then
        peer lifecycle chaincode commit -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name evmcc $PEER_CONN_PARMS --version ${VERSION} --sequence ${SEQUENCE} --init-required >&log.txt
        cat log.txt

    fi

fi

setGlobals 1 0

#peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n evmcc -v ${VERSION} -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')"

peer chaincode invoke -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n evmcc $PEER_CONN_PARMS --isInit -c '{"function":"Init","Args":[]}' >&log.txt
cat log.txt


setGlobals 1 1

peer chaincode invoke -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n evmcc $PEER_CONN_PARMS --isInit -c '{"function":"Init","Args":[]}' >&log.txt
cat log.txt

setGlobals 2 0

peer chaincode invoke -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n evmcc $PEER_CONN_PARMS --isInit -c '{"function":"Init","Args":[]}' >&log.txt
cat log.txt

setGlobals 2 1

peer chaincode invoke -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n evmcc $PEER_CONN_PARMS --isInit -c '{"function":"Init","Args":[]}' >&log.txt
cat log.txt

Upvotes: 1

Related Questions