DevNews: Finchains — a Live WRKChain

In our continuing series of DevNews articles, we’ll be publishing some behind the scenes details on Unification’s projects and repos. We hope these articles will give the developer community some insight into our progress, and encourage devs to get involved!

“Show don’t tell” is a term often used my favourite film critic, Mark Kermode (hello to Jason Isaacs!), and I find it somewhat apposite for this edition of DevNews, since the article will be covering a live WRKChain we’ve just released, called Finchains.

The WRKchain itself can be viewed here: https://finchains.io, and as always, the code is available via GitHub for fellow developers to tinker with: https://github.com/unification-com/finchain

Although we have previously released demos of our WRKChain (for example WeatherChain) which run in self-contained environments (requiring Docker), we realise there is also a need to demonstrate the ease of rapid, cloud-deployable WRKChains for many constituents, hence hosting a public interactive WRKChain.

In the following weeks, we’ll be releasing articles covering the practical and business potential of this particular WRKChain model when applied across different data sources (such as Forex), industries (such as insurance, weather, etc.) and business models (such as arbitrage and risk mitigation, etc.).

This article will cover the more technical aspects of how Finchains and the underlying WRKChain technology works. To offer a simple business view from 30,000 feet: Finchains is a WRKChain which implements Oracles to monitor crypto data from various exchanges, and reports price discrepancies between them. It showcases one of innumerable possible uses for WRKChains — in this case, the potential for preventing (or indeed in full transparent reality, taking advantage of, if that’s your brew…) arbitrage, and offering the opportunity for disparate sources to automatically monitor and conceivably reconcile data differences. Further, since it’s WRKChain, it periodically submits its own block header hashes to the Unification Mainchain via the WRKOracle software, thus immutably sealing those hashes on Mainchain.

Finchain Smart Contract

https://github.com/unification-com/finchain/blob/master/Docker/wrkchain/assets/finchain-oracle-contract/contracts/Crypto.sol

Finchains accomplishes its task via a smart contract (deployed on the WRKChain itself, of course!), which accepts specifically formatted data input submitted by each of the several oracles running alongside. Since Finchains is a WRKChain, and therefore has control over its own transaction fees, the operators and oracles need not worry about exceptionally high fees for submitting data to the smart contract and having their respective data processed by it. In fact, all of the data that is visible on the “Crypto Watcher” homepage of finchains.io is coming from, and being processed by the smart contract itself.

Each Finchains oracle is registered and white-listed as a source within the smart contract, and only white-listed addresses can submit data. Data is submitted via the updateCurrency method, which stores the submitted values, and emits a currencyData event. This is one of the events the Crypto Watcher front-end is monitoring and tracking via Web3. Once the updateStock method detects that oracles have submitted data for a particular crypto ticker symbol, it passes the data to a comparison algorithm which scans it and calculates any possible discrepancy between the sources. If a discrepancy is detected within a specified threshold, the contract emits a discrepancy event. The threshold itself can be changed by calling the contract’s setThreshold method. The Crypto Watcher front-end is also monitoring for these events, and outputting them as they are found.

Finchains Oracles

https://github.com/unification-com/finchain/tree/master/Docker/wrkchain/assets/finchain-oracle-service

The Finchain software oracles periodically poll Crypto APIs (the frequency, and tickers they poll are configurable). The Oracles then generate and sign a WRKChain transaction using their private key, submitting the data to the smart contract on the WRKChain via the updateCurrency method outlined above.

Finchain’s WRKOracle

https://finchains.io/wrkoracle

Finchains is a WRKChain, and is therefore running a WRKOracle in parallel to periodically seal its own block header hashes on Mainchain. The submission transaction and validation results are also monitored by Finchains’ front-end, and can be viewed via the URL above. Since Finchains is a geth based WRKChain, its WRKOracle software has been configured to submit each block’s hash, parent hash, Tx root hash, receipt root hash and state root hash (this occurs once every 60 seconds, or every 4 Finchains blocks — Finchain’s blocktime is set at 15 seconds. Since a block’s parent hash is also submitted, it’s parent’s block hash can also potentially be cross-validated). The page itself details the last block submitted to Mainchain, along with a recent history of submitted blocks. It also links through to the validation page, which in turn displays proof that a given WRKChain’s block is valid (and unchanged etc.) according to the data submitted to Mainchain.

