Even When I'm Down to the Wire Baby

m

Nima Kaviani HackerNoon profile picture

@ nimak

Nima Kaviani

Senior Cloud Engineer

Project BlockHead: An Ethereum Smart Contract Service Broker for Kubernetes and Deject Foundry

This blogpost is co-authored past Swetha Repakula , morgan bauer , and Jonathan Berkhahn

With the growing interest in blockchain technology, software developers are looking into integrating smart contracts into their applications. Applications developed and integrated with blockchain are typically equanimous of two parts:

  • A smart contract deployed to the blockchain network
  • A Spider web application that binds to the deployed contract and uses it.

A smart contract can exist idea of as a snippet of code available at a given address in the blockchain network which is capable of receiving and processing input information, retrieving or updating ledger country, and returning results to the requesting party. The web applications using the contract are commonly referred to as Web3 applications.

Despite all the excitement in using blockchain, the end-to-end multi-step process of deploying a smart contract and integrating information technology into a Web application is fairly cumbersome. An application programmer requires to:

  1. develop or reuse a smart contract
  2. compile the contract code
  3. retrieve the executable binary and the awarding binary interface (ABI)
  4. bring upward a blockchain node (e.g., Ethereum)
  5. create or import an account (i.e. Wallet) into the node
  6. use the account to deploy the binary code into the blockchain network
  7. verify deployment and recollect the contract address
  8. and finally use the combination of the account accost, the contract address, and the contract ABI in a Web application to bind to the contract and employ it

There have been efforts to simplify the procedure of developing smart contracts. Truffle, for example, offers a development framework that brings up a local Ethereum network and allows developers to test-bulldoze development of their smart contract applications.

Yet, when information technology comes to a deployment to the principal Ethereum network (mainnet) or a test network (testnet), developers still need to manually become through the process of provisioning a blockchain node to ensure successful deployment and integration of their contracts with their applications.

As open up source platform engineers, we strive to simplify the procedure of application development for software engineers. Platform-as-a-Service (PaaS) exists on the premise of making it easier for developers to deploy, scale, and manage their applications; and platforms like Kubernetes and Deject Foundry have come a long way in simplifying application lifecycle management. Following the same premise, we believe PaaS platforms can and should simplify development of smart contract applications and go far integral to the lifecycle of smart contract applications deployed to PaaS. This is why project BlockHead was built-in.

Project BlockHead takes reward of the Open up Service Banker API specification to build a service broker layer placed between the Web application and the blockchain network. Doing and so, the banker controls management of the smart contract by automating cosmos and deployment of smart contracts and then exposing the required set up of information to the Web awarding.

Open Service Broker API

The Open up Service Broker API (OSB API) specification offers a mutual interface for the creation and integration of a service marketplace into cloud applications in such a mode that services tin can exist maintained and managed independently from the applications and still applications can hands bind and apply services through the exposed APIs. Service brokers are responsible for advertising a catalog of service offerings and service plans to the marketplace, and acting on requests from the marketplace for provisioning, bounden, unbinding, and deprovisioning.

Borrowing from the specification of the OSB API, provisioning reserves a resource on a service as an instance. In the context of the BlockHead banker, the service case represents a blockchain node connected to the blockchain network. What a binding represents may too vary by service. Cosmos of a binding provides the service instance with smart contract information for it to exist compiled and deployed and become bachelor to the application using the service. A platform marketplace may expose services from one or many service brokers, and an individual service broker may support 1 or many platform marketplaces using different URL prefixes and credentials. Motion-picture show above shows an example of interaction with the service broker API to provision a service."

More than details on how to interact with a service broker can be found below:

BlockHead Service Broker

With projection BlockHead, we aim to translate each OSB API telephone call to a series of steps in the lifecycle of the smart contract and thus hide the complexity of interaction with a blockchain away from application developers.

The get-go version of the banker is built on height of the Container Service Broker, a Cloud Foundry community projection. By utilizing the container service broker, blockchain nodes can be run inside an isolated Docker container and operate independently when deploying and binding smart contracts.

We apply the broker to deploy stateful Ethereum nodes on demand. Each step in provisioning and binding or unbinding and deprovisioning are then modified to deliver on creation / deletion of smart contracts or nodes. Motion picture below provides an overall compages for how the Blockhead service broker provisions Ethereum nodes and integrates with the Cloud Foundry applications:

