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

Omit relayer flag for IBFT consensus #1971

Merged
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protoc: check-protoc
.PHONY: build
build: check-go check-git
$(eval COMMIT_HASH = $(shell git rev-parse HEAD))
$(eval VERSION = $(shell git tag --points-at $COMMIT_HASH))
$(eval VERSION = $(shell git tag --points-at ${COMMIT_HASH}))
$(eval BRANCH = $(shell git rev-parse --abbrev-ref HEAD | tr -d '\040\011\012\015\n'))
$(eval TIME = $(shell date))
go build -o polygon-edge -ldflags="\
Expand Down
1 change: 0 additions & 1 deletion docker/local/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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 5001
Expand Down
11 changes: 1 addition & 10 deletions docker/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,7 @@ services:
node-1:
image: local/polygon-edge
container_name: polygon-edge-validator-1
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",
"--prometheus", "0.0.0.0:5001",
"--relayer"
]
command: [ "start-node-1", "${EDGE_CONSENSUS:-polybft}" ]
depends_on:
init:
condition: service_completed_successfully
Expand Down
64 changes: 42 additions & 22 deletions docker/local/polygon-edge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ CHAIN_CUSTOM_OPTIONS=$(tr "\n" " " << EOL
EOL
)

# createGenesisConfig creates genesis configuration
createGenesisConfig() {
local consensus_type="$1"
local secrets="$2"
shift 2
echo "Generating $consensus_type Genesis file..."

"$POLYGON_EDGE_BIN" genesis $CHAIN_CUSTOM_OPTIONS \
--dir /data/genesis.json \
--consensus $consensus_type \
--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')" \
--bootnode "/dns4/node-3/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[2] | .node_id')" \
--bootnode "/dns4/node-4/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[3] | .node_id')" \
"$@"
}

case "$1" in
"init")
case "$2" in
Expand All @@ -28,15 +45,8 @@ case "$1" in

rm -f /data/genesis.json

echo "Generating IBFT Genesis file..."
"$POLYGON_EDGE_BIN" genesis $CHAIN_CUSTOM_OPTIONS \
--dir /data/genesis.json \
--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')" \
--bootnode "/dns4/node-3/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[2] | .node_id')" \
--bootnode "/dns4/node-4/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[3] | .node_id')"
createGenesisConfig "$2" "$secrets" \
--ibft-validators-prefix-path data-
fi
;;
"polybft")
Expand All @@ -48,19 +58,12 @@ case "$1" in

proxyContractsAdmin=0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed

echo "Generating PolyBFT genesis file..."
"$POLYGON_EDGE_BIN" genesis $CHAIN_CUSTOM_OPTIONS \
--dir /data/genesis.json \
--consensus polybft \
--validators-path /data \
--validators-prefix data- \
--reward-wallet 0xDEADBEEF:1000000 \
--native-token-config "Polygon:MATIC:18:true:$(echo "$secrets" | jq -r '.[0] | .address')" \
--proxy-contracts-admin ${proxyContractsAdmin} \
--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')" \
--bootnode "/dns4/node-3/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[2] | .node_id')" \
--bootnode "/dns4/node-4/tcp/1478/p2p/$(echo "$secrets" | jq -r '.[3] | .node_id')"
createGenesisConfig "$2" "$secrets" \
--validators-path /data \
--validators-prefix data- \
--reward-wallet 0xDEADBEEF:1000000 \
--native-token-config "Polygon:MATIC:18:true:$(echo "$secrets" | jq -r '.[0] | .address')" \
--proxy-contracts-admin ${proxyContractsAdmin}

echo "Deploying stake manager..."
"$POLYGON_EDGE_BIN" polybft stake-manager-deploy \
Expand Down Expand Up @@ -128,6 +131,23 @@ case "$1" in
;;
esac
;;
"start-node-1")
relayer_flag=""
# Start relayer only when run in polybft
if [ "$2" == "polybft" ]; then
echo "Starting relayer..."
relayer_flag="--relayer"
fi

"$POLYGON_EDGE_BIN" 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 \
--prometheus 0.0.0.0:5001 \
$relayer_flag
;;
*)
echo "Executing polygon-edge..."
exec "$POLYGON_EDGE_BIN" "$@"
Expand Down
71 changes: 39 additions & 32 deletions scripts/cluster
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if [[ "$dp_error_flag" -eq 1 ]]; then
exit 1
fi

