This guide shows how to deploy and run a FPC Chaincode on test-network provided by fabric-samples.
We provide fabric-samples as a submodule in $FPC_PATH/integration/test-network/fabric-samples.
Before moving forward, follow the main README to set up your environment. This guide works also with the FPC Dev docker container.
We start with building the FPC components as docker images which are deployed on our test network.
Use TEST_CC_ID and TEST_CC_PATH to define the FPC Chaincode you want to build.
cd $FPC_PATH/integration/test-network/
export TEST_CC_ID=echo
export TEST_CC_PATH=${FPC_PATH}/examples/echo
make buildNote: If you want to build with mock-enclave rather than the real enclave-based one, build with
make build GOTAGS="-tags mock_ecc" instead.
Next, setup fabric sample network, binaries and docker images. Here we follow the official Fabric instructions.
cd $FPC_PATH/integration/test-network/fabric-samples
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.3.0 1.4.9 -sBefore we can start the network, we need to update the Fabric peer configuration to enable FPC support.
That is, we need to install the external builders by adding the following lines to the peers core.yaml:
chaincode:
externalBuilders:
- path: /opt/gopath/src/github.com/hyperledger-labs/fabric-private-chaincode/fabric/externalBuilder/chaincode_server
name: fpc-external-launcher
propagateEnvironment:
- CORE_PEER_ID
- FABRIC_LOGGING_SPECSince the Fabric-Samples test network uses docker and docker-compose, we need to ensure that the external Builder
scripts are also available inside the peer container. For this reason, we mount $FPC_PATH/fabric/externalBuilder/chaincode_server into
/opt/gopath/src/github.com/hyperledger-labs/fabric-private-chaincode/fabric/externalBuilder/chaincode_server.
For convenience, we provide a setup.sh script to update the core.yaml and the docker compose files to mount the external
Builder.
cd $FPC_PATH/integration/test-network
./setup.shLet's start the Fabric-Samples test network.
cd $FPC_PATH/integration/test-network/fabric-samples/test-network
./network.sh up
./network.sh createChannel -c mychannel -ca -cai 1.4.9 -i 2.3.0Next, we install the FPC Enclave Registry and our FPC Chaincode on the network by using the standard Lifecycle commands,
including chaincode package, install, approveformyorg, and commit. An important detail here is that the
chaincode packaging differs from traditional chaincode. Since we are using the external Builder and run the FPC Chaincode
as Chaincode as a Service (CaaS), the packaging artifact will contain information including the CaaS endpoint rather
than the actual Chaincode.
We continue with the following command to install the FPC Chaincode as just described.
cd $FPC_PATH/integration/test-network
./installFPC.sh
# IMPORTANT: a successfully install will show you an `export ...`
# statement as stdout on the command-line. Copy/Paste this statement
# into your shell or below starting of FPC containers will not work properly
# (but also would not give you clear errors that it doesn't!!)Now we have the FPC Chaincode installed on the Fabric peers, but we still need to start our chaincode containers.
Make sure you have set TEST_CC_ID to the same chaincode ID as used in the earlier step when building the chaincode.
# Start FPC container
export TEST_CC_ID=echo
make ercc-ecc-startThe FPC Chaincode is now up and running, ready for processing invocations!
Now we show how to use the FPC Client SDK to interact with the FPC Chaincode running on the test network.
The Fabric-Samples test network generates the connection profiles which are required by the FPC Client SDK to connect to
the network. For example, you can find the connection profile for org1 in
$FPC_PATH/integration/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/.
However, the generated connection profiles are missing some additional information to be used with FPC, in particular, to use
the LifecycleInitEnclave command.
Moreover, FPC Client SDK currently requires the connection profile to contain the connection details of the peer that hosts the FPC Chaincode Enclave. We use a helper script to update the connect profile files.
cd $FPC_PATH/integration/test-network
./update-connection.shNow we will use the go app in ${FPC_PATH}/client_sdk/go/sample to demonstrate the usage of the FPC Client SDK.
In order to initiate the FPC Chaincode enclave and register it with the FPC Enclave Registry, run the app with the -withLifecycleInitEnclave flag.
cd $FPC_PATH/client_sdk/go/sample
CC_ID=echo ORG_NAME=Org1 go run . -withLifecycleInitEnclaveNote that we execute the go app as Org1, thereby creating and registering the FPC Chaincode enclave at peer0.org1.example.com. Alternativley, we could run this as Org2 to initiate the enclave at peer0.org2.example.com.
Afterwards you must run the application without the withLifecycleInitEnclave flag and you can play with multiple organizations.
cd $FPC_PATH/client_sdk/go/sample
CC_ID=echo ORG_NAME=Org1 go run .
CC_ID=echo ORG_NAME=Org2 go run .make -C $FPC_PATH/integration/test-network ercc-ecc-stop
cd $FPC_PATH/integration/test-network/fabric-samples/test-network
./network.sh downFor diagnostics, you can run the following to see logs for peer0.org1.example.com.
docker logs -f peer0.org1.example.com
docker logs -f ercc.peer0.org1.example.com
docker logs -f ecc.peer0.org1.example.comTo interact with the peer using the peer CLI, run the following
cd $FPC_PATH/integration/test-network/fabric-samples/test-network;
export FABRIC_CFG_PATH=$FPC_PATH/integration/test-network/fabric-samples/config
export PATH=$(readlink -f ../bin):$PATH
source ./scripts/envVar.sh; \
setGlobals 1;and you will be able to run the usual peer cli commands, e.g.,
peer lifecycle chaincode queryinstalledand, in particular, also access ercc to see the registry state, e.g.,
peer chaincode query -C mychannel -n ercc -c '{"Function": "queryChaincodeEndPoints", "Args" : ["echo"]}'
peer chaincode query -C mychannel -n ercc -c '{"Function": "queryListProvisionedEnclaves", "Args" : ["echo"]}'
peer chaincode query -C mychannel -n ercc -c '{"Function": "queryChaincodeEncryptionKey", "Args" : ["echo"]}'
peer chaincode query -C mychannel -n ercc -c '{"Function": "queryListEnclaveCredentials", "Args" : ["echo"]}'
E_ID=$(peer chaincode query -C mychannel -n ercc -c '{"Function": "queryListProvisionedEnclaves", "Args" : ["echo"]}' 2> /dev/null | jq -r '.[0]')
peer chaincode query -C mychannel -n ercc -c '{"Function": "queryEnclaveCredentials", "Args" : ["echo", "'${E_ID}'"]}'