The overall interaction model between the BlockHead service banker and Cloud Foundry applications

1. Deploying the Broker

The initial version of the BlockHead broker is published as a BOSH release. A BOSH release is a versioned collection of configuration properties, configuration templates, startup scripts, source lawmaking, binary artifacts, and annihilation else required to build and deploy software in a reproducible way.

In this blogpost nosotros have the BlockHead service broker deployed alongside a Deject Foundry deployment. This allows us to benefit from capabilities in Cloud Foundry to push Web3 applications and bind them to the contract service. For instructions on how to deploy Deject Foundry consult the documentation below.

One time you have a BOSH deployment environment with Cloud Foundry deployed on it, deploying the BlockHead banker is as unproblematic as running the following script:

Since Kubernetes integrates with Open up Service Banker API compliant brokers, in case yous have a Kubernetes deployment, you can hook upward the deployed BlockHead broker to your Kubernetes platform and bind to deployed smart contracts using Web3 applications deployed to Kubernetes. You can discover out how to do the integration with Kubernetes Here.

two. Service MarketPlace and Contract MarketPlace

For the banker to announced in the Cloud Foundry marketplace you need to first annals it using the post-obit command:

                bosh run-errand -d docker-broker broker-registrar              

Once the broker is registered, you can query the marketplace and you will run across the Ethereum service appear in the market place:

Farther to this, we accept likewise developed a simple contract market that would allow u.s. to listing contracts and then refer to them using their URL when bounden an awarding to an Ethereum node. To have the contract marketplace deployed, you can add your smart contracts to the marketplace, build the docker image, push it up to a docker registry and so use a command like to the post-obit to download and use it:

cf push contract-marketplace --docker-prototype nimak/contract-market

You can verify that the awarding is up and running by checking cf apps:

In our example the marketplace is available at the accost below and navigating to the address we can discover the website:

Notice on meridian of each contract definition there is a hyperlink reference to the code for the contract. This contract URL is what we use to bind the service to the application and deploy the contract. Note that deploying the contract market place is optional and if you take other ways to supply a smart contract URL to the Ethereum service, it would totally work equally well.

3. Provision the Service Instance

When a request to provision a service instance is issued, the broker starts upwardly an Ethereum node. The Ethereum node exposes its Remote Procedure Call (RPC) api for interactions and makes the endpoints available through a given accost and port number.

For the node cosmos to occur, you lot demand to first deploy a Web3 application that is intended to use the smart contract. For the case of this weblog post, we will be using our simple-node-awarding that just writes and reads a unmarried value to and from the ledger. Note that since the app does non have the contract continued to it even so, we do non start the app when pushing it otherwise the deploy will neglect.

Verify that application nora is pushed to your Deject Foundry deployment:

Next, nosotros create the Ethereum service for the deployed application:

With the asking to create the service, the service broker creates a docker container with an Ethereum node running on it.

This tin be verified with BOSH by connecting to the docker VM in the broker deployment and looking at the listing of docker containers it is running (Note that each docker container runs an instance of the Ethereum node that corresponds to the created service).

You lot encounter that the Ethereum node has its server running on port8545 which is mapped to port32771 externally and on the host vm.

iv. Create Service Binding

When binding to the service, the location of a smart contract in the class of a URL is passed to the banker. The banker downloads the contract, compiles it, extracts the ABI and pushes the binary to the Ethereum node using the account created at the fourth dimension of launching the service.

We mentioned earlier that the sample contract market place provides the link to the given contract, so nosotros can simply get the URL location of the contract and bind it to the application.

Note that when binding the service we pass the contract_url in the class of an inlined JSON configuration to cf demark-service.

With the service binding going through successfully, we can issue a cf env command to run into the updated listing of surroundings variables for the application.

Under VCAP_SERVICES the configuration for eth involves credentials data for the eth_node such as contract abi, business relationship address, contract address, transaction hash for the deployed contract, as well equally the host address and port mappings for the awarding to connect to the Ethereum node.

Going back to the sample node application referenced earlier, you lot see that the lawmaking in the application uses these environs variables to exist able to demark to the smart contract and use it.

