Skip to content

Commit

Permalink
docs: add instructions to run the node with Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
gligneul committed Jan 19, 2024
1 parent 6e4650a commit 4f45d89
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
version: v1.54.2

- name: Check auto generated files
run: make
run: make check-generate
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added experimental sunodo validator mode
- Added inspect command to `cartesi-rollups-cli`
- Added increase-time command to `cartesi-rollups-cli`
- Added instructions on how to run the node with Docker.

### Changed

Expand Down
69 changes: 64 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,80 @@
.PHONY: all generate cargo diff
.PHONY: all
all: help

all: diff
.PHONY: submodules
submodules: ## Download the git submodules
@git submodule update --init --recursive

generate:
.PHONY: test
test: ## Execute the node tests
@echo "Running the tests"
@go test ./...

.PHONY: lint
lint: ## Run the linter
@echo "Running the linter"
@golangci-lint run

.PHONY: generate
generate: ## Generate the file that are commited to the repo
@echo "Generating Go files"
@go mod tidy
@go generate -v ./...

cargo:
.PHONY: graphql-schema
graphql-schema: ## Generate the graphql schema file
@cd offchain; cargo run --bin generate-schema
@mv offchain/schema.graphql api/graphql/reader.graphql

diff: cargo generate
.PHONY: check-generate
check-generate: generate graphql-schema ## Check whether the generated files are in sync
@echo "Checking differences on the repository..."
@if git diff --exit-code; then \
echo "No differences found."; \
else \
echo "ERROR: Differences found in the resulting files."; \
exit 1; \
fi

.PHONY: docker-build
docker-build: ## Build the docker images using bake
@cd build && docker buildx bake --load

.PHONY: docker-run
docker-run: docker-clean ## Run the node with the anvil devnet
@docker compose \
-f ./build/compose-database.yaml \
-f ./build/compose-devnet.yaml \
-f ./build/compose-snapshot.yaml \
-f ./build/compose-node.yaml \
up

.PHONY: docker-run-sepolia
docker-run-sepolia: docker-clean ## Run the node with the sepolia testnet
@if [ ! -n "$$RPC_HTTP_URL" ]; then \
echo "RPC_HTTP_URL was not set"; \
exit 1; \
fi
@if [ ! -n "$$RPC_WS_URL" ]; then \
echo "RPC_WS_URL was not set"; \
exit 1; \
fi
@docker compose \
-f ./build/compose-database.yaml \
-f ./build/compose-snapshot.yaml \
-f ./build/compose-node.yaml \
-f ./build/compose-sepolia.yaml \
up

.PHONY: docker-clean
docker-clean: ## Remove the containers and volumes from previous compose run
@docker compose \
-f ./build/compose-database.yaml \
-f ./build/compose-devnet.yaml \
-f ./build/compose-snapshot.yaml \
-f ./build/compose-node.yaml \
down -v

.PHONY: help
help: ## Show help for each of the Makefile recipes
@grep "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/:.*##\(.*\)/:\n\t\1\n/'
88 changes: 42 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,75 +14,71 @@ They consume information from the blockchain but do not bother to enforce state

Validators, on the other hand, have more responsibility: they not only watch the blockchain but also fight to ensure that the blockchain will only accept valid state updates.

## Getting Started
## Dependencies

### Cloning submodules

Before building and running any of the inner projects, you should download the submodules with:
The Cartesi Node depends on the following Cartesi components:

