0xDeCA10B/demo
dependabot[bot] 8979b02d0b
build(deps): bump elliptic from 6.5.7 to 6.6.0 in /demo (#185)
Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.7 to 6.6.0.
- [Commits](https://github.com/indutny/elliptic/compare/v6.5.7...v6.6.0)

---
updated-dependencies:
- dependency-name: elliptic
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-31 09:37:16 -04:00
..
client build(deps): bump express from 4.18.2 to 4.21.1 in /demo/client (#183) 2024-10-21 13:42:16 -04:00
scripts [demo] Lint More Files (#127) 2021-07-04 22:00:35 -04:00
.dockerignore [demo] Add Point based Incentive Mechanism (#73) 2020-01-06 14:53:28 -05:00
.eslintignore [demo] Lint More Files (#127) 2021-07-04 22:00:35 -04:00
.eslintrc.js [demo] Lint More Files (#127) 2021-07-04 22:00:35 -04:00
.gitignore [demo] Add Point based Incentive Mechanism (#73) 2020-01-06 14:53:28 -05:00
.soliumignore [demo] Add an option for word hashing vocab and optimize Sparse Nearest Centroid Classifier (#91) 2020-06-17 13:24:42 -04:00
.soliumrc.json Add demo and simulation code. (#2) 2019-05-24 12:00:36 -04:00
Dockerfile [demo] Correct issues with pulling Git repos during build. (#154) 2022-06-22 15:14:12 -04:00
README.md Remove references to public Docker images. (#178) 2024-09-10 12:04:23 -04:00
package.json build(deps): bump express from 4.17.3 to 4.20.0 in /demo (#179) 2024-09-10 17:32:30 -04:00
server.js Correct Docker pushes (#129) 2021-09-13 13:55:37 -04:00
service.Dockerfile [demo] Correct issues with pulling Git repos during build. (#154) 2022-06-22 15:14:12 -04:00
setup.sh [demo] Lint More Files (#127) 2021-07-04 22:00:35 -04:00
setup_libs.sh [demo] Lint More Files (#127) 2021-07-04 22:00:35 -04:00
yarn.lock build(deps): bump elliptic from 6.5.7 to 6.6.0 in /demo (#185) 2024-10-31 09:37:16 -04:00

README.md

Sharing Updatable Models (SUM) on Blockchain Demo

(formerly Decentralized & Collaborative AI on Blockchain Demo)

Demo: Test

A dashboard and examples for deploying updatable AI models to Ethereum. A video demo is available There is a video example showing how to deploy here.

This folder also contains Solidity examples for models, data handlers, and incentive mechanisms for deploying models that are free to use for inference as initially proposed in our introductory paper.

This project is made from a React project with Truffle added. This Truffle example was used to help add Truffle.

This work in its current form is just meant as an example and proof of concept. It is not ready to be deployed for production yet.

Setup

This section explains how to set up locally on Linux/WSL, alternatively, you can skip ahead and use a Docker image.

The following steps are made for Linux/WSL and require npm with node version 10. Other later versions of node might work too but some node-gyp issues occurred with version 14.

You will need to have make installed. On Debian (e.g. Ubuntu) you can do:

sudo apt install build-essential

Run

./setup.sh

Troubleshooting Setup

If you have problems running the setup steps related to node-gyp, then you might need to set Python 2.7 to be your default (just during the installation). Recommendation: Temporarily set up a Python 2.7 Conda environment (just for the installation) and activate it:

conda create --name python2 python=2
conda activate python2

Docker Setup

  1. Clone this repo.

  2. Navigate into the folder containing this README.md file:

cd 0xDeCA10B/demo
  1. Using a Docker Image

docker build -t decai-demo .

docker run --rm -it -p 3000:3000 -p 5387:5387 -p 7545:7545 -v ${PWD}:/root/workspace/demo -v /root/workspace/demo/node_modules -v /root/workspace/demo/client/node_modules --name decai-demo decai-demo bash

In the container:

# If this is your first time setting up then run:
./setup_libs.sh

# So that you can start a few processes in the Docker container, run:
byobu
  1. You have completed the setup steps. Next, refer to the Deploy steps lower down on this page.

If you want to use a different version of the Docker image, then you can find the available tags for the Docker image here and check the details for the latest tag here.

Deploy

There is a video example showing how to deploy here.

Blockchain

Models and data are stored on a local blockchain.

Start the blockchain (uses ganache-cli) in one terminal. Run:

yarn blockchain

Do once:

  • In your browser, you will need to add http://localhost:7545 as a custom RPC, you can use the MetaMask extension for this.
    • If required, you can set the chain ID to: 0xDeCA10B
  • Copy the first private key output by the above command.
  • Use that private key to create a new account in MetaMask.

Server

(Optional) The server is used to store model meta-data and original data when for training models.

The server is used by default in development mode but not in production mode.

If you want to store meta-data in a local database file instead of just within the browser, then start the server in one terminal. This step allows you to see models listed when you open the dashboard for the first time.

If you do want to use the database file then you should have REACT_APP_ENABLE_SERVICE_DATA_STORE=true in your client/.env.development file.

Run:

yarn server

Client

The website is the "client", it allows you to interract with the blockchain and optional server.

In another terminal. Run:

yarn client

Troubleshooting Deployment

Blockchain Issues

Run yarn clean to delete your local blockchain and cached contracts. This will delete any transactions done but should make everything work again.

Errors about a contract not found at a certain address

If you get errors about calling a contract then it's probably because you restarted your blockchain (Ganache) and the contract doesn't exist anymore on the blockchain. This could happen if you restarted your computer. You have to delete the generated .json files that keep track of contract addresses:

rm -f client/{build,src}/contracts/compiled/*.json

Then you should be able to deploy normally.

You can also try to rm -rf blockchain_db to delete your blockchain and restart from scratch.

MetaMask Issues

Issues about nonce

If MetaMask gives issues about the nonce not being right for a transaction then it's probably because you restarted your blockchain but MetaMask caches some basic things on the URL and the network ID.

You can first try to reset your account in the MetaMask settings. This will clear your transaction history.

You shouldn't need to if you've been consistently using a blockchain for just this project but you can also try changing the network ID for Ganache. This can be done in the Ganache UI or CLI (--networkId).

MetaMask Loading Issues

If MetaMask is spinning and non-responsive:

  1. Disable the extension here: chrome://extensions
  2. Re-enable the extension.
  3. Open the extension.
  4. Change the network to use. E.g. Select Main Ethereum Network.
  5. Log in to MetaMask.
  6. Change the network back to the custom one.
  7. Reject any queued transactions.

If you get the spinning issue again, then also try following the steps above with resetting your account as well as restarting the blockchain by:

  1. Stop the yarn blockchain process.
  2. Run yarn clean.
  3. Run yarn blockchain.

Testing

To run all automated tests:

yarn test

A local blockchain will be started and stopped so it's best not to have a blockchain running at the same address and port (e.g. one running through yarn blockchain).

Manual Testing

Not all tests are automated (yet, maybe one we'll automate them all). Some things that should be manually tested in the UI after completing the deployment:

  • Pick a model
  • PREDICT: Verify that you can use the model to classify some data
  • TRAIN: Add "incorrect" data as user "Bad"
  • Add "correct" data as user "Good"
  • REFUND: Verify that "Good" can get a refund for the "correct" data
  • REWARD: Verify that "Good" can report "Bad"'s "incorrect" data
  • Add a new model

Running Specific Tests

To run specific smart contract tests and save time by not waiting for Truffle migrations:

  • In one terminal, start a blockchain: yarn blockchain
  • In another terminal session, run:
cd client
npx truffle test [<test file paths>] --network skipMigrations
# For example:
npx truffle test test/contracts/*.js test/contracts/**/*.js --network skipMigrations

Linting

Run yarn lint.

Run yarn lint-fix to automatically resolve some issues.

Solidity Files

We use Ethlint for linting and enforce it on pull requests. The above yarn lint and yarn lint-fix commands will also check Solidity files.