How Many M&ms Can Fit in a Baby Bottle

m

Nima Kaviani HackerNoon profile picture

@ nimak

Nima Kaviani

Senior Cloud Engineer

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

This blogpost is co-authored by 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 adult and integrated with blockchain are typically composed of two parts:

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

A smart contract tin be thought of as a snippet of code available at a given address in the blockchain network which is capable of receiving and processing input data, retrieving or updating ledger state, and returning results to the requesting party. The web applications using the contract are normally 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 it into a Web application is fairly cumbersome. An awarding developer requires to:

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

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

Still, when information technology comes to a deployment to the main Ethereum network (mainnet) or a examination network (testnet), developers withal need to manually go through the process of provisioning a blockchain node to ensure successful deployment and integration of their contracts with their applications.

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

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

Open Service Broker API

The Open Service Banker API (OSB API) specification offers a common interface for the creation and integration of a service marketplace into deject applications in such a way that services can exist maintained and managed independently from the applications and yet applications tin hands bind and employ services through the exposed APIs. Service brokers are responsible for advert a catalog of service offerings and service plans to the marketplace, and acting on requests from the marketplace for provisioning, binding, unbinding, and deprovisioning.

Borrowing from the specification of the OSB API, provisioning reserves a resources on a service as an instance. In the context of the BlockHead broker, the service instance represents a blockchain node connected to the blockchain network. What a binding represents may also vary past service. Creation of a bounden provides the service instance with smart contract information for information technology to be compiled and deployed and go available to the application using the service. A platform market place may expose services from one or many service brokers, and an individual service broker may back up one or many platform marketplaces using different URL prefixes and credentials. Movie to a higher place shows an example of interaction with the service broker API to provision a service."

More details on how to interact with a service banker tin can exist found below:

BlockHead Service Broker

With project BlockHead, we aim to translate each OSB API call to a serial of steps in the lifecycle of the smart contract and thus hibernate the complication of interaction with a blockchain away from application developers.

The starting time version of the broker is built on elevation of the Container Service Banker, a Cloud Foundry community project. Past utilizing the container service broker, blockchain nodes tin be run inside an isolated Docker container and operate independently when deploying and bounden smart contracts.

We utilize the banker to deploy stateful Ethereum nodes on demand. Each stride in provisioning and binding or unbinding and deprovisioning are and so modified to deliver on creation / deletion of smart contracts or nodes. Picture below provides an overall architecture for how the Blockhead service broker provisions Ethereum nodes and integrates with the Cloud Foundry applications:

The overall interaction model betwixt the BlockHead service broker and Cloud Foundry applications

1. Deploying the Banker

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

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

Once y'all have a BOSH deployment environment with Cloud Foundry deployed on it, deploying the BlockHead broker is as uncomplicated as running the following script:

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

2. Service MarketPlace and Contract Market

For the broker to appear in the Deject Foundry marketplace yous need to get-go register it using the post-obit command:

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

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

Further to this, we accept as well adult a simple contract marketplace that would let usa to list contracts and and then refer to them using their URL when binding an awarding to an Ethereum node. To have the contract marketplace deployed, you can add together your smart contracts to the marketplace, build the docker image, push it up to a docker registry and and so use a control like to the following to download and utilise it:

cf push contract-marketplace --docker-image nimak/contract-marketplace

Yous can verify that the application is upward and running by checking cf apps:

In our case the market is available at the address beneath and navigating to the accost nosotros can find the website:

Find on height of each contract definition there is a hyperlink reference to the code for the contract. This contract URL is what nosotros apply to demark the service to the application and deploy the contract. Notation that deploying the contract marketplace is optional and if you have other ways to supply a smart contract URL to the Ethereum service, it would totally work every bit well.

3. Provision the Service Instance

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

For the node creation to occur, you need to first deploy a Web3 application that is intended to use the smart contract. For the case of this blog post, nosotros will be using our unproblematic-node-application that only writes and reads a single value to and from the ledger. Note that since the app does non have the contract connected to it yet, nosotros do not start the app when pushing it otherwise the deploy will fail.

Verify that awarding nora is pushed to your Cloud Foundry deployment:

Next, we create the Ethereum service for the deployed awarding:

With the request to create the service, the service banker creates a docker container with an Ethereum node running on information technology.

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

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

4. Create Service Bounden

When binding to the service, the location of a smart contract in the form of a URL is passed to the broker. The broker 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.

Nosotros mentioned earlier that the sample contract market place provides the link to the given contract, and so we tin can simply get the URL location of the contract and demark it to the application.

Notation that when bounden the service nosotros laissez passer the contract_url in the form of an inlined JSON configuration to cf demark-service.

With the service bounden going through successfully, nosotros can outcome a cf env command to see the updated listing of surroundings variables for the application.

Nether VCAP_SERVICES the configuration for eth involves credentials data for the eth_node such as contract abi, account address, contract address, transaction hash for the deployed contract, as well every bit the host address and port mappings for the application to connect to the Ethereum node.

Going back to the sample node application referenced earlier, you come across that the code in the application uses these environment variables to be able to bind to the smart contract and use it.

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

5. Delete Service Binding

When unbinding the service, the broker assumes that the contract used during the bind phase 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, but keeps the node effectually for information technology to perhaps accept other contracts deployed to it. Newly deployed contracts will apply the same Ethereum node with the same account created during the service creation phase.

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

cf unbind-service nora uncomplicated

6. Deprovision Service Instance

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

Challenges and Future Improvement Plans

one. Syncing the Ledger

Similar many other blockchain networks, nodes in Ethereum crave the full ledger to be present for subsequent transactions to accept event. This implies that the docker container created past the BlockHead service banker either needs to include the full ledger at the time it gets created or to sync the ledger later 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, it would take considerable amount of time for the provisioned Ethereum node to sync its ledger and be fix, making the integration impractical.

An culling solution is for the service broker to maintain a warm docker image with a adequately upwardly-to-engagement copy of the ledger to use when creating a service. This requires the broker 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 u.s. quickly bring upwardly a evolution environment to exam Web3 applications against while avoiding the long wait for ledger syncup. We programme to implement techniques that would let quick startup of an Ethereum node against the mainnet or testnet for product purposes likewise.

two. Memory footprint

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

3. Account Management

Equally mentioned earlier, Ethereum nodes need to bind to an Ethereum account before existence capable of deploying contracts. This implies that the banker either needs to manage Ethereum accounts past both internally creating and and then exposing them to the awarding developers or past allowing the developers to import their own accounts to utilise 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 mail 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 Projection 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 end-to-stop process of deploying and using the banker, awarding developers need to only care about Steps 3 to 6 of the process described higher up. 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 merely once and typically managed by platform engineers and operations engineers, simplifying the overall process.

Project BlockHead came near as a hackathon project during Cloud Foundry Meridian 2018 in Boston and as you might have noticed well-nigh of the repositories we shared in this blog mail are personal github repositories of our team participating in the hackathon. Luckily the project has received proficient corporeality of involvement from the customs and hopefully in the virtually time to come it volition find a new home as an incubated project and be properly CI/CD-ed. So come back to this blog post for further announcements as to where you lot tin can find the official project repository. It is an open up source project and we certainly welcome whatever contribution to make it improve.

Tags

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

Related Stories

hamlietund1960.blogspot.com

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

0 Response to "How Many M&ms Can Fit in a Baby Bottle"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel