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 polybft consensus support to edge #1051

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
13 changes: 0 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ test-e2e-polybft:
go build -o artifacts/polygon-edge .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true go test -v -timeout=30m ./e2e-polybft/...

.PHONY: run-local
run-local:
$(MAKE) compile-core-contracts
docker-compose -f ./docker/local/docker-compose.yml up -d --build

.PHONY: stop-local
stop-local:
docker-compose -f ./docker/local/docker-compose.yml stop

.PHONY: destroy-local
destroy-local:
docker-compose -f ./docker/local/docker-compose.yml down

.PHONY: compile-core-contracts
compile-core-contracts:
cd core-contracts && npm install && npm run compile
Expand Down
61 changes: 61 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Deploying local docker cluster

## Prerequisites
* [Docker Desktop](https://www.docker.com/products/docker-desktop/) - Docker 17.12.0+
* [Docker compose 2+](https://github.com/docker/compose/releases/tag/v2.14.1)

### `polybft` consensus
When deploying with `polybft` consensus, there are some additional dependencies:
* [npm](https://nodejs.org/en/)
* [go 1.18.x](https://go.dev/dl/)

## Local development
Running `polygon-edge` local cluster with docker can be done very easily by using provided `scripts` folder
or by running `docker-compose` manually.

### Using provided `scripts` folder
***All commands need to be run from the repo root / root folder.***

* `scripts/cluster ibft --docker` - deploy environment with `ibft` consensus
* `scripts/cluster polybft --docker` - deploy environment with `polybft` consensus
* `scripts/cluster {ibft or polybft} --docker stop` - stop containers
* `scripts/cluster {ibft or polybft}--docker destroy` - destroy environment (delete containers and volumes)

### Using `docker-compose`
***All commands need to be run from the repo root / root folder.***

#### use `ibft` PoA consensus
* `export EDGE_CONSENSUS=ibft` - set `ibft` consensus
* `docker-compose -f ./docker/local/docker-compose.yml up -d --build` - deploy environment

#### use `polybft` consensus
* `cd core-contracts && npm install && npm run compile && cd -` - install `npm` dependencies and compile smart contracts
* `go run ./consensus/polybft/contractsapi/gen/main.go` generate needed code
* `export EDGE_CONSENSUS=polybft` - set `polybft` consensus
* `docker-compose -f ./docker/local/docker-compose.yml up -d --build` - deploy environment

#### stop / destroy
* `docker-compose -f ./docker/local/docker-compose.yml stop` - stop containers
* `docker-compose -f ./docker/local/docker-compose.yml down -v` - destroy environment

## Customization
Use `docker/local/polygon-edge.sh` script to customize chain parameters.
All parameters can be defined at the very beginning of the script, in the `CHAIN_CUSTOM_OPTIONS` variable.
It already has some default parameters, which can be easily modified.
These are the `genesis` parameters from the official [docs](https://wiki.polygon.technology/docs/edge/get-started/cli-commands#genesis-flags).

Primarily, the `--premine` parameter needs to be edited to include the accounts that the user has access to.

## Considerations

### Submodules
Before deploying `polybft` environment, `core-contracts` submodule needs to be downloaded.
To do that simply run `make download-submodules`.

### Build times
When building containers for the first time (or after purging docker build cache)
it might take a while to complete, depending on the hardware that the build operation is running on.

### Production
This is **NOT** a production ready deployment. It is to be used in *development* / *test* environments only.
For production usage, please check out the official [docs](https://wiki.polygon.technology/docs/edge/overview/).
1 change: 1 addition & 0 deletions docker/local/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ WORKDIR /polygon-edge

COPY --from=builder /polygon-edge/polygon-edge ./
COPY ./docker/local/polygon-edge.sh ./
COPY ./core-contracts/artifacts ./core-contracts/artifacts

# Expose json-rpc, libp2p and grpc ports
EXPOSE 8545 9632 1478
Expand Down
34 changes: 11 additions & 23 deletions docker/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,26 @@ services:
build:
context: ../../
dockerfile: docker/local/Dockerfile
command: ["init"]
command: ["init", "${EDGE_CONSENSUS:-ibft}"]
volumes:
- node-1:/polygon-edge/data-1
- node-2:/polygon-edge/data-2
- node-3:/polygon-edge/data-3
- node-4:/polygon-edge/data-4
- genesis:/genesis
- data:/data
networks:
- polygon-edge-docker

## RUN NODES
## Nodes must have the same names as folders in genesis-legde
node-1:
build:
context: ../../
dockerfile: docker/local/Dockerfile
command: ["server", "--data-dir", "/data", "--chain", "/genesis/genesis.json", "--grpc-address", "0.0.0.0:9632", "--libp2p", "0.0.0.0:1478", "--jsonrpc", "0.0.0.0:8545", "--seal"]
command: ["server", "--data-dir", "/data/data-1", "--chain", "/data/genesis.json", "--grpc-address", "0.0.0.0:9632", "--libp2p", "0.0.0.0:1478", "--jsonrpc", "0.0.0.0:8545", "--log-level", "DEBUG"]
depends_on:
init:
condition: service_completed_successfully
ports:
- '10000:9632'
- '10002:8545'
volumes:
- node-1:/data
- genesis:/genesis
- data:/data
networks:
- polygon-edge-docker
restart: on-failure
Expand All @@ -40,16 +34,15 @@ services:
build:
context: ../../
dockerfile: docker/local/Dockerfile
command: ["server", "--data-dir", "/data", "--chain", "/genesis/genesis.json", "--grpc-address", "0.0.0.0:9632", "--libp2p", "0.0.0.0:1478", "--jsonrpc", "0.0.0.0:8545", "--seal"]
command: ["server", "--data-dir", "/data/data-2", "--chain", "/data/genesis.json", "--grpc-address", "0.0.0.0:9632", "--libp2p", "0.0.0.0:1478", "--jsonrpc", "0.0.0.0:8545", "--log-level", "DEBUG"]
depends_on:
init:
condition: service_completed_successfully
ports:
- '20000:9632'
- '20002:8545'
volumes:
- node-2:/data
- genesis:/genesis
- data:/data
networks:
- polygon-edge-docker
restart: on-failure
Expand All @@ -58,16 +51,15 @@ services:
build:
context: ../../
dockerfile: docker/local/Dockerfile
command: ["server", "--data-dir", "/data", "--chain", "/genesis/genesis.json", "--grpc-address", "0.0.0.0:9632", "--libp2p", "0.0.0.0:1478", "--jsonrpc", "0.0.0.0:8545", "--seal"]
command: ["server", "--data-dir", "/data/data-3", "--chain", "/data/genesis.json", "--grpc-address", "0.0.0.0:9632", "--libp2p", "0.0.0.0:1478", "--jsonrpc", "0.0.0.0:8545", "--log-level", "DEBUG"]
depends_on:
init:
condition: service_completed_successfully
ports:
- '30000:9632'
- '30002:8545'
volumes:
- node-3:/data
- genesis:/genesis
- data:/data
networks:
- polygon-edge-docker
restart: on-failure
Expand All @@ -76,16 +68,15 @@ services:
build:
context: ../../
dockerfile: docker/local/Dockerfile
command: ["server", "--data-dir", "/data", "--chain", "/genesis/genesis.json", "--grpc-address", "0.0.0.0:9632", "--libp2p", "0.0.0.0:1478", "--jsonrpc", "0.0.0.0:8545", "--seal"]
command: ["server", "--data-dir", "/data/data-4", "--chain", "/data/genesis.json", "--grpc-address", "0.0.0.0:9632", "--libp2p", "0.0.0.0:1478", "--jsonrpc", "0.0.0.0:8545", "--log-level", "DEBUG"]
depends_on:
init:
condition: service_completed_successfully
ports:
- '40000:9632'
- '40002:8545'
volumes:
- node-4:/data
- genesis:/genesis
- data:/data
networks:
- polygon-edge-docker
restart: on-failure
Expand All @@ -96,8 +87,5 @@ networks:
name: polygon-edge-docker

volumes:
node-1:
node-2:
node-3:
node-4:
data:
genesis:
63 changes: 41 additions & 22 deletions docker/local/polygon-edge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,54 @@
set -e

POLYGON_EDGE_BIN=./polygon-edge
GENESIS_PATH=/genesis/genesis.json
CHAIN_CUSTOM_OPTIONS=$(tr "\n" " " << EOL
--block-gas-limit 10000000
--epoch-size 10
--chain-id 51001
--name polygon-edge-docker
--premine 0x228466F2C715CbEC05dEAbfAc040ce3619d7CF0B:0xD3C21BCECCEDA1000000
--premine 0xca48694ebcB2548dF5030372BE4dAad694ef174e:0xD3C21BCECCEDA1000000
EOL
)

case "$1" in

"init")
if [ -f "$GENESIS_PATH" ]; then
echo "Secrets have already been generated."
else
echo "Generating secrets..."
secrets=$("$POLYGON_EDGE_BIN" secrets init --num 4 --data-dir data- --json)
echo "Secrets have been successfully generated"

echo "Generating genesis file..."
"$POLYGON_EDGE_BIN" genesis \
--dir "$GENESIS_PATH" \
--consensus ibft \
--ibft-validators-prefix-path data- \
--bootnode /dns4/node-1/tcp/1478/p2p/$(echo $secrets | jq -r '.[0] | .node_id') \
--bootnode /dns4/node-2/tcp/1478/p2p/$(echo $secrets | jq -r '.[1] | .node_id')
echo "Genesis file has been successfully generated"
fi
case "$2" in
"ibft")
echo "Generating secrets..."
secrets=$("$POLYGON_EDGE_BIN" secrets init --num 4 --data-dir /data/data- --json)
echo "Secrets have been successfully generated"
echo "Generating IBFT Genesis file..."
cd /data && /polygon-edge/polygon-edge genesis $CHAIN_CUSTOM_OPTIONS \
--dir genesis.json \
--consensus ibft \
--ibft-validators-prefix-path data- \
--validator-set-size=4 \
--bootnode /dns4/node-1/tcp/1478/p2p/$(echo $secrets | jq -r '.[0] | .node_id') \
--bootnode /dns4/node-2/tcp/1478/p2p/$(echo $secrets | jq -r '.[1] | .node_id') \
;;
"polybft")
echo "Generating PolyBFT secrets..."
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved
secrets=$("$POLYGON_EDGE_BIN" polybft-secrets init --num 4 --data-dir /data/data- --json)
echo "Secrets have been successfully generated"

echo "Generating manifest..."
"$POLYGON_EDGE_BIN" manifest --path /data/manifest.json --validators-path /data --validators-prefix data-

echo "Generating PolyBFT Genesis file..."
"$POLYGON_EDGE_BIN" genesis $CHAIN_CUSTOM_OPTIONS \
--dir /data/genesis.json \
--consensus polybft \
--manifest /data/manifest.json \
--validator-set-size=4 \
--bootnode /dns4/node-1/tcp/1478/p2p/$(echo $secrets | jq -r '.[0] | .node_id') \
--bootnode /dns4/node-2/tcp/1478/p2p/$(echo $secrets | jq -r '.[1] | .node_id')
;;
esac
;;

*)
until [ -f "$GENESIS_PATH" ]
do
echo "Waiting 1s for genesis file $GENESIS_PATH to be created by init container..."
sleep 1
done
echo "Executing polygon-edge..."
exec "$POLYGON_EDGE_BIN" "$@"
;;
Expand Down
36 changes: 36 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Run servers form local binary

## Prerequisites

When deploying with `polybft` consensus, there are some additional dependencies:
* [npm](https://nodejs.org/en/)
* [go 1.18.x](https://go.dev/dl/)

## Local development
Running `polygon-edge` from local binary can be done very easily by using provided `scripts` folder.

* `scripts/cluster ibft` - deploy environment with `ibft` consensus
* `scripts/cluster polybft` - deploy environment with `polybft` consensus

## Customisation
Use `scripts/cluster` script to customize chain parameters.
It already has some default parameters, which can be easily modified.
These are the `genesis` parameters from the official [docs](https://wiki.polygon.technology/docs/edge/get-started/cli-commands#genesis-flags).

Primarily, the `--premine` parameter needs to be edited (`createGenesis` function) to include the accounts that the user has access to.

## Considerations

### Live console
The servers are run in foreground, meaning that the terminal console that is running the script
must remain active. To stop the servers - `Ctrl/Cmd + C`.
To interact with the chain use another terminal or run a dockerized environment by following the instructions
in `docker/README.md`.

### Submodules
Before deploying `polybft` environment, `core-contracts` submodule needs to be downloaded.
To do that simply run `make download-submodules`.

### Production
This is **NOT** a production ready deployment. It is to be used in *development* / *test* environments only.
For production usage, please check out the official [docs](https://wiki.polygon.technology/docs/edge/overview/).
Loading