Skip to content

Commit 17252d4

Browse files
committed
Update READMEs, env. variables and more
1 parent 12a256f commit 17252d4

File tree

8 files changed

+141
-106
lines changed

8 files changed

+141
-106
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ FROM ubuntu:20.04
1919

2020
RUN apt update && apt-get install -y libssl-dev ca-certificates
2121

22+
# `production` or `development` - default: `development`
23+
ENV ENV=
24+
2225
# `ethereum` or `dummy`
2326
ENV ADAPTER=
2427

Dockerfile-sentry

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ FROM ubuntu:20.04
4545

4646
RUN apt update && apt-get install -y libssl-dev ca-certificates
4747

48+
# `production` or `development` - default: `development`
49+
ENV ENV=
50+
51+
# Redis URL - default: `redis://127.0.0.1:6379`
52+
ENV READIS_URL=
53+
# The IP address on which the sentry server will be listening - default: `0.0.0.0`
54+
ENV IP_ADDR=
55+
# The Port on which the sentry server will be listening - default: `8005`
56+
ENV PORT=
57+
4858
# `ethereum` or `dummy`
4959
ENV ADAPTER=
5060

README.md

Lines changed: 119 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
# AdEx Validator Stack in Rust [![CI](https://github.com/AdExNetwork/adex-validator-stack-rust/workflows/Continuous%20Integration/badge.svg)](https://github.com/AdExNetwork/adex-validator-stack-rust/actions)
2-
3-
The Rust implementation of the Validator Stack
4-
5-
Reference implementation of the [AdEx validator stack](https://github.com/adexnetwork/adex-protocol#validator-stack-platform).
1+
# Ambire AdEx Validator Stack [![CI](https://github.com/AdExNetwork/adex-validator-stack-rust/workflows/Continuous%20Integration/badge.svg)](https://github.com/AdExNetwork/adex-validator-stack-rust/actions)
62

73
Components:
84

95
* [Sentry](#sentry)
106
* [Validator worker](#validator-worker)
11-
* Adapter - Ethereum & Dummy (for testing) Adapters
12-
* AdView manager
7+
* [Adapter](./adapter/README.md) - Ethereum & Dummy (for testing) Adapters
8+
* [AdView manager](./adview-manager/README.md)
139

1410
## Local & Testing setup
1511

1612
Requirements:
1713

1814
- Rust
19-
20-
Check the [`rust-toolchain`](./rust-toolchain) file for specific version of rust.
15+
- We target the `stable` version of the Rust compiler.
2116
- [`cargo-make`](https://github.com/sagiegurari/cargo-make)
22-
- Docker
23-
- Node 14 (LTS) & npm
24-
Used for running a local Ethereum node with `ganache-cli` for automated tests in the `Ethereum Adapter` ([adapter/src/ethereum.rs](./adapter/src/ethereum.rs), also check [scripts/ethereum.sh](./scripts/ethereum.sh))
17+
- Docker & Docker-compose
2518

2619
#### Linux
2720

@@ -30,17 +23,25 @@ Requirements:
3023

3124
## Sentry
3225

33-
`Sentry` is the REST API that the [`Validator worker`](#validator-worker) uses for storing and retrieving information.
34-
We need two services to be able to run `Sentry`: `Postgres` and `Redis`.
26+
`Sentry` is the REST API that the [`Validator worker`](#running-the-validator-worker)
27+
uses for storing and retrieving information.
28+
29+
Two services are needed to run `Sentry`: `Postgres` and `Redis`.
30+
31+
The easiest way to run these services locally is by using the provided `docker-compose` file:
3532

36-
### Running Postgres
33+
`docker-compose -f ../docker-compose.harness.yml up -d adex-redis adex-postgres`
34+
35+
If you want to run them manually without `docker-compose`:
36+
37+
#### Running Postgres
3738

3839
`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`
3940

4041
- `$HOME/docker/volumes/postgres` - your local storage for postgres (persist the data when we remove the container)
41-
- `POSTGRES_PASSWORD=postgres` - the password of `postgres` user
42+
- `POSTGRES_PASSWORD=postgres` - the password of the default `postgres` user
4243

43-
**NOTE:** Additionally you must setup 2 databases - `sentry_leader` & `sentry_follower` in order for the provided examples bellow to work.
44+
**NOTE:** Additionally you must setup 2 databases - `sentry_leader` & `sentry_follower` in order for the provided examples below to work. Postgres comes with an environment variable `POSTGRES_DB` that you can use to change the default `postgres` database, but there is currently no way to create multiple using the official `postgres` image.
4445

4546
### Running Redis
4647

@@ -56,47 +57,60 @@ cargo run -p sentry -- --help
5657

5758
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.
5859

59-
In `development` ( [`ENV` environment variable](#environment-variables) ) it will seed the database as well.
60+
By default, we use the `development` environment ( [`ENV` environment variable](#environment-variables) ) as it will also seed the database.
6061

61-
#### Using the `Ethereum Adapter`
62+
#### Using the `Ethereum` adapter
6263

63-
The password for the Keystore file can be set using the [environment variable `KEYSTORE_PWD`](#adapter).
64+
The password for the keystore file can be set using the [`KEYSTORE_PWD` environment variable](#adapter).
65+
These examples use the Leader and Follower addresses for testing locally with
66+
`ganache` and the production configuration of the validator.
6467

65-
- Leader
66-
```bash
67-
POSTGRES_DB="sentry_leader" PORT=8005 KEYSTORE_PWD=adexvalidator cargo run -p sentry -- \
68-
--adapter ethereum \
69-
--keystoreFile ./adapter/resources/keystore.json \
70-
./docs/config/dev.toml
71-
```
68+
##### Leader (`0x80690751969B234697e9059e04ed72195c3507fa`)
7269

73-
- Follower
74-
```bash
75-
POSTGRES_DB="sentry_follower" PORT=8006 KEYSTORE_PWD=adexvalidator cargo run -p sentry -- \
76-
--adapter ethereum \
77-
--keystoreFile ./adapter/resources/keystore.json
78-
./docs/config/dev.toml
79-
```
70+
Sentry API will be accessible at `localhost:8005`
8071

81-
#### Using the `Dummy Adapter`
72+
```bash
73+
IP_ADDR=127.0.0.1 REDIS_URL="redis://127.0.0.1:6379/1" \
74+
POSTGRES_DB="sentry_leader" PORT=8005 KEYSTORE_PWD=ganache0 \
75+
cargo run -p sentry -- \
76+
--adapter ethereum \
77+
--keystoreFile ./adapter/tests/resources/0x80690751969B234697e9059e04ed72195c3507fa_keystore.json \
78+
./docs/config/prod.toml
79+
```
80+
81+
##### Follower (`0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7`)
82+
83+
Sentry API will be accessible at `localhost:8006`
84+
85+
```bash
86+
IP_ADDR=127.0.0.1 REDIS_URL="redis://127.0.0.1:6379/2" \
87+
POSTGRES_DB="sentry_follower" PORT=8006 KEYSTORE_PWD=ganache1 cargo run -p sentry -- \
88+
--adapter ethereum \
89+
--keystoreFile ./adapter/test/resources/0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7_keystore.json
90+
./docs/config/prod.toml
91+
```
92+
93+
#### Using the `Dummy` adapter
8294

8395
**Dummy** identities:
8496

85-
- Leader: `ce07CbB7e054514D590a0262C93070D838bFBA2e`
97+
##### Leader (`0x80690751969B234697e9059e04ed72195c3507fa`)
8698

8799
```bash
88-
POSTGRES_DB="sentry_leader" PORT=8005 cargo run -p sentry -- \
89-
--adapter dummy \
90-
--dummyIdentity ce07CbB7e054514D590a0262C93070D838bFBA2e \
91-
./docs/config/dev.toml
100+
IP_ADDR=127.0.0.1 REDIS_URL="redis://127.0.0.1:6379/1" \
101+
POSTGRES_DB="sentry_leader" PORT=8005 cargo run -p sentry -- \
102+
--adapter dummy \
103+
--dummyIdentity 80690751969B234697e9059e04ed72195c3507fa \
104+
./docs/config/prod.toml
92105
```
93-
- Follower: `c91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3`
106+
##### Follower (`0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7`)
94107

95108
```bash
96-
POSTGRES_DB="sentry_follower" PORT=8006 cargo run -p sentry -- \
97-
--adapter dummy \
98-
--dummyIdentity c91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3 \
99-
./docs/config/dev.toml
109+
IP_ADDR=127.0.0.1 REDIS_URL="redis://127.0.0.1:6379/2" \
110+
POSTGRES_DB="sentry_follower" PORT=8006 cargo run -p sentry -- \
111+
--adapter dummy \
112+
--dummyIdentity f3f583AEC5f7C030722Fe992A5688557e1B86ef7 \
113+
./docs/config/prod.toml
100114
```
101115

102116
For full list, check out [primitives/src/util/tests/prep_db.rs#L29-L43](./primitives/src/util/tests/prep_db.rs#L29-L43)
@@ -106,114 +120,119 @@ For full list, check out [primitives/src/util/tests/prep_db.rs#L29-L43](./primit
106120
- `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.
107121
- `PORT` - *default*: `8005` - The local port that Sentry API will be accessible at
108122
- `IP_ADDR` - *default*: `0.0.0.0` - the IP address that the API should be listening to
109-
- `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`)
123+
110124
##### Adapter
111-
- `KEYSTORE_PWD` - Password for the `Keystore file`, only available when using `Ethereum Adapter` (`--adapter ethereum`)
125+
- `KEYSTORE_PWD` - Password for the `Keystore file`, only available when using `Ethereum` adapter (`--adapter ethereum`)
112126

113127
##### Redis
128+
114129
- `REDIS_URL` - *default*: `redis://127.0.0.1:6379`
115130

116131
##### Postgres
132+
117133
- `POSTGRES_HOST` - *default*: `localhost`
118134
- `POSTGRES_USER` - *default*: `postgres`
119135
- `POSTGRES_PASSWORD` - *default*: `postgres`
120136
- `POSTGRES_DB` - *default*: `user` name - Database name in Postgres to be used for this instance
121137
- `POSTGRES_PORT` - *default*: `5432`
122138

123-
#####
124139

125-
### Running the Validator Worker
140+
### Validator worker
126141

127142
For a full list of all available CLI options on the Validator worker run `--help`:
128143

129144
```bash
130145
cargo run -p validator_worker -- --help
131146
```
132147

133-
#### Using the `Ethereum Adapter`
134-
TODO: Update Keystore file and Keystore password for Leader/Follower as they are using the same at the moment.
135-
148+
#### Using the `Ethereum` adapter
136149
The password for the Keystore file can be set using the environment variable `KEYSTORE_PWD`.
137150

138-
- Leader
151+
##### Validator Leader (`0x80690751969B234697e9059e04ed72195c3507fa`)
139152
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Leader** on port `8005`:
140153

141-
```bash
142-
KEYSTORE_PWD=adexvalidator cargo run -p validator_worker -- \
143-
--adapter ethereum \
144-
--keystoreFile ./adapter/resources/keystore.json \
145-
--sentryUrl http://127.0.0.1:8005 \
146-
./docs/config/dev.toml
147-
```
154+
```bash
155+
KEYSTORE_PWD=ganache0 cargo run -p validator_worker -- \
156+
--adapter ethereum \
157+
--keystoreFile ./adapter/test/resources/0x80690751969B234697e9059e04ed72195c3507fa_keystore.json \
158+
--sentryUrl http://127.0.0.1:8005 \
159+
./docs/config/prod.toml
160+
```
148161

149-
- Follower
162+
##### Validator Follower
150163

151-
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Follower** on port `8006`:
164+
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Follower** on port `8006`:
152165

153-
```bash
154-
KEYSTORE_PWD=adexvalidator cargo run -p validator_worker -- \
155-
--adapter ethereum \
156-
--keystoreFile ./adapter/resources/keystore.json \
157-
--sentryUrl http://127.0.0.1:8006 \
158-
./docs/config/dev.toml
159-
```
166+
```bash
167+
KEYSTORE_PWD=ganache1 cargo run -p validator_worker -- \
168+
--adapter ethereum \
169+
--keystoreFile ./adapter/test/resources/0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7_keystore.json \
170+
--sentryUrl http://127.0.0.1:8006 \
171+
./docs/config/prod.toml
172+
```
160173

161-
#### Using the `Dummy Adapter`
162-
- Leader: `ce07CbB7e054514D590a0262C93070D838bFBA2e`
174+
#### Using the `Dummy` adapter
163175

164-
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Leader** on port `8005`:
176+
##### Validator Leader (`0x80690751969B234697e9059e04ed72195c3507fa`)
165177

166-
```bash
167-
cargo run -p validator_worker -- \
168-
--adapter dummy \
169-
--dummyIdentity ce07CbB7e054514D590a0262C93070D838bFBA2e \
170-
--sentryUrl http://127.0.0.1:8005 \
171-
./docs/config/dev.toml
172-
```
178+
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Leader** on port `8005`:
173179

174-
- Follower: `c91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3`
180+
```bash
181+
cargo run -p validator_worker -- \
182+
--adapter dummy \
183+
--dummyIdentity 0x80690751969B234697e9059e04ed72195c3507fa \
184+
--sentryUrl http://127.0.0.1:8005 \
185+
./docs/config/prod.toml
186+
```
175187

176-
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Follower** on port `8006`:
188+
##### Follower: `0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7`
177189

178-
```bash
179-
cargo run -p validator_worker -- \
180-
--adapter dummy \
181-
--dummyIdentity c91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3 \
182-
--sentryUrl http://127.0.0.1:8006 \
183-
./docs/config/dev.toml
184-
```
190+
Assuming you have [Sentry API running](#running-sentry-rest-api) for the **Follower** on port `8006`:
191+
192+
```bash
193+
cargo run -p validator_worker -- \
194+
--adapter dummy \
195+
--dummyIdentity 0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7 \
196+
--sentryUrl http://127.0.0.1:8006 \
197+
./docs/config/prod.toml
198+
```
185199

186200
#### Environment variables
187201

188-
- `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.
202+
- `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 that Sentry seeds the database.
189203
- `PORT` - The local port that Sentry API will accessible at
190204

191205
##### Adapter
206+
192207
- `KEYSTORE_PWD` - Password for the `Keystore file`, only available when using `Ethereum Adapter` (`--adapter ethereum`)
193208

194209
## Development environment
195210

196-
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
197-
as well as on our Continuous Integration (CI). For a complete list of out-of-the-box commands you can check
198-
[Makefile.stable.toml](https://github.com/sagiegurari/cargo-make/blob/master/src/lib/Makefile.stable.toml).
211+
We use [`cargo-make`][cargo-make overview] for running automated checks
212+
(tests, builds, formatting, code linting, etc.) and building the project locally
213+
as well as on our Continuous Integration (CI).
214+
215+
For a complete list of out-of-the-box commands you can check out the [`Predefined Makefiles`](https://github.com/sagiegurari/cargo-make#usage-predefined-makefiles)
216+
while locally defined commands can be found in the `Makefiles.toml` in each crate directory.
199217

200218
### Local development
201219

202-
Locally it's enough to ensure that the default development command is executing successfully:
220+
It's enough to ensure that the default development command is executing successfully:
203221

204222
```bash
205223
cargo make
206224
```
207225

208-
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.).
226+
It will format your code using `rustfmt` and will perform `clippy` checks (it will fail on warnings).
227+
Thanks to `cargo` it will run all the tests (doc tests, unit tests, integration tests, etc.).
228+
229+
Using the provided `docker-compose.harness.yml` setup [`cargo-make`][cargo-make overview] will run
230+
all the required services for the specific crate/application before executing the tests.
209231

210-
This will also run the [Automated tests](#automated-tests), so you must have `Redis` & `Postgres` running.
232+
[cargo-make overview]: https://github.com/sagiegurari/cargo-make#overview
211233

212-
#### Automated tests
213234

214-
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:
215235

216-
`cargo make test`
236+
### License
217237

218-
You can relate to the [`Makefile.stable.toml`](https://github.com/sagiegurari/cargo-make/blob/master/src/lib/Makefile.stable.toml)
219-
for more commands and cargo-make as a whole.
238+
This project is licensed under the [AGPL-3.0 license](./LICENSE)

adapter/Makefile.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies = [
1717
args = ["test", "--release", "--all-features"]
1818

1919
[tasks.ganache-up]
20+
# `--renew-anon-volumes` is required to make sure that the snapshot used for the `ganache` instances is reloaded.
2021
script = '''
2122
docker-compose -f ../docker-compose.harness.yml up --renew-anon-volumes -d ganache-1 ganache-1337 \
2223
&& sleep 10

adview-manager/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# AdView Manager
22

3-
Gives you the ability to generate the code for showing ads on a publisher website.
3+
Gives you the ability to generate the code required for showing ads
4+
on a website (publisher).
45

56
### Testing
67

docker-compose.harness.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ services:
1212
POSTGRES_HOST: 'localhost'
1313
POSTGRES_USER: 'postgres'
1414
POSTGRES_PASSWORD: 'postgres'
15+
# harness_* databases are used by the `test_harness` crate for testing
16+
# `sentry_leader` is the default database used by `sentry` for running tests
17+
# `primitives` is used for running tests in the `primitives` crate
1518
POSTGRES_MULTIPLE_DATABASES: harness_leader,harness_follower,sentry_leader,primitives
1619
networks:
1720
- adex-external

sentry/Migrant.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ database_type = "postgres"
44
# Required database info
55
database_name = "sentry_leader"
66
database_user = "postgres"
7-
database_password = "docker"
7+
database_password = "postgres"
88

99
# Configurable database info
1010
# default "localhost"

0 commit comments

Comments
 (0)