banner



How Can I Know If I'm Registered To Vote

1000

Nima Kaviani HackerNoon profile picture

@ nimak

Nima Kaviani

Senior Cloud Engineer

Project BlockHead: An Ethereum Smart Contract Service Banker 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 developed and integrated with blockchain are typically composed of two parts:

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

A smart contract tin be thought of as a snippet of lawmaking available at a given accost 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 ordinarily referred to equally Web3 applications.

Despite all the excitement in using blockchain, the end-to-cease multi-step procedure of deploying a smart contract and integrating it into a Spider 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 up a blockchain node (due east.g., Ethereum)
  5. create or import an account (i.eastward. Wallet) into the node
  6. employ the business relationship to deploy the binary code into the blockchain network
  7. verify deployment and retrieve the contract accost
  8. and finally utilise the combination of the business relationship address, the contract address, and the contract ABI in a Spider web application to bind to the contract and utilise 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-drive development of their smart contract applications.

Still, when it comes to a deployment to the main Ethereum network (mainnet) or a test network (testnet), developers nevertheless demand to manually get 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 procedure of application development for software engineers. Platform-equally-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 Cloud Foundry take come a long way in simplifying awarding lifecycle management. Following the same premise, we believe PaaS platforms tin and should simplify development of smart contract applications and make information technology integral to the lifecycle of smart contract applications deployed to PaaS. This is why project BlockHead was born.

Project BlockHead takes advantage of the Open Service Broker API specification to build a service broker layer placed between the Spider web application and the blockchain network. Doing and then, the broker controls management of the smart contract past automating creation and deployment of smart contracts and then exposing the required set of information to the Spider web application.

Open Service Banker API

The Open Service Broker 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 tin can be maintained and managed independently from the applications and withal applications can easily demark and use services through the exposed APIs. Service brokers are responsible for advertizing 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 resource on a service as an instance. In the context of the BlockHead banker, the service instance represents a blockchain node connected to the blockchain network. What a binding represents may also vary by service. Creation of a binding provides the service case with smart contract information for information technology to be compiled and deployed and become available to the application using the service. A platform marketplace may betrayal services from one or many service brokers, and an private service broker may back up one or many platform marketplaces using different URL prefixes and credentials. Picture above shows an example of interaction with the service broker API to provision a service."

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

BlockHead Service Broker

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

The first version of the broker is built on top of the Container Service Broker, a Cloud Foundry community projection. Past 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 banker 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. Pic 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 between the BlockHead service banker and Deject Foundry applications

i. 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 code, binary artifacts, and anything else required to build and deploy software in a reproducible manner.

In this blogpost we have the BlockHead service broker deployed aslope a Cloud Foundry deployment. This allows u.s.a. to benefit from capabilities in Cloud Foundry to push 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 Deject Foundry deployed on it, deploying the BlockHead banker is as simple equally running the following script:

Since Kubernetes integrates with Open Service Broker API compliant brokers, in case you accept a Kubernetes deployment, y'all can hook up the deployed BlockHead broker to your Kubernetes platform and bind to deployed smart contracts using Web3 applications deployed to Kubernetes. You tin can observe out how to practice the integration with Kubernetes Here.

2. Service MarketPlace and Contract MarketPlace

For the broker to appear in the Cloud Foundry marketplace you need to first annals information technology using the post-obit command:

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

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

Further to this, we take also developed a uncomplicated contract market place that would allow usa to list contracts so refer to them using their URL when binding an application to an Ethereum node. To have the contract marketplace deployed, you lot can add together your smart contracts to the market, build the docker image, push button it up to a docker registry and so use a command like to the following to download and apply it:

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

Y'all tin can verify that the application is up and running by checking cf apps:

In our case the marketplace is available at the address below and navigating to the address we can find the website:

Find on elevation 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. 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 case is issued, the banker starts upward an Ethereum node. The Ethereum node exposes its Remote Procedure Call (RPC) api for interactions and makes the endpoints bachelor through a given address and port number.

For the node cosmos to occur, you lot need to offset deploy a Web3 awarding that is intended to apply the smart contract. For the example of this weblog post, nosotros will be using our simple-node-application that only writes and reads a single value to and from the ledger. Note that since the app does not take the contract continued to it yet, we exercise non beginning the app when pushing information technology otherwise the deploy will fail.

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

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

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

This can exist verified with BOSH by connecting to the docker VM in the banker deployment and looking at the list 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 come across 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 broker. The broker downloads the contract, compiles it, extracts the ABI and pushes the binary to the Ethereum node using the business relationship created at the time of launching the service.

Nosotros mentioned earlier that the sample contract marketplace provides the link to the given contract, and then we tin just get the URL location of the contract and bind it to the awarding.

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

With the service binding going through successfully, we can issue a cf env command to run across the updated list of environment variables for the awarding.

Under VCAP_SERVICES the configuration for eth involves credentials information for the eth_node such as contract abi, account address, contract address, transaction hash for the deployed contract, besides as the host address and port mappings for the application to connect to the Ethereum node.

Going dorsum to the sample node application referenced earlier, you meet that the code in the application uses these environment variables to be able to demark to the smart contract and use it.

And VOILA! with that data, you tin can ascertain routes for you node.js application to get and set 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 issue, upon receiving an unbind asking, the banker detaches the service from the application and removes the injected contract information from VCAP_SERVICES, simply keeps the node around for information technology to possibly take other contracts deployed to information technology. Newly deployed contracts volition use the same Ethereum node with the same account created during the service creation phase.

In example of our running example, the post-obit command would unbind the contract:

cf unbind-service nora uncomplicated

6. Deprovision Service Instance

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

Challenges and Future Improvement Plans

1. Syncing the Ledger

Like many other blockchain networks, nodes in Ethereum require the full ledger to exist present for subsequent transactions to have result. This implies that the docker container created by the BlockHead service broker either needs to include the full ledger at the time it gets created or to sync the ledger after 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 accept considerable amount of time for the provisioned Ethereum node to sync its ledger and be fix, making the integration impractical.

An alternative solution is for the service broker to maintain a warm docker prototype with a fairly upward-to-date re-create of the ledger to apply 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 epitome.

Currently, the service banker launches the Ethereum node in developer mode which implies starting with a fresh ledger. This helps u.s.a. quickly bring up a development environment to examination Web3 applications confronting while avoiding the long wait for ledger syncup. Nosotros plan to implement techniques that would allow quick startup of an Ethereum node against the mainnet or testnet for production purposes as well.

2. Retentivity footprint

Syncing the ledger involves reading transaction blocks from other peers in the network, validating them, and 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 retentivity 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 exist run and managed by the banker.

3. Business relationship Management

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

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 weblog post we discussed the implementation of Project BlockHead as a service broker to be used in PaaS platforms such as 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 nosotros described the end-to-stop process of deploying and using the broker, awarding developers need to only care virtually Steps 3 to 6 of the procedure described to a higher place. This involves creating a smart contract service and bounden it to an awarding. Steps i and 2 of deploying the service banker and the contract market would potentially exist done only in one case and typically managed by platform engineers and operations engineers, simplifying the overall process.

Project BlockHead came almost as a hackathon project during Deject Foundry Summit 2018 in Boston and equally yous might have noticed most of the repositories nosotros shared in this blog post are personal github repositories of our squad participating in the hackathon. Luckily the projection has received good amount of involvement from the community and hopefully in the most time to come it will find a new habitation every bit an incubated project and be properly CI/CD-ed. So come back to this weblog post for further announcements as to where you can discover the official project repository. It is an open source project and we certainly welcome any contribution to get in improve.

Tags

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

Related Stories

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

Posted by: lowereares.blogspot.com

0 Response to "How Can I Know If I'm Registered To Vote"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel