Skip to content

Commit e77c08a

Browse files
authored
Merge pull request #349 from AdExNetwork/improvements-with-rust-1.48.0
Ethereum Adapter fix + Improvements & rust 1.48.0
2 parents 82e13d2 + b0ddebd commit e77c08a

27 files changed

+2417
-2602
lines changed

Cargo.lock

+1,981-2,338
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
FROM rust:1.40 as builder
1+
# Builder
2+
FROM rust:1.48.0 as builder
23

3-
4+
LABEL maintainer="[email protected]"
45

56
WORKDIR /usr/src/app
67

78
COPY . .
89

9-
RUN cargo install --path validator_worker --all-features
10+
# We intall the validator_worker binary with all features in Release mode
11+
# Inlcude the full backtrace for easier debugging
12+
RUN RUST_BACKTRACE=full cargo install --path validator_worker --all-features
1013

1114
WORKDIR /usr/local/bin
1215

1316
RUN cp $CARGO_HOME/bin/validator_worker .
1417

15-
FROM ubuntu:18.04
18+
FROM ubuntu:20.04
19+
20+
RUN apt update && apt-get install -y libssl-dev ca-certificates
1621

1722
# `ethereum` or `dummy`
1823
ENV ADAPTER=
@@ -34,8 +39,6 @@ ENV SINGLE_TICK=
3439

3540
WORKDIR /usr/local/bin
3641

37-
RUN apt update && apt-get install -y libssl-dev ca-certificates
38-
3942
COPY docs/config/cloudflare_origin.crt /usr/local/share/ca-certificates/
4043

4144
RUN update-ca-certificates

README.md