The block validation process involves querying both the WRKChain’s RPC server for the block’s actual data, along with querying the WRKChain Root smart contract on Mainchain to obtain its version of the block data as submitted by the WRKOracle at the time of the WRKChain’s block production. The two results are then compared and verified. Any discrepancy between the WRKChain’s block and the version of truth stored on Mainchain means that the WRKChain’s block is probably invalid (it may have been tampered with, for example). Further, the validation process also queries the original transaction sent to Mainchain by the WRKOracle, and displays all of the transaction’s original information (Mainchain block it was recorded in, raw Tx input data, and so on), offering dual layers of “truth” as Mainchain views it.

Configurable self-contained Finchain environment

The live online version showcases a lot of Finchain’s functionality, and the overall potential for WRKChains, but has limited scope for tinkering. As a developer, I like to see how something works and be able to play with it — we’ve therefore released Finchain in its entirety in a completely self-contained environment (including a self-contained mini-Mainchain developer network), which will allow developers to download, make changes, extend, and see what’s happening in the guts of Finchain.

Some examples that we look forward to seeing from the community — and will be happy to support efforts of — include, but are not limited to:

  • Variable threshholds between API sources/ticker symbols, and the ability to modify via smart contract calls
  • Multiple thresholds with differing severity levels — for example, $0.50 severe discrepancy threshold, $0.20 warning discrepancy threshold, $0.01 informational discrepancy threshold
  • Implementing additional source API oracles to give a wider range of data.
  • Cross referencing the WRKChain’s submitted parent hash with the WRKChain block’s actual parent’s block header hash.

If you plan to or have interest in supporting development on these extensions or any other interesting proposals, we welcome you to get in touch with us to discuss best practices and see how we can support our initiatives.

To run the self-contained environment, you’ll need Docker and Docker Compose installed (along with the usual build tools such as make). You may also need a host with above average CPU/RAM specs, since several Docker containers will be spawned. Note: the following commands are for Linux and OSX.

Once everything is installed, clone the repo:

git clone https://github.com/unification-com/finchain

Once cloned, some configuration will be required. Copy the example.env file:

cd finchain
cp example.env .env

Open up the .env file in a text editor, and configure the values.

It’s also possible to modify the CRYPTO_THRESHOLD, TRACKED_CRYPTOS , and CRYPTO_UPDATE_TIME values. Once configured, just run:

make

The environment may take a few minutes to spin up, since Docker needs to download and set up quite a few containers, so go and grab a brew. After some time, you should see the following message fly by:

====================================
= FINCHAIN UI READY =
= -------------------------------- =
= =
= open: =
= http://localhost:4040 =
= =
====================================

Opening http://localhost:4040 in your browser should display a familiar page. The self-contained environment also has a few other local servers running:

Finchain’s Block Explorer: http://localhost:8081
Finchain’s JSON RPC: http://localhost:8547
DevNet Mainchain’s Block Explorer: http://localhost:3000
DevNet Mainchain’s RPC: http://localhost:26661
(DevNet Mainchain has a Chain ID of UND-Mainchain-DevNet).

Finchain’s software (oracles, and front-end UI) and smart contract can all be found in the Docker/wrkchain/assets directory:

Docker/wrkchain/assets/finchain-oracle-contract — Finchain’s smart contracts, deployed on the WRKChain
Docker/wrkchain/assets/finchain-oracle-service — Finchain’s oracles
Docker/wrkchain/assets/finchain-ui — Finchain’s front-end UI

Finally, to bring down the Docker composition, use Ctrl+C followed by:

make down

It is also possible to parse and store the Docker logs into individual [SERVICE_NAME].txt files, allowing for simpler viewing by running:

make logs

The individual logs are saved in the logs directory

As always, feel free to track our overall progress — all of our public repos are available at https://github.com/unification-com

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store