This blog post will show how to deploy a local Corda cluster for day-to-day development and testing. For this, we will use an All-In-One combined worker cluster. It will help if you read the previous article about Next-Gen Corda’s basic architecture as a prerequisite.
The Corda cluster is of no use until we deploy an application network by uploading CPIs and unless we create virtual nodes. Next-Gen Corda supports two types of application networks – static and dynamic. Static networks are meant to be used for development and testing. You do not need to set up an MGM for onboarding identities to such a network.
This blog post will use an all-in-one worker to set up a Corda cluster locally and deploy a static network. Next-Gen Corda also provides CSDE, a Corda Standard Development Environment, that defines some convenient Gradle tasks that automates starting the cluster and deploying the CorDapp onto your cluster.
Let’s start an all-in-one Corda cluster and deploy a CorDapp onto it.
Step 1: Clone CSDE
Clone the CSDE sample. The CSDE provides a ready-set-up CorDapp project which you can use as a starting point to develop your prototypes. It consists of a set of Gradle helper tasks which speed up and simplify the development and deployment process.
As a prerequisite to CSDE, you need the Corda CLI installed on your system. CSDE also requires Docker to be installed to run the combined worker cluster.
Step 2: Start the All-in-one-combined worker cluster
Start the startCorda Gradle task. It downloads the combined worker from the Artifactory and JDBC Postgres driver to your home directory and starts a local JVM combined worker process. You can also check if the combined worker has started by running a ps grep command. The startCorda task starts an instance of Docker Postgres, which will be used as a database by the combined worker cluster.
Next, we will use Kafka as a message bus for production-grade cluster deployment. But the combined-worker uses the Postgres database as the emulated message bus for development and testing. You can test if the cluster is started by hitting the swagger API at localhost:8888/api/v1/swagger#/
Step 3: Click the quickdeploy Gradle task
As a next step, we will run the quickdeploy Gradle task, which combines specific Gradle tasks, and lets you deploy your CorDapp in minutes. Let’s understand what happens when you run the quickDeploy task.
A group policy file is created
For a static network, we will be using a static GroupPolicy file. This is generated internally using the Corda CLI tool. The GroupPolicy file consists of a staticNetwork field that lets you start a static network in your local Corda cluster deployment.
A CPI file is created
The workflow and contract classes are bundled into a .CPK file and ultimately bundled into a .CPI file.
Upload the .CPI file to the local cluster
We have created a CorDapp bundle(.CPI file), and associated it with a particular group/network. Now as a next step, we will upload this .CPI file to the Corda cluster. The CPI is uploaded to the network by calling the HTTP REST API /cpi. This returns a CPI checksum, which will be used in the next step. Uploading the CPI makes it available by the identities/virtual nodes when required.
Let’s run the listCpi Gradle task, and you should see the list of available CPI’s.
Create virtual nodes
The CorDapps are of no use until someone uses them. We will use the HTTP REST API to create a virtual node by passing in the x500 name of the identity and the CPI checksum returned in the previous step. This associates an identity to a CorDapp and to a specific application network.
Register a virtual node to an MGM
But it’s still not useful until everyone on the network knows this virtual node is available for interaction. For a static network, the membership is automatically approved. We will talk more in the next blog post about how to setup a dynamic network, and how MGM approves the membership request made by the virtual node for a dynamic network.
So the Corda cluster is set up, a CorDapp and the network information (CPI) have been uploaded to the cluster, and virtual nodes have been created for Alice,Bob and Charlie.
To reset your cluster by following the below-mentioned steps.
- Click the stopCorda Gradle task
- Delete the /workspace directory from your CSDE project.
- Delete the /home/.corda/corda5 directory.
- Confirm if any corda-worker-combined process is still alive using the below grep command and kill the process using process-id.
ps -ef | grep corda-combined-worker
How to write a Next-Gen Corda CorDapp?
You can look at these steps about how to write a Next-Gen CorDapp.
How do we use the HTTP RPC API to hit a flow?
You can look at these steps, which discuss triggering a flow.
In the next article, we will explore how to set up a local static network with individual worker nodes.