+170-26
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,208 @@ Reference implementation of the [AdEx validator stack](https://github.com/adexne
66

77
Components:
88

9-
* Sentry
10-
* Validator worker
11-
* Adapter
9+
* [Sentry](#sentry)
10+
* [Validator worker](#validator-worker)
11+
* Adapter - Ethereum & Dummy (for testing) Adapters
1212
* AdView manager
1313

1414
## Local & Testing setup
1515

16+
Requirements:
17+
18+
- Rust
19+
20+
Check the [`rust-toolchain`](./rust-toolchain) file for specific version of rust.
21+
- [`cargo-make`](https://github.com/sagiegurari/cargo-make)
22+
- Docker
23+
1624
#### Linux
1725
- `build-essentials` is required to build the project (error: `linker ``cc`` not found`)
1826
- The crate `openssl-sys` requires `libssl-dev` and `pkg-config` for Ubuntu.
1927

20-
### Run Postgres
28+
## Sentry
29+
30+
`Sentry` is the REST API that the [`Validator worker`](#validator-worker) uses for storing and retrieving information.
31+
We need two services to be able to run `Sentry`: `Postgres` and `Redis`.
32+
33+
### Running Postgres
2134

22-
`docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres`
35+
`docker run --rm --name adex-validator-postgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres`
2336

2437
- `$HOME/docker/volumes/postgres` - your local storage for postgres (persist the data when we remove the container)
25-
- `POSTGRES_PASSWORD=docker` - the password of `postgres` user
38+
- `POSTGRES_PASSWORD=postgres` - the password of `postgres` user
2639

27-
### Run Redis:
40+
### Running Redis
2841

29-
`docker run --name some-redis -d redis`
42+
`docker run --rm --name adex-validator-redis -d redis`
3043

31-
### Run automated tests
44+
### Running Sentry Rest API
3245

33-
Since we have integration tests that require Redis & Postgres,
34-
you need to be running those in order to run the automated tests:
46+
For a full list of all available CLI options on Sentry run `--help`:
3547

36-
`cargo make test`
48+
```bash
49+
cargo run -p sentry -- --help
50+
```
51+
52+
Starting the Sentry API in will always run migrations, this will make sure the database is always up to date with the latest migrations, before starting and exposing the web server.
53+
54+
In `development` ( [`ENV` environment variable](#environment-variables) ) it will seed the database as well.
55+
56+
#### Using the `Ethereum Adapter`
57+
58+
The password for the Keystore file can be set using the [environment variable `KEYSTORE_PWD`](#adapter).
59+
60+
- Leader
61+
```bash
62+
POSTGRES_DB="sentry_leader" PORT=8006 cargo run -p sentry -- \
63+
--adapter ethereum \
64+
--keystoreFile ./adapter/resources/keystore.json \
65+
./docs/config/dev.toml
66+
```
67+
68+
- Follower
69+
```bash
70+
POSTGRES_DB="sentry_follower" PORT=8006 cargo run -p sentry -- \
71+
--adapter ethereum \
72+
--keystoreFile ./adapter/resources/keystore.json
73+
./docs/config/dev.toml
74+
```
75+
76+
#### Using the `Dummy Adapter`
77+
78+
**Dummy** identities:
79+
80+
- Leader: `ce07CbB7e054514D590a0262C93070D838bFBA2e`
81+
82+
```bash
83+
POSTGRES_DB="sentry_leader" PORT=8005 cargo run -p sentry -- \
84+
--adapter dummy \
85+
--dummyIdentity ce07CbB7e054514D590a0262C93070D838bFBA2e \
86+
./docs/config/dev.toml
87+
```
88+
- Follower: `c91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3`
89+
90+
```bash
91+
POSTGRES_DB="sentry_follower" PORT=8006 cargo run -p sentry -- \
92+
--adapter dummy \
93+
--dummyIdentity c91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3 \
94+
./docs/config/dev.toml
95+
```
96+
97+
For full list, check out [primitives/src/util/tests/prep_db.rs#L29-L43](./primitives/src/util/tests/prep_db.rs#L29-L43)
98+
99+
#### Environment variables
37100

38-
### Run Sentry Rest API
101+
- `ENV` - `production` or `development`; *default*: `development` - passing this env. variable will use the default configuration paths - [`docs/config/dev.toml`](./docs/config/dev.toml) (for `development`) or [`docs/config/prod.toml`](./docs/config/prod.toml) (for `production`). Otherwise you can pass your own configuration file path to the binary (check `cargo run -p sentry --help` for more information). In `development` it will make sure Sentry to seed the database.
102+
- `PORT` - *default*: `8005` - The local port that Sentry API will be accessible at
103+
- `ANALYTICS_RECORDER` - accepts any non-zero value - whether or not to start the `Analytics recorder` that will track analytics stats for payout events (`IMPRESSION` & `CLICK`)
104+
##### Adapter
105+
- `KEYSTORE_PWD` - Password for the `Keystore file`, only available when using `Ethereum Adapter` (`--adapter ethereum`)
39106

40-
* With the DummyAdapter(replace the `DummyIdentity`):
107+
##### Redis
108+
- `REDIS_URL` - *default*: `redis://127.0.0.1:6379`
41109

42-
`export PORT=8006; cargo run -p sentry -- -a dummy -i DummyIdentity`
110+
##### Postgres
111+
- `POSTGRES_HOST` - *default*: `localhost`
112+
- `POSTGRES_USER` - *default*: `postgres`
113+
- `POSTGRES_PASSWORD` - *default*: `postgres`
114+
- `POSTGRES_DB` - *default*: `user` name - Database name in Postgres to be used for this instance
115+
- `POSTGRES_PORT` - *default*: `5432`
43116

44-
* With the EthereumAdapter:
117+
#####
45118

46-
TODO
119+
### Running the Validator Worker
47120

48-
### Bug
121+
For a full list of all available CLI options on the Validator worker run `--help`:
49122

123+
```bash
124+
cargo run -p validator_worker -- --help
125+
```
50126

127+
#### Using the `Ethereum Adapter`
128+
TODO: Update Keystore file and Keystore password for Leader/Follower as they are using the same at the moment.
51129

130+
The password for the Keystore file can be set using the environment variable `KEYSTORE_PWD`.
52131

53-
### Run Validator Worker
132+
- Leader
133+
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Leader** on port `8005`:
54134

55-
TODO
135+
```bash
136+
cargo run -p validator_worker
137+
--adapter ethereum
138+
--keystoreFile ./adapter/resources/keystore.json
139+
--sentryUrl http://127.0.0.1:8005
140+
./docs/config/dev.toml
141+
```
142+
143+
- Follower
144+
145+
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Follower** on port `8006`:
146+
147+
```bash
148+
cargo run -p validator_worker
149+
--adapter ethereum
150+
--keystoreFile ./adapter/resources/keystore.json
151+
--sentryUrl http://127.0.0.1:8006
152+
./docs/config/dev.toml
153+
```
154+
155+
#### Using the `Dummy Adapter`
156+
- Leader: `ce07CbB7e054514D590a0262C93070D838bFBA2e`
157+
158+
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Leader** on port `8005`:
159+
160+
```bash
161+
cargo run -p validator_worker
162+
--adapter dummy
163+
--dummyIdentity ce07CbB7e054514D590a0262C93070D838bFBA2e
164+
--sentryUrl http://127.0.0.1:8005
165+
./docs/config/dev.toml
166+
```
167+
168+
- Follower: `c91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3`
169+
170+
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Follower** on port `8006`:
171+
172+
```bash
173+
cargo run -p validator_worker
174+
--adapter dummy
175+
--dummyIdentity c91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3
176+
--sentryUrl http://127.0.0.1:8006
177+
./docs/config/dev.toml
178+
```
179+
180+
#### Environment variables
181+
182+
- `ENV`: `production` or `development` ( *default* ) - passing this env. variable will use the default configuration paths - [`docs/config/dev.toml`](./docs/config/dev.toml) (for `development`) or [`docs/config/prod.toml`](./docs/config/prod.toml) (for `production`). Otherwise you can pass your own configuration file path to the binary (check `cargo run -p sentry --help` for more information). In `development` it will make sure Sentry to seed the database.
183+
- `PORT` - The local port that Sentry API will accessible at
184+
185+
##### Adapter
186+
- `KEYSTORE_PWD` - Password for the `Keystore file`, only available when using `Ethereum Adapter` (`--adapter ethereum`)
56187

57188
## Development environment
58189

59-
We use [cargo-make](https://github.com/sagiegurari/cargo-make) for running the checks and build project locally
60-
as well as on CI. For a complete list of out-of-the-box commands you can check
190+
We use [`cargo-make`](https://github.com/sagiegurari/cargo-make#overview) for running automated checks (tests, builds, formatting, code linting, etc.) and building the project locally
191+
as well as on our Continuous Integration (CI). For a complete list of out-of-the-box commands you can check
61192
[Makefile.stable.toml](https://github.com/sagiegurari/cargo-make/blob/master/src/lib/Makefile.stable.toml).
62193

63-
Locally it's enough to ensure that `cargo make` command (it will execute the default dev. command) is passing.
64-
It will run `rustfmt` for you, it will fail on `clippy` warnings and it will run all the tests.
194+
### Local development
195+
196+
Locally it's enough to ensure that the default development command is executing successfully:
197+
198+
```bash
199+
cargo make
200+
```
201+
202+
It will run `rustfmt` for you as well as `clippy` (it will fail on warnings) and it will run all the tests thanks to `cargo` (doc tests, unit tests, integration tests, etc.).
65203
66-
*Note:* You need to have setup Redis and Postgres as well.
204+
This will also run the [Automated tests](#automated-tests), so you must have `Redis` & `Postgres` running.
205+
206+
#### Automated tests
207+
208+
This requires [`cargo-make`](https://github.com/sagiegurari/cargo-make#overview) and since we have integration tests that require `Redis` ([see `Running Redis`](#running-redis)) & `Postgres` (see [`Running Postgres`](#running-postgres)), you need to be running those in order to run the automated tests:
209+
210+
`cargo make test`
67211
68-
You can related to the [Makefile.stable.toml](https://github.com/sagiegurari/cargo-make/blob/master/src/lib/Makefile.stable.toml)
212+
You can relate to the [`Makefile.stable.toml`](https://github.com/sagiegurari/cargo-make/blob/master/src/lib/Makefile.stable.toml)
69213
for more commands and cargo-make as a whole.

adapter/Cargo.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ serde = { version = "^1.0", features = ['derive'] }
1414
serde_json = "1.0"
1515
serde-hex = "0.1.0"
1616
# Ethereum
17-
web3 = { git = "https://github.com/samparsky/rust-web3" }
17+
web3 = { git = "https://github.com/tomusdrw/rust-web3" }
1818
eth_checksum = "0.1.1"
19-
ethabi = { git = "https://github.com/samparsky/ethabi", branch = "graph-patches" }
2019
tiny-keccak = "1.5"
21-
parity-crypto = { version = "0.5.0", features = ["publickey"] }
22-
ethstore = { version = "0.2.1", git = "https://github.com/paritytech/parity-ethereum"}
23-
ethkey = { version = "0.4.0", git = "https://github.com/paritytech/parity-ethereum"}
20+
ethstore = { git = "https://github.com/elpiel/openethereum", branch = "remove-dir-depenedency-for-ethstore" }
2421
# API client
2522
reqwest = { version = "0.10", features = ["json"] }
2623

0 commit comments

Comments
 (0)