Smart meters normally running in centerlized system before Blockchain technology. P2P smart meter can send bill contract in more secure way to distributed ledger. There are strong point can provide CPU or GPU or FPGA power to support the system, with FPAG accelerating card, the smart contract can be confirmed much faster to make the P2P system runs well.
This could be one big project including Blockchain Ecosystem. While the xilinx FPGA with DPU acceleration plays key role among the scenery since the balance of power consumption and performance. There have been tons of choice of in blockchain service choice. In this project, private Ethereum Blockchain network is constructed and smart meter runs under POW (Proof of Work) acceleration with DPU embedded in Xilinx C1100 PCI card.
The computer with Adaptive Computation power accelerator card can run as p2p node to support the confirmation of smart contract on Distributing Ledge. Existing solution uses control center to collect data from smart meter. The control center must be trustworthy in all means. This is useful to make fair contracts.
2. Hardware and SoftwareThere are limited sources for blockchain relative development concerning FPGA development, while the source code is good to go even takes extra debugging efforts. Xilinx XART lies at core, interface PCI bus with FPGA acceleration card.
Big data analytics card shall be use as acceleration card, solving the heavy POW in the system in parallel in FPGA on bitstream files. The function uses XRT to share global memory with host computer.
There are basic requirement for host server. In personal computer, upgrade is neccessary. At least the computer shall upgrade the power at least 500W and memory of 16G.
3.1 Prepare the xilinx XRT for ubuntu 18.04, install and run XRT with deployment packages, according to instructions on "ug1525-varium-c1100-install.pdf"
sudo apt install ./xrt*.deb
sudo apt install ./xilinx*.deb
Test the software and hardware installation with
sudo /opt/xilinx/xrt/bin/xbmgmt flash --scan
Now the software is ready for Varium C1100 accelerator.
3.2 Download and build the ethermin with xilinx DPU supported, the dag_gen_kernel.xclbin and ethash_kernel.xclbin are officially bitstream file for PoW for etherum mining acceleration. That is easy with script of build.sh
./build.sh
Usage: ./build.sh [option]
Options:
help print this help
build_ethash build ethash_kernel.xclbin @Not available
build_daggen build dag_gen_kernel.xclbin @Not available
build_host build ethminer
get_xclbin down xclbin files needed from Xilinx OMS
mine <wallet> <name> <pool_address> start mining with your wallet, name and pool address
It takes some time to build host with
cd build/
cmake ..
cmake --build .
And the ethminer is configurated with running alone in
3.3 Install geth with
sudo apt-get install geth
Run the smart meter as client with worker mining on server, and the ethereum console is ready for new nodes to added
4.1 Power Meter on Private Ethereum Net
Here is the scenary
- Start Geth bootnode with Ethereum Private Net
- Start Ethereum Private Miner with Xilinx DPU acceleration
- Start DApps with smart meter contract management
- Run Smart Meter DApps with RTC or http on terminal smart meter with Internet access
4.2 Prepare the Geth bootnode
Create keystore and start clef
clef init
clef newaccount --keystore powerMeterDir
sudo clef --keystore powerMeterDir/keystore --configdir powerMeterDir/clef --chainid 5
start first node with Geth
geth --datadir="powerMeterdir/60/01" -verbosity 6 --ipcdisable --port 30301 --http.port 81 console 2>> tmp.log
Then the second node in another terminal or another computer
geth --datadir="powerMeterdir/60/02" --verbosity 6 --ipcdisable --port 30302 --http.port 8102 console 2>> tmp02.log
The private net is constructed and ready to go.
4.3 Start miner with DPU acceleration on PCIe port via Xilinx XRT with the build file./ethminer
ethminer <wallet> <name> <pool_address>
// start mining with your wallet, name and pool address
4.4 The EVM is running automatically and ready to receive dApp as Ethererum mainet running. Refer to guide
Test and compile the dApp is Remix Online
The DApp is running in javascript codes and can be access world wide if internet is accessible.
Here is one smart contract for electricity in solidity
pragma solidity 0.8.7;
contract PowerMeter {
// Declare state variables of the contract
address public owner;
mapping (address => uint) public electricityBalances;
// When 'electricity' contract is deployed:
// 1. set the deploying address as the owner of the contract
// 2. set the deployed smart contract's electricity balance to 100
constructor() {
owner = msg.sender;
electricityBalances[address(this)] = 100;
}
// Allow the owner to increase the smart contract's electricity balance
function refill(uint amount) public {
require(msg.sender == owner, "Only the owner can refill.");
electricityBalances[address(this)] += amount;
}
// Allow anyone to purchase electricity
function purchase(uint amount) public payable {
require(msg.value >= amount * 1 ether, "You must pay at least 1 ETH per electricity");
require(electricityBalances[address(this)] >= amount, "Not enough electricity in stock to complete this purchase");
electricityBalances[address(this)] -= amount;
electricityBalances[msg.sender] += amount;
}
This DApp can be deployed and open for other nodes to use.
The deployment shall comply with ethereum rules with enough gas used.
In this privated Net, each ether can be got but ether miner or auction in private exchange market.
4.5 The smart Meter shall be internet accessible, the smart contract is delivered with http RPC Smart Contract
JavaScript client libraries allow your application to call smart contract functions by reading the Application Binary Interface (ABI) of a compiled contract. The ABI essentially explains the contract's functions in a JSON format and allows you to use it like a normal JavaScript object. In one sample smart Contract delivered by one Smart Meter Node
contract PowerMeter {
uint a;
address d = 0x12345678901234567890123456789012;
function PowerMeter(uint testInt) { a = testInt;}
event Event(uint indexed b, bytes32 c);
function send (uint b, bytes32 c) returns(address) {
Event(b, c);
return d;
}
}
Return with one jason file to be parsed.
5. In ProgressThere are more to developed and run in private net than expected, it is quick in Testnet since each transaction with zero Gas fee.
The Private Net net more efforts in deployment and operational with proper ethereum production and exchange.
But these parts are out of the Xilinx FPGA scope. The Xilinx C1100 acceleration card can be installed in any commercial upgraded computer with memory chips and computer power, just as one Nvidia Graphic Card's installation. But with much cheaper price and lower power consumption.
Ethash is the planned PoW algorithm for Ethereum 1.0 and it consumed computer power.
Dag_gen is directed acyclic graph (DAG), a finite directed graph with no directed cycles. Equivalently, a DAG is a directed graph that has a topological ordering, a sequence of the vertices such that every edge is directed from earlier to later in the sequence.
The FPGA can run with balance effect with performance and cost, the solid foundation for private Blockchain Net, especially for data-sensitive industrial smart contract.
This blog provides outline of how smart meters can be runs in Distributed Ledger as Ethereum can do. And FPGA is out of question one optimal choice with this XRT supported DPUs.
Comments