function showhelp(){
function showhelp() {
echo "Usage: cluster {consensus} [{command}] [{flags}]"
echo "Consensus:"
echo " ibft Start Supernets test environment locally with ibft consensus"
Expand Down Expand Up @@ -160,37 +160,44 @@ function initRootchain() {
--jsonrpc http://127.0.0.1:8545
}

function startServerFromBinary() {
if [ "$1" == "write-logs" ]; then
function startNodes() {
if [ "$2" == "write-logs" ]; then
echo "Writing validators logs to the files..."
./polygon-edge server --data-dir ./test-chain-1 --chain genesis.json \
--grpc-address :10000 --libp2p :30301 --jsonrpc :10002 --relayer \
--num-block-confirmations 2 --log-level DEBUG 2>&1 | tee ./validator-1.log &
./polygon-edge server --data-dir ./test-chain-2 --chain genesis.json \
--grpc-address :20000 --libp2p :30302 --jsonrpc :20002 \
--num-block-confirmations 2 --log-level DEBUG 2>&1 | tee ./validator-2.log &
./polygon-edge server --data-dir ./test-chain-3 --chain genesis.json \
--grpc-address :30000 --libp2p :30303 --jsonrpc :30002 \
--num-block-confirmations 2 --log-level DEBUG 2>&1 | tee ./validator-3.log &
./polygon-edge server --data-dir ./test-chain-4 --chain genesis.json \
--grpc-address :40000 --libp2p :30304 --jsonrpc :40002 \
--num-block-confirmations 2 --log-level DEBUG 2>&1 | tee ./validator-4.log &
wait
else
./polygon-edge server --data-dir ./test-chain-1 --chain genesis.json \
--grpc-address :10000 --libp2p :30301 --jsonrpc :10002 --relayer \
--num-block-confirmations 2 --log-level DEBUG &
./polygon-edge server --data-dir ./test-chain-2 --chain genesis.json \
--grpc-address :20000 --libp2p :30302 --jsonrpc :20002 \
--num-block-confirmations 2 --log-level DEBUG &
./polygon-edge server --data-dir ./test-chain-3 --chain genesis.json \
--grpc-address :30000 --libp2p :30303 --jsonrpc :30002 \
--num-block-confirmations 2 --log-level DEBUG &
./polygon-edge server --data-dir ./test-chain-4 --chain genesis.json \
--grpc-address :40000 --libp2p :30304 --jsonrpc :40002 \
--num-block-confirmations 2 --log-level DEBUG &
wait
fi

for i in {1..4}; do
data_dir="./test-chain-$i"
grpc_port=$((10000 * $i))
libp2p_port=$((30300 + $i))
jsonrpc_port=$((10000 * $i + 2))

log_file="./validator-$i.log"

relayer_arg=""
# Start relayer only if running polybft and for the 1st node
if [ "$1" == "polybft" ] && [ $i -eq 1 ]; then
relayer_arg="--relayer"
fi

if [ "$2" == "write-logs" ]; then
if [ ! -f "$log_file" ]; then
touch "$log_file"
fi

./polygon-edge server --data-dir "$data_dir" --chain genesis.json \
--grpc-address ":$grpc_port" --libp2p ":$libp2p_port" --jsonrpc ":$jsonrpc_port" \
--num-block-confirmations 2 $relayer_arg \
--log-level DEBUG 2>&1 | tee $log_file &
else
./polygon-edge server --data-dir "$data_dir" --chain genesis.json \
--grpc-address ":$grpc_port" --libp2p ":$libp2p_port" --jsonrpc ":$jsonrpc_port" \
--num-block-confirmations 2 $relayer_arg \
--log-level DEBUG &
fi

done

wait
}

function startServerFromDockerCompose() {
Expand Down Expand Up @@ -254,15 +261,15 @@ case "$2" in
initIbftConsensus
# Create genesis file and start the server from binary
createGenesis
startServerFromBinary $2
startNodes $1 $2
exit 0
elif [ "$1" == "polybft" ]; then
# Initialize polybft consensus
initPolybftConsensus
# Create genesis file and start the server from binary
createGenesis
initRootchain $2
startServerFromBinary $2
startNodes $1 $2
exit 0
else
echo "Unsupported consensus mode. Supported modes are: ibft and polybft."
Expand Down
Loading