Skip to content

Commit

Permalink
feat: Add infrastructure to run node
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Oct 1, 2023
1 parent 99b6650 commit d26174f
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.env
.DS_Store
**/.idea/
offchain/integration-tests/deployments/**
275 changes: 275 additions & 0 deletions offchain/integration-tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
version: "3.9"

x-credentials:
&postgres-config
POSTGRES_HOSTNAME: database
POSTGRES_PORT: "5432"
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres

services:
hardhat:
image: cartesi/rollups-hardhat:1.0.0
command:
[
"node",
"--network",
"hardhat",
"--export",
"/opt/cartesi/share/deployments/localhost.json"
]
init: true
ports:
- "8545:8545"
healthcheck:
test:
[
"CMD",
"test",
"-f",
"/opt/cartesi/share/deployments/localhost.json"
]
interval: 30s
timeout: 30s
retries: 5
volumes:
- blockchain-data:/opt/cartesi/share/deployments
- ./deployments:/app/rollups/deployments

dispatcher:
image: cartesi/rollups-node:devel
command: cartesi-rollups-dispatcher
restart: always
depends_on:
hardhat:
condition: service_healthy
hardhat_set_interval:
condition: service_completed_successfully
deployer:
condition: service_completed_successfully
state_server:
condition: service_healthy
redis:
condition: service_healthy
environment:
RUST_LOG: info
RD_DAPP_DEPLOYMENT_FILE: /deployments/localhost/dapp.json
RD_ROLLUPS_DEPLOYMENT_FILE: /opt/cartesi/share/deployments/localhost.json
RD_EPOCH_DURATION: 86400
SC_GRPC_ENDPOINT: http://state_server:50051
SC_DEFAULT_CONFIRMATIONS: 1
TX_PROVIDER_HTTP_ENDPOINT: http://hardhat:8545
AUTH_MNEMONIC: "test test test test test test test test test test test junk"
TX_CHAIN_ID: 31337
TX_CHAIN_IS_LEGACY: ${TX_LEGACY:-false}
TX_DEFAULT_CONFIRMATIONS: 2
REDIS_ENDPOINT: redis://redis:6379
volumes:
- blockchain-data:/opt/cartesi/share/deployments:ro
- ./deployments:/deployments:ro

state_server:
image: cartesi/rollups-node:devel
command: cartesi-rollups-state-server
restart: always
healthcheck:
test: ["CMD-SHELL","bash -c 'echo \"\" > /dev/tcp/127.0.0.1/50051;'"]
interval: 10s
timeout: 5s
retries: 5
depends_on:
hardhat:
condition: service_healthy
environment:
RUST_LOG: info
SF_GENESIS_BLOCK: 0x1
SF_SAFETY_MARGIN: 1
BH_HTTP_ENDPOINT: http://hardhat:8545
BH_WS_ENDPOINT: ws://hardhat:8545
BH_BLOCK_TIMEOUT: 8

advance_runner:
image: cartesi/rollups-node:devel
command: cartesi-rollups-advance-runner
restart: always
healthcheck:
test: [ "CMD", "curl", "--fail", "localhost:8080/healthz" ]
interval: 10s
timeout: 5s
retries: 5
depends_on:
redis:
condition: service_healthy
server_manager:
condition: service_healthy
deployer:
condition: service_completed_successfully
volumes:
- ./deployments:/deployments:ro
- machine:/var/opt/cartesi/machine-snapshots
environment:
RUST_LOG: info
SERVER_MANAGER_ENDPOINT: http://server_manager:5001
PROVIDER_HTTP_ENDPOINT: http://hardhat:8545
SESSION_ID: default_rollups_id
REDIS_ENDPOINT: redis://redis:6379
CHAIN_ID: 31337
DAPP_CONTRACT_ADDRESS_FILE: /deployments/localhost/dapp.json
SNAPSHOT_DIR: /var/opt/cartesi/machine-snapshots
SNAPSHOT_LATEST: /var/opt/cartesi/machine-snapshots/latest

server_manager:
image: cartesi/dapp:echo-devel-server
restart: always
ports:
- "5001:5001"
healthcheck:
test: ["CMD-SHELL","bash -c 'echo \"\" > /dev/tcp/127.0.0.1/5001;'"]
interval: 10s
timeout: 5s
retries: 5
volumes:
- machine:/var/opt/cartesi/machine-snapshots
environment:
- SERVER_MANAGER_LOG_LEVEL=warning
- REMOTE_CARTESI_MACHINE_LOG_LEVEL=info

deployer:
image: cartesi/rollups-cli:1.0.0
restart: on-failure
depends_on:
hardhat:
condition: service_healthy
server_manager:
condition: service_healthy
command:
[
"create",
"--rpc",
"http://hardhat:8545",
"--deploymentFile",
"/opt/cartesi/share/deployments/localhost.json",
"--mnemonic",
"test test test test test test test test test test test junk",
"--templateHashFile",
"/var/opt/cartesi/machine-snapshots/0_0/hash",
"--outputFile",
"/deployments/localhost/dapp.json"
]
volumes:
- blockchain-data:/opt/cartesi/share/deployments:ro
- machine:/var/opt/cartesi/machine-snapshots:ro
- ./deployments:/deployments

hardhat_stop_automine:
image: curlimages/curl:7.84.0
restart: on-failure
depends_on:
hardhat:
condition: service_healthy
deployer:
condition: service_completed_successfully
command:
[
"--data",
'{"id":1337,"jsonrpc":"2.0","method":"evm_setAutomine","params":[false]}',
"http://hardhat:8545"
]

hardhat_set_interval:
image: curlimages/curl:7.84.0
restart: on-failure
depends_on:
hardhat:
condition: service_healthy
hardhat_stop_automine:
condition: service_completed_successfully
command:
[
"--data",
'{"id":1337,"jsonrpc":"2.0","method":"evm_setIntervalMining","params":[5000]}',
"http://hardhat:8545"
]

inspect_server:
image: cartesi/rollups-node:devel
command: cartesi-rollups-inspect-server
restart: always
ports:
- "5005:5005"
depends_on:
server_manager:
condition: service_healthy
environment:
RUST_LOG: info
INSPECT_SERVER_ADDRESS: 0.0.0.0:5005
SERVER_MANAGER_ADDRESS: server_manager:5001
SESSION_ID: default_rollups_id

indexer:
image: cartesi/rollups-node:devel
command: cartesi-rollups-indexer
restart: always
depends_on:
database:
condition: service_healthy
redis:
condition: service_healthy
deployer:
condition: service_completed_successfully
environment:
<<: *postgres-config
RUST_LOG: info
REDIS_ENDPOINT: redis://redis:6379
CHAIN_ID: 31337
DAPP_CONTRACT_ADDRESS_FILE: /deployments/localhost/dapp.json
volumes:
- ./deployments:/deployments:ro

graphql_server:
image: cartesi/rollups-node:devel
command: cartesi-rollups-graphql-server
ports:
- "4000:4000"
depends_on:
database:
condition: service_healthy
environment:
RUST_LOG: info
GRAPHQL_HOST: "0.0.0.0"
GRAPHQL_PORT: "4000"
<<: *postgres-config

database:
image: postgres:13-alpine
ports:
- 5432:5432
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres || exit 1" ]
interval: 10s
timeout: 5s
retries: 5
environment:
- POSTGRES_PASSWORD=password
volumes:
- database-data:/var/lib/postgresql/data

redis:
image: redis:6-alpine
ports:
- 6379:6379
restart: always
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 10s
timeout: 5s
retries: 5
volumes:
- redis-data:/data

volumes:
blockchain-data: {}
machine: {}
database-data: {}
redis-data: {}
30 changes: 30 additions & 0 deletions offchain/integration-tests/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# (c) Cartesi and individual authors (see AUTHORS)
# SPDX-License-Identifier: Apache-2.0 (see LICENSE)

FROM cartesi/server-manager:0.8.2 as build-server-stage

USER root

# Install system dependencies
RUN apt update && \
apt install -y wget

# Download rootfs, linux and rom
ENV IMAGES_PATH /usr/share/cartesi-machine/images
RUN wget -O ${IMAGES_PATH}/rootfs.ext2 https://github.com/cartesi/image-rootfs/releases/download/v0.18.0/rootfs-v0.18.0.ext2 && \
wget -O ${IMAGES_PATH}/linux.bin https://github.com/cartesi/image-kernel/releases/download/v0.17.0/linux-5.15.63-ctsi-2-v0.17.0.bin && \
wget -O ${IMAGES_PATH}/rom.bin https://github.com/cartesi/machine-emulator-rom/releases/download/v0.17.0/rom-v0.17.0.bin

# Generate machine with echo and store it
ENV SNAPSHOT_DIR=/tmp/dapp-bin
RUN cartesi-machine \
--ram-length=128Mi \
--rollup \
--store=$SNAPSHOT_DIR \
-- "ioctl-echo-loop --vouchers=1 --notices=1 --reports=1 --verbose=1"

FROM cartesi/server-manager:0.8.2 as server-stage

WORKDIR /opt/cartesi/bin
COPY --from=build-server-stage --chown=cartesi:cartesi /tmp/dapp-bin /var/opt/cartesi/machine-snapshots/0_0
RUN ln -s /var/opt/cartesi/machine-snapshots/0_0 /var/opt/cartesi/machine-snapshots/latest
10 changes: 10 additions & 0 deletions offchain/integration-tests/docker/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
group "default" {
targets = ["server"]
}


target "server" {
context = "."
target = "server-stage"
tags = ["cartesi/dapp:echo-devel-server"]
}
3 changes: 3 additions & 0 deletions offchain/integration-tests/send_input.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

export INPUT_BOX_ADDRESS=0x59b22D57D4f067708AB0c00552767405926dc768
cast send $INPUT_BOX_ADDRESS "addInput(address,bytes)(bytes32)" 0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C 0x68656C6C6F206E6F6465 --mnemonic "test test test test test test test test test test test junk" --rpc-url "http://localhost:8545"

0 comments on commit d26174f

Please sign in to comment.