And VOILA! with that information, you tin define routes for you node.js application to get and fix values into the ledger using the smart contract:

5. Delete Service Bounden

When unbinding the service, the banker assumes that the contract used during the bind stage is no longer required, as a result, upon receiving an unbind request, the broker detaches the service from the application and removes the injected contract information from VCAP_SERVICES, just keeps the node around for it to possibly have other contracts deployed to it. Newly deployed contracts will use the aforementioned Ethereum node with the aforementioned business relationship created during the service creation stage.

In case of our running example, the following command would unbind the contract:

cf unbind-service nora simple

half-dozen. Deprovision Service Instance

When a asking is issued to deprovision the service, the service banker proceeds to delete the docker container:

Challenges and Future Improvement Plans

one. Syncing the Ledger

Like many other blockchain networks, nodes in Ethereum require the total ledger to exist nowadays for subsequent transactions to accept issue. This implies that the docker container created by the BlockHead service banker either needs to include the full ledger at the fourth dimension it gets created or to sync the ledger later on the container is created. The latter is very time intensive. The ledger size for the mainnet Ethereum is around 600GB and growing. Given the ledger size, information technology would take considerable amount of time for the provisioned Ethereum node to sync its ledger and be prepare, making the integration impractical.

An alternative solution is for the service broker to maintain a warm docker epitome with a adequately up-to-date copy of the ledger to apply when creating a service. This requires the banker to run a side node that constantly syncs its ledger with the ledger for the Ethereum network and to periodically create and publish an Ethereum node docker image.

Currently, the service broker launches the Ethereum node in developer mode which implies starting with a fresh ledger. This helps us chop-chop bring upwards a development environment to test Web3 applications against while avoiding the long await for ledger syncup. We program to implement techniques that would let quick startup of an Ethereum node confronting the mainnet or testnet for production purposes every bit well.

2. Retention footprint

Syncing the ledger involves reading transaction blocks from other peers in the network, validating them, so adding them to the local copy of the ledger. Since writing to the deejay is I/O intensive, an Ethereum node maintains a subset of the ledger in retention while performing validation and chaining of the nodes before writing the new blocks to the disk. This constrains memory usage on the VMs deploying Ethereum nodes and puts an upper bound to the number of containers that can be run and managed by the broker.

3. Business relationship Management

Every bit mentioned before, Ethereum nodes need to bind to an Ethereum business relationship before being capable of deploying contracts. This implies that the broker either needs to manage Ethereum accounts past both internally creating and and then exposing them to the application developers or by allowing the developers to import their own accounts to employ with the broker.

Currently accounts get discarded upon deleting the smart contract service and the corresponding Ethereum node. This will be revised for the accounts to be exportable / downloadable.

Summary

In this web log post we discussed the implementation of Project BlockHead as a service broker to be used in PaaS platforms such every bit Cloud Foundry and Kubernetes. The goal of Project BlockHead is to simplify how smart contracts are deployed and used in Web3 applications by taking away the complication of deploying and managing blockchain nodes.

While we described the finish-to-end process of deploying and using the banker, awarding developers need to only care near Steps three to six of the process described above. This involves creating a smart contract service and binding it to an application. Steps 1 and 2 of deploying the service broker and the contract marketplace would potentially be done only one time and typically managed past platform engineers and operations engineers, simplifying the overall procedure.

Project BlockHead came well-nigh as a hackathon project during Cloud Foundry Summit 2018 in Boston and every bit yous might accept noticed most of the repositories we shared in this web log mail service are personal github repositories of our team participating in the hackathon. Luckily the projection has received proficient corporeality of interest from the community and hopefully in the nearly time to come it will find a new home as an incubated projection and be properly CI/CD-ed. So come back to this blog post for farther announcements as to where you tin can observe the official project repository. Information technology is an open source project and we certainly welcome any contribution to make it better.

Tags

# ethereum# project-blockhead# smart-contract-broker# smart-contracts# kubernetes

Related Stories

petersonsearattables1950.blogspot.com

Source: https://hackernoon.com/project-blockhead-an-ethereum-smart-contract-service-broker-for-kubernetes-and-cloud-foundry-88390a3ac63f

0 Response to "Even When I'm Down to the Wire Baby"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel