Skip to content

2. Ethereum

SamR1 edited this page May 22, 2017 · 18 revisions

(documentation in progress)

This page describes the setup of a local blockchain (using Parity client) and the DAISEE application on a Raspberry Pi 3.

Parity installation

An image is available with Parity and Geth clients:
http://ethraspbian.com/downloads/image_2017-04-19-EthRaspbian-parity-1.6.6-lite.zip
(see repository diglos/pi-gen for more informations).

This image is compatible with Rapsberry Pi 2 and 3 and runs Parity Ethereum client as a boot service (full Ethereum node).

After turning on the Raspberry Pi, disable the Parity service for now:

$ sudo systemctl stop parity
$ sudo systemctl disable parity
Removed symlink /etc/systemd/system/multi-user.target.wants/parity.service.

And update/upgrade Raspbian:

$ sudo aptitude update && sudo aptitude upgrade

Parity configuration

Parity can be easily configure through a configuration file:
https://github.com/paritytech/parity/wiki/Configuring-Parity#config-file

For testing purposes and due to ressources limitations, a private/local blockchain will be set up with Proof-of-Authority consensus engine, for this version of DAISEE prototype.

[Proof-of-Authority] does not depend on nodes solving arbitrarily difficult mathematical problems, but instead uses a hard-configured set of "authorities" - nodes that are explicitly allowed to create new blocks and secure the blockchain. This makes it easier to maintain a private chain and keep the block issuers accountable.

All steps for setting up a local blockchain with Proof-of-Authority are described here:
Demo PoA tutorial

After following the tutorial, here are the differents files used for one node of the prototype:

  • blockchain specifications (demo-spec.json):
{
    "name": "DemoPoA",
    "engine": {
        "authorityRound": {
            "params": {
                "gasLimitBoundDivisor": "0x400",
                "stepDuration": "5",
                "validators" : {
		    "list": [
			"0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e",
			"0x00Aa39d30F0D20FF03a22cCfc30B7EfbFca597C2",
			"0x002e28950558fbede1a9675cb113f0bd20912019"
		    ]
		}
            }
        }
    },
    "params": {
        "maximumExtraDataSize": "0x20",
        "minGasLimit": "0x1388",
        "networkID" : "0x2323"
    },
    "genesis": {
        "seal": {
            "authorityRound": {
                "step": "0x0",
                "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
            }
        },
        "difficulty": "0x20000",
        "gasLimit": "0x5B8D80"
    },
    "accounts": {
        "0x0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
        "0x0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
        "0x0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
        "0x0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
	"0x004ec07d2329997267Ec62b4166639513386F32E": { "balance": "10000000000000000000000" }
    }
}

3 validators are defined

  • config.toml
[parity]
chain = "/home/pi/demo-spec.json"
base_path = "/home/pi/parity/"
[network]
port = 30300
bootnodes = ["enode://ff14ae0a273e08ffbbe20b4b398460eb471e23f1b4301ce46b92a86ad420f67b9b470d097f1939fa7b9b2aae7d24e72cf7c63fe67217bdf3fd6cb60bbb7ecc59@192.168.0.47:30300"]
discovery = false
[rpc]
disable = false
interface = "192.168.0.15"
port = 8545
cors = "*"
apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces", "rpc", "parity_accounts"]
[ui]
force = false
disable = false
port = 8180
interface = "192.168.0.15"
path = "/home/pi/parity/signer/"
[dapps]
port = 8088
[account]
password = ["node.pwds"]
[mining]
engine_signer = "0x002e28950558fbede1a9675cb113f0bd20912019"
reseal_on_txs = "none"

config file for one node

  • Running Parity
$ parity

parity

  • Adding a node

Since the blockchain is private/locale, adding a node can be done with the configuration file in Network part.

[network]
bootnodes = ["enode://ff14ae0a273e08ffbbe20b4b398460eb471e23f1b4301ce46b92a86ad420f67b9b470d097f1939fa7b9b2aae7d24e72cf7c63fe67217bdf3fd6cb60bbb7ecc59@192.168.0.47:30300"]
discovery = false

The Public node Node is displayed on Parity Client launch. It can also be found on Parity UI, in Status tab:

  • In the case where a new validator node is added, after modifying lists of validators, the following message may appear during blocks import:
Error: Engine(NotProposer(Mismatch { expected: 00aa39d30f0d20ff03a22ccfc30b7efbfca597c2, found: 00bd138abd70e2f00903268f3db08f2d25677c9e }))

The workaround is to modify the chain specifications to revert to the precedent version, until a new error message.
Exemple: parity client Only 3 blocks are imported with the last version of chain-specs.json (3 validators). In order to import the next blocks, the last validator is removed from chain specs, and blocks are imported until block #55. After this message, using the last version of chain specs (with the 3 validators) allows to import the full blockchain.
The best solution would be to add the new validator account only after importing the full blockchain on the node.

Smart-contracts

2 smart-contracts (in Solidity) are used:

  • token.sol
    This is the smart-contract described in the tutorial "Create your own crypto-currency".
    It allows to create a token, according to the ERC20 Token Standard.
  • daisee.sol
    The current version allows to :
    • store energy data on blockchain (consumption and production),
    • make transactions between peers.
      For now, the rules that trigger transactions are not implemented in a smart contract. Note: the smart contract is still under development, the code may change (see Issues).

Several methods exist for deploying and testing a smart contract.
In this wiki, the use of the Parity UI is described.

Deploying contracts

In Contracts Tab, after clicking on "DEVELOP" button, paste the smart contract code for the token and compile:

With Parity UI, the smart contract can be easily deployed ("DEPLOY" button):

Deploy the Daisee smart contract:

The two smart-contract now appear in Contracts tab:

Note: the current version of DAISEE smart contract allows to update consumption and production directly:

see Issue DApp-v2/issues/5

Interface

To view data, a Web interface communicates with the local node, through Web3 JavaScript API, using web3.js.
Tutorial:
A simple smart contract Web UI using web3.js

The microframework Flask allows to display the interface from the Raspberry Pi node.

  • clone the repository
$ git clone https://github.com/DAISEE/DApp-v2.git
  • create the configuration file (config.yml) from the example and complete it:
Type Field Description
contract
daisee Daisee.sol address on the blockchain
token DaiseeCoin smart-contract address on the blockchain
user
login login for UI
pwd hashed password for the UI*
coinbase user address
type type of node ('C' for consumer, 'P' for producer). Not Used
url url of energy monitoring application
sensorId url of energy monitoring application
sensorLogin login for energy monitoring application
sensorPassword password energy monitoring application
sensorSource energy monitoring application : 'CW' for citizenWatt (only app supported for now)
sensorPort if necessary, port of energy monitoring application

still under development, it may change

* to obtain the hashed password, use 'url/hash/<password>'

  • run the server
$ export FLASK_APP=server.py
$ python3 -m flask run --host=0.0.0.0

The current version displays Ethereum transactions and realtime data from the energy monitoring application

(to be completed)

Clone this wiki locally