Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/gprusak-ord-for-key…
Browse files Browse the repository at this point in the history
…' into gprusak-ord-for-key
  • Loading branch information
pompon0 committed Jan 23, 2024
2 parents 8039ebe + 4a2edd8 commit 9085e35
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 16 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node/target
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build Stage
FROM rust:latest as build
COPY /node/ /node/
COPY Makefile .
WORKDIR /node
RUN apt-get update && apt-get install -y libclang-dev
RUN cargo build --release
RUN cd .. && make docker_node_configs

# Runtime Stage
FROM debian:stable-slim as runtime

COPY --from=build /node/target/release/executor /node/
COPY --from=build /node/tools/docker-config/nodes-config /node/
COPY docker-entrypoint.sh /node/

WORKDIR /node
RUN chmod +x docker-entrypoint.sh

ENTRYPOINT ["./docker-entrypoint.sh"]

EXPOSE 3054
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.PHONY: node nodes_config docker_node_configs node_docker consensus_docker_example clean clean_docker
IP?=127.0.0.1:3054
DOCKER_IP=172.12.0.10
EXECUTABLE_NODE_DIR=node/tools

# Locally run commands

node:
export RUST_LOG=INFO && cd ${EXECUTABLE_NODE_DIR}/nodes-config/${IP} && cargo run -- --database ../../database/${IP}

nodes_config:
cd ${EXECUTABLE_NODE_DIR} && cargo run --bin localnet_config -- --input-addrs addresses.txt --output-dir nodes-config

# Docker commands

# This command will run inside the Dockerfile and it's not necessary to use it outside there.
docker_node_configs:
cd ${EXECUTABLE_NODE_DIR} && cargo run --release --bin localnet_config -- --input-addrs docker-config/addresses.txt --output-dir docker-config/nodes-config

node_docker:
mkdir -p ${EXECUTABLE_NODE_DIR}/docker-config
cd ${EXECUTABLE_NODE_DIR}/docker-config && rm -rf addresses.txt && echo ${DOCKER_IP}:3054 >> addresses.txt
docker-compose up -d node-1

consensus_docker_example:
mkdir -p ${EXECUTABLE_NODE_DIR}/docker-config
cd ${EXECUTABLE_NODE_DIR}/docker-config && rm -rf addresses.txt && touch addresses.txt && echo 172.12.0.10:3054 >> addresses.txt && echo 172.12.0.11:3054 >> addresses.txt
docker-compose up -d

stop_docker_nodes:
docker stop consensus-node-1 consensus-node-2

# Clean commands

clean: clean_docker
rm -rf ${EXECUTABLE_NODE_DIR}/nodes-config
rm -rf ${EXECUTABLE_NODE_DIR}/database

clean_docker:
rm -rf ${EXECUTABLE_NODE_DIR}/docker-config
docker rm -f consensus-node-1
docker rm -f consensus-node-2
docker network rm -f node-net
docker image rm -f consensus-node
28 changes: 28 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "3.9"

services:
node-1:
build: .
image: consensus-node
container_name: consensus-node-1
networks:
node_net:
# This allow us to know the ip of the node-1 container to fill the address in the config file
# Only for test purposes, may be removed in the future
ipv4_address: 172.12.0.10
node-2:
image: consensus-node
container_name: consensus-node-2
networks:
node_net:
# This allow us to know the ip of the node-2 container to fill the address in the config file
# Only for test purposes, may be removed in the future
ipv4_address: 172.12.0.11

networks:
node_net:
name: node-net
ipam:
config:
- subnet: "172.12.0.0/24"
gateway: "172.12.0.1"
6 changes: 6 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# This file works as an entrypoint of the docker container running the node binary copied inside of it.

cd $(hostname -i):3054
export RUST_LOG=INFO
../executor
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd $(hostname -i):3054
export RUST_LOG=INFO
../executor
12 changes: 0 additions & 12 deletions node/tools/Makefile

This file was deleted.

58 changes: 54 additions & 4 deletions node/tools/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
# Running a test node
# Running Test Consensus Nodes

1. Generate a file named `addresses.txt` in the root directory of the tools crate, containing node addresses in the format `IP:PORT`, with each address on a separate line.
2. Run `make node-configs`. This command will establish a directory named `node-configs` and create a folder for each address listed in the `.txt` file, providing the necessary configuration files for the respective node.
3. Execute `make run-node IP=<NODE_IP>`. The default value for this command would be `127.0.0.1:3054`. Note that running this command will take control of the terminal.
These instructions guide you through the process of setting up and running a test consensus node in both local and Dockerized environments. Additionally, examples are provided to demonstrate how to run two or more nodes, communicating and doing consensus between them.

## Local Setup

1. Edit the `addresses.txt` file located in the root directory of the tools crate. This file contains node addresses in the format `IP:PORT`. For a single node, use the example file. To run multiple nodes communicating with each other, write each node address on a separate line. This will run one node per address.

2. Move to the project root (era-consensus) and execute the following commands:

```bash
make nodes_config
```

This command establishes a directory named `nodes-config` and creates a folder for each address listed in the `.txt` file, providing necessary configuration files for the respective node.

```bash
make node IP=<NODE_IP>
```

The default value for this command is `127.0.0.1:3054`. Note that running this command will take control of the terminal.

## Dockerized Setup

To launch a standalone consensus node in a Docker container, run the following command in the project root (era-consensus):

```bash
make node_docker
```

This command creates a container running a single node that advances views and finalizes blocks.

For a simple example with two nodes communicating in different containers, use:

```bash
make consensus_docker_example
```

This sets up two containers, each hosting a consensus node, interlinked and progressing through views to finalize blocks, achieving consensus between them.

To stop the node containers, use:

```bash
make stop_docker_nodes
```

The node will resume the last viewed block from the previous session when initiated again.

To clean all states after running these commands, use:

```bash
make clean_docker
```

> This deletes the generated images and containers, requiring regeneration.
1 change: 1 addition & 0 deletions node/tools/addresses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
127.0.0.1:3054

0 comments on commit 9085e35

Please sign in to comment.