Skip to content

Latest commit

 

History

History
 
 

fabric-driver

Fabric-Driver

This driver is for communication with a Fabric Network.

This driver implements the Driver Service specified in the driver.proto file.

Development

NOTE: Minimum requirement of npm v5.0 for patch-package to apply the patch for the fabric-network package.

Setup

Create a .env file using .env.template as the base and setting suitable environment variable values (see here) and config.json files need to be checked and updated to match the network and relay that it will be connecting to. The .env contains information related to the network and relay. The config.json contains information about the ca admin, user and its org, that is used when connecting to the network.

Enabling TLS

If the relay is TLS-enabled, set the following values in the .env:

RELAY_TLS=true
RELAY_TLSCA_CERT_PATH=path_to_tls_ca_cert_pem_for_relay
  • path_to_tls_ca_cert_pem_for_relay should be set to CA certificate file path

To enforce secure communication over TLS with your driver, set the following values in the .env:

DRIVER_TLS=true
DRIVER_TLS_CERT_PATH=path_to_tls_cert_pem_for_driver
DRIVER_TLS_KEY_PATH=path_to_tls_key_pem_for_driver
  • path_to_tls_cert_pem_for_driver should be set to driver's TLS certificate file path
  • path_to_tls_key_pem_for_driver should be set to driver's TLS private key file path

If the driver is deployed within a Docker container, set the same variables as above in the appropriate .env file. The following sample files in ./docker-testnet-envs/ can be used and tweaked for Fabric drivers associated with particular testnets:

  • Fabric network1: .env.n1 (non-TLS) and .env.n1.tls (TLS)
  • Fabric network2: .env.n2 (non-TLS) and .env.n2.tls (TLS)

Running

To do a full build run then make build-local. This update/clones protos, generates js protos and compiles TypeScript.

For tsc compilation in watch mode: npm run watch

Running the server: npm run dev

Note: Can also be run in mocked mode by setting environment variable MOCK=true

Deployment

Make sure the env and config file have the expected values.

Update the docker compose with the correct external network and ports exposed

To do a full build run make build-image. This update/clones protos, generates js protos and compiles typescript.

To deploy, run make deploy

Sample steps to use docker deployment:

  • Create a Personal Access Token with read packages access in github. Refer Creating a Personal Access Token for help.
  • Run docker login ghcr.io and use your github username and personal access token as password.
  • Copy .env.docker.template to .env and make changes appropriately (like correcting the base path of repo, changing network name if required etc, check image details here: weaver-fabric-driver).
  • Make sure connection profile used for docker, containers correct hostnames instead of localhost in urls.
  • If deploying more than one driver on same host, make sure to change service name in docker compose to avoid conflicts.
  • Finally run docker compose up -d to deploy the fabric driver.

TL/MP Environment

If you are spinning up the driver for the first time and plan to use docker in the TL/WT environemnt, either run the driver locally to generate the wallet, or copy across the wallet generated by the WT/TL application. This is to prevent issues with the CA denying creation of a new wallet. An alternative solution in the case that you have spun up the driver with docker without creating a wallet is to bash into the docker container and copy the contents of the created wallet and put them in the fabric-driver folder. The driver could be improved to have a way to revoke the prexisting identity in the CA and create a new one to avoid this issue.

Environment variables

The connection profile is required to set up the required material to communicate with the network. This should be supplied with the CONNECTION_PROFILE environment variable (ex: CONNECTION_PROFILE=path/to/con_profile.json)

<Hostname>:<Port> for connecting relay: RELAY_ENDPOINT (ex: RELAY_ENDPOINT=localhost:9081 )

Boolean for when to use mocked fabric communication: MOCK (ex: MOCK=true)

<Hostname>:<Port> for the driver to be run on: DRIVER_ENDPOINT (ex: DRIVER_ENDPOINT=localhost:9093) (Not required for docker)

Can pass in a variable 'local' for working with fabric and docker: local (ex: local=false)

Can pass in a config file for the driver to be run with: DRIVER_CONFIG (ex: DRIVER_CONFIG=./config.json)

INTEROP_CHAINCODE stores the name of the interop chaincode installed.

DB_PATH stores the path hosting the database files containing the event subscription information.

WALLET_PATH stores the path hosting the user wallets to access a network.

NOTE: When specifying ensure that they match the config that the relay is using.

For docker-compose:*

  • DOCKER_IMAGE_NAME, and DOCKER_TAG needs to specified based on weaver-fabric-driver image.
  • DRIVER_PORT is the driver server port.
  • EXTERNAL_NETWORK is the docker network in which fabric-network is running.

Push Fabric Driver image to Github container registry

  • Create a Personal Access Token with write, read, and delete packages access in github. Refer Creating a Personal Access Token for help.
  • Run docker login ghcr.io and use your github username and personal access token as password.
  • Create a copy of .npmrc.template as .npmrc.
  • Replace in copied .npmrc file with your personal access token.
  • Run make push-image to build and push the image to github registry.

NOTE: Push image to hyperledger-labs only after PR approval, first test it by deploying it on your fork by running (instead of last step above): make push-image DOCKER_REGISTRY=ghcr.io/<username>, where replace <username> with your git username.

Known Issues

If running an old version of linux or experiancing this issue

/lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found

Install libstdc++.so library that is CXXABI_1.3.8 version Update /lib64 folder with the new library or replace the existing link

NOTE

Due to how fabric works and the CA works once a wallet has been created with identities in the CA you can not create new wallet without fist revoking the original credentials. This can have some issues if you have deleted a wallet and are trying to recreate one.