Skip to content

Commit

Permalink
Merge branch 'tilen/refactoring' into 'main'
Browse files Browse the repository at this point in the history
Refactoring and go-client imporvements

See merge request flarenetwork/fast-updates!17
  • Loading branch information
tilenflare committed Apr 23, 2024
2 parents 1b30f24 + 100c73f commit 2182f95
Show file tree
Hide file tree
Showing 225 changed files with 15,880 additions and 22,734 deletions.
25 changes: 0 additions & 25 deletions .env.example

This file was deleted.

74 changes: 0 additions & 74 deletions .eslintrc.js

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: container-images

on:
push:
branches: [ "main" ]
tags: [ "v*" ]

jobs:
build-container-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

- run: echo "IMAGE_TAG=latest" >> $GITHUB_ENV
if: github.ref_name == 'main'
- run: echo "IMAGE_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/v')

- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: set lower case repository
run: |
echo "REPOSITORY_LC=${REPOSITORY,,}" >>${GITHUB_ENV}
env:
REPOSITORY: '${{ github.repository }}'

- name: Build and push default image
uses: docker/build-push-action@v5
with:
context: go-client # Because GH actions are for kids and put protection on everything; https://stackoverflow.com/a/71159809/11276254
file: go-client/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ env.REPOSITORY_LC }}/go-client:${{ env.IMAGE_TAG }}
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,5 @@ artifacts
nul

# other files
deployment/config/deployed-contracts/deployed-contracts.json


nul

# other files
deployment/config/deployed-contracts/deployed-contracts.json

go-client/sig.out
go-client/keys.out
93 changes: 64 additions & 29 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,69 @@
workflow:
rules:
- if: '$CI_OPEN_MERGE_REQUESTS != null && ($CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "webide")'
when: never
- when: always
rules:
- if: '$CI_OPEN_MERGE_REQUESTS != null && ($CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "webide")'
when: never
- when: always

.test:
stage: test
image: node:18
cache:
- key:
files:
- yarn.lock
paths:
- node_modules/
policy: pull
before_script:
- yarn install --immutable
- yarn compile
# lint-ts-simulation:
# image: node:18
# before_script:
# - cd ts-simulation
# script:
# - yarn install --immutable
# - yarn lint

lint:
extends: .test
script:
- yarn lint
# test-ts-simulation:
# extends: .lint-ts-simulation
# before_script:
# - cd ts-simulation
# script:
# - yarn install --immutable
# - yarn test

test:
extends: .test
script:
- yarn test
lint-py-visualizer:
image: python:3.12
before_script:
- curl -sSL https://install.python-poetry.org | python3 -
- export PATH="/root/.local/bin:$PATH"
- cd py-visualizer
script:
- poetry install --no-root
- poetry run ruff check --fix

test-coverage:
extends: .test
script:
- yarn test-coverage
lint-go-client:
image: golang:1.21.0
before_script:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2
- cd go-client
script:
- go vet ./...
- go fmt ./...
- go mod tidy
- go mod verify
- golangci-lint run

test-go-client:
image: golang:1.21.0
before_script:
- cd go-client
script:
- go test -v provider/random_provider_test.go
- go test -v provider/feed_provider_test.go
- go test -v sortition/sortition_test.go

test-go-client-docker:
image: docker
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
before_script:
- cd go-client/tests
script:
- docker compose up ganache --detach
- VALUE_PROVIDER_IMPL=random docker compose up value-provider --detach
- docker compose up test-client --exit-code-from test-client
- docker compose stop ganache
- docker compose stop value-provider
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "flare-smart-contracts-v2"]
path = flare-smart-contracts-v2
url = git@gitlab.com:flarenetwork/flare-smart-contracts-v2.git
branch = fast_updates
1 change: 0 additions & 1 deletion .yarnrc.yml

This file was deleted.

8 changes: 0 additions & 8 deletions Dockerfile

This file was deleted.

102 changes: 10 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,21 @@
# FTSO Fast Updates

This repo contains MVP of an implementation of the new Fast Updates proposal.
This repo contains all the client side code associated with the new FTSO Fast Updates protocol. The Fast Updates smart contracts are pulled in from [flarenetwork/flare-smart-contracts-v2](https://gitlab.com/flarenetwork/flare-smart-contracts-v2).

## Setup
## go-client

### Node.JS
The go-client is a FTSO Fast Updates client implementation in Golang. It is responsible for generating the sortition proof and submitting the updates to the Flare blockchain.

Install [NVM](https://github.com/nvm-sh/nvm), and Node v18 (LTS):
The full README can be found at [go-client/README.md](./go-client/README.md)

```bash
nvm install 18
```
## py-visualizer

### Yarn
The py-visualizer is a FTSO Fast Updates Visualizer implemented in Python. It is used to provide a real-time visualization of the time-series feeds generated by the Fast Updates client.

Install dependencies with `yarn`:
The full README can be found at [py-visualizer/README.md](./py-visualizer/README.md)

```bash
corepack enable
yarn install
```
## ts-simulation

### Project
The ts-simulation is a FTSO Fast Updates Simulation implemented in TypeScript. It is used to optimize and test new contract parameters. It can be used alongside py-visualizer to visualize the Fast Updates protocol in action.

To compile smart contracts:

```bash
yarn compile
```

To format with prettier:

```bash
yarn format
```

To lint with eslint:

```bash
yarn lint
```

## Docker

To build a docker image, run:

```bash
docker build -t fast-updates .
```

To test the protocol using docker, navigate to the `test` directory and run docker compose:

```bash
cd test
docker compose up
```

## Simulating locally

Start the chain:

```bash
yarn hardhat node
```

Deploy the contracts and run the admin daemon:

```bash
yarn hardhat deploy-contracts --network localhost && yarn hardhat run-admin-daemon --network localhost
```

Run the fast updates providers:

```bash
yarn ts-node client/run-fast-updates-provider.ts $ID --network localhost
```

where `$ID` is the ID of the provider (1, 2, ...)

## Visualizer

Uses `dash` and `plotly` to render a live graph of the price feed in the browser, along with monitoring error rates of individual providers. Follow the instructions in `visualizer/README.md` to install and run the visualizer.

## Simulating with Docker

A simulation of the protocol using docker is available. It includes deploying and setting a chain node,
deploying contracts, running a daemon, and running multiple fast updates providers. Navigate to
`deployment/simulation` (assuming that the docker image `fast-updates` was build, as explained above)
and run docker compose:

```bash
cd deployment
docker compose up
```

## Notes

Strict type checked (in addition to strict mode) is enforced throughout the project (see `tsconfig.json` and `.eslintrc.js`).

For testing purposes (under `test/`), `typechain-truffle` is used to generate typechain artifacts from the contracts. The contracts are locally instantiated and used in the tests.

For deployment purposes (under `deployment/`), `typechain-web3-v1` is used to interact with the contracts.
The full README can be found at [ts-simulation/README.md](./ts-simulation/README.md)
Loading

0 comments on commit 2182f95

Please sign in to comment.