Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Safe events service #117

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ CFG_VERSION=latest
CGW_VERSION=latest
TXS_VERSION=latest
UI_VERSION=latest
EVENTS_VERSION=latest

RPC_NODE_URL=http://url.to.node
9 changes: 9 additions & 0 deletions container_env_files/events.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DATABASE_URL=psql://postgres:postgres@events-db:5432/postgres
AMQP_URL=amqp://general-rabbitmq:5672
AMQP_EXCHANGE=safe-transaction-service-events
AMQP_QUEUE=safe-events-service
ADMIN_EMAIL=admin@safe
ADMIN_PASSWORD=password
WEBHOOKS_CACHE_TTL=300000
NODE_ENV=production
URL_BASE_PATH=/events
3 changes: 3 additions & 0 deletions container_env_files/txs.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ CELERY_BROKER_URL=amqp://guest:guest@txs-rabbitmq/
DJANGO_ALLOWED_HOSTS="*"
FORCE_SCRIPT_NAME=/txs/
CSRF_TRUSTED_ORIGINS="http://localhost:8000"
EVENTS_QUEUE_URL=amqp://general-rabbitmq:5672
EVENTS_QUEUE_ASYNC_CONNECTION=True
EVENTS_QUEUE_EXCHANGE_NAME="safe-transaction-service-events"
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:
- txs-web
- cfg-web
- cgw-web
- events-web

txs-db:
image: postgres:14-alpine
Expand All @@ -49,6 +50,14 @@ services:
- ./data/cfg-db:/var/lib/postgresql/data
<<: *pghealthcheck

events-db:
image: postgres:14-alpine
environment:
POSTGRES_PASSWORD: postgres
volumes:
- ./data/events-db:/var/lib/postgresql/data
<<: *pghealthcheck

# Safe Transaction Service
txs-redis:
image: redis:alpine
Expand Down Expand Up @@ -152,3 +161,22 @@ services:
- nginx
ports:
- "${REVERSE_PROXY_UI_PORT}:8080"

general-rabbitmq:
image: rabbitmq:alpine
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 15s
timeout: 30s
retries: 3
start_period: 15s

events-web:
image: safeglobal/safe-events-service:${EVENTS_VERSION}
env_file:
- container_env_files/events.env
depends_on:
events-db:
condition: service_healthy
general-rabbitmq:
condition: service_healthy
24 changes: 24 additions & 0 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ http {
keepalive 32;
}

upstream events_app_server {
ip_hash; # For load-balancing
server events-web:3000 fail_timeout=0;
#
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response
keepalive 32;
}

server {
access_log off;
listen 8000 deferred;
Expand Down Expand Up @@ -120,6 +129,21 @@ http {
proxy_redirect off;
proxy_pass http://cgw_app_server/;

proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header Front-End-Https on;
}

## Events service mounting point
location /events/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
# we don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
proxy_pass http://events_app_server/events/;

proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header Front-End-Https on;
Expand Down
5 changes: 4 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Safe Infrastructure

![Safe Infrastructure Diagram](https://user-images.githubusercontent.com/6909403/231760296-afaa126c-db04-4f62-b996-c53b1d884247.png)
**Safe infrastructure diagram**
<figure><img src="./diagrams/safe-infrastructure-diagram.png" width="100%" alt="" /></figure>

- **Tx Service** is the core of the Safe. It indexes multisig transactions, module transactions, token transfers, collects signatures... There must be **1 Tx Service per Chain**, with different workers, PostgreSQL, Redis and RabbitMQ.
- **Config Service** holds configuration for every Chain (blockexplorer, tx service url, apps enabled, wallets enabled...). **1 instance of the Config Service supports multiple Chains**
- **Client Gateway** provides an API optimized for clients (web ui, android, ios...). **1 instance of the Client Gateway supports multiple Chains**
- **Safe Events Service** handle Safe indexing events from Transaction Service and deliver as HTTP webhooks.

## Setup

Expand All @@ -16,6 +18,7 @@ CFG_VERSION=v2.60.0
CGW_VERSION=v0.4.1
TXS_VERSION=v4.6.1
UI_VERSION=v1.2.0
EVENTS_VERSION=v0.5.0
```

You can change them to the version you are interested available in [docker-hub](https://hub.docker.com/u/safeglobal) but be aware that not all versions of our services are compatible with each other, so do so **at your own risk.**
Expand Down
Loading