```shell
git submodule update --init --recursive
```
| Component | Version |
|---|---|
| Cartesi Machine SDK | [v0.16.2](https://github.com/cartesi/machine-emulator-sdk/releases/tag/v0.16.2) |
| Cartesi OpenAPI Interfaces | [v0.6.0](https://github.com/cartesi/openapi-interfaces/releases/tag/v0.6.0) |
| Cartesi Rollups Contracts | [v1.1.0](https://github.com/cartesi/rollups-contracts/releases/tag/v1.1.0) |
| Cartesi Server Manager | [v0.8.2](https://github.com/cartesi/server-manager/releases/tag/v0.8.2) |

### Generating files
## Node Configuration

All the necessary auto-generated files are already commited to the project; but if you wish to generate them again, you can run the Makefile at the root of the project. Simply run the command:
The node should be configured exclusively with environment variables.
Those variables are described at [Node Configuration](./docs/config.md).

```shell
make
```
## Node Development

### Building the Docker image
The recommended way of running the node for Cartesi users and application developers is using [Sunodo](https://docs.sunodo.io).
This section of the documentation is for developers that want to modify the node source code.

For more information on how to build the rollups-node docker image, see the [build directory](./build/README.md).
### Cloning submodules

### Rust
Before building and running the node, you should download the submodules with the command below.

All projects comprising the Cartesi Node require Rust to be executed.
To install it, follow the [instructions](https://www.rust-lang.org/tools/install) from the Rust website.
```sh
make submodules
```

### Dependencies
### Generating files

The Cartesi Node depends on the following components:
All the necessary auto-generated files are already commited to the project; but if you wish to generate them again, you can run the command below.

| Component | Version |
|---|---|
| Cartesi Machine SDK | [v0.16.2](https://github.com/cartesi/machine-emulator-sdk/releases/tag/v0.16.2) |
| Cartesi OpenAPI Interfaces | [v0.6.0](https://github.com/cartesi/openapi-interfaces/releases/tag/v0.6.0) |
| Cartesi Rollups Contracts | [v1.1.0](https://github.com/cartesi/rollups-contracts/releases/tag/v1.1.0) |
| Cartesi Server Manager | [v0.8.2](https://github.com/cartesi/server-manager/releases/tag/v0.8.2) |
```sh
make generate
```

### Running
### Building the Docker images

To run any of the inner projects, execute the command:
The easiest way to run the node is using the pre-configured Docker images.
These images include a development Ethereum node and a test Cartesi application.
To build those images, run the command below.

```shell
cargo run
```sh
make docker-build
```

Some of the inner projects may have additional run instructions.
Refer to their own documentation for more details.
### Running the node with Docker

## Configuration
After building the Docker images, you may run the node running the command below.
This command will run a PostgreSQL database and the development Ethereum node.

It is possible to configure the behavior of any of the projects by passing CLI arguments and using environment variables.
Execute the following command to check the available options for each project:

```shell
cargo run -- -h
```sh
make docker-run
```

### Redis TLS Configuration

To connect the Broker to a Redis server via TLS, the server's URL must use the `rediss://` scheme (with two "s"es).
This is currently the only way to tell `Broker` to use a TLS connection.

## Tests
#### Connecting to Sepolia testnet

To run the tests available in any of the projects, execute the command:
It is possible to connect the node to the Sepolia testnet instead of running a local devnet.
First, you need to set the environment variables `RPC_HTTP_URL` and `RPC_WS_URL` with the URLs of the RPC provider.
For instance, if you are using Alchemy, the variables should be set to `https://eth-sepolia.g.alchemy.com/v2/$ALCHEMY_API_KEY` and `wss://eth-sepolia.g.alchemy.com/v2/$ALCHEMY_API_KEY`.
Then, run the command below to run the node.

```shell
cargo test
```sh
make docker-run-sepolia
```

## Architecture Overview
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ COPY --from=devnet-builder ${DEVNET_BUILD_PATH}/anvil_state.json ${ANVIL_STATE_P

# Copy healthcheck script.
COPY scripts/devnet/lib/anvil_net_listening.sh /usr/bin/anvil_net_listening.sh
HEALTHCHECK --interval=10s --timeout=1s --retries=5 CMD anvil_net_listening.sh
HEALTHCHECK --interval=1s --timeout=1s --retries=5 CMD anvil_net_listening.sh

# Make Anvil bind to the external network interface.
ENV ANVIL_IP_ADDR="0.0.0.0"
Expand Down
7 changes: 0 additions & 7 deletions build/README.md

This file was deleted.

24 changes: 24 additions & 0 deletions build/compose-database.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This compose file contains the PostgreSQL database necessary to run the node.

version: "3.9"

name: rollups-node
services:
database:
image: postgres:13-alpine
ports:
- 5432:5432
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres || exit 1"]
interval: 1s
timeout: 1s
retries: 5
environment:
- POSTGRES_PASSWORD=password

node:
depends_on:
database:
condition: service_healthy
environment:
CARTESI_POSTGRES_ENDPOINT: "postgres://postgres:password@database:5432/postgres"
28 changes: 8 additions & 20 deletions build/node-compose.yml → build/compose-devnet.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
# This compose file contains the Anvil devnet container for the node.

version: "3.9"

name: rollups-node
services:
node:
image: "cartesi/rollups-node:devel"
devnet:
image: cartesi/rollups-node-devnet:devel
ports:
- "10000:10000" # Supervisor
- "10004:10004" # GraphQL Server
- "10009:10009" # Inspect Server
restart: always
- 8545:8545

node:
depends_on:
devnet:
condition: service_healthy
machine_snapshot_setup:
condition: service_completed_successfully
database:
condition: service_healthy
environment:
CARTESI_LOG_LEVEL: "info"
CARTESI_LOG_TIMESTAMP: "false"
CARTESI_FEATURE_HOST_MODE: "false"
CARTESI_FEATURE_READER_MODE: "false"
CARTESI_EPOCH_DURATION: "120"
CARTESI_BLOCKCHAIN_ID: "31337"
CARTESI_BLOCKCHAIN_HTTP_ENDPOINT: "http://devnet:8545"
CARTESI_BLOCKCHAIN_WS_ENDPOINT: "ws://devnet:8545"
Expand All @@ -33,9 +25,5 @@ services:
CARTESI_CONTRACTS_AUTHORITY_ADDRESS: "0xb090149a3cA43000681B74875500854B54355496"
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER: "17"
CARTESI_SNAPSHOT_DIR: "/usr/share/cartesi/snapshots"
CARTESI_EPOCH_DURATION: "120"
CARTESI_AUTH_MNEMONIC: "test test test test test test test test test test test junk"
CARTESI_POSTGRES_ENDPOINT: "postgres://postgres:password@database:5432/postgres"
CARTESI_HTTP_ADDRESS: "0.0.0.0"
volumes:
- machine:/usr/share/cartesi/snapshots
21 changes: 21 additions & 0 deletions build/compose-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file contains the bare configuration to run the node.
# This file should be merged with the other compose files to run the node with
# the desired configuration.

version: "3.9"

name: rollups-node
services:
node:
image: "cartesi/rollups-node:devel"
ports:
- "10000:10000" # Supervisor
- "10004:10004" # GraphQL Server
- "10009:10009" # Inspect Server
environment:
CARTESI_LOG_LEVEL: "info"
CARTESI_LOG_TIMESTAMP: "false"
CARTESI_FEATURE_HOST_MODE: "false"
CARTESI_FEATURE_READER_MODE: "false"
CARTESI_HTTP_ADDRESS: "0.0.0.0"
CARTESI_HTTP_PORT: "10000"
25 changes: 25 additions & 0 deletions build/compose-sepolia.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This compose file contains the config to run the node with the Sepolia testnet.
# The config points to the echo Python application running in Sepolia.
# It is necessary to set the RPC provider URLs in the RPC_*_URL environment variables.
# Notice the node will run in reader mode, so it doesn't need a Ethereum wallet.

version: "3.9"

name: rollups-node
services:
node:
environment:
CARTESI_BLOCKCHAIN_ID: "11155111"
CARTESI_BLOCKCHAIN_HTTP_ENDPOINT: "${RPC_HTTP_URL}"
CARTESI_BLOCKCHAIN_WS_ENDPOINT: "${RPC_WS_URL}"
CARTESI_BLOCKCHAIN_IS_LEGACY: "false"
CARTESI_BLOCKCHAIN_FINALITY_OFFSET: "1"
CARTESI_CONTRACTS_DAPP_ADDRESS: "0x9f12D4365806FC000D6555ACB85c5371b464E506"
CARTESI_CONTRACTS_DAPP_DEPLOYMENT_BLOCK_NUMBER: "4152308"
CARTESI_CONTRACTS_HISTORY_ADDRESS: "0x76f4dCaC0920826541EE718214EEE4be07346cEE"
CARTESI_CONTRACTS_AUTHORITY_ADDRESS: "0x5827Ec9365D3a9b27bF1dB982d258Ad234D37242"
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS: "0x59b22D57D4f067708AB0c00552767405926dc768"
CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER: "3963384"
CARTESI_EPOCH_DURATION: "86400"
CARTESI_FEATURE_READER_MODE: "true"
CARTESI_FEATURE_DISABLE_MACHINE_HASH_CHECK: "true"
23 changes: 23 additions & 0 deletions build/compose-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This compose file contains cartesi-machine test-application snapshot.
# It creates a dummy container just to create the volume with the snapshot.

version: "3.9"

name: rollups-node
services:
machine_snapshot_setup:
image: cartesi/rollups-node-snapshot:devel
volumes:
- machine:/usr/share/cartesi/snapshots

node:
depends_on:
machine_snapshot_setup:
condition: service_completed_successfully
environment:
CARTESI_SNAPSHOT_DIR: "/usr/share/cartesi/snapshots"
volumes:
- machine:/usr/share/cartesi/snapshots

volumes:
machine: {}
Loading

0 comments on commit 4f45d89

Please sign in to comment.