Implementation of the XYO Network Diviner Node in Go
Switch branches/tags
Nothing to show
Clone or download

README.md

XY Oracle Network Diviner Node

Implementation of a basic diviner node of the XYO Network. This node is responsible for querying the Archivist net, processing proof of origin data, and relaying responses back to the XYO smart contract as an oracle.

Overview

The initial, reference diviner node architecture will consist of the following components:

  1. A client that creates a JSON-RPC connection to a locally running Geth node
  2. A server that connects to the XYO Archivist Network through an endpoint for issuing issuing queries
  3. A simple tool for simulating pending queries sent over to the XY Smart Contract

In a mainnet implementation, an end-to-end example of the XYO Network would entail having the diviner node send answers into the smart contract that can then be extracted by a tool such as https://if-eth.com that listens to event logs from smart contracts using webhooks.

Requirements

Installing Ganache as a local, Ethereum blockchain node:

  • Make sure you have Node.js installed, then run npm install -g ganache-cli
  • Then, run ganache-cli. It will start a local Ethereum simulation on port 8545.

Now that you have Ganache, you can clone the xyo-solidity repo and deploy the XY core smart contract to the local node as follows:

  • Install truffle with npm i truffle -g
  • Clone the xyo-solidity repo git clone https://github.com/XYOracleNetwork/xyo-solidity
  • While ganache is running, compile and deploy the contract: truffle compile && truffle migrate
  • You should see the following in your command line so copy the XY: contract address somewhere (you'll need it!)

Truffle Migrate

Getting Golang, $GOPATH, and cloning the repository:

  • Install the latest version of go for your operating system
  • Ensure your $GOPATH is set. If not, then pick a directory as your $GOPATH, preferably ~/go/
  • Create the path $GOPATH/src/github.com/XYOracleNetwork
  • Run cd $GOPATH/src/github.com/XYOracleNetwork and git clone https://github.com/XYOracleNetwork/xyo-diviner
  • Run cd ./xyo-diviver and then make
  • Inside the xyo-diviner folder run, ./main -contract CONTRACT_ADDRESS where CONTRACT_ADDRESS is the address of the deployed XY contract in the running Ethereum node you copied earlier

Then, you'll start seeing some queries being issued to the XY contract and the diviner node constantly polling for pending queries that it will start to process! You'll see in the command line when the diviner node successfully publishes an answer to a query back to the XY smart contract as follows:

Diviner

How the XYO-Diviner Works

When we start a diviner node instance, it sets up a connection to an Ethereum instance endpoint - in this case the ganache-cli. Then, it sets up a server that connects to the Archivist network, which for now is implemented as a single JSON http endpoint that accepts queries and returns a hardcoded response.

After the server begins listening for requests, 3 concurrent threads are launched:

  1. FetchPendingQueries() interacts with the XY smart contract to fetch the list of pending queries and transmits them over a channel
  2. IssueQuery() listens for pending queries being sent over the previous channel and issues JSON post requests with the query payload to the Archivist server. Once it receives an answer it sends it over to another channel that listens for answers.
  3. ProcessAndPublishSignedAnswers() listens to answers over the previous channel, processes them, and sends signed answers back to the XY smart contract which will eliminate the corresponding pending query in the contract and issue an AnswerReceived log that can then be subscribed to with webhooks from services such as https://if-eth.com.

Roadmap

-[x] Implement fake Archivist network endpoint server

-[ ] Fetch pending queries from the actual XYO contract with ABI bindings

-[ ] Send signed transactions over to